diff mbox series

[v5,09/19] net: ipv6: Incorporate IPv6 support into u-boot net subsystem

Message ID 20221202091818.2382748-10-v.v.mitrofanov@yadro.com
State Accepted
Delegated to: Tom Rini
Headers show
Series IPv6 support | expand

Commit Message

Vyacheslav V. Mitrofanov Dec. 2, 2022, 9:18 a.m. UTC
Add net_ip6_handler (an IPv6 packet handler) into net_loop. Add
neighbor discovery mechanism into network init process. That is the
main step to run IPv6 in u-boot. Now u-boot is capable to use NDP and
handle IPv6 packets.

Signed-off-by: Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
---
 net/net.c | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

Comments

Daniel Schwierzeck Dec. 6, 2022, 2:13 a.m. UTC | #1
On 12/2/22 10:18, Viacheslav Mitrofanov wrote:
> Add net_ip6_handler (an IPv6 packet handler) into net_loop. Add
> neighbor discovery mechanism into network init process. That is the
> main step to run IPv6 in u-boot. Now u-boot is capable to use NDP and
> handle IPv6 packets.
> 
> Signed-off-by: Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>
> Reviewed-by: Ramon Fried <rfried.dev@gmail.com>
> Reviewed-by: Simon Glass <sjg@chromium.org>
> ---
>   net/net.c | 23 ++++++++++++++++++++++-
>   1 file changed, 22 insertions(+), 1 deletion(-)
> 
> diff --git a/net/net.c b/net/net.c
> index aca20e43b0..63bf962b53 100644
> --- a/net/net.c
> +++ b/net/net.c
> @@ -91,6 +91,8 @@
>   #include <image.h>
>   #include <log.h>
>   #include <net.h>
> +#include <net6.h>
> +#include <ndisc.h>
>   #include <net/fastboot.h>
>   #include <net/tftp.h>
>   #include <net/ncsi.h>
> @@ -343,8 +345,17 @@ void net_auto_load(void)
>   
>   static int net_init_loop(void)
>   {
> -	if (eth_get_dev())
> +	if (eth_get_dev()) {
>   		memcpy(net_ethaddr, eth_get_ethaddr(), 6);
> +
> +		if (IS_ENABLED(CONFIG_IPV6)) {
> +			ip6_make_lladdr(&net_link_local_ip6, net_ethaddr);
> +			if (!memcmp(&net_ip6, &net_null_addr_ip6,
> +				    sizeof(struct in6_addr)))
> +				memcpy(&net_ip6, &net_link_local_ip6,
> +				       sizeof(struct in6_addr));
> +		}
> +	}
>   	else
>   		/*
>   		 * Not ideal, but there's no way to get the actual error, and I
> @@ -385,6 +396,7 @@ int net_init(void)
>   				(i + 1) * PKTSIZE_ALIGN;
>   		}
>   		arp_init();
> +		ndisc_init();
>   		net_clear_handlers();
>   
>   		/* Only need to setup buffer pointers once. */
> @@ -589,6 +601,11 @@ restart:
>   		if (arp_timeout_check() > 0)
>   			time_start = get_timer(0);
>   
> +		if (IS_ENABLED(CONFIG_IPV6)) {
> +			if (use_ip6 && (ndisc_timeout_check() > 0))
> +				time_start = get_timer(0);
> +		}
> +
>   		/*
>   		 *	Check the ethernet for a new packet.  The ethernet
>   		 *	receive routine will process it.
> @@ -1243,6 +1260,10 @@ void net_process_received_packet(uchar *in_packet, int len)
>   	case PROT_RARP:
>   		rarp_receive(ip, len);
>   		break;
> +#endif
> +#if IS_ENABLED(CONFIG_IPV6)
> +	case PROT_IP6:
> +		net_ip6_handler(et, (struct ip6_hdr *)ip, len);
>   #endif

Coverity reports the following:

CID 430975:  Control flow issues  (MISSING_BREAK)
The case for value "34525" is not terminated by a "break" statement.


Either a 'break;' or a 'fallthrough;' is missing. It looks like 
net_ip6_handler() already handles ICMP and UDP so probably the PROT_IP 
case shouldn't be executed at all. Therefore you should add a 'break;'.


>   	case PROT_IP:
>   		debug_cond(DEBUG_NET_PKT, "Got IP\n");
Vyacheslav V. Mitrofanov Dec. 6, 2022, 5:41 a.m. UTC | #2
On Tue, 2022-12-06 at 03:13 +0100, Daniel Schwierzeck wrote:
> «Внимание! Данное письмо от внешнего адресата!»
> 
> On 12/2/22 10:18, Viacheslav Mitrofanov wrote:
> > Add net_ip6_handler (an IPv6 packet handler) into net_loop. Add
> > neighbor discovery mechanism into network init process. That is the
> > main step to run IPv6 in u-boot. Now u-boot is capable to use NDP
> > and
> > handle IPv6 packets.
> > 
> > Signed-off-by: Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>
> > Reviewed-by: Ramon Fried <rfried.dev@gmail.com>
> > Reviewed-by: Simon Glass <sjg@chromium.org>
> > ---
> >   net/net.c | 23 ++++++++++++++++++++++-
> >   1 file changed, 22 insertions(+), 1 deletion(-)
> > 
> > diff --git a/net/net.c b/net/net.c
> > index aca20e43b0..63bf962b53 100644
> > --- a/net/net.c
> > +++ b/net/net.c
> > @@ -91,6 +91,8 @@
> >   #include <image.h>
> >   #include <log.h>
> >   #include <net.h>
> > +#include <net6.h>
> > +#include <ndisc.h>
> >   #include <net/fastboot.h>
> >   #include <net/tftp.h>
> >   #include <net/ncsi.h>
> > @@ -343,8 +345,17 @@ void net_auto_load(void)
> > 
> >   static int net_init_loop(void)
> >   {
> > -     if (eth_get_dev())
> > +     if (eth_get_dev()) {
> >               memcpy(net_ethaddr, eth_get_ethaddr(), 6);
> > +
> > +             if (IS_ENABLED(CONFIG_IPV6)) {
> > +                     ip6_make_lladdr(&net_link_local_ip6,
> > net_ethaddr);
> > +                     if (!memcmp(&net_ip6, &net_null_addr_ip6,
> > +                                 sizeof(struct in6_addr)))
> > +                             memcpy(&net_ip6, &net_link_local_ip6,
> > +                                    sizeof(struct in6_addr));
> > +             }
> > +     }
> >       else
> >               /*
> >                * Not ideal, but there's no way to get the actual
> > error, and I
> > @@ -385,6 +396,7 @@ int net_init(void)
> >                               (i + 1) * PKTSIZE_ALIGN;
> >               }
> >               arp_init();
> > +             ndisc_init();
> >               net_clear_handlers();
> > 
> >               /* Only need to setup buffer pointers once. */
> > @@ -589,6 +601,11 @@ restart:
> >               if (arp_timeout_check() > 0)
> >                       time_start = get_timer(0);
> > 
> > +             if (IS_ENABLED(CONFIG_IPV6)) {
> > +                     if (use_ip6 && (ndisc_timeout_check() > 0))
> > +                             time_start = get_timer(0);
> > +             }
> > +
> >               /*
> >                *      Check the ethernet for a new packet.  The
> > ethernet
> >                *      receive routine will process it.
> > @@ -1243,6 +1260,10 @@ void net_process_received_packet(uchar
> > *in_packet, int len)
> >       case PROT_RARP:
> >               rarp_receive(ip, len);
> >               break;
> > +#endif
> > +#if IS_ENABLED(CONFIG_IPV6)
> > +     case PROT_IP6:
> > +             net_ip6_handler(et, (struct ip6_hdr *)ip, len);
> >   #endif
> 
> Coverity reports the following:
> 
> CID 430975:  Control flow issues  (MISSING_BREAK)
> The case for value "34525" is not terminated by a "break" statement.
> 
> 
> Either a 'break;' or a 'fallthrough;' is missing. It looks like
> net_ip6_handler() already handles ICMP and UDP so probably the
> PROT_IP
> case shouldn't be executed at all. Therefore you should add a
> 'break;'.
> 
> 
> >       case PROT_IP:
> >               debug_cond(DEBUG_NET_PKT, "Got IP\n");
> 
> --
> - Daniel
> 
Thanks Daniel! I do agree with you. It is missed break.
diff mbox series

Patch

diff --git a/net/net.c b/net/net.c
index aca20e43b0..63bf962b53 100644
--- a/net/net.c
+++ b/net/net.c
@@ -91,6 +91,8 @@ 
 #include <image.h>
 #include <log.h>
 #include <net.h>
+#include <net6.h>
+#include <ndisc.h>
 #include <net/fastboot.h>
 #include <net/tftp.h>
 #include <net/ncsi.h>
@@ -343,8 +345,17 @@  void net_auto_load(void)
 
 static int net_init_loop(void)
 {
-	if (eth_get_dev())
+	if (eth_get_dev()) {
 		memcpy(net_ethaddr, eth_get_ethaddr(), 6);
+
+		if (IS_ENABLED(CONFIG_IPV6)) {
+			ip6_make_lladdr(&net_link_local_ip6, net_ethaddr);
+			if (!memcmp(&net_ip6, &net_null_addr_ip6,
+				    sizeof(struct in6_addr)))
+				memcpy(&net_ip6, &net_link_local_ip6,
+				       sizeof(struct in6_addr));
+		}
+	}
 	else
 		/*
 		 * Not ideal, but there's no way to get the actual error, and I
@@ -385,6 +396,7 @@  int net_init(void)
 				(i + 1) * PKTSIZE_ALIGN;
 		}
 		arp_init();
+		ndisc_init();
 		net_clear_handlers();
 
 		/* Only need to setup buffer pointers once. */
@@ -589,6 +601,11 @@  restart:
 		if (arp_timeout_check() > 0)
 			time_start = get_timer(0);
 
+		if (IS_ENABLED(CONFIG_IPV6)) {
+			if (use_ip6 && (ndisc_timeout_check() > 0))
+				time_start = get_timer(0);
+		}
+
 		/*
 		 *	Check the ethernet for a new packet.  The ethernet
 		 *	receive routine will process it.
@@ -1243,6 +1260,10 @@  void net_process_received_packet(uchar *in_packet, int len)
 	case PROT_RARP:
 		rarp_receive(ip, len);
 		break;
+#endif
+#if IS_ENABLED(CONFIG_IPV6)
+	case PROT_IP6:
+		net_ip6_handler(et, (struct ip6_hdr *)ip, len);
 #endif
 	case PROT_IP:
 		debug_cond(DEBUG_NET_PKT, "Got IP\n");