@@ -3536,6 +3536,177 @@ static int cmd_net_ipv6(const struct shell *sh, size_t argc, char *argv[])
3536
3536
return 0 ;
3537
3537
}
3538
3538
3539
+ static int cmd_net_ip6_add (const struct shell * sh , size_t argc , char * argv [])
3540
+ {
3541
+ #if defined(CONFIG_NET_NATIVE_IPV6 )
3542
+ struct net_if * iface = NULL ;
3543
+ int idx ;
3544
+ struct in6_addr addr ;
3545
+
3546
+ if (argc != 3 ) {
3547
+ PR_ERROR ("Correct usage: net ipv6 add <index> <address>\n" );
3548
+ return - EINVAL ;
3549
+ }
3550
+
3551
+ idx = get_iface_idx (sh , argv [1 ]);
3552
+ if (idx < 0 ) {
3553
+ return - ENOEXEC ;
3554
+ }
3555
+
3556
+ iface = net_if_get_by_index (idx );
3557
+ if (!iface ) {
3558
+ PR_WARNING ("No such interface in index %d\n" , idx );
3559
+ return - ENOENT ;
3560
+ }
3561
+
3562
+ if (net_addr_pton (AF_INET6 , argv [2 ], & addr )) {
3563
+ PR_ERROR ("Invalid address: %s\n" , argv [2 ]);
3564
+ return - EINVAL ;
3565
+ }
3566
+
3567
+ if (!net_if_ipv6_addr_add (iface , & addr , NET_ADDR_MANUAL , 0 )) {
3568
+ PR_ERROR ("Failed to add %s address to interface %p\n" , argv [2 ], iface );
3569
+ }
3570
+
3571
+ #else /* CONFIG_NET_NATIVE_IPV6 */
3572
+ PR_INFO ("Set %s and %s to enable native %s support.\n" ,
3573
+ "CONFIG_NET_NATIVE" , "CONFIG_NET_IPV6" , "IPv6" );
3574
+ #endif /* CONFIG_NET_NATIVE_IPV6 */
3575
+ return 0 ;
3576
+ }
3577
+
3578
+ static int cmd_net_ip6_del (const struct shell * sh , size_t argc , char * argv [])
3579
+ {
3580
+ #if defined(CONFIG_NET_NATIVE_IPV6 )
3581
+ struct net_if * iface = NULL ;
3582
+ int idx ;
3583
+ struct in6_addr addr ;
3584
+
3585
+ if (argc != 3 ) {
3586
+ PR_ERROR ("Correct usage: net ipv6 del <index> <address>\n" );
3587
+ return - EINVAL ;
3588
+ }
3589
+
3590
+ idx = get_iface_idx (sh , argv [1 ]);
3591
+ if (idx < 0 ) {
3592
+ return - ENOEXEC ;
3593
+ }
3594
+
3595
+ iface = net_if_get_by_index (idx );
3596
+ if (!iface ) {
3597
+ PR_WARNING ("No such interface in index %d\n" , idx );
3598
+ return - ENOEXEC ;
3599
+ }
3600
+
3601
+ if (net_addr_pton (AF_INET6 , argv [2 ], & addr )) {
3602
+ PR_ERROR ("Invalid address: %s\n" , argv [2 ]);
3603
+ return - EINVAL ;
3604
+ }
3605
+
3606
+ if (!net_if_ipv6_addr_rm (iface , & addr )) {
3607
+ PR_ERROR ("Failed to delete %s\n" , argv [2 ]);
3608
+ return -1 ;
3609
+ }
3610
+
3611
+ #else /* CONFIG_NET_NATIVE_IPV6 */
3612
+ PR_INFO ("Set %s and %s to enable native %s support.\n" ,
3613
+ "CONFIG_NET_NATIVE" , "CONFIG_NET_IPV6" , "IPv6" );
3614
+ #endif /* CONFIG_NET_NATIVE_IPV6 */
3615
+ return 0 ;
3616
+ }
3617
+
3618
+ static int cmd_net_ip6_route_add (const struct shell * sh , size_t argc , char * argv [])
3619
+ {
3620
+ #if defined(CONFIG_NET_NATIVE_IPV6 ) && (CONFIG_NET_ROUTE )
3621
+ struct net_if * iface = NULL ;
3622
+ int idx ;
3623
+ struct net_route_entry * route ;
3624
+ struct in6_addr gw = {0 };
3625
+ struct in6_addr prefix = {0 };
3626
+
3627
+ if (argc != 4 ) {
3628
+ PR_ERROR ("Correct usage: net route add <index> "
3629
+ "<destination> <gateway>\n" );
3630
+ return - EINVAL ;
3631
+ }
3632
+
3633
+ idx = get_iface_idx (sh , argv [1 ]);
3634
+ if (idx < 0 ) {
3635
+ return - ENOEXEC ;
3636
+ }
3637
+
3638
+ iface = net_if_get_by_index (idx );
3639
+ if (!iface ) {
3640
+ PR_WARNING ("No such interface in index %d\n" , idx );
3641
+ return - ENOEXEC ;
3642
+ }
3643
+
3644
+ if (net_addr_pton (AF_INET6 , argv [2 ], & prefix )) {
3645
+ PR_ERROR ("Invalid address: %s\n" , argv [2 ]);
3646
+ return - EINVAL ;
3647
+ }
3648
+
3649
+ if (net_addr_pton (AF_INET6 , argv [3 ], & gw )) {
3650
+ PR_ERROR ("Invalid gateway: %s\n" , argv [3 ]);
3651
+ return - EINVAL ;
3652
+ }
3653
+
3654
+ route = net_route_add (iface , & prefix , NET_IPV6_DEFAULT_PREFIX_LEN ,
3655
+ & gw , NET_IPV6_ND_INFINITE_LIFETIME ,
3656
+ NET_ROUTE_PREFERENCE_MEDIUM );
3657
+ if (route == NULL ) {
3658
+ PR_ERROR ("Failed to add route\n" );
3659
+ return - ENOEXEC ;
3660
+ }
3661
+
3662
+ #else /* CONFIG_NET_NATIVE_IPV6 && CONFIG_NET_ROUTE */
3663
+ PR_INFO ("Set %s and %s to enable native %s support."
3664
+ " And enable CONFIG_NET_ROUTE.\n" ,
3665
+ "CONFIG_NET_NATIVE" , "CONFIG_NET_IPV6" , "IPv6" );
3666
+ #endif /* CONFIG_NET_NATIVE_IPV6 && CONFIG_NET_ROUTE */
3667
+ return 0 ;
3668
+ }
3669
+
3670
+ static int cmd_net_ip6_route_del (const struct shell * sh , size_t argc , char * argv [])
3671
+ {
3672
+ #if defined(CONFIG_NET_NATIVE_IPV6 ) && (CONFIG_NET_ROUTE )
3673
+ struct net_if * iface = NULL ;
3674
+ int idx ;
3675
+ struct net_route_entry * route ;
3676
+ struct in6_addr prefix = { 0 };
3677
+
3678
+ if (argc != 3 ) {
3679
+ PR_ERROR ("Correct usage: net route del <index> <destination>\n" );
3680
+ return - EINVAL ;
3681
+ }
3682
+ idx = get_iface_idx (sh , argv [1 ]);
3683
+ if (idx < 0 ) {
3684
+ return - ENOEXEC ;
3685
+ }
3686
+
3687
+ iface = net_if_get_by_index (idx );
3688
+ if (!iface ) {
3689
+ PR_WARNING ("No such interface in index %d\n" , idx );
3690
+ return - ENOEXEC ;
3691
+ }
3692
+
3693
+ if (net_addr_pton (AF_INET6 , argv [2 ], & prefix )) {
3694
+ PR_ERROR ("Invalid address: %s\n" , argv [2 ]);
3695
+ return - EINVAL ;
3696
+ }
3697
+
3698
+ route = net_route_lookup (iface , & prefix );
3699
+ if (route ) {
3700
+ net_route_del (route );
3701
+ }
3702
+ #else /* CONFIG_NET_NATIVE_IPV6 && CONFIG_NET_ROUTE */
3703
+ PR_INFO ("Set %s and %s to enable native %s support."
3704
+ " And enable CONFIG_NET_ROUTE\n" ,
3705
+ "CONFIG_NET_NATIVE" , "CONFIG_NET_IPV6" , "IPv6" );
3706
+ #endif /* CONFIG_NET_NATIVE_IPV6 && CONFIG_NET_ROUTE */
3707
+ return 0 ;
3708
+ }
3709
+
3539
3710
#if defined(CONFIG_NET_NATIVE_IPV4 )
3540
3711
static void ip_address_lifetime_cb (struct net_if * iface , void * user_data )
3541
3712
{
@@ -6151,6 +6322,28 @@ SHELL_STATIC_SUBCMD_SET_CREATE(net_cmd_ip,
6151
6322
SHELL_SUBCMD_SET_END
6152
6323
);
6153
6324
6325
+ SHELL_STATIC_SUBCMD_SET_CREATE (net_cmd_ip6 ,
6326
+ SHELL_CMD (add , NULL ,
6327
+ "'net ipv6 add <index> <address>' adds the address to the interface." ,
6328
+ cmd_net_ip6_add ),
6329
+ SHELL_CMD (del , NULL ,
6330
+ "'net ipv6 del <index> <address>' deletes the address from the interface." ,
6331
+ cmd_net_ip6_del ),
6332
+ SHELL_SUBCMD_SET_END
6333
+ );
6334
+
6335
+ SHELL_STATIC_SUBCMD_SET_CREATE (net_cmd_route ,
6336
+ SHELL_CMD (add , NULL ,
6337
+ "'net route add <index> <destination> <gateway>'"
6338
+ " adds the route to the destination." ,
6339
+ cmd_net_ip6_route_add ),
6340
+ SHELL_CMD (del , NULL ,
6341
+ "'net route del <index> <destination>'"
6342
+ " deletes the route to the destination." ,
6343
+ cmd_net_ip6_route_del ),
6344
+ SHELL_SUBCMD_SET_END
6345
+ );
6346
+
6154
6347
SHELL_STATIC_SUBCMD_SET_CREATE (net_cmd_ppp ,
6155
6348
SHELL_CMD (ping , IFACE_PPP_DYN_CMD ,
6156
6349
"'net ppp ping <index>' sends Echo-request to PPP interface." ,
@@ -6326,7 +6519,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE(net_commands,
6326
6519
SHELL_CMD (iface , & net_cmd_iface ,
6327
6520
"Print information about network interfaces." ,
6328
6521
cmd_net_iface ),
6329
- SHELL_CMD (ipv6 , NULL ,
6522
+ SHELL_CMD (ipv6 , & net_cmd_ip6 ,
6330
6523
"Print information about IPv6 specific information and "
6331
6524
"configuration." ,
6332
6525
cmd_net_ipv6 ),
@@ -6342,7 +6535,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE(net_commands,
6342
6535
SHELL_CMD (pkt , & net_cmd_pkt , "net_pkt information." , cmd_net_pkt ),
6343
6536
SHELL_CMD (ppp , & net_cmd_ppp , "PPP information." , cmd_net_ppp_status ),
6344
6537
SHELL_CMD (resume , NULL , "Resume a network interface" , cmd_net_resume ),
6345
- SHELL_CMD (route , NULL , "Show network route." , cmd_net_route ),
6538
+ SHELL_CMD (route , & net_cmd_route , "Show network route." , cmd_net_route ),
6346
6539
SHELL_CMD (stacks , NULL , "Show network stacks information." ,
6347
6540
cmd_net_stacks ),
6348
6541
SHELL_CMD (stats , & net_cmd_stats , "Show network statistics." ,
0 commit comments