]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
net/dhcp: Make grub_net_process_dhcp() take an interface
authorAndrei Borzenkov <arvidjaar@gmail.com>
Thu, 7 Mar 2019 15:14:11 +0000 (15:14 +0000)
committerDaniel Kiper <daniel.kiper@oracle.com>
Tue, 12 Mar 2019 19:04:07 +0000 (20:04 +0100)
Change the interface of the function dealing with incoming BOOTP packets
to take an interface instead of a card, to allow more fine per-interface
state (timeout, handshake state) later on.

Use the opportunity to clean up the code a bit.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
grub-core/net/bootp.c
grub-core/net/ip.c
include/grub/net.h

index 1a7cd672b95e543817cebd947a5a1a7fe677f1a6..5bb5b3d271e1cf182fdec2f9a75775417d7bc4f5 100644 (file)
@@ -395,12 +395,19 @@ out:
   return err;
 }
 
+/*
+ * This is called directly from net/ip.c:handle_dgram(), because those
+ * BOOTP/DHCP packets are a bit special due to their improper
+ * sender/receiver IP fields.
+ */
 void
 grub_net_process_dhcp (struct grub_net_buff *nb,
-                      struct grub_net_card *card)
+                      struct grub_net_network_level_interface *iface)
 {
   char *name;
-  struct grub_net_network_level_interface *inf;
+  struct grub_net_card *card = iface->card;
+  const struct grub_net_bootp_packet *bp = (const struct grub_net_bootp_packet *) nb->data;
+  grub_size_t size = nb->tail - nb->data;
 
   name = grub_xasprintf ("%s:dhcp", card->name);
   if (!name)
@@ -408,23 +415,15 @@ grub_net_process_dhcp (struct grub_net_buff *nb,
       grub_print_error ();
       return;
     }
-  grub_net_configure_by_dhcp_ack (name, card,
-                                 0, (const struct grub_net_bootp_packet *) nb->data,
-                                 (nb->tail - nb->data), 0, 0, 0);
+  grub_net_configure_by_dhcp_ack (name, card, 0, bp, size, 0, 0, 0);
   grub_free (name);
   if (grub_errno)
     grub_print_error ();
   else
-    {
-      FOR_NET_NETWORK_LEVEL_INTERFACES(inf)
-       if (grub_memcmp (inf->name, card->name, grub_strlen (card->name)) == 0
-           && grub_memcmp (inf->name + grub_strlen (card->name),
-                           ":dhcp_tmp", sizeof (":dhcp_tmp") - 1) == 0)
-         {
-           grub_net_network_level_interface_unregister (inf);
-           break;
-         }
-    }
+    if (grub_memcmp (iface->name, card->name, grub_strlen (card->name)) == 0 &&
+       grub_memcmp (iface->name + grub_strlen (card->name),
+                         ":dhcp_tmp", sizeof (":dhcp_tmp") - 1) == 0)
+      grub_net_network_level_interface_unregister (iface);
 }
 
 static char
index 7c95cc7464a09af4b223c94d6653a03f0dbee062..ea5edf8f1f61f52bcb52465a2029750cde81da0f 100644 (file)
@@ -279,7 +279,7 @@ handle_dgram (struct grub_net_buff *nb,
              && grub_memcmp (inf->hwaddress.mac, &bootp->mac_addr,
                              sizeof (inf->hwaddress.mac)) == 0)
            {
-             grub_net_process_dhcp (nb, inf->card);
+             grub_net_process_dhcp (nb, inf);
              grub_netbuff_free (nb);
              return GRUB_ERR_NONE;
            }
index 0c7286bd249d5e29893b7e1c62c537a13959c53b..3f649d75399fb96e3811ddacd490be87ce2b9cf3 100644 (file)
@@ -475,7 +475,7 @@ grub_net_add_ipv4_local (struct grub_net_network_level_interface *inf,
 
 void
 grub_net_process_dhcp (struct grub_net_buff *nb,
-                      struct grub_net_card *card);
+                      struct grub_net_network_level_interface *iface);
 
 int
 grub_net_hwaddr_cmp (const grub_net_link_level_address_t *a,