Merge pull request #403 from dragonorloong/master

vlan buf fix
This commit is contained in:
johnjiang 2019-07-29 14:31:51 +08:00 committed by GitHub
commit 8eb6d4d5ae
4 changed files with 26 additions and 9 deletions

View File

@ -50,3 +50,4 @@ ff_getsockopt_freebsd
ff_setsockopt_freebsd ff_setsockopt_freebsd
ff_dup ff_dup
ff_dup2 ff_dup2
ff_mbuf_set_vlan_info

View File

@ -97,6 +97,8 @@ static int enable_kni;
static int kni_accept; static int kni_accept;
#endif #endif
#define ETH_P_8021Q 0x8100
static int numa_on; static int numa_on;
static unsigned idle_sleep; 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*); void *data = rte_pktmbuf_mtod(pkt, void*);
uint16_t len = rte_pktmbuf_data_len(pkt); 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; return;
} }
if (pkt->ol_flags & PKT_RX_VLAN_STRIPPED) {
ff_mbuf_set_vlan_info(hdr, pkt->vlan_tci);
}
struct rte_mbuf *pn = pkt->next; struct rte_mbuf *pn = pkt->next;
void *prev = hdr; void *prev = hdr;
while(pn != NULL) { while(pn != NULL) {
@ -901,15 +902,23 @@ ff_veth_input(const struct ff_dpdk_if_context *ctx, struct rte_mbuf *pkt)
} }
static enum FilterReturn 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) if(len < ETHER_HDR_LEN)
return FILTER_UNKNOWN; return FILTER_UNKNOWN;
const struct ether_hdr *hdr; const struct ether_hdr *hdr;
const struct vlan_hdr *vlanhdr;
void *data = rte_pktmbuf_mtod(mbuf, void*);
hdr = (const struct ether_hdr *)data; 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; return FILTER_ARP;
#ifndef FF_KNI #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) { if (filter == FILTER_ARP) {
struct rte_mempool *mbuf_pool; struct rte_mempool *mbuf_pool;
struct rte_mbuf *mbuf_clone; struct rte_mbuf *mbuf_clone;

View File

@ -205,7 +205,6 @@ ff_mbuf_gethdr(void *pkt, uint16_t total, void *data,
CSUM_DATA_VALID | CSUM_PSEUDO_HDR; CSUM_DATA_VALID | CSUM_PSEUDO_HDR;
m->m_pkthdr.csum_data = 0xffff; m->m_pkthdr.csum_data = 0xffff;
} }
return (void *)m; return (void *)m;
} }
@ -420,3 +419,10 @@ ff_veth_softc_to_hostc(void *softc)
return (void *)sc->host_ctx; 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;
}

View File

@ -45,5 +45,6 @@ void ff_veth_process_packet(void *arg, void *m);
void *ff_veth_softc_to_hostc(void *softc); 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 */ #endif /* ifndef _FSTACK_VETH_H */