5a73eab
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
5a73eab
From: Andrzej Kacprowski <andrzej.kacprowski@intel.com>
5a73eab
Date: Fri, 21 Apr 2017 09:20:38 +0200
5a73eab
Subject: [PATCH] Use xid to match DHCP replies
5a73eab
5a73eab
Transaction identifier (xid) from DHCP request
5a73eab
packet is stored in network level interface and used
5a73eab
to match request with the responses it generates.
5a73eab
5a73eab
Resolves: rhbz#1370642
5a73eab
5a73eab
Signed-off-by: Andrzej Kacprowski <andrzej.kacprowski@intel.com>
5a73eab
---
5a73eab
 grub-core/net/bootp.c | 3 ++-
5a73eab
 grub-core/net/ip.c    | 1 +
5a73eab
 include/grub/net.h    | 3 ++-
5a73eab
 3 files changed, 5 insertions(+), 2 deletions(-)
5a73eab
5a73eab
diff --git a/grub-core/net/bootp.c b/grub-core/net/bootp.c
5a73eab
index da3e454466b..2869482fe06 100644
5a73eab
--- a/grub-core/net/bootp.c
5a73eab
+++ b/grub-core/net/bootp.c
5a73eab
@@ -777,7 +777,8 @@ grub_cmd_bootp (struct grub_command *cmd __attribute__ ((unused)),
5a73eab
 	      grub_errno = GRUB_ERR_NONE;
5a73eab
 	      t = 0;
5a73eab
 	    }
5a73eab
-	  pack->ident = grub_cpu_to_be32 (t);
5a73eab
+	  pack->xid = grub_cpu_to_be32 (t);
5a73eab
+	  ifaces[j].dhcp_xid = pack->xid;
5a73eab
 	  pack->seconds = grub_cpu_to_be16 (t);
5a73eab
 
5a73eab
 	  grub_memcpy (&pack->mac_addr, &ifaces[j].hwaddress.mac, 6); 
5a73eab
diff --git a/grub-core/net/ip.c b/grub-core/net/ip.c
5a73eab
index 7c95cc7464a..8411e0ecca3 100644
5a73eab
--- a/grub-core/net/ip.c
5a73eab
+++ b/grub-core/net/ip.c
5a73eab
@@ -275,6 +275,7 @@ handle_dgram (struct grub_net_buff *nb,
5a73eab
 	FOR_NET_NETWORK_LEVEL_INTERFACES (inf)
5a73eab
 	  if (inf->card == card
5a73eab
 	      && inf->address.type == GRUB_NET_NETWORK_LEVEL_PROTOCOL_DHCP_RECV
5a73eab
+	      && inf->dhcp_xid == bootp->xid
5a73eab
 	      && inf->hwaddress.type == GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET
5a73eab
 	      && grub_memcmp (inf->hwaddress.mac, &bootp->mac_addr,
5a73eab
 			      sizeof (inf->hwaddress.mac)) == 0)
5a73eab
diff --git a/include/grub/net.h b/include/grub/net.h
5a73eab
index f8f3ec13acc..de51894cbbf 100644
5a73eab
--- a/include/grub/net.h
5a73eab
+++ b/include/grub/net.h
5a73eab
@@ -292,6 +292,7 @@ struct grub_net_network_level_interface
5a73eab
   struct grub_net_bootp_packet *dhcp_ack;
5a73eab
   grub_size_t dhcp_acklen;
5a73eab
   grub_uint16_t vlantag;
5a73eab
+  grub_uint32_t dhcp_xid;
5a73eab
   void *data;
5a73eab
 };
5a73eab
 
5a73eab
@@ -429,7 +430,7 @@ struct grub_net_bootp_packet
5a73eab
   grub_uint8_t hw_type;		/* hardware type.  */
5a73eab
   grub_uint8_t hw_len;		/* hardware addr len.  */
5a73eab
   grub_uint8_t gate_hops;	/* zero it.  */
5a73eab
-  grub_uint32_t ident;		/* random number chosen by client.  */
5a73eab
+  grub_uint32_t xid;		/* transaction id chosen by client.  */
5a73eab
   grub_uint16_t seconds;	/* seconds since did initial bootstrap.  */
5a73eab
   grub_uint16_t flags;
5a73eab
   grub_uint32_t	client_ip;