From 5d722ccd406a426cf2a622fa92ab9b876989440a Mon Sep 17 00:00:00 2001 From: Luca Bodini Date: Wed, 18 Sep 2019 13:05:01 +0200 Subject: [PATCH 1/2] Update pxed.py Casting bytes to string, in python3 casting bytes to string is not implicit --- pybootd/pxed.py | 57 +++++++++++++++++++++++++------------------------ 1 file changed, 29 insertions(+), 28 deletions(-) diff --git a/pybootd/pxed.py b/pybootd/pxed.py index 1c13ac4..26eb1c1 100644 --- a/pybootd/pxed.py +++ b/pybootd/pxed.py @@ -312,34 +312,35 @@ def parse_options(self, tail): continue dhcp_tags[tag] = value - def build_pxe_options(self, options, server): - buf = b'' - try: - uuid = options[97] - buf += spack('!BB%ds' % len(uuid), - 97, len(uuid), uuid) - clientclass = options[60] - clientclass = clientclass[:clientclass.find(':')] - buf += spack('!BB%ds' % len(clientclass), - 60, len(clientclass), clientclass) - vendor = '' - vendor += spack('!BBB', PXE_DISCOVERY_CONTROL, 1, 0x0A) - vendor += spack('!BBHB4s', PXE_BOOT_SERVERS, 2+1+4, - 0, 1, server) - srvstr = 'Python' - vendor += spack('!BBHB%ds' % len(srvstr), PXE_BOOT_MENU, - 2+1+len(srvstr), 0, len(srvstr), srvstr) - prompt = 'Stupid PXE' - vendor += spack('!BBB%ds' % len(prompt), PXE_MENU_PROMPT, - 1+len(prompt), len(prompt), prompt) - buf += spack('!BB%ds' % len(vendor), 43, - len(vendor), vendor) - buf += spack('!BBB', 255, 0, 0) - return buf - except KeyError as exc: - self.log.error('Missing options, cancelling: %s' % exc) - return b'' - +def build_pxe_options(self, options, server): + buf = b'' + try: + uuid = options[97] + buf += spack('!BB%ds' % len(uuid), + 97, len(uuid), uuid) + clientclass = options[60] + #clientclass = clientclass[:clientclass.find(':')] + clientclass = clientclass[:clientclass.find(b':')] + buf += spack('!BB%ds' % len(clientclass), + 60, len(clientclass), clientclass) + vendor = '' + vendor += spack('!BBB', PXE_DISCOVERY_CONTROL, 1, 0x0a).decode("utf-8") + vendor += spack('!BBHB4s', PXE_BOOT_SERVERS, 2+1+4, + 0, 1, server).decode("utf-8") + srvstr = b'Python' + vendor += spack('!BBHB%ds' % len(srvstr), PXE_BOOT_MENU, + 2+1+len(srvstr), 0, len(srvstr), srvstr).decode("utf-8") + prompt = b'Stupid PXE' + vendor += spack('!BBB%ds' % len(prompt), PXE_MENU_PROMPT, + 1+len(prompt), len(prompt), prompt).decode("utf-8") + buf += spack('!BB%ds' % len(vendor), 43, + len(vendor), vendor.encode("utf-8")) + buf += spack('!BBB', 255, 0, 0) + return buf + except KeyError as exc: + self.log.error('Missing options, cancelling: %s' % exc) + return b'' + def build_dhcp_options(self, clientname): if not clientname: return b'' From bb6e5c0e13fb8553911e600b7f4801c7c45aa916 Mon Sep 17 00:00:00 2001 From: Luca Bodini Date: Wed, 18 Sep 2019 13:11:54 +0200 Subject: [PATCH 2/2] Update tftpd.py tftpd before doesn't allow to send data up to 16,7MB (512*32767) because "int" was overflowing and expecting an ack backet with negative ACK: fixed initializing self.blockNumber = np.int16(0x0000) and sum block with block = self.blockNumber = np.int16(self.blockNumber + 1) --- pybootd/tftpd.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pybootd/tftpd.py b/pybootd/tftpd.py index 39ef502..ca1f613 100644 --- a/pybootd/tftpd.py +++ b/pybootd/tftpd.py @@ -30,6 +30,7 @@ from urllib.request import urlopen from . import pybootd_path from .util import hexline +import numpy as np #pylint: disable-msg=broad-except #pylint: disable-msg=invalid-name @@ -71,7 +72,7 @@ def __init__(self, server, port=0): self.client_addr = None self.sock = None self.active = 0 # 0: inactive, 1: active - self.blockNumber = 0 + self.blockNumber = np.int16(0x0000) self.lastpkt = '' self.mode = '' self.filename = '' @@ -263,7 +264,7 @@ def send_data(self, data, pack=spack): if not self.time: self.time = now() blocksize = self.blocksize - block = self.blockNumber = self.blockNumber + 1 + block = self.blockNumber = np.int16(self.blockNumber + 1) lendata = len(data) fmt = '!hh%ds' % lendata pkt = pack(fmt, self.DATA, block, data)