@@ -305,6 +305,86 @@ static int cmd_wg_del(const struct shell *sh, size_t argc, char *argv[])
305305 return 0 ;
306306}
307307
308+ #if defined(CONFIG_NET_STATISTICS_VPN ) && defined(CONFIG_NET_STATISTICS_USER_API )
309+ static void print_vpn_stats (struct net_if * iface , struct net_stats_vpn * data ,
310+ const struct shell * sh )
311+ {
312+ PR ("Statistics for VPN interface %p [%d]\n" , iface ,
313+ net_if_get_by_iface (iface ));
314+
315+ PR ("Keepalive RX : %u\n" , data -> keepalive_rx );
316+ PR ("Keepalive TX : %u\n" , data -> keepalive_tx );
317+ PR ("Peer not found : %u\n" , data -> peer_not_found );
318+ PR ("Key expired : %u\n" , data -> key_expired );
319+ PR ("Invalid packet : %u\n" , data -> invalid_packet );
320+ PR ("Invalid key : %u\n" , data -> invalid_key );
321+ PR ("Invalid packet len : %u\n" , data -> invalid_packet_len );
322+ PR ("Invalid keepalive : %u\n" , data -> invalid_keepalive );
323+ PR ("Invalid handshake : %u\n" , data -> invalid_handshake );
324+ PR ("Invalid cookie : %u\n" , data -> invalid_cookie );
325+ PR ("Invalid MIC : %u\n" , data -> invalid_mic );
326+ PR ("Invalid MAC1 : %u\n" , data -> invalid_mac1 );
327+ PR ("Invalid MAC2 : %u\n" , data -> invalid_mac2 );
328+ PR ("Decrypt failed : %u\n" , data -> decrypt_failed );
329+ PR ("Dropped RX : %u\n" , data -> drop_rx );
330+ PR ("Allocation failed : %u\n" , data -> alloc_failed );
331+ PR ("Invalid IP version : %u\n" , data -> invalid_ip_version );
332+ PR ("Invalid IP family : %u\n" , data -> invalid_ip_family );
333+ PR ("Denied IP address : %u\n" , data -> denied_ip );
334+ PR ("Replay error : %u\n" , data -> replay_error );
335+ PR ("Valid RX data pkts : %u\n" , data -> valid_rx );
336+ }
337+
338+ static void iface_cb (struct net_if * iface , void * user_data )
339+ {
340+ struct net_shell_user_data * data = user_data ;
341+ const struct shell * sh = data -> sh ;
342+ int * count = data -> user_data ;
343+
344+ if (iface && net_if_l2 (iface ) == & NET_L2_GET_NAME (VIRTUAL )) {
345+ struct net_stats_vpn vpn_data ;
346+ int ret ;
347+
348+ if (net_virtual_get_iface_capabilities (iface ) != VIRTUAL_INTERFACE_VPN ) {
349+ return ;
350+ }
351+
352+ ret = net_mgmt (NET_REQUEST_STATS_GET_VPN , iface ,
353+ & vpn_data , sizeof (vpn_data ));
354+ if (!ret ) {
355+ print_vpn_stats (iface , & vpn_data , sh );
356+ (* count )++ ;
357+ }
358+ }
359+ }
360+ #endif /* CONFIG_NET_STATISTICS_VPN && CONFIG_NET_STATISTICS_USER_API */
361+
362+ static int cmd_wg_stats (const struct shell * sh , size_t argc , char * argv [])
363+ {
364+ #if defined(CONFIG_NET_STATISTICS_VPN ) && defined(CONFIG_NET_STATISTICS_USER_API )
365+ struct net_shell_user_data user_data ;
366+ int count = 0 ;
367+
368+ ARG_UNUSED (argc );
369+ ARG_UNUSED (argv );
370+
371+ user_data .sh = sh ;
372+ user_data .user_data = & count ;
373+
374+ net_if_foreach (iface_cb , & user_data );
375+
376+ if (count == 0 ) {
377+ PR ("No connections\n" );
378+ }
379+ #else
380+ PR_INFO ("Set %s to enable %s support.\n" ,
381+ "CONFIG_NET_STATISTICS_VPN, CONFIG_NET_STATISTICS_USER_API and CONFIG_WIREGUARD" ,
382+ "Wireguard VPN statistics" );
383+ #endif /* CONFIG_NET_STATISTICS_VPN */
384+
385+ return 0 ;
386+ }
387+
308388SHELL_STATIC_SUBCMD_SET_CREATE (net_cmd_wg ,
309389 SHELL_CMD_ARG (add , NULL ,
310390 "Add a peer in order to establish a VPN connection.\n"
@@ -319,6 +399,10 @@ SHELL_STATIC_SUBCMD_SET_CREATE(net_cmd_wg,
319399 SHELL_CMD_ARG (show , NULL ,
320400 "Show information about the Wireguard VPN connections.\n" ,
321401 cmd_net_wg , 1 , 1 ),
402+ SHELL_CMD_ARG (stats , NULL ,
403+ "Show statistics information about the Wireguard VPN connections.\n"
404+ "The statistics can be reset by using the 'reset' command.\n" ,
405+ cmd_wg_stats , 1 , 1 ),
322406 SHELL_SUBCMD_SET_END
323407);
324408
0 commit comments