2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* ip_vs_proto.c: transport protocol load balancing support for IPVS
|
|
|
|
*
|
|
|
|
* Authors: Wensong Zhang <wensong@linuxvirtualserver.org>
|
|
|
|
* 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 23:29:44 +02:00
|
|
|
#define KMSG_COMPONENT "IPVS"
|
|
|
|
#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
|
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/skbuff.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 09:04:11 +01:00
|
|
|
#include <linux/gfp.h>
|
2005-04-17 00:20:36 +02:00
|
|
|
#include <linux/in.h>
|
|
|
|
#include <linux/ip.h>
|
|
|
|
#include <net/protocol.h>
|
|
|
|
#include <net/tcp.h>
|
|
|
|
#include <net/udp.h>
|
|
|
|
#include <asm/system.h>
|
|
|
|
#include <linux/stat.h>
|
|
|
|
#include <linux/proc_fs.h>
|
|
|
|
|
|
|
|
#include <net/ip_vs.h>
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* IPVS protocols can only be registered/unregistered when the ipvs
|
|
|
|
* module is loaded/unloaded, so no lock is needed in accessing the
|
|
|
|
* ipvs protocol table.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define IP_VS_PROTO_TAB_SIZE 32 /* must be power of 2 */
|
|
|
|
#define IP_VS_PROTO_HASH(proto) ((proto) & (IP_VS_PROTO_TAB_SIZE-1))
|
|
|
|
|
|
|
|
static struct ip_vs_protocol *ip_vs_proto_table[IP_VS_PROTO_TAB_SIZE];
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* register an ipvs protocol
|
|
|
|
*/
|
2008-08-10 20:24:35 +02:00
|
|
|
static int __used __init register_ip_vs_protocol(struct ip_vs_protocol *pp)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
|
|
|
unsigned hash = IP_VS_PROTO_HASH(pp->protocol);
|
|
|
|
|
|
|
|
pp->next = ip_vs_proto_table[hash];
|
|
|
|
ip_vs_proto_table[hash] = pp;
|
|
|
|
|
|
|
|
if (pp->init != NULL)
|
|
|
|
pp->init(pp);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* unregister an ipvs protocol
|
|
|
|
*/
|
|
|
|
static int unregister_ip_vs_protocol(struct ip_vs_protocol *pp)
|
|
|
|
{
|
|
|
|
struct ip_vs_protocol **pp_p;
|
|
|
|
unsigned hash = IP_VS_PROTO_HASH(pp->protocol);
|
|
|
|
|
|
|
|
pp_p = &ip_vs_proto_table[hash];
|
|
|
|
for (; *pp_p; pp_p = &(*pp_p)->next) {
|
|
|
|
if (*pp_p == pp) {
|
|
|
|
*pp_p = pp->next;
|
|
|
|
if (pp->exit != NULL)
|
|
|
|
pp->exit(pp);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return -ESRCH;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* get ip_vs_protocol object by its proto.
|
|
|
|
*/
|
|
|
|
struct ip_vs_protocol * ip_vs_proto_get(unsigned short proto)
|
|
|
|
{
|
|
|
|
struct ip_vs_protocol *pp;
|
|
|
|
unsigned hash = IP_VS_PROTO_HASH(proto);
|
|
|
|
|
|
|
|
for (pp = ip_vs_proto_table[hash]; pp; pp = pp->next) {
|
|
|
|
if (pp->protocol == proto)
|
|
|
|
return pp;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
2010-07-23 12:42:58 +02:00
|
|
|
EXPORT_SYMBOL(ip_vs_proto_get);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Propagate event for state change to all protocols
|
|
|
|
*/
|
|
|
|
void ip_vs_protocol_timeout_change(int flags)
|
|
|
|
{
|
|
|
|
struct ip_vs_protocol *pp;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < IP_VS_PROTO_TAB_SIZE; i++) {
|
|
|
|
for (pp = ip_vs_proto_table[i]; pp; pp = pp->next) {
|
|
|
|
if (pp->timeout_change)
|
|
|
|
pp->timeout_change(pp, flags);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int *
|
|
|
|
ip_vs_create_timeout_table(int *table, int size)
|
|
|
|
{
|
2006-11-21 04:17:18 +01:00
|
|
|
return kmemdup(table, size, GFP_ATOMIC);
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set timeout value for state specified by name
|
|
|
|
*/
|
|
|
|
int
|
2009-08-05 19:42:58 +02:00
|
|
|
ip_vs_set_state_timeout(int *table, int num, const char *const *names,
|
|
|
|
const char *name, int to)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!table || !name || !to)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
for (i = 0; i < num; i++) {
|
|
|
|
if (strcmp(names[i], name))
|
|
|
|
continue;
|
|
|
|
table[i] = to * HZ;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const char * ip_vs_state_name(__u16 proto, int state)
|
|
|
|
{
|
|
|
|
struct ip_vs_protocol *pp = ip_vs_proto_get(proto);
|
|
|
|
|
|
|
|
if (pp == NULL || pp->state_name == NULL)
|
2008-04-29 12:21:23 +02:00
|
|
|
return (IPPROTO_IP == proto) ? "NONE" : "ERR!";
|
2005-04-17 00:20:36 +02:00
|
|
|
return pp->state_name(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-09-05 14:43:00 +02:00
|
|
|
static void
|
2008-09-02 15:55:41 +02:00
|
|
|
ip_vs_tcpudp_debug_packet_v4(struct ip_vs_protocol *pp,
|
|
|
|
const struct sk_buff *skb,
|
|
|
|
int offset,
|
|
|
|
const char *msg)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
|
|
|
char buf[128];
|
|
|
|
struct iphdr _iph, *ih;
|
|
|
|
|
|
|
|
ih = skb_header_pointer(skb, offset, sizeof(_iph), &_iph);
|
|
|
|
if (ih == NULL)
|
2010-04-08 13:35:47 +02:00
|
|
|
sprintf(buf, "TRUNCATED");
|
2007-12-11 19:53:11 +01:00
|
|
|
else if (ih->frag_off & htons(IP_OFFSET))
|
2010-04-08 13:35:47 +02:00
|
|
|
sprintf(buf, "%pI4->%pI4 frag", &ih->saddr, &ih->daddr);
|
2005-04-17 00:20:36 +02:00
|
|
|
else {
|
2010-10-17 15:46:17 +02:00
|
|
|
__be16 _ports[2], *pptr;
|
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
pptr = skb_header_pointer(skb, offset + ih->ihl*4,
|
|
|
|
sizeof(_ports), _ports);
|
|
|
|
if (pptr == NULL)
|
2010-04-08 13:35:47 +02:00
|
|
|
sprintf(buf, "TRUNCATED %pI4->%pI4",
|
|
|
|
&ih->saddr, &ih->daddr);
|
2005-04-17 00:20:36 +02:00
|
|
|
else
|
2010-04-08 13:35:47 +02:00
|
|
|
sprintf(buf, "%pI4:%u->%pI4:%u",
|
2008-10-31 08:54:29 +01:00
|
|
|
&ih->saddr, ntohs(pptr[0]),
|
|
|
|
&ih->daddr, ntohs(pptr[1]));
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
2010-04-08 13:35:47 +02:00
|
|
|
pr_debug("%s: %s %s\n", msg, pp->name, buf);
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
2008-09-02 15:55:41 +02:00
|
|
|
#ifdef CONFIG_IP_VS_IPV6
|
2008-09-05 14:43:00 +02:00
|
|
|
static void
|
2008-09-02 15:55:41 +02:00
|
|
|
ip_vs_tcpudp_debug_packet_v6(struct ip_vs_protocol *pp,
|
|
|
|
const struct sk_buff *skb,
|
|
|
|
int offset,
|
|
|
|
const char *msg)
|
|
|
|
{
|
|
|
|
char buf[192];
|
|
|
|
struct ipv6hdr _iph, *ih;
|
|
|
|
|
|
|
|
ih = skb_header_pointer(skb, offset, sizeof(_iph), &_iph);
|
|
|
|
if (ih == NULL)
|
2010-04-08 13:35:47 +02:00
|
|
|
sprintf(buf, "TRUNCATED");
|
2008-09-02 15:55:41 +02:00
|
|
|
else if (ih->nexthdr == IPPROTO_FRAGMENT)
|
2010-04-08 13:35:47 +02:00
|
|
|
sprintf(buf, "%pI6->%pI6 frag", &ih->saddr, &ih->daddr);
|
2008-09-02 15:55:41 +02:00
|
|
|
else {
|
|
|
|
__be16 _ports[2], *pptr;
|
|
|
|
|
|
|
|
pptr = skb_header_pointer(skb, offset + sizeof(struct ipv6hdr),
|
|
|
|
sizeof(_ports), _ports);
|
|
|
|
if (pptr == NULL)
|
2010-04-08 13:35:47 +02:00
|
|
|
sprintf(buf, "TRUNCATED %pI6->%pI6",
|
|
|
|
&ih->saddr, &ih->daddr);
|
2008-09-02 15:55:41 +02:00
|
|
|
else
|
2010-04-08 13:35:47 +02:00
|
|
|
sprintf(buf, "%pI6:%u->%pI6:%u",
|
2008-10-29 00:08:13 +01:00
|
|
|
&ih->saddr, ntohs(pptr[0]),
|
|
|
|
&ih->daddr, ntohs(pptr[1]));
|
2008-09-02 15:55:41 +02:00
|
|
|
}
|
|
|
|
|
2010-04-08 13:35:47 +02:00
|
|
|
pr_debug("%s: %s %s\n", msg, pp->name, buf);
|
2008-09-02 15:55:41 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2010-10-17 15:46:17 +02:00
|
|
|
ip_vs_tcpudp_debug_packet(int af, struct ip_vs_protocol *pp,
|
2008-09-02 15:55:41 +02:00
|
|
|
const struct sk_buff *skb,
|
|
|
|
int offset,
|
|
|
|
const char *msg)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_IP_VS_IPV6
|
2010-10-17 15:46:17 +02:00
|
|
|
if (af == AF_INET6)
|
2008-09-02 15:55:41 +02:00
|
|
|
ip_vs_tcpudp_debug_packet_v6(pp, skb, offset, msg);
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
ip_vs_tcpudp_debug_packet_v4(pp, skb, offset, msg);
|
|
|
|
}
|
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2008-08-10 20:24:35 +02:00
|
|
|
int __init ip_vs_protocol_init(void)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
|
|
|
char protocols[64];
|
|
|
|
#define REGISTER_PROTOCOL(p) \
|
|
|
|
do { \
|
|
|
|
register_ip_vs_protocol(p); \
|
|
|
|
strcat(protocols, ", "); \
|
|
|
|
strcat(protocols, (p)->name); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
protocols[0] = '\0';
|
|
|
|
protocols[2] = '\0';
|
|
|
|
#ifdef CONFIG_IP_VS_PROTO_TCP
|
|
|
|
REGISTER_PROTOCOL(&ip_vs_protocol_tcp);
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_IP_VS_PROTO_UDP
|
|
|
|
REGISTER_PROTOCOL(&ip_vs_protocol_udp);
|
|
|
|
#endif
|
2010-02-18 12:31:05 +01:00
|
|
|
#ifdef CONFIG_IP_VS_PROTO_SCTP
|
|
|
|
REGISTER_PROTOCOL(&ip_vs_protocol_sctp);
|
|
|
|
#endif
|
2005-04-17 00:20:36 +02:00
|
|
|
#ifdef CONFIG_IP_VS_PROTO_AH
|
|
|
|
REGISTER_PROTOCOL(&ip_vs_protocol_ah);
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_IP_VS_PROTO_ESP
|
|
|
|
REGISTER_PROTOCOL(&ip_vs_protocol_esp);
|
|
|
|
#endif
|
2009-08-02 13:05:41 +02:00
|
|
|
pr_info("Registered protocols (%s)\n", &protocols[2]);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ip_vs_protocol_cleanup(void)
|
|
|
|
{
|
|
|
|
struct ip_vs_protocol *pp;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* unregister all the ipvs protocols */
|
|
|
|
for (i = 0; i < IP_VS_PROTO_TAB_SIZE; i++) {
|
|
|
|
while ((pp = ip_vs_proto_table[i]) != NULL)
|
|
|
|
unregister_ip_vs_protocol(pp);
|
|
|
|
}
|
|
|
|
}
|