[PATCH 11/17] net: ping6: Add ping6 command

Simon Glass sjg at chromium.org
Thu Sep 1 04:27:00 CEST 2022


On Tue, 30 Aug 2022 at 07:02, Viacheslav Mitrofanov
<v.v.mitrofanov at yadro.com> wrote:
>
> Implement ping6 command to ping hosts using IPv6. It works the same way as
> an ordinary ping command. There is no ICMP request so it is not possible
> to ping our host. This patch adds options in Kconfig and Makefile to
> build ping6 command.
>
> Signed-off-by: Viacheslav Mitrofanov <v.v.mitrofanov at yadro.com>
> ---
>  cmd/Kconfig    |   7 +++
>  cmd/net.c      |  26 +++++++++++
>  include/net.h  |   4 +-
>  include/net6.h |  17 +++++++
>  net/Makefile   |   1 +
>  net/net.c      |  13 ++++++
>  net/net6.c     |   4 ++
>  net/ping6.c    | 117 +++++++++++++++++++++++++++++++++++++++++++++++++
>  8 files changed, 187 insertions(+), 2 deletions(-)
>  create mode 100644 net/ping6.c
>
> diff --git a/cmd/Kconfig b/cmd/Kconfig
> index 8ea064b8d2..4c95c6fd9b 100644
> --- a/cmd/Kconfig
> +++ b/cmd/Kconfig
> @@ -1801,6 +1801,13 @@ config CMD_PING
>         help
>           Send ICMP ECHO_REQUEST to network host
>
> +config CMD_PING6
> +       bool "ping6"
> +       depends on IPV6
> +       default y if (CMD_PING && IPV6)
> +       help
> +         Send ICMPv6 ECHO_REQUEST to network host
> +
>  config CMD_CDP
>         bool "cdp"
>         help
> diff --git a/cmd/net.c b/cmd/net.c
> index 0225f9ce3e..cd24813bcd 100644
> --- a/cmd/net.c
> +++ b/cmd/net.c
> @@ -334,6 +334,32 @@ U_BOOT_CMD(
>  );
>  #endif
>
> +#if IS_ENABLED(CONFIG_CMD_PING6)
> +int do_ping6(struct cmd_tbl *cmdtp, int flag, int argc, char * const argv[])
> +{
> +       if (string_to_ip6(argv[1], &net_ping_ip6) != 0)
> +               return CMD_RET_USAGE;
> +
> +       use_ip6 = true;
> +       if (net_loop(PING6) < 0) {
> +               use_ip6 = false;
> +               printf("ping6 failed; host %pI6c is not alive\n",
> +                      &net_ping_ip6);
> +               return 1;
> +       }
> +
> +       use_ip6 = false;
> +       printf("host %pI6c is alive\n", &net_ping_ip6);
> +       return 0;
> +}
> +
> +U_BOOT_CMD(
> +       ping6,  2,      1,      do_ping6,
> +       "send ICMPv6 ECHO_REQUEST to network host",
> +       "pingAddress"
> +);
> +#endif /* CONFIG_CMD_PING6 */
> +
>  #if defined(CONFIG_CMD_CDP)
>
>  static void cdp_update_env(void)
> diff --git a/include/net.h b/include/net.h
> index c06b577808..72d32d358a 100644
> --- a/include/net.h
> +++ b/include/net.h
> @@ -559,8 +559,8 @@ extern ushort               net_native_vlan;        /* Our Native VLAN */
>  extern int             net_restart_wrap;       /* Tried all network devices */
>
>  enum proto_t {
> -       BOOTP, RARP, ARP, TFTPGET, DHCP, PING, DNS, NFS, CDP, NETCONS, SNTP,
> -       TFTPSRV, TFTPPUT, LINKLOCAL, FASTBOOT, WOL, UDP
> +       BOOTP, RARP, ARP, TFTPGET, DHCP, PING, PING6, DNS, NFS, CDP, NETCONS,
> +       SNTP, TFTPSRV, TFTPPUT, LINKLOCAL, FASTBOOT, WOL, UDP
>  };
>
>  extern char    net_boot_file_name[1024];/* Boot File name */
> diff --git a/include/net6.h b/include/net6.h
> index a7be2496d9..08d31b8197 100644
> --- a/include/net6.h
> +++ b/include/net6.h
> @@ -175,6 +175,7 @@ extern struct in6_addr net_ip6;     /* Our IPv6 addr (0 = unknown) */
>  extern struct in6_addr net_link_local_ip6;     /* Our link local IPv6 addr */
>  extern u32 net_prefix_length;  /* Our prefixlength (0 = unknown) */
>  extern struct in6_addr net_server_ip6; /* Server IPv6 addr (0 = unknown) */
> +extern struct in6_addr net_ping_ip6; /* the ipv6 address to ping */
>  extern bool use_ip6;
>
>  #if IS_ENABLED(CONFIG_IPV6)
> @@ -292,4 +293,20 @@ static inline void net_copy_ip6(void *to, const void *from)
>  }
>  #endif
>
> +#if IS_ENABLED(CONFIG_CMD_PING6)
> +/* starts a Ping6 process */
> +void ping6_start(void);
> +/* handles reception of icmpv6 echo request/reply */
> +void ping6_receive(struct ethernet_hdr *et, struct ip6_hdr *ip6, int len);

Proper comments again. Also It seems that this one can fail?

> +#else
> +static inline void ping6_start(void)
> +{
> +}
> +
> +static inline
> +void ping6_receive(struct ethernet_hdr *et, struct ip6_hdr *ip6, int len)
> +{
> +}
> +#endif /* CONFIG_CMD_PING6 */
> +

[..]

Regards,
Simon


More information about the U-Boot mailing list