2005-04-16 16:20:36 -06:00
|
|
|
/*
|
|
|
|
* IPVS An implementation of the IP virtual server support for the
|
|
|
|
* LINUX operating system. IPVS is now implemented as a module
|
|
|
|
* over the NetFilter framework. IPVS can be used to build a
|
|
|
|
* high-performance and highly available server based on a
|
|
|
|
* cluster of servers.
|
|
|
|
*
|
|
|
|
* Authors: Wensong Zhang <wensong@linuxvirtualserver.org>
|
|
|
|
* Peter Kese <peter.kese@ijs.si>
|
|
|
|
* Julian Anastasov <ja@ssi.bg>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version
|
|
|
|
* 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Changes:
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2009-07-30 15:29:44 -06:00
|
|
|
#define KMSG_COMPONENT "IPVS"
|
|
|
|
#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/types.h>
|
2006-01-11 13:17:47 -07:00
|
|
|
#include <linux/capability.h>
|
2005-04-16 16:20:36 -06:00
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/sysctl.h>
|
|
|
|
#include <linux/proc_fs.h>
|
|
|
|
#include <linux/workqueue.h>
|
|
|
|
#include <linux/swap.h>
|
|
|
|
#include <linux/seq_file.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 02:04:11 -06:00
|
|
|
#include <linux/slab.h>
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
#include <linux/netfilter.h>
|
|
|
|
#include <linux/netfilter_ipv4.h>
|
2006-03-26 02:37:14 -07:00
|
|
|
#include <linux/mutex.h>
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2007-09-12 04:01:34 -06:00
|
|
|
#include <net/net_namespace.h>
|
2011-01-03 06:44:51 -07:00
|
|
|
#include <linux/nsproxy.h>
|
2005-04-16 16:20:36 -06:00
|
|
|
#include <net/ip.h>
|
2008-09-02 07:55:52 -06:00
|
|
|
#ifdef CONFIG_IP_VS_IPV6
|
|
|
|
#include <net/ipv6.h>
|
|
|
|
#include <net/ip6_route.h>
|
|
|
|
#endif
|
2005-12-26 21:43:12 -07:00
|
|
|
#include <net/route.h>
|
2005-04-16 16:20:36 -06:00
|
|
|
#include <net/sock.h>
|
2008-08-14 06:08:44 -06:00
|
|
|
#include <net/genetlink.h>
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
#include <asm/uaccess.h>
|
|
|
|
|
|
|
|
#include <net/ip_vs.h>
|
|
|
|
|
|
|
|
/* semaphore for IPVS sockopts. And, [gs]etsockopt may sleep. */
|
2006-03-26 02:37:14 -07:00
|
|
|
static DEFINE_MUTEX(__ip_vs_mutex);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
/* sysctl variables */
|
|
|
|
|
|
|
|
#ifdef CONFIG_IP_VS_DEBUG
|
|
|
|
static int sysctl_ip_vs_debug_level = 0;
|
|
|
|
|
|
|
|
int ip_vs_get_debug_level(void)
|
|
|
|
{
|
|
|
|
return sysctl_ip_vs_debug_level;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-05-03 14:09:31 -06:00
|
|
|
|
|
|
|
/* Protos */
|
2013-03-22 03:46:49 -06:00
|
|
|
static void __ip_vs_del_service(struct ip_vs_service *svc, bool cleanup);
|
2011-05-03 14:09:31 -06:00
|
|
|
|
|
|
|
|
2008-09-02 07:55:52 -06:00
|
|
|
#ifdef CONFIG_IP_VS_IPV6
|
|
|
|
/* Taken from rt6_fill_node() in net/ipv6/route.c, is there a better way? */
|
2012-06-24 15:58:23 -06:00
|
|
|
static bool __ip_vs_addr_is_local_v6(struct net *net,
|
|
|
|
const struct in6_addr *addr)
|
2008-09-02 07:55:52 -06:00
|
|
|
{
|
2011-03-12 14:22:43 -07:00
|
|
|
struct flowi6 fl6 = {
|
|
|
|
.daddr = *addr,
|
2008-09-02 07:55:52 -06:00
|
|
|
};
|
2012-06-24 15:58:23 -06:00
|
|
|
struct dst_entry *dst = ip6_route_output(net, NULL, &fl6);
|
|
|
|
bool is_local;
|
2008-09-02 07:55:52 -06:00
|
|
|
|
2012-06-24 15:58:23 -06:00
|
|
|
is_local = !dst->error && dst->dev && (dst->dev->flags & IFF_LOOPBACK);
|
2008-09-02 07:55:52 -06:00
|
|
|
|
2012-06-24 15:58:23 -06:00
|
|
|
dst_release(dst);
|
|
|
|
return is_local;
|
2008-09-02 07:55:52 -06:00
|
|
|
}
|
|
|
|
#endif
|
2011-02-04 02:33:02 -07:00
|
|
|
|
|
|
|
#ifdef CONFIG_SYSCTL
|
2005-04-16 16:20:36 -06:00
|
|
|
/*
|
2005-07-11 21:59:57 -06:00
|
|
|
* update_defense_level is called from keventd and from sysctl,
|
|
|
|
* so it needs to protect itself from softirqs
|
2005-04-16 16:20:36 -06:00
|
|
|
*/
|
2011-01-03 06:44:51 -07:00
|
|
|
static void update_defense_level(struct netns_ipvs *ipvs)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
struct sysinfo i;
|
|
|
|
static int old_secure_tcp = 0;
|
|
|
|
int availmem;
|
|
|
|
int nomem;
|
|
|
|
int to_change = -1;
|
|
|
|
|
|
|
|
/* we only count free and buffered memory (in pages) */
|
|
|
|
si_meminfo(&i);
|
|
|
|
availmem = i.freeram + i.bufferram;
|
|
|
|
/* however in linux 2.5 the i.bufferram is total page cache size,
|
|
|
|
we need adjust it */
|
|
|
|
/* si_swapinfo(&i); */
|
|
|
|
/* availmem = availmem - (i.totalswap - i.freeswap); */
|
|
|
|
|
2011-01-03 06:44:58 -07:00
|
|
|
nomem = (availmem < ipvs->sysctl_amemthresh);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2005-07-11 21:59:57 -06:00
|
|
|
local_bh_disable();
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
/* drop_entry */
|
2011-01-03 06:44:58 -07:00
|
|
|
spin_lock(&ipvs->dropentry_lock);
|
|
|
|
switch (ipvs->sysctl_drop_entry) {
|
2005-04-16 16:20:36 -06:00
|
|
|
case 0:
|
2011-01-03 06:44:58 -07:00
|
|
|
atomic_set(&ipvs->dropentry, 0);
|
2005-04-16 16:20:36 -06:00
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
if (nomem) {
|
2011-01-03 06:44:58 -07:00
|
|
|
atomic_set(&ipvs->dropentry, 1);
|
|
|
|
ipvs->sysctl_drop_entry = 2;
|
2005-04-16 16:20:36 -06:00
|
|
|
} else {
|
2011-01-03 06:44:58 -07:00
|
|
|
atomic_set(&ipvs->dropentry, 0);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
if (nomem) {
|
2011-01-03 06:44:58 -07:00
|
|
|
atomic_set(&ipvs->dropentry, 1);
|
2005-04-16 16:20:36 -06:00
|
|
|
} else {
|
2011-01-03 06:44:58 -07:00
|
|
|
atomic_set(&ipvs->dropentry, 0);
|
|
|
|
ipvs->sysctl_drop_entry = 1;
|
2005-04-16 16:20:36 -06:00
|
|
|
};
|
|
|
|
break;
|
|
|
|
case 3:
|
2011-01-03 06:44:58 -07:00
|
|
|
atomic_set(&ipvs->dropentry, 1);
|
2005-04-16 16:20:36 -06:00
|
|
|
break;
|
|
|
|
}
|
2011-01-03 06:44:58 -07:00
|
|
|
spin_unlock(&ipvs->dropentry_lock);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
/* drop_packet */
|
2011-01-03 06:44:58 -07:00
|
|
|
spin_lock(&ipvs->droppacket_lock);
|
|
|
|
switch (ipvs->sysctl_drop_packet) {
|
2005-04-16 16:20:36 -06:00
|
|
|
case 0:
|
2011-01-03 06:44:58 -07:00
|
|
|
ipvs->drop_rate = 0;
|
2005-04-16 16:20:36 -06:00
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
if (nomem) {
|
2011-01-03 06:44:58 -07:00
|
|
|
ipvs->drop_rate = ipvs->drop_counter
|
|
|
|
= ipvs->sysctl_amemthresh /
|
|
|
|
(ipvs->sysctl_amemthresh-availmem);
|
|
|
|
ipvs->sysctl_drop_packet = 2;
|
2005-04-16 16:20:36 -06:00
|
|
|
} else {
|
2011-01-03 06:44:58 -07:00
|
|
|
ipvs->drop_rate = 0;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
if (nomem) {
|
2011-01-03 06:44:58 -07:00
|
|
|
ipvs->drop_rate = ipvs->drop_counter
|
|
|
|
= ipvs->sysctl_amemthresh /
|
|
|
|
(ipvs->sysctl_amemthresh-availmem);
|
2005-04-16 16:20:36 -06:00
|
|
|
} else {
|
2011-01-03 06:44:58 -07:00
|
|
|
ipvs->drop_rate = 0;
|
|
|
|
ipvs->sysctl_drop_packet = 1;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 3:
|
2011-01-03 06:44:58 -07:00
|
|
|
ipvs->drop_rate = ipvs->sysctl_am_droprate;
|
2005-04-16 16:20:36 -06:00
|
|
|
break;
|
|
|
|
}
|
2011-01-03 06:44:58 -07:00
|
|
|
spin_unlock(&ipvs->droppacket_lock);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
/* secure_tcp */
|
2011-01-03 06:44:58 -07:00
|
|
|
spin_lock(&ipvs->securetcp_lock);
|
|
|
|
switch (ipvs->sysctl_secure_tcp) {
|
2005-04-16 16:20:36 -06:00
|
|
|
case 0:
|
|
|
|
if (old_secure_tcp >= 2)
|
|
|
|
to_change = 0;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
if (nomem) {
|
|
|
|
if (old_secure_tcp < 2)
|
|
|
|
to_change = 1;
|
2011-01-03 06:44:58 -07:00
|
|
|
ipvs->sysctl_secure_tcp = 2;
|
2005-04-16 16:20:36 -06:00
|
|
|
} else {
|
|
|
|
if (old_secure_tcp >= 2)
|
|
|
|
to_change = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
if (nomem) {
|
|
|
|
if (old_secure_tcp < 2)
|
|
|
|
to_change = 1;
|
|
|
|
} else {
|
|
|
|
if (old_secure_tcp >= 2)
|
|
|
|
to_change = 0;
|
2011-01-03 06:44:58 -07:00
|
|
|
ipvs->sysctl_secure_tcp = 1;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
if (old_secure_tcp < 2)
|
|
|
|
to_change = 1;
|
|
|
|
break;
|
|
|
|
}
|
2011-01-03 06:44:58 -07:00
|
|
|
old_secure_tcp = ipvs->sysctl_secure_tcp;
|
2005-04-16 16:20:36 -06:00
|
|
|
if (to_change >= 0)
|
2011-01-03 06:44:51 -07:00
|
|
|
ip_vs_protocol_timeout_change(ipvs,
|
2011-01-03 06:44:58 -07:00
|
|
|
ipvs->sysctl_secure_tcp > 1);
|
|
|
|
spin_unlock(&ipvs->securetcp_lock);
|
2005-07-11 21:59:57 -06:00
|
|
|
|
|
|
|
local_bh_enable();
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Timer for checking the defense
|
|
|
|
*/
|
|
|
|
#define DEFENSE_TIMER_PERIOD 1*HZ
|
|
|
|
|
2006-11-22 07:57:56 -07:00
|
|
|
static void defense_work_handler(struct work_struct *work)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2011-01-03 06:44:59 -07:00
|
|
|
struct netns_ipvs *ipvs =
|
|
|
|
container_of(work, struct netns_ipvs, defense_work.work);
|
2011-01-03 06:44:51 -07:00
|
|
|
|
|
|
|
update_defense_level(ipvs);
|
2011-01-03 06:44:58 -07:00
|
|
|
if (atomic_read(&ipvs->dropentry))
|
2011-01-03 06:44:59 -07:00
|
|
|
ip_vs_random_dropentry(ipvs->net);
|
|
|
|
schedule_delayed_work(&ipvs->defense_work, DEFENSE_TIMER_PERIOD);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
2011-02-04 02:33:02 -07:00
|
|
|
#endif
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
int
|
|
|
|
ip_vs_use_count_inc(void)
|
|
|
|
{
|
|
|
|
return try_module_get(THIS_MODULE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ip_vs_use_count_dec(void)
|
|
|
|
{
|
|
|
|
module_put(THIS_MODULE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Hash table: for virtual service lookups
|
|
|
|
*/
|
|
|
|
#define IP_VS_SVC_TAB_BITS 8
|
|
|
|
#define IP_VS_SVC_TAB_SIZE (1 << IP_VS_SVC_TAB_BITS)
|
|
|
|
#define IP_VS_SVC_TAB_MASK (IP_VS_SVC_TAB_SIZE - 1)
|
|
|
|
|
|
|
|
/* the service table hashed by <protocol, addr, port> */
|
2013-03-22 03:46:53 -06:00
|
|
|
static struct hlist_head ip_vs_svc_table[IP_VS_SVC_TAB_SIZE];
|
2005-04-16 16:20:36 -06:00
|
|
|
/* the service table hashed by fwmark */
|
2013-03-22 03:46:53 -06:00
|
|
|
static struct hlist_head ip_vs_svc_fwm_table[IP_VS_SVC_TAB_SIZE];
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Returns hash value for virtual service
|
|
|
|
*/
|
2012-04-14 23:58:06 -06:00
|
|
|
static inline unsigned int
|
|
|
|
ip_vs_svc_hashkey(struct net *net, int af, unsigned int proto,
|
2011-01-03 06:44:43 -07:00
|
|
|
const union nf_inet_addr *addr, __be16 port)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2012-04-14 23:58:06 -06:00
|
|
|
register unsigned int porth = ntohs(port);
|
2008-09-02 07:55:37 -06:00
|
|
|
__be32 addr_fold = addr->ip;
|
2013-03-09 14:25:07 -07:00
|
|
|
__u32 ahash;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2008-09-02 07:55:37 -06:00
|
|
|
#ifdef CONFIG_IP_VS_IPV6
|
|
|
|
if (af == AF_INET6)
|
|
|
|
addr_fold = addr->ip6[0]^addr->ip6[1]^
|
|
|
|
addr->ip6[2]^addr->ip6[3];
|
|
|
|
#endif
|
2013-03-09 14:25:07 -07:00
|
|
|
ahash = ntohl(addr_fold);
|
|
|
|
ahash ^= ((size_t) net >> 8);
|
2008-09-02 07:55:37 -06:00
|
|
|
|
2013-03-09 14:25:07 -07:00
|
|
|
return (proto ^ ahash ^ (porth >> IP_VS_SVC_TAB_BITS) ^ porth) &
|
|
|
|
IP_VS_SVC_TAB_MASK;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Returns hash value of fwmark for virtual service lookup
|
|
|
|
*/
|
2012-04-14 23:58:06 -06:00
|
|
|
static inline unsigned int ip_vs_svc_fwm_hashkey(struct net *net, __u32 fwmark)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2011-01-03 06:44:43 -07:00
|
|
|
return (((size_t)net>>8) ^ fwmark) & IP_VS_SVC_TAB_MASK;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2011-01-03 06:44:43 -07:00
|
|
|
* Hashes a service in the ip_vs_svc_table by <netns,proto,addr,port>
|
2005-04-16 16:20:36 -06:00
|
|
|
* or in the ip_vs_svc_fwm_table by fwmark.
|
|
|
|
* Should be called with locked tables.
|
|
|
|
*/
|
|
|
|
static int ip_vs_svc_hash(struct ip_vs_service *svc)
|
|
|
|
{
|
2012-04-14 23:58:06 -06:00
|
|
|
unsigned int hash;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
if (svc->flags & IP_VS_SVC_F_HASHED) {
|
2009-08-02 05:05:41 -06:00
|
|
|
pr_err("%s(): request for already hashed, called from %pF\n",
|
|
|
|
__func__, __builtin_return_address(0));
|
2005-04-16 16:20:36 -06:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (svc->fwmark == 0) {
|
|
|
|
/*
|
2011-01-03 06:44:43 -07:00
|
|
|
* Hash it by <netns,protocol,addr,port> in ip_vs_svc_table
|
2005-04-16 16:20:36 -06:00
|
|
|
*/
|
2011-01-03 06:44:43 -07:00
|
|
|
hash = ip_vs_svc_hashkey(svc->net, svc->af, svc->protocol,
|
|
|
|
&svc->addr, svc->port);
|
2013-03-22 03:46:53 -06:00
|
|
|
hlist_add_head_rcu(&svc->s_list, &ip_vs_svc_table[hash]);
|
2005-04-16 16:20:36 -06:00
|
|
|
} else {
|
|
|
|
/*
|
2011-01-03 06:44:43 -07:00
|
|
|
* Hash it by fwmark in svc_fwm_table
|
2005-04-16 16:20:36 -06:00
|
|
|
*/
|
2011-01-03 06:44:43 -07:00
|
|
|
hash = ip_vs_svc_fwm_hashkey(svc->net, svc->fwmark);
|
2013-03-22 03:46:53 -06:00
|
|
|
hlist_add_head_rcu(&svc->f_list, &ip_vs_svc_fwm_table[hash]);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
svc->flags |= IP_VS_SVC_F_HASHED;
|
|
|
|
/* increase its refcnt because it is referenced by the svc table */
|
|
|
|
atomic_inc(&svc->refcnt);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2011-01-03 06:44:43 -07:00
|
|
|
* Unhashes a service from svc_table / svc_fwm_table.
|
2005-04-16 16:20:36 -06:00
|
|
|
* Should be called with locked tables.
|
|
|
|
*/
|
|
|
|
static int ip_vs_svc_unhash(struct ip_vs_service *svc)
|
|
|
|
{
|
|
|
|
if (!(svc->flags & IP_VS_SVC_F_HASHED)) {
|
2009-08-02 05:05:41 -06:00
|
|
|
pr_err("%s(): request for unhash flagged, called from %pF\n",
|
|
|
|
__func__, __builtin_return_address(0));
|
2005-04-16 16:20:36 -06:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (svc->fwmark == 0) {
|
2011-01-03 06:44:43 -07:00
|
|
|
/* Remove it from the svc_table table */
|
2013-03-22 03:46:53 -06:00
|
|
|
hlist_del_rcu(&svc->s_list);
|
2005-04-16 16:20:36 -06:00
|
|
|
} else {
|
2011-01-03 06:44:43 -07:00
|
|
|
/* Remove it from the svc_fwm_table table */
|
2013-03-22 03:46:53 -06:00
|
|
|
hlist_del_rcu(&svc->f_list);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
svc->flags &= ~IP_VS_SVC_F_HASHED;
|
|
|
|
atomic_dec(&svc->refcnt);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2011-01-03 06:44:43 -07:00
|
|
|
* Get service by {netns, proto,addr,port} in the service table.
|
2005-04-16 16:20:36 -06:00
|
|
|
*/
|
2008-09-02 07:55:37 -06:00
|
|
|
static inline struct ip_vs_service *
|
2011-01-03 06:44:43 -07:00
|
|
|
__ip_vs_service_find(struct net *net, int af, __u16 protocol,
|
|
|
|
const union nf_inet_addr *vaddr, __be16 vport)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2012-04-14 23:58:06 -06:00
|
|
|
unsigned int hash;
|
2005-04-16 16:20:36 -06:00
|
|
|
struct ip_vs_service *svc;
|
|
|
|
|
|
|
|
/* Check for "full" addressed entries */
|
2011-01-03 06:44:43 -07:00
|
|
|
hash = ip_vs_svc_hashkey(net, af, protocol, vaddr, vport);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2013-03-22 03:46:53 -06:00
|
|
|
hlist_for_each_entry_rcu(svc, &ip_vs_svc_table[hash], s_list) {
|
2008-09-02 07:55:37 -06:00
|
|
|
if ((svc->af == af)
|
|
|
|
&& ip_vs_addr_equal(af, &svc->addr, vaddr)
|
2005-04-16 16:20:36 -06:00
|
|
|
&& (svc->port == vport)
|
2011-01-03 06:44:43 -07:00
|
|
|
&& (svc->protocol == protocol)
|
|
|
|
&& net_eq(svc->net, net)) {
|
2005-04-16 16:20:36 -06:00
|
|
|
/* HIT */
|
|
|
|
return svc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get service by {fwmark} in the service table.
|
|
|
|
*/
|
2008-09-02 07:55:37 -06:00
|
|
|
static inline struct ip_vs_service *
|
2011-01-03 06:44:43 -07:00
|
|
|
__ip_vs_svc_fwm_find(struct net *net, int af, __u32 fwmark)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2012-04-14 23:58:06 -06:00
|
|
|
unsigned int hash;
|
2005-04-16 16:20:36 -06:00
|
|
|
struct ip_vs_service *svc;
|
|
|
|
|
|
|
|
/* Check for fwmark addressed entries */
|
2011-01-03 06:44:43 -07:00
|
|
|
hash = ip_vs_svc_fwm_hashkey(net, fwmark);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2013-03-22 03:46:53 -06:00
|
|
|
hlist_for_each_entry_rcu(svc, &ip_vs_svc_fwm_table[hash], f_list) {
|
2011-01-03 06:44:43 -07:00
|
|
|
if (svc->fwmark == fwmark && svc->af == af
|
|
|
|
&& net_eq(svc->net, net)) {
|
2005-04-16 16:20:36 -06:00
|
|
|
/* HIT */
|
|
|
|
return svc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-03-22 03:46:53 -06:00
|
|
|
/* Find service, called under RCU lock */
|
2005-04-16 16:20:36 -06:00
|
|
|
struct ip_vs_service *
|
2013-03-22 03:46:53 -06:00
|
|
|
ip_vs_service_find(struct net *net, int af, __u32 fwmark, __u16 protocol,
|
|
|
|
const union nf_inet_addr *vaddr, __be16 vport)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
struct ip_vs_service *svc;
|
2011-01-03 06:45:01 -07:00
|
|
|
struct netns_ipvs *ipvs = net_ipvs(net);
|
2008-09-02 07:55:38 -06:00
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
/*
|
|
|
|
* Check the table hashed by fwmark first
|
|
|
|
*/
|
2011-03-04 03:26:17 -07:00
|
|
|
if (fwmark) {
|
|
|
|
svc = __ip_vs_svc_fwm_find(net, af, fwmark);
|
|
|
|
if (svc)
|
|
|
|
goto out;
|
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Check the table hashed by <protocol,addr,port>
|
|
|
|
* for "full" addressed entries
|
|
|
|
*/
|
2011-01-03 06:44:43 -07:00
|
|
|
svc = __ip_vs_service_find(net, af, protocol, vaddr, vport);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
if (svc == NULL
|
|
|
|
&& protocol == IPPROTO_TCP
|
2011-01-03 06:45:01 -07:00
|
|
|
&& atomic_read(&ipvs->ftpsvc_counter)
|
2005-04-16 16:20:36 -06:00
|
|
|
&& (vport == FTPDATA || ntohs(vport) >= PROT_SOCK)) {
|
|
|
|
/*
|
|
|
|
* Check if ftp service entry exists, the packet
|
|
|
|
* might belong to FTP data connections.
|
|
|
|
*/
|
2011-01-03 06:44:43 -07:00
|
|
|
svc = __ip_vs_service_find(net, af, protocol, vaddr, FTPPORT);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
if (svc == NULL
|
2011-01-03 06:45:01 -07:00
|
|
|
&& atomic_read(&ipvs->nullsvc_counter)) {
|
2005-04-16 16:20:36 -06:00
|
|
|
/*
|
|
|
|
* Check if the catch-all port (port zero) exists
|
|
|
|
*/
|
2011-01-03 06:44:43 -07:00
|
|
|
svc = __ip_vs_service_find(net, af, protocol, vaddr, 0);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
2008-09-02 07:55:38 -06:00
|
|
|
IP_VS_DBG_BUF(9, "lookup service: fwm %u %s %s:%u %s\n",
|
|
|
|
fwmark, ip_vs_proto_name(protocol),
|
|
|
|
IP_VS_DBG_ADDR(af, vaddr), ntohs(vport),
|
|
|
|
svc ? "hit" : "not hit");
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
return svc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
__ip_vs_bind_svc(struct ip_vs_dest *dest, struct ip_vs_service *svc)
|
|
|
|
{
|
|
|
|
atomic_inc(&svc->refcnt);
|
2013-09-12 02:21:07 -06:00
|
|
|
rcu_assign_pointer(dest->svc, svc);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2013-03-22 03:46:53 -06:00
|
|
|
static void ip_vs_service_free(struct ip_vs_service *svc)
|
|
|
|
{
|
2014-11-18 12:37:05 -07:00
|
|
|
free_percpu(svc->stats.cpustats);
|
2013-03-22 03:46:53 -06:00
|
|
|
kfree(svc);
|
|
|
|
}
|
|
|
|
|
2013-09-12 02:21:07 -06:00
|
|
|
static void ip_vs_service_rcu_free(struct rcu_head *head)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2013-09-12 02:21:07 -06:00
|
|
|
struct ip_vs_service *svc;
|
|
|
|
|
|
|
|
svc = container_of(head, struct ip_vs_service, rcu_head);
|
|
|
|
ip_vs_service_free(svc);
|
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2013-09-12 02:21:07 -06:00
|
|
|
static void __ip_vs_svc_put(struct ip_vs_service *svc, bool do_delay)
|
|
|
|
{
|
2010-09-21 10:12:30 -06:00
|
|
|
if (atomic_dec_and_test(&svc->refcnt)) {
|
2013-03-22 03:46:53 -06:00
|
|
|
IP_VS_DBG_BUF(3, "Removing service %u/%s:%u\n",
|
2010-09-21 10:12:30 -06:00
|
|
|
svc->fwmark,
|
|
|
|
IP_VS_DBG_ADDR(svc->af, &svc->addr),
|
2013-03-22 03:46:53 -06:00
|
|
|
ntohs(svc->port));
|
2013-09-12 02:21:07 -06:00
|
|
|
if (do_delay)
|
|
|
|
call_rcu(&svc->rcu_head, ip_vs_service_rcu_free);
|
|
|
|
else
|
|
|
|
ip_vs_service_free(svc);
|
2010-09-21 10:12:30 -06:00
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Returns hash value for real service
|
|
|
|
*/
|
2012-04-14 23:58:06 -06:00
|
|
|
static inline unsigned int ip_vs_rs_hashkey(int af,
|
2008-09-02 07:55:48 -06:00
|
|
|
const union nf_inet_addr *addr,
|
|
|
|
__be16 port)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2012-04-14 23:58:06 -06:00
|
|
|
register unsigned int porth = ntohs(port);
|
2008-09-02 07:55:48 -06:00
|
|
|
__be32 addr_fold = addr->ip;
|
|
|
|
|
|
|
|
#ifdef CONFIG_IP_VS_IPV6
|
|
|
|
if (af == AF_INET6)
|
|
|
|
addr_fold = addr->ip6[0]^addr->ip6[1]^
|
|
|
|
addr->ip6[2]^addr->ip6[3];
|
|
|
|
#endif
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2008-09-02 07:55:48 -06:00
|
|
|
return (ntohl(addr_fold)^(porth>>IP_VS_RTAB_BITS)^porth)
|
2005-04-16 16:20:36 -06:00
|
|
|
& IP_VS_RTAB_MASK;
|
|
|
|
}
|
|
|
|
|
2013-03-21 03:58:08 -06:00
|
|
|
/* Hash ip_vs_dest in rs_table by <proto,addr,port>. */
|
|
|
|
static void ip_vs_rs_hash(struct netns_ipvs *ipvs, struct ip_vs_dest *dest)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2012-04-14 23:58:06 -06:00
|
|
|
unsigned int hash;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2013-03-21 03:58:08 -06:00
|
|
|
if (dest->in_rs_table)
|
|
|
|
return;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Hash by proto,addr,port,
|
|
|
|
* which are the parameters of the real service.
|
|
|
|
*/
|
2008-09-02 07:55:48 -06:00
|
|
|
hash = ip_vs_rs_hashkey(dest->af, &dest->addr, dest->port);
|
|
|
|
|
2013-03-21 03:58:08 -06:00
|
|
|
hlist_add_head_rcu(&dest->d_list, &ipvs->rs_table[hash]);
|
|
|
|
dest->in_rs_table = 1;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2013-03-21 03:58:08 -06:00
|
|
|
/* Unhash ip_vs_dest from rs_table. */
|
|
|
|
static void ip_vs_rs_unhash(struct ip_vs_dest *dest)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
/*
|
2011-01-03 06:44:43 -07:00
|
|
|
* Remove it from the rs_table table.
|
2005-04-16 16:20:36 -06:00
|
|
|
*/
|
2013-03-21 03:58:08 -06:00
|
|
|
if (dest->in_rs_table) {
|
|
|
|
hlist_del_rcu(&dest->d_list);
|
|
|
|
dest->in_rs_table = 0;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-21 03:58:08 -06:00
|
|
|
/* Check if real service by <proto,addr,port> is present */
|
|
|
|
bool ip_vs_has_real_service(struct net *net, int af, __u16 protocol,
|
|
|
|
const union nf_inet_addr *daddr, __be16 dport)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2011-01-03 06:44:43 -07:00
|
|
|
struct netns_ipvs *ipvs = net_ipvs(net);
|
2012-04-14 23:58:06 -06:00
|
|
|
unsigned int hash;
|
2005-04-16 16:20:36 -06:00
|
|
|
struct ip_vs_dest *dest;
|
|
|
|
|
2013-03-21 03:58:08 -06:00
|
|
|
/* Check for "full" addressed entries */
|
2008-09-02 07:55:48 -06:00
|
|
|
hash = ip_vs_rs_hashkey(af, daddr, dport);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2013-03-21 03:58:08 -06:00
|
|
|
rcu_read_lock();
|
|
|
|
hlist_for_each_entry_rcu(dest, &ipvs->rs_table[hash], d_list) {
|
|
|
|
if (dest->port == dport &&
|
|
|
|
dest->af == af &&
|
|
|
|
ip_vs_addr_equal(af, &dest->addr, daddr) &&
|
|
|
|
(dest->protocol == protocol || dest->vfwmark)) {
|
2005-04-16 16:20:36 -06:00
|
|
|
/* HIT */
|
2013-03-21 03:58:08 -06:00
|
|
|
rcu_read_unlock();
|
|
|
|
return true;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
}
|
2013-03-21 03:58:08 -06:00
|
|
|
rcu_read_unlock();
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2013-03-21 03:58:08 -06:00
|
|
|
return false;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2013-03-22 03:46:52 -06:00
|
|
|
/* Lookup destination by {addr,port} in the given service
|
|
|
|
* Called under RCU lock.
|
2005-04-16 16:20:36 -06:00
|
|
|
*/
|
|
|
|
static struct ip_vs_dest *
|
2014-09-09 17:40:21 -06:00
|
|
|
ip_vs_lookup_dest(struct ip_vs_service *svc, int dest_af,
|
|
|
|
const union nf_inet_addr *daddr, __be16 dport)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
struct ip_vs_dest *dest;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find the destination for the given service
|
|
|
|
*/
|
2013-03-22 03:46:52 -06:00
|
|
|
list_for_each_entry_rcu(dest, &svc->destinations, n_list) {
|
2014-09-09 17:40:21 -06:00
|
|
|
if ((dest->af == dest_af) &&
|
|
|
|
ip_vs_addr_equal(dest_af, &dest->addr, daddr) &&
|
|
|
|
(dest->port == dport)) {
|
2005-04-16 16:20:36 -06:00
|
|
|
/* HIT */
|
|
|
|
return dest;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-11-07 03:35:54 -07:00
|
|
|
/*
|
|
|
|
* Find destination by {daddr,dport,vaddr,protocol}
|
2013-03-22 03:46:52 -06:00
|
|
|
* Created to be used in ip_vs_process_message() in
|
2007-11-07 03:35:54 -07:00
|
|
|
* the backup synchronization daemon. It finds the
|
|
|
|
* destination to be bound to the received connection
|
|
|
|
* on the backup.
|
2013-03-22 03:46:52 -06:00
|
|
|
* Called under RCU lock, no refcnt is returned.
|
2007-11-07 03:35:54 -07:00
|
|
|
*/
|
2014-09-09 17:40:21 -06:00
|
|
|
struct ip_vs_dest *ip_vs_find_dest(struct net *net, int svc_af, int dest_af,
|
2011-01-03 06:44:43 -07:00
|
|
|
const union nf_inet_addr *daddr,
|
2008-09-02 07:55:48 -06:00
|
|
|
__be16 dport,
|
|
|
|
const union nf_inet_addr *vaddr,
|
2011-12-29 22:19:02 -07:00
|
|
|
__be16 vport, __u16 protocol, __u32 fwmark,
|
|
|
|
__u32 flags)
|
2007-11-07 03:35:54 -07:00
|
|
|
{
|
|
|
|
struct ip_vs_dest *dest;
|
|
|
|
struct ip_vs_service *svc;
|
2011-12-29 22:19:02 -07:00
|
|
|
__be16 port = dport;
|
2007-11-07 03:35:54 -07:00
|
|
|
|
2014-09-09 17:40:21 -06:00
|
|
|
svc = ip_vs_service_find(net, svc_af, fwmark, protocol, vaddr, vport);
|
2007-11-07 03:35:54 -07:00
|
|
|
if (!svc)
|
|
|
|
return NULL;
|
2011-12-29 22:19:02 -07:00
|
|
|
if (fwmark && (flags & IP_VS_CONN_F_FWD_MASK) != IP_VS_CONN_F_MASQ)
|
|
|
|
port = 0;
|
2014-09-09 17:40:21 -06:00
|
|
|
dest = ip_vs_lookup_dest(svc, dest_af, daddr, port);
|
2011-12-29 22:19:02 -07:00
|
|
|
if (!dest)
|
2014-09-09 17:40:21 -06:00
|
|
|
dest = ip_vs_lookup_dest(svc, dest_af, daddr, port ^ dport);
|
2007-11-07 03:35:54 -07:00
|
|
|
return dest;
|
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2013-03-21 03:58:06 -06:00
|
|
|
void ip_vs_dest_dst_rcu_free(struct rcu_head *head)
|
|
|
|
{
|
|
|
|
struct ip_vs_dest_dst *dest_dst = container_of(head,
|
|
|
|
struct ip_vs_dest_dst,
|
|
|
|
rcu_head);
|
|
|
|
|
|
|
|
dst_release(dest_dst->dst_cache);
|
|
|
|
kfree(dest_dst);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Release dest_dst and dst_cache for dest in user context */
|
2013-03-21 03:58:02 -06:00
|
|
|
static void __ip_vs_dst_cache_reset(struct ip_vs_dest *dest)
|
|
|
|
{
|
2013-03-21 03:58:06 -06:00
|
|
|
struct ip_vs_dest_dst *old;
|
2013-03-21 03:58:02 -06:00
|
|
|
|
2013-03-21 03:58:06 -06:00
|
|
|
old = rcu_dereference_protected(dest->dest_dst, 1);
|
|
|
|
if (old) {
|
|
|
|
RCU_INIT_POINTER(dest->dest_dst, NULL);
|
|
|
|
call_rcu(&old->rcu_head, ip_vs_dest_dst_rcu_free);
|
|
|
|
}
|
2013-03-21 03:58:02 -06:00
|
|
|
}
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
/*
|
|
|
|
* Lookup dest by {svc,addr,port} in the destination trash.
|
|
|
|
* The destination trash is used to hold the destinations that are removed
|
|
|
|
* from the service table but are still referenced by some conn entries.
|
|
|
|
* The reason to add the destination trash is when the dest is temporary
|
|
|
|
* down (either by administrator or by monitor program), the dest can be
|
|
|
|
* picked back from the trash, the remaining connections to the dest can
|
|
|
|
* continue, and the counting information of the dest is also useful for
|
|
|
|
* scheduling.
|
|
|
|
*/
|
|
|
|
static struct ip_vs_dest *
|
2014-09-09 17:40:22 -06:00
|
|
|
ip_vs_trash_get_dest(struct ip_vs_service *svc, int dest_af,
|
|
|
|
const union nf_inet_addr *daddr, __be16 dport)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2013-03-22 03:46:49 -06:00
|
|
|
struct ip_vs_dest *dest;
|
2011-01-03 06:45:00 -07:00
|
|
|
struct netns_ipvs *ipvs = net_ipvs(svc->net);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Find the destination in trash
|
|
|
|
*/
|
2013-03-22 03:46:49 -06:00
|
|
|
spin_lock_bh(&ipvs->dest_trash_lock);
|
|
|
|
list_for_each_entry(dest, &ipvs->dest_trash, t_list) {
|
2008-09-02 07:55:48 -06:00
|
|
|
IP_VS_DBG_BUF(3, "Destination %u/%s:%u still in trash, "
|
|
|
|
"dest->refcnt=%d\n",
|
|
|
|
dest->vfwmark,
|
2014-09-09 17:40:22 -06:00
|
|
|
IP_VS_DBG_ADDR(dest->af, &dest->addr),
|
2008-09-02 07:55:48 -06:00
|
|
|
ntohs(dest->port),
|
|
|
|
atomic_read(&dest->refcnt));
|
2014-09-09 17:40:22 -06:00
|
|
|
if (dest->af == dest_af &&
|
|
|
|
ip_vs_addr_equal(dest_af, &dest->addr, daddr) &&
|
2005-04-16 16:20:36 -06:00
|
|
|
dest->port == dport &&
|
|
|
|
dest->vfwmark == svc->fwmark &&
|
|
|
|
dest->protocol == svc->protocol &&
|
|
|
|
(svc->fwmark ||
|
2008-09-02 07:55:48 -06:00
|
|
|
(ip_vs_addr_equal(svc->af, &dest->vaddr, &svc->addr) &&
|
2005-04-16 16:20:36 -06:00
|
|
|
dest->vport == svc->port))) {
|
|
|
|
/* HIT */
|
2013-03-22 03:46:49 -06:00
|
|
|
list_del(&dest->t_list);
|
|
|
|
ip_vs_dest_hold(dest);
|
|
|
|
goto out;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-22 03:46:49 -06:00
|
|
|
dest = NULL;
|
|
|
|
|
|
|
|
out:
|
|
|
|
spin_unlock_bh(&ipvs->dest_trash_lock);
|
|
|
|
|
|
|
|
return dest;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2013-03-22 03:46:49 -06:00
|
|
|
static void ip_vs_dest_free(struct ip_vs_dest *dest)
|
|
|
|
{
|
2013-09-12 02:21:07 -06:00
|
|
|
struct ip_vs_service *svc = rcu_dereference_protected(dest->svc, 1);
|
|
|
|
|
2013-03-22 03:46:49 -06:00
|
|
|
__ip_vs_dst_cache_reset(dest);
|
2013-09-12 02:21:07 -06:00
|
|
|
__ip_vs_svc_put(svc, false);
|
2013-03-22 03:46:49 -06:00
|
|
|
free_percpu(dest->stats.cpustats);
|
2013-10-09 00:24:27 -06:00
|
|
|
ip_vs_dest_put_and_free(dest);
|
2013-03-22 03:46:49 -06:00
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Clean up all the destinations in the trash
|
|
|
|
* Called by the ip_vs_control_cleanup()
|
|
|
|
*
|
|
|
|
* When the ip_vs_control_clearup is activated by ipvs module exit,
|
|
|
|
* the service tables must have been flushed and all the connections
|
|
|
|
* are expired, and the refcnt of each destination in the trash must
|
2013-03-22 03:46:49 -06:00
|
|
|
* be 0, so we simply release them here.
|
2005-04-16 16:20:36 -06:00
|
|
|
*/
|
2011-01-03 06:45:00 -07:00
|
|
|
static void ip_vs_trash_cleanup(struct net *net)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
struct ip_vs_dest *dest, *nxt;
|
2011-01-03 06:45:00 -07:00
|
|
|
struct netns_ipvs *ipvs = net_ipvs(net);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2013-03-22 03:46:49 -06:00
|
|
|
del_timer_sync(&ipvs->dest_trash_timer);
|
|
|
|
/* No need to use dest_trash_lock */
|
|
|
|
list_for_each_entry_safe(dest, nxt, &ipvs->dest_trash, t_list) {
|
|
|
|
list_del(&dest->t_list);
|
|
|
|
ip_vs_dest_free(dest);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-13 17:37:49 -06:00
|
|
|
static void
|
|
|
|
ip_vs_copy_stats(struct ip_vs_stats_user *dst, struct ip_vs_stats *src)
|
|
|
|
{
|
|
|
|
#define IP_VS_SHOW_STATS_COUNTER(c) dst->c = src->ustats.c - src->ustats0.c
|
|
|
|
|
|
|
|
spin_lock_bh(&src->lock);
|
|
|
|
|
|
|
|
IP_VS_SHOW_STATS_COUNTER(conns);
|
|
|
|
IP_VS_SHOW_STATS_COUNTER(inpkts);
|
|
|
|
IP_VS_SHOW_STATS_COUNTER(outpkts);
|
|
|
|
IP_VS_SHOW_STATS_COUNTER(inbytes);
|
|
|
|
IP_VS_SHOW_STATS_COUNTER(outbytes);
|
|
|
|
|
2011-03-13 17:41:54 -06:00
|
|
|
ip_vs_read_estimator(dst, src);
|
2011-03-13 17:37:49 -06:00
|
|
|
|
|
|
|
spin_unlock_bh(&src->lock);
|
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
static void
|
|
|
|
ip_vs_zero_stats(struct ip_vs_stats *stats)
|
|
|
|
{
|
|
|
|
spin_lock_bh(&stats->lock);
|
2008-08-11 01:19:14 -06:00
|
|
|
|
2011-03-13 17:37:49 -06:00
|
|
|
/* get current counters as zero point, rates are zeroed */
|
|
|
|
|
|
|
|
#define IP_VS_ZERO_STATS_COUNTER(c) stats->ustats0.c = stats->ustats.c
|
|
|
|
|
|
|
|
IP_VS_ZERO_STATS_COUNTER(conns);
|
|
|
|
IP_VS_ZERO_STATS_COUNTER(inpkts);
|
|
|
|
IP_VS_ZERO_STATS_COUNTER(outpkts);
|
|
|
|
IP_VS_ZERO_STATS_COUNTER(inbytes);
|
|
|
|
IP_VS_ZERO_STATS_COUNTER(outbytes);
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
ip_vs_zero_estimator(stats);
|
2008-08-11 01:19:14 -06:00
|
|
|
|
2008-08-10 12:24:41 -06:00
|
|
|
spin_unlock_bh(&stats->lock);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Update a destination in the given service
|
|
|
|
*/
|
|
|
|
static void
|
2010-09-21 10:12:30 -06:00
|
|
|
__ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
|
|
|
|
struct ip_vs_dest_user_kern *udest, int add)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2011-01-03 06:44:43 -07:00
|
|
|
struct netns_ipvs *ipvs = net_ipvs(svc->net);
|
2013-09-12 02:21:07 -06:00
|
|
|
struct ip_vs_service *old_svc;
|
2013-03-22 03:46:53 -06:00
|
|
|
struct ip_vs_scheduler *sched;
|
2005-04-16 16:20:36 -06:00
|
|
|
int conn_flags;
|
|
|
|
|
2014-09-09 17:40:24 -06:00
|
|
|
/* We cannot modify an address and change the address family */
|
|
|
|
BUG_ON(!add && udest->af != dest->af);
|
|
|
|
|
|
|
|
if (add && udest->af != svc->af)
|
|
|
|
ipvs->mixed_address_family_dests++;
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
/* set the weight and the flags */
|
|
|
|
atomic_set(&dest->weight, udest->weight);
|
2010-09-17 06:18:16 -06:00
|
|
|
conn_flags = udest->conn_flags & IP_VS_CONN_F_DEST_MASK;
|
|
|
|
conn_flags |= IP_VS_CONN_F_INACTIVE;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
/* set the IP_VS_CONN_F_NOOUTPUT flag if not masquerading/NAT */
|
2010-09-17 06:18:16 -06:00
|
|
|
if ((conn_flags & IP_VS_CONN_F_FWD_MASK) != IP_VS_CONN_F_MASQ) {
|
2005-04-16 16:20:36 -06:00
|
|
|
conn_flags |= IP_VS_CONN_F_NOOUTPUT;
|
|
|
|
} else {
|
|
|
|
/*
|
2011-01-03 06:44:43 -07:00
|
|
|
* Put the real service in rs_table if not present.
|
2005-04-16 16:20:36 -06:00
|
|
|
* For now only for NAT!
|
|
|
|
*/
|
2011-01-03 06:44:43 -07:00
|
|
|
ip_vs_rs_hash(ipvs, dest);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
atomic_set(&dest->conn_flags, conn_flags);
|
|
|
|
|
|
|
|
/* bind the service */
|
2013-09-12 02:21:07 -06:00
|
|
|
old_svc = rcu_dereference_protected(dest->svc, 1);
|
|
|
|
if (!old_svc) {
|
2005-04-16 16:20:36 -06:00
|
|
|
__ip_vs_bind_svc(dest, svc);
|
|
|
|
} else {
|
2013-09-12 02:21:07 -06:00
|
|
|
if (old_svc != svc) {
|
2005-04-16 16:20:36 -06:00
|
|
|
ip_vs_zero_stats(&dest->stats);
|
|
|
|
__ip_vs_bind_svc(dest, svc);
|
2013-09-12 02:21:07 -06:00
|
|
|
__ip_vs_svc_put(old_svc, true);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* set the dest status flags */
|
|
|
|
dest->flags |= IP_VS_DEST_F_AVAILABLE;
|
|
|
|
|
|
|
|
if (udest->u_threshold == 0 || udest->u_threshold > dest->u_threshold)
|
|
|
|
dest->flags &= ~IP_VS_DEST_F_OVERLOAD;
|
|
|
|
dest->u_threshold = udest->u_threshold;
|
|
|
|
dest->l_threshold = udest->l_threshold;
|
2010-09-21 10:12:30 -06:00
|
|
|
|
2014-09-09 17:40:20 -06:00
|
|
|
dest->af = udest->af;
|
|
|
|
|
2011-02-22 01:40:25 -07:00
|
|
|
spin_lock_bh(&dest->dst_lock);
|
2013-03-21 03:58:02 -06:00
|
|
|
__ip_vs_dst_cache_reset(dest);
|
2011-02-22 01:40:25 -07:00
|
|
|
spin_unlock_bh(&dest->dst_lock);
|
2010-10-17 07:38:15 -06:00
|
|
|
|
2013-03-22 03:46:53 -06:00
|
|
|
sched = rcu_dereference_protected(svc->scheduler, 1);
|
2010-09-21 10:12:30 -06:00
|
|
|
if (add) {
|
2013-03-22 03:46:53 -06:00
|
|
|
ip_vs_start_estimator(svc->net, &dest->stats);
|
2013-03-22 03:46:52 -06:00
|
|
|
list_add_rcu(&dest->n_list, &svc->destinations);
|
2010-09-21 10:12:30 -06:00
|
|
|
svc->num_dests++;
|
2013-03-22 03:46:53 -06:00
|
|
|
if (sched->add_dest)
|
|
|
|
sched->add_dest(svc, dest);
|
2013-03-22 03:46:37 -06:00
|
|
|
} else {
|
2013-03-22 03:46:53 -06:00
|
|
|
if (sched->upd_dest)
|
|
|
|
sched->upd_dest(svc, dest);
|
2010-09-21 10:12:30 -06:00
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create a destination for the given service
|
|
|
|
*/
|
|
|
|
static int
|
2008-09-02 07:55:36 -06:00
|
|
|
ip_vs_new_dest(struct ip_vs_service *svc, struct ip_vs_dest_user_kern *udest,
|
2005-04-16 16:20:36 -06:00
|
|
|
struct ip_vs_dest **dest_p)
|
|
|
|
{
|
|
|
|
struct ip_vs_dest *dest;
|
2013-10-07 16:51:58 -06:00
|
|
|
unsigned int atype, i;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
EnterFunction(2);
|
|
|
|
|
2008-09-02 07:55:52 -06:00
|
|
|
#ifdef CONFIG_IP_VS_IPV6
|
2014-09-09 17:40:20 -06:00
|
|
|
if (udest->af == AF_INET6) {
|
2008-09-02 07:55:52 -06:00
|
|
|
atype = ipv6_addr_type(&udest->addr.in6);
|
2008-09-05 08:53:49 -06:00
|
|
|
if ((!(atype & IPV6_ADDR_UNICAST) ||
|
|
|
|
atype & IPV6_ADDR_LINKLOCAL) &&
|
2011-01-03 06:45:02 -07:00
|
|
|
!__ip_vs_addr_is_local_v6(svc->net, &udest->addr.in6))
|
2008-09-02 07:55:52 -06:00
|
|
|
return -EINVAL;
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
{
|
2011-01-03 06:45:02 -07:00
|
|
|
atype = inet_addr_type(svc->net, udest->addr.ip);
|
2008-09-02 07:55:52 -06:00
|
|
|
if (atype != RTN_LOCAL && atype != RTN_UNICAST)
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2010-08-25 20:54:31 -06:00
|
|
|
dest = kzalloc(sizeof(struct ip_vs_dest), GFP_KERNEL);
|
2011-08-29 15:17:25 -06:00
|
|
|
if (dest == NULL)
|
2005-04-16 16:20:36 -06:00
|
|
|
return -ENOMEM;
|
2011-08-29 15:17:25 -06:00
|
|
|
|
2011-01-03 06:44:56 -07:00
|
|
|
dest->stats.cpustats = alloc_percpu(struct ip_vs_cpu_stats);
|
2011-08-29 15:17:25 -06:00
|
|
|
if (!dest->stats.cpustats)
|
2011-01-03 06:44:56 -07:00
|
|
|
goto err_alloc;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2013-10-07 16:51:58 -06:00
|
|
|
for_each_possible_cpu(i) {
|
|
|
|
struct ip_vs_cpu_stats *ip_vs_dest_stats;
|
|
|
|
ip_vs_dest_stats = per_cpu_ptr(dest->stats.cpustats, i);
|
|
|
|
u64_stats_init(&ip_vs_dest_stats->syncp);
|
|
|
|
}
|
|
|
|
|
2014-09-09 17:40:20 -06:00
|
|
|
dest->af = udest->af;
|
2005-04-16 16:20:36 -06:00
|
|
|
dest->protocol = svc->protocol;
|
2008-09-02 07:55:36 -06:00
|
|
|
dest->vaddr = svc->addr;
|
2005-04-16 16:20:36 -06:00
|
|
|
dest->vport = svc->port;
|
|
|
|
dest->vfwmark = svc->fwmark;
|
2014-09-09 17:40:20 -06:00
|
|
|
ip_vs_addr_copy(udest->af, &dest->addr, &udest->addr);
|
2005-04-16 16:20:36 -06:00
|
|
|
dest->port = udest->port;
|
|
|
|
|
|
|
|
atomic_set(&dest->activeconns, 0);
|
|
|
|
atomic_set(&dest->inactconns, 0);
|
|
|
|
atomic_set(&dest->persistconns, 0);
|
2010-09-21 10:12:30 -06:00
|
|
|
atomic_set(&dest->refcnt, 1);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2013-03-21 03:58:08 -06:00
|
|
|
INIT_HLIST_NODE(&dest->d_list);
|
2005-04-16 16:20:36 -06:00
|
|
|
spin_lock_init(&dest->dst_lock);
|
|
|
|
spin_lock_init(&dest->stats.lock);
|
2010-09-21 10:12:30 -06:00
|
|
|
__ip_vs_update_dest(svc, dest, udest, 1);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
*dest_p = dest;
|
|
|
|
|
|
|
|
LeaveFunction(2);
|
|
|
|
return 0;
|
2011-01-03 06:44:56 -07:00
|
|
|
|
|
|
|
err_alloc:
|
|
|
|
kfree(dest);
|
|
|
|
return -ENOMEM;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add a destination into an existing service
|
|
|
|
*/
|
|
|
|
static int
|
2008-09-02 07:55:36 -06:00
|
|
|
ip_vs_add_dest(struct ip_vs_service *svc, struct ip_vs_dest_user_kern *udest)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
struct ip_vs_dest *dest;
|
2008-09-02 07:55:36 -06:00
|
|
|
union nf_inet_addr daddr;
|
2006-09-28 15:29:52 -06:00
|
|
|
__be16 dport = udest->port;
|
2005-04-16 16:20:36 -06:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
EnterFunction(2);
|
|
|
|
|
|
|
|
if (udest->weight < 0) {
|
2009-08-02 05:05:41 -06:00
|
|
|
pr_err("%s(): server weight less than zero\n", __func__);
|
2005-04-16 16:20:36 -06:00
|
|
|
return -ERANGE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (udest->l_threshold > udest->u_threshold) {
|
2009-08-02 05:05:41 -06:00
|
|
|
pr_err("%s(): lower threshold is higher than upper threshold\n",
|
|
|
|
__func__);
|
2005-04-16 16:20:36 -06:00
|
|
|
return -ERANGE;
|
|
|
|
}
|
|
|
|
|
2014-09-09 17:40:20 -06:00
|
|
|
ip_vs_addr_copy(udest->af, &daddr, &udest->addr);
|
2008-09-02 07:55:36 -06:00
|
|
|
|
2013-03-22 03:46:52 -06:00
|
|
|
/* We use function that requires RCU lock */
|
|
|
|
rcu_read_lock();
|
2014-09-09 17:40:21 -06:00
|
|
|
dest = ip_vs_lookup_dest(svc, udest->af, &daddr, dport);
|
2013-03-22 03:46:52 -06:00
|
|
|
rcu_read_unlock();
|
2008-09-02 07:55:48 -06:00
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
if (dest != NULL) {
|
2009-08-02 05:05:41 -06:00
|
|
|
IP_VS_DBG(1, "%s(): dest already exists\n", __func__);
|
2005-04-16 16:20:36 -06:00
|
|
|
return -EEXIST;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if the dest already exists in the trash and
|
|
|
|
* is from the same service
|
|
|
|
*/
|
2014-09-09 17:40:22 -06:00
|
|
|
dest = ip_vs_trash_get_dest(svc, udest->af, &daddr, dport);
|
2008-09-02 07:55:48 -06:00
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
if (dest != NULL) {
|
2008-09-02 07:55:53 -06:00
|
|
|
IP_VS_DBG_BUF(3, "Get destination %s:%u from trash, "
|
|
|
|
"dest->refcnt=%d, service %u/%s:%u\n",
|
2014-09-09 17:40:20 -06:00
|
|
|
IP_VS_DBG_ADDR(udest->af, &daddr), ntohs(dport),
|
2008-09-02 07:55:53 -06:00
|
|
|
atomic_read(&dest->refcnt),
|
|
|
|
dest->vfwmark,
|
|
|
|
IP_VS_DBG_ADDR(svc->af, &dest->vaddr),
|
|
|
|
ntohs(dest->vport));
|
|
|
|
|
2010-09-21 10:12:30 -06:00
|
|
|
__ip_vs_update_dest(svc, dest, udest, 1);
|
|
|
|
ret = 0;
|
|
|
|
} else {
|
2005-04-16 16:20:36 -06:00
|
|
|
/*
|
2010-09-21 10:12:30 -06:00
|
|
|
* Allocate and initialize the dest structure
|
2005-04-16 16:20:36 -06:00
|
|
|
*/
|
2010-09-21 10:12:30 -06:00
|
|
|
ret = ip_vs_new_dest(svc, udest, &dest);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
LeaveFunction(2);
|
|
|
|
|
2010-09-21 10:12:30 -06:00
|
|
|
return ret;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Edit a destination in the given service
|
|
|
|
*/
|
|
|
|
static int
|
2008-09-02 07:55:36 -06:00
|
|
|
ip_vs_edit_dest(struct ip_vs_service *svc, struct ip_vs_dest_user_kern *udest)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
struct ip_vs_dest *dest;
|
2008-09-02 07:55:36 -06:00
|
|
|
union nf_inet_addr daddr;
|
2006-09-28 15:29:52 -06:00
|
|
|
__be16 dport = udest->port;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
EnterFunction(2);
|
|
|
|
|
|
|
|
if (udest->weight < 0) {
|
2009-08-02 05:05:41 -06:00
|
|
|
pr_err("%s(): server weight less than zero\n", __func__);
|
2005-04-16 16:20:36 -06:00
|
|
|
return -ERANGE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (udest->l_threshold > udest->u_threshold) {
|
2009-08-02 05:05:41 -06:00
|
|
|
pr_err("%s(): lower threshold is higher than upper threshold\n",
|
|
|
|
__func__);
|
2005-04-16 16:20:36 -06:00
|
|
|
return -ERANGE;
|
|
|
|
}
|
|
|
|
|
2014-09-09 17:40:20 -06:00
|
|
|
ip_vs_addr_copy(udest->af, &daddr, &udest->addr);
|
2008-09-02 07:55:36 -06:00
|
|
|
|
2013-03-22 03:46:52 -06:00
|
|
|
/* We use function that requires RCU lock */
|
|
|
|
rcu_read_lock();
|
2014-09-09 17:40:21 -06:00
|
|
|
dest = ip_vs_lookup_dest(svc, udest->af, &daddr, dport);
|
2013-03-22 03:46:52 -06:00
|
|
|
rcu_read_unlock();
|
2008-09-02 07:55:48 -06:00
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
if (dest == NULL) {
|
2009-08-02 05:05:41 -06:00
|
|
|
IP_VS_DBG(1, "%s(): dest doesn't exist\n", __func__);
|
2005-04-16 16:20:36 -06:00
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
2010-09-21 10:12:30 -06:00
|
|
|
__ip_vs_update_dest(svc, dest, udest, 0);
|
2005-04-16 16:20:36 -06:00
|
|
|
LeaveFunction(2);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Delete a destination (must be already unlinked from the service)
|
|
|
|
*/
|
2013-03-22 03:46:49 -06:00
|
|
|
static void __ip_vs_del_dest(struct net *net, struct ip_vs_dest *dest,
|
|
|
|
bool cleanup)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2011-01-03 06:44:58 -07:00
|
|
|
struct netns_ipvs *ipvs = net_ipvs(net);
|
|
|
|
|
2011-03-13 17:44:28 -06:00
|
|
|
ip_vs_stop_estimator(net, &dest->stats);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Remove it from the d-linked list with the real services.
|
|
|
|
*/
|
|
|
|
ip_vs_rs_unhash(dest);
|
|
|
|
|
2013-03-22 03:46:49 -06:00
|
|
|
spin_lock_bh(&ipvs->dest_trash_lock);
|
|
|
|
IP_VS_DBG_BUF(3, "Moving dest %s:%u into trash, dest->refcnt=%d\n",
|
|
|
|
IP_VS_DBG_ADDR(dest->af, &dest->addr), ntohs(dest->port),
|
|
|
|
atomic_read(&dest->refcnt));
|
|
|
|
if (list_empty(&ipvs->dest_trash) && !cleanup)
|
|
|
|
mod_timer(&ipvs->dest_trash_timer,
|
2013-09-12 02:21:07 -06:00
|
|
|
jiffies + (IP_VS_DEST_TRASH_PERIOD >> 1));
|
2013-03-22 03:46:49 -06:00
|
|
|
/* dest lives in trash without reference */
|
|
|
|
list_add(&dest->t_list, &ipvs->dest_trash);
|
2013-09-12 02:21:07 -06:00
|
|
|
dest->idle_start = 0;
|
2013-03-22 03:46:49 -06:00
|
|
|
spin_unlock_bh(&ipvs->dest_trash_lock);
|
|
|
|
ip_vs_dest_put(dest);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Unlink a destination from the given service
|
|
|
|
*/
|
|
|
|
static void __ip_vs_unlink_dest(struct ip_vs_service *svc,
|
|
|
|
struct ip_vs_dest *dest,
|
|
|
|
int svcupd)
|
|
|
|
{
|
|
|
|
dest->flags &= ~IP_VS_DEST_F_AVAILABLE;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Remove it from the d-linked destination list.
|
|
|
|
*/
|
2013-03-22 03:46:52 -06:00
|
|
|
list_del_rcu(&dest->n_list);
|
2005-04-16 16:20:36 -06:00
|
|
|
svc->num_dests--;
|
2008-08-11 13:36:06 -06:00
|
|
|
|
2014-09-09 17:40:24 -06:00
|
|
|
if (dest->af != svc->af)
|
|
|
|
net_ipvs(svc->net)->mixed_address_family_dests--;
|
|
|
|
|
2013-03-22 03:46:53 -06:00
|
|
|
if (svcupd) {
|
|
|
|
struct ip_vs_scheduler *sched;
|
2013-03-22 03:46:37 -06:00
|
|
|
|
2013-03-22 03:46:53 -06:00
|
|
|
sched = rcu_dereference_protected(svc->scheduler, 1);
|
|
|
|
if (sched->del_dest)
|
|
|
|
sched->del_dest(svc, dest);
|
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Delete a destination server in the given service
|
|
|
|
*/
|
|
|
|
static int
|
2008-09-02 07:55:36 -06:00
|
|
|
ip_vs_del_dest(struct ip_vs_service *svc, struct ip_vs_dest_user_kern *udest)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
struct ip_vs_dest *dest;
|
2006-09-28 15:29:52 -06:00
|
|
|
__be16 dport = udest->port;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
EnterFunction(2);
|
|
|
|
|
2013-03-22 03:46:52 -06:00
|
|
|
/* We use function that requires RCU lock */
|
|
|
|
rcu_read_lock();
|
2014-09-09 17:40:21 -06:00
|
|
|
dest = ip_vs_lookup_dest(svc, udest->af, &udest->addr, dport);
|
2013-03-22 03:46:52 -06:00
|
|
|
rcu_read_unlock();
|
2008-09-02 07:55:36 -06:00
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
if (dest == NULL) {
|
2009-08-02 05:05:41 -06:00
|
|
|
IP_VS_DBG(1, "%s(): destination not found!\n", __func__);
|
2005-04-16 16:20:36 -06:00
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Unlink dest from the service
|
|
|
|
*/
|
|
|
|
__ip_vs_unlink_dest(svc, dest, 1);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Delete the destination
|
|
|
|
*/
|
2013-03-22 03:46:49 -06:00
|
|
|
__ip_vs_del_dest(svc->net, dest, false);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
LeaveFunction(2);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-03-22 03:46:49 -06:00
|
|
|
static void ip_vs_dest_trash_expire(unsigned long data)
|
|
|
|
{
|
|
|
|
struct net *net = (struct net *) data;
|
|
|
|
struct netns_ipvs *ipvs = net_ipvs(net);
|
|
|
|
struct ip_vs_dest *dest, *next;
|
2013-09-12 02:21:07 -06:00
|
|
|
unsigned long now = jiffies;
|
2013-03-22 03:46:49 -06:00
|
|
|
|
|
|
|
spin_lock(&ipvs->dest_trash_lock);
|
|
|
|
list_for_each_entry_safe(dest, next, &ipvs->dest_trash, t_list) {
|
|
|
|
if (atomic_read(&dest->refcnt) > 0)
|
|
|
|
continue;
|
2013-09-12 02:21:07 -06:00
|
|
|
if (dest->idle_start) {
|
|
|
|
if (time_before(now, dest->idle_start +
|
|
|
|
IP_VS_DEST_TRASH_PERIOD))
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
dest->idle_start = max(1UL, now);
|
|
|
|
continue;
|
|
|
|
}
|
2013-03-22 03:46:49 -06:00
|
|
|
IP_VS_DBG_BUF(3, "Removing destination %u/%s:%u from trash\n",
|
|
|
|
dest->vfwmark,
|
2013-09-12 02:21:07 -06:00
|
|
|
IP_VS_DBG_ADDR(dest->af, &dest->addr),
|
2013-03-22 03:46:49 -06:00
|
|
|
ntohs(dest->port));
|
|
|
|
list_del(&dest->t_list);
|
|
|
|
ip_vs_dest_free(dest);
|
|
|
|
}
|
|
|
|
if (!list_empty(&ipvs->dest_trash))
|
|
|
|
mod_timer(&ipvs->dest_trash_timer,
|
2013-09-12 02:21:07 -06:00
|
|
|
jiffies + (IP_VS_DEST_TRASH_PERIOD >> 1));
|
2013-03-22 03:46:49 -06:00
|
|
|
spin_unlock(&ipvs->dest_trash_lock);
|
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Add a service into the service hash table
|
|
|
|
*/
|
|
|
|
static int
|
2011-01-03 06:44:43 -07:00
|
|
|
ip_vs_add_service(struct net *net, struct ip_vs_service_user_kern *u,
|
2008-09-02 07:55:36 -06:00
|
|
|
struct ip_vs_service **svc_p)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2013-10-07 16:51:58 -06:00
|
|
|
int ret = 0, i;
|
2005-04-16 16:20:36 -06:00
|
|
|
struct ip_vs_scheduler *sched = NULL;
|
2010-08-22 06:37:54 -06:00
|
|
|
struct ip_vs_pe *pe = NULL;
|
2005-04-16 16:20:36 -06:00
|
|
|
struct ip_vs_service *svc = NULL;
|
2011-01-03 06:44:58 -07:00
|
|
|
struct netns_ipvs *ipvs = net_ipvs(net);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
/* increase the module use count */
|
|
|
|
ip_vs_use_count_inc();
|
|
|
|
|
|
|
|
/* Lookup the scheduler by 'u->sched_name' */
|
|
|
|
sched = ip_vs_scheduler_get(u->sched_name);
|
|
|
|
if (sched == NULL) {
|
2009-08-02 05:05:41 -06:00
|
|
|
pr_info("Scheduler module ip_vs_%s not found\n", u->sched_name);
|
2005-04-16 16:20:36 -06:00
|
|
|
ret = -ENOENT;
|
2010-08-22 06:37:52 -06:00
|
|
|
goto out_err;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2010-08-22 06:37:54 -06:00
|
|
|
if (u->pe_name && *u->pe_name) {
|
2010-11-08 04:05:57 -07:00
|
|
|
pe = ip_vs_pe_getbyname(u->pe_name);
|
2010-08-22 06:37:54 -06:00
|
|
|
if (pe == NULL) {
|
|
|
|
pr_info("persistence engine module ip_vs_pe_%s "
|
|
|
|
"not found\n", u->pe_name);
|
|
|
|
ret = -ENOENT;
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-02 07:55:55 -06:00
|
|
|
#ifdef CONFIG_IP_VS_IPV6
|
2013-04-17 14:50:49 -06:00
|
|
|
if (u->af == AF_INET6) {
|
|
|
|
__u32 plen = (__force __u32) u->netmask;
|
|
|
|
|
|
|
|
if (plen < 1 || plen > 128) {
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto out_err;
|
|
|
|
}
|
2008-09-02 07:55:55 -06:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-08-25 20:54:31 -06:00
|
|
|
svc = kzalloc(sizeof(struct ip_vs_service), GFP_KERNEL);
|
2005-04-16 16:20:36 -06:00
|
|
|
if (svc == NULL) {
|
2009-08-02 05:05:41 -06:00
|
|
|
IP_VS_DBG(1, "%s(): no memory\n", __func__);
|
2005-04-16 16:20:36 -06:00
|
|
|
ret = -ENOMEM;
|
|
|
|
goto out_err;
|
|
|
|
}
|
2011-01-03 06:44:56 -07:00
|
|
|
svc->stats.cpustats = alloc_percpu(struct ip_vs_cpu_stats);
|
2012-08-29 00:49:11 -06:00
|
|
|
if (!svc->stats.cpustats) {
|
|
|
|
ret = -ENOMEM;
|
2011-01-03 06:44:56 -07:00
|
|
|
goto out_err;
|
2012-08-29 00:49:11 -06:00
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2013-10-07 16:51:58 -06:00
|
|
|
for_each_possible_cpu(i) {
|
|
|
|
struct ip_vs_cpu_stats *ip_vs_stats;
|
|
|
|
ip_vs_stats = per_cpu_ptr(svc->stats.cpustats, i);
|
|
|
|
u64_stats_init(&ip_vs_stats->syncp);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
/* I'm the first user of the service */
|
|
|
|
atomic_set(&svc->refcnt, 0);
|
|
|
|
|
2008-09-02 07:55:36 -06:00
|
|
|
svc->af = u->af;
|
2005-04-16 16:20:36 -06:00
|
|
|
svc->protocol = u->protocol;
|
2008-09-02 07:55:36 -06:00
|
|
|
ip_vs_addr_copy(svc->af, &svc->addr, &u->addr);
|
2005-04-16 16:20:36 -06:00
|
|
|
svc->port = u->port;
|
|
|
|
svc->fwmark = u->fwmark;
|
|
|
|
svc->flags = u->flags;
|
|
|
|
svc->timeout = u->timeout * HZ;
|
|
|
|
svc->netmask = u->netmask;
|
2011-01-03 06:44:43 -07:00
|
|
|
svc->net = net;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
INIT_LIST_HEAD(&svc->destinations);
|
2013-03-22 03:46:51 -06:00
|
|
|
spin_lock_init(&svc->sched_lock);
|
2005-04-16 16:20:36 -06:00
|
|
|
spin_lock_init(&svc->stats.lock);
|
|
|
|
|
|
|
|
/* Bind the scheduler */
|
|
|
|
ret = ip_vs_bind_scheduler(svc, sched);
|
|
|
|
if (ret)
|
|
|
|
goto out_err;
|
|
|
|
sched = NULL;
|
|
|
|
|
2010-08-22 06:37:54 -06:00
|
|
|
/* Bind the ct retriever */
|
2013-03-22 03:46:53 -06:00
|
|
|
RCU_INIT_POINTER(svc->pe, pe);
|
2010-08-22 06:37:54 -06:00
|
|
|
pe = NULL;
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
/* Update the virtual service counters */
|
|
|
|
if (svc->port == FTPPORT)
|
2011-01-03 06:45:01 -07:00
|
|
|
atomic_inc(&ipvs->ftpsvc_counter);
|
2005-04-16 16:20:36 -06:00
|
|
|
else if (svc->port == 0)
|
2011-01-03 06:45:01 -07:00
|
|
|
atomic_inc(&ipvs->nullsvc_counter);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2011-03-13 17:44:28 -06:00
|
|
|
ip_vs_start_estimator(net, &svc->stats);
|
2008-09-02 07:55:55 -06:00
|
|
|
|
|
|
|
/* Count only IPv4 services for old get/setsockopt interface */
|
|
|
|
if (svc->af == AF_INET)
|
2011-01-03 06:44:58 -07:00
|
|
|
ipvs->num_services++;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
/* Hash the service into the service table */
|
|
|
|
ip_vs_svc_hash(svc);
|
|
|
|
|
|
|
|
*svc_p = svc;
|
2011-05-03 14:09:31 -06:00
|
|
|
/* Now there is a service - full throttle */
|
|
|
|
ipvs->enable = 1;
|
2005-04-16 16:20:36 -06:00
|
|
|
return 0;
|
|
|
|
|
2011-01-03 06:44:56 -07:00
|
|
|
|
2010-08-22 06:37:52 -06:00
|
|
|
out_err:
|
2005-04-16 16:20:36 -06:00
|
|
|
if (svc != NULL) {
|
2013-03-22 03:46:53 -06:00
|
|
|
ip_vs_unbind_scheduler(svc, sched);
|
|
|
|
ip_vs_service_free(svc);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
ip_vs_scheduler_put(sched);
|
2010-08-22 06:37:54 -06:00
|
|
|
ip_vs_pe_put(pe);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
/* decrease the module use count */
|
|
|
|
ip_vs_use_count_dec();
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Edit a service and bind it with a new scheduler
|
|
|
|
*/
|
|
|
|
static int
|
2008-09-02 07:55:36 -06:00
|
|
|
ip_vs_edit_service(struct ip_vs_service *svc, struct ip_vs_service_user_kern *u)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
struct ip_vs_scheduler *sched, *old_sched;
|
2010-08-22 06:37:54 -06:00
|
|
|
struct ip_vs_pe *pe = NULL, *old_pe = NULL;
|
2005-04-16 16:20:36 -06:00
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Lookup the scheduler, by 'u->sched_name'
|
|
|
|
*/
|
|
|
|
sched = ip_vs_scheduler_get(u->sched_name);
|
|
|
|
if (sched == NULL) {
|
2009-08-02 05:05:41 -06:00
|
|
|
pr_info("Scheduler module ip_vs_%s not found\n", u->sched_name);
|
2005-04-16 16:20:36 -06:00
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
old_sched = sched;
|
|
|
|
|
2010-08-22 06:37:54 -06:00
|
|
|
if (u->pe_name && *u->pe_name) {
|
2010-11-08 04:05:57 -07:00
|
|
|
pe = ip_vs_pe_getbyname(u->pe_name);
|
2010-08-22 06:37:54 -06:00
|
|
|
if (pe == NULL) {
|
|
|
|
pr_info("persistence engine module ip_vs_pe_%s "
|
|
|
|
"not found\n", u->pe_name);
|
|
|
|
ret = -ENOENT;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
old_pe = pe;
|
|
|
|
}
|
|
|
|
|
2008-09-02 07:55:55 -06:00
|
|
|
#ifdef CONFIG_IP_VS_IPV6
|
2013-04-17 14:50:49 -06:00
|
|
|
if (u->af == AF_INET6) {
|
|
|
|
__u32 plen = (__force __u32) u->netmask;
|
|
|
|
|
|
|
|
if (plen < 1 || plen > 128) {
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
2008-09-02 07:55:55 -06:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-03-22 03:46:53 -06:00
|
|
|
old_sched = rcu_dereference_protected(svc->scheduler, 1);
|
|
|
|
if (sched != old_sched) {
|
|
|
|
/* Bind the new scheduler */
|
|
|
|
ret = ip_vs_bind_scheduler(svc, sched);
|
|
|
|
if (ret) {
|
|
|
|
old_sched = sched;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
/* Unbind the old scheduler on success */
|
|
|
|
ip_vs_unbind_scheduler(svc, old_sched);
|
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the flags and timeout value
|
|
|
|
*/
|
|
|
|
svc->flags = u->flags | IP_VS_SVC_F_HASHED;
|
|
|
|
svc->timeout = u->timeout * HZ;
|
|
|
|
svc->netmask = u->netmask;
|
|
|
|
|
2013-03-22 03:46:53 -06:00
|
|
|
old_pe = rcu_dereference_protected(svc->pe, 1);
|
|
|
|
if (pe != old_pe)
|
|
|
|
rcu_assign_pointer(svc->pe, pe);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2011-06-13 04:19:26 -06:00
|
|
|
out:
|
2010-08-22 06:37:52 -06:00
|
|
|
ip_vs_scheduler_put(old_sched);
|
2010-08-22 06:37:54 -06:00
|
|
|
ip_vs_pe_put(old_pe);
|
2005-04-16 16:20:36 -06:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Delete a service from the service list
|
|
|
|
* - The service must be unlinked, unlocked and not referenced!
|
|
|
|
* - We are called under _bh lock
|
|
|
|
*/
|
2013-03-22 03:46:49 -06:00
|
|
|
static void __ip_vs_del_service(struct ip_vs_service *svc, bool cleanup)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
struct ip_vs_dest *dest, *nxt;
|
|
|
|
struct ip_vs_scheduler *old_sched;
|
2010-08-22 06:37:54 -06:00
|
|
|
struct ip_vs_pe *old_pe;
|
2011-01-03 06:44:58 -07:00
|
|
|
struct netns_ipvs *ipvs = net_ipvs(svc->net);
|
2010-08-22 06:37:54 -06:00
|
|
|
|
|
|
|
pr_info("%s: enter\n", __func__);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2008-09-02 07:55:55 -06:00
|
|
|
/* Count only IPv4 services for old get/setsockopt interface */
|
|
|
|
if (svc->af == AF_INET)
|
2011-01-03 06:44:58 -07:00
|
|
|
ipvs->num_services--;
|
2008-09-02 07:55:55 -06:00
|
|
|
|
2011-03-13 17:44:28 -06:00
|
|
|
ip_vs_stop_estimator(svc->net, &svc->stats);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
/* Unbind scheduler */
|
2013-03-22 03:46:53 -06:00
|
|
|
old_sched = rcu_dereference_protected(svc->scheduler, 1);
|
|
|
|
ip_vs_unbind_scheduler(svc, old_sched);
|
2010-08-22 06:37:52 -06:00
|
|
|
ip_vs_scheduler_put(old_sched);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2013-03-22 03:46:53 -06:00
|
|
|
/* Unbind persistence engine, keep svc->pe */
|
|
|
|
old_pe = rcu_dereference_protected(svc->pe, 1);
|
2010-08-22 06:37:54 -06:00
|
|
|
ip_vs_pe_put(old_pe);
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
/*
|
|
|
|
* Unlink the whole destination list
|
|
|
|
*/
|
|
|
|
list_for_each_entry_safe(dest, nxt, &svc->destinations, n_list) {
|
|
|
|
__ip_vs_unlink_dest(svc, dest, 0);
|
2013-03-22 03:46:49 -06:00
|
|
|
__ip_vs_del_dest(svc->net, dest, cleanup);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Update the virtual service counters
|
|
|
|
*/
|
|
|
|
if (svc->port == FTPPORT)
|
2011-01-03 06:45:01 -07:00
|
|
|
atomic_dec(&ipvs->ftpsvc_counter);
|
2005-04-16 16:20:36 -06:00
|
|
|
else if (svc->port == 0)
|
2011-01-03 06:45:01 -07:00
|
|
|
atomic_dec(&ipvs->nullsvc_counter);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Free the service if nobody refers to it
|
|
|
|
*/
|
2013-09-12 02:21:07 -06:00
|
|
|
__ip_vs_svc_put(svc, true);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
/* decrease the module use count */
|
|
|
|
ip_vs_use_count_dec();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2010-09-21 10:12:30 -06:00
|
|
|
* Unlink a service from list and try to delete it if its refcnt reached 0
|
2005-04-16 16:20:36 -06:00
|
|
|
*/
|
2013-03-22 03:46:49 -06:00
|
|
|
static void ip_vs_unlink_service(struct ip_vs_service *svc, bool cleanup)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2013-03-22 03:46:53 -06:00
|
|
|
/* Hold svc to avoid double release from dest_trash */
|
|
|
|
atomic_inc(&svc->refcnt);
|
2005-04-16 16:20:36 -06:00
|
|
|
/*
|
|
|
|
* Unhash it from the service table
|
|
|
|
*/
|
|
|
|
ip_vs_svc_unhash(svc);
|
|
|
|
|
2013-03-22 03:46:49 -06:00
|
|
|
__ip_vs_del_service(svc, cleanup);
|
2010-09-21 10:12:30 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Delete a service from the service list
|
|
|
|
*/
|
|
|
|
static int ip_vs_del_service(struct ip_vs_service *svc)
|
|
|
|
{
|
|
|
|
if (svc == NULL)
|
|
|
|
return -EEXIST;
|
2013-03-22 03:46:49 -06:00
|
|
|
ip_vs_unlink_service(svc, false);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Flush all the virtual services
|
|
|
|
*/
|
2013-03-22 03:46:49 -06:00
|
|
|
static int ip_vs_flush(struct net *net, bool cleanup)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
int idx;
|
2013-03-22 03:46:53 -06:00
|
|
|
struct ip_vs_service *svc;
|
|
|
|
struct hlist_node *n;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
/*
|
2011-01-03 06:44:43 -07:00
|
|
|
* Flush the service table hashed by <netns,protocol,addr,port>
|
2005-04-16 16:20:36 -06:00
|
|
|
*/
|
|
|
|
for(idx = 0; idx < IP_VS_SVC_TAB_SIZE; idx++) {
|
2013-03-22 03:46:53 -06:00
|
|
|
hlist_for_each_entry_safe(svc, n, &ip_vs_svc_table[idx],
|
|
|
|
s_list) {
|
2011-01-03 06:44:43 -07:00
|
|
|
if (net_eq(svc->net, net))
|
2013-03-22 03:46:49 -06:00
|
|
|
ip_vs_unlink_service(svc, cleanup);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Flush the service table hashed by fwmark
|
|
|
|
*/
|
|
|
|
for(idx = 0; idx < IP_VS_SVC_TAB_SIZE; idx++) {
|
2013-03-22 03:46:53 -06:00
|
|
|
hlist_for_each_entry_safe(svc, n, &ip_vs_svc_fwm_table[idx],
|
|
|
|
f_list) {
|
2011-01-03 06:44:43 -07:00
|
|
|
if (net_eq(svc->net, net))
|
2013-03-22 03:46:49 -06:00
|
|
|
ip_vs_unlink_service(svc, cleanup);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-05-03 14:09:31 -06:00
|
|
|
/*
|
|
|
|
* Delete service by {netns} in the service table.
|
|
|
|
* Called by __ip_vs_cleanup()
|
|
|
|
*/
|
2011-05-01 10:50:16 -06:00
|
|
|
void ip_vs_service_net_cleanup(struct net *net)
|
2011-05-03 14:09:31 -06:00
|
|
|
{
|
|
|
|
EnterFunction(2);
|
|
|
|
/* Check for "full" addressed entries */
|
|
|
|
mutex_lock(&__ip_vs_mutex);
|
2013-03-22 03:46:49 -06:00
|
|
|
ip_vs_flush(net, true);
|
2011-05-03 14:09:31 -06:00
|
|
|
mutex_unlock(&__ip_vs_mutex);
|
|
|
|
LeaveFunction(2);
|
|
|
|
}
|
2013-03-21 03:58:02 -06:00
|
|
|
|
|
|
|
/* Put all references for device (dst_cache) */
|
2011-05-03 14:09:31 -06:00
|
|
|
static inline void
|
2013-03-21 03:58:02 -06:00
|
|
|
ip_vs_forget_dev(struct ip_vs_dest *dest, struct net_device *dev)
|
2011-05-03 14:09:31 -06:00
|
|
|
{
|
2013-04-17 14:50:45 -06:00
|
|
|
struct ip_vs_dest_dst *dest_dst;
|
|
|
|
|
2011-05-03 14:09:31 -06:00
|
|
|
spin_lock_bh(&dest->dst_lock);
|
2013-04-17 14:50:45 -06:00
|
|
|
dest_dst = rcu_dereference_protected(dest->dest_dst, 1);
|
|
|
|
if (dest_dst && dest_dst->dst_cache->dev == dev) {
|
2011-05-03 14:09:31 -06:00
|
|
|
IP_VS_DBG_BUF(3, "Reset dev:%s dest %s:%u ,dest->refcnt=%d\n",
|
|
|
|
dev->name,
|
|
|
|
IP_VS_DBG_ADDR(dest->af, &dest->addr),
|
|
|
|
ntohs(dest->port),
|
|
|
|
atomic_read(&dest->refcnt));
|
2013-03-21 03:58:02 -06:00
|
|
|
__ip_vs_dst_cache_reset(dest);
|
2011-05-03 14:09:31 -06:00
|
|
|
}
|
|
|
|
spin_unlock_bh(&dest->dst_lock);
|
|
|
|
|
|
|
|
}
|
2013-03-21 03:58:00 -06:00
|
|
|
/* Netdev event receiver
|
|
|
|
* Currently only NETDEV_DOWN is handled to release refs to cached dsts
|
2011-05-03 14:09:31 -06:00
|
|
|
*/
|
|
|
|
static int ip_vs_dst_event(struct notifier_block *this, unsigned long event,
|
2013-05-27 19:30:21 -06:00
|
|
|
void *ptr)
|
2011-05-03 14:09:31 -06:00
|
|
|
{
|
2013-05-27 19:30:21 -06:00
|
|
|
struct net_device *dev = netdev_notifier_info_to_dev(ptr);
|
2011-05-03 14:09:31 -06:00
|
|
|
struct net *net = dev_net(dev);
|
2012-07-07 11:30:11 -06:00
|
|
|
struct netns_ipvs *ipvs = net_ipvs(net);
|
2011-05-03 14:09:31 -06:00
|
|
|
struct ip_vs_service *svc;
|
|
|
|
struct ip_vs_dest *dest;
|
|
|
|
unsigned int idx;
|
|
|
|
|
2013-03-21 03:58:00 -06:00
|
|
|
if (event != NETDEV_DOWN || !ipvs)
|
2011-05-03 14:09:31 -06:00
|
|
|
return NOTIFY_DONE;
|
|
|
|
IP_VS_DBG(3, "%s() dev=%s\n", __func__, dev->name);
|
|
|
|
EnterFunction(2);
|
|
|
|
mutex_lock(&__ip_vs_mutex);
|
|
|
|
for (idx = 0; idx < IP_VS_SVC_TAB_SIZE; idx++) {
|
2013-03-22 03:46:53 -06:00
|
|
|
hlist_for_each_entry(svc, &ip_vs_svc_table[idx], s_list) {
|
2011-05-03 14:09:31 -06:00
|
|
|
if (net_eq(svc->net, net)) {
|
|
|
|
list_for_each_entry(dest, &svc->destinations,
|
|
|
|
n_list) {
|
2013-03-21 03:58:02 -06:00
|
|
|
ip_vs_forget_dev(dest, dev);
|
2011-05-03 14:09:31 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-22 03:46:53 -06:00
|
|
|
hlist_for_each_entry(svc, &ip_vs_svc_fwm_table[idx], f_list) {
|
2011-05-03 14:09:31 -06:00
|
|
|
if (net_eq(svc->net, net)) {
|
|
|
|
list_for_each_entry(dest, &svc->destinations,
|
|
|
|
n_list) {
|
2013-03-21 03:58:02 -06:00
|
|
|
ip_vs_forget_dev(dest, dev);
|
2011-05-03 14:09:31 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-22 03:46:49 -06:00
|
|
|
spin_lock_bh(&ipvs->dest_trash_lock);
|
|
|
|
list_for_each_entry(dest, &ipvs->dest_trash, t_list) {
|
2013-03-21 03:58:02 -06:00
|
|
|
ip_vs_forget_dev(dest, dev);
|
2011-05-03 14:09:31 -06:00
|
|
|
}
|
2013-03-22 03:46:49 -06:00
|
|
|
spin_unlock_bh(&ipvs->dest_trash_lock);
|
2011-05-03 14:09:31 -06:00
|
|
|
mutex_unlock(&__ip_vs_mutex);
|
|
|
|
LeaveFunction(2);
|
|
|
|
return NOTIFY_DONE;
|
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Zero counters in a service or all services
|
|
|
|
*/
|
|
|
|
static int ip_vs_zero_service(struct ip_vs_service *svc)
|
|
|
|
{
|
|
|
|
struct ip_vs_dest *dest;
|
|
|
|
|
|
|
|
list_for_each_entry(dest, &svc->destinations, n_list) {
|
|
|
|
ip_vs_zero_stats(&dest->stats);
|
|
|
|
}
|
|
|
|
ip_vs_zero_stats(&svc->stats);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-01-03 06:44:43 -07:00
|
|
|
static int ip_vs_zero_all(struct net *net)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
int idx;
|
|
|
|
struct ip_vs_service *svc;
|
|
|
|
|
|
|
|
for(idx = 0; idx < IP_VS_SVC_TAB_SIZE; idx++) {
|
2013-03-22 03:46:53 -06:00
|
|
|
hlist_for_each_entry(svc, &ip_vs_svc_table[idx], s_list) {
|
2011-01-03 06:44:43 -07:00
|
|
|
if (net_eq(svc->net, net))
|
|
|
|
ip_vs_zero_service(svc);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for(idx = 0; idx < IP_VS_SVC_TAB_SIZE; idx++) {
|
2013-03-22 03:46:53 -06:00
|
|
|
hlist_for_each_entry(svc, &ip_vs_svc_fwm_table[idx], f_list) {
|
2011-01-03 06:44:43 -07:00
|
|
|
if (net_eq(svc->net, net))
|
|
|
|
ip_vs_zero_service(svc);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-04 03:20:35 -07:00
|
|
|
ip_vs_zero_stats(&net_ipvs(net)->tot_stats);
|
2005-04-16 16:20:36 -06:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-02-04 02:33:02 -07:00
|
|
|
#ifdef CONFIG_SYSCTL
|
2012-04-24 14:46:40 -06:00
|
|
|
|
|
|
|
static int zero;
|
|
|
|
static int three = 3;
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
static int
|
2013-06-12 00:04:25 -06:00
|
|
|
proc_do_defense_mode(struct ctl_table *table, int write,
|
2005-04-16 16:20:36 -06:00
|
|
|
void __user *buffer, size_t *lenp, loff_t *ppos)
|
|
|
|
{
|
2011-01-03 06:44:51 -07:00
|
|
|
struct net *net = current->nsproxy->net_ns;
|
2005-04-16 16:20:36 -06:00
|
|
|
int *valp = table->data;
|
|
|
|
int val = *valp;
|
|
|
|
int rc;
|
|
|
|
|
2009-09-23 16:57:19 -06:00
|
|
|
rc = proc_dointvec(table, write, buffer, lenp, ppos);
|
2005-04-16 16:20:36 -06:00
|
|
|
if (write && (*valp != val)) {
|
|
|
|
if ((*valp < 0) || (*valp > 3)) {
|
|
|
|
/* Restore the correct value */
|
|
|
|
*valp = val;
|
|
|
|
} else {
|
2011-01-03 06:44:51 -07:00
|
|
|
update_defense_level(net_ipvs(net));
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2013-06-12 00:04:25 -06:00
|
|
|
proc_do_sync_threshold(struct ctl_table *table, int write,
|
2005-04-16 16:20:36 -06:00
|
|
|
void __user *buffer, size_t *lenp, loff_t *ppos)
|
|
|
|
{
|
|
|
|
int *valp = table->data;
|
|
|
|
int val[2];
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
/* backup the value first */
|
|
|
|
memcpy(val, valp, sizeof(val));
|
|
|
|
|
2009-09-23 16:57:19 -06:00
|
|
|
rc = proc_dointvec(table, write, buffer, lenp, ppos);
|
2012-04-24 14:46:40 -06:00
|
|
|
if (write && (valp[0] < 0 || valp[1] < 0 ||
|
|
|
|
(valp[0] >= valp[1] && valp[1]))) {
|
2005-04-16 16:20:36 -06:00
|
|
|
/* Restore the correct value */
|
|
|
|
memcpy(valp, val, sizeof(val));
|
|
|
|
}
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2010-11-19 06:25:14 -07:00
|
|
|
static int
|
2013-06-12 00:04:25 -06:00
|
|
|
proc_do_sync_mode(struct ctl_table *table, int write,
|
2010-11-19 06:25:14 -07:00
|
|
|
void __user *buffer, size_t *lenp, loff_t *ppos)
|
|
|
|
{
|
|
|
|
int *valp = table->data;
|
|
|
|
int val = *valp;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
rc = proc_dointvec(table, write, buffer, lenp, ppos);
|
|
|
|
if (write && (*valp != val)) {
|
|
|
|
if ((*valp < 0) || (*valp > 1)) {
|
|
|
|
/* Restore the correct value */
|
|
|
|
*valp = val;
|
2012-05-08 11:40:30 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2013-06-12 00:04:25 -06:00
|
|
|
proc_do_sync_ports(struct ctl_table *table, int write,
|
2012-05-08 11:40:30 -06:00
|
|
|
void __user *buffer, size_t *lenp, loff_t *ppos)
|
|
|
|
{
|
|
|
|
int *valp = table->data;
|
|
|
|
int val = *valp;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
rc = proc_dointvec(table, write, buffer, lenp, ppos);
|
|
|
|
if (write && (*valp != val)) {
|
|
|
|
if (*valp < 1 || !is_power_of_2(*valp)) {
|
|
|
|
/* Restore the correct value */
|
|
|
|
*valp = val;
|
2010-11-19 06:25:14 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return rc;
|
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
/*
|
|
|
|
* IPVS sysctl table (under the /proc/sys/net/ipv4/vs/)
|
2011-01-03 06:44:58 -07:00
|
|
|
* Do not change order or insert new entries without
|
2011-05-01 10:50:16 -06:00
|
|
|
* align with netns init in ip_vs_control_net_init()
|
2005-04-16 16:20:36 -06:00
|
|
|
*/
|
|
|
|
|
|
|
|
static struct ctl_table vs_vars[] = {
|
|
|
|
{
|
|
|
|
.procname = "amemthresh",
|
|
|
|
.maxlen = sizeof(int),
|
|
|
|
.mode = 0644,
|
2008-11-03 19:21:05 -07:00
|
|
|
.proc_handler = proc_dointvec,
|
2005-04-16 16:20:36 -06:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.procname = "am_droprate",
|
|
|
|
.maxlen = sizeof(int),
|
|
|
|
.mode = 0644,
|
2008-11-03 19:21:05 -07:00
|
|
|
.proc_handler = proc_dointvec,
|
2005-04-16 16:20:36 -06:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.procname = "drop_entry",
|
|
|
|
.maxlen = sizeof(int),
|
|
|
|
.mode = 0644,
|
2008-11-03 19:21:05 -07:00
|
|
|
.proc_handler = proc_do_defense_mode,
|
2005-04-16 16:20:36 -06:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.procname = "drop_packet",
|
|
|
|
.maxlen = sizeof(int),
|
|
|
|
.mode = 0644,
|
2008-11-03 19:21:05 -07:00
|
|
|
.proc_handler = proc_do_defense_mode,
|
2005-04-16 16:20:36 -06:00
|
|
|
},
|
2010-09-21 09:35:41 -06:00
|
|
|
#ifdef CONFIG_IP_VS_NFCT
|
|
|
|
{
|
|
|
|
.procname = "conntrack",
|
|
|
|
.maxlen = sizeof(int),
|
|
|
|
.mode = 0644,
|
|
|
|
.proc_handler = &proc_dointvec,
|
|
|
|
},
|
|
|
|
#endif
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
.procname = "secure_tcp",
|
|
|
|
.maxlen = sizeof(int),
|
|
|
|
.mode = 0644,
|
2008-11-03 19:21:05 -07:00
|
|
|
.proc_handler = proc_do_defense_mode,
|
2005-04-16 16:20:36 -06:00
|
|
|
},
|
2010-09-21 09:38:57 -06:00
|
|
|
{
|
|
|
|
.procname = "snat_reroute",
|
|
|
|
.maxlen = sizeof(int),
|
|
|
|
.mode = 0644,
|
|
|
|
.proc_handler = &proc_dointvec,
|
|
|
|
},
|
2010-11-19 06:25:14 -07:00
|
|
|
{
|
|
|
|
.procname = "sync_version",
|
|
|
|
.maxlen = sizeof(int),
|
|
|
|
.mode = 0644,
|
|
|
|
.proc_handler = &proc_do_sync_mode,
|
|
|
|
},
|
2012-05-08 11:40:30 -06:00
|
|
|
{
|
|
|
|
.procname = "sync_ports",
|
|
|
|
.maxlen = sizeof(int),
|
|
|
|
.mode = 0644,
|
|
|
|
.proc_handler = &proc_do_sync_ports,
|
|
|
|
},
|
2013-06-24 13:44:41 -06:00
|
|
|
{
|
|
|
|
.procname = "sync_persist_mode",
|
|
|
|
.maxlen = sizeof(int),
|
|
|
|
.mode = 0644,
|
|
|
|
.proc_handler = proc_dointvec,
|
|
|
|
},
|
2012-05-08 11:39:49 -06:00
|
|
|
{
|
|
|
|
.procname = "sync_qlen_max",
|
2013-04-29 12:55:10 -06:00
|
|
|
.maxlen = sizeof(unsigned long),
|
2012-05-08 11:39:49 -06:00
|
|
|
.mode = 0644,
|
2013-04-29 12:55:10 -06:00
|
|
|
.proc_handler = proc_doulongvec_minmax,
|
2012-05-08 11:39:49 -06:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.procname = "sync_sock_size",
|
|
|
|
.maxlen = sizeof(int),
|
|
|
|
.mode = 0644,
|
|
|
|
.proc_handler = proc_dointvec,
|
|
|
|
},
|
2011-01-03 06:44:58 -07:00
|
|
|
{
|
|
|
|
.procname = "cache_bypass",
|
|
|
|
.maxlen = sizeof(int),
|
|
|
|
.mode = 0644,
|
|
|
|
.proc_handler = proc_dointvec,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.procname = "expire_nodest_conn",
|
|
|
|
.maxlen = sizeof(int),
|
|
|
|
.mode = 0644,
|
|
|
|
.proc_handler = proc_dointvec,
|
|
|
|
},
|
2013-06-13 01:56:15 -06:00
|
|
|
{
|
|
|
|
.procname = "sloppy_tcp",
|
|
|
|
.maxlen = sizeof(int),
|
|
|
|
.mode = 0644,
|
|
|
|
.proc_handler = proc_dointvec,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.procname = "sloppy_sctp",
|
|
|
|
.maxlen = sizeof(int),
|
|
|
|
.mode = 0644,
|
|
|
|
.proc_handler = proc_dointvec,
|
|
|
|
},
|
2011-01-03 06:44:58 -07:00
|
|
|
{
|
|
|
|
.procname = "expire_quiescent_template",
|
|
|
|
.maxlen = sizeof(int),
|
|
|
|
.mode = 0644,
|
|
|
|
.proc_handler = proc_dointvec,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.procname = "sync_threshold",
|
|
|
|
.maxlen =
|
|
|
|
sizeof(((struct netns_ipvs *)0)->sysctl_sync_threshold),
|
|
|
|
.mode = 0644,
|
|
|
|
.proc_handler = proc_do_sync_threshold,
|
|
|
|
},
|
2012-04-24 14:46:40 -06:00
|
|
|
{
|
|
|
|
.procname = "sync_refresh_period",
|
|
|
|
.maxlen = sizeof(int),
|
|
|
|
.mode = 0644,
|
|
|
|
.proc_handler = proc_dointvec_jiffies,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.procname = "sync_retries",
|
|
|
|
.maxlen = sizeof(int),
|
|
|
|
.mode = 0644,
|
|
|
|
.proc_handler = proc_dointvec_minmax,
|
|
|
|
.extra1 = &zero,
|
|
|
|
.extra2 = &three,
|
|
|
|
},
|
2011-01-03 06:44:58 -07:00
|
|
|
{
|
|
|
|
.procname = "nat_icmp_send",
|
|
|
|
.maxlen = sizeof(int),
|
|
|
|
.mode = 0644,
|
|
|
|
.proc_handler = proc_dointvec,
|
|
|
|
},
|
2012-07-20 02:59:53 -06:00
|
|
|
{
|
|
|
|
.procname = "pmtu_disc",
|
|
|
|
.maxlen = sizeof(int),
|
|
|
|
.mode = 0644,
|
|
|
|
.proc_handler = proc_dointvec,
|
|
|
|
},
|
2013-03-09 14:25:04 -07:00
|
|
|
{
|
|
|
|
.procname = "backup_only",
|
|
|
|
.maxlen = sizeof(int),
|
|
|
|
.mode = 0644,
|
|
|
|
.proc_handler = proc_dointvec,
|
|
|
|
},
|
2011-01-03 06:44:58 -07:00
|
|
|
#ifdef CONFIG_IP_VS_DEBUG
|
|
|
|
{
|
|
|
|
.procname = "debug_level",
|
|
|
|
.data = &sysctl_ip_vs_debug_level,
|
|
|
|
.maxlen = sizeof(int),
|
|
|
|
.mode = 0644,
|
|
|
|
.proc_handler = proc_dointvec,
|
|
|
|
},
|
2005-04-16 16:20:36 -06:00
|
|
|
#endif
|
2009-11-05 14:32:03 -07:00
|
|
|
{ }
|
2005-04-16 16:20:36 -06:00
|
|
|
};
|
|
|
|
|
2011-02-04 02:33:02 -07:00
|
|
|
#endif
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
#ifdef CONFIG_PROC_FS
|
|
|
|
|
|
|
|
struct ip_vs_iter {
|
2011-01-03 06:44:43 -07:00
|
|
|
struct seq_net_private p; /* Do not move this, netns depends upon it*/
|
2013-03-22 03:46:53 -06:00
|
|
|
struct hlist_head *table;
|
2005-04-16 16:20:36 -06:00
|
|
|
int bucket;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Write the contents of the VS rule table to a PROCfs file.
|
|
|
|
* (It is kept just for backward compatibility)
|
|
|
|
*/
|
2012-04-14 23:58:06 -06:00
|
|
|
static inline const char *ip_vs_fwd_name(unsigned int flags)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
switch (flags & IP_VS_CONN_F_FWD_MASK) {
|
|
|
|
case IP_VS_CONN_F_LOCALNODE:
|
|
|
|
return "Local";
|
|
|
|
case IP_VS_CONN_F_TUNNEL:
|
|
|
|
return "Tunnel";
|
|
|
|
case IP_VS_CONN_F_DROUTE:
|
|
|
|
return "Route";
|
|
|
|
default:
|
|
|
|
return "Masq";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Get the Nth entry in the two lists */
|
|
|
|
static struct ip_vs_service *ip_vs_info_array(struct seq_file *seq, loff_t pos)
|
|
|
|
{
|
2011-01-03 06:44:43 -07:00
|
|
|
struct net *net = seq_file_net(seq);
|
2005-04-16 16:20:36 -06:00
|
|
|
struct ip_vs_iter *iter = seq->private;
|
|
|
|
int idx;
|
|
|
|
struct ip_vs_service *svc;
|
|
|
|
|
|
|
|
/* look in hash by protocol */
|
|
|
|
for (idx = 0; idx < IP_VS_SVC_TAB_SIZE; idx++) {
|
2013-03-22 03:46:53 -06:00
|
|
|
hlist_for_each_entry_rcu(svc, &ip_vs_svc_table[idx], s_list) {
|
2011-01-03 06:44:43 -07:00
|
|
|
if (net_eq(svc->net, net) && pos-- == 0) {
|
2005-04-16 16:20:36 -06:00
|
|
|
iter->table = ip_vs_svc_table;
|
|
|
|
iter->bucket = idx;
|
|
|
|
return svc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* keep looking in fwmark */
|
|
|
|
for (idx = 0; idx < IP_VS_SVC_TAB_SIZE; idx++) {
|
2013-03-22 03:46:53 -06:00
|
|
|
hlist_for_each_entry_rcu(svc, &ip_vs_svc_fwm_table[idx],
|
|
|
|
f_list) {
|
2011-01-03 06:44:43 -07:00
|
|
|
if (net_eq(svc->net, net) && pos-- == 0) {
|
2005-04-16 16:20:36 -06:00
|
|
|
iter->table = ip_vs_svc_fwm_table;
|
|
|
|
iter->bucket = idx;
|
|
|
|
return svc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *ip_vs_info_seq_start(struct seq_file *seq, loff_t *pos)
|
2013-04-17 14:50:50 -06:00
|
|
|
__acquires(RCU)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2013-03-22 03:46:53 -06:00
|
|
|
rcu_read_lock();
|
2005-04-16 16:20:36 -06:00
|
|
|
return *pos ? ip_vs_info_array(seq, *pos - 1) : SEQ_START_TOKEN;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void *ip_vs_info_seq_next(struct seq_file *seq, void *v, loff_t *pos)
|
|
|
|
{
|
2013-03-22 03:46:53 -06:00
|
|
|
struct hlist_node *e;
|
2005-04-16 16:20:36 -06:00
|
|
|
struct ip_vs_iter *iter;
|
|
|
|
struct ip_vs_service *svc;
|
|
|
|
|
|
|
|
++*pos;
|
|
|
|
if (v == SEQ_START_TOKEN)
|
|
|
|
return ip_vs_info_array(seq,0);
|
|
|
|
|
|
|
|
svc = v;
|
|
|
|
iter = seq->private;
|
|
|
|
|
|
|
|
if (iter->table == ip_vs_svc_table) {
|
|
|
|
/* next service in table hashed by protocol */
|
2013-03-22 03:46:53 -06:00
|
|
|
e = rcu_dereference(hlist_next_rcu(&svc->s_list));
|
|
|
|
if (e)
|
|
|
|
return hlist_entry(e, struct ip_vs_service, s_list);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
while (++iter->bucket < IP_VS_SVC_TAB_SIZE) {
|
2013-03-22 03:46:53 -06:00
|
|
|
hlist_for_each_entry_rcu(svc,
|
|
|
|
&ip_vs_svc_table[iter->bucket],
|
|
|
|
s_list) {
|
2005-04-16 16:20:36 -06:00
|
|
|
return svc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
iter->table = ip_vs_svc_fwm_table;
|
|
|
|
iter->bucket = -1;
|
|
|
|
goto scan_fwmark;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* next service in hashed by fwmark */
|
2013-03-22 03:46:53 -06:00
|
|
|
e = rcu_dereference(hlist_next_rcu(&svc->f_list));
|
|
|
|
if (e)
|
|
|
|
return hlist_entry(e, struct ip_vs_service, f_list);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
scan_fwmark:
|
|
|
|
while (++iter->bucket < IP_VS_SVC_TAB_SIZE) {
|
2013-03-22 03:46:53 -06:00
|
|
|
hlist_for_each_entry_rcu(svc,
|
|
|
|
&ip_vs_svc_fwm_table[iter->bucket],
|
|
|
|
f_list)
|
2005-04-16 16:20:36 -06:00
|
|
|
return svc;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ip_vs_info_seq_stop(struct seq_file *seq, void *v)
|
2013-04-17 14:50:50 -06:00
|
|
|
__releases(RCU)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2013-03-22 03:46:53 -06:00
|
|
|
rcu_read_unlock();
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
|
|
|
|
{
|
|
|
|
if (v == SEQ_START_TOKEN) {
|
|
|
|
seq_printf(seq,
|
|
|
|
"IP Virtual Server version %d.%d.%d (size=%d)\n",
|
IPVS: Allow boot time change of hash size
I was very frustrated about the fact that I have to recompile the kernel
to change the hash size. So, I created this patch.
If IPVS is built-in you can append ip_vs.conn_tab_bits=?? to kernel
command line, or, if you built IPVS as modules, you can add
options ip_vs conn_tab_bits=??.
To keep everything backward compatible, you still can select the size at
compile time, and that will be used as default.
It has been about a year since this patch was originally posted
and subsequently dropped on the basis of insufficient test data.
Mark Bergsma has provided the following test results which seem
to strongly support the need for larger hash table sizes:
We do however run into the same problem with the default setting (212 =
4096 entries), as most of our LVS balancers handle around a million
connections/SLAB entries at any point in time (around 100-150 kpps
load). With only 4096 hash table entries this implies that each entry
consists of a linked list of 256 connections *on average*.
To provide some statistics, I did an oprofile run on an 2.6.31 kernel,
with both the default 4096 table size, and the same kernel recompiled
with IP_VS_CONN_TAB_BITS set to 18 (218 = 262144 entries). I built a
quick test setup with a part of Wikimedia/Wikipedia's live traffic
mirrored by the switch to the test host.
With the default setting, at ~ 120 kpps packet load we saw a typical %si
CPU usage of around 30-35%, and oprofile reported a hot spot in
ip_vs_conn_in_get:
samples % image name app name
symbol name
1719761 42.3741 ip_vs.ko ip_vs.ko ip_vs_conn_in_get
302577 7.4554 bnx2 bnx2 /bnx2
181984 4.4840 vmlinux vmlinux __ticket_spin_lock
128636 3.1695 vmlinux vmlinux ip_route_input
74345 1.8318 ip_vs.ko ip_vs.ko ip_vs_conn_out_get
68482 1.6874 vmlinux vmlinux mwait_idle
After loading the recompiled kernel with 218 entries, %si CPU usage
dropped in half to around 12-18%, and oprofile looks much healthier,
with only 7% spent in ip_vs_conn_in_get:
samples % image name app name
symbol name
265641 14.4616 bnx2 bnx2 /bnx2
143251 7.7986 vmlinux vmlinux __ticket_spin_lock
140661 7.6576 ip_vs.ko ip_vs.ko ip_vs_conn_in_get
94364 5.1372 vmlinux vmlinux mwait_idle
86267 4.6964 vmlinux vmlinux ip_route_input
[ horms@verge.net.au: trivial up-port and minor style fixes ]
Signed-off-by: Catalin(ux) M. BOIE <catab@embedromix.ro>
Cc: Mark Bergsma <mark@wikimedia.org>
Signed-off-by: Simon Horman <horms@verge.net.au>
Signed-off-by: Patrick McHardy <kaber@trash.net>
2010-01-04 21:50:24 -07:00
|
|
|
NVERSION(IP_VS_VERSION_CODE), ip_vs_conn_tab_size);
|
2005-04-16 16:20:36 -06:00
|
|
|
seq_puts(seq,
|
|
|
|
"Prot LocalAddress:Port Scheduler Flags\n");
|
|
|
|
seq_puts(seq,
|
|
|
|
" -> RemoteAddress:Port Forward Weight ActiveConn InActConn\n");
|
|
|
|
} else {
|
|
|
|
const struct ip_vs_service *svc = v;
|
|
|
|
const struct ip_vs_iter *iter = seq->private;
|
|
|
|
const struct ip_vs_dest *dest;
|
2013-03-22 03:46:53 -06:00
|
|
|
struct ip_vs_scheduler *sched = rcu_dereference(svc->scheduler);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2008-09-02 07:55:49 -06:00
|
|
|
if (iter->table == ip_vs_svc_table) {
|
|
|
|
#ifdef CONFIG_IP_VS_IPV6
|
|
|
|
if (svc->af == AF_INET6)
|
2008-10-29 13:52:50 -06:00
|
|
|
seq_printf(seq, "%s [%pI6]:%04X %s ",
|
2008-09-02 07:55:49 -06:00
|
|
|
ip_vs_proto_name(svc->protocol),
|
2008-10-28 17:08:13 -06:00
|
|
|
&svc->addr.in6,
|
2008-09-02 07:55:49 -06:00
|
|
|
ntohs(svc->port),
|
2013-03-22 03:46:53 -06:00
|
|
|
sched->name);
|
2008-09-02 07:55:49 -06:00
|
|
|
else
|
|
|
|
#endif
|
2010-06-22 00:07:01 -06:00
|
|
|
seq_printf(seq, "%s %08X:%04X %s %s ",
|
2008-09-02 07:55:49 -06:00
|
|
|
ip_vs_proto_name(svc->protocol),
|
|
|
|
ntohl(svc->addr.ip),
|
|
|
|
ntohs(svc->port),
|
2013-03-22 03:46:53 -06:00
|
|
|
sched->name,
|
2010-06-22 00:07:01 -06:00
|
|
|
(svc->flags & IP_VS_SVC_F_ONEPACKET)?"ops ":"");
|
2008-09-02 07:55:49 -06:00
|
|
|
} else {
|
2010-06-22 00:07:01 -06:00
|
|
|
seq_printf(seq, "FWM %08X %s %s",
|
2013-03-22 03:46:53 -06:00
|
|
|
svc->fwmark, sched->name,
|
2010-06-22 00:07:01 -06:00
|
|
|
(svc->flags & IP_VS_SVC_F_ONEPACKET)?"ops ":"");
|
2008-09-02 07:55:49 -06:00
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
if (svc->flags & IP_VS_SVC_F_PERSISTENT)
|
|
|
|
seq_printf(seq, "persistent %d %08X\n",
|
|
|
|
svc->timeout,
|
|
|
|
ntohl(svc->netmask));
|
|
|
|
else
|
|
|
|
seq_putc(seq, '\n');
|
|
|
|
|
2013-03-22 03:46:52 -06:00
|
|
|
list_for_each_entry_rcu(dest, &svc->destinations, n_list) {
|
2008-09-02 07:55:49 -06:00
|
|
|
#ifdef CONFIG_IP_VS_IPV6
|
|
|
|
if (dest->af == AF_INET6)
|
|
|
|
seq_printf(seq,
|
2008-10-29 13:52:50 -06:00
|
|
|
" -> [%pI6]:%04X"
|
2008-09-02 07:55:49 -06:00
|
|
|
" %-7s %-6d %-10d %-10d\n",
|
2008-10-28 17:08:13 -06:00
|
|
|
&dest->addr.in6,
|
2008-09-02 07:55:49 -06:00
|
|
|
ntohs(dest->port),
|
|
|
|
ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
|
|
|
|
atomic_read(&dest->weight),
|
|
|
|
atomic_read(&dest->activeconns),
|
|
|
|
atomic_read(&dest->inactconns));
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
seq_printf(seq,
|
|
|
|
" -> %08X:%04X "
|
|
|
|
"%-7s %-6d %-10d %-10d\n",
|
|
|
|
ntohl(dest->addr.ip),
|
|
|
|
ntohs(dest->port),
|
|
|
|
ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
|
|
|
|
atomic_read(&dest->weight),
|
|
|
|
atomic_read(&dest->activeconns),
|
|
|
|
atomic_read(&dest->inactconns));
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-07-11 00:07:31 -06:00
|
|
|
static const struct seq_operations ip_vs_info_seq_ops = {
|
2005-04-16 16:20:36 -06:00
|
|
|
.start = ip_vs_info_seq_start,
|
|
|
|
.next = ip_vs_info_seq_next,
|
|
|
|
.stop = ip_vs_info_seq_stop,
|
|
|
|
.show = ip_vs_info_seq_show,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int ip_vs_info_open(struct inode *inode, struct file *file)
|
|
|
|
{
|
2011-01-03 06:44:43 -07:00
|
|
|
return seq_open_net(inode, file, &ip_vs_info_seq_ops,
|
2007-10-10 03:29:29 -06:00
|
|
|
sizeof(struct ip_vs_iter));
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2007-02-12 01:55:35 -07:00
|
|
|
static const struct file_operations ip_vs_info_fops = {
|
2005-04-16 16:20:36 -06:00
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.open = ip_vs_info_open,
|
|
|
|
.read = seq_read,
|
|
|
|
.llseek = seq_lseek,
|
2011-05-15 09:20:29 -06:00
|
|
|
.release = seq_release_net,
|
2005-04-16 16:20:36 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
static int ip_vs_stats_show(struct seq_file *seq, void *v)
|
|
|
|
{
|
2011-01-03 06:44:56 -07:00
|
|
|
struct net *net = seq_file_single_net(seq);
|
2011-03-13 17:37:49 -06:00
|
|
|
struct ip_vs_stats_user show;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
/* 01234567 01234567 01234567 0123456701234567 0123456701234567 */
|
|
|
|
seq_puts(seq,
|
|
|
|
" Total Incoming Outgoing Incoming Outgoing\n");
|
|
|
|
seq_printf(seq,
|
|
|
|
" Conns Packets Packets Bytes Bytes\n");
|
|
|
|
|
2011-03-13 17:37:49 -06:00
|
|
|
ip_vs_copy_stats(&show, &net_ipvs(net)->tot_stats);
|
|
|
|
seq_printf(seq, "%8X %8X %8X %16LX %16LX\n\n", show.conns,
|
|
|
|
show.inpkts, show.outpkts,
|
|
|
|
(unsigned long long) show.inbytes,
|
|
|
|
(unsigned long long) show.outbytes);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
/* 01234567 01234567 01234567 0123456701234567 0123456701234567 */
|
|
|
|
seq_puts(seq,
|
|
|
|
" Conns/s Pkts/s Pkts/s Bytes/s Bytes/s\n");
|
2011-03-13 17:37:49 -06:00
|
|
|
seq_printf(seq, "%8X %8X %8X %16X %16X\n",
|
|
|
|
show.cps, show.inpps, show.outpps,
|
|
|
|
show.inbps, show.outbps);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ip_vs_stats_seq_open(struct inode *inode, struct file *file)
|
|
|
|
{
|
2011-01-03 06:44:43 -07:00
|
|
|
return single_open_net(inode, file, ip_vs_stats_show);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2007-02-12 01:55:35 -07:00
|
|
|
static const struct file_operations ip_vs_stats_fops = {
|
2005-04-16 16:20:36 -06:00
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.open = ip_vs_stats_seq_open,
|
|
|
|
.read = seq_read,
|
|
|
|
.llseek = seq_lseek,
|
2011-05-15 09:20:29 -06:00
|
|
|
.release = single_release_net,
|
2005-04-16 16:20:36 -06:00
|
|
|
};
|
|
|
|
|
2011-01-03 06:44:56 -07:00
|
|
|
static int ip_vs_stats_percpu_show(struct seq_file *seq, void *v)
|
|
|
|
{
|
|
|
|
struct net *net = seq_file_single_net(seq);
|
2011-03-04 03:20:35 -07:00
|
|
|
struct ip_vs_stats *tot_stats = &net_ipvs(net)->tot_stats;
|
2013-04-17 14:50:50 -06:00
|
|
|
struct ip_vs_cpu_stats __percpu *cpustats = tot_stats->cpustats;
|
2011-03-13 17:41:54 -06:00
|
|
|
struct ip_vs_stats_user rates;
|
2011-01-03 06:44:56 -07:00
|
|
|
int i;
|
|
|
|
|
|
|
|
/* 01234567 01234567 01234567 0123456701234567 0123456701234567 */
|
|
|
|
seq_puts(seq,
|
|
|
|
" Total Incoming Outgoing Incoming Outgoing\n");
|
|
|
|
seq_printf(seq,
|
|
|
|
"CPU Conns Packets Packets Bytes Bytes\n");
|
|
|
|
|
|
|
|
for_each_possible_cpu(i) {
|
2011-03-04 03:20:35 -07:00
|
|
|
struct ip_vs_cpu_stats *u = per_cpu_ptr(cpustats, i);
|
|
|
|
unsigned int start;
|
|
|
|
__u64 inbytes, outbytes;
|
|
|
|
|
|
|
|
do {
|
2014-03-13 22:26:42 -06:00
|
|
|
start = u64_stats_fetch_begin_irq(&u->syncp);
|
2011-03-04 03:20:35 -07:00
|
|
|
inbytes = u->ustats.inbytes;
|
|
|
|
outbytes = u->ustats.outbytes;
|
2014-03-13 22:26:42 -06:00
|
|
|
} while (u64_stats_fetch_retry_irq(&u->syncp, start));
|
2011-03-04 03:20:35 -07:00
|
|
|
|
2011-01-03 06:44:56 -07:00
|
|
|
seq_printf(seq, "%3X %8X %8X %8X %16LX %16LX\n",
|
2011-03-04 03:20:35 -07:00
|
|
|
i, u->ustats.conns, u->ustats.inpkts,
|
|
|
|
u->ustats.outpkts, (__u64)inbytes,
|
|
|
|
(__u64)outbytes);
|
2011-01-03 06:44:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
spin_lock_bh(&tot_stats->lock);
|
2011-03-13 17:41:54 -06:00
|
|
|
|
2011-01-03 06:44:56 -07:00
|
|
|
seq_printf(seq, " ~ %8X %8X %8X %16LX %16LX\n\n",
|
|
|
|
tot_stats->ustats.conns, tot_stats->ustats.inpkts,
|
|
|
|
tot_stats->ustats.outpkts,
|
|
|
|
(unsigned long long) tot_stats->ustats.inbytes,
|
|
|
|
(unsigned long long) tot_stats->ustats.outbytes);
|
|
|
|
|
2011-03-13 17:41:54 -06:00
|
|
|
ip_vs_read_estimator(&rates, tot_stats);
|
|
|
|
|
|
|
|
spin_unlock_bh(&tot_stats->lock);
|
|
|
|
|
2011-01-03 06:44:56 -07:00
|
|
|
/* 01234567 01234567 01234567 0123456701234567 0123456701234567 */
|
|
|
|
seq_puts(seq,
|
|
|
|
" Conns/s Pkts/s Pkts/s Bytes/s Bytes/s\n");
|
|
|
|
seq_printf(seq, " %8X %8X %8X %16X %16X\n",
|
2011-03-13 17:41:54 -06:00
|
|
|
rates.cps,
|
|
|
|
rates.inpps,
|
|
|
|
rates.outpps,
|
|
|
|
rates.inbps,
|
|
|
|
rates.outbps);
|
2011-01-03 06:44:56 -07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ip_vs_stats_percpu_seq_open(struct inode *inode, struct file *file)
|
|
|
|
{
|
|
|
|
return single_open_net(inode, file, ip_vs_stats_percpu_show);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct file_operations ip_vs_stats_percpu_fops = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.open = ip_vs_stats_percpu_seq_open,
|
|
|
|
.read = seq_read,
|
|
|
|
.llseek = seq_lseek,
|
2011-05-15 09:20:29 -06:00
|
|
|
.release = single_release_net,
|
2011-01-03 06:44:56 -07:00
|
|
|
};
|
2005-04-16 16:20:36 -06:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set timeout values for tcp tcpfin udp in the timeout_table.
|
|
|
|
*/
|
2011-01-03 06:44:51 -07:00
|
|
|
static int ip_vs_set_timeout(struct net *net, struct ip_vs_timeout_user *u)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2011-01-21 03:02:13 -07:00
|
|
|
#if defined(CONFIG_IP_VS_PROTO_TCP) || defined(CONFIG_IP_VS_PROTO_UDP)
|
2011-01-03 06:44:51 -07:00
|
|
|
struct ip_vs_proto_data *pd;
|
2011-01-21 03:02:13 -07:00
|
|
|
#endif
|
2011-01-03 06:44:51 -07:00
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
IP_VS_DBG(2, "Setting timeout tcp:%d tcpfin:%d udp:%d\n",
|
|
|
|
u->tcp_timeout,
|
|
|
|
u->tcp_fin_timeout,
|
|
|
|
u->udp_timeout);
|
|
|
|
|
|
|
|
#ifdef CONFIG_IP_VS_PROTO_TCP
|
|
|
|
if (u->tcp_timeout) {
|
2011-01-03 06:44:51 -07:00
|
|
|
pd = ip_vs_proto_data_get(net, IPPROTO_TCP);
|
|
|
|
pd->timeout_table[IP_VS_TCP_S_ESTABLISHED]
|
2005-04-16 16:20:36 -06:00
|
|
|
= u->tcp_timeout * HZ;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (u->tcp_fin_timeout) {
|
2011-01-03 06:44:51 -07:00
|
|
|
pd = ip_vs_proto_data_get(net, IPPROTO_TCP);
|
|
|
|
pd->timeout_table[IP_VS_TCP_S_FIN_WAIT]
|
2005-04-16 16:20:36 -06:00
|
|
|
= u->tcp_fin_timeout * HZ;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_IP_VS_PROTO_UDP
|
|
|
|
if (u->udp_timeout) {
|
2011-01-03 06:44:51 -07:00
|
|
|
pd = ip_vs_proto_data_get(net, IPPROTO_UDP);
|
|
|
|
pd->timeout_table[IP_VS_UDP_S_NORMAL]
|
2005-04-16 16:20:36 -06:00
|
|
|
= u->udp_timeout * HZ;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-09-02 15:02:49 -06:00
|
|
|
#define CMDID(cmd) (cmd - IP_VS_BASE_CTL)
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2014-09-02 15:02:49 -06:00
|
|
|
struct ip_vs_svcdest_user {
|
|
|
|
struct ip_vs_service_user s;
|
|
|
|
struct ip_vs_dest_user d;
|
2005-04-16 16:20:36 -06:00
|
|
|
};
|
|
|
|
|
2014-09-02 15:02:49 -06:00
|
|
|
static const unsigned char set_arglen[CMDID(IP_VS_SO_SET_MAX) + 1] = {
|
|
|
|
[CMDID(IP_VS_SO_SET_ADD)] = sizeof(struct ip_vs_service_user),
|
|
|
|
[CMDID(IP_VS_SO_SET_EDIT)] = sizeof(struct ip_vs_service_user),
|
|
|
|
[CMDID(IP_VS_SO_SET_DEL)] = sizeof(struct ip_vs_service_user),
|
|
|
|
[CMDID(IP_VS_SO_SET_ADDDEST)] = sizeof(struct ip_vs_svcdest_user),
|
|
|
|
[CMDID(IP_VS_SO_SET_DELDEST)] = sizeof(struct ip_vs_svcdest_user),
|
|
|
|
[CMDID(IP_VS_SO_SET_EDITDEST)] = sizeof(struct ip_vs_svcdest_user),
|
|
|
|
[CMDID(IP_VS_SO_SET_TIMEOUT)] = sizeof(struct ip_vs_timeout_user),
|
|
|
|
[CMDID(IP_VS_SO_SET_STARTDAEMON)] = sizeof(struct ip_vs_daemon_user),
|
|
|
|
[CMDID(IP_VS_SO_SET_STOPDAEMON)] = sizeof(struct ip_vs_daemon_user),
|
|
|
|
[CMDID(IP_VS_SO_SET_ZERO)] = sizeof(struct ip_vs_service_user),
|
|
|
|
};
|
|
|
|
|
|
|
|
union ip_vs_set_arglen {
|
|
|
|
struct ip_vs_service_user field_IP_VS_SO_SET_ADD;
|
|
|
|
struct ip_vs_service_user field_IP_VS_SO_SET_EDIT;
|
|
|
|
struct ip_vs_service_user field_IP_VS_SO_SET_DEL;
|
|
|
|
struct ip_vs_svcdest_user field_IP_VS_SO_SET_ADDDEST;
|
|
|
|
struct ip_vs_svcdest_user field_IP_VS_SO_SET_DELDEST;
|
|
|
|
struct ip_vs_svcdest_user field_IP_VS_SO_SET_EDITDEST;
|
|
|
|
struct ip_vs_timeout_user field_IP_VS_SO_SET_TIMEOUT;
|
|
|
|
struct ip_vs_daemon_user field_IP_VS_SO_SET_STARTDAEMON;
|
|
|
|
struct ip_vs_daemon_user field_IP_VS_SO_SET_STOPDAEMON;
|
|
|
|
struct ip_vs_service_user field_IP_VS_SO_SET_ZERO;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define MAX_SET_ARGLEN sizeof(union ip_vs_set_arglen)
|
|
|
|
|
2008-09-02 07:55:36 -06:00
|
|
|
static void ip_vs_copy_usvc_compat(struct ip_vs_service_user_kern *usvc,
|
|
|
|
struct ip_vs_service_user *usvc_compat)
|
|
|
|
{
|
2010-08-22 06:37:54 -06:00
|
|
|
memset(usvc, 0, sizeof(*usvc));
|
|
|
|
|
2008-09-02 07:55:36 -06:00
|
|
|
usvc->af = AF_INET;
|
|
|
|
usvc->protocol = usvc_compat->protocol;
|
|
|
|
usvc->addr.ip = usvc_compat->addr;
|
|
|
|
usvc->port = usvc_compat->port;
|
|
|
|
usvc->fwmark = usvc_compat->fwmark;
|
|
|
|
|
|
|
|
/* Deep copy of sched_name is not needed here */
|
|
|
|
usvc->sched_name = usvc_compat->sched_name;
|
|
|
|
|
|
|
|
usvc->flags = usvc_compat->flags;
|
|
|
|
usvc->timeout = usvc_compat->timeout;
|
|
|
|
usvc->netmask = usvc_compat->netmask;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ip_vs_copy_udest_compat(struct ip_vs_dest_user_kern *udest,
|
|
|
|
struct ip_vs_dest_user *udest_compat)
|
|
|
|
{
|
2010-08-22 06:37:54 -06:00
|
|
|
memset(udest, 0, sizeof(*udest));
|
|
|
|
|
2008-09-02 07:55:36 -06:00
|
|
|
udest->addr.ip = udest_compat->addr;
|
|
|
|
udest->port = udest_compat->port;
|
|
|
|
udest->conn_flags = udest_compat->conn_flags;
|
|
|
|
udest->weight = udest_compat->weight;
|
|
|
|
udest->u_threshold = udest_compat->u_threshold;
|
|
|
|
udest->l_threshold = udest_compat->l_threshold;
|
2014-09-09 17:40:20 -06:00
|
|
|
udest->af = AF_INET;
|
2008-09-02 07:55:36 -06:00
|
|
|
}
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
static int
|
|
|
|
do_ip_vs_set_ctl(struct sock *sk, int cmd, void __user *user, unsigned int len)
|
|
|
|
{
|
2011-01-03 06:44:43 -07:00
|
|
|
struct net *net = sock_net(sk);
|
2005-04-16 16:20:36 -06:00
|
|
|
int ret;
|
2014-09-02 15:02:49 -06:00
|
|
|
unsigned char arg[MAX_SET_ARGLEN];
|
2008-09-02 07:55:36 -06:00
|
|
|
struct ip_vs_service_user *usvc_compat;
|
|
|
|
struct ip_vs_service_user_kern usvc;
|
2005-04-16 16:20:36 -06:00
|
|
|
struct ip_vs_service *svc;
|
2008-09-02 07:55:36 -06:00
|
|
|
struct ip_vs_dest_user *udest_compat;
|
|
|
|
struct ip_vs_dest_user_kern udest;
|
2011-10-10 19:54:35 -06:00
|
|
|
struct netns_ipvs *ipvs = net_ipvs(net);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2014-09-02 15:02:49 -06:00
|
|
|
BUILD_BUG_ON(sizeof(arg) > 255);
|
2012-11-15 20:03:07 -07:00
|
|
|
if (!ns_capable(sock_net(sk)->user_ns, CAP_NET_ADMIN))
|
2005-04-16 16:20:36 -06:00
|
|
|
return -EPERM;
|
|
|
|
|
2010-01-04 08:37:12 -07:00
|
|
|
if (cmd < IP_VS_BASE_CTL || cmd > IP_VS_SO_SET_MAX)
|
|
|
|
return -EINVAL;
|
2014-09-02 15:02:49 -06:00
|
|
|
if (len != set_arglen[CMDID(cmd)]) {
|
|
|
|
IP_VS_DBG(1, "set_ctl: len %u != %u\n",
|
|
|
|
len, set_arglen[CMDID(cmd)]);
|
2005-04-16 16:20:36 -06:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (copy_from_user(arg, user, len) != 0)
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
/* increase the module use count */
|
|
|
|
ip_vs_use_count_inc();
|
|
|
|
|
2011-10-10 19:54:35 -06:00
|
|
|
/* Handle daemons since they have another lock */
|
|
|
|
if (cmd == IP_VS_SO_SET_STARTDAEMON ||
|
|
|
|
cmd == IP_VS_SO_SET_STOPDAEMON) {
|
|
|
|
struct ip_vs_daemon_user *dm = (struct ip_vs_daemon_user *)arg;
|
|
|
|
|
2014-07-31 12:38:46 -06:00
|
|
|
mutex_lock(&ipvs->sync_mutex);
|
2011-10-10 19:54:35 -06:00
|
|
|
if (cmd == IP_VS_SO_SET_STARTDAEMON)
|
|
|
|
ret = start_sync_thread(net, dm->state, dm->mcast_ifn,
|
|
|
|
dm->syncid);
|
|
|
|
else
|
|
|
|
ret = stop_sync_thread(net, dm->state);
|
|
|
|
mutex_unlock(&ipvs->sync_mutex);
|
|
|
|
goto out_dec;
|
|
|
|
}
|
|
|
|
|
2014-07-31 12:38:46 -06:00
|
|
|
mutex_lock(&__ip_vs_mutex);
|
2005-04-16 16:20:36 -06:00
|
|
|
if (cmd == IP_VS_SO_SET_FLUSH) {
|
|
|
|
/* Flush the virtual service */
|
2013-03-22 03:46:49 -06:00
|
|
|
ret = ip_vs_flush(net, false);
|
2005-04-16 16:20:36 -06:00
|
|
|
goto out_unlock;
|
|
|
|
} else if (cmd == IP_VS_SO_SET_TIMEOUT) {
|
|
|
|
/* Set timeout values for (tcp tcpfin udp) */
|
2011-01-03 06:44:51 -07:00
|
|
|
ret = ip_vs_set_timeout(net, (struct ip_vs_timeout_user *)arg);
|
2005-04-16 16:20:36 -06:00
|
|
|
goto out_unlock;
|
|
|
|
}
|
|
|
|
|
2008-09-02 07:55:36 -06:00
|
|
|
usvc_compat = (struct ip_vs_service_user *)arg;
|
|
|
|
udest_compat = (struct ip_vs_dest_user *)(usvc_compat + 1);
|
|
|
|
|
|
|
|
/* We only use the new structs internally, so copy userspace compat
|
|
|
|
* structs to extended internal versions */
|
|
|
|
ip_vs_copy_usvc_compat(&usvc, usvc_compat);
|
|
|
|
ip_vs_copy_udest_compat(&udest, udest_compat);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
if (cmd == IP_VS_SO_SET_ZERO) {
|
|
|
|
/* if no service address is set, zero counters in all */
|
2008-09-02 07:55:36 -06:00
|
|
|
if (!usvc.fwmark && !usvc.addr.ip && !usvc.port) {
|
2011-01-03 06:44:43 -07:00
|
|
|
ret = ip_vs_zero_all(net);
|
2005-04-16 16:20:36 -06:00
|
|
|
goto out_unlock;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-18 04:31:05 -07:00
|
|
|
/* Check for valid protocol: TCP or UDP or SCTP, even for fwmark!=0 */
|
|
|
|
if (usvc.protocol != IPPROTO_TCP && usvc.protocol != IPPROTO_UDP &&
|
|
|
|
usvc.protocol != IPPROTO_SCTP) {
|
2009-08-02 05:05:41 -06:00
|
|
|
pr_err("set_ctl: invalid protocol: %d %pI4:%d %s\n",
|
|
|
|
usvc.protocol, &usvc.addr.ip,
|
|
|
|
ntohs(usvc.port), usvc.sched_name);
|
2005-04-16 16:20:36 -06:00
|
|
|
ret = -EFAULT;
|
|
|
|
goto out_unlock;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Lookup the exact service by <protocol, addr, port> or fwmark */
|
2013-03-22 03:46:53 -06:00
|
|
|
rcu_read_lock();
|
2008-09-02 07:55:36 -06:00
|
|
|
if (usvc.fwmark == 0)
|
2011-01-03 06:44:43 -07:00
|
|
|
svc = __ip_vs_service_find(net, usvc.af, usvc.protocol,
|
2010-09-21 10:12:30 -06:00
|
|
|
&usvc.addr, usvc.port);
|
2005-04-16 16:20:36 -06:00
|
|
|
else
|
2011-01-03 06:44:43 -07:00
|
|
|
svc = __ip_vs_svc_fwm_find(net, usvc.af, usvc.fwmark);
|
2013-03-22 03:46:53 -06:00
|
|
|
rcu_read_unlock();
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
if (cmd != IP_VS_SO_SET_ADD
|
2008-09-02 07:55:36 -06:00
|
|
|
&& (svc == NULL || svc->protocol != usvc.protocol)) {
|
2005-04-16 16:20:36 -06:00
|
|
|
ret = -ESRCH;
|
2010-09-21 10:12:30 -06:00
|
|
|
goto out_unlock;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case IP_VS_SO_SET_ADD:
|
|
|
|
if (svc != NULL)
|
|
|
|
ret = -EEXIST;
|
|
|
|
else
|
2011-01-03 06:44:43 -07:00
|
|
|
ret = ip_vs_add_service(net, &usvc, &svc);
|
2005-04-16 16:20:36 -06:00
|
|
|
break;
|
|
|
|
case IP_VS_SO_SET_EDIT:
|
2008-09-02 07:55:36 -06:00
|
|
|
ret = ip_vs_edit_service(svc, &usvc);
|
2005-04-16 16:20:36 -06:00
|
|
|
break;
|
|
|
|
case IP_VS_SO_SET_DEL:
|
|
|
|
ret = ip_vs_del_service(svc);
|
|
|
|
if (!ret)
|
|
|
|
goto out_unlock;
|
|
|
|
break;
|
|
|
|
case IP_VS_SO_SET_ZERO:
|
|
|
|
ret = ip_vs_zero_service(svc);
|
|
|
|
break;
|
|
|
|
case IP_VS_SO_SET_ADDDEST:
|
2008-09-02 07:55:36 -06:00
|
|
|
ret = ip_vs_add_dest(svc, &udest);
|
2005-04-16 16:20:36 -06:00
|
|
|
break;
|
|
|
|
case IP_VS_SO_SET_EDITDEST:
|
2008-09-02 07:55:36 -06:00
|
|
|
ret = ip_vs_edit_dest(svc, &udest);
|
2005-04-16 16:20:36 -06:00
|
|
|
break;
|
|
|
|
case IP_VS_SO_SET_DELDEST:
|
2008-09-02 07:55:36 -06:00
|
|
|
ret = ip_vs_del_dest(svc, &udest);
|
2005-04-16 16:20:36 -06:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ret = -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
out_unlock:
|
2006-03-26 02:37:14 -07:00
|
|
|
mutex_unlock(&__ip_vs_mutex);
|
2005-04-16 16:20:36 -06:00
|
|
|
out_dec:
|
|
|
|
/* decrease the module use count */
|
|
|
|
ip_vs_use_count_dec();
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
ip_vs_copy_service(struct ip_vs_service_entry *dst, struct ip_vs_service *src)
|
|
|
|
{
|
2013-03-22 03:46:53 -06:00
|
|
|
struct ip_vs_scheduler *sched;
|
|
|
|
|
|
|
|
sched = rcu_dereference_protected(src->scheduler, 1);
|
2005-04-16 16:20:36 -06:00
|
|
|
dst->protocol = src->protocol;
|
2008-09-02 07:55:33 -06:00
|
|
|
dst->addr = src->addr.ip;
|
2005-04-16 16:20:36 -06:00
|
|
|
dst->port = src->port;
|
|
|
|
dst->fwmark = src->fwmark;
|
2013-03-22 03:46:53 -06:00
|
|
|
strlcpy(dst->sched_name, sched->name, sizeof(dst->sched_name));
|
2005-04-16 16:20:36 -06:00
|
|
|
dst->flags = src->flags;
|
|
|
|
dst->timeout = src->timeout / HZ;
|
|
|
|
dst->netmask = src->netmask;
|
|
|
|
dst->num_dests = src->num_dests;
|
|
|
|
ip_vs_copy_stats(&dst->stats, &src->stats);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
2011-01-03 06:44:43 -07:00
|
|
|
__ip_vs_get_service_entries(struct net *net,
|
|
|
|
const struct ip_vs_get_services *get,
|
2005-04-16 16:20:36 -06:00
|
|
|
struct ip_vs_get_services __user *uptr)
|
|
|
|
{
|
|
|
|
int idx, count=0;
|
|
|
|
struct ip_vs_service *svc;
|
|
|
|
struct ip_vs_service_entry entry;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
for (idx = 0; idx < IP_VS_SVC_TAB_SIZE; idx++) {
|
2013-03-22 03:46:53 -06:00
|
|
|
hlist_for_each_entry(svc, &ip_vs_svc_table[idx], s_list) {
|
2008-09-02 07:55:55 -06:00
|
|
|
/* Only expose IPv4 entries to old interface */
|
2011-01-03 06:44:43 -07:00
|
|
|
if (svc->af != AF_INET || !net_eq(svc->net, net))
|
2008-09-02 07:55:55 -06:00
|
|
|
continue;
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
if (count >= get->num_services)
|
|
|
|
goto out;
|
2005-06-26 17:00:19 -06:00
|
|
|
memset(&entry, 0, sizeof(entry));
|
2005-04-16 16:20:36 -06:00
|
|
|
ip_vs_copy_service(&entry, svc);
|
|
|
|
if (copy_to_user(&uptr->entrytable[count],
|
|
|
|
&entry, sizeof(entry))) {
|
|
|
|
ret = -EFAULT;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (idx = 0; idx < IP_VS_SVC_TAB_SIZE; idx++) {
|
2013-03-22 03:46:53 -06:00
|
|
|
hlist_for_each_entry(svc, &ip_vs_svc_fwm_table[idx], f_list) {
|
2008-09-02 07:55:55 -06:00
|
|
|
/* Only expose IPv4 entries to old interface */
|
2011-01-03 06:44:43 -07:00
|
|
|
if (svc->af != AF_INET || !net_eq(svc->net, net))
|
2008-09-02 07:55:55 -06:00
|
|
|
continue;
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
if (count >= get->num_services)
|
|
|
|
goto out;
|
2005-06-26 17:00:19 -06:00
|
|
|
memset(&entry, 0, sizeof(entry));
|
2005-04-16 16:20:36 -06:00
|
|
|
ip_vs_copy_service(&entry, svc);
|
|
|
|
if (copy_to_user(&uptr->entrytable[count],
|
|
|
|
&entry, sizeof(entry))) {
|
|
|
|
ret = -EFAULT;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
2011-06-13 04:19:26 -06:00
|
|
|
out:
|
2005-04-16 16:20:36 -06:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
2011-01-03 06:44:43 -07:00
|
|
|
__ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
|
2005-04-16 16:20:36 -06:00
|
|
|
struct ip_vs_get_dests __user *uptr)
|
|
|
|
{
|
|
|
|
struct ip_vs_service *svc;
|
2008-09-02 07:55:37 -06:00
|
|
|
union nf_inet_addr addr = { .ip = get->addr };
|
2005-04-16 16:20:36 -06:00
|
|
|
int ret = 0;
|
|
|
|
|
2013-03-22 03:46:53 -06:00
|
|
|
rcu_read_lock();
|
2005-04-16 16:20:36 -06:00
|
|
|
if (get->fwmark)
|
2011-01-03 06:44:43 -07:00
|
|
|
svc = __ip_vs_svc_fwm_find(net, AF_INET, get->fwmark);
|
2005-04-16 16:20:36 -06:00
|
|
|
else
|
2011-01-03 06:44:43 -07:00
|
|
|
svc = __ip_vs_service_find(net, AF_INET, get->protocol, &addr,
|
2010-09-21 10:12:30 -06:00
|
|
|
get->port);
|
2013-03-22 03:46:53 -06:00
|
|
|
rcu_read_unlock();
|
2008-09-02 07:55:37 -06:00
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
if (svc) {
|
|
|
|
int count = 0;
|
|
|
|
struct ip_vs_dest *dest;
|
|
|
|
struct ip_vs_dest_entry entry;
|
|
|
|
|
2013-06-03 03:00:49 -06:00
|
|
|
memset(&entry, 0, sizeof(entry));
|
2005-04-16 16:20:36 -06:00
|
|
|
list_for_each_entry(dest, &svc->destinations, n_list) {
|
|
|
|
if (count >= get->num_dests)
|
|
|
|
break;
|
|
|
|
|
2014-09-09 17:40:20 -06:00
|
|
|
/* Cannot expose heterogeneous members via sockopt
|
|
|
|
* interface
|
|
|
|
*/
|
|
|
|
if (dest->af != svc->af)
|
|
|
|
continue;
|
|
|
|
|
2008-09-02 07:55:33 -06:00
|
|
|
entry.addr = dest->addr.ip;
|
2005-04-16 16:20:36 -06:00
|
|
|
entry.port = dest->port;
|
|
|
|
entry.conn_flags = atomic_read(&dest->conn_flags);
|
|
|
|
entry.weight = atomic_read(&dest->weight);
|
|
|
|
entry.u_threshold = dest->u_threshold;
|
|
|
|
entry.l_threshold = dest->l_threshold;
|
|
|
|
entry.activeconns = atomic_read(&dest->activeconns);
|
|
|
|
entry.inactconns = atomic_read(&dest->inactconns);
|
|
|
|
entry.persistconns = atomic_read(&dest->persistconns);
|
|
|
|
ip_vs_copy_stats(&entry.stats, &dest->stats);
|
|
|
|
if (copy_to_user(&uptr->entrytable[count],
|
|
|
|
&entry, sizeof(entry))) {
|
|
|
|
ret = -EFAULT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
ret = -ESRCH;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
2011-01-03 06:44:51 -07:00
|
|
|
__ip_vs_get_timeouts(struct net *net, struct ip_vs_timeout_user *u)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2011-01-21 03:02:13 -07:00
|
|
|
#if defined(CONFIG_IP_VS_PROTO_TCP) || defined(CONFIG_IP_VS_PROTO_UDP)
|
2011-01-03 06:44:51 -07:00
|
|
|
struct ip_vs_proto_data *pd;
|
2011-01-21 03:02:13 -07:00
|
|
|
#endif
|
2011-01-03 06:44:51 -07:00
|
|
|
|
2012-10-08 22:04:34 -06:00
|
|
|
memset(u, 0, sizeof (*u));
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
#ifdef CONFIG_IP_VS_PROTO_TCP
|
2011-01-03 06:44:51 -07:00
|
|
|
pd = ip_vs_proto_data_get(net, IPPROTO_TCP);
|
|
|
|
u->tcp_timeout = pd->timeout_table[IP_VS_TCP_S_ESTABLISHED] / HZ;
|
|
|
|
u->tcp_fin_timeout = pd->timeout_table[IP_VS_TCP_S_FIN_WAIT] / HZ;
|
2005-04-16 16:20:36 -06:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_IP_VS_PROTO_UDP
|
2011-01-03 06:44:51 -07:00
|
|
|
pd = ip_vs_proto_data_get(net, IPPROTO_UDP);
|
2005-04-16 16:20:36 -06:00
|
|
|
u->udp_timeout =
|
2011-01-03 06:44:51 -07:00
|
|
|
pd->timeout_table[IP_VS_UDP_S_NORMAL] / HZ;
|
2005-04-16 16:20:36 -06:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-09-02 15:02:49 -06:00
|
|
|
static const unsigned char get_arglen[CMDID(IP_VS_SO_GET_MAX) + 1] = {
|
|
|
|
[CMDID(IP_VS_SO_GET_VERSION)] = 64,
|
|
|
|
[CMDID(IP_VS_SO_GET_INFO)] = sizeof(struct ip_vs_getinfo),
|
|
|
|
[CMDID(IP_VS_SO_GET_SERVICES)] = sizeof(struct ip_vs_get_services),
|
|
|
|
[CMDID(IP_VS_SO_GET_SERVICE)] = sizeof(struct ip_vs_service_entry),
|
|
|
|
[CMDID(IP_VS_SO_GET_DESTS)] = sizeof(struct ip_vs_get_dests),
|
|
|
|
[CMDID(IP_VS_SO_GET_TIMEOUT)] = sizeof(struct ip_vs_timeout_user),
|
|
|
|
[CMDID(IP_VS_SO_GET_DAEMON)] = 2 * sizeof(struct ip_vs_daemon_user),
|
|
|
|
};
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2014-09-02 15:02:49 -06:00
|
|
|
union ip_vs_get_arglen {
|
|
|
|
char field_IP_VS_SO_GET_VERSION[64];
|
|
|
|
struct ip_vs_getinfo field_IP_VS_SO_GET_INFO;
|
|
|
|
struct ip_vs_get_services field_IP_VS_SO_GET_SERVICES;
|
|
|
|
struct ip_vs_service_entry field_IP_VS_SO_GET_SERVICE;
|
|
|
|
struct ip_vs_get_dests field_IP_VS_SO_GET_DESTS;
|
|
|
|
struct ip_vs_timeout_user field_IP_VS_SO_GET_TIMEOUT;
|
|
|
|
struct ip_vs_daemon_user field_IP_VS_SO_GET_DAEMON[2];
|
2005-04-16 16:20:36 -06:00
|
|
|
};
|
|
|
|
|
2014-09-02 15:02:49 -06:00
|
|
|
#define MAX_GET_ARGLEN sizeof(union ip_vs_get_arglen)
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
static int
|
|
|
|
do_ip_vs_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
|
|
|
|
{
|
2014-09-02 15:02:49 -06:00
|
|
|
unsigned char arg[MAX_GET_ARGLEN];
|
2005-04-16 16:20:36 -06:00
|
|
|
int ret = 0;
|
2010-01-04 08:37:12 -07:00
|
|
|
unsigned int copylen;
|
2011-01-03 06:44:43 -07:00
|
|
|
struct net *net = sock_net(sk);
|
2011-01-03 06:44:55 -07:00
|
|
|
struct netns_ipvs *ipvs = net_ipvs(net);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2011-01-03 06:44:43 -07:00
|
|
|
BUG_ON(!net);
|
2014-09-02 15:02:49 -06:00
|
|
|
BUILD_BUG_ON(sizeof(arg) > 255);
|
2012-11-15 20:03:07 -07:00
|
|
|
if (!ns_capable(sock_net(sk)->user_ns, CAP_NET_ADMIN))
|
2005-04-16 16:20:36 -06:00
|
|
|
return -EPERM;
|
|
|
|
|
2010-01-04 08:37:12 -07:00
|
|
|
if (cmd < IP_VS_BASE_CTL || cmd > IP_VS_SO_GET_MAX)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2014-09-02 15:02:49 -06:00
|
|
|
copylen = get_arglen[CMDID(cmd)];
|
|
|
|
if (*len < (int) copylen) {
|
|
|
|
IP_VS_DBG(1, "get_ctl: len %d < %u\n", *len, copylen);
|
2005-04-16 16:20:36 -06:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2010-01-04 08:37:12 -07:00
|
|
|
if (copy_from_user(arg, user, copylen) != 0)
|
2005-04-16 16:20:36 -06:00
|
|
|
return -EFAULT;
|
2011-10-10 19:54:35 -06:00
|
|
|
/*
|
|
|
|
* Handle daemons first since it has its own locking
|
|
|
|
*/
|
|
|
|
if (cmd == IP_VS_SO_GET_DAEMON) {
|
|
|
|
struct ip_vs_daemon_user d[2];
|
|
|
|
|
|
|
|
memset(&d, 0, sizeof(d));
|
2014-07-31 12:38:46 -06:00
|
|
|
mutex_lock(&ipvs->sync_mutex);
|
2011-10-10 19:54:35 -06:00
|
|
|
if (ipvs->sync_state & IP_VS_STATE_MASTER) {
|
|
|
|
d[0].state = IP_VS_STATE_MASTER;
|
|
|
|
strlcpy(d[0].mcast_ifn, ipvs->master_mcast_ifn,
|
|
|
|
sizeof(d[0].mcast_ifn));
|
|
|
|
d[0].syncid = ipvs->master_syncid;
|
|
|
|
}
|
|
|
|
if (ipvs->sync_state & IP_VS_STATE_BACKUP) {
|
|
|
|
d[1].state = IP_VS_STATE_BACKUP;
|
|
|
|
strlcpy(d[1].mcast_ifn, ipvs->backup_mcast_ifn,
|
|
|
|
sizeof(d[1].mcast_ifn));
|
|
|
|
d[1].syncid = ipvs->backup_syncid;
|
|
|
|
}
|
|
|
|
if (copy_to_user(user, &d, sizeof(d)) != 0)
|
|
|
|
ret = -EFAULT;
|
|
|
|
mutex_unlock(&ipvs->sync_mutex);
|
|
|
|
return ret;
|
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2014-07-31 12:38:46 -06:00
|
|
|
mutex_lock(&__ip_vs_mutex);
|
2005-04-16 16:20:36 -06:00
|
|
|
switch (cmd) {
|
|
|
|
case IP_VS_SO_GET_VERSION:
|
|
|
|
{
|
|
|
|
char buf[64];
|
|
|
|
|
|
|
|
sprintf(buf, "IP Virtual Server version %d.%d.%d (size=%d)",
|
IPVS: Allow boot time change of hash size
I was very frustrated about the fact that I have to recompile the kernel
to change the hash size. So, I created this patch.
If IPVS is built-in you can append ip_vs.conn_tab_bits=?? to kernel
command line, or, if you built IPVS as modules, you can add
options ip_vs conn_tab_bits=??.
To keep everything backward compatible, you still can select the size at
compile time, and that will be used as default.
It has been about a year since this patch was originally posted
and subsequently dropped on the basis of insufficient test data.
Mark Bergsma has provided the following test results which seem
to strongly support the need for larger hash table sizes:
We do however run into the same problem with the default setting (212 =
4096 entries), as most of our LVS balancers handle around a million
connections/SLAB entries at any point in time (around 100-150 kpps
load). With only 4096 hash table entries this implies that each entry
consists of a linked list of 256 connections *on average*.
To provide some statistics, I did an oprofile run on an 2.6.31 kernel,
with both the default 4096 table size, and the same kernel recompiled
with IP_VS_CONN_TAB_BITS set to 18 (218 = 262144 entries). I built a
quick test setup with a part of Wikimedia/Wikipedia's live traffic
mirrored by the switch to the test host.
With the default setting, at ~ 120 kpps packet load we saw a typical %si
CPU usage of around 30-35%, and oprofile reported a hot spot in
ip_vs_conn_in_get:
samples % image name app name
symbol name
1719761 42.3741 ip_vs.ko ip_vs.ko ip_vs_conn_in_get
302577 7.4554 bnx2 bnx2 /bnx2
181984 4.4840 vmlinux vmlinux __ticket_spin_lock
128636 3.1695 vmlinux vmlinux ip_route_input
74345 1.8318 ip_vs.ko ip_vs.ko ip_vs_conn_out_get
68482 1.6874 vmlinux vmlinux mwait_idle
After loading the recompiled kernel with 218 entries, %si CPU usage
dropped in half to around 12-18%, and oprofile looks much healthier,
with only 7% spent in ip_vs_conn_in_get:
samples % image name app name
symbol name
265641 14.4616 bnx2 bnx2 /bnx2
143251 7.7986 vmlinux vmlinux __ticket_spin_lock
140661 7.6576 ip_vs.ko ip_vs.ko ip_vs_conn_in_get
94364 5.1372 vmlinux vmlinux mwait_idle
86267 4.6964 vmlinux vmlinux ip_route_input
[ horms@verge.net.au: trivial up-port and minor style fixes ]
Signed-off-by: Catalin(ux) M. BOIE <catab@embedromix.ro>
Cc: Mark Bergsma <mark@wikimedia.org>
Signed-off-by: Simon Horman <horms@verge.net.au>
Signed-off-by: Patrick McHardy <kaber@trash.net>
2010-01-04 21:50:24 -07:00
|
|
|
NVERSION(IP_VS_VERSION_CODE), ip_vs_conn_tab_size);
|
2005-04-16 16:20:36 -06:00
|
|
|
if (copy_to_user(user, buf, strlen(buf)+1) != 0) {
|
|
|
|
ret = -EFAULT;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
*len = strlen(buf)+1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IP_VS_SO_GET_INFO:
|
|
|
|
{
|
|
|
|
struct ip_vs_getinfo info;
|
|
|
|
info.version = IP_VS_VERSION_CODE;
|
IPVS: Allow boot time change of hash size
I was very frustrated about the fact that I have to recompile the kernel
to change the hash size. So, I created this patch.
If IPVS is built-in you can append ip_vs.conn_tab_bits=?? to kernel
command line, or, if you built IPVS as modules, you can add
options ip_vs conn_tab_bits=??.
To keep everything backward compatible, you still can select the size at
compile time, and that will be used as default.
It has been about a year since this patch was originally posted
and subsequently dropped on the basis of insufficient test data.
Mark Bergsma has provided the following test results which seem
to strongly support the need for larger hash table sizes:
We do however run into the same problem with the default setting (212 =
4096 entries), as most of our LVS balancers handle around a million
connections/SLAB entries at any point in time (around 100-150 kpps
load). With only 4096 hash table entries this implies that each entry
consists of a linked list of 256 connections *on average*.
To provide some statistics, I did an oprofile run on an 2.6.31 kernel,
with both the default 4096 table size, and the same kernel recompiled
with IP_VS_CONN_TAB_BITS set to 18 (218 = 262144 entries). I built a
quick test setup with a part of Wikimedia/Wikipedia's live traffic
mirrored by the switch to the test host.
With the default setting, at ~ 120 kpps packet load we saw a typical %si
CPU usage of around 30-35%, and oprofile reported a hot spot in
ip_vs_conn_in_get:
samples % image name app name
symbol name
1719761 42.3741 ip_vs.ko ip_vs.ko ip_vs_conn_in_get
302577 7.4554 bnx2 bnx2 /bnx2
181984 4.4840 vmlinux vmlinux __ticket_spin_lock
128636 3.1695 vmlinux vmlinux ip_route_input
74345 1.8318 ip_vs.ko ip_vs.ko ip_vs_conn_out_get
68482 1.6874 vmlinux vmlinux mwait_idle
After loading the recompiled kernel with 218 entries, %si CPU usage
dropped in half to around 12-18%, and oprofile looks much healthier,
with only 7% spent in ip_vs_conn_in_get:
samples % image name app name
symbol name
265641 14.4616 bnx2 bnx2 /bnx2
143251 7.7986 vmlinux vmlinux __ticket_spin_lock
140661 7.6576 ip_vs.ko ip_vs.ko ip_vs_conn_in_get
94364 5.1372 vmlinux vmlinux mwait_idle
86267 4.6964 vmlinux vmlinux ip_route_input
[ horms@verge.net.au: trivial up-port and minor style fixes ]
Signed-off-by: Catalin(ux) M. BOIE <catab@embedromix.ro>
Cc: Mark Bergsma <mark@wikimedia.org>
Signed-off-by: Simon Horman <horms@verge.net.au>
Signed-off-by: Patrick McHardy <kaber@trash.net>
2010-01-04 21:50:24 -07:00
|
|
|
info.size = ip_vs_conn_tab_size;
|
2011-01-03 06:44:58 -07:00
|
|
|
info.num_services = ipvs->num_services;
|
2005-04-16 16:20:36 -06:00
|
|
|
if (copy_to_user(user, &info, sizeof(info)) != 0)
|
|
|
|
ret = -EFAULT;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IP_VS_SO_GET_SERVICES:
|
|
|
|
{
|
|
|
|
struct ip_vs_get_services *get;
|
|
|
|
int size;
|
|
|
|
|
|
|
|
get = (struct ip_vs_get_services *)arg;
|
|
|
|
size = sizeof(*get) +
|
|
|
|
sizeof(struct ip_vs_service_entry) * get->num_services;
|
|
|
|
if (*len != size) {
|
2009-08-02 05:05:41 -06:00
|
|
|
pr_err("length: %u != %u\n", *len, size);
|
2005-04-16 16:20:36 -06:00
|
|
|
ret = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
2011-01-03 06:44:43 -07:00
|
|
|
ret = __ip_vs_get_service_entries(net, get, user);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IP_VS_SO_GET_SERVICE:
|
|
|
|
{
|
|
|
|
struct ip_vs_service_entry *entry;
|
|
|
|
struct ip_vs_service *svc;
|
2008-09-02 07:55:37 -06:00
|
|
|
union nf_inet_addr addr;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
entry = (struct ip_vs_service_entry *)arg;
|
2008-09-02 07:55:37 -06:00
|
|
|
addr.ip = entry->addr;
|
2013-03-22 03:46:53 -06:00
|
|
|
rcu_read_lock();
|
2005-04-16 16:20:36 -06:00
|
|
|
if (entry->fwmark)
|
2011-01-03 06:44:43 -07:00
|
|
|
svc = __ip_vs_svc_fwm_find(net, AF_INET, entry->fwmark);
|
2005-04-16 16:20:36 -06:00
|
|
|
else
|
2011-01-03 06:44:43 -07:00
|
|
|
svc = __ip_vs_service_find(net, AF_INET,
|
|
|
|
entry->protocol, &addr,
|
|
|
|
entry->port);
|
2013-03-22 03:46:53 -06:00
|
|
|
rcu_read_unlock();
|
2005-04-16 16:20:36 -06:00
|
|
|
if (svc) {
|
|
|
|
ip_vs_copy_service(entry, svc);
|
|
|
|
if (copy_to_user(user, entry, sizeof(*entry)) != 0)
|
|
|
|
ret = -EFAULT;
|
|
|
|
} else
|
|
|
|
ret = -ESRCH;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IP_VS_SO_GET_DESTS:
|
|
|
|
{
|
|
|
|
struct ip_vs_get_dests *get;
|
|
|
|
int size;
|
|
|
|
|
|
|
|
get = (struct ip_vs_get_dests *)arg;
|
|
|
|
size = sizeof(*get) +
|
|
|
|
sizeof(struct ip_vs_dest_entry) * get->num_dests;
|
|
|
|
if (*len != size) {
|
2009-08-02 05:05:41 -06:00
|
|
|
pr_err("length: %u != %u\n", *len, size);
|
2005-04-16 16:20:36 -06:00
|
|
|
ret = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
2011-01-03 06:44:43 -07:00
|
|
|
ret = __ip_vs_get_dest_entries(net, get, user);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IP_VS_SO_GET_TIMEOUT:
|
|
|
|
{
|
|
|
|
struct ip_vs_timeout_user t;
|
|
|
|
|
2011-01-03 06:44:51 -07:00
|
|
|
__ip_vs_get_timeouts(net, &t);
|
2005-04-16 16:20:36 -06:00
|
|
|
if (copy_to_user(user, &t, sizeof(t)) != 0)
|
|
|
|
ret = -EFAULT;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
ret = -EINVAL;
|
|
|
|
}
|
|
|
|
|
2011-06-13 04:19:26 -06:00
|
|
|
out:
|
2006-03-26 02:37:14 -07:00
|
|
|
mutex_unlock(&__ip_vs_mutex);
|
2005-04-16 16:20:36 -06:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static struct nf_sockopt_ops ip_vs_sockopts = {
|
|
|
|
.pf = PF_INET,
|
|
|
|
.set_optmin = IP_VS_BASE_CTL,
|
|
|
|
.set_optmax = IP_VS_SO_SET_MAX+1,
|
|
|
|
.set = do_ip_vs_set_ctl,
|
|
|
|
.get_optmin = IP_VS_BASE_CTL,
|
|
|
|
.get_optmax = IP_VS_SO_GET_MAX+1,
|
|
|
|
.get = do_ip_vs_get_ctl,
|
[NETFILTER]: Fix/improve deadlock condition on module removal netfilter
So I've had a deadlock reported to me. I've found that the sequence of
events goes like this:
1) process A (modprobe) runs to remove ip_tables.ko
2) process B (iptables-restore) runs and calls setsockopt on a netfilter socket,
increasing the ip_tables socket_ops use count
3) process A acquires a file lock on the file ip_tables.ko, calls remove_module
in the kernel, which in turn executes the ip_tables module cleanup routine,
which calls nf_unregister_sockopt
4) nf_unregister_sockopt, seeing that the use count is non-zero, puts the
calling process into uninterruptible sleep, expecting the process using the
socket option code to wake it up when it exits the kernel
4) the user of the socket option code (process B) in do_ipt_get_ctl, calls
ipt_find_table_lock, which in this case calls request_module to load
ip_tables_nat.ko
5) request_module forks a copy of modprobe (process C) to load the module and
blocks until modprobe exits.
6) Process C. forked by request_module process the dependencies of
ip_tables_nat.ko, of which ip_tables.ko is one.
7) Process C attempts to lock the request module and all its dependencies, it
blocks when it attempts to lock ip_tables.ko (which was previously locked in
step 3)
Theres not really any great permanent solution to this that I can see, but I've
developed a two part solution that corrects the problem
Part 1) Modifies the nf_sockopt registration code so that, instead of using a
use counter internal to the nf_sockopt_ops structure, we instead use a pointer
to the registering modules owner to do module reference counting when nf_sockopt
calls a modules set/get routine. This prevents the deadlock by preventing set 4
from happening.
Part 2) Enhances the modprobe utilty so that by default it preforms non-blocking
remove operations (the same way rmmod does), and add an option to explicity
request blocking operation. So if you select blocking operation in modprobe you
can still cause the above deadlock, but only if you explicity try (and since
root can do any old stupid thing it would like.... :) ).
Signed-off-by: Neil Horman <nhorman@tuxdriver.com>
Signed-off-by: Patrick McHardy <kaber@trash.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-09-11 03:28:26 -06:00
|
|
|
.owner = THIS_MODULE,
|
2005-04-16 16:20:36 -06:00
|
|
|
};
|
|
|
|
|
2008-08-14 06:08:44 -06:00
|
|
|
/*
|
|
|
|
* Generic Netlink interface
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* IPVS genetlink family */
|
|
|
|
static struct genl_family ip_vs_genl_family = {
|
|
|
|
.id = GENL_ID_GENERATE,
|
|
|
|
.hdrsize = 0,
|
|
|
|
.name = IPVS_GENL_NAME,
|
|
|
|
.version = IPVS_GENL_VERSION,
|
|
|
|
.maxattr = IPVS_CMD_MAX,
|
2011-01-03 06:45:03 -07:00
|
|
|
.netnsok = true, /* Make ipvsadm to work on netns */
|
2008-08-14 06:08:44 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Policy used for first-level command attributes */
|
|
|
|
static const struct nla_policy ip_vs_cmd_policy[IPVS_CMD_ATTR_MAX + 1] = {
|
|
|
|
[IPVS_CMD_ATTR_SERVICE] = { .type = NLA_NESTED },
|
|
|
|
[IPVS_CMD_ATTR_DEST] = { .type = NLA_NESTED },
|
|
|
|
[IPVS_CMD_ATTR_DAEMON] = { .type = NLA_NESTED },
|
|
|
|
[IPVS_CMD_ATTR_TIMEOUT_TCP] = { .type = NLA_U32 },
|
|
|
|
[IPVS_CMD_ATTR_TIMEOUT_TCP_FIN] = { .type = NLA_U32 },
|
|
|
|
[IPVS_CMD_ATTR_TIMEOUT_UDP] = { .type = NLA_U32 },
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Policy used for attributes in nested attribute IPVS_CMD_ATTR_DAEMON */
|
|
|
|
static const struct nla_policy ip_vs_daemon_policy[IPVS_DAEMON_ATTR_MAX + 1] = {
|
|
|
|
[IPVS_DAEMON_ATTR_STATE] = { .type = NLA_U32 },
|
|
|
|
[IPVS_DAEMON_ATTR_MCAST_IFN] = { .type = NLA_NUL_STRING,
|
|
|
|
.len = IP_VS_IFNAME_MAXLEN },
|
|
|
|
[IPVS_DAEMON_ATTR_SYNC_ID] = { .type = NLA_U32 },
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Policy used for attributes in nested attribute IPVS_CMD_ATTR_SERVICE */
|
|
|
|
static const struct nla_policy ip_vs_svc_policy[IPVS_SVC_ATTR_MAX + 1] = {
|
|
|
|
[IPVS_SVC_ATTR_AF] = { .type = NLA_U16 },
|
|
|
|
[IPVS_SVC_ATTR_PROTOCOL] = { .type = NLA_U16 },
|
|
|
|
[IPVS_SVC_ATTR_ADDR] = { .type = NLA_BINARY,
|
|
|
|
.len = sizeof(union nf_inet_addr) },
|
|
|
|
[IPVS_SVC_ATTR_PORT] = { .type = NLA_U16 },
|
|
|
|
[IPVS_SVC_ATTR_FWMARK] = { .type = NLA_U32 },
|
|
|
|
[IPVS_SVC_ATTR_SCHED_NAME] = { .type = NLA_NUL_STRING,
|
|
|
|
.len = IP_VS_SCHEDNAME_MAXLEN },
|
2010-08-22 06:37:54 -06:00
|
|
|
[IPVS_SVC_ATTR_PE_NAME] = { .type = NLA_NUL_STRING,
|
|
|
|
.len = IP_VS_PENAME_MAXLEN },
|
2008-08-14 06:08:44 -06:00
|
|
|
[IPVS_SVC_ATTR_FLAGS] = { .type = NLA_BINARY,
|
|
|
|
.len = sizeof(struct ip_vs_flags) },
|
|
|
|
[IPVS_SVC_ATTR_TIMEOUT] = { .type = NLA_U32 },
|
|
|
|
[IPVS_SVC_ATTR_NETMASK] = { .type = NLA_U32 },
|
|
|
|
[IPVS_SVC_ATTR_STATS] = { .type = NLA_NESTED },
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Policy used for attributes in nested attribute IPVS_CMD_ATTR_DEST */
|
|
|
|
static const struct nla_policy ip_vs_dest_policy[IPVS_DEST_ATTR_MAX + 1] = {
|
|
|
|
[IPVS_DEST_ATTR_ADDR] = { .type = NLA_BINARY,
|
|
|
|
.len = sizeof(union nf_inet_addr) },
|
|
|
|
[IPVS_DEST_ATTR_PORT] = { .type = NLA_U16 },
|
|
|
|
[IPVS_DEST_ATTR_FWD_METHOD] = { .type = NLA_U32 },
|
|
|
|
[IPVS_DEST_ATTR_WEIGHT] = { .type = NLA_U32 },
|
|
|
|
[IPVS_DEST_ATTR_U_THRESH] = { .type = NLA_U32 },
|
|
|
|
[IPVS_DEST_ATTR_L_THRESH] = { .type = NLA_U32 },
|
|
|
|
[IPVS_DEST_ATTR_ACTIVE_CONNS] = { .type = NLA_U32 },
|
|
|
|
[IPVS_DEST_ATTR_INACT_CONNS] = { .type = NLA_U32 },
|
|
|
|
[IPVS_DEST_ATTR_PERSIST_CONNS] = { .type = NLA_U32 },
|
|
|
|
[IPVS_DEST_ATTR_STATS] = { .type = NLA_NESTED },
|
2014-09-09 17:40:20 -06:00
|
|
|
[IPVS_DEST_ATTR_ADDR_FAMILY] = { .type = NLA_U16 },
|
2008-08-14 06:08:44 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
static int ip_vs_genl_fill_stats(struct sk_buff *skb, int container_type,
|
|
|
|
struct ip_vs_stats *stats)
|
|
|
|
{
|
2011-03-13 17:37:49 -06:00
|
|
|
struct ip_vs_stats_user ustats;
|
2008-08-14 06:08:44 -06:00
|
|
|
struct nlattr *nl_stats = nla_nest_start(skb, container_type);
|
|
|
|
if (!nl_stats)
|
|
|
|
return -EMSGSIZE;
|
|
|
|
|
2011-03-13 17:37:49 -06:00
|
|
|
ip_vs_copy_stats(&ustats, stats);
|
2008-08-14 06:08:44 -06:00
|
|
|
|
2012-04-01 17:03:15 -06:00
|
|
|
if (nla_put_u32(skb, IPVS_STATS_ATTR_CONNS, ustats.conns) ||
|
|
|
|
nla_put_u32(skb, IPVS_STATS_ATTR_INPKTS, ustats.inpkts) ||
|
|
|
|
nla_put_u32(skb, IPVS_STATS_ATTR_OUTPKTS, ustats.outpkts) ||
|
|
|
|
nla_put_u64(skb, IPVS_STATS_ATTR_INBYTES, ustats.inbytes) ||
|
|
|
|
nla_put_u64(skb, IPVS_STATS_ATTR_OUTBYTES, ustats.outbytes) ||
|
|
|
|
nla_put_u32(skb, IPVS_STATS_ATTR_CPS, ustats.cps) ||
|
|
|
|
nla_put_u32(skb, IPVS_STATS_ATTR_INPPS, ustats.inpps) ||
|
|
|
|
nla_put_u32(skb, IPVS_STATS_ATTR_OUTPPS, ustats.outpps) ||
|
|
|
|
nla_put_u32(skb, IPVS_STATS_ATTR_INBPS, ustats.inbps) ||
|
|
|
|
nla_put_u32(skb, IPVS_STATS_ATTR_OUTBPS, ustats.outbps))
|
|
|
|
goto nla_put_failure;
|
2008-08-14 06:08:44 -06:00
|
|
|
nla_nest_end(skb, nl_stats);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
nla_put_failure:
|
|
|
|
nla_nest_cancel(skb, nl_stats);
|
|
|
|
return -EMSGSIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ip_vs_genl_fill_service(struct sk_buff *skb,
|
|
|
|
struct ip_vs_service *svc)
|
|
|
|
{
|
2013-03-22 03:46:53 -06:00
|
|
|
struct ip_vs_scheduler *sched;
|
2013-04-17 14:50:50 -06:00
|
|
|
struct ip_vs_pe *pe;
|
2008-08-14 06:08:44 -06:00
|
|
|
struct nlattr *nl_service;
|
|
|
|
struct ip_vs_flags flags = { .flags = svc->flags,
|
|
|
|
.mask = ~0 };
|
|
|
|
|
|
|
|
nl_service = nla_nest_start(skb, IPVS_CMD_ATTR_SERVICE);
|
|
|
|
if (!nl_service)
|
|
|
|
return -EMSGSIZE;
|
|
|
|
|
2012-04-01 17:03:15 -06:00
|
|
|
if (nla_put_u16(skb, IPVS_SVC_ATTR_AF, svc->af))
|
|
|
|
goto nla_put_failure;
|
2008-08-14 06:08:44 -06:00
|
|
|
if (svc->fwmark) {
|
2012-04-01 17:03:15 -06:00
|
|
|
if (nla_put_u32(skb, IPVS_SVC_ATTR_FWMARK, svc->fwmark))
|
|
|
|
goto nla_put_failure;
|
2008-08-14 06:08:44 -06:00
|
|
|
} else {
|
2012-04-01 17:03:15 -06:00
|
|
|
if (nla_put_u16(skb, IPVS_SVC_ATTR_PROTOCOL, svc->protocol) ||
|
|
|
|
nla_put(skb, IPVS_SVC_ATTR_ADDR, sizeof(svc->addr), &svc->addr) ||
|
2013-04-17 14:50:49 -06:00
|
|
|
nla_put_be16(skb, IPVS_SVC_ATTR_PORT, svc->port))
|
2012-04-01 17:03:15 -06:00
|
|
|
goto nla_put_failure;
|
2008-08-14 06:08:44 -06:00
|
|
|
}
|
|
|
|
|
2013-03-22 03:46:53 -06:00
|
|
|
sched = rcu_dereference_protected(svc->scheduler, 1);
|
2013-04-17 14:50:50 -06:00
|
|
|
pe = rcu_dereference_protected(svc->pe, 1);
|
2013-03-22 03:46:53 -06:00
|
|
|
if (nla_put_string(skb, IPVS_SVC_ATTR_SCHED_NAME, sched->name) ||
|
2013-04-17 14:50:50 -06:00
|
|
|
(pe && nla_put_string(skb, IPVS_SVC_ATTR_PE_NAME, pe->name)) ||
|
2012-04-01 17:03:15 -06:00
|
|
|
nla_put(skb, IPVS_SVC_ATTR_FLAGS, sizeof(flags), &flags) ||
|
|
|
|
nla_put_u32(skb, IPVS_SVC_ATTR_TIMEOUT, svc->timeout / HZ) ||
|
2013-04-17 14:50:49 -06:00
|
|
|
nla_put_be32(skb, IPVS_SVC_ATTR_NETMASK, svc->netmask))
|
2012-04-01 17:03:15 -06:00
|
|
|
goto nla_put_failure;
|
2008-08-14 06:08:44 -06:00
|
|
|
if (ip_vs_genl_fill_stats(skb, IPVS_SVC_ATTR_STATS, &svc->stats))
|
|
|
|
goto nla_put_failure;
|
|
|
|
|
|
|
|
nla_nest_end(skb, nl_service);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
nla_put_failure:
|
|
|
|
nla_nest_cancel(skb, nl_service);
|
|
|
|
return -EMSGSIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ip_vs_genl_dump_service(struct sk_buff *skb,
|
|
|
|
struct ip_vs_service *svc,
|
|
|
|
struct netlink_callback *cb)
|
|
|
|
{
|
|
|
|
void *hdr;
|
|
|
|
|
2012-09-07 14:12:54 -06:00
|
|
|
hdr = genlmsg_put(skb, NETLINK_CB(cb->skb).portid, cb->nlh->nlmsg_seq,
|
2008-08-14 06:08:44 -06:00
|
|
|
&ip_vs_genl_family, NLM_F_MULTI,
|
|
|
|
IPVS_CMD_NEW_SERVICE);
|
|
|
|
if (!hdr)
|
|
|
|
return -EMSGSIZE;
|
|
|
|
|
|
|
|
if (ip_vs_genl_fill_service(skb, svc) < 0)
|
|
|
|
goto nla_put_failure;
|
|
|
|
|
2015-01-16 14:09:00 -07:00
|
|
|
genlmsg_end(skb, hdr);
|
|
|
|
return 0;
|
2008-08-14 06:08:44 -06:00
|
|
|
|
|
|
|
nla_put_failure:
|
|
|
|
genlmsg_cancel(skb, hdr);
|
|
|
|
return -EMSGSIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ip_vs_genl_dump_services(struct sk_buff *skb,
|
|
|
|
struct netlink_callback *cb)
|
|
|
|
{
|
|
|
|
int idx = 0, i;
|
|
|
|
int start = cb->args[0];
|
|
|
|
struct ip_vs_service *svc;
|
2011-01-03 06:44:43 -07:00
|
|
|
struct net *net = skb_sknet(skb);
|
2008-08-14 06:08:44 -06:00
|
|
|
|
|
|
|
mutex_lock(&__ip_vs_mutex);
|
|
|
|
for (i = 0; i < IP_VS_SVC_TAB_SIZE; i++) {
|
2013-03-22 03:46:53 -06:00
|
|
|
hlist_for_each_entry(svc, &ip_vs_svc_table[i], s_list) {
|
2011-01-03 06:44:43 -07:00
|
|
|
if (++idx <= start || !net_eq(svc->net, net))
|
2008-08-14 06:08:44 -06:00
|
|
|
continue;
|
|
|
|
if (ip_vs_genl_dump_service(skb, svc, cb) < 0) {
|
|
|
|
idx--;
|
|
|
|
goto nla_put_failure;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < IP_VS_SVC_TAB_SIZE; i++) {
|
2013-03-22 03:46:53 -06:00
|
|
|
hlist_for_each_entry(svc, &ip_vs_svc_fwm_table[i], f_list) {
|
2011-01-03 06:44:43 -07:00
|
|
|
if (++idx <= start || !net_eq(svc->net, net))
|
2008-08-14 06:08:44 -06:00
|
|
|
continue;
|
|
|
|
if (ip_vs_genl_dump_service(skb, svc, cb) < 0) {
|
|
|
|
idx--;
|
|
|
|
goto nla_put_failure;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nla_put_failure:
|
|
|
|
mutex_unlock(&__ip_vs_mutex);
|
|
|
|
cb->args[0] = idx;
|
|
|
|
|
|
|
|
return skb->len;
|
|
|
|
}
|
|
|
|
|
2011-01-03 06:44:43 -07:00
|
|
|
static int ip_vs_genl_parse_service(struct net *net,
|
|
|
|
struct ip_vs_service_user_kern *usvc,
|
2010-09-21 10:12:30 -06:00
|
|
|
struct nlattr *nla, int full_entry,
|
|
|
|
struct ip_vs_service **ret_svc)
|
2008-08-14 06:08:44 -06:00
|
|
|
{
|
|
|
|
struct nlattr *attrs[IPVS_SVC_ATTR_MAX + 1];
|
|
|
|
struct nlattr *nla_af, *nla_port, *nla_fwmark, *nla_protocol, *nla_addr;
|
2010-09-21 10:12:30 -06:00
|
|
|
struct ip_vs_service *svc;
|
2008-08-14 06:08:44 -06:00
|
|
|
|
|
|
|
/* Parse mandatory identifying service fields first */
|
|
|
|
if (nla == NULL ||
|
|
|
|
nla_parse_nested(attrs, IPVS_SVC_ATTR_MAX, nla, ip_vs_svc_policy))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
nla_af = attrs[IPVS_SVC_ATTR_AF];
|
|
|
|
nla_protocol = attrs[IPVS_SVC_ATTR_PROTOCOL];
|
|
|
|
nla_addr = attrs[IPVS_SVC_ATTR_ADDR];
|
|
|
|
nla_port = attrs[IPVS_SVC_ATTR_PORT];
|
|
|
|
nla_fwmark = attrs[IPVS_SVC_ATTR_FWMARK];
|
|
|
|
|
|
|
|
if (!(nla_af && (nla_fwmark || (nla_port && nla_protocol && nla_addr))))
|
|
|
|
return -EINVAL;
|
|
|
|
|
2009-12-15 09:01:25 -07:00
|
|
|
memset(usvc, 0, sizeof(*usvc));
|
|
|
|
|
2008-09-02 07:55:36 -06:00
|
|
|
usvc->af = nla_get_u16(nla_af);
|
2008-09-02 07:55:55 -06:00
|
|
|
#ifdef CONFIG_IP_VS_IPV6
|
|
|
|
if (usvc->af != AF_INET && usvc->af != AF_INET6)
|
|
|
|
#else
|
|
|
|
if (usvc->af != AF_INET)
|
|
|
|
#endif
|
2008-08-14 06:08:44 -06:00
|
|
|
return -EAFNOSUPPORT;
|
|
|
|
|
|
|
|
if (nla_fwmark) {
|
|
|
|
usvc->protocol = IPPROTO_TCP;
|
|
|
|
usvc->fwmark = nla_get_u32(nla_fwmark);
|
|
|
|
} else {
|
|
|
|
usvc->protocol = nla_get_u16(nla_protocol);
|
|
|
|
nla_memcpy(&usvc->addr, nla_addr, sizeof(usvc->addr));
|
2013-04-17 14:50:49 -06:00
|
|
|
usvc->port = nla_get_be16(nla_port);
|
2008-08-14 06:08:44 -06:00
|
|
|
usvc->fwmark = 0;
|
|
|
|
}
|
|
|
|
|
2013-03-22 03:46:53 -06:00
|
|
|
rcu_read_lock();
|
2010-09-21 10:12:30 -06:00
|
|
|
if (usvc->fwmark)
|
2011-01-03 06:44:43 -07:00
|
|
|
svc = __ip_vs_svc_fwm_find(net, usvc->af, usvc->fwmark);
|
2010-09-21 10:12:30 -06:00
|
|
|
else
|
2011-01-03 06:44:43 -07:00
|
|
|
svc = __ip_vs_service_find(net, usvc->af, usvc->protocol,
|
2010-09-21 10:12:30 -06:00
|
|
|
&usvc->addr, usvc->port);
|
2013-03-22 03:46:53 -06:00
|
|
|
rcu_read_unlock();
|
2010-09-21 10:12:30 -06:00
|
|
|
*ret_svc = svc;
|
|
|
|
|
2008-08-14 06:08:44 -06:00
|
|
|
/* If a full entry was requested, check for the additional fields */
|
|
|
|
if (full_entry) {
|
2010-08-22 06:37:54 -06:00
|
|
|
struct nlattr *nla_sched, *nla_flags, *nla_pe, *nla_timeout,
|
2008-08-14 06:08:44 -06:00
|
|
|
*nla_netmask;
|
|
|
|
struct ip_vs_flags flags;
|
|
|
|
|
|
|
|
nla_sched = attrs[IPVS_SVC_ATTR_SCHED_NAME];
|
2010-08-22 06:37:54 -06:00
|
|
|
nla_pe = attrs[IPVS_SVC_ATTR_PE_NAME];
|
2008-08-14 06:08:44 -06:00
|
|
|
nla_flags = attrs[IPVS_SVC_ATTR_FLAGS];
|
|
|
|
nla_timeout = attrs[IPVS_SVC_ATTR_TIMEOUT];
|
|
|
|
nla_netmask = attrs[IPVS_SVC_ATTR_NETMASK];
|
|
|
|
|
|
|
|
if (!(nla_sched && nla_flags && nla_timeout && nla_netmask))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
nla_memcpy(&flags, nla_flags, sizeof(flags));
|
|
|
|
|
|
|
|
/* prefill flags from service if it already exists */
|
2010-09-21 10:12:30 -06:00
|
|
|
if (svc)
|
2008-08-14 06:08:44 -06:00
|
|
|
usvc->flags = svc->flags;
|
|
|
|
|
|
|
|
/* set new flags from userland */
|
|
|
|
usvc->flags = (usvc->flags & ~flags.mask) |
|
|
|
|
(flags.flags & flags.mask);
|
2008-09-02 07:55:36 -06:00
|
|
|
usvc->sched_name = nla_data(nla_sched);
|
2010-08-22 06:37:54 -06:00
|
|
|
usvc->pe_name = nla_pe ? nla_data(nla_pe) : NULL;
|
2008-08-14 06:08:44 -06:00
|
|
|
usvc->timeout = nla_get_u32(nla_timeout);
|
2013-04-17 14:50:49 -06:00
|
|
|
usvc->netmask = nla_get_be32(nla_netmask);
|
2008-08-14 06:08:44 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-01-03 06:44:43 -07:00
|
|
|
static struct ip_vs_service *ip_vs_genl_find_service(struct net *net,
|
|
|
|
struct nlattr *nla)
|
2008-08-14 06:08:44 -06:00
|
|
|
{
|
2008-09-02 07:55:36 -06:00
|
|
|
struct ip_vs_service_user_kern usvc;
|
2010-09-21 10:12:30 -06:00
|
|
|
struct ip_vs_service *svc;
|
2008-08-14 06:08:44 -06:00
|
|
|
int ret;
|
|
|
|
|
2011-01-03 06:44:43 -07:00
|
|
|
ret = ip_vs_genl_parse_service(net, &usvc, nla, 0, &svc);
|
2010-09-21 10:12:30 -06:00
|
|
|
return ret ? ERR_PTR(ret) : svc;
|
2008-08-14 06:08:44 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
|
|
|
|
{
|
|
|
|
struct nlattr *nl_dest;
|
|
|
|
|
|
|
|
nl_dest = nla_nest_start(skb, IPVS_CMD_ATTR_DEST);
|
|
|
|
if (!nl_dest)
|
|
|
|
return -EMSGSIZE;
|
|
|
|
|
2012-04-01 17:03:15 -06:00
|
|
|
if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
|
2013-04-17 14:50:49 -06:00
|
|
|
nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
|
2012-04-01 17:03:15 -06:00
|
|
|
nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
|
|
|
|
(atomic_read(&dest->conn_flags) &
|
|
|
|
IP_VS_CONN_F_FWD_MASK)) ||
|
|
|
|
nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
|
|
|
|
atomic_read(&dest->weight)) ||
|
|
|
|
nla_put_u32(skb, IPVS_DEST_ATTR_U_THRESH, dest->u_threshold) ||
|
|
|
|
nla_put_u32(skb, IPVS_DEST_ATTR_L_THRESH, dest->l_threshold) ||
|
|
|
|
nla_put_u32(skb, IPVS_DEST_ATTR_ACTIVE_CONNS,
|
|
|
|
atomic_read(&dest->activeconns)) ||
|
|
|
|
nla_put_u32(skb, IPVS_DEST_ATTR_INACT_CONNS,
|
|
|
|
atomic_read(&dest->inactconns)) ||
|
|
|
|
nla_put_u32(skb, IPVS_DEST_ATTR_PERSIST_CONNS,
|
2014-09-09 17:40:20 -06:00
|
|
|
atomic_read(&dest->persistconns)) ||
|
|
|
|
nla_put_u16(skb, IPVS_DEST_ATTR_ADDR_FAMILY, dest->af))
|
2012-04-01 17:03:15 -06:00
|
|
|
goto nla_put_failure;
|
2008-08-14 06:08:44 -06:00
|
|
|
if (ip_vs_genl_fill_stats(skb, IPVS_DEST_ATTR_STATS, &dest->stats))
|
|
|
|
goto nla_put_failure;
|
|
|
|
|
|
|
|
nla_nest_end(skb, nl_dest);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
nla_put_failure:
|
|
|
|
nla_nest_cancel(skb, nl_dest);
|
|
|
|
return -EMSGSIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ip_vs_genl_dump_dest(struct sk_buff *skb, struct ip_vs_dest *dest,
|
|
|
|
struct netlink_callback *cb)
|
|
|
|
{
|
|
|
|
void *hdr;
|
|
|
|
|
2012-09-07 14:12:54 -06:00
|
|
|
hdr = genlmsg_put(skb, NETLINK_CB(cb->skb).portid, cb->nlh->nlmsg_seq,
|
2008-08-14 06:08:44 -06:00
|
|
|
&ip_vs_genl_family, NLM_F_MULTI,
|
|
|
|
IPVS_CMD_NEW_DEST);
|
|
|
|
if (!hdr)
|
|
|
|
return -EMSGSIZE;
|
|
|
|
|
|
|
|
if (ip_vs_genl_fill_dest(skb, dest) < 0)
|
|
|
|
goto nla_put_failure;
|
|
|
|
|
2015-01-16 14:09:00 -07:00
|
|
|
genlmsg_end(skb, hdr);
|
|
|
|
return 0;
|
2008-08-14 06:08:44 -06:00
|
|
|
|
|
|
|
nla_put_failure:
|
|
|
|
genlmsg_cancel(skb, hdr);
|
|
|
|
return -EMSGSIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ip_vs_genl_dump_dests(struct sk_buff *skb,
|
|
|
|
struct netlink_callback *cb)
|
|
|
|
{
|
|
|
|
int idx = 0;
|
|
|
|
int start = cb->args[0];
|
|
|
|
struct ip_vs_service *svc;
|
|
|
|
struct ip_vs_dest *dest;
|
|
|
|
struct nlattr *attrs[IPVS_CMD_ATTR_MAX + 1];
|
2011-01-03 06:44:58 -07:00
|
|
|
struct net *net = skb_sknet(skb);
|
2008-08-14 06:08:44 -06:00
|
|
|
|
|
|
|
mutex_lock(&__ip_vs_mutex);
|
|
|
|
|
|
|
|
/* Try to find the service for which to dump destinations */
|
|
|
|
if (nlmsg_parse(cb->nlh, GENL_HDRLEN, attrs,
|
|
|
|
IPVS_CMD_ATTR_MAX, ip_vs_cmd_policy))
|
|
|
|
goto out_err;
|
|
|
|
|
2011-01-03 06:44:58 -07:00
|
|
|
|
2011-01-03 06:44:43 -07:00
|
|
|
svc = ip_vs_genl_find_service(net, attrs[IPVS_CMD_ATTR_SERVICE]);
|
2008-08-14 06:08:44 -06:00
|
|
|
if (IS_ERR(svc) || svc == NULL)
|
|
|
|
goto out_err;
|
|
|
|
|
|
|
|
/* Dump the destinations */
|
|
|
|
list_for_each_entry(dest, &svc->destinations, n_list) {
|
|
|
|
if (++idx <= start)
|
|
|
|
continue;
|
|
|
|
if (ip_vs_genl_dump_dest(skb, dest, cb) < 0) {
|
|
|
|
idx--;
|
|
|
|
goto nla_put_failure;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nla_put_failure:
|
|
|
|
cb->args[0] = idx;
|
|
|
|
|
|
|
|
out_err:
|
|
|
|
mutex_unlock(&__ip_vs_mutex);
|
|
|
|
|
|
|
|
return skb->len;
|
|
|
|
}
|
|
|
|
|
2008-09-02 07:55:36 -06:00
|
|
|
static int ip_vs_genl_parse_dest(struct ip_vs_dest_user_kern *udest,
|
2008-08-14 06:08:44 -06:00
|
|
|
struct nlattr *nla, int full_entry)
|
|
|
|
{
|
|
|
|
struct nlattr *attrs[IPVS_DEST_ATTR_MAX + 1];
|
|
|
|
struct nlattr *nla_addr, *nla_port;
|
2014-09-09 17:40:20 -06:00
|
|
|
struct nlattr *nla_addr_family;
|
2008-08-14 06:08:44 -06:00
|
|
|
|
|
|
|
/* Parse mandatory identifying destination fields first */
|
|
|
|
if (nla == NULL ||
|
|
|
|
nla_parse_nested(attrs, IPVS_DEST_ATTR_MAX, nla, ip_vs_dest_policy))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
nla_addr = attrs[IPVS_DEST_ATTR_ADDR];
|
|
|
|
nla_port = attrs[IPVS_DEST_ATTR_PORT];
|
2014-09-09 17:40:20 -06:00
|
|
|
nla_addr_family = attrs[IPVS_DEST_ATTR_ADDR_FAMILY];
|
2008-08-14 06:08:44 -06:00
|
|
|
|
|
|
|
if (!(nla_addr && nla_port))
|
|
|
|
return -EINVAL;
|
|
|
|
|
2009-12-15 09:01:25 -07:00
|
|
|
memset(udest, 0, sizeof(*udest));
|
|
|
|
|
2008-08-14 06:08:44 -06:00
|
|
|
nla_memcpy(&udest->addr, nla_addr, sizeof(udest->addr));
|
2013-04-17 14:50:49 -06:00
|
|
|
udest->port = nla_get_be16(nla_port);
|
2008-08-14 06:08:44 -06:00
|
|
|
|
2014-09-09 17:40:20 -06:00
|
|
|
if (nla_addr_family)
|
|
|
|
udest->af = nla_get_u16(nla_addr_family);
|
|
|
|
else
|
|
|
|
udest->af = 0;
|
|
|
|
|
2008-08-14 06:08:44 -06:00
|
|
|
/* If a full entry was requested, check for the additional fields */
|
|
|
|
if (full_entry) {
|
|
|
|
struct nlattr *nla_fwd, *nla_weight, *nla_u_thresh,
|
|
|
|
*nla_l_thresh;
|
|
|
|
|
|
|
|
nla_fwd = attrs[IPVS_DEST_ATTR_FWD_METHOD];
|
|
|
|
nla_weight = attrs[IPVS_DEST_ATTR_WEIGHT];
|
|
|
|
nla_u_thresh = attrs[IPVS_DEST_ATTR_U_THRESH];
|
|
|
|
nla_l_thresh = attrs[IPVS_DEST_ATTR_L_THRESH];
|
|
|
|
|
|
|
|
if (!(nla_fwd && nla_weight && nla_u_thresh && nla_l_thresh))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
udest->conn_flags = nla_get_u32(nla_fwd)
|
|
|
|
& IP_VS_CONN_F_FWD_MASK;
|
|
|
|
udest->weight = nla_get_u32(nla_weight);
|
|
|
|
udest->u_threshold = nla_get_u32(nla_u_thresh);
|
|
|
|
udest->l_threshold = nla_get_u32(nla_l_thresh);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-04-17 14:50:49 -06:00
|
|
|
static int ip_vs_genl_fill_daemon(struct sk_buff *skb, __u32 state,
|
|
|
|
const char *mcast_ifn, __u32 syncid)
|
2008-08-14 06:08:44 -06:00
|
|
|
{
|
|
|
|
struct nlattr *nl_daemon;
|
|
|
|
|
|
|
|
nl_daemon = nla_nest_start(skb, IPVS_CMD_ATTR_DAEMON);
|
|
|
|
if (!nl_daemon)
|
|
|
|
return -EMSGSIZE;
|
|
|
|
|
2012-04-01 17:03:15 -06:00
|
|
|
if (nla_put_u32(skb, IPVS_DAEMON_ATTR_STATE, state) ||
|
|
|
|
nla_put_string(skb, IPVS_DAEMON_ATTR_MCAST_IFN, mcast_ifn) ||
|
|
|
|
nla_put_u32(skb, IPVS_DAEMON_ATTR_SYNC_ID, syncid))
|
|
|
|
goto nla_put_failure;
|
2008-08-14 06:08:44 -06:00
|
|
|
nla_nest_end(skb, nl_daemon);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
nla_put_failure:
|
|
|
|
nla_nest_cancel(skb, nl_daemon);
|
|
|
|
return -EMSGSIZE;
|
|
|
|
}
|
|
|
|
|
2013-04-17 14:50:49 -06:00
|
|
|
static int ip_vs_genl_dump_daemon(struct sk_buff *skb, __u32 state,
|
|
|
|
const char *mcast_ifn, __u32 syncid,
|
2008-08-14 06:08:44 -06:00
|
|
|
struct netlink_callback *cb)
|
|
|
|
{
|
|
|
|
void *hdr;
|
2012-09-07 14:12:54 -06:00
|
|
|
hdr = genlmsg_put(skb, NETLINK_CB(cb->skb).portid, cb->nlh->nlmsg_seq,
|
2008-08-14 06:08:44 -06:00
|
|
|
&ip_vs_genl_family, NLM_F_MULTI,
|
|
|
|
IPVS_CMD_NEW_DAEMON);
|
|
|
|
if (!hdr)
|
|
|
|
return -EMSGSIZE;
|
|
|
|
|
|
|
|
if (ip_vs_genl_fill_daemon(skb, state, mcast_ifn, syncid))
|
|
|
|
goto nla_put_failure;
|
|
|
|
|
2015-01-16 14:09:00 -07:00
|
|
|
genlmsg_end(skb, hdr);
|
|
|
|
return 0;
|
2008-08-14 06:08:44 -06:00
|
|
|
|
|
|
|
nla_put_failure:
|
|
|
|
genlmsg_cancel(skb, hdr);
|
|
|
|
return -EMSGSIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ip_vs_genl_dump_daemons(struct sk_buff *skb,
|
|
|
|
struct netlink_callback *cb)
|
|
|
|
{
|
2011-04-04 07:25:18 -06:00
|
|
|
struct net *net = skb_sknet(skb);
|
2011-01-03 06:44:55 -07:00
|
|
|
struct netns_ipvs *ipvs = net_ipvs(net);
|
|
|
|
|
2011-10-10 19:54:35 -06:00
|
|
|
mutex_lock(&ipvs->sync_mutex);
|
2011-01-03 06:44:55 -07:00
|
|
|
if ((ipvs->sync_state & IP_VS_STATE_MASTER) && !cb->args[0]) {
|
2008-08-14 06:08:44 -06:00
|
|
|
if (ip_vs_genl_dump_daemon(skb, IP_VS_STATE_MASTER,
|
2011-01-03 06:44:55 -07:00
|
|
|
ipvs->master_mcast_ifn,
|
|
|
|
ipvs->master_syncid, cb) < 0)
|
2008-08-14 06:08:44 -06:00
|
|
|
goto nla_put_failure;
|
|
|
|
|
|
|
|
cb->args[0] = 1;
|
|
|
|
}
|
|
|
|
|
2011-01-03 06:44:55 -07:00
|
|
|
if ((ipvs->sync_state & IP_VS_STATE_BACKUP) && !cb->args[1]) {
|
2008-08-14 06:08:44 -06:00
|
|
|
if (ip_vs_genl_dump_daemon(skb, IP_VS_STATE_BACKUP,
|
2011-01-03 06:44:55 -07:00
|
|
|
ipvs->backup_mcast_ifn,
|
|
|
|
ipvs->backup_syncid, cb) < 0)
|
2008-08-14 06:08:44 -06:00
|
|
|
goto nla_put_failure;
|
|
|
|
|
|
|
|
cb->args[1] = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
nla_put_failure:
|
2011-10-10 19:54:35 -06:00
|
|
|
mutex_unlock(&ipvs->sync_mutex);
|
2008-08-14 06:08:44 -06:00
|
|
|
|
|
|
|
return skb->len;
|
|
|
|
}
|
|
|
|
|
2011-01-03 06:44:55 -07:00
|
|
|
static int ip_vs_genl_new_daemon(struct net *net, struct nlattr **attrs)
|
2008-08-14 06:08:44 -06:00
|
|
|
{
|
|
|
|
if (!(attrs[IPVS_DAEMON_ATTR_STATE] &&
|
|
|
|
attrs[IPVS_DAEMON_ATTR_MCAST_IFN] &&
|
|
|
|
attrs[IPVS_DAEMON_ATTR_SYNC_ID]))
|
|
|
|
return -EINVAL;
|
|
|
|
|
2014-09-09 17:40:24 -06:00
|
|
|
/* The synchronization protocol is incompatible with mixed family
|
|
|
|
* services
|
|
|
|
*/
|
|
|
|
if (net_ipvs(net)->mixed_address_family_dests > 0)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2011-01-03 06:44:55 -07:00
|
|
|
return start_sync_thread(net,
|
|
|
|
nla_get_u32(attrs[IPVS_DAEMON_ATTR_STATE]),
|
2008-08-14 06:08:44 -06:00
|
|
|
nla_data(attrs[IPVS_DAEMON_ATTR_MCAST_IFN]),
|
|
|
|
nla_get_u32(attrs[IPVS_DAEMON_ATTR_SYNC_ID]));
|
|
|
|
}
|
|
|
|
|
2011-01-03 06:44:55 -07:00
|
|
|
static int ip_vs_genl_del_daemon(struct net *net, struct nlattr **attrs)
|
2008-08-14 06:08:44 -06:00
|
|
|
{
|
|
|
|
if (!attrs[IPVS_DAEMON_ATTR_STATE])
|
|
|
|
return -EINVAL;
|
|
|
|
|
2011-01-03 06:44:55 -07:00
|
|
|
return stop_sync_thread(net,
|
|
|
|
nla_get_u32(attrs[IPVS_DAEMON_ATTR_STATE]));
|
2008-08-14 06:08:44 -06:00
|
|
|
}
|
|
|
|
|
2011-01-03 06:44:51 -07:00
|
|
|
static int ip_vs_genl_set_config(struct net *net, struct nlattr **attrs)
|
2008-08-14 06:08:44 -06:00
|
|
|
{
|
|
|
|
struct ip_vs_timeout_user t;
|
|
|
|
|
2011-01-03 06:44:51 -07:00
|
|
|
__ip_vs_get_timeouts(net, &t);
|
2008-08-14 06:08:44 -06:00
|
|
|
|
|
|
|
if (attrs[IPVS_CMD_ATTR_TIMEOUT_TCP])
|
|
|
|
t.tcp_timeout = nla_get_u32(attrs[IPVS_CMD_ATTR_TIMEOUT_TCP]);
|
|
|
|
|
|
|
|
if (attrs[IPVS_CMD_ATTR_TIMEOUT_TCP_FIN])
|
|
|
|
t.tcp_fin_timeout =
|
|
|
|
nla_get_u32(attrs[IPVS_CMD_ATTR_TIMEOUT_TCP_FIN]);
|
|
|
|
|
|
|
|
if (attrs[IPVS_CMD_ATTR_TIMEOUT_UDP])
|
|
|
|
t.udp_timeout = nla_get_u32(attrs[IPVS_CMD_ATTR_TIMEOUT_UDP]);
|
|
|
|
|
2011-01-03 06:44:51 -07:00
|
|
|
return ip_vs_set_timeout(net, &t);
|
2008-08-14 06:08:44 -06:00
|
|
|
}
|
|
|
|
|
2011-10-10 19:54:35 -06:00
|
|
|
static int ip_vs_genl_set_daemon(struct sk_buff *skb, struct genl_info *info)
|
2008-08-14 06:08:44 -06:00
|
|
|
{
|
|
|
|
int ret = 0, cmd;
|
2011-01-03 06:44:43 -07:00
|
|
|
struct net *net;
|
2011-01-03 06:44:58 -07:00
|
|
|
struct netns_ipvs *ipvs;
|
2008-08-14 06:08:44 -06:00
|
|
|
|
2011-01-03 06:44:43 -07:00
|
|
|
net = skb_sknet(skb);
|
2011-01-03 06:44:58 -07:00
|
|
|
ipvs = net_ipvs(net);
|
2008-08-14 06:08:44 -06:00
|
|
|
cmd = info->genlhdr->cmd;
|
|
|
|
|
2011-10-10 19:54:35 -06:00
|
|
|
if (cmd == IPVS_CMD_NEW_DAEMON || cmd == IPVS_CMD_DEL_DAEMON) {
|
2008-08-14 06:08:44 -06:00
|
|
|
struct nlattr *daemon_attrs[IPVS_DAEMON_ATTR_MAX + 1];
|
|
|
|
|
2011-10-10 19:54:35 -06:00
|
|
|
mutex_lock(&ipvs->sync_mutex);
|
2008-08-14 06:08:44 -06:00
|
|
|
if (!info->attrs[IPVS_CMD_ATTR_DAEMON] ||
|
|
|
|
nla_parse_nested(daemon_attrs, IPVS_DAEMON_ATTR_MAX,
|
|
|
|
info->attrs[IPVS_CMD_ATTR_DAEMON],
|
|
|
|
ip_vs_daemon_policy)) {
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cmd == IPVS_CMD_NEW_DAEMON)
|
2011-01-03 06:44:55 -07:00
|
|
|
ret = ip_vs_genl_new_daemon(net, daemon_attrs);
|
2008-08-14 06:08:44 -06:00
|
|
|
else
|
2011-01-03 06:44:55 -07:00
|
|
|
ret = ip_vs_genl_del_daemon(net, daemon_attrs);
|
2011-10-10 19:54:35 -06:00
|
|
|
out:
|
|
|
|
mutex_unlock(&ipvs->sync_mutex);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ip_vs_genl_set_cmd(struct sk_buff *skb, struct genl_info *info)
|
|
|
|
{
|
|
|
|
struct ip_vs_service *svc = NULL;
|
|
|
|
struct ip_vs_service_user_kern usvc;
|
|
|
|
struct ip_vs_dest_user_kern udest;
|
|
|
|
int ret = 0, cmd;
|
|
|
|
int need_full_svc = 0, need_full_dest = 0;
|
|
|
|
struct net *net;
|
|
|
|
|
|
|
|
net = skb_sknet(skb);
|
|
|
|
cmd = info->genlhdr->cmd;
|
|
|
|
|
|
|
|
mutex_lock(&__ip_vs_mutex);
|
|
|
|
|
|
|
|
if (cmd == IPVS_CMD_FLUSH) {
|
2013-03-22 03:46:49 -06:00
|
|
|
ret = ip_vs_flush(net, false);
|
2011-10-10 19:54:35 -06:00
|
|
|
goto out;
|
|
|
|
} else if (cmd == IPVS_CMD_SET_CONFIG) {
|
|
|
|
ret = ip_vs_genl_set_config(net, info->attrs);
|
2008-08-14 06:08:44 -06:00
|
|
|
goto out;
|
|
|
|
} else if (cmd == IPVS_CMD_ZERO &&
|
|
|
|
!info->attrs[IPVS_CMD_ATTR_SERVICE]) {
|
2011-01-03 06:44:43 -07:00
|
|
|
ret = ip_vs_zero_all(net);
|
2008-08-14 06:08:44 -06:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* All following commands require a service argument, so check if we
|
|
|
|
* received a valid one. We need a full service specification when
|
|
|
|
* adding / editing a service. Only identifying members otherwise. */
|
|
|
|
if (cmd == IPVS_CMD_NEW_SERVICE || cmd == IPVS_CMD_SET_SERVICE)
|
|
|
|
need_full_svc = 1;
|
|
|
|
|
2011-01-03 06:44:43 -07:00
|
|
|
ret = ip_vs_genl_parse_service(net, &usvc,
|
2008-08-14 06:08:44 -06:00
|
|
|
info->attrs[IPVS_CMD_ATTR_SERVICE],
|
2010-09-21 10:12:30 -06:00
|
|
|
need_full_svc, &svc);
|
2008-08-14 06:08:44 -06:00
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/* Unless we're adding a new service, the service must already exist */
|
|
|
|
if ((cmd != IPVS_CMD_NEW_SERVICE) && (svc == NULL)) {
|
|
|
|
ret = -ESRCH;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Destination commands require a valid destination argument. For
|
|
|
|
* adding / editing a destination, we need a full destination
|
|
|
|
* specification. */
|
|
|
|
if (cmd == IPVS_CMD_NEW_DEST || cmd == IPVS_CMD_SET_DEST ||
|
|
|
|
cmd == IPVS_CMD_DEL_DEST) {
|
|
|
|
if (cmd != IPVS_CMD_DEL_DEST)
|
|
|
|
need_full_dest = 1;
|
|
|
|
|
|
|
|
ret = ip_vs_genl_parse_dest(&udest,
|
|
|
|
info->attrs[IPVS_CMD_ATTR_DEST],
|
|
|
|
need_full_dest);
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
2014-09-09 17:40:20 -06:00
|
|
|
|
|
|
|
/* Old protocols did not allow the user to specify address
|
|
|
|
* family, so we set it to zero instead. We also didn't
|
|
|
|
* allow heterogeneous pools in the old code, so it's safe
|
|
|
|
* to assume that this will have the same address family as
|
|
|
|
* the service.
|
|
|
|
*/
|
|
|
|
if (udest.af == 0)
|
|
|
|
udest.af = svc->af;
|
2014-09-09 17:40:39 -06:00
|
|
|
|
|
|
|
if (udest.af != svc->af) {
|
|
|
|
/* The synchronization protocol is incompatible
|
|
|
|
* with mixed family services
|
|
|
|
*/
|
|
|
|
if (net_ipvs(net)->sync_state) {
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Which connection types do we support? */
|
|
|
|
switch (udest.conn_flags) {
|
|
|
|
case IP_VS_CONN_F_TUNNEL:
|
|
|
|
/* We are able to forward this */
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
2008-08-14 06:08:44 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case IPVS_CMD_NEW_SERVICE:
|
|
|
|
if (svc == NULL)
|
2011-01-03 06:44:43 -07:00
|
|
|
ret = ip_vs_add_service(net, &usvc, &svc);
|
2008-08-14 06:08:44 -06:00
|
|
|
else
|
|
|
|
ret = -EEXIST;
|
|
|
|
break;
|
|
|
|
case IPVS_CMD_SET_SERVICE:
|
|
|
|
ret = ip_vs_edit_service(svc, &usvc);
|
|
|
|
break;
|
|
|
|
case IPVS_CMD_DEL_SERVICE:
|
|
|
|
ret = ip_vs_del_service(svc);
|
2010-09-21 10:12:30 -06:00
|
|
|
/* do not use svc, it can be freed */
|
2008-08-14 06:08:44 -06:00
|
|
|
break;
|
|
|
|
case IPVS_CMD_NEW_DEST:
|
|
|
|
ret = ip_vs_add_dest(svc, &udest);
|
|
|
|
break;
|
|
|
|
case IPVS_CMD_SET_DEST:
|
|
|
|
ret = ip_vs_edit_dest(svc, &udest);
|
|
|
|
break;
|
|
|
|
case IPVS_CMD_DEL_DEST:
|
|
|
|
ret = ip_vs_del_dest(svc, &udest);
|
|
|
|
break;
|
|
|
|
case IPVS_CMD_ZERO:
|
|
|
|
ret = ip_vs_zero_service(svc);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ret = -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
mutex_unlock(&__ip_vs_mutex);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ip_vs_genl_get_cmd(struct sk_buff *skb, struct genl_info *info)
|
|
|
|
{
|
|
|
|
struct sk_buff *msg;
|
|
|
|
void *reply;
|
|
|
|
int ret, cmd, reply_cmd;
|
2011-01-03 06:44:43 -07:00
|
|
|
struct net *net;
|
2008-08-14 06:08:44 -06:00
|
|
|
|
2011-01-03 06:44:43 -07:00
|
|
|
net = skb_sknet(skb);
|
2008-08-14 06:08:44 -06:00
|
|
|
cmd = info->genlhdr->cmd;
|
|
|
|
|
|
|
|
if (cmd == IPVS_CMD_GET_SERVICE)
|
|
|
|
reply_cmd = IPVS_CMD_NEW_SERVICE;
|
|
|
|
else if (cmd == IPVS_CMD_GET_INFO)
|
|
|
|
reply_cmd = IPVS_CMD_SET_INFO;
|
|
|
|
else if (cmd == IPVS_CMD_GET_CONFIG)
|
|
|
|
reply_cmd = IPVS_CMD_SET_CONFIG;
|
|
|
|
else {
|
2009-08-02 05:05:41 -06:00
|
|
|
pr_err("unknown Generic Netlink command\n");
|
2008-08-14 06:08:44 -06:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
|
|
|
|
if (!msg)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
mutex_lock(&__ip_vs_mutex);
|
|
|
|
|
|
|
|
reply = genlmsg_put_reply(msg, info, &ip_vs_genl_family, 0, reply_cmd);
|
|
|
|
if (reply == NULL)
|
|
|
|
goto nla_put_failure;
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case IPVS_CMD_GET_SERVICE:
|
|
|
|
{
|
|
|
|
struct ip_vs_service *svc;
|
|
|
|
|
2011-01-03 06:44:43 -07:00
|
|
|
svc = ip_vs_genl_find_service(net,
|
|
|
|
info->attrs[IPVS_CMD_ATTR_SERVICE]);
|
2008-08-14 06:08:44 -06:00
|
|
|
if (IS_ERR(svc)) {
|
|
|
|
ret = PTR_ERR(svc);
|
|
|
|
goto out_err;
|
|
|
|
} else if (svc) {
|
|
|
|
ret = ip_vs_genl_fill_service(msg, svc);
|
|
|
|
if (ret)
|
|
|
|
goto nla_put_failure;
|
|
|
|
} else {
|
|
|
|
ret = -ESRCH;
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case IPVS_CMD_GET_CONFIG:
|
|
|
|
{
|
|
|
|
struct ip_vs_timeout_user t;
|
|
|
|
|
2011-01-03 06:44:51 -07:00
|
|
|
__ip_vs_get_timeouts(net, &t);
|
2008-08-14 06:08:44 -06:00
|
|
|
#ifdef CONFIG_IP_VS_PROTO_TCP
|
2012-04-01 17:03:15 -06:00
|
|
|
if (nla_put_u32(msg, IPVS_CMD_ATTR_TIMEOUT_TCP,
|
|
|
|
t.tcp_timeout) ||
|
|
|
|
nla_put_u32(msg, IPVS_CMD_ATTR_TIMEOUT_TCP_FIN,
|
|
|
|
t.tcp_fin_timeout))
|
|
|
|
goto nla_put_failure;
|
2008-08-14 06:08:44 -06:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_IP_VS_PROTO_UDP
|
2012-04-01 17:03:15 -06:00
|
|
|
if (nla_put_u32(msg, IPVS_CMD_ATTR_TIMEOUT_UDP, t.udp_timeout))
|
|
|
|
goto nla_put_failure;
|
2008-08-14 06:08:44 -06:00
|
|
|
#endif
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case IPVS_CMD_GET_INFO:
|
2012-04-01 17:03:15 -06:00
|
|
|
if (nla_put_u32(msg, IPVS_INFO_ATTR_VERSION,
|
|
|
|
IP_VS_VERSION_CODE) ||
|
|
|
|
nla_put_u32(msg, IPVS_INFO_ATTR_CONN_TAB_SIZE,
|
|
|
|
ip_vs_conn_tab_size))
|
|
|
|
goto nla_put_failure;
|
2008-08-14 06:08:44 -06:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
genlmsg_end(msg, reply);
|
2009-07-10 03:51:34 -06:00
|
|
|
ret = genlmsg_reply(msg, info);
|
2008-08-14 06:08:44 -06:00
|
|
|
goto out;
|
|
|
|
|
|
|
|
nla_put_failure:
|
2009-08-02 05:05:41 -06:00
|
|
|
pr_err("not enough space in Netlink message\n");
|
2008-08-14 06:08:44 -06:00
|
|
|
ret = -EMSGSIZE;
|
|
|
|
|
|
|
|
out_err:
|
|
|
|
nlmsg_free(msg);
|
|
|
|
out:
|
|
|
|
mutex_unlock(&__ip_vs_mutex);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-02-08 00:57:01 -07:00
|
|
|
static const struct genl_ops ip_vs_genl_ops[] = {
|
2008-08-14 06:08:44 -06:00
|
|
|
{
|
|
|
|
.cmd = IPVS_CMD_NEW_SERVICE,
|
|
|
|
.flags = GENL_ADMIN_PERM,
|
|
|
|
.policy = ip_vs_cmd_policy,
|
|
|
|
.doit = ip_vs_genl_set_cmd,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.cmd = IPVS_CMD_SET_SERVICE,
|
|
|
|
.flags = GENL_ADMIN_PERM,
|
|
|
|
.policy = ip_vs_cmd_policy,
|
|
|
|
.doit = ip_vs_genl_set_cmd,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.cmd = IPVS_CMD_DEL_SERVICE,
|
|
|
|
.flags = GENL_ADMIN_PERM,
|
|
|
|
.policy = ip_vs_cmd_policy,
|
|
|
|
.doit = ip_vs_genl_set_cmd,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.cmd = IPVS_CMD_GET_SERVICE,
|
|
|
|
.flags = GENL_ADMIN_PERM,
|
|
|
|
.doit = ip_vs_genl_get_cmd,
|
|
|
|
.dumpit = ip_vs_genl_dump_services,
|
|
|
|
.policy = ip_vs_cmd_policy,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.cmd = IPVS_CMD_NEW_DEST,
|
|
|
|
.flags = GENL_ADMIN_PERM,
|
|
|
|
.policy = ip_vs_cmd_policy,
|
|
|
|
.doit = ip_vs_genl_set_cmd,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.cmd = IPVS_CMD_SET_DEST,
|
|
|
|
.flags = GENL_ADMIN_PERM,
|
|
|
|
.policy = ip_vs_cmd_policy,
|
|
|
|
.doit = ip_vs_genl_set_cmd,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.cmd = IPVS_CMD_DEL_DEST,
|
|
|
|
.flags = GENL_ADMIN_PERM,
|
|
|
|
.policy = ip_vs_cmd_policy,
|
|
|
|
.doit = ip_vs_genl_set_cmd,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.cmd = IPVS_CMD_GET_DEST,
|
|
|
|
.flags = GENL_ADMIN_PERM,
|
|
|
|
.policy = ip_vs_cmd_policy,
|
|
|
|
.dumpit = ip_vs_genl_dump_dests,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.cmd = IPVS_CMD_NEW_DAEMON,
|
|
|
|
.flags = GENL_ADMIN_PERM,
|
|
|
|
.policy = ip_vs_cmd_policy,
|
2011-10-10 19:54:35 -06:00
|
|
|
.doit = ip_vs_genl_set_daemon,
|
2008-08-14 06:08:44 -06:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.cmd = IPVS_CMD_DEL_DAEMON,
|
|
|
|
.flags = GENL_ADMIN_PERM,
|
|
|
|
.policy = ip_vs_cmd_policy,
|
2011-10-10 19:54:35 -06:00
|
|
|
.doit = ip_vs_genl_set_daemon,
|
2008-08-14 06:08:44 -06:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.cmd = IPVS_CMD_GET_DAEMON,
|
|
|
|
.flags = GENL_ADMIN_PERM,
|
|
|
|
.dumpit = ip_vs_genl_dump_daemons,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.cmd = IPVS_CMD_SET_CONFIG,
|
|
|
|
.flags = GENL_ADMIN_PERM,
|
|
|
|
.policy = ip_vs_cmd_policy,
|
|
|
|
.doit = ip_vs_genl_set_cmd,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.cmd = IPVS_CMD_GET_CONFIG,
|
|
|
|
.flags = GENL_ADMIN_PERM,
|
|
|
|
.doit = ip_vs_genl_get_cmd,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.cmd = IPVS_CMD_GET_INFO,
|
|
|
|
.flags = GENL_ADMIN_PERM,
|
|
|
|
.doit = ip_vs_genl_get_cmd,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.cmd = IPVS_CMD_ZERO,
|
|
|
|
.flags = GENL_ADMIN_PERM,
|
|
|
|
.policy = ip_vs_cmd_policy,
|
|
|
|
.doit = ip_vs_genl_set_cmd,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.cmd = IPVS_CMD_FLUSH,
|
|
|
|
.flags = GENL_ADMIN_PERM,
|
|
|
|
.doit = ip_vs_genl_set_cmd,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init ip_vs_genl_register(void)
|
|
|
|
{
|
2009-05-21 04:34:05 -06:00
|
|
|
return genl_register_family_with_ops(&ip_vs_genl_family,
|
2013-11-19 07:19:31 -07:00
|
|
|
ip_vs_genl_ops);
|
2008-08-14 06:08:44 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static void ip_vs_genl_unregister(void)
|
|
|
|
{
|
|
|
|
genl_unregister_family(&ip_vs_genl_family);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* End of Generic Netlink interface definitions */
|
|
|
|
|
2011-01-03 06:44:42 -07:00
|
|
|
/*
|
|
|
|
* per netns intit/exit func.
|
|
|
|
*/
|
2011-02-04 02:33:02 -07:00
|
|
|
#ifdef CONFIG_SYSCTL
|
2012-07-18 03:10:22 -06:00
|
|
|
static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
|
2011-01-03 06:44:42 -07:00
|
|
|
{
|
2011-01-03 06:44:43 -07:00
|
|
|
int idx;
|
|
|
|
struct netns_ipvs *ipvs = net_ipvs(net);
|
2011-01-03 06:44:58 -07:00
|
|
|
struct ctl_table *tbl;
|
2011-01-03 06:44:43 -07:00
|
|
|
|
2011-01-03 06:44:58 -07:00
|
|
|
atomic_set(&ipvs->dropentry, 0);
|
|
|
|
spin_lock_init(&ipvs->dropentry_lock);
|
|
|
|
spin_lock_init(&ipvs->droppacket_lock);
|
|
|
|
spin_lock_init(&ipvs->securetcp_lock);
|
|
|
|
|
|
|
|
if (!net_eq(net, &init_net)) {
|
|
|
|
tbl = kmemdup(vs_vars, sizeof(vs_vars), GFP_KERNEL);
|
|
|
|
if (tbl == NULL)
|
2011-02-04 02:33:02 -07:00
|
|
|
return -ENOMEM;
|
2012-11-15 20:02:59 -07:00
|
|
|
|
|
|
|
/* Don't export sysctls to unprivileged users */
|
|
|
|
if (net->user_ns != &init_user_ns)
|
|
|
|
tbl[0].procname = NULL;
|
2011-01-03 06:44:58 -07:00
|
|
|
} else
|
|
|
|
tbl = vs_vars;
|
|
|
|
/* Initialize sysctl defaults */
|
|
|
|
idx = 0;
|
|
|
|
ipvs->sysctl_amemthresh = 1024;
|
|
|
|
tbl[idx++].data = &ipvs->sysctl_amemthresh;
|
|
|
|
ipvs->sysctl_am_droprate = 10;
|
|
|
|
tbl[idx++].data = &ipvs->sysctl_am_droprate;
|
|
|
|
tbl[idx++].data = &ipvs->sysctl_drop_entry;
|
|
|
|
tbl[idx++].data = &ipvs->sysctl_drop_packet;
|
|
|
|
#ifdef CONFIG_IP_VS_NFCT
|
|
|
|
tbl[idx++].data = &ipvs->sysctl_conntrack;
|
|
|
|
#endif
|
|
|
|
tbl[idx++].data = &ipvs->sysctl_secure_tcp;
|
|
|
|
ipvs->sysctl_snat_reroute = 1;
|
|
|
|
tbl[idx++].data = &ipvs->sysctl_snat_reroute;
|
|
|
|
ipvs->sysctl_sync_ver = 1;
|
|
|
|
tbl[idx++].data = &ipvs->sysctl_sync_ver;
|
2012-05-08 11:40:30 -06:00
|
|
|
ipvs->sysctl_sync_ports = 1;
|
|
|
|
tbl[idx++].data = &ipvs->sysctl_sync_ports;
|
2013-06-24 13:44:41 -06:00
|
|
|
tbl[idx++].data = &ipvs->sysctl_sync_persist_mode;
|
2012-05-08 11:39:49 -06:00
|
|
|
ipvs->sysctl_sync_qlen_max = nr_free_buffer_pages() / 32;
|
|
|
|
tbl[idx++].data = &ipvs->sysctl_sync_qlen_max;
|
|
|
|
ipvs->sysctl_sync_sock_size = 0;
|
|
|
|
tbl[idx++].data = &ipvs->sysctl_sync_sock_size;
|
2011-01-03 06:44:58 -07:00
|
|
|
tbl[idx++].data = &ipvs->sysctl_cache_bypass;
|
|
|
|
tbl[idx++].data = &ipvs->sysctl_expire_nodest_conn;
|
2013-06-13 01:56:15 -06:00
|
|
|
tbl[idx++].data = &ipvs->sysctl_sloppy_tcp;
|
|
|
|
tbl[idx++].data = &ipvs->sysctl_sloppy_sctp;
|
2011-01-03 06:44:58 -07:00
|
|
|
tbl[idx++].data = &ipvs->sysctl_expire_quiescent_template;
|
2011-02-04 02:33:01 -07:00
|
|
|
ipvs->sysctl_sync_threshold[0] = DEFAULT_SYNC_THRESHOLD;
|
|
|
|
ipvs->sysctl_sync_threshold[1] = DEFAULT_SYNC_PERIOD;
|
2011-01-03 06:44:58 -07:00
|
|
|
tbl[idx].data = &ipvs->sysctl_sync_threshold;
|
|
|
|
tbl[idx++].maxlen = sizeof(ipvs->sysctl_sync_threshold);
|
2012-04-24 14:46:40 -06:00
|
|
|
ipvs->sysctl_sync_refresh_period = DEFAULT_SYNC_REFRESH_PERIOD;
|
|
|
|
tbl[idx++].data = &ipvs->sysctl_sync_refresh_period;
|
|
|
|
ipvs->sysctl_sync_retries = clamp_t(int, DEFAULT_SYNC_RETRIES, 0, 3);
|
|
|
|
tbl[idx++].data = &ipvs->sysctl_sync_retries;
|
2011-01-03 06:44:58 -07:00
|
|
|
tbl[idx++].data = &ipvs->sysctl_nat_icmp_send;
|
2012-07-20 02:59:53 -06:00
|
|
|
ipvs->sysctl_pmtu_disc = 1;
|
|
|
|
tbl[idx++].data = &ipvs->sysctl_pmtu_disc;
|
2013-03-09 14:25:04 -07:00
|
|
|
tbl[idx++].data = &ipvs->sysctl_backup_only;
|
2011-01-03 06:44:58 -07:00
|
|
|
|
|
|
|
|
2012-04-19 07:44:49 -06:00
|
|
|
ipvs->sysctl_hdr = register_net_sysctl(net, "net/ipv4/vs", tbl);
|
2011-02-01 10:29:04 -07:00
|
|
|
if (ipvs->sysctl_hdr == NULL) {
|
|
|
|
if (!net_eq(net, &init_net))
|
|
|
|
kfree(tbl);
|
2011-02-04 02:33:02 -07:00
|
|
|
return -ENOMEM;
|
2011-02-01 10:29:04 -07:00
|
|
|
}
|
2011-03-13 17:44:28 -06:00
|
|
|
ip_vs_start_estimator(net, &ipvs->tot_stats);
|
2011-01-03 06:44:58 -07:00
|
|
|
ipvs->sysctl_tbl = tbl;
|
2011-01-03 06:44:59 -07:00
|
|
|
/* Schedule defense work */
|
|
|
|
INIT_DELAYED_WORK(&ipvs->defense_work, defense_work_handler);
|
|
|
|
schedule_delayed_work(&ipvs->defense_work, DEFENSE_TIMER_PERIOD);
|
2011-01-03 06:44:42 -07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-07-18 03:10:22 -06:00
|
|
|
static void __net_exit ip_vs_control_net_cleanup_sysctl(struct net *net)
|
2011-01-03 06:44:42 -07:00
|
|
|
{
|
2011-01-03 06:44:56 -07:00
|
|
|
struct netns_ipvs *ipvs = net_ipvs(net);
|
|
|
|
|
2011-01-03 06:45:00 -07:00
|
|
|
cancel_delayed_work_sync(&ipvs->defense_work);
|
|
|
|
cancel_work_sync(&ipvs->defense_work.work);
|
2011-01-03 06:44:58 -07:00
|
|
|
unregister_net_sysctl_table(ipvs->sysctl_hdr);
|
2014-06-12 00:17:55 -06:00
|
|
|
ip_vs_stop_estimator(net, &ipvs->tot_stats);
|
2011-02-04 02:33:02 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2012-07-18 03:10:22 -06:00
|
|
|
static int __net_init ip_vs_control_net_init_sysctl(struct net *net) { return 0; }
|
|
|
|
static void __net_exit ip_vs_control_net_cleanup_sysctl(struct net *net) { }
|
2011-02-04 02:33:02 -07:00
|
|
|
|
2011-02-01 10:29:04 -07:00
|
|
|
#endif
|
2011-02-04 02:33:02 -07:00
|
|
|
|
2011-05-03 14:09:31 -06:00
|
|
|
static struct notifier_block ip_vs_dst_notifier = {
|
|
|
|
.notifier_call = ip_vs_dst_event,
|
|
|
|
};
|
|
|
|
|
2011-05-01 10:50:16 -06:00
|
|
|
int __net_init ip_vs_control_net_init(struct net *net)
|
2011-02-04 02:33:02 -07:00
|
|
|
{
|
2013-10-07 16:51:58 -06:00
|
|
|
int i, idx;
|
2011-02-04 02:33:02 -07:00
|
|
|
struct netns_ipvs *ipvs = net_ipvs(net);
|
|
|
|
|
|
|
|
/* Initialize rs_table */
|
|
|
|
for (idx = 0; idx < IP_VS_RTAB_SIZE; idx++)
|
2013-03-21 03:58:08 -06:00
|
|
|
INIT_HLIST_HEAD(&ipvs->rs_table[idx]);
|
2011-02-04 02:33:02 -07:00
|
|
|
|
|
|
|
INIT_LIST_HEAD(&ipvs->dest_trash);
|
2013-03-22 03:46:49 -06:00
|
|
|
spin_lock_init(&ipvs->dest_trash_lock);
|
|
|
|
setup_timer(&ipvs->dest_trash_timer, ip_vs_dest_trash_expire,
|
|
|
|
(unsigned long) net);
|
2011-02-04 02:33:02 -07:00
|
|
|
atomic_set(&ipvs->ftpsvc_counter, 0);
|
|
|
|
atomic_set(&ipvs->nullsvc_counter, 0);
|
|
|
|
|
|
|
|
/* procfs stats */
|
|
|
|
ipvs->tot_stats.cpustats = alloc_percpu(struct ip_vs_cpu_stats);
|
2011-08-29 15:17:25 -06:00
|
|
|
if (!ipvs->tot_stats.cpustats)
|
2011-02-04 02:33:02 -07:00
|
|
|
return -ENOMEM;
|
2011-08-29 15:17:25 -06:00
|
|
|
|
2013-10-07 16:51:58 -06:00
|
|
|
for_each_possible_cpu(i) {
|
|
|
|
struct ip_vs_cpu_stats *ipvs_tot_stats;
|
|
|
|
ipvs_tot_stats = per_cpu_ptr(ipvs->tot_stats.cpustats, i);
|
|
|
|
u64_stats_init(&ipvs_tot_stats->syncp);
|
|
|
|
}
|
|
|
|
|
2011-02-04 02:33:02 -07:00
|
|
|
spin_lock_init(&ipvs->tot_stats.lock);
|
|
|
|
|
2013-02-17 18:34:54 -07:00
|
|
|
proc_create("ip_vs", 0, net->proc_net, &ip_vs_info_fops);
|
|
|
|
proc_create("ip_vs_stats", 0, net->proc_net, &ip_vs_stats_fops);
|
|
|
|
proc_create("ip_vs_stats_percpu", 0, net->proc_net,
|
|
|
|
&ip_vs_stats_percpu_fops);
|
2011-02-04 02:33:02 -07:00
|
|
|
|
2011-05-01 10:50:16 -06:00
|
|
|
if (ip_vs_control_net_init_sysctl(net))
|
2011-02-04 02:33:02 -07:00
|
|
|
goto err;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err:
|
2011-03-04 03:20:35 -07:00
|
|
|
free_percpu(ipvs->tot_stats.cpustats);
|
2011-01-03 06:44:42 -07:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2011-05-01 10:50:16 -06:00
|
|
|
void __net_exit ip_vs_control_net_cleanup(struct net *net)
|
2011-01-03 06:44:42 -07:00
|
|
|
{
|
2011-01-03 06:44:56 -07:00
|
|
|
struct netns_ipvs *ipvs = net_ipvs(net);
|
|
|
|
|
2011-01-03 06:45:00 -07:00
|
|
|
ip_vs_trash_cleanup(net);
|
2011-05-01 10:50:16 -06:00
|
|
|
ip_vs_control_net_cleanup_sysctl(net);
|
2013-02-17 18:34:56 -07:00
|
|
|
remove_proc_entry("ip_vs_stats_percpu", net->proc_net);
|
|
|
|
remove_proc_entry("ip_vs_stats", net->proc_net);
|
|
|
|
remove_proc_entry("ip_vs", net->proc_net);
|
2011-03-04 03:20:35 -07:00
|
|
|
free_percpu(ipvs->tot_stats.cpustats);
|
2011-01-03 06:44:42 -07:00
|
|
|
}
|
|
|
|
|
2012-04-25 23:47:44 -06:00
|
|
|
int __init ip_vs_register_nl_ioctl(void)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2011-01-03 06:44:43 -07:00
|
|
|
int ret;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
ret = nf_register_sockopt(&ip_vs_sockopts);
|
|
|
|
if (ret) {
|
2009-08-02 05:05:41 -06:00
|
|
|
pr_err("cannot register sockopt.\n");
|
2011-05-03 14:09:31 -06:00
|
|
|
goto err_sock;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2008-08-14 06:08:44 -06:00
|
|
|
ret = ip_vs_genl_register();
|
|
|
|
if (ret) {
|
2009-08-02 05:05:41 -06:00
|
|
|
pr_err("cannot register Generic Netlink interface.\n");
|
2011-05-03 14:09:31 -06:00
|
|
|
goto err_genl;
|
2008-08-14 06:08:44 -06:00
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
return 0;
|
2011-01-03 06:44:43 -07:00
|
|
|
|
2011-05-03 14:09:31 -06:00
|
|
|
err_genl:
|
|
|
|
nf_unregister_sockopt(&ip_vs_sockopts);
|
|
|
|
err_sock:
|
2011-01-03 06:44:43 -07:00
|
|
|
return ret;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2012-04-25 23:47:44 -06:00
|
|
|
void ip_vs_unregister_nl_ioctl(void)
|
|
|
|
{
|
|
|
|
ip_vs_genl_unregister();
|
|
|
|
nf_unregister_sockopt(&ip_vs_sockopts);
|
|
|
|
}
|
|
|
|
|
|
|
|
int __init ip_vs_control_init(void)
|
|
|
|
{
|
|
|
|
int idx;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
EnterFunction(2);
|
|
|
|
|
2013-03-21 03:58:08 -06:00
|
|
|
/* Initialize svc_table, ip_vs_svc_fwm_table */
|
2012-04-25 23:47:44 -06:00
|
|
|
for (idx = 0; idx < IP_VS_SVC_TAB_SIZE; idx++) {
|
2013-03-22 03:46:53 -06:00
|
|
|
INIT_HLIST_HEAD(&ip_vs_svc_table[idx]);
|
|
|
|
INIT_HLIST_HEAD(&ip_vs_svc_fwm_table[idx]);
|
2012-04-25 23:47:44 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
smp_wmb(); /* Do we really need it now ? */
|
|
|
|
|
|
|
|
ret = register_netdevice_notifier(&ip_vs_dst_notifier);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
LeaveFunction(2);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
void ip_vs_control_cleanup(void)
|
|
|
|
{
|
|
|
|
EnterFunction(2);
|
2011-05-19 06:32:57 -06:00
|
|
|
unregister_netdevice_notifier(&ip_vs_dst_notifier);
|
2005-04-16 16:20:36 -06:00
|
|
|
LeaveFunction(2);
|
|
|
|
}
|