From 2a7631a6bc3eb6e410d1bddabcdcf8ac7653a35b Mon Sep 17 00:00:00 2001 From: HongBo Long Date: Tue, 9 Jul 2019 19:56:16 +0800 Subject: [PATCH 1/2] set freebsd mbuf vlan information when the vlan_strip is enable && get ether_type error when the vlan_strip is disabled --- lib/ff_api.symlist | 1 + lib/ff_dpdk_if.c | 25 +++++++++++++++++-------- lib/ff_veth.c | 8 +++++++- lib/ff_veth.h | 1 + 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/lib/ff_api.symlist b/lib/ff_api.symlist index 4c2558ea7..8f1804f2a 100755 --- a/lib/ff_api.symlist +++ b/lib/ff_api.symlist @@ -50,3 +50,4 @@ ff_getsockopt_freebsd ff_setsockopt_freebsd ff_dup ff_dup2 +ff_mbuf_set_vlan_info diff --git a/lib/ff_dpdk_if.c b/lib/ff_dpdk_if.c index 089aad8fb..654a53696 100644 --- a/lib/ff_dpdk_if.c +++ b/lib/ff_dpdk_if.c @@ -97,6 +97,8 @@ static int enable_kni; static int kni_accept; #endif +#define ETH_P_8021Q 0x8100 + static int numa_on; static unsigned idle_sleep; @@ -867,11 +869,6 @@ ff_veth_input(const struct ff_dpdk_if_context *ctx, struct rte_mbuf *pkt) } } - /* - * FIXME: should we save pkt->vlan_tci - * if (pkt->ol_flags & PKT_RX_VLAN_PKT) - */ - void *data = rte_pktmbuf_mtod(pkt, void*); uint16_t len = rte_pktmbuf_data_len(pkt); @@ -881,6 +878,10 @@ ff_veth_input(const struct ff_dpdk_if_context *ctx, struct rte_mbuf *pkt) return; } + if (pkt->ol_flags & PKT_RX_VLAN_STRIPPED) { + ff_mbuf_set_vlan_info(hdr, pkt->vlan_tci); + } + struct rte_mbuf *pn = pkt->next; void *prev = hdr; while(pn != NULL) { @@ -901,15 +902,23 @@ ff_veth_input(const struct ff_dpdk_if_context *ctx, struct rte_mbuf *pkt) } static enum FilterReturn -protocol_filter(const void *data, uint16_t len) +protocol_filter(const struct rte_mbuf *mbuf, uint16_t len) { if(len < ETHER_HDR_LEN) return FILTER_UNKNOWN; const struct ether_hdr *hdr; + const struct vlan_hdr *vlanhdr; + void *data = rte_pktmbuf_mtod(mbuf, void*); hdr = (const struct ether_hdr *)data; + uint16_t ether_type = ntohs(hdr->ether_type); - if(ntohs(hdr->ether_type) == ETHER_TYPE_ARP) + if (hdr->ether_type == htons(ETH_P_8021Q) && !(mbuf->ol_flags & PKT_RX_VLAN_STRIPPED)) { + vlanhdr = (struct vlan_hdr *)(data + sizeof(struct ether_hdr)); + ether_type = ntohs(vlanhdr->eth_proto); + } + + if(ether_type == ETHER_TYPE_ARP) return FILTER_ARP; #ifndef FF_KNI @@ -1034,7 +1043,7 @@ process_packets(uint16_t port_id, uint16_t queue_id, struct rte_mbuf **bufs, } } - enum FilterReturn filter = protocol_filter(data, len); + enum FilterReturn filter = protocol_filter(rtem, len); if (filter == FILTER_ARP) { struct rte_mempool *mbuf_pool; struct rte_mbuf *mbuf_clone; diff --git a/lib/ff_veth.c b/lib/ff_veth.c index 0f0b09efd..e2acb276e 100644 --- a/lib/ff_veth.c +++ b/lib/ff_veth.c @@ -205,7 +205,6 @@ ff_mbuf_gethdr(void *pkt, uint16_t total, void *data, CSUM_DATA_VALID | CSUM_PSEUDO_HDR; m->m_pkthdr.csum_data = 0xffff; } - return (void *)m; } @@ -420,3 +419,10 @@ ff_veth_softc_to_hostc(void *softc) return (void *)sc->host_ctx; } +void +ff_mbuf_set_vlan_info(void *hdr, uint16_t vlan_tci) { + struct mbuf *m = (struct mbuf *)hdr; + m->m_pkthdr.ether_vtag = vlan_tci; + m->m_flags |= M_VLANTAG; + return; +} diff --git a/lib/ff_veth.h b/lib/ff_veth.h index 7cbeecc3c..9464530fb 100644 --- a/lib/ff_veth.h +++ b/lib/ff_veth.h @@ -45,5 +45,6 @@ void ff_veth_process_packet(void *arg, void *m); void *ff_veth_softc_to_hostc(void *softc); +void ff_mbuf_set_vlan_info(void *hdr, uint16_t vlan_tci); #endif /* ifndef _FSTACK_VETH_H */ From ab2d620de66ba880ea59c9edb1aba9a43705b204 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?fengbojiang=28=E5=A7=9C=E5=87=A4=E6=B3=A2=29?= Date: Mon, 29 Jul 2019 14:47:11 +0800 Subject: [PATCH 2/2] Modified vlan code. --- lib/ff_dpdk_if.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/lib/ff_dpdk_if.c b/lib/ff_dpdk_if.c index 654a53696..b2894f54b 100644 --- a/lib/ff_dpdk_if.c +++ b/lib/ff_dpdk_if.c @@ -97,8 +97,6 @@ static int enable_kni; static int kni_accept; #endif -#define ETH_P_8021Q 0x8100 - static int numa_on; static unsigned idle_sleep; @@ -902,20 +900,19 @@ ff_veth_input(const struct ff_dpdk_if_context *ctx, struct rte_mbuf *pkt) } static enum FilterReturn -protocol_filter(const struct rte_mbuf *mbuf, uint16_t len) +protocol_filter(const void *data, uint16_t len) { if(len < ETHER_HDR_LEN) return FILTER_UNKNOWN; const struct ether_hdr *hdr; const struct vlan_hdr *vlanhdr; - void *data = rte_pktmbuf_mtod(mbuf, void*); hdr = (const struct ether_hdr *)data; - uint16_t ether_type = ntohs(hdr->ether_type); + uint16_t ether_type = rte_be_to_cpu_16(hdr->ether_type); - if (hdr->ether_type == htons(ETH_P_8021Q) && !(mbuf->ol_flags & PKT_RX_VLAN_STRIPPED)) { + if (ether_type == ETHER_TYPE_VLAN) { vlanhdr = (struct vlan_hdr *)(data + sizeof(struct ether_hdr)); - ether_type = ntohs(vlanhdr->eth_proto); + ether_type = rte_be_to_cpu_16(vlanhdr->eth_proto); } if(ether_type == ETHER_TYPE_ARP) @@ -928,7 +925,7 @@ protocol_filter(const struct rte_mbuf *mbuf, uint16_t len) return FILTER_UNKNOWN; } - if(ntohs(hdr->ether_type) != ETHER_TYPE_IPv4) + if(ether_type != ETHER_TYPE_IPv4) return FILTER_UNKNOWN; return ff_kni_proto_filter(data + ETHER_HDR_LEN, @@ -1043,7 +1040,7 @@ process_packets(uint16_t port_id, uint16_t queue_id, struct rte_mbuf **bufs, } } - enum FilterReturn filter = protocol_filter(rtem, len); + enum FilterReturn filter = protocol_filter(data, len); if (filter == FILTER_ARP) { struct rte_mempool *mbuf_pool; struct rte_mbuf *mbuf_clone;