Commit 72c39a0a authored by David S. Miller's avatar David S. Miller

Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next

Pablo Neira Ayuso says:

====================
This is another batch containing Netfilter/IPVS updates for your net-next
tree, they are:

* Six patches to make the ipt_CLUSTERIP target support netnamespace,
  from Gao feng.

* Two cleanups for the nf_conntrack_acct infrastructure, introducing
  a new structure to encapsulate conntrack counters, from Holger
  Eitzenberger.

* Fix missing verdict in SCTP support for IPVS, from Daniel Borkmann.

* Skip checksum recalculation in SCTP support for IPVS, also from
  Daniel Borkmann.

* Fix behavioural change in xt_socket after IP early demux, from
  Florian Westphal.

* Fix bogus large memory allocation in the bitmap port set type in ipset,
  from Jozsef Kadlecsik.

* Fix possible compilation issues in the hash netnet set type in ipset,
  also from Jozsef Kadlecsik.

* Define constants to identify netlink callback data in ipset dumps,
  again from Jozsef Kadlecsik.

* Use sock_gen_put() in xt_socket to replace xt_socket_put_sk,
  from Eric Dumazet.

* Improvements for the SH scheduler in IPVS, from Alexander Frolkin.

* Remove extra delay due to unneeded rcu barrier in IPVS net namespace
  cleanup path, from Julian Anastasov.

* Save some cycles in ip6t_REJECT by skipping checksum validation in
  packets leaving from our stack, from Stanislav Fomichev.

* Fix IPVS_CMD_ATTR_MAX definition in IPVS, larger that required, from
  Julian Anastasov.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 6fcf018a 4542fa47
...@@ -316,6 +316,16 @@ ip_set_init_counter(struct ip_set_counter *counter, ...@@ -316,6 +316,16 @@ ip_set_init_counter(struct ip_set_counter *counter,
atomic64_set(&(counter)->packets, (long long)(ext->packets)); atomic64_set(&(counter)->packets, (long long)(ext->packets));
} }
/* Netlink CB args */
enum {
IPSET_CB_NET = 0,
IPSET_CB_DUMP,
IPSET_CB_INDEX,
IPSET_CB_ARG0,
IPSET_CB_ARG1,
IPSET_CB_ARG2,
};
/* register and unregister set references */ /* register and unregister set references */
extern ip_set_id_t ip_set_get_byname(struct net *net, extern ip_set_id_t ip_set_get_byname(struct net *net,
const char *name, struct ip_set **set); const char *name, struct ip_set **set);
......
...@@ -1442,6 +1442,12 @@ static inline void ip_vs_dest_put(struct ip_vs_dest *dest) ...@@ -1442,6 +1442,12 @@ static inline void ip_vs_dest_put(struct ip_vs_dest *dest)
atomic_dec(&dest->refcnt); atomic_dec(&dest->refcnt);
} }
static inline void ip_vs_dest_put_and_free(struct ip_vs_dest *dest)
{
if (atomic_dec_return(&dest->refcnt) < 0)
kfree(dest);
}
/* /*
* IPVS sync daemon data and function prototypes * IPVS sync daemon data and function prototypes
* (from ip_vs_sync.c) * (from ip_vs_sync.c)
......
...@@ -19,17 +19,21 @@ struct nf_conn_counter { ...@@ -19,17 +19,21 @@ struct nf_conn_counter {
atomic64_t bytes; atomic64_t bytes;
}; };
struct nf_conn_acct {
struct nf_conn_counter counter[IP_CT_DIR_MAX];
};
static inline static inline
struct nf_conn_counter *nf_conn_acct_find(const struct nf_conn *ct) struct nf_conn_acct *nf_conn_acct_find(const struct nf_conn *ct)
{ {
return nf_ct_ext_find(ct, NF_CT_EXT_ACCT); return nf_ct_ext_find(ct, NF_CT_EXT_ACCT);
} }
static inline static inline
struct nf_conn_counter *nf_ct_acct_ext_add(struct nf_conn *ct, gfp_t gfp) struct nf_conn_acct *nf_ct_acct_ext_add(struct nf_conn *ct, gfp_t gfp)
{ {
struct net *net = nf_ct_net(ct); struct net *net = nf_ct_net(ct);
struct nf_conn_counter *acct; struct nf_conn_acct *acct;
if (!net->ct.sysctl_acct) if (!net->ct.sysctl_acct)
return NULL; return NULL;
......
...@@ -36,7 +36,7 @@ enum nf_ct_ext_id { ...@@ -36,7 +36,7 @@ enum nf_ct_ext_id {
#define NF_CT_EXT_HELPER_TYPE struct nf_conn_help #define NF_CT_EXT_HELPER_TYPE struct nf_conn_help
#define NF_CT_EXT_NAT_TYPE struct nf_conn_nat #define NF_CT_EXT_NAT_TYPE struct nf_conn_nat
#define NF_CT_EXT_SEQADJ_TYPE struct nf_conn_seqadj #define NF_CT_EXT_SEQADJ_TYPE struct nf_conn_seqadj
#define NF_CT_EXT_ACCT_TYPE struct nf_conn_counter #define NF_CT_EXT_ACCT_TYPE struct nf_conn_acct
#define NF_CT_EXT_ECACHE_TYPE struct nf_conntrack_ecache #define NF_CT_EXT_ECACHE_TYPE struct nf_conntrack_ecache
#define NF_CT_EXT_ZONE_TYPE struct nf_conntrack_zone #define NF_CT_EXT_ZONE_TYPE struct nf_conntrack_zone
#define NF_CT_EXT_TSTAMP_TYPE struct nf_conn_tstamp #define NF_CT_EXT_TSTAMP_TYPE struct nf_conn_tstamp
......
...@@ -334,7 +334,7 @@ enum { ...@@ -334,7 +334,7 @@ enum {
__IPVS_CMD_ATTR_MAX, __IPVS_CMD_ATTR_MAX,
}; };
#define IPVS_CMD_ATTR_MAX (__IPVS_SVC_ATTR_MAX - 1) #define IPVS_CMD_ATTR_MAX (__IPVS_CMD_ATTR_MAX - 1)
/* /*
* Attributes used to describe a service * Attributes used to describe a service
......
...@@ -559,6 +559,8 @@ static struct net_device *setup_pre_routing(struct sk_buff *skb) ...@@ -559,6 +559,8 @@ static struct net_device *setup_pre_routing(struct sk_buff *skb)
else if (skb->protocol == htons(ETH_P_PPP_SES)) else if (skb->protocol == htons(ETH_P_PPP_SES))
nf_bridge->mask |= BRNF_PPPoE; nf_bridge->mask |= BRNF_PPPoE;
/* Must drop socket now because of tproxy. */
skb_orphan(skb);
return skb->dev; return skb->dev;
} }
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include <linux/netfilter_ipv4/ipt_CLUSTERIP.h> #include <linux/netfilter_ipv4/ipt_CLUSTERIP.h>
#include <net/netfilter/nf_conntrack.h> #include <net/netfilter/nf_conntrack.h>
#include <net/net_namespace.h> #include <net/net_namespace.h>
#include <net/netns/generic.h>
#include <net/checksum.h> #include <net/checksum.h>
#include <net/ip.h> #include <net/ip.h>
...@@ -57,15 +58,21 @@ struct clusterip_config { ...@@ -57,15 +58,21 @@ struct clusterip_config {
struct rcu_head rcu; struct rcu_head rcu;
}; };
static LIST_HEAD(clusterip_configs); #ifdef CONFIG_PROC_FS
static const struct file_operations clusterip_proc_fops;
#endif
/* clusterip_lock protects the clusterip_configs list */ static int clusterip_net_id __read_mostly;
static DEFINE_SPINLOCK(clusterip_lock);
struct clusterip_net {
struct list_head configs;
/* lock protects the configs list */
spinlock_t lock;
#ifdef CONFIG_PROC_FS #ifdef CONFIG_PROC_FS
static const struct file_operations clusterip_proc_fops; struct proc_dir_entry *procdir;
static struct proc_dir_entry *clusterip_procdir;
#endif #endif
};
static inline void static inline void
clusterip_config_get(struct clusterip_config *c) clusterip_config_get(struct clusterip_config *c)
...@@ -92,10 +99,13 @@ clusterip_config_put(struct clusterip_config *c) ...@@ -92,10 +99,13 @@ clusterip_config_put(struct clusterip_config *c)
static inline void static inline void
clusterip_config_entry_put(struct clusterip_config *c) clusterip_config_entry_put(struct clusterip_config *c)
{ {
struct net *net = dev_net(c->dev);
struct clusterip_net *cn = net_generic(net, clusterip_net_id);
local_bh_disable(); local_bh_disable();
if (atomic_dec_and_lock(&c->entries, &clusterip_lock)) { if (atomic_dec_and_lock(&c->entries, &cn->lock)) {
list_del_rcu(&c->list); list_del_rcu(&c->list);
spin_unlock(&clusterip_lock); spin_unlock(&cn->lock);
local_bh_enable(); local_bh_enable();
dev_mc_del(c->dev, c->clustermac); dev_mc_del(c->dev, c->clustermac);
...@@ -113,11 +123,12 @@ clusterip_config_entry_put(struct clusterip_config *c) ...@@ -113,11 +123,12 @@ clusterip_config_entry_put(struct clusterip_config *c)
} }
static struct clusterip_config * static struct clusterip_config *
__clusterip_config_find(__be32 clusterip) __clusterip_config_find(struct net *net, __be32 clusterip)
{ {
struct clusterip_config *c; struct clusterip_config *c;
struct clusterip_net *cn = net_generic(net, clusterip_net_id);
list_for_each_entry_rcu(c, &clusterip_configs, list) { list_for_each_entry_rcu(c, &cn->configs, list) {
if (c->clusterip == clusterip) if (c->clusterip == clusterip)
return c; return c;
} }
...@@ -126,12 +137,12 @@ __clusterip_config_find(__be32 clusterip) ...@@ -126,12 +137,12 @@ __clusterip_config_find(__be32 clusterip)
} }
static inline struct clusterip_config * static inline struct clusterip_config *
clusterip_config_find_get(__be32 clusterip, int entry) clusterip_config_find_get(struct net *net, __be32 clusterip, int entry)
{ {
struct clusterip_config *c; struct clusterip_config *c;
rcu_read_lock_bh(); rcu_read_lock_bh();
c = __clusterip_config_find(clusterip); c = __clusterip_config_find(net, clusterip);
if (c) { if (c) {
if (unlikely(!atomic_inc_not_zero(&c->refcount))) if (unlikely(!atomic_inc_not_zero(&c->refcount)))
c = NULL; c = NULL;
...@@ -158,6 +169,7 @@ clusterip_config_init(const struct ipt_clusterip_tgt_info *i, __be32 ip, ...@@ -158,6 +169,7 @@ clusterip_config_init(const struct ipt_clusterip_tgt_info *i, __be32 ip,
struct net_device *dev) struct net_device *dev)
{ {
struct clusterip_config *c; struct clusterip_config *c;
struct clusterip_net *cn = net_generic(dev_net(dev), clusterip_net_id);
c = kzalloc(sizeof(*c), GFP_ATOMIC); c = kzalloc(sizeof(*c), GFP_ATOMIC);
if (!c) if (!c)
...@@ -180,7 +192,7 @@ clusterip_config_init(const struct ipt_clusterip_tgt_info *i, __be32 ip, ...@@ -180,7 +192,7 @@ clusterip_config_init(const struct ipt_clusterip_tgt_info *i, __be32 ip,
/* create proc dir entry */ /* create proc dir entry */
sprintf(buffer, "%pI4", &ip); sprintf(buffer, "%pI4", &ip);
c->pde = proc_create_data(buffer, S_IWUSR|S_IRUSR, c->pde = proc_create_data(buffer, S_IWUSR|S_IRUSR,
clusterip_procdir, cn->procdir,
&clusterip_proc_fops, c); &clusterip_proc_fops, c);
if (!c->pde) { if (!c->pde) {
kfree(c); kfree(c);
...@@ -189,9 +201,9 @@ clusterip_config_init(const struct ipt_clusterip_tgt_info *i, __be32 ip, ...@@ -189,9 +201,9 @@ clusterip_config_init(const struct ipt_clusterip_tgt_info *i, __be32 ip,
} }
#endif #endif
spin_lock_bh(&clusterip_lock); spin_lock_bh(&cn->lock);
list_add_rcu(&c->list, &clusterip_configs); list_add_rcu(&c->list, &cn->configs);
spin_unlock_bh(&clusterip_lock); spin_unlock_bh(&cn->lock);
return c; return c;
} }
...@@ -370,7 +382,7 @@ static int clusterip_tg_check(const struct xt_tgchk_param *par) ...@@ -370,7 +382,7 @@ static int clusterip_tg_check(const struct xt_tgchk_param *par)
/* FIXME: further sanity checks */ /* FIXME: further sanity checks */
config = clusterip_config_find_get(e->ip.dst.s_addr, 1); config = clusterip_config_find_get(par->net, e->ip.dst.s_addr, 1);
if (!config) { if (!config) {
if (!(cipinfo->flags & CLUSTERIP_FLAG_NEW)) { if (!(cipinfo->flags & CLUSTERIP_FLAG_NEW)) {
pr_info("no config found for %pI4, need 'new'\n", pr_info("no config found for %pI4, need 'new'\n",
...@@ -384,7 +396,7 @@ static int clusterip_tg_check(const struct xt_tgchk_param *par) ...@@ -384,7 +396,7 @@ static int clusterip_tg_check(const struct xt_tgchk_param *par)
return -EINVAL; return -EINVAL;
} }
dev = dev_get_by_name(&init_net, e->ip.iniface); dev = dev_get_by_name(par->net, e->ip.iniface);
if (!dev) { if (!dev) {
pr_info("no such interface %s\n", pr_info("no such interface %s\n",
e->ip.iniface); e->ip.iniface);
...@@ -492,6 +504,7 @@ arp_mangle(const struct nf_hook_ops *ops, ...@@ -492,6 +504,7 @@ arp_mangle(const struct nf_hook_ops *ops,
struct arphdr *arp = arp_hdr(skb); struct arphdr *arp = arp_hdr(skb);
struct arp_payload *payload; struct arp_payload *payload;
struct clusterip_config *c; struct clusterip_config *c;
struct net *net = dev_net(in ? in : out);
/* we don't care about non-ethernet and non-ipv4 ARP */ /* we don't care about non-ethernet and non-ipv4 ARP */
if (arp->ar_hrd != htons(ARPHRD_ETHER) || if (arp->ar_hrd != htons(ARPHRD_ETHER) ||
...@@ -508,7 +521,7 @@ arp_mangle(const struct nf_hook_ops *ops, ...@@ -508,7 +521,7 @@ arp_mangle(const struct nf_hook_ops *ops,
/* if there is no clusterip configuration for the arp reply's /* if there is no clusterip configuration for the arp reply's
* source ip, we don't want to mangle it */ * source ip, we don't want to mangle it */
c = clusterip_config_find_get(payload->src_ip, 0); c = clusterip_config_find_get(net, payload->src_ip, 0);
if (!c) if (!c)
return NF_ACCEPT; return NF_ACCEPT;
...@@ -698,48 +711,75 @@ static const struct file_operations clusterip_proc_fops = { ...@@ -698,48 +711,75 @@ static const struct file_operations clusterip_proc_fops = {
#endif /* CONFIG_PROC_FS */ #endif /* CONFIG_PROC_FS */
static int clusterip_net_init(struct net *net)
{
struct clusterip_net *cn = net_generic(net, clusterip_net_id);
INIT_LIST_HEAD(&cn->configs);
spin_lock_init(&cn->lock);
#ifdef CONFIG_PROC_FS
cn->procdir = proc_mkdir("ipt_CLUSTERIP", net->proc_net);
if (!cn->procdir) {
pr_err("Unable to proc dir entry\n");
return -ENOMEM;
}
#endif /* CONFIG_PROC_FS */
return 0;
}
static void clusterip_net_exit(struct net *net)
{
#ifdef CONFIG_PROC_FS
struct clusterip_net *cn = net_generic(net, clusterip_net_id);
proc_remove(cn->procdir);
#endif
}
static struct pernet_operations clusterip_net_ops = {
.init = clusterip_net_init,
.exit = clusterip_net_exit,
.id = &clusterip_net_id,
.size = sizeof(struct clusterip_net),
};
static int __init clusterip_tg_init(void) static int __init clusterip_tg_init(void)
{ {
int ret; int ret;
ret = xt_register_target(&clusterip_tg_reg); ret = register_pernet_subsys(&clusterip_net_ops);
if (ret < 0) if (ret < 0)
return ret; return ret;
ret = xt_register_target(&clusterip_tg_reg);
if (ret < 0)
goto cleanup_subsys;
ret = nf_register_hook(&cip_arp_ops); ret = nf_register_hook(&cip_arp_ops);
if (ret < 0) if (ret < 0)
goto cleanup_target; goto cleanup_target;
#ifdef CONFIG_PROC_FS
clusterip_procdir = proc_mkdir("ipt_CLUSTERIP", init_net.proc_net);
if (!clusterip_procdir) {
pr_err("Unable to proc dir entry\n");
ret = -ENOMEM;
goto cleanup_hook;
}
#endif /* CONFIG_PROC_FS */
pr_info("ClusterIP Version %s loaded successfully\n", pr_info("ClusterIP Version %s loaded successfully\n",
CLUSTERIP_VERSION); CLUSTERIP_VERSION);
return 0; return 0;
#ifdef CONFIG_PROC_FS
cleanup_hook:
nf_unregister_hook(&cip_arp_ops);
#endif /* CONFIG_PROC_FS */
cleanup_target: cleanup_target:
xt_unregister_target(&clusterip_tg_reg); xt_unregister_target(&clusterip_tg_reg);
cleanup_subsys:
unregister_pernet_subsys(&clusterip_net_ops);
return ret; return ret;
} }
static void __exit clusterip_tg_exit(void) static void __exit clusterip_tg_exit(void)
{ {
pr_info("ClusterIP Version %s unloading\n", CLUSTERIP_VERSION); pr_info("ClusterIP Version %s unloading\n", CLUSTERIP_VERSION);
#ifdef CONFIG_PROC_FS
proc_remove(clusterip_procdir);
#endif
nf_unregister_hook(&cip_arp_ops); nf_unregister_hook(&cip_arp_ops);
xt_unregister_target(&clusterip_tg_reg); xt_unregister_target(&clusterip_tg_reg);
unregister_pernet_subsys(&clusterip_net_ops);
/* Wait for completion of call_rcu_bh()'s (clusterip_config_rcu_free) */ /* Wait for completion of call_rcu_bh()'s (clusterip_config_rcu_free) */
rcu_barrier_bh(); rcu_barrier_bh();
......
...@@ -39,7 +39,7 @@ MODULE_DESCRIPTION("Xtables: packet \"rejection\" target for IPv6"); ...@@ -39,7 +39,7 @@ MODULE_DESCRIPTION("Xtables: packet \"rejection\" target for IPv6");
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
/* Send RST reply */ /* Send RST reply */
static void send_reset(struct net *net, struct sk_buff *oldskb) static void send_reset(struct net *net, struct sk_buff *oldskb, int hook)
{ {
struct sk_buff *nskb; struct sk_buff *nskb;
struct tcphdr otcph, *tcph; struct tcphdr otcph, *tcph;
...@@ -88,8 +88,7 @@ static void send_reset(struct net *net, struct sk_buff *oldskb) ...@@ -88,8 +88,7 @@ static void send_reset(struct net *net, struct sk_buff *oldskb)
} }
/* Check checksum. */ /* Check checksum. */
if (csum_ipv6_magic(&oip6h->saddr, &oip6h->daddr, otcplen, IPPROTO_TCP, if (nf_ip6_checksum(oldskb, hook, tcphoff, IPPROTO_TCP)) {
skb_checksum(oldskb, tcphoff, otcplen, 0))) {
pr_debug("TCP checksum is invalid\n"); pr_debug("TCP checksum is invalid\n");
return; return;
} }
...@@ -227,7 +226,7 @@ reject_tg6(struct sk_buff *skb, const struct xt_action_param *par) ...@@ -227,7 +226,7 @@ reject_tg6(struct sk_buff *skb, const struct xt_action_param *par)
/* Do nothing */ /* Do nothing */
break; break;
case IP6T_TCP_RESET: case IP6T_TCP_RESET:
send_reset(net, skb); send_reset(net, skb, par->hooknum);
break; break;
default: default:
net_info_ratelimited("case %u not handled yet\n", reject->with); net_info_ratelimited("case %u not handled yet\n", reject->with);
......
...@@ -198,13 +198,14 @@ mtype_list(const struct ip_set *set, ...@@ -198,13 +198,14 @@ mtype_list(const struct ip_set *set,
struct mtype *map = set->data; struct mtype *map = set->data;
struct nlattr *adt, *nested; struct nlattr *adt, *nested;
void *x; void *x;
u32 id, first = cb->args[2]; u32 id, first = cb->args[IPSET_CB_ARG0];
adt = ipset_nest_start(skb, IPSET_ATTR_ADT); adt = ipset_nest_start(skb, IPSET_ATTR_ADT);
if (!adt) if (!adt)
return -EMSGSIZE; return -EMSGSIZE;
for (; cb->args[2] < map->elements; cb->args[2]++) { for (; cb->args[IPSET_CB_ARG0] < map->elements;
id = cb->args[2]; cb->args[IPSET_CB_ARG0]++) {
id = cb->args[IPSET_CB_ARG0];
x = get_ext(set, map, id); x = get_ext(set, map, id);
if (!test_bit(id, map->members) || if (!test_bit(id, map->members) ||
(SET_WITH_TIMEOUT(set) && (SET_WITH_TIMEOUT(set) &&
...@@ -231,14 +232,14 @@ mtype_list(const struct ip_set *set, ...@@ -231,14 +232,14 @@ mtype_list(const struct ip_set *set,
ipset_nest_end(skb, adt); ipset_nest_end(skb, adt);
/* Set listing finished */ /* Set listing finished */
cb->args[2] = 0; cb->args[IPSET_CB_ARG0] = 0;
return 0; return 0;
nla_put_failure: nla_put_failure:
nla_nest_cancel(skb, nested); nla_nest_cancel(skb, nested);
if (unlikely(id == first)) { if (unlikely(id == first)) {
cb->args[2] = 0; cb->args[IPSET_CB_ARG0] = 0;
return -EMSGSIZE; return -EMSGSIZE;
} }
ipset_nest_end(skb, adt); ipset_nest_end(skb, adt);
......
...@@ -254,7 +254,7 @@ bitmap_port_create(struct net *net, struct ip_set *set, struct nlattr *tb[], ...@@ -254,7 +254,7 @@ bitmap_port_create(struct net *net, struct ip_set *set, struct nlattr *tb[],
return -ENOMEM; return -ENOMEM;
map->elements = last_port - first_port + 1; map->elements = last_port - first_port + 1;
map->memsize = map->elements * sizeof(unsigned long); map->memsize = bitmap_bytes(0, map->elements);
set->variant = &bitmap_port; set->variant = &bitmap_port;
set->dsize = ip_set_elem_len(set, tb, 0); set->dsize = ip_set_elem_len(set, tb, 0);
if (!init_map_port(set, map, first_port, last_port)) { if (!init_map_port(set, map, first_port, last_port)) {
......
...@@ -1182,10 +1182,12 @@ ip_set_swap(struct sock *ctnl, struct sk_buff *skb, ...@@ -1182,10 +1182,12 @@ ip_set_swap(struct sock *ctnl, struct sk_buff *skb,
static int static int
ip_set_dump_done(struct netlink_callback *cb) ip_set_dump_done(struct netlink_callback *cb)
{ {
struct ip_set_net *inst = (struct ip_set_net *)cb->data; struct ip_set_net *inst = (struct ip_set_net *)cb->args[IPSET_CB_NET];
if (cb->args[2]) { if (cb->args[IPSET_CB_ARG0]) {
pr_debug("release set %s\n", nfnl_set(inst, cb->args[1])->name); pr_debug("release set %s\n",
__ip_set_put_byindex(inst, (ip_set_id_t) cb->args[1]); nfnl_set(inst, cb->args[IPSET_CB_INDEX])->name);
__ip_set_put_byindex(inst,
(ip_set_id_t) cb->args[IPSET_CB_INDEX]);
} }
return 0; return 0;
} }
...@@ -1203,7 +1205,7 @@ dump_attrs(struct nlmsghdr *nlh) ...@@ -1203,7 +1205,7 @@ dump_attrs(struct nlmsghdr *nlh)
} }
static int static int
dump_init(struct netlink_callback *cb) dump_init(struct netlink_callback *cb, struct ip_set_net *inst)
{ {
struct nlmsghdr *nlh = nlmsg_hdr(cb->skb); struct nlmsghdr *nlh = nlmsg_hdr(cb->skb);
int min_len = nlmsg_total_size(sizeof(struct nfgenmsg)); int min_len = nlmsg_total_size(sizeof(struct nfgenmsg));
...@@ -1211,15 +1213,15 @@ dump_init(struct netlink_callback *cb) ...@@ -1211,15 +1213,15 @@ dump_init(struct netlink_callback *cb)
struct nlattr *attr = (void *)nlh + min_len; struct nlattr *attr = (void *)nlh + min_len;
u32 dump_type; u32 dump_type;
ip_set_id_t index; ip_set_id_t index;
struct ip_set_net *inst = (struct ip_set_net *)cb->data;
/* Second pass, so parser can't fail */ /* Second pass, so parser can't fail */
nla_parse(cda, IPSET_ATTR_CMD_MAX, nla_parse(cda, IPSET_ATTR_CMD_MAX,
attr, nlh->nlmsg_len - min_len, ip_set_setname_policy); attr, nlh->nlmsg_len - min_len, ip_set_setname_policy);
/* cb->args[0] : dump single set/all sets /* cb->args[IPSET_CB_NET]: net namespace
* [1] : set index * [IPSET_CB_DUMP]: dump single set/all sets
* [..]: type specific * [IPSET_CB_INDEX]: set index
* [IPSET_CB_ARG0]: type specific
*/ */
if (cda[IPSET_ATTR_SETNAME]) { if (cda[IPSET_ATTR_SETNAME]) {
...@@ -1231,7 +1233,7 @@ dump_init(struct netlink_callback *cb) ...@@ -1231,7 +1233,7 @@ dump_init(struct netlink_callback *cb)
return -ENOENT; return -ENOENT;
dump_type = DUMP_ONE; dump_type = DUMP_ONE;
cb->args[1] = index; cb->args[IPSET_CB_INDEX] = index;
} else } else
dump_type = DUMP_ALL; dump_type = DUMP_ALL;
...@@ -1239,7 +1241,8 @@ dump_init(struct netlink_callback *cb) ...@@ -1239,7 +1241,8 @@ dump_init(struct netlink_callback *cb)
u32 f = ip_set_get_h32(cda[IPSET_ATTR_FLAGS]); u32 f = ip_set_get_h32(cda[IPSET_ATTR_FLAGS]);
dump_type |= (f << 16); dump_type |= (f << 16);
} }
cb->args[0] = dump_type; cb->args[IPSET_CB_NET] = (unsigned long)inst;
cb->args[IPSET_CB_DUMP] = dump_type;
return 0; return 0;
} }
...@@ -1251,12 +1254,12 @@ ip_set_dump_start(struct sk_buff *skb, struct netlink_callback *cb) ...@@ -1251,12 +1254,12 @@ ip_set_dump_start(struct sk_buff *skb, struct netlink_callback *cb)
struct ip_set *set = NULL; struct ip_set *set = NULL;
struct nlmsghdr *nlh = NULL; struct nlmsghdr *nlh = NULL;
unsigned int flags = NETLINK_CB(cb->skb).portid ? NLM_F_MULTI : 0; unsigned int flags = NETLINK_CB(cb->skb).portid ? NLM_F_MULTI : 0;
struct ip_set_net *inst = ip_set_pernet(sock_net(skb->sk));
u32 dump_type, dump_flags; u32 dump_type, dump_flags;
int ret = 0; int ret = 0;
struct ip_set_net *inst = (struct ip_set_net *)cb->data;
if (!cb->args[0]) { if (!cb->args[IPSET_CB_DUMP]) {
ret = dump_init(cb); ret = dump_init(cb, inst);
if (ret < 0) { if (ret < 0) {
nlh = nlmsg_hdr(cb->skb); nlh = nlmsg_hdr(cb->skb);
/* We have to create and send the error message /* We have to create and send the error message
...@@ -1267,17 +1270,18 @@ ip_set_dump_start(struct sk_buff *skb, struct netlink_callback *cb) ...@@ -1267,17 +1270,18 @@ ip_set_dump_start(struct sk_buff *skb, struct netlink_callback *cb)
} }
} }
if (cb->args[1] >= inst->ip_set_max) if (cb->args[IPSET_CB_INDEX] >= inst->ip_set_max)
goto out; goto out;
dump_type = DUMP_TYPE(cb->args[0]); dump_type = DUMP_TYPE(cb->args[IPSET_CB_DUMP]);
dump_flags = DUMP_FLAGS(cb->args[0]); dump_flags = DUMP_FLAGS(cb->args[IPSET_CB_DUMP]);
max = dump_type == DUMP_ONE ? cb->args[1] + 1 : inst->ip_set_max; max = dump_type == DUMP_ONE ? cb->args[IPSET_CB_INDEX] + 1
: inst->ip_set_max;
dump_last: dump_last:
pr_debug("args[0]: %u %u args[1]: %ld\n", pr_debug("dump type, flag: %u %u index: %ld\n",
dump_type, dump_flags, cb->args[1]); dump_type, dump_flags, cb->args[IPSET_CB_INDEX]);
for (; cb->args[1] < max; cb->args[1]++) { for (; cb->args[IPSET_CB_INDEX] < max; cb->args[IPSET_CB_INDEX]++) {
index = (ip_set_id_t) cb->args[1]; index = (ip_set_id_t) cb->args[IPSET_CB_INDEX];
set = nfnl_set(inst, index); set = nfnl_set(inst, index);
if (set == NULL) { if (set == NULL) {
if (dump_type == DUMP_ONE) { if (dump_type == DUMP_ONE) {
...@@ -1294,7 +1298,7 @@ ip_set_dump_start(struct sk_buff *skb, struct netlink_callback *cb) ...@@ -1294,7 +1298,7 @@ ip_set_dump_start(struct sk_buff *skb, struct netlink_callback *cb)
!!(set->type->features & IPSET_DUMP_LAST))) !!(set->type->features & IPSET_DUMP_LAST)))
continue; continue;
pr_debug("List set: %s\n", set->name); pr_debug("List set: %s\n", set->name);
if (!cb->args[2]) { if (!cb->args[IPSET_CB_ARG0]) {
/* Start listing: make sure set won't be destroyed */ /* Start listing: make sure set won't be destroyed */
pr_debug("reference set\n"); pr_debug("reference set\n");
__ip_set_get(set); __ip_set_get(set);
...@@ -1311,7 +1315,7 @@ ip_set_dump_start(struct sk_buff *skb, struct netlink_callback *cb) ...@@ -1311,7 +1315,7 @@ ip_set_dump_start(struct sk_buff *skb, struct netlink_callback *cb)
goto nla_put_failure; goto nla_put_failure;
if (dump_flags & IPSET_FLAG_LIST_SETNAME) if (dump_flags & IPSET_FLAG_LIST_SETNAME)
goto next_set; goto next_set;
switch (cb->args[2]) { switch (cb->args[IPSET_CB_ARG0]) {
case 0: case 0:
/* Core header data */ /* Core header data */
if (nla_put_string(skb, IPSET_ATTR_TYPENAME, if (nla_put_string(skb, IPSET_ATTR_TYPENAME,
...@@ -1331,7 +1335,7 @@ ip_set_dump_start(struct sk_buff *skb, struct netlink_callback *cb) ...@@ -1331,7 +1335,7 @@ ip_set_dump_start(struct sk_buff *skb, struct netlink_callback *cb)
read_lock_bh(&set->lock); read_lock_bh(&set->lock);
ret = set->variant->list(set, skb, cb); ret = set->variant->list(set, skb, cb);
read_unlock_bh(&set->lock); read_unlock_bh(&set->lock);
if (!cb->args[2]) if (!cb->args[IPSET_CB_ARG0])
/* Set is done, proceed with next one */ /* Set is done, proceed with next one */
goto next_set; goto next_set;
goto release_refcount; goto release_refcount;
...@@ -1340,8 +1344,8 @@ ip_set_dump_start(struct sk_buff *skb, struct netlink_callback *cb) ...@@ -1340,8 +1344,8 @@ ip_set_dump_start(struct sk_buff *skb, struct netlink_callback *cb)
/* If we dump all sets, continue with dumping last ones */ /* If we dump all sets, continue with dumping last ones */
if (dump_type == DUMP_ALL) { if (dump_type == DUMP_ALL) {
dump_type = DUMP_LAST; dump_type = DUMP_LAST;
cb->args[0] = dump_type | (dump_flags << 16); cb->args[IPSET_CB_DUMP] = dump_type | (dump_flags << 16);
cb->args[1] = 0; cb->args[IPSET_CB_INDEX] = 0;
goto dump_last; goto dump_last;
} }
goto out; goto out;
...@@ -1350,15 +1354,15 @@ ip_set_dump_start(struct sk_buff *skb, struct netlink_callback *cb) ...@@ -1350,15 +1354,15 @@ ip_set_dump_start(struct sk_buff *skb, struct netlink_callback *cb)
ret = -EFAULT; ret = -EFAULT;
next_set: next_set:
if (dump_type == DUMP_ONE) if (dump_type == DUMP_ONE)
cb->args[1] = IPSET_INVALID_ID; cb->args[IPSET_CB_INDEX] = IPSET_INVALID_ID;
else else
cb->args[1]++; cb->args[IPSET_CB_INDEX]++;
release_refcount: release_refcount:
/* If there was an error or set is done, release set */ /* If there was an error or set is done, release set */
if (ret || !cb->args[2]) { if (ret || !cb->args[IPSET_CB_ARG0]) {
pr_debug("release set %s\n", nfnl_set(inst, index)->name); pr_debug("release set %s\n", nfnl_set(inst, index)->name);
__ip_set_put_byindex(inst, index); __ip_set_put_byindex(inst, index);
cb->args[2] = 0; cb->args[IPSET_CB_ARG0] = 0;
} }
out: out:
if (nlh) { if (nlh) {
...@@ -1375,8 +1379,6 @@ ip_set_dump(struct sock *ctnl, struct sk_buff *skb, ...@@ -1375,8 +1379,6 @@ ip_set_dump(struct sock *ctnl, struct sk_buff *skb,
const struct nlmsghdr *nlh, const struct nlmsghdr *nlh,
const struct nlattr * const attr[]) const struct nlattr * const attr[])
{ {
struct ip_set_net *inst = ip_set_pernet(sock_net(ctnl));
if (unlikely(protocol_failed(attr))) if (unlikely(protocol_failed(attr)))
return -IPSET_ERR_PROTOCOL; return -IPSET_ERR_PROTOCOL;
...@@ -1384,7 +1386,6 @@ ip_set_dump(struct sock *ctnl, struct sk_buff *skb, ...@@ -1384,7 +1386,6 @@ ip_set_dump(struct sock *ctnl, struct sk_buff *skb,
struct netlink_dump_control c = { struct netlink_dump_control c = {
.dump = ip_set_dump_start, .dump = ip_set_dump_start,
.done = ip_set_dump_done, .done = ip_set_dump_done,
.data = (void *)inst
}; };
return netlink_dump_start(ctnl, skb, nlh, &c); return netlink_dump_start(ctnl, skb, nlh, &c);
} }
...@@ -1961,7 +1962,6 @@ static int __net_init ...@@ -1961,7 +1962,6 @@ static int __net_init
ip_set_net_init(struct net *net) ip_set_net_init(struct net *net)
{ {
struct ip_set_net *inst = ip_set_pernet(net); struct ip_set_net *inst = ip_set_pernet(net);
struct ip_set **list; struct ip_set **list;
inst->ip_set_max = max_sets ? max_sets : CONFIG_IP_SET_MAX; inst->ip_set_max = max_sets ? max_sets : CONFIG_IP_SET_MAX;
......
...@@ -234,7 +234,6 @@ hbucket_elem_add(struct hbucket *n, u8 ahash_max, size_t dsize) ...@@ -234,7 +234,6 @@ hbucket_elem_add(struct hbucket *n, u8 ahash_max, size_t dsize)
#define mtype_uadt IPSET_TOKEN(MTYPE, _uadt) #define mtype_uadt IPSET_TOKEN(MTYPE, _uadt)
#define mtype MTYPE #define mtype MTYPE
#define mtype_elem IPSET_TOKEN(MTYPE, _elem)
#define mtype_add IPSET_TOKEN(MTYPE, _add) #define mtype_add IPSET_TOKEN(MTYPE, _add)
#define mtype_del IPSET_TOKEN(MTYPE, _del) #define mtype_del IPSET_TOKEN(MTYPE, _del)
#define mtype_test_cidrs IPSET_TOKEN(MTYPE, _test_cidrs) #define mtype_test_cidrs IPSET_TOKEN(MTYPE, _test_cidrs)
...@@ -931,7 +930,7 @@ mtype_list(const struct ip_set *set, ...@@ -931,7 +930,7 @@ mtype_list(const struct ip_set *set,
struct nlattr *atd, *nested; struct nlattr *atd, *nested;
const struct hbucket *n; const struct hbucket *n;
const struct mtype_elem *e; const struct mtype_elem *e;
u32 first = cb->args[2]; u32 first = cb->args[IPSET_CB_ARG0];
/* We assume that one hash bucket fills into one page */ /* We assume that one hash bucket fills into one page */
void *incomplete; void *incomplete;
int i; int i;
...@@ -940,20 +939,22 @@ mtype_list(const struct ip_set *set, ...@@ -940,20 +939,22 @@ mtype_list(const struct ip_set *set,
if (!atd) if (!atd)
return -EMSGSIZE; return -EMSGSIZE;
pr_debug("list hash set %s\n", set->name); pr_debug("list hash set %s\n", set->name);
for (; cb->args[2] < jhash_size(t->htable_bits); cb->args[2]++) { for (; cb->args[IPSET_CB_ARG0] < jhash_size(t->htable_bits);
cb->args[IPSET_CB_ARG0]++) {
incomplete = skb_tail_pointer(skb); incomplete = skb_tail_pointer(skb);
n = hbucket(t, cb->args[2]); n = hbucket(t, cb->args[IPSET_CB_ARG0]);
pr_debug("cb->args[2]: %lu, t %p n %p\n", cb->args[2], t, n); pr_debug("cb->arg bucket: %lu, t %p n %p\n",
cb->args[IPSET_CB_ARG0], t, n);
for (i = 0; i < n->pos; i++) { for (i = 0; i < n->pos; i++) {
e = ahash_data(n, i, set->dsize); e = ahash_data(n, i, set->dsize);
if (SET_WITH_TIMEOUT(set) && if (SET_WITH_TIMEOUT(set) &&
ip_set_timeout_expired(ext_timeout(e, set))) ip_set_timeout_expired(ext_timeout(e, set)))
continue; continue;
pr_debug("list hash %lu hbucket %p i %u, data %p\n", pr_debug("list hash %lu hbucket %p i %u, data %p\n",
cb->args[2], n, i, e); cb->args[IPSET_CB_ARG0], n, i, e);
nested = ipset_nest_start(skb, IPSET_ATTR_DATA); nested = ipset_nest_start(skb, IPSET_ATTR_DATA);
if (!nested) { if (!nested) {
if (cb->args[2] == first) { if (cb->args[IPSET_CB_ARG0] == first) {
nla_nest_cancel(skb, atd); nla_nest_cancel(skb, atd);
return -EMSGSIZE; return -EMSGSIZE;
} else } else
...@@ -968,16 +969,16 @@ mtype_list(const struct ip_set *set, ...@@ -968,16 +969,16 @@ mtype_list(const struct ip_set *set,
} }
ipset_nest_end(skb, atd); ipset_nest_end(skb, atd);
/* Set listing finished */ /* Set listing finished */
cb->args[2] = 0; cb->args[IPSET_CB_ARG0] = 0;
return 0; return 0;
nla_put_failure: nla_put_failure:
nlmsg_trim(skb, incomplete); nlmsg_trim(skb, incomplete);
if (unlikely(first == cb->args[2])) { if (unlikely(first == cb->args[IPSET_CB_ARG0])) {
pr_warning("Can't list set %s: one bucket does not fit into " pr_warning("Can't list set %s: one bucket does not fit into "
"a message. Please report it!\n", set->name); "a message. Please report it!\n", set->name);
cb->args[2] = 0; cb->args[IPSET_CB_ARG0] = 0;
return -EMSGSIZE; return -EMSGSIZE;
} }
ipset_nest_end(skb, atd); ipset_nest_end(skb, atd);
......
...@@ -137,12 +137,11 @@ hash_netnet4_kadt(struct ip_set *set, const struct sk_buff *skb, ...@@ -137,12 +137,11 @@ hash_netnet4_kadt(struct ip_set *set, const struct sk_buff *skb,
{ {
const struct hash_netnet *h = set->data; const struct hash_netnet *h = set->data;
ipset_adtfn adtfn = set->variant->adt[adt]; ipset_adtfn adtfn = set->variant->adt[adt];
struct hash_netnet4_elem e = { struct hash_netnet4_elem e = { };
.cidr[0] = h->nets[0].cidr[0] ? h->nets[0].cidr[0] : HOST_MASK,
.cidr[1] = h->nets[0].cidr[1] ? h->nets[0].cidr[1] : HOST_MASK,
};
struct ip_set_ext ext = IP_SET_INIT_KEXT(skb, opt, set); struct ip_set_ext ext = IP_SET_INIT_KEXT(skb, opt, set);
e.cidr[0] = IP_SET_INIT_CIDR(h->nets[0].cidr[0], HOST_MASK);
e.cidr[1] = IP_SET_INIT_CIDR(h->nets[0].cidr[1], HOST_MASK);
if (adt == IPSET_TEST) if (adt == IPSET_TEST)
e.ccmp = (HOST_MASK << (sizeof(e.cidr[0]) * 8)) | HOST_MASK; e.ccmp = (HOST_MASK << (sizeof(e.cidr[0]) * 8)) | HOST_MASK;
...@@ -160,14 +159,14 @@ hash_netnet4_uadt(struct ip_set *set, struct nlattr *tb[], ...@@ -160,14 +159,14 @@ hash_netnet4_uadt(struct ip_set *set, struct nlattr *tb[],
{ {
const struct hash_netnet *h = set->data; const struct hash_netnet *h = set->data;
ipset_adtfn adtfn = set->variant->adt[adt]; ipset_adtfn adtfn = set->variant->adt[adt];
struct hash_netnet4_elem e = { .cidr[0] = HOST_MASK, struct hash_netnet4_elem e = { };
.cidr[1] = HOST_MASK };
struct ip_set_ext ext = IP_SET_INIT_UEXT(set); struct ip_set_ext ext = IP_SET_INIT_UEXT(set);
u32 ip = 0, ip_to = 0, last; u32 ip = 0, ip_to = 0, last;
u32 ip2 = 0, ip2_from = 0, ip2_to = 0, last2; u32 ip2 = 0, ip2_from = 0, ip2_to = 0, last2;
u8 cidr, cidr2; u8 cidr, cidr2;
int ret; int ret;
e.cidr[0] = e.cidr[1] = HOST_MASK;
if (unlikely(!tb[IPSET_ATTR_IP] || !tb[IPSET_ATTR_IP2] || if (unlikely(!tb[IPSET_ATTR_IP] || !tb[IPSET_ATTR_IP2] ||
!ip_set_optattr_netorder(tb, IPSET_ATTR_TIMEOUT) || !ip_set_optattr_netorder(tb, IPSET_ATTR_TIMEOUT) ||
!ip_set_optattr_netorder(tb, IPSET_ATTR_CADT_FLAGS) || !ip_set_optattr_netorder(tb, IPSET_ATTR_CADT_FLAGS) ||
...@@ -364,12 +363,11 @@ hash_netnet6_kadt(struct ip_set *set, const struct sk_buff *skb, ...@@ -364,12 +363,11 @@ hash_netnet6_kadt(struct ip_set *set, const struct sk_buff *skb,
{ {
const struct hash_netnet *h = set->data; const struct hash_netnet *h = set->data;
ipset_adtfn adtfn = set->variant->adt[adt]; ipset_adtfn adtfn = set->variant->adt[adt];
struct hash_netnet6_elem e = { struct hash_netnet6_elem e = { };
.cidr[0] = h->nets[0].cidr[0] ? h->nets[0].cidr[0] : HOST_MASK,
.cidr[1] = h->nets[0].cidr[1] ? h->nets[0].cidr[1] : HOST_MASK
};
struct ip_set_ext ext = IP_SET_INIT_KEXT(skb, opt, set); struct ip_set_ext ext = IP_SET_INIT_KEXT(skb, opt, set);
e.cidr[0] = IP_SET_INIT_CIDR(h->nets[0].cidr[0], HOST_MASK);
e.cidr[1] = IP_SET_INIT_CIDR(h->nets[0].cidr[1], HOST_MASK);
if (adt == IPSET_TEST) if (adt == IPSET_TEST)
e.ccmp = (HOST_MASK << (sizeof(u8)*8)) | HOST_MASK; e.ccmp = (HOST_MASK << (sizeof(u8)*8)) | HOST_MASK;
...@@ -386,11 +384,11 @@ hash_netnet6_uadt(struct ip_set *set, struct nlattr *tb[], ...@@ -386,11 +384,11 @@ hash_netnet6_uadt(struct ip_set *set, struct nlattr *tb[],
enum ipset_adt adt, u32 *lineno, u32 flags, bool retried) enum ipset_adt adt, u32 *lineno, u32 flags, bool retried)
{ {
ipset_adtfn adtfn = set->variant->adt[adt]; ipset_adtfn adtfn = set->variant->adt[adt];
struct hash_netnet6_elem e = { .cidr[0] = HOST_MASK, struct hash_netnet6_elem e = { };
.cidr[1] = HOST_MASK };
struct ip_set_ext ext = IP_SET_INIT_UEXT(set); struct ip_set_ext ext = IP_SET_INIT_UEXT(set);
int ret; int ret;
e.cidr[0] = e.cidr[1] = HOST_MASK;
if (unlikely(!tb[IPSET_ATTR_IP] || !tb[IPSET_ATTR_IP2] || if (unlikely(!tb[IPSET_ATTR_IP] || !tb[IPSET_ATTR_IP2] ||
!ip_set_optattr_netorder(tb, IPSET_ATTR_TIMEOUT) || !ip_set_optattr_netorder(tb, IPSET_ATTR_TIMEOUT) ||
!ip_set_optattr_netorder(tb, IPSET_ATTR_CADT_FLAGS) || !ip_set_optattr_netorder(tb, IPSET_ATTR_CADT_FLAGS) ||
......
...@@ -147,12 +147,11 @@ hash_netportnet4_kadt(struct ip_set *set, const struct sk_buff *skb, ...@@ -147,12 +147,11 @@ hash_netportnet4_kadt(struct ip_set *set, const struct sk_buff *skb,
{ {
const struct hash_netportnet *h = set->data; const struct hash_netportnet *h = set->data;
ipset_adtfn adtfn = set->variant->adt[adt]; ipset_adtfn adtfn = set->variant->adt[adt];
struct hash_netportnet4_elem e = { struct hash_netportnet4_elem e = { };
.cidr[0] = IP_SET_INIT_CIDR(h->nets[0].cidr[0], HOST_MASK),
.cidr[1] = IP_SET_INIT_CIDR(h->nets[0].cidr[1], HOST_MASK),
};
struct ip_set_ext ext = IP_SET_INIT_KEXT(skb, opt, set); struct ip_set_ext ext = IP_SET_INIT_KEXT(skb, opt, set);
e.cidr[0] = IP_SET_INIT_CIDR(h->nets[0].cidr[0], HOST_MASK);
e.cidr[1] = IP_SET_INIT_CIDR(h->nets[0].cidr[1], HOST_MASK);
if (adt == IPSET_TEST) if (adt == IPSET_TEST)
e.ccmp = (HOST_MASK << (sizeof(e.cidr[0]) * 8)) | HOST_MASK; e.ccmp = (HOST_MASK << (sizeof(e.cidr[0]) * 8)) | HOST_MASK;
...@@ -174,8 +173,7 @@ hash_netportnet4_uadt(struct ip_set *set, struct nlattr *tb[], ...@@ -174,8 +173,7 @@ hash_netportnet4_uadt(struct ip_set *set, struct nlattr *tb[],
{ {
const struct hash_netportnet *h = set->data; const struct hash_netportnet *h = set->data;
ipset_adtfn adtfn = set->variant->adt[adt]; ipset_adtfn adtfn = set->variant->adt[adt];
struct hash_netportnet4_elem e = { .cidr[0] = HOST_MASK, struct hash_netportnet4_elem e = { };
.cidr[1] = HOST_MASK };
struct ip_set_ext ext = IP_SET_INIT_UEXT(set); struct ip_set_ext ext = IP_SET_INIT_UEXT(set);
u32 ip = 0, ip_to = 0, ip_last, p = 0, port, port_to; u32 ip = 0, ip_to = 0, ip_last, p = 0, port, port_to;
u32 ip2_from = 0, ip2_to = 0, ip2_last, ip2; u32 ip2_from = 0, ip2_to = 0, ip2_last, ip2;
...@@ -183,6 +181,7 @@ hash_netportnet4_uadt(struct ip_set *set, struct nlattr *tb[], ...@@ -183,6 +181,7 @@ hash_netportnet4_uadt(struct ip_set *set, struct nlattr *tb[],
u8 cidr, cidr2; u8 cidr, cidr2;
int ret; int ret;
e.cidr[0] = e.cidr[1] = HOST_MASK;
if (unlikely(!tb[IPSET_ATTR_IP] || !tb[IPSET_ATTR_IP2] || if (unlikely(!tb[IPSET_ATTR_IP] || !tb[IPSET_ATTR_IP2] ||
!ip_set_attr_netorder(tb, IPSET_ATTR_PORT) || !ip_set_attr_netorder(tb, IPSET_ATTR_PORT) ||
!ip_set_optattr_netorder(tb, IPSET_ATTR_PORT_TO) || !ip_set_optattr_netorder(tb, IPSET_ATTR_PORT_TO) ||
...@@ -419,12 +418,11 @@ hash_netportnet6_kadt(struct ip_set *set, const struct sk_buff *skb, ...@@ -419,12 +418,11 @@ hash_netportnet6_kadt(struct ip_set *set, const struct sk_buff *skb,
{ {
const struct hash_netportnet *h = set->data; const struct hash_netportnet *h = set->data;
ipset_adtfn adtfn = set->variant->adt[adt]; ipset_adtfn adtfn = set->variant->adt[adt];
struct hash_netportnet6_elem e = { struct hash_netportnet6_elem e = { };
.cidr[0] = IP_SET_INIT_CIDR(h->nets[0].cidr[0], HOST_MASK),
.cidr[1] = IP_SET_INIT_CIDR(h->nets[0].cidr[1], HOST_MASK),
};
struct ip_set_ext ext = IP_SET_INIT_KEXT(skb, opt, set); struct ip_set_ext ext = IP_SET_INIT_KEXT(skb, opt, set);
e.cidr[0] = IP_SET_INIT_CIDR(h->nets[0].cidr[0], HOST_MASK);
e.cidr[1] = IP_SET_INIT_CIDR(h->nets[0].cidr[1], HOST_MASK);
if (adt == IPSET_TEST) if (adt == IPSET_TEST)
e.ccmp = (HOST_MASK << (sizeof(u8) * 8)) | HOST_MASK; e.ccmp = (HOST_MASK << (sizeof(u8) * 8)) | HOST_MASK;
...@@ -446,13 +444,13 @@ hash_netportnet6_uadt(struct ip_set *set, struct nlattr *tb[], ...@@ -446,13 +444,13 @@ hash_netportnet6_uadt(struct ip_set *set, struct nlattr *tb[],
{ {
const struct hash_netportnet *h = set->data; const struct hash_netportnet *h = set->data;
ipset_adtfn adtfn = set->variant->adt[adt]; ipset_adtfn adtfn = set->variant->adt[adt];
struct hash_netportnet6_elem e = { .cidr[0] = HOST_MASK, struct hash_netportnet6_elem e = { };
.cidr[1] = HOST_MASK };
struct ip_set_ext ext = IP_SET_INIT_UEXT(set); struct ip_set_ext ext = IP_SET_INIT_UEXT(set);
u32 port, port_to; u32 port, port_to;
bool with_ports = false; bool with_ports = false;
int ret; int ret;
e.cidr[0] = e.cidr[1] = HOST_MASK;
if (unlikely(!tb[IPSET_ATTR_IP] || !tb[IPSET_ATTR_IP2] || if (unlikely(!tb[IPSET_ATTR_IP] || !tb[IPSET_ATTR_IP2] ||
!ip_set_attr_netorder(tb, IPSET_ATTR_PORT) || !ip_set_attr_netorder(tb, IPSET_ATTR_PORT) ||
!ip_set_optattr_netorder(tb, IPSET_ATTR_PORT_TO) || !ip_set_optattr_netorder(tb, IPSET_ATTR_PORT_TO) ||
......
...@@ -490,14 +490,15 @@ list_set_list(const struct ip_set *set, ...@@ -490,14 +490,15 @@ list_set_list(const struct ip_set *set,
{ {
const struct list_set *map = set->data; const struct list_set *map = set->data;
struct nlattr *atd, *nested; struct nlattr *atd, *nested;
u32 i, first = cb->args[2]; u32 i, first = cb->args[IPSET_CB_ARG0];
const struct set_elem *e; const struct set_elem *e;
atd = ipset_nest_start(skb, IPSET_ATTR_ADT); atd = ipset_nest_start(skb, IPSET_ATTR_ADT);
if (!atd) if (!atd)
return -EMSGSIZE; return -EMSGSIZE;
for (; cb->args[2] < map->size; cb->args[2]++) { for (; cb->args[IPSET_CB_ARG0] < map->size;
i = cb->args[2]; cb->args[IPSET_CB_ARG0]++) {
i = cb->args[IPSET_CB_ARG0];
e = list_set_elem(set, map, i); e = list_set_elem(set, map, i);
if (e->id == IPSET_INVALID_ID) if (e->id == IPSET_INVALID_ID)
goto finish; goto finish;
...@@ -522,13 +523,13 @@ list_set_list(const struct ip_set *set, ...@@ -522,13 +523,13 @@ list_set_list(const struct ip_set *set,
finish: finish:
ipset_nest_end(skb, atd); ipset_nest_end(skb, atd);
/* Set listing finished */ /* Set listing finished */
cb->args[2] = 0; cb->args[IPSET_CB_ARG0] = 0;
return 0; return 0;
nla_put_failure: nla_put_failure:
nla_nest_cancel(skb, nested); nla_nest_cancel(skb, nested);
if (unlikely(i == first)) { if (unlikely(i == first)) {
cb->args[2] = 0; cb->args[IPSET_CB_ARG0] = 0;
return -EMSGSIZE; return -EMSGSIZE;
} }
ipset_nest_end(skb, atd); ipset_nest_end(skb, atd);
......
...@@ -704,7 +704,7 @@ static void ip_vs_dest_free(struct ip_vs_dest *dest) ...@@ -704,7 +704,7 @@ static void ip_vs_dest_free(struct ip_vs_dest *dest)
__ip_vs_dst_cache_reset(dest); __ip_vs_dst_cache_reset(dest);
__ip_vs_svc_put(svc, false); __ip_vs_svc_put(svc, false);
free_percpu(dest->stats.cpustats); free_percpu(dest->stats.cpustats);
kfree(dest); ip_vs_dest_put_and_free(dest);
} }
/* /*
...@@ -3820,10 +3820,6 @@ void __net_exit ip_vs_control_net_cleanup(struct net *net) ...@@ -3820,10 +3820,6 @@ void __net_exit ip_vs_control_net_cleanup(struct net *net)
{ {
struct netns_ipvs *ipvs = net_ipvs(net); struct netns_ipvs *ipvs = net_ipvs(net);
/* Some dest can be in grace period even before cleanup, we have to
* defer ip_vs_trash_cleanup until ip_vs_dest_wait_readers is called.
*/
rcu_barrier();
ip_vs_trash_cleanup(net); ip_vs_trash_cleanup(net);
ip_vs_stop_estimator(net, &ipvs->tot_stats); ip_vs_stop_estimator(net, &ipvs->tot_stats);
ip_vs_control_net_cleanup_sysctl(net); ip_vs_control_net_cleanup_sysctl(net);
......
...@@ -136,7 +136,7 @@ static void ip_vs_lblc_rcu_free(struct rcu_head *head) ...@@ -136,7 +136,7 @@ static void ip_vs_lblc_rcu_free(struct rcu_head *head)
struct ip_vs_lblc_entry, struct ip_vs_lblc_entry,
rcu_head); rcu_head);
ip_vs_dest_put(en->dest); ip_vs_dest_put_and_free(en->dest);
kfree(en); kfree(en);
} }
......
...@@ -130,7 +130,7 @@ static void ip_vs_lblcr_elem_rcu_free(struct rcu_head *head) ...@@ -130,7 +130,7 @@ static void ip_vs_lblcr_elem_rcu_free(struct rcu_head *head)
struct ip_vs_dest_set_elem *e; struct ip_vs_dest_set_elem *e;
e = container_of(head, struct ip_vs_dest_set_elem, rcu_head); e = container_of(head, struct ip_vs_dest_set_elem, rcu_head);
ip_vs_dest_put(e->dest); ip_vs_dest_put_and_free(e->dest);
kfree(e); kfree(e);
} }
......
...@@ -20,13 +20,18 @@ sctp_conn_schedule(int af, struct sk_buff *skb, struct ip_vs_proto_data *pd, ...@@ -20,13 +20,18 @@ sctp_conn_schedule(int af, struct sk_buff *skb, struct ip_vs_proto_data *pd,
sctp_sctphdr_t *sh, _sctph; sctp_sctphdr_t *sh, _sctph;
sh = skb_header_pointer(skb, iph->len, sizeof(_sctph), &_sctph); sh = skb_header_pointer(skb, iph->len, sizeof(_sctph), &_sctph);
if (sh == NULL) if (sh == NULL) {
*verdict = NF_DROP;
return 0; return 0;
}
sch = skb_header_pointer(skb, iph->len + sizeof(sctp_sctphdr_t), sch = skb_header_pointer(skb, iph->len + sizeof(sctp_sctphdr_t),
sizeof(_schunkh), &_schunkh); sizeof(_schunkh), &_schunkh);
if (sch == NULL) if (sch == NULL) {
*verdict = NF_DROP;
return 0; return 0;
}
net = skb_net(skb); net = skb_net(skb);
ipvs = net_ipvs(net); ipvs = net_ipvs(net);
rcu_read_lock(); rcu_read_lock();
...@@ -76,6 +81,7 @@ sctp_snat_handler(struct sk_buff *skb, struct ip_vs_protocol *pp, ...@@ -76,6 +81,7 @@ sctp_snat_handler(struct sk_buff *skb, struct ip_vs_protocol *pp,
{ {
sctp_sctphdr_t *sctph; sctp_sctphdr_t *sctph;
unsigned int sctphoff = iph->len; unsigned int sctphoff = iph->len;
bool payload_csum = false;
#ifdef CONFIG_IP_VS_IPV6 #ifdef CONFIG_IP_VS_IPV6
if (cp->af == AF_INET6 && iph->fragoffs) if (cp->af == AF_INET6 && iph->fragoffs)
...@@ -87,19 +93,31 @@ sctp_snat_handler(struct sk_buff *skb, struct ip_vs_protocol *pp, ...@@ -87,19 +93,31 @@ sctp_snat_handler(struct sk_buff *skb, struct ip_vs_protocol *pp,
return 0; return 0;
if (unlikely(cp->app != NULL)) { if (unlikely(cp->app != NULL)) {
int ret;
/* Some checks before mangling */ /* Some checks before mangling */
if (pp->csum_check && !pp->csum_check(cp->af, skb, pp)) if (pp->csum_check && !pp->csum_check(cp->af, skb, pp))
return 0; return 0;
/* Call application helper if needed */ /* Call application helper if needed */
if (!ip_vs_app_pkt_out(cp, skb)) ret = ip_vs_app_pkt_out(cp, skb);
if (ret == 0)
return 0; return 0;
/* ret=2: csum update is needed after payload mangling */
if (ret == 2)
payload_csum = true;
} }
sctph = (void *) skb_network_header(skb) + sctphoff; sctph = (void *) skb_network_header(skb) + sctphoff;
sctph->source = cp->vport;
/* Only update csum if we really have to */
if (sctph->source != cp->vport || payload_csum ||
skb->ip_summed == CHECKSUM_PARTIAL) {
sctph->source = cp->vport;
sctp_nat_csum(skb, sctph, sctphoff); sctp_nat_csum(skb, sctph, sctphoff);
} else {
skb->ip_summed = CHECKSUM_UNNECESSARY;
}
return 1; return 1;
} }
...@@ -110,6 +128,7 @@ sctp_dnat_handler(struct sk_buff *skb, struct ip_vs_protocol *pp, ...@@ -110,6 +128,7 @@ sctp_dnat_handler(struct sk_buff *skb, struct ip_vs_protocol *pp,
{ {
sctp_sctphdr_t *sctph; sctp_sctphdr_t *sctph;
unsigned int sctphoff = iph->len; unsigned int sctphoff = iph->len;
bool payload_csum = false;
#ifdef CONFIG_IP_VS_IPV6 #ifdef CONFIG_IP_VS_IPV6
if (cp->af == AF_INET6 && iph->fragoffs) if (cp->af == AF_INET6 && iph->fragoffs)
...@@ -121,19 +140,32 @@ sctp_dnat_handler(struct sk_buff *skb, struct ip_vs_protocol *pp, ...@@ -121,19 +140,32 @@ sctp_dnat_handler(struct sk_buff *skb, struct ip_vs_protocol *pp,
return 0; return 0;
if (unlikely(cp->app != NULL)) { if (unlikely(cp->app != NULL)) {
int ret;
/* Some checks before mangling */ /* Some checks before mangling */
if (pp->csum_check && !pp->csum_check(cp->af, skb, pp)) if (pp->csum_check && !pp->csum_check(cp->af, skb, pp))
return 0; return 0;
/* Call application helper if needed */ /* Call application helper if needed */
if (!ip_vs_app_pkt_in(cp, skb)) ret = ip_vs_app_pkt_in(cp, skb);
if (ret == 0)
return 0; return 0;
/* ret=2: csum update is needed after payload mangling */
if (ret == 2)
payload_csum = true;
} }
sctph = (void *) skb_network_header(skb) + sctphoff; sctph = (void *) skb_network_header(skb) + sctphoff;
sctph->dest = cp->dport;
/* Only update csum if we really have to */
if (sctph->dest != cp->dport || payload_csum ||
(skb->ip_summed == CHECKSUM_PARTIAL &&
!(skb_dst(skb)->dev->features & NETIF_F_SCTP_CSUM))) {
sctph->dest = cp->dport;
sctp_nat_csum(skb, sctph, sctphoff); sctp_nat_csum(skb, sctph, sctphoff);
} else if (skb->ip_summed != CHECKSUM_PARTIAL) {
skb->ip_summed = CHECKSUM_UNNECESSARY;
}
return 1; return 1;
} }
......
...@@ -115,27 +115,46 @@ ip_vs_sh_get(struct ip_vs_service *svc, struct ip_vs_sh_state *s, ...@@ -115,27 +115,46 @@ ip_vs_sh_get(struct ip_vs_service *svc, struct ip_vs_sh_state *s,
} }
/* As ip_vs_sh_get, but with fallback if selected server is unavailable */ /* As ip_vs_sh_get, but with fallback if selected server is unavailable
*
* The fallback strategy loops around the table starting from a "random"
* point (in fact, it is chosen to be the original hash value to make the
* algorithm deterministic) to find a new server.
*/
static inline struct ip_vs_dest * static inline struct ip_vs_dest *
ip_vs_sh_get_fallback(struct ip_vs_service *svc, struct ip_vs_sh_state *s, ip_vs_sh_get_fallback(struct ip_vs_service *svc, struct ip_vs_sh_state *s,
const union nf_inet_addr *addr, __be16 port) const union nf_inet_addr *addr, __be16 port)
{ {
unsigned int offset; unsigned int offset, roffset;
unsigned int hash; unsigned int hash, ihash;
struct ip_vs_dest *dest; struct ip_vs_dest *dest;
/* first try the dest it's supposed to go to */
ihash = ip_vs_sh_hashkey(svc->af, addr, port, 0);
dest = rcu_dereference(s->buckets[ihash].dest);
if (!dest)
return NULL;
if (!is_unavailable(dest))
return dest;
IP_VS_DBG_BUF(6, "SH: selected unavailable server %s:%d, reselecting",
IP_VS_DBG_ADDR(svc->af, &dest->addr), ntohs(dest->port));
/* if the original dest is unavailable, loop around the table
* starting from ihash to find a new dest
*/
for (offset = 0; offset < IP_VS_SH_TAB_SIZE; offset++) { for (offset = 0; offset < IP_VS_SH_TAB_SIZE; offset++) {
hash = ip_vs_sh_hashkey(svc->af, addr, port, offset); roffset = (offset + ihash) % IP_VS_SH_TAB_SIZE;
hash = ip_vs_sh_hashkey(svc->af, addr, port, roffset);
dest = rcu_dereference(s->buckets[hash].dest); dest = rcu_dereference(s->buckets[hash].dest);
if (!dest) if (!dest)
break; break;
if (is_unavailable(dest)) if (!is_unavailable(dest))
IP_VS_DBG_BUF(6, "SH: selected unavailable server "
"%s:%d (offset %d)",
IP_VS_DBG_ADDR(svc->af, &dest->addr),
ntohs(dest->port), offset);
else
return dest; return dest;
IP_VS_DBG_BUF(6, "SH: selected unavailable "
"server %s:%d (offset %d), reselecting",
IP_VS_DBG_ADDR(svc->af, &dest->addr),
ntohs(dest->port), roffset);
} }
return NULL; return NULL;
......
...@@ -39,21 +39,23 @@ static struct ctl_table acct_sysctl_table[] = { ...@@ -39,21 +39,23 @@ static struct ctl_table acct_sysctl_table[] = {
unsigned int unsigned int
seq_print_acct(struct seq_file *s, const struct nf_conn *ct, int dir) seq_print_acct(struct seq_file *s, const struct nf_conn *ct, int dir)
{ {
struct nf_conn_counter *acct; struct nf_conn_acct *acct;
struct nf_conn_counter *counter;
acct = nf_conn_acct_find(ct); acct = nf_conn_acct_find(ct);
if (!acct) if (!acct)
return 0; return 0;
counter = acct->counter;
return seq_printf(s, "packets=%llu bytes=%llu ", return seq_printf(s, "packets=%llu bytes=%llu ",
(unsigned long long)atomic64_read(&acct[dir].packets), (unsigned long long)atomic64_read(&counter[dir].packets),
(unsigned long long)atomic64_read(&acct[dir].bytes)); (unsigned long long)atomic64_read(&counter[dir].bytes));
}; };
EXPORT_SYMBOL_GPL(seq_print_acct); EXPORT_SYMBOL_GPL(seq_print_acct);
static struct nf_ct_ext_type acct_extend __read_mostly = { static struct nf_ct_ext_type acct_extend __read_mostly = {
.len = sizeof(struct nf_conn_counter[IP_CT_DIR_MAX]), .len = sizeof(struct nf_conn_acct),
.align = __alignof__(struct nf_conn_counter[IP_CT_DIR_MAX]), .align = __alignof__(struct nf_conn_acct),
.id = NF_CT_EXT_ACCT, .id = NF_CT_EXT_ACCT,
}; };
......
...@@ -1109,12 +1109,14 @@ void __nf_ct_refresh_acct(struct nf_conn *ct, ...@@ -1109,12 +1109,14 @@ void __nf_ct_refresh_acct(struct nf_conn *ct,
acct: acct:
if (do_acct) { if (do_acct) {
struct nf_conn_counter *acct; struct nf_conn_acct *acct;
acct = nf_conn_acct_find(ct); acct = nf_conn_acct_find(ct);
if (acct) { if (acct) {
atomic64_inc(&acct[CTINFO2DIR(ctinfo)].packets); struct nf_conn_counter *counter = acct->counter;
atomic64_add(skb->len, &acct[CTINFO2DIR(ctinfo)].bytes);
atomic64_inc(&counter[CTINFO2DIR(ctinfo)].packets);
atomic64_add(skb->len, &counter[CTINFO2DIR(ctinfo)].bytes);
} }
} }
} }
...@@ -1126,13 +1128,15 @@ bool __nf_ct_kill_acct(struct nf_conn *ct, ...@@ -1126,13 +1128,15 @@ bool __nf_ct_kill_acct(struct nf_conn *ct,
int do_acct) int do_acct)
{ {
if (do_acct) { if (do_acct) {
struct nf_conn_counter *acct; struct nf_conn_acct *acct;
acct = nf_conn_acct_find(ct); acct = nf_conn_acct_find(ct);
if (acct) { if (acct) {
atomic64_inc(&acct[CTINFO2DIR(ctinfo)].packets); struct nf_conn_counter *counter = acct->counter;
atomic64_inc(&counter[CTINFO2DIR(ctinfo)].packets);
atomic64_add(skb->len - skb_network_offset(skb), atomic64_add(skb->len - skb_network_offset(skb),
&acct[CTINFO2DIR(ctinfo)].bytes); &counter[CTINFO2DIR(ctinfo)].bytes);
} }
} }
......
...@@ -211,13 +211,23 @@ ctnetlink_dump_helpinfo(struct sk_buff *skb, const struct nf_conn *ct) ...@@ -211,13 +211,23 @@ ctnetlink_dump_helpinfo(struct sk_buff *skb, const struct nf_conn *ct)
} }
static int static int
dump_counters(struct sk_buff *skb, u64 pkts, u64 bytes, dump_counters(struct sk_buff *skb, struct nf_conn_acct *acct,
enum ip_conntrack_dir dir) enum ip_conntrack_dir dir, int type)
{ {
enum ctattr_type type = dir ? CTA_COUNTERS_REPLY: CTA_COUNTERS_ORIG; enum ctattr_type attr = dir ? CTA_COUNTERS_REPLY: CTA_COUNTERS_ORIG;
struct nf_conn_counter *counter = acct->counter;
struct nlattr *nest_count; struct nlattr *nest_count;
u64 pkts, bytes;
if (type == IPCTNL_MSG_CT_GET_CTRZERO) {
pkts = atomic64_xchg(&counter[dir].packets, 0);
bytes = atomic64_xchg(&counter[dir].bytes, 0);
} else {
pkts = atomic64_read(&counter[dir].packets);
bytes = atomic64_read(&counter[dir].bytes);
}
nest_count = nla_nest_start(skb, type | NLA_F_NESTED); nest_count = nla_nest_start(skb, attr | NLA_F_NESTED);
if (!nest_count) if (!nest_count)
goto nla_put_failure; goto nla_put_failure;
...@@ -234,24 +244,19 @@ dump_counters(struct sk_buff *skb, u64 pkts, u64 bytes, ...@@ -234,24 +244,19 @@ dump_counters(struct sk_buff *skb, u64 pkts, u64 bytes,
} }
static int static int
ctnetlink_dump_counters(struct sk_buff *skb, const struct nf_conn *ct, ctnetlink_dump_acct(struct sk_buff *skb, const struct nf_conn *ct, int type)
enum ip_conntrack_dir dir, int type)
{ {
struct nf_conn_counter *acct; struct nf_conn_acct *acct = nf_conn_acct_find(ct);
u64 pkts, bytes;
acct = nf_conn_acct_find(ct);
if (!acct) if (!acct)
return 0; return 0;
if (type == IPCTNL_MSG_CT_GET_CTRZERO) { if (dump_counters(skb, acct, IP_CT_DIR_ORIGINAL, type) < 0)
pkts = atomic64_xchg(&acct[dir].packets, 0); return -1;
bytes = atomic64_xchg(&acct[dir].bytes, 0); if (dump_counters(skb, acct, IP_CT_DIR_REPLY, type) < 0)
} else { return -1;
pkts = atomic64_read(&acct[dir].packets);
bytes = atomic64_read(&acct[dir].bytes); return 0;
}
return dump_counters(skb, pkts, bytes, dir);
} }
static int static int
...@@ -488,8 +493,7 @@ ctnetlink_fill_info(struct sk_buff *skb, u32 portid, u32 seq, u32 type, ...@@ -488,8 +493,7 @@ ctnetlink_fill_info(struct sk_buff *skb, u32 portid, u32 seq, u32 type,
if (ctnetlink_dump_status(skb, ct) < 0 || if (ctnetlink_dump_status(skb, ct) < 0 ||
ctnetlink_dump_timeout(skb, ct) < 0 || ctnetlink_dump_timeout(skb, ct) < 0 ||
ctnetlink_dump_counters(skb, ct, IP_CT_DIR_ORIGINAL, type) < 0 || ctnetlink_dump_acct(skb, ct, type) < 0 ||
ctnetlink_dump_counters(skb, ct, IP_CT_DIR_REPLY, type) < 0 ||
ctnetlink_dump_timestamp(skb, ct) < 0 || ctnetlink_dump_timestamp(skb, ct) < 0 ||
ctnetlink_dump_protoinfo(skb, ct) < 0 || ctnetlink_dump_protoinfo(skb, ct) < 0 ||
ctnetlink_dump_helpinfo(skb, ct) < 0 || ctnetlink_dump_helpinfo(skb, ct) < 0 ||
...@@ -530,7 +534,7 @@ ctnetlink_proto_size(const struct nf_conn *ct) ...@@ -530,7 +534,7 @@ ctnetlink_proto_size(const struct nf_conn *ct)
} }
static inline size_t static inline size_t
ctnetlink_counters_size(const struct nf_conn *ct) ctnetlink_acct_size(const struct nf_conn *ct)
{ {
if (!nf_ct_ext_exist(ct, NF_CT_EXT_ACCT)) if (!nf_ct_ext_exist(ct, NF_CT_EXT_ACCT))
return 0; return 0;
...@@ -579,7 +583,7 @@ ctnetlink_nlmsg_size(const struct nf_conn *ct) ...@@ -579,7 +583,7 @@ ctnetlink_nlmsg_size(const struct nf_conn *ct)
+ 3 * nla_total_size(sizeof(u_int8_t)) /* CTA_PROTO_NUM */ + 3 * nla_total_size(sizeof(u_int8_t)) /* CTA_PROTO_NUM */
+ nla_total_size(sizeof(u_int32_t)) /* CTA_ID */ + nla_total_size(sizeof(u_int32_t)) /* CTA_ID */
+ nla_total_size(sizeof(u_int32_t)) /* CTA_STATUS */ + nla_total_size(sizeof(u_int32_t)) /* CTA_STATUS */
+ ctnetlink_counters_size(ct) + ctnetlink_acct_size(ct)
+ ctnetlink_timestamp_size(ct) + ctnetlink_timestamp_size(ct)
+ nla_total_size(sizeof(u_int32_t)) /* CTA_TIMEOUT */ + nla_total_size(sizeof(u_int32_t)) /* CTA_TIMEOUT */
+ nla_total_size(0) /* CTA_PROTOINFO */ + nla_total_size(0) /* CTA_PROTOINFO */
...@@ -673,10 +677,7 @@ ctnetlink_conntrack_event(unsigned int events, struct nf_ct_event *item) ...@@ -673,10 +677,7 @@ ctnetlink_conntrack_event(unsigned int events, struct nf_ct_event *item)
goto nla_put_failure; goto nla_put_failure;
if (events & (1 << IPCT_DESTROY)) { if (events & (1 << IPCT_DESTROY)) {
if (ctnetlink_dump_counters(skb, ct, if (ctnetlink_dump_acct(skb, ct, type) < 0 ||
IP_CT_DIR_ORIGINAL, type) < 0 ||
ctnetlink_dump_counters(skb, ct,
IP_CT_DIR_REPLY, type) < 0 ||
ctnetlink_dump_timestamp(skb, ct) < 0) ctnetlink_dump_timestamp(skb, ct) < 0)
goto nla_put_failure; goto nla_put_failure;
} else { } else {
......
...@@ -26,16 +26,18 @@ connbytes_mt(const struct sk_buff *skb, struct xt_action_param *par) ...@@ -26,16 +26,18 @@ connbytes_mt(const struct sk_buff *skb, struct xt_action_param *par)
u_int64_t what = 0; /* initialize to make gcc happy */ u_int64_t what = 0; /* initialize to make gcc happy */
u_int64_t bytes = 0; u_int64_t bytes = 0;
u_int64_t pkts = 0; u_int64_t pkts = 0;
const struct nf_conn_acct *acct;
const struct nf_conn_counter *counters; const struct nf_conn_counter *counters;
ct = nf_ct_get(skb, &ctinfo); ct = nf_ct_get(skb, &ctinfo);
if (!ct) if (!ct)
return false; return false;
counters = nf_conn_acct_find(ct); acct = nf_conn_acct_find(ct);
if (!counters) if (!acct)
return false; return false;
counters = acct->counter;
switch (sinfo->what) { switch (sinfo->what) {
case XT_CONNBYTES_PKTS: case XT_CONNBYTES_PKTS:
switch (sinfo->direction) { switch (sinfo->direction) {
......
...@@ -35,15 +35,6 @@ ...@@ -35,15 +35,6 @@
#include <net/netfilter/nf_conntrack.h> #include <net/netfilter/nf_conntrack.h>
#endif #endif
static void
xt_socket_put_sk(struct sock *sk)
{
if (sk->sk_state == TCP_TIME_WAIT)
inet_twsk_put(inet_twsk(sk));
else
sock_put(sk);
}
static int static int
extract_icmp4_fields(const struct sk_buff *skb, extract_icmp4_fields(const struct sk_buff *skb,
u8 *protocol, u8 *protocol,
...@@ -216,7 +207,7 @@ socket_match(const struct sk_buff *skb, struct xt_action_param *par, ...@@ -216,7 +207,7 @@ socket_match(const struct sk_buff *skb, struct xt_action_param *par,
inet_twsk(sk)->tw_transparent)); inet_twsk(sk)->tw_transparent));
if (sk != skb->sk) if (sk != skb->sk)
xt_socket_put_sk(sk); sock_gen_put(sk);
if (wildcard || !transparent) if (wildcard || !transparent)
sk = NULL; sk = NULL;
...@@ -381,7 +372,7 @@ socket_mt6_v1_v2(const struct sk_buff *skb, struct xt_action_param *par) ...@@ -381,7 +372,7 @@ socket_mt6_v1_v2(const struct sk_buff *skb, struct xt_action_param *par)
inet_twsk(sk)->tw_transparent)); inet_twsk(sk)->tw_transparent));
if (sk != skb->sk) if (sk != skb->sk)
xt_socket_put_sk(sk); sock_gen_put(sk);
if (wildcard || !transparent) if (wildcard || !transparent)
sk = NULL; sk = NULL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment