this factors out the vlan shim header injection as vlan_inject()

i intend to use this code in mpw in an upcoming diff.

ok?

Index: if_vlan.c
===================================================================
RCS file: /cvs/src/sys/net/if_vlan.c,v
retrieving revision 1.151
diff -u -p -r1.151 if_vlan.c
--- if_vlan.c   13 Jan 2016 03:18:26 -0000      1.151
+++ if_vlan.c   2 Mar 2016 01:16:26 -0000
@@ -274,21 +274,12 @@ vlan_start(struct ifnet *ifp)
                            (prio << EVL_PRIO_BITS);
                        m->m_flags |= M_VLANTAG;
                } else {
-                       struct ether_vlan_header evh;
-
-                       m_copydata(m, 0, ETHER_HDR_LEN, (caddr_t)&evh);
-                       evh.evl_proto = evh.evl_encap_proto;
-                       evh.evl_encap_proto = htons(ifv->ifv_type);
-                       evh.evl_tag = htons(ifv->ifv_tag +
-                           (prio << EVL_PRIO_BITS));
-                       m_adj(m, ETHER_HDR_LEN);
-                       M_PREPEND(m, sizeof(evh), M_DONTWAIT);
+                       m = vlan_inject(m, ifv->ifv_type, ifv->ifv_tag |
+                            (prio << EVL_PRIO_BITS));
                        if (m == NULL) {
                                ifp->if_oerrors++;
                                continue;
                        }
-                       m_copyback(m, 0, sizeof(evh), &evh, M_NOWAIT);
-                       m->m_flags &= ~M_VLANTAG;
                }
 
                if (if_enqueue(p, m)) {
@@ -298,6 +289,26 @@ vlan_start(struct ifnet *ifp)
                ifp->if_opackets++;
        }
 }
+
+struct mbuf *
+vlan_inject(struct mbuf *m, uint16_t type, uint16_t tag)
+{
+       struct ether_vlan_header evh;
+
+       m_copydata(m, 0, ETHER_HDR_LEN, (caddr_t)&evh);
+       evh.evl_proto = evh.evl_encap_proto;
+       evh.evl_encap_proto = htons(type);
+       evh.evl_tag = htons(tag);
+       m_adj(m, ETHER_HDR_LEN);
+       M_PREPEND(m, sizeof(evh), M_DONTWAIT);
+       if (m == NULL)
+               return (NULL);
+
+       m_copyback(m, 0, sizeof(evh), &evh, M_NOWAIT);
+       CLR(m->m_flags, M_VLANTAG);
+
+       return (m);
+ }
 
 /*
  * vlan_input() returns 1 if it has consumed the packet, 0 otherwise.
Index: if_vlan_var.h
===================================================================
RCS file: /cvs/src/sys/net/if_vlan_var.h,v
retrieving revision 1.31
diff -u -p -r1.31 if_vlan_var.h
--- if_vlan_var.h       3 Dec 2015 16:27:32 -0000       1.31
+++ if_vlan_var.h       2 Mar 2016 01:16:26 -0000
@@ -98,6 +98,8 @@ struct        ifvlan {
 #define        ifv_prio        ifv_mib.ifvm_prio
 #define        ifv_type        ifv_mib.ifvm_type
 #define        IFVF_PROMISC    0x01
+
+struct mbuf    *vlan_inject(struct mbuf *, uint16_t, uint16_t);
 #endif /* _KERNEL */
 
 #endif /* _NET_IF_VLAN_VAR_H_ */

Reply via email to