From 32ab481c23553a4560ca0a5b5347d720c5d48de3 Mon Sep 17 00:00:00 2001 From: krzysztof-cabaj Date: Thu, 27 Jul 2023 12:46:47 -0400 Subject: [PATCH] sys/shell/lwip: add gateway configuration --- sys/shell/cmds/lwip_netif.c | 41 ++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/sys/shell/cmds/lwip_netif.c b/sys/shell/cmds/lwip_netif.c index 6c3a61c24f812..9730deac9b487 100644 --- a/sys/shell/cmds/lwip_netif.c +++ b/sys/shell/cmds/lwip_netif.c @@ -31,7 +31,6 @@ #include "arch/sys_arch.h" #include -//#include "net/ipv4/addr.h" #include "net/netif.h" @@ -137,6 +136,11 @@ static void _lwip_prefix_to_subnet(int prefix, ip4_addr_t *subnet) static int _lwip_netif_add4(int argc, char **argv) { + struct netif *iface; + char *ip_ptr, *prefix_ptr = NULL; + ip4_addr_t ip, subnet, gw; + int prefix; + if(argc != 4 && argc != 6) { printf("error: invalid number of parameters\n"); @@ -144,8 +148,6 @@ static int _lwip_netif_add4(int argc, char **argv) return 1; } - struct netif *iface; - sys_lock_tcpip_core(); iface = netif_find(argv[2]); @@ -156,10 +158,7 @@ static int _lwip_netif_add4(int argc, char **argv) return 1; } - char *ip_ptr, *prefix_ptr = NULL; - ip_ptr = argv[3]; - while((*ip_ptr) != 0) { if((*ip_ptr) == '/') @@ -170,21 +169,16 @@ static int _lwip_netif_add4(int argc, char **argv) ip_ptr++; } - ip_ptr = argv[3]; if(prefix_ptr == NULL) { - printf("error: ivalid IPv4 prefix notation\n"); + printf("error: invalid IPv4 prefix notation\n"); _usage_add4(argv[0]); sys_unlock_tcpip_core(); return 1; } - ip4_addr_t ip, subnet; - - subnet.addr = 0x00ffffff; - if(inet_pton(AF_INET, ip_ptr, &ip.addr) != 1) { printf("error:invalid IPv4 address\n"); @@ -192,7 +186,7 @@ static int _lwip_netif_add4(int argc, char **argv) return 1; } - int prefix = atoi(prefix_ptr); + prefix = atoi(prefix_ptr); if( prefix < 0 || prefix > 32) { @@ -203,7 +197,26 @@ static int _lwip_netif_add4(int argc, char **argv) _lwip_prefix_to_subnet(prefix, &subnet); - netif_set_addr(iface, &ip, &subnet, NULL); + if(argc == 4) + netif_set_addr(iface, &ip, &subnet, NULL); + else + { + if(strcmp("gw", argv[4]) != 0) + { + printf("error: invalid subcommand \"%s\"\n", argv[4]); + _usage_add4(argv[0]); + sys_unlock_tcpip_core(); + return 1; + } + + if(inet_pton(AF_INET, argv[5], &gw.addr) != 1) + { + printf("error: invalid gateway address\n"); + sys_unlock_tcpip_core(); + return 1; + } + netif_set_addr(iface, &ip, &subnet, &gw); + } sys_unlock_tcpip_core(); return 0;