From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1gtc9O-0002UA-VF for mharc-grub-devel@gnu.org; Tue, 12 Feb 2019 12:47:18 -0500 Received: from eggs.gnu.org ([209.51.188.92]:53813) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gtc9M-0002SC-Pm for grub-devel@gnu.org; Tue, 12 Feb 2019 12:47:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gtc9L-0002pz-RH for grub-devel@gnu.org; Tue, 12 Feb 2019 12:47:16 -0500 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:37658 helo=foss.arm.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gtc9L-0002oM-HB for grub-devel@gnu.org; Tue, 12 Feb 2019 12:47:15 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 5D3311682; Tue, 12 Feb 2019 09:47:14 -0800 (PST) Received: from donnerap.arm.com (donnerap.cambridge.arm.com [10.1.197.44]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 074993F675; Tue, 12 Feb 2019 09:47:12 -0800 (PST) From: Andre Przywara To: Daniel Kiper Cc: Vladimir Serbinenko , Andrei Borzenkov , Daniel Kiper , Mark Rutland , grub-devel@gnu.org Subject: [PATCH v2 4/9] net: dhcp: make grub_net_process_dhcp take an interface Date: Tue, 12 Feb 2019 17:46:55 +0000 Message-Id: <20190212174700.184741-5-andre.przywara@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190212174700.184741-1-andre.przywara@arm.com> References: <20190212174700.184741-1-andre.przywara@arm.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 217.140.101.70 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Feb 2019 17:47:17 -0000 From: Andrei Borzenkov 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. Signed-off-by: Andre Przywara --- grub-core/net/bootp.c | 29 ++++++++++++++++------------- grub-core/net/ip.c | 2 +- include/grub/net.h | 2 +- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/grub-core/net/bootp.c b/grub-core/net/bootp.c index fd56de907..573398aa4 100644 --- a/grub-core/net/bootp.c +++ b/grub-core/net/bootp.c @@ -396,12 +396,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) @@ -409,22 +416,18 @@ 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); + } } } diff --git a/grub-core/net/ip.c b/grub-core/net/ip.c index 7c95cc746..ea5edf8f1 100644 --- a/grub-core/net/ip.c +++ b/grub-core/net/ip.c @@ -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; } diff --git a/include/grub/net.h b/include/grub/net.h index 0c7286bd2..3f649d753 100644 --- a/include/grub/net.h +++ b/include/grub/net.h @@ -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, -- 2.17.1