From 7fbf230d79ad531e680475529191e2ec08099c7d Mon Sep 17 00:00:00 2001 From: Viacheslav Mitrofanov Date: Fri, 2 Dec 2022 12:18:07 +0300 Subject: net: tftp: Add IPv6 support for tftpboot The command tftpboot uses IPv4 by default. Add the possibility to use IPv6 instead. If an address in the command is an IPv6 address it will use IPv6 to boot or if there is a suffix -ipv6 in the end of the command it also force using IPv6. All other tftpboot features and parameters are left the same. Signed-off-by: Viacheslav Mitrofanov Reviewed-by: Ramon Fried Reviewed-by: Simon Glass --- cmd/net.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'cmd/net.c') diff --git a/cmd/net.c b/cmd/net.c index f6d9f5ea3ab..221b3525caa 100644 --- a/cmd/net.c +++ b/cmd/net.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -45,12 +46,22 @@ int do_tftpb(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) return ret; } +#if IS_ENABLED(CONFIG_IPV6) +U_BOOT_CMD( + tftpboot, 4, 1, do_tftpb, + "boot image via network using TFTP protocol\n" + "To use IPv6 add -ipv6 parameter or use IPv6 hostIPaddr framed " + "with [] brackets", + "[loadAddress] [[hostIPaddr:]bootfilename] [" USE_IP6_CMD_PARAM "]" +); +#else U_BOOT_CMD( tftpboot, 3, 1, do_tftpb, "load file via network using TFTP protocol", "[loadAddress] [[hostIPaddr:]bootfilename]" ); #endif +#endif #ifdef CONFIG_CMD_TFTPPUT static int do_tftpput(struct cmd_tbl *cmdtp, int flag, int argc, @@ -306,6 +317,17 @@ static int netboot_common(enum proto_t proto, struct cmd_tbl *cmdtp, int argc, if (s != NULL) image_load_addr = hextoul(s, NULL); + if (IS_ENABLED(CONFIG_IPV6)) { + use_ip6 = false; + + /* IPv6 parameter has to be always *last* */ + if (!strcmp(argv[argc - 1], USE_IP6_CMD_PARAM)) { + use_ip6 = true; + /* It is a hack not to break switch/case code */ + --argc; + } + } + if (parse_args(proto, argc, argv)) { bootstage_error(BOOTSTAGE_ID_NET_START); return CMD_RET_USAGE; @@ -313,6 +335,19 @@ static int netboot_common(enum proto_t proto, struct cmd_tbl *cmdtp, int argc, bootstage_mark(BOOTSTAGE_ID_NET_START); + if (IS_ENABLED(CONFIG_IPV6) && !use_ip6) { + char *s, *e; + size_t len; + + s = strchr(net_boot_file_name, '['); + e = strchr(net_boot_file_name, ']'); + if (s && e) { + len = e - s; + if (!string_to_ip6(s + 1, len - 1, &net_server_ip6)) + use_ip6 = true; + } + } + size = net_loop(proto); if (size < 0) { bootstage_error(BOOTSTAGE_ID_NET_NETLOOP_OK); -- cgit v1.2.3 From eeb0a2c6938226ee3c46fa66971da9231d64667d Mon Sep 17 00:00:00 2001 From: Viacheslav Mitrofanov Date: Fri, 2 Dec 2022 12:18:08 +0300 Subject: net: ping6: Add ping6 command 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. Series-changes: 3 - Added structures and functions descriptions - Added to ping6_receive() return value instead of void Series-changes: 4 - Fixed structures and functions description style Signed-off-by: Viacheslav Mitrofanov Reviewed-by: Ramon Fried Reviewed-by: Simon Glass --- cmd/net.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'cmd/net.c') diff --git a/cmd/net.c b/cmd/net.c index 221b3525caa..0e9f200ca97 100644 --- a/cmd/net.c +++ b/cmd/net.c @@ -403,6 +403,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], strlen(argv[1]), &net_ping_ip6)) + 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) -- cgit v1.2.3