Skip to content

Commit af0a248

Browse files
committed
Merge git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next
Pablo Neira Ayuso says: ==================== Netfilter updates for net-next The following patchset contains Netfilter updates for net-next to extend ctnetlink and the flowtable infrastructure: 1) Extend ctnetlink kernel side netlink dump filtering capabilities, from Romain Bellan. 2) Generalise the flowtable hook parser to take a hook list. 3) Pass a hook list to the flowtable hook registration/unregistration. 4) Add a helper function to release the flowtable hook list. 5) Update the flowtable event notifier to pass a flowtable hook list. 6) Allow users to add new devices to an existing flowtables. 7) Allow users to remove devices to an existing flowtables. 8) Allow for registering a flowtable with no initial devices. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents a74d19b + 5b6743f commit af0a248

9 files changed

Lines changed: 670 additions & 137 deletions

File tree

‎include/net/netfilter/nf_conntrack_l4proto.h‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ struct nf_conntrack_l4proto {
4242
/* Calculate tuple nlattr size */
4343
unsigned int (*nlattr_tuple_size)(void);
4444
int (*nlattr_to_tuple)(struct nlattr *tb[],
45-
struct nf_conntrack_tuple *t);
45+
struct nf_conntrack_tuple *t,
46+
u_int32_t flags);
4647
const struct nla_policy *nla_policy;
4748

4849
struct {
@@ -152,7 +153,8 @@ const struct nf_conntrack_l4proto *nf_ct_l4proto_find(u8 l4proto);
152153
int nf_ct_port_tuple_to_nlattr(struct sk_buff *skb,
153154
const struct nf_conntrack_tuple *tuple);
154155
int nf_ct_port_nlattr_to_tuple(struct nlattr *tb[],
155-
struct nf_conntrack_tuple *t);
156+
struct nf_conntrack_tuple *t,
157+
u_int32_t flags);
156158
unsigned int nf_ct_port_nlattr_tuple_size(void);
157159
extern const struct nla_policy nf_ct_port_nla_policy[];
158160

‎include/net/netfilter/nf_tables.h‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,6 +1002,7 @@ struct nft_stats {
10021002

10031003
struct nft_hook {
10041004
struct list_head list;
1005+
bool inactive;
10051006
struct nf_hook_ops ops;
10061007
struct rcu_head rcu;
10071008
};
@@ -1481,10 +1482,16 @@ struct nft_trans_obj {
14811482

14821483
struct nft_trans_flowtable {
14831484
struct nft_flowtable *flowtable;
1485+
bool update;
1486+
struct list_head hook_list;
14841487
};
14851488

14861489
#define nft_trans_flowtable(trans) \
14871490
(((struct nft_trans_flowtable *)trans->data)->flowtable)
1491+
#define nft_trans_flowtable_update(trans) \
1492+
(((struct nft_trans_flowtable *)trans->data)->update)
1493+
#define nft_trans_flowtable_hooks(trans) \
1494+
(((struct nft_trans_flowtable *)trans->data)->hook_list)
14881495

14891496
int __init nft_chain_filter_init(void);
14901497
void nft_chain_filter_fini(void);

‎include/uapi/linux/netfilter/nfnetlink_conntrack.h‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ enum ctattr_type {
5555
CTA_LABELS,
5656
CTA_LABELS_MASK,
5757
CTA_SYNPROXY,
58+
CTA_FILTER,
5859
__CTA_MAX
5960
};
6061
#define CTA_MAX (__CTA_MAX - 1)
@@ -276,4 +277,12 @@ enum ctattr_expect_stats {
276277
};
277278
#define CTA_STATS_EXP_MAX (__CTA_STATS_EXP_MAX - 1)
278279

280+
enum ctattr_filter {
281+
CTA_FILTER_UNSPEC,
282+
CTA_FILTER_ORIG_FLAGS,
283+
CTA_FILTER_REPLY_FLAGS,
284+
__CTA_FILTER_MAX
285+
};
286+
#define CTA_FILTER_MAX (__CTA_FILTER_MAX - 1)
287+
279288
#endif /* _IPCONNTRACK_NETLINK_H */

‎net/netfilter/nf_conntrack_core.c‎

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1974,13 +1974,22 @@ const struct nla_policy nf_ct_port_nla_policy[CTA_PROTO_MAX+1] = {
19741974
EXPORT_SYMBOL_GPL(nf_ct_port_nla_policy);
19751975

19761976
int nf_ct_port_nlattr_to_tuple(struct nlattr *tb[],
1977-
struct nf_conntrack_tuple *t)
1977+
struct nf_conntrack_tuple *t,
1978+
u_int32_t flags)
19781979
{
1979-
if (!tb[CTA_PROTO_SRC_PORT] || !tb[CTA_PROTO_DST_PORT])
1980-
return -EINVAL;
1980+
if (flags & CTA_FILTER_FLAG(CTA_PROTO_SRC_PORT)) {
1981+
if (!tb[CTA_PROTO_SRC_PORT])
1982+
return -EINVAL;
1983+
1984+
t->src.u.tcp.port = nla_get_be16(tb[CTA_PROTO_SRC_PORT]);
1985+
}
19811986

1982-
t->src.u.tcp.port = nla_get_be16(tb[CTA_PROTO_SRC_PORT]);
1983-
t->dst.u.tcp.port = nla_get_be16(tb[CTA_PROTO_DST_PORT]);
1987+
if (flags & CTA_FILTER_FLAG(CTA_PROTO_DST_PORT)) {
1988+
if (!tb[CTA_PROTO_DST_PORT])
1989+
return -EINVAL;
1990+
1991+
t->dst.u.tcp.port = nla_get_be16(tb[CTA_PROTO_DST_PORT]);
1992+
}
19841993

19851994
return 0;
19861995
}

0 commit comments

Comments
 (0)