samples: net: echo-server: Make sure to attach to correct tunnel

If there are multiple tunnels, then use the tunnel device name
to select the correct one. Note that this tunnel is only used
for network packet capture in this sample application.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
This commit is contained in:
Jukka Rissanen 2024-03-25 12:20:21 +02:00 committed by Carles Cufí
commit 76290b052f

View file

@ -21,7 +21,9 @@ struct ud {
bool is_tunnel(struct net_if *iface) bool is_tunnel(struct net_if *iface)
{ {
if (net_if_l2(iface) == &NET_L2_GET_NAME(VIRTUAL)) { if (net_if_l2(iface) == &NET_L2_GET_NAME(VIRTUAL) &&
strncmp(net_if_get_device(iface)->name, "IP_TUNNEL0",
strlen(net_if_get_device(iface)->name)) == 0) {
return true; return true;
} }
@ -134,6 +136,11 @@ int init_tunnel(void)
net_if_foreach(iface_cb, &ud); net_if_foreach(iface_cb, &ud);
if (ud.tunnel == NULL) {
LOG_ERR("Tunnel interface not found.");
return -ENOENT;
}
ret = net_mgmt(NET_REQUEST_VIRTUAL_INTERFACE_SET_PEER_ADDRESS, ret = net_mgmt(NET_REQUEST_VIRTUAL_INTERFACE_SET_PEER_ADDRESS,
ud.tunnel, &params, sizeof(params)); ud.tunnel, &params, sizeof(params));
if (ret < 0 && ret != -ENOTSUP) { if (ret < 0 && ret != -ENOTSUP) {