From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1aTcXD-0000kT-G1 for mharc-grub-devel@gnu.org; Wed, 10 Feb 2016 16:42:51 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52235) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aTcXB-0000kJ-K9 for grub-devel@gnu.org; Wed, 10 Feb 2016 16:42:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aTcX7-0003ix-Ix for grub-devel@gnu.org; Wed, 10 Feb 2016 16:42:49 -0500 Received: from 66-220-144-178.intmgw.facebook.com ([66.220.144.178]:26616 helo=mx-out.facebook.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aTcX7-0003ir-CP for grub-devel@gnu.org; Wed, 10 Feb 2016 16:42:45 -0500 Received: from facebook.com (2401:db00:2040:5012:face:0:9:0) by mx-out.facebook.com (10.102.107.97) with ESMTP id 0d9270c4d03c11e5b7800002c99331b0-ffcef270 for ; Wed, 10 Feb 2016 13:20:05 -0800 Received: by devbig041.ash4.facebook.com (Postfix, from userid 8730) id 0AC5B45406E1; Wed, 10 Feb 2016 13:21:10 -0800 (PST) From: Josef Bacik To: grub-devel@gnu.org, kernel-team@fb.com Subject: [PATCH 13/14] bootp: don't add multiple interfaces for the same address Date: Wed, 10 Feb 2016 13:21:07 -0800 Message-Id: <1455139268-3241273-14-git-send-email-jbacik@fb.com> X-Mailer: git-send-email 1.8.1 In-Reply-To: <1455139268-3241273-1-git-send-email-jbacik@fb.com> References: <1455139268-3241273-1-git-send-email-jbacik@fb.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 66.220.144.178 Cc: Josef Bacik X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 10 Feb 2016 21:42:50 -0000 Since we can sometimes configure an interface from the dhcp packet that is still in the pxe configuration any subsequent dhcp requests could add duplicate interfaces for the same address. Fix this by checking to see if we already have an interface configured for the address we got from the server and return. Also make these functions void as nobody uses the return value. Thanks, Signed-off-by: Josef Bacik --- grub-core/net/bootp.c | 29 ++++++++++++++++++----------- include/grub/net.h | 4 ++-- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/grub-core/net/bootp.c b/grub-core/net/bootp.c index 9fc47bd..345ad7a 100644 --- a/grub-core/net/bootp.c +++ b/grub-core/net/bootp.c @@ -131,7 +131,7 @@ parse_dhcp_vendor (const char *name, const void *vend, int limit, int *mask) #define OFFSET_OF(x, y) ((grub_size_t)((grub_uint8_t *)((y)->x) - (grub_uint8_t *)(y))) -struct grub_net_network_level_interface * +void grub_net_configure_by_dhcp_ack (const char *name, struct grub_net_card *card, grub_net_interface_flags_t flags, @@ -157,6 +157,13 @@ grub_net_configure_by_dhcp_ack (const char *name, : sizeof (hwaddr.mac)); hwaddr.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET; + FOR_NET_NETWORK_LEVEL_INTERFACES (inter) + { + if (inter->card == card && + grub_net_addr_cmp (&inter->address, &addr) == 0) + return; + } + inter = grub_net_add_addr (name, card, &addr, &hwaddr, flags); #if 0 /* This is likely based on misunderstanding. gateway_ip refers to @@ -260,8 +267,6 @@ grub_net_configure_by_dhcp_ack (const char *name, } else grub_errno = GRUB_ERR_NONE; - - return inter; } struct grub_dhcpv6_option { @@ -803,7 +808,7 @@ grub_net_configure_by_dhcpv6_adv (const struct grub_net_dhcpv6_packet *v6_adv, } -struct grub_net_network_level_interface * +void grub_net_configure_by_dhcpv6_reply (const char *name, struct grub_net_card *card, grub_net_interface_flags_t flags, @@ -831,7 +836,7 @@ grub_net_configure_by_dhcpv6_reply (const char *name, if (v6->message_type != DHCPv6_REPLY) { grub_error (GRUB_ERR_IO, N_("DHCPv6 info not found")); - return NULL; + return; } your_ip = find_dhcpv6_address(v6); @@ -839,7 +844,7 @@ grub_net_configure_by_dhcpv6_reply (const char *name, if (!your_ip) { grub_error (GRUB_ERR_IO, N_("DHCPv6 address not found")); - return NULL; + return; } get_dhcpv6_dns_address (v6, &dns, &num_dns); @@ -867,6 +872,12 @@ grub_net_configure_by_dhcpv6_reply (const char *name, addr.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV6; addr.ipv6[0] = grub_get_unaligned64 (your_ip); addr.ipv6[1] = grub_get_unaligned64 (your_ip + 8); + FOR_NET_NETWORK_LEVEL_INTERFACES (inf) + { + if (inf->card == card + && grub_net_addr_cmp (&inf->address, &addr) == 0) + return; + } inf = grub_net_add_addr (name, card, &addr, &card->default_address, flags); netaddr.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV6; @@ -889,7 +900,7 @@ grub_net_configure_by_dhcpv6_reply (const char *name, { *device = grub_xasprintf ("%s,%s", proto, server_ip); if (!*device) - return NULL; + return; } if (path && boot_file) @@ -904,11 +915,7 @@ grub_net_configure_by_dhcpv6_reply (const char *name, else **path = 0; } - else - return NULL; } - - return inf; } void diff --git a/include/grub/net.h b/include/grub/net.h index 080a2d9..393ad3c 100644 --- a/include/grub/net.h +++ b/include/grub/net.h @@ -469,7 +469,7 @@ enum GRUB_NET_BOOTP_END = 0xff }; -struct grub_net_network_level_interface * +void grub_net_configure_by_dhcp_ack (const char *name, struct grub_net_card *card, grub_net_interface_flags_t flags, @@ -477,7 +477,7 @@ grub_net_configure_by_dhcp_ack (const char *name, grub_size_t size, int is_def, char **device, char **path); -struct grub_net_network_level_interface * +void grub_net_configure_by_dhcpv6_reply (const char *name, struct grub_net_card *card, grub_net_interface_flags_t flags, -- 1.8.1