1010#include <strings.h>
1111LOG_MODULE_DECLARE (net_shell );
1212
13+ #include <zephyr/sys/base64.h>
14+
1315#if defined(CONFIG_NET_L2_ETHERNET )
1416#include <zephyr/net/ethernet.h>
1517#endif
@@ -18,6 +20,7 @@ LOG_MODULE_DECLARE(net_shell);
1820#endif
1921#if defined(CONFIG_NET_L2_VIRTUAL )
2022#include <zephyr/net/virtual.h>
23+ #include <zephyr/net/virtual_mgmt.h>
2124#endif
2225#if defined(CONFIG_ETH_PHY_DRIVER )
2326#include <zephyr/net/phy.h>
@@ -156,6 +159,9 @@ static void iface_cb(struct net_if *iface, void *user_data)
156159{
157160 struct net_shell_user_data * data = user_data ;
158161 const struct shell * sh = data -> sh ;
162+ int ret ;
163+
164+ ARG_UNUSED (ret ); /* could be unused depending on config */
159165
160166#if defined(CONFIG_NET_NATIVE_IPV6 )
161167 struct net_if_ipv6_prefix * prefix ;
@@ -173,7 +179,6 @@ static void iface_cb(struct net_if *iface, void *user_data)
173179#endif
174180#if defined(CONFIG_NET_L2_ETHERNET_MGMT )
175181 struct ethernet_req_params params ;
176- int ret ;
177182#endif
178183 const char * extra ;
179184#if defined(CONFIG_NET_IP ) || defined(CONFIG_NET_L2_ETHERNET_MGMT )
@@ -257,6 +262,38 @@ static void iface_cb(struct net_if *iface, void *user_data)
257262 orig_iface );
258263 }
259264 }
265+
266+ if (IS_ENABLED (CONFIG_NET_VPN ) &&
267+ net_if_l2 (iface ) == & NET_L2_GET_NAME (VIRTUAL )) {
268+ if (net_virtual_get_iface_capabilities (iface ) & VIRTUAL_INTERFACE_VPN ) {
269+ struct virtual_interface_req_params vparams = { 0 };
270+ char public_key [NET_VIRTUAL_MAX_PUBLIC_KEY_LEN * 2 ];
271+ size_t olen ;
272+
273+ ret = net_mgmt (NET_REQUEST_VIRTUAL_INTERFACE_GET_PUBLIC_KEY ,
274+ iface , & vparams , sizeof (vparams ));
275+ if (ret < 0 ) {
276+ PR_WARNING ("Cannot get VPN public key (%d)\n" , ret );
277+ } else {
278+ bool all_zeros = true;
279+
280+ for (int i = 0 ;
281+ all_zeros && i < NET_VIRTUAL_MAX_PUBLIC_KEY_LEN ; i ++ ) {
282+ all_zeros = (vparams .public_key .data [i ] == 0 );
283+ }
284+
285+ if (all_zeros ) {
286+ PR ("Public key: <not set>\n" );
287+ } else {
288+ (void )base64_encode (public_key , sizeof (public_key ),
289+ & olen , vparams .public_key .data ,
290+ vparams .public_key .len );
291+
292+ PR ("Public key: %s\n" , public_key );
293+ }
294+ }
295+ }
296+ }
260297#endif /* CONFIG_NET_L2_VIRTUAL */
261298
262299 net_if_lock (iface );
0 commit comments