Skip to content

Commit

Permalink
Add sync support
Browse files Browse the repository at this point in the history
But still not working. Frames read from pppd via pty sometime are
broken, I don't know why.
  • Loading branch information
sorz committed Mar 30, 2017
1 parent 993709c commit 15f66b3
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 7 deletions.
4 changes: 4 additions & 0 deletions sstpd/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def _getArgs():
'pppd': '/usr/sbin/pppd',
'pppd_config': '/etc/ppp/options.sstpd',
'local': '192.168.20.1',
'sync': False,
'log_level': logging.INFO
}
if args.conf_file:
Expand Down Expand Up @@ -75,6 +76,9 @@ def _getArgs():
parser.add_argument('--ciphers',
metavar="CIPHER-LIST",
help='Custom OpenSSL cipher suite. See ciphers(1).')
parser.add_argument('--sync',
action='store_true',
help="Enable Synchronous HDLC.")
parser.add_argument('-v', '--log-level',
type=int, metavar='LOG-LEVEL',
help="1 to 50. Default 20, debug 10, verbose 5.")
Expand Down
36 changes: 30 additions & 6 deletions sstpd/ppp.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,47 @@
class PPPDProtocol(ProcessProtocol):
implements(interfaces.IPushProducer)

def __init__(self):
def __init__(self, sync):
self.frameBuffer = b''
self.frameEscaped = False
self.paused = False
self.sync = sync


def writeFrame(self, frame):
self.transport.write(escape(frame))
if self.sync:
self.transport.write(frame)
else:
self.transport.write(escape(frame))


def outReceived(self, data):
if __debug__:
logging.log(VERBOSE, "Raw data: %s", hexdump(data))
frames, self.frameBuffer, self.frameEscaped = \
unescape(data, self.frameBuffer, self.frameEscaped)
for frame in frames:
self.pppFrameReceived(frame)
if self.sync:
data = self.frameBuffer + data
self.frameBuffer = b''
start = 0
while start < len(data):
if data[start] == '\xff':
length = ord(data[start+6]) << 8 | ord(data[start+7])
length += 4
elif data[start] not in ('\xff', '\x80', '\x82', '\xc0', '\xc2', '\xc4'):
length = ord(data[start+3]) << 8 | ord(data[start+4])
length += 1 # proto no. on first byte
#logging.info("length: %s", length)
else:
length = len(data) - start
if start + length <= len(data):
self.pppFrameReceived(data[start:start+length])
else:
self.frameBuffer = data[start:]
start += length
else:
frames, self.frameBuffer, self.frameEscaped = \
unescape(data, self.frameBuffer, self.frameEscaped)
for frame in frames:
self.pppFrameReceived(frame)


def pppFrameReceived(self, frame):
Expand Down
5 changes: 4 additions & 1 deletion sstpd/sstp.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def sstpMsgCallConnectRequestReceived(self, protocolId):
ack.attributes = [(SSTP_ATTRIB_CRYPTO_BINDING_REQ,
'\x00\x00\x00' + '\x03' + self.nonce)]
ack.writeTo(self.transport.write)
self.pppd = PPPDProtocol()
self.pppd = PPPDProtocol(self.factory.syncMode)
self.pppd.sstp = self
if self.factory.remotePool:
self.pppd.remote = self.factory.remotePool.apply()
Expand All @@ -224,6 +224,8 @@ def sstpMsgCallConnectRequestReceived(self, protocolId):
'115200', addressArgument]
if self.remoteHost is not None:
args += ['remotenumber', self.remoteHost]
if self.factory.syncMode:
args += ['sync']
reactor.spawnProcess(self.pppd, self.factory.pppd, args=args, usePTY=True)
self.transport.registerProducer(self.pppd, True)
self.pppd.resumeProducing()
Expand Down Expand Up @@ -395,4 +397,5 @@ def __init__(self, config, remotePool, certHash=None):
self.proxyProtocol = config.proxy_protocol
self.remotePool = remotePool
self.certHash = certHash
self.syncMode = config.sync

0 comments on commit 15f66b3

Please sign in to comment.