Merge "IpmiServer to allow using IP version 4"

This commit is contained in:
Jenkins 2016-12-01 15:13:07 +00:00 committed by Gerrit Code Review
commit d77b4caa75
2 changed files with 15 additions and 5 deletions

View File

@ -23,6 +23,7 @@ import hmac
import os
import pyghmi.ipmi.private.constants as constants
import pyghmi.ipmi.private.session as ipmisession
import socket
import struct
import uuid
@ -239,7 +240,7 @@ class IpmiServer(object):
reasonable subset.
:param port: The default port number to bind to. Defaults to the
standard 623
:param address: The IPv6 address to bind to. Defaults to '::' (all
:param address: The IP address to bind to. Defaults to '::' (all
zeroes)
"""
self.revision = 0
@ -265,8 +266,9 @@ class IpmiServer(object):
authstatus, chancap, *oemdata)
self.kg = None
self.timeout = 60
self.serversocket = ipmisession.Session._assignsocket(
(address, port, 0, 0))
addrinfo = socket.getaddrinfo(address, port, 0,
socket.SOCK_DGRAM)[0]
self.serversocket = ipmisession.Session._assignsocket(addrinfo)
ipmisession.Session.bmc_handlers[self.serversocket] = self
def send_auth_cap(self, myaddr, mylun, clientaddr, clientlun, clientseq,

View File

@ -329,6 +329,7 @@ class Session(object):
global iosockets
global ipv6support
global myself
# seek for the least used socket. As sessions close, they may free
# up slots in seemingly 'full' sockets. This scheme allows those
# slots to be recycled
@ -340,7 +341,14 @@ class Session(object):
cls.socketpool[sorted_candidates[0][0]] += 1
return sorted_candidates[0][0]
# we need a new socket
if ipv6support:
if server:
# Regardless of whether ipv6 is supported or not, we
# must try to honor the address format of the given
# server, rather than trying to create an automatic one
tmpsocket = socket.socket(server[0], socket.SOCK_DGRAM)
if server[0] == socket.AF_INET6:
tmpsocket.setsockopt(IPPROTO_IPV6, socket.IPV6_V6ONLY, 0)
elif ipv6support:
tmpsocket = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
tmpsocket.setsockopt(IPPROTO_IPV6, socket.IPV6_V6ONLY, 0)
elif ipv6support is None: # we need to determine ipv6 support now
@ -360,7 +368,7 @@ class Session(object):
tmpsocket.bind(('', 0))
cls.socketpool[tmpsocket] = 1
else:
tmpsocket.bind(server)
tmpsocket.bind(server[4])
iosockets.append(tmpsocket)
if myself is None:
# we have confirmed kernel IPv6 support, but ::1 may still not