Skip to content

Commit 9f0e896

Browse files
committed
Merge git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next
Pablo Neira Ayuso says: ==================== Netfilter/IPVS updates for net-next The following patchset contains Netfilter/IPVS updates for your net-next tree: 1) Free hooks via call_rcu to speed up netns release path, from Florian Westphal. 2) Reduce memory footprint of hook arrays, skip allocation if family is not present - useful in case decnet support is not compiled built-in. Patches from Florian Westphal. 3) Remove defensive check for malformed IPv4 - including ihl field - and IPv6 headers in x_tables and nf_tables. 4) Add generic flow table offload infrastructure for nf_tables, this includes the netlink control plane and support for IPv4, IPv6 and mixed IPv4/IPv6 dataplanes. This comes with NAT support too. This patchset adds the IPS_OFFLOAD conntrack status bit to indicate that this flow has been offloaded. 5) Add secpath matching support for nf_tables, from Florian. 6) Save some code bytes in the fast path for the nf_tables netdev, bridge and inet families. 7) Allow one single NAT hook per point and do not allow to register NAT hooks in nf_tables before the conntrack hook, patches from Florian. 8) Seven patches to remove the struct nf_af_info abstraction, instead we perform direct calls for IPv4 which is faster. IPv6 indirections are still needed to avoid dependencies with the 'ipv6' module, but these now reside in struct nf_ipv6_ops. 9) Seven patches to handle NFPROTO_INET from the Netfilter core, hence we can remove specific code in nf_tables to handle this pseudofamily. 10) No need for synchronize_net() call for nf_queue after conversion to hook arrays. Also from Florian. 11) Call cond_resched_rcu() when dumping large sets in ipset to avoid softlockup. Again from Florian. 12) Pass lockdep_nfnl_is_held() to rcu_dereference_protected(), patch from Florian Westphal. 13) Fix matching of counters in ipset, from Jozsef Kadlecsik. 14) Missing nfnl lock protection in the ip_set_net_exit path, also from Jozsef. 15) Move connlimit code that we can reuse from nf_tables into nf_conncount, from Florian Westhal. And asorted cleanups: 16) Get rid of nft_dereference(), it only has one single caller. 17) Add nft_set_is_anonymous() helper function. 18) Remove NF_ARP_FORWARD leftover chain definition in nf_tables_arp. 19) Remove unnecessary comments in nf_conntrack_h323_asn1.c From Varsha Rao. 20) Remove useless parameters in frag_safe_skb_hp(), from Gao Feng. 21) Constify layer 4 conntrack protocol definitions, function parameters to register/unregister these protocol trackers, and timeouts. Patches from Florian Westphal. 22) Remove nlattr_size indirection, from Florian Westphal. 23) Add fall-through comments as -Wimplicit-fallthrough needs this, from Gustavo A. R. Silva. 24) Use swap() macro to exchange values in ipset, patch from Gustavo A. R. Silva. ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 0c3b34d + f998b6b commit 9f0e896

File tree

108 files changed

+3853
-1403
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

108 files changed

+3853
-1403
lines changed

include/linux/netfilter.h

Lines changed: 53 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ struct nf_hook_ops {
6767
struct net_device *dev;
6868
void *priv;
6969
u_int8_t pf;
70+
bool nat_hook;
7071
unsigned int hooknum;
7172
/* Hooks are ordered in ascending priority. */
7273
int priority;
@@ -77,17 +78,28 @@ struct nf_hook_entry {
7778
void *priv;
7879
};
7980

81+
struct nf_hook_entries_rcu_head {
82+
struct rcu_head head;
83+
void *allocation;
84+
};
85+
8086
struct nf_hook_entries {
8187
u16 num_hook_entries;
8288
/* padding */
8389
struct nf_hook_entry hooks[];
8490

85-
/* trailer: pointers to original orig_ops of each hook.
86-
*
87-
* This is not part of struct nf_hook_entry since its only
88-
* needed in slow path (hook register/unregister).
91+
/* trailer: pointers to original orig_ops of each hook,
92+
* followed by rcu_head and scratch space used for freeing
93+
* the structure via call_rcu.
8994
*
95+
* This is not part of struct nf_hook_entry since its only
96+
* needed in slow path (hook register/unregister):
9097
* const struct nf_hook_ops *orig_ops[]
98+
*
99+
* For the same reason, we store this at end -- its
100+
* only needed when a hook is deleted, not during
101+
* packet path processing:
102+
* struct nf_hook_entries_rcu_head head
91103
*/
92104
};
93105

@@ -184,7 +196,7 @@ static inline int nf_hook(u_int8_t pf, unsigned int hook, struct net *net,
184196
struct net_device *indev, struct net_device *outdev,
185197
int (*okfn)(struct net *, struct sock *, struct sk_buff *))
186198
{
187-
struct nf_hook_entries *hook_head;
199+
struct nf_hook_entries *hook_head = NULL;
188200
int ret = 1;
189201

190202
#ifdef HAVE_JUMP_LABEL
@@ -195,7 +207,33 @@ static inline int nf_hook(u_int8_t pf, unsigned int hook, struct net *net,
195207
#endif
196208

197209
rcu_read_lock();
198-
hook_head = rcu_dereference(net->nf.hooks[pf][hook]);
210+
switch (pf) {
211+
case NFPROTO_IPV4:
212+
hook_head = rcu_dereference(net->nf.hooks_ipv4[hook]);
213+
break;
214+
case NFPROTO_IPV6:
215+
hook_head = rcu_dereference(net->nf.hooks_ipv6[hook]);
216+
break;
217+
case NFPROTO_ARP:
218+
#ifdef CONFIG_NETFILTER_FAMILY_ARP
219+
hook_head = rcu_dereference(net->nf.hooks_arp[hook]);
220+
#endif
221+
break;
222+
case NFPROTO_BRIDGE:
223+
#ifdef CONFIG_NETFILTER_FAMILY_BRIDGE
224+
hook_head = rcu_dereference(net->nf.hooks_bridge[hook]);
225+
#endif
226+
break;
227+
#if IS_ENABLED(CONFIG_DECNET)
228+
case NFPROTO_DECNET:
229+
hook_head = rcu_dereference(net->nf.hooks_decnet[hook]);
230+
break;
231+
#endif
232+
default:
233+
WARN_ON_ONCE(1);
234+
break;
235+
}
236+
199237
if (hook_head) {
200238
struct nf_hook_state state;
201239

@@ -271,64 +309,16 @@ int skb_make_writable(struct sk_buff *skb, unsigned int writable_len);
271309
struct flowi;
272310
struct nf_queue_entry;
273311

274-
struct nf_afinfo {
275-
unsigned short family;
276-
__sum16 (*checksum)(struct sk_buff *skb, unsigned int hook,
277-
unsigned int dataoff, u_int8_t protocol);
278-
__sum16 (*checksum_partial)(struct sk_buff *skb,
279-
unsigned int hook,
280-
unsigned int dataoff,
281-
unsigned int len,
282-
u_int8_t protocol);
283-
int (*route)(struct net *net, struct dst_entry **dst,
284-
struct flowi *fl, bool strict);
285-
void (*saveroute)(const struct sk_buff *skb,
286-
struct nf_queue_entry *entry);
287-
int (*reroute)(struct net *net, struct sk_buff *skb,
288-
const struct nf_queue_entry *entry);
289-
int route_key_size;
290-
};
291-
292-
extern const struct nf_afinfo __rcu *nf_afinfo[NFPROTO_NUMPROTO];
293-
static inline const struct nf_afinfo *nf_get_afinfo(unsigned short family)
294-
{
295-
return rcu_dereference(nf_afinfo[family]);
296-
}
297-
298-
static inline __sum16
299-
nf_checksum(struct sk_buff *skb, unsigned int hook, unsigned int dataoff,
300-
u_int8_t protocol, unsigned short family)
301-
{
302-
const struct nf_afinfo *afinfo;
303-
__sum16 csum = 0;
304-
305-
rcu_read_lock();
306-
afinfo = nf_get_afinfo(family);
307-
if (afinfo)
308-
csum = afinfo->checksum(skb, hook, dataoff, protocol);
309-
rcu_read_unlock();
310-
return csum;
311-
}
312-
313-
static inline __sum16
314-
nf_checksum_partial(struct sk_buff *skb, unsigned int hook,
315-
unsigned int dataoff, unsigned int len,
316-
u_int8_t protocol, unsigned short family)
317-
{
318-
const struct nf_afinfo *afinfo;
319-
__sum16 csum = 0;
320-
321-
rcu_read_lock();
322-
afinfo = nf_get_afinfo(family);
323-
if (afinfo)
324-
csum = afinfo->checksum_partial(skb, hook, dataoff, len,
325-
protocol);
326-
rcu_read_unlock();
327-
return csum;
328-
}
312+
__sum16 nf_checksum(struct sk_buff *skb, unsigned int hook,
313+
unsigned int dataoff, u_int8_t protocol,
314+
unsigned short family);
329315

330-
int nf_register_afinfo(const struct nf_afinfo *afinfo);
331-
void nf_unregister_afinfo(const struct nf_afinfo *afinfo);
316+
__sum16 nf_checksum_partial(struct sk_buff *skb, unsigned int hook,
317+
unsigned int dataoff, unsigned int len,
318+
u_int8_t protocol, unsigned short family);
319+
int nf_route(struct net *net, struct dst_entry **dst, struct flowi *fl,
320+
bool strict, unsigned short family);
321+
int nf_reroute(struct sk_buff *skb, struct nf_queue_entry *entry);
332322

333323
#include <net/flow.h>
334324
extern void (*nf_nat_decode_session_hook)(struct sk_buff *, struct flowi *);

include/linux/netfilter/ipset/ip_set.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ struct ip_set_ext {
122122
u64 bytes;
123123
char *comment;
124124
u32 timeout;
125+
u8 packets_op;
126+
u8 bytes_op;
125127
};
126128

127129
struct ip_set;
@@ -339,6 +341,10 @@ extern int ip_set_get_extensions(struct ip_set *set, struct nlattr *tb[],
339341
struct ip_set_ext *ext);
340342
extern int ip_set_put_extensions(struct sk_buff *skb, const struct ip_set *set,
341343
const void *e, bool active);
344+
extern bool ip_set_match_extensions(struct ip_set *set,
345+
const struct ip_set_ext *ext,
346+
struct ip_set_ext *mext,
347+
u32 flags, void *data);
342348

343349
static inline int
344350
ip_set_get_hostipaddr4(struct nlattr *nla, u32 *ipaddr)

include/linux/netfilter/ipset/ip_set_counter.h

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,33 @@ ip_set_get_packets(const struct ip_set_counter *counter)
3434
return (u64)atomic64_read(&(counter)->packets);
3535
}
3636

37+
static inline bool
38+
ip_set_match_counter(u64 counter, u64 match, u8 op)
39+
{
40+
switch (op) {
41+
case IPSET_COUNTER_NONE:
42+
return true;
43+
case IPSET_COUNTER_EQ:
44+
return counter == match;
45+
case IPSET_COUNTER_NE:
46+
return counter != match;
47+
case IPSET_COUNTER_LT:
48+
return counter < match;
49+
case IPSET_COUNTER_GT:
50+
return counter > match;
51+
}
52+
return false;
53+
}
54+
3755
static inline void
3856
ip_set_update_counter(struct ip_set_counter *counter,
39-
const struct ip_set_ext *ext,
40-
struct ip_set_ext *mext, u32 flags)
57+
const struct ip_set_ext *ext, u32 flags)
4158
{
4259
if (ext->packets != ULLONG_MAX &&
4360
!(flags & IPSET_FLAG_SKIP_COUNTER_UPDATE)) {
4461
ip_set_add_bytes(ext->bytes, counter);
4562
ip_set_add_packets(ext->packets, counter);
4663
}
47-
if (flags & IPSET_FLAG_MATCH_COUNTERS) {
48-
mext->packets = ip_set_get_packets(counter);
49-
mext->bytes = ip_set_get_bytes(counter);
50-
}
5164
}
5265

5366
static inline bool

include/linux/netfilter/x_tables.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,8 @@ int xt_find_revision(u8 af, const char *name, u8 revision, int target,
320320

321321
struct xt_table *xt_find_table_lock(struct net *net, u_int8_t af,
322322
const char *name);
323+
struct xt_table *xt_request_find_table_lock(struct net *net, u_int8_t af,
324+
const char *name);
323325
void xt_table_unlock(struct xt_table *t);
324326

325327
int xt_proto_init(struct net *net, u_int8_t af);

include/linux/netfilter_defs.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,17 @@
44

55
#include <uapi/linux/netfilter.h>
66

7+
/* in/out/forward only */
8+
#define NF_ARP_NUMHOOKS 3
9+
10+
/* max hook is NF_DN_ROUTE (6), also see uapi/linux/netfilter_decnet.h */
11+
#define NF_DN_NUMHOOKS 7
12+
13+
#if IS_ENABLED(CONFIG_DECNET)
714
/* Largest hook number + 1, see uapi/linux/netfilter_decnet.h */
8-
#define NF_MAX_HOOKS 8
15+
#define NF_MAX_HOOKS NF_DN_NUMHOOKS
16+
#else
17+
#define NF_MAX_HOOKS NF_INET_NUMHOOKS
18+
#endif
919

1020
#endif

include/linux/netfilter_ipv4.h

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,53 @@
66

77
#include <uapi/linux/netfilter_ipv4.h>
88

9+
/* Extra routing may needed on local out, as the QUEUE target never returns
10+
* control to the table.
11+
*/
12+
struct ip_rt_info {
13+
__be32 daddr;
14+
__be32 saddr;
15+
u_int8_t tos;
16+
u_int32_t mark;
17+
};
18+
919
int ip_route_me_harder(struct net *net, struct sk_buff *skb, unsigned addr_type);
20+
21+
struct nf_queue_entry;
22+
23+
#ifdef CONFIG_INET
1024
__sum16 nf_ip_checksum(struct sk_buff *skb, unsigned int hook,
1125
unsigned int dataoff, u_int8_t protocol);
26+
__sum16 nf_ip_checksum_partial(struct sk_buff *skb, unsigned int hook,
27+
unsigned int dataoff, unsigned int len,
28+
u_int8_t protocol);
29+
int nf_ip_route(struct net *net, struct dst_entry **dst, struct flowi *fl,
30+
bool strict);
31+
int nf_ip_reroute(struct sk_buff *skb, const struct nf_queue_entry *entry);
32+
#else
33+
static inline __sum16 nf_ip_checksum(struct sk_buff *skb, unsigned int hook,
34+
unsigned int dataoff, u_int8_t protocol)
35+
{
36+
return 0;
37+
}
38+
static inline __sum16 nf_ip_checksum_partial(struct sk_buff *skb,
39+
unsigned int hook,
40+
unsigned int dataoff,
41+
unsigned int len,
42+
u_int8_t protocol)
43+
{
44+
return 0;
45+
}
46+
static inline int nf_ip_route(struct net *net, struct dst_entry **dst,
47+
struct flowi *fl, bool strict)
48+
{
49+
return -EOPNOTSUPP;
50+
}
51+
static inline int nf_ip_reroute(struct sk_buff *skb,
52+
const struct nf_queue_entry *entry)
53+
{
54+
return -EOPNOTSUPP;
55+
}
56+
#endif /* CONFIG_INET */
57+
1258
#endif /*__LINUX_IP_NETFILTER_H*/

include/linux/netfilter_ipv6.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,17 @@
99

1010
#include <uapi/linux/netfilter_ipv6.h>
1111

12+
/* Extra routing may needed on local out, as the QUEUE target never returns
13+
* control to the table.
14+
*/
15+
struct ip6_rt_info {
16+
struct in6_addr daddr;
17+
struct in6_addr saddr;
18+
u_int32_t mark;
19+
};
20+
21+
struct nf_queue_entry;
22+
1223
/*
1324
* Hook functions for ipv6 to allow xt_* modules to be built-in even
1425
* if IPv6 is a module.
@@ -19,6 +30,14 @@ struct nf_ipv6_ops {
1930
void (*route_input)(struct sk_buff *skb);
2031
int (*fragment)(struct net *net, struct sock *sk, struct sk_buff *skb,
2132
int (*output)(struct net *, struct sock *, struct sk_buff *));
33+
__sum16 (*checksum)(struct sk_buff *skb, unsigned int hook,
34+
unsigned int dataoff, u_int8_t protocol);
35+
__sum16 (*checksum_partial)(struct sk_buff *skb, unsigned int hook,
36+
unsigned int dataoff, unsigned int len,
37+
u_int8_t protocol);
38+
int (*route)(struct net *net, struct dst_entry **dst, struct flowi *fl,
39+
bool strict);
40+
int (*reroute)(struct sk_buff *skb, const struct nf_queue_entry *entry);
2241
};
2342

2443
#ifdef CONFIG_NETFILTER

include/net/ip_vs.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ struct ip_vs_iphdr {
6969
};
7070

7171
static inline void *frag_safe_skb_hp(const struct sk_buff *skb, int offset,
72-
int len, void *buffer,
73-
const struct ip_vs_iphdr *ipvsh)
72+
int len, void *buffer)
7473
{
7574
return skb_header_pointer(skb, offset, len, buffer);
7675
}

include/net/ipv6.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -969,6 +969,8 @@ static inline struct sk_buff *ip6_finish_skb(struct sock *sk)
969969
&inet6_sk(sk)->cork);
970970
}
971971

972+
unsigned int ip6_dst_mtu_forward(const struct dst_entry *dst);
973+
972974
int ip6_dst_lookup(struct net *net, struct sock *sk, struct dst_entry **dst,
973975
struct flowi6 *fl6);
974976
struct dst_entry *ip6_dst_lookup_flow(const struct sock *sk, struct flowi6 *fl6,

include/net/netfilter/ipv4/nf_conntrack_ipv4.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@
1313

1414
const extern struct nf_conntrack_l3proto nf_conntrack_l3proto_ipv4;
1515

16-
extern struct nf_conntrack_l4proto nf_conntrack_l4proto_tcp4;
17-
extern struct nf_conntrack_l4proto nf_conntrack_l4proto_udp4;
18-
extern struct nf_conntrack_l4proto nf_conntrack_l4proto_icmp;
16+
extern const struct nf_conntrack_l4proto nf_conntrack_l4proto_tcp4;
17+
extern const struct nf_conntrack_l4proto nf_conntrack_l4proto_udp4;
18+
extern const struct nf_conntrack_l4proto nf_conntrack_l4proto_icmp;
1919
#ifdef CONFIG_NF_CT_PROTO_DCCP
20-
extern struct nf_conntrack_l4proto nf_conntrack_l4proto_dccp4;
20+
extern const struct nf_conntrack_l4proto nf_conntrack_l4proto_dccp4;
2121
#endif
2222
#ifdef CONFIG_NF_CT_PROTO_SCTP
23-
extern struct nf_conntrack_l4proto nf_conntrack_l4proto_sctp4;
23+
extern const struct nf_conntrack_l4proto nf_conntrack_l4proto_sctp4;
2424
#endif
2525
#ifdef CONFIG_NF_CT_PROTO_UDPLITE
26-
extern struct nf_conntrack_l4proto nf_conntrack_l4proto_udplite4;
26+
extern const struct nf_conntrack_l4proto nf_conntrack_l4proto_udplite4;
2727
#endif
2828

2929
int nf_conntrack_ipv4_compat_init(void);

0 commit comments

Comments
 (0)