Without an assigned source port, Transmit function assign a random new source port to the packet being sent. It thus have to be set before calling Transmit if the source port have already been decided. Conversly, we have to save the assigned port to reuse it later if needed. Resolve bug #35. Signed-off-by: Celelibi <celelibi at gmail.com> --- efi/udp.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/efi/udp.c b/efi/udp.c index 59bb426..7271f1f 100644 --- a/efi/udp.c +++ b/efi/udp.c @@ -336,6 +336,9 @@ void core_udp_sendto(struct pxe_pvt_inode *socket, const void *data, memset(&udata, 0, sizeof(udata)); + /* Re-use the existing local port number if any */ + udata.StationPort = socket->net.efi.localport; + memcpy(&udata.StationAddress, &IPInfo.myip, sizeof(IPInfo.myip)); memcpy(&udata.SubnetMask, &IPInfo.netmask, sizeof(IPInfo.netmask)); memcpy(&udata.RemoteAddress, &ip, sizeof(ip)); @@ -373,6 +376,21 @@ void core_udp_sendto(struct pxe_pvt_inode *socket, const void *data, /* Reset */ cb_status = -1; + /* + * If this is the first time sending a packet, save the random local + * port number that the UDPv4 Protocol Driver picked for us. The TFTP + * protocol uses the local port number as the TID, and it needs to + * be consistent across connect()/disconnect() calls. + */ + if (!socket->net.efi.localport) { + status = uefi_call_wrapper(udp->GetModeData, 5, udp, + &udata, NULL, NULL, NULL); + if (status != EFI_SUCCESS) + Print(L"Failed to get UDP mode data: %d\n", status); + else + socket->net.efi.localport = udata.StationPort; + } + close: uefi_call_wrapper(BS->CloseEvent, 1, token->Event); -- 1.8.4.3
On Thu, Nov 28, 2013 at 9:34 PM, Celelibi <celelibi at gmail.com> wrote:> Without an assigned source port, Transmit function assign a random new > source port to the packet being sent. It thus have to be set before > calling Transmit if the source port have already been decided. > Conversly, we have to save the assigned port to reuse it later if > needed. > > Resolve bug #35. > > Signed-off-by: Celelibi <celelibi at gmail.com> > --- > efi/udp.c | 18 ++++++++++++++++++ > 1 file changed, 18 insertions(+) > > diff --git a/efi/udp.c b/efi/udp.c > index 59bb426..7271f1f 100644 > --- a/efi/udp.c > +++ b/efi/udp.c > @@ -336,6 +336,9 @@ void core_udp_sendto(struct pxe_pvt_inode *socket, const void *data, > > memset(&udata, 0, sizeof(udata)); > > + /* Re-use the existing local port number if any */ > + udata.StationPort = socket->net.efi.localport; > +As HPA noted, this shouldn't be saved here. Commit 7ec052b on my branch efi-fixes (will be renamed to efi-fixes-for-mfleming once Jason gives more feedback). -- -Gene
On Thu, Nov 28, 2013 at 9:47 PM, Gene Cumm <gene.cumm at gmail.com> wrote:> On Thu, Nov 28, 2013 at 9:34 PM, Celelibi <celelibi at gmail.com> wrote: >> Without an assigned source port, Transmit function assign a random new >> source port to the packet being sent. It thus have to be set before >> calling Transmit if the source port have already been decided. >> Conversly, we have to save the assigned port to reuse it later if >> needed. >> >> Resolve bug #35. >> >> Signed-off-by: Celelibi <celelibi at gmail.com> >> --- >> efi/udp.c | 18 ++++++++++++++++++ >> 1 file changed, 18 insertions(+) >> >> diff --git a/efi/udp.c b/efi/udp.c >> index 59bb426..7271f1f 100644 >> --- a/efi/udp.c >> +++ b/efi/udp.c >> @@ -336,6 +336,9 @@ void core_udp_sendto(struct pxe_pvt_inode *socket, const void *data, >> >> memset(&udata, 0, sizeof(udata)); >> >> + /* Re-use the existing local port number if any */ >> + udata.StationPort = socket->net.efi.localport; >> + > > As HPA noted, this shouldn't be saved here. Commit 7ec052b on my > branch efi-fixes (will be renamed to efi-fixes-for-mfleming once Jason > gives more feedback).To clarify, this code-quote reuses (needed) while the removed one saves and should be in core_udp_open(). Perhaps a fallback-save in here if the local port is somehow still NULL. -- -Gene