fix ipv6 support
cover fix ipv6 support
These patches are on top of Michael Chang's bootp6 code (which we also really need so it would be great if those could go in as well). At Facebook we have ipv6 only clusters that we need to be able to provision over the network. The current grub2 support for ipv6 is broken in a few ways. The routing stuff needed to be reworked to handle talking to an ipv6 router properly. I tried to not change the code too much in order to make sure I didn't regress the ipv4 support.
There is also a patch for the efinet driver, without it we are unable to do any networking with our UEFI boxes.
I'd appreciate reviews on these patches, this is my first foray into grub2. Facebook is going to be replacing ipxe with grub2 and so we are dedicated to getting grub2 into shape in order to be used to do network based provisioning well. Thanks,
Josef
PATCH 1/3 efinet: handle get_status() properly
The EFI SNP documentation isn't super clear on the value that is returned in txbuf when calling into GetStatus. The documentation says its the pointer to the recycle buffer, but the documentation for Transmit() says that it should be the pointer to the buffer that we transmitted. On the boxes I'm using it's just a random pointer (usually 0x1). It is definitely transmitting stuff, but the get_status call is not returning the pointer to the txbuf we passed in. Looking at a few EFI implementations and other SNP drivers it seems like there is confusion everywhere on this. So since we only transmit one buffer at a time, just assume that a non-NULL txbuf means that our transmit happened properly. With this patch I can now do networking on our EFI enabled boxes. Thanks,
--- grub-core/net/drivers/efi/efinet.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-)
grub-core/net/drivers/efi/efinet.c +3 -10
@@ -47,19 +47,11 @@ send_card_buffer (struct grub_net_card *dev,if (st !=GRUB_EFI_SUCCESS )return grub_error (GRUB_ERR_IO ,N_ ("couldn't send network packet" )); -if (txbuf == dev->txbuf) +if (txbuf) { dev->txbusy =0 ;break ; } -if (txbuf) - { - st =efi_call_7 (net->transmit, net,0 , dev->last_pkt_size, - dev->txbuf,NULL ,NULL ,NULL ); -if (st !=GRUB_EFI_SUCCESS ) -return grub_error (GRUB_ERR_IO , -N_ ("couldn't send network packet" )); - }if (limit_time <grub_get_time_ms ())return grub_error (GRUB_ERR_TIMEOUT ,N_ ("couldn't send network packet" ));
@@ -84,8 +76,9 @@ send_card_buffer (struct grub_net_card *dev,we run in the GRUB_ERR_TIMEOUT case above. Perhaps a timeout in the FW has discarded the recycle buffer. */ + txbuf =NULL ; st =efi_call_3 (net->get_status, net,0 , &txbuf); - dev->txbusy = !(st ==GRUB_EFI_SUCCESS && txbuf == dev->txbuf); + dev->txbusy = !(st ==GRUB_EFI_SUCCESS && txbuf);return GRUB_ERR_NONE ; }
Signature · 1 line
1.8.5.6
PATCH 2/3 net: add local route when creating link local ipv6 interface
In reply to Josef BacikIn order to talk to link local ipv6 addresses we need to have a route out of the link local interface for this to work. Thanks,
--- grub-core/net/net.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)
grub-core/net/net.c +13 -1
@@ -297,7 +297,9 @@ grub_net_ipv6_get_link_local (struct grub_net_card *card,struct grub_net_network_level_interface *inf;char *name;char *ptr; +grub_err_t err;grub_net_network_level_address_t addr; +grub_net_network_level_netaddress_t netaddr; name =grub_malloc (grub_strlen (card->name) + GRUB_NET_MAX_STR_HWADDR_LEN
@@ -325,7 +327,17 @@ grub_net_ipv6_get_link_local (struct grub_net_card *card, ptr +=grub_strlen (ptr); } ptr =grub_stpcpy (ptr,":link" ); -return grub_net_add_addr_real (name, card, &addr, hwaddr,0 ); + inf =grub_net_add_addr_real (name, card, &addr, hwaddr,0 ); +if (!inf) +return NULL ; + netaddr.type =GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV6 ; + netaddr.ipv6.base[0 ] =grub_cpu_to_be64_compile_time (0xfe80ULL <<48 ); + netaddr.ipv6.base[1 ] =0 ; + netaddr.ipv6.masksize =64 ; + err =grub_net_add_route (name, netaddr, inf); +if (err !=GRUB_ERR_NONE ) +return NULL ; +return inf; }/* FIXME: allow to specify mac address. */
Signature · 1 line
1.8.5.6
PATCH 3/3 net: fix ipv6 routing
In reply to Josef BacikCurrently we cannot talk to ipv6 addresses outside of our local link area because we don't setup our routes properly nor do we talk to the router properly. Currently net_ipv6_autoconf adds routes for the local link prefix and ties it to the global link device. This isn't helpful at all, we completely drop the router part of the router advertisement. So instead create a "default route" flag in routes and create a new route with the local link prefix and the router source address.
The second part of this problem is that the routing code thinks in ipv4 terms, so it expects to find a route to the address we're looking for in our routing table. If we find a gateway then we just look for which interface matches the network for the gateway. This doesn't work for ipv6 since the router gives us its local link address, so the gateway will find the local link interface, instead of the global interface. So to deal with this do a few things
1) Create a new "default route" flag for any router advertisements we get when doing the ipv6 autoconf stuff. Then we create a normal gateway route with the default route flag set.
2) When looking for routes keep track of any default routes we find, and if we don't find an exact route that matches we use the default route, which will set the gateway to the router, and then we will find the local link interface that matches this router.
3) Translate the local link interface to the global link interface. We build the ip packets based on the address on the interface, and this needs to have the global address, not the local one. So loop through our interfaces until we find a global address with the same hwaddress as the local link interface and use that instead. This way we get the right addresses on our IP packets.
With this patch I can now do net_ipv6_autoconf and immediately talk to ipv6 addresses outside of my local network. Thanks,
--- grub-core/net/bootp.c | 2 +- grub-core/net/drivers/ieee1275/ofnet.c | 2 +- grub-core/net/icmp6.c | 50 ++++++++++------------ grub-core/net/net.c | 76 +++++++++++++++++++++------------- include/grub/net.h | 28 ++++++++++++- 5 files changed, 99 insertions(+), 59 deletions(-)
grub-core/net/bootp.c +1 -1
@@ -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 =grub_xasprintf ("%s:default" , name);if (rname) -grub_net_add_route_gw (rname, target, gw); +grub_net_add_route_gw (rname, target, gw,0 );grub_free (rname); }break ;
grub-core/net/drivers/ieee1275/ofnet.c +1 -1
@@ -221,7 +221,7 @@ grub_ieee1275_parse_bootpath (const char *devpath, char *bootpath, target.ipv4.masksize =0 ; rname =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,0 );else return grub_errno; }
grub-core/net/icmp6.c +23 -27
77 lines not on this page · raw message
grub-core/net/net.c +47 -29
142 lines not on this page · raw message
include/grub/net.h +27 -1
@@ -192,6 +192,22 @@ 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; +int default_route; +union + { +struct grub_net_network_level_interface *interface; +grub_net_network_level_address_t gw; + }; +}; +#define FOR_PACKETS (cont,var) for (var = (cont).first; var; var = var->next) static inline grub_err_t
@@ -368,6 +384,16 @@ grub_net_card_unregister (struct grub_net_card *card);#define FOR_NET_CARDS_SAFE (var, next) for (var = grub_net_cards, next = (var ? var->next : 0); var; var = next, next = (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 = grub_net_routes; var; var = var->next)struct grub_net_session *grub_net_open_tcp (char *address,grub_uint16_t port);
@@ -393,7 +419,7 @@ 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,int default_route);#define GRUB_NET_BOOTP_MAC_ADDR_LEN 16
Signature · 1 line
1.8.5.6
Quoted 7 lines · Josef Bacik
These patches are on top of Michael Chang's bootp6 code (which we also really need so it would be great if those could go in as well). At Facebook we have ipv6 only clusters that we need to be able to provision over the network. The current grub2 support for ipv6 is broken in a few ways. The routing stuff needed to be reworked to handle talking to an ipv6 router properly. I tried to not change the code too much in order to make sure I didn't regress the ipv4 support.
Thanks for your feedback, that's very encouraging to me. :-)
The patch is still in review and need to solve some issues addressed by Andrei. I was distracted by some other stuff later and my own server hosted virtual machine to develope and test ipv6 was accidently broken by system update of virtualization package. The major changes that cause the failure seems to be qemu changes to enable ipxe UEFI option rom which somehow did not provide ipv6 support in it's UNDI driver, along with some other issues in edk2/ovmf itself.
Anyway boop6 patches seems to be innocent to the new problem I have and can continue the work by not loading iPXE UEFI option rom from qemu. To whom who may be interested here is libvirt guest config I use to disable option rom and use edk2's network stack.
<interface type='network'>
<rom bar='off'/>
</interface>I will continue on working on the patches and follow through review for the patch set with upstream.
Thanks.
Michael
Quoted 24 lines · Michael Chang
Quoted 7 lines · Josef Bacik
These patches are on top of Michael Chang's bootp6 code (which we also really need so it would be great if those could go in as well). At Facebook we have ipv6 only clusters that we need to be able to provision over the network. The current grub2 support for ipv6 is broken in a few ways. The routing stuff needed to be reworked to handle talking to an ipv6 router properly. I tried to not change the code too much in order to make sure I didn't regress the ipv4 support.
Thanks for your feedback, that's very encouraging to me. :-)
The patch is still in review and need to solve some issues addressed by Andrei. I was distracted by some other stuff later and my own server hosted virtual machine to develope and test ipv6 was accidently broken by system update of virtualization package. The major changes that cause the failure seems to be qemu changes to enable ipxe UEFI option rom which somehow did not provide ipv6 support in it's UNDI driver, along with some other issues in edk2/ovmf itself.
Anyway boop6 patches seems to be innocent to the new problem I have and can continue the work by not loading iPXE UEFI option rom from qemu. To whom who may be interested here is libvirt guest config I use to disable option rom and use edk2's network stack.
Quoted 7 lines
<interface type='network'> <rom bar='off'/> </interface>I will continue on working on the patches and follow through review for the patch set with upstream.
That would be great, anything you post I'll pull in immediately and test on real hardware in one of our ipv6 only clusters to make sure it's still working. From my perspective none of your code has given me any problems, it pulls the dhcp information that uefi has already properly, and manually doing the bootp thing also works properly. Thanks,
Josef