Skip to contentSkip to conversation

netfilter: install nf_nat.h and nf_conntrack_tuple.h to INSTALL_HDR_PATH

PATCH In review Anthony G. Basile 2 participants 6 messages Sep 9, 2011 – Sep 29, 2011 netfilter

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 netfilter: install nf_nat.h and nf_conntrack_tuple.h to INSTALL_HDR_PATH

From: "Anthony G. Basile" <[email protected]>

This exports sanitized versions of nf_nat.h, nf_conntrack_tuple.h for userland applications, like iptables and miniupnpd, which make use of binary representations of NAT in the kernel's netfilter API.

This patch makes these headers public by installing them in INSTALL_HDR_PATH.

See: https://bugs.gentoo.org/376873

---
 include/linux/netfilter/Kbuild               |    2 +
 include/linux/netfilter/nf_conntrack_tuple.h |  110 ++++++++++++++++++++++++++
 include/linux/netfilter/nf_nat.h             |   52 ++++++++++++
 3 files changed, 164 insertions(+), 0 deletions(-)
 create mode 100644 include/linux/netfilter/nf_conntrack_tuple.h
 create mode 100644 include/linux/netfilter/nf_nat.h
include/linux/netfilter/Kbuild +2 -0
index a1b410c..e9ee3eb 100644
@@ -5,6 +5,8 @@ header-y += nf_conntrack_ftp.h
 header-y += nf_conntrack_sctp.h
 header-y += nf_conntrack_tcp.h
 header-y += nf_conntrack_tuple_common.h
+header-y += nf_conntrack_tuple.h
+header-y += nf_nat.h
 header-y += nfnetlink.h
 header-y += nfnetlink_compat.h
 header-y += nfnetlink_conntrack.h
include/linux/netfilter/nf_conntrack_tuple.h new file +110 -0

110 lines not on this page · raw message

include/linux/netfilter/nf_nat.h new file +52 -0

52 lines not on this page · raw message

Signature · 1 line
1.7.6.1
#1 lore raw

Hi Anthony,

Thanks for taking the time to fix this. Some comments:

include/linux/netfilter/Kbuild header-y += nf_conntrack_ftp.h · line 8

Quoted 9 lines · Anthony G. Basile
include/linux/netfilter/Kbuild +1 -0
index a1b410c..e9ee3eb 100644
@@ -5,6 +5,8 @@ header-y += nf_conntrack_ftp.h
 header-y += nf_conntrack_sctp.h
 header-y += nf_conntrack_tcp.h
 header-y += nf_conntrack_tuple_common.h
+header-y += nf_conntrack_tuple.h

I think exporting nf_conntrack_tuple.h is too much, let me suggest some alternative.

Quoted 40 lines
include/linux/netfilter/Kbuild +1 -0
+header-y += nf_nat.h
 header-y += nfnetlink.h
 header-y += nfnetlink_compat.h
 header-y += nfnetlink_conntrack.h
include/linux/netfilter/nf_nat.h new file +30 -0
new file mode 100644
index 0000000..73c1946
@@ -0,0 +1,52 @@
+#ifndef _NF_NAT_H
+#define _NF_NAT_H
+#include <linux/netfilter_ipv4.h>
+#include <linux/netfilter/nf_conntrack_tuple.h>
+
+#define NF_NAT_MAPPING_TYPE_MAX_NAMELEN 16
+
+enum nf_nat_manip_type {
+	IP_NAT_MANIP_SRC,
+	IP_NAT_MANIP_DST
+};
+
+/* SRC manip occurs POST_ROUTING or LOCAL_IN */
+#define HOOK2MANIP(hooknum) ((hooknum) != NF_INET_POST_ROUTING && \
+			     (hooknum) != NF_INET_LOCAL_IN)
+
+#define IP_NAT_RANGE_MAP_IPS 1
+#define IP_NAT_RANGE_PROTO_SPECIFIED 2
+#define IP_NAT_RANGE_PROTO_RANDOM 4
+#define IP_NAT_RANGE_PERSISTENT 8
+
+/* NAT sequence number modifications */
+struct nf_nat_seq {
+	/* position of the last TCP sequence number modification (if any) */
+	u_int32_t correction_pos;
+
+	/* sequence number offset before and after last modification */
+	int16_t offset_before, offset_after;
+};
+

include/linux/netfilter/nf_nat.h line 40

Quoted 10 lines
include/linux/netfilter/nf_nat.h new file +10 -0
+/* Single range specification. */
+struct nf_nat_range {
+	/* Set to OR of flags above. */
+	unsigned int flags;
+
+	/* Inclusive: network order. */
+	__be32 min_ip, max_ip;
+
+	/* Inclusive: network order */
+	union nf_conntrack_man_proto min, max;

Better replace union nf_conntrack_man_proto by __be16, we don't break binary compatibility and we don't need to export the whole tuple definitions.

#2 lore raw
Quoted 6 lines · Pablo Neira Ayuso
Quoted 6 lines
include/linux/netfilter/nf_nat.h new file +6 -0
+/* Single range specification. */
+struct nf_nat_range {
+	/* Set to OR of flags above. */
+	unsigned int flags;
+
+	/* Inclusive: network order. */
Quoted 8 lines

include/linux/netfilter/nf_nat.h line 40

Quoted 4 lines
include/linux/netfilter/nf_nat.h new file +4 -0
+	__be32 min_ip, max_ip;
+
+	/* Inclusive: network order */
+	union nf_conntrack_man_proto min, max;

Better replace union nf_conntrack_man_proto by __be16, we don't break binary compatibility and we don't need to export the whole tuple definitions.

Hm, I just noticed that this will not work that easy.

git grep shows several NAT protocol helpers that rely on nf_conntrack_man_proto under net/ipv4/netfilter/, we need to change those as well to use the new definition of nf_nat_range.

I think I prefer the change that I'm proposing that exporting the whole nf_conntrack_tuple.h header file.

#3 lore raw
Quoted 16 lines · Pablo Neira Ayuso
Quoted 6 lines · Pablo Neira Ayuso
Quoted 6 lines
include/linux/netfilter/nf_nat.h new file +6 -0
+/* Single range specification. */
+struct nf_nat_range {
+	/* Set to OR of flags above. */
+	unsigned int flags;
+
+	/* Inclusive: network order. */
Quoted 8 lines

include/linux/netfilter/nf_nat.h line 40

Quoted 4 lines
include/linux/netfilter/nf_nat.h new file +4 -0
+	__be32 min_ip, max_ip;
+
+	/* Inclusive: network order */
+	union nf_conntrack_man_proto min, max;

Better replace union nf_conntrack_man_proto by __be16, we don't break binary compatibility and we don't need to export the whole tuple definitions.

Quoted 8 lines

Hm, I just noticed that this will not work that easy.

git grep shows several NAT protocol helpers that rely on nf_conntrack_man_proto under net/ipv4/netfilter/, we need to change those as well to use the new definition of nf_nat_range.

I think I prefer the change that I'm proposing that exporting the whole nf_conntrack_tuple.h header file.

Sorry for the delay in responding, real life.

What I did in that last patch was just grab nf_nat.h and nf_contrack_tupple.h from iptables source tree at include/net/netfilter plus minor changes. I didn't look for the minimum of what iptables and miniupnpd need.

Here's a possibility that works, move nf_conntrack_man_proto to nf_nat.h and only export that header with:

    #define IP_NAT_RANGE_MAP_IPS 1
    ...

    union nf_conntrack_man_proto {
        __be16 all;
        struct { __be16 port } tcp;
        ...
    }

    struct nf_nat_range {
        ...
        union nf_conntrack_man_proto min, max;
    };

    struct nf_nat_multi_range_compat { ... }

    #define nf_nat_multi_range nf_nat_multi_range_compat

This is the minimum that iptables and miniupnpd need to compile.

Does this look like a workable solution?

Signature · 5 lines
Anthony G. Basile, Ph. D.
Chair of Information Technology
D'Youville College
Buffalo, NY 14201
(716) 829-8197
#4 lore raw
Quoted 9 lines · Anthony G. Basile

Sorry for the delay in responding, real life.

What I did in that last patch was just grab nf_nat.h and nf_contrack_tupple.h from iptables source tree at include/net/netfilter plus minor changes. I didn't look for the minimum of what iptables and miniupnpd need.

Here's a possibility that works, move nf_conntrack_man_proto to nf_nat.h and only export that header with:

I guess, you mean the new include/linux/netfilter/nf_nat.h file, right?

Quoted 8 lines
    #define IP_NAT_RANGE_MAP_IPS 1
    ...

    union nf_conntrack_man_proto {
        __be16 all;
        struct { __be16 port } tcp;
        ...
    }

If you want to keep the "port" field, I'd prefer something like:

union nf_conntrack_man_proto {
        __be16 port;
        __be16 icmp_id;
        __be16 gre_key;
};

And propagate the changes to the corresponding .c files.

Quoted 9 lines
    struct nf_nat_range {
        ...
        union nf_conntrack_man_proto min, max;
    };

    struct nf_nat_multi_range_compat { ... }

    #define nf_nat_multi_range nf_nat_multi_range_compat
Quoted 3 lines

This is the minimum that iptables and miniupnpd need to compile.

Does this look like a workable solution?

Close to it, but please change union nf_conntrack_man_proto to what I suggested.

Thanks!

#5 lore raw
Quoted 8 lines · Pablo Neira Ayuso
Quoted 7 lines · Anthony G. Basile

Sorry for the delay in responding, real life.

What I did in that last patch was just grab nf_nat.h and nf_contrack_tupple.h from iptables source tree at include/net/netfilter plus minor changes. I didn't look for the minimum of what iptables and miniupnpd need.

Quoted 4 lines
Quoted 2 lines

Here's a possibility that works, move nf_conntrack_man_proto to nf_nat.h and only export that header with:

I guess, you mean the new include/linux/netfilter/nf_nat.h file, right?

Yes, that's what I meant.

Quoted 12 lines
Quoted 9 lines
    #define IP_NAT_RANGE_MAP_IPS 1
    ...

    union nf_conntrack_man_proto {
        __be16 all;
        struct { __be16 port } tcp;
        ...
    }

If you want to keep the "port" field, I'd prefer something like:

Quoted 8 lines
union nf_conntrack_man_proto {
        __be16 port;
        __be16 icmp_id;
        __be16 gre_key;
};

And propagate the changes to the corresponding .c files.

Got it.

Quoted 7 lines
Quoted 7 lines
    struct nf_nat_range {
        ...
        union nf_conntrack_man_proto min, max;
    };

    struct nf_nat_multi_range_compat { ... }
Quoted 8 lines
Quoted 5 lines
    #define nf_nat_multi_range nf_nat_multi_range_compat

This is the minimum that iptables and miniupnpd need to compile.

Does this look like a workable solution?

Close to it, but please change union nf_conntrack_man_proto to what I suggested.

Yep. I like it too. I'll make the changes, make sure kernel land is okay, test iptables and miniupnpd against it and then resubmit.

Signature · 5 lines
Anthony G. Basile, Ph. D.
Chair of Information Technology
D'Youville College
Buffalo, NY 14201
(716) 829-8197