samples: net: vlan: Add IPv6 prefix config to each vlan-iface
Without the IPv6-prefix set, the net_if_ipv6_addr_onlink() check will always fail. The packets with DIP in the local link will go to 'try_send' code branch, which is not expected. Signed-off-by: Shrek Wang <shrek.wang@nxp.com>
This commit is contained in:
parent
54942ec9a8
commit
1968220838
4 changed files with 28 additions and 3 deletions
|
@ -53,4 +53,12 @@ config NET_SAMPLE_IFACE3_VLAN_TAG
|
|||
Set VLAN (virtual LAN) tag (id) that is used in the sample
|
||||
application.
|
||||
|
||||
config NET_SAMPLE_IFACE_MY_IPV6_PREFIXLEN
|
||||
int "IPv6 address prefix length for the interfaces"
|
||||
default 64
|
||||
range 0 128
|
||||
help
|
||||
Set the IPv6 address prefix length (netmask) for the interfaces
|
||||
that is used in the sample application.
|
||||
|
||||
source "Kconfig.zephyr"
|
||||
|
|
|
@ -32,6 +32,9 @@ CONFIG_NET_CONFIG_NEED_IPV6=y
|
|||
CONFIG_NET_CONFIG_NEED_IPV4=y
|
||||
CONFIG_NET_CONFIG_SETTINGS=y
|
||||
|
||||
# IPv6 prefix len
|
||||
CONFIG_NET_SAMPLE_IFACE_MY_IPV6_PREFIXLEN=64
|
||||
|
||||
# First ethernet interface will use these settings
|
||||
CONFIG_NET_CONFIG_MY_IPV6_ADDR="2001:db8::1"
|
||||
CONFIG_NET_CONFIG_PEER_IPV6_ADDR="2001:db8::2"
|
||||
|
|
|
@ -42,7 +42,7 @@ static int setup_iface(struct net_if *iface, struct net_if *vlan,
|
|||
{
|
||||
struct net_if_addr *ifaddr;
|
||||
struct in_addr addr4;
|
||||
struct in6_addr addr6;
|
||||
struct in6_addr addr6, netaddr6;
|
||||
int ret;
|
||||
|
||||
ret = net_eth_vlan_enable(iface, vlan_tag);
|
||||
|
@ -63,6 +63,20 @@ static int setup_iface(struct net_if *iface, struct net_if *vlan,
|
|||
ipv6_addr, vlan);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
net_ipv6_addr_prefix_mask((uint8_t *)&addr6,
|
||||
(uint8_t *)&netaddr6,
|
||||
CONFIG_NET_SAMPLE_IFACE_MY_IPV6_PREFIXLEN);
|
||||
|
||||
if (!net_if_ipv6_prefix_add(vlan, &netaddr6,
|
||||
CONFIG_NET_SAMPLE_IFACE_MY_IPV6_PREFIXLEN,
|
||||
(uint32_t)0xffffffff)) {
|
||||
LOG_ERR("Cannot add %s with prefix_len %d to interface %p",
|
||||
ipv6_addr,
|
||||
CONFIG_NET_SAMPLE_IFACE_MY_IPV6_PREFIXLEN,
|
||||
vlan);
|
||||
return -EINVAL;
|
||||
}
|
||||
}
|
||||
|
||||
if (IS_ENABLED(CONFIG_NET_IPV4)) {
|
||||
|
|
|
@ -49,11 +49,11 @@ ip link add link ${IFACE} name ${VLAN_NAME_PREFIX}.200 type vlan id 200
|
|||
ip link set ${VLAN_NAME_PREFIX}.100 up
|
||||
ip link set ${VLAN_NAME_PREFIX}.200 up
|
||||
|
||||
ip -6 addr add ${PREFIX_1_IPV6}::2 dev ${VLAN_NAME_PREFIX}.100
|
||||
ip -6 addr add ${PREFIX_1_IPV6}::2/${PREFIXLEN_1_IPV6} dev ${VLAN_NAME_PREFIX}.100
|
||||
ip -6 route add ${PREFIX_1_IPV6}::/${PREFIXLEN_1_IPV6} \
|
||||
dev ${VLAN_NAME_PREFIX}.100
|
||||
|
||||
ip -6 addr add ${PREFIX_2_IPV6}::2 dev ${VLAN_NAME_PREFIX}.200
|
||||
ip -6 addr add ${PREFIX_2_IPV6}::2/${PREFIXLEN_2_IPV6} dev ${VLAN_NAME_PREFIX}.200
|
||||
ip -6 route add ${PREFIX_2_IPV6}::/${PREFIXLEN_2_IPV6} \
|
||||
dev ${VLAN_NAME_PREFIX}.200
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue