mirror of
https://github.com/openvswitch/ovs
synced 2025-08-31 14:25:26 +00:00
python: Add TCP passive-mode to IDL.
Requested-by: "D M, Vikas" <vikas.d-m@hpe.com> Requested-by: "Kamat, Maruti Haridas" <maruti.kamat@hpe.com> Requested-by: "Sukhdev Kapur" <sukhdev@arista.com> Requested-by: "Migliaccio, Armando" <armando.migliaccio@hpe.com> Signed-off-by: "Ofer Ben-Yacov" <ofer.benyacov@gmail.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
This commit is contained in:
committed by
Ben Pfaff
parent
0cfd47f9dc
commit
af35823711
@@ -435,7 +435,7 @@ class Session(object):
|
||||
self.reconnect.connecting(ovs.timeval.msec())
|
||||
else:
|
||||
self.reconnect.connect_failed(ovs.timeval.msec(), error)
|
||||
elif self.pstream is not None:
|
||||
elif self.pstream is None:
|
||||
error, self.pstream = ovs.stream.PassiveStream.open(name)
|
||||
if not error:
|
||||
self.reconnect.listening(ovs.timeval.msec())
|
||||
|
@@ -269,9 +269,9 @@ class PassiveStream(object):
|
||||
@staticmethod
|
||||
def is_valid_name(name):
|
||||
"""Returns True if 'name' is a passive stream name in the form
|
||||
"TYPE:ARGS" and TYPE is a supported passive stream type (currently only
|
||||
"punix:"), otherwise False."""
|
||||
return name.startswith("punix:")
|
||||
"TYPE:ARGS" and TYPE is a supported passive stream type (currently
|
||||
"punix:" or "ptcp"), otherwise False."""
|
||||
return name.startswith("punix:") | name.startswith("ptcp:")
|
||||
|
||||
def __init__(self, sock, name, bind_path):
|
||||
self.name = name
|
||||
@@ -282,8 +282,8 @@ class PassiveStream(object):
|
||||
def open(name):
|
||||
"""Attempts to start listening for remote stream connections. 'name'
|
||||
is a connection name in the form "TYPE:ARGS", where TYPE is an passive
|
||||
stream class's name and ARGS are stream class-specific. Currently the
|
||||
only supported TYPE is "punix".
|
||||
stream class's name and ARGS are stream class-specific. Currently the
|
||||
supported values for TYPE are "punix" and "ptcp".
|
||||
|
||||
Returns (error, pstream): on success 'error' is 0 and 'pstream' is the
|
||||
new PassiveStream, on failure 'error' is a positive errno value and
|
||||
@@ -294,10 +294,20 @@ class PassiveStream(object):
|
||||
bind_path = name[6:]
|
||||
if name.startswith("punix:"):
|
||||
bind_path = ovs.util.abs_file_name(ovs.dirs.RUNDIR, bind_path)
|
||||
error, sock = ovs.socket_util.make_unix_socket(socket.SOCK_STREAM,
|
||||
True, bind_path, None)
|
||||
if error:
|
||||
return error, None
|
||||
error, sock = ovs.socket_util.make_unix_socket(socket.SOCK_STREAM,
|
||||
True, bind_path,
|
||||
None)
|
||||
if error:
|
||||
return error, None
|
||||
|
||||
elif name.startswith("ptcp:"):
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||
remote = name.split(':')
|
||||
sock.bind((remote[1], int(remote[2])))
|
||||
|
||||
else:
|
||||
raise Exception('Unknown connection string')
|
||||
|
||||
try:
|
||||
sock.listen(10)
|
||||
@@ -328,7 +338,10 @@ class PassiveStream(object):
|
||||
try:
|
||||
sock, addr = self.socket.accept()
|
||||
ovs.socket_util.set_nonblocking(sock)
|
||||
return 0, Stream(sock, "unix:%s" % addr, 0)
|
||||
if (sock.family == socket.AF_UNIX):
|
||||
return 0, Stream(sock, "unix:%s" % addr, 0)
|
||||
return 0, Stream(sock, 'ptcp:%s:%s' % (addr[0],
|
||||
str(addr[1])), 0)
|
||||
except socket.error as e:
|
||||
error = ovs.socket_util.get_exception_errno(e)
|
||||
if error != errno.EAGAIN:
|
||||
|
Reference in New Issue
Block a user