Skip to content

Commit 9000a45

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 your net-next tree: 1) Support for matching on ipsec policy already set in the route, from Florian Westphal. 2) Split set destruction into deactivate and destroy phase to make it fit better into the transaction infrastructure, also from Florian. This includes a patch to warn on imbalance when setting the new activate and deactivate interfaces. 3) Release transaction list from the workqueue to remove expensive synchronize_rcu() from configuration plane path. This speeds up configuration plane quite a bit. From Florian Westphal. 4) Add new xfrm/ipsec extension, this new extension allows you to match for ipsec tunnel keys such as source and destination address, spi and reqid. From Máté Eckl and Florian Westphal. 5) Add secmark support, this includes connsecmark too, patches from Christian Gottsche. 6) Allow to specify remaining bytes in xt_quota, from Chenbo Feng. One follow up patch to calm a clang warning for this one, from Nathan Chancellor. 7) Flush conntrack entries based on layer 3 family, from Kristian Evensen. 8) New revision for cgroups2 to shrink the path field. 9) Get rid of obsolete need_conntrack(), as a result from recent demodularization works. 10) Use WARN_ON instead of BUG_ON, from Florian Westphal. 11) Unused exported symbol in nf_nat_ipv4_fn(), from Florian. 12) Remove superfluous check for timeout netlink parser and dump functions in layer 4 conntrack helpers. 13) Unnecessary redundant rcu read side locks in NAT redirect, from Taehee Yoo. 14) Pass nf_hook_state structure to error handlers, patch from Florian Westphal. 15) Remove ->new() interface from layer 4 protocol trackers. Place them in the ->packet() interface. From Florian. 16) Place conntrack ->error() handling in the ->packet() interface. Patches from Florian Westphal. 17) Remove unused parameter in the pernet initialization path, also from Florian. 18) Remove additional parameter to specify layer 3 protocol when looking up for protocol tracker. From Florian. 19) Shrink array of layer 4 protocol trackers, from Florian. 20) Check for linear skb only once from the ALG NAT mangling codebase, from Taehee Yoo. 21) Use rhashtable_walk_enter() instead of deprecated rhashtable_walk_init(), also from Taehee. 22) No need to flush all conntracks when only one single address is gone, from Tan Hu. 23) Remove redundant check for NAT flags in flowtable code, from Taehee Yoo. 24) Use rhashtable_lookup() instead of rhashtable_lookup_fast() from netfilter codebase, since rcu read lock side is already assumed in this path. ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 68049a5 + ffa0a9a commit 9000a45

Some content is hidden

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

53 files changed

+1555
-1054
lines changed

include/linux/netfilter/nf_conntrack_common.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,4 @@ struct ip_conntrack_stat {
1919
unsigned int search_restart;
2020
};
2121

22-
/* call to create an explicit dependency on nf_conntrack. */
23-
void need_conntrack(void);
24-
2522
#endif /* _NF_CONNTRACK_COMMON_H */

include/net/netfilter/ipv4/nf_conntrack_ipv4.h

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,17 @@
1010
#ifndef _NF_CONNTRACK_IPV4_H
1111
#define _NF_CONNTRACK_IPV4_H
1212

13-
extern const struct nf_conntrack_l4proto nf_conntrack_l4proto_tcp4;
14-
extern const struct nf_conntrack_l4proto nf_conntrack_l4proto_udp4;
13+
extern const struct nf_conntrack_l4proto nf_conntrack_l4proto_tcp;
14+
extern const struct nf_conntrack_l4proto nf_conntrack_l4proto_udp;
1515
extern const struct nf_conntrack_l4proto nf_conntrack_l4proto_icmp;
1616
#ifdef CONFIG_NF_CT_PROTO_DCCP
17-
extern const struct nf_conntrack_l4proto nf_conntrack_l4proto_dccp4;
17+
extern const struct nf_conntrack_l4proto nf_conntrack_l4proto_dccp;
1818
#endif
1919
#ifdef CONFIG_NF_CT_PROTO_SCTP
20-
extern const struct nf_conntrack_l4proto nf_conntrack_l4proto_sctp4;
20+
extern const struct nf_conntrack_l4proto nf_conntrack_l4proto_sctp;
2121
#endif
2222
#ifdef CONFIG_NF_CT_PROTO_UDPLITE
23-
extern const struct nf_conntrack_l4proto nf_conntrack_l4proto_udplite4;
23+
extern const struct nf_conntrack_l4proto nf_conntrack_l4proto_udplite;
2424
#endif
2525

26-
int nf_conntrack_ipv4_compat_init(void);
27-
void nf_conntrack_ipv4_compat_fini(void);
28-
2926
#endif /*_NF_CONNTRACK_IPV4_H*/

include/net/netfilter/ipv6/nf_conntrack_ipv6.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,7 @@
22
#ifndef _NF_CONNTRACK_IPV6_H
33
#define _NF_CONNTRACK_IPV6_H
44

5-
extern const struct nf_conntrack_l3proto nf_conntrack_l3proto_ipv6;
6-
7-
extern const struct nf_conntrack_l4proto nf_conntrack_l4proto_tcp6;
8-
extern const struct nf_conntrack_l4proto nf_conntrack_l4proto_udp6;
95
extern const struct nf_conntrack_l4proto nf_conntrack_l4proto_icmpv6;
10-
#ifdef CONFIG_NF_CT_PROTO_DCCP
11-
extern const struct nf_conntrack_l4proto nf_conntrack_l4proto_dccp6;
12-
#endif
13-
#ifdef CONFIG_NF_CT_PROTO_SCTP
14-
extern const struct nf_conntrack_l4proto nf_conntrack_l4proto_sctp6;
15-
#endif
16-
#ifdef CONFIG_NF_CT_PROTO_UDPLITE
17-
extern const struct nf_conntrack_l4proto nf_conntrack_l4proto_udplite6;
18-
#endif
196

207
#include <linux/sysctl.h>
218
extern struct ctl_table nf_ct_ipv6_sysctl_table[];

include/net/netfilter/nf_conntrack_core.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020
/* This header is used to share core functionality between the
2121
standalone connection tracking module, and the compatibility layer's use
2222
of connection tracking. */
23-
unsigned int nf_conntrack_in(struct net *net, u_int8_t pf, unsigned int hooknum,
24-
struct sk_buff *skb);
23+
unsigned int nf_conntrack_in(struct sk_buff *skb, const struct nf_hook_state *state);
2524

2625
int nf_conntrack_init_net(struct net *net);
2726
void nf_conntrack_cleanup_net(struct net *net);

include/net/netfilter/nf_conntrack_l4proto.h

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@
1818
struct seq_file;
1919

2020
struct nf_conntrack_l4proto {
21-
/* L3 Protocol number. */
22-
u_int16_t l3proto;
23-
2421
/* L4 Protocol number. */
2522
u_int8_t l4proto;
2623

@@ -43,22 +40,14 @@ struct nf_conntrack_l4proto {
4340

4441
/* Returns verdict for packet, or -1 for invalid. */
4542
int (*packet)(struct nf_conn *ct,
46-
const struct sk_buff *skb,
43+
struct sk_buff *skb,
4744
unsigned int dataoff,
48-
enum ip_conntrack_info ctinfo);
49-
50-
/* Called when a new connection for this protocol found;
51-
* returns TRUE if it's OK. If so, packet() called next. */
52-
bool (*new)(struct nf_conn *ct, const struct sk_buff *skb,
53-
unsigned int dataoff);
45+
enum ip_conntrack_info ctinfo,
46+
const struct nf_hook_state *state);
5447

5548
/* Called when a conntrack entry is destroyed */
5649
void (*destroy)(struct nf_conn *ct);
5750

58-
int (*error)(struct net *net, struct nf_conn *tmpl, struct sk_buff *skb,
59-
unsigned int dataoff,
60-
u_int8_t pf, unsigned int hooknum);
61-
6251
/* called by gc worker if table is full */
6352
bool (*can_early_drop)(const struct nf_conn *ct);
6453

@@ -92,7 +81,7 @@ struct nf_conntrack_l4proto {
9281
#endif
9382
unsigned int *net_id;
9483
/* Init l4proto pernet data */
95-
int (*init_net)(struct net *net, u_int16_t proto);
84+
int (*init_net)(struct net *net);
9685

9786
/* Return the per-net protocol part. */
9887
struct nf_proto_net *(*get_net_proto)(struct net *net);
@@ -101,16 +90,23 @@ struct nf_conntrack_l4proto {
10190
struct module *me;
10291
};
10392

93+
int nf_conntrack_icmpv4_error(struct nf_conn *tmpl,
94+
struct sk_buff *skb,
95+
unsigned int dataoff,
96+
const struct nf_hook_state *state);
97+
98+
int nf_conntrack_icmpv6_error(struct nf_conn *tmpl,
99+
struct sk_buff *skb,
100+
unsigned int dataoff,
101+
const struct nf_hook_state *state);
104102
/* Existing built-in generic protocol */
105103
extern const struct nf_conntrack_l4proto nf_conntrack_l4proto_generic;
106104

107-
#define MAX_NF_CT_PROTO 256
105+
#define MAX_NF_CT_PROTO IPPROTO_UDPLITE
108106

109-
const struct nf_conntrack_l4proto *__nf_ct_l4proto_find(u_int16_t l3proto,
110-
u_int8_t l4proto);
107+
const struct nf_conntrack_l4proto *__nf_ct_l4proto_find(u8 l4proto);
111108

112-
const struct nf_conntrack_l4proto *nf_ct_l4proto_find_get(u_int16_t l3proto,
113-
u_int8_t l4proto);
109+
const struct nf_conntrack_l4proto *nf_ct_l4proto_find_get(u8 l4proto);
114110
void nf_ct_l4proto_put(const struct nf_conntrack_l4proto *p);
115111

116112
/* Protocol pernet registration. */

include/net/netfilter/nf_tables.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,9 @@ int nf_tables_bind_set(const struct nft_ctx *ctx, struct nft_set *set,
470470
struct nft_set_binding *binding);
471471
void nf_tables_unbind_set(const struct nft_ctx *ctx, struct nft_set *set,
472472
struct nft_set_binding *binding);
473+
void nf_tables_rebind_set(const struct nft_ctx *ctx, struct nft_set *set,
474+
struct nft_set_binding *binding);
475+
void nf_tables_destroy_set(const struct nft_ctx *ctx, struct nft_set *set);
473476

474477
/**
475478
* enum nft_set_extensions - set extension type IDs
@@ -724,7 +727,9 @@ struct nft_expr_type {
724727
* @eval: Expression evaluation function
725728
* @size: full expression size, including private data size
726729
* @init: initialization function
727-
* @destroy: destruction function
730+
* @activate: activate expression in the next generation
731+
* @deactivate: deactivate expression in next generation
732+
* @destroy: destruction function, called after synchronize_rcu
728733
* @dump: function to dump parameters
729734
* @type: expression type
730735
* @validate: validate expression, called during loop detection
@@ -1293,12 +1298,14 @@ static inline void nft_set_elem_clear_busy(struct nft_set_ext *ext)
12931298
*
12941299
* @list: used internally
12951300
* @msg_type: message type
1301+
* @put_net: ctx->net needs to be put
12961302
* @ctx: transaction context
12971303
* @data: internal information related to the transaction
12981304
*/
12991305
struct nft_trans {
13001306
struct list_head list;
13011307
int msg_type;
1308+
bool put_net;
13021309
struct nft_ctx ctx;
13031310
char data[0];
13041311
};

include/net/netfilter/nf_tables_core.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ extern struct nft_expr_type nft_meta_type;
1616
extern struct nft_expr_type nft_rt_type;
1717
extern struct nft_expr_type nft_exthdr_type;
1818

19+
#ifdef CONFIG_NETWORK_SECMARK
20+
extern struct nft_object_type nft_secmark_obj_type;
21+
#endif
22+
1923
int nf_tables_core_module_init(void);
2024
void nf_tables_core_module_exit(void);
2125

include/uapi/linux/netfilter/nf_tables.h

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -826,12 +826,14 @@ enum nft_meta_keys {
826826
* @NFT_RT_NEXTHOP4: routing nexthop for IPv4
827827
* @NFT_RT_NEXTHOP6: routing nexthop for IPv6
828828
* @NFT_RT_TCPMSS: fetch current path tcp mss
829+
* @NFT_RT_XFRM: boolean, skb->dst->xfrm != NULL
829830
*/
830831
enum nft_rt_keys {
831832
NFT_RT_CLASSID,
832833
NFT_RT_NEXTHOP4,
833834
NFT_RT_NEXTHOP6,
834835
NFT_RT_TCPMSS,
836+
NFT_RT_XFRM,
835837
__NFT_RT_MAX
836838
};
837839
#define NFT_RT_MAX (__NFT_RT_MAX - 1)
@@ -1174,6 +1176,21 @@ enum nft_quota_attributes {
11741176
};
11751177
#define NFTA_QUOTA_MAX (__NFTA_QUOTA_MAX - 1)
11761178

1179+
/**
1180+
* enum nft_secmark_attributes - nf_tables secmark object netlink attributes
1181+
*
1182+
* @NFTA_SECMARK_CTX: security context (NLA_STRING)
1183+
*/
1184+
enum nft_secmark_attributes {
1185+
NFTA_SECMARK_UNSPEC,
1186+
NFTA_SECMARK_CTX,
1187+
__NFTA_SECMARK_MAX,
1188+
};
1189+
#define NFTA_SECMARK_MAX (__NFTA_SECMARK_MAX - 1)
1190+
1191+
/* Max security context length */
1192+
#define NFT_SECMARK_CTX_MAXLEN 256
1193+
11771194
/**
11781195
* enum nft_reject_types - nf_tables reject expression reject types
11791196
*
@@ -1430,7 +1447,8 @@ enum nft_ct_timeout_timeout_attributes {
14301447
#define NFT_OBJECT_CONNLIMIT 5
14311448
#define NFT_OBJECT_TUNNEL 6
14321449
#define NFT_OBJECT_CT_TIMEOUT 7
1433-
#define __NFT_OBJECT_MAX 8
1450+
#define NFT_OBJECT_SECMARK 8
1451+
#define __NFT_OBJECT_MAX 9
14341452
#define NFT_OBJECT_MAX (__NFT_OBJECT_MAX - 1)
14351453

14361454
/**
@@ -1512,6 +1530,35 @@ enum nft_devices_attributes {
15121530
};
15131531
#define NFTA_DEVICE_MAX (__NFTA_DEVICE_MAX - 1)
15141532

1533+
/*
1534+
* enum nft_xfrm_attributes - nf_tables xfrm expr netlink attributes
1535+
*
1536+
* @NFTA_XFRM_DREG: destination register (NLA_U32)
1537+
* @NFTA_XFRM_KEY: enum nft_xfrm_keys (NLA_U32)
1538+
* @NFTA_XFRM_DIR: direction (NLA_U8)
1539+
* @NFTA_XFRM_SPNUM: index in secpath array (NLA_U32)
1540+
*/
1541+
enum nft_xfrm_attributes {
1542+
NFTA_XFRM_UNSPEC,
1543+
NFTA_XFRM_DREG,
1544+
NFTA_XFRM_KEY,
1545+
NFTA_XFRM_DIR,
1546+
NFTA_XFRM_SPNUM,
1547+
__NFTA_XFRM_MAX
1548+
};
1549+
#define NFTA_XFRM_MAX (__NFTA_XFRM_MAX - 1)
1550+
1551+
enum nft_xfrm_keys {
1552+
NFT_XFRM_KEY_UNSPEC,
1553+
NFT_XFRM_KEY_DADDR_IP4,
1554+
NFT_XFRM_KEY_DADDR_IP6,
1555+
NFT_XFRM_KEY_SADDR_IP4,
1556+
NFT_XFRM_KEY_SADDR_IP6,
1557+
NFT_XFRM_KEY_REQID,
1558+
NFT_XFRM_KEY_SPI,
1559+
__NFT_XFRM_KEY_MAX,
1560+
};
1561+
#define NFT_XFRM_KEY_MAX (__NFT_XFRM_KEY_MAX - 1)
15151562

15161563
/**
15171564
* enum nft_trace_attributes - nf_tables trace netlink attributes

include/uapi/linux/netfilter/xt_cgroup.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,20 @@ struct xt_cgroup_info_v1 {
2222
void *priv __attribute__((aligned(8)));
2323
};
2424

25+
#define XT_CGROUP_PATH_MAX 512
26+
27+
struct xt_cgroup_info_v2 {
28+
__u8 has_path;
29+
__u8 has_classid;
30+
__u8 invert_path;
31+
__u8 invert_classid;
32+
union {
33+
char path[XT_CGROUP_PATH_MAX];
34+
__u32 classid;
35+
};
36+
37+
/* kernel internal data */
38+
void *priv __attribute__((aligned(8)));
39+
};
40+
2541
#endif /* _UAPI_XT_CGROUP_H */

include/uapi/linux/netfilter/xt_quota.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ struct xt_quota_info {
1515
__u32 flags;
1616
__u32 pad;
1717
__aligned_u64 quota;
18-
19-
/* Used internally by the kernel */
20-
struct xt_quota_priv *master;
18+
#ifdef __KERNEL__
19+
atomic64_t counter;
20+
#else
21+
__aligned_u64 remain;
22+
#endif
2123
};
2224

2325
#endif /* _XT_QUOTA_H */

net/ipv4/netfilter/nf_nat_l3proto_ipv4.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,6 @@ nf_nat_ipv4_fn(void *priv, struct sk_buff *skb,
264264

265265
return nf_nat_inet_fn(priv, skb, state);
266266
}
267-
EXPORT_SYMBOL_GPL(nf_nat_ipv4_fn);
268267

269268
static unsigned int
270269
nf_nat_ipv4_in(void *priv, struct sk_buff *skb,

net/ipv4/netfilter/nf_nat_masquerade_ipv4.c

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,26 @@ static int masq_device_event(struct notifier_block *this,
104104
return NOTIFY_DONE;
105105
}
106106

107+
static int inet_cmp(struct nf_conn *ct, void *ptr)
108+
{
109+
struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
110+
struct net_device *dev = ifa->ifa_dev->dev;
111+
struct nf_conntrack_tuple *tuple;
112+
113+
if (!device_cmp(ct, (void *)(long)dev->ifindex))
114+
return 0;
115+
116+
tuple = &ct->tuplehash[IP_CT_DIR_REPLY].tuple;
117+
118+
return ifa->ifa_address == tuple->dst.u3.ip;
119+
}
120+
107121
static int masq_inet_event(struct notifier_block *this,
108122
unsigned long event,
109123
void *ptr)
110124
{
111125
struct in_device *idev = ((struct in_ifaddr *)ptr)->ifa_dev;
112-
struct netdev_notifier_info info;
126+
struct net *net = dev_net(idev->dev);
113127

114128
/* The masq_dev_notifier will catch the case of the device going
115129
* down. So if the inetdev is dead and being destroyed we have
@@ -119,8 +133,10 @@ static int masq_inet_event(struct notifier_block *this,
119133
if (idev->dead)
120134
return NOTIFY_DONE;
121135

122-
netdev_notifier_info_init(&info, idev->dev);
123-
return masq_device_event(this, event, &info);
136+
if (event == NETDEV_DOWN)
137+
nf_ct_iterate_cleanup_net(net, inet_cmp, ptr, 0, 0);
138+
139+
return NOTIFY_DONE;
124140
}
125141

126142
static struct notifier_block masq_dev_notifier = {

net/ipv6/netfilter/ip6t_ipv6header.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,10 @@ ipv6header_mt6(const struct sk_buff *skb, struct xt_action_param *par)
6565
}
6666

6767
hp = skb_header_pointer(skb, ptr, sizeof(_hdr), &_hdr);
68-
BUG_ON(hp == NULL);
68+
if (!hp) {
69+
par->hotdrop = true;
70+
return false;
71+
}
6972

7073
/* Calculate the header length */
7174
if (nexthdr == NEXTHDR_FRAGMENT)

net/ipv6/netfilter/ip6t_rt.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,10 @@ static bool rt_mt6(const struct sk_buff *skb, struct xt_action_param *par)
137137
sizeof(_addr),
138138
&_addr);
139139

140-
BUG_ON(ap == NULL);
140+
if (ap == NULL) {
141+
par->hotdrop = true;
142+
return false;
143+
}
141144

142145
if (ipv6_addr_equal(ap, &rtinfo->addrs[i])) {
143146
pr_debug("i=%d temp=%d;\n", i, temp);
@@ -166,7 +169,10 @@ static bool rt_mt6(const struct sk_buff *skb, struct xt_action_param *par)
166169
+ temp * sizeof(_addr),
167170
sizeof(_addr),
168171
&_addr);
169-
BUG_ON(ap == NULL);
172+
if (ap == NULL) {
173+
par->hotdrop = true;
174+
return false;
175+
}
170176

171177
if (!ipv6_addr_equal(ap, &rtinfo->addrs[temp]))
172178
break;

0 commit comments

Comments
 (0)