From 8c88b695289c1f3fca604a30e3ca59dd1c957377 Mon Sep 17 00:00:00 2001 From: Pablo Neira Ayuso Date: Sun, 31 Jan 2010 16:50:48 +0100 Subject: conntrackd: cleanup port addition in the message building path This patch move the ports addition to the layer 4 functions, instead of checking for the port attribute. It also add a function for UDP otherwise we break support for this protocol. Signed-off-by: Pablo Neira Ayuso --- src/build.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'src/build.c') diff --git a/src/build.c b/src/build.c index 0bfe8c1..a73476a 100644 --- a/src/build.c +++ b/src/build.c @@ -99,6 +99,9 @@ static enum nf_conntrack_attr nat_type[] = static void build_l4proto_tcp(const struct nf_conntrack *ct, struct nethdr *n) { + __build_group(ct, ATTR_GRP_ORIG_PORT, n, NTA_PORT, + sizeof(struct nfct_attr_grp_port)); + if (!nfct_attr_is_set(ct, ATTR_TCP_STATE)) return; @@ -111,6 +114,9 @@ static void build_l4proto_tcp(const struct nf_conntrack *ct, struct nethdr *n) static void build_l4proto_sctp(const struct nf_conntrack *ct, struct nethdr *n) { + __build_group(ct, ATTR_GRP_ORIG_PORT, n, NTA_PORT, + sizeof(struct nfct_attr_grp_port)); + if (!nfct_attr_is_set(ct, ATTR_SCTP_STATE)) return; @@ -121,6 +127,9 @@ static void build_l4proto_sctp(const struct nf_conntrack *ct, struct nethdr *n) static void build_l4proto_dccp(const struct nf_conntrack *ct, struct nethdr *n) { + __build_group(ct, ATTR_GRP_ORIG_PORT, n, NTA_PORT, + sizeof(struct nfct_attr_grp_port)); + if (!nfct_attr_is_set(ct, ATTR_DCCP_STATE)) return; @@ -135,6 +144,12 @@ static void build_l4proto_icmp(const struct nf_conntrack *ct, struct nethdr *n) __build_u16(ct, ATTR_ICMP_ID, n, NTA_ICMP_ID); } +static void build_l4proto_udp(const struct nf_conntrack *ct, struct nethdr *n) +{ + __build_group(ct, ATTR_GRP_ORIG_PORT, n, NTA_PORT, + sizeof(struct nfct_attr_grp_port)); +} + #ifndef IPPROTO_DCCP #define IPPROTO_DCCP 33 #endif @@ -146,6 +161,7 @@ static struct build_l4proto { [IPPROTO_SCTP] = { .build = build_l4proto_sctp }, [IPPROTO_DCCP] = { .build = build_l4proto_dccp }, [IPPROTO_ICMP] = { .build = build_l4proto_icmp }, + [IPPROTO_UDP] = { .build = build_l4proto_udp }, }; void build_payload(const struct nf_conntrack *ct, struct nethdr *n) @@ -160,13 +176,8 @@ void build_payload(const struct nf_conntrack *ct, struct nethdr *n) sizeof(struct nfct_attr_grp_ipv6)); } - __build_u8(ct, ATTR_L4PROTO, n, NTA_L4PROTO); - if (nfct_attr_grp_is_set(ct, ATTR_GRP_ORIG_PORT)) { - __build_group(ct, ATTR_GRP_ORIG_PORT, n, NTA_PORT, - sizeof(struct nfct_attr_grp_port)); - } - __build_u32(ct, ATTR_STATUS, n, NTA_STATUS); + __build_u8(ct, ATTR_L4PROTO, n, NTA_L4PROTO); if (l4proto_fcn[l4proto].build) l4proto_fcn[l4proto].build(ct, n); -- cgit v1.2.3