Skip to content

Commit 99d20a4

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) No need to set ttl from reject action for the bridge family, from Taehee Yoo. 2) Use a fixed timeout for flow that are passed up from the flowtable to conntrack, from Florian Westphal. 3) More preparation patches for tproxy support for nf_tables, from Mate Eckl. 4) Remove unnecessary indirection in core IPv6 checksum function, from Florian Westphal. 5) Use nf_ct_get_tuplepr() from openvswitch, instead of opencoding it. From Florian Westphal. 6) socket match now selects socket infrastructure, instead of depending on it. From Mate Eckl. 7) Patch series to simplify conntrack tuple building/parsing from packet path and ctnetlink, from Florian Westphal. 8) Fetch timeout policy from protocol helpers, instead of doing it from core, from Florian Westphal. 9) Merge IPv4 and IPv6 protocol trackers into conntrack core, from Florian Westphal. 10) Depend on CONFIG_NF_TABLES_IPV6 and CONFIG_IP6_NF_IPTABLES respectively, instead of IPV6. Patch from Mate Eckl. 11) Add specific function for garbage collection in conncount, from Yi-Hung Wei. 12) Catch number of elements in the connlimit list, from Yi-Hung Wei. 13) Move locking to nf_conncount, from Yi-Hung Wei. 14) Series of patches to add lockless tree traversal in nf_conncount, from Yi-Hung Wei. 15) Resolve clash in matching conntracks when race happens, from Martynas Pumputis. 16) If connection entry times out, remove template entry from the ip_vs_conn_tab table to improve behaviour under flood, from Julian Anastasov. 17) Remove useless parameter from nf_ct_helper_ext_add(), from Gao feng. 18) Call abort from 2-phase commit protocol before requesting modules, make sure this is done under the mutex, from Florian Westphal. 19) Grab module reference when starting transaction, also from Florian. 20) Dynamically allocate expression info array for pre-parsing, from Florian. 21) Add per netns mutex for nf_tables, from Florian Westphal. 22) A couple of patches to simplify and refactor nf_osf code to prepare for nft_osf support. 23) Break evaluation on missing socket, from Mate Eckl. 24) Allow to match socket mark from nft_socket, from Mate Eckl. 25) Remove dependency on nf_defrag_ipv6, now that IPv6 tracker is built-in into nf_conntrack. From Florian Westphal. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents c4c5551 + 24c458c commit 99d20a4

72 files changed

Lines changed: 2029 additions & 2408 deletions

Some content is hidden

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

‎include/linux/netfilter/nfnetlink.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ struct nfnetlink_subsystem {
2929
__u8 subsys_id; /* nfnetlink subsystem ID */
3030
__u8 cb_count; /* number of callbacks */
3131
const struct nfnl_callback *cb; /* callback for individual types */
32+
struct module *owner;
3233
int (*commit)(struct net *net, struct sk_buff *skb);
3334
int (*abort)(struct net *net, struct sk_buff *skb);
3435
void (*cleanup)(struct net *net);

‎include/linux/netfilter_ipv4.h‎

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ struct nf_queue_entry;
2323
#ifdef CONFIG_INET
2424
__sum16 nf_ip_checksum(struct sk_buff *skb, unsigned int hook,
2525
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);
2926
int nf_ip_route(struct net *net, struct dst_entry **dst, struct flowi *fl,
3027
bool strict);
3128
int nf_ip_reroute(struct sk_buff *skb, const struct nf_queue_entry *entry);
@@ -35,14 +32,6 @@ static inline __sum16 nf_ip_checksum(struct sk_buff *skb, unsigned int hook,
3532
{
3633
return 0;
3734
}
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-
}
4635
static inline int nf_ip_route(struct net *net, struct dst_entry **dst,
4736
struct flowi *fl, bool strict)
4837
{

‎include/linux/netfilter_ipv6.h‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,6 @@ struct nf_ipv6_ops {
3030
void (*route_input)(struct sk_buff *skb);
3131
int (*fragment)(struct net *net, struct sock *sk, struct sk_buff *skb,
3232
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);
3833
int (*route)(struct net *net, struct dst_entry **dst, struct flowi *fl,
3934
bool strict);
4035
int (*reroute)(struct sk_buff *skb, const struct nf_queue_entry *entry);

‎include/net/ip_vs.h‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,11 @@ enum ip_vs_sctp_states {
335335
IP_VS_SCTP_S_LAST
336336
};
337337

338+
/* Connection templates use bits from state */
339+
#define IP_VS_CTPL_S_NONE 0x0000
340+
#define IP_VS_CTPL_S_ASSURED 0x0001
341+
#define IP_VS_CTPL_S_LAST 0x0002
342+
338343
/* Delta sequence info structure
339344
* Each ip_vs_conn has 2 (output AND input seq. changes).
340345
* Only used in the VS/NAT.
@@ -1221,7 +1226,7 @@ struct ip_vs_conn *ip_vs_conn_new(const struct ip_vs_conn_param *p, int dest_af,
12211226
struct ip_vs_dest *dest, __u32 fwmark);
12221227
void ip_vs_conn_expire_now(struct ip_vs_conn *cp);
12231228

1224-
const char *ip_vs_state_name(__u16 proto, int state);
1229+
const char *ip_vs_state_name(const struct ip_vs_conn *cp);
12251230

12261231
void ip_vs_tcp_conn_listen(struct ip_vs_conn *cp);
12271232
int ip_vs_check_template(struct ip_vs_conn *ct, struct ip_vs_dest *cdest);
@@ -1289,6 +1294,17 @@ ip_vs_control_add(struct ip_vs_conn *cp, struct ip_vs_conn *ctl_cp)
12891294
atomic_inc(&ctl_cp->n_control);
12901295
}
12911296

1297+
/* Mark our template as assured */
1298+
static inline void
1299+
ip_vs_control_assure_ct(struct ip_vs_conn *cp)
1300+
{
1301+
struct ip_vs_conn *ct = cp->control;
1302+
1303+
if (ct && !(ct->state & IP_VS_CTPL_S_ASSURED) &&
1304+
(ct->flags & IP_VS_CONN_F_TEMPLATE))
1305+
ct->state |= IP_VS_CTPL_S_ASSURED;
1306+
}
1307+
12921308
/* IPVS netns init & cleanup functions */
12931309
int ip_vs_estimator_net_init(struct netns_ipvs *ipvs);
12941310
int ip_vs_control_net_init(struct netns_ipvs *ipvs);

‎include/net/ipv6.h‎

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -574,34 +574,6 @@ static inline bool ipv6_prefix_equal(const struct in6_addr *addr1,
574574
}
575575
#endif
576576

577-
struct inet_frag_queue;
578-
579-
enum ip6_defrag_users {
580-
IP6_DEFRAG_LOCAL_DELIVER,
581-
IP6_DEFRAG_CONNTRACK_IN,
582-
__IP6_DEFRAG_CONNTRACK_IN = IP6_DEFRAG_CONNTRACK_IN + USHRT_MAX,
583-
IP6_DEFRAG_CONNTRACK_OUT,
584-
__IP6_DEFRAG_CONNTRACK_OUT = IP6_DEFRAG_CONNTRACK_OUT + USHRT_MAX,
585-
IP6_DEFRAG_CONNTRACK_BRIDGE_IN,
586-
__IP6_DEFRAG_CONNTRACK_BRIDGE_IN = IP6_DEFRAG_CONNTRACK_BRIDGE_IN + USHRT_MAX,
587-
};
588-
589-
void ip6_frag_init(struct inet_frag_queue *q, const void *a);
590-
extern const struct rhashtable_params ip6_rhash_params;
591-
592-
/*
593-
* Equivalent of ipv4 struct ip
594-
*/
595-
struct frag_queue {
596-
struct inet_frag_queue q;
597-
598-
int iif;
599-
__u16 nhoffset;
600-
u8 ecn;
601-
};
602-
603-
void ip6_expire_frag_queue(struct net *net, struct frag_queue *fq);
604-
605577
static inline bool ipv6_addr_any(const struct in6_addr *a)
606578
{
607579
#if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && BITS_PER_LONG == 64

‎include/net/ipv6_frag.h‎

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
#ifndef _IPV6_FRAG_H
3+
#define _IPV6_FRAG_H
4+
#include <linux/kernel.h>
5+
#include <net/addrconf.h>
6+
#include <net/ipv6.h>
7+
#include <net/inet_frag.h>
8+
9+
enum ip6_defrag_users {
10+
IP6_DEFRAG_LOCAL_DELIVER,
11+
IP6_DEFRAG_CONNTRACK_IN,
12+
__IP6_DEFRAG_CONNTRACK_IN = IP6_DEFRAG_CONNTRACK_IN + USHRT_MAX,
13+
IP6_DEFRAG_CONNTRACK_OUT,
14+
__IP6_DEFRAG_CONNTRACK_OUT = IP6_DEFRAG_CONNTRACK_OUT + USHRT_MAX,
15+
IP6_DEFRAG_CONNTRACK_BRIDGE_IN,
16+
__IP6_DEFRAG_CONNTRACK_BRIDGE_IN = IP6_DEFRAG_CONNTRACK_BRIDGE_IN + USHRT_MAX,
17+
};
18+
19+
/*
20+
* Equivalent of ipv4 struct ip
21+
*/
22+
struct frag_queue {
23+
struct inet_frag_queue q;
24+
25+
int iif;
26+
__u16 nhoffset;
27+
u8 ecn;
28+
};
29+
30+
#if IS_ENABLED(CONFIG_IPV6)
31+
static inline void ip6frag_init(struct inet_frag_queue *q, const void *a)
32+
{
33+
struct frag_queue *fq = container_of(q, struct frag_queue, q);
34+
const struct frag_v6_compare_key *key = a;
35+
36+
q->key.v6 = *key;
37+
fq->ecn = 0;
38+
}
39+
40+
static inline u32 ip6frag_key_hashfn(const void *data, u32 len, u32 seed)
41+
{
42+
return jhash2(data,
43+
sizeof(struct frag_v6_compare_key) / sizeof(u32), seed);
44+
}
45+
46+
static inline u32 ip6frag_obj_hashfn(const void *data, u32 len, u32 seed)
47+
{
48+
const struct inet_frag_queue *fq = data;
49+
50+
return jhash2((const u32 *)&fq->key.v6,
51+
sizeof(struct frag_v6_compare_key) / sizeof(u32), seed);
52+
}
53+
54+
static inline int
55+
ip6frag_obj_cmpfn(struct rhashtable_compare_arg *arg, const void *ptr)
56+
{
57+
const struct frag_v6_compare_key *key = arg->key;
58+
const struct inet_frag_queue *fq = ptr;
59+
60+
return !!memcmp(&fq->key, key, sizeof(*key));
61+
}
62+
63+
static inline void
64+
ip6frag_expire_frag_queue(struct net *net, struct frag_queue *fq)
65+
{
66+
struct net_device *dev = NULL;
67+
struct sk_buff *head;
68+
69+
rcu_read_lock();
70+
spin_lock(&fq->q.lock);
71+
72+
if (fq->q.flags & INET_FRAG_COMPLETE)
73+
goto out;
74+
75+
inet_frag_kill(&fq->q);
76+
77+
dev = dev_get_by_index_rcu(net, fq->iif);
78+
if (!dev)
79+
goto out;
80+
81+
__IP6_INC_STATS(net, __in6_dev_get(dev), IPSTATS_MIB_REASMFAILS);
82+
__IP6_INC_STATS(net, __in6_dev_get(dev), IPSTATS_MIB_REASMTIMEOUT);
83+
84+
/* Don't send error if the first segment did not arrive. */
85+
head = fq->q.fragments;
86+
if (!(fq->q.flags & INET_FRAG_FIRST_IN) || !head)
87+
goto out;
88+
89+
head->dev = dev;
90+
skb_get(head);
91+
spin_unlock(&fq->q.lock);
92+
93+
icmpv6_send(head, ICMPV6_TIME_EXCEED, ICMPV6_EXC_FRAGTIME, 0);
94+
kfree_skb(head);
95+
goto out_rcu_unlock;
96+
97+
out:
98+
spin_unlock(&fq->q.lock);
99+
out_rcu_unlock:
100+
rcu_read_unlock();
101+
inet_frag_put(&fq->q);
102+
}
103+
#endif
104+
#endif

‎include/net/netfilter/ipv4/nf_conntrack_ipv4.h‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010
#ifndef _NF_CONNTRACK_IPV4_H
1111
#define _NF_CONNTRACK_IPV4_H
1212

13-
14-
const extern struct nf_conntrack_l3proto nf_conntrack_l3proto_ipv4;
15-
1613
extern const struct nf_conntrack_l4proto nf_conntrack_l4proto_tcp4;
1714
extern const struct nf_conntrack_l4proto nf_conntrack_l4proto_udp4;
1815
extern const struct nf_conntrack_l4proto nf_conntrack_l4proto_icmp;

‎include/net/netfilter/nf_conntrack.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ union nf_conntrack_expect_proto {
4141
/* insert expect proto private data here */
4242
};
4343

44+
struct nf_conntrack_net {
45+
unsigned int users4;
46+
unsigned int users6;
47+
};
48+
4449
#include <linux/types.h>
4550
#include <linux/skbuff.h>
4651

‎include/net/netfilter/nf_conntrack_core.h‎

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#define _NF_CONNTRACK_CORE_H
1515

1616
#include <linux/netfilter.h>
17-
#include <net/netfilter/nf_conntrack_l3proto.h>
1817
#include <net/netfilter/nf_conntrack_l4proto.h>
1918
#include <net/netfilter/nf_conntrack_ecache.h>
2019

@@ -40,16 +39,8 @@ void nf_conntrack_cleanup_start(void);
4039
void nf_conntrack_init_end(void);
4140
void nf_conntrack_cleanup_end(void);
4241

43-
bool nf_ct_get_tuple(const struct sk_buff *skb, unsigned int nhoff,
44-
unsigned int dataoff, u_int16_t l3num, u_int8_t protonum,
45-
struct net *net,
46-
struct nf_conntrack_tuple *tuple,
47-
const struct nf_conntrack_l3proto *l3proto,
48-
const struct nf_conntrack_l4proto *l4proto);
49-
5042
bool nf_ct_invert_tuple(struct nf_conntrack_tuple *inverse,
5143
const struct nf_conntrack_tuple *orig,
52-
const struct nf_conntrack_l3proto *l3proto,
5344
const struct nf_conntrack_l4proto *l4proto);
5445

5546
/* Find a connection corresponding to a tuple. */
@@ -75,10 +66,8 @@ static inline int nf_conntrack_confirm(struct sk_buff *skb)
7566
return ret;
7667
}
7768

78-
void
79-
print_tuple(struct seq_file *s, const struct nf_conntrack_tuple *tuple,
80-
const struct nf_conntrack_l3proto *l3proto,
81-
const struct nf_conntrack_l4proto *proto);
69+
void print_tuple(struct seq_file *s, const struct nf_conntrack_tuple *tuple,
70+
const struct nf_conntrack_l4proto *proto);
8271

8372
#define CONNTRACK_LOCKS 1024
8473

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,23 @@
11
#ifndef _NF_CONNTRACK_COUNT_H
22
#define _NF_CONNTRACK_COUNT_H
33

4+
#include <linux/list.h>
5+
46
struct nf_conncount_data;
57

8+
enum nf_conncount_list_add {
9+
NF_CONNCOUNT_ADDED, /* list add was ok */
10+
NF_CONNCOUNT_ERR, /* -ENOMEM, must drop skb */
11+
NF_CONNCOUNT_SKIP, /* list is already reclaimed by gc */
12+
};
13+
14+
struct nf_conncount_list {
15+
spinlock_t list_lock;
16+
struct list_head head; /* connections with the same filtering key */
17+
unsigned int count; /* length of list */
18+
bool dead;
19+
};
20+
621
struct nf_conncount_data *nf_conncount_init(struct net *net, unsigned int family,
722
unsigned int keylen);
823
void nf_conncount_destroy(struct net *net, unsigned int family,
@@ -14,15 +29,21 @@ unsigned int nf_conncount_count(struct net *net,
1429
const struct nf_conntrack_tuple *tuple,
1530
const struct nf_conntrack_zone *zone);
1631

17-
unsigned int nf_conncount_lookup(struct net *net, struct hlist_head *head,
18-
const struct nf_conntrack_tuple *tuple,
19-
const struct nf_conntrack_zone *zone,
20-
bool *addit);
32+
void nf_conncount_lookup(struct net *net, struct nf_conncount_list *list,
33+
const struct nf_conntrack_tuple *tuple,
34+
const struct nf_conntrack_zone *zone,
35+
bool *addit);
36+
37+
void nf_conncount_list_init(struct nf_conncount_list *list);
38+
39+
enum nf_conncount_list_add
40+
nf_conncount_add(struct nf_conncount_list *list,
41+
const struct nf_conntrack_tuple *tuple,
42+
const struct nf_conntrack_zone *zone);
2143

22-
bool nf_conncount_add(struct hlist_head *head,
23-
const struct nf_conntrack_tuple *tuple,
24-
const struct nf_conntrack_zone *zone);
44+
bool nf_conncount_gc_list(struct net *net,
45+
struct nf_conncount_list *list);
2546

26-
void nf_conncount_cache_free(struct hlist_head *hhead);
47+
void nf_conncount_cache_free(struct nf_conncount_list *list);
2748

2849
#endif

0 commit comments

Comments
 (0)