commit 36e566f9ed455961014662439bd1e7699e13e2b4 Author: Ryota Ozaki Date: Wed May 27 12:23:57 2015 +0900 Use a mtag instead of a mbuf flag for MPLS fixup diff --git a/sys/net/if_ethersubr.c b/sys/net/if_ethersubr.c index 2b7a9ae..8327213 100644 --- a/sys/net/if_ethersubr.c +++ b/sys/net/if_ethersubr.c @@ -353,9 +353,14 @@ ether_output(struct ifnet * const ifp0, struct mbuf * const m0, } #ifdef MPLS - if ((m->m_flags & M_MPLS) != 0) { - etype = htons(ETHERTYPE_MPLS); - m->m_flags &= ~M_MPLS; + { + struct m_tag *mtag; + mtag = m_tag_find(m, PACKET_TAG_MPLS, NULL); + if (mtag != NULL) { + /* Having the tag itself indicates it's MPLS */ + etype = htons(ETHERTYPE_MPLS); + m_tag_delete(m, mtag); + } } #endif diff --git a/sys/netinet/ip_output.c b/sys/netinet/ip_output.c index 84e7f63..7d8786f 100644 --- a/sys/netinet/ip_output.c +++ b/sys/netinet/ip_output.c @@ -276,11 +276,25 @@ out: #ifdef MPLS if (rt0 != NULL && rt_gettag(rt0) != NULL && rt_gettag(rt0)->sa_family == AF_MPLS && - (m->m_flags & (M_MCAST | M_BCAST)) == 0) { + (m->m_flags & (M_MCAST | M_BCAST)) == 0 && + ifp->if_type == IFT_ETHER) { union mpls_shim msh; msh.s_addr = MPLS_GETSADDR(rt0); - if (msh.shim.label != MPLS_LABEL_IMPLNULL) - m->m_flags |= M_MPLS; + if (msh.shim.label != MPLS_LABEL_IMPLNULL) { + struct m_tag *mtag; + /* + * XXX tentative solution to tell ether_output + * it's MPLS. Need some more efficient solution. + */ + mtag = m_tag_get(PACKET_TAG_MPLS, + sizeof(int) /* dummy */, + M_NOWAIT); + if (mtag == NULL) { + error = ENOMEM; + goto bad; + } + m_tag_prepend(m, mtag); + } } #endif diff --git a/sys/sys/mbuf.h b/sys/sys/mbuf.h index 6fe6fc3..c907bdd 100644 --- a/sys/sys/mbuf.h +++ b/sys/sys/mbuf.h @@ -351,8 +351,6 @@ MBUF_DEFINE(mbuf, MHLEN, MLEN); #define M_LINK6 0x00040000 /* link layer specific flag */ #define M_LINK7 0x00080000 /* link layer specific flag */ -#define M_MPLS 0x00100000 /* MPLS flag */ - /* additional flags for M_EXT mbufs */ #define M_EXT_FLAGS 0xff000000 #define M_EXT_CLUSTER 0x01000000 /* ext is a cluster */ @@ -915,6 +913,8 @@ struct m_tag *m_tag_next(struct mbuf *, struct m_tag *); * loop detection/recovery */ +#define PACKET_TAG_MPLS 29 /* Indicate it's for MPLS */ + /* * Return the number of bytes in the mbuf chain, m. */