Module Name: src Committed By: martin Date: Fri Nov 3 10:10:49 UTC 2023
Modified Files: src/sys/dev/pci/ixgbe [netbsd-10]: ixgbe.c ixv.c src/sys/net [netbsd-10]: if_ethersubr.c if_l2tp.c if_vlan.c src/tests/net/if_vlan [netbsd-10]: t_vlan.sh Log Message: Pull up following revision(s) (requested by yamaguchi in ticket #455): sys/dev/pci/ixgbe/ixgbe.c: revision 1.347 sys/net/if_l2tp.c: revision 1.49 tests/net/if_vlan/t_vlan.sh: revision 1.25 sys/net/if_vlan.c: revision 1.171 sys/net/if_ethersubr.c: revision 1.326 sys/dev/pci/ixgbe/ixv.c: revision 1.194 Use ether_bpf_mtap only when the device supports vlan harware tagging The function is bpf_mtap() for ethernet devices and *currently* it is just handling VLAN tag stripped by the hardware. l2tp(4): use ether_ifattach() to initialize ethercom Support vlan(4) over l2tp(4) Added the test for vlan over l2tp To generate a diff of this commit: cvs rdiff -u -r1.324.2.5 -r1.324.2.6 src/sys/dev/pci/ixgbe/ixgbe.c cvs rdiff -u -r1.183.4.4 -r1.183.4.5 src/sys/dev/pci/ixgbe/ixv.c cvs rdiff -u -r1.323 -r1.323.2.1 src/sys/net/if_ethersubr.c cvs rdiff -u -r1.48 -r1.48.4.1 src/sys/net/if_l2tp.c cvs rdiff -u -r1.170 -r1.170.4.1 src/sys/net/if_vlan.c cvs rdiff -u -r1.24 -r1.24.2.1 src/tests/net/if_vlan/t_vlan.sh Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/dev/pci/ixgbe/ixgbe.c diff -u src/sys/dev/pci/ixgbe/ixgbe.c:1.324.2.5 src/sys/dev/pci/ixgbe/ixgbe.c:1.324.2.6 --- src/sys/dev/pci/ixgbe/ixgbe.c:1.324.2.5 Wed Oct 18 11:53:21 2023 +++ src/sys/dev/pci/ixgbe/ixgbe.c Fri Nov 3 10:10:49 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: ixgbe.c,v 1.324.2.5 2023/10/18 11:53:21 martin Exp $ */ +/* $NetBSD: ixgbe.c,v 1.324.2.6 2023/11/03 10:10:49 martin Exp $ */ /****************************************************************************** @@ -64,7 +64,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: ixgbe.c,v 1.324.2.5 2023/10/18 11:53:21 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ixgbe.c,v 1.324.2.6 2023/11/03 10:10:49 martin Exp $"); #ifdef _KERNEL_OPT #include "opt_inet.h" @@ -1411,14 +1411,10 @@ ixgbe_setup_interface(device_t dev, stru if_initialize(ifp); sc->ipq = if_percpuq_create(&sc->osdep.ec.ec_if); - ether_ifattach(ifp, sc->hw.mac.addr); - aprint_normal_dev(dev, "Ethernet address %s\n", - ether_sprintf(sc->hw.mac.addr)); /* * We use per TX queue softint, so if_deferred_start_init() isn't * used. */ - ether_set_ifflags_cb(ec, ixgbe_ifflags_cb); sc->max_frame_size = ifp->if_mtu + ETHER_HDR_LEN + ETHER_CRC_LEN; @@ -1442,6 +1438,11 @@ ixgbe_setup_interface(device_t dev, stru /* Enable the above capabilities by default */ ec->ec_capenable = ec->ec_capabilities; + ether_ifattach(ifp, sc->hw.mac.addr); + aprint_normal_dev(dev, "Ethernet address %s\n", + ether_sprintf(sc->hw.mac.addr)); + ether_set_ifflags_cb(ec, ixgbe_ifflags_cb); + /* * Don't turn this on by default, if vlans are * created on another pseudo device (eg. lagg) Index: src/sys/dev/pci/ixgbe/ixv.c diff -u src/sys/dev/pci/ixgbe/ixv.c:1.183.4.4 src/sys/dev/pci/ixgbe/ixv.c:1.183.4.5 --- src/sys/dev/pci/ixgbe/ixv.c:1.183.4.4 Wed Oct 18 11:53:22 2023 +++ src/sys/dev/pci/ixgbe/ixv.c Fri Nov 3 10:10:49 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: ixv.c,v 1.183.4.4 2023/10/18 11:53:22 martin Exp $ */ +/* $NetBSD: ixv.c,v 1.183.4.5 2023/11/03 10:10:49 martin Exp $ */ /****************************************************************************** @@ -35,7 +35,7 @@ /*$FreeBSD: head/sys/dev/ixgbe/if_ixv.c 331224 2018-03-19 20:55:05Z erj $*/ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: ixv.c,v 1.183.4.4 2023/10/18 11:53:22 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ixv.c,v 1.183.4.5 2023/11/03 10:10:49 martin Exp $"); #ifdef _KERNEL_OPT #include "opt_inet.h" @@ -1678,14 +1678,10 @@ ixv_setup_interface(device_t dev, struct if_initialize(ifp); sc->ipq = if_percpuq_create(&sc->osdep.ec.ec_if); - ether_ifattach(ifp, sc->hw.mac.addr); - aprint_normal_dev(dev, "Ethernet address %s\n", - ether_sprintf(sc->hw.mac.addr)); /* * We use per TX queue softint, so if_deferred_start_init() isn't * used. */ - ether_set_ifflags_cb(ec, ixv_ifflags_cb); sc->max_frame_size = ifp->if_mtu + IXGBE_MTU_HDR; @@ -1709,6 +1705,11 @@ ixv_setup_interface(device_t dev, struct /* Enable the above capabilities by default */ ec->ec_capenable = ec->ec_capabilities; + ether_ifattach(ifp, sc->hw.mac.addr); + aprint_normal_dev(dev, "Ethernet address %s\n", + ether_sprintf(sc->hw.mac.addr)); + ether_set_ifflags_cb(ec, ixv_ifflags_cb); + /* Don't enable LRO by default */ #if 0 /* NetBSD doesn't support LRO yet */ Index: src/sys/net/if_ethersubr.c diff -u src/sys/net/if_ethersubr.c:1.323 src/sys/net/if_ethersubr.c:1.323.2.1 --- src/sys/net/if_ethersubr.c:1.323 Tue Nov 15 10:47:39 2022 +++ src/sys/net/if_ethersubr.c Fri Nov 3 10:10:49 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: if_ethersubr.c,v 1.323 2022/11/15 10:47:39 roy Exp $ */ +/* $NetBSD: if_ethersubr.c,v 1.323.2.1 2023/11/03 10:10:49 martin Exp $ */ /* * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. @@ -61,7 +61,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: if_ethersubr.c,v 1.323 2022/11/15 10:47:39 roy Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_ethersubr.c,v 1.323.2.1 2023/11/03 10:10:49 martin Exp $"); #ifdef _KERNEL_OPT #include "opt_inet.h" @@ -1047,7 +1047,8 @@ ether_ifattach(struct ifnet *ifp, const ifp->if_mtu = ETHERMTU; ifp->if_output = ether_output; ifp->_if_input = ether_input; - ifp->if_bpf_mtap = ether_bpf_mtap; + if (ec->ec_capabilities & ETHERCAP_VLAN_HWTAGGING) + ifp->if_bpf_mtap = ether_bpf_mtap; if (ifp->if_baudrate == 0) ifp->if_baudrate = IF_Mbps(10); /* just a default */ Index: src/sys/net/if_l2tp.c diff -u src/sys/net/if_l2tp.c:1.48 src/sys/net/if_l2tp.c:1.48.4.1 --- src/sys/net/if_l2tp.c:1.48 Sat Sep 3 02:47:59 2022 +++ src/sys/net/if_l2tp.c Fri Nov 3 10:10:49 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: if_l2tp.c,v 1.48 2022/09/03 02:47:59 thorpej Exp $ */ +/* $NetBSD: if_l2tp.c,v 1.48.4.1 2023/11/03 10:10:49 martin Exp $ */ /* * Copyright (c) 2017 Internet Initiative Japan Inc. @@ -31,7 +31,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: if_l2tp.c,v 1.48 2022/09/03 02:47:59 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_l2tp.c,v 1.48.4.1 2023/11/03 10:10:49 martin Exp $"); #ifdef _KERNEL_OPT #include "opt_inet.h" @@ -281,6 +281,12 @@ int l2tpattach0(struct l2tp_softc *sc) { + sc->l2tp_ec.ec_capabilities = 0; + sc->l2tp_ec.ec_capabilities |= ETHERCAP_VLAN_MTU; + sc->l2tp_ec.ec_capabilities |= ETHERCAP_JUMBO_MTU; + + ether_ifattach(&sc->l2tp_ec.ec_if, NULL); + sc->l2tp_ec.ec_if.if_addrlen = 0; sc->l2tp_ec.ec_if.if_mtu = L2TP_MTU; sc->l2tp_ec.ec_if.if_flags = IFF_POINTOPOINT|IFF_MULTICAST|IFF_SIMPLEX; @@ -296,23 +302,6 @@ l2tpattach0(struct l2tp_softc *sc) sc->l2tp_ec.ec_if._if_input = ether_input; IFQ_SET_READY(&sc->l2tp_ec.ec_if.if_snd); -#ifdef MBUFTRACE - struct ethercom *ec = &sc->l2tp_ec; - struct ifnet *ifp = &sc->l2tp_ec.ec_if; - - strlcpy(ec->ec_tx_mowner.mo_name, ifp->if_xname, - sizeof(ec->ec_tx_mowner.mo_name)); - strlcpy(ec->ec_tx_mowner.mo_descr, "tx", - sizeof(ec->ec_tx_mowner.mo_descr)); - strlcpy(ec->ec_rx_mowner.mo_name, ifp->if_xname, - sizeof(ec->ec_rx_mowner.mo_name)); - strlcpy(ec->ec_rx_mowner.mo_descr, "rx", - sizeof(ec->ec_rx_mowner.mo_descr)); - MOWNER_ATTACH(&ec->ec_tx_mowner); - MOWNER_ATTACH(&ec->ec_rx_mowner); - ifp->if_mowner = &ec->ec_tx_mowner; -#endif - /* XXX * It may improve performance to use if_initialize()/if_register() * so that l2tp_input() calls if_input() instead of @@ -322,7 +311,6 @@ l2tpattach0(struct l2tp_softc *sc) if_attach(&sc->l2tp_ec.ec_if); if_link_state_change(&sc->l2tp_ec.ec_if, LINK_STATE_DOWN); if_alloc_sadl(&sc->l2tp_ec.ec_if); - bpf_attach(&sc->l2tp_ec.ec_if, DLT_EN10MB, sizeof(struct ether_header)); return 0; } @@ -351,6 +339,8 @@ l2tp_clone_destroy(struct ifnet *ifp) struct l2tp_softc *sc = container_of(ifp, struct l2tp_softc, l2tp_ec.ec_if); + ether_ifdetach(ifp); + l2tp_clear_session(sc); l2tp_delete_tunnel(&sc->l2tp_ec.ec_if); /* @@ -369,8 +359,6 @@ l2tp_clone_destroy(struct ifnet *ifp) LIST_REMOVE(sc, l2tp_list); mutex_exit(&l2tp_softcs.lock); - bpf_detach(ifp); - if_detach(ifp); if_tunnel_free_ro_percpu(sc->l2tp_ro_percpu); Index: src/sys/net/if_vlan.c diff -u src/sys/net/if_vlan.c:1.170 src/sys/net/if_vlan.c:1.170.4.1 --- src/sys/net/if_vlan.c:1.170 Mon Jun 20 08:14:48 2022 +++ src/sys/net/if_vlan.c Fri Nov 3 10:10:49 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: if_vlan.c,v 1.170 2022/06/20 08:14:48 yamaguchi Exp $ */ +/* $NetBSD: if_vlan.c,v 1.170.4.1 2023/11/03 10:10:49 martin Exp $ */ /* * Copyright (c) 2000, 2001 The NetBSD Foundation, Inc. @@ -78,7 +78,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v 1.170 2022/06/20 08:14:48 yamaguchi Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v 1.170.4.1 2023/11/03 10:10:49 martin Exp $"); #ifdef _KERNEL_OPT #include "opt_inet.h" @@ -97,6 +97,7 @@ __KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v #include <sys/kauth.h> #include <sys/mutex.h> #include <sys/kmem.h> +#include <sys/cprng.h> #include <sys/cpu.h> #include <sys/pserialize.h> #include <sys/psref.h> @@ -149,6 +150,7 @@ struct ifvlan_linkmib { struct ifvlan { struct ethercom ifv_ec; + uint8_t ifv_lladdr[ETHER_ADDR_LEN]; struct ifvlan_linkmib *ifv_mib; /* * reader must use vlan_getref_linkmib() * instead of direct dereference @@ -189,6 +191,15 @@ const struct vlan_multisw vlan_ether_mul .vmsw_purgemulti = vlan_ether_purgemulti, }; +static void vlan_multi_nothing(struct ifvlan *); +static int vlan_multi_nothing_ifreq(struct ifvlan *, struct ifreq *); + +const struct vlan_multisw vlan_nothing_multisw = { + .vmsw_addmulti = vlan_multi_nothing_ifreq, + .vmsw_delmulti = vlan_multi_nothing_ifreq, + .vmsw_purgemulti = vlan_multi_nothing, +}; + static int vlan_clone_create(struct if_clone *, int); static int vlan_clone_destroy(struct ifnet *); static int vlan_config(struct ifvlan *, struct ifnet *, uint16_t); @@ -327,6 +338,9 @@ vlan_clone_create(struct if_clone *ifc, mib = kmem_zalloc(sizeof(struct ifvlan_linkmib), KM_SLEEP); ifp = &ifv->ifv_if; LIST_INIT(&ifv->ifv_mc_listhead); + cprng_fast(ifv->ifv_lladdr, sizeof(ifv->ifv_lladdr)); + ifv->ifv_lladdr[0] &= 0xFE; /* clear I/G bit */ + ifv->ifv_lladdr[0] |= 0x02; /* set G/L bit */ mib->ifvm_ifvlan = ifv; mib->ifvm_p = NULL; @@ -394,7 +408,10 @@ vlan_config(struct ifvlan *ifv, struct i struct ifvlan_linkmib *omib = NULL; struct ifvlan_linkmib *checkmib; struct psref_target *nmib_psref = NULL; + struct ethercom *ec; const uint16_t vid = EVL_VLANOFTAG(tag); + const uint8_t *lla; + u_char ifv_iftype; int error = 0; int idx; bool omib_cleanup = false; @@ -428,69 +445,79 @@ vlan_config(struct ifvlan *ifv, struct i switch (p->if_type) { case IFT_ETHER: - { - struct ethercom *ec = (void *)p; - nmib->ifvm_msw = &vlan_ether_multisw; nmib->ifvm_mintu = ETHERMIN; - error = ether_add_vlantag(p, tag, NULL); - if (error != 0) - goto done; - - if (ec->ec_capenable & ETHERCAP_VLAN_MTU) { - nmib->ifvm_mtufudge = 0; - } else { - /* - * Fudge the MTU by the encapsulation size. This - * makes us incompatible with strictly compliant - * 802.1Q implementations, but allows us to use - * the feature with other NetBSD - * implementations, which might still be useful. - */ - nmib->ifvm_mtufudge = ETHER_VLAN_ENCAP_LEN; - } - /* - * If the parent interface can do hardware-assisted - * VLAN encapsulation, then propagate its hardware- - * assisted checksumming flags and tcp segmentation - * offload. + * We inherit the parent's Ethernet address. */ - if (ec->ec_capabilities & ETHERCAP_VLAN_HWTAGGING) { - ifp->if_capabilities = p->if_capabilities & - (IFCAP_TSOv4 | IFCAP_TSOv6 | - IFCAP_CSUM_IPv4_Tx | IFCAP_CSUM_IPv4_Rx | - IFCAP_CSUM_TCPv4_Tx | IFCAP_CSUM_TCPv4_Rx | - IFCAP_CSUM_UDPv4_Tx | IFCAP_CSUM_UDPv4_Rx | - IFCAP_CSUM_TCPv6_Tx | IFCAP_CSUM_TCPv6_Rx | - IFCAP_CSUM_UDPv6_Tx | IFCAP_CSUM_UDPv6_Rx); - } + lla = CLLADDR(p->if_sadl); /* - * We inherit the parent's Ethernet address. + * Inherit the if_type from the parent. This allows us + * to participate in bridges of that type. */ - ether_ifattach(ifp, CLLADDR(p->if_sadl)); - ifp->if_hdrlen = sizeof(struct ether_vlan_header); /* XXX? */ + ifv_iftype = p->if_type; + break; + + case IFT_L2TP: + nmib->ifvm_msw = &vlan_nothing_multisw; + nmib->ifvm_mintu = ETHERMIN; + /* use random Ethernet address. */ + lla = ifv->ifv_lladdr; + ifv_iftype = IFT_ETHER; break; - } default: error = EPROTONOSUPPORT; goto done; } + error = ether_add_vlantag(p, tag, NULL); + if (error != 0) + goto done; + + ec = (struct ethercom *)p; + if (ec->ec_capenable & ETHERCAP_VLAN_MTU) { + nmib->ifvm_mtufudge = 0; + } else { + /* + * Fudge the MTU by the encapsulation size. This + * makes us incompatible with strictly compliant + * 802.1Q implementations, but allows us to use + * the feature with other NetBSD + * implementations, which might still be useful. + */ + nmib->ifvm_mtufudge = ETHER_VLAN_ENCAP_LEN; + } + + /* + * If the parent interface can do hardware-assisted + * VLAN encapsulation, then propagate its hardware- + * assisted checksumming flags and tcp segmentation + * offload. + */ + if (ec->ec_capabilities & ETHERCAP_VLAN_HWTAGGING) { + ifp->if_capabilities = p->if_capabilities & + (IFCAP_TSOv4 | IFCAP_TSOv6 | + IFCAP_CSUM_IPv4_Tx | IFCAP_CSUM_IPv4_Rx | + IFCAP_CSUM_TCPv4_Tx | IFCAP_CSUM_TCPv4_Rx | + IFCAP_CSUM_UDPv4_Tx | IFCAP_CSUM_UDPv4_Rx | + IFCAP_CSUM_TCPv6_Tx | IFCAP_CSUM_TCPv6_Rx | + IFCAP_CSUM_UDPv6_Tx | IFCAP_CSUM_UDPv6_Rx); + } + + ether_ifattach(ifp, lla); + ifp->if_hdrlen = sizeof(struct ether_vlan_header); /* XXX? */ + nmib->ifvm_p = p; nmib->ifvm_tag = vid; ifv->ifv_if.if_mtu = p->if_mtu - nmib->ifvm_mtufudge; ifv->ifv_if.if_flags = p->if_flags & (IFF_UP | IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST); - /* - * Inherit the if_type from the parent. This allows us - * to participate in bridges of that type. - */ - ifv->ifv_if.if_type = p->if_type; + /*XXX need to update the if_type in if_sadl if it is changed */ + ifv->ifv_if.if_type = ifv_iftype; PSLIST_ENTRY_INIT(ifv, ifv_hash); idx = vlan_tag_hash(vid, ifv_hash.mask); @@ -587,32 +614,26 @@ vlan_unconfig_locked(struct ifvlan *ifv, (*nmib->ifvm_msw->vmsw_purgemulti)(ifv); /* Disconnect from parent. */ - switch (p->if_type) { - case IFT_ETHER: - { - (void)ether_del_vlantag(p, nmib->ifvm_tag); - - /* XXX ether_ifdetach must not be called with IFNET_LOCK */ - ifv->ifv_stopping = true; - mutex_exit(&ifv->ifv_lock); - IFNET_UNLOCK(ifp); - ether_ifdetach(ifp); - IFNET_LOCK(ifp); - mutex_enter(&ifv->ifv_lock); - ifv->ifv_stopping = false; + KASSERT( + p->if_type == IFT_ETHER || + p->if_type == IFT_L2TP); + (void)ether_del_vlantag(p, nmib->ifvm_tag); - /* if_free_sadl must be called with IFNET_LOCK */ - if_free_sadl(ifp, 1); + /* XXX ether_ifdetach must not be called with IFNET_LOCK */ + ifv->ifv_stopping = true; + mutex_exit(&ifv->ifv_lock); + IFNET_UNLOCK(ifp); + ether_ifdetach(ifp); + IFNET_LOCK(ifp); + mutex_enter(&ifv->ifv_lock); + ifv->ifv_stopping = false; - /* Restore vlan_ioctl overwritten by ether_ifdetach */ - ifp->if_ioctl = vlan_ioctl; - vlan_reset_linkname(ifp); - break; - } + /* if_free_sadl must be called with IFNET_LOCK */ + if_free_sadl(ifp, 1); - default: - panic("%s: impossible", __func__); - } + /* Restore vlan_ioctl overwritten by ether_ifdetach */ + ifp->if_ioctl = vlan_ioctl; + vlan_reset_linkname(ifp); nmib->ifvm_p = NULL; ifv->ifv_if.if_mtu = 0; @@ -1190,6 +1211,18 @@ vlan_ether_purgemulti(struct ifvlan *ifv } } +static int +vlan_multi_nothing_ifreq(struct ifvlan *v __unused, struct ifreq *r __unused) +{ + /* do nothing */ + return 0; +} +static void +vlan_multi_nothing(struct ifvlan *v __unused) +{ + /* do nothing */ +} + static void vlan_start(struct ifnet *ifp) { @@ -1253,13 +1286,10 @@ vlan_start(struct ifnet *ifp) * the address family/header pointer in the pktattr. */ if (ALTQ_IS_ENABLED(&p->if_snd)) { - switch (p->if_type) { - case IFT_ETHER: - altq_etherclassify(&p->if_snd, m); - break; - default: - panic("%s: impossible (altq)", __func__); - } + KASSERT( + p->if_type == IFT_ETHER || + p->if_type == IFT_L2TP); + altq_etherclassify(&p->if_snd, m); } KERNEL_UNLOCK_ONE(NULL); #endif /* ALTQ */ @@ -1275,20 +1305,15 @@ vlan_start(struct ifnet *ifp) /* * insert the tag ourselves */ - - switch (p->if_type) { - case IFT_ETHER: - (void)ether_inject_vlantag(&m, - ETHERTYPE_VLAN, mib->ifvm_tag); - if (m == NULL) { - printf("%s: unable to inject VLAN tag", - p->if_xname); - continue; - } - break; - - default: - panic("%s: impossible", __func__); + KASSERT( + p->if_type == IFT_ETHER || + p->if_type == IFT_L2TP); + (void)ether_inject_vlantag(&m, + ETHERTYPE_VLAN, mib->ifvm_tag); + if (m == NULL) { + printf("%s: unable to inject VLAN tag", + p->if_xname); + continue; } } @@ -1376,20 +1401,16 @@ vlan_transmit(struct ifnet *ifp, struct /* * insert the tag ourselves */ - switch (p->if_type) { - case IFT_ETHER: - error = ether_inject_vlantag(&m, - ETHERTYPE_VLAN, mib->ifvm_tag); - if (error != 0) { - KASSERT(m == NULL); - printf("%s: unable to inject VLAN tag", - p->if_xname); - goto out; - } - break; - - default: - panic("%s: impossible", __func__); + KASSERT( + p->if_type == IFT_ETHER || + p->if_type == IFT_L2TP); + error = ether_inject_vlantag(&m, + ETHERTYPE_VLAN, mib->ifvm_tag); + if (error != 0) { + KASSERT(m == NULL); + printf("%s: unable to inject VLAN tag", + p->if_xname); + goto out; } } Index: src/tests/net/if_vlan/t_vlan.sh diff -u src/tests/net/if_vlan/t_vlan.sh:1.24 src/tests/net/if_vlan/t_vlan.sh:1.24.2.1 --- src/tests/net/if_vlan/t_vlan.sh:1.24 Thu Aug 19 03:27:05 2021 +++ src/tests/net/if_vlan/t_vlan.sh Fri Nov 3 10:10:49 2023 @@ -1,4 +1,4 @@ -# $NetBSD: t_vlan.sh,v 1.24 2021/08/19 03:27:05 yamaguchi Exp $ +# $NetBSD: t_vlan.sh,v 1.24.2.1 2023/11/03 10:10:49 martin Exp $ # # Copyright (c) 2016 Internet Initiative Japan Inc. # All rights reserved. @@ -1035,6 +1035,139 @@ vlan_promisc_cleanup() cleanup } +vlan_l2tp_body_common() +{ + local atf_ifconfig="atf_check -s exit:0 rump.ifconfig" + + local af=$1 + local ping_cmd="rump.ping -c 1" + local pfx=24 + local local0=$IP_LOCAL0 + local local1=$IP_LOCAL1 + local remote0=$IP_REMOTE0 + local remote1=$IP_REMOTE1 + local sysctl_param="net.inet.ip.dad_count=0" + local vid0=10 + local vid1=11 + + local l2tp_laddr=10.222.222.1 + local l2tp_lsession=1001 + local l2tp_raddr=10.222.222.2 + local l2tp_rsession=1002 + + if [ x"$af" = x"inet6" ]; then + ping_cmd="rump.ping6 -c 1" + rumplib="netinet6" + pfx=64 + local0=$IP6_LOCAL0 + local1=$IP6_LOCAL1 + remote0=$IP6_REMOTE0 + remote1=$IP6_REMOTE1 + sysctl_param="net.inet6.ip6.dad_count=0" + fi + + rump_server_add_iface $SOCK_LOCAL shmif0 $BUS + rump_server_add_iface $SOCK_LOCAL l2tp0 + rump_server_add_iface $SOCK_LOCAL vlan0 + rump_server_add_iface $SOCK_LOCAL vlan1 + + rump_server_add_iface $SOCK_REMOTE shmif0 $BUS + rump_server_add_iface $SOCK_REMOTE l2tp0 + rump_server_add_iface $SOCK_REMOTE vlan0 + rump_server_add_iface $SOCK_REMOTE vlan1 + + export RUMP_SERVER=$SOCK_LOCAL + atf_check -s exit:0 -o ignore rump.sysctl -w $sysctl_param + $atf_ifconfig shmif0 $l2tp_laddr/24 + $atf_ifconfig l2tp0 tunnel $l2tp_laddr $l2tp_raddr + $atf_ifconfig l2tp0 session $l2tp_lsession $l2tp_rsession + $atf_ifconfig l2tp0 up + + export RUMP_SERVER=$SOCK_REMOTE + atf_check -s exit:0 -o ignore rump.sysctl -w $sysctl_param + $atf_ifconfig shmif0 $l2tp_raddr/24 + $atf_ifconfig l2tp0 tunnel $l2tp_raddr $l2tp_laddr + $atf_ifconfig l2tp0 session $l2tp_rsession $l2tp_lsession + $atf_ifconfig l2tp0 up + + # configure vlans on l2tp(4) + export RUMP_SERVER=$SOCK_LOCAL + $atf_ifconfig vlan0 vlan $vid0 vlanif l2tp0 + $atf_ifconfig vlan0 $af $local0/$pfx + $atf_ifconfig vlan1 vlan $vid1 vlanif l2tp0 + $atf_ifconfig vlan1 $af $local1/$pfx + export RUMP_SERVER=$SOCK_REMOTE + $atf_ifconfig vlan0 vlan $vid0 vlanif l2tp0 + $atf_ifconfig vlan0 $af $remote0/$pfx + $atf_ifconfig vlan1 vlan $vid1 vlanif l2tp0 + $atf_ifconfig vlan1 $af $remote1/$pfx + + # test for VLAN frame transfer + export RUMP_SERVER=$SOCK_LOCAL + atf_check -s exit:0 -o ignore $ping_cmd $remote0 + atf_check -s exit:0 -o ignore $ping_cmd $remote1 + + # unconfig vlans + export RUMP_SERVER=$SOCK_LOCAL + $atf_ifconfig vlan0 -vlanif + export RUMP_SERVER=$SOCK_REMOTE + $atf_ifconfig vlan0 -vlanif + + # remove l2tp0 that has vlan1 + export RUMP_SERVER=$SOCK_LOCAL + $atf_ifconfig l2tp0 destroy + export RUMP_SERVER=$SOCK_REMOTE + $atf_ifconfig l2tp0 destroy +} + +atf_test_case vlan_l2tp cleanup +vlan_l2tp_head() +{ + + atf_set "descr" "tests of vlan(IPv4) over l2tp(IPv4)" + atf_set "require.progs" "rump_server" +} + +vlan_l2tp_body() +{ + + rump_server_start $SOCK_LOCAL vlan l2tp + rump_server_start $SOCK_REMOTE vlan l2tp + + vlan_l2tp_body_common "inet" +} + +vlan_l2tp_cleanup() +{ + + $DEBUG && dump + cleanup +} + +atf_test_case vlan_l2tp6 cleanup +vlan_l2tp6_head() +{ + + atf_set "descr" "tests of vlan(IPv6) over l2tp(IPv4)" + atf_set "require.progs" "rump_server" +} + +vlan_l2tp6_body() +{ + + rump_server_start $SOCK_LOCAL vlan l2tp netinet6 + rump_server_start $SOCK_REMOTE vlan l2tp netinet6 + + vlan_l2tp_body_common "inet6" +} + +vlan_l2tp6_cleanup() +{ + + $DEBUG && dump + cleanup +} + atf_init_test_cases() { @@ -1046,6 +1179,7 @@ atf_init_test_cases() atf_add_test_case vlan_bridge atf_add_test_case vlan_multicast atf_add_test_case vlan_promisc + atf_add_test_case vlan_l2tp atf_add_test_case vlan_create_destroy6 atf_add_test_case vlan_basic6 @@ -1054,4 +1188,5 @@ atf_init_test_cases() atf_add_test_case vlan_configs6 atf_add_test_case vlan_bridge6 atf_add_test_case vlan_multicast6 + atf_add_test_case vlan_l2tp6 }