diff --git a/samples/net/lldp/prj.conf b/samples/net/lldp/prj.conf index 07b5c1b601..ca4c6835e3 100644 --- a/samples/net/lldp/prj.conf +++ b/samples/net/lldp/prj.conf @@ -18,6 +18,8 @@ CONFIG_NET_IF_UNICAST_IPV6_ADDR_COUNT=5 CONFIG_NET_IF_MCAST_IPV6_ADDR_COUNT=5 CONFIG_NET_IF_UNICAST_IPV4_ADDR_COUNT=1 CONFIG_NET_MAX_CONTEXTS=2 +CONFIG_NET_IF_MAX_IPV6_COUNT=3 +CONFIG_NET_IF_MAX_IPV4_COUNT=3 CONFIG_INIT_STACKS=y CONFIG_PRINTK=y @@ -56,11 +58,9 @@ CONFIG_NET_SAMPLE_IFACE3_VLAN_TAG=200 # Logging CONFIG_LOG=y -# VLAN settings. We will have three VLANs in this sample. -# The CONFIG_NET_VLAN_COUNT will also determine how many ethernet network -# interfaces there will be in the system. +# VLAN settings. We will have two VLANs in this sample. CONFIG_NET_VLAN=y -CONFIG_NET_VLAN_COUNT=3 +CONFIG_NET_VLAN_COUNT=2 # LLDP settings CONFIG_NET_LLDP=y diff --git a/samples/net/lldp/src/main.c b/samples/net/lldp/src/main.c index f63ab2edad..d4d90f2e43 100644 --- a/samples/net/lldp/src/main.c +++ b/samples/net/lldp/src/main.c @@ -36,14 +36,13 @@ static void set_optional_tlv(struct net_if *iface) 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) { struct ud *ud = user_data; - if (net_if_l2(iface) != &NET_L2_GET_NAME(ETHERNET)) { + if (net_if_l2(iface) != &NET_L2_GET_NAME(VIRTUAL)) { return; } @@ -56,22 +55,20 @@ static void iface_cb(struct net_if *iface, void *user_data) ud->second = iface; return; } - - if (!ud->third) { - ud->third = iface; - return; - } } -static int setup_iface(struct net_if *iface, const char *ipv6_addr, - const char *ipv4_addr, uint16_t vlan_tag) +static int setup_iface(struct net_if *eth_iface, + struct net_if *iface, + const char *ipv6_addr, + const char *ipv4_addr, + uint16_t vlan_tag) { struct net_if_addr *ifaddr; struct in_addr addr4; 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); } @@ -105,7 +102,7 @@ static int setup_iface(struct net_if *iface, const char *ipv6_addr, static struct ud ud; -static int init_vlan(void) +static int init_vlan(struct net_if *iface) { enum ethernet_hw_caps caps; int ret; @@ -114,17 +111,13 @@ static int init_vlan(void) net_if_foreach(iface_cb, &ud); - caps = net_eth_get_hw_capabilities(ud.first); + caps = net_eth_get_hw_capabilities(iface); if (!(caps & ETHERNET_HW_VLAN)) { - LOG_DBG("Interface %p does not support %s", ud.first, "VLAN"); + LOG_DBG("Interface %p does not support %s", iface, "VLAN"); return -ENOENT; } - /* This sample has two VLANs. For the second one we need to manually - * 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(ud.second, + ret = setup_iface(iface, ud.first, CONFIG_NET_SAMPLE_IFACE2_MY_IPV6_ADDR, CONFIG_NET_SAMPLE_IFACE2_MY_IPV4_ADDR, CONFIG_NET_SAMPLE_IFACE2_VLAN_TAG); @@ -132,7 +125,7 @@ static int init_vlan(void) return ret; } - ret = setup_iface(ud.third, + ret = setup_iface(iface, ud.second, CONFIG_NET_SAMPLE_IFACE3_MY_IPV6_ADDR, CONFIG_NET_SAMPLE_IFACE3_MY_IPV4_ADDR, CONFIG_NET_SAMPLE_IFACE3_VLAN_TAG); @@ -140,6 +133,10 @@ static int init_vlan(void) return ret; } + /* Bring up the VLAN interface automatically */ + net_if_up(ud.first); + net_if_up(ud.second); + return 0; } @@ -194,22 +191,29 @@ static enum net_verdict parse_lldp(struct net_if *iface, struct net_pkt *pkt) static int init_app(void) { enum ethernet_hw_caps caps; + struct net_if *iface; int ret; - ret = init_vlan(); + iface = net_if_get_first_by_type(&NET_L2_GET_NAME(ETHERNET)); + if (!iface) { + LOG_ERR("No ethernet interfaces found."); + return -ENOENT; + } + + ret = init_vlan(iface); if (ret < 0) { LOG_WRN("Cannot setup VLAN (%d)", ret); } - caps = net_eth_get_hw_capabilities(ud.first); + caps = net_eth_get_hw_capabilities(iface); if (!(caps & ETHERNET_LLDP)) { - LOG_ERR("Interface %p does not support %s", ud.first, "LLDP"); + LOG_ERR("Interface %p does not support %s", iface, "LLDP"); LOG_ERR("Cannot continue!"); return -ENOENT; } - set_optional_tlv(ud.first); - net_lldp_register_callback(ud.first, parse_lldp); + set_optional_tlv(iface); + net_lldp_register_callback(iface, parse_lldp); return 0; }