vSPC: Escape 'sequence' and 'secret' in replies.

The values of 'sequence' and 'secret' are arbitrary byte strings which might
contain IAC (0xff) or SE (0xf0) in any position.  Lack of escaping during
transmission might cause receiver confusion and potentially vMotion failures.

This change adds escaping of these 'sequence' and 'secret' values before
transmission.  They are already being unescaped correctly during receipt; Only
the transmit side needs to be fixed.

Change-Id: I82384424d684b931805ca921d0597ad7642f66ac
This commit is contained in:
Darius Davis 2023-06-21 21:15:41 -07:00 committed by Radoslav Gerganov
parent b3914a6e8c
commit 206e36008f
3 changed files with 11 additions and 3 deletions

View File

@ -15,5 +15,6 @@ commands = flake8
commands = {posargs} commands = {posargs}
[flake8] [flake8]
ignore = E121,E122,E123,E124,E125,E126,E127,E128,E129,E131,E251,H405 # W504 skipped since you must choose either W503 or W504 (they conflict)
ignore = E121,E122,E123,E124,E125,E126,E127,E128,E129,E131,E251,H405,W504
exclude = venv,.venv,.git,.tox,dist,doc,*lib/python*,*egg,build exclude = venv,.venv,.git,.tox,dist,doc,*lib/python*,*egg,build

View File

@ -44,6 +44,12 @@ class AsyncTelnet:
self.sb = 0 # flag for SB and SE sequence. self.sb = 0 # flag for SB and SE sequence.
self.sbdataq = b'' self.sbdataq = b''
@staticmethod
def escape(data):
"""Escape any Telnet IACs with another IAC.
"""
return data.replace(IAC, IAC + IAC)
@asyncio.coroutine @asyncio.coroutine
def process_rawq(self): def process_rawq(self):
"""Transfer from raw queue to cooked queue. """Transfer from raw queue to cooked queue.

View File

@ -121,7 +121,7 @@ class VspcServer(object):
secret = os.urandom(4) secret = os.urandom(4)
LOG.debug(">> %s VMOTION-GOAHEAD %s %s", peer, data, secret) LOG.debug(">> %s VMOTION-GOAHEAD %s %s", peer, data, secret)
writer.write(IAC + SB + VMWARE_EXT + VMOTION_GOAHEAD + writer.write(IAC + SB + VMWARE_EXT + VMOTION_GOAHEAD +
data + secret + IAC + SE) async_telnet.AsyncTelnet.escape(data + secret) + IAC + SE)
yield from writer.drain() yield from writer.drain()
@asyncio.coroutine @asyncio.coroutine
@ -130,7 +130,8 @@ class VspcServer(object):
peer = socket.getpeername() peer = socket.getpeername()
LOG.debug("<< %s VMOTION-PEER %s", peer, data) LOG.debug("<< %s VMOTION-PEER %s", peer, data)
LOG.debug("<< %s VMOTION-PEER-OK %s", peer, data) LOG.debug("<< %s VMOTION-PEER-OK %s", peer, data)
writer.write(IAC + SB + VMWARE_EXT + VMOTION_PEER_OK + data + IAC + SE) writer.write(IAC + SB + VMWARE_EXT + VMOTION_PEER_OK +
async_telnet.AsyncTelnet.escape(data) + IAC + SE)
yield from writer.drain() yield from writer.drain()
def handle_vmotion_complete(self, socket, data): def handle_vmotion_complete(self, socket, data):