[syslinux] [PATCH] Updated udp.c to use real client ip and subnetmask values if on local subnet
jeff_sloan at selinc.com
jeff_sloan at selinc.com
Wed Jul 8 12:32:32 PDT 2015
from: Jeff Sloan <jeff_sloan at selinc.com>
Based on commit: 9314e330
Setting UseDefaultAddress to TRUE uses invalid StationAddress and
SubnetMask values. This is in a network with a local TFTP/MTFTP server. If
the server is local, on the same subnet, UseDefaultAddress is set to false
and the client ip and subnetmask are loaded, otherwise set
UseDefaultAddress to TRUE. This is added to core_udp_connect and
core_udp_sendto.
Signed-off-by: Jeff Sloan <jeff_sloan at selinc.com>
---
Diffstat:
udp.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 50 insertions(+), 2 deletions(-)
--- udp.c 2015-07-06 07:22:04.000000000 -0700
+++ efi/udp.c 2015-07-08 12:13:48.000000000 -0700
@@ -142,6 +142,7 @@ void core_udp_connect(struct pxe_pvt_ino
EFI_UDP4_CONFIG_DATA udata;
EFI_STATUS status;
EFI_UDP4 *udp;
+ uint32_t tip;
udp = (EFI_UDP4 *)socket->net.efi.binding->this;
@@ -150,7 +151,30 @@ void core_udp_connect(struct pxe_pvt_ino
/* Re-use the existing local port number */
udata.StationPort = socket->net.efi.localport;
- udata.UseDefaultAddress = TRUE;
+ /**
+ * Determine if this is remote or local subnet to set
+ * UseDefaultAddress. If ip (TFTP/MTFTP server or
+ * RemoteAddress) is on same subnet as client,
+ * which is stored in IPInfo.myip, this is local subnet.
+ */
+ if (0 == IPInfo.myip || 0 == ip) {
+ /* if either address is NULL, enable default addresses */
+ udata.UseDefaultAddress = TRUE;
+ } else {
+ if ((IPInfo.myip & IPInfo.netmask) == (ip & IPInfo.netmask)) {
+ /* On same subnet */
+ udata.UseDefaultAddress = FALSE;
+ /* Set ip and subnet*/
+ tip = IPInfo.myip;
+ memcpy(&udata.StationAddress, &tip, sizeof(tip));
+ tip = IPInfo.netmask;
+ memcpy(&udata.SubnetMask, &tip, sizeof(tip));
+ } else {
+ /*on different subnets*/
+ udata.UseDefaultAddress = TRUE;
+ }
+ }
+
memcpy(&udata.RemoteAddress, &ip, sizeof(ip));
udata.RemotePort = port;
udata.AcceptPromiscuous = TRUE;
@@ -350,6 +374,7 @@ void core_udp_sendto(struct pxe_pvt_inod
EFI_STATUS status;
struct efi_binding *b;
EFI_UDP4 *udp;
+ uint32_t tip;
(void)socket;
@@ -372,7 +397,30 @@ void core_udp_sendto(struct pxe_pvt_inod
/* Re-use the existing local port number */
udata.StationPort = socket->net.efi.localport;
- udata.UseDefaultAddress = TRUE;
+ /**
+ * Determine if this is remote or local subnet to set
+ * UseDefaultAddress. If ip (TFTP/MTFTP server or
+ * RemoteAddress) is on same subnet as client,
+ * which is stored in IPInfo.myip, this is local subnet.
+ */
+ if (0 == IPInfo.myip || 0 == ip) {
+ /* if either address is NULL, enable default addresses */
+ udata.UseDefaultAddress = TRUE;
+ } else {
+ if ((IPInfo.myip & IPInfo.netmask) == (ip & IPInfo.netmask)) {
+ /* On same subnet */
+ udata.UseDefaultAddress = FALSE;
+ /* Set ip and subnet*/
+ tip = IPInfo.myip;
+ memcpy(&udata.StationAddress, &tip, sizeof(tip));
+ tip = IPInfo.netmask;
+ memcpy(&udata.SubnetMask, &tip, sizeof(tip));
+ } else {
+ /*on different subnets*/
+ udata.UseDefaultAddress = TRUE;
+ }
+ }
+
memcpy(&udata.RemoteAddress, &ip, sizeof(ip));
udata.RemotePort = port;
udata.AcceptPromiscuous = TRUE;
More information about the Syslinux
mailing list