From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1aMbLe-0001Cq-8K for mharc-grub-devel@gnu.org; Fri, 22 Jan 2016 08:01:54 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36293) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aMbLa-0001Bu-FQ for grub-devel@gnu.org; Fri, 22 Jan 2016 08:01:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aMbLY-0004OA-80 for grub-devel@gnu.org; Fri, 22 Jan 2016 08:01:50 -0500 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]:33745) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aMbLX-0004Nk-SN for grub-devel@gnu.org; Fri, 22 Jan 2016 08:01:48 -0500 Received: by mail-wm0-x241.google.com with SMTP id u188so17633093wmu.0 for ; Fri, 22 Jan 2016 05:01:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-type; bh=j5neq9cbkKgj2cSjzA/xhVag7aPTSxRTwmeN1RElzpk=; b=cAsLHRWjrzwIt2vY06aV2MScovKOUV/Wjx+4kq/6MPandwnlkqc8eKcz4Daw9/ya+J WKHKxV6dBm6TvO6fFJrUC/Y9SlInQtCoVXqAmYoN4uTPFWMOK7G8KgrB2ZokuTFFl4bT kcW0OG8Ih1WllztZBKvO2dlRWCjHtMgZwzIWPEW28X15PI2v1dKo43tW9K4k2Nl2LdNZ sCkWQo1xNbx4RYxnY6aLtMe5korLnmn1bgxgaRpRqcZSaIbhYXs8Cie/MTnzb2noMhRA FBGfgimXK/0ymh/BLzA3E4XCnoTTN2121F3J5CqUsRZqI+8lMzVnQ3UyghytaOvwuzU0 ZLag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-type; bh=j5neq9cbkKgj2cSjzA/xhVag7aPTSxRTwmeN1RElzpk=; b=R7NENBA4gf3rMafLXvt2FEQ2qYTVld4M6vbPfUGg8wsapzVR1os9f0KD+rzmm84E5j p5qjj3aJUWPgeauty4iPmz+xymT/HIza18pgiOIHZ6mtOfrNwaRhQl7c2v+NG1L7Z1Lw jVziYp9I2xhOcc9P7O2q6K3LP3kQmiG2dlHoop0I/2TJgQoEMCTOMBIMHPgmlNMHIHYu Pg3BiitHXdWAJYxYADMwmZUr7UgLBKkIzfJGiDfWmCOhoDrZzXXG30L49n/R5jIJj9JO SwcxZR6xBT0erO9NJocODEnCdIeiXLeF/ZAfl9hfHBCu7/5gG/8Aut3AD3W9YyoV5a7a JXQA== X-Gm-Message-State: AG10YOQpUMz6Fmmo1NfzYoqTv663J8KAMGcb/UAWDDJIIhhf0X/al08nhMR4VYYMjBsWVQ== X-Received: by 10.28.12.140 with SMTP id 134mr3307836wmm.21.1453467707118; Fri, 22 Jan 2016 05:01:47 -0800 (PST) Received: from ?IPv6:2a02:120b:2c41:63f0:a2a8:cdff:fe64:b3b5? ([2a02:120b:2c41:63f0:a2a8:cdff:fe64:b3b5]) by smtp.gmail.com with ESMTPSA id i63sm2829692wmf.24.2016.01.22.05.01.45 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 22 Jan 2016 05:01:45 -0800 (PST) Subject: Re: [PATCH V2] net: fix ipv6 routing To: The development of GNU GRUB , kernel-team@fb.com References: <1440775489-21046-1-git-send-email-jbacik@fb.com> <55FE817B.2020307@gmail.com> From: =?UTF-8?Q?Vladimir_'=cf=86-coder/phcoder'_Serbinenko?= Message-ID: <56A22839.5030503@gmail.com> Date: Fri, 22 Jan 2016 14:01:45 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Icedove/38.5.0 MIME-Version: 1.0 In-Reply-To: <55FE817B.2020307@gmail.com> Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="HKbmqqV51KMHgso3wSN9OLIS4Pxj3MTUx" X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::241 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: Fri, 22 Jan 2016 13:01:52 -0000 This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --HKbmqqV51KMHgso3wSN9OLIS4Pxj3MTUx Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Were Andrey's comments ever adressed? Other than his comments the patch looks good. On 20.09.2015 11:50, Andrei Borzenkov wrote: > 28.08.2015 18:24, Josef Bacik =D0=BF=D0=B8=D1=88=D0=B5=D1=82: >> ipv6 routing in grub2 is broken, we cannot talk to anything outside >> our local >> network or anything that doesn't route in our global namespace. This >> patch >> fixes this by doing a couple of things >> >> 1) Read the router information off of the router advertisement. If we= >> have a >> router lifetime we need to take the source address and create a route >> from it. >> >> 2) Changes the routing stuff slightly to allow you to specify a >> gateway _and_ an >> interface. Since the router advertisements come in on the link local >> address we >> need to associate it with the global address on the card. So when we = are >> processing the router advertisement, either use the SLAAC interface we= >> create >> and add the route to that interface, or loop through the global >> addresses we >> currently have on our interface and associate it with one of those >> addresses. >> We need to have a special case here for the default route so that it >> gets used, >> we do this by setting the masksize to 0 to mean it encompasses all >> networks. >> The routing code will automatically select the best route so if there >> is a >> closer match we will use that. >> >=20 > I think this is OK; minor comments below. We probably want to augment > net_route to allow both gateway and interface as well. >=20 >> With this patch I can now talk to ipv6 addresses outside of my local >> network. >> Thanks, >> >> Signed-off-by: Josef Bacik >> --- >> V1->V2: >> -reworked the route stuff to hold an interface for gateways as well. >> -fixed the slaac stuff so the route information is separate from the >> interface >> configuration >> >> grub-core/net/bootp.c | 2 +- >> grub-core/net/drivers/ieee1275/ofnet.c | 4 +-- >> grub-core/net/icmp6.c | 63 >> +++++++++++++++++++++++++++++++++- >> grub-core/net/net.c | 40 ++++++++------------- >> include/grub/net.h | 25 +++++++++++++- >> 5 files changed, 103 insertions(+), 31 deletions(-) >> >> diff --git a/grub-core/net/bootp.c b/grub-core/net/bootp.c >> index 37d1cfa..9fc47bd 100644 >> --- a/grub-core/net/bootp.c >> +++ b/grub-core/net/bootp.c >> @@ -83,7 +83,7 @@ parse_dhcp_vendor (const char *name, const void >> *vend, int limit, int *mask) >> grub_memcpy (&gw.ipv4, ptr, sizeof (gw.ipv4)); >> rname =3D grub_xasprintf ("%s:default", name); >> if (rname) >> - grub_net_add_route_gw (rname, target, gw); >> + grub_net_add_route_gw (rname, target, gw, NULL); >> grub_free (rname); >> } >> break; >> diff --git a/grub-core/net/drivers/ieee1275/ofnet.c >> b/grub-core/net/drivers/ieee1275/ofnet.c >> index eea8e71..d238628 100644 >> --- a/grub-core/net/drivers/ieee1275/ofnet.c >> +++ b/grub-core/net/drivers/ieee1275/ofnet.c >> @@ -151,7 +151,7 @@ grub_ieee1275_parse_bootpath (const char *devpath,= >> char *bootpath, >> grub_net_network_level_address_t client_addr, gateway_addr, >> subnet_mask; >> grub_net_link_level_address_t hw_addr; >> grub_net_interface_flags_t flags =3D 0; >> - struct grub_net_network_level_interface *inter; >> + struct grub_net_network_level_interface *inter =3D NULL; >> >> hw_addr.type =3D GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET; >> >> @@ -221,7 +221,7 @@ grub_ieee1275_parse_bootpath (const char *devpath,= >> char *bootpath, >> target.ipv4.masksize =3D 0; >> rname =3D grub_xasprintf ("%s:default", ((*card)->name)); >> if (rname) >> - grub_net_add_route_gw (rname, target, gateway_addr); >> + grub_net_add_route_gw (rname, target, gateway_addr, inter); >> else >> return grub_errno; >> } >> diff --git a/grub-core/net/icmp6.c b/grub-core/net/icmp6.c >> index 7953e68..79a4a30 100644 >> --- a/grub-core/net/icmp6.c >> +++ b/grub-core/net/icmp6.c >> @@ -115,6 +115,7 @@ grub_net_recv_icmp6_packet (struct grub_net_buff *= nb, >> grub_uint8_t ttl) >> { >> struct icmp_header *icmph; >> + struct grub_net_network_level_interface *orig_inf =3D inf; >> grub_err_t err; >> grub_uint16_t checksum; >> >> @@ -345,8 +346,25 @@ grub_net_recv_icmp6_packet (struct grub_net_buff >> *nb, >> { >> grub_uint8_t *ptr; >> struct option_header *ohdr; >> + struct router_adv *radv; >> + struct grub_net_network_level_interface *route_inf =3D NULL; >> + int default_route =3D 0; >> if (icmph->code) >> break; >> + radv =3D (void *)nb->data; >> + if (grub_be_to_cpu16 (radv->router_lifetime) > 0) >=20 > This should come after grub_netbuff_pull error check to make sure we ge= t > ohis struct. >=20 >=20 >> + { >> + struct grub_net_route *route; >> + >> + FOR_NET_ROUTES (route) >> + { >> + if (!grub_memcmp (&route->gw, source, sizeof (route->gw))) >> + break; >> + } >> + if (route =3D=3D NULL) >> + default_route =3D 1; >> + } >> + >> err =3D grub_netbuff_pull (nb, sizeof (struct router_adv)); >> if (err) >> { >> @@ -413,7 +431,11 @@ grub_net_recv_icmp6_packet (struct grub_net_buff >> *nb, >> /* Update lease time if needed here once we have >> lease times. */ >> if (inf) >> - continue; >> + { >> + if (!route_inf) >> + route_inf =3D inf; >> + continue; >> + } >> >> grub_dprintf ("net", "creating slaac\n"); >> >> @@ -429,12 +451,51 @@ grub_net_recv_icmp6_packet (struct grub_net_buff= >> *nb, >> inf =3D grub_net_add_addr (name, >> card, &addr, >> &slaac->address, 0); >> + if (!route_inf) >> + route_inf =3D inf; >> grub_net_add_route (name, netaddr, inf); >> grub_free (name); >> } >> } >> } >> } >> + if (default_route) >> + { >> + char *name; >> + grub_net_network_level_netaddress_t netaddr; >> + name =3D grub_xasprintf ("default6:%s", card->name); >=20 > It is usually :, not other way round. DHCPv4 sets= > default route to card:dhcp:default. May be card:ra:default6 to indicate= > auto-configuration. >=20 >> + if (!name) >> + { >> + grub_errno =3D GRUB_ERR_NONE; >> + goto next; >> + } >> + /* Default routes take alll of the traffic, so make the mask >> huge */ > typo >=20 >> + netaddr.type =3D GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV6; >> + netaddr.ipv6.masksize =3D 0; >> + netaddr.ipv6.base[0] =3D 0; >> + netaddr.ipv6.base[1] =3D 0; >> + >> + /* May not have gotten slaac info, find a global address on t= his >> + card. */ >> + if (route_inf =3D=3D NULL) >> + { >> + FOR_NET_NETWORK_LEVEL_INTERFACES (inf) >> + { >> + if (inf->card =3D=3D card && inf !=3D orig_inf >> + && inf->address.type =3D=3D >> GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV6 >> + && grub_net_hwaddr_cmp(&inf->hwaddress, >> + &orig_inf->hwaddress) =3D=3D 0) >> + { >> + route_inf =3D inf; >> + break; >> + } >> + } >> + } >> + if (route_inf !=3D NULL) >> + grub_net_add_route_gw (name, netaddr, *source, route_inf); >> + grub_free (name); >> + } >> +next: >> if (ptr !=3D nb->tail) >> break; >> } >> diff --git a/grub-core/net/net.c b/grub-core/net/net.c >> index 21a4e94..65bea28 100644 >> --- a/grub-core/net/net.c >> +++ b/grub-core/net/net.c >> @@ -37,21 +37,6 @@ GRUB_MOD_LICENSE ("GPLv3+"); >> >> char *grub_net_default_server; >> >> -struct grub_net_route >> -{ >> - struct grub_net_route *next; >> - struct grub_net_route **prev; >> - grub_net_network_level_netaddress_t target; >> - char *name; >> - struct grub_net_network_level_protocol *prot; >> - int is_gateway; >> - union >> - { >> - struct grub_net_network_level_interface *interface; >> - grub_net_network_level_address_t gw; >> - }; >> -}; >> - >> struct grub_net_route *grub_net_routes =3D NULL; >> struct grub_net_network_level_interface >> *grub_net_network_level_interfaces =3D NULL; >> struct grub_net_card *grub_net_cards =3D NULL; >> @@ -410,14 +395,6 @@ grub_cmd_ipv6_autoconf (struct grub_command *cmd >> __attribute__ ((unused)), >> return err; >> } >> >> -static inline void >> -grub_net_route_register (struct grub_net_route *route) >> -{ >> - grub_list_push (GRUB_AS_LIST_P (&grub_net_routes), >> - GRUB_AS_LIST (route)); >> -} >> - >> -#define FOR_NET_ROUTES(var) for (var =3D grub_net_routes; var; var =3D= >> var->next) >> >> static int >> parse_ip (const char *val, grub_uint32_t *ip, const char **rest) >> @@ -524,6 +501,8 @@ match_net (const >> grub_net_network_level_netaddress_t *net, >> case GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV6: >> { >> grub_uint64_t mask[2]; >> + if (net->ipv6.masksize =3D=3D 0) >> + return 1; >> if (net->ipv6.masksize <=3D 64) >> { >> mask[0] =3D 0xffffffffffffffffULL << (64 - net->ipv6.masksiz= e); >> @@ -687,7 +666,14 @@ grub_net_route_address >> (grub_net_network_level_address_t addr, >> return GRUB_ERR_NONE; >> } >> if (depth =3D=3D 0) >> - *gateway =3D bestroute->gw; >> + { >> + *gateway =3D bestroute->gw; >> + if (bestroute->interface !=3D NULL) >> + { >> + *interf =3D bestroute->interface; >> + return GRUB_ERR_NONE; >> + } >> + } >> curtarget =3D bestroute->gw; >> } >> >> @@ -1109,7 +1095,8 @@ grub_net_add_route (const char *name, >> grub_err_t >> grub_net_add_route_gw (const char *name, >> grub_net_network_level_netaddress_t target, >> - grub_net_network_level_address_t gw) >> + grub_net_network_level_address_t gw, >> + struct grub_net_network_level_interface *inter) >=20 > This actually makes two functions rather redundant. But it is better > merge them separately. >=20 >> { >> struct grub_net_route *route; >> >> @@ -1127,6 +1114,7 @@ grub_net_add_route_gw (const char *name, >> route->target =3D target; >> route->is_gateway =3D 1; >> route->gw =3D gw; >> + route->interface =3D inter; >> >> grub_net_route_register (route); >> >> @@ -1152,7 +1140,7 @@ grub_cmd_addroute (struct grub_command *cmd >> __attribute__ ((unused)), >> err =3D grub_net_resolve_address (args[3], &gw); >> if (err) >> return err; >> - return grub_net_add_route_gw (args[0], target, gw); >> + return grub_net_add_route_gw (args[0], target, gw, NULL); >> } >> else >> { >> diff --git a/include/grub/net.h b/include/grub/net.h >> index 4571b72..a1ff519 100644 >> --- a/include/grub/net.h >> +++ b/include/grub/net.h >> @@ -192,6 +192,18 @@ typedef struct grub_net_network_level_netaddress >> }; >> } grub_net_network_level_netaddress_t; >> >> +struct grub_net_route >> +{ >> + struct grub_net_route *next; >> + struct grub_net_route **prev; >> + grub_net_network_level_netaddress_t target; >> + char *name; >> + struct grub_net_network_level_protocol *prot; >> + int is_gateway; >> + struct grub_net_network_level_interface *interface; >> + grub_net_network_level_address_t gw; >> +}; >> + >> #define FOR_PACKETS(cont,var) for (var =3D (cont).first; var; var =3D= >> var->next) >> >> static inline grub_err_t >> @@ -368,6 +380,16 @@ grub_net_card_unregister (struct grub_net_card >> *card); >> #define FOR_NET_CARDS_SAFE(var, next) for (var =3D grub_net_cards, >> next =3D (var ? var->next : 0); var; var =3D next, next =3D (var ? var= ->next >> : 0)) >> >> >> +extern struct grub_net_route *grub_net_routes; >> + >> +static inline void >> +grub_net_route_register (struct grub_net_route *route) >> +{ >> + grub_list_push (GRUB_AS_LIST_P (&grub_net_routes), >> + GRUB_AS_LIST (route)); >> +} >> + >> +#define FOR_NET_ROUTES(var) for (var =3D grub_net_routes; var; var =3D= >> var->next) >> struct grub_net_session * >> grub_net_open_tcp (char *address, grub_uint16_t port); >> >> @@ -393,7 +415,8 @@ grub_net_add_route (const char *name, >> grub_err_t >> grub_net_add_route_gw (const char *name, >> grub_net_network_level_netaddress_t target, >> - grub_net_network_level_address_t gw); >> + grub_net_network_level_address_t gw, >> + struct grub_net_network_level_interface *inter); >> >> >> #define GRUB_NET_BOOTP_MAC_ADDR_LEN 16 >> >=20 >=20 > _______________________________________________ > Grub-devel mailing list > Grub-devel@gnu.org > https://lists.gnu.org/mailman/listinfo/grub-devel --HKbmqqV51KMHgso3wSN9OLIS4Pxj3MTUx Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iF4EAREKAAYFAlaiKDkACgkQmBXlbbo5nOukOQEAoioGk+GA6+XXDm7uyd0oNnBf +BqkXBwj4RRMN9EKvlMBAKiNoN+O8273jKQbhA8nI7GKgw7RyLMv75XTNrJJzEs+ =keCK -----END PGP SIGNATURE----- --HKbmqqV51KMHgso3wSN9OLIS4Pxj3MTUx--