[syslinux] [PATCH] efi: reuse UDP port with sendto

Celelibi celelibi at gmail.com
Thu Nov 28 18:34:41 PST 2013


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



More information about the Syslinux mailing list