@@ -392,12 +392,13 @@ static void iface_cb(struct net_if *iface, void *user_data)
392392 continue ;
393393 }
394394
395- PR ("\t%s %s %s%s%s\n" ,
395+ PR ("\t%s %s %s%s%s%s \n" ,
396396 net_sprint_ipv6_addr (& unicast -> address .in6_addr ),
397397 addrtype2str (unicast -> addr_type ),
398398 addrstate2str (unicast -> addr_state ),
399399 unicast -> is_infinite ? " infinite" : "" ,
400- unicast -> is_mesh_local ? " meshlocal" : "" );
400+ unicast -> is_mesh_local ? " meshlocal" : "" ,
401+ unicast -> is_temporary ? " temporary" : "" );
401402 count ++ ;
402403 }
403404
@@ -453,6 +454,12 @@ static void iface_cb(struct net_if *iface, void *user_data)
453454 router -> is_infinite ? " infinite" : "" );
454455 }
455456
457+ #if defined(CONFIG_NET_IPV6_PE_ENABLE )
458+ printk ("IPv6 privacy extension : %s (preferring %s addresses)\n" ,
459+ iface -> pe_enabled ? "enabled" : "disabled" ,
460+ iface -> pe_prefer_public ? "public" : "temporary" );
461+ #endif
462+
456463 if (ipv6 ) {
457464 PR ("IPv6 hop limit : %d\n" ,
458465 ipv6 -> hop_limit );
@@ -2332,6 +2339,26 @@ static u32_t time_diff(u32_t time1, u32_t time2)
23322339 return (u32_t )abs ((s32_t )time1 - (s32_t )time2 );
23332340}
23342341
2342+ #if defined(CONFIG_NET_IPV6_PE_ENABLE )
2343+ static void ipv6_pe_filter_cb (struct in6_addr * prefix , bool is_blacklist ,
2344+ void * user_data )
2345+ {
2346+ char ipaddr [INET6_ADDRSTRLEN + 1 ];
2347+ int * count = user_data ;
2348+
2349+ net_addr_ntop (AF_INET6 , prefix , ipaddr , sizeof (ipaddr ) - 1 );
2350+
2351+ if ((* count ) == 0 ) {
2352+ printk ("IPv6 privacy extension %s list filters :\n" ,
2353+ is_blacklist ? "black" : "white" );
2354+ }
2355+
2356+ printk ("[%d] %s/64\n" , * count , ipaddr );
2357+
2358+ (* count )++ ;
2359+ }
2360+ #endif /* CONFIG_NET_IPV6_PE_ENABLE */
2361+
23352362static void address_lifetime_cb (struct net_if * iface , void * user_data )
23362363{
23372364 struct net_shell_user_data * data = user_data ;
@@ -2386,13 +2413,14 @@ static void address_lifetime_cb(struct net_if *iface, void *user_data)
23862413 "%u" , (u32_t )(remaining / 1000U ));
23872414 }
23882415
2389- PR ("%s \t%s\t%s \t%s/%d\n" ,
2416+ PR ("%s \t%s\t%s \t%s/%d%s \n" ,
23902417 addrtype2str (ipv6 -> unicast [i ].addr_type ),
23912418 addrstate2str (ipv6 -> unicast [i ].addr_state ),
23922419 remaining_str ,
23932420 net_sprint_ipv6_addr (
23942421 & ipv6 -> unicast [i ].address .in6_addr ),
2395- prefix_len );
2422+ prefix_len ,
2423+ ipv6 -> unicast [i ].is_temporary ? " (temporary)" : "" );
23962424 }
23972425}
23982426#endif /* CONFIG_NET_NATIVE_IPV6 */
@@ -2401,6 +2429,15 @@ static int cmd_net_ipv6(const struct shell *shell, size_t argc, char *argv[])
24012429{
24022430#if defined(CONFIG_NET_NATIVE_IPV6 )
24032431 struct net_shell_user_data user_data ;
2432+ int arg = 0 ;
2433+
2434+ #if defined(CONFIG_NET_IPV6_PE_ENABLE )
2435+ int ret ;
2436+ #endif
2437+
2438+ if (argc > 1 ) {
2439+ goto skip_summary ;
2440+ }
24042441#endif
24052442
24062443 PR ("IPv6 support : %s\n" ,
@@ -2440,6 +2477,20 @@ static int cmd_net_ipv6(const struct shell *shell, size_t argc, char *argv[])
24402477 "disabled" );
24412478 }
24422479
2480+ PR ("Privacy extension support : %s\n" ,
2481+ IS_ENABLED (CONFIG_NET_IPV6_PE_ENABLE ) ? "enabled" :
2482+ "disabled" );
2483+
2484+ #if defined(CONFIG_NET_IPV6_PE_ENABLE )
2485+ ret = 0 ;
2486+
2487+ net_ipv6_pe_filter_foreach (ipv6_pe_filter_cb , & ret );
2488+
2489+ PR ("Max number of IPv6 privacy extension filters "
2490+ " : %d\n" ,
2491+ CONFIG_NET_IPV6_PE_FILTER_PREFIX_COUNT );
2492+ #endif
2493+
24432494 PR ("Max number of IPv6 network interfaces "
24442495 "in the system : %d\n" ,
24452496 CONFIG_NET_IF_MAX_IPV6_COUNT );
@@ -2458,7 +2509,96 @@ static int cmd_net_ipv6(const struct shell *shell, size_t argc, char *argv[])
24582509
24592510 /* Print information about address lifetime */
24602511 net_if_foreach (address_lifetime_cb , & user_data );
2512+
2513+ if (argc <= 1 ) {
2514+ return 0 ;
2515+ }
2516+
2517+ skip_summary :
2518+
2519+ if (strcmp (argv [arg ], "pe" ) == 0 ) {
2520+ #if CONFIG_NET_IPV6_PE_FILTER_PREFIX_COUNT > 0
2521+ bool do_whitelisting = true;
2522+ struct in6_addr prefix ;
2523+ bool do_add ;
2524+
2525+ arg ++ ;
2526+
2527+ if (!argv [arg ]) {
2528+ PR ("No sub-options given. See \"help net ipv6\" "
2529+ "command for details.\n" );
2530+ return 0 ;
2531+ }
2532+
2533+ if (strcmp (argv [arg ], "add" ) == 0 ) {
2534+ arg ++ ;
2535+ do_add = true;
2536+ } else if (strcmp (argv [arg ], "del" ) == 0 ) {
2537+ arg ++ ;
2538+ do_add = false;
2539+ } else {
2540+ PR ("Unknown sub-option \"%s\"\n" , argv [arg ]);
2541+ return 0 ;
2542+ }
2543+
2544+ if (!argv [arg ]) {
2545+ PR ("No sub-options given. See \"help net ipv6\" "
2546+ "command for details.\n" );
2547+ return 0 ;
2548+ }
2549+
2550+ if (strcmp (argv [arg ], "white" ) == 0 ) {
2551+ arg ++ ;
2552+ } else if (strcmp (argv [arg ], "black" ) == 0 ) {
2553+ arg ++ ;
2554+ do_whitelisting = false;
2555+ }
2556+
2557+ if (!argv [arg ]) {
2558+ PR ("No sub-options given. See \"help net ipv6\" "
2559+ "command for details.\n" );
2560+ return 0 ;
2561+ }
2562+
2563+ ret = net_addr_pton (AF_INET6 , argv [arg ], & prefix );
2564+ if (ret < 0 ) {
2565+ PR ("Invalid prefix \"%s\"\n" , argv [arg ]);
2566+ if (strstr (argv [arg ], "/" )) {
2567+ PR ("Do not add the prefix length.\n" );
2568+ }
2569+
2570+ return 0 ;
2571+ }
2572+
2573+ if (do_add ) {
2574+ ret = net_ipv6_pe_add_filter (& prefix , !do_whitelisting );
2575+ } else {
2576+ ret = net_ipv6_pe_del_filter (& prefix );
2577+ }
2578+
2579+ if (ret < 0 ) {
2580+ PR ("Cannot %s %s %sfilter (%d)\n" ,
2581+ do_add ? "add" : "delete" ,
2582+ argv [arg ],
2583+ do_add ?
2584+ (do_whitelisting ? "whitelist " :
2585+ "blacklist " ) : "" ,
2586+ ret );
2587+ return 0 ;
2588+ }
2589+
2590+ PR ("%s %sfilter for %s\n" , do_add ? "Added" : "Deleted" ,
2591+ do_add ?
2592+ (do_whitelisting ? "whitelist " : "blacklist " ) : "" ,
2593+ argv [arg ]);
2594+ #else
2595+ PR ("IPv6 privacy extension filter support is disabled.\n" );
2596+ PR ("Set CONFIG_NET_IPV6_PE_FILTER_PREFIX_COUNT > 0 to "
2597+ "enable it.\n" );
24612598#endif
2599+ #endif /* CONFIG_NET_NATIVE_IPV6 */
2600+ return 0 ;
2601+ }
24622602
24632603 return 0 ;
24642604}
@@ -3958,6 +4098,19 @@ SHELL_STATIC_SUBCMD_SET_CREATE(net_cmd_gptp,
39584098 SHELL_SUBCMD_SET_END
39594099);
39604100
4101+ SHELL_STATIC_SUBCMD_SET_CREATE (net_cmd_ipv6 ,
4102+ SHELL_CMD (pe , NULL ,
4103+ "net ipv6 pe add [black|white] <IPv6 prefix>\n"
4104+ "Add IPv6 address to filter list. The black/white "
4105+ "parameter tells if this is white listed (accepted) or "
4106+ "black listed (declined) prefix. Default is to white list "
4107+ "the prefix.\n"
4108+ "ipv6 pe del <IPv6 prefix>\n"
4109+ "Delete IPv6 address from filter list." ,
4110+ cmd_net_ipv6 ),
4111+ SHELL_SUBCMD_SET_END
4112+ );
4113+
39614114#if !defined(NET_VLAN_MAX_COUNT )
39624115#define MAX_IFACE_COUNT NET_IF_MAX_CONFIGS
39634116#else
@@ -4231,7 +4384,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE(net_commands,
42314384 SHELL_CMD (iface , & net_cmd_iface ,
42324385 "Print information about network interfaces." ,
42334386 cmd_net_iface ),
4234- SHELL_CMD (ipv6 , NULL ,
4387+ SHELL_CMD (ipv6 , & net_cmd_ipv6 ,
42354388 "Print information about IPv6 specific information and "
42364389 "configuration." ,
42374390 cmd_net_ipv6 ),
0 commit comments