Skip to content

Commit ae3e456

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, they are: 1) Don't use userspace datatypes in bridge netfilter code, from Tobin Harding. 2) Iterate only once over the expectation table when removing the helper module, instead of once per-netns, from Florian Westphal. 3) Extra sanitization in xt_hook_ops_alloc() to return error in case we ever pass zero hooks, xt_hook_ops_alloc(): 4) Handle NFPROTO_INET from the logging core infrastructure, from Liping Zhang. 5) Autoload loggers when TRACE target is used from rules, this doesn't change the behaviour in case the user already selected nfnetlink_log as preferred way to print tracing logs, also from Liping Zhang. 6) Conntrack slabs with SLAB_HWCACHE_ALIGN to allow rearranging fields by cache lines, increases the size of entries in 11% per entry. From Florian Westphal. 7) Skip zone comparison if CONFIG_NF_CONNTRACK_ZONES=n, from Florian. 8) Remove useless defensive check in nf_logger_find_get() from Shivani Bhardwaj. 9) Remove zone extension as place it in the conntrack object, this is always include in the hashing and we expect more intensive use of zones since containers are in place. Also from Florian Westphal. 10) Owner match now works from any namespace, from Eric Bierdeman. 11) Make sure we only reply with TCP reset to TCP traffic from nf_reject_ipv4, patch from Liping Zhang. 12) Introduce --nflog-size to indicate amount of network packet bytes that are copied to userspace via log message, from Vishwanath Pai. This obsoletes --nflog-range that has never worked, it was designed to achieve this but it has never worked. 13) Introduce generic macros for nf_tables object generation masks. 14) Use generation mask in table, chain and set objects in nf_tables. This allows fixes interferences with ongoing preparation phase of the commit protocol and object listings going on at the same time. This update is introduced in three patches, one per object. 15) Check if the object is active in the next generation for element deactivation in the rbtree implementation, given that deactivation happens from the commit phase path we have to observe the future status of the object. 16) Support for deletion of just added elements in the hash set type. 17) Allow to resize hashtable from /proc entry, not only from the obscure /sys entry that maps to the module parameter, from Florian Westphal. 18) Get rid of NFT_BASECHAIN_DISABLED, this code is not exercised anymore since we tear down the ruleset whenever the netdevice goes away. 19) Support for matching inverted set lookups, from Arturo Borrero. 20) Simplify the iptables_mangle_hook() by removing a superfluous extra branch. 21) Introduce ether_addr_equal_masked() and use it from the netfilter codebase, from Joe Perches. 22) Remove references to "Use netfilter MARK value as routing key" from the Netfilter Kconfig description given that this toggle doesn't exists already for 10 years, from Moritz Sichert. 23) Introduce generic NF_INVF() and use it from the xtables codebase, from Joe Perches. 24) Setting logger to NONE via /proc was not working unless explicit nul-termination was included in the string. This fixes seems to leave the former behaviour there, so we don't break backward. ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 73e20b7 + c6ac37d commit ae3e456

40 files changed

+699
-532
lines changed

Documentation/networking/nf_conntrack-sysctl.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ nf_conntrack_acct - BOOLEAN
77
Enable connection tracking flow accounting. 64-bit byte and packet
88
counters per flow are added.
99

10-
nf_conntrack_buckets - INTEGER (read-only)
10+
nf_conntrack_buckets - INTEGER
1111
Size of hash table. If not specified as parameter during module
1212
loading, the default size is calculated by dividing total memory
1313
by 16384 to determine the number of buckets but the hash table will
1414
never have fewer than 32 and limited to 16384 buckets. For systems
1515
with more than 4GB of memory it will be 65536 buckets.
16+
This sysctl is only writeable in the initial net namespace.
1617

1718
nf_conntrack_checksum - BOOLEAN
1819
0 - disabled

include/linux/etherdevice.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,29 @@ static inline bool ether_addr_equal_unaligned(const u8 *addr1, const u8 *addr2)
373373
#endif
374374
}
375375

376+
/**
377+
* ether_addr_equal_masked - Compare two Ethernet addresses with a mask
378+
* @addr1: Pointer to a six-byte array containing the 1st Ethernet address
379+
* @addr2: Pointer to a six-byte array containing the 2nd Ethernet address
380+
* @mask: Pointer to a six-byte array containing the Ethernet address bitmask
381+
*
382+
* Compare two Ethernet addresses with a mask, returns true if for every bit
383+
* set in the bitmask the equivalent bits in the ethernet addresses are equal.
384+
* Using a mask with all bits set is a slower ether_addr_equal.
385+
*/
386+
static inline bool ether_addr_equal_masked(const u8 *addr1, const u8 *addr2,
387+
const u8 *mask)
388+
{
389+
int i;
390+
391+
for (i = 0; i < ETH_ALEN; i++) {
392+
if ((addr1[i] ^ addr2[i]) & mask[i])
393+
return false;
394+
}
395+
396+
return true;
397+
}
398+
376399
/**
377400
* is_etherdev_addr - Tell if given Ethernet address belongs to the device.
378401
* @dev: Pointer to a device structure

include/linux/netfilter/x_tables.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
#include <linux/static_key.h>
77
#include <uapi/linux/netfilter/x_tables.h>
88

9+
/* Test a struct->invflags and a boolean for inequality */
10+
#define NF_INVF(ptr, flag, boolean) \
11+
((boolean) ^ !!((ptr)->invflags & (flag)))
12+
913
/**
1014
* struct xt_action_param - parameters for matches/targets
1115
*

include/linux/netfilter_bridge/ebtables.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,6 @@ extern unsigned int ebt_do_table(struct sk_buff *skb,
115115
const struct nf_hook_state *state,
116116
struct ebt_table *table);
117117

118-
/* Used in the kernel match() functions */
119-
#define FWINV(bool,invflg) ((bool) ^ !!(info->invflags & invflg))
120118
/* True if the hook mask denotes that the rule is in a base chain,
121119
* used in the check() functions */
122120
#define BASE_CHAIN (par->hook_mask & (1 << NF_BR_NUMHOOKS))

include/net/netfilter/nf_conntrack.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ struct nf_conn {
8585
spinlock_t lock;
8686
u16 cpu;
8787

88+
#ifdef CONFIG_NF_CONNTRACK_ZONES
89+
struct nf_conntrack_zone zone;
90+
#endif
8891
/* XXX should I move this to the tail ? - Y.K */
8992
/* These are my tuples; original and reply */
9093
struct nf_conntrack_tuple_hash tuplehash[IP_CT_DIR_MAX];
@@ -287,6 +290,7 @@ static inline bool nf_is_loopback_packet(const struct sk_buff *skb)
287290
struct kernel_param;
288291

289292
int nf_conntrack_set_hashsize(const char *val, struct kernel_param *kp);
293+
int nf_conntrack_hash_resize(unsigned int hashsize);
290294
extern unsigned int nf_conntrack_htable_size;
291295
extern unsigned int nf_conntrack_max;
292296

include/net/netfilter/nf_conntrack_extend.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ enum nf_ct_ext_id {
1515
#ifdef CONFIG_NF_CONNTRACK_EVENTS
1616
NF_CT_EXT_ECACHE,
1717
#endif
18-
#ifdef CONFIG_NF_CONNTRACK_ZONES
19-
NF_CT_EXT_ZONE,
20-
#endif
2118
#ifdef CONFIG_NF_CONNTRACK_TIMESTAMP
2219
NF_CT_EXT_TSTAMP,
2320
#endif
@@ -38,7 +35,6 @@ enum nf_ct_ext_id {
3835
#define NF_CT_EXT_SEQADJ_TYPE struct nf_conn_seqadj
3936
#define NF_CT_EXT_ACCT_TYPE struct nf_conn_acct
4037
#define NF_CT_EXT_ECACHE_TYPE struct nf_conntrack_ecache
41-
#define NF_CT_EXT_ZONE_TYPE struct nf_conntrack_zone
4238
#define NF_CT_EXT_TSTAMP_TYPE struct nf_conn_tstamp
4339
#define NF_CT_EXT_TIMEOUT_TYPE struct nf_conn_timeout
4440
#define NF_CT_EXT_LABELS_TYPE struct nf_conn_labels

include/net/netfilter/nf_conntrack_zones.h

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@
99
static inline const struct nf_conntrack_zone *
1010
nf_ct_zone(const struct nf_conn *ct)
1111
{
12-
const struct nf_conntrack_zone *nf_ct_zone = NULL;
13-
1412
#ifdef CONFIG_NF_CONNTRACK_ZONES
15-
nf_ct_zone = nf_ct_ext_find(ct, NF_CT_EXT_ZONE);
13+
return &ct->zone;
14+
#else
15+
return &nf_ct_zone_dflt;
1616
#endif
17-
return nf_ct_zone ? nf_ct_zone : &nf_ct_zone_dflt;
1817
}
1918

2019
static inline const struct nf_conntrack_zone *
@@ -31,32 +30,22 @@ static inline const struct nf_conntrack_zone *
3130
nf_ct_zone_tmpl(const struct nf_conn *tmpl, const struct sk_buff *skb,
3231
struct nf_conntrack_zone *tmp)
3332
{
34-
const struct nf_conntrack_zone *zone;
35-
33+
#ifdef CONFIG_NF_CONNTRACK_ZONES
3634
if (!tmpl)
3735
return &nf_ct_zone_dflt;
3836

39-
zone = nf_ct_zone(tmpl);
40-
if (zone->flags & NF_CT_FLAG_MARK)
41-
zone = nf_ct_zone_init(tmp, skb->mark, zone->dir, 0);
42-
43-
return zone;
37+
if (tmpl->zone.flags & NF_CT_FLAG_MARK)
38+
return nf_ct_zone_init(tmp, skb->mark, tmpl->zone.dir, 0);
39+
#endif
40+
return nf_ct_zone(tmpl);
4441
}
4542

46-
static inline int nf_ct_zone_add(struct nf_conn *ct, gfp_t flags,
47-
const struct nf_conntrack_zone *info)
43+
static inline void nf_ct_zone_add(struct nf_conn *ct,
44+
const struct nf_conntrack_zone *zone)
4845
{
4946
#ifdef CONFIG_NF_CONNTRACK_ZONES
50-
struct nf_conntrack_zone *nf_ct_zone;
51-
52-
nf_ct_zone = nf_ct_ext_add(ct, NF_CT_EXT_ZONE, flags);
53-
if (!nf_ct_zone)
54-
return -ENOMEM;
55-
56-
nf_ct_zone_init(nf_ct_zone, info->id, info->dir,
57-
info->flags);
47+
ct->zone = *zone;
5848
#endif
59-
return 0;
6049
}
6150

6251
static inline bool nf_ct_zone_matches_dir(const struct nf_conntrack_zone *zone,
@@ -68,22 +57,34 @@ static inline bool nf_ct_zone_matches_dir(const struct nf_conntrack_zone *zone,
6857
static inline u16 nf_ct_zone_id(const struct nf_conntrack_zone *zone,
6958
enum ip_conntrack_dir dir)
7059
{
60+
#ifdef CONFIG_NF_CONNTRACK_ZONES
7161
return nf_ct_zone_matches_dir(zone, dir) ?
7262
zone->id : NF_CT_DEFAULT_ZONE_ID;
63+
#else
64+
return NF_CT_DEFAULT_ZONE_ID;
65+
#endif
7366
}
7467

7568
static inline bool nf_ct_zone_equal(const struct nf_conn *a,
7669
const struct nf_conntrack_zone *b,
7770
enum ip_conntrack_dir dir)
7871
{
72+
#ifdef CONFIG_NF_CONNTRACK_ZONES
7973
return nf_ct_zone_id(nf_ct_zone(a), dir) ==
8074
nf_ct_zone_id(b, dir);
75+
#else
76+
return true;
77+
#endif
8178
}
8279

8380
static inline bool nf_ct_zone_equal_any(const struct nf_conn *a,
8481
const struct nf_conntrack_zone *b)
8582
{
83+
#ifdef CONFIG_NF_CONNTRACK_ZONES
8684
return nf_ct_zone(a)->id == b->id;
85+
#else
86+
return true;
87+
#endif
8788
}
8889
#endif /* IS_ENABLED(CONFIG_NF_CONNTRACK) */
8990
#endif /* _NF_CONNTRACK_ZONES_H */

include/net/netfilter/nf_log.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
#define NF_LOG_UID 0x08 /* Log UID owning local socket */
1313
#define NF_LOG_MASK 0x0f
1414

15+
/* This flag indicates that copy_len field in nf_loginfo is set */
16+
#define NF_LOG_F_COPY_LEN 0x1
17+
1518
enum nf_log_type {
1619
NF_LOG_TYPE_LOG = 0,
1720
NF_LOG_TYPE_ULOG,
@@ -22,9 +25,13 @@ struct nf_loginfo {
2225
u_int8_t type;
2326
union {
2427
struct {
28+
/* copy_len will be used iff you set
29+
* NF_LOG_F_COPY_LEN in flags
30+
*/
2531
u_int32_t copy_len;
2632
u_int16_t group;
2733
u_int16_t qthreshold;
34+
u_int16_t flags;
2835
} ulog;
2936
struct {
3037
u_int8_t level;

include/net/netfilter/nf_tables.h

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ void nft_unregister_set(struct nft_set_ops *ops);
297297
* @ops: set ops
298298
* @pnet: network namespace
299299
* @flags: set flags
300+
* @genmask: generation mask
300301
* @klen: key length
301302
* @dlen: data length
302303
* @data: private set data
@@ -318,7 +319,8 @@ struct nft_set {
318319
/* runtime data below here */
319320
const struct nft_set_ops *ops ____cacheline_aligned;
320321
possible_net_t pnet;
321-
u16 flags;
322+
u16 flags:14,
323+
genmask:2;
322324
u8 klen;
323325
u8 dlen;
324326
unsigned char data[]
@@ -336,9 +338,9 @@ static inline struct nft_set *nft_set_container_of(const void *priv)
336338
}
337339

338340
struct nft_set *nf_tables_set_lookup(const struct nft_table *table,
339-
const struct nlattr *nla);
341+
const struct nlattr *nla, u8 genmask);
340342
struct nft_set *nf_tables_set_lookup_byid(const struct net *net,
341-
const struct nlattr *nla);
343+
const struct nlattr *nla, u8 genmask);
342344

343345
static inline unsigned long nft_set_gc_interval(const struct nft_set *set)
344346
{
@@ -733,7 +735,6 @@ static inline struct nft_userdata *nft_userdata(const struct nft_rule *rule)
733735

734736
enum nft_chain_flags {
735737
NFT_BASE_CHAIN = 0x1,
736-
NFT_CHAIN_INACTIVE = 0x2,
737738
};
738739

739740
/**
@@ -755,7 +756,8 @@ struct nft_chain {
755756
u64 handle;
756757
u32 use;
757758
u16 level;
758-
u8 flags;
759+
u8 flags:6,
760+
genmask:2;
759761
char name[NFT_CHAIN_MAXNAMELEN];
760762
};
761763

@@ -797,7 +799,6 @@ struct nft_stats {
797799
};
798800

799801
#define NFT_HOOK_OPS_MAX 2
800-
#define NFT_BASECHAIN_DISABLED (1 << 0)
801802

802803
/**
803804
* struct nft_base_chain - nf_tables base chain
@@ -839,6 +840,7 @@ unsigned int nft_do_chain(struct nft_pktinfo *pkt, void *priv);
839840
* @hgenerator: handle generator state
840841
* @use: number of chain references to this table
841842
* @flags: table flag (see enum nft_table_flags)
843+
* @genmask: generation mask
842844
* @name: name of the table
843845
*/
844846
struct nft_table {
@@ -847,7 +849,8 @@ struct nft_table {
847849
struct list_head sets;
848850
u64 hgenerator;
849851
u32 use;
850-
u16 flags;
852+
u16 flags:14,
853+
genmask:2;
851854
char name[NFT_TABLE_MAXNAMELEN];
852855
};
853856

@@ -970,6 +973,32 @@ static inline u8 nft_genmask_cur(const struct net *net)
970973

971974
#define NFT_GENMASK_ANY ((1 << 0) | (1 << 1))
972975

976+
/*
977+
* Generic transaction helpers
978+
*/
979+
980+
/* Check if this object is currently active. */
981+
#define nft_is_active(__net, __obj) \
982+
(((__obj)->genmask & nft_genmask_cur(__net)) == 0)
983+
984+
/* Check if this object is active in the next generation. */
985+
#define nft_is_active_next(__net, __obj) \
986+
(((__obj)->genmask & nft_genmask_next(__net)) == 0)
987+
988+
/* This object becomes active in the next generation. */
989+
#define nft_activate_next(__net, __obj) \
990+
(__obj)->genmask = nft_genmask_cur(__net)
991+
992+
/* This object becomes inactive in the next generation. */
993+
#define nft_deactivate_next(__net, __obj) \
994+
(__obj)->genmask = nft_genmask_next(__net)
995+
996+
/* After committing the ruleset, clear the stale generation bit. */
997+
#define nft_clear(__net, __obj) \
998+
(__obj)->genmask &= ~nft_genmask_next(__net)
999+
#define nft_active_genmask(__obj, __genmask) \
1000+
!((__obj)->genmask & __genmask)
1001+
9731002
/*
9741003
* Set element transaction helpers
9751004
*/

include/uapi/linux/netfilter/nf_tables.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,20 +546,26 @@ enum nft_cmp_attributes {
546546
};
547547
#define NFTA_CMP_MAX (__NFTA_CMP_MAX - 1)
548548

549+
enum nft_lookup_flags {
550+
NFT_LOOKUP_F_INV = (1 << 0),
551+
};
552+
549553
/**
550554
* enum nft_lookup_attributes - nf_tables set lookup expression netlink attributes
551555
*
552556
* @NFTA_LOOKUP_SET: name of the set where to look for (NLA_STRING)
553557
* @NFTA_LOOKUP_SREG: source register of the data to look for (NLA_U32: nft_registers)
554558
* @NFTA_LOOKUP_DREG: destination register (NLA_U32: nft_registers)
555559
* @NFTA_LOOKUP_SET_ID: uniquely identifies a set in a transaction (NLA_U32)
560+
* @NFTA_LOOKUP_FLAGS: flags (NLA_U32: enum nft_lookup_flags)
556561
*/
557562
enum nft_lookup_attributes {
558563
NFTA_LOOKUP_UNSPEC,
559564
NFTA_LOOKUP_SET,
560565
NFTA_LOOKUP_SREG,
561566
NFTA_LOOKUP_DREG,
562567
NFTA_LOOKUP_SET_ID,
568+
NFTA_LOOKUP_FLAGS,
563569
__NFTA_LOOKUP_MAX
564570
};
565571
#define NFTA_LOOKUP_MAX (__NFTA_LOOKUP_MAX - 1)

include/uapi/linux/netfilter/xt_NFLOG.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@
66
#define XT_NFLOG_DEFAULT_GROUP 0x1
77
#define XT_NFLOG_DEFAULT_THRESHOLD 0
88

9-
#define XT_NFLOG_MASK 0x0
9+
#define XT_NFLOG_MASK 0x1
10+
11+
/* This flag indicates that 'len' field in xt_nflog_info is set*/
12+
#define XT_NFLOG_F_COPY_LEN 0x1
1013

1114
struct xt_nflog_info {
15+
/* 'len' will be used iff you set XT_NFLOG_F_COPY_LEN in flags */
1216
__u32 len;
1317
__u16 group;
1418
__u16 threshold;

net/bridge/netfilter/ebt_802_3.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ ebt_802_3_mt(const struct sk_buff *skb, struct xt_action_param *par)
2020
__be16 type = hdr->llc.ui.ctrl & IS_UI ? hdr->llc.ui.type : hdr->llc.ni.type;
2121

2222
if (info->bitmask & EBT_802_3_SAP) {
23-
if (FWINV(info->sap != hdr->llc.ui.ssap, EBT_802_3_SAP))
23+
if (NF_INVF(info, EBT_802_3_SAP, info->sap != hdr->llc.ui.ssap))
2424
return false;
25-
if (FWINV(info->sap != hdr->llc.ui.dsap, EBT_802_3_SAP))
25+
if (NF_INVF(info, EBT_802_3_SAP, info->sap != hdr->llc.ui.dsap))
2626
return false;
2727
}
2828

2929
if (info->bitmask & EBT_802_3_TYPE) {
3030
if (!(hdr->llc.ui.dsap == CHECK_TYPE && hdr->llc.ui.ssap == CHECK_TYPE))
3131
return false;
32-
if (FWINV(info->type != type, EBT_802_3_TYPE))
32+
if (NF_INVF(info, EBT_802_3_TYPE, info->type != type))
3333
return false;
3434
}
3535

0 commit comments

Comments
 (0)