? mild Index: if.c =================================================================== RCS file: /cvs/src/sys/net/if.c,v retrieving revision 1.603 diff -u -p -r1.603 if.c --- if.c 12 Apr 2020 07:04:03 -0000 1.603 +++ if.c 5 May 2020 12:03:23 -0000 @@ -710,6 +710,53 @@ if_enqueue(struct ifnet *ifp, struct mbu } int +if_mtag_vif(struct ifnet *ifp, struct mbuf *m) +{ + struct m_tag *mtag = NULL; + + /* Try to limit infinite recursion through misconfiguration. */ + while ((mtag = m_tag_find(m, PACKET_TAG_GRE, mtag)) != NULL) { + if (memcmp((caddr_t)(mtag + 1), &ifp->if_index, + sizeof(ifp->if_index)) == 0) { + return (EIO); + } + } + + mtag = m_tag_get(PACKET_TAG_GRE, sizeof(ifp->if_index), M_NOWAIT); + if (mtag == NULL) + return (ENOMEM); + + memcpy((caddr_t)(mtag + 1), &ifp->if_index, sizeof(ifp->if_index)); + m_tag_prepend(m, mtag); + + return (0); +} + +int +if_venqueue(struct ifnet *ifp, struct mbuf *m) +{ + struct ifqueue *ifq = &ifp->if_snd; + int error; + + /* we assume virtual interfaces don't do multiple rings */ + KASSERT(ifp->if_nifqs == 1); + + error = if_mtag_vif(ifp, m); + if (error != 0) { + m_freem(m); + return (error); + } + + error = ifq_enqueue(ifq, m); + if (error) + return (error); + + ifq_start(ifq); + + return (0); +} + +int if_enqueue_ifq(struct ifnet *ifp, struct mbuf *m) { struct ifqueue *ifq = &ifp->if_snd; Index: if_aggr.c =================================================================== RCS file: /cvs/src/sys/net/if_aggr.c,v retrieving revision 1.29 diff -u -p -r1.29 if_aggr.c --- if_aggr.c 12 Apr 2020 06:59:54 -0000 1.29 +++ if_aggr.c 5 May 2020 12:03:23 -0000 @@ -676,6 +676,12 @@ aggr_enqueue(struct ifnet *ifp, struct m const struct aggr_map *map; int error = 0; + error = if_mtag_vif(ifp, m); + if (error != 0) { + m_freem(m); + return (error); + } + if (!ifq_is_priq(&ifp->if_snd)) return (if_enqueue_ifq(ifp, m)); Index: if_bpe.c =================================================================== RCS file: /cvs/src/sys/net/if_bpe.c,v retrieving revision 1.10 diff -u -p -r1.10 if_bpe.c --- if_bpe.c 7 Nov 2019 07:36:31 -0000 1.10 +++ if_bpe.c 5 May 2020 12:03:23 -0000 @@ -187,6 +187,7 @@ bpe_clone_create(struct if_clone *ifc, i ifp->if_softc = sc; ifp->if_hardmtu = ETHER_MAX_HARDMTU_LEN; ifp->if_ioctl = bpe_ioctl; + ifp->if_enqueue = if_venqueue; ifp->if_start = bpe_start; ifp->if_flags = IFF_BROADCAST | IFF_MULTICAST; ifp->if_xflags = IFXF_CLONED; Index: if_etherip.c =================================================================== RCS file: /cvs/src/sys/net/if_etherip.c,v retrieving revision 1.45 diff -u -p -r1.45 if_etherip.c --- if_etherip.c 23 Apr 2019 10:53:45 -0000 1.45 +++ if_etherip.c 5 May 2020 12:03:23 -0000 @@ -147,6 +147,7 @@ etherip_clone_create(struct if_clone *if ifp->if_softc = sc; ifp->if_hardmtu = ETHER_MAX_HARDMTU_LEN; ifp->if_ioctl = etherip_ioctl; + ifp->if_enqueue = if_venqueue; ifp->if_start = etherip_start; ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; ifp->if_xflags = IFXF_CLONED; Index: if_gif.c =================================================================== RCS file: /cvs/src/sys/net/if_gif.c,v retrieving revision 1.128 diff -u -p -r1.128 if_gif.c --- if_gif.c 4 Oct 2019 05:00:49 -0000 1.128 +++ if_gif.c 5 May 2020 12:03:23 -0000 @@ -390,7 +390,6 @@ int gif_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst, struct rtentry *rt) { - struct m_tag *mtag; int error = 0; if (!ISSET(ifp->if_flags, IFF_RUNNING)) { @@ -412,23 +411,9 @@ gif_output(struct ifnet *ifp, struct mbu goto drop; } - /* Try to limit infinite recursion through misconfiguration. */ - for (mtag = m_tag_find(m, PACKET_TAG_GRE, NULL); mtag; - mtag = m_tag_find(m, PACKET_TAG_GRE, mtag)) { - if (memcmp((caddr_t)(mtag + 1), &ifp->if_index, - sizeof(ifp->if_index)) == 0) { - error = EIO; - goto drop; - } - } - - mtag = m_tag_get(PACKET_TAG_GRE, sizeof(ifp->if_index), M_NOWAIT); - if (mtag == NULL) { - error = ENOBUFS; + error = if_mtag_vif(ifp, m); + if (error != 0) goto drop; - } - memcpy((caddr_t)(mtag + 1), &ifp->if_index, sizeof(ifp->if_index)); - m_tag_prepend(m, mtag); m->m_pkthdr.ph_family = dst->sa_family; Index: if_gre.c =================================================================== RCS file: /cvs/src/sys/net/if_gre.c,v retrieving revision 1.155 diff -u -p -r1.155 if_gre.c --- if_gre.c 10 Nov 2019 11:44:10 -0000 1.155 +++ if_gre.c 5 May 2020 12:03:23 -0000 @@ -713,6 +713,7 @@ egre_clone_create(struct if_clone *ifc, ifp->if_softc = sc; ifp->if_hardmtu = ETHER_MAX_HARDMTU_LEN; ifp->if_ioctl = egre_ioctl; + ifp->if_enqueue = if_venqueue; ifp->if_start = egre_start; ifp->if_xflags = IFXF_CLONED; IFQ_SET_MAXLEN(&ifp->if_snd, IFQ_MAXLEN); @@ -775,6 +776,7 @@ nvgre_clone_create(struct if_clone *ifc, ifp->if_softc = sc; ifp->if_hardmtu = ETHER_MAX_HARDMTU_LEN; ifp->if_ioctl = nvgre_ioctl; + ifp->if_enqueue = if_venqueue; ifp->if_start = nvgre_start; ifp->if_xflags = IFXF_CLONED; IFQ_SET_MAXLEN(&ifp->if_snd, IFQ_MAXLEN); @@ -847,6 +849,7 @@ eoip_clone_create(struct if_clone *ifc, ifp->if_softc = sc; ifp->if_hardmtu = ETHER_MAX_HARDMTU_LEN; ifp->if_ioctl = eoip_ioctl; + ifp->if_enqueue = if_venqueue; ifp->if_start = eoip_start; ifp->if_xflags = IFXF_CLONED; IFQ_SET_MAXLEN(&ifp->if_snd, IFQ_MAXLEN); @@ -1701,7 +1704,6 @@ static int gre_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst, struct rtentry *rt) { - struct m_tag *mtag; int error = 0; if (!gre_allow) { @@ -1728,30 +1730,13 @@ gre_output(struct ifnet *ifp, struct mbu goto drop; } - /* Try to limit infinite recursion through misconfiguration. */ - for (mtag = m_tag_find(m, PACKET_TAG_GRE, NULL); mtag; - mtag = m_tag_find(m, PACKET_TAG_GRE, mtag)) { - if (memcmp((caddr_t)(mtag + 1), &ifp->if_index, - sizeof(ifp->if_index)) == 0) { - m_freem(m); - error = EIO; - goto end; - } - } - - mtag = m_tag_get(PACKET_TAG_GRE, sizeof(ifp->if_index), M_NOWAIT); - if (mtag == NULL) { - m_freem(m); - error = ENOBUFS; - goto end; - } - memcpy((caddr_t)(mtag + 1), &ifp->if_index, sizeof(ifp->if_index)); - m_tag_prepend(m, mtag); + error = if_mtag_vif(ifp, m); + if (error != 0) + goto drop; m->m_pkthdr.ph_family = dst->sa_family; error = if_enqueue(ifp, m); -end: if (error) ifp->if_oerrors++; return (error); @@ -1838,7 +1823,6 @@ mgre_output(struct ifnet *ifp, struct mb struct mgre_softc *sc = ifp->if_softc; struct sockaddr *gate; struct rtentry *rt; - struct m_tag *mtag; int error = 0; sa_family_t af; const void *addr; @@ -1895,23 +1879,9 @@ mgre_output(struct ifnet *ifp, struct mb goto drop; } - /* Try to limit infinite recursion through misconfiguration. */ - for (mtag = m_tag_find(m, PACKET_TAG_GRE, NULL); mtag; - mtag = m_tag_find(m, PACKET_TAG_GRE, mtag)) { - if (memcmp((caddr_t)(mtag + 1), &ifp->if_index, - sizeof(ifp->if_index)) == 0) { - error = EIO; - goto drop; - } - } - - mtag = m_tag_get(PACKET_TAG_GRE, sizeof(ifp->if_index), M_NOWAIT); - if (mtag == NULL) { - error = ENOBUFS; + error = if_mtag_vif(ifp, m); + if (error != 0) goto drop; - } - memcpy((caddr_t)(mtag + 1), &ifp->if_index, sizeof(ifp->if_index)); - m_tag_prepend(m, mtag); switch (af) { case AF_INET: { Index: if_mpe.c =================================================================== RCS file: /cvs/src/sys/net/if_mpe.c,v retrieving revision 1.95 diff -u -p -r1.95 if_mpe.c --- if_mpe.c 24 Jan 2020 05:14:51 -0000 1.95 +++ if_mpe.c 5 May 2020 12:03:23 -0000 @@ -109,6 +109,7 @@ mpe_clone_create(struct if_clone *ifc, i ifp->if_mtu = MPE_MTU; ifp->if_ioctl = mpe_ioctl; ifp->if_output = mpe_output; + ifp->if_enqueue = if_venqueue; ifp->if_start = mpe_start; ifp->if_type = IFT_MPLS; ifp->if_hdrlen = MPE_HDRLEN; Index: if_mpip.c =================================================================== RCS file: /cvs/src/sys/net/if_mpip.c,v retrieving revision 1.8 diff -u -p -r1.8 if_mpip.c --- if_mpip.c 26 Jun 2019 08:13:13 -0000 1.8 +++ if_mpip.c 5 May 2020 12:03:23 -0000 @@ -113,6 +113,7 @@ mpip_clone_create(struct if_clone *ifc, ifp->if_xflags = IFXF_CLONED; ifp->if_ioctl = mpip_ioctl; ifp->if_output = mpip_output; + ifp->if_enqueue = if_venqueue; ifp->if_start = mpip_start; ifp->if_rtrequest = p2p_rtrequest; ifp->if_mtu = 1500; Index: if_mpw.c =================================================================== RCS file: /cvs/src/sys/net/if_mpw.c,v retrieving revision 1.55 diff -u -p -r1.55 if_mpw.c --- if_mpw.c 26 Jun 2019 08:13:13 -0000 1.55 +++ if_mpw.c 5 May 2020 12:03:23 -0000 @@ -109,6 +109,7 @@ mpw_clone_create(struct if_clone *ifc, i ifp->if_xflags = IFXF_CLONED; ifp->if_ioctl = mpw_ioctl; ifp->if_output = mpw_output; + ifp->if_enqueue = if_venqueue; ifp->if_start = mpw_start; ifp->if_hardmtu = ETHER_MAX_HARDMTU_LEN; IFQ_SET_MAXLEN(&ifp->if_snd, IFQ_MAXLEN); Index: if_trunk.c =================================================================== RCS file: /cvs/src/sys/net/if_trunk.c,v retrieving revision 1.144 diff -u -p -r1.144 if_trunk.c --- if_trunk.c 6 Dec 2019 02:02:18 -0000 1.144 +++ if_trunk.c 5 May 2020 12:03:23 -0000 @@ -180,6 +180,7 @@ trunk_clone_create(struct if_clone *ifc, ifp = &tr->tr_ac.ac_if; ifp->if_softc = tr; + ifp->if_enqueue = if_venqueue; ifp->if_start = trunk_start; ifp->if_ioctl = trunk_ioctl; ifp->if_flags = IFF_SIMPLEX | IFF_BROADCAST | IFF_MULTICAST; Index: if_var.h =================================================================== RCS file: /cvs/src/sys/net/if_var.h,v retrieving revision 1.104 diff -u -p -r1.104 if_var.h --- if_var.h 12 Apr 2020 07:02:43 -0000 1.104 +++ if_var.h 5 May 2020 12:03:23 -0000 @@ -338,8 +338,11 @@ int niq_enlist(struct niqueue *, struct extern struct ifnet_head ifnet; +int if_mtag_vif(struct ifnet *, struct mbuf *); + void if_start(struct ifnet *); int if_enqueue(struct ifnet *, struct mbuf *); +int if_venqueue(struct ifnet *, struct mbuf *); int if_enqueue_ifq(struct ifnet *, struct mbuf *); void if_input(struct ifnet *, struct mbuf_list *); void if_vinput(struct ifnet *, struct mbuf *); Index: if_vlan.c =================================================================== RCS file: /cvs/src/sys/net/if_vlan.c,v retrieving revision 1.203 diff -u -p -r1.203 if_vlan.c --- if_vlan.c 1 Feb 2020 10:27:40 -0000 1.203 +++ if_vlan.c 5 May 2020 12:03:23 -0000 @@ -295,6 +295,12 @@ vlan_enqueue(struct ifnet *ifp, struct m struct vlan_softc *sc; int error = 0; + error = if_mtag_vif(ifp, m); + if (error != 0) { + m_freem(m); + return (error); + } + if (!ifq_is_priq(&ifp->if_snd)) return (if_enqueue_ifq(ifp, m)); Index: if_vxlan.c =================================================================== RCS file: /cvs/src/sys/net/if_vxlan.c,v retrieving revision 1.76 diff -u -p -r1.76 if_vxlan.c --- if_vxlan.c 8 Nov 2019 07:16:29 -0000 1.76 +++ if_vxlan.c 5 May 2020 12:03:23 -0000 @@ -150,6 +150,7 @@ vxlan_clone_create(struct if_clone *ifc, ifp->if_softc = sc; ifp->if_ioctl = vxlanioctl; + ifp->if_enqueue = if_venqueue; ifp->if_start = vxlanstart; IFQ_SET_MAXLEN(&ifp->if_snd, IFQ_MAXLEN);