[dpdk-dev,v2,5/7] fix the Marco conflict

Message ID 1409105634-29980-6-git-send-email-jingjing.wu@intel.com (mailing list archive)
State Superseded, archived
Headers

Commit Message

Jingjing Wu Aug. 27, 2014, 2:13 a.m. UTC
  fix the Marco conflict between rte_ip.h and netinet/in.h
 
Signed-off-by: jingjing.wu <jingjing.wu@intel.com>
Reviewed-by: Helin Zhang <helin.zhang@intel.com>
Reviewed-by: Jing Chen <jing.d.chen@intel.com>
Reviewed-by: Jijiang Liu <jijiang.liu@intel.com>
 
---
 lib/librte_net/rte_ip.h | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
  

Comments

Thomas Monjalon Aug. 27, 2014, 2:27 p.m. UTC | #1
2014-08-27 10:13, Jingjing Wu:
> fix the Marco conflict between rte_ip.h and netinet/in.h

Who is Marco?

> +#ifndef _NETINET_IN_H
> +#ifndef _NETINET_IN_H_
>  /* IPv4 protocols */
>  #define IPPROTO_IP         0  /**< dummy for IP */
>  #define IPPROTO_HOPOPTS    0  /**< IP6 hop-by-hop options */
> @@ -226,7 +228,8 @@ struct ipv4_hdr {
>  #define IPPROTO_DIVERT   254  /**< divert pseudo-protocol */
>  #define IPPROTO_RAW      255  /**< raw IP packet */
>  #define IPPROTO_MAX      256  /**< maximum protocol number */
> -
> +#endif /* _NETINET_IN_H_ */
> +#endif /* _NETINET_IN_H */

Please explain your "fix" (which seems to be a workaround).
  
Jingjing Wu Aug. 28, 2014, 3:39 a.m. UTC | #2
Hi, Thomas

Because these macros such as IPPROTO_TCP, IPPROTO_UDP are already defined in <netinet/in.h>. If user's application include <netinet/in.h> and rte_ip.h at the same time, there will be conflict error, for example cmdline.c in testpmd.
I remember there was someone also raised this issue few month ago.
So just use the way "#ifndef #endif" to avoid the conflict. And it is exactly workaround as you said.

Oh, it should be macro, but not marco, my spelling mistake.
Sorry for that. I will rename this.


> -----Original Message-----
> From: Thomas Monjalon [mailto:thomas.monjalon@6wind.com]
> Sent: Wednesday, August 27, 2014 10:28 PM
> To: Wu, Jingjing
> Cc: dev@dpdk.org
> Subject: Re: [dpdk-dev] [PATCH v2 5/7] fix the Marco conflict
> 
> 2014-08-27 10:13, Jingjing Wu:
> > fix the Marco conflict between rte_ip.h and netinet/in.h
> 
> Who is Marco?
> 
> > +#ifndef _NETINET_IN_H
> > +#ifndef _NETINET_IN_H_
> >  /* IPv4 protocols */
> >  #define IPPROTO_IP         0  /**< dummy for IP */
> >  #define IPPROTO_HOPOPTS    0  /**< IP6 hop-by-hop options */
> > @@ -226,7 +228,8 @@ struct ipv4_hdr {
> >  #define IPPROTO_DIVERT   254  /**< divert pseudo-protocol */
> >  #define IPPROTO_RAW      255  /**< raw IP packet */
> >  #define IPPROTO_MAX      256  /**< maximum protocol number */
> > -
> > +#endif /* _NETINET_IN_H_ */
> > +#endif /* _NETINET_IN_H */
> 
> Please explain your "fix" (which seems to be a workaround).
> 
> --
> Thomas
  
Thomas Monjalon Aug. 28, 2014, 8:55 a.m. UTC | #3
2014-08-28 03:39, Wu, Jingjing:
> Because these macros such as IPPROTO_TCP, IPPROTO_UDP are already
> defined in <netinet/in.h>. If user's application include <netinet/in.h>
> and rte_ip.h at the same time, there will be conflict error, for
> example cmdline.c in testpmd.

Yes

> I remember there was someone also raised this issue few month ago.

Yes, and the question was: "should we totally remove these definitions"?
I think yes.

> So just use the way "#ifndef #endif" to avoid the conflict.

But you didn't explain difference between _NETINET_IN_H and _NETINET_IN_H_.

> And it is exactly workaround as you said.

Yes, it's a workaround.
If rte_ip.h is included before netinet/in.h, I think there is still a problem.
  
Jingjing Wu Aug. 28, 2014, 2:37 p.m. UTC | #4
> -----Original Message-----
> From: Thomas Monjalon [mailto:thomas.monjalon@6wind.com]
> Sent: Thursday, August 28, 2014 4:56 PM
> To: Wu, Jingjing
> Cc: dev@dpdk.org
> Subject: Re: [dpdk-dev] [PATCH v2 5/7] fix the Marco conflict
> 
> 2014-08-28 03:39, Wu, Jingjing:
> > Because these macros such as IPPROTO_TCP, IPPROTO_UDP are already
> > defined in <netinet/in.h>. If user's application include <netinet/in.h>
> > and rte_ip.h at the same time, there will be conflict error, for
> > example cmdline.c in testpmd.
> 
> Yes
> 
> > I remember there was someone also raised this issue few month ago.
> 
> Yes, and the question was: "should we totally remove these definitions"?
> I think yes.
> 
Yes, it will be clear. But it also provides a way to user who doesn't use netinet/in.h.

> > So just use the way "#ifndef #endif" to avoid the conflict.
> 
> But you didn't explain difference between _NETINET_IN_H and _NETINET_IN_H_.

It is due to the different versions of in.h, some use _NETINET_IN_H_ to define the
head file, while some use _NETINET_IN_H
> 
> > And it is exactly workaround as you said.
> 
> Yes, it's a workaround.
> If rte_ip.h is included before netinet/in.h, I think there is still a problem.

Yes, it's just workaround.
As my understanding, in DPDK's source code
System head files includes first should be as following. So I think it's OK then.
> 
> --
> Thomas

Can I send a separate patch for this? Because it has no strict relationship with flow director.

Thanks 
Jingjing
  
Thomas Monjalon Aug. 28, 2014, 2:46 p.m. UTC | #5
2014-08-28 14:37, Wu, Jingjing:
> Can I send a separate patch for this?
> Because it has no strict relationship with flow director.

Yes, please.
But I think you should look at the removal option (no redefinition
of at all).

Thanks
  

Patch

diff --git a/lib/librte_net/rte_ip.h b/lib/librte_net/rte_ip.h
index e3f65c1..67b6c2d 100644
--- a/lib/librte_net/rte_ip.h
+++ b/lib/librte_net/rte_ip.h
@@ -116,6 +116,8 @@  struct ipv4_hdr {
 
 #define	IPV4_HDR_OFFSET_UNITS	8
 
+#ifndef _NETINET_IN_H
+#ifndef _NETINET_IN_H_
 /* IPv4 protocols */
 #define IPPROTO_IP         0  /**< dummy for IP */
 #define IPPROTO_HOPOPTS    0  /**< IP6 hop-by-hop options */
@@ -226,7 +228,8 @@  struct ipv4_hdr {
 #define IPPROTO_DIVERT   254  /**< divert pseudo-protocol */
 #define IPPROTO_RAW      255  /**< raw IP packet */
 #define IPPROTO_MAX      256  /**< maximum protocol number */
-
+#endif /* _NETINET_IN_H_ */
+#endif /* _NETINET_IN_H */
 /*
  * IPv4 address types
  */