2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* ip_vs_app.c: Application module support for IPVS
|
|
|
|
*
|
|
|
|
* Authors: Wensong Zhang <wensong@linuxvirtualserver.org>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* Most code here is taken from ip_masq_app.c in kernel 2.2. The difference
|
|
|
|
* is that ip_vs_app module handles the reverse direction (incoming requests
|
|
|
|
* and outgoing responses).
|
|
|
|
*
|
|
|
|
* IP_MASQ_APP application masquerading module
|
|
|
|
*
|
|
|
|
* Author: Juan Jose Ciarlante, <jjciarla@raiz.uncu.edu.ar>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
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 <linux/in.h>
|
|
|
|
#include <linux/ip.h>
|
2007-10-14 09:39:33 +02:00
|
|
|
#include <linux/netfilter.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/slab.h>
|
2007-09-12 12:01:34 +02:00
|
|
|
#include <net/net_namespace.h>
|
2005-04-17 00:20:36 +02:00
|
|
|
#include <net/protocol.h>
|
2005-08-10 05:08:28 +02:00
|
|
|
#include <net/tcp.h>
|
2005-04-17 00:20:36 +02:00
|
|
|
#include <linux/stat.h>
|
|
|
|
#include <linux/proc_fs.h>
|
|
|
|
#include <linux/seq_file.h>
|
2006-03-21 07:35:41 +01:00
|
|
|
#include <linux/mutex.h>
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
#include <net/ip_vs.h>
|
|
|
|
|
|
|
|
EXPORT_SYMBOL(register_ip_vs_app);
|
|
|
|
EXPORT_SYMBOL(unregister_ip_vs_app);
|
|
|
|
EXPORT_SYMBOL(register_ip_vs_app_inc);
|
|
|
|
|
2011-03-21 16:18:01 +01:00
|
|
|
static DEFINE_MUTEX(__ip_vs_app_mutex);
|
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* Get an ip_vs_app object
|
|
|
|
*/
|
|
|
|
static inline int ip_vs_app_get(struct ip_vs_app *app)
|
|
|
|
{
|
2007-11-20 07:52:41 +01:00
|
|
|
return try_module_get(app->module);
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static inline void ip_vs_app_put(struct ip_vs_app *app)
|
|
|
|
{
|
2007-11-20 07:52:41 +01:00
|
|
|
module_put(app->module);
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate/initialize app incarnation and register it in proto apps.
|
|
|
|
*/
|
|
|
|
static int
|
2011-01-03 14:44:53 +01:00
|
|
|
ip_vs_app_inc_new(struct net *net, struct ip_vs_app *app, __u16 proto,
|
|
|
|
__u16 port)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
|
|
|
struct ip_vs_protocol *pp;
|
|
|
|
struct ip_vs_app *inc;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!(pp = ip_vs_proto_get(proto)))
|
|
|
|
return -EPROTONOSUPPORT;
|
|
|
|
|
|
|
|
if (!pp->unregister_app)
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
|
2006-11-21 04:17:18 +01:00
|
|
|
inc = kmemdup(app, sizeof(*inc), GFP_KERNEL);
|
2005-04-17 00:20:36 +02:00
|
|
|
if (!inc)
|
|
|
|
return -ENOMEM;
|
|
|
|
INIT_LIST_HEAD(&inc->p_list);
|
|
|
|
INIT_LIST_HEAD(&inc->incs_list);
|
|
|
|
inc->app = app;
|
|
|
|
inc->port = htons(port);
|
|
|
|
atomic_set(&inc->usecnt, 0);
|
|
|
|
|
|
|
|
if (app->timeouts) {
|
|
|
|
inc->timeout_table =
|
|
|
|
ip_vs_create_timeout_table(app->timeouts,
|
|
|
|
app->timeouts_size);
|
|
|
|
if (!inc->timeout_table) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-03 14:44:53 +01:00
|
|
|
ret = pp->register_app(net, inc);
|
2005-04-17 00:20:36 +02:00
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
list_add(&inc->a_list, &app->incs_list);
|
2010-09-21 18:12:30 +02:00
|
|
|
IP_VS_DBG(9, "%s App %s:%u registered\n",
|
|
|
|
pp->name, inc->name, ntohs(inc->port));
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
out:
|
2005-11-08 18:41:34 +01:00
|
|
|
kfree(inc->timeout_table);
|
2005-04-17 00:20:36 +02:00
|
|
|
kfree(inc);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Release app incarnation
|
|
|
|
*/
|
|
|
|
static void
|
2011-01-03 14:44:53 +01:00
|
|
|
ip_vs_app_inc_release(struct net *net, struct ip_vs_app *inc)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
|
|
|
struct ip_vs_protocol *pp;
|
|
|
|
|
|
|
|
if (!(pp = ip_vs_proto_get(inc->protocol)))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (pp->unregister_app)
|
2011-01-03 14:44:53 +01:00
|
|
|
pp->unregister_app(net, inc);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
IP_VS_DBG(9, "%s App %s:%u unregistered\n",
|
2010-09-21 18:12:30 +02:00
|
|
|
pp->name, inc->name, ntohs(inc->port));
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
list_del(&inc->a_list);
|
|
|
|
|
2005-11-08 18:41:34 +01:00
|
|
|
kfree(inc->timeout_table);
|
2005-04-17 00:20:36 +02:00
|
|
|
kfree(inc);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get reference to app inc (only called from softirq)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
int ip_vs_app_inc_get(struct ip_vs_app *inc)
|
|
|
|
{
|
|
|
|
int result;
|
|
|
|
|
|
|
|
atomic_inc(&inc->usecnt);
|
|
|
|
if (unlikely((result = ip_vs_app_get(inc->app)) != 1))
|
|
|
|
atomic_dec(&inc->usecnt);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Put the app inc (only called from timer or net softirq)
|
|
|
|
*/
|
|
|
|
void ip_vs_app_inc_put(struct ip_vs_app *inc)
|
|
|
|
{
|
|
|
|
ip_vs_app_put(inc->app);
|
|
|
|
atomic_dec(&inc->usecnt);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Register an application incarnation in protocol applications
|
|
|
|
*/
|
|
|
|
int
|
2011-01-03 14:44:53 +01:00
|
|
|
register_ip_vs_app_inc(struct net *net, struct ip_vs_app *app, __u16 proto,
|
|
|
|
__u16 port)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
|
|
|
int result;
|
|
|
|
|
2011-03-21 16:18:01 +01:00
|
|
|
mutex_lock(&__ip_vs_app_mutex);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2011-01-03 14:44:53 +01:00
|
|
|
result = ip_vs_app_inc_new(net, app, proto, port);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2011-03-21 16:18:01 +01:00
|
|
|
mutex_unlock(&__ip_vs_app_mutex);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ip_vs_app registration routine
|
|
|
|
*/
|
2011-01-03 14:44:53 +01:00
|
|
|
int register_ip_vs_app(struct net *net, struct ip_vs_app *app)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
2011-01-03 14:44:53 +01:00
|
|
|
struct netns_ipvs *ipvs = net_ipvs(net);
|
2005-04-17 00:20:36 +02:00
|
|
|
/* increase the module use count */
|
|
|
|
ip_vs_use_count_inc();
|
|
|
|
|
2011-03-21 16:18:01 +01:00
|
|
|
mutex_lock(&__ip_vs_app_mutex);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2011-01-03 14:44:53 +01:00
|
|
|
list_add(&app->a_list, &ipvs->app_list);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2011-03-21 16:18:01 +01:00
|
|
|
mutex_unlock(&__ip_vs_app_mutex);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ip_vs_app unregistration routine
|
|
|
|
* We are sure there are no app incarnations attached to services
|
|
|
|
*/
|
2011-01-03 14:44:53 +01:00
|
|
|
void unregister_ip_vs_app(struct net *net, struct ip_vs_app *app)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
|
|
|
struct ip_vs_app *inc, *nxt;
|
|
|
|
|
2011-03-21 16:18:01 +01:00
|
|
|
mutex_lock(&__ip_vs_app_mutex);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
list_for_each_entry_safe(inc, nxt, &app->incs_list, a_list) {
|
2011-01-03 14:44:53 +01:00
|
|
|
ip_vs_app_inc_release(net, inc);
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
list_del(&app->a_list);
|
|
|
|
|
2011-03-21 16:18:01 +01:00
|
|
|
mutex_unlock(&__ip_vs_app_mutex);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
/* decrease the module use count */
|
|
|
|
ip_vs_use_count_dec();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Bind ip_vs_conn to its ip_vs_app (called by cp constructor)
|
|
|
|
*/
|
2011-01-03 14:44:53 +01:00
|
|
|
int ip_vs_bind_app(struct ip_vs_conn *cp,
|
|
|
|
struct ip_vs_protocol *pp)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
|
|
|
return pp->app_conn_bind(cp);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Unbind cp from application incarnation (called by cp destructor)
|
|
|
|
*/
|
|
|
|
void ip_vs_unbind_app(struct ip_vs_conn *cp)
|
|
|
|
{
|
|
|
|
struct ip_vs_app *inc = cp->app;
|
|
|
|
|
|
|
|
if (!inc)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (inc->unbind_conn)
|
|
|
|
inc->unbind_conn(inc, cp);
|
|
|
|
if (inc->done_conn)
|
|
|
|
inc->done_conn(inc, cp);
|
|
|
|
ip_vs_app_inc_put(inc);
|
|
|
|
cp->app = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Fixes th->seq based on ip_vs_seq info.
|
|
|
|
*/
|
|
|
|
static inline void vs_fix_seq(const struct ip_vs_seq *vseq, struct tcphdr *th)
|
|
|
|
{
|
|
|
|
__u32 seq = ntohl(th->seq);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Adjust seq with delta-offset for all packets after
|
|
|
|
* the most recent resized pkt seq and with previous_delta offset
|
|
|
|
* for all packets before most recent resized pkt seq.
|
|
|
|
*/
|
|
|
|
if (vseq->delta || vseq->previous_delta) {
|
|
|
|
if(after(seq, vseq->init_seq)) {
|
|
|
|
th->seq = htonl(seq + vseq->delta);
|
2009-08-02 13:05:41 +02:00
|
|
|
IP_VS_DBG(9, "%s(): added delta (%d) to seq\n",
|
|
|
|
__func__, vseq->delta);
|
2005-04-17 00:20:36 +02:00
|
|
|
} else {
|
|
|
|
th->seq = htonl(seq + vseq->previous_delta);
|
2009-08-02 13:05:41 +02:00
|
|
|
IP_VS_DBG(9, "%s(): added previous_delta (%d) to seq\n",
|
|
|
|
__func__, vseq->previous_delta);
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Fixes th->ack_seq based on ip_vs_seq info.
|
|
|
|
*/
|
|
|
|
static inline void
|
|
|
|
vs_fix_ack_seq(const struct ip_vs_seq *vseq, struct tcphdr *th)
|
|
|
|
{
|
|
|
|
__u32 ack_seq = ntohl(th->ack_seq);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Adjust ack_seq with delta-offset for
|
|
|
|
* the packets AFTER most recent resized pkt has caused a shift
|
|
|
|
* for packets before most recent resized pkt, use previous_delta
|
|
|
|
*/
|
|
|
|
if (vseq->delta || vseq->previous_delta) {
|
|
|
|
/* since ack_seq is the number of octet that is expected
|
|
|
|
to receive next, so compare it with init_seq+delta */
|
|
|
|
if(after(ack_seq, vseq->init_seq+vseq->delta)) {
|
|
|
|
th->ack_seq = htonl(ack_seq - vseq->delta);
|
2009-08-02 13:05:41 +02:00
|
|
|
IP_VS_DBG(9, "%s(): subtracted delta "
|
|
|
|
"(%d) from ack_seq\n", __func__, vseq->delta);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
} else {
|
|
|
|
th->ack_seq = htonl(ack_seq - vseq->previous_delta);
|
2009-08-02 13:05:41 +02:00
|
|
|
IP_VS_DBG(9, "%s(): subtracted "
|
2005-04-17 00:20:36 +02:00
|
|
|
"previous_delta (%d) from ack_seq\n",
|
2009-08-02 13:05:41 +02:00
|
|
|
__func__, vseq->previous_delta);
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Updates ip_vs_seq if pkt has been resized
|
|
|
|
* Assumes already checked proto==IPPROTO_TCP and diff!=0.
|
|
|
|
*/
|
|
|
|
static inline void vs_seq_update(struct ip_vs_conn *cp, struct ip_vs_seq *vseq,
|
|
|
|
unsigned flag, __u32 seq, int diff)
|
|
|
|
{
|
|
|
|
/* spinlock is to keep updating cp->flags atomic */
|
|
|
|
spin_lock(&cp->lock);
|
|
|
|
if (!(cp->flags & flag) || after(seq, vseq->init_seq)) {
|
|
|
|
vseq->previous_delta = vseq->delta;
|
|
|
|
vseq->delta += diff;
|
|
|
|
vseq->init_seq = seq;
|
|
|
|
cp->flags |= flag;
|
|
|
|
}
|
|
|
|
spin_unlock(&cp->lock);
|
|
|
|
}
|
|
|
|
|
2007-10-15 09:53:15 +02:00
|
|
|
static inline int app_tcp_pkt_out(struct ip_vs_conn *cp, struct sk_buff *skb,
|
2005-04-17 00:20:36 +02:00
|
|
|
struct ip_vs_app *app)
|
|
|
|
{
|
|
|
|
int diff;
|
2007-10-15 09:53:15 +02:00
|
|
|
const unsigned int tcp_offset = ip_hdrlen(skb);
|
2005-04-17 00:20:36 +02:00
|
|
|
struct tcphdr *th;
|
|
|
|
__u32 seq;
|
|
|
|
|
2007-10-15 09:53:15 +02:00
|
|
|
if (!skb_make_writable(skb, tcp_offset + sizeof(*th)))
|
2005-04-17 00:20:36 +02:00
|
|
|
return 0;
|
|
|
|
|
2007-10-15 09:53:15 +02:00
|
|
|
th = (struct tcphdr *)(skb_network_header(skb) + tcp_offset);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Remember seq number in case this pkt gets resized
|
|
|
|
*/
|
|
|
|
seq = ntohl(th->seq);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Fix seq stuff if flagged as so.
|
|
|
|
*/
|
|
|
|
if (cp->flags & IP_VS_CONN_F_OUT_SEQ)
|
|
|
|
vs_fix_seq(&cp->out_seq, th);
|
|
|
|
if (cp->flags & IP_VS_CONN_F_IN_SEQ)
|
|
|
|
vs_fix_ack_seq(&cp->in_seq, th);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Call private output hook function
|
|
|
|
*/
|
|
|
|
if (app->pkt_out == NULL)
|
|
|
|
return 1;
|
|
|
|
|
2007-10-15 09:53:15 +02:00
|
|
|
if (!app->pkt_out(app, cp, skb, &diff))
|
2005-04-17 00:20:36 +02:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Update ip_vs seq stuff if len has changed.
|
|
|
|
*/
|
|
|
|
if (diff != 0)
|
|
|
|
vs_seq_update(cp, &cp->out_seq,
|
|
|
|
IP_VS_CONN_F_OUT_SEQ, seq, diff);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Output pkt hook. Will call bound ip_vs_app specific function
|
|
|
|
* called by ipvs packet handler, assumes previously checked cp!=NULL
|
|
|
|
* returns false if it can't handle packet (oom)
|
|
|
|
*/
|
2007-10-15 09:53:15 +02:00
|
|
|
int ip_vs_app_pkt_out(struct ip_vs_conn *cp, struct sk_buff *skb)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
|
|
|
struct ip_vs_app *app;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* check if application module is bound to
|
|
|
|
* this ip_vs_conn.
|
|
|
|
*/
|
|
|
|
if ((app = cp->app) == NULL)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
/* TCP is complicated */
|
|
|
|
if (cp->protocol == IPPROTO_TCP)
|
2007-10-15 09:53:15 +02:00
|
|
|
return app_tcp_pkt_out(cp, skb, app);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Call private output hook function
|
|
|
|
*/
|
|
|
|
if (app->pkt_out == NULL)
|
|
|
|
return 1;
|
|
|
|
|
2007-10-15 09:53:15 +02:00
|
|
|
return app->pkt_out(app, cp, skb, NULL);
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-15 09:53:15 +02:00
|
|
|
static inline int app_tcp_pkt_in(struct ip_vs_conn *cp, struct sk_buff *skb,
|
2005-04-17 00:20:36 +02:00
|
|
|
struct ip_vs_app *app)
|
|
|
|
{
|
|
|
|
int diff;
|
2007-10-15 09:53:15 +02:00
|
|
|
const unsigned int tcp_offset = ip_hdrlen(skb);
|
2005-04-17 00:20:36 +02:00
|
|
|
struct tcphdr *th;
|
|
|
|
__u32 seq;
|
|
|
|
|
2007-10-15 09:53:15 +02:00
|
|
|
if (!skb_make_writable(skb, tcp_offset + sizeof(*th)))
|
2005-04-17 00:20:36 +02:00
|
|
|
return 0;
|
|
|
|
|
2007-10-15 09:53:15 +02:00
|
|
|
th = (struct tcphdr *)(skb_network_header(skb) + tcp_offset);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Remember seq number in case this pkt gets resized
|
|
|
|
*/
|
|
|
|
seq = ntohl(th->seq);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Fix seq stuff if flagged as so.
|
|
|
|
*/
|
|
|
|
if (cp->flags & IP_VS_CONN_F_IN_SEQ)
|
|
|
|
vs_fix_seq(&cp->in_seq, th);
|
|
|
|
if (cp->flags & IP_VS_CONN_F_OUT_SEQ)
|
|
|
|
vs_fix_ack_seq(&cp->out_seq, th);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Call private input hook function
|
|
|
|
*/
|
|
|
|
if (app->pkt_in == NULL)
|
|
|
|
return 1;
|
|
|
|
|
2007-10-15 09:53:15 +02:00
|
|
|
if (!app->pkt_in(app, cp, skb, &diff))
|
2005-04-17 00:20:36 +02:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Update ip_vs seq stuff if len has changed.
|
|
|
|
*/
|
|
|
|
if (diff != 0)
|
|
|
|
vs_seq_update(cp, &cp->in_seq,
|
|
|
|
IP_VS_CONN_F_IN_SEQ, seq, diff);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Input pkt hook. Will call bound ip_vs_app specific function
|
|
|
|
* called by ipvs packet handler, assumes previously checked cp!=NULL.
|
|
|
|
* returns false if can't handle packet (oom).
|
|
|
|
*/
|
2007-10-15 09:53:15 +02:00
|
|
|
int ip_vs_app_pkt_in(struct ip_vs_conn *cp, struct sk_buff *skb)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
|
|
|
struct ip_vs_app *app;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* check if application module is bound to
|
|
|
|
* this ip_vs_conn.
|
|
|
|
*/
|
|
|
|
if ((app = cp->app) == NULL)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
/* TCP is complicated */
|
|
|
|
if (cp->protocol == IPPROTO_TCP)
|
2007-10-15 09:53:15 +02:00
|
|
|
return app_tcp_pkt_in(cp, skb, app);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Call private input hook function
|
|
|
|
*/
|
|
|
|
if (app->pkt_in == NULL)
|
|
|
|
return 1;
|
|
|
|
|
2007-10-15 09:53:15 +02:00
|
|
|
return app->pkt_in(app, cp, skb, NULL);
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef CONFIG_PROC_FS
|
|
|
|
/*
|
|
|
|
* /proc/net/ip_vs_app entry function
|
|
|
|
*/
|
|
|
|
|
2011-01-03 14:44:53 +01:00
|
|
|
static struct ip_vs_app *ip_vs_app_idx(struct netns_ipvs *ipvs, loff_t pos)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
|
|
|
struct ip_vs_app *app, *inc;
|
|
|
|
|
2011-01-03 14:44:53 +01:00
|
|
|
list_for_each_entry(app, &ipvs->app_list, a_list) {
|
2005-04-17 00:20:36 +02:00
|
|
|
list_for_each_entry(inc, &app->incs_list, a_list) {
|
|
|
|
if (pos-- == 0)
|
|
|
|
return inc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *ip_vs_app_seq_start(struct seq_file *seq, loff_t *pos)
|
|
|
|
{
|
2011-01-03 14:44:53 +01:00
|
|
|
struct net *net = seq_file_net(seq);
|
|
|
|
struct netns_ipvs *ipvs = net_ipvs(net);
|
|
|
|
|
2011-03-21 16:18:01 +01:00
|
|
|
mutex_lock(&__ip_vs_app_mutex);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2011-01-03 14:44:53 +01:00
|
|
|
return *pos ? ip_vs_app_idx(ipvs, *pos - 1) : SEQ_START_TOKEN;
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void *ip_vs_app_seq_next(struct seq_file *seq, void *v, loff_t *pos)
|
|
|
|
{
|
|
|
|
struct ip_vs_app *inc, *app;
|
|
|
|
struct list_head *e;
|
2011-01-03 14:44:53 +01:00
|
|
|
struct net *net = seq_file_net(seq);
|
|
|
|
struct netns_ipvs *ipvs = net_ipvs(net);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
++*pos;
|
|
|
|
if (v == SEQ_START_TOKEN)
|
2011-01-03 14:44:53 +01:00
|
|
|
return ip_vs_app_idx(ipvs, 0);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
inc = v;
|
|
|
|
app = inc->app;
|
|
|
|
|
|
|
|
if ((e = inc->a_list.next) != &app->incs_list)
|
|
|
|
return list_entry(e, struct ip_vs_app, a_list);
|
|
|
|
|
|
|
|
/* go on to next application */
|
2011-01-03 14:44:53 +01:00
|
|
|
for (e = app->a_list.next; e != &ipvs->app_list; e = e->next) {
|
2005-04-17 00:20:36 +02:00
|
|
|
app = list_entry(e, struct ip_vs_app, a_list);
|
|
|
|
list_for_each_entry(inc, &app->incs_list, a_list) {
|
|
|
|
return inc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ip_vs_app_seq_stop(struct seq_file *seq, void *v)
|
|
|
|
{
|
2011-03-21 16:18:01 +01:00
|
|
|
mutex_unlock(&__ip_vs_app_mutex);
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static int ip_vs_app_seq_show(struct seq_file *seq, void *v)
|
|
|
|
{
|
|
|
|
if (v == SEQ_START_TOKEN)
|
|
|
|
seq_puts(seq, "prot port usecnt name\n");
|
|
|
|
else {
|
|
|
|
const struct ip_vs_app *inc = v;
|
|
|
|
|
|
|
|
seq_printf(seq, "%-3s %-7u %-6d %-17s\n",
|
|
|
|
ip_vs_proto_name(inc->protocol),
|
|
|
|
ntohs(inc->port),
|
|
|
|
atomic_read(&inc->usecnt),
|
|
|
|
inc->name);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-07-11 08:07:31 +02:00
|
|
|
static const struct seq_operations ip_vs_app_seq_ops = {
|
2005-04-17 00:20:36 +02:00
|
|
|
.start = ip_vs_app_seq_start,
|
|
|
|
.next = ip_vs_app_seq_next,
|
|
|
|
.stop = ip_vs_app_seq_stop,
|
|
|
|
.show = ip_vs_app_seq_show,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int ip_vs_app_open(struct inode *inode, struct file *file)
|
|
|
|
{
|
2011-01-03 14:44:53 +01:00
|
|
|
return seq_open_net(inode, file, &ip_vs_app_seq_ops,
|
|
|
|
sizeof(struct seq_net_private));
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
2007-02-12 09:55:35 +01:00
|
|
|
static const struct file_operations ip_vs_app_fops = {
|
2005-04-17 00:20:36 +02:00
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.open = ip_vs_app_open,
|
|
|
|
.read = seq_read,
|
|
|
|
.llseek = seq_lseek,
|
2011-05-15 17:20:29 +02:00
|
|
|
.release = seq_release_net,
|
2005-04-17 00:20:36 +02:00
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2011-05-01 18:50:16 +02:00
|
|
|
int __net_init ip_vs_app_net_init(struct net *net)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
2011-01-03 14:44:53 +01:00
|
|
|
struct netns_ipvs *ipvs = net_ipvs(net);
|
|
|
|
|
|
|
|
INIT_LIST_HEAD(&ipvs->app_list);
|
2011-01-03 14:44:42 +01:00
|
|
|
proc_net_fops_create(net, "ip_vs_app", 0, &ip_vs_app_fops);
|
2005-04-17 00:20:36 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-05-01 18:50:16 +02:00
|
|
|
void __net_exit ip_vs_app_net_cleanup(struct net *net)
|
2011-01-03 14:44:42 +01:00
|
|
|
{
|
|
|
|
proc_net_remove(net, "ip_vs_app");
|
|
|
|
}
|