Skip to content

Commit a0840e2

Browse files
Hans Schillstromhorms
authored andcommitted
IPVS: netns, ip_vs_ctl local vars moved to ipvs struct.
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) Signed-off-by: Hans Schillstrom <[email protected]> Acked-by: Julian Anastasov <[email protected]> Signed-off-by: Simon Horman <[email protected]>
1 parent 6e67e58 commit a0840e2

File tree

9 files changed

+230
-181
lines changed

9 files changed

+230
-181
lines changed

include/net/ip_vs.h

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ static inline struct netns_ipvs *net_ipvs(struct net* net)
4141
* Get net ptr from skb in traffic cases
4242
* use skb_sknet when call is from userland (ioctl or netlink)
4343
*/
44-
static inline struct net *skb_net(struct sk_buff *skb)
44+
static inline struct net *skb_net(const struct sk_buff *skb)
4545
{
4646
#ifdef CONFIG_NET_NS
4747
#ifdef CONFIG_IP_VS_DEBUG
@@ -69,7 +69,7 @@ static inline struct net *skb_net(struct sk_buff *skb)
6969
#endif
7070
}
7171

72-
static inline struct net *skb_sknet(struct sk_buff *skb)
72+
static inline struct net *skb_sknet(const struct sk_buff *skb)
7373
{
7474
#ifdef CONFIG_NET_NS
7575
#ifdef CONFIG_IP_VS_DEBUG
@@ -1023,13 +1023,6 @@ extern int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
10231023
/*
10241024
* IPVS control data and functions (from ip_vs_ctl.c)
10251025
*/
1026-
extern int sysctl_ip_vs_cache_bypass;
1027-
extern int sysctl_ip_vs_expire_nodest_conn;
1028-
extern int sysctl_ip_vs_expire_quiescent_template;
1029-
extern int sysctl_ip_vs_sync_threshold[2];
1030-
extern int sysctl_ip_vs_nat_icmp_send;
1031-
extern int sysctl_ip_vs_conntrack;
1032-
extern int sysctl_ip_vs_snat_reroute;
10331026
extern struct ip_vs_stats ip_vs_stats;
10341027
extern const struct ctl_path net_vs_ctl_path[];
10351028
extern int sysctl_ip_vs_sync_ver;
@@ -1119,11 +1112,13 @@ extern int ip_vs_icmp_xmit_v6
11191112
extern int ip_vs_drop_rate;
11201113
extern int ip_vs_drop_counter;
11211114

1122-
static __inline__ int ip_vs_todrop(void)
1115+
static inline int ip_vs_todrop(struct netns_ipvs *ipvs)
11231116
{
1124-
if (!ip_vs_drop_rate) return 0;
1125-
if (--ip_vs_drop_counter > 0) return 0;
1126-
ip_vs_drop_counter = ip_vs_drop_rate;
1117+
if (!ipvs->drop_rate)
1118+
return 0;
1119+
if (--ipvs->drop_counter > 0)
1120+
return 0;
1121+
ipvs->drop_counter = ipvs->drop_rate;
11271122
return 1;
11281123
}
11291124

@@ -1211,9 +1206,9 @@ static inline void ip_vs_notrack(struct sk_buff *skb)
12111206
* Netfilter connection tracking
12121207
* (from ip_vs_nfct.c)
12131208
*/
1214-
static inline int ip_vs_conntrack_enabled(void)
1209+
static inline int ip_vs_conntrack_enabled(struct netns_ipvs *ipvs)
12151210
{
1216-
return sysctl_ip_vs_conntrack;
1211+
return ipvs->sysctl_conntrack;
12171212
}
12181213

12191214
extern void ip_vs_update_conntrack(struct sk_buff *skb, struct ip_vs_conn *cp,
@@ -1226,7 +1221,7 @@ extern void ip_vs_conn_drop_conntrack(struct ip_vs_conn *cp);
12261221

12271222
#else
12281223

1229-
static inline int ip_vs_conntrack_enabled(void)
1224+
static inline int ip_vs_conntrack_enabled(struct netns_ipvs *ipvs)
12301225
{
12311226
return 0;
12321227
}

include/net/netns/ip_vs.h

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,46 @@ struct netns_ipvs {
6161
struct list_head sctp_apps[SCTP_APP_TAB_SIZE];
6262
spinlock_t sctp_app_lock;
6363
#endif
64+
/* ip_vs_conn */
65+
atomic_t conn_count; /* connection counter */
66+
6467
/* ip_vs_ctl */
6568
struct ip_vs_stats *tot_stats; /* Statistics & est. */
6669
struct ip_vs_cpu_stats __percpu *cpustats; /* Stats per cpu */
6770
seqcount_t *ustats_seq; /* u64 read retry */
6871

69-
/* ip_vs_conn */
70-
atomic_t conn_count; /* connection counter */
72+
int num_services; /* no of virtual services */
73+
/* 1/rate drop and drop-entry variables */
74+
int drop_rate;
75+
int drop_counter;
76+
atomic_t dropentry;
77+
/* locks in ctl.c */
78+
spinlock_t dropentry_lock; /* drop entry handling */
79+
spinlock_t droppacket_lock; /* drop packet handling */
80+
spinlock_t securetcp_lock; /* state and timeout tables */
81+
rwlock_t rs_lock; /* real services table */
82+
/* semaphore for IPVS sockopts. And, [gs]etsockopt may sleep. */
83+
struct lock_class_key ctl_key; /* ctl_mutex debuging */
84+
/* sys-ctl struct */
85+
struct ctl_table_header *sysctl_hdr;
86+
struct ctl_table *sysctl_tbl;
87+
/* sysctl variables */
88+
int sysctl_amemthresh;
89+
int sysctl_am_droprate;
90+
int sysctl_drop_entry;
91+
int sysctl_drop_packet;
92+
int sysctl_secure_tcp;
93+
#ifdef CONFIG_IP_VS_NFCT
94+
int sysctl_conntrack;
95+
#endif
96+
int sysctl_snat_reroute;
97+
int sysctl_sync_ver;
98+
int sysctl_cache_bypass;
99+
int sysctl_expire_nodest_conn;
100+
int sysctl_expire_quiescent_template;
101+
int sysctl_sync_threshold[2];
102+
int sysctl_nat_icmp_send;
103+
71104
/* ip_vs_lblc */
72105
int sysctl_lblc_expiration;
73106
struct ctl_table_header *lblc_ctl_header;

net/netfilter/ipvs/ip_vs_conn.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -686,13 +686,14 @@ static inline void ip_vs_unbind_dest(struct ip_vs_conn *cp)
686686
int ip_vs_check_template(struct ip_vs_conn *ct)
687687
{
688688
struct ip_vs_dest *dest = ct->dest;
689+
struct netns_ipvs *ipvs = net_ipvs(ip_vs_conn_net(ct));
689690

690691
/*
691692
* Checking the dest server status.
692693
*/
693694
if ((dest == NULL) ||
694695
!(dest->flags & IP_VS_DEST_F_AVAILABLE) ||
695-
(sysctl_ip_vs_expire_quiescent_template &&
696+
(ipvs->sysctl_expire_quiescent_template &&
696697
(atomic_read(&dest->weight) == 0))) {
697698
IP_VS_DBG_BUF(9, "check_template: dest not available for "
698699
"protocol %s s:%s:%d v:%s:%d "
@@ -879,7 +880,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
879880
* IP_VS_CONN_F_ONE_PACKET too.
880881
*/
881882

882-
if (ip_vs_conntrack_enabled())
883+
if (ip_vs_conntrack_enabled(ipvs))
883884
cp->flags |= IP_VS_CONN_F_NFCT;
884885

885886
/* Hash it in the ip_vs_conn_tab finally */
@@ -1198,7 +1199,7 @@ static void ip_vs_conn_flush(struct net *net)
11981199
struct ip_vs_conn *cp;
11991200
struct netns_ipvs *ipvs = net_ipvs(net);
12001201

1201-
flush_again:
1202+
flush_again:
12021203
for (idx = 0; idx < ip_vs_conn_tab_size; idx++) {
12031204
/*
12041205
* Lock is actually needed in this loop.

net/netfilter/ipvs/ip_vs_core.c

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,7 @@ ip_vs_schedule(struct ip_vs_service *svc, struct sk_buff *skb,
499499
int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
500500
struct ip_vs_proto_data *pd)
501501
{
502+
struct netns_ipvs *ipvs;
502503
__be16 _ports[2], *pptr;
503504
struct ip_vs_iphdr iph;
504505
int unicast;
@@ -521,7 +522,8 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
521522
/* if it is fwmark-based service, the cache_bypass sysctl is up
522523
and the destination is a non-local unicast, then create
523524
a cache_bypass connection entry */
524-
if (sysctl_ip_vs_cache_bypass && svc->fwmark && unicast) {
525+
ipvs = net_ipvs(skb_net(skb));
526+
if (ipvs->sysctl_cache_bypass && svc->fwmark && unicast) {
525527
int ret, cs;
526528
struct ip_vs_conn *cp;
527529
unsigned int flags = (svc->flags & IP_VS_SVC_F_ONEPACKET &&
@@ -733,6 +735,7 @@ static int handle_response_icmp(int af, struct sk_buff *skb,
733735
struct ip_vs_protocol *pp,
734736
unsigned int offset, unsigned int ihl)
735737
{
738+
struct netns_ipvs *ipvs;
736739
unsigned int verdict = NF_DROP;
737740

738741
if (IP_VS_FWD_METHOD(cp) != 0) {
@@ -754,6 +757,8 @@ static int handle_response_icmp(int af, struct sk_buff *skb,
754757
if (!skb_make_writable(skb, offset))
755758
goto out;
756759

760+
ipvs = net_ipvs(skb_net(skb));
761+
757762
#ifdef CONFIG_IP_VS_IPV6
758763
if (af == AF_INET6)
759764
ip_vs_nat_icmp_v6(skb, pp, cp, 1);
@@ -763,11 +768,11 @@ static int handle_response_icmp(int af, struct sk_buff *skb,
763768

764769
#ifdef CONFIG_IP_VS_IPV6
765770
if (af == AF_INET6) {
766-
if (sysctl_ip_vs_snat_reroute && ip6_route_me_harder(skb) != 0)
771+
if (ipvs->sysctl_snat_reroute && ip6_route_me_harder(skb) != 0)
767772
goto out;
768773
} else
769774
#endif
770-
if ((sysctl_ip_vs_snat_reroute ||
775+
if ((ipvs->sysctl_snat_reroute ||
771776
skb_rtable(skb)->rt_flags & RTCF_LOCAL) &&
772777
ip_route_me_harder(skb, RTN_LOCAL) != 0)
773778
goto out;
@@ -979,6 +984,7 @@ handle_response(int af, struct sk_buff *skb, struct ip_vs_proto_data *pd,
979984
struct ip_vs_conn *cp, int ihl)
980985
{
981986
struct ip_vs_protocol *pp = pd->pp;
987+
struct netns_ipvs *ipvs;
982988

983989
IP_VS_DBG_PKT(11, af, pp, skb, 0, "Outgoing packet");
984990

@@ -1014,13 +1020,15 @@ handle_response(int af, struct sk_buff *skb, struct ip_vs_proto_data *pd,
10141020
* if it came from this machine itself. So re-compute
10151021
* the routing information.
10161022
*/
1023+
ipvs = net_ipvs(skb_net(skb));
1024+
10171025
#ifdef CONFIG_IP_VS_IPV6
10181026
if (af == AF_INET6) {
1019-
if (sysctl_ip_vs_snat_reroute && ip6_route_me_harder(skb) != 0)
1027+
if (ipvs->sysctl_snat_reroute && ip6_route_me_harder(skb) != 0)
10201028
goto drop;
10211029
} else
10221030
#endif
1023-
if ((sysctl_ip_vs_snat_reroute ||
1031+
if ((ipvs->sysctl_snat_reroute ||
10241032
skb_rtable(skb)->rt_flags & RTCF_LOCAL) &&
10251033
ip_route_me_harder(skb, RTN_LOCAL) != 0)
10261034
goto drop;
@@ -1057,6 +1065,7 @@ ip_vs_out(unsigned int hooknum, struct sk_buff *skb, int af)
10571065
struct ip_vs_protocol *pp;
10581066
struct ip_vs_proto_data *pd;
10591067
struct ip_vs_conn *cp;
1068+
struct netns_ipvs *ipvs;
10601069

10611070
EnterFunction(11);
10621071

@@ -1131,10 +1140,11 @@ ip_vs_out(unsigned int hooknum, struct sk_buff *skb, int af)
11311140
* Check if the packet belongs to an existing entry
11321141
*/
11331142
cp = pp->conn_out_get(af, skb, &iph, iph.len, 0);
1143+
ipvs = net_ipvs(net);
11341144

11351145
if (likely(cp))
11361146
return handle_response(af, skb, pd, cp, iph.len);
1137-
if (sysctl_ip_vs_nat_icmp_send &&
1147+
if (ipvs->sysctl_nat_icmp_send &&
11381148
(pp->protocol == IPPROTO_TCP ||
11391149
pp->protocol == IPPROTO_UDP ||
11401150
pp->protocol == IPPROTO_SCTP)) {
@@ -1580,7 +1590,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
15801590
if (cp->dest && !(cp->dest->flags & IP_VS_DEST_F_AVAILABLE)) {
15811591
/* the destination server is not available */
15821592

1583-
if (sysctl_ip_vs_expire_nodest_conn) {
1593+
if (ipvs->sysctl_expire_nodest_conn) {
15841594
/* try to expire the connection immediately */
15851595
ip_vs_conn_expire_now(cp);
15861596
}
@@ -1610,15 +1620,15 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
16101620
*/
16111621

16121622
if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
1613-
pkts = sysctl_ip_vs_sync_threshold[0];
1623+
pkts = ipvs->sysctl_sync_threshold[0];
16141624
else
16151625
pkts = atomic_add_return(1, &cp->in_pkts);
16161626

16171627
if ((ipvs->sync_state & IP_VS_STATE_MASTER) &&
16181628
cp->protocol == IPPROTO_SCTP) {
16191629
if ((cp->state == IP_VS_SCTP_S_ESTABLISHED &&
1620-
(pkts % sysctl_ip_vs_sync_threshold[1]
1621-
== sysctl_ip_vs_sync_threshold[0])) ||
1630+
(pkts % ipvs->sysctl_sync_threshold[1]
1631+
== ipvs->sysctl_sync_threshold[0])) ||
16221632
(cp->old_state != cp->state &&
16231633
((cp->state == IP_VS_SCTP_S_CLOSED) ||
16241634
(cp->state == IP_VS_SCTP_S_SHUT_ACK_CLI) ||
@@ -1632,8 +1642,8 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
16321642
else if ((ipvs->sync_state & IP_VS_STATE_MASTER) &&
16331643
(((cp->protocol != IPPROTO_TCP ||
16341644
cp->state == IP_VS_TCP_S_ESTABLISHED) &&
1635-
(pkts % sysctl_ip_vs_sync_threshold[1]
1636-
== sysctl_ip_vs_sync_threshold[0])) ||
1645+
(pkts % ipvs->sysctl_sync_threshold[1]
1646+
== ipvs->sysctl_sync_threshold[0])) ||
16371647
((cp->protocol == IPPROTO_TCP) && (cp->old_state != cp->state) &&
16381648
((cp->state == IP_VS_TCP_S_FIN_WAIT) ||
16391649
(cp->state == IP_VS_TCP_S_CLOSE) ||

0 commit comments

Comments
 (0)