Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 22866
b: refs/heads/master
c: 1cde643
h: refs/heads/master
v: v3
  • Loading branch information
Pablo Neira Ayuso authored and David S. Miller committed Mar 22, 2006
1 parent bcf3b2c commit 819aea5
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 40 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 50b521aa54f415a626bfd63d1a9b72120e9fbe88
refs/heads/master: 1cde64365b0c4f576f8f45b834e6a6de081b5914
72 changes: 55 additions & 17 deletions trunk/net/ipv4/netfilter/ip_conntrack_netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* (C) 2001 by Jay Schulist <jschlst@samba.org>
* (C) 2002-2005 by Harald Welte <laforge@gnumonks.org>
* (C) 2003 by Patrick Mchardy <kaber@trash.net>
* (C) 2005 by Pablo Neira Ayuso <pablo@eurodev.net>
* (C) 2005-2006 by Pablo Neira Ayuso <pablo@eurodev.net>
*
* I've reworked this stuff to use attributes instead of conntrack
* structures. 5.44 am. I need more tea. --pablo 05/07/11.
Expand Down Expand Up @@ -53,20 +53,18 @@ static char __initdata version[] = "0.90";

static inline int
ctnetlink_dump_tuples_proto(struct sk_buff *skb,
const struct ip_conntrack_tuple *tuple)
const struct ip_conntrack_tuple *tuple,
struct ip_conntrack_protocol *proto)
{
struct ip_conntrack_protocol *proto;
int ret = 0;
struct nfattr *nest_parms = NFA_NEST(skb, CTA_TUPLE_PROTO);

NFA_PUT(skb, CTA_PROTO_NUM, sizeof(u_int8_t), &tuple->dst.protonum);

/* If no protocol helper is found, this function will return the
* generic protocol helper, so proto won't *ever* be NULL */
proto = ip_conntrack_proto_find_get(tuple->dst.protonum);
if (likely(proto->tuple_to_nfattr))
ret = proto->tuple_to_nfattr(skb, tuple);

ip_conntrack_proto_put(proto);
NFA_NEST_END(skb, nest_parms);

return ret;

Expand All @@ -75,27 +73,40 @@ ctnetlink_dump_tuples_proto(struct sk_buff *skb,
}

static inline int
ctnetlink_dump_tuples(struct sk_buff *skb,
const struct ip_conntrack_tuple *tuple)
ctnetlink_dump_tuples_ip(struct sk_buff *skb,
const struct ip_conntrack_tuple *tuple)
{
struct nfattr *nest_parms;
int ret;
struct nfattr *nest_parms = NFA_NEST(skb, CTA_TUPLE_IP);

nest_parms = NFA_NEST(skb, CTA_TUPLE_IP);
NFA_PUT(skb, CTA_IP_V4_SRC, sizeof(u_int32_t), &tuple->src.ip);
NFA_PUT(skb, CTA_IP_V4_DST, sizeof(u_int32_t), &tuple->dst.ip);
NFA_NEST_END(skb, nest_parms);

nest_parms = NFA_NEST(skb, CTA_TUPLE_PROTO);
ret = ctnetlink_dump_tuples_proto(skb, tuple);
NFA_NEST_END(skb, nest_parms);

return ret;
return 0;

nfattr_failure:
return -1;
}

static inline int
ctnetlink_dump_tuples(struct sk_buff *skb,
const struct ip_conntrack_tuple *tuple)
{
int ret;
struct ip_conntrack_protocol *proto;

ret = ctnetlink_dump_tuples_ip(skb, tuple);
if (unlikely(ret < 0))
return ret;

proto = ip_conntrack_proto_find_get(tuple->dst.protonum);
ret = ctnetlink_dump_tuples_proto(skb, tuple, proto);
ip_conntrack_proto_put(proto);

return ret;
}

static inline int
ctnetlink_dump_status(struct sk_buff *skb, const struct ip_conntrack *ct)
{
Expand Down Expand Up @@ -1134,6 +1145,33 @@ ctnetlink_exp_dump_tuple(struct sk_buff *skb,
return -1;
}

static inline int
ctnetlink_exp_dump_mask(struct sk_buff *skb,
const struct ip_conntrack_tuple *tuple,
const struct ip_conntrack_tuple *mask)
{
int ret;
struct ip_conntrack_protocol *proto;
struct nfattr *nest_parms = NFA_NEST(skb, CTA_EXPECT_MASK);

ret = ctnetlink_dump_tuples_ip(skb, mask);
if (unlikely(ret < 0))
goto nfattr_failure;

proto = ip_conntrack_proto_find_get(tuple->dst.protonum);
ret = ctnetlink_dump_tuples_proto(skb, mask, proto);
ip_conntrack_proto_put(proto);
if (unlikely(ret < 0))
goto nfattr_failure;

NFA_NEST_END(skb, nest_parms);

return 0;

nfattr_failure:
return -1;
}

static inline int
ctnetlink_exp_dump_expect(struct sk_buff *skb,
const struct ip_conntrack_expect *exp)
Expand All @@ -1144,7 +1182,7 @@ ctnetlink_exp_dump_expect(struct sk_buff *skb,

if (ctnetlink_exp_dump_tuple(skb, &exp->tuple, CTA_EXPECT_TUPLE) < 0)
goto nfattr_failure;
if (ctnetlink_exp_dump_tuple(skb, &exp->mask, CTA_EXPECT_MASK) < 0)
if (ctnetlink_exp_dump_mask(skb, &exp->tuple, &exp->mask) < 0)
goto nfattr_failure;
if (ctnetlink_exp_dump_tuple(skb,
&master->tuplehash[IP_CT_DIR_ORIGINAL].tuple,
Expand Down
84 changes: 62 additions & 22 deletions trunk/net/netfilter/nf_conntrack_netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* (C) 2001 by Jay Schulist <jschlst@samba.org>
* (C) 2002-2006 by Harald Welte <laforge@gnumonks.org>
* (C) 2003 by Patrick Mchardy <kaber@trash.net>
* (C) 2005 by Pablo Neira Ayuso <pablo@eurodev.net>
* (C) 2005-2006 by Pablo Neira Ayuso <pablo@eurodev.net>
*
* I've reworked this stuff to use attributes instead of conntrack
* structures. 5.44 am. I need more tea. --pablo 05/07/11.
Expand Down Expand Up @@ -55,20 +55,18 @@ static char __initdata version[] = "0.93";

static inline int
ctnetlink_dump_tuples_proto(struct sk_buff *skb,
const struct nf_conntrack_tuple *tuple)
const struct nf_conntrack_tuple *tuple,
struct nf_conntrack_protocol *proto)
{
struct nf_conntrack_protocol *proto;
int ret = 0;
struct nfattr *nest_parms = NFA_NEST(skb, CTA_TUPLE_PROTO);

NFA_PUT(skb, CTA_PROTO_NUM, sizeof(u_int8_t), &tuple->dst.protonum);

/* If no protocol helper is found, this function will return the
* generic protocol helper, so proto won't *ever* be NULL */
proto = nf_ct_proto_find_get(tuple->src.l3num, tuple->dst.protonum);
if (likely(proto->tuple_to_nfattr))
ret = proto->tuple_to_nfattr(skb, tuple);

nf_ct_proto_put(proto);
NFA_NEST_END(skb, nest_parms);

return ret;

Expand All @@ -77,33 +75,44 @@ ctnetlink_dump_tuples_proto(struct sk_buff *skb,
}

static inline int
ctnetlink_dump_tuples(struct sk_buff *skb,
const struct nf_conntrack_tuple *tuple)
ctnetlink_dump_tuples_ip(struct sk_buff *skb,
const struct nf_conntrack_tuple *tuple,
struct nf_conntrack_l3proto *l3proto)
{
struct nfattr *nest_parms;
struct nf_conntrack_l3proto *l3proto;
int ret = 0;

l3proto = nf_ct_l3proto_find_get(tuple->src.l3num);

nest_parms = NFA_NEST(skb, CTA_TUPLE_IP);
struct nfattr *nest_parms = NFA_NEST(skb, CTA_TUPLE_IP);

if (likely(l3proto->tuple_to_nfattr))
ret = l3proto->tuple_to_nfattr(skb, tuple);

NFA_NEST_END(skb, nest_parms);

return ret;

nfattr_failure:
return -1;
}

static inline int
ctnetlink_dump_tuples(struct sk_buff *skb,
const struct nf_conntrack_tuple *tuple)
{
int ret;
struct nf_conntrack_l3proto *l3proto;
struct nf_conntrack_protocol *proto;

l3proto = nf_ct_l3proto_find_get(tuple->src.l3num);
ret = ctnetlink_dump_tuples_ip(skb, tuple, l3proto);
nf_ct_l3proto_put(l3proto);

if (unlikely(ret < 0))
return ret;

nest_parms = NFA_NEST(skb, CTA_TUPLE_PROTO);
ret = ctnetlink_dump_tuples_proto(skb, tuple);
NFA_NEST_END(skb, nest_parms);
proto = nf_ct_proto_find_get(tuple->src.l3num, tuple->dst.protonum);
ret = ctnetlink_dump_tuples_proto(skb, tuple, proto);
nf_ct_proto_put(proto);

return ret;

nfattr_failure:
return -1;
}

static inline int
Expand Down Expand Up @@ -1152,6 +1161,37 @@ ctnetlink_exp_dump_tuple(struct sk_buff *skb,
return -1;
}

static inline int
ctnetlink_exp_dump_mask(struct sk_buff *skb,
const struct nf_conntrack_tuple *tuple,
const struct nf_conntrack_tuple *mask)
{
int ret;
struct nf_conntrack_l3proto *l3proto;
struct nf_conntrack_protocol *proto;
struct nfattr *nest_parms = NFA_NEST(skb, CTA_EXPECT_MASK);

l3proto = nf_ct_l3proto_find_get(tuple->src.l3num);
ret = ctnetlink_dump_tuples_ip(skb, mask, l3proto);
nf_ct_l3proto_put(l3proto);

if (unlikely(ret < 0))
goto nfattr_failure;

proto = nf_ct_proto_find_get(tuple->src.l3num, tuple->dst.protonum);
ret = ctnetlink_dump_tuples_proto(skb, mask, proto);
nf_ct_proto_put(proto);
if (unlikely(ret < 0))
goto nfattr_failure;

NFA_NEST_END(skb, nest_parms);

return 0;

nfattr_failure:
return -1;
}

static inline int
ctnetlink_exp_dump_expect(struct sk_buff *skb,
const struct nf_conntrack_expect *exp)
Expand All @@ -1162,7 +1202,7 @@ ctnetlink_exp_dump_expect(struct sk_buff *skb,

if (ctnetlink_exp_dump_tuple(skb, &exp->tuple, CTA_EXPECT_TUPLE) < 0)
goto nfattr_failure;
if (ctnetlink_exp_dump_tuple(skb, &exp->mask, CTA_EXPECT_MASK) < 0)
if (ctnetlink_exp_dump_mask(skb, &exp->tuple, &exp->mask) < 0)
goto nfattr_failure;
if (ctnetlink_exp_dump_tuple(skb,
&master->tuplehash[IP_CT_DIR_ORIGINAL].tuple,
Expand Down

0 comments on commit 819aea5

Please sign in to comment.