[dpdk-dev,v3,19/25] ether: Fix vlan strip/insert issue

Message ID 1422516249-14596-20-git-send-email-changchun.ouyang@intel.com (mailing list archive)
State Superseded, archived
Headers

Commit Message

Ouyang Changchun Jan. 29, 2015, 7:24 a.m. UTC
  Need swap the data from cpu to BE(big endian) for vlan-type.

Signed-off-by: Changchun Ouyang <changchun.ouyang@intel.com>
---
 lib/librte_ether/rte_ether.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
  

Comments

Huawei Xie Feb. 4, 2015, 10:54 a.m. UTC | #1
On 1/29/2015 3:24 PM, Ouyang Changchun wrote:
> Need swap the data from cpu to BE(big endian) for vlan-type.
>
> Signed-off-by: Changchun Ouyang <changchun.ouyang@intel.com>
> ---
> lib/librte_ether/rte_ether.h | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/lib/librte_ether/rte_ether.h b/lib/librte_ether/rte_ether.h
> index 74f71c2..0797908 100644
> --- a/lib/librte_ether/rte_ether.h
> +++ b/lib/librte_ether/rte_ether.h
> @@ -351,7 +351,7 @@ static inline int rte_vlan_strip(struct rte_mbuf *m)
>     struct ether_hdr *eh
>          = rte_pktmbuf_mtod(m, struct ether_hdr *);
>
> -    if (eh->ether_type != ETHER_TYPE_VLAN)
> +    if (eh->ether_type != rte_cpu_to_be_16(ETHER_TYPE_VLAN))
rte_be_to_cpu_16?
>         return -1;
>
>     struct vlan_hdr *vh = (struct vlan_hdr *)(eh + 1);
> @@ -401,7 +401,7 @@ static inline int rte_vlan_insert(struct rte_mbuf
> **m)
>         return -ENOSPC;
>
>     memmove(nh, oh, 2 * ETHER_ADDR_LEN);
> -    nh->ether_type = ETHER_TYPE_VLAN;
> +    nh->ether_type = rte_cpu_to_be_16(ETHER_TYPE_VLAN);
rte_be_to_cpu_16?
>
>     vh = (struct vlan_hdr *) (nh + 1);
>     vh->vlan_tci = rte_cpu_to_be_16((*m)->vlan_tci);
  
Ouyang Changchun Feb. 5, 2015, 12:54 a.m. UTC | #2
Hi huawei,

> -----Original Message-----
> From: Xie, Huawei
> Sent: Wednesday, February 4, 2015 6:54 PM
> To: Ouyang, Changchun; dev@dpdk.org
> Cc: stephen@networkplumber.org; Cao, Waterman; Xu, Qian Q
> Subject: Re: [PATCH v3 19/25] ether: Fix vlan strip/insert issue
> 
> On 1/29/2015 3:24 PM, Ouyang Changchun wrote:
> > Need swap the data from cpu to BE(big endian) for vlan-type.
> >
> > Signed-off-by: Changchun Ouyang <changchun.ouyang@intel.com>
> > ---
> > lib/librte_ether/rte_ether.h | 4 ++--
> > 1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/lib/librte_ether/rte_ether.h
> > b/lib/librte_ether/rte_ether.h index 74f71c2..0797908 100644
> > --- a/lib/librte_ether/rte_ether.h
> > +++ b/lib/librte_ether/rte_ether.h
> > @@ -351,7 +351,7 @@ static inline int rte_vlan_strip(struct rte_mbuf *m)
> >     struct ether_hdr *eh
> >          = rte_pktmbuf_mtod(m, struct ether_hdr *);
> >
> > -    if (eh->ether_type != ETHER_TYPE_VLAN)
> > +    if (eh->ether_type != rte_cpu_to_be_16(ETHER_TYPE_VLAN))
> rte_be_to_cpu_16?

Eh->ether_type is in network byte order(big endian),
While  ETHER_TYPE_VLAN is host byte order(little endian on x86), so it need change into big endian.

> >         return -1;
> >
> >     struct vlan_hdr *vh = (struct vlan_hdr *)(eh + 1); @@ -401,7
> > +401,7 @@ static inline int rte_vlan_insert(struct rte_mbuf
> > **m)
> >         return -ENOSPC;
> >
> >     memmove(nh, oh, 2 * ETHER_ADDR_LEN);
> > -    nh->ether_type = ETHER_TYPE_VLAN;
> > +    nh->ether_type = rte_cpu_to_be_16(ETHER_TYPE_VLAN);
> rte_be_to_cpu_16?

Similar reason as above.

Thanks
Changchun
  

Patch

diff --git a/lib/librte_ether/rte_ether.h b/lib/librte_ether/rte_ether.h
index 74f71c2..0797908 100644
--- a/lib/librte_ether/rte_ether.h
+++ b/lib/librte_ether/rte_ether.h
@@ -351,7 +351,7 @@  static inline int rte_vlan_strip(struct rte_mbuf *m)
 	struct ether_hdr *eh
 		 = rte_pktmbuf_mtod(m, struct ether_hdr *);
 
-	if (eh->ether_type != ETHER_TYPE_VLAN)
+	if (eh->ether_type != rte_cpu_to_be_16(ETHER_TYPE_VLAN))
 		return -1;
 
 	struct vlan_hdr *vh = (struct vlan_hdr *)(eh + 1);
@@ -401,7 +401,7 @@  static inline int rte_vlan_insert(struct rte_mbuf **m)
 		return -ENOSPC;
 
 	memmove(nh, oh, 2 * ETHER_ADDR_LEN);
-	nh->ether_type = ETHER_TYPE_VLAN;
+	nh->ether_type = rte_cpu_to_be_16(ETHER_TYPE_VLAN);
 
 	vh = (struct vlan_hdr *) (nh + 1);
 	vh->vlan_tci = rte_cpu_to_be_16((*m)->vlan_tci);