aboutsummaryrefslogtreecommitdiff
path: root/net/net.c
diff options
context:
space:
mode:
authorEhsan Mohandesi <emohandesi@linux.microsoft.com>2023-04-21 17:08:21 -0700
committerTom Rini <trini@konsulko.com>2023-05-05 17:58:52 -0400
commit6de98b60ba89fb96a3adada11a5b5406f3b3786b (patch)
tree37713f86715e19599874069861547f09037528b0 /net/net.c
parent09005c2fb288decb4010f062fdc87d0b82e57584 (diff)
net: ipv6: Add support for default gateway discovery.
In IPv6, the default gateway and prefix length are determined by receiving a router advertisement as defined in - https://www.rfc-editor.org/rfc/rfc4861. Add support for sending router solicitation (RS) and processing router advertisements (RA). If the RA has prefix info option and following conditions are met, then gatewayip6 and net_prefix_length of ip6addr env variables are initialized. These are later consumed by IPv6 code for non-local destination IP. - "Router Lifetime" != 0 - Prefix is NOT link-local prefix (0xfe80::/10) - L flag is 1 - "Valid Lifetime" != 0 Timing Parameters: - MAX_RTR_SOLICITATION_DELAY (0-1s) - RTR_SOLICITATION_INTERVAL (4s) (min retransmit delay) - MAX_RTR_SOLICITATIONS (3 RS transmissions) The functionality is enabled by CONFIG_IPV6_ROUTER_DISCOVERY and invoked automatically from net_init_loop(). Signed-off-by: Ehsan Mohandesi <emohandesi@linux.microsoft.com> Tested-by: Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>Reviewed-by: Tested-by: Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com> Reviewed-by: Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com> Tested-by: Sergei Antonov <saproj@gmail.com> Reviewed-by: Sergei Antonov <saproj@gmail.com>
Diffstat (limited to 'net/net.c')
-rw-r--r--net/net.c23
1 files changed, 21 insertions, 2 deletions
diff --git a/net/net.c b/net/net.c
index 253340f3c4..43abbac7c3 100644
--- a/net/net.c
+++ b/net/net.c
@@ -24,7 +24,7 @@
* - name of bootfile
* Next step: ARP
*
- * LINK_LOCAL:
+ * LINKLOCAL:
*
* Prerequisites: - own ethernet address
* We want: - own IP address
@@ -124,6 +124,7 @@
#include "wol.h"
#endif
#include "dhcpv6.h"
+#include "net_rand.h"
/** BOOTP EXTENTIONS **/
@@ -350,6 +351,8 @@ void net_auto_load(void)
static int net_init_loop(void)
{
+ static bool first_call = true;
+
if (eth_get_dev()) {
memcpy(net_ethaddr, eth_get_ethaddr(), 6);
@@ -369,6 +372,12 @@ static int net_init_loop(void)
*/
return -ENONET;
+ if (IS_ENABLED(CONFIG_IPV6_ROUTER_DISCOVERY))
+ if (first_call && use_ip6) {
+ first_call = false;
+ srand_mac(); /* This is for rand used in ip6_send_rs. */
+ net_loop(RS);
+ }
return 0;
}
@@ -587,6 +596,10 @@ restart:
ncsi_probe_packages();
break;
#endif
+ case RS:
+ if (IS_ENABLED(CONFIG_IPV6_ROUTER_DISCOVERY))
+ ip6_send_rs();
+ break;
default:
break;
}
@@ -684,7 +697,13 @@ restart:
x = time_handler;
time_handler = (thand_f *)0;
(*x)();
- }
+ } else if (IS_ENABLED(CONFIG_IPV6_ROUTER_DISCOVERY))
+ if (time_handler && protocol == RS)
+ if (!ip6_is_unspecified_addr(&net_gateway6) &&
+ net_prefix_length != 0) {
+ net_set_state(NETLOOP_SUCCESS);
+ net_set_timeout_handler(0, NULL);
+ }
if (net_state == NETLOOP_FAIL)
ret = net_start_again();