samples: net: mdns_responder: Fix the VLAN support

The mdns-responder VLAN code needed updating so that correct
interfaces are in use.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
This commit is contained in:
Jukka Rissanen 2024-03-26 19:06:58 +02:00 committed by Fabio Baltieri
parent b1e31f9f7f
commit 793cd56678
3 changed files with 24 additions and 13 deletions

View file

@ -1,7 +1,7 @@
CONFIG_NET_VLAN=y
# We have one non-vlan interface and two VLAN interfaces
CONFIG_NET_VLAN_COUNT=3
CONFIG_NET_VLAN_COUNT=2
# There will be three network interfaces.

View file

@ -5,6 +5,9 @@ CONFIG_NET_IPV6=y
CONFIG_NET_IPV4=y
#CONFIG_NET_DHCPV4=y
CONFIG_NET_IF_MAX_IPV6_COUNT=3
CONFIG_NET_IF_MAX_IPV4_COUNT=3
CONFIG_NET_HOSTNAME_ENABLE=y
CONFIG_NET_HOSTNAME_UNIQUE=n
CONFIG_NET_HOSTNAME="zephyr"

View file

@ -15,14 +15,13 @@ LOG_MODULE_DECLARE(net_mdns_responder_sample, LOG_LEVEL_DBG);
struct ud {
struct net_if *first;
struct net_if *second;
struct net_if *third;
};
static void iface_cb(struct net_if *iface, void *user_data_param)
{
struct ud *user_data = user_data_param;
if (net_if_l2(iface) != &NET_L2_GET_NAME(ETHERNET)) {
if (net_if_l2(iface) != &NET_L2_GET_NAME(VIRTUAL)) {
return;
}
@ -35,15 +34,13 @@ static void iface_cb(struct net_if *iface, void *user_data_param)
user_data->second = iface;
return;
}
if (!user_data->third) {
user_data->third = iface;
return;
}
}
static int setup_iface(struct net_if *iface, const char *ipv6_addr,
const char *ipv4_addr, const char *netmask,
static int setup_iface(struct net_if *eth_iface,
struct net_if *iface,
const char *ipv6_addr,
const char *ipv4_addr,
const char *netmask,
uint16_t vlan_tag)
{
struct net_if_addr *ifaddr;
@ -51,7 +48,7 @@ static int setup_iface(struct net_if *iface, const char *ipv6_addr,
struct in6_addr addr6;
int ret;
ret = net_eth_vlan_enable(iface, vlan_tag);
ret = net_eth_vlan_enable(eth_iface, vlan_tag);
if (ret < 0) {
LOG_ERR("Cannot enable VLAN for tag %d (%d)", vlan_tag, ret);
}
@ -104,9 +101,16 @@ static int setup_iface(struct net_if *iface, const char *ipv6_addr,
int init_vlan(void)
{
struct net_if *iface;
struct ud user_data;
int ret;
iface = net_if_get_first_by_type(&NET_L2_GET_NAME(ETHERNET));
if (!iface) {
LOG_ERR("No ethernet interfaces found.");
return -ENOENT;
}
memset(&user_data, 0, sizeof(user_data));
net_if_foreach(iface_cb, &user_data);
@ -115,7 +119,7 @@ int init_vlan(void)
* create IP address for this test. But first the VLAN needs to be
* added to the interface so that IPv6 DAD can work properly.
*/
ret = setup_iface(user_data.second,
ret = setup_iface(iface, user_data.first,
CONFIG_NET_SAMPLE_IFACE2_MY_IPV6_ADDR,
CONFIG_NET_SAMPLE_IFACE2_MY_IPV4_ADDR,
CONFIG_NET_SAMPLE_IFACE2_MY_IPV4_NETMASK,
@ -124,7 +128,7 @@ int init_vlan(void)
return ret;
}
ret = setup_iface(user_data.third,
ret = setup_iface(iface, user_data.second,
CONFIG_NET_SAMPLE_IFACE3_MY_IPV6_ADDR,
CONFIG_NET_SAMPLE_IFACE3_MY_IPV4_ADDR,
CONFIG_NET_SAMPLE_IFACE3_MY_IPV4_NETMASK,
@ -133,5 +137,9 @@ int init_vlan(void)
return ret;
}
/* Bring up the VLAN interface automatically */
net_if_up(user_data.first);
net_if_up(user_data.second);
return 0;
}