Netfilter updates for net-next
Subsystems (4)
Pablo Neira Ayuso
maintainercover Netfilter updates for net-next
Hi,
The following patchset contains Netfilter updates for net-next:
1) Move existing bridge packet reject infra to nf_reject_{ipv4,ipv6}.c from Jose M. Guisado.
2) Consolidate nft_reject_inet initialization and dump, also from Jose.
3) Add the netdev reject action, from Jose.
4) Allow to combine the exist flag and the destroy command in ipset, from Joszef Kadlecsik.
5) Expose bucket size parameter for hashtables, also from Jozsef.
6) Expose the init value for reproducible ipset listings, from Jozsef.
7) Use __printf attribute in nft_request_module, from Andrew Lunn.
8) Allow to use reject from the inet ingress chain.
Please, pull these changes from:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next.git
Thanks.
----------------------------------------------------------------
The following changes since commit 37d38ece9b898ea183db9e5a6582651e6ed64c9a:
net/mac8390: discard unnecessary breaks (2020-10-29 19:03:46 -0700)
are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next.git HEAD
for you to fetch changes up to 117ca1f8920cf4087bf82f44bd2a51b49d6aae63:
netfilter: nft_reject_inet: allow to use reject from inet ingress (2020-11-01 12:52:17 +0100)
----------------------------------------------------------------
Andrew Lunn (1):
netfilter: nftables: Add __printf() attribute
Jose M. Guisado Gomez (3):
netfilter: nf_reject: add reject skbuff creation helpers
netfilter: nft_reject: unify reject init and dump into nft_reject
netfilter: nft_reject: add reject verdict support for netdev
Jozsef Kadlecsik (3):
netfilter: ipset: Support the -exist flag with the destroy command
netfilter: ipset: Add bucketsize parameter to all hash types
netfilter: ipset: Expose the initval hash parameter to userspace
Pablo Neira Ayuso (1):
netfilter: nft_reject_inet: allow to use reject from inet ingress
include/linux/netfilter/ipset/ip_set.h | 5 + include/net/netfilter/ipv4/nf_reject.h | 10 ++ include/net/netfilter/ipv6/nf_reject.h | 9 + include/uapi/linux/netfilter/ipset/ip_set.h | 6 +- net/bridge/netfilter/Kconfig | 2 +- net/bridge/netfilter/nft_reject_bridge.c | 255 +-------------------------- net/ipv4/netfilter/nf_reject_ipv4.c | 128 +++++++++++++- net/ipv6/netfilter/nf_reject_ipv6.c | 139 ++++++++++++++- net/netfilter/Kconfig | 10 ++ net/netfilter/Makefile | 1 + net/netfilter/ipset/ip_set_core.c | 6 +- net/netfilter/ipset/ip_set_hash_gen.h | 45 +++-- net/netfilter/ipset/ip_set_hash_ip.c | 7 +- net/netfilter/ipset/ip_set_hash_ipmac.c | 6 +- net/netfilter/ipset/ip_set_hash_ipmark.c | 7 +- net/netfilter/ipset/ip_set_hash_ipport.c | 7 +- net/netfilter/ipset/ip_set_hash_ipportip.c | 7 +- net/netfilter/ipset/ip_set_hash_ipportnet.c | 7 +- net/netfilter/ipset/ip_set_hash_mac.c | 6 +- net/netfilter/ipset/ip_set_hash_net.c | 7 +- net/netfilter/ipset/ip_set_hash_netiface.c | 7 +- net/netfilter/ipset/ip_set_hash_netnet.c | 7 +- net/netfilter/ipset/ip_set_hash_netport.c | 7 +- net/netfilter/ipset/ip_set_hash_netportnet.c | 7 +- net/netfilter/nf_tables_api.c | 3 +- net/netfilter/nft_reject.c | 12 +- net/netfilter/nft_reject_inet.c | 68 ++----- net/netfilter/nft_reject_netdev.c | 189 ++++++++++++++++++++ 28 files changed, 615 insertions(+), 355 deletions(-) create mode 100644 net/netfilter/nft_reject_netdev.c
Pablo Neira Ayuso
maintainerPATCH 1/8 netfilter: nf_reject: add reject skbuff creation helpers
From: "Jose M. Guisado Gomez" <[email protected]>
Adds reject skbuff creation helper functions to ipv4/6 nf_reject infrastructure. Use these functions for reject verdict in bridge family.
Can be reused by all different families that support reject and will not inject the reject packet through ip local out.
--- include/net/netfilter/ipv4/nf_reject.h | 10 ++ include/net/netfilter/ipv6/nf_reject.h | 9 ++ net/bridge/netfilter/Kconfig | 2 +- net/bridge/netfilter/nft_reject_bridge.c | 195 +---------------------- net/ipv4/netfilter/nf_reject_ipv4.c | 122 ++++++++++++++ net/ipv6/netfilter/nf_reject_ipv6.c | 134 ++++++++++++++++ 6 files changed, 280 insertions(+), 192 deletions(-)
include/net/netfilter/ipv4/nf_reject.h +10 -0
@@ -18,4 +18,14 @@ struct iphdr *nf_reject_iphdr_put(struct sk_buff *nskb,void nf_reject_ip_tcphdr_put (struct sk_buff *nskb,const struct sk_buff *oldskb,const struct tcphdr *oth); +struct sk_buff *nf_reject_skb_v4_unreach (struct net *net, +struct sk_buff *oldskb, +const struct net_device *dev, +int hook,u8 code); +struct sk_buff *nf_reject_skb_v4_tcp_reset (struct net *net, +struct sk_buff *oldskb, +const struct net_device *dev, +int hook); + +#endif /* _IPV4_NF_REJECT_H */
include/net/netfilter/ipv6/nf_reject.h +9 -0
@@ -20,4 +20,13 @@ void nf_reject_ip6_tcphdr_put(struct sk_buff *nskb,const struct sk_buff *oldskb, const struct tcphdr *oth, unsigned int otcplen); +struct sk_buff *nf_reject_skb_v6_tcp_reset (struct net *net, +struct sk_buff *oldskb, +const struct net_device *dev, +int hook); +struct sk_buff *nf_reject_skb_v6_unreach (struct net *net, +struct sk_buff *oldskb, +const struct net_device *dev, +int hook,u8 code); +#endif /* _IPV6_NF_REJECT_H */
net/bridge/netfilter/Kconfig +1 -1
@@ -17,7 +17,7 @@ config NFT_BRIDGE_META config NFT_BRIDGE_REJECT tristate "Netfilter nf_tables bridge reject support" - depends on NFT_REJECT && NFT_REJECT_IPV4 && NFT_REJECT_IPV6 + depends on NFT_REJECT help Add support to reject packets.
net/bridge/netfilter/nft_reject_bridge.c +4 -191
251 lines not on this page · raw message
net/ipv4/netfilter/nf_reject_ipv4.c +122 -0
128 lines not on this page · raw message
net/ipv6/netfilter/nf_reject_ipv6.c +134 -0
140 lines not on this page · raw message
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerPATCH 2/8 netfilter: nft_reject: unify reject init and dump into nft_reject
In reply to Pablo Neira AyusoFrom: "Jose M. Guisado Gomez" <[email protected]>
Bridge family is using the same static init and dump function as inet.
This patch removes duplicate code unifying these functions body into nft_reject.c so they can be reused in the rest of families supporting reject verdict.
--- net/bridge/netfilter/nft_reject_bridge.c | 60 +----------------------- net/netfilter/nft_reject.c | 12 ++++- net/netfilter/nft_reject_inet.c | 60 +----------------------- 3 files changed, 15 insertions(+), 117 deletions(-)
net/bridge/netfilter/nft_reject_bridge.c +2 -58
@@ -177,69 +177,13 @@ static int nft_reject_bridge_validate(const struct nft_ctx *ctx, (1 << NF_BR_LOCAL_IN)); } -static int nft_reject_bridge_init (const struct nft_ctx *ctx, -const struct nft_expr *expr, -const struct nlattr *const tb[]) -{ -struct nft_reject *priv =nft_expr_priv (expr); -int icmp_code; - -if (tb[NFTA_REJECT_TYPE ] ==NULL ) -return -EINVAL ; - - priv->type =ntohl (nla_get_be32 (tb[NFTA_REJECT_TYPE ])); -switch (priv->type) { -case NFT_REJECT_ICMP_UNREACH : -case NFT_REJECT_ICMPX_UNREACH : -if (tb[NFTA_REJECT_ICMP_CODE ] ==NULL ) -return -EINVAL ; - - icmp_code =nla_get_u8 (tb[NFTA_REJECT_ICMP_CODE ]); -if (priv->type ==NFT_REJECT_ICMPX_UNREACH && - icmp_code >NFT_REJECT_ICMPX_MAX ) -return -EINVAL ; - - priv->icmp_code = icmp_code; -break ; -case NFT_REJECT_TCP_RST : -break ; -default : -return -EINVAL ; - } -return 0 ; -} - -static int nft_reject_bridge_dump (struct sk_buff *skb, -const struct nft_expr *expr) -{ -const struct nft_reject *priv =nft_expr_priv (expr); - -if (nla_put_be32 (skb,NFTA_REJECT_TYPE ,htonl (priv->type))) - goto nla_put_failure; - -switch (priv->type) { -case NFT_REJECT_ICMP_UNREACH : -case NFT_REJECT_ICMPX_UNREACH : -if (nla_put_u8 (skb,NFTA_REJECT_ICMP_CODE , priv->icmp_code)) - goto nla_put_failure; -break ; -default : -break ; - } - -return 0 ; - -nla_put_failure: -return -1 ; -} -static struct nft_expr_type nft_reject_bridge_type;static const struct nft_expr_ops nft_reject_bridge_ops = { .type = &nft_reject_bridge_type, .size =NFT_EXPR_SIZE (sizeof (struct nft_reject )), .eval = nft_reject_bridge_eval, - .init = nft_reject_bridge_init, - .dump = nft_reject_bridge_dump, + .init = nft_reject_init, + .dump = nft_reject_dump, .validate = nft_reject_bridge_validate, };
net/netfilter/nft_reject.c +11 -1
@@ -40,6 +40,7 @@ int nft_reject_init(const struct nft_ctx *ctx, const struct nlattr * const tb[]) {struct nft_reject *priv =nft_expr_priv (expr); +int icmp_code;if (tb[NFTA_REJECT_TYPE ] ==NULL )return -EINVAL ;
@@ -47,9 +48,17 @@ int nft_reject_init(const struct nft_ctx *ctx, priv->type =ntohl (nla_get_be32 (tb[NFTA_REJECT_TYPE ]));switch (priv->type) {case NFT_REJECT_ICMP_UNREACH : +case NFT_REJECT_ICMPX_UNREACH :if (tb[NFTA_REJECT_ICMP_CODE ] ==NULL )return -EINVAL ; - priv->icmp_code =nla_get_u8 (tb[NFTA_REJECT_ICMP_CODE ]); + + icmp_code =nla_get_u8 (tb[NFTA_REJECT_ICMP_CODE ]); +if (priv->type ==NFT_REJECT_ICMPX_UNREACH && + icmp_code >NFT_REJECT_ICMPX_MAX ) +return -EINVAL ; + + priv->icmp_code = icmp_code; +break ;case NFT_REJECT_TCP_RST :break ;default :
@@ -69,6 +78,7 @@ int nft_reject_dump(struct sk_buff *skb, const struct nft_expr *expr)switch (priv->type) {case NFT_REJECT_ICMP_UNREACH : +case NFT_REJECT_ICMPX_UNREACH :if (nla_put_u8 (skb,NFTA_REJECT_ICMP_CODE , priv->icmp_code)) goto nla_put_failure;break ;
net/netfilter/nft_reject_inet.c +2 -58
71 lines not on this page · raw message
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerPATCH 3/8 netfilter: nft_reject: add reject verdict support for netdev
In reply to Pablo Neira AyusoFrom: "Jose M. Guisado Gomez" <[email protected]>
Adds support for reject from ingress hook in netdev family. Both stacks ipv4 and ipv6. With reject packets supporting ICMP and TCP RST.
This ability is required in devices that need to REJECT legitimate clients which traffic is forwarded from the ingress hook.
Joint work with Laura Garcia.
--- net/netfilter/Kconfig | 10 ++ net/netfilter/Makefile | 1 + net/netfilter/nft_reject_netdev.c | 189 ++++++++++++++++++++++++++++++ 3 files changed, 200 insertions(+) create mode 100644 net/netfilter/nft_reject_netdev.c
net/netfilter/Kconfig +10 -0
@@ -682,6 +682,16 @@ config NFT_FIB_NETDEV The lookup will be delegated to the IPv4 or IPv6 FIB depending on the protocol of the packet. +config NFT_REJECT_NETDEV + depends on NFT_REJECT_IPV4 + depends on NFT_REJECT_IPV6 + tristate "Netfilter nf_tables netdev REJECT support" + help + This option enables the REJECT support from the netdev table. + The return packet generation will be delegated to the IPv4 + or IPv6 ICMP or TCP RST implementation depending on the + protocol of the packet. + endif # NF_TABLES_NETDEV endif # NF_TABLES
net/netfilter/Makefile +1 -0
@@ -101,6 +101,7 @@ obj-$(CONFIG_NFT_QUEUE) += nft_queue.o obj-$(CONFIG_NFT_QUOTA) += nft_quota.o obj-$(CONFIG_NFT_REJECT) += nft_reject.o obj-$(CONFIG_NFT_REJECT_INET) += nft_reject_inet.o +obj-$(CONFIG_NFT_REJECT_NETDEV) += nft_reject_netdev.o obj-$(CONFIG_NFT_TUNNEL) += nft_tunnel.o obj-$(CONFIG_NFT_COUNTER) += nft_counter.o obj-$(CONFIG_NFT_LOG) += nft_log.o
net/netfilter/nft_reject_netdev.c new file +189 -0
189 lines not on this page · raw message
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerPATCH 4/8 netfilter: ipset: Support the -exist flag with the destroy command
In reply to Pablo Neira AyusoFrom: Jozsef Kadlecsik <[email protected]>
The -exist flag was supported with the create, add and delete commands. In order to gracefully handle the destroy command with nonexistent sets, the -exist flag is added to destroy too.
--- net/netfilter/ipset/ip_set_core.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
net/netfilter/ipset/ip_set_core.c +3 -1
@@ -1239,10 +1239,12 @@ static int ip_set_destroy(struct net *net, struct sock *ctnl,/* Modified by ip_set_destroy() only, which is serialized */ inst->is_destroyed = false; }else { +u32 flags =flag_exist (nlh); s =find_set_and_id (inst,nla_data (attr[IPSET_ATTR_SETNAME ]), &i);if (!s) { - ret = -ENOENT ; +if (!(flags &IPSET_FLAG_EXIST )) + ret = -ENOENT ; goto out; }else if (s->ref || s->ref_netlink) { ret = -IPSET_ERR_BUSY ;
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerPATCH 5/8 netfilter: ipset: Add bucketsize parameter to all hash types
In reply to Pablo Neira AyusoFrom: Jozsef Kadlecsik <[email protected]>
The parameter defines the upper limit in any hash bucket at adding new entries from userspace - if the limit would be exceeded, ipset doubles the hash size and rehashes. It means the set may consume more memory but gives faster evaluation at matching in the set.
--- include/linux/netfilter/ipset/ip_set.h | 5 +++ include/uapi/linux/netfilter/ipset/ip_set.h | 4 ++- net/netfilter/ipset/ip_set_core.c | 2 ++ net/netfilter/ipset/ip_set_hash_gen.h | 38 ++++++++++++-------- net/netfilter/ipset/ip_set_hash_ip.c | 6 ++-- net/netfilter/ipset/ip_set_hash_ipmac.c | 5 +-- net/netfilter/ipset/ip_set_hash_ipmark.c | 6 ++-- net/netfilter/ipset/ip_set_hash_ipport.c | 6 ++-- net/netfilter/ipset/ip_set_hash_ipportip.c | 6 ++-- net/netfilter/ipset/ip_set_hash_ipportnet.c | 6 ++-- net/netfilter/ipset/ip_set_hash_mac.c | 5 +-- net/netfilter/ipset/ip_set_hash_net.c | 6 ++-- net/netfilter/ipset/ip_set_hash_netiface.c | 6 ++-- net/netfilter/ipset/ip_set_hash_netnet.c | 6 ++-- net/netfilter/ipset/ip_set_hash_netport.c | 6 ++-- net/netfilter/ipset/ip_set_hash_netportnet.c | 6 ++-- 16 files changed, 79 insertions(+), 40 deletions(-)
include/linux/netfilter/ipset/ip_set.h +5 -0
@@ -198,6 +198,9 @@ struct ip_set_region {u32 elements;/* Number of elements vs timeout */ }; +/* The max revision number supported by any set type + 1 */ +#define IPSET_REVISION_MAX 9 +/* The core set type structure */ struct ip_set_type {struct list_head list;
@@ -215,6 +218,8 @@ struct ip_set_type {u8 family;/* Type revisions */ u8 revision_min, revision_max; +/* Revision-specific supported (create) flags */ +u8 create_flags[IPSET_REVISION_MAX +1 ];/* Set features to control swapping */ u16 features;
include/uapi/linux/netfilter/ipset/ip_set.h +3 -1
@@ -96,7 +96,7 @@ enum {IPSET_ATTR_HASHSIZE ,IPSET_ATTR_MAXELEM ,IPSET_ATTR_NETMASK , -IPSET_ATTR_PROBES , +IPSET_ATTR_BUCKETSIZE ,/* was unused IPSET_ATTR_PROBES */ IPSET_ATTR_RESIZE , IPSET_ATTR_SIZE,/* Kernel-only */
@@ -214,6 +214,8 @@ enum ipset_cadt_flags {enum ipset_create_flags {IPSET_CREATE_FLAG_BIT_FORCEADD =0 ,IPSET_CREATE_FLAG_FORCEADD = (1 <<IPSET_CREATE_FLAG_BIT_FORCEADD ), +IPSET_CREATE_FLAG_BIT_BUCKETSIZE =1 , +IPSET_CREATE_FLAG_BUCKETSIZE = (1 <<IPSET_CREATE_FLAG_BIT_BUCKETSIZE ),IPSET_CREATE_FLAG_BIT_MAX =7 , };
net/netfilter/ipset/ip_set_core.c +2 -0
@@ -1109,6 +1109,8 @@ static int ip_set_create(struct net *net, struct sock *ctnl, ret = -IPSET_ERR_PROTOCOL ; goto put_out; } +/* Set create flags depending on the type revision */ + set->flags |= set->type->create_flags[revision]; ret = set->type->create (net, set, tb, flags);if (ret !=0 )
net/netfilter/ipset/ip_set_hash_gen.h +23 -15
@@ -37,18 +37,18 @@*/ /* Number of elements to store in an initial array block */ -#define AHASH_INIT_SIZE 4 +#define AHASH_INIT_SIZE 2/* Max number of elements to store in an array block */ -#define AHASH_MAX_SIZE (3 * AHASH_INIT_SIZE) +#define AHASH_MAX_SIZE (6 * AHASH_INIT_SIZE)/* Max muber of elements in the array block when tuned */ #define AHASH_MAX_TUNED 64 +#define AHASH_MAX (h) ((h)->bucketsize) +/* Max number of elements can be tuned */ #ifdef IP_SET_HASH_WITH_MULTI -#define AHASH_MAX (h) ((h)->ahash_max) -static u8 -tune_ahash_max (u8 curr,u32 multi) +tune_bucketsize (u8 curr,u32 multi) {u32 n;
@@ -61,12 +61,10 @@ tune_ahash_max(u8 curr, u32 multi)*/ return n > curr && n <= AHASH_MAX_TUNED ? n : curr; } - -#define TUNE_AHASH_MAX (h, multi) \ - ((h)->ahash_max = tune_ahash_max((h)->ahash_max, multi)) +#define TUNE_BUCKETSIZE (h, multi) \ + ((h)->bucketsize = tune_bucketsize((h)->bucketsize, multi))#else -#define AHASH_MAX (h) AHASH_MAX_SIZE -#define TUNE_AHASH_MAX (h, multi) +#define TUNE_BUCKETSIZE (h, multi)#endif /* A hash bucket */
@@ -321,9 +319,7 @@ struct htype {#ifdef IP_SET_HASH_WITH_MARKMASK u32 markmask;/* markmask value for mark mask to store */ #endif -#ifdef IP_SET_HASH_WITH_MULTI -u8 ahash_max;/* max elements in an array block */ -#endif +u8 bucketsize;/* max elements in an array block */ #ifdef IP_SET_HASH_WITH_NETMASK u8 netmask;/* netmask value for subnets to store */ #endif
@@ -950,7 +946,7 @@ mtype_add(struct ip_set *set, void *value, const struct ip_set_ext *ext, goto set_full;/* Create a new slot */ if (n->pos >= n->size) { -TUNE_AHASH_MAX (h, multi); +TUNE_BUCKETSIZE (h, multi);if (n->size >=AHASH_MAX (h)) {/* Trigger rehashing */ mtype_data_next (&h->next, d);
@@ -1305,6 +1301,9 @@ mtype_head(struct ip_set *set, struct sk_buff *skb)if (nla_put_u32 (skb,IPSET_ATTR_MARKMASK , h->markmask)) goto nla_put_failure;#endif +if (set->flags &IPSET_CREATE_FLAG_BUCKETSIZE && +nla_put_u8 (skb,IPSET_ATTR_BUCKETSIZE , h->bucketsize)) + goto nla_put_failure;if (nla_put_net32 (skb,IPSET_ATTR_REFERENCES ,htonl (set->ref)) ||nla_put_net32 (skb,IPSET_ATTR_MEMSIZE ,htonl (memsize)) ||nla_put_net32 (skb,IPSET_ATTR_ELEMENTS ,htonl (elements)))
@@ -1548,7 +1547,16 @@ IPSET_TOKEN(HTYPE, _create)(struct net *net, struct ip_set *set, h->markmask = markmask;#endif get_random_bytes (&h->initval,sizeof (h->initval)); - + h->bucketsize =AHASH_MAX_SIZE ; +if (tb[IPSET_ATTR_BUCKETSIZE ]) { + h->bucketsize =nla_get_u8 (tb[IPSET_ATTR_BUCKETSIZE ]); +if (h->bucketsize <AHASH_INIT_SIZE ) + h->bucketsize =AHASH_INIT_SIZE ; +else if (h->bucketsize >AHASH_MAX_SIZE ) + h->bucketsize =AHASH_MAX_SIZE ; +else if (h->bucketsize %2 ) + h->bucketsize +=1 ; + } t->htable_bits = hbits; t->maxelem = h->maxelem /ahash_numof_locks (hbits);RCU_INIT_POINTER (h->table, t);
net/netfilter/ipset/ip_set_hash_ip.c +4 -2
@@ -23,7 +23,8 @@/* 1 Counters support */ /* 2 Comments support */ /* 3 Forceadd support */ -#define IPSET_TYPE_REV_MAX 4/* skbinfo support */ +/* 4 skbinfo support */ +#define IPSET_TYPE_REV_MAX 5/* bucketsize support */ MODULE_LICENSE ("GPL" );MODULE_AUTHOR ("Jozsef Kadlecsik <[email protected]>" );
@@ -277,11 +278,12 @@ static struct ip_set_type hash_ip_type __read_mostly = { .family = NFPROTO_UNSPEC, .revision_min = IPSET_TYPE_REV_MIN, .revision_max = IPSET_TYPE_REV_MAX, + .create_flags[IPSET_TYPE_REV_MAX] = IPSET_CREATE_FLAG_BUCKETSIZE, .create = hash_ip_create, .create_policy = { [IPSET_ATTR_HASHSIZE] = { .type = NLA_U32 }, [IPSET_ATTR_MAXELEM] = { .type = NLA_U32 }, - [IPSET_ATTR_PROBES] = { .type = NLA_U8 }, + [IPSET_ATTR_BUCKETSIZE] = { .type = NLA_U8 }, [IPSET_ATTR_RESIZE] = { .type = NLA_U8 }, [IPSET_ATTR_TIMEOUT] = { .type = NLA_U32 }, [IPSET_ATTR_NETMASK] = { .type = NLA_U8 },
net/netfilter/ipset/ip_set_hash_ipmac.c +3 -2
@@ -23,7 +23,7 @@#include <linux/netfilter/ipset/ip_set_hash.h> #define IPSET_TYPE_REV_MIN 0 -#define IPSET_TYPE_REV_MAX 0 +#define IPSET_TYPE_REV_MAX 1/* bucketsize support */ MODULE_LICENSE ("GPL" );MODULE_AUTHOR ("Tomasz Chilinski <[email protected]>" );
@@ -268,11 +268,12 @@ static struct ip_set_type hash_ipmac_type __read_mostly = { .family = NFPROTO_UNSPEC, .revision_min = IPSET_TYPE_REV_MIN, .revision_max = IPSET_TYPE_REV_MAX, + .create_flags[IPSET_TYPE_REV_MAX] = IPSET_CREATE_FLAG_BUCKETSIZE, .create = hash_ipmac_create, .create_policy = { [IPSET_ATTR_HASHSIZE] = { .type = NLA_U32 }, [IPSET_ATTR_MAXELEM] = { .type = NLA_U32 }, - [IPSET_ATTR_PROBES] = { .type = NLA_U8 }, + [IPSET_ATTR_BUCKETSIZE] = { .type = NLA_U8 }, [IPSET_ATTR_RESIZE] = { .type = NLA_U8 }, [IPSET_ATTR_TIMEOUT] = { .type = NLA_U32 }, [IPSET_ATTR_CADT_FLAGS] = { .type = NLA_U32 },
net/netfilter/ipset/ip_set_hash_ipmark.c +4 -2
@@ -21,7 +21,8 @@#define IPSET_TYPE_REV_MIN 0/* 1 Forceadd support */ -#define IPSET_TYPE_REV_MAX 2/* skbinfo support */ +/* 2 skbinfo support */ +#define IPSET_TYPE_REV_MAX 3/* bucketsize support */ MODULE_LICENSE ("GPL" );MODULE_AUTHOR ("Vytas Dauksa <[email protected]>" );
@@ -274,12 +275,13 @@ static struct ip_set_type hash_ipmark_type __read_mostly = { .family = NFPROTO_UNSPEC, .revision_min = IPSET_TYPE_REV_MIN, .revision_max = IPSET_TYPE_REV_MAX, + .create_flags[IPSET_TYPE_REV_MAX] = IPSET_CREATE_FLAG_BUCKETSIZE, .create = hash_ipmark_create, .create_policy = { [IPSET_ATTR_MARKMASK] = { .type = NLA_U32 }, [IPSET_ATTR_HASHSIZE] = { .type = NLA_U32 }, [IPSET_ATTR_MAXELEM] = { .type = NLA_U32 }, - [IPSET_ATTR_PROBES] = { .type = NLA_U8 }, + [IPSET_ATTR_BUCKETSIZE] = { .type = NLA_U8 }, [IPSET_ATTR_RESIZE] = { .type = NLA_U8 }, [IPSET_ATTR_TIMEOUT] = { .type = NLA_U32 }, [IPSET_ATTR_CADT_FLAGS] = { .type = NLA_U32 },
net/netfilter/ipset/ip_set_hash_ipport.c +4 -2
@@ -25,7 +25,8 @@/* 2 Counters support added */ /* 3 Comments support added */ /* 4 Forceadd support added */ -#define IPSET_TYPE_REV_MAX 5/* skbinfo support added */ +/* 5 skbinfo support added */ +#define IPSET_TYPE_REV_MAX 6/* bucketsize support added */ MODULE_LICENSE ("GPL" );MODULE_AUTHOR ("Jozsef Kadlecsik <[email protected]>" );
@@ -341,11 +342,12 @@ static struct ip_set_type hash_ipport_type __read_mostly = { .family = NFPROTO_UNSPEC, .revision_min = IPSET_TYPE_REV_MIN, .revision_max = IPSET_TYPE_REV_MAX, + .create_flags[IPSET_TYPE_REV_MAX] = IPSET_CREATE_FLAG_BUCKETSIZE, .create = hash_ipport_create, .create_policy = { [IPSET_ATTR_HASHSIZE] = { .type = NLA_U32 }, [IPSET_ATTR_MAXELEM] = { .type = NLA_U32 }, - [IPSET_ATTR_PROBES] = { .type = NLA_U8 }, + [IPSET_ATTR_BUCKETSIZE] = { .type = NLA_U8 }, [IPSET_ATTR_RESIZE] = { .type = NLA_U8 }, [IPSET_ATTR_PROTO] = { .type = NLA_U8 }, [IPSET_ATTR_TIMEOUT] = { .type = NLA_U32 },
net/netfilter/ipset/ip_set_hash_ipportip.c +4 -2
@@ -25,7 +25,8 @@/* 2 Counters support added */ /* 3 Comments support added */ /* 4 Forceadd support added */ -#define IPSET_TYPE_REV_MAX 5/* skbinfo support added */ +/* 5 skbinfo support added */ +#define IPSET_TYPE_REV_MAX 6/* bucketsize support added */ MODULE_LICENSE ("GPL" );MODULE_AUTHOR ("Jozsef Kadlecsik <[email protected]>" );
@@ -356,11 +357,12 @@ static struct ip_set_type hash_ipportip_type __read_mostly = { .family = NFPROTO_UNSPEC, .revision_min = IPSET_TYPE_REV_MIN, .revision_max = IPSET_TYPE_REV_MAX, + .create_flags[IPSET_TYPE_REV_MAX] = IPSET_CREATE_FLAG_BUCKETSIZE, .create = hash_ipportip_create, .create_policy = { [IPSET_ATTR_HASHSIZE] = { .type = NLA_U32 }, [IPSET_ATTR_MAXELEM] = { .type = NLA_U32 }, - [IPSET_ATTR_PROBES] = { .type = NLA_U8 }, + [IPSET_ATTR_BUCKETSIZE] = { .type = NLA_U8 }, [IPSET_ATTR_RESIZE] = { .type = NLA_U8 }, [IPSET_ATTR_TIMEOUT] = { .type = NLA_U32 }, [IPSET_ATTR_CADT_FLAGS] = { .type = NLA_U32 },
net/netfilter/ipset/ip_set_hash_ipportnet.c +4 -2
@@ -27,7 +27,8 @@/* 4 Counters support added */ /* 5 Comments support added */ /* 6 Forceadd support added */ -#define IPSET_TYPE_REV_MAX 7/* skbinfo support added */ +/* 7 skbinfo support added */ +#define IPSET_TYPE_REV_MAX 8/* bucketsize support added */ MODULE_LICENSE ("GPL" );MODULE_AUTHOR ("Jozsef Kadlecsik <[email protected]>" );
@@ -513,11 +514,12 @@ static struct ip_set_type hash_ipportnet_type __read_mostly = { .family = NFPROTO_UNSPEC, .revision_min = IPSET_TYPE_REV_MIN, .revision_max = IPSET_TYPE_REV_MAX, + .create_flags[IPSET_TYPE_REV_MAX] = IPSET_CREATE_FLAG_BUCKETSIZE, .create = hash_ipportnet_create, .create_policy = { [IPSET_ATTR_HASHSIZE] = { .type = NLA_U32 }, [IPSET_ATTR_MAXELEM] = { .type = NLA_U32 }, - [IPSET_ATTR_PROBES] = { .type = NLA_U8 }, + [IPSET_ATTR_BUCKETSIZE] = { .type = NLA_U8 }, [IPSET_ATTR_RESIZE] = { .type = NLA_U8 }, [IPSET_ATTR_TIMEOUT] = { .type = NLA_U32 }, [IPSET_ATTR_CADT_FLAGS] = { .type = NLA_U32 },
net/netfilter/ipset/ip_set_hash_mac.c +3 -2
@@ -16,7 +16,7 @@#include <linux/netfilter/ipset/ip_set_hash.h> #define IPSET_TYPE_REV_MIN 0 -#define IPSET_TYPE_REV_MAX 0 +#define IPSET_TYPE_REV_MAX 1/* bucketsize support */ MODULE_LICENSE ("GPL" );MODULE_AUTHOR ("Jozsef Kadlecsik <[email protected]>" );
@@ -125,11 +125,12 @@ static struct ip_set_type hash_mac_type __read_mostly = { .family = NFPROTO_UNSPEC, .revision_min = IPSET_TYPE_REV_MIN, .revision_max = IPSET_TYPE_REV_MAX, + .create_flags[IPSET_TYPE_REV_MAX] = IPSET_CREATE_FLAG_BUCKETSIZE, .create = hash_mac_create, .create_policy = { [IPSET_ATTR_HASHSIZE] = { .type = NLA_U32 }, [IPSET_ATTR_MAXELEM] = { .type = NLA_U32 }, - [IPSET_ATTR_PROBES] = { .type = NLA_U8 }, + [IPSET_ATTR_BUCKETSIZE] = { .type = NLA_U8 }, [IPSET_ATTR_RESIZE] = { .type = NLA_U8 }, [IPSET_ATTR_TIMEOUT] = { .type = NLA_U32 }, [IPSET_ATTR_CADT_FLAGS] = { .type = NLA_U32 },
net/netfilter/ipset/ip_set_hash_net.c +4 -2
@@ -24,7 +24,8 @@/* 3 Counters support added */ /* 4 Comments support added */ /* 5 Forceadd support added */ -#define IPSET_TYPE_REV_MAX 6/* skbinfo mapping support added */ +/* 6 skbinfo support added */ +#define IPSET_TYPE_REV_MAX 7/* bucketsize support added */ MODULE_LICENSE ("GPL" );MODULE_AUTHOR ("Jozsef Kadlecsik <[email protected]>" );
@@ -354,11 +355,12 @@ static struct ip_set_type hash_net_type __read_mostly = { .family = NFPROTO_UNSPEC, .revision_min = IPSET_TYPE_REV_MIN, .revision_max = IPSET_TYPE_REV_MAX, + .create_flags[IPSET_TYPE_REV_MAX] = IPSET_CREATE_FLAG_BUCKETSIZE, .create = hash_net_create, .create_policy = { [IPSET_ATTR_HASHSIZE] = { .type = NLA_U32 }, [IPSET_ATTR_MAXELEM] = { .type = NLA_U32 }, - [IPSET_ATTR_PROBES] = { .type = NLA_U8 }, + [IPSET_ATTR_BUCKETSIZE] = { .type = NLA_U8 }, [IPSET_ATTR_RESIZE] = { .type = NLA_U8 }, [IPSET_ATTR_TIMEOUT] = { .type = NLA_U32 }, [IPSET_ATTR_CADT_FLAGS] = { .type = NLA_U32 },
net/netfilter/ipset/ip_set_hash_netiface.c +4 -2
@@ -26,7 +26,8 @@/* 4 Comments support added */ /* 5 Forceadd support added */ /* 6 skbinfo support added */ -#define IPSET_TYPE_REV_MAX 7/* interface wildcard support added */ +/* 7 interface wildcard support added */ +#define IPSET_TYPE_REV_MAX 8/* bucketsize support added */ MODULE_LICENSE ("GPL" );MODULE_AUTHOR ("Jozsef Kadlecsik <[email protected]>" );
@@ -470,11 +471,12 @@ static struct ip_set_type hash_netiface_type __read_mostly = { .family = NFPROTO_UNSPEC, .revision_min = IPSET_TYPE_REV_MIN, .revision_max = IPSET_TYPE_REV_MAX, + .create_flags[IPSET_TYPE_REV_MAX] = IPSET_CREATE_FLAG_BUCKETSIZE, .create = hash_netiface_create, .create_policy = { [IPSET_ATTR_HASHSIZE] = { .type = NLA_U32 }, [IPSET_ATTR_MAXELEM] = { .type = NLA_U32 }, - [IPSET_ATTR_PROBES] = { .type = NLA_U8 }, + [IPSET_ATTR_BUCKETSIZE] = { .type = NLA_U8 }, [IPSET_ATTR_RESIZE] = { .type = NLA_U8 }, [IPSET_ATTR_PROTO] = { .type = NLA_U8 }, [IPSET_ATTR_TIMEOUT] = { .type = NLA_U32 },
net/netfilter/ipset/ip_set_hash_netnet.c +4 -2
@@ -22,7 +22,8 @@#define IPSET_TYPE_REV_MIN 0/* 1 Forceadd support added */ -#define IPSET_TYPE_REV_MAX 2/* skbinfo support added */ +/* 2 skbinfo support added */ +#define IPSET_TYPE_REV_MAX 3/* bucketsize support added */ MODULE_LICENSE ("GPL" );MODULE_AUTHOR ("Oliver Smith <[email protected]>" );
@@ -459,11 +460,12 @@ static struct ip_set_type hash_netnet_type __read_mostly = { .family = NFPROTO_UNSPEC, .revision_min = IPSET_TYPE_REV_MIN, .revision_max = IPSET_TYPE_REV_MAX, + .create_flags[IPSET_TYPE_REV_MAX] = IPSET_CREATE_FLAG_BUCKETSIZE, .create = hash_netnet_create, .create_policy = { [IPSET_ATTR_HASHSIZE] = { .type = NLA_U32 }, [IPSET_ATTR_MAXELEM] = { .type = NLA_U32 }, - [IPSET_ATTR_PROBES] = { .type = NLA_U8 }, + [IPSET_ATTR_BUCKETSIZE] = { .type = NLA_U8 }, [IPSET_ATTR_RESIZE] = { .type = NLA_U8 }, [IPSET_ATTR_TIMEOUT] = { .type = NLA_U32 }, [IPSET_ATTR_CADT_FLAGS] = { .type = NLA_U32 },
net/netfilter/ipset/ip_set_hash_netport.c +4 -2
@@ -26,7 +26,8 @@/* 4 Counters support added */ /* 5 Comments support added */ /* 6 Forceadd support added */ -#define IPSET_TYPE_REV_MAX 7/* skbinfo support added */ +/* 7 skbinfo support added */ +#define IPSET_TYPE_REV_MAX 8/* bucketsize support added */ MODULE_LICENSE ("GPL" );MODULE_AUTHOR ("Jozsef Kadlecsik <[email protected]>" );
@@ -460,11 +461,12 @@ static struct ip_set_type hash_netport_type __read_mostly = { .family = NFPROTO_UNSPEC, .revision_min = IPSET_TYPE_REV_MIN, .revision_max = IPSET_TYPE_REV_MAX, + .create_flags[IPSET_TYPE_REV_MAX] = IPSET_CREATE_FLAG_BUCKETSIZE, .create = hash_netport_create, .create_policy = { [IPSET_ATTR_HASHSIZE] = { .type = NLA_U32 }, [IPSET_ATTR_MAXELEM] = { .type = NLA_U32 }, - [IPSET_ATTR_PROBES] = { .type = NLA_U8 }, + [IPSET_ATTR_BUCKETSIZE] = { .type = NLA_U8 }, [IPSET_ATTR_RESIZE] = { .type = NLA_U8 }, [IPSET_ATTR_PROTO] = { .type = NLA_U8 }, [IPSET_ATTR_TIMEOUT] = { .type = NLA_U32 },
net/netfilter/ipset/ip_set_hash_netportnet.c +4 -2
@@ -23,7 +23,8 @@#define IPSET_TYPE_REV_MIN 0/* 0 Comments support added */ /* 1 Forceadd support added */ -#define IPSET_TYPE_REV_MAX 2/* skbinfo support added */ +/* 2 skbinfo support added */ +#define IPSET_TYPE_REV_MAX 3/* bucketsize support added */ MODULE_LICENSE ("GPL" );MODULE_AUTHOR ("Oliver Smith <[email protected]>" );
@@ -558,11 +559,12 @@ static struct ip_set_type hash_netportnet_type __read_mostly = { .family = NFPROTO_UNSPEC, .revision_min = IPSET_TYPE_REV_MIN, .revision_max = IPSET_TYPE_REV_MAX, + .create_flags[IPSET_TYPE_REV_MAX] = IPSET_CREATE_FLAG_BUCKETSIZE, .create = hash_netportnet_create, .create_policy = { [IPSET_ATTR_HASHSIZE] = { .type = NLA_U32 }, [IPSET_ATTR_MAXELEM] = { .type = NLA_U32 }, - [IPSET_ATTR_PROBES] = { .type = NLA_U8 }, + [IPSET_ATTR_BUCKETSIZE] = { .type = NLA_U8 }, [IPSET_ATTR_RESIZE] = { .type = NLA_U8 }, [IPSET_ATTR_TIMEOUT] = { .type = NLA_U32 }, [IPSET_ATTR_CADT_FLAGS] = { .type = NLA_U32 },
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerPATCH 6/8 netfilter: ipset: Expose the initval hash parameter to userspace
In reply to Pablo Neira AyusoFrom: Jozsef Kadlecsik <[email protected]>
It makes possible to reproduce exactly the same set after a save/restore.
--- include/uapi/linux/netfilter/ipset/ip_set.h | 2 +- net/netfilter/ipset/ip_set_hash_gen.h | 13 +++++++++---- net/netfilter/ipset/ip_set_hash_ip.c | 3 ++- net/netfilter/ipset/ip_set_hash_ipmac.c | 3 ++- net/netfilter/ipset/ip_set_hash_ipmark.c | 3 ++- net/netfilter/ipset/ip_set_hash_ipport.c | 3 ++- net/netfilter/ipset/ip_set_hash_ipportip.c | 3 ++- net/netfilter/ipset/ip_set_hash_ipportnet.c | 3 ++- net/netfilter/ipset/ip_set_hash_mac.c | 3 ++- net/netfilter/ipset/ip_set_hash_net.c | 3 ++- net/netfilter/ipset/ip_set_hash_netiface.c | 3 ++- net/netfilter/ipset/ip_set_hash_netnet.c | 3 ++- net/netfilter/ipset/ip_set_hash_netport.c | 3 ++- net/netfilter/ipset/ip_set_hash_netportnet.c | 3 ++- 14 files changed, 34 insertions(+), 17 deletions(-)
include/uapi/linux/netfilter/ipset/ip_set.h +1 -1
@@ -92,7 +92,7 @@ enum {/* Reserve empty slots */ IPSET_ATTR_CADT_MAX =16 ,/* Create-only specific attributes */ -IPSET_ATTR_GC , +IPSET_ATTR_INITVAL ,/* was unused IPSET_ATTR_GC */ IPSET_ATTR_HASHSIZE ,IPSET_ATTR_MAXELEM , IPSET_ATTR_NETMASK,
net/netfilter/ipset/ip_set_hash_gen.h +9 -4
@@ -1301,9 +1301,11 @@ mtype_head(struct ip_set *set, struct sk_buff *skb)if (nla_put_u32 (skb,IPSET_ATTR_MARKMASK , h->markmask)) goto nla_put_failure;#endif -if (set->flags &IPSET_CREATE_FLAG_BUCKETSIZE && -nla_put_u8 (skb,IPSET_ATTR_BUCKETSIZE , h->bucketsize)) - goto nla_put_failure; +if (set->flags &IPSET_CREATE_FLAG_BUCKETSIZE ) { +if (nla_put_u8 (skb,IPSET_ATTR_BUCKETSIZE , h->bucketsize) || +nla_put_net32 (skb,IPSET_ATTR_INITVAL ,htonl (h->initval))) + goto nla_put_failure; + }if (nla_put_net32 (skb,IPSET_ATTR_REFERENCES ,htonl (set->ref)) ||nla_put_net32 (skb,IPSET_ATTR_MEMSIZE ,htonl (memsize)) ||nla_put_net32 (skb,IPSET_ATTR_ELEMENTS ,htonl (elements)))
@@ -1546,7 +1548,10 @@ IPSET_TOKEN(HTYPE, _create)(struct net *net, struct ip_set *set,#ifdef IP_SET_HASH_WITH_MARKMASK h->markmask = markmask;#endif -get_random_bytes (&h->initval,sizeof (h->initval)); +if (tb[IPSET_ATTR_INITVAL ]) + h->initval =ntohl (nla_get_be32 (tb[IPSET_ATTR_INITVAL ])); +else +get_random_bytes (&h->initval,sizeof (h->initval)); h->bucketsize =AHASH_MAX_SIZE ;if (tb[IPSET_ATTR_BUCKETSIZE ]) { h->bucketsize =nla_get_u8 (tb[IPSET_ATTR_BUCKETSIZE ]);
net/netfilter/ipset/ip_set_hash_ip.c +2 -1
@@ -24,7 +24,7 @@/* 2 Comments support */ /* 3 Forceadd support */ /* 4 skbinfo support */ -#define IPSET_TYPE_REV_MAX 5/* bucketsize support */ +#define IPSET_TYPE_REV_MAX 5/* bucketsize, initval support */ MODULE_LICENSE ("GPL" );MODULE_AUTHOR ("Jozsef Kadlecsik <[email protected]>" );
@@ -283,6 +283,7 @@ static struct ip_set_type hash_ip_type __read_mostly = { .create_policy = { [IPSET_ATTR_HASHSIZE] = { .type = NLA_U32 }, [IPSET_ATTR_MAXELEM] = { .type = NLA_U32 }, + [IPSET_ATTR_INITVAL] = { .type = NLA_U32 }, [IPSET_ATTR_BUCKETSIZE] = { .type = NLA_U8 }, [IPSET_ATTR_RESIZE] = { .type = NLA_U8 }, [IPSET_ATTR_TIMEOUT] = { .type = NLA_U32 },
net/netfilter/ipset/ip_set_hash_ipmac.c +2 -1
@@ -23,7 +23,7 @@#include <linux/netfilter/ipset/ip_set_hash.h> #define IPSET_TYPE_REV_MIN 0 -#define IPSET_TYPE_REV_MAX 1/* bucketsize support */ +#define IPSET_TYPE_REV_MAX 1/* bucketsize, initval support */ MODULE_LICENSE ("GPL" );MODULE_AUTHOR ("Tomasz Chilinski <[email protected]>" );
@@ -273,6 +273,7 @@ static struct ip_set_type hash_ipmac_type __read_mostly = { .create_policy = { [IPSET_ATTR_HASHSIZE] = { .type = NLA_U32 }, [IPSET_ATTR_MAXELEM] = { .type = NLA_U32 }, + [IPSET_ATTR_INITVAL] = { .type = NLA_U32 }, [IPSET_ATTR_BUCKETSIZE] = { .type = NLA_U8 }, [IPSET_ATTR_RESIZE] = { .type = NLA_U8 }, [IPSET_ATTR_TIMEOUT] = { .type = NLA_U32 },
net/netfilter/ipset/ip_set_hash_ipmark.c +2 -1
@@ -22,7 +22,7 @@#define IPSET_TYPE_REV_MIN 0/* 1 Forceadd support */ /* 2 skbinfo support */ -#define IPSET_TYPE_REV_MAX 3/* bucketsize support */ +#define IPSET_TYPE_REV_MAX 3/* bucketsize, initval support */ MODULE_LICENSE ("GPL" );MODULE_AUTHOR ("Vytas Dauksa <[email protected]>" );
@@ -281,6 +281,7 @@ static struct ip_set_type hash_ipmark_type __read_mostly = { [IPSET_ATTR_MARKMASK] = { .type = NLA_U32 }, [IPSET_ATTR_HASHSIZE] = { .type = NLA_U32 }, [IPSET_ATTR_MAXELEM] = { .type = NLA_U32 }, + [IPSET_ATTR_INITVAL] = { .type = NLA_U32 }, [IPSET_ATTR_BUCKETSIZE] = { .type = NLA_U8 }, [IPSET_ATTR_RESIZE] = { .type = NLA_U8 }, [IPSET_ATTR_TIMEOUT] = { .type = NLA_U32 },
net/netfilter/ipset/ip_set_hash_ipport.c +2 -1
@@ -26,7 +26,7 @@/* 3 Comments support added */ /* 4 Forceadd support added */ /* 5 skbinfo support added */ -#define IPSET_TYPE_REV_MAX 6/* bucketsize support added */ +#define IPSET_TYPE_REV_MAX 6/* bucketsize, initval support added */ MODULE_LICENSE ("GPL" );MODULE_AUTHOR ("Jozsef Kadlecsik <[email protected]>" );
@@ -347,6 +347,7 @@ static struct ip_set_type hash_ipport_type __read_mostly = { .create_policy = { [IPSET_ATTR_HASHSIZE] = { .type = NLA_U32 }, [IPSET_ATTR_MAXELEM] = { .type = NLA_U32 }, + [IPSET_ATTR_INITVAL] = { .type = NLA_U32 }, [IPSET_ATTR_BUCKETSIZE] = { .type = NLA_U8 }, [IPSET_ATTR_RESIZE] = { .type = NLA_U8 }, [IPSET_ATTR_PROTO] = { .type = NLA_U8 },
net/netfilter/ipset/ip_set_hash_ipportip.c +2 -1
@@ -26,7 +26,7 @@/* 3 Comments support added */ /* 4 Forceadd support added */ /* 5 skbinfo support added */ -#define IPSET_TYPE_REV_MAX 6/* bucketsize support added */ +#define IPSET_TYPE_REV_MAX 6/* bucketsize, initval support added */ MODULE_LICENSE ("GPL" );MODULE_AUTHOR ("Jozsef Kadlecsik <[email protected]>" );
@@ -362,6 +362,7 @@ static struct ip_set_type hash_ipportip_type __read_mostly = { .create_policy = { [IPSET_ATTR_HASHSIZE] = { .type = NLA_U32 }, [IPSET_ATTR_MAXELEM] = { .type = NLA_U32 }, + [IPSET_ATTR_INITVAL] = { .type = NLA_U32 }, [IPSET_ATTR_BUCKETSIZE] = { .type = NLA_U8 }, [IPSET_ATTR_RESIZE] = { .type = NLA_U8 }, [IPSET_ATTR_TIMEOUT] = { .type = NLA_U32 },
net/netfilter/ipset/ip_set_hash_ipportnet.c +2 -1
@@ -28,7 +28,7 @@/* 5 Comments support added */ /* 6 Forceadd support added */ /* 7 skbinfo support added */ -#define IPSET_TYPE_REV_MAX 8/* bucketsize support added */ +#define IPSET_TYPE_REV_MAX 8/* bucketsize, initval support added */ MODULE_LICENSE ("GPL" );MODULE_AUTHOR ("Jozsef Kadlecsik <[email protected]>" );
@@ -519,6 +519,7 @@ static struct ip_set_type hash_ipportnet_type __read_mostly = { .create_policy = { [IPSET_ATTR_HASHSIZE] = { .type = NLA_U32 }, [IPSET_ATTR_MAXELEM] = { .type = NLA_U32 }, + [IPSET_ATTR_INITVAL] = { .type = NLA_U32 }, [IPSET_ATTR_BUCKETSIZE] = { .type = NLA_U8 }, [IPSET_ATTR_RESIZE] = { .type = NLA_U8 }, [IPSET_ATTR_TIMEOUT] = { .type = NLA_U32 },
net/netfilter/ipset/ip_set_hash_mac.c +2 -1
@@ -16,7 +16,7 @@#include <linux/netfilter/ipset/ip_set_hash.h> #define IPSET_TYPE_REV_MIN 0 -#define IPSET_TYPE_REV_MAX 1/* bucketsize support */ +#define IPSET_TYPE_REV_MAX 1/* bucketsize, initval support */ MODULE_LICENSE ("GPL" );MODULE_AUTHOR ("Jozsef Kadlecsik <[email protected]>" );
@@ -130,6 +130,7 @@ static struct ip_set_type hash_mac_type __read_mostly = { .create_policy = { [IPSET_ATTR_HASHSIZE] = { .type = NLA_U32 }, [IPSET_ATTR_MAXELEM] = { .type = NLA_U32 }, + [IPSET_ATTR_INITVAL] = { .type = NLA_U32 }, [IPSET_ATTR_BUCKETSIZE] = { .type = NLA_U8 }, [IPSET_ATTR_RESIZE] = { .type = NLA_U8 }, [IPSET_ATTR_TIMEOUT] = { .type = NLA_U32 },
net/netfilter/ipset/ip_set_hash_net.c +2 -1
@@ -25,7 +25,7 @@/* 4 Comments support added */ /* 5 Forceadd support added */ /* 6 skbinfo support added */ -#define IPSET_TYPE_REV_MAX 7/* bucketsize support added */ +#define IPSET_TYPE_REV_MAX 7/* bucketsize, initval support added */ MODULE_LICENSE ("GPL" );MODULE_AUTHOR ("Jozsef Kadlecsik <[email protected]>" );
@@ -360,6 +360,7 @@ static struct ip_set_type hash_net_type __read_mostly = { .create_policy = { [IPSET_ATTR_HASHSIZE] = { .type = NLA_U32 }, [IPSET_ATTR_MAXELEM] = { .type = NLA_U32 }, + [IPSET_ATTR_INITVAL] = { .type = NLA_U32 }, [IPSET_ATTR_BUCKETSIZE] = { .type = NLA_U8 }, [IPSET_ATTR_RESIZE] = { .type = NLA_U8 }, [IPSET_ATTR_TIMEOUT] = { .type = NLA_U32 },
net/netfilter/ipset/ip_set_hash_netiface.c +2 -1
@@ -27,7 +27,7 @@/* 5 Forceadd support added */ /* 6 skbinfo support added */ /* 7 interface wildcard support added */ -#define IPSET_TYPE_REV_MAX 8/* bucketsize support added */ +#define IPSET_TYPE_REV_MAX 8/* bucketsize, initval support added */ MODULE_LICENSE ("GPL" );MODULE_AUTHOR ("Jozsef Kadlecsik <[email protected]>" );
@@ -476,6 +476,7 @@ static struct ip_set_type hash_netiface_type __read_mostly = { .create_policy = { [IPSET_ATTR_HASHSIZE] = { .type = NLA_U32 }, [IPSET_ATTR_MAXELEM] = { .type = NLA_U32 }, + [IPSET_ATTR_INITVAL] = { .type = NLA_U32 }, [IPSET_ATTR_BUCKETSIZE] = { .type = NLA_U8 }, [IPSET_ATTR_RESIZE] = { .type = NLA_U8 }, [IPSET_ATTR_PROTO] = { .type = NLA_U8 },
net/netfilter/ipset/ip_set_hash_netnet.c +2 -1
@@ -23,7 +23,7 @@#define IPSET_TYPE_REV_MIN 0/* 1 Forceadd support added */ /* 2 skbinfo support added */ -#define IPSET_TYPE_REV_MAX 3/* bucketsize support added */ +#define IPSET_TYPE_REV_MAX 3/* bucketsize, initval support added */ MODULE_LICENSE ("GPL" );MODULE_AUTHOR ("Oliver Smith <[email protected]>" );
@@ -465,6 +465,7 @@ static struct ip_set_type hash_netnet_type __read_mostly = { .create_policy = { [IPSET_ATTR_HASHSIZE] = { .type = NLA_U32 }, [IPSET_ATTR_MAXELEM] = { .type = NLA_U32 }, + [IPSET_ATTR_INITVAL] = { .type = NLA_U32 }, [IPSET_ATTR_BUCKETSIZE] = { .type = NLA_U8 }, [IPSET_ATTR_RESIZE] = { .type = NLA_U8 }, [IPSET_ATTR_TIMEOUT] = { .type = NLA_U32 },
net/netfilter/ipset/ip_set_hash_netport.c +2 -1
@@ -27,7 +27,7 @@/* 5 Comments support added */ /* 6 Forceadd support added */ /* 7 skbinfo support added */ -#define IPSET_TYPE_REV_MAX 8/* bucketsize support added */ +#define IPSET_TYPE_REV_MAX 8/* bucketsize, initval support added */ MODULE_LICENSE ("GPL" );MODULE_AUTHOR ("Jozsef Kadlecsik <[email protected]>" );
@@ -466,6 +466,7 @@ static struct ip_set_type hash_netport_type __read_mostly = { .create_policy = { [IPSET_ATTR_HASHSIZE] = { .type = NLA_U32 }, [IPSET_ATTR_MAXELEM] = { .type = NLA_U32 }, + [IPSET_ATTR_INITVAL] = { .type = NLA_U32 }, [IPSET_ATTR_BUCKETSIZE] = { .type = NLA_U8 }, [IPSET_ATTR_RESIZE] = { .type = NLA_U8 }, [IPSET_ATTR_PROTO] = { .type = NLA_U8 },
net/netfilter/ipset/ip_set_hash_netportnet.c +2 -1
@@ -24,7 +24,7 @@/* 0 Comments support added */ /* 1 Forceadd support added */ /* 2 skbinfo support added */ -#define IPSET_TYPE_REV_MAX 3/* bucketsize support added */ +#define IPSET_TYPE_REV_MAX 3/* bucketsize, initval support added */ MODULE_LICENSE ("GPL" );MODULE_AUTHOR ("Oliver Smith <[email protected]>" );
@@ -564,6 +564,7 @@ static struct ip_set_type hash_netportnet_type __read_mostly = { .create_policy = { [IPSET_ATTR_HASHSIZE] = { .type = NLA_U32 }, [IPSET_ATTR_MAXELEM] = { .type = NLA_U32 }, + [IPSET_ATTR_INITVAL] = { .type = NLA_U32 }, [IPSET_ATTR_BUCKETSIZE] = { .type = NLA_U8 }, [IPSET_ATTR_RESIZE] = { .type = NLA_U8 }, [IPSET_ATTR_TIMEOUT] = { .type = NLA_U32 },
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerPATCH 7/8 netfilter: nftables: Add __printf() attribute
In reply to Pablo Neira AyusoFrom: Andrew Lunn <[email protected]>
nft_request_module calls vsnprintf() using parameters passed to it. Make the function with __printf() attribute so the compiler can check the format and arguments.
--- net/netfilter/nf_tables_api.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/netfilter/nf_tables_api.c +2 -1
@@ -581,7 +581,8 @@ struct nft_module_request { };#ifdef CONFIG_MODULES -static int nft_request_module (struct net *net,const char *fmt, ...) +static __printf(2, 3) int nft_request_module(struct net *net, const char *fmt, + ...) { char module_name[MODULE_NAME_LEN]; struct nft_module_request *req;
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerPATCH 8/8 netfilter: nft_reject_inet: allow to use reject from inet ingress
In reply to Pablo Neira AyusoEnhance validation to support for reject from inet ingress chains.
Note that, reject from inet ingress and netdev ingress differ.
Reject packets from inet ingress are sent through ip_local_out() since inet reject emulates the IP layer receive path. So the reject packet follows to classic IP output and postrouting paths.
The reject action from netdev ingress assumes the packet not yet entered the IP layer, so the reject packet is sent through dev_queue_xmit(). Therefore, reject packets from netdev ingress do not follow the classic IP output and postrouting paths.
--- net/ipv4/netfilter/nf_reject_ipv4.c | 6 ++++-- net/ipv6/netfilter/nf_reject_ipv6.c | 5 +++-- net/netfilter/nft_reject_inet.c | 14 +++++++++++++- 3 files changed, 20 insertions(+), 5 deletions(-)
net/ipv4/netfilter/nf_reject_ipv4.c +4 -2
@@ -246,7 +246,8 @@ void nf_send_reset(struct net *net, struct sk_buff *oldskb, int hook)if (!oth)return ; -if (hook ==NF_INET_PRE_ROUTING &&nf_reject_fill_skb_dst (oldskb)) +if ((hook ==NF_INET_PRE_ROUTING || hook ==NF_INET_INGRESS ) && +nf_reject_fill_skb_dst (oldskb) <0 )return ;if (skb_rtable (oldskb)->rt_flags & (RTCF_BROADCAST |RTCF_MULTICAST ))
@@ -315,7 +316,8 @@ void nf_send_unreach(struct sk_buff *skb_in, int code, int hook)if (iph->frag_off &htons (IP_OFFSET ))return ; -if (hook ==NF_INET_PRE_ROUTING &&nf_reject_fill_skb_dst (skb_in)) +if ((hook ==NF_INET_PRE_ROUTING || hook ==NF_INET_INGRESS ) && +nf_reject_fill_skb_dst (skb_in) <0 )return ;if (skb_csum_unnecessary (skb_in) || !nf_reject_verify_csum (proto)) {
net/ipv6/netfilter/nf_reject_ipv6.c +3 -2
@@ -304,7 +304,7 @@ void nf_send_reset6(struct net *net, struct sk_buff *oldskb, int hook) fl6.fl6_sport = otcph->dest; fl6.fl6_dport = otcph->source; -if (hook ==NF_INET_PRE_ROUTING ) { +if (hook ==NF_INET_PRE_ROUTING || hook ==NF_INET_INGRESS ) {nf_ip6_route (net, &dst,flowi6_to_flowi (&fl6), false);if (!dst)return ;
@@ -402,7 +402,8 @@ void nf_send_unreach6(struct net *net, struct sk_buff *skb_in,if (hooknum ==NF_INET_LOCAL_OUT && skb_in->dev ==NULL ) skb_in->dev = net->loopback_dev; -if (hooknum ==NF_INET_PRE_ROUTING &&nf_reject6_fill_skb_dst (skb_in)) +if ((hooknum ==NF_INET_PRE_ROUTING || hooknum ==NF_INET_INGRESS ) && +nf_reject6_fill_skb_dst (skb_in) <0 )return ;icmpv6_send (skb_in,ICMPV6_DEST_UNREACH , code,0 );
net/netfilter/nft_reject_inet.c +13 -1
@@ -58,6 +58,18 @@ static void nft_reject_inet_eval(const struct nft_expr *expr, regs->verdict.code =NF_DROP ; } +static int nft_reject_inet_validate (const struct nft_ctx *ctx, +const struct nft_expr *expr, +const struct nft_data **data) +{ +return nft_chain_validate_hooks (ctx->chain, + (1 <<NF_INET_LOCAL_IN ) | + (1 <<NF_INET_FORWARD ) | + (1 <<NF_INET_LOCAL_OUT ) | + (1 <<NF_INET_PRE_ROUTING ) | + (1 <<NF_INET_INGRESS )); +} +static struct nft_expr_type nft_reject_inet_type;static const struct nft_expr_ops nft_reject_inet_ops = { .type = &nft_reject_inet_type,
@@ -65,7 +77,7 @@ static const struct nft_expr_ops nft_reject_inet_ops = { .eval = nft_reject_inet_eval, .init = nft_reject_init, .dump = nft_reject_dump, - .validate = nft_reject_validate, + .validate = nft_reject_inet_validate, };static struct nft_expr_type nft_reject_inet_type__read_mostly = {
Signature · 1 line
2.20.1
Jakub Kicinski
maintainerQuoted 10 lines · On Wed, 4 Nov 2020 15:11:41 +0100 Pablo Neira Ayuso wrote:
1) Move existing bridge packet reject infra to nf_reject_{ipv4,ipv6}.c from Jose M. Guisado.
2) Consolidate
nft_reject_inetinitialization and dump, also from Jose.3) Add the netdev reject action, from Jose.
4) Allow to combine the exist flag and the destroy command in ipset, from Joszef Kadlecsik.
Quoted 7 lines
5) Expose bucket size parameter for hashtables, also from Jozsef.
6) Expose the init value for reproducible ipset listings, from Jozsef.
7) Use
__printfattribute innft_request_module, from Andrew Lunn.8) Allow to use reject from the inet ingress chain.
Pulled, thanks!