netfilter updates for 3.0.0-rc1
Subsystems (3)
[email protected]
maintainercover netfilter updates for 3.0.0-rc1
From: Pablo Neira Ayuso <[email protected]>
Hi David,
the following patches contain Netfilter updates for 3.0.0-rc1 The highlights are:
- ipset updates from Jozsef.
- one IPVS fix from Julian Anastasov.
- one enhancement for the SIP tracker to handle Cisco 7941/7945 IP phones
- deprecate /proc/net/nf_conntrack interface from Jan.
- one fix for nf_nat_csum mangling also from Julian.
- one fix for a refcount leak in the untracked conntrack by myself.
Please pull from:
git://1984.lsi.us.es/net-next-2.6 pablo/nf-next-2.6-updates
Thanks!
Dave Jones (1):
netfilter: use unsigned variables for packet lengths in ip[6]_queue.
Eric Dumazet (2):
netfilter: add more values to enum ip_conntrack_info
netfilter: nf_conntrack: remove one synchronize_net()
Jan Engelhardt (1):
netfilter: nf_conntrack: provide config option to disable ancient
procfs parts
Jesper Juhl (1):
ipvs: Avoid undefined order of evaluation in assignments to struct
nf_conn *
Jozsef Kadlecsik (11):
netfilter: ipset: Options and flags support added to the kernel API
netfilter: ipset: Support listing setnames and headers too
netfilter: ipset: Fix adding ranges to hash types
netfilter: ipset: Set type support with multiple revisions added
netfilter: ipset: Support range for IPv4 at adding/deleting elements
for hash:*net* types
netfilter: ipset: Take into account cidr value for the from address
when creating the set
netfilter: ipset: Add xt_action_param to the variant level kadt
functions
netfilter: ipset: Fix return code for destroy when sets are in use
netfilter: ipset: Use the stored first cidr value instead of '1'
netfilter: ipset: hash:net,iface type introduced
netfilter: ipset: Whitespace and coding fixes, detected by
checkpatch.pl
Julian Anastasov (2):
ipvs: restore support for iptables SNAT
netfilter: nf_nat: fix crash in nf_nat_csum
Kevin Cernekee (1):
netfilter: nf_conntrack_sip: Handle Cisco 7941/7945 IP phones
Pablo Neira Ayuso (1):
netfilter: nf_conntrack: fix ct refcount leak in l4proto->error()
include/linux/netfilter/ipset/ip_set.h | 47 ++- include/linux/netfilter/ipset/ip_set_ahash.h | 33 +- include/linux/netfilter/ipset/ip_set_hash.h | 4 + include/linux/netfilter/ipset/ip_set_timeout.h | 3 + include/linux/netfilter/ipset/pfxlen.h | 11 +- include/linux/netfilter/nf_conntrack_common.h | 3 + include/linux/netfilter/nf_conntrack_sip.h | 3 + include/linux/netfilter/xt_set.h | 15 +- net/ipv4/netfilter/Kconfig | 2 +- net/ipv4/netfilter/ip_queue.c | 3 +- net/ipv4/netfilter/ipt_CLUSTERIP.c | 6 +- net/ipv4/netfilter/ipt_MASQUERADE.c | 2 +- net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c | 3 +- net/ipv4/netfilter/nf_conntrack_proto_icmp.c | 2 +- net/ipv4/netfilter/nf_nat_core.c | 2 +- net/ipv4/netfilter/nf_nat_helper.c | 2 +- net/ipv4/netfilter/nf_nat_rule.c | 2 +- net/ipv4/netfilter/nf_nat_sip.c | 26 +- net/ipv4/netfilter/nf_nat_standalone.c | 4 +- net/ipv6/netfilter/ip6_queue.c | 3 +- net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c | 2 +- net/ipv6/netfilter/nf_conntrack_proto_icmpv6.c | 2 +- net/netfilter/Kconfig | 10 + net/netfilter/ipset/Kconfig | 10 + net/netfilter/ipset/Makefile | 1 + net/netfilter/ipset/ip_set_bitmap_ip.c | 17 +- net/netfilter/ipset/ip_set_bitmap_ipmac.c | 19 +- net/netfilter/ipset/ip_set_bitmap_port.c | 13 +- net/netfilter/ipset/ip_set_core.c | 165 +++--- net/netfilter/ipset/ip_set_hash_ip.c | 37 +- net/netfilter/ipset/ip_set_hash_ipport.c | 55 ++- net/netfilter/ipset/ip_set_hash_ipportip.c | 59 ++- net/netfilter/ipset/ip_set_hash_ipportnet.c | 135 +++-- net/netfilter/ipset/ip_set_hash_net.c | 88 +++- net/netfilter/ipset/ip_set_hash_netiface.c | 762 ++++++++++++++++++++++++ net/netfilter/ipset/ip_set_hash_netport.c | 113 +++- net/netfilter/ipset/ip_set_list_set.c | 14 +- net/netfilter/ipset/pfxlen.c | 23 +- net/netfilter/ipvs/ip_vs_core.c | 16 +- net/netfilter/ipvs/ip_vs_nfct.c | 2 +- net/netfilter/ipvs/ip_vs_xmit.c | 8 +- net/netfilter/nf_conntrack_core.c | 7 +- net/netfilter/nf_conntrack_expect.c | 12 +- net/netfilter/nf_conntrack_ftp.c | 2 +- net/netfilter/nf_conntrack_h323_main.c | 10 +- net/netfilter/nf_conntrack_irc.c | 3 +- net/netfilter/nf_conntrack_pptp.c | 3 +- net/netfilter/nf_conntrack_sane.c | 2 +- net/netfilter/nf_conntrack_sip.c | 19 +- net/netfilter/nf_conntrack_standalone.c | 4 +- net/netfilter/xt_set.c | 152 ++++-- net/netfilter/xt_socket.c | 4 +- 52 files changed, 1581 insertions(+), 364 deletions(-) create mode 100644 net/netfilter/ipset/ip_set_hash_netiface.c
Signature · 1 line
1.7.2.5
[email protected]
maintainerPATCH 1/20 netfilter: ipset: Options and flags support added to the kernel API
From: Jozsef Kadlecsik <[email protected]>
The support makes possible to specify the timeout value for the SET target and a flag to reset the timeout for already existing entries.
--- include/linux/netfilter/ipset/ip_set.h | 18 ++- include/linux/netfilter/ipset/ip_set_ahash.h | 2 +- include/linux/netfilter/ipset/ip_set_timeout.h | 3 + include/linux/netfilter/xt_set.h | 15 ++- net/netfilter/ipset/ip_set_bitmap_ip.c | 6 +- net/netfilter/ipset/ip_set_bitmap_ipmac.c | 8 +- net/netfilter/ipset/ip_set_bitmap_port.c | 7 +- net/netfilter/ipset/ip_set_core.c | 26 ++-- net/netfilter/ipset/ip_set_hash_ip.c | 12 +- net/netfilter/ipset/ip_set_hash_ipport.c | 16 ++-- net/netfilter/ipset/ip_set_hash_ipportip.c | 20 ++-- net/netfilter/ipset/ip_set_hash_ipportnet.c | 20 ++-- net/netfilter/ipset/ip_set_hash_net.c | 12 +- net/netfilter/ipset/ip_set_hash_netport.c | 16 ++-- net/netfilter/ipset/ip_set_list_set.c | 8 +- net/netfilter/xt_set.c | 151 ++++++++++++++++-------- 16 files changed, 206 insertions(+), 134 deletions(-)
include/linux/netfilter/ipset/ip_set.h +14 -4
@@ -217,6 +217,15 @@ struct ip_set;typedef int (*ipset_adtfn )(struct ip_set *set,void *value,u32 timeout,u32 flags); +/* Kernel API function options */ +struct ip_set_adt_opt { +u8 family;/* Actual protocol family */ +u8 dim;/* Dimension of match/target */ +u8 flags;/* Direction and negation flags */ +u32 cmdflags;/* Command-like flags */ +u32 timeout;/* Timeout value */ +}; +/* Set type, variant-specific part */ struct ip_set_type_variant {/* Kernelspace: test/add/del entries
@@ -224,7 +233,7 @@ struct ip_set_type_variant {* zero for no match/success to add/delete * positive for matching element */ int (*kadt)(struct ip_set *set,const struct sk_buff * skb, -enum ipset_adt adt,u8 pf,u8 dim,u8 flags); +enum ipset_adt adt,const struct ip_set_adt_opt *opt);/* Userspace: test/add/del entries * returns negative error code,
@@ -314,12 +323,13 @@ extern ip_set_id_t ip_set_nfnl_get_byindex(ip_set_id_t index);extern void ip_set_nfnl_put (ip_set_id_t index);/* API for iptables set match, and SET target */ +extern int ip_set_add (ip_set_id_t id,const struct sk_buff *skb, -u8 family,u8 dim,u8 flags); +const struct ip_set_adt_opt *opt);extern int ip_set_del (ip_set_id_t id,const struct sk_buff *skb, -u8 family,u8 dim,u8 flags); +const struct ip_set_adt_opt *opt);extern int ip_set_test (ip_set_id_t id,const struct sk_buff *skb, -u8 family,u8 dim,u8 flags); +const struct ip_set_adt_opt *opt);/* Utility functions */ extern void *ip_set_alloc (size_t size);
include/linux/netfilter/ipset/ip_set_ahash.h +1 -1
@@ -586,7 +586,7 @@ nla_put_failure:static int type_pf_kadt (struct ip_set *set,const struct sk_buff * skb, -enum ipset_adt adt,u8 pf,u8 dim,u8 flags); +enum ipset_adt adt,const struct ip_set_adt_opt *opt);static int type_pf_uadt (struct ip_set *set,struct nlattr *tb[],enum ipset_adt adt,u32 *lineno,u32 flags);
include/linux/netfilter/ipset/ip_set_timeout.h +3 -0
@@ -22,6 +22,9 @@#define with_timeout (timeout) ((timeout) != IPSET_NO_TIMEOUT) +#define opt_timeout (opt, map) \ + (with_timeout((opt)->timeout) ? (opt)->timeout : (map)->timeout) +static inline unsigned int ip_set_timeout_uget (struct nlattr *tb) {
include/linux/netfilter/xt_set.h +12 -3
@@ -35,7 +35,7 @@ struct xt_set_info_target_v0 {struct xt_set_info_v0 del_set; }; -/* Revision 1: current interface to netfilter/iptables */ +/* Revision 1 match and target */ struct xt_set_info {ip_set_id_t index;
@@ -44,13 +44,22 @@ struct xt_set_info { };/* match and target infos */ -struct xt_set_info_match { +struct xt_set_info_match_v1 {struct xt_set_info match_set; }; -struct xt_set_info_target { +struct xt_set_info_target_v1 {struct xt_set_info add_set;struct xt_set_info del_set; }; +/* Revision 2 target */ + +struct xt_set_info_target_v2 { +struct xt_set_info add_set; +struct xt_set_info del_set; +u32 flags; +u32 timeout; +}; +#endif /*_XT_SET_H*/
net/netfilter/ipset/ip_set_bitmap_ip.c +3 -3
@@ -219,19 +219,19 @@ nla_put_failure:static int bitmap_ip_kadt (struct ip_set *set,const struct sk_buff *skb, -enum ipset_adt adt,u8 pf,u8 dim,u8 flags) +enum ipset_adt adt,const struct ip_set_adt_opt *opt) {struct bitmap_ip *map = set->data;ipset_adtfn adtfn = set->variant->adt[adt];u32 ip; - ip =ntohl (ip4addr (skb, flags &IPSET_DIM_ONE_SRC )); + ip =ntohl (ip4addr (skb, opt->flags &IPSET_DIM_ONE_SRC ));if (ip < map->first_ip || ip > map->last_ip)return -IPSET_ERR_BITMAP_RANGE ; ip =ip_to_id (map, ip); -return adtfn (set, &ip, map->timeout, flags); +return adtfn (set, &ip,opt_timeout (opt, map), opt->cmdflags); } static int
net/netfilter/ipset/ip_set_bitmap_ipmac.c +4 -4
@@ -338,17 +338,17 @@ nla_put_failure:static int bitmap_ipmac_kadt (struct ip_set *set,const struct sk_buff *skb, -enum ipset_adt adt,u8 pf,u8 dim,u8 flags) +enum ipset_adt adt,const struct ip_set_adt_opt *opt) {struct bitmap_ipmac *map = set->data;ipset_adtfn adtfn = set->variant->adt[adt];struct ipmac data;/* MAC can be src only */ -if (!(flags &IPSET_DIM_TWO_SRC )) +if (!(opt->flags &IPSET_DIM_TWO_SRC ))return 0 ; - data.id =ntohl (ip4addr (skb, flags &IPSET_DIM_ONE_SRC )); + data.id =ntohl (ip4addr (skb, opt->flags &IPSET_DIM_ONE_SRC ));if (data.id < map->first_ip || data.id > map->last_ip)return -IPSET_ERR_BITMAP_RANGE ;
@@ -360,7 +360,7 @@ bitmap_ipmac_kadt(struct ip_set *set, const struct sk_buff *skb, data.id -= map->first_ip; data.ether =eth_hdr (skb)->h_source; -return adtfn (set, &data, map->timeout, flags); +return adtfn (set, &data,opt_timeout (opt, map), opt->cmdflags); } static int
net/netfilter/ipset/ip_set_bitmap_port.c +4 -3
@@ -208,14 +208,15 @@ nla_put_failure:static int bitmap_port_kadt (struct ip_set *set,const struct sk_buff *skb, -enum ipset_adt adt,u8 pf,u8 dim,u8 flags) +enum ipset_adt adt,const struct ip_set_adt_opt *opt) {struct bitmap_port *map = set->data;ipset_adtfn adtfn = set->variant->adt[adt];__be16 __port;u16 port =0 ; -if (!ip_set_get_ip_port (skb, pf, flags &IPSET_DIM_ONE_SRC , &__port)) +if (!ip_set_get_ip_port (skb, opt->family, + opt->flags &IPSET_DIM_ONE_SRC , &__port))return -EINVAL ; port =ntohs (__port);
@@ -225,7 +226,7 @@ bitmap_port_kadt(struct ip_set *set, const struct sk_buff *skb, port -= map->first_port; -return adtfn (set, &port, map->timeout, flags); +return adtfn (set, &port,opt_timeout (opt, map), opt->cmdflags); } static int
net/netfilter/ipset/ip_set_core.c +13 -13
@@ -325,7 +325,7 @@ __ip_set_put(ip_set_id_t index)int ip_set_test (ip_set_id_t index,const struct sk_buff *skb, -u8 family,u8 dim,u8 flags) +const struct ip_set_adt_opt *opt) {struct ip_set *set = ip_set_list[index];int ret =0 ;
@@ -333,19 +333,19 @@ ip_set_test(ip_set_id_t index, const struct sk_buff *skb,BUG_ON (set ==NULL );pr_debug ("set %s, index %u\n" , set->name, index); -if (dim < set->type->dimension || - !(family == set->family || set->family ==AF_UNSPEC )) +if (opt->dim < set->type->dimension || + !(opt->family == set->family || set->family ==AF_UNSPEC ))return 0 ;read_lock_bh (&set->lock); - ret = set->variant->kadt (set, skb,IPSET_TEST , family, dim, flags); + ret = set->variant->kadt (set, skb,IPSET_TEST , opt);read_unlock_bh (&set->lock);if (ret == -EAGAIN ) {/* Type requests element to be completed */ pr_debug ("element must be competed, ADD is triggered\n" );write_lock_bh (&set->lock); - set->variant->kadt (set, skb,IPSET_ADD , family, dim, flags); + set->variant->kadt (set, skb,IPSET_ADD , opt);write_unlock_bh (&set->lock); ret =1 ; }
@@ -357,7 +357,7 @@ EXPORT_SYMBOL_GPL(ip_set_test);int ip_set_add (ip_set_id_t index,const struct sk_buff *skb, -u8 family,u8 dim,u8 flags) +const struct ip_set_adt_opt *opt) {struct ip_set *set = ip_set_list[index];int ret;
@@ -365,12 +365,12 @@ ip_set_add(ip_set_id_t index, const struct sk_buff *skb,BUG_ON (set ==NULL );pr_debug ("set %s, index %u\n" , set->name, index); -if (dim < set->type->dimension || - !(family == set->family || set->family ==AF_UNSPEC )) +if (opt->dim < set->type->dimension || + !(opt->family == set->family || set->family ==AF_UNSPEC ))return 0 ;write_lock_bh (&set->lock); - ret = set->variant->kadt (set, skb,IPSET_ADD , family, dim, flags); + ret = set->variant->kadt (set, skb,IPSET_ADD , opt);write_unlock_bh (&set->lock);return ret;
@@ -379,7 +379,7 @@ EXPORT_SYMBOL_GPL(ip_set_add);int ip_set_del (ip_set_id_t index,const struct sk_buff *skb, -u8 family,u8 dim,u8 flags) +const struct ip_set_adt_opt *opt) {struct ip_set *set = ip_set_list[index];int ret =0 ;
@@ -387,12 +387,12 @@ ip_set_del(ip_set_id_t index, const struct sk_buff *skb,BUG_ON (set ==NULL );pr_debug ("set %s, index %u\n" , set->name, index); -if (dim < set->type->dimension || - !(family == set->family || set->family ==AF_UNSPEC )) +if (opt->dim < set->type->dimension || + !(opt->family == set->family || set->family ==AF_UNSPEC ))return 0 ;write_lock_bh (&set->lock); - ret = set->variant->kadt (set, skb,IPSET_DEL , family, dim, flags); + ret = set->variant->kadt (set, skb,IPSET_DEL , opt);write_unlock_bh (&set->lock);return ret;
net/netfilter/ipset/ip_set_hash_ip.c +6 -6
@@ -110,18 +110,18 @@ nla_put_failure:static int hash_ip4_kadt (struct ip_set *set,const struct sk_buff *skb, -enum ipset_adt adt,u8 pf,u8 dim,u8 flags) +enum ipset_adt adt,const struct ip_set_adt_opt *opt) {const struct ip_set_hash *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt];__be32 ip; -ip4addrptr (skb, flags &IPSET_DIM_ONE_SRC , &ip); +ip4addrptr (skb, opt->flags &IPSET_DIM_ONE_SRC , &ip); ip &=ip_set_netmask (h->netmask);if (ip ==0 )return -EINVAL ; -return adtfn (set, &ip, h->timeout, flags); +return adtfn (set, &ip,opt_timeout (opt, h), opt->cmdflags); } static int
@@ -283,18 +283,18 @@ nla_put_failure:static int hash_ip6_kadt (struct ip_set *set,const struct sk_buff *skb, -enum ipset_adt adt,u8 pf,u8 dim,u8 flags) +enum ipset_adt adt,const struct ip_set_adt_opt *opt) {const struct ip_set_hash *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt];union nf_inet_addr ip; -ip6addrptr (skb, flags &IPSET_DIM_ONE_SRC , &ip.in6); +ip6addrptr (skb, opt->flags &IPSET_DIM_ONE_SRC , &ip.in6);ip6_netmask (&ip, h->netmask);if (ipv6_addr_any (&ip.in6))return -EINVAL ; -return adtfn (set, &ip, h->timeout, flags); +return adtfn (set, &ip,opt_timeout (opt, h), opt->cmdflags); }static const struct nla_policy hash_ip6_adt_policy[IPSET_ATTR_ADT_MAX +1 ] = {
net/netfilter/ipset/ip_set_hash_ipport.c +8 -8
@@ -126,19 +126,19 @@ nla_put_failure:static int hash_ipport4_kadt (struct ip_set *set,const struct sk_buff *skb, -enum ipset_adt adt,u8 pf,u8 dim,u8 flags) +enum ipset_adt adt,const struct ip_set_adt_opt *opt) {const struct ip_set_hash *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt];struct hash_ipport4_elem data = { }; -if (!ip_set_get_ip4_port (skb, flags &IPSET_DIM_TWO_SRC , +if (!ip_set_get_ip4_port (skb, opt->flags &IPSET_DIM_TWO_SRC , &data.port, &data.proto))return -EINVAL ; -ip4addrptr (skb, flags &IPSET_DIM_ONE_SRC , &data.ip); +ip4addrptr (skb, opt->flags &IPSET_DIM_ONE_SRC , &data.ip); -return adtfn (set, &data, h->timeout, flags); +return adtfn (set, &data,opt_timeout (opt, h), opt->cmdflags); } static int
@@ -330,19 +330,19 @@ nla_put_failure:static int hash_ipport6_kadt (struct ip_set *set,const struct sk_buff *skb, -enum ipset_adt adt,u8 pf,u8 dim,u8 flags) +enum ipset_adt adt,const struct ip_set_adt_opt *opt) {const struct ip_set_hash *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt];struct hash_ipport6_elem data = { }; -if (!ip_set_get_ip6_port (skb, flags &IPSET_DIM_TWO_SRC , +if (!ip_set_get_ip6_port (skb, opt->flags &IPSET_DIM_TWO_SRC , &data.port, &data.proto))return -EINVAL ; -ip6addrptr (skb, flags &IPSET_DIM_ONE_SRC , &data.ip.in6); +ip6addrptr (skb, opt->flags &IPSET_DIM_ONE_SRC , &data.ip.in6); -return adtfn (set, &data, h->timeout, flags); +return adtfn (set, &data,opt_timeout (opt, h), opt->cmdflags); } static int
net/netfilter/ipset/ip_set_hash_ipportip.c +10 -10
@@ -129,20 +129,20 @@ nla_put_failure:static int hash_ipportip4_kadt (struct ip_set *set,const struct sk_buff *skb, -enum ipset_adt adt,u8 pf,u8 dim,u8 flags) +enum ipset_adt adt,const struct ip_set_adt_opt *opt) {const struct ip_set_hash *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt];struct hash_ipportip4_elem data = { }; -if (!ip_set_get_ip4_port (skb, flags &IPSET_DIM_TWO_SRC , +if (!ip_set_get_ip4_port (skb, opt->flags &IPSET_DIM_TWO_SRC , &data.port, &data.proto))return -EINVAL ; -ip4addrptr (skb, flags &IPSET_DIM_ONE_SRC , &data.ip); -ip4addrptr (skb, flags &IPSET_DIM_THREE_SRC , &data.ip2); +ip4addrptr (skb, opt->flags &IPSET_DIM_ONE_SRC , &data.ip); +ip4addrptr (skb, opt->flags &IPSET_DIM_THREE_SRC , &data.ip2); -return adtfn (set, &data, h->timeout, flags); +return adtfn (set, &data,opt_timeout (opt, h), opt->cmdflags); } static int
@@ -343,20 +343,20 @@ nla_put_failure:static int hash_ipportip6_kadt (struct ip_set *set,const struct sk_buff *skb, -enum ipset_adt adt,u8 pf,u8 dim,u8 flags) +enum ipset_adt adt,const struct ip_set_adt_opt *opt) {const struct ip_set_hash *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt];struct hash_ipportip6_elem data = { }; -if (!ip_set_get_ip6_port (skb, flags &IPSET_DIM_TWO_SRC , +if (!ip_set_get_ip6_port (skb, opt->flags &IPSET_DIM_TWO_SRC , &data.port, &data.proto))return -EINVAL ; -ip6addrptr (skb, flags &IPSET_DIM_ONE_SRC , &data.ip.in6); -ip6addrptr (skb, flags &IPSET_DIM_THREE_SRC , &data.ip2.in6); +ip6addrptr (skb, opt->flags &IPSET_DIM_ONE_SRC , &data.ip.in6); +ip6addrptr (skb, opt->flags &IPSET_DIM_THREE_SRC , &data.ip2.in6); -return adtfn (set, &data, h->timeout, flags); +return adtfn (set, &data,opt_timeout (opt, h), opt->cmdflags); } static int
net/netfilter/ipset/ip_set_hash_ipportnet.c +10 -10
@@ -142,7 +142,7 @@ nla_put_failure:static int hash_ipportnet4_kadt (struct ip_set *set,const struct sk_buff *skb, -enum ipset_adt adt,u8 pf,u8 dim,u8 flags) +enum ipset_adt adt,const struct ip_set_adt_opt *opt) {const struct ip_set_hash *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt];
@@ -154,15 +154,15 @@ hash_ipportnet4_kadt(struct ip_set *set, const struct sk_buff *skb,if (adt ==IPSET_TEST ) data.cidr =HOST_MASK ; -if (!ip_set_get_ip4_port (skb, flags &IPSET_DIM_TWO_SRC , +if (!ip_set_get_ip4_port (skb, opt->flags &IPSET_DIM_TWO_SRC , &data.port, &data.proto))return -EINVAL ; -ip4addrptr (skb, flags &IPSET_DIM_ONE_SRC , &data.ip); -ip4addrptr (skb, flags &IPSET_DIM_THREE_SRC , &data.ip2); +ip4addrptr (skb, opt->flags &IPSET_DIM_ONE_SRC , &data.ip); +ip4addrptr (skb, opt->flags &IPSET_DIM_THREE_SRC , &data.ip2); data.ip2 &=ip_set_netmask (data.cidr); -return adtfn (set, &data, h->timeout, flags); +return adtfn (set, &data,opt_timeout (opt, h), opt->cmdflags); } static int
@@ -390,7 +390,7 @@ nla_put_failure:static int hash_ipportnet6_kadt (struct ip_set *set,const struct sk_buff *skb, -enum ipset_adt adt,u8 pf,u8 dim,u8 flags) +enum ipset_adt adt,const struct ip_set_adt_opt *opt) {const struct ip_set_hash *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt];
@@ -402,15 +402,15 @@ hash_ipportnet6_kadt(struct ip_set *set, const struct sk_buff *skb,if (adt ==IPSET_TEST ) data.cidr =HOST_MASK ; -if (!ip_set_get_ip6_port (skb, flags &IPSET_DIM_TWO_SRC , +if (!ip_set_get_ip6_port (skb, opt->flags &IPSET_DIM_TWO_SRC , &data.port, &data.proto))return -EINVAL ; -ip6addrptr (skb, flags &IPSET_DIM_ONE_SRC , &data.ip.in6); -ip6addrptr (skb, flags &IPSET_DIM_THREE_SRC , &data.ip2.in6); +ip6addrptr (skb, opt->flags &IPSET_DIM_ONE_SRC , &data.ip.in6); +ip6addrptr (skb, opt->flags &IPSET_DIM_THREE_SRC , &data.ip2.in6);ip6_netmask (&data.ip2, data.cidr); -return adtfn (set, &data, h->timeout, flags); +return adtfn (set, &data,opt_timeout (opt, h), opt->cmdflags); } static int
net/netfilter/ipset/ip_set_hash_net.c +6 -6
@@ -127,7 +127,7 @@ nla_put_failure:static int hash_net4_kadt (struct ip_set *set,const struct sk_buff *skb, -enum ipset_adt adt,u8 pf,u8 dim,u8 flags) +enum ipset_adt adt,const struct ip_set_adt_opt *opt) {const struct ip_set_hash *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt];
@@ -138,10 +138,10 @@ hash_net4_kadt(struct ip_set *set, const struct sk_buff *skb,if (adt ==IPSET_TEST ) data.cidr =HOST_MASK ; -ip4addrptr (skb, flags &IPSET_DIM_ONE_SRC , &data.ip); +ip4addrptr (skb, opt->flags &IPSET_DIM_ONE_SRC , &data.ip); data.ip &=ip_set_netmask (data.cidr); -return adtfn (set, &data, h->timeout, flags); +return adtfn (set, &data,opt_timeout (opt, h), opt->cmdflags); } static int
@@ -292,7 +292,7 @@ nla_put_failure:static int hash_net6_kadt (struct ip_set *set,const struct sk_buff *skb, -enum ipset_adt adt,u8 pf,u8 dim,u8 flags) +enum ipset_adt adt,const struct ip_set_adt_opt *opt) {const struct ip_set_hash *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt];
@@ -303,10 +303,10 @@ hash_net6_kadt(struct ip_set *set, const struct sk_buff *skb,if (adt ==IPSET_TEST ) data.cidr =HOST_MASK ; -ip6addrptr (skb, flags &IPSET_DIM_ONE_SRC , &data.ip.in6); +ip6addrptr (skb, opt->flags &IPSET_DIM_ONE_SRC , &data.ip.in6);ip6_netmask (&data.ip, data.cidr); -return adtfn (set, &data, h->timeout, flags); +return adtfn (set, &data,opt_timeout (opt, h), opt->cmdflags); } static int
net/netfilter/ipset/ip_set_hash_netport.c +8 -8
@@ -139,7 +139,7 @@ nla_put_failure:static int hash_netport4_kadt (struct ip_set *set,const struct sk_buff *skb, -enum ipset_adt adt,u8 pf,u8 dim,u8 flags) +enum ipset_adt adt,const struct ip_set_adt_opt *opt) {const struct ip_set_hash *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt];
@@ -151,14 +151,14 @@ hash_netport4_kadt(struct ip_set *set, const struct sk_buff *skb,if (adt ==IPSET_TEST ) data.cidr =HOST_MASK ; -if (!ip_set_get_ip4_port (skb, flags &IPSET_DIM_TWO_SRC , +if (!ip_set_get_ip4_port (skb, opt->flags &IPSET_DIM_TWO_SRC , &data.port, &data.proto))return -EINVAL ; -ip4addrptr (skb, flags &IPSET_DIM_ONE_SRC , &data.ip); +ip4addrptr (skb, opt->flags &IPSET_DIM_ONE_SRC , &data.ip); data.ip &=ip_set_netmask (data.cidr); -return adtfn (set, &data, h->timeout, flags); +return adtfn (set, &data,opt_timeout (opt, h), opt->cmdflags); } static int
@@ -352,7 +352,7 @@ nla_put_failure:static int hash_netport6_kadt (struct ip_set *set,const struct sk_buff *skb, -enum ipset_adt adt,u8 pf,u8 dim,u8 flags) +enum ipset_adt adt,const struct ip_set_adt_opt *opt) {const struct ip_set_hash *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt];
@@ -364,14 +364,14 @@ hash_netport6_kadt(struct ip_set *set, const struct sk_buff *skb,if (adt ==IPSET_TEST ) data.cidr =HOST_MASK ; -if (!ip_set_get_ip6_port (skb, flags &IPSET_DIM_TWO_SRC , +if (!ip_set_get_ip6_port (skb, opt->flags &IPSET_DIM_TWO_SRC , &data.port, &data.proto))return -EINVAL ; -ip6addrptr (skb, flags &IPSET_DIM_ONE_SRC , &data.ip.in6); +ip6addrptr (skb, opt->flags &IPSET_DIM_ONE_SRC , &data.ip.in6);ip6_netmask (&data.ip, data.cidr); -return adtfn (set, &data, h->timeout, flags); +return adtfn (set, &data,opt_timeout (opt, h), opt->cmdflags); } static int
net/netfilter/ipset/ip_set_list_set.c +4 -4
@@ -72,7 +72,7 @@ list_set_expired(const struct list_set *map, u32 id)static int list_set_kadt (struct ip_set *set,const struct sk_buff *skb, -enum ipset_adt adt,u8 pf,u8 dim,u8 flags) +enum ipset_adt adt,const struct ip_set_adt_opt *opt) {struct list_set *map = set->data;struct set_elem *elem;
@@ -87,17 +87,17 @@ list_set_kadt(struct ip_set *set, const struct sk_buff *skb,continue ;switch (adt) {case IPSET_TEST : - ret =ip_set_test (elem->id, skb, pf, dim, flags); + ret =ip_set_test (elem->id, skb, opt);if (ret >0 )return ret;break ;case IPSET_ADD : - ret =ip_set_add (elem->id, skb, pf, dim, flags); + ret =ip_set_add (elem->id, skb, opt);if (ret ==0 )return ret;break ;case IPSET_DEL : - ret =ip_set_del (elem->id, skb, pf, dim, flags); + ret =ip_set_del (elem->id, skb, opt);if (ret ==0 )return ret;break ;
net/netfilter/xt_set.c +100 -51
252 lines not on this page · raw message
Signature · 1 line
1.7.2.5
[email protected]
maintainerPATCH 2/20 netfilter: ipset: Support listing setnames and headers too
In reply to [email protected]From: Jozsef Kadlecsik <[email protected]>
Current listing makes possible to list sets with full content only. The patch adds support partial listings, i.e. listing just the existing setnames or listing set headers, without set members.
--- include/linux/netfilter/ipset/ip_set.h | 4 ++ net/netfilter/ipset/ip_set_core.c | 73 ++++++++++++++++++++------------ 2 files changed, 50 insertions(+), 27 deletions(-)
include/linux/netfilter/ipset/ip_set.h +4 -0
@@ -142,6 +142,10 @@ enum ipset_errno {enum ipset_cmd_flags {IPSET_FLAG_BIT_EXIST =0 ,IPSET_FLAG_EXIST = (1 <<IPSET_FLAG_BIT_EXIST ), +IPSET_FLAG_BIT_LIST_SETNAME =1 , +IPSET_FLAG_LIST_SETNAME = (1 <<IPSET_FLAG_BIT_LIST_SETNAME ), +IPSET_FLAG_BIT_LIST_HEADER =2 , +IPSET_FLAG_LIST_HEADER = (1 <<IPSET_FLAG_BIT_LIST_HEADER ), };/* Flags at CADT attribute level */
net/netfilter/ipset/ip_set_core.c +46 -27
146 lines not on this page · raw message
Signature · 1 line
1.7.2.5
[email protected]
maintainerPATCH 3/20 netfilter: ipset: Fix adding ranges to hash types
In reply to [email protected]From: Jozsef Kadlecsik <[email protected]>
When ranges are added to hash types, the elements may trigger the rehashing of the set. However, the last successfully added element was not kept track so the adding started again with the first element after the rehashing.
--- include/linux/netfilter/ipset/ip_set.h | 2 +- include/linux/netfilter/ipset/ip_set_ahash.h | 22 ++++++++++++++++-- net/netfilter/ipset/ip_set_bitmap_ip.c | 2 +- net/netfilter/ipset/ip_set_bitmap_ipmac.c | 2 +- net/netfilter/ipset/ip_set_bitmap_port.c | 2 +- net/netfilter/ipset/ip_set_core.c | 11 +++++---- net/netfilter/ipset/ip_set_hash_ip.c | 17 ++++++++++++- net/netfilter/ipset/ip_set_hash_ipport.c | 31 +++++++++++++++++++++---- net/netfilter/ipset/ip_set_hash_ipportip.c | 31 +++++++++++++++++++++---- net/netfilter/ipset/ip_set_hash_ipportnet.c | 31 +++++++++++++++++++++---- net/netfilter/ipset/ip_set_hash_net.c | 16 +++++++++++- net/netfilter/ipset/ip_set_hash_netport.c | 22 ++++++++++++++++- net/netfilter/ipset/ip_set_list_set.c | 2 +- 13 files changed, 157 insertions(+), 34 deletions(-)
include/linux/netfilter/ipset/ip_set.h +1 -1
@@ -244,7 +244,7 @@ struct ip_set_type_variant {* zero for no match/success to add/delete * positive for matching element */ int (*uadt)(struct ip_set *set,struct nlattr *tb[], -enum ipset_adt adt,u32 *lineno,u32 flags); +enum ipset_adt adt,u32 *lineno,u32 flags,bool retried);/* Low level add/del/test functions */ ipset_adtfn adt[IPSET_ADT_MAX ];
include/linux/netfilter/ipset/ip_set_ahash.h +19 -3
@@ -5,6 +5,11 @@#include <linux/jhash.h> #include <linux/netfilter/ipset/ip_set_timeout.h> +#define CONCAT (a, b, c) a##b##c +#define TOKEN (a, b, c) CONCAT(a, b, c) + +#define type_pf_next TOKEN(TYPE, PF, _elem) +/* Hashing which uses arrays to resolve clashing. The hash table is resized * (doubled) when searching becomes too long. * Internally jhash is used with the assumption that the size of the
@@ -54,6 +59,7 @@ struct ip_set_hash {u32 initval;/* random jhash init value */ u32 timeout;/* timeout value, if enabled */ struct timer_list gc;/* garbage collection when timeout enabled */ +struct type_pf_next next;/* temporary storage for uadd */ #ifdef IP_SET_HASH_WITH_NETMASK u8 netmask;/* netmask value for subnets to store */ #endif
@@ -217,6 +223,7 @@ ip_set_hash_destroy(struct ip_set *set)#define type_pf_data_netmask TOKEN(TYPE, PF, _data_netmask)#define type_pf_data_list TOKEN(TYPE, PF, _data_list)#define type_pf_data_tlist TOKEN(TYPE, PF, _data_tlist) +#define type_pf_data_next TOKEN(TYPE, PF, _data_next)#define type_pf_elem TOKEN(TYPE, PF, _elem)#define type_pf_telem TOKEN(TYPE, PF, _telem)
@@ -346,6 +353,9 @@ retry:return 0 ; } +static inline void +type_pf_data_next (struct ip_set_hash *h,const struct type_pf_elem *d); +/* Add an element to a hash and update the internal counters when succeeded, * otherwise report the proper error code. */ static int
@@ -372,8 +382,11 @@ type_pf_add(struct ip_set *set, void *value, u32 timeout, u32 flags) } ret =type_pf_elem_add (n, value); -if (ret !=0 ) +if (ret !=0 ) { +if (ret == -EAGAIN ) +type_pf_data_next (h, d); goto out; + }#ifdef IP_SET_HASH_WITH_NETS add_cidr (h, d->cidr,HOST_MASK );
@@ -589,7 +602,7 @@ type_pf_kadt(struct ip_set *set, const struct sk_buff * skb, enum ipset_adt adt, const struct ip_set_adt_opt *opt);static int type_pf_uadt (struct ip_set *set,struct nlattr *tb[], -enum ipset_adt adt,u32 *lineno,u32 flags); +enum ipset_adt adt,u32 *lineno,u32 flags,bool retried);static const struct ip_set_type_variant type_pf_variant = { .kadt = type_pf_kadt,
@@ -821,8 +834,11 @@ type_pf_tadd(struct ip_set *set, void *value, u32 timeout, u32 flags) goto out; } ret =type_pf_elem_tadd (n, d, timeout); -if (ret !=0 ) +if (ret !=0 ) { +if (ret == -EAGAIN ) +type_pf_data_next (h, d); goto out; + }#ifdef IP_SET_HASH_WITH_NETS add_cidr (h, d->cidr,HOST_MASK );
net/netfilter/ipset/ip_set_bitmap_ip.c +1 -1
@@ -236,7 +236,7 @@ bitmap_ip_kadt(struct ip_set *set, const struct sk_buff *skb,static int bitmap_ip_uadt (struct ip_set *set,struct nlattr *tb[], -enum ipset_adt adt,u32 *lineno,u32 flags) +enum ipset_adt adt,u32 *lineno,u32 flags,bool retried) {struct bitmap_ip *map = set->data;ipset_adtfn adtfn = set->variant->adt[adt];
net/netfilter/ipset/ip_set_bitmap_ipmac.c +1 -1
@@ -365,7 +365,7 @@ bitmap_ipmac_kadt(struct ip_set *set, const struct sk_buff *skb,static int bitmap_ipmac_uadt (struct ip_set *set,struct nlattr *tb[], -enum ipset_adt adt,u32 *lineno,u32 flags) +enum ipset_adt adt,u32 *lineno,u32 flags,bool retried) {const struct bitmap_ipmac *map = set->data;ipset_adtfn adtfn = set->variant->adt[adt];
net/netfilter/ipset/ip_set_bitmap_port.c +1 -1
@@ -231,7 +231,7 @@ bitmap_port_kadt(struct ip_set *set, const struct sk_buff *skb,static int bitmap_port_uadt (struct ip_set *set,struct nlattr *tb[], -enum ipset_adt adt,u32 *lineno,u32 flags) +enum ipset_adt adt,u32 *lineno,u32 flags,bool retried) {struct bitmap_port *map = set->data;ipset_adtfn adtfn = set->variant->adt[adt];
net/netfilter/ipset/ip_set_core.c +6 -5
@@ -1158,17 +1158,18 @@ call_ad(struct sock *ctnl, struct sk_buff *skb, struct ip_set *set, struct nlattr *tb[], enum ipset_adt adt, u32 flags, bool use_lineno) { - int ret, retried = 0; + int ret;u32 lineno =0 ; -bool eexist = flags &IPSET_FLAG_EXIST ; +bool eexist = flags &IPSET_FLAG_EXIST , retried = false;do {write_lock_bh (&set->lock); - ret = set->variant->uadt (set, tb, adt, &lineno, flags); + ret = set->variant->uadt (set, tb, adt, &lineno, flags, retried);write_unlock_bh (&set->lock); + retried = true; }while (ret == -EAGAIN && set->variant->resize && - (ret = set->variant->resize (set, retried++)) ==0 ); + (ret = set->variant->resize (set, retried)) ==0 );if (!ret || (ret == -IPSET_ERR_EXIST && eexist))return 0 ;
@@ -1341,7 +1342,7 @@ ip_set_utest(struct sock *ctnl, struct sk_buff *skb,return -IPSET_ERR_PROTOCOL ;read_lock_bh (&set->lock); - ret = set->variant->uadt (set, tb,IPSET_TEST ,NULL ,0 ); + ret = set->variant->uadt (set, tb,IPSET_TEST ,NULL ,0 ,0 );read_unlock_bh (&set->lock);/* Userspace can't trigger element to be re-added */ if (ret == -EAGAIN )
net/netfilter/ipset/ip_set_hash_ip.c +15 -2
@@ -108,6 +108,12 @@ nla_put_failure:#define HOST_MASK 32#include <linux/netfilter/ipset/ip_set_ahash.h> +static inline void +hash_ip4_data_next (struct ip_set_hash *h,const struct hash_ip4_elem *d) +{ + h->next.ip =ntohl (d->ip); +} +static int hash_ip4_kadt (struct ip_set *set,const struct sk_buff *skb,enum ipset_adt adt,const struct ip_set_adt_opt *opt)
@@ -126,7 +132,7 @@ hash_ip4_kadt(struct ip_set *set, const struct sk_buff *skb,static int hash_ip4_uadt (struct ip_set *set,struct nlattr *tb[], -enum ipset_adt adt,u32 *lineno,u32 flags) +enum ipset_adt adt,u32 *lineno,u32 flags,bool retried) {const struct ip_set_hash *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt];
@@ -178,6 +184,8 @@ hash_ip4_uadt(struct ip_set *set, struct nlattr *tb[], hosts = h->netmask ==32 ?1 :2 << (32 - h->netmask -1 ); +if (retried) + ip = h->next.ip;for (; !before (ip_to, ip); ip += hosts) { nip =htonl (ip);if (nip ==0 )
@@ -281,6 +289,11 @@ nla_put_failure:#define HOST_MASK 128#include <linux/netfilter/ipset/ip_set_ahash.h> +static inline void +hash_ip6_data_next (struct ip_set_hash *h,const struct hash_ip6_elem *d) +{ +} +static int hash_ip6_kadt (struct ip_set *set,const struct sk_buff *skb,enum ipset_adt adt,const struct ip_set_adt_opt *opt)
@@ -305,7 +318,7 @@ static const struct nla_policy hash_ip6_adt_policy[IPSET_ATTR_ADT_MAX + 1] = {static int hash_ip6_uadt (struct ip_set *set,struct nlattr *tb[], -enum ipset_adt adt,u32 *lineno,u32 flags) +enum ipset_adt adt,u32 *lineno,u32 flags,bool retried) {const struct ip_set_hash *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt];
net/netfilter/ipset/ip_set_hash_ipport.c +26 -5
@@ -124,6 +124,14 @@ nla_put_failure:#define HOST_MASK 32#include <linux/netfilter/ipset/ip_set_ahash.h> +static inline void +hash_ipport4_data_next (struct ip_set_hash *h, +const struct hash_ipport4_elem *d) +{ + h->next.ip =ntohl (d->ip); + h->next.port =ntohs (d->port); +} +static int hash_ipport4_kadt (struct ip_set *set,const struct sk_buff *skb,enum ipset_adt adt,const struct ip_set_adt_opt *opt)
@@ -143,12 +151,12 @@ hash_ipport4_kadt(struct ip_set *set, const struct sk_buff *skb,static int hash_ipport4_uadt (struct ip_set *set,struct nlattr *tb[], -enum ipset_adt adt,u32 *lineno,u32 flags) +enum ipset_adt adt,u32 *lineno,u32 flags,bool retried) {const struct ip_set_hash *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt];struct hash_ipport4_elem data = { }; -u32 ip, ip_to, p, port, port_to; +u32 ip, ip_to, p =0 , port, port_to;u32 timeout = h->timeout;bool with_ports = false;int ret;
@@ -220,8 +228,11 @@ hash_ipport4_uadt(struct ip_set *set, struct nlattr *tb[],swap (port, port_to); } -for (; !before (ip_to, ip); ip++) -for (p = port; p <= port_to; p++) { +if (retried) + ip = h->next.ip; +for (; !before (ip_to, ip); ip++) { + p = retried && ip == h->next.ip ? h->next.port : port; +for (; p <= port_to; p++) { data.ip =htonl (ip); data.port =htons (p); ret =adtfn (set, &data, timeout, flags);
@@ -231,6 +242,7 @@ hash_ipport4_uadt(struct ip_set *set, struct nlattr *tb[],else ret =0 ; } + }return ret; }
@@ -328,6 +340,13 @@ nla_put_failure:#define HOST_MASK 128#include <linux/netfilter/ipset/ip_set_ahash.h> +static inline void +hash_ipport6_data_next (struct ip_set_hash *h, +const struct hash_ipport6_elem *d) +{ + h->next.port =ntohs (d->port); +} +static int hash_ipport6_kadt (struct ip_set *set,const struct sk_buff *skb,enum ipset_adt adt,const struct ip_set_adt_opt *opt)
@@ -347,7 +366,7 @@ hash_ipport6_kadt(struct ip_set *set, const struct sk_buff *skb,static int hash_ipport6_uadt (struct ip_set *set,struct nlattr *tb[], -enum ipset_adt adt,u32 *lineno,u32 flags) +enum ipset_adt adt,u32 *lineno,u32 flags,bool retried) {const struct ip_set_hash *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt];
@@ -405,6 +424,8 @@ hash_ipport6_uadt(struct ip_set *set, struct nlattr *tb[],if (port > port_to)swap (port, port_to); +if (retried) + port = h->next.port;for (; port <= port_to; port++) { data.port =htons (port); ret =adtfn (set, &data, timeout, flags);
net/netfilter/ipset/ip_set_hash_ipportip.c +26 -5
@@ -127,6 +127,14 @@ nla_put_failure:#define HOST_MASK 32#include <linux/netfilter/ipset/ip_set_ahash.h> +static inline void +hash_ipportip4_data_next (struct ip_set_hash *h, +const struct hash_ipportip4_elem *d) +{ + h->next.ip =ntohl (d->ip); + h->next.port =ntohs (d->port); +} +static int hash_ipportip4_kadt (struct ip_set *set,const struct sk_buff *skb,enum ipset_adt adt,const struct ip_set_adt_opt *opt)
@@ -147,12 +155,12 @@ hash_ipportip4_kadt(struct ip_set *set, const struct sk_buff *skb,static int hash_ipportip4_uadt (struct ip_set *set,struct nlattr *tb[], -enum ipset_adt adt,u32 *lineno,u32 flags) +enum ipset_adt adt,u32 *lineno,u32 flags,bool retried) {const struct ip_set_hash *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt];struct hash_ipportip4_elem data = { }; -u32 ip, ip_to, p, port, port_to; +u32 ip, ip_to, p =0 , port, port_to;u32 timeout = h->timeout;bool with_ports = false;int ret;
@@ -228,8 +236,11 @@ hash_ipportip4_uadt(struct ip_set *set, struct nlattr *tb[],swap (port, port_to); } -for (; !before (ip_to, ip); ip++) -for (p = port; p <= port_to; p++) { +if (retried) + ip = h->next.ip; +for (; !before (ip_to, ip); ip++) { + p = retried && ip == h->next.ip ? h->next.port : port; +for (; p <= port_to; p++) { data.ip =htonl (ip); data.port =htons (p); ret =adtfn (set, &data, timeout, flags);
@@ -239,6 +250,7 @@ hash_ipportip4_uadt(struct ip_set *set, struct nlattr *tb[],else ret =0 ; } + }return ret; }
@@ -341,6 +353,13 @@ nla_put_failure:#define HOST_MASK 128#include <linux/netfilter/ipset/ip_set_ahash.h> +static inline void +hash_ipportip6_data_next (struct ip_set_hash *h, +const struct hash_ipportip6_elem *d) +{ + h->next.port =ntohs (d->port); +} +static int hash_ipportip6_kadt (struct ip_set *set,const struct sk_buff *skb,enum ipset_adt adt,const struct ip_set_adt_opt *opt)
@@ -361,7 +380,7 @@ hash_ipportip6_kadt(struct ip_set *set, const struct sk_buff *skb,static int hash_ipportip6_uadt (struct ip_set *set,struct nlattr *tb[], -enum ipset_adt adt,u32 *lineno,u32 flags) +enum ipset_adt adt,u32 *lineno,u32 flags,bool retried) {const struct ip_set_hash *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt];
@@ -423,6 +442,8 @@ hash_ipportip6_uadt(struct ip_set *set, struct nlattr *tb[],if (port > port_to)swap (port, port_to); +if (retried) + port = h->next.port;for (; port <= port_to; port++) { data.port =htons (port); ret =adtfn (set, &data, timeout, flags);
net/netfilter/ipset/ip_set_hash_ipportnet.c +26 -5
@@ -140,6 +140,14 @@ nla_put_failure:#define HOST_MASK 32#include <linux/netfilter/ipset/ip_set_ahash.h> +static inline void +hash_ipportnet4_data_next (struct ip_set_hash *h, +const struct hash_ipportnet4_elem *d) +{ + h->next.ip =ntohl (d->ip); + h->next.port =ntohs (d->port); +} +static int hash_ipportnet4_kadt (struct ip_set *set,const struct sk_buff *skb,enum ipset_adt adt,const struct ip_set_adt_opt *opt)
@@ -167,12 +175,12 @@ hash_ipportnet4_kadt(struct ip_set *set, const struct sk_buff *skb,static int hash_ipportnet4_uadt (struct ip_set *set,struct nlattr *tb[], -enum ipset_adt adt,u32 *lineno,u32 flags) +enum ipset_adt adt,u32 *lineno,u32 flags,bool retried) {const struct ip_set_hash *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt];struct hash_ipportnet4_elem data = { .cidr =HOST_MASK }; -u32 ip, ip_to, p, port, port_to; +u32 ip, ip_to, p =0 , port, port_to;u32 timeout = h->timeout;bool with_ports = false;int ret;
@@ -256,8 +264,11 @@ hash_ipportnet4_uadt(struct ip_set *set, struct nlattr *tb[],swap (port, port_to); } -for (; !before (ip_to, ip); ip++) -for (p = port; p <= port_to; p++) { +if (retried) + ip = h->next.ip; +for (; !before (ip_to, ip); ip++) { + p = retried && ip == h->next.ip ? h->next.port : port; +for (; p <= port_to; p++) { data.ip =htonl (ip); data.port =htons (p); ret =adtfn (set, &data, timeout, flags);
@@ -267,6 +278,7 @@ hash_ipportnet4_uadt(struct ip_set *set, struct nlattr *tb[],else ret =0 ; } + }return ret; }
@@ -388,6 +400,13 @@ nla_put_failure:#define HOST_MASK 128#include <linux/netfilter/ipset/ip_set_ahash.h> +static inline void +hash_ipportnet6_data_next (struct ip_set_hash *h, +const struct hash_ipportnet6_elem *d) +{ + h->next.port =ntohs (d->port); +} +static int hash_ipportnet6_kadt (struct ip_set *set,const struct sk_buff *skb,enum ipset_adt adt,const struct ip_set_adt_opt *opt)
@@ -415,7 +434,7 @@ hash_ipportnet6_kadt(struct ip_set *set, const struct sk_buff *skb,static int hash_ipportnet6_uadt (struct ip_set *set,struct nlattr *tb[], -enum ipset_adt adt,u32 *lineno,u32 flags) +enum ipset_adt adt,u32 *lineno,u32 flags,bool retried) {const struct ip_set_hash *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt];
@@ -485,6 +504,8 @@ hash_ipportnet6_uadt(struct ip_set *set, struct nlattr *tb[],if (port > port_to)swap (port, port_to); +if (retried) + port = h->next.port;for (; port <= port_to; port++) { data.port =htons (port); ret =adtfn (set, &data, timeout, flags);
net/netfilter/ipset/ip_set_hash_net.c +14 -2
@@ -125,6 +125,12 @@ nla_put_failure:#define HOST_MASK 32#include <linux/netfilter/ipset/ip_set_ahash.h> +static inline void +hash_net4_data_next (struct ip_set_hash *h, +const struct hash_net4_elem *d) +{ +} +static int hash_net4_kadt (struct ip_set *set,const struct sk_buff *skb,enum ipset_adt adt,const struct ip_set_adt_opt *opt)
@@ -146,7 +152,7 @@ hash_net4_kadt(struct ip_set *set, const struct sk_buff *skb,static int hash_net4_uadt (struct ip_set *set,struct nlattr *tb[], -enum ipset_adt adt,u32 *lineno,u32 flags) +enum ipset_adt adt,u32 *lineno,u32 flags,bool retried) {const struct ip_set_hash *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt];
@@ -290,6 +296,12 @@ nla_put_failure:#define HOST_MASK 128#include <linux/netfilter/ipset/ip_set_ahash.h> +static inline void +hash_net6_data_next (struct ip_set_hash *h, +const struct hash_net6_elem *d) +{ +} +static int hash_net6_kadt (struct ip_set *set,const struct sk_buff *skb,enum ipset_adt adt,const struct ip_set_adt_opt *opt)
@@ -311,7 +323,7 @@ hash_net6_kadt(struct ip_set *set, const struct sk_buff *skb,static int hash_net6_uadt (struct ip_set *set,struct nlattr *tb[], -enum ipset_adt adt,u32 *lineno,u32 flags) +enum ipset_adt adt,u32 *lineno,u32 flags,bool retried) {const struct ip_set_hash *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt];
net/netfilter/ipset/ip_set_hash_netport.c +20 -2
@@ -137,6 +137,13 @@ nla_put_failure:#define HOST_MASK 32#include <linux/netfilter/ipset/ip_set_ahash.h> +static inline void +hash_netport4_data_next (struct ip_set_hash *h, +const struct hash_netport4_elem *d) +{ + h->next.port =ntohs (d->port); +} +static int hash_netport4_kadt (struct ip_set *set,const struct sk_buff *skb,enum ipset_adt adt,const struct ip_set_adt_opt *opt)
@@ -163,7 +170,7 @@ hash_netport4_kadt(struct ip_set *set, const struct sk_buff *skb,static int hash_netport4_uadt (struct ip_set *set,struct nlattr *tb[], -enum ipset_adt adt,u32 *lineno,u32 flags) +enum ipset_adt adt,u32 *lineno,u32 flags,bool retried) {const struct ip_set_hash *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt];
@@ -225,6 +232,8 @@ hash_netport4_uadt(struct ip_set *set, struct nlattr *tb[],if (port > port_to)swap (port, port_to); +if (retried) + port = h->next.port;for (; port <= port_to; port++) { data.port =htons (port); ret =adtfn (set, &data, timeout, flags);
@@ -350,6 +359,13 @@ nla_put_failure:#define HOST_MASK 128#include <linux/netfilter/ipset/ip_set_ahash.h> +static inline void +hash_netport6_data_next (struct ip_set_hash *h, +const struct hash_netport6_elem *d) +{ + h->next.port =ntohs (d->port); +} +static int hash_netport6_kadt (struct ip_set *set,const struct sk_buff *skb,enum ipset_adt adt,const struct ip_set_adt_opt *opt)
@@ -376,7 +392,7 @@ hash_netport6_kadt(struct ip_set *set, const struct sk_buff *skb,static int hash_netport6_uadt (struct ip_set *set,struct nlattr *tb[], -enum ipset_adt adt,u32 *lineno,u32 flags) +enum ipset_adt adt,u32 *lineno,u32 flags,bool retried) {const struct ip_set_hash *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt];
@@ -438,6 +454,8 @@ hash_netport6_uadt(struct ip_set *set, struct nlattr *tb[],if (port > port_to)swap (port, port_to); +if (retried) + port = h->next.port;for (; port <= port_to; port++) { data.port =htons (port); ret =adtfn (set, &data, timeout, flags);
net/netfilter/ipset/ip_set_list_set.c +1 -1
@@ -218,7 +218,7 @@ cleanup_entries(struct list_set *map)static int list_set_uadt (struct ip_set *set,struct nlattr *tb[], -enum ipset_adt adt,u32 *lineno,u32 flags) +enum ipset_adt adt,u32 *lineno,u32 flags,bool retried) {struct list_set *map = set->data;bool with_timeout =with_timeout (map->timeout);
Signature · 1 line
1.7.2.5
[email protected]
maintainerPATCH 4/20 netfilter: ipset: Set type support with multiple revisions added
In reply to [email protected]From: Jozsef Kadlecsik <[email protected]>
A set type may have multiple revisions, for example when syntax is extended. Support continuous revision ranges in set types.
--- include/linux/netfilter/ipset/ip_set.h | 6 ++- net/netfilter/ipset/ip_set_bitmap_ip.c | 3 +- net/netfilter/ipset/ip_set_bitmap_ipmac.c | 3 +- net/netfilter/ipset/ip_set_bitmap_port.c | 3 +- net/netfilter/ipset/ip_set_core.c | 45 +++++++++++++++------------ net/netfilter/ipset/ip_set_hash_ip.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_net.c | 3 +- net/netfilter/ipset/ip_set_hash_netport.c | 3 +- net/netfilter/ipset/ip_set_list_set.c | 3 +- 12 files changed, 49 insertions(+), 32 deletions(-)
include/linux/netfilter/ipset/ip_set.h +4 -2
@@ -282,8 +282,8 @@ struct ip_set_type {u8 dimension;/* Supported family: may be AF_UNSPEC for both AF_INET/AF_INET6 */ u8 family; -/* Type revision */ -u8 revision; +/* Type revisions */ +u8 revision_min, revision_max;/* Create set */ int (*create)(struct ip_set *set,struct nlattr *tb[],u32 flags);
@@ -314,6 +314,8 @@ struct ip_set {const struct ip_set_type_variant *variant;/* The actual INET family of the set */ u8 family; +/* The type revision */ +u8 revision;/* The type specific data */ void *data; };
net/netfilter/ipset/ip_set_bitmap_ip.c +2 -1
@@ -551,7 +551,8 @@ static struct ip_set_type bitmap_ip_type __read_mostly = { .features = IPSET_TYPE_IP, .dimension = IPSET_DIM_ONE, .family = AF_INET, - .revision = 0, + .revision_min = 0, + .revision_max = 0, .create = bitmap_ip_create, .create_policy = { [IPSET_ATTR_IP] = { .type = NLA_NESTED },
net/netfilter/ipset/ip_set_bitmap_ipmac.c +2 -1
@@ -623,7 +623,8 @@ static struct ip_set_type bitmap_ipmac_type = { .features = IPSET_TYPE_IP | IPSET_TYPE_MAC, .dimension = IPSET_DIM_TWO, .family = AF_INET, - .revision = 0, + .revision_min = 0, + .revision_max = 0, .create = bitmap_ipmac_create, .create_policy = { [IPSET_ATTR_IP] = { .type = NLA_NESTED },
net/netfilter/ipset/ip_set_bitmap_port.c +2 -1
@@ -483,7 +483,8 @@ static struct ip_set_type bitmap_port_type = { .features = IPSET_TYPE_PORT, .dimension = IPSET_DIM_ONE, .family = AF_UNSPEC, - .revision = 0, + .revision_min = 0, + .revision_max = 0, .create = bitmap_port_create, .create_policy = { [IPSET_ATTR_PORT] = { .type = NLA_U16 },
net/netfilter/ipset/ip_set_core.c +25 -20
109 lines not on this page · raw message
net/netfilter/ipset/ip_set_hash_ip.c +2 -1
@@ -441,7 +441,8 @@ static struct ip_set_type hash_ip_type __read_mostly = { .features = IPSET_TYPE_IP, .dimension = IPSET_DIM_ONE, .family = AF_UNSPEC, - .revision = 0, + .revision_min = 0, + .revision_max = 0, .create = hash_ip_create, .create_policy = { [IPSET_ATTR_HASHSIZE] = { .type = NLA_U32 },
net/netfilter/ipset/ip_set_hash_ipport.c +2 -1
@@ -512,7 +512,8 @@ static struct ip_set_type hash_ipport_type __read_mostly = { .features = IPSET_TYPE_IP | IPSET_TYPE_PORT, .dimension = IPSET_DIM_TWO, .family = AF_UNSPEC, - .revision = 1, + .revision_min = 0, + .revision_max = 1, /* SCTP and UDPLITE support added */ .create = hash_ipport_create, .create_policy = { [IPSET_ATTR_HASHSIZE] = { .type = NLA_U32 },
net/netfilter/ipset/ip_set_hash_ipportip.c +2 -1
@@ -530,7 +530,8 @@ static struct ip_set_type hash_ipportip_type __read_mostly = { .features = IPSET_TYPE_IP | IPSET_TYPE_PORT | IPSET_TYPE_IP2, .dimension = IPSET_DIM_THREE, .family = AF_UNSPEC, - .revision = 1, + .revision_min = 0, + .revision_max = 1, /* SCTP and UDPLITE support added */ .create = hash_ipportip_create, .create_policy = { [IPSET_ATTR_HASHSIZE] = { .type = NLA_U32 },
net/netfilter/ipset/ip_set_hash_ipportnet.c +2 -1
@@ -595,7 +595,8 @@ static struct ip_set_type hash_ipportnet_type __read_mostly = { .features = IPSET_TYPE_IP | IPSET_TYPE_PORT | IPSET_TYPE_IP2, .dimension = IPSET_DIM_THREE, .family = AF_UNSPEC, - .revision = 1, + .revision_min = 0, + .revision_max = 1, /* SCTP and UDPLITE support added */ .create = hash_ipportnet_create, .create_policy = { [IPSET_ATTR_HASHSIZE] = { .type = NLA_U32 },
net/netfilter/ipset/ip_set_hash_net.c +2 -1
@@ -437,7 +437,8 @@ static struct ip_set_type hash_net_type __read_mostly = { .features = IPSET_TYPE_IP, .dimension = IPSET_DIM_ONE, .family = AF_UNSPEC, - .revision = 0, + .revision_min = 0, + .revision_max = 0, .create = hash_net_create, .create_policy = { [IPSET_ATTR_HASHSIZE] = { .type = NLA_U32 },
net/netfilter/ipset/ip_set_hash_netport.c +2 -1
@@ -544,7 +544,8 @@ static struct ip_set_type hash_netport_type __read_mostly = { .features = IPSET_TYPE_IP | IPSET_TYPE_PORT, .dimension = IPSET_DIM_TWO, .family = AF_UNSPEC, - .revision = 1, + .revision_min = 0, + .revision_max = 1, /* SCTP and UDPLITE support added */ .create = hash_netport_create, .create_policy = { [IPSET_ATTR_HASHSIZE] = { .type = NLA_U32 },
net/netfilter/ipset/ip_set_list_set.c +2 -1
@@ -575,7 +575,8 @@ static struct ip_set_type list_set_type __read_mostly = { .features = IPSET_TYPE_NAME | IPSET_DUMP_LAST, .dimension = IPSET_DIM_ONE, .family = AF_UNSPEC, - .revision = 0, + .revision_min = 0, + .revision_max = 0, .create = list_set_create, .create_policy = { [IPSET_ATTR_SIZE] = { .type = NLA_U32 },
Signature · 1 line
1.7.2.5
[email protected]
maintainerPATCH 5/20 netfilter: ipset: Support range for IPv4 at adding/deleting elements for hash:*net* types
In reply to [email protected]From: Jozsef Kadlecsik <[email protected]>
The IPv4 input may be expressed in a range. The range is then internally converted to the network(s) equal to the range. Example:
# ipset new test hash:net
# ipset add test 10.2.0.0-10.2.1.12
# ipset list test
Name: test
Type: hash:net
Header: family inet hashsize 1024 maxelem 65536
Size in memory: 16888
References: 0
Members:
10.2.1.12
10.2.1.0/29
10.2.0.0/24
10.2.1.8/30--- include/linux/netfilter/ipset/ip_set.h | 1 + include/linux/netfilter/ipset/ip_set_ahash.h | 2 +- include/linux/netfilter/ipset/ip_set_hash.h | 4 ++ include/linux/netfilter/ipset/pfxlen.h | 3 + net/netfilter/ipset/ip_set_hash_ipportnet.c | 69 +++++++++++++++++-------- net/netfilter/ipset/ip_set_hash_net.c | 51 +++++++++++++++---- net/netfilter/ipset/ip_set_hash_netport.c | 69 ++++++++++++++++++-------- net/netfilter/ipset/pfxlen.c | 21 ++++++++ 8 files changed, 165 insertions(+), 55 deletions(-)
include/linux/netfilter/ipset/ip_set.h +1 -0
@@ -104,6 +104,7 @@ enum {IPSET_ATTR_NAMEREF ,IPSET_ATTR_IP2 ,IPSET_ATTR_CIDR2 , +IPSET_ATTR_IP2_TO , __IPSET_ATTR_ADT_MAX, };#define IPSET_ATTR_ADT_MAX (__IPSET_ATTR_ADT_MAX - 1)
include/linux/netfilter/ipset/ip_set_ahash.h +1 -1
@@ -353,7 +353,7 @@ retry:return 0 ; } -static inline void +static void type_pf_data_next (struct ip_set_hash *h,const struct type_pf_elem *d);/* Add an element to a hash and update the internal counters when succeeded,
include/linux/netfilter/ipset/ip_set_hash.h +4 -0
@@ -11,6 +11,10 @@ enum {IPSET_ERR_INVALID_PROTO ,/* Protocol missing but must be specified */ IPSET_ERR_MISSING_PROTO , +/* Range not supported */ +IPSET_ERR_HASH_RANGE_UNSUPPORTED , +/* Invalid range */ + IPSET_ERR_HASH_RANGE, };#ifdef __KERNEL__
include/linux/netfilter/ipset/pfxlen.h +3 -0
@@ -3,6 +3,7 @@#include <asm/byteorder.h> #include <linux/netfilter.h> +#include <net/tcp.h> /* Prefixlen maps, by Jan Engelhardt */ extern const union nf_inet_addr ip_set_netmask_map[];
@@ -32,4 +33,6 @@ ip_set_hostmask6(u8 pfxlen) return &ip_set_hostmask_map[pfxlen].ip6[0]; } +extern u32 ip_set_range_to_cidr (u32 from,u32 to,u8 *cidr); +#endif /*_PFXLEN_H */
net/netfilter/ipset/ip_set_hash_ipportnet.c +47 -22
142 lines not on this page · raw message
net/netfilter/ipset/ip_set_hash_net.c +40 -11
98 lines not on this page · raw message
net/netfilter/ipset/ip_set_hash_netport.c +48 -21
121 lines not on this page · raw message
net/netfilter/ipset/pfxlen.c +21 -0
@@ -289,3 +289,24 @@ const union nf_inet_addr ip_set_hostmask_map[] = {E (0xFFFFFFFF ,0xFFFFFFFF ,0xFFFFFFFF ,0xFFFFFFFF ), };EXPORT_SYMBOL_GPL (ip_set_hostmask_map); + +/* Find the largest network which matches the range from left, in host order. */ +u32 +ip_set_range_to_cidr (u32 from,u32 to,u8 *cidr) +{ +u32 last; +u8 i; + +for (i =1 ; i <32 ; i++) { +if ((from &ip_set_hostmask (i)) != from) +continue ; + last = from | ~ip_set_hostmask (i); +if (!after (last, to)) { + *cidr = i; +return last; + } + } + *cidr =32 ; +return from; +} +EXPORT_SYMBOL_GPL (ip_set_range_to_cidr);
Signature · 1 line
1.7.2.5
[email protected]
maintainerPATCH 6/20 netfilter: ipset: Take into account cidr value for the from address when creating the set
In reply to [email protected]From: Jozsef Kadlecsik <[email protected]>
When creating a set from a range expressed as a network like 10.1.1.172/29, the from address was taken as the IP address part and not masked with the netmask from the cidr. Use unified from/to address masking.
--- include/linux/netfilter/ipset/pfxlen.h | 6 ++++++ net/netfilter/ipset/ip_set_bitmap_ip.c | 5 ++--- net/netfilter/ipset/ip_set_bitmap_ipmac.c | 2 +- net/netfilter/ipset/ip_set_hash_ip.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 | 6 ++---- net/netfilter/ipset/ip_set_hash_netport.c | 3 +-- 8 files changed, 15 insertions(+), 16 deletions(-)
include/linux/netfilter/ipset/pfxlen.h +6 -0
@@ -35,4 +35,10 @@ ip_set_hostmask6(u8 pfxlen)extern u32 ip_set_range_to_cidr (u32 from,u32 to,u8 *cidr); +#define ip_set_mask_from_to (from, to, cidr) \ +do { \ + from &= ip_set_hostmask(cidr); \ + to = from | ~ip_set_hostmask(cidr); \ +} while (0) +#endif /*_PFXLEN_H */
net/netfilter/ipset/ip_set_bitmap_ip.c +2 -3
@@ -283,8 +283,7 @@ bitmap_ip_uadt(struct ip_set *set, struct nlattr *tb[],if (cidr >32 )return -IPSET_ERR_INVALID_CIDR ; - ip &=ip_set_hostmask (cidr); - ip_to = ip | ~ip_set_hostmask (cidr); +ip_set_mask_from_to (ip, ip_to, cidr); }else ip_to = ip;
@@ -478,7 +477,7 @@ bitmap_ip_create(struct ip_set *set, struct nlattr *tb[], u32 flags)if (cidr >=32 )return -IPSET_ERR_INVALID_CIDR ; - last_ip = first_ip | ~ip_set_hostmask (cidr); +ip_set_mask_from_to (first_ip, last_ip, cidr); }else return -IPSET_ERR_PROTOCOL ;
net/netfilter/ipset/ip_set_bitmap_ipmac.c +1 -1
@@ -578,7 +578,7 @@ bitmap_ipmac_create(struct ip_set *set, struct nlattr *tb[],if (cidr >=32 )return -IPSET_ERR_INVALID_CIDR ; - last_ip = first_ip | ~ip_set_hostmask (cidr); +ip_set_mask_from_to (first_ip, last_ip, cidr); }else return -IPSET_ERR_PROTOCOL ;
net/netfilter/ipset/ip_set_hash_ip.c +1 -2
@@ -177,8 +177,7 @@ hash_ip4_uadt(struct ip_set *set, struct nlattr *tb[],if (cidr >32 )return -IPSET_ERR_INVALID_CIDR ; - ip &=ip_set_hostmask (cidr); - ip_to = ip | ~ip_set_hostmask (cidr); +ip_set_mask_from_to (ip, ip_to, cidr); }else ip_to = ip;
net/netfilter/ipset/ip_set_hash_ipport.c +1 -2
@@ -216,8 +216,7 @@ hash_ipport4_uadt(struct ip_set *set, struct nlattr *tb[],if (cidr >32 )return -IPSET_ERR_INVALID_CIDR ; - ip &=ip_set_hostmask (cidr); - ip_to = ip | ~ip_set_hostmask (cidr); +ip_set_mask_from_to (ip, ip_to, cidr); }else ip_to = ip;
net/netfilter/ipset/ip_set_hash_ipportip.c +1 -2
@@ -224,8 +224,7 @@ hash_ipportip4_uadt(struct ip_set *set, struct nlattr *tb[],if (cidr >32 )return -IPSET_ERR_INVALID_CIDR ; - ip &=ip_set_hostmask (cidr); - ip_to = ip | ~ip_set_hostmask (cidr); +ip_set_mask_from_to (ip, ip_to, cidr); }else ip_to = ip;
net/netfilter/ipset/ip_set_hash_ipportnet.c +2 -4
@@ -254,8 +254,7 @@ hash_ipportnet4_uadt(struct ip_set *set, struct nlattr *tb[],if (cidr >32 )return -IPSET_ERR_INVALID_CIDR ; - ip &=ip_set_hostmask (cidr); - ip_to = ip | ~ip_set_hostmask (cidr); +ip_set_mask_from_to (ip, ip_to, cidr); } port_to = port =ntohs (data.port);
@@ -273,8 +272,7 @@ hash_ipportnet4_uadt(struct ip_set *set, struct nlattr *tb[],if (ip2_from +UINT_MAX == ip2_to)return -IPSET_ERR_HASH_RANGE ; }else { - ip2_from &=ip_set_hostmask (data.cidr); - ip2_to = ip2_from | ~ip_set_hostmask (data.cidr); +ip_set_mask_from_to (ip2_from, ip2_to, data.cidr); }if (retried)
net/netfilter/ipset/ip_set_hash_netport.c +1 -2
@@ -245,8 +245,7 @@ hash_netport4_uadt(struct ip_set *set, struct nlattr *tb[],if (ip +UINT_MAX == ip_to)return -IPSET_ERR_HASH_RANGE ; }else { - ip &=ip_set_hostmask (data.cidr); - ip_to = ip | ~ip_set_hostmask (data.cidr); +ip_set_mask_from_to (ip, ip_to, data.cidr); }if (retried)
Signature · 1 line
1.7.2.5
[email protected]
maintainerPATCH 7/20 netfilter: nf_conntrack_sip: Handle Cisco 7941/7945 IP phones
In reply to [email protected]From: Kevin Cernekee <[email protected]>
Most SIP devices use a source port of 5060/udp on SIP requests, so the response automatically comes back to port 5060:
phone_ip:5060 -> proxy_ip:5060 REGISTER
proxy_ip:5060 -> phone_ip:5060 100 Trying
The newer Cisco IP phones, however, use a randomly chosen high source port for the SIP request but expect the response on port 5060:
phone_ip:49173 -> proxy_ip:5060 REGISTER
proxy_ip:5060 -> phone_ip:5060 100 Trying
Standard Linux NAT, with or without nf_nat_sip, will send the reply back to port 49173, not 5060:
phone_ip:49173 -> proxy_ip:5060 REGISTER
proxy_ip:5060 -> phone_ip:49173 100 Trying
But the phone is not listening on 49173, so it will never see the reply.
This patch modifies nf_*_sip to work around this quirk by extracting the SIP response port from the Via: header, iff the source IP in the packet header matches the source IP in the SIP request.
--- include/linux/netfilter/nf_conntrack_sip.h | 3 +++ net/ipv4/netfilter/nf_nat_sip.c | 26 +++++++++++++++++++++++--- net/netfilter/nf_conntrack_sip.c | 17 +++++++++++++++++ 3 files changed, 43 insertions(+), 3 deletions(-)
include/linux/netfilter/nf_conntrack_sip.h +3 -0
@@ -2,12 +2,15 @@#define __NF_CONNTRACK_SIP_H__#ifdef __KERNEL__ +#include <linux/types.h> +#define SIP_PORT 5060#define SIP_TIMEOUT 3600struct nf_ct_sip_master {unsigned int register_cseq;unsigned int invite_cseq; +__be16 forced_dport; }; enum sip_expectation_classes {
net/ipv4/netfilter/nf_nat_sip.c +23 -3
@@ -73,6 +73,7 @@ static int map_addr(struct sk_buff *skb, unsigned int dataoff,enum ip_conntrack_info ctinfo;struct nf_conn *ct =nf_ct_get (skb, &ctinfo);enum ip_conntrack_dir dir =CTINFO2DIR (ctinfo); +struct nf_conn_help *help =nfct_help (ct);char buffer[sizeof ("nnn.nnn.nnn.nnn:nnnnn" )];unsigned int buflen;__be32 newaddr;
@@ -85,7 +86,8 @@ static int map_addr(struct sk_buff *skb, unsigned int dataoff, }else if (ct->tuplehash[dir].tuple.dst.u3.ip == addr->ip && ct->tuplehash[dir].tuple.dst.u.udp.port == port) { newaddr = ct->tuplehash[!dir].tuple.src.u3.ip; - newport = ct->tuplehash[!dir].tuple.src.u.udp.port; + newport = help->help.ct_sip_info.forced_dport ? : + ct->tuplehash[!dir].tuple.src.u.udp.port; }else return 1 ;
@@ -121,6 +123,7 @@ static unsigned int ip_nat_sip(struct sk_buff *skb, unsigned int dataoff,enum ip_conntrack_info ctinfo;struct nf_conn *ct =nf_ct_get (skb, &ctinfo);enum ip_conntrack_dir dir =CTINFO2DIR (ctinfo); +struct nf_conn_help *help =nfct_help (ct);unsigned int coff, matchoff, matchlen;enum sip_header_types hdr;union nf_inet_addr addr;
@@ -229,6 +232,20 @@ next: !map_sip_addr(skb, dataoff, dptr, datalen, SIP_HDR_TO))return NF_DROP ; +/* Mangle destination port for Cisco phones, then fix up checksums */ +if (dir ==IP_CT_DIR_REPLY && help->help.ct_sip_info.forced_dport) { +struct udphdr *uh; + +if (!skb_make_writable (skb, skb->len)) +return NF_DROP ; + + uh = (struct udphdr *)(skb->data +ip_hdrlen (skb)); + uh->dest = help->help.ct_sip_info.forced_dport; + +if (!nf_nat_mangle_udp_packet (skb, ct, ctinfo,0 ,0 ,NULL ,0 )) +return NF_DROP ; + } +return NF_ACCEPT ; }
@@ -280,8 +297,10 @@ static unsigned int ip_nat_sip_expect(struct sk_buff *skb, unsigned int dataoff,enum ip_conntrack_info ctinfo;struct nf_conn *ct =nf_ct_get (skb, &ctinfo);enum ip_conntrack_dir dir =CTINFO2DIR (ctinfo); +struct nf_conn_help *help =nfct_help (ct);__be32 newip;u_int16_t port; +__be16 srcport;char buffer[sizeof ("nnn.nnn.nnn.nnn:nnnnn" )];unsigned buflen;
@@ -294,8 +313,9 @@ static unsigned int ip_nat_sip_expect(struct sk_buff *skb, unsigned int dataoff,/* If the signalling port matches the connection's source port in the * original direction, try to use the destination port in the opposite * direction. */ -if (exp->tuple.dst.u.udp.port == - ct->tuplehash[dir].tuple.src.u.udp.port) + srcport = help->help.ct_sip_info.forced_dport ? : + ct->tuplehash[dir].tuple.src.u.udp.port; +if (exp->tuple.dst.u.udp.port == srcport) port =ntohs (ct->tuplehash[!dir].tuple.dst.u.udp.port);else port =ntohs (exp->tuple.dst.u.udp.port);
net/netfilter/nf_conntrack_sip.c +17 -0
@@ -1363,8 +1363,25 @@ static int process_sip_request(struct sk_buff *skb, unsigned int dataoff, {enum ip_conntrack_info ctinfo;struct nf_conn *ct =nf_ct_get (skb, &ctinfo); +struct nf_conn_help *help =nfct_help (ct); +enum ip_conntrack_dir dir =CTINFO2DIR (ctinfo);unsigned int matchoff, matchlen;unsigned int cseq, i; +union nf_inet_addr addr; +__be16 port; + +/* Many Cisco IP phones use a high source port for SIP requests, but +* listen for the response on port 5060. If we are the local +* router for one of these phones, save the port number from the +* Via: header so that nf_nat_sip can redirect the responses to +* the correct port. +*/ +if (ct_sip_parse_header_uri (ct, *dptr,NULL , *datalen, +SIP_HDR_VIA_UDP ,NULL , &matchoff, + &matchlen, &addr, &port) >0 && + port != ct->tuplehash[dir].tuple.src.u.udp.port && +nf_inet_addr_cmp (&addr, &ct->tuplehash[dir].tuple.src.u3)) + help->help.ct_sip_info.forced_dport = port;for (i =0 ; i <ARRAY_SIZE (sip_handlers); i++) {const struct sip_handler *handler;
Signature · 1 line
1.7.2.5
[email protected]
maintainerPATCH 8/20 netfilter: add more values to enum ip_conntrack_info
In reply to [email protected]From: Eric Dumazet <[email protected]>
Following error is raised (and other similar ones) :
net/ipv4/netfilter/nf_nat_standalone.c: In function ‘nf_nat_fn’:net/ipv4/netfilter/nf_nat_standalone.c:119:2: warning: case value ‘4’ not in enumerated type ‘enum ip_conntrack_info’
gcc barfs on adding two enum values and getting a not enumerated result :
case IP_CT_RELATED+IP_CT_IS_REPLY:
Add missing enum values
--- include/linux/netfilter/nf_conntrack_common.h | 3 +++ net/ipv4/netfilter/ipt_CLUSTERIP.c | 6 +++--- net/ipv4/netfilter/ipt_MASQUERADE.c | 2 +- net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c | 2 +- net/ipv4/netfilter/nf_nat_core.c | 2 +- net/ipv4/netfilter/nf_nat_rule.c | 2 +- net/ipv4/netfilter/nf_nat_standalone.c | 4 ++-- net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c | 2 +- net/netfilter/nf_conntrack_core.c | 4 ++-- net/netfilter/nf_conntrack_ftp.c | 2 +- net/netfilter/nf_conntrack_h323_main.c | 10 ++++------ net/netfilter/nf_conntrack_irc.c | 3 +-- net/netfilter/nf_conntrack_pptp.c | 3 +-- net/netfilter/nf_conntrack_sane.c | 2 +- net/netfilter/nf_conntrack_sip.c | 2 +- net/netfilter/xt_socket.c | 4 ++-- 16 files changed, 26 insertions(+), 27 deletions(-)
include/linux/netfilter/nf_conntrack_common.h +3 -0
@@ -18,6 +18,9 @@ enum ip_conntrack_info {/* >= this indicates reply direction */ IP_CT_IS_REPLY , +IP_CT_ESTABLISHED_REPLY =IP_CT_ESTABLISHED +IP_CT_IS_REPLY , +IP_CT_RELATED_REPLY =IP_CT_RELATED +IP_CT_IS_REPLY , +IP_CT_NEW_REPLY =IP_CT_NEW +IP_CT_IS_REPLY ,/* Number of distinct IP_CT types (no NEW in reply dirn). */ IP_CT_NUMBER = IP_CT_IS_REPLY * 2 - 1 };
net/ipv4/netfilter/ipt_CLUSTERIP.c +3 -3
@@ -307,7 +307,7 @@ clusterip_tg(struct sk_buff *skb, const struct xt_action_param *par)* error messages (RELATED) and information requests (see below) */ if (ip_hdr (skb)->protocol ==IPPROTO_ICMP && (ctinfo ==IP_CT_RELATED || - ctinfo ==IP_CT_RELATED +IP_CT_IS_REPLY )) + ctinfo ==IP_CT_RELATED_REPLY ))return XT_CONTINUE ;/* ip_conntrack_icmp guarantees us that we only have ICMP_ECHO,
@@ -321,12 +321,12 @@ clusterip_tg(struct sk_buff *skb, const struct xt_action_param *par) ct->mark = hash;break ;case IP_CT_RELATED : -case IP_CT_RELATED +IP_CT_IS_REPLY : +case IP_CT_RELATED_REPLY :/* FIXME: we don't handle expectations at the * moment. they can arrive on a different node than * the master connection (e.g. FTP passive mode) */ case IP_CT_ESTABLISHED : -case IP_CT_ESTABLISHED +IP_CT_IS_REPLY : +case IP_CT_ESTABLISHED_REPLY :break ;default :break ;
net/ipv4/netfilter/ipt_MASQUERADE.c +1 -1
@@ -60,7 +60,7 @@ masquerade_tg(struct sk_buff *skb, const struct xt_action_param *par) nat =nfct_nat (ct);NF_CT_ASSERT (ct && (ctinfo ==IP_CT_NEW || ctinfo ==IP_CT_RELATED || - ctinfo ==IP_CT_RELATED +IP_CT_IS_REPLY )); + ctinfo ==IP_CT_RELATED_REPLY ));/* Source address is 0.0.0.0 - locally generated packet that is * probably not supposed to be masqueraded.
net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c +1 -1
@@ -101,7 +101,7 @@ static unsigned int ipv4_confirm(unsigned int hooknum,/* This is where we call the helper: as the packet goes out. */ ct =nf_ct_get (skb, &ctinfo); -if (!ct || ctinfo ==IP_CT_RELATED +IP_CT_IS_REPLY ) +if (!ct || ctinfo ==IP_CT_RELATED_REPLY ) goto out; help =nfct_help (ct);
net/ipv4/netfilter/nf_nat_core.c +1 -1
@@ -433,7 +433,7 @@ int nf_nat_icmp_reply_translation(struct nf_conn *ct,/* Must be RELATED */ NF_CT_ASSERT (skb->nfctinfo ==IP_CT_RELATED || - skb->nfctinfo ==IP_CT_RELATED +IP_CT_IS_REPLY ); + skb->nfctinfo ==IP_CT_RELATED_REPLY );/* Redirects on non-null nats must be dropped, else they'll start talking to each other without our translation, and be
net/ipv4/netfilter/nf_nat_rule.c +1 -1
@@ -53,7 +53,7 @@ ipt_snat_target(struct sk_buff *skb, const struct xt_action_param *par)/* Connection must be valid and new. */ NF_CT_ASSERT (ct && (ctinfo ==IP_CT_NEW || ctinfo ==IP_CT_RELATED || - ctinfo ==IP_CT_RELATED +IP_CT_IS_REPLY )); + ctinfo ==IP_CT_RELATED_REPLY ));NF_CT_ASSERT (par->out !=NULL );return nf_nat_setup_info (ct, &mr->range[0 ],IP_NAT_MANIP_SRC );
net/ipv4/netfilter/nf_nat_standalone.c +2 -2
@@ -116,7 +116,7 @@ nf_nat_fn(unsigned int hooknum,switch (ctinfo) {case IP_CT_RELATED : -case IP_CT_RELATED +IP_CT_IS_REPLY : +case IP_CT_RELATED_REPLY :if (ip_hdr (skb)->protocol ==IPPROTO_ICMP ) {if (!nf_nat_icmp_reply_translation (ct, ctinfo, hooknum, skb))
@@ -144,7 +144,7 @@ nf_nat_fn(unsigned int hooknum,default :/* ESTABLISHED */ NF_CT_ASSERT (ctinfo ==IP_CT_ESTABLISHED || - ctinfo == (IP_CT_ESTABLISHED +IP_CT_IS_REPLY )); + ctinfo ==IP_CT_ESTABLISHED_REPLY ); }return nf_nat_packet (ct, ctinfo, hooknum, skb);
net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c +1 -1
@@ -160,7 +160,7 @@ static unsigned int ipv6_confirm(unsigned int hooknum,/* This is where we call the helper: as the packet goes out. */ ct =nf_ct_get (skb, &ctinfo); -if (!ct || ctinfo ==IP_CT_RELATED +IP_CT_IS_REPLY ) +if (!ct || ctinfo ==IP_CT_RELATED_REPLY ) goto out; help =nfct_help (ct);
net/netfilter/nf_conntrack_core.c +2 -2
@@ -850,7 +850,7 @@ resolve_normal_ct(struct net *net, struct nf_conn *tmpl,/* It exists; we have (non-exclusive) reference. */ if (NF_CT_DIRECTION (h) ==IP_CT_DIR_REPLY ) { - *ctinfo =IP_CT_ESTABLISHED +IP_CT_IS_REPLY ; + *ctinfo =IP_CT_ESTABLISHED_REPLY ;/* Please set reply bit if this packet OK */ *set_reply =1 ; }else {
@@ -1143,7 +1143,7 @@ static void nf_conntrack_attach(struct sk_buff *nskb, struct sk_buff *skb)/* This ICMP is in reverse direction to the packet which caused it */ ct =nf_ct_get (skb, &ctinfo);if (CTINFO2DIR (ctinfo) ==IP_CT_DIR_ORIGINAL ) - ctinfo =IP_CT_RELATED +IP_CT_IS_REPLY ; + ctinfo =IP_CT_RELATED_REPLY ;else ctinfo =IP_CT_RELATED ;
net/netfilter/nf_conntrack_ftp.c +1 -1
@@ -368,7 +368,7 @@ static int help(struct sk_buff *skb,/* Until there's been traffic both ways, don't look in packets. */ if (ctinfo !=IP_CT_ESTABLISHED && - ctinfo !=IP_CT_ESTABLISHED +IP_CT_IS_REPLY ) { + ctinfo !=IP_CT_ESTABLISHED_REPLY ) {pr_debug ("ftp: Conntrackinfo = %u\n" , ctinfo);return NF_ACCEPT ; }
net/netfilter/nf_conntrack_h323_main.c +4 -6
@@ -571,10 +571,9 @@ static int h245_help(struct sk_buff *skb, unsigned int protoff,int ret;/* Until there's been traffic both ways, don't look in packets. */ -if (ctinfo !=IP_CT_ESTABLISHED && - ctinfo !=IP_CT_ESTABLISHED +IP_CT_IS_REPLY ) { +if (ctinfo !=IP_CT_ESTABLISHED && ctinfo !=IP_CT_ESTABLISHED_REPLY )return NF_ACCEPT ; - } +pr_debug ("nf_ct_h245: skblen = %u\n" , skb->len);spin_lock_bh (&nf_h323_lock);
@@ -1125,10 +1124,9 @@ static int q931_help(struct sk_buff *skb, unsigned int protoff,int ret;/* Until there's been traffic both ways, don't look in packets. */ -if (ctinfo !=IP_CT_ESTABLISHED && - ctinfo !=IP_CT_ESTABLISHED +IP_CT_IS_REPLY ) { +if (ctinfo !=IP_CT_ESTABLISHED && ctinfo !=IP_CT_ESTABLISHED_REPLY )return NF_ACCEPT ; - } +pr_debug ("nf_ct_q931: skblen = %u\n" , skb->len);spin_lock_bh (&nf_h323_lock);
net/netfilter/nf_conntrack_irc.c +1 -2
@@ -125,8 +125,7 @@ static int help(struct sk_buff *skb, unsigned int protoff,return NF_ACCEPT ;/* Until there's been traffic both ways, don't look in packets. */ -if (ctinfo !=IP_CT_ESTABLISHED && - ctinfo !=IP_CT_ESTABLISHED +IP_CT_IS_REPLY ) +if (ctinfo !=IP_CT_ESTABLISHED && ctinfo !=IP_CT_ESTABLISHED_REPLY )return NF_ACCEPT ;/* Not a full tcp header? */
net/netfilter/nf_conntrack_pptp.c +1 -2
@@ -519,8 +519,7 @@ conntrack_pptp_help(struct sk_buff *skb, unsigned int protoff,u_int16_t msg;/* don't do any tracking before tcp handshake complete */ -if (ctinfo !=IP_CT_ESTABLISHED && - ctinfo !=IP_CT_ESTABLISHED +IP_CT_IS_REPLY ) +if (ctinfo !=IP_CT_ESTABLISHED && ctinfo !=IP_CT_ESTABLISHED_REPLY )return NF_ACCEPT ; nexthdr_off = protoff;
net/netfilter/nf_conntrack_sane.c +1 -1
@@ -78,7 +78,7 @@ static int help(struct sk_buff *skb, ct_sane_info = &nfct_help (ct)->help.ct_sane_info;/* Until there's been traffic both ways, don't look in packets. */ if (ctinfo !=IP_CT_ESTABLISHED && - ctinfo !=IP_CT_ESTABLISHED +IP_CT_IS_REPLY ) + ctinfo !=IP_CT_ESTABLISHED_REPLY )return NF_ACCEPT ;/* Not a full tcp header? */
net/netfilter/nf_conntrack_sip.c +1 -1
@@ -1440,7 +1440,7 @@ static int sip_help_tcp(struct sk_buff *skb, unsigned int protoff,typeof (nf_nat_sip_seq_adjust_hook) nf_nat_sip_seq_adjust;if (ctinfo !=IP_CT_ESTABLISHED && - ctinfo !=IP_CT_ESTABLISHED +IP_CT_IS_REPLY ) + ctinfo !=IP_CT_ESTABLISHED_REPLY )return NF_ACCEPT ;/* No Data ? */
net/netfilter/xt_socket.c +2 -2
@@ -143,9 +143,9 @@ socket_match(const struct sk_buff *skb, struct xt_action_param *par, ct =nf_ct_get (skb, &ctinfo);if (ct && !nf_ct_is_untracked (ct) && ((iph->protocol !=IPPROTO_ICMP && - ctinfo ==IP_CT_IS_REPLY +IP_CT_ESTABLISHED ) || + ctinfo ==IP_CT_ESTABLISHED_REPLY ) || (iph->protocol ==IPPROTO_ICMP && - ctinfo ==IP_CT_IS_REPLY +IP_CT_RELATED )) && + ctinfo ==IP_CT_RELATED_REPLY )) && (ct->status &IPS_SRC_NAT_DONE )) { daddr = ct->tuplehash[IP_CT_DIR_ORIGINAL ].tuple.src.u3.ip;
Signature · 6 lines
1.7.2.5 -- To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
[email protected]
maintainerPATCH 10/20 netfilter: ipset: Add xt_action_param to the variant level kadt functions
In reply to [email protected]From: Jozsef Kadlecsik <[email protected]>
With the change the sets can use any parameter available for the match and target extensions, like input/output interface. It's required for the hash:net,iface set type.
--- include/linux/netfilter/ipset/ip_set.h | 5 +++++ include/linux/netfilter/ipset/ip_set_ahash.h | 1 + net/netfilter/ipset/ip_set_bitmap_ip.c | 1 + net/netfilter/ipset/ip_set_bitmap_ipmac.c | 1 + net/netfilter/ipset/ip_set_bitmap_port.c | 1 + net/netfilter/ipset/ip_set_core.c | 12 ++++++++---- net/netfilter/ipset/ip_set_hash_ip.c | 2 ++ net/netfilter/ipset/ip_set_hash_ipport.c | 2 ++ net/netfilter/ipset/ip_set_hash_ipportip.c | 2 ++ net/netfilter/ipset/ip_set_hash_ipportnet.c | 2 ++ net/netfilter/ipset/ip_set_hash_net.c | 2 ++ net/netfilter/ipset/ip_set_hash_netport.c | 2 ++ net/netfilter/ipset/ip_set_list_set.c | 7 ++++--- net/netfilter/xt_set.c | 19 ++++++++++--------- 14 files changed, 43 insertions(+), 16 deletions(-)
include/linux/netfilter/ipset/ip_set.h +5 -0
@@ -170,6 +170,7 @@ enum ipset_adt {#include <linux/ipv6.h> #include <linux/netlink.h> #include <linux/netfilter.h> +#include <linux/netfilter/x_tables.h> #include <linux/vmalloc.h> #include <net/netlink.h>
@@ -238,6 +239,7 @@ struct ip_set_type_variant {* zero for no match/success to add/delete * positive for matching element */ int (*kadt)(struct ip_set *set,const struct sk_buff * skb, +const struct xt_action_param *par,enum ipset_adt adt,const struct ip_set_adt_opt *opt);/* Userspace: test/add/del entries
@@ -332,10 +334,13 @@ extern void ip_set_nfnl_put(ip_set_id_t index);/* API for iptables set match, and SET target */ extern int ip_set_add (ip_set_id_t id,const struct sk_buff *skb, +const struct xt_action_param *par,const struct ip_set_adt_opt *opt);extern int ip_set_del (ip_set_id_t id,const struct sk_buff *skb, +const struct xt_action_param *par,const struct ip_set_adt_opt *opt);extern int ip_set_test (ip_set_id_t id,const struct sk_buff *skb, +const struct xt_action_param *par,const struct ip_set_adt_opt *opt);/* Utility functions */
include/linux/netfilter/ipset/ip_set_ahash.h +1 -0
@@ -599,6 +599,7 @@ nla_put_failure:static int type_pf_kadt (struct ip_set *set,const struct sk_buff * skb, +const struct xt_action_param *par,enum ipset_adt adt,const struct ip_set_adt_opt *opt); static int type_pf_uadt(struct ip_set *set, struct nlattr *tb[],
net/netfilter/ipset/ip_set_bitmap_ip.c +1 -0
@@ -219,6 +219,7 @@ nla_put_failure:static int bitmap_ip_kadt (struct ip_set *set,const struct sk_buff *skb, +const struct xt_action_param *par,enum ipset_adt adt,const struct ip_set_adt_opt *opt) {struct bitmap_ip *map = set->data;
net/netfilter/ipset/ip_set_bitmap_ipmac.c +1 -0
@@ -338,6 +338,7 @@ nla_put_failure:static int bitmap_ipmac_kadt (struct ip_set *set,const struct sk_buff *skb, +const struct xt_action_param *par,enum ipset_adt adt,const struct ip_set_adt_opt *opt) {struct bitmap_ipmac *map = set->data;
net/netfilter/ipset/ip_set_bitmap_port.c +1 -0
@@ -208,6 +208,7 @@ nla_put_failure:static int bitmap_port_kadt (struct ip_set *set,const struct sk_buff *skb, +const struct xt_action_param *par,enum ipset_adt adt,const struct ip_set_adt_opt *opt) {struct bitmap_port *map = set->data;
net/netfilter/ipset/ip_set_core.c +8 -4
@@ -21,6 +21,7 @@#include <net/netlink.h> #include <linux/netfilter.h> +#include <linux/netfilter/x_tables.h> #include <linux/netfilter/nfnetlink.h> #include <linux/netfilter/ipset/ip_set.h>
@@ -328,6 +329,7 @@ __ip_set_put(ip_set_id_t index)int ip_set_test (ip_set_id_t index,const struct sk_buff *skb, +const struct xt_action_param *par,const struct ip_set_adt_opt *opt) {struct ip_set *set = ip_set_list[index];
@@ -341,14 +343,14 @@ ip_set_test(ip_set_id_t index, const struct sk_buff *skb,return 0 ;read_lock_bh (&set->lock); - ret = set->variant->kadt (set, skb,IPSET_TEST , opt); + ret = set->variant->kadt (set, skb, par,IPSET_TEST , opt);read_unlock_bh (&set->lock);if (ret == -EAGAIN ) {/* Type requests element to be completed */ pr_debug ("element must be competed, ADD is triggered\n" );write_lock_bh (&set->lock); - set->variant->kadt (set, skb,IPSET_ADD , opt); + set->variant->kadt (set, skb, par,IPSET_ADD , opt);write_unlock_bh (&set->lock); ret =1 ; }
@@ -360,6 +362,7 @@ EXPORT_SYMBOL_GPL(ip_set_test);int ip_set_add (ip_set_id_t index,const struct sk_buff *skb, +const struct xt_action_param *par,const struct ip_set_adt_opt *opt) {struct ip_set *set = ip_set_list[index];
@@ -373,7 +376,7 @@ ip_set_add(ip_set_id_t index, const struct sk_buff *skb,return 0 ;write_lock_bh (&set->lock); - ret = set->variant->kadt (set, skb,IPSET_ADD , opt); + ret = set->variant->kadt (set, skb, par,IPSET_ADD , opt);write_unlock_bh (&set->lock);return ret;
@@ -382,6 +385,7 @@ EXPORT_SYMBOL_GPL(ip_set_add);int ip_set_del (ip_set_id_t index,const struct sk_buff *skb, +const struct xt_action_param *par,const struct ip_set_adt_opt *opt) {struct ip_set *set = ip_set_list[index];
@@ -395,7 +399,7 @@ ip_set_del(ip_set_id_t index, const struct sk_buff *skb,return 0 ;write_lock_bh (&set->lock); - ret = set->variant->kadt (set, skb,IPSET_DEL , opt); + ret = set->variant->kadt (set, skb, par,IPSET_DEL , opt);write_unlock_bh (&set->lock);return ret;
net/netfilter/ipset/ip_set_hash_ip.c +2 -0
@@ -116,6 +116,7 @@ hash_ip4_data_next(struct ip_set_hash *h, const struct hash_ip4_elem *d)static int hash_ip4_kadt (struct ip_set *set,const struct sk_buff *skb, +const struct xt_action_param *par,enum ipset_adt adt,const struct ip_set_adt_opt *opt) {const struct ip_set_hash *h = set->data;
@@ -295,6 +296,7 @@ hash_ip6_data_next(struct ip_set_hash *h, const struct hash_ip6_elem *d)static int hash_ip6_kadt (struct ip_set *set,const struct sk_buff *skb, +const struct xt_action_param *par,enum ipset_adt adt,const struct ip_set_adt_opt *opt) {const struct ip_set_hash *h = set->data;
net/netfilter/ipset/ip_set_hash_ipport.c +2 -0
@@ -134,6 +134,7 @@ hash_ipport4_data_next(struct ip_set_hash *h,static int hash_ipport4_kadt (struct ip_set *set,const struct sk_buff *skb, +const struct xt_action_param *par,enum ipset_adt adt,const struct ip_set_adt_opt *opt) {const struct ip_set_hash *h = set->data;
@@ -348,6 +349,7 @@ hash_ipport6_data_next(struct ip_set_hash *h,static int hash_ipport6_kadt (struct ip_set *set,const struct sk_buff *skb, +const struct xt_action_param *par,enum ipset_adt adt,const struct ip_set_adt_opt *opt) {const struct ip_set_hash *h = set->data;
net/netfilter/ipset/ip_set_hash_ipportip.c +2 -0
@@ -137,6 +137,7 @@ hash_ipportip4_data_next(struct ip_set_hash *h,static int hash_ipportip4_kadt (struct ip_set *set,const struct sk_buff *skb, +const struct xt_action_param *par,enum ipset_adt adt,const struct ip_set_adt_opt *opt) {const struct ip_set_hash *h = set->data;
@@ -361,6 +362,7 @@ hash_ipportip6_data_next(struct ip_set_hash *h,static int hash_ipportip6_kadt (struct ip_set *set,const struct sk_buff *skb, +const struct xt_action_param *par,enum ipset_adt adt,const struct ip_set_adt_opt *opt) {const struct ip_set_hash *h = set->data;
net/netfilter/ipset/ip_set_hash_ipportnet.c +2 -0
@@ -151,6 +151,7 @@ hash_ipportnet4_data_next(struct ip_set_hash *h,static int hash_ipportnet4_kadt (struct ip_set *set,const struct sk_buff *skb, +const struct xt_action_param *par,enum ipset_adt adt,const struct ip_set_adt_opt *opt) {const struct ip_set_hash *h = set->data;
@@ -428,6 +429,7 @@ hash_ipportnet6_data_next(struct ip_set_hash *h,static int hash_ipportnet6_kadt (struct ip_set *set,const struct sk_buff *skb, +const struct xt_action_param *par,enum ipset_adt adt,const struct ip_set_adt_opt *opt) {const struct ip_set_hash *h = set->data;
net/netfilter/ipset/ip_set_hash_net.c +2 -0
@@ -134,6 +134,7 @@ hash_net4_data_next(struct ip_set_hash *h,static int hash_net4_kadt (struct ip_set *set,const struct sk_buff *skb, +const struct xt_action_param *par,enum ipset_adt adt,const struct ip_set_adt_opt *opt) {const struct ip_set_hash *h = set->data;
@@ -330,6 +331,7 @@ hash_net6_data_next(struct ip_set_hash *h,static int hash_net6_kadt (struct ip_set *set,const struct sk_buff *skb, +const struct xt_action_param *par,enum ipset_adt adt,const struct ip_set_adt_opt *opt) {const struct ip_set_hash *h = set->data;
net/netfilter/ipset/ip_set_hash_netport.c +2 -0
@@ -147,6 +147,7 @@ hash_netport4_data_next(struct ip_set_hash *h,static int hash_netport4_kadt (struct ip_set *set,const struct sk_buff *skb, +const struct xt_action_param *par,enum ipset_adt adt,const struct ip_set_adt_opt *opt) {const struct ip_set_hash *h = set->data;
@@ -390,6 +391,7 @@ hash_netport6_data_next(struct ip_set_hash *h,static int hash_netport6_kadt (struct ip_set *set,const struct sk_buff *skb, +const struct xt_action_param *par,enum ipset_adt adt,const struct ip_set_adt_opt *opt) {const struct ip_set_hash *h = set->data;
net/netfilter/ipset/ip_set_list_set.c +4 -3
@@ -72,6 +72,7 @@ list_set_expired(const struct list_set *map, u32 id)static int list_set_kadt (struct ip_set *set,const struct sk_buff *skb, +const struct xt_action_param *par,enum ipset_adt adt,const struct ip_set_adt_opt *opt) {struct list_set *map = set->data;
@@ -87,17 +88,17 @@ list_set_kadt(struct ip_set *set, const struct sk_buff *skb,continue ;switch (adt) {case IPSET_TEST : - ret =ip_set_test (elem->id, skb, opt); + ret =ip_set_test (elem->id, skb, par, opt);if (ret >0 )return ret;break ;case IPSET_ADD : - ret =ip_set_add (elem->id, skb, opt); + ret =ip_set_add (elem->id, skb, par, opt);if (ret ==0 )return ret;break ;case IPSET_DEL : - ret =ip_set_del (elem->id, skb, opt); + ret =ip_set_del (elem->id, skb, par, opt);if (ret ==0 )return ret;break ;
net/netfilter/xt_set.c +10 -9
@@ -29,9 +29,10 @@ MODULE_ALIAS("ip6t_SET");static inline int match_set (ip_set_id_t index,const struct sk_buff *skb, +const struct xt_action_param *par,const struct ip_set_adt_opt *opt,int inv) { -if (ip_set_test (index, skb, opt)) +if (ip_set_test (index, skb, par, opt)) inv = !inv;return inv; }
@@ -54,7 +55,7 @@ set_match_v0(const struct sk_buff *skb, struct xt_action_param *par)ADT_OPT (opt, par->family, info->match_set.u.compat.dim, info->match_set.u.compat.flags,0 ,UINT_MAX ); -return match_set (info->match_set.index, skb, &opt, +return match_set (info->match_set.index, skb, par, &opt, info->match_set.u.compat.flags &IPSET_INV_MATCH ); }
@@ -118,9 +119,9 @@ set_target_v0(struct sk_buff *skb, const struct xt_action_param *par) info->del_set.u.compat.flags, 0, UINT_MAX);if (info->add_set.index !=IPSET_INVALID_ID ) -ip_set_add (info->add_set.index, skb, &add_opt); +ip_set_add (info->add_set.index, skb, par, &add_opt);if (info->del_set.index !=IPSET_INVALID_ID ) -ip_set_del (info->del_set.index, skb, &del_opt); +ip_set_del (info->del_set.index, skb, par, &del_opt);return XT_CONTINUE ; }
@@ -188,7 +189,7 @@ set_match_v1(const struct sk_buff *skb, struct xt_action_param *par)ADT_OPT (opt, par->family, info->match_set.dim, info->match_set.flags,0 ,UINT_MAX ); -return match_set (info->match_set.index, skb, &opt, +return match_set (info->match_set.index, skb, par, &opt, info->match_set.flags &IPSET_INV_MATCH ); }
@@ -233,9 +234,9 @@ set_target_v1(struct sk_buff *skb, const struct xt_action_param *par) info->del_set.flags, 0, UINT_MAX);if (info->add_set.index !=IPSET_INVALID_ID ) -ip_set_add (info->add_set.index, skb, &add_opt); +ip_set_add (info->add_set.index, skb, par, &add_opt);if (info->del_set.index !=IPSET_INVALID_ID ) -ip_set_del (info->del_set.index, skb, &del_opt); +ip_set_del (info->del_set.index, skb, par, &del_opt);return XT_CONTINUE ; }
@@ -302,9 +303,9 @@ set_target_v2(struct sk_buff *skb, const struct xt_action_param *par) info->del_set.flags, 0, UINT_MAX);if (info->add_set.index !=IPSET_INVALID_ID ) -ip_set_add (info->add_set.index, skb, &add_opt); +ip_set_add (info->add_set.index, skb, par, &add_opt);if (info->del_set.index !=IPSET_INVALID_ID ) -ip_set_del (info->del_set.index, skb, &del_opt); +ip_set_del (info->del_set.index, skb, par, &del_opt);return XT_CONTINUE ; }
Signature · 1 line
1.7.2.5
[email protected]
maintainerPATCH 11/20 netfilter: ipset: Fix return code for destroy when sets are in use
In reply to [email protected]From: Jozsef Kadlecsik <[email protected]>
--- net/netfilter/ipset/ip_set_core.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
net/netfilter/ipset/ip_set_core.c +1 -1
@@ -776,7 +776,7 @@ ip_set_destroy(struct sock *ctnl, struct sk_buff *skb,if (!attr[IPSET_ATTR_SETNAME ]) {for (i =0 ; i < ip_set_max; i++) {if (ip_set_list[i] !=NULL && ip_set_list[i]->ref) { - ret =IPSET_ERR_BUSY ; + ret = -IPSET_ERR_BUSY ; goto out; } }
Signature · 1 line
1.7.2.5
[email protected]
maintainerPATCH 12/20 netfilter: ipset: Use the stored first cidr value instead of '1'
In reply to [email protected]From: Jozsef Kadlecsik <[email protected]>
The stored cidr values are tried one after anoter. The boolean condition evaluated to '1' instead of the first stored cidr or the default host cidr.
--- net/netfilter/ipset/ip_set_hash_ipportnet.c | 10 ++++++---- net/netfilter/ipset/ip_set_hash_net.c | 8 ++++++-- net/netfilter/ipset/ip_set_hash_netport.c | 6 ++++-- 3 files changed, 16 insertions(+), 8 deletions(-)
net/netfilter/ipset/ip_set_hash_ipportnet.c +6 -4
@@ -156,8 +156,9 @@ hash_ipportnet4_kadt(struct ip_set *set, const struct sk_buff *skb, {const struct ip_set_hash *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt]; -struct hash_ipportnet4_elem data = - { .cidr = h->nets[0 ].cidr ||HOST_MASK }; +struct hash_ipportnet4_elem data = { + .cidr = h->nets[0 ].cidr ? h->nets[0 ].cidr :HOST_MASK + };if (data.cidr ==0 )return -EINVAL ;
@@ -434,8 +435,9 @@ hash_ipportnet6_kadt(struct ip_set *set, const struct sk_buff *skb, {const struct ip_set_hash *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt]; -struct hash_ipportnet6_elem data = - { .cidr = h->nets[0 ].cidr ||HOST_MASK }; +struct hash_ipportnet6_elem data = { + .cidr = h->nets[0 ].cidr ? h->nets[0 ].cidr :HOST_MASK + };if (data.cidr ==0 )return -EINVAL ;
net/netfilter/ipset/ip_set_hash_net.c +6 -2
@@ -139,7 +139,9 @@ hash_net4_kadt(struct ip_set *set, const struct sk_buff *skb, {const struct ip_set_hash *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt]; -struct hash_net4_elem data = { .cidr = h->nets[0 ].cidr ||HOST_MASK }; +struct hash_net4_elem data = { + .cidr = h->nets[0 ].cidr ? h->nets[0 ].cidr :HOST_MASK + };if (data.cidr ==0 )return -EINVAL ;
@@ -336,7 +338,9 @@ hash_net6_kadt(struct ip_set *set, const struct sk_buff *skb, {const struct ip_set_hash *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt]; -struct hash_net6_elem data = { .cidr = h->nets[0 ].cidr ||HOST_MASK }; +struct hash_net6_elem data = { + .cidr = h->nets[0 ].cidr ? h->nets[0 ].cidr :HOST_MASK + };if (data.cidr ==0 )return -EINVAL ;
net/netfilter/ipset/ip_set_hash_netport.c +4 -2
@@ -153,7 +153,8 @@ hash_netport4_kadt(struct ip_set *set, const struct sk_buff *skb,const struct ip_set_hash *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt];struct hash_netport4_elem data = { - .cidr = h->nets[0 ].cidr ||HOST_MASK }; + .cidr = h->nets[0 ].cidr ? h->nets[0 ].cidr :HOST_MASK + };if (data.cidr ==0 )return -EINVAL ;
@@ -397,7 +398,8 @@ hash_netport6_kadt(struct ip_set *set, const struct sk_buff *skb,const struct ip_set_hash *h = set->data;ipset_adtfn adtfn = set->variant->adt[adt];struct hash_netport6_elem data = { - .cidr = h->nets[0 ].cidr ||HOST_MASK }; + .cidr = h->nets[0 ].cidr ? h->nets[0 ].cidr :HOST_MASK + };if (data.cidr ==0 )return -EINVAL ;
Signature · 1 line
1.7.2.5
[email protected]
maintainerPATCH 13/20 netfilter: ipset: hash:net,iface type introduced
In reply to [email protected]From: Jozsef Kadlecsik <[email protected]>
The hash:net,iface type makes possible to store network address and interface name pairs in a set. It's mostly suitable for egress and ingress filtering. Examples:
# ipset create test hash:net,iface
# ipset add test 192.168.0.0/16,eth0
# ipset add test 192.168.0.0/24,eth1--- include/linux/netfilter/ipset/ip_set.h | 5 + include/linux/netfilter/ipset/ip_set_ahash.h | 6 + net/netfilter/ipset/Kconfig | 10 + net/netfilter/ipset/Makefile | 1 + net/netfilter/ipset/ip_set_hash_netiface.c | 762 ++++++++++++++++++++++++++ 5 files changed, 784 insertions(+), 0 deletions(-) create mode 100644 net/netfilter/ipset/ip_set_hash_netiface.c
include/linux/netfilter/ipset/ip_set.h +5 -0
@@ -105,6 +105,7 @@ enum {IPSET_ATTR_IP2 ,IPSET_ATTR_CIDR2 ,IPSET_ATTR_IP2_TO , +IPSET_ATTR_IFACE , __IPSET_ATTR_ADT_MAX, };#define IPSET_ATTR_ADT_MAX (__IPSET_ATTR_ADT_MAX - 1)
@@ -153,6 +154,8 @@ enum ipset_cmd_flags {enum ipset_cadt_flags {IPSET_FLAG_BIT_BEFORE =0 ,IPSET_FLAG_BEFORE = (1 <<IPSET_FLAG_BIT_BEFORE ), +IPSET_FLAG_BIT_PHYSDEV =1 , +IPSET_FLAG_PHYSDEV = (1 <<IPSET_FLAG_BIT_PHYSDEV ), };/* Commands with settype-specific attributes */
@@ -212,6 +215,8 @@ enum ip_set_feature {IPSET_TYPE_IP2 = (1 <<IPSET_TYPE_IP2_FLAG ),IPSET_TYPE_NAME_FLAG =4 ,IPSET_TYPE_NAME = (1 <<IPSET_TYPE_NAME_FLAG ), +IPSET_TYPE_IFACE_FLAG =5 , +IPSET_TYPE_IFACE = (1 <<IPSET_TYPE_IFACE_FLAG ),/* Strictly speaking not a feature, but a flag for dumping: * this settype must be dumped last */ IPSET_DUMP_LAST_FLAG = 7,
include/linux/netfilter/ipset/ip_set_ahash.h +6 -0
@@ -63,6 +63,9 @@ struct ip_set_hash {#ifdef IP_SET_HASH_WITH_NETMASK u8 netmask;/* netmask value for subnets to store */ #endif +#ifdef IP_SET_HASH_WITH_RBTREE +struct rb_root rbtree; +#endif #ifdef IP_SET_HASH_WITH_NETS struct ip_set_hash_nets nets[0 ];/* book-keeping of prefixes */ #endif
@@ -200,6 +203,9 @@ ip_set_hash_destroy(struct ip_set *set)del_timer_sync (&h->gc);ahash_destroy (h->table); +#ifdef IP_SET_HASH_WITH_RBTREE +rbtree_destroy (&h->rbtree); +#endif kfree (h); set->data =NULL ;
net/netfilter/ipset/Kconfig +10 -0
@@ -109,6 +109,16 @@ config IP_SET_HASH_NETPORT To compile it as a module, choose M here. If unsure, say N. +config IP_SET_HASH_NETIFACE + tristate "hash:net,iface set support" + depends on IP_SET + help + This option adds the hash:net,iface set type support, by which + one can store IPv4/IPv6 network address/prefix and + inteface name pairs as elements in a set. + + To compile it as a module, choose M here. If unsure, say N. + config IP_SET_LIST_SET tristate "list:set set support" depends on IP_SET
net/netfilter/ipset/Makefile +1 -0
@@ -19,6 +19,7 @@ obj-$(CONFIG_IP_SET_HASH_IPPORTIP) += ip_set_hash_ipportip.o obj-$(CONFIG_IP_SET_HASH_IPPORTNET) += ip_set_hash_ipportnet.o obj-$(CONFIG_IP_SET_HASH_NET) += ip_set_hash_net.o obj-$(CONFIG_IP_SET_HASH_NETPORT) += ip_set_hash_netport.o +obj-$(CONFIG_IP_SET_HASH_NETIFACE) += ip_set_hash_netiface.o # list types obj-$(CONFIG_IP_SET_LIST_SET) += ip_set_list_set.o
net/netfilter/ipset/ip_set_hash_netiface.c new file +762 -0
762 lines not on this page · raw message
Signature · 1 line
1.7.2.5
[email protected]
maintainerPATCH 14/20 netfilter: ipset: Whitespace and coding fixes, detected by checkpatch.pl
In reply to [email protected]From: Jozsef Kadlecsik <[email protected]>
I added a call to checkpatch.pl into the pre-commit hook of my git tree in order to prevent whitespace errors in the future.
--- include/linux/netfilter/ipset/ip_set.h | 6 +++--- include/linux/netfilter/ipset/ip_set_ahash.h | 2 +- include/linux/netfilter/ipset/pfxlen.h | 2 +- net/netfilter/ipset/ip_set_bitmap_ipmac.c | 3 ++- net/netfilter/ipset/ip_set_core.c | 4 ++-- net/netfilter/ipset/ip_set_hash_net.c | 4 ++-- net/netfilter/ipset/ip_set_hash_netiface.c | 26 +++++++++++++------------- net/netfilter/ipset/ip_set_hash_netport.c | 2 +- net/netfilter/ipset/pfxlen.c | 2 +- net/netfilter/xt_set.c | 2 +- 10 files changed, 27 insertions(+), 26 deletions(-)
include/linux/netfilter/ipset/ip_set.h +3 -3
@@ -331,7 +331,7 @@ struct ip_set {/* register and unregister set references */ extern ip_set_id_t ip_set_get_byname (const char *name,struct ip_set **set);extern void ip_set_put_byindex (ip_set_id_t index); -extern const char *ip_set_name_byindex (ip_set_id_t index); +extern const char *ip_set_name_byindex (ip_set_id_t index);extern ip_set_id_t ip_set_nfnl_get (const char *name);extern ip_set_id_t ip_set_nfnl_get_byindex (ip_set_id_t index);extern void ip_set_nfnl_put (ip_set_id_t index);
@@ -349,7 +349,7 @@ extern int ip_set_test(ip_set_id_t id, const struct sk_buff *skb, const struct ip_set_adt_opt *opt);/* Utility functions */ -extern void *ip_set_alloc (size_t size); +extern void *ip_set_alloc (size_t size);extern void ip_set_free (void *members);extern int ip_set_get_ipaddr4 (struct nlattr *nla,__be32 *ipaddr);extern int ip_set_get_ipaddr6 (struct nlattr *nla,union nf_inet_addr *ipaddr);
@@ -359,7 +359,7 @@ ip_set_get_hostipaddr4(struct nlattr *nla, u32 *ipaddr) {__be32 ip;int ret =ip_set_get_ipaddr4 (nla, &ip); - +if (ret)return ret; *ipaddr =ntohl (ip);
include/linux/netfilter/ipset/ip_set_ahash.h +1 -1
@@ -43,7 +43,7 @@ struct htable {struct hbucket bucket[0 ];/* hashtable buckets */ }; -#define hbucket (h, i) &((h)->bucket[i]) +#define hbucket (h, i) (&((h)->bucket[i]))/* Book-keeping of the prefixes added to the set */ struct ip_set_hash_nets {
include/linux/netfilter/ipset/pfxlen.h +1 -1
@@ -2,7 +2,7 @@#define _PFXLEN_H#include <asm/byteorder.h> -#include <linux/netfilter.h> +#include <linux/netfilter.h> #include <net/tcp.h> /* Prefixlen maps, by Jan Engelhardt */
net/netfilter/ipset/ip_set_bitmap_ipmac.c +2 -1
@@ -635,7 +635,8 @@ static struct ip_set_type bitmap_ipmac_type = { }, .adt_policy = { [IPSET_ATTR_IP] = { .type = NLA_NESTED }, - [IPSET_ATTR_ETHER] = { .type = NLA_BINARY, .len = ETH_ALEN }, + [IPSET_ATTR_ETHER] = { .type = NLA_BINARY, + .len = ETH_ALEN }, [IPSET_ATTR_TIMEOUT] = { .type = NLA_U32 }, [IPSET_ATTR_LINENO] = { .type = NLA_U32 }, },
net/netfilter/ipset/ip_set_core.c +2 -2
@@ -683,8 +683,8 @@ ip_set_create(struct sock *ctnl, struct sk_buff *skb,if (attr[IPSET_ATTR_DATA ] &&nla_parse_nested (tb,IPSET_ATTR_CREATE_MAX , attr[IPSET_ATTR_DATA ], set->type->create_policy)) { - ret = -IPSET_ERR_PROTOCOL ; - goto put_out; + ret = -IPSET_ERR_PROTOCOL ; + goto put_out; } ret = set->type->create (set, tb, flags);
net/netfilter/ipset/ip_set_hash_net.c +2 -2
@@ -187,7 +187,7 @@ hash_net4_uadt(struct ip_set *set, struct nlattr *tb[],return -IPSET_ERR_TIMEOUT ; timeout =ip_set_timeout_uget (tb[IPSET_ATTR_TIMEOUT ]); } - +if (adt ==IPSET_TEST || !tb[IPSET_ATTR_IP_TO ]) { data.ip =htonl (ip &ip_set_hostmask (data.cidr)); ret =adtfn (set, &data, timeout, flags);
@@ -205,7 +205,7 @@ hash_net4_uadt(struct ip_set *set, struct nlattr *tb[],return -IPSET_ERR_HASH_RANGE ; }if (retried) - ip = h->next.ip; + ip = h->next.ip;while (!after (ip, ip_to)) { data.ip =htonl (ip); last =ip_set_range_to_cidr (ip, ip_to, &data.cidr);
net/netfilter/ipset/ip_set_hash_netiface.c +13 -13
@@ -100,7 +100,7 @@ iface_test(struct rb_root *root, const char **iface)while (n) {const char *d =iface_data (n);int res =ifname_compare (*iface, d); - +if (res <0 ) n = n->rb_left;else if (res >0 )
@@ -118,7 +118,7 @@ iface_add(struct rb_root *root, const char **iface) {struct rb_node **n = &(root->rb_node), *p =NULL ;struct iface_node *d; - +while (*n) {char *ifname =iface_data (*n);int res =ifname_compare (*iface, ifname);
@@ -296,10 +296,10 @@ hash_netiface4_kadt(struct ip_set *set, const struct sk_buff *skb,if (opt->cmdflags &IPSET_FLAG_PHYSDEV ) {#ifdef CONFIG_BRIDGE_NETFILTER const struct nf_bridge_info *nf_bridge = skb->nf_bridge; - +if (!nf_bridge)return -EINVAL ; - data.iface =SRCDIR ?PHYSDEV (physindev):PHYSDEV (physoutdev); + data.iface =SRCDIR ?PHYSDEV (physindev) :PHYSDEV (physoutdev); data.physdev =1 ;#else data.iface =NULL ;
@@ -350,7 +350,7 @@ hash_netiface4_uadt(struct ip_set *set, struct nlattr *tb[],if (tb[IPSET_ATTR_CIDR ]) { data.cidr =nla_get_u8 (tb[IPSET_ATTR_CIDR ]);if (!data.cidr) -return -IPSET_ERR_INVALID_CIDR ; +return -IPSET_ERR_INVALID_CIDR ; }if (tb[IPSET_ATTR_TIMEOUT ]) {
@@ -359,7 +359,7 @@ hash_netiface4_uadt(struct ip_set *set, struct nlattr *tb[], timeout =ip_set_timeout_uget (tb[IPSET_ATTR_TIMEOUT ]); } -strcpy (iface,nla_data (tb[IPSET_ATTR_IFACE ])); +strcpy (iface,nla_data (tb[IPSET_ATTR_IFACE ])); data.iface = iface; ret =iface_test (&h->rbtree, &data.iface);if (adt ==IPSET_ADD ) {
@@ -372,8 +372,8 @@ hash_netiface4_uadt(struct ip_set *set, struct nlattr *tb[],return ret;if (tb[IPSET_ATTR_CADT_FLAGS ]) { -u32 flags =ip_set_get_h32 (tb[IPSET_ATTR_CADT_FLAGS ]); -if (flags &IPSET_FLAG_PHYSDEV ) +u32 cadt_flags =ip_set_get_h32 (tb[IPSET_ATTR_CADT_FLAGS ]); +if (cadt_flags &IPSET_FLAG_PHYSDEV ) data.physdev =1 ; }
@@ -559,10 +559,10 @@ hash_netiface6_kadt(struct ip_set *set, const struct sk_buff *skb,if (opt->cmdflags &IPSET_FLAG_PHYSDEV ) {#ifdef CONFIG_BRIDGE_NETFILTER const struct nf_bridge_info *nf_bridge = skb->nf_bridge; - +if (!nf_bridge)return -EINVAL ; - data.iface =SRCDIR ?PHYSDEV (physindev):PHYSDEV (physoutdev); + data.iface =SRCDIR ?PHYSDEV (physindev) :PHYSDEV (physoutdev); data.physdev =1 ;#else data.iface =NULL ;
@@ -623,7 +623,7 @@ hash_netiface6_uadt(struct ip_set *set, struct nlattr *tb[], timeout =ip_set_timeout_uget (tb[IPSET_ATTR_TIMEOUT ]); } -strcpy (iface,nla_data (tb[IPSET_ATTR_IFACE ])); +strcpy (iface,nla_data (tb[IPSET_ATTR_IFACE ])); data.iface = iface; ret =iface_test (&h->rbtree, &data.iface);if (adt ==IPSET_ADD ) {
@@ -636,8 +636,8 @@ hash_netiface6_uadt(struct ip_set *set, struct nlattr *tb[],return ret;if (tb[IPSET_ATTR_CADT_FLAGS ]) { -u32 flags =ip_set_get_h32 (tb[IPSET_ATTR_CADT_FLAGS ]); -if (flags &IPSET_FLAG_PHYSDEV ) +u32 cadt_flags =ip_set_get_h32 (tb[IPSET_ATTR_CADT_FLAGS ]); +if (cadt_flags &IPSET_FLAG_PHYSDEV ) data.physdev =1 ; }
net/netfilter/ipset/ip_set_hash_netport.c +1 -1
@@ -199,7 +199,7 @@ hash_netport4_uadt(struct ip_set *set, struct nlattr *tb[],if (tb[IPSET_ATTR_CIDR ]) { data.cidr =nla_get_u8 (tb[IPSET_ATTR_CIDR ]);if (!data.cidr) -return -IPSET_ERR_INVALID_CIDR ; +return -IPSET_ERR_INVALID_CIDR ; }if (tb[IPSET_ATTR_PORT ])
net/netfilter/ipset/pfxlen.c +1 -1
@@ -148,7 +148,7 @@ const union nf_inet_addr ip_set_netmask_map[] = {EXPORT_SYMBOL_GPL (ip_set_netmask_map);#undef E -#define E (a, b, c, d) \ +#define E (a, b, c, d) \ {.ip6 = { (__force __be32) a, (__force __be32) b, \ (__force __be32) c, (__force __be32) d, \ } }
net/netfilter/xt_set.c +1 -1
@@ -37,7 +37,7 @@ match_set(ip_set_id_t index, const struct sk_buff *skb,return inv; } -#define ADT_OPT (n, f, d, fs, cfs, t) \ +#define ADT_OPT (n, f, d, fs, cfs, t) \ const struct ip_set_adt_opt n = { \ .family = f, \ .dim = d, \
Signature · 1 line
1.7.2.5
[email protected]
maintainerPATCH 15/20 ipvs: Avoid undefined order of evaluation in assignments to struct nf_conn *
In reply to [email protected]From: Jesper Juhl <[email protected]>
In net/netfilter/ipvs/ip_vs_nfct.c::ip_vs_update_conntrack(), net/netfilter/ipvs/ip_vs_xmit.c::ip_vs_nat_xmit(), net/netfilter/ipvs/ip_vs_xmit.c::ip_vs_nat_xmit_v6(), net/netfilter/ipvs/ip_vs_xmit.c::ip_vs_icmp_xmit)() net/netfilter/ipvs/ip_vs_xmit.c::and ip_vs_icmp_xmit_v6() we do this:
... struct nf_conn *ct = ct = nf_ct_get(skb, &ctinfo); ...
Since '=' is not a sequence point the order of these assignments happening is undefined. Luckily it's easy to avoid by just doing what is obviously the intended thing:
struct nf_conn *ct = nf_ct_get(skb, &ctinfo);
--- net/netfilter/ipvs/ip_vs_nfct.c | 2 +- net/netfilter/ipvs/ip_vs_xmit.c | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-)
net/netfilter/ipvs/ip_vs_nfct.c +1 -1
@@ -82,7 +82,7 @@ void ip_vs_update_conntrack(struct sk_buff *skb, struct ip_vs_conn *cp, int outin) { enum ip_conntrack_info ctinfo; -struct nf_conn *ct = ct =nf_ct_get (skb, &ctinfo); +struct nf_conn *ct =nf_ct_get (skb, &ctinfo);struct nf_conntrack_tuple new_tuple; if (ct == NULL || nf_ct_is_confirmed(ct) || nf_ct_is_untracked(ct) ||
net/netfilter/ipvs/ip_vs_xmit.c +4 -4
@@ -544,7 +544,7 @@ ip_vs_nat_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,#if defined(CONFIG_NF_CONNTRACK ) || defined(CONFIG_NF_CONNTRACK_MODULE )if (cp->flags &IP_VS_CONN_F_SYNC && local) {enum ip_conntrack_info ctinfo; -struct nf_conn *ct = ct =nf_ct_get (skb, &ctinfo); +struct nf_conn *ct =nf_ct_get (skb, &ctinfo);if (ct && !nf_ct_is_untracked (ct)) { IP_VS_DBG_RL_PKT(10, AF_INET, pp, skb, 0,
@@ -661,7 +661,7 @@ ip_vs_nat_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,#if defined(CONFIG_NF_CONNTRACK ) || defined(CONFIG_NF_CONNTRACK_MODULE )if (cp->flags &IP_VS_CONN_F_SYNC && local) {enum ip_conntrack_info ctinfo; -struct nf_conn *ct = ct =nf_ct_get (skb, &ctinfo); +struct nf_conn *ct =nf_ct_get (skb, &ctinfo);if (ct && !nf_ct_is_untracked (ct)) { IP_VS_DBG_RL_PKT(10, AF_INET6, pp, skb, 0,
@@ -1176,7 +1176,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,#if defined(CONFIG_NF_CONNTRACK ) || defined(CONFIG_NF_CONNTRACK_MODULE )if (cp->flags &IP_VS_CONN_F_SYNC && local) {enum ip_conntrack_info ctinfo; -struct nf_conn *ct = ct =nf_ct_get (skb, &ctinfo); +struct nf_conn *ct =nf_ct_get (skb, &ctinfo);if (ct && !nf_ct_is_untracked (ct)) { IP_VS_DBG(10, "%s(): "
@@ -1296,7 +1296,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,#if defined(CONFIG_NF_CONNTRACK ) || defined(CONFIG_NF_CONNTRACK_MODULE )if (cp->flags &IP_VS_CONN_F_SYNC && local) {enum ip_conntrack_info ctinfo; -struct nf_conn *ct = ct =nf_ct_get (skb, &ctinfo); +struct nf_conn *ct =nf_ct_get (skb, &ctinfo);if (ct && !nf_ct_is_untracked (ct)) { IP_VS_DBG(10, "%s(): "
Signature · 1 line
1.7.2.5
[email protected]
maintainerPATCH 16/20 netfilter: nf_conntrack: remove one synchronize_net()
In reply to [email protected]From: Eric Dumazet <[email protected]>
No point to wait a rcu grace period before the unregisters.
--- net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c | 1 - 1 files changed, 0 insertions(+), 1 deletions(-)
net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c +0 -1
@@ -435,7 +435,6 @@ static int __init nf_conntrack_l3proto_ipv4_init(void) static void __exit nf_conntrack_l3proto_ipv4_fini(void) { -synchronize_net ();#if defined(CONFIG_PROC_FS ) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT )nf_conntrack_ipv4_compat_fini ();#endif
Signature · 1 line
1.7.2.5
[email protected]
maintainerPATCH 17/20 netfilter: nf_nat: fix crash in nf_nat_csum
In reply to [email protected]From: Julian Anastasov <[email protected]>
Fix crash in nf_nat_csum when mangling packets
in OUTPUT hook where skb->dev is not defined, it is set later before POSTROUTING. Problem happens for CHECKSUM_NONE. We can check device from rt but using CHECKSUM_PARTIAL should be safe (skb_checksum_help).
--- net/ipv4/netfilter/nf_nat_helper.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
net/ipv4/netfilter/nf_nat_helper.c +1 -1
@@ -160,7 +160,7 @@ static void nf_nat_csum(struct sk_buff *skb, const struct iphdr *iph, void *dataif (skb->ip_summed !=CHECKSUM_PARTIAL ) {if (!(rt->rt_flags &RTCF_LOCAL ) && - skb->dev->features &NETIF_F_V4_CSUM ) { + (!skb->dev || skb->dev->features &NETIF_F_V4_CSUM )) { skb->ip_summed =CHECKSUM_PARTIAL ; skb->csum_start =skb_headroom (skb) + skb_network_offset(skb) +
Signature · 1 line
1.7.2.5
[email protected]
maintainerPATCH 18/20 netfilter: nf_conntrack: fix ct refcount leak in l4proto->error()
In reply to [email protected]From: Pablo Neira Ayuso <[email protected]>
This patch fixes a refcount leak of ct objects that may occur if l4proto->error() assigns one conntrack object to one skbuff. In that case, we have to skip further processing in nf_conntrack_in().
With this patch, we can also fix wrong return values (-NF_ACCEPT) for special cases in ICMP[v6] that should not bump the invalid/error statistic counters.
--- net/ipv4/netfilter/nf_conntrack_proto_icmp.c | 2 +- net/ipv6/netfilter/nf_conntrack_proto_icmpv6.c | 2 +- net/netfilter/nf_conntrack_core.c | 3 +++ 3 files changed, 5 insertions(+), 2 deletions(-)
net/ipv4/netfilter/nf_conntrack_proto_icmp.c +1 -1
@@ -160,7 +160,7 @@ icmp_error_message(struct net *net, struct nf_conn *tmpl, struct sk_buff *skb,/* Update skb to refer to this connection */ skb->nfct = &nf_ct_tuplehash_to_ctrack (h)->ct_general; skb->nfctinfo = *ctinfo; -return -NF_ACCEPT ; +return NF_ACCEPT ; }/* Small and modified version of icmp_rcv */
net/ipv6/netfilter/nf_conntrack_proto_icmpv6.c +1 -1
@@ -177,7 +177,7 @@ icmpv6_error_message(struct net *net, struct nf_conn *tmpl,/* Update skb to refer to this connection */ skb->nfct = &nf_ct_tuplehash_to_ctrack (h)->ct_general; skb->nfctinfo = *ctinfo; -return -NF_ACCEPT ; +return NF_ACCEPT ; } static int
net/netfilter/nf_conntrack_core.c +3 -0
@@ -922,6 +922,9 @@ nf_conntrack_in(struct net *net, u_int8_t pf, unsigned int hooknum, ret = -ret; goto out; } +/* ICMP[v6] protocol trackers may assign one conntrack. */ +if (skb->nfct) + goto out; } ct = resolve_normal_ct(net, tmpl, skb, dataoff, pf, protonum,
Signature · 1 line
1.7.2.5
[email protected]
maintainerPATCH 19/20 netfilter: use unsigned variables for packet lengths in ip[6]_queue.
In reply to [email protected]From: Dave Jones <[email protected]>
Netlink message lengths can't be negative, so use unsigned variables.
--- net/ipv4/netfilter/ip_queue.c | 3 ++- net/ipv6/netfilter/ip6_queue.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-)
net/ipv4/netfilter/ip_queue.c +2 -1
@@ -402,7 +402,8 @@ ipq_dev_drop(int ifindex)static inline void __ipq_rcv_skb (struct sk_buff *skb) { -int status, type, pid, flags, nlmsglen, skblen; +int status, type, pid, flags; +unsigned int nlmsglen, skblen;struct nlmsghdr *nlh; skblen = skb->len;
net/ipv6/netfilter/ip6_queue.c +2 -1
@@ -403,7 +403,8 @@ ipq_dev_drop(int ifindex)static inline void __ipq_rcv_skb (struct sk_buff *skb) { -int status, type, pid, flags, nlmsglen, skblen; +int status, type, pid, flags; +unsigned int nlmsglen, skblen;struct nlmsghdr *nlh; skblen = skb->len;
Signature · 1 line
1.7.2.5
[email protected]
maintainerPATCH 20/20 netfilter: nf_conntrack: provide config option to disable ancient procfs parts
In reply to [email protected]From: Jan Engelhardt <[email protected]>
This option enables for the list of known conntrack entries to be shown in procfs under net/netfilter/nf_conntrack. This is considered obsolete in favor of using the conntrack(8) tool which uses Netlink.
--- net/ipv4/netfilter/Kconfig | 2 +- net/netfilter/Kconfig | 10 ++++++++++ net/netfilter/nf_conntrack_expect.c | 12 ++++++------ net/netfilter/nf_conntrack_standalone.c | 4 ++-- 4 files changed, 19 insertions(+), 9 deletions(-)
net/ipv4/netfilter/Kconfig +1 -1
@@ -27,7 +27,7 @@ config NF_CONNTRACK_IPV4 config NF_CONNTRACK_PROC_COMPAT bool "proc/sysctl compatibility with old connection tracking" - depends on NF_CONNTRACK_IPV4 + depends on NF_CONNTRACK_PROCFS && NF_CONNTRACK_IPV4 default y help This option enables /proc and sysctl compatibility with the old
net/netfilter/Kconfig +10 -0
@@ -75,6 +75,16 @@ config NF_CONNTRACK_ZONES If unsure, say `N'. +config NF_CONNTRACK_PROCFS + bool "Supply CT list in procfs (OBSOLETE)" + default y + depends on PROC_FS + ---help--- + This option enables for the list of known conntrack entries + to be shown in procfs under net/netfilter/nf_conntrack. This + is considered obsolete in favor of using the conntrack(8) + tool which uses Netlink. + config NF_CONNTRACK_EVENTS bool "Connection tracking events" depends on NETFILTER_ADVANCED
net/netfilter/nf_conntrack_expect.c +6 -6
@@ -474,7 +474,7 @@ void nf_ct_remove_userspace_expectations(void) }EXPORT_SYMBOL_GPL (nf_ct_remove_userspace_expectations); -#ifdef CONFIG_PROC_FS +#ifdef CONFIG_NF_CONNTRACK_PROCFS struct ct_expect_iter_state { struct seq_net_private p; unsigned int bucket;
@@ -602,25 +602,25 @@ static const struct file_operations exp_file_ops = { .llseek = seq_lseek, .release = seq_release_net, }; -#endif /* CONFIG_PROC_FS */ +#endif /* CONFIG_NF_CONNTRACK_PROCFS */ static int exp_proc_init (struct net *net) { -#ifdef CONFIG_PROC_FS +#ifdef CONFIG_NF_CONNTRACK_PROCFS struct proc_dir_entry *proc; proc =proc_net_fops_create (net,"nf_conntrack_expect" ,0440 , &exp_file_ops);if (!proc)return -ENOMEM ; -#endif /* CONFIG_PROC_FS */ +#endif /* CONFIG_NF_CONNTRACK_PROCFS */ return 0 ; }static void exp_proc_remove (struct net *net) { -#ifdef CONFIG_PROC_FS +#ifdef CONFIG_NF_CONNTRACK_PROCFS proc_net_remove (net,"nf_conntrack_expect" ); -#endif /* CONFIG_PROC_FS */ +#endif /* CONFIG_NF_CONNTRACK_PROCFS */ }module_param_named (expect_hashsize, nf_ct_expect_hsize, uint,0400 );
net/netfilter/nf_conntrack_standalone.c +2 -2
@@ -34,7 +34,7 @@MODULE_LICENSE ("GPL" ); -#ifdef CONFIG_PROC_FS +#ifdef CONFIG_NF_CONNTRACK_PROCFS int print_tuple(struct seq_file *s, const struct nf_conntrack_tuple *tuple, const struct nf_conntrack_l3proto *l3proto,
@@ -396,7 +396,7 @@ static int nf_conntrack_standalone_init_proc(struct net *net)static void nf_conntrack_standalone_fini_proc (struct net *net) { } -#endif /* CONFIG_PROC_FS */ +#endif /* CONFIG_NF_CONNTRACK_PROCFS */ /* Sysctl support */
Signature · 1 line
1.7.2.5
David Miller
maintainerFrom: [email protected]
Date: Mon, 6 Jun 2011 01:08:51 +0200
Quoted 2 lines
the following patches contain Netfilter updates for 3.0.0-rc1 The highlights are:
Are these bug fixes only or do we have new features in here?
If new features, then this stuff should be targeted for 3.1 (ie. net-next-2.6) not 3.0.0-rc1
Pablo Neira Ayuso
maintainerQuoted 10 lines · David Miller
From: [email protected]
Date: Mon, 6 Jun 2011 01:08:51 +0200Quoted 2 lines
the following patches contain Netfilter updates for 3.0.0-rc1 The highlights are:
Are these bug fixes only or do we have new features in here?
If new features, then this stuff should be targeted for 3.1 (ie. net-next-2.6) not 3.0.0-rc1
There are a couple of new features in this batch, sorry.
I'll remake this batch to only include fixes for 3.0.0-rc1 only.
BTW, when does 3.1 (net-next-2.6) becomes closed for new features?
David Miller
maintainerFrom: Pablo Neira Ayuso <[email protected]>
Date: Mon, 06 Jun 2011 01:23:46 +0200
Quoted 1 line
I'll remake this batch to only include fixes for 3.0.0-rc1 only.
Thanks.
Quoted 1 line
BTW, when does 3.1 (net-next-2.6) becomes closed for new features?
When Linus releases 3.0-final and opens up the merge window.