Skip to contentSkip to conversation

ip_tables.h does not compile when using g++

PATCH In review Scott Andrew Baillie 3 participants 5 messages Sep 16, 2002 netfilter

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ip_tables.h does not compile when using g++

Hi,

The following patch fixes the 3 places in ip_tables.h that involve pointer arithmetic using a void* type.

Pointer arithmetic involving a void* type does not compile with g++.

The header file ip_tables.h is included by the kernel and by user space programs so it should compile when using g++.

Regards,

Scott.

include/linux/netfilter_ipv4/ip_tables.h +3 -3
diff -ur linux-2.4.19/include/linux/netfilter_ipv4/ip_tables.h linux-2.4.19-new/include/linux/netfilter_ipv4/ip_tables.h
@@ -292,7 +292,7 @@
 static __inline__ struct ipt_entry_target *
 ipt_get_target(struct ipt_entry *e)
 {
-	return (void *)e + e->target_offset;
+	return ((struct ipt_entry_target *)((char *)e + e->target_offset));
 }
 
 /* fn returns 0 to continue iteration */
@@ -305,7 +305,7 @@
 	for (__i = sizeof(struct ipt_entry);	\
 	     __i < (e)->target_offset;		\
 	     __i += __match->u.match_size) {	\
-		__match = (void *)(e) + __i;	\
+		__match = (struct ipt_entry_match *)((char *)(e) + __i); \
 						\
 		__ret = fn(__match , ## args);	\
 		if (__ret != 0)			\
@@ -322,7 +322,7 @@
 	struct ipt_entry *__entry;				\
 								\
 	for (__i = 0; __i < (size); __i += __entry->next_offset) { \
-		__entry = (void *)(entries) + __i;		\
+		__entry = (struct ipt_entry *)((char *)(entries) + __i); \
 								\
 		__ret = fn(__entry , ## args);			\
 		if (__ret != 0)					\
#1 lore raw
Quoted 2 lines

The header file ip_tables.h is included by the kernel and by user space programs so it should compile when using g++.

I don't understand why you arrive at this conclusion. ip_tables.h is in no way a valid documented user level API, and the fact that the existing iptables user level code base (all implemented in C) is including it, is a design error in the iptables userlevel - good style would be to copy those headers into the userlevel distribution, thus properly seperating kernel and userlevel headers.

A future userlevel C++ API to iptables would indeed need to concern itself with such things - but there is no such thing in existence (and I don't know whether it is under consideration to have a C++ callable API).

I strongly disagree with the "void *" -> "char *" conversion in pure kernel headers, because the kernel is by definition geared towards gcc with most extensions (and void * arithmetic is one that makes sense).

best regards
Patrick

#2 lore raw
Quoted 9 lines · Patrick Schaaf
Quoted 2 lines

The header file ip_tables.h is included by the kernel and by user space programs so it should compile when using g++.

I don't understand why you arrive at this conclusion. ip_tables.h is in no way a valid documented user level API, and the fact that the existing iptables user level code base (all implemented in C) is including it, is a design error in the iptables userlevel - good style would be to copy those headers into the userlevel distribution, thus properly seperating kernel and userlevel headers.

Patrick, you are right. It is not a userspace API. But unfortunately it is included by libiptc, and if you as an application include libiptc.h, you will in turn include ip_tables.h

Quoted 4 lines

A future userlevel C++ API to iptables would indeed need to concern itself with such things - but there is no such thing in existence (and I don't know whether it is under consideration to have a C++ callable API).

Well, you can call the C api from C++, but we don't intend to release any real C++ classes for iptables manipulation.

Quoted 4 lines

I strongly disagree with the "void *" -> "char *" conversion in pure kernel headers, because the kernel is by definition geared towards gcc with most extensions (and void * arithmetic is one that makes sense).

I share this disagreemenent. However, if it's the only way we can make C++ apps use libiptc (for now), I am willing to pay this 'price'.

Quoted 2 lines

best regards
Patrick

Signature · 5 lines
Live long and prosper
- Harald Welte / [email protected]               http://www.gnumonks.org/
============================================================================
GCS/E/IT d- s-: a-- C+++ UL++++$ P+++ L++++$ E--- W- N++ o? K- w--- O- M+ 
V-- PS++ PE-- Y++ PGP++ t+ 5-- !X !R tv-- b+++ !DI !D G+ e* h--- r++ y+(*)
#3 lore raw
Quoted 7 lines
Quoted 4 lines

I strongly disagree with the "void *" -> "char *" conversion in pure kernel headers, because the kernel is by definition geared towards gcc with most extensions (and void * arithmetic is one that makes sense).

I share this disagreemenent. However, if it's the only way we can make C++ apps use libiptc (for now), I am willing to pay this 'price'.

Fully agreed. I did not know about the "libiptc" connection.

Sorry for my intervention, Scott, your problem analysis and solution is completely appropriate.

Would you agree, Harald, and maybe work towards that goal, that a future new pkttables structure should have a clean seperation between kernel and userspace headers?

best regards
Patrick

#4 lore raw
In reply to Patrick Schaaf

Hi Patrick,

Quoted 9 lines · Patrick Schaaf
Quoted 2 lines

The header file ip_tables.h is included by the kernel and by user space programs so it should compile when using g++.

I don't understand why you arrive at this conclusion. ip_tables.h is in no way a valid documented user level API, and the fact that the existing iptables user level code base (all implemented in C) is including it, is a design error in the iptables userlevel - good style would be to copy those headers into the userlevel distribution, thus properly seperating kernel and userlevel headers.

Yes, you are probably right about the good style thing, but the changes you propose would be a much bigger (and more intrusive) patch than the small one I submitted.

Currently, the header file iptables-1.2.7a/include/libiptc/libiptc.h is intended to be used by user space programs. It even has the construct :

#ifdef __cplusplus
extern "C" {
#endif

in it which implies that header file was intended to compile using g++.

The header libiptc.h pulls in ip_tables.h from the kernel and this is where the compile error occurs. I agree with your comment that the header files should be restructured into kernel and user-space sections, and I am prepared to do this, but would the patch be accepted ? I am not sure. This task sounds like it would have to be done by one of the netfilter core developers. Am I wrong?

Quoted 6 lines

A future userlevel C++ API to iptables would indeed need to concern itself with such things - but there is no such thing in existence (and I don't know whether it is under consideration to have a C++ callable API).

I am currently creating a C++ user level library for iptables using g++ and the STL. This is how I came across the problem !!!

Quoted 5 lines

I strongly disagree with the "void *" -> "char *" conversion in pure kernel headers, because the kernel is by definition geared towards gcc with most extensions (and void * arithmetic is one that makes sense).

Yes, it seems as though a lot of kernel developers feel this way, OH well. Actually, I just want my compile problem fixed and I am prepared to help do the work, what ever way it is done.

Quoted 3 lines

best regards
Patrick

Regards,

Scott.