IPVS Network Name Space aware
Subsystems (5)
cover IPVS Network Name Space aware
From: Hans Schillstrom <[email protected]>
This patch series adds network name space support to the LVS.
REVISION
This is version 3
OVERVIEW
The patch doesn't remove or add any functionality except for netns. For users that don't use network name space (netns) this patch is completely transparent.
Now it's possible to run LVS in a Linux container (see lxc-tools) i.e. a light weight visualization. For example it's possible to run one or several lvs on a real server in their own network name spaces. From the LVS point of view it looks like it runs on it's own machine.
IMPLEMENTATION
Basic requirements for netns awareness
- Global variables has to be moved to dyn. allocated memory.
- No or very little performance loss
Large hash tables connection hash and service hashes still resides in global memory with net ptr added in hash key.
Most global variables now resides in a struct ipvs { } in netns/ip_vs.h. The size of per name space is 2096 bytes (for x86_64) and a little bit less for 32 bit arch's.
Statistics counters is now lock-free i.e. incremented per CPU, The estimator does a sum when using it.
Procfs: ip_vs_stats_percpu is added to reflect the "per cpu" ex.
# cat /proc/net/ip_vs_stats
Total Incoming Outgoing Incoming Outgoing
CPU Conns Packets Packets Bytes Bytes
0 0 3 1 9D 34
1 0 1 2 49 70
2 0 1 2 34 76
3 1 2 2 70 74
~ 1 7 7 18A 18E Conns/s Pkts/s Pkts/s Bytes/s Bytes/s
0 0 0 0 0
Algorithm files are untouched except for lblc and lblcr.
STEP BY STEP
First patch creates network name space init for all files that need it. How ever if a new name space is created an error is returned. This will be removed in the last patch.
When net ptr ain't available init_net will be used temporarily.
CHANGES
*v2
The patches is totally reworked so each patch compile ... Depends on the IPv6 and Persistence Backup patch.
Common hash-table per name-space for connections and services Stats per CPU
smaller changes in lblc and lblcr
Triggered by Julians comment:
"tcp_timeout_change should work with the new struct ip_vs_proto_data
so that tcp_state_table will go to pd->state_table and set_tcp_state will get pd instead of pp"
*v3
Changes triggered by comment mostly, see individual patches for details.
procfs ip_vs_stats remains the same, ip_vs_stats_percpu added instead. Unused functions removed.
The pp -> pd conversion should start from functions like ip_vs_out().... Timer per ns instead of a common timer in estimator.
Moved net compare to the end in "fast path"
__ip_vs_mutex remains global
PATCH SET
This patch set is based upon lvs-test-2.6 / v2.6.37-rc1 and depends upon IPVS sync patches
STATUS
untested protos
- sctp
- esp_ah
and SIP for IPv6
SUMMARY
include/net/ip_vs.h | 248 +++++++--- include/net/net_namespace.h | 2 + include/net/netns/ip_vs.h | 146 ++++++ net/netfilter/ipvs/ip_vs_app.c | 101 +++-- net/netfilter/ipvs/ip_vs_conn.c | 159 ++++--- net/netfilter/ipvs/ip_vs_core.c | 228 ++++++--- net/netfilter/ipvs/ip_vs_ctl.c | 826 ++++++++++++++++++------------- net/netfilter/ipvs/ip_vs_est.c | 131 ++++-- net/netfilter/ipvs/ip_vs_ftp.c | 56 ++- net/netfilter/ipvs/ip_vs_lblc.c | 66 +++- net/netfilter/ipvs/ip_vs_lblcr.c | 70 +++- net/netfilter/ipvs/ip_vs_nfct.c | 6 +- net/netfilter/ipvs/ip_vs_proto.c | 121 +++++- net/netfilter/ipvs/ip_vs_proto_ah_esp.c | 45 +- net/netfilter/ipvs/ip_vs_proto_sctp.c | 144 +++--- net/netfilter/ipvs/ip_vs_proto_tcp.c | 133 +++--- net/netfilter/ipvs/ip_vs_proto_udp.c | 102 ++-- net/netfilter/ipvs/ip_vs_sync.c | 422 +++++++++------- net/netfilter/xt_ipvs.c | 2 +- 19 files changed, 1960 insertions(+), 1048 deletions(-)
PATCH 1/22 IPVS: netns, add basic init per netns.
From: Hans Schillstrom <[email protected]>
Preparation for network name-space init, in this stage some empty functions exists.
In most files there is a check if it is root ns i.e. init_net if (!net_eq(net, &init_net))
return ...
this will be removed by the last patch, when enabling name-space.
*v3
ip_vs_conn.c merge error corrected.
net_ipvs #ifdef removed as sugested by Jan Engelhardt
--- include/net/ip_vs.h | 11 ++++++ include/net/net_namespace.h | 2 + include/net/netns/ip_vs.h | 26 +++++++++++++++ net/netfilter/ipvs/ip_vs_app.c | 32 +++++++++++++++--- net/netfilter/ipvs/ip_vs_conn.c | 34 +++++++++++++++++--- net/netfilter/ipvs/ip_vs_core.c | 63 ++++++++++++++++++++++++++++++++++++- net/netfilter/ipvs/ip_vs_ctl.c | 48 +++++++++++++++++++++++----- net/netfilter/ipvs/ip_vs_est.c | 20 +++++++++++- net/netfilter/ipvs/ip_vs_ftp.c | 34 ++++++++++++++++++-- net/netfilter/ipvs/ip_vs_lblc.c | 37 ++++++++++++++++++++-- net/netfilter/ipvs/ip_vs_lblcr.c | 38 ++++++++++++++++++++-- net/netfilter/ipvs/ip_vs_proto.c | 19 +++++++++++ net/netfilter/ipvs/ip_vs_sync.c | 28 +++++++++++++++++ 13 files changed, 357 insertions(+), 35 deletions(-) create mode 100644 include/net/netns/ip_vs.h
include/net/ip_vs.h +11 -0
@@ -28,6 +28,15 @@#if defined(CONFIG_NF_CONNTRACK ) || defined(CONFIG_NF_CONNTRACK_MODULE )#include <net/netfilter/nf_conntrack.h> #endif +#include <net/net_namespace.h> /* Netw namespace */ + +/* +* Generic access of ipvs struct +*/ +static inline struct netns_ipvs *net_ipvs (struct net * net) +{ +return net->ipvs; +}/* Connections' size value needed by ip_vs_ctl.c */ extern int ip_vs_conn_tab_size;
@@ -922,6 +931,8 @@ extern char ip_vs_backup_mcast_ifn[IP_VS_IFNAME_MAXLEN];extern int start_sync_thread (int state,char *mcast_ifn,__u8 syncid);extern int stop_sync_thread (int state);extern void ip_vs_sync_conn (struct ip_vs_conn *cp); +extern int ip_vs_sync_init (void ); +extern void ip_vs_sync_cleanup (void );/*
include/net/net_namespace.h +2 -0
@@ -20,6 +20,7 @@#include <net/netns/conntrack.h> #endif #include <net/netns/xfrm.h> +#include <net/netns/ip_vs.h> struct proc_dir_entry ;struct net_device ;
@@ -94,6 +95,7 @@ struct net {#ifdef CONFIG_XFRM struct netns_xfrm xfrm;#endif +struct netns_ipvs *ipvs; };
include/net/netns/ip_vs.h new file +26 -0
@@ -0,0 +1,26 @@ +/* +* ip_vs.h +* +* Created on: Nov 23, 2010 +* Author: hans +*/ + +#ifndef IP_VS_H_ +#define IP_VS_H_ + +#include <linux/list.h> +#include <linux/mutex.h> +#include <linux/list_nulls.h> +#include <linux/ip_vs.h> +#include <asm/atomic.h> +#include <linux/in.h> + +struct ip_vs_stats ; +struct ip_vs_sync_buff ; +struct ctl_table_header ; + +struct netns_ipvs { +int inc;/* Incarnation */ +}; + +#endif /* IP_VS_H_ */
net/netfilter/ipvs/ip_vs_app.c +26 -6
@@ -264,7 +264,7 @@ static inline void vs_fix_seq(const struct ip_vs_seq *vseq, struct tcphdr *th)* for all packets before most recent resized pkt seq. */ if (vseq->delta || vseq->previous_delta) { -if (after (seq, vseq->init_seq)) { +if (after (seq, vseq->init_seq)) { th->seq =htonl (seq + vseq->delta);IP_VS_DBG (9 ,"%s(): added delta (%d) to seq\n" , __func__, vseq->delta);
@@ -293,7 +293,7 @@ vs_fix_ack_seq(const struct ip_vs_seq *vseq, struct tcphdr *th)if (vseq->delta || vseq->previous_delta) {/* since ack_seq is the number of octet that is expected to receive next, so compare it with init_seq+delta */ -if (after (ack_seq, vseq->init_seq+vseq->delta)) { +if (after (ack_seq, vseq->init_seq+vseq->delta)) { th->ack_seq =htonl (ack_seq - vseq->delta);IP_VS_DBG (9 ,"%s(): subtracted delta " "(%d) from ack_seq\n" , __func__, vseq->delta);
@@ -569,15 +569,35 @@ static const struct file_operations ip_vs_app_fops = { };#endif -int __init ip_vs_app_init (void ) +static int __net_init __ip_vs_app_init (struct net *net) { -/* we will replace it with proc_net_ipvs_create() soon */ -proc_net_fops_create (&init_net,"ip_vs_app" ,0 , &ip_vs_app_fops); +if (!net_eq (net, &init_net))/* netns not enabled yet */ +return -EPERM ; + +proc_net_fops_create (net,"ip_vs_app" ,0 , &ip_vs_app_fops);return 0 ; } +static void __net_exit __ip_vs_app_cleanup(struct net *net) +{ +proc_net_remove (net,"ip_vs_app" ); +} + +static struct pernet_operations ip_vs_app_ops = { + .init = __ip_vs_app_init, + .exit = __ip_vs_app_cleanup, +}; + +int __init ip_vs_app_init (void ) +{ +int rv; + + rv =register_pernet_subsys (&ip_vs_app_ops); +return rv; +} +void ip_vs_app_cleanup (void ) { -proc_net_remove (&init_net,"ip_vs_app" ); +unregister_pernet_subsys (&ip_vs_app_ops); }
net/netfilter/ipvs/ip_vs_conn.c +28 -6
@@ -1201,11 +1201,36 @@ static void ip_vs_conn_flush(void) goto flush_again; } } +/* +* per netns init and exit +*/ +int __net_init __ip_vs_conn_init (struct net *net) +{ +if (!net_eq (net, &init_net))/* netns not enabled yet */ +return -EPERM ; +proc_net_fops_create (net,"ip_vs_conn" ,0 , &ip_vs_conn_fops); +proc_net_fops_create (net,"ip_vs_conn_sync" ,0 , &ip_vs_conn_sync_fops); +return 0 ; +} + +static void __net_exit __ip_vs_conn_cleanup(struct net *net) +{ +if (!net_eq (net, &init_net))/* netns not enabled yet */ +return ; + +proc_net_remove (net,"ip_vs_conn" ); +proc_net_remove (net,"ip_vs_conn_sync" ); +} +static struct pernet_operations ipvs_conn_ops = { + .init = __ip_vs_conn_init, + .exit = __ip_vs_conn_cleanup, +};int __init ip_vs_conn_init (void ) {int idx; +int retc;/* Compute size and mask */ ip_vs_conn_tab_size =1 << ip_vs_conn_tab_bits;
@@ -1243,24 +1268,21 @@ int __init ip_vs_conn_init(void)rwlock_init (&__ip_vs_conntbl_lock_array[idx].l); } -proc_net_fops_create (&init_net,"ip_vs_conn" ,0 , &ip_vs_conn_fops); -proc_net_fops_create (&init_net,"ip_vs_conn_sync" ,0 , &ip_vs_conn_sync_fops); + retc =register_pernet_subsys (&ipvs_conn_ops);/* calculate the random value for connection hash */ get_random_bytes (&ip_vs_conn_rnd,sizeof (ip_vs_conn_rnd)); -return 0 ; +return retc; } -void ip_vs_conn_cleanup (void ) { +unregister_pernet_subsys (&ipvs_conn_ops);/* flush all the connection entries first */ ip_vs_conn_flush ();/* Release the empty cache */ kmem_cache_destroy (ip_vs_conn_cachep); -proc_net_remove (&init_net,"ip_vs_conn" ); -proc_net_remove (&init_net,"ip_vs_conn_sync" );vfree (ip_vs_conn_tab); }
net/netfilter/ipvs/ip_vs_core.c +61 -2
119 lines not on this page · raw message
net/netfilter/ipvs/ip_vs_ctl.c +39 -9
66 lines not on this page · raw message
net/netfilter/ipvs/ip_vs_est.c +19 -1
@@ -157,13 +157,31 @@ void ip_vs_zero_estimator(struct ip_vs_stats *stats) est->outbps =0 ; } +static int __net_init __ip_vs_estimator_init (struct net *net) +{ +if (!net_eq (net, &init_net))/* netns not enabled yet */ +return -EPERM ; + +return 0 ; +} + +static struct pernet_operations ip_vs_app_ops = { + .init = __ip_vs_estimator_init, +}; +int __init ip_vs_estimator_init (void ) { +int rv; + + rv =register_pernet_subsys (&ip_vs_app_ops); +if (rv <0 ) +return rv;mod_timer (&est_timer, jiffies +2 *HZ ); -return 0 ; +return rv; }void ip_vs_estimator_cleanup (void ) {del_timer_sync (&est_timer); +unregister_pernet_subsys (&ip_vs_app_ops); }
net/netfilter/ipvs/ip_vs_ftp.c +30 -4
@@ -399,15 +399,17 @@ static struct ip_vs_app ip_vs_ftp = { .pkt_in = ip_vs_ftp_in, }; -/* -* ip_vs_ftp initialization +* per netns ip_vs_ftp initialization */ -static int __init ip_vs_ftp_init (void ) +static int __net_init __ip_vs_ftp_init (struct net *net) {int i, ret;struct ip_vs_app *app = &ip_vs_ftp; +if (!net_eq (net, &init_net))/* netns not enabled yet */ +return -EPERM ; + ret =register_ip_vs_app (app);if (ret)return ret;
@@ -427,14 +429,38 @@ static int __init ip_vs_ftp_init(void)return ret; } +/* +* netns exit +*/ +static void __ip_vs_ftp_exit (struct net *net) +{ +struct ip_vs_app *app = &ip_vs_ftp; + +if (!net_eq (net, &init_net))/* netns not enabled yet */ +return ; + +unregister_ip_vs_app (app); +} + +static struct pernet_operations ip_vs_ftp_ops = { + .init = __ip_vs_ftp_init, + .exit = __ip_vs_ftp_exit, +}; +int __init ip_vs_ftp_init (void ) +{ +int rv; + + rv =register_pernet_subsys (&ip_vs_ftp_ops); +return rv; +}/* * ip_vs_ftp finish. */ static void __exit ip_vs_ftp_exit(void) { -unregister_ip_vs_app (&ip_vs_ftp); +unregister_pernet_subsys (&ip_vs_ftp_ops); }
net/netfilter/ipvs/ip_vs_lblc.c +34 -3
@@ -543,23 +543,54 @@ static struct ip_vs_scheduler ip_vs_lblc_scheduler = .schedule = ip_vs_lblc_schedule, }; +/* +* per netns init. +*/ +static int __net_init __ip_vs_lblc_init (struct net *net) +{ +if (!net_eq (net, &init_net))/* netns not enabled yet */ +return -EPERM ; + + sysctl_header =register_net_sysctl_table (net, net_vs_ctl_path, + vs_vars_table); +if (!sysctl_header) +return -ENOMEM ; + +return 0 ; +} + +static void __net_exit __ip_vs_lblc_exit(struct net *net) +{ +if (!net_eq (net, &init_net))/* netns not enabled yet */ +return ; + +unregister_net_sysctl_table (sysctl_header); +} + +static struct pernet_operations ip_vs_lblc_ops = { + .init = __ip_vs_lblc_init, + .exit = __ip_vs_lblc_exit, +};static int __init ip_vs_lblc_init (void ) {int ret; - sysctl_header =register_sysctl_paths (net_vs_ctl_path, vs_vars_table); + ret =register_pernet_subsys (&ip_vs_lblc_ops); +if (ret) +return ret; + ret =register_ip_vs_scheduler (&ip_vs_lblc_scheduler);if (ret) -unregister_sysctl_table (sysctl_header); +unregister_pernet_subsys (&ip_vs_lblc_ops);return ret; } static void __exit ip_vs_lblc_cleanup(void) { -unregister_sysctl_table (sysctl_header);unregister_ip_vs_scheduler (&ip_vs_lblc_scheduler); +unregister_pernet_subsys (&ip_vs_lblc_ops); }
net/netfilter/ipvs/ip_vs_lblcr.c +34 -4
@@ -744,23 +744,53 @@ static struct ip_vs_scheduler ip_vs_lblcr_scheduler = .schedule = ip_vs_lblcr_schedule, }; +/* +* per netns init. +*/ +static int __net_init __ip_vs_lblcr_init (struct net *net) +{ +if (!net_eq (net, &init_net))/* netns not enabled yet */ +return -EPERM ; + + sysctl_header =register_net_sysctl_table (net, net_vs_ctl_path, + vs_vars_table); +if (!sysctl_header) +return -ENOMEM ; + +return 0 ; +} + +static void __net_exit __ip_vs_lblcr_exit(struct net *net) +{ +if (!net_eq (net, &init_net))/* netns not enabled yet */ +return ; + +unregister_net_sysctl_table (sysctl_header); +} + +static struct pernet_operations ip_vs_lblcr_ops = { + .init = __ip_vs_lblcr_init, + .exit = __ip_vs_lblcr_exit, +};static int __init ip_vs_lblcr_init (void ) {int ret; - sysctl_header =register_sysctl_paths (net_vs_ctl_path, vs_vars_table); + ret =register_pernet_subsys (&ip_vs_lblcr_ops); +if (ret) +return ret; + ret =register_ip_vs_scheduler (&ip_vs_lblcr_scheduler);if (ret) -unregister_sysctl_table (sysctl_header); +unregister_pernet_subsys (&ip_vs_lblcr_ops);return ret; } - static void __exit ip_vs_lblcr_cleanup(void) { -unregister_sysctl_table (sysctl_header);unregister_ip_vs_scheduler (&ip_vs_lblcr_scheduler); +unregister_pernet_subsys (&ip_vs_lblcr_ops); }
net/netfilter/ipvs/ip_vs_proto.c +19 -0
@@ -236,6 +236,23 @@ ip_vs_tcpudp_debug_packet(int af, struct ip_vs_protocol *pp,ip_vs_tcpudp_debug_packet_v4 (pp, skb, offset, msg); } +/* +* per network name-space init +*/ +static int __net_init __ip_vs_protocol_init (struct net *net) +{ +return 0 ; +} + +static void __net_exit __ip_vs_protocol_cleanup(struct net *net) +{ +/* empty */ +} + +static struct pernet_operations ipvs_proto_ops = { + .init = __ip_vs_protocol_init, + .exit = __ip_vs_protocol_cleanup, +};int __init ip_vs_protocol_init (void ) {
@@ -265,6 +282,7 @@ int __init ip_vs_protocol_init(void)REGISTER_PROTOCOL (&ip_vs_protocol_esp);#endif pr_info ("Registered protocols (%s)\n" , &protocols[2 ]); +return register_pernet_subsys (&ipvs_proto_ops);return 0 ; }
@@ -275,6 +293,7 @@ void ip_vs_protocol_cleanup(void)struct ip_vs_protocol *pp;int i; +unregister_pernet_subsys (&ipvs_proto_ops);/* unregister all the ipvs protocols */ for (i =0 ; i <IP_VS_PROTO_TAB_SIZE ; i++) {while ((pp = ip_vs_proto_table[i]) !=NULL )
net/netfilter/ipvs/ip_vs_sync.c +28 -0
@@ -1639,3 +1639,31 @@ int stop_sync_thread(int state)return 0 ; } + +/* +* Initialize data struct for each netns +*/ +static int __net_init __ip_vs_sync_init (struct net *net) +{ +return 0 ; +} + +static void __ip_vs_sync_cleanup (struct net *net) +{ +return ; +} +static struct pernet_operations ipvs_sync_ops = { + .init = __ip_vs_sync_init, + .exit = __ip_vs_sync_cleanup, +}; + + +int __init ip_vs_sync_init (void ) +{ +return register_pernet_subsys (&ipvs_sync_ops); +} + +void __exit ip_vs_sync_cleanup(void) +{ +unregister_pernet_subsys (&ipvs_sync_ops); +}
--
1.7.2.3
PATCH 2/22 IPVS: netns to services part 1
In reply to [email protected]From: Hans Schillstrom <[email protected]>
Services hash tables got netns ptr a hash arg, While Real Servers (rs) has been moved to ipvs struct. Two new inline functions added to get net ptr from skb.
Since ip_vs is called from different contexts there is two places to dig for the net ptr skb->dev or skb->sk this is handled in skb_net() and skb_sknet()
Global functions, ip_vs_service_get() ip_vs_lookup_real_service() etc have got struct net *net as first param.
If possible get net ptr skb etc,
- if not &init_net is used at this early stage of patching.
ip_vs_ctl.c procfs not ready for netns yet.
*v3
Comments by Julian
- __ip_vs_service_find and __ip_vs_svc_fwm_find are fast path, net_eq(svc->net, net) so the check is at the end now.
- net = skb_net(skb) in ip_vs_out moved after check for skb_dst.
--- include/net/ip_vs.h | 62 +++++++++- include/net/netns/ip_vs.h | 9 ++ net/netfilter/ipvs/ip_vs_conn.c | 2 +- net/netfilter/ipvs/ip_vs_core.c | 4 +- net/netfilter/ipvs/ip_vs_ctl.c | 224 +++++++++++++++++++-------------- net/netfilter/ipvs/ip_vs_proto_sctp.c | 5 +- net/netfilter/ipvs/ip_vs_proto_tcp.c | 5 +- net/netfilter/ipvs/ip_vs_proto_udp.c | 5 +- net/netfilter/ipvs/ip_vs_sync.c | 2 +- 9 files changed, 207 insertions(+), 111 deletions(-)
include/net/ip_vs.h +57 -5
@@ -37,6 +37,57 @@ static inline struct netns_ipvs * net_ipvs(struct net* net) {return net->ipvs; } +/* +* Get net ptr from skb in traffic cases +* use skb_sknet when call is from userland (ioctl or netlink) +*/ +static inline struct net *skb_net (struct sk_buff *skb) { +#ifdef CONFIG_NET_NS +#ifdef CONFIG_IP_VS_DEBUG +/* +* This is used for debug only. +* Start with the most likely hit +* End with BUG +*/ +if (likely (skb->dev && skb->dev->nd_net)) +return dev_net (skb->dev); +if (skb_dst (skb)->dev) +return dev_net (skb_dst (skb)->dev); +WARN (skb->sk,"Maybe skb_sknet should be used instead in %s() line:%d\n" , + __func__, __LINE__); +if (likely (skb->sk && skb->sk->sk_net)) +return sock_net (skb->sk); +pr_err ("There is no net ptr to find in the skb in %s() line:%d\n" , + __func__, __LINE__); +BUG (); +#else +return dev_net (skb->dev ? :skb_dst (skb)->dev); +#endif +#else +return &init_net; +#endif +} + +static inline struct net *skb_sknet (struct sk_buff *skb) { +#ifdef CONFIG_NET_NS +#ifdef CONFIG_IP_VS_DEBUG +/* Start with the most likely hit */ +if (likely (skb->sk && skb->sk->sk_net)) +return sock_net (skb->sk); +WARN (skb->dev,"Maybe skb_net should be used instead in %s() line:%d\n" , + __func__, __LINE__); +if (likely (skb->dev && skb->dev->nd_net)) +return dev_net (skb->dev); +pr_err ("There is no net ptr to find in the skb in %s() line:%d\n" , + __func__, __LINE__); +BUG (); +#else +return sock_net (skb->sk); +#endif +#else +return &init_net; +#endif +}/* Connections' size value needed by ip_vs_ctl.c */ extern int ip_vs_conn_tab_size;
@@ -496,6 +547,7 @@ struct ip_vs_service {unsigned flags;/* service status flags */ unsigned timeout;/* persistent timeout in ticks */ __be32 netmask;/* grouping granularity */ +struct net *net;struct list_head destinations;/* real server d-linked list */ __u32 num_dests;/* number of servers */
@@ -896,7 +948,7 @@ extern int sysctl_ip_vs_sync_ver;extern void ip_vs_sync_switch_mode (int mode);extern struct ip_vs_service * -ip_vs_service_get (int af,__u32 fwmark,__u16 protocol, +ip_vs_service_get (struct net *net,int af,__u32 fwmark,__u16 protocol,const union nf_inet_addr *vaddr,__be16 vport);static inline void ip_vs_service_put (struct ip_vs_service *svc)
@@ -905,7 +957,7 @@ static inline void ip_vs_service_put(struct ip_vs_service *svc) }extern struct ip_vs_dest * -ip_vs_lookup_real_service (int af,__u16 protocol, +ip_vs_lookup_real_service (struct net *net,int af,__u16 protocol,const union nf_inet_addr *daddr,__be16 dport);extern int ip_vs_use_count_inc (void );
@@ -913,9 +965,9 @@ extern void ip_vs_use_count_dec(void);extern int ip_vs_control_init (void );extern void ip_vs_control_cleanup (void );extern struct ip_vs_dest * -ip_vs_find_dest (int af,const union nf_inet_addr *daddr,__be16 dport, -const union nf_inet_addr *vaddr,__be16 vport,__u16 protocol, -__u32 fwmark); +ip_vs_find_dest (struct net *net,int af,const union nf_inet_addr *daddr, +__be16 dport,const union nf_inet_addr *vaddr,__be16 vport, +__u16 protocol,__u32 fwmark);extern struct ip_vs_dest *ip_vs_try_bind_dest (struct ip_vs_conn *cp);
include/net/netns/ip_vs.h +9 -0
@@ -21,6 +21,15 @@ struct ctl_table_header;struct netns_ipvs {int inc;/* Incarnation */ +/* +* Hash table: for real service lookups +*/ +#define IP_VS_RTAB_BITS 4 +#define IP_VS_RTAB_SIZE (1 << IP_VS_RTAB_BITS) +#define IP_VS_RTAB_MASK (IP_VS_RTAB_SIZE - 1) + +struct list_head rs_table[IP_VS_RTAB_SIZE ]; + };#endif /* IP_VS_H_ */
net/netfilter/ipvs/ip_vs_conn.c +1 -1
@@ -611,7 +611,7 @@ struct ip_vs_dest *ip_vs_try_bind_dest(struct ip_vs_conn *cp)struct ip_vs_dest *dest;if ((cp) && (!cp->dest)) { - dest =ip_vs_find_dest (cp->af, &cp->daddr, cp->dport, + dest =ip_vs_find_dest (&init_net, cp->af, &cp->daddr, cp->dport, &cp->vaddr, cp->vport, cp->protocol, cp->fwmark);ip_vs_bind_dest (cp, dest);
net/netfilter/ipvs/ip_vs_core.c +3 -1
@@ -1031,6 +1031,7 @@ drop:static unsigned int ip_vs_out (unsigned int hooknum,struct sk_buff *skb,int af) { +struct net *net =NULL ;struct ip_vs_iphdr iph;struct ip_vs_protocol *pp;struct ip_vs_conn *cp;
@@ -1054,6 +1055,7 @@ ip_vs_out(unsigned int hooknum, struct sk_buff *skb, int af)if (unlikely (!skb_dst (skb)))return NF_ACCEPT ; + net =skb_net (skb);ip_vs_fill_iphdr (af,skb_network_header (skb), &iph);#ifdef CONFIG_IP_VS_IPV6 if (af ==AF_INET6 ) {
@@ -1119,7 +1121,7 @@ ip_vs_out(unsigned int hooknum, struct sk_buff *skb, int af) sizeof(_ports), _ports);if (pptr ==NULL )return NF_ACCEPT ;/* Not for me */ -if (ip_vs_lookup_real_service (af, iph.protocol, +if (ip_vs_lookup_real_service (net, af, iph.protocol, &iph.saddr, pptr[0 ])) {/*
net/netfilter/ipvs/ip_vs_ctl.c +127 -97
713 lines not on this page · raw message
net/netfilter/ipvs/ip_vs_proto_sctp.c +3 -2
@@ -12,6 +12,7 @@ static int sctp_conn_schedule(int af, struct sk_buff *skb, struct ip_vs_protocol *pp, int *verdict, struct ip_vs_conn **cpp) { + struct net *net;struct ip_vs_service *svc;sctp_chunkhdr_t _schunkh, *sch;sctp_sctphdr_t *sh, _sctph;
@@ -27,9 +28,9 @@ sctp_conn_schedule(int af, struct sk_buff *skb, struct ip_vs_protocol *pp, sizeof(_schunkh), &_schunkh);if (sch ==NULL )return 0 ; - + net =skb_net (skb);if ((sch->type ==SCTP_CID_INIT ) && - (svc =ip_vs_service_get (af, skb->mark, iph.protocol, + (svc =ip_vs_service_get (net, af, skb->mark, iph.protocol, &iph.daddr, sh->dest))) {int ignored;
net/netfilter/ipvs/ip_vs_proto_tcp.c +3 -2
@@ -31,6 +31,7 @@ static int tcp_conn_schedule(int af, struct sk_buff *skb, struct ip_vs_protocol *pp, int *verdict, struct ip_vs_conn **cpp) { + struct net *net;struct ip_vs_service *svc;struct tcphdr _tcph, *th;struct ip_vs_iphdr iph;
@@ -42,10 +43,10 @@ tcp_conn_schedule(int af, struct sk_buff *skb, struct ip_vs_protocol *pp, *verdict =NF_DROP ;return 0 ; } - + net =skb_net (skb);/* No !th->ack check to allow scheduling on SYN+ACK for Active FTP */ if (th->syn && - (svc =ip_vs_service_get (af, skb->mark, iph.protocol, &iph.daddr, + (svc =ip_vs_service_get (net, af, skb->mark, iph.protocol, &iph.daddr, th->dest))) {int ignored;
net/netfilter/ipvs/ip_vs_proto_udp.c +3 -2
@@ -31,6 +31,7 @@ static int udp_conn_schedule(int af, struct sk_buff *skb, struct ip_vs_protocol *pp, int *verdict, struct ip_vs_conn **cpp) { + struct net *net;struct ip_vs_service *svc;struct udphdr _udph, *uh;struct ip_vs_iphdr iph;
@@ -42,8 +43,8 @@ udp_conn_schedule(int af, struct sk_buff *skb, struct ip_vs_protocol *pp, *verdict =NF_DROP ;return 0 ; } - - svc =ip_vs_service_get (af, skb->mark, iph.protocol, + net =skb_net (skb); + svc =ip_vs_service_get (net, af, skb->mark, iph.protocol, &iph.daddr, uh->dest);if (svc) {int ignored;
net/netfilter/ipvs/ip_vs_sync.c +1 -1
@@ -749,7 +749,7 @@ static void ip_vs_proc_conn(struct ip_vs_conn_param *param, unsigned flags,* If it is not found the connection will remain unbound * but still handled. */ - dest =ip_vs_find_dest (type, daddr, dport, param->vaddr, + dest =ip_vs_find_dest (&init_net, type, daddr, dport, param->vaddr, param->vport, protocol, fwmark);/* Set the approprite ativity flag */
Signature · 1 line
1.7.2.3
PATCH 3/22 IPVS: netns awarness to lblcr sheduler
In reply to [email protected]From: Hans Schillstrom <[email protected]>
var sysctl_ip_vs_lblcr_expiration moved to ipvs struct as
sysctl_lblcr_expiration
procfs updated to handle this.
--- include/net/netns/ip_vs.h | 4 +++ net/netfilter/ipvs/ip_vs_lblcr.c | 52 +++++++++++++++++++++++++------------ 2 files changed, 39 insertions(+), 17 deletions(-)
include/net/netns/ip_vs.h +4 -0
@@ -30,6 +30,10 @@ struct netns_ipvs {struct list_head rs_table[IP_VS_RTAB_SIZE ]; +/* ip_vs_lblcr */ +int sysctl_lblcr_expiration; +struct ctl_table_header *lblcr_ctl_header; + struct ctl_table *lblcr_ctl_table; };#endif /* IP_VS_H_ */
net/netfilter/ipvs/ip_vs_lblcr.c +35 -17
107 lines not on this page · raw message
Signature · 1 line
1.7.2.3
PATCH 4/22 IPVS: netns awarness to lblc sheduler
In reply to [email protected]From: Hans Schillstrom <[email protected]>
var sysctl_ip_vs_lblc_expiration moved to ipvs struct as
sysctl_lblc_expiration
procfs updated to handle this.
--- include/net/netns/ip_vs.h | 4 +++ net/netfilter/ipvs/ip_vs_lblc.c | 49 ++++++++++++++++++++++++++------------ 2 files changed, 37 insertions(+), 16 deletions(-)
include/net/netns/ip_vs.h +4 -0
@@ -30,6 +30,10 @@ struct netns_ipvs {struct list_head rs_table[IP_VS_RTAB_SIZE ]; +/* ip_vs_lblc */ +int sysctl_lblc_expiration; +struct ctl_table_header *lblc_ctl_header; +struct ctl_table *lblc_ctl_table;/* ip_vs_lblcr */ int sysctl_lblcr_expiration;struct ctl_table_header *lblcr_ctl_header;
net/netfilter/ipvs/ip_vs_lblc.c +33 -16
98 lines not on this page · raw message
Signature · 1 line
1.7.2.3
PATCH 5/22 IPVS: netns, prepare protocol
In reply to [email protected]From: Hans Schillstrom <[email protected]>
Add support for protocol data per name-space.
in struct ip_vs_protocol, appcnt will be removed when all protos are modified for network name-space.
This patch causes warnings of unused functions, they will be used when next patch will be applied.
--- include/net/ip_vs.h | 20 +++++++++++- include/net/netns/ip_vs.h | 3 ++ net/netfilter/ipvs/ip_vs_proto.c | 66 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 88 insertions(+), 1 deletions(-)
include/net/ip_vs.h +19 -1
@@ -350,6 +350,7 @@ struct iphdr;struct ip_vs_conn ;struct ip_vs_app ;struct sk_buff ; +struct ip_vs_proto_data ;struct ip_vs_protocol {struct ip_vs_protocol *next;
@@ -364,6 +365,10 @@ struct ip_vs_protocol {void (*exit)(struct ip_vs_protocol *pp); +void (*init_netns)(struct net *net,struct ip_vs_proto_data *pd); + +void (*exit_netns)(struct net *net,struct ip_vs_proto_data *pd); +int (*conn_schedule)(int af,struct sk_buff *skb,struct ip_vs_protocol *pp,int *verdict,struct ip_vs_conn **cpp);
@@ -415,7 +420,20 @@ struct ip_vs_protocol {int (*set_state_timeout)(struct ip_vs_protocol *pp,char *sname,int to); }; -extern struct ip_vs_protocol *ip_vs_proto_get (unsigned short proto); +/* +* protocol data per netns +*/ +struct ip_vs_proto_data { +struct ip_vs_proto_data *next; +struct ip_vs_protocol *pp; +int *timeout_table;/* protocol timeout table */ +atomic_t appcnt;/* counter of proto app incs. */ +struct tcp_states_t *tcp_state_table; +}; + +extern struct ip_vs_protocol *ip_vs_proto_get (unsigned short proto); +extern struct ip_vs_proto_data *ip_vs_proto_data_get (struct net *net, +unsigned short proto);struct ip_vs_conn_param {const union nf_inet_addr *caddr;
include/net/netns/ip_vs.h +3 -0
@@ -29,6 +29,9 @@ struct netns_ipvs {#define IP_VS_RTAB_MASK (IP_VS_RTAB_SIZE - 1)struct list_head rs_table[IP_VS_RTAB_SIZE ]; +/* ip_vs_proto */ +#define IP_VS_PROTO_TAB_SIZE 32/* must be power of 2 */ +struct ip_vs_proto_data *proto_data_table[IP_VS_PROTO_TAB_SIZE ];/* ip_vs_lblc */ int sysctl_lblc_expiration;
net/netfilter/ipvs/ip_vs_proto.c +66 -0
84 lines not on this page · raw message
Signature · 1 line
1.7.2.3
PATCH 6/22 IPVS: netns preparation for proto_tcp
In reply to [email protected]From: Hans Schillstrom <[email protected]>
In this phase (one), all local vars will be moved to ipvs struct.
Remaining work, add param struct net *net to a couple of functions that is common for all protos and use all ip_vs_proto_data
*v3
Removed unused function as sugested by Simon
--- include/net/ip_vs.h | 6 +- include/net/netns/ip_vs.h | 8 +++ net/netfilter/ipvs/ip_vs_ftp.c | 8 ++- net/netfilter/ipvs/ip_vs_proto.c | 13 ++++- net/netfilter/ipvs/ip_vs_proto_tcp.c | 101 ++++++++++++++++++---------------- 5 files changed, 83 insertions(+), 53 deletions(-)
include/net/ip_vs.h +3 -3
@@ -41,7 +41,7 @@ static inline struct netns_ipvs * net_ipvs(struct net* net)* Get net ptr from skb in traffic cases * use skb_sknet when call is from userland (ioctl or netlink) */ -static inline struct net *skb_net (struct sk_buff *skb) { +static inline struct net *skb_net (const struct sk_buff *skb) {#ifdef CONFIG_NET_NS #ifdef CONFIG_IP_VS_DEBUG /*
@@ -68,7 +68,7 @@ static inline struct net *skb_net(struct sk_buff *skb) {#endif } -static inline struct net *skb_sknet (struct sk_buff *skb) { +static inline struct net *skb_sknet (const struct sk_buff *skb) {#ifdef CONFIG_NET_NS #ifdef CONFIG_IP_VS_DEBUG /* Start with the most likely hit */
@@ -805,7 +805,7 @@ extern void ip_vs_conn_expire_now(struct ip_vs_conn *cp);extern const char *ip_vs_state_name (__u16 proto,int state); -extern void ip_vs_tcp_conn_listen (struct ip_vs_conn *cp); +extern void ip_vs_tcp_conn_listen (struct net *net,struct ip_vs_conn *cp);extern int ip_vs_check_template (struct ip_vs_conn *ct);extern void ip_vs_random_dropentry (void );extern int ip_vs_conn_init (void );
include/net/netns/ip_vs.h +8 -0
@@ -32,6 +32,14 @@ struct netns_ipvs {/* ip_vs_proto */ #define IP_VS_PROTO_TAB_SIZE 32/* must be power of 2 */ struct ip_vs_proto_data *proto_data_table[IP_VS_PROTO_TAB_SIZE ]; +/* ip_vs_proto_tcp */ +#ifdef CONFIG_IP_VS_PROTO_TCP +#define TCP_APP_TAB_BITS 4 +#define TCP_APP_TAB_SIZE (1 << TCP_APP_TAB_BITS) +#define TCP_APP_TAB_MASK (TCP_APP_TAB_SIZE - 1) +struct list_head tcp_apps[TCP_APP_TAB_SIZE ]; +spinlock_t tcp_app_lock; +#endif /* ip_vs_lblc */ int sysctl_lblc_expiration;
net/netfilter/ipvs/ip_vs_ftp.c +6 -2
@@ -157,6 +157,7 @@ static int ip_vs_ftp_out(struct ip_vs_app *app, struct ip_vs_conn *cp,int ret =0 ;enum ip_conntrack_info ctinfo;struct nf_conn *ct; +struct net *net;#ifdef CONFIG_IP_VS_IPV6 /* This application helper doesn't work with IPv6 yet,
@@ -257,8 +258,9 @@ static int ip_vs_ftp_out(struct ip_vs_app *app, struct ip_vs_conn *cp,* would be adjusted twice. */ + net =skb_net (skb); cp->app_data =NULL ; -ip_vs_tcp_conn_listen (n_cp); +ip_vs_tcp_conn_listen (net, n_cp);ip_vs_conn_put (n_cp);return ret; }
@@ -287,6 +289,7 @@ static int ip_vs_ftp_in(struct ip_vs_app *app, struct ip_vs_conn *cp,union nf_inet_addr to;__be16 port;struct ip_vs_conn *n_cp; +struct net *net;#ifdef CONFIG_IP_VS_IPV6 /* This application helper doesn't work with IPv6 yet,
@@ -378,7 +381,8 @@ static int ip_vs_ftp_in(struct ip_vs_app *app, struct ip_vs_conn *cp,/* * Move tunnel to listen state */ -ip_vs_tcp_conn_listen (n_cp); + net =skb_net (skb); +ip_vs_tcp_conn_listen (net, n_cp);ip_vs_conn_put (n_cp);return 1 ;
net/netfilter/ipvs/ip_vs_proto.c +12 -1
@@ -307,12 +307,23 @@ ip_vs_tcpudp_debug_packet(int af, struct ip_vs_protocol *pp,*/ static int __net_init __ip_vs_protocol_init (struct net *net) { +#ifdef CONFIG_IP_VS_PROTO_TCP +register_ip_vs_proto_netns (net, &ip_vs_protocol_tcp); +#endif return 0 ; } static void __net_exit __ip_vs_protocol_cleanup(struct net *net) { -/* empty */ +struct netns_ipvs *ipvs =net_ipvs (net); +struct ip_vs_proto_data *pd; +int i; + +/* unregister all the ipvs proto data for this netns */ +for (i =0 ; i <IP_VS_PROTO_TAB_SIZE ; i++) { +while ((pd = ipvs->proto_data_table[i]) !=NULL ) +unregister_ip_vs_proto_netns (net, pd); + } }static struct pernet_operations ipvs_proto_ops = {
net/netfilter/ipvs/ip_vs_proto_tcp.c +54 -47
216 lines not on this page · raw message
Signature · 1 line
1.7.2.3
PATCH 7/22 IPVS: netns preparation for proto_udp
In reply to [email protected]From: Hans Schillstrom <[email protected]>
In this phase (one), all local vars will be moved to ipvs struct.
Remaining work, add param struct net *net to a couple of functions that is common for all protos and use ip_vs_proto_data
*v3
Removed unused function set_state_timeout()
--- include/net/netns/ip_vs.h | 8 +++ net/netfilter/ipvs/ip_vs_proto.c | 3 + net/netfilter/ipvs/ip_vs_proto_udp.c | 86 +++++++++++++++++----------------- 3 files changed, 54 insertions(+), 43 deletions(-)
include/net/netns/ip_vs.h +8 -0
@@ -40,6 +40,14 @@ struct netns_ipvs {struct list_head tcp_apps[TCP_APP_TAB_SIZE ];spinlock_t tcp_app_lock;#endif +/* ip_vs_proto_udp */ +#ifdef CONFIG_IP_VS_PROTO_UDP +#define UDP_APP_TAB_BITS 4 +#define UDP_APP_TAB_SIZE (1 << UDP_APP_TAB_BITS) +#define UDP_APP_TAB_MASK (UDP_APP_TAB_SIZE - 1) +struct list_head udp_apps[UDP_APP_TAB_SIZE ]; +spinlock_t udp_app_lock; +#endif /* ip_vs_lblc */ int sysctl_lblc_expiration;
net/netfilter/ipvs/ip_vs_proto.c +3 -0
@@ -310,6 +310,9 @@ static int __net_init __ip_vs_protocol_init(struct net *net)#ifdef CONFIG_IP_VS_PROTO_TCP register_ip_vs_proto_netns (net, &ip_vs_protocol_tcp);#endif +#ifdef CONFIG_IP_VS_PROTO_UDP +register_ip_vs_proto_netns (net, &ip_vs_protocol_udp); +#endif return 0 ; }
net/netfilter/ipvs/ip_vs_proto_udp.c +43 -43
177 lines not on this page · raw message
Signature · 1 line
1.7.2.3
PATCH 8/22 IPVS: netns preparation for proto_sctp
In reply to [email protected]From: Hans Schillstrom <[email protected]>
In this phase (one), all local vars will be moved to ipvs struct.
Remaining work, add param struct net *net to a couple of functions that is common for all protos and use ip_vs_proto_data
*v3
Removed unuset function set_state_timeout()
--- include/net/netns/ip_vs.h | 10 +++- net/netfilter/ipvs/ip_vs_proto.c | 3 + net/netfilter/ipvs/ip_vs_proto_sctp.c | 121 ++++++++++++++++----------------- 3 files changed, 70 insertions(+), 64 deletions(-)
include/net/netns/ip_vs.h +9 -1
@@ -48,7 +48,15 @@ struct netns_ipvs {struct list_head udp_apps[UDP_APP_TAB_SIZE ];spinlock_t udp_app_lock;#endif - +/* ip_vs_proto_sctp */ +#ifdef CONFIG_IP_VS_PROTO_SCTP +#define SCTP_APP_TAB_BITS 4 +#define SCTP_APP_TAB_SIZE (1 << SCTP_APP_TAB_BITS) +#define SCTP_APP_TAB_MASK (SCTP_APP_TAB_SIZE - 1) +/* Hash table for SCTP application incarnations */ +struct list_head sctp_apps[SCTP_APP_TAB_SIZE ]; +spinlock_t sctp_app_lock; +#endif /* ip_vs_lblc */ int sysctl_lblc_expiration;struct ctl_table_header *lblc_ctl_header;
net/netfilter/ipvs/ip_vs_proto.c +3 -0
@@ -313,6 +313,9 @@ static int __net_init __ip_vs_protocol_init(struct net *net)#ifdef CONFIG_IP_VS_PROTO_UDP register_ip_vs_proto_netns (net, &ip_vs_protocol_udp);#endif +#ifdef CONFIG_IP_VS_PROTO_SCTP +register_ip_vs_proto_netns (net, &ip_vs_protocol_sctp); +#endif return 0 ; }
net/netfilter/ipvs/ip_vs_proto_sctp.c +58 -63
204 lines not on this page · raw message
Signature · 1 line
1.7.2.3
PATCH 9/22 IPVS: netns preparation for proto_ah_esp
In reply to [email protected]From: Hans Schillstrom <[email protected]>
In this phase (one), all local vars will be moved to ipvs struct.
Remaining work, add param struct net *net to a couple of functions that common for all protos.
--- net/netfilter/ipvs/ip_vs_proto.c | 6 ++++++ net/netfilter/ipvs/ip_vs_proto_ah_esp.c | 20 ++++---------------- 2 files changed, 10 insertions(+), 16 deletions(-)
net/netfilter/ipvs/ip_vs_proto.c +6 -0
@@ -316,6 +316,12 @@ static int __net_init __ip_vs_protocol_init(struct net *net)#ifdef CONFIG_IP_VS_PROTO_SCTP register_ip_vs_proto_netns (net, &ip_vs_protocol_sctp);#endif +#ifdef CONFIG_IP_VS_PROTO_AH +register_ip_vs_proto_netns (net, &ip_vs_protocol_ah); +#endif +#ifdef CONFIG_IP_VS_PROTO_ESP +register_ip_vs_proto_netns (net, &ip_vs_protocol_esp); +#endif return 0 ; }
net/netfilter/ipvs/ip_vs_proto_ah_esp.c +4 -16
@@ -117,26 +117,14 @@ ah_esp_conn_schedule(int af, struct sk_buff *skb, struct ip_vs_protocol *pp,return 0 ; } -static void ah_esp_init (struct ip_vs_protocol *pp) -{ -/* nothing to do now */ -} - - -static void ah_esp_exit (struct ip_vs_protocol *pp) -{ -/* nothing to do now */ -} - -#ifdef CONFIG_IP_VS_PROTO_AH struct ip_vs_protocol ip_vs_protocol_ah = { .name ="AH" , .protocol =IPPROTO_AH , .num_states =1 , .dont_defrag =1 , - .init = ah_esp_init, - .exit = ah_esp_exit, + .init =NULL , + .exit =NULL , .conn_schedule = ah_esp_conn_schedule, .conn_in_get = ah_esp_conn_in_get, .conn_out_get = ah_esp_conn_out_get,
@@ -159,8 +147,8 @@ struct ip_vs_protocol ip_vs_protocol_esp = { .protocol = IPPROTO_ESP, .num_states = 1, .dont_defrag = 1, - .init = ah_esp_init, - .exit = ah_esp_exit, + .init = NULL, + .exit = NULL, .conn_schedule = ah_esp_conn_schedule, .conn_in_get = ah_esp_conn_in_get, .conn_out_get = ah_esp_conn_out_get,
Signature · 1 line
1.7.2.3
PATCH 10/22 IPVS: netns, use ip_vs_proto_data as param.
In reply to [email protected]From: Hans Schillstrom <[email protected]>
ip_vs_protocol *pp is replaced by ip_vs_proto_data *pd in function call in ip_vs_protocol struct i.e. :,
- timeout_change()
- state_transition()
ip_vs_protocol_timeout_change() got ipvs as param, due to above and a upcoming patch - defence work
Most of this changes are triggered by Julians comment:
"tcp_timeout_change should work with the new struct ip_vs_proto_data
so that tcp_state_table will go to pd->state_table and set_tcp_state will get pd instead of pp"
*v3
Mostly comments from Julian
The pp -> pd conversion should start from functions like ip_vs_out() that use pp = ip_vs_proto_get(iph.protocol), now they should use ip_vs_proto_data_get(net, iph.protocol). conn_in_get() and conn_out_get() unused param *pp, removed.
--- include/net/ip_vs.h | 18 ++----- net/netfilter/ipvs/ip_vs_conn.c | 2 - net/netfilter/ipvs/ip_vs_core.c | 77 +++++++++++++++++++------------ net/netfilter/ipvs/ip_vs_ctl.c | 54 +++++++++++++-------- net/netfilter/ipvs/ip_vs_proto.c | 17 +++++-- net/netfilter/ipvs/ip_vs_proto_ah_esp.c | 10 ++-- net/netfilter/ipvs/ip_vs_proto_sctp.c | 16 +++---- net/netfilter/ipvs/ip_vs_proto_tcp.c | 26 ++++------ net/netfilter/ipvs/ip_vs_proto_udp.c | 11 ++--- net/netfilter/xt_ipvs.c | 2 +- 10 files changed, 126 insertions(+), 107 deletions(-)
include/net/ip_vs.h +6 -12
@@ -370,13 +370,12 @@ struct ip_vs_protocol {void (*exit_netns)(struct net *net,struct ip_vs_proto_data *pd);int (*conn_schedule)(int af,struct sk_buff *skb, -struct ip_vs_protocol *pp, +struct ip_vs_proto_data *pd,int *verdict,struct ip_vs_conn **cpp);struct ip_vs_conn * (*conn_in_get)(int af,const struct sk_buff *skb, -struct ip_vs_protocol *pp,const struct ip_vs_iphdr *iph,unsigned int proto_off,int inverse);
@@ -384,7 +383,6 @@ struct ip_vs_protocol {struct ip_vs_conn * (*conn_out_get)(int af,const struct sk_buff *skb, -struct ip_vs_protocol *pp,const struct ip_vs_iphdr *iph,unsigned int proto_off,int inverse);
@@ -402,7 +400,7 @@ struct ip_vs_protocol {int (*state_transition)(struct ip_vs_conn *cp,int direction,const struct sk_buff *skb, -struct ip_vs_protocol *pp); +struct ip_vs_proto_data *pd);int (*register_app)(struct ip_vs_app *inc);
@@ -415,9 +413,7 @@ struct ip_vs_protocol {int offset, const char *msg); -void (*timeout_change)(struct ip_vs_protocol *pp,int flags); - -int (*set_state_timeout)(struct ip_vs_protocol *pp,char *sname,int to); +void (*timeout_change)(struct ip_vs_proto_data *pd,int flags); };/*
@@ -776,7 +772,6 @@ struct ip_vs_conn *ip_vs_conn_in_get(const struct ip_vs_conn_param *p);struct ip_vs_conn *ip_vs_ct_in_get (const struct ip_vs_conn_param *p);struct ip_vs_conn *ip_vs_conn_in_get_proto (int af,const struct sk_buff *skb, -struct ip_vs_protocol *pp,const struct ip_vs_iphdr *iph,unsigned int proto_off,int inverse);
@@ -784,7 +779,6 @@ struct ip_vs_conn * ip_vs_conn_in_get_proto(int af, const struct sk_buff *skb,struct ip_vs_conn *ip_vs_conn_out_get (const struct ip_vs_conn_param *p);struct ip_vs_conn *ip_vs_conn_out_get_proto (int af,const struct sk_buff *skb, -struct ip_vs_protocol *pp,const struct ip_vs_iphdr *iph,unsigned int proto_off,int inverse);
@@ -915,7 +909,7 @@ static inline void ip_vs_pe_put(const struct ip_vs_pe *pe)*/ extern int ip_vs_protocol_init (void );extern void ip_vs_protocol_cleanup (void ); -extern void ip_vs_protocol_timeout_change (int flags); +extern void ip_vs_protocol_timeout_change (struct netns_ipvs *ipvs,int flags);extern int *ip_vs_create_timeout_table (int *table,int size); extern int ip_vs_set_state_timeout(int *table, int num, const char *const *names,
@@ -945,9 +939,9 @@ extern struct ip_vs_scheduler *ip_vs_scheduler_get(const char *sched_name);extern void ip_vs_scheduler_put (struct ip_vs_scheduler *scheduler);extern struct ip_vs_conn *ip_vs_schedule (struct ip_vs_service *svc,struct sk_buff *skb, -struct ip_vs_protocol *pp,int *ignored); +struct ip_vs_proto_data *pd,int *ignored);extern int ip_vs_leave (struct ip_vs_service *svc,struct sk_buff *skb, -struct ip_vs_protocol *pp); +struct ip_vs_proto_data *pd);/*
net/netfilter/ipvs/ip_vs_conn.c +0 -2
@@ -329,7 +329,6 @@ ip_vs_conn_fill_param_proto(int af, const struct sk_buff *skb,struct ip_vs_conn *ip_vs_conn_in_get_proto (int af,const struct sk_buff *skb, -struct ip_vs_protocol *pp,const struct ip_vs_iphdr *iph,unsigned int proto_off,int inverse) {
@@ -428,7 +427,6 @@ struct ip_vs_conn *ip_vs_conn_out_get(const struct ip_vs_conn_param *p)struct ip_vs_conn *ip_vs_conn_out_get_proto (int af,const struct sk_buff *skb, -struct ip_vs_protocol *pp,const struct ip_vs_iphdr *iph,unsigned int proto_off,int inverse) {
net/netfilter/ipvs/ip_vs_core.c +47 -30
246 lines not on this page · raw message
net/netfilter/ipvs/ip_vs_ctl.c +33 -21
163 lines not on this page · raw message
net/netfilter/ipvs/ip_vs_proto.c +13 -4
@@ -152,9 +152,8 @@ EXPORT_SYMBOL(ip_vs_proto_get);* get ip_vs_protocol object data by netns and proto */ struct ip_vs_proto_data * -ip_vs_proto_data_get (struct net *net,unsigned short proto) +__ipvs_proto_data_get (struct netns_ipvs *ipvs,unsigned short proto) { -struct netns_ipvs *ipvs =net_ipvs (net);struct ip_vs_proto_data *pd;unsigned hash =IP_VS_PROTO_HASH (proto);
@@ -165,12 +164,20 @@ ip_vs_proto_data_get(struct net *net, unsigned short proto)return NULL ; } + +struct ip_vs_proto_data * +ip_vs_proto_data_get (struct net *net,unsigned short proto) +{ +struct netns_ipvs *ipvs =net_ipvs (net); + +return __ipvs_proto_data_get (ipvs, proto); +}EXPORT_SYMBOL (ip_vs_proto_data_get);/* * Propagate event for state change to all protocols */ -void ip_vs_protocol_timeout_change (int flags) +void ip_vs_protocol_timeout_change (struct netns_ipvs *ipvs,int flags) {struct ip_vs_protocol *pp;int i;
@@ -178,7 +185,9 @@ void ip_vs_protocol_timeout_change(int flags)for (i =0 ; i <IP_VS_PROTO_TAB_SIZE ; i++) {for (pp = ip_vs_proto_table[i]; pp; pp = pp->next) {if (pp->timeout_change) - pp->timeout_change (pp, flags); + pp->timeout_change (__ipvs_proto_data_get (ipvs, + pp->protocol), + flags); } } }
net/netfilter/ipvs/ip_vs_proto_ah_esp.c +4 -6
@@ -55,7 +55,7 @@ ah_esp_conn_fill_param_proto(int af, const struct ip_vs_iphdr *iph, }static struct ip_vs_conn * -ah_esp_conn_in_get (int af,const struct sk_buff *skb,struct ip_vs_protocol *pp, +ah_esp_conn_in_get (int af,const struct sk_buff *skb,const struct ip_vs_iphdr *iph,unsigned int proto_off,int inverse) {
@@ -72,7 +72,7 @@ ah_esp_conn_in_get(int af, const struct sk_buff *skb, struct ip_vs_protocol *pp,IP_VS_DBG_BUF (12 ,"Unknown ISAKMP entry for outin packet " "%s%s %s->%s\n" , inverse ?"ICMP+" :"" , - pp->name, +ip_vs_proto_get (iph->protocol)->name,IP_VS_DBG_ADDR (af, &iph->saddr),IP_VS_DBG_ADDR (af, &iph->daddr)); }
@@ -83,7 +83,6 @@ ah_esp_conn_in_get(int af, const struct sk_buff *skb, struct ip_vs_protocol *pp,static struct ip_vs_conn *ah_esp_conn_out_get (int af,const struct sk_buff *skb, -struct ip_vs_protocol *pp,const struct ip_vs_iphdr *iph,unsigned int proto_off,int inverse)
@@ -97,7 +96,7 @@ ah_esp_conn_out_get(int af, const struct sk_buff *skb,IP_VS_DBG_BUF (12 ,"Unknown ISAKMP entry for inout packet " "%s%s %s->%s\n" , inverse ?"ICMP+" :"" , - pp->name, +ip_vs_proto_get (iph->protocol)->name,IP_VS_DBG_ADDR (af, &iph->saddr),IP_VS_DBG_ADDR (af, &iph->daddr)); }
@@ -107,7 +106,7 @@ ah_esp_conn_out_get(int af, const struct sk_buff *skb,static int -ah_esp_conn_schedule (int af,struct sk_buff *skb,struct ip_vs_protocol *pp, +ah_esp_conn_schedule (int af,struct sk_buff *skb,struct ip_vs_proto_data *pd,int *verdict,struct ip_vs_conn **cpp) {/*
@@ -137,7 +136,6 @@ struct ip_vs_protocol ip_vs_protocol_ah = { .app_conn_bind = NULL, .debug_packet = ip_vs_tcpudp_debug_packet, .timeout_change = NULL, /* ISAKMP */ - .set_state_timeout = NULL, };#endif
net/netfilter/ipvs/ip_vs_proto_sctp.c +7 -9
@@ -9,7 +9,7 @@#include <net/ip_vs.h> static int -sctp_conn_schedule (int af,struct sk_buff *skb,struct ip_vs_protocol *pp, +sctp_conn_schedule (int af,struct sk_buff *skb,struct ip_vs_proto_data *pd,int *verdict,struct ip_vs_conn **cpp) {struct net *net;
@@ -47,10 +47,10 @@ sctp_conn_schedule(int af, struct sk_buff *skb, struct ip_vs_protocol *pp,* Let the virtual server select a real server for the * incoming connection, and create a connection entry. */ - *cpp =ip_vs_schedule (svc, skb, pp, &ignored); + *cpp =ip_vs_schedule (svc, skb, pd, &ignored);if (!*cpp && ignored <=0 ) {if (!ignored) - *verdict =ip_vs_leave (svc, skb, pp); + *verdict =ip_vs_leave (svc, skb, pd);else {ip_vs_service_put (svc); *verdict =NF_DROP ;
@@ -907,14 +907,13 @@ static const char *sctp_state_name(int state) }static inline int -set_sctp_state (struct ip_vs_protocol *pp,struct ip_vs_conn *cp, +set_sctp_state (struct ip_vs_proto_data *pd,struct ip_vs_conn *cp,int direction,const struct sk_buff *skb) {sctp_chunkhdr_t _sctpch, *sch;unsigned char chunk_type;int event, next_state;int ihl; -struct ip_vs_proto_data *pd;#ifdef CONFIG_IP_VS_IPV6 ihl = cp->af ==AF_INET ?ip_hdrlen (skb) :sizeof (struct ipv6hdr );
@@ -966,7 +965,7 @@ set_sctp_state(struct ip_vs_protocol *pp, struct ip_vs_conn *cp, IP_VS_DBG_BUF(8, "%s %s %s:%d->" "%s:%d state: %s->%s conn->refcnt:%d\n", - pp->name, + pd->pp->name, ((direction == IP_VS_DIR_OUTPUT) ? "output " : "input "), IP_VS_DBG_ADDR(cp->af, &cp->daddr),
@@ -990,7 +989,6 @@ set_sctp_state(struct ip_vs_protocol *pp, struct ip_vs_conn *cp, } } } - pd =ip_vs_proto_data_get (&init_net, pp->protocol);/* tmp fix */ if (likely (pd)) cp->timeout = pd->timeout_table[cp->state = next_state];else /* What to do ? */
@@ -1001,12 +999,12 @@ set_sctp_state(struct ip_vs_protocol *pp, struct ip_vs_conn *cp,static int sctp_state_transition (struct ip_vs_conn *cp,int direction, -const struct sk_buff *skb,struct ip_vs_protocol *pp) +const struct sk_buff *skb,struct ip_vs_proto_data *pd) {int ret =0 ;spin_lock (&cp->lock); - ret =set_sctp_state (pp, cp, direction, skb); + ret =set_sctp_state (pd, cp, direction, skb);spin_unlock (&cp->lock);return ret;
net/netfilter/ipvs/ip_vs_proto_tcp.c +11 -15
@@ -32,7 +32,7 @@#include <net/ip_vs.h> static int -tcp_conn_schedule (int af,struct sk_buff *skb,struct ip_vs_protocol *pp, +tcp_conn_schedule (int af,struct sk_buff *skb,struct ip_vs_proto_data *pd,int *verdict,struct ip_vs_conn **cpp) {struct net *net;
@@ -68,10 +68,10 @@ tcp_conn_schedule(int af, struct sk_buff *skb, struct ip_vs_protocol *pp,* Let the virtual server select a real server for the * incoming connection, and create a connection entry. */ - *cpp =ip_vs_schedule (svc, skb, pp, &ignored); + *cpp =ip_vs_schedule (svc, skb, pd, &ignored);if (!*cpp && ignored <=0 ) {if (!ignored) - *verdict =ip_vs_leave (svc, skb, pp); + *verdict =ip_vs_leave (svc, skb, pd);else {ip_vs_service_put (svc); *verdict =NF_DROP ;
@@ -448,10 +448,7 @@ static struct tcp_states_t tcp_states_dos [] = { /*rst*/ {{sCL, sCL, sCL, sSR, sCL, sCL, sCL, sCL, sLA, sLI, sCL }}, }; -static struct tcp_states_t *tcp_state_table = tcp_states; - - -static void tcp_timeout_change(struct ip_vs_protocol *pp, int flags) +static void tcp_timeout_change(struct ip_vs_proto_data *pd, int flags) { int on = (flags & 1); /* secure_tcp */
@@ -461,7 +458,7 @@ static void tcp_timeout_change(struct ip_vs_protocol *pp, int flags)** for most if not for all of the applications. Something ** like "capabilities" (flags) for each object. */ - tcp_state_table = (on? tcp_states_dos : tcp_states); + pd->tcp_state_table = (on? tcp_states_dos : tcp_states); }static inline int tcp_state_idx (struct tcphdr *th)
@@ -478,13 +475,12 @@ static inline int tcp_state_idx(struct tcphdr *th) }static inline void -set_tcp_state (struct ip_vs_protocol *pp,struct ip_vs_conn *cp, +set_tcp_state (struct ip_vs_proto_data *pd,struct ip_vs_conn *cp,int direction,struct tcphdr *th) {int state_idx;int new_state =IP_VS_TCP_S_CLOSE ;int state_off = tcp_state_off[direction]; -struct ip_vs_proto_data *pd;/* Temp fix */ /* * Update state offset to INPUT_ONLY if necessary
@@ -502,7 +498,7 @@ set_tcp_state(struct ip_vs_protocol *pp, struct ip_vs_conn *cp, goto tcp_state_out; } - new_state = tcp_state_table[state_off+state_idx].next_state[cp->state]; + new_state = pd->tcp_state_table[state_off+state_idx].next_state[cp->state]; tcp_state_out:if (new_state != cp->state) {
@@ -510,7 +506,7 @@ set_tcp_state(struct ip_vs_protocol *pp, struct ip_vs_conn *cp, IP_VS_DBG_BUF(8, "%s %s [%c%c%c%c] %s:%d->" "%s:%d state: %s->%s conn->refcnt:%d\n", - pp->name, + pd->pp->name, ((state_off == TCP_DIR_OUTPUT) ? "output " : "input "), th->syn ? 'S' : '.',
@@ -540,7 +536,6 @@ set_tcp_state(struct ip_vs_protocol *pp, struct ip_vs_conn *cp, } } - pd =ip_vs_proto_data_get (&init_net, pp->protocol);if (likely (pd)) cp->timeout = pd->timeout_table[cp->state = new_state];else /* What to do ? */
@@ -553,7 +548,7 @@ set_tcp_state(struct ip_vs_protocol *pp, struct ip_vs_conn *cp,static int tcp_state_transition (struct ip_vs_conn *cp,int direction,const struct sk_buff *skb, -struct ip_vs_protocol *pp) +struct ip_vs_proto_data *pd) {struct tcphdr _tcph, *th;
@@ -568,7 +563,7 @@ tcp_state_transition(struct ip_vs_conn *cp, int direction,return 0 ;spin_lock (&cp->lock); -set_tcp_state (pp, cp, direction, th); +set_tcp_state (pd, cp, direction, th);spin_unlock (&cp->lock);return 1 ;
@@ -691,6 +686,7 @@ static void __ip_vs_tcp_init(struct net *net, struct ip_vs_proto_data *pd)spin_lock_init (&ipvs->tcp_app_lock); pd->timeout_table =ip_vs_create_timeout_table ((int *)tcp_timeouts,sizeof (tcp_timeouts)); + pd->tcp_state_table = tcp_states; }static void __ip_vs_tcp_exit (struct net *net,struct ip_vs_proto_data *pd)
net/netfilter/ipvs/ip_vs_proto_udp.c +4 -5
@@ -29,7 +29,7 @@#include <net/ip6_checksum.h> static int -udp_conn_schedule (int af,struct sk_buff *skb,struct ip_vs_protocol *pp, +udp_conn_schedule (int af,struct sk_buff *skb,struct ip_vs_proto_data *pd,int *verdict,struct ip_vs_conn **cpp) {struct net *net;
@@ -64,10 +64,10 @@ udp_conn_schedule(int af, struct sk_buff *skb, struct ip_vs_protocol *pp,* Let the virtual server select a real server for the * incoming connection, and create a connection entry. */ - *cpp =ip_vs_schedule (svc, skb, pp, &ignored); + *cpp =ip_vs_schedule (svc, skb, pd, &ignored);if (!*cpp && ignored <=0 ) {if (!ignored) - *verdict =ip_vs_leave (svc, skb, pp); + *verdict =ip_vs_leave (svc, skb, pd);else {ip_vs_service_put (svc); *verdict =NF_DROP ;
@@ -457,11 +457,8 @@ static const char * udp_state_name(int state)static int udp_state_transition (struct ip_vs_conn *cp,int direction,const struct sk_buff *skb, -struct ip_vs_protocol *pp) +struct ip_vs_proto_data *pd) { -struct ip_vs_proto_data *pd;/* Temp fix, pp will be replaced by pd */
PATCH 11/22 IPVS: netns, common protocol changes and use of appcnt.
In reply to [email protected]From: Hans Schillstrom <[email protected]>
appcnt and timeout_table moved from struct ip_vs_protocol to ip_vs proto_data.
struct net *net added as first param to
- register_app()
- unregister_app()
- app_conn_bind()
- ip_vs_conn_new()
--- include/net/ip_vs.h | 2 - net/netfilter/ipvs/ip_vs_conn.c | 6 ++-- net/netfilter/ipvs/ip_vs_proto_sctp.c | 4 +- net/netfilter/ipvs/ip_vs_proto_tcp.c | 5 +-- net/netfilter/ipvs/ip_vs_proto_udp.c | 4 +- net/netfilter/ipvs/ip_vs_sync.c | 56 +++++++++++++++++--------------- 6 files changed, 39 insertions(+), 38 deletions(-)
include/net/ip_vs.h +0 -2
@@ -358,8 +358,6 @@ struct ip_vs_protocol {u16 protocol;u16 num_states;int dont_defrag; -atomic_t appcnt;/* counter of proto app incs */ -int *timeout_table;/* protocol timeout table */ void (*init)(struct ip_vs_protocol *pp);
net/netfilter/ipvs/ip_vs_conn.c +3 -3
@@ -804,7 +804,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p, struct ip_vs_dest *dest, __u32 fwmark) {struct ip_vs_conn *cp; -struct ip_vs_protocol *pp =ip_vs_proto_get (p->protocol); +struct ip_vs_proto_data *pd =ip_vs_proto_data_get (&init_net, p->protocol); cp =kmem_cache_zalloc (ip_vs_conn_cachep,GFP_ATOMIC );if (cp ==NULL ) {
@@ -863,8 +863,8 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,#endif ip_vs_bind_xmit (cp); -if (unlikely (pp &&atomic_read (&pp->appcnt))) -ip_vs_bind_app (cp, pp); +if (unlikely (pd &&atomic_read (&pd->appcnt))) +ip_vs_bind_app (cp, pd->pp);/* * Allow conntrack to be preserved. By default, conntrack
net/netfilter/ipvs/ip_vs_proto_sctp.c +2 -2
@@ -1035,7 +1035,7 @@ static int sctp_register_app(struct ip_vs_app *inc) } }list_add (&inc->p_list, &ipvs->sctp_apps[hash]); -atomic_inc (&pd->pp->appcnt); +atomic_inc (&pd->appcnt); out:spin_unlock_bh (&ipvs->sctp_app_lock);
@@ -1048,7 +1048,7 @@ static void sctp_unregister_app(struct ip_vs_app *inc)struct ip_vs_proto_data *pd =ip_vs_proto_data_get (&init_net,IPPROTO_SCTP );spin_lock_bh (&ipvs->sctp_app_lock); -atomic_dec (&pd->pp->appcnt); +atomic_dec (&pd->appcnt);list_del (&inc->p_list);spin_unlock_bh (&ipvs->sctp_app_lock); }
net/netfilter/ipvs/ip_vs_proto_tcp.c +2 -3
@@ -595,7 +595,7 @@ static int tcp_register_app(struct ip_vs_app *inc) } }list_add (&inc->p_list, &ipvs->tcp_apps[hash]); -atomic_inc (&pd->pp->appcnt); +atomic_inc (&pd->appcnt); out:spin_unlock_bh (&ipvs->tcp_app_lock);
@@ -610,7 +610,7 @@ tcp_unregister_app(struct ip_vs_app *inc)struct ip_vs_proto_data *pd =ip_vs_proto_data_get (&init_net,IPPROTO_TCP );spin_lock_bh (&ipvs->tcp_app_lock); -atomic_dec (&pd->pp->appcnt); +atomic_dec (&pd->appcnt);list_del (&inc->p_list);spin_unlock_bh (&ipvs->tcp_app_lock); }
@@ -700,7 +700,6 @@ struct ip_vs_protocol ip_vs_protocol_tcp = { .protocol = IPPROTO_TCP, .num_states = IP_VS_TCP_S_LAST, .dont_defrag = 0, - .appcnt = ATOMIC_INIT(0), .init = NULL, .exit = NULL, .init_netns = __ip_vs_tcp_init,
net/netfilter/ipvs/ip_vs_proto_udp.c +2 -2
@@ -373,7 +373,7 @@ static int udp_register_app(struct ip_vs_app *inc) } }list_add (&inc->p_list, &ipvs->udp_apps[hash]); -atomic_inc (&pd->pp->appcnt); +atomic_inc (&pd->appcnt); out:spin_unlock_bh (&ipvs->udp_app_lock);
@@ -388,7 +388,7 @@ udp_unregister_app(struct ip_vs_app *inc)struct netns_ipvs *ipvs =net_ipvs (&init_net);spin_lock_bh (&ipvs->udp_app_lock); -atomic_dec (&pd->pp->appcnt); +atomic_dec (&pd->appcnt);list_del (&inc->p_list);spin_unlock_bh (&ipvs->udp_app_lock); }
net/netfilter/ipvs/ip_vs_sync.c +30 -26
147 lines not on this page · raw message
Signature · 1 line
1.7.2.3
PATCH 12/22 IPVS: netns awareness to ip_vs_app
In reply to [email protected]From: Hans Schillstrom <[email protected]>
All variables moved to struct ipvs,
most external changes fixed (i.e. init_net removed)
in ip_vs_protocol param struct net *net added to:
- register_app()
- unregister_app()
This affected almost all proto_xxx.c files
--- include/net/ip_vs.h | 12 +++--- include/net/netns/ip_vs.h | 5 ++ net/netfilter/ipvs/ip_vs_app.c | 72 +++++++++++++++++++-------------- net/netfilter/ipvs/ip_vs_ftp.c | 8 ++-- net/netfilter/ipvs/ip_vs_proto_sctp.c | 12 +++--- net/netfilter/ipvs/ip_vs_proto_tcp.c | 12 +++--- net/netfilter/ipvs/ip_vs_proto_udp.c | 12 +++--- 7 files changed, 75 insertions(+), 58 deletions(-)
include/net/ip_vs.h +6 -6
@@ -400,9 +400,9 @@ struct ip_vs_protocol {const struct sk_buff *skb, struct ip_vs_proto_data *pd); -int (*register_app)(struct ip_vs_app *inc); +int (*register_app)(struct net *net,struct ip_vs_app *inc); -void (*unregister_app)(struct ip_vs_app *inc); +void (*unregister_app)(struct net *net,struct ip_vs_app *inc);int (*app_conn_bind)(struct ip_vs_conn *cp);
@@ -869,12 +869,12 @@ ip_vs_control_add(struct ip_vs_conn *cp, struct ip_vs_conn *ctl_cp)* (from ip_vs_app.c) */ #define IP_VS_APP_MAX_PORTS 8 -extern int register_ip_vs_app (struct ip_vs_app *app); -extern void unregister_ip_vs_app (struct ip_vs_app *app); +extern int register_ip_vs_app (struct net *net,struct ip_vs_app *app); +extern void unregister_ip_vs_app (struct net *net,struct ip_vs_app *app);extern int ip_vs_bind_app (struct ip_vs_conn *cp,struct ip_vs_protocol *pp);extern void ip_vs_unbind_app (struct ip_vs_conn *cp); -extern int -register_ip_vs_app_inc (struct ip_vs_app *app,__u16 proto,__u16 port); +extern int register_ip_vs_app_inc (struct net *net,struct ip_vs_app *app, +__u16 proto,__u16 port);extern int ip_vs_app_inc_get (struct ip_vs_app *inc);extern void ip_vs_app_inc_put (struct ip_vs_app *inc);
include/net/netns/ip_vs.h +5 -0
@@ -29,6 +29,11 @@ struct netns_ipvs {#define IP_VS_RTAB_MASK (IP_VS_RTAB_SIZE - 1)struct list_head rs_table[IP_VS_RTAB_SIZE ]; +/* ip_vs_app */ +struct list_head app_list; +struct mutex app_mutex; +struct lock_class_key app_key;/* mutex debuging */ +/* ip_vs_proto */ #define IP_VS_PROTO_TAB_SIZE 32/* must be power of 2 */ struct ip_vs_proto_data *proto_data_table[IP_VS_PROTO_TAB_SIZE ];
net/netfilter/ipvs/ip_vs_app.c +42 -30
198 lines not on this page · raw message
net/netfilter/ipvs/ip_vs_ftp.c +4 -4
@@ -414,14 +414,14 @@ static int __net_init __ip_vs_ftp_init(struct net *net)if (!net_eq (net, &init_net))/* netns not enabled yet */ return -EPERM ; - ret =register_ip_vs_app (app); + ret =register_ip_vs_app (net, app);if (ret)return ret;for (i=0 ; i<IP_VS_APP_MAX_PORTS ; i++) {if (!ports[i])continue ; - ret =register_ip_vs_app_inc (app, app->protocol, ports[i]); + ret =register_ip_vs_app_inc (net, app, app->protocol, ports[i]);if (ret)break ; pr_info("%s: loaded support on port[%d] = %d\n",
@@ -429,7 +429,7 @@ static int __net_init __ip_vs_ftp_init(struct net *net) }if (ret) -unregister_ip_vs_app (app); +unregister_ip_vs_app (net, app);return ret; }
@@ -443,7 +443,7 @@ static void __ip_vs_ftp_exit(struct net *net)if (!net_eq (net, &init_net))/* netns not enabled yet */ return ; -unregister_ip_vs_app (app); +unregister_ip_vs_app (net, app); }static struct pernet_operations ip_vs_ftp_ops = {
net/netfilter/ipvs/ip_vs_proto_sctp.c +6 -6
@@ -1016,14 +1016,14 @@ static inline __u16 sctp_app_hashkey(__be16 port) &SCTP_APP_TAB_MASK ; } -static int sctp_register_app (struct ip_vs_app *inc) +static int sctp_register_app (struct net *net,struct ip_vs_app *inc) {struct ip_vs_app *i;__u16 hash;__be16 port = inc->port;int ret =0 ; -struct netns_ipvs *ipvs =net_ipvs (&init_net); -struct ip_vs_proto_data *pd =ip_vs_proto_data_get (&init_net,IPPROTO_SCTP ); +struct netns_ipvs *ipvs =net_ipvs (net); +struct ip_vs_proto_data *pd =ip_vs_proto_data_get (net,IPPROTO_SCTP ); hash =sctp_app_hashkey (port);
@@ -1042,10 +1042,10 @@ out:return ret; } -static void sctp_unregister_app (struct ip_vs_app *inc) +static void sctp_unregister_app (struct net *net,struct ip_vs_app *inc) { -struct netns_ipvs *ipvs =net_ipvs (&init_net); -struct ip_vs_proto_data *pd =ip_vs_proto_data_get (&init_net,IPPROTO_SCTP ); +struct netns_ipvs *ipvs =net_ipvs (net); +struct ip_vs_proto_data *pd =ip_vs_proto_data_get (net,IPPROTO_SCTP );spin_lock_bh (&ipvs->sctp_app_lock);atomic_dec (&pd->appcnt);
net/netfilter/ipvs/ip_vs_proto_tcp.c +6 -6
@@ -576,14 +576,14 @@ static inline __u16 tcp_app_hashkey(__be16 port) } -static int tcp_register_app (struct ip_vs_app *inc) +static int tcp_register_app (struct net *net,struct ip_vs_app *inc) {struct ip_vs_app *i;__u16 hash;__be16 port = inc->port;int ret =0 ; -struct netns_ipvs *ipvs =net_ipvs (&init_net); -struct ip_vs_proto_data *pd =ip_vs_proto_data_get (&init_net,IPPROTO_TCP ); +struct netns_ipvs *ipvs =net_ipvs (net); +struct ip_vs_proto_data *pd =ip_vs_proto_data_get (net,IPPROTO_TCP ); hash =tcp_app_hashkey (port);
@@ -604,10 +604,10 @@ static int tcp_register_app(struct ip_vs_app *inc)static void -tcp_unregister_app (struct ip_vs_app *inc) +tcp_unregister_app (struct net *net,struct ip_vs_app *inc) { -struct netns_ipvs *ipvs =net_ipvs (&init_net); -struct ip_vs_proto_data *pd =ip_vs_proto_data_get (&init_net,IPPROTO_TCP ); +struct netns_ipvs *ipvs =net_ipvs (net); +struct ip_vs_proto_data *pd =ip_vs_proto_data_get (net,IPPROTO_TCP );spin_lock_bh (&ipvs->tcp_app_lock);atomic_dec (&pd->appcnt);
net/netfilter/ipvs/ip_vs_proto_udp.c +6 -6
@@ -353,14 +353,14 @@ static inline __u16 udp_app_hashkey(__be16 port) } -static int udp_register_app (struct ip_vs_app *inc) +static int udp_register_app (struct net *net,struct ip_vs_app *inc) {struct ip_vs_app *i;__u16 hash;__be16 port = inc->port;int ret =0 ; -struct netns_ipvs *ipvs =net_ipvs (&init_net); -struct ip_vs_proto_data *pd =ip_vs_proto_data_get (&init_net,IPPROTO_UDP ); +struct netns_ipvs *ipvs =net_ipvs (net); +struct ip_vs_proto_data *pd =ip_vs_proto_data_get (net,IPPROTO_UDP ); hash =udp_app_hashkey (port);
@@ -382,10 +382,10 @@ static int udp_register_app(struct ip_vs_app *inc)static void -udp_unregister_app (struct ip_vs_app *inc) +udp_unregister_app (struct net *net,struct ip_vs_app *inc) { -struct ip_vs_proto_data *pd =ip_vs_proto_data_get (&init_net,IPPROTO_UDP ); -struct netns_ipvs *ipvs =net_ipvs (&init_net); +struct ip_vs_proto_data *pd =ip_vs_proto_data_get (net,IPPROTO_UDP ); +struct netns_ipvs *ipvs =net_ipvs (net);spin_lock_bh (&ipvs->udp_app_lock);atomic_dec (&pd->appcnt);
Signature · 1 line
1.7.2.3
PATCH 13/22 IPVS: netns awareness to ip_vs_est
In reply to [email protected]From: Hans Schillstrom <[email protected]>
All variables moved to struct ipvs,
most external changes fixed (i.e. init_net removed)
*v3
timer per ns instead of a common timer in estimator.
--- include/net/ip_vs.h | 4 +- include/net/netns/ip_vs.h | 5 ++ net/netfilter/ipvs/ip_vs_ctl.c | 20 +++++----- net/netfilter/ipvs/ip_vs_est.c | 86 ++++++++++++++++++++++----------------- 4 files changed, 65 insertions(+), 50 deletions(-)
include/net/ip_vs.h +2 -2
@@ -1002,8 +1002,8 @@ extern void ip_vs_sync_cleanup(void);*/ extern int ip_vs_estimator_init (void );extern void ip_vs_estimator_cleanup (void ); -extern void ip_vs_new_estimator (struct ip_vs_stats *stats); -extern void ip_vs_kill_estimator (struct ip_vs_stats *stats); +extern void ip_vs_new_estimator (struct net *net,struct ip_vs_stats *stats); +extern void ip_vs_kill_estimator (struct net *net,struct ip_vs_stats *stats);extern void ip_vs_zero_estimator (struct ip_vs_stats *stats);/*
include/net/netns/ip_vs.h +5 -0
@@ -70,6 +70,11 @@ struct netns_ipvs {int sysctl_lblcr_expiration;struct ctl_table_header *lblcr_ctl_header;struct ctl_table *lblcr_ctl_table; +/* ip_vs_est */ +struct list_head est_list;/* estimator list */ +spinlock_t est_lock; + struct timer_list est_timer; /* Estimation timer */ + };#endif /* IP_VS_H_ */
net/netfilter/ipvs/ip_vs_ctl.c +10 -10
@@ -816,7 +816,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,spin_unlock (&dest->dst_lock);if (add) -ip_vs_new_estimator (&dest->stats); +ip_vs_new_estimator (svc->net, &dest->stats);write_lock_bh (&__ip_vs_svc_lock);
@@ -1009,9 +1009,9 @@ ip_vs_edit_dest(struct ip_vs_service *svc, struct ip_vs_dest_user_kern *udest)/* * Delete a destination (must be already unlinked from the service) */ -static void __ip_vs_del_dest (struct ip_vs_dest *dest) +static void __ip_vs_del_dest (struct net *net,struct ip_vs_dest *dest) { -ip_vs_kill_estimator (&dest->stats); +ip_vs_kill_estimator (net, &dest->stats);/* * Remove it from the d-linked list with the real services.
@@ -1080,6 +1080,7 @@ static int ip_vs_del_dest(struct ip_vs_service *svc, struct ip_vs_dest_user_kern *udest) { struct ip_vs_dest *dest; +struct net *net = svc->net;__be16 dport = udest->port;EnterFunction (2 );
@@ -1108,7 +1109,7 @@ ip_vs_del_dest(struct ip_vs_service *svc, struct ip_vs_dest_user_kern *udest)/* * Delete the destination */ -__ip_vs_del_dest (dest); +__ip_vs_del_dest (net, dest);LeaveFunction (2 );
@@ -1197,7 +1198,7 @@ ip_vs_add_service(struct net *net, struct ip_vs_service_user_kern *u,else if (svc->port ==0 )atomic_inc (&ip_vs_nullsvc_counter); -ip_vs_new_estimator (&svc->stats); +ip_vs_new_estimator (net, &svc->stats);/* Count only IPv4 services for old get/setsockopt interface */ if (svc->af ==AF_INET )
@@ -1345,7 +1346,7 @@ static void __ip_vs_del_service(struct ip_vs_service *svc)if (svc->af ==AF_INET ) ip_vs_num_services--; -ip_vs_kill_estimator (&svc->stats); +ip_vs_kill_estimator (svc->net, &svc->stats);/* Unbind scheduler */ old_sched = svc->scheduler;
@@ -1368,7 +1369,7 @@ static void __ip_vs_del_service(struct ip_vs_service *svc)*/ list_for_each_entry_safe (dest, nxt, &svc->destinations, n_list) {__ip_vs_unlink_dest (svc, dest,0 ); -__ip_vs_del_dest (dest); +__ip_vs_del_dest (svc->net, dest); }/*
@@ -3458,7 +3459,7 @@ int __net_init __ip_vs_control_init(struct net *net) sysctl_header =register_net_sysctl_table (net, net_vs_ctl_path, vs_vars);if (sysctl_header ==NULL ) goto err_reg; -ip_vs_new_estimator (&ip_vs_stats); +ip_vs_new_estimator (net, &ip_vs_stats);return 0 ; err_reg:
@@ -3470,7 +3471,7 @@ static void __net_exit __ip_vs_control_cleanup(struct net *net)if (!net_eq (net, &init_net))/* netns not enabled yet */ return ; -ip_vs_kill_estimator (&ip_vs_stats); +ip_vs_kill_estimator (net, &ip_vs_stats);unregister_net_sysctl_table (sysctl_header);proc_net_remove (net,"ip_vs_stats" );proc_net_remove (net,"ip_vs" );
@@ -3534,7 +3535,6 @@ void ip_vs_control_cleanup(void)ip_vs_trash_cleanup ();cancel_rearming_delayed_work (&defense_work);cancel_work_sync (&defense_work.work); -ip_vs_kill_estimator (&ip_vs_stats);unregister_pernet_subsys (&ipvs_control_ops);ip_vs_genl_unregister ();nf_unregister_sockopt (&ip_vs_sockopts);
net/netfilter/ipvs/ip_vs_est.c +48 -38
161 lines not on this page · raw message
--
1.7.2.3
PATCH 14/22 IPVS: netns awareness to ip_vs_sync
In reply to [email protected]From: Hans Schillstrom <[email protected]>
All global variables moved to struct ipvs, most external changes fixed (i.e. init_net removed) in sync_buf create + 4 replaced by sizeof(struct..)
--- include/net/ip_vs.h | 14 +- include/net/netns/ip_vs.h | 16 ++ net/netfilter/ipvs/ip_vs_core.c | 14 +- net/netfilter/ipvs/ip_vs_ctl.c | 55 ++++--- net/netfilter/ipvs/ip_vs_sync.c | 325 +++++++++++++++++++++------------------ 5 files changed, 235 insertions(+), 189 deletions(-)
include/net/ip_vs.h +5 -9
@@ -956,7 +956,7 @@ extern struct ip_vs_stats ip_vs_stats;extern const struct ctl_path net_vs_ctl_path[];extern int sysctl_ip_vs_sync_ver; -extern void ip_vs_sync_switch_mode (int mode); +extern void ip_vs_sync_switch_mode (struct net *net,int mode);extern struct ip_vs_service *ip_vs_service_get (struct net *net,int af,__u32 fwmark,__u16 protocol,const union nf_inet_addr *vaddr,__be16 vport);
@@ -985,14 +985,10 @@ extern struct ip_vs_dest *ip_vs_try_bind_dest(struct ip_vs_conn *cp);* IPVS sync daemon data and function prototypes * (from ip_vs_sync.c) */ -extern volatile int ip_vs_sync_state; -extern volatile int ip_vs_master_syncid; -extern volatile int ip_vs_backup_syncid; -extern char ip_vs_master_mcast_ifn[IP_VS_IFNAME_MAXLEN ]; -extern char ip_vs_backup_mcast_ifn[IP_VS_IFNAME_MAXLEN ]; -extern int start_sync_thread (int state,char *mcast_ifn,__u8 syncid); -extern int stop_sync_thread (int state); -extern void ip_vs_sync_conn (struct ip_vs_conn *cp); +extern int start_sync_thread (struct net *net,int state,char *mcast_ifn, +__u8 syncid); +extern int stop_sync_thread (struct net *net,int state); +extern void ip_vs_sync_conn (struct net *net,struct ip_vs_conn *cp);extern int ip_vs_sync_init (void );extern void ip_vs_sync_cleanup (void );
include/net/netns/ip_vs.h +16 -0
@@ -75,6 +75,22 @@ struct netns_ipvs {spinlock_t est_lock;struct timer_list est_timer;/* Estimation timer */ +/* ip_vs_sync */ +struct list_head sync_queue; +spinlock_t sync_lock; +struct ip_vs_sync_buff *sync_buff; +spinlock_t sync_buff_lock; +struct sockaddr_in sync_mcast_addr; +struct task_struct *master_thread; +struct task_struct *backup_thread; +int send_mesg_maxlen; +int recv_mesg_maxlen; +volatile int sync_state; +volatile int master_syncid; +volatile int backup_syncid; +/* multicast interface name */ +char master_mcast_ifn[IP_VS_IFNAME_MAXLEN ]; + char backup_mcast_ifn[IP_VS_IFNAME_MAXLEN]; };#endif /* IP_VS_H_ */
net/netfilter/ipvs/ip_vs_core.c +9 -5
@@ -1477,6 +1477,8 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)struct ip_vs_proto_data *pd;struct ip_vs_conn *cp;int ret, restart, pkts; +struct net *net; +struct netns_ipvs *ipvs;/* Already marked as IPVS request or reply? */ if (skb->ipvs_property)
@@ -1556,7 +1558,8 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af) }IP_VS_DBG_PKT (11 , af, pp, skb,0 ,"Incoming packet" ); - + net =skb_net (skb); + ipvs =net_ipvs (net);/* Check the server status */ if (cp->dest && !(cp->dest->flags &IP_VS_DEST_F_AVAILABLE )) {/* the destination server is not available */
@@ -1589,12 +1592,13 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)* * For ONE_PKT let ip_vs_sync_conn() do the filter work. */ +if (cp->flags &IP_VS_CONN_F_ONE_PACKET ) pkts = sysctl_ip_vs_sync_threshold[0 ];else pkts =atomic_add_return (1 , &cp->in_pkts); -if ((ip_vs_sync_state &IP_VS_STATE_MASTER ) && +if ((ipvs->sync_state &IP_VS_STATE_MASTER ) && cp->protocol ==IPPROTO_SCTP ) { if ((cp->state == IP_VS_SCTP_S_ESTABLISHED && (pkts % sysctl_ip_vs_sync_threshold[1]
@@ -1603,13 +1607,13 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af) ((cp->state == IP_VS_SCTP_S_CLOSED) || (cp->state == IP_VS_SCTP_S_SHUT_ACK_CLI) || (cp->state == IP_VS_SCTP_S_SHUT_ACK_SER)))) { -ip_vs_sync_conn (cp); +ip_vs_sync_conn (net, cp); goto out; } }/* Keep this block last: TCP and others with pp->num_states <= 1 */ - else if ((ip_vs_sync_state & IP_VS_STATE_MASTER) && + else if ((ipvs->sync_state & IP_VS_STATE_MASTER) && (((cp->protocol != IPPROTO_TCP || cp->state == IP_VS_TCP_S_ESTABLISHED) && (pkts % sysctl_ip_vs_sync_threshold[1]
@@ -1619,7 +1623,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af) (cp->state == IP_VS_TCP_S_CLOSE) || (cp->state == IP_VS_TCP_S_CLOSE_WAIT) || (cp->state == IP_VS_TCP_S_TIME_WAIT))))) -ip_vs_sync_conn (cp); +ip_vs_sync_conn (net, cp); out: cp->old_state = cp->state;
net/netfilter/ipvs/ip_vs_ctl.c +33 -22
132 lines not on this page · raw message
net/netfilter/ipvs/ip_vs_sync.c +172 -153
738 lines not on this page · raw message
Signature · 1 line
1.7.2.3
PATCH 15/22 IPVS: netns, ip_vs_stats and its procfs
In reply to [email protected]From: Hans Schillstrom <[email protected]>
The statistic counter locks for every packet are now removed, and that statistic is now per CPU, i.e. no locks needed. However summing is made in ip_vs_est into ip_vs_stats struct which is moved to ipvs struc.
procfs, ip_vs_stats now have a "per cpu" count and a grand total. A new function seq_file_single_net() in ip_vs.h created for handling of single_open_net() since it does not place net ptr in a struct, like others.
/var/lib/lxc # cat /proc/net/ip_vs_stats_percpu
Total Incoming Outgoing Incoming Outgoing
CPU Conns Packets Packets Bytes Bytes
0 0 3 1 9D 34 1 0 1 2 49 70 2 0 1 2 34 76 3 1 2 2 70 74 ~ 1 7 7 18A 18E
Conns/s Pkts/s Pkts/s Bytes/s Bytes/s
0 0 0 0 0
*v3ip_vs_stats reamains as before, instead ip_vs_stats_percpu is added. u64 seq lock added
--- include/net/ip_vs.h | 25 +++++++++ include/net/netns/ip_vs.h | 5 ++ net/netfilter/ipvs/ip_vs_core.c | 26 ++++----- net/netfilter/ipvs/ip_vs_ctl.c | 110 ++++++++++++++++++++++++++++++++------- net/netfilter/ipvs/ip_vs_est.c | 34 ++++++++++++ 5 files changed, 166 insertions(+), 34 deletions(-)
include/net/ip_vs.h +25 -0
@@ -88,6 +88,18 @@ static inline struct net *skb_sknet(const struct sk_buff *skb) {return &init_net;#endif } +/* +* This one needed for single_open_net since net is stored directly in +* private not as a struct i.e. seq_file_net cant be used. +*/ +static inline struct net *seq_file_single_net (struct seq_file *seq) +{ +#ifdef CONFIG_NET_NS +return (struct net *)seq->private; +#else +return &init_net; +#endif +}/* Connections' size value needed by ip_vs_ctl.c */ extern int ip_vs_conn_tab_size;
@@ -344,6 +356,19 @@ struct ip_vs_stats {spinlock_t lock;/* spin lock */ }; +/* +* Helper Macros for per cpu +* ipvs->ctl_stats->ustats.count +*/ +#define IPVS_STAT_INC (ipvs, count) \ + __this_cpu_inc((ipvs)->ustats->count) + +#define IPVS_STAT_ADD (ipvs, count, value) \ + write_seqcount_begin(per_cpu_ptr((ipvs)->ustats_seq, \ + raw_smp_processor_id())); \ + __this_cpu_add((ipvs)->ustats->count, value); \ + write_seqcount_end(per_cpu_ptr((ipvs)->ustats_seq, \ + raw_smp_processor_id()))struct dst_entry ;struct iphdr ;
include/net/netns/ip_vs.h +5 -0
@@ -62,6 +62,11 @@ struct netns_ipvs {struct list_head sctp_apps[SCTP_APP_TAB_SIZE ];spinlock_t sctp_app_lock;#endif +/* ip_vs_ctl */ +struct ip_vs_stats *ctl_stats;/* Statistics & estimator */ +struct ip_vs_stats_user __percpu *ustats;/* Statistics */ +seqcount_t *ustats_seq;/* u64 read retry */ +/* ip_vs_lblc */ int sysctl_lblc_expiration;struct ctl_table_header *lblc_ctl_header;
net/netfilter/ipvs/ip_vs_core.c +12 -14
@@ -115,6 +115,8 @@ static inline void ip_vs_in_stats(struct ip_vs_conn *cp, struct sk_buff *skb) { struct ip_vs_dest *dest = cp->dest; +struct netns_ipvs *ipvs =net_ipvs (skb_net (skb)); +if (dest && (dest->flags &IP_VS_DEST_F_AVAILABLE )) {spin_lock (&dest->stats.lock); dest->stats.ustats.inpkts++;
@@ -126,10 +128,8 @@ ip_vs_in_stats(struct ip_vs_conn *cp, struct sk_buff *skb) dest->svc->stats.ustats.inbytes += skb->len;spin_unlock (&dest->svc->stats.lock); -spin_lock (&ip_vs_stats.lock); - ip_vs_stats.ustats.inpkts++; - ip_vs_stats.ustats.inbytes += skb->len; -spin_unlock (&ip_vs_stats.lock); +IPVS_STAT_INC (ipvs, inpkts); +IPVS_STAT_ADD (ipvs, inbytes, skb->len); } }
@@ -138,6 +138,8 @@ static inline void ip_vs_out_stats(struct ip_vs_conn *cp, struct sk_buff *skb) { struct ip_vs_dest *dest = cp->dest; +struct netns_ipvs *ipvs =net_ipvs (skb_net (skb)); +if (dest && (dest->flags &IP_VS_DEST_F_AVAILABLE )) {spin_lock (&dest->stats.lock); dest->stats.ustats.outpkts++;
@@ -149,10 +151,8 @@ ip_vs_out_stats(struct ip_vs_conn *cp, struct sk_buff *skb) dest->svc->stats.ustats.outbytes += skb->len;spin_unlock (&dest->svc->stats.lock); -spin_lock (&ip_vs_stats.lock); - ip_vs_stats.ustats.outpkts++; - ip_vs_stats.ustats.outbytes += skb->len; -spin_unlock (&ip_vs_stats.lock); +IPVS_STAT_INC (ipvs, outpkts); +IPVS_STAT_ADD (ipvs, outbytes, skb->len); } }
@@ -160,6 +160,8 @@ ip_vs_out_stats(struct ip_vs_conn *cp, struct sk_buff *skb)static inline void ip_vs_conn_stats (struct ip_vs_conn *cp,struct ip_vs_service *svc) { +struct netns_ipvs *ipvs =net_ipvs (svc->net); +spin_lock (&cp->dest->stats.lock); cp->dest->stats.ustats.conns++;spin_unlock (&cp->dest->stats.lock);
@@ -168,9 +170,7 @@ ip_vs_conn_stats(struct ip_vs_conn *cp, struct ip_vs_service *svc) svc->stats.ustats.conns++;spin_unlock (&svc->stats.lock); -spin_lock (&ip_vs_stats.lock); - ip_vs_stats.ustats.conns++; -spin_unlock (&ip_vs_stats.lock); +IPVS_STAT_INC (ipvs, conns); }
@@ -1471,13 +1471,12 @@ ip_vs_in_icmp_v6(struct sk_buff *skb, int *related, unsigned int hooknum)static unsigned int ip_vs_in (unsigned int hooknum,struct sk_buff *skb,int af) { -struct net *net =NULL ; +struct net *net;struct ip_vs_iphdr iph;struct ip_vs_protocol *pp;struct ip_vs_proto_data *pd;struct ip_vs_conn *cp;int ret, restart, pkts; -struct net *net;struct netns_ipvs *ipvs;/* Already marked as IPVS request or reply? */
@@ -1842,7 +1841,6 @@ static struct nf_hook_ops ip_vs_ops[] __read_mostly = { },#endif }; -/* * Initialize IP Virtual Server netns mem. */
net/netfilter/ipvs/ip_vs_ctl.c +90 -20
177 lines not on this page · raw message
net/netfilter/ipvs/ip_vs_est.c +34 -0
@@ -52,6 +52,39 @@*/ +/* +* Make a summary from each cpu +*/ +static inline void get_stats (struct netns_ipvs *ipvs) +{ +int i; + +for_each_possible_cpu (i) { +struct ip_vs_stats_user *u =per_cpu_ptr (ipvs->ustats, i); +seqcount_t *seq_count =per_cpu_ptr (ipvs->ustats_seq, i); +unsigned int start; +if (i) { + ipvs->ctl_stats->ustats.conns += u->conns; + ipvs->ctl_stats->ustats.inpkts += u->inpkts; + ipvs->ctl_stats->ustats.outpkts += u->outpkts; +do { + start =read_seqcount_begin (seq_count); + ipvs->ctl_stats->ustats.inbytes += u->inbytes; + ipvs->ctl_stats->ustats.outbytes += u->outbytes; + }while (read_seqcount_retry (seq_count, start)); + }else { + ipvs->ctl_stats->ustats.conns = u->conns; + ipvs->ctl_stats->ustats.inpkts = u->inpkts; + ipvs->ctl_stats->ustats.outpkts = u->outpkts; +do { + start =read_seqcount_begin (seq_count); + ipvs->ctl_stats->ustats.inbytes = u->inbytes; + ipvs->ctl_stats->ustats.outbytes = u->outbytes; + }while (read_seqcount_retry (seq_count, start)); + } + } +} +static void estimation_timer (unsigned long arg) {struct ip_vs_estimator *e;
@@ -64,6 +97,7 @@ static void estimation_timer(unsigned long arg)struct netns_ipvs *ipvs; ipvs =net_ipvs (net); +get_stats (ipvs);spin_lock (&ipvs->est_lock);list_for_each_entry (e, &ipvs->est_list, list) { s = container_of(e, struct ip_vs_stats, est);
Signature · 1 line
1.7.2.3
PATCH 16/22 IPVS: netns, connection hash got net as param.
In reply to [email protected]From: Hans Schillstrom <[email protected]>
Connection hash table is now name space aware.
i.e. net ptr >> 8 is xor:ed to the hash,
and this is the first param to be compared.
The net struct is 0xa40 in size ( a little bit smaller for 32 bit arch:s) and cache-line aligned, so a ptr >> 5 might be a more clever solution ?
All lookups where net is compared uses net_eq() which returns 1 when netns is disabled, and the compiler seems to do something clever in that case.
ip_vs_conn_fill_param() have *net as first param now.
Three new inlines added to keep conn struct smaller when names space is disabled.
- ip_vs_conn_net()
- ip_vs_conn_net_set()
- ip_vs_conn_net_eq()
*v3
moved net compare to the end in "fast path"
--- include/net/ip_vs.h | 53 ++++++++++++--- include/net/netns/ip_vs.h | 2 + net/netfilter/ipvs/ip_vs_conn.c | 112 +++++++++++++++++++------------ net/netfilter/ipvs/ip_vs_core.c | 15 +++-- net/netfilter/ipvs/ip_vs_ftp.c | 14 ++-- net/netfilter/ipvs/ip_vs_nfct.c | 6 +- net/netfilter/ipvs/ip_vs_proto_ah_esp.c | 15 +++-- net/netfilter/ipvs/ip_vs_proto_sctp.c | 2 +- net/netfilter/ipvs/ip_vs_proto_tcp.c | 2 +- net/netfilter/ipvs/ip_vs_proto_udp.c | 2 +- net/netfilter/ipvs/ip_vs_sync.c | 13 ++-- 11 files changed, 153 insertions(+), 83 deletions(-)
include/net/ip_vs.h +42 -11
@@ -455,6 +455,7 @@ extern struct ip_vs_proto_data * ip_vs_proto_data_get(struct net *net, unsigned short proto);struct ip_vs_conn_param { +struct net * net;const union nf_inet_addr *caddr;const union nf_inet_addr *vaddr;__be16 cport;
@@ -472,17 +473,19 @@ struct ip_vs_conn_param {*/ struct ip_vs_conn {struct list_head c_list;/* hashed list heads */ - +#ifdef CONFIG_NET_NS +struct net *net;/* Name space */ +#endif /* Protocol, addresses and port numbers */ -u16 af;/* address family */ -union nf_inet_addr caddr;/* client address */ -union nf_inet_addr vaddr;/* virtual address */ -union nf_inet_addr daddr;/* destination address */ -volatile __u32 flags;/* status flags */ -__u32 fwmark;/* Fire wall mark from skb */ -__be16 cport; -__be16 vport; -__be16 dport; +u16 af;/* address family */ +__be16 cport; +__be16 vport; +__be16 dport; +__u32 fwmark;/* Fire wall mark from skb */ +union nf_inet_addr caddr;/* client address */ +union nf_inet_addr vaddr;/* virtual address */ +union nf_inet_addr daddr;/* destination address */ +volatile __u32 flags;/* status flags */ __u16 protocol;/* Which protocol (TCP/UDP) */ /* counter and timer */
@@ -525,6 +528,33 @@ struct ip_vs_conn {__u8 pe_data_len; }; +/* +* To save some memory in conn table when name space is disabled. +*/ +static inline struct net *ip_vs_conn_net (const struct ip_vs_conn *cp) +{ +#ifdef CONFIG_NET_NS +return cp->net; +#else +return &init_net; +#endif +} +static inline void ip_vs_conn_net_set (struct ip_vs_conn *cp,struct net *net) +{ +#ifdef CONFIG_NET_NS + cp->net = net; +#endif +} + +static inline int ip_vs_conn_net_eq (const struct ip_vs_conn *cp, +struct net *net) +{ +#ifdef CONFIG_NET_NS +return cp->net == net; +#else +return 1 ; +#endif +}/* * Extended internal versions of struct ip_vs_service_user and
@@ -774,13 +804,14 @@ enum { IP_VS_DIR_LAST, }; -static inline void ip_vs_conn_fill_param (int af,int protocol, +static inline void ip_vs_conn_fill_param (struct net *net,int af,int protocol,const union nf_inet_addr *caddr,__be16 cport,const union nf_inet_addr *vaddr,__be16 vport,struct ip_vs_conn_param *p) { + p->net = net; p->af = af; p->protocol = protocol; p->caddr = caddr;
include/net/netns/ip_vs.h +2 -0
@@ -67,6 +67,8 @@ struct netns_ipvs {struct ip_vs_stats_user __percpu *ustats;/* Statistics */ seqcount_t *ustats_seq;/* u64 read retry */ +/* ip_vs_conn */ +atomic_t conn_count;/* connection counter */ /* ip_vs_lblc */ int sysctl_lblc_expiration;struct ctl_table_header *lblc_ctl_header;
net/netfilter/ipvs/ip_vs_conn.c +70 -42
337 lines not on this page · raw message
net/netfilter/ipvs/ip_vs_core.c +9 -6
@@ -191,7 +191,8 @@ ip_vs_conn_fill_param_persist(const struct ip_vs_service *svc, const union nf_inet_addr *vaddr, __be16 vport, struct ip_vs_conn_param *p) { - ip_vs_conn_fill_param(svc->af, protocol, caddr, cport, vaddr, vport, p); + ip_vs_conn_fill_param(svc->net, svc->af, protocol, caddr, cport, vaddr, +vport ,p ); p->pe = svc->pe;if (p->pe && p->pe->fill_param)return p->pe->fill_param (p, skb);
@@ -334,8 +335,8 @@ ip_vs_sched_persist(struct ip_vs_service *svc,/* * Create a new connection according to the template */ -ip_vs_conn_fill_param (svc->af, iph.protocol, &iph.saddr, src_port, - &iph.daddr, dst_port, ¶m); +ip_vs_conn_fill_param (svc->net, svc->af, iph.protocol, &iph.saddr, + src_port, &iph.daddr, dst_port, ¶m); cp =ip_vs_conn_new (¶m, &dest->addr, dport, flags, dest, skb->mark);if (cp ==NULL ) {
@@ -450,8 +451,10 @@ ip_vs_schedule(struct ip_vs_service *svc, struct sk_buff *skb,*/ {struct ip_vs_conn_param p; -ip_vs_conn_fill_param (svc->af, iph.protocol, &iph.saddr, - pptr[0 ], &iph.daddr, pptr[1 ], &p); + +ip_vs_conn_fill_param (svc->net, svc->af, iph.protocol, + &iph.saddr, pptr[0 ], &iph.daddr, pptr[1 ], + &p); cp =ip_vs_conn_new (&p, &dest->addr, dest->port ? dest->port : pptr[1 ], flags, dest, skb->mark);
@@ -518,7 +521,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,IP_VS_DBG (6 ,"%s(): create a cache_bypass entry\n" , __func__); {struct ip_vs_conn_param p; -ip_vs_conn_fill_param (svc->af, iph.protocol, +ip_vs_conn_fill_param (svc->net, svc->af, iph.protocol, &iph.saddr, pptr[0 ], &iph.daddr, pptr[1 ], &p); cp = ip_vs_conn_new(&p, &daddr, 0,
net/netfilter/ipvs/ip_vs_ftp.c +8 -6
@@ -198,13 +198,15 @@ static int ip_vs_ftp_out(struct ip_vs_app *app, struct ip_vs_conn *cp,*/ {struct ip_vs_conn_param p; -ip_vs_conn_fill_param (AF_INET , iph->protocol, - &from, port, &cp->caddr,0 , &p); +ip_vs_conn_fill_param (ip_vs_conn_net (cp),AF_INET , + iph->protocol, &from, port, + &cp->caddr,0 , &p); n_cp =ip_vs_conn_out_get (&p); }if (!n_cp) {struct ip_vs_conn_param p; -ip_vs_conn_fill_param (AF_INET ,IPPROTO_TCP , &cp->caddr, +ip_vs_conn_fill_param (ip_vs_conn_net (cp), +AF_INET ,IPPROTO_TCP , &cp->caddr,0 , &cp->vaddr, port, &p); n_cp = ip_vs_conn_new(&p, &from, port, IP_VS_CONN_F_NO_CPORT |
@@ -361,9 +363,9 @@ static int ip_vs_ftp_in(struct ip_vs_app *app, struct ip_vs_conn *cp, {struct ip_vs_conn_param p; -ip_vs_conn_fill_param (AF_INET , iph->protocol, &to, port, - &cp->vaddr,htons (ntohs (cp->vport)-1 ), - &p); +ip_vs_conn_fill_param (ip_vs_conn_net (cp),AF_INET , + iph->protocol, &to, port, &cp->vaddr, +htons (ntohs (cp->vport)-1 ), &p); n_cp =ip_vs_conn_in_get (&p);if (!n_cp) { n_cp = ip_vs_conn_new(&p, &cp->daddr,
net/netfilter/ipvs/ip_vs_nfct.c +4 -2
@@ -141,6 +141,7 @@ static void ip_vs_nfct_expect_callback(struct nf_conn *ct,struct nf_conntrack_tuple *orig, new_reply;struct ip_vs_conn *cp;struct ip_vs_conn_param p; +struct net *net =nf_ct_net (ct);if (exp->tuple.src.l3num !=PF_INET )return ;
@@ -155,7 +156,7 @@ static void ip_vs_nfct_expect_callback(struct nf_conn *ct,/* RS->CLIENT */ orig = &ct->tuplehash[IP_CT_DIR_ORIGINAL ].tuple; -ip_vs_conn_fill_param (exp->tuple.src.l3num, orig->dst.protonum, +ip_vs_conn_fill_param (net, exp->tuple.src.l3num, orig->dst.protonum, &orig->src.u3, orig->src.u.tcp.port, &orig->dst.u3, orig->dst.u.tcp.port, &p); cp =ip_vs_conn_out_get (&p);
@@ -268,7 +269,8 @@ void ip_vs_conn_drop_conntrack(struct ip_vs_conn *cp)" for conn " FMT_CONN "\n" , __func__, ARG_TUPLE(&tuple), ARG_CONN(cp)); - h =nf_conntrack_find_get (&init_net,NF_CT_DEFAULT_ZONE , &tuple); + h =nf_conntrack_find_get (ip_vs_conn_net (cp),NF_CT_DEFAULT_ZONE , + &tuple);if (h) { ct =nf_ct_tuplehash_to_ctrack (h);/* Show what happens instead of calling nf_ct_kill() */
net/netfilter/ipvs/ip_vs_proto_ah_esp.c +9 -6
@@ -41,15 +41,16 @@ struct isakmp_hdr {#define PORT_ISAKMP 500static void -ah_esp_conn_fill_param_proto (int af,const struct ip_vs_iphdr *iph, -int inverse,struct ip_vs_conn_param *p) +ah_esp_conn_fill_param_proto (struct net *net,int af, +const struct ip_vs_iphdr *iph,int inverse, +struct ip_vs_conn_param *p) {if (likely (!inverse)) -ip_vs_conn_fill_param (af,IPPROTO_UDP , +ip_vs_conn_fill_param (net, af,IPPROTO_UDP , &iph->saddr,htons (PORT_ISAKMP ), &iph->daddr,htons (PORT_ISAKMP ), p);else -ip_vs_conn_fill_param (af,IPPROTO_UDP , +ip_vs_conn_fill_param (net, af,IPPROTO_UDP , &iph->daddr,htons (PORT_ISAKMP ), &iph->saddr,htons (PORT_ISAKMP ), p); }
@@ -61,8 +62,9 @@ ah_esp_conn_in_get(int af, const struct sk_buff *skb, {struct ip_vs_conn *cp;struct ip_vs_conn_param p; +struct net *net =skb_net (skb); -ah_esp_conn_fill_param_proto (af, iph, inverse, &p); +ah_esp_conn_fill_param_proto (net, af, iph, inverse, &p); cp =ip_vs_conn_in_get (&p);if (!cp) {/*
@@ -89,8 +91,9 @@ ah_esp_conn_out_get(int af, const struct sk_buff *skb, {struct ip_vs_conn *cp;struct ip_vs_conn_param p; +struct net *net =skb_net (skb); -ah_esp_conn_fill_param_proto (af, iph, inverse, &p); +ah_esp_conn_fill_param_proto (net, af, iph, inverse, &p); cp =ip_vs_conn_out_get (&p);if (!cp) { IP_VS_DBG_BUF(12, "Unknown ISAKMP entry for inout packet "
net/netfilter/ipvs/ip_vs_proto_sctp.c +1 -1
@@ -1055,7 +1055,7 @@ static void sctp_unregister_app(struct net *net, struct ip_vs_app *inc)static int sctp_app_conn_bind (struct ip_vs_conn *cp) { -struct netns_ipvs *ipvs =net_ipvs (&init_net); +struct netns_ipvs *ipvs =net_ipvs (ip_vs_conn_net (cp));int hash;struct ip_vs_app *inc;int result =0 ;
net/netfilter/ipvs/ip_vs_proto_tcp.c +1 -1
@@ -619,7 +619,7 @@ tcp_unregister_app(struct net *net, struct ip_vs_app *inc)static int tcp_app_conn_bind (struct ip_vs_conn *cp) { -struct netns_ipvs *ipvs =net_ipvs (&init_net); +struct netns_ipvs *ipvs =net_ipvs (ip_vs_conn_net (cp));int hash;struct ip_vs_app *inc;int result =0 ;
net/netfilter/ipvs/ip_vs_proto_udp.c +1 -1
@@ -396,7 +396,7 @@ udp_unregister_app(struct net *net, struct ip_vs_app *inc)static int udp_app_conn_bind (struct ip_vs_conn *cp) { -struct netns_ipvs *ipvs =net_ipvs (&init_net); +struct netns_ipvs *ipvs =net_ipvs (ip_vs_conn_net (cp));int hash;struct ip_vs_app *inc;int result =0 ;
net/netfilter/ipvs/ip_vs_sync.c +6 -7
@@ -657,21 +657,21 @@ control:* fill_param used by version 1 */ static inline int -ip_vs_conn_fill_param_sync (int af,union ip_vs_sync_conn *sc, +ip_vs_conn_fill_param_sync (struct net *net,int af,union ip_vs_sync_conn *sc,struct ip_vs_conn_param *p,__u8 *pe_data,unsigned int pe_data_len,__u8 *pe_name,unsigned int pe_name_len) {#ifdef CONFIG_IP_VS_IPV6 if (af ==AF_INET6 ) -ip_vs_conn_fill_param (af, sc->v6.protocol, +ip_vs_conn_fill_param (net, af, sc->v6.protocol, (const union nf_inet_addr *)&sc->v6.caddr, sc->v6.cport, (const union nf_inet_addr *)&sc->v6.vaddr, sc->v6.vport, p); else#endif - ip_vs_conn_fill_param(af, sc->v4.protocol, + ip_vs_conn_fill_param(net, af, sc->v4.protocol, (const union nf_inet_addr *)&sc->v4.caddr, sc->v4.cport, (const union nf_inet_addr *)&sc->v4.vaddr,
@@ -878,7 +878,7 @@ static void ip_vs_process_message_v0(struct net *net, const char *buffer, } } - ip_vs_conn_fill_param(AF_INET, s->protocol, + ip_vs_conn_fill_param(net, AF_INET, s->protocol, (const union nf_inet_addr *)&s->caddr, s->cport, (const union nf_inet_addr *)&s->vaddr,
@@ -1040,9 +1040,8 @@ static inline int ip_vs_proc_sync_conn(struct net *net, __u8 *p, __u8 *msg_end) state =0 ; } } -if (ip_vs_conn_fill_param_sync (af, s, ¶m, - pe_data, pe_data_len, - pe_name, pe_name_len)) { +if (ip_vs_conn_fill_param_sync (net, af, s, ¶m, pe_data, + pe_data_len, pe_name, pe_name_len)) { retc =50 ; goto out; }
--
1.7.2.3
PATCH 17/22 IPVS: netns, ip_vs_ctl local vars moved to ipvs struct.
In reply to [email protected]From: Hans Schillstrom <[email protected]>
Moving global vars to ipvs struct, except for svc table lock. Next patch for ctl will be drop-rate handling.
*v3__ip_vs_mutex remains global
ip_vs_conntrack_enabled(struct netns_ipvs *ipvs)
--- include/net/ip_vs.h | 21 +-- include/net/netns/ip_vs.h | 37 ++++- net/netfilter/ipvs/ip_vs_conn.c | 7 +- net/netfilter/ipvs/ip_vs_core.c | 34 +++-- net/netfilter/ipvs/ip_vs_ctl.c | 293 +++++++++++++++++---------------- net/netfilter/ipvs/ip_vs_proto_sctp.c | 2 +- net/netfilter/ipvs/ip_vs_proto_tcp.c | 2 +- net/netfilter/ipvs/ip_vs_proto_udp.c | 2 +- net/netfilter/ipvs/ip_vs_sync.c | 9 +- 9 files changed, 227 insertions(+), 180 deletions(-)
include/net/ip_vs.h +7 -14
@@ -1001,13 +1001,6 @@ extern int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,/* * IPVS control data and functions (from ip_vs_ctl.c) */ -extern int sysctl_ip_vs_cache_bypass; -extern int sysctl_ip_vs_expire_nodest_conn; -extern int sysctl_ip_vs_expire_quiescent_template; -extern int sysctl_ip_vs_sync_threshold[2 ]; -extern int sysctl_ip_vs_nat_icmp_send; -extern int sysctl_ip_vs_conntrack; -extern int sysctl_ip_vs_snat_reroute;extern struct ip_vs_stats ip_vs_stats;extern const struct ctl_path net_vs_ctl_path[];extern int sysctl_ip_vs_sync_ver;
@@ -1097,11 +1090,11 @@ extern int ip_vs_icmp_xmit_v6extern int ip_vs_drop_rate;extern int ip_vs_drop_counter; -static __inline__int ip_vs_todrop (void ) +static __inline__int ip_vs_todrop (struct netns_ipvs *ipvs) { -if (!ip_vs_drop_rate)return 0 ; -if (--ip_vs_drop_counter >0 )return 0 ; - ip_vs_drop_counter = ip_vs_drop_rate; +if (!ipvs->drop_rate)return 0 ; +if (--ipvs->drop_counter >0 )return 0 ; + ipvs->drop_counter = ipvs->drop_rate;return 1 ; }
@@ -1189,9 +1182,9 @@ static inline void ip_vs_notrack(struct sk_buff *skb)* Netfilter connection tracking * (from ip_vs_nfct.c) */ -static inline int ip_vs_conntrack_enabled (void ) +static inline int ip_vs_conntrack_enabled (struct netns_ipvs *ipvs) { -return sysctl_ip_vs_conntrack; +return ipvs->sysctl_conntrack; } extern void ip_vs_update_conntrack(struct sk_buff *skb, struct ip_vs_conn *cp,
@@ -1204,7 +1197,7 @@ extern void ip_vs_conn_drop_conntrack(struct ip_vs_conn *cp);#else -static inline int ip_vs_conntrack_enabled (void ) +static inline int ip_vs_conntrack_enabled (struct netns_ipvs *ipvs) {return 0 ; }
include/net/netns/ip_vs.h +35 -2
@@ -62,13 +62,46 @@ struct netns_ipvs {struct list_head sctp_apps[SCTP_APP_TAB_SIZE ];spinlock_t sctp_app_lock;#endif +/* ip_vs_conn */ +atomic_t conn_count;/* connection counter */ +/* ip_vs_ctl */ struct ip_vs_stats *ctl_stats;/* Statistics & estimator */ struct ip_vs_stats_user __percpu *ustats;/* Statistics */ seqcount_t *ustats_seq;/* u64 read retry */ -/* ip_vs_conn */ -atomic_t conn_count;/* connection counter */ +int num_services;/* no of virtual services */ +/* 1/rate drop and drop-entry variables */ +int drop_rate; +int drop_counter; +atomic_t dropentry; +/* locks in ctl.c */ +spinlock_t dropentry_lock;/* drop entry handling */ +spinlock_t droppacket_lock;/* drop packet handling */ +spinlock_t securetcp_lock;/* state and timeout tables */ +rwlock_t rs_lock;/* real services table */ +/* semaphore for IPVS sockopts. And, [gs]etsockopt may sleep. */ +struct lock_class_key ctl_key;/* ctl_mutex debuging */ +/* sys-ctl struct */ +struct ctl_table_header *sysctl_hdr; +struct ctl_table *sysctl_tbl; +/* sysctl variables */ +int sysctl_amemthresh; +int sysctl_am_droprate; +int sysctl_drop_entry; +int sysctl_drop_packet; +int sysctl_secure_tcp; +#ifdef CONFIG_IP_VS_NFCT +int sysctl_conntrack; +#endif +int sysctl_snat_reroute; +int sysctl_sync_ver; +int sysctl_cache_bypass; +int sysctl_expire_nodest_conn; +int sysctl_expire_quiescent_template; +int sysctl_sync_threshold[2 ]; +int sysctl_nat_icmp_send; +/* ip_vs_lblc */ int sysctl_lblc_expiration;struct ctl_table_header *lblc_ctl_header;
net/netfilter/ipvs/ip_vs_conn.c +4 -3
@@ -686,13 +686,14 @@ static inline void ip_vs_unbind_dest(struct ip_vs_conn *cp)int ip_vs_check_template (struct ip_vs_conn *ct) {struct ip_vs_dest *dest = ct->dest; +struct netns_ipvs *ipvs =net_ipvs (ip_vs_conn_net (ct));/* * Checking the dest server status. */ if ((dest ==NULL ) || !(dest->flags &IP_VS_DEST_F_AVAILABLE ) || - (sysctl_ip_vs_expire_quiescent_template && + (ipvs->sysctl_expire_quiescent_template && (atomic_read (&dest->weight) ==0 ))) {IP_VS_DBG_BUF (9 ,"check_template: dest not available for " "protocol %s s:%s:%d v:%s:%d "
@@ -879,7 +880,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,* IP_VS_CONN_F_ONE_PACKET too. */ -if (ip_vs_conntrack_enabled ()) +if (ip_vs_conntrack_enabled (ipvs)) cp->flags |=IP_VS_CONN_F_NFCT ;/* Hash it in the ip_vs_conn_tab finally */
@@ -1198,7 +1199,7 @@ static void ip_vs_conn_flush(struct net *net)struct ip_vs_conn *cp;struct netns_ipvs *ipvs =net_ipvs (net); - flush_again: +flush_again:for (idx =0 ; idx < ip_vs_conn_tab_size; idx++) {/* * Lock is actually needed in this loop.
net/netfilter/ipvs/ip_vs_core.c +22 -12
@@ -485,6 +485,7 @@ ip_vs_schedule(struct ip_vs_service *svc, struct sk_buff *skb,int ip_vs_leave (struct ip_vs_service *svc,struct sk_buff *skb,struct ip_vs_proto_data *pd) { +struct netns_ipvs *ipvs;__be16 _ports[2 ], *pptr;struct ip_vs_iphdr iph;int unicast;
@@ -507,7 +508,8 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,/* if it is fwmark-based service, the cache_bypass sysctl is up and the destination is a non-local unicast, then create a cache_bypass connection entry */ -if (sysctl_ip_vs_cache_bypass && svc->fwmark && unicast) { + ipvs =net_ipvs (skb_net (skb)); +if (ipvs->sysctl_cache_bypass && svc->fwmark && unicast) {int ret, cs;struct ip_vs_conn *cp; unsigned int flags = (svc->flags & IP_VS_SVC_F_ONEPACKET &&
@@ -719,6 +721,7 @@ static int handle_response_icmp(int af, struct sk_buff *skb,struct ip_vs_protocol *pp, unsigned int offset, unsigned int ihl) { + struct netns_ipvs *ipvs;unsigned int verdict =NF_DROP ;if (IP_VS_FWD_METHOD (cp) !=0 ) {
@@ -740,6 +743,8 @@ static int handle_response_icmp(int af, struct sk_buff *skb,if (!skb_make_writable (skb, offset)) goto out; + ipvs =net_ipvs (skb_net (skb)); +#ifdef CONFIG_IP_VS_IPV6 if (af ==AF_INET6 )ip_vs_nat_icmp_v6 (skb, pp, cp,1 );
@@ -749,11 +754,11 @@ static int handle_response_icmp(int af, struct sk_buff *skb,#ifdef CONFIG_IP_VS_IPV6 if (af ==AF_INET6 ) { -if (sysctl_ip_vs_snat_reroute &&ip6_route_me_harder (skb) !=0 ) +if (ipvs->sysctl_snat_reroute &&ip6_route_me_harder (skb) !=0 ) goto out; } else#endif -if ((sysctl_ip_vs_snat_reroute || +if ((ipvs->sysctl_snat_reroute ||skb_rtable (skb)->rt_flags &RTCF_LOCAL ) &&ip_route_me_harder (skb,RTN_LOCAL ) !=0 ) goto out;
@@ -965,6 +970,7 @@ handle_response(int af, struct sk_buff *skb, struct ip_vs_proto_data *pd, struct ip_vs_conn *cp, int ihl) {struct ip_vs_protocol *pp = pd->pp; +struct netns_ipvs *ipvs;IP_VS_DBG_PKT (11 , af, pp, skb,0 ,"Outgoing packet" );
@@ -1000,13 +1006,15 @@ handle_response(int af, struct sk_buff *skb, struct ip_vs_proto_data *pd,* if it came from this machine itself. So re-compute * the routing information. */ + ipvs =net_ipvs (skb_net (skb)); +#ifdef CONFIG_IP_VS_IPV6 if (af ==AF_INET6 ) { -if (sysctl_ip_vs_snat_reroute &&ip6_route_me_harder (skb) !=0 ) +if (ipvs->sysctl_snat_reroute &&ip6_route_me_harder (skb) !=0 ) goto drop; } else#endif -if ((sysctl_ip_vs_snat_reroute || +if ((ipvs->sysctl_snat_reroute ||skb_rtable (skb)->rt_flags &RTCF_LOCAL ) &&ip_route_me_harder (skb,RTN_LOCAL ) !=0 ) goto drop;
@@ -1043,6 +1051,7 @@ ip_vs_out(unsigned int hooknum, struct sk_buff *skb, int af)struct ip_vs_protocol *pp;struct ip_vs_proto_data *pd;struct ip_vs_conn *cp; +struct netns_ipvs *ipvs;EnterFunction (11 );
@@ -1117,10 +1126,11 @@ ip_vs_out(unsigned int hooknum, struct sk_buff *skb, int af)* Check if the packet belongs to an existing entry */ cp = pp->conn_out_get (af, skb, &iph, iph.len,0 ); + ipvs =net_ipvs (net);if (likely (cp))return handle_response (af, skb, pd, cp, iph.len); -if (sysctl_ip_vs_nat_icmp_send && +if (ipvs->sysctl_nat_icmp_send && (pp->protocol ==IPPROTO_TCP || pp->protocol ==IPPROTO_UDP || pp->protocol ==IPPROTO_SCTP )) {
@@ -1566,7 +1576,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)if (cp->dest && !(cp->dest->flags &IP_VS_DEST_F_AVAILABLE )) {/* the destination server is not available */ -if (sysctl_ip_vs_expire_nodest_conn) { +if (ipvs->sysctl_expire_nodest_conn) {/* try to expire the connection immediately */ ip_vs_conn_expire_now (cp); }
@@ -1596,15 +1606,15 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)*/ if (cp->flags &IP_VS_CONN_F_ONE_PACKET ) - pkts = sysctl_ip_vs_sync_threshold[0 ]; + pkts = ipvs->sysctl_sync_threshold[0 ];else pkts =atomic_add_return (1 , &cp->in_pkts);if ((ipvs->sync_state &IP_VS_STATE_MASTER ) && cp->protocol ==IPPROTO_SCTP ) { if ((cp->state == IP_VS_SCTP_S_ESTABLISHED && - (pkts % sysctl_ip_vs_sync_threshold[1] - == sysctl_ip_vs_sync_threshold[0])) || + (pkts % ipvs->sysctl_sync_threshold[1] + == ipvs->sysctl_sync_threshold[0])) || (cp->old_state != cp->state && ((cp->state == IP_VS_SCTP_S_CLOSED) || (cp->state == IP_VS_SCTP_S_SHUT_ACK_CLI) ||
@@ -1618,8 +1628,8 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af) else if ((ipvs->sync_state & IP_VS_STATE_MASTER) && (((cp->protocol != IPPROTO_TCP || cp->state == IP_VS_TCP_S_ESTABLISHED) && - (pkts % sysctl_ip_vs_sync_threshold[1] - == sysctl_ip_vs_sync_threshold[0])) || + (pkts % ipvs->sysctl_sync_threshold[1] + == ipvs->sysctl_sync_threshold[0])) || ((cp->protocol == IPPROTO_TCP) && (cp->old_state != cp->state) && ((cp->state == IP_VS_TCP_S_FIN_WAIT) || (cp->state == IP_VS_TCP_S_CLOSE) ||
net/netfilter/ipvs/ip_vs_ctl.c +151 -142
571 lines not on this page · raw message
net/netfilter/ipvs/ip_vs_proto_sctp.c +1 -1
@@ -34,7 +34,7 @@ sctp_conn_schedule(int af, struct sk_buff *skb, struct ip_vs_proto_data *pd, &iph.daddr, sh->dest))) {int ignored; -if (ip_vs_todrop ()) { +if (ip_vs_todrop (net_ipvs (net))) {/* * It seems that we are very loaded. * We have to drop this packet :(
net/netfilter/ipvs/ip_vs_proto_tcp.c +1 -1
@@ -54,7 +54,7 @@ tcp_conn_schedule(int af, struct sk_buff *skb, struct ip_vs_proto_data *pd, &iph.daddr, th->dest))) {int ignored; -if (ip_vs_todrop ()) { +if (ip_vs_todrop (net_ipvs (net))) {/* * It seems that we are very loaded. * We have to drop this packet :(
net/netfilter/ipvs/ip_vs_proto_udp.c +1 -1
@@ -50,7 +50,7 @@ udp_conn_schedule(int af, struct sk_buff *skb, struct ip_vs_proto_data *pd,if (svc) {int ignored; -if (ip_vs_todrop ()) { +if (ip_vs_todrop (net_ipvs (net))) {/* * It seems that we are very loaded. * We have to drop this packet :(
net/netfilter/ipvs/ip_vs_sync.c +5 -4
@@ -393,7 +393,7 @@ void ip_vs_sync_switch_mode(struct net *net, int mode)if (!ipvs->sync_state &IP_VS_STATE_MASTER )return ; -if (mode == sysctl_ip_vs_sync_ver || !ipvs->sync_buff) +if (mode == ipvs->sysctl_sync_ver || !ipvs->sync_buff)return ;spin_lock_bh (&ipvs->sync_buff_lock);
@@ -519,7 +519,7 @@ void ip_vs_sync_conn(struct net *net, struct ip_vs_conn *cp)unsigned int len, pe_name_len, pad;/* Handle old version of the protocol */ -if (sysctl_ip_vs_sync_ver ==0 ) { +if (ipvs->sysctl_sync_ver ==0 ) {ip_vs_sync_conn_v0 (net, cp);return ; }
@@ -647,7 +647,7 @@ control:if (cp->flags &IP_VS_CONN_F_TEMPLATE ) {int pkts =atomic_add_return (1 , &cp->in_pkts); -if (pkts % sysctl_ip_vs_sync_threshold[1 ] !=1 ) +if (pkts % ipvs->sysctl_sync_threshold[1 ] !=1 )return ; } goto sloop;
@@ -721,6 +721,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param, {struct ip_vs_dest *dest;struct ip_vs_conn *cp; +struct netns_ipvs *ipvs =net_ipvs (net);if (!(flags &IP_VS_CONN_F_TEMPLATE )) cp =ip_vs_conn_in_get (param);
@@ -791,7 +792,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,if (opt)memcpy (&cp->in_seq, opt,sizeof (*opt)); -atomic_set (&cp->in_pkts, sysctl_ip_vs_sync_threshold[0 ]); +atomic_set (&cp->in_pkts, ipvs->sysctl_sync_threshold[0 ]); cp->state = state; cp->old_state = cp->state;/*
Signature · 1 line
1.7.2.3
PATCH 18/22 IPVS: netns, defense work timer.
In reply to [email protected]From: Hans Schillstrom <[email protected]>
This patch makes defense work timer per name-space, A net ptr had to be added to the ipvs struct, since it's needed by defense_work_handler.
--- include/net/ip_vs.h | 2 +- include/net/netns/ip_vs.h | 3 +++ net/netfilter/ipvs/ip_vs_conn.c | 5 +++-- net/netfilter/ipvs/ip_vs_core.c | 1 + net/netfilter/ipvs/ip_vs_ctl.c | 20 +++++++++----------- 5 files changed, 17 insertions(+), 14 deletions(-)
include/net/ip_vs.h +1 -1
@@ -855,7 +855,7 @@ extern const char * ip_vs_state_name(__u16 proto, int state);extern void ip_vs_tcp_conn_listen (struct net *net,struct ip_vs_conn *cp);extern int ip_vs_check_template (struct ip_vs_conn *ct); -extern void ip_vs_random_dropentry (void ); +extern void ip_vs_random_dropentry (struct net *net);extern int ip_vs_conn_init (void );extern void ip_vs_conn_cleanup (void );
include/net/netns/ip_vs.h +3 -0
@@ -72,6 +72,7 @@ struct netns_ipvs {int num_services;/* no of virtual services */ /* 1/rate drop and drop-entry variables */ +struct delayed_work defense_work;/* Work handler */ int drop_rate;int drop_counter;atomic_t dropentry;
@@ -131,6 +132,8 @@ struct netns_ipvs {/* multicast interface name */ char master_mcast_ifn[IP_VS_IFNAME_MAXLEN ];char backup_mcast_ifn[IP_VS_IFNAME_MAXLEN ]; +/* net name space ptr */ + struct net *net; /* Needed by timer routines */ };#endif /* IP_VS_H_ */
net/netfilter/ipvs/ip_vs_conn.c +3 -2
@@ -1138,7 +1138,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp) }/* Called from keventd and must protect itself from softirqs */ -void ip_vs_random_dropentry (void ) +void ip_vs_random_dropentry (struct net *net) {int idx;struct ip_vs_conn *cp;
@@ -1158,7 +1158,8 @@ void ip_vs_random_dropentry(void)if (cp->flags &IP_VS_CONN_F_TEMPLATE )/* connection template */ continue ; - +if (!ip_vs_conn_net_eq (cp, net)) +continue ;if (cp->protocol ==IPPROTO_TCP ) {switch (cp->state) {case IP_VS_TCP_S_SYN_RECV :
net/netfilter/ipvs/ip_vs_core.c +1 -0
@@ -1870,6 +1870,7 @@ static int __net_init __ip_vs_init(struct net *net)pr_err ("%s(): no memory.\n" , __func__);return -ENOMEM ; } + ipvs->net = net;/* Incarnation counters used for creating unique names */ ipvs->inc =atomic_read (&ipvs_netns_cnt);atomic_inc (&ipvs_netns_cnt);
net/netfilter/ipvs/ip_vs_ctl.c +9 -8
@@ -218,18 +218,16 @@ static void update_defense_level(struct netns_ipvs *ipvs)* Timer for checking the defense */ #define DEFENSE_TIMER_PERIOD 1*HZ -static void defense_work_handler (struct work_struct *work); -static DECLARE_DELAYED_WORK(defense_work, defense_work_handler);static void defense_work_handler (struct work_struct *work) { -struct netns_ipvs *ipvs =net_ipvs (&init_net); +struct netns_ipvs *ipvs = + container_of(work, struct netns_ipvs, defense_work.work);update_defense_level (ipvs);if (atomic_read (&ipvs->dropentry)) -ip_vs_random_dropentry (); - -schedule_delayed_work (&defense_work,DEFENSE_TIMER_PERIOD ); +ip_vs_random_dropentry (ipvs->net); +schedule_delayed_work (&ipvs->defense_work,DEFENSE_TIMER_PERIOD ); }int
@@ -3539,6 +3537,9 @@ int __net_init __ip_vs_control_init(struct net *net) goto err_reg;ip_vs_new_estimator (net, ipvs->ctl_stats); ipvs->sysctl_tbl = tbl; +/* Schedule defense work */ +INIT_DELAYED_WORK (&ipvs->defense_work, defense_work_handler); +schedule_delayed_work (&ipvs->defense_work,DEFENSE_TIMER_PERIOD );return 0 ; err_reg:
@@ -3563,6 +3564,8 @@ static void __net_exit __ip_vs_control_cleanup(struct net *net)proc_net_remove (net,"ip_vs_stats_percpu" );proc_net_remove (net,"ip_vs_stats" );proc_net_remove (net,"ip_vs" ); +cancel_rearming_delayed_work (&ipvs->defense_work); +cancel_work_sync (&ipvs->defense_work.work);free_percpu (ipvs->ustats);kfree (ipvs->ctl_stats); }
@@ -3606,9 +3609,6 @@ int __init ip_vs_control_init(void) goto err_net; } -/* Hook the defense timer */ -schedule_delayed_work (&defense_work,DEFENSE_TIMER_PERIOD );
PATCH 19/22 IPVS: netns, trash handling
In reply to [email protected]From: Hans Schillstrom <[email protected]>
trash list per namspace,
and reordering of some params in dst struct.
--- include/net/ip_vs.h | 4 ++-- include/net/netns/ip_vs.h | 3 +++ net/netfilter/ipvs/ip_vs_ctl.c | 23 ++++++++++------------- 3 files changed, 15 insertions(+), 15 deletions(-)
include/net/ip_vs.h +2 -2
@@ -640,8 +640,8 @@ struct ip_vs_dest {struct list_head d_list;/* for table with all the dests */ u16 af;/* address family */ -union nf_inet_addr addr;/* IP address of the server */ __be16 port;/* port number of the server */ +union nf_inet_addr addr;/* IP address of the server */ volatile unsigned flags;/* dest status flags */ atomic_t conn_flags;/* flags to copy to conn */ atomic_t weight;/* server weight */
@@ -668,8 +668,8 @@ struct ip_vs_dest {/* for virtual service */ struct ip_vs_service *svc;/* service it belongs to */ __u16 protocol;/* which protocol (TCP/UDP) */ -union nf_inet_addr vaddr;/* virtual IP address */ __be16 vport;/* virtual port number */ +union nf_inet_addr vaddr;/* virtual IP address */ __u32 vfwmark;/* firewall mark of service */ };
include/net/netns/ip_vs.h +3 -0
@@ -83,6 +83,9 @@ struct netns_ipvs {rwlock_t rs_lock;/* real services table */ /* semaphore for IPVS sockopts. And, [gs]etsockopt may sleep. */ struct lock_class_key ctl_key;/* ctl_mutex debuging */ +/* Trash for destinations */ +struct list_head dest_trash; +/* sys-ctl struct */ struct ctl_table_header *sysctl_hdr;struct ctl_table *sysctl_tbl;
net/netfilter/ipvs/ip_vs_ctl.c +10 -13
@@ -256,11 +256,6 @@ static struct list_head ip_vs_svc_table[IP_VS_SVC_TAB_SIZE];static struct list_head ip_vs_svc_fwm_table[IP_VS_SVC_TAB_SIZE ];/* -* Trash for destinations -*/ -static LIST_HEAD (ip_vs_dest_trash); - -/* * FTP & NULL virtual service counters */ static atomic_t ip_vs_ftpsvc_counter =ATOMIC_INIT (0 );
@@ -649,11 +644,12 @@ ip_vs_trash_get_dest(struct ip_vs_service *svc, const union nf_inet_addr *daddr, __be16 dport) {struct ip_vs_dest *dest, *nxt; +struct netns_ipvs *ipvs =net_ipvs (svc->net);/* * Find the destination in trash */ -list_for_each_entry_safe (dest, nxt, &ip_vs_dest_trash, n_list) { +list_for_each_entry_safe (dest, nxt, &ipvs->dest_trash, n_list) { IP_VS_DBG_BUF(3, "Destination %u/%s:%u still in trash, " "dest->refcnt=%d\n", dest->vfwmark,
@@ -701,11 +697,12 @@ ip_vs_trash_get_dest(struct ip_vs_service *svc, const union nf_inet_addr *daddr,* are expired, and the refcnt of each destination in the trash must * be 1, so we simply release them here. */ -static void ip_vs_trash_cleanup (void ) +static void ip_vs_trash_cleanup (struct net *net) {struct ip_vs_dest *dest, *nxt; +struct netns_ipvs *ipvs =net_ipvs (net); -list_for_each_entry_safe (dest, nxt, &ip_vs_dest_trash, n_list) { +list_for_each_entry_safe (dest, nxt, &ipvs->dest_trash, n_list) {list_del (&dest->n_list);ip_vs_dst_reset (dest);__ip_vs_unbind_svc (dest);
@@ -830,7 +827,6 @@ ip_vs_new_dest(struct ip_vs_service *svc, struct ip_vs_dest_user_kern *udest,pr_err ("%s(): no memory.\n" , __func__);return -ENOMEM ; } - dest->af = svc->af; dest->protocol = svc->protocol; dest->vaddr = svc->addr;
@@ -1008,7 +1004,7 @@ static void __ip_vs_del_dest(struct net *net, struct ip_vs_dest *dest)IP_VS_DBG_ADDR (dest->af, &dest->addr),ntohs (dest->port), atomic_read(&dest->refcnt)); -list_add (&dest->n_list, &ip_vs_dest_trash); +list_add (&dest->n_list, &ipvs->dest_trash);atomic_inc (&dest->refcnt); } }
@@ -3477,6 +3473,7 @@ int __net_init __ip_vs_control_init(struct net *net)for (idx =0 ; idx <IP_VS_RTAB_SIZE ; idx++) {INIT_LIST_HEAD (&ipvs->rs_table[idx]); } +INIT_LIST_HEAD (&ipvs->dest_trash);/* procfs stats */ ipvs->ctl_stats =kzalloc (sizeof (struct ip_vs_stats ),GFP_KERNEL );
@@ -3559,13 +3556,14 @@ static void __net_exit __ip_vs_control_cleanup(struct net *net)if (!net_eq (net, &init_net))/* netns not enabled yet */ return ; +ip_vs_trash_cleanup (net);ip_vs_kill_estimator (net, ipvs->ctl_stats); +cancel_rearming_delayed_work (&ipvs->defense_work); +cancel_work_sync (&ipvs->defense_work.work);unregister_net_sysctl_table (ipvs->sysctl_hdr);proc_net_remove (net,"ip_vs_stats_percpu" );proc_net_remove (net,"ip_vs_stats" );proc_net_remove (net,"ip_vs" ); -cancel_rearming_delayed_work (&ipvs->defense_work); -cancel_work_sync (&ipvs->defense_work.work);free_percpu (ipvs->ustats);kfree (ipvs->ctl_stats); }
@@ -3622,7 +3620,6 @@ err:void ip_vs_control_cleanup (void ) {EnterFunction (2 ); -ip_vs_trash_cleanup ();unregister_pernet_subsys (&ipvs_control_ops);ip_vs_genl_unregister ();nf_unregister_sockopt (&ip_vs_sockopts);
Signature · 1 line
1.7.2.3
PATCH 20/22 IPVS: netns, svc counters moved in ip_vs_ctl,c
In reply to [email protected]From: Hans Schillstrom <[email protected]>
Last two global vars to be moved,ip_vs_ftpsvc_counter and ip_vs_nullsvc_counter.
--- include/net/netns/ip_vs.h | 4 ++++ net/netfilter/ipvs/ip_vs_ctl.c | 21 +++++++++------------ 2 files changed, 13 insertions(+), 12 deletions(-)
include/net/netns/ip_vs.h +4 -0
@@ -71,6 +71,7 @@ struct netns_ipvs {seqcount_t *ustats_seq;/* u64 read retry */ int num_services;/* no of virtual services */ +/* 1/rate drop and drop-entry variables */ struct delayed_work defense_work;/* Work handler */ int drop_rate;
@@ -85,6 +86,9 @@ struct netns_ipvs {struct lock_class_key ctl_key;/* ctl_mutex debuging */ /* Trash for destinations */ struct list_head dest_trash; +/* Service counters */ +atomic_t ftpsvc_counter; +atomic_t nullsvc_counter;/* sys-ctl struct */ struct ctl_table_header *sysctl_hdr;
net/netfilter/ipvs/ip_vs_ctl.c +9 -12
@@ -255,12 +255,6 @@ static struct list_head ip_vs_svc_table[IP_VS_SVC_TAB_SIZE];/* the service table hashed by fwmark */ static struct list_head ip_vs_svc_fwm_table[IP_VS_SVC_TAB_SIZE ]; -/* -* FTP & NULL virtual service counters -*/ -static atomic_t ip_vs_ftpsvc_counter =ATOMIC_INIT (0 ); -static atomic_t ip_vs_nullsvc_counter =ATOMIC_INIT (0 ); -/* * Returns hash value for virtual service
@@ -410,6 +404,7 @@ ip_vs_service_get(struct net *net, int af, __u32 fwmark, __u16 protocol, const union nf_inet_addr *vaddr, __be16 vport) {struct ip_vs_service *svc; +struct netns_ipvs *ipvs =net_ipvs (net);read_lock (&__ip_vs_svc_lock);
@@ -427,7 +422,7 @@ ip_vs_service_get(struct net *net, int af, __u32 fwmark, __u16 protocol,if (svc ==NULL && protocol ==IPPROTO_TCP - &&atomic_read (&ip_vs_ftpsvc_counter) + &&atomic_read (&ipvs->ftpsvc_counter) && (vport ==FTPDATA ||ntohs (vport) >=PROT_SOCK )) {/* * Check if ftp service entry exists, the packet
@@ -437,7 +432,7 @@ ip_vs_service_get(struct net *net, int af, __u32 fwmark, __u16 protocol, }if (svc ==NULL - &&atomic_read (&ip_vs_nullsvc_counter)) { + &&atomic_read (&ipvs->nullsvc_counter)) {/* * Check if the catch-all port (port zero) exists */
@@ -1154,9 +1149,9 @@ ip_vs_add_service(struct net *net, struct ip_vs_service_user_kern *u,/* Update the virtual service counters */ if (svc->port ==FTPPORT ) -atomic_inc (&ip_vs_ftpsvc_counter); +atomic_inc (&ipvs->ftpsvc_counter);else if (svc->port ==0 ) -atomic_inc (&ip_vs_nullsvc_counter); +atomic_inc (&ipvs->nullsvc_counter);ip_vs_new_estimator (net, &svc->stats);
@@ -1337,9 +1332,9 @@ static void __ip_vs_del_service(struct ip_vs_service *svc)* Update the virtual service counters */ if (svc->port ==FTPPORT ) -atomic_dec (&ip_vs_ftpsvc_counter); +atomic_dec (&ipvs->ftpsvc_counter);else if (svc->port ==0 ) -atomic_dec (&ip_vs_nullsvc_counter); +atomic_dec (&ipvs->nullsvc_counter);/* * Free the service if nobody refers to it
@@ -3474,6 +3469,8 @@ int __net_init __ip_vs_control_init(struct net *net)INIT_LIST_HEAD (&ipvs->rs_table[idx]); }INIT_LIST_HEAD (&ipvs->dest_trash); +atomic_set (&ipvs->ftpsvc_counter,0 ); +atomic_set (&ipvs->nullsvc_counter,0 );/* procfs stats */ ipvs->ctl_stats =kzalloc (sizeof (struct ip_vs_stats ),GFP_KERNEL );
Signature · 1 line
1.7.2.3
PATCH 21/22 IPVS: netns, misc init_net removal in core.
In reply to [email protected]From: Hans Schillstrom <[email protected]>
init_net removed in __ip_vs_addr_is_local_v6, and got net as param.
--- net/netfilter/ipvs/ip_vs_core.c | 6 ++++-- net/netfilter/ipvs/ip_vs_ctl.c | 9 +++++---- 2 files changed, 9 insertions(+), 6 deletions(-)
net/netfilter/ipvs/ip_vs_core.c +4 -2
@@ -485,6 +485,7 @@ ip_vs_schedule(struct ip_vs_service *svc, struct sk_buff *skb,int ip_vs_leave (struct ip_vs_service *svc,struct sk_buff *skb,struct ip_vs_proto_data *pd) { +struct net *net;struct netns_ipvs *ipvs;__be16 _ports[2 ], *pptr;struct ip_vs_iphdr iph;
@@ -497,18 +498,19 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,ip_vs_service_put (svc);return NF_DROP ; } + net =skb_net (skb);#ifdef CONFIG_IP_VS_IPV6 if (svc->af ==AF_INET6 ) unicast =ipv6_addr_type (&iph.daddr.in6) &IPV6_ADDR_UNICAST ; else#endif - unicast = (inet_addr_type (&init_net, iph.daddr.ip) ==RTN_UNICAST ); + unicast = (inet_addr_type (net, iph.daddr.ip) ==RTN_UNICAST );/* if it is fwmark-based service, the cache_bypass sysctl is up and the destination is a non-local unicast, then create a cache_bypass connection entry */ - ipvs =net_ipvs (skb_net (skb)); + ipvs =net_ipvs (net);if (ipvs->sysctl_cache_bypass && svc->fwmark && unicast) {int ret, cs;struct ip_vs_conn *cp;
net/netfilter/ipvs/ip_vs_ctl.c +5 -4
@@ -71,7 +71,8 @@ int ip_vs_get_debug_level(void) #ifdef CONFIG_IP_VS_IPV6 /* Taken from rt6_fill_node() in net/ipv6/route.c, is there a better way? */ -static int __ip_vs_addr_is_local_v6(const struct in6_addr *addr) +static int __ip_vs_addr_is_local_v6(struct net *net, + const struct in6_addr *addr) { struct rt6_info *rt; struct flowi fl = {
@@ -82,7 +83,7 @@ static int __ip_vs_addr_is_local_v6(const struct in6_addr *addr) .saddr = { .s6_addr32 = {0, 0, 0, 0} }, } }, }; - rt = (struct rt6_info *)ip6_route_output (&init_net,NULL , &fl); + rt = (struct rt6_info *)ip6_route_output (net,NULL , &fl);if (rt && rt->rt6i_dev && (rt->rt6i_dev->flags &IFF_LOOPBACK ))return 1 ;
@@ -807,12 +808,12 @@ ip_vs_new_dest(struct ip_vs_service *svc, struct ip_vs_dest_user_kern *udest, atype =ipv6_addr_type (&udest->addr.in6);if ((!(atype &IPV6_ADDR_UNICAST ) || atype &IPV6_ADDR_LINKLOCAL ) && - !__ip_vs_addr_is_local_v6 (&udest->addr.in6)) + !__ip_vs_addr_is_local_v6 (svc->net, &udest->addr.in6))return -EINVAL ; } else#endif { - atype =inet_addr_type (&init_net, udest->addr.ip); + atype =inet_addr_type (svc->net, udest->addr.ip);if (atype !=RTN_LOCAL && atype !=RTN_UNICAST )return -EINVAL ; }
Signature · 1 line
1.7.2.3
PATCH 22/22 IPVS: netns, final patch enabling network name space.
In reply to [email protected]From: Hans Schillstrom <[email protected]>
all init_net removed, (except for some alloc related that needs to be there)
--- net/netfilter/ipvs/ip_vs_app.c | 3 --- net/netfilter/ipvs/ip_vs_conn.c | 5 ----- net/netfilter/ipvs/ip_vs_core.c | 4 ---- net/netfilter/ipvs/ip_vs_ctl.c | 7 +------ net/netfilter/ipvs/ip_vs_est.c | 3 --- net/netfilter/ipvs/ip_vs_ftp.c | 6 ------ net/netfilter/ipvs/ip_vs_sync.c | 5 ----- 7 files changed, 1 insertions(+), 32 deletions(-)
net/netfilter/ipvs/ip_vs_app.c +0 -3
@@ -581,9 +581,6 @@ static int __net_init __ip_vs_app_init(struct net *net) {struct netns_ipvs *ipvs =net_ipvs (net); -if (!net_eq (net, &init_net))/* netns not enabled yet */ -return -EPERM ; -INIT_LIST_HEAD (&ipvs->app_list);__mutex_init (&ipvs->app_mutex,"ipvs->app_mutex" , &ipvs->app_key);proc_net_fops_create (net,"ip_vs_app" ,0 , &ip_vs_app_fops);
net/netfilter/ipvs/ip_vs_conn.c +0 -5
@@ -1234,8 +1234,6 @@ int __net_init __ip_vs_conn_init(struct net *net) {struct netns_ipvs *ipvs =net_ipvs (net); -if (!net_eq (net, &init_net))/* netns not enabled yet */ -return -EPERM ;atomic_set (&ipvs->conn_count,0 );proc_net_fops_create (net,"ip_vs_conn" ,0 , &ip_vs_conn_fops);
@@ -1245,9 +1243,6 @@ int __net_init __ip_vs_conn_init(struct net *net) static void __net_exit __ip_vs_conn_cleanup(struct net *net) { -if (!net_eq (net, &init_net))/* netns not enabled yet */ -return ; -/* flush all the connection entries first */ ip_vs_conn_flush (net);proc_net_remove (net,"ip_vs_conn" );
net/netfilter/ipvs/ip_vs_core.c +0 -4
@@ -1863,10 +1863,6 @@ static int __net_init __ip_vs_init(struct net *net) {struct netns_ipvs *ipvs; -if (!net_eq (net, &init_net)) { -pr_err ("The final patch for enabling netns is missing\n" ); -return -EPERM ; - } ipvs = (struct netns_ipvs *)net_generic (net, ip_vs_net_id);if (ipvs ==NULL ) {pr_err ("%s(): no memory.\n" , __func__);
net/netfilter/ipvs/ip_vs_ctl.c +1 -6
@@ -2590,6 +2590,7 @@ static struct genl_family ip_vs_genl_family = { .name = IPVS_GENL_NAME, .version = IPVS_GENL_VERSION, .maxattr = IPVS_CMD_MAX, + .netnsok = true, /* Make ipvsadm to work on netns */ };/* Policy used for first-level command attributes */
@@ -3456,9 +3457,6 @@ int __net_init __ip_vs_control_init(struct net *net)struct netns_ipvs *ipvs =net_ipvs (net);struct ctl_table *tbl; -if (!net_eq (net, &init_net))/* netns not enabled yet */ -return -EPERM ; -atomic_set (&ipvs->dropentry,0 );spin_lock_init (&ipvs->dropentry_lock);spin_lock_init (&ipvs->droppacket_lock);
@@ -3551,9 +3549,6 @@ static void __net_exit __ip_vs_control_cleanup(struct net *net) {struct netns_ipvs *ipvs =net_ipvs (net); -if (!net_eq (net, &init_net))/* netns not enabled yet */ -return ; -ip_vs_trash_cleanup (net);ip_vs_kill_estimator (net, ipvs->ctl_stats);cancel_rearming_delayed_work (&ipvs->defense_work);
net/netfilter/ipvs/ip_vs_est.c +0 -3
@@ -198,9 +198,6 @@ static int __net_init __ip_vs_estimator_init(struct net *net) {struct netns_ipvs *ipvs =net_ipvs (net); -if (!net_eq (net, &init_net))/* netns not enabled yet */ -return -EPERM ; -INIT_LIST_HEAD (&ipvs->est_list);spin_lock_init (&ipvs->est_lock);setup_timer (&ipvs->est_timer, estimation_timer, (unsigned long )net);
net/netfilter/ipvs/ip_vs_ftp.c +0 -6
@@ -413,9 +413,6 @@ static int __net_init __ip_vs_ftp_init(struct net *net)int i, ret;struct ip_vs_app *app = &ip_vs_ftp; -if (!net_eq (net, &init_net))/* netns not enabled yet */ -return -EPERM ; - ret =register_ip_vs_app (net, app);if (ret)return ret;
@@ -442,9 +439,6 @@ static void __ip_vs_ftp_exit(struct net *net) {struct ip_vs_app *app = &ip_vs_ftp; -if (!net_eq (net, &init_net))/* netns not enabled yet */ -return ; -unregister_ip_vs_app (net, app); }
net/netfilter/ipvs/ip_vs_sync.c +0 -5
@@ -1653,9 +1653,6 @@ static int __net_init __ip_vs_sync_init(struct net *net) {struct netns_ipvs *ipvs =net_ipvs (net); -if (!net_eq (net, &init_net))/* netns not enabled yet */ -return -EPERM ; -INIT_LIST_HEAD (&ipvs->sync_queue);spin_lock_init (&ipvs->sync_lock);spin_lock_init (&ipvs->sync_buff_lock);
@@ -1668,8 +1665,6 @@ static int __net_init __ip_vs_sync_init(struct net *net)static void __ip_vs_sync_cleanup (struct net *net) { -if (!net_eq (net, &init_net))/* netns not enabled yet */ -return ;stop_sync_thread (net,IP_VS_STATE_MASTER );stop_sync_thread (net,IP_VS_STATE_BACKUP );return ;
Signature · 1 line
1.7.2.3
Re: [*v3 PATCH 01/22] IPVS: netns, add basic init per netns.
In reply to [email protected]include/net/ip_vs.h line 36
Quoted 11 lines · On Thursday 2010-12-30 11:50, [email protected] wrote:
+++
b/include/net/ip_vs.hinclude/net/ip_vs.h +6
-0@@ -28,6 +28,15 @@#if defined(CONFIG_NF_CONNTRACK ) || defined(CONFIG_NF_CONNTRACK_MODULE )#include <net/netfilter/nf_conntrack.h> #endif +#include <net/net_namespace.h> /* Netw namespace */ + +/* +* Generic access of ipvs struct +*/ +static inline struct netns_ipvs *net_ipvs (struct net * net)
Balancing the '*' between the ' ' would be nice... I know it's hard at this time of the year ;-)
include/net/netns/ip_vs.h line 6
Quoted 12 lines
include/net/netns/ip_vs.h new file +6
-0@@ -0,0 +1,26 @@ +/* +* ip_vs.h +* +* Created on: Nov 23, 2010 +* Author: hans +*/
Filenames, creation dates, author names (when they don't serve a copyright notice), CVS $Id$ tags, etc. don't belong into files. The git log exists for that very purpose.
include/net/netns/ip_vs.h line 24
Quoted 3 lines
include/net/netns/ip_vs.h new file +3
-0+struct netns_ipvs { +int inc;/* Incarnation */ +};
Just my thoughts: Incarnation - haven't heard that in a while. ("inc" is also used as an abbreviation for increment, so ~ ~). Other places use "generation" as a term (such as the VFS on inode generation). [I also get the feeling that (re)"incarnation" may require a death, so it is different from "generation" after all -]
Quoted 7 lines
include/net/netns/ip_vs.h new file +3
-0+++ b/net/netfilter/ipvs/ip_vs_core.c@@ -1813,6 +1820,44 @@ static struct nf_hook_ops ip_vs_ops[] __read_mostly = {#endif }; +/* +* Initialize IP Virtual Server netns mem.
include/net/netns/ip_vs.h static struct nf_hook_ops ip_vs_ops[] __read_mostly = { · line 1834
Quoted 10 lines
include/net/netns/ip_vs.h new file +10
-0+*/ +static int __net_init __ip_vs_init (struct net *net) +{ +struct netns_ipvs *ipvs; + +if (!net_eq (net, &init_net)) { +pr_err ("The final patch for enabling netns is missing\n" ); +return -EPERM ; + } + ipvs = (struct netns_ipvs *)net_generic (net, ip_vs_net_id);
Pointless cast is pointless.
Quoted 10 lines
index c1c167a..ea390f8 100644
net/netfilter/ipvs/ip_vs_sync.c +3
-0@@ -1639,3 +1639,31 @@ int stop_sync_thread(int state)return 0 ; } + +/* +* Initialize data struct for each netns
net/netfilter/ipvs/ip_vs_sync.c int stop_sync_thread(int state) · line 1654
Quoted 10 lines
net/netfilter/ipvs/ip_vs_sync.c +10
-0+*/ +static int __net_init __ip_vs_sync_init (struct net *net) +{ +return 0 ; +} + +static void __ip_vs_sync_cleanup (struct net *net) +{ +return ; +}
The trailing return; in functions returning nothing can be (and generally, is) omitted.
Simon Horman
maintainerRe: [*v3 PATCH 14/22] IPVS: netns awareness to ip_vs_sync
In reply to [email protected]Quoted 5 lines · On Thu, Dec 30, 2010 at 11:50:58AM +0100, [email protected] wrote:
From: Hans Schillstrom <[email protected]>
All global variables moved to struct ipvs, most external changes fixed (i.e.
init_netremoved) insync_bufcreate + 4 replaced by sizeof(struct..)
[ snip ]
net/netfilter/ipvs/ip_vs_core.c ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af) · line 1480
Quoted 9 lines
net/netfilter/ipvs/ip_vs_core.c +1
-0@@ -1477,6 +1477,8 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)struct ip_vs_proto_data *pd;struct ip_vs_conn *cp;int ret, restart, pkts; +struct net *net;
The line above adds a duplicate declaration of net as just before the diff-context starts there is
struct net *net = NULL;
Re: [*v3 PATCH 01/22] IPVS: netns, add basic init per netns.
In reply to Jan EngelhardtQuoted 17 lines · On Friday, December 31, 2010 00:58:35 Jan Engelhardt wrote:
include/net/ip_vs.h line 36
Quoted 11 lines · On Thursday 2010-12-30 11:50, [email protected] wrote:
+++
b/include/net/ip_vs.hinclude/net/ip_vs.h +6
-0@@ -28,6 +28,15 @@#if defined(CONFIG_NF_CONNTRACK ) || defined(CONFIG_NF_CONNTRACK_MODULE )#include <net/netfilter/nf_conntrack.h> #endif +#include <net/net_namespace.h> /* Netw namespace */ + +/* +* Generic access of ipvs struct +*/ +static inline struct netns_ipvs *net_ipvs (struct net * net)Balancing the '*' between the ' ' would be nice... I know it's hard at this time of the year ;-)
I'll send a new patch set and run checkpatch,
but that will be after new years eve :-)
Quoted 8 lines
Quoted 8 lines
include/net/netns/ip_vs.h new file +2
-0@@ -0,0 +1,26 @@ +/* +* ip_vs.h
Quoted 9 lines
include/net/netns/ip_vs.h line 6
Quoted 4 lines
include/net/netns/ip_vs.h new file +4
-0+* +* Created on: Nov 23, 2010 +* Author: hans +*/ Filenames, creation dates, author names (when they don't serve a copyright notice), CVS $Id$ tags, etc. don't belong into files. The git log exists for that very purpose.
Oops that's an eclipse feature, that should be removed.
Quoted 9 lines
include/net/netns/ip_vs.h line 24
Quoted 3 lines
include/net/netns/ip_vs.h new file +3
-0+struct netns_ipvs { +int inc;/* Incarnation */ +};Just my thoughts: Incarnation - haven't heard that in a while. ("inc" is also used as an abbreviation for increment, so ~ ~). Other places use "generation" as a term (such as the VFS on inode generation). [I also get the feeling that (re)"incarnation" may require a death, so it is different from "generation" after all -]
:-))
Quoted 6 lines
Quoted 6 lines
include/net/netns/ip_vs.h new file +1
-0+++ b/net/netfilter/ipvs/ip_vs_core.c@@ -1813,6 +1820,44 @@ static struct nf_hook_ops ip_vs_ops[] __read_mostly = {#endif };
Quoted 14 lines
include/net/netns/ip_vs.h static struct nf_hook_ops ip_vs_ops[] __read_mostly = { · line 1834
Quoted 12 lines
include/net/netns/ip_vs.h new file +12
-0+/* +* Initialize IP Virtual Server netns mem. +*/ +static int __net_init __ip_vs_init (struct net *net) +{ +struct netns_ipvs *ipvs; + +if (!net_eq (net, &init_net)) { +pr_err ("The final patch for enabling netns is missing\n" ); +return -EPERM ; + } + ipvs = (struct netns_ipvs *)net_generic (net, ip_vs_net_id);Pointless cast is pointless.
Well, that is a reminder from a backport...
Quoted 16 lines
Quoted 16 lines
index c1c167a..ea390f8 100644
net/netfilter/ipvs/ip_vs_sync.c +8
-0@@ -1639,3 +1639,31 @@ int stop_sync_thread(int state)return 0 ; } + +/* +* Initialize data struct for each netns +*/ +static int __net_init __ip_vs_sync_init (struct net *net) +{ +return 0 ; +}
Quoted 9 lines
net/netfilter/ipvs/ip_vs_sync.c int stop_sync_thread(int state) · line 1654
Quoted 5 lines
net/netfilter/ipvs/ip_vs_sync.c +5
-0+ +static void __ip_vs_sync_cleanup (struct net *net) +{ +return ; +}The trailing return; in functions returning nothing can be (and generally, is) omitted.
Oops
Thanks alot
/Hans
Julian Anastasov
maintainerHello,
Quoted 10 lines · On Thu, 30 Dec 2010, [email protected] wrote:
From: Hans Schillstrom <[email protected]>
This patch series adds network name space support to the LVS.
REVISION
This is version 3
OVERVIEW
Quoted 8 lines
The patch doesn't remove or add any functionality except for netns. For users that don't use network name space (netns) this patch is completely transparent.
Now it's possible to run LVS in a Linux container (see lxc-tools) i.e. a light weight visualization. For example it's possible to run one or several lvs on a real server in their own network name spaces.
Quoted 1 line
From the LVS point of view it looks like it runs on it's own machine.
Only some comments for two of the patches:
v3 PATCH 10/22 use ip_vs_proto_data as param
- Can ip_vs_protocol_timeout_change() walk proto_data_table instead of ip_vs_proto_table to avoid the __ipvs_proto_data_get call?
v3 PATCH 15/22 ip_vs_stats
- Is ustats_seq allocated with alloc_percpu?
Such reader sections should be changed to use tmp vars because
on retry we risk to add the values multiple times. For example:
do {
start = read_seqcount_begin(seq_count);
ipvs->ctl_stats->ustats.inbytes += u->inbytes;
ipvs->ctl_stats->ustats.outbytes += u->outbytes;
} while (read_seqcount_retry(seq_count, start));
should be changed as follows:
u64 inbytes, outbytes;
do {
start = read_seqcount_begin(seq_count);
inbytes = u->inbytes;
outbytes = u->outbytes;
} while (read_seqcount_retry(seq_count, start));
ipvs->ctl_stats->ustats.inbytes += inbytes;
ipvs->ctl_stats->ustats.outbytes += outbytes;
Or it is better to create new struct for percpu stats,
they will have their own syncp, because we can not
change struct ip_vs_stats_user. syncp should be percpu
because we remove locks.
For example:
struct ip_vs_cpu_stats {
struct ip_vs_stats_user ustats;
struct u64_stats_sync syncp;
};
Then we can add this in struct netns_ipvs:
struct ip_vs_cpu_stats __percpu *stats; /* Statistics */
without the seqcount_t * ustats_seq;
Then syncp does not need any initialization, it seems
alloc_percpu returns zeroed area.
When we use percpu stats for all places (dest and svc) we
can create new struct struct ip_vs_counters, so that we
can reduce the memory usage from percpu data. Now stats
include counters and estimated values. The estimated
values should not be percpu. Then ip_vs_cpu_stats
will be shorter (it is not visible to user space):
struct ip_vs_cpu_stats {
struct ip_vs_counters ustats;
struct u64_stats_sync syncp;
};
For writer side in softirq context we should protect the whole
section with u64 counters, for example this code:
spin_lock(&ip_vs_stats.lock);
ip_vs_stats.ustats.outpkts++;
ip_vs_stats.ustats.outbytes += skb->len;
spin_unlock(&ip_vs_stats.lock);
should be changed to:
struct ip_vs_cpu_stats *s = this_cpu_ptr(ipvs->stats);
u64_stats_update_begin(&s->syncp);
s->ustats.outpkts++;
s->ustats.outbytes += skb->len;
u64_stats_update_end(&s->syncp);
Readers should look in similar way, only that _bh fetching
should be used only for the u64 counters because writer is in
softirq context:
u64 inbytes, outbytes;
for_each_possible_cpu(i) {
const struct ip_vs_cpu_stats *s = per_cpu_ptr(ipvs->stats, i);
unsigned int start;
...
do {
start = u64_stats_fetch_begin_bh(&s->syncp);
inbytes = s->ustats.inbytes;
outbytes = s->ustats.outbytes;
} while (u64_stats_fetch_retry_bh(&s->syncp, start));
ipvs->ctl_stats->ustats.inbytes += inbytes;
ipvs->ctl_stats->ustats.outbytes += outbytes;
}
Then IPVS_STAT_ADD and IPVS_STAT_INC can not access
the syncp. They do not look generic enough, in case we
decide to use struct ip_vs_cpu_stats for dest and svc stats.
I think, these macros are not needed.
It is possible to have other macros for write side,
for percpu stats:
#define IP_VS_STATS_UPDATE_BEGIN(stats) \
{ struct ip_vs_cpu_stats *s = this_cpu_ptr(stats); \
u64_stats_update_begin(&s->syncp)
#define IP_VS_STATS_UPDATE_END() \
u64_stats_update_end(&s->syncp); \
}
Then usage can be:
IP_VS_STATS_UPDATE_BEGIN(ipvs->stats);
s->ustats.outpkts++;
s->ustats.outbytes += skb->len;
IP_VS_STATS_UPDATE_END();
Then we can rename ctl_stats to total_stats or full_stats.
get_stats() can be changed to ip_vs_read_cpu_stats(), it
will be used to read all percpu stats as sum in the
total_stats/full_stats structure or tmp space:
/* Get sum of percpu stats */
... ip_vs_read_cpu_stats(struct ip_vs_stats_user *sum,
struct ip_vs_cpu_stats *stats)
{
...
for_each_possible_cpu(i) {
const struct ip_vs_cpu_stats *s = per_cpu_ptr(stats, i);
unsigned int start;
if (i) {...
...
do {
start = u64_stats_fetch_begin_bh(&s->syncp);
inbytes = s->ustats.inbytes;
outbytes = s->ustats.outbytes;
} while (u64_stats_fetch_retry_bh(&s->syncp, start));
sum->inbytes += inbytes;
sum->outbytes += outbytes;
}
}
As result, ip_vs_read_cpu_stats() will be used in
estimation_timer() instead of get_stats():
ip_vs_read_cpu_stats(&ipvs->total_stats->ustats, ipvs->stats);
but also in ip_vs_stats_show()
{
// I hope struct ip_vs_stats_user can fit in stack:
struct ip_vs_stats_user sum;
here we do not need to use spin_lock_bh(&ctl_stats->lock);
because now the stats are lockless, estimation_timer
does not use ctl_stats->lock, so we have to call
ip_vs_read_cpu_stats to avoid problems with
reading incorrect u64 values directly from
ipvs->total_stats->ustats.
ip_vs_read_cpu_stats(&sum, ipvs->stats);
seq_printf for sum
}
ip_vs_read_cpu_stats can be used also in ip_vs_copy_stats()
which copies values to user space and needs proper u64 reading.
But it is used only for svc and dest stats which are not
percpu yet.
Now this code does not look ok:
ip_vs_zero_stats(net_ipvs(net)->ctl_stats);
May be we need new func ip_vs_zero_percpu_stats that will
reset stats for all CPUs, i.e. ipvs->stats in our case?
Even if this operation is not very safe if done from
user space while the softirq can modify u64 counters
on another CPU.Happy New Year!
Re: [*v3 PATCH 02/22] IPVS: netns to services part 1
In reply to [email protected]Quoted 20 lines · On Thursday 2010-12-30 11:50, [email protected] wrote:
include/net/ip_vs.h +20
-0+/* +* Get net ptr from skb in traffic cases +* use skb_sknet when call is from userland (ioctl or netlink) +*/ +static inline struct net *skb_net (struct sk_buff *skb) { +#ifdef CONFIG_NET_NS +#ifdef CONFIG_IP_VS_DEBUG +/* +* This is used for debug only. +* Start with the most likely hit +* End with BUG +*/ +if (likely (skb->dev && skb->dev->nd_net)) +return dev_net (skb->dev); +if (skb_dst (skb)->dev) +return dev_net (skb_dst (skb)->dev); +WARN (skb->sk,"Maybe skb_sknet should be used instead in %s() line:%d\n" , + __func__, __LINE__); +if (likely (skb->sk && skb->sk->sk_net)) +return sock_net (skb->sk);
include/net/ip_vs.h static inline struct netns_ipvs * net_ipvs(struct net* net) · line 69
Quoted 10 lines
include/net/ip_vs.h +10
-0+pr_err ("There is no net ptr to find in the skb in %s() line:%d\n" , + __func__, __LINE__); +BUG (); +#else +return dev_net (skb->dev ? :skb_dst (skb)->dev); +#endif +#else +return &init_net; +#endif +}
Whether NETNS is disabled or not, dev_net(skb->dev) can be used in either case, so the extra return &init_net case is not really required AFAICS.
net/netfilter/ipvs/ip_vs_ctl.c static struct pernet_operations ipvs_control_ops = { · line 3472
Quoted 4 lines
net/netfilter/ipvs/ip_vs_ctl.c +2
-1@@ -3446,43 +3471,48 @@ static struct pernet_operations ipvs_control_ops = { -smp_wmb (); + +smp_wmb ();/* Do wee really need it now ? */
not "whee" :)
Re: [*v3 PATCH 14/22] IPVS: netns awareness to ip_vs_sync
In reply to Simon HormanQuoted 22 lines · On Friday, December 31, 2010 01:44:33 Simon Horman wrote:
Quoted 5 lines · On Thu, Dec 30, 2010 at 11:50:58AM +0100, [email protected] wrote:
From: Hans Schillstrom <[email protected]>
All global variables moved to struct ipvs, most external changes fixed (i.e.
init_netremoved) insync_bufcreate + 4 replaced by sizeof(struct..)[ snip ]
net/netfilter/ipvs/ip_vs_core.c ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af) · line 1480
Quoted 9 lines
net/netfilter/ipvs/ip_vs_core.c +1
-0@@ -1477,6 +1477,8 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)struct ip_vs_proto_data *pd;struct ip_vs_conn *cp;int ret, restart, pkts; +struct net *net;The line above adds a duplicate declaration of net as just before the diff-context starts there is
Quoted 2 lines
struct net *net = NULL;
I'll remove that
Quoted 29 lines · On Saturday, January 01, 2011 13:27:00 Julian Anastasov wrote:
Hello,
Quoted 10 lines · On Thu, 30 Dec 2010, [email protected] wrote:
From: Hans Schillstrom <[email protected]>
This patch series adds network name space support to the LVS.
REVISION
This is version 3
OVERVIEW
Quoted 8 lines
The patch doesn't remove or add any functionality except for netns. For users that don't use network name space (netns) this patch is completely transparent.
Now it's possible to run LVS in a Linux container (see lxc-tools) i.e. a light weight visualization. For example it's possible to run one or several lvs on a real server in their own network name spaces.
Quoted 1 line
From the LVS point of view it looks like it runs on it's own machine.
Only some comments for two of the patches:
v3 PATCH 10/22 use
ip_vs_proto_dataas param
Review
Quoted 3 lines
(quoted diff) +0
-0- Can ip_vs_protocol_timeout_change() walk proto_data_table instead of ip_vs_proto_table to avoid the __ipvs_proto_data_get call?
I just forget to do that ...
Quoted 15 lines
v3 PATCH 15/22
ip_vs_stats(quoted diff) +0
-0- Is ustats_seq allocated with alloc_percpu? Such reader sections should be changed to use tmp vars because on retry we risk to add the values multiple times. For example: do { start = read_seqcount_begin(seq_count); ipvs->ctl_stats->ustats.inbytes += u->inbytes; ipvs->ctl_stats->ustats.outbytes += u->outbytes; } while (read_seqcount_retry(seq_count, start)); should be changed as follows:
Review
Quoted 10 lines
(quoted diff) +0
-0u64 inbytes, outbytes; do { start = read_seqcount_begin(seq_count); inbytes = u->inbytes; outbytes = u->outbytes; } while (read_seqcount_retry(seq_count, start)); ipvs->ctl_stats->ustats.inbytes += inbytes; ipvs->ctl_stats->ustats.outbytes += outbytes;
Ooops, that was a bug :-(
Quoted 26 lines
(quoted diff) +0
-0Or it is better to create new struct for percpu stats, they will have their own syncp, because we can not change struct ip_vs_stats_user. syncp should be percpu because we remove locks. For example: struct ip_vs_cpu_stats { struct ip_vs_stats_user ustats; struct u64_stats_sync syncp; }; Then we can add this in struct netns_ipvs: struct ip_vs_cpu_stats __percpu *stats; /* Statistics */ without the seqcount_t * ustats_seq; Then syncp does not need any initialization, it seems alloc_percpu returns zeroed area. When we use percpu stats for all places (dest and svc) we can create new struct struct ip_vs_counters, so that we can reduce the memory usage from percpu data. Now stats include counters and estimated values. The estimated
Review
Quoted 10 lines
(quoted diff) +0
-0values should not be percpu. Then ip_vs_cpu_stats will be shorter (it is not visible to user space): struct ip_vs_cpu_stats { struct ip_vs_counters ustats; struct u64_stats_sync syncp; }; For writer side in softirq context we should protect the whole section with u64 counters, for example this code:
There is only two u64, inbytes and outbytes
Quoted 107 lines
(quoted diff) +0
-0spin_lock(&ip_vs_stats.lock); ip_vs_stats.ustats.outpkts++; ip_vs_stats.ustats.outbytes += skb->len; spin_unlock(&ip_vs_stats.lock); should be changed to: struct ip_vs_cpu_stats *s = this_cpu_ptr(ipvs->stats); u64_stats_update_begin(&s->syncp); s->ustats.outpkts++; s->ustats.outbytes += skb->len; u64_stats_update_end(&s->syncp); Readers should look in similar way, only that _bh fetching should be used only for the u64 counters because writer is in softirq context: u64 inbytes, outbytes; for_each_possible_cpu(i) { const struct ip_vs_cpu_stats *s = per_cpu_ptr(ipvs->stats, i); unsigned int start; do { start = u64_stats_fetch_begin_bh(&s->syncp); inbytes = s->ustats.inbytes; outbytes = s->ustats.outbytes; } while (u64_stats_fetch_retry_bh(&s->syncp, start)); ipvs->ctl_stats->ustats.inbytes += inbytes; ipvs->ctl_stats->ustats.outbytes += outbytes; } Then IPVS_STAT_ADD and IPVS_STAT_INC can not access the syncp. They do not look generic enough, in case we decide to use struct ip_vs_cpu_stats for dest and svc stats. I think, these macros are not needed. It is possible to have other macros for write side, for percpu stats: #define IP_VS_STATS_UPDATE_BEGIN(stats) \ { struct ip_vs_cpu_stats *s = this_cpu_ptr(stats); \ u64_stats_update_begin(&s->syncp) #define IP_VS_STATS_UPDATE_END() \ u64_stats_update_end(&s->syncp); \ } Then usage can be: IP_VS_STATS_UPDATE_BEGIN(ipvs->stats); s->ustats.outpkts++; s->ustats.outbytes += skb->len; IP_VS_STATS_UPDATE_END(); Then we can rename ctl_stats to total_stats or full_stats. get_stats() can be changed to ip_vs_read_cpu_stats(), it will be used to read all percpu stats as sum in the total_stats/full_stats structure or tmp space: /* Get sum of percpu stats */ ... ip_vs_read_cpu_stats(struct ip_vs_stats_user *sum, struct ip_vs_cpu_stats *stats) { for_each_possible_cpu(i) { const struct ip_vs_cpu_stats *s = per_cpu_ptr(stats, i); unsigned int start; if (i) {... do { start = u64_stats_fetch_begin_bh(&s->syncp); inbytes = s->ustats.inbytes; outbytes = s->ustats.outbytes; } while (u64_stats_fetch_retry_bh(&s->syncp, start)); sum->inbytes += inbytes; sum->outbytes += outbytes; } } As result, ip_vs_read_cpu_stats() will be used in estimation_timer() instead of get_stats(): ip_vs_read_cpu_stats(&ipvs->total_stats->ustats, ipvs->stats); but also in ip_vs_stats_show() { // I hope struct ip_vs_stats_user can fit in stack: struct ip_vs_stats_user sum; here we do not need to use spin_lock_bh(&ctl_stats->lock); because now the stats are lockless, estimation_timer does not use ctl_stats->lock, so we have to call ip_vs_read_cpu_stats to avoid problems with reading incorrect u64 values directly from ipvs->total_stats->ustats. ip_vs_read_cpu_stats(&sum, ipvs->stats); seq_printf for sum } ip_vs_read_cpu_stats can be used also in ip_vs_copy_stats() which copies values to user space and needs proper u64 reading. But it is used only for svc and dest stats which are not percpu yet.
Review
Quoted 10 lines
(quoted diff) +0
-0Now this code does not look ok: ip_vs_zero_stats(net_ipvs(net)->ctl_stats); May be we need new func ip_vs_zero_percpu_stats that will reset stats for all CPUs, i.e. ipvs->stats in our case? Even if this operation is not very safe if done from user space while the softirq can modify u64 counters on another CPU.
OK, I will take a look at this when I'm back from my vacation at 20 Jan. I guess it might be worth the work to make all the stat counters per_cpu.
My tests shows that the big "CPU cycle bandit" was the one that I made per_cpu.
Quoted 4 lines
Happy New Year!
Re: [*v3 PATCH 02/22] IPVS: netns to services part 1
In reply to Jan EngelhardtQuoted 26 lines · Jan Engelhardt
Quoted 25 lines · On Thursday 2010-12-30 11:50, [email protected] wrote:
include/net/ip_vs.h +25
-0+/* +* Get net ptr from skb in traffic cases +* use skb_sknet when call is from userland (ioctl or netlink) +*/ +static inline struct net *skb_net (struct sk_buff *skb) { +#ifdef CONFIG_NET_NS +#ifdef CONFIG_IP_VS_DEBUG +/* +* This is used for debug only. +* Start with the most likely hit +* End with BUG +*/ +if (likely (skb->dev && skb->dev->nd_net)) +return dev_net (skb->dev); +if (skb_dst (skb)->dev) +return dev_net (skb_dst (skb)->dev); +WARN (skb->sk,"Maybe skb_sknet should be used instead in %s() line:%d\n" , + __func__, __LINE__); +if (likely (skb->sk && skb->sk->sk_net)) +return sock_net (skb->sk); +pr_err ("There is no net ptr to find in the skb in %s() line:%d\n" , + __func__, __LINE__); +BUG (); +#else +return dev_net (skb->dev ? :skb_dst (skb)->dev);
Quoted 8 lines
include/net/ip_vs.h static inline struct netns_ipvs * net_ipvs(struct net* net) · line 69
Quoted 5 lines
include/net/ip_vs.h +5
-0+#endif +#else +return &init_net; +#endif +}Whether NETNS is disabled or not,
dev_net(skb->dev)can be used in either case, so the extra return&init_netcase is not really required AFAICS.
OK, but the debug part will not compile without the ifdef since there is some symbols that is #ifdef CONFIG_NET_NS.
"&init_net" is faster than the " ? : "
And the rest I guess is obvious.
Quoted 7 lines
net/netfilter/ipvs/ip_vs_ctl.c static struct pernet_operations ipvs_control_ops = { · line 3472
Quoted 5 lines
net/netfilter/ipvs/ip_vs_ctl.c +2
-1@@ -3446,43 +3471,48 @@ static struct pernet_operations ipvs_control_ops = { -smp_wmb (); + +smp_wmb ();/* Do wee really need it now ? */ not "whee" :)