2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* net/sched/em_meta.c Metadata ematch
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* Authors: Thomas Graf <tgraf@suug.ch>
|
|
|
|
*
|
|
|
|
* ==========================================================================
|
2007-02-09 22:25:16 +08:00
|
|
|
*
|
2005-04-17 06:20:36 +08:00
|
|
|
* The metadata ematch compares two meta objects where each object
|
|
|
|
* represents either a meta value stored in the kernel or a static
|
|
|
|
* value provided by userspace. The objects are not provided by
|
|
|
|
* userspace itself but rather a definition providing the information
|
|
|
|
* to build them. Every object is of a certain type which must be
|
|
|
|
* equal to the object it is being compared to.
|
|
|
|
*
|
|
|
|
* The definition of a objects conists of the type (meta type), a
|
|
|
|
* identifier (meta id) and additional type specific information.
|
|
|
|
* The meta id is either TCF_META_TYPE_VALUE for values provided by
|
|
|
|
* userspace or a index to the meta operations table consisting of
|
|
|
|
* function pointers to type specific meta data collectors returning
|
|
|
|
* the value of the requested meta value.
|
|
|
|
*
|
|
|
|
* lvalue rvalue
|
|
|
|
* +-----------+ +-----------+
|
|
|
|
* | type: INT | | type: INT |
|
2005-07-23 05:43:52 +08:00
|
|
|
* def | id: DEV | | id: VALUE |
|
2005-04-17 06:20:36 +08:00
|
|
|
* | data: | | data: 3 |
|
|
|
|
* +-----------+ +-----------+
|
|
|
|
* | |
|
2005-07-23 05:43:52 +08:00
|
|
|
* ---> meta_ops[INT][DEV](...) |
|
2005-06-09 06:10:48 +08:00
|
|
|
* | |
|
2005-04-17 06:20:36 +08:00
|
|
|
* ----------- |
|
|
|
|
* V V
|
|
|
|
* +-----------+ +-----------+
|
|
|
|
* | type: INT | | type: INT |
|
2005-07-23 05:43:52 +08:00
|
|
|
* obj | id: DEV | | id: VALUE |
|
2005-04-17 06:20:36 +08:00
|
|
|
* | data: 2 |<--data got filled out | data: 3 |
|
|
|
|
* +-----------+ +-----------+
|
|
|
|
* | |
|
|
|
|
* --------------> 2 equals 3 <--------------
|
|
|
|
*
|
|
|
|
* This is a simplified schema, the complexity varies depending
|
|
|
|
* on the meta type. Obviously, the length of the data must also
|
|
|
|
* be provided for non-numeric types.
|
|
|
|
*
|
2011-03-31 09:57:33 +08:00
|
|
|
* Additionally, type dependent modifiers such as shift operators
|
2005-04-17 06:20:36 +08:00
|
|
|
* or mask may be applied to extend the functionaliy. As of now,
|
|
|
|
* the variable length type supports shifting the byte string to
|
|
|
|
* the right, eating up any number of octets and thus supporting
|
|
|
|
* wildcard interface name comparisons such as "ppp%" matching
|
|
|
|
* ppp0..9.
|
|
|
|
*
|
|
|
|
* NOTE: Certain meta values depend on other subsystems and are
|
2007-10-20 05:10:43 +08:00
|
|
|
* only available if that subsystem is enabled in the kernel.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
|
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 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/sched.h>
|
2017-02-08 15:45:17 +08:00
|
|
|
#include <linux/sched/loadavg.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/skbuff.h>
|
|
|
|
#include <linux/random.h>
|
2008-02-05 19:20:13 +08:00
|
|
|
#include <linux/if_vlan.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/tc_ematch/tc_em_meta.h>
|
|
|
|
#include <net/dst.h>
|
|
|
|
#include <net/route.h>
|
|
|
|
#include <net/pkt_cls.h>
|
2005-06-09 06:10:48 +08:00
|
|
|
#include <net/sock.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2011-01-20 03:26:56 +08:00
|
|
|
struct meta_obj {
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned long value;
|
|
|
|
unsigned int len;
|
|
|
|
};
|
|
|
|
|
2011-01-20 03:26:56 +08:00
|
|
|
struct meta_value {
|
2005-04-17 06:20:36 +08:00
|
|
|
struct tcf_meta_val hdr;
|
|
|
|
unsigned long val;
|
|
|
|
unsigned int len;
|
|
|
|
};
|
|
|
|
|
2011-01-20 03:26:56 +08:00
|
|
|
struct meta_match {
|
2005-04-17 06:20:36 +08:00
|
|
|
struct meta_value lvalue;
|
|
|
|
struct meta_value rvalue;
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline int meta_id(struct meta_value *v)
|
|
|
|
{
|
|
|
|
return TCF_META_ID(v->hdr.kind);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int meta_type(struct meta_value *v)
|
|
|
|
{
|
|
|
|
return TCF_META_TYPE(v->hdr.kind);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define META_COLLECTOR(FUNC) static void meta_##FUNC(struct sk_buff *skb, \
|
|
|
|
struct tcf_pkt_info *info, struct meta_value *v, \
|
|
|
|
struct meta_obj *dst, int *err)
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* System status & misc
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
META_COLLECTOR(int_random)
|
|
|
|
{
|
|
|
|
get_random_bytes(&dst->value, sizeof(dst->value));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline unsigned long fixed_loadavg(int load)
|
|
|
|
{
|
|
|
|
int rnd_load = load + (FIXED_1/200);
|
|
|
|
int rnd_frac = ((rnd_load & (FIXED_1-1)) * 100) >> FSHIFT;
|
|
|
|
|
|
|
|
return ((rnd_load >> FSHIFT) * 100) + rnd_frac;
|
|
|
|
}
|
|
|
|
|
|
|
|
META_COLLECTOR(int_loadavg_0)
|
|
|
|
{
|
|
|
|
dst->value = fixed_loadavg(avenrun[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
META_COLLECTOR(int_loadavg_1)
|
|
|
|
{
|
|
|
|
dst->value = fixed_loadavg(avenrun[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
META_COLLECTOR(int_loadavg_2)
|
|
|
|
{
|
|
|
|
dst->value = fixed_loadavg(avenrun[2]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* Device names & indices
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
static inline int int_dev(struct net_device *dev, struct meta_obj *dst)
|
|
|
|
{
|
|
|
|
if (unlikely(dev == NULL))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
dst->value = dev->ifindex;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int var_dev(struct net_device *dev, struct meta_obj *dst)
|
|
|
|
{
|
|
|
|
if (unlikely(dev == NULL))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
dst->value = (unsigned long) dev->name;
|
|
|
|
dst->len = strlen(dev->name);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
META_COLLECTOR(int_dev)
|
|
|
|
{
|
|
|
|
*err = int_dev(skb->dev, dst);
|
|
|
|
}
|
|
|
|
|
|
|
|
META_COLLECTOR(var_dev)
|
|
|
|
{
|
|
|
|
*err = var_dev(skb->dev, dst);
|
|
|
|
}
|
|
|
|
|
2008-02-05 19:20:13 +08:00
|
|
|
/**************************************************************************
|
|
|
|
* vlan tag
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
META_COLLECTOR(int_vlan_tag)
|
|
|
|
{
|
2009-04-14 09:12:57 +08:00
|
|
|
unsigned short tag;
|
|
|
|
|
2016-10-21 05:18:08 +08:00
|
|
|
if (skb_vlan_tag_present(skb))
|
|
|
|
dst->value = skb_vlan_tag_get(skb);
|
|
|
|
else if (!__vlan_get_tag(skb, &tag))
|
2008-02-05 19:20:13 +08:00
|
|
|
dst->value = tag;
|
2016-10-21 05:18:08 +08:00
|
|
|
else
|
|
|
|
*err = -1;
|
2008-02-05 19:20:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/**************************************************************************
|
|
|
|
* skb attributes
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
META_COLLECTOR(int_priority)
|
|
|
|
{
|
|
|
|
dst->value = skb->priority;
|
|
|
|
}
|
|
|
|
|
|
|
|
META_COLLECTOR(int_protocol)
|
|
|
|
{
|
|
|
|
/* Let userspace take care of the byte ordering */
|
2015-01-14 00:13:43 +08:00
|
|
|
dst->value = tc_skb_protocol(skb);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
META_COLLECTOR(int_pkttype)
|
|
|
|
{
|
|
|
|
dst->value = skb->pkt_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
META_COLLECTOR(int_pktlen)
|
|
|
|
{
|
|
|
|
dst->value = skb->len;
|
|
|
|
}
|
|
|
|
|
|
|
|
META_COLLECTOR(int_datalen)
|
|
|
|
{
|
|
|
|
dst->value = skb->data_len;
|
|
|
|
}
|
|
|
|
|
|
|
|
META_COLLECTOR(int_maclen)
|
|
|
|
{
|
|
|
|
dst->value = skb->mac_len;
|
|
|
|
}
|
|
|
|
|
2010-08-25 05:48:10 +08:00
|
|
|
META_COLLECTOR(int_rxhash)
|
|
|
|
{
|
2013-12-16 14:12:06 +08:00
|
|
|
dst->value = skb_get_hash(skb);
|
2010-08-25 05:48:10 +08:00
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/**************************************************************************
|
|
|
|
* Netfilter
|
|
|
|
**************************************************************************/
|
|
|
|
|
2006-11-10 07:19:14 +08:00
|
|
|
META_COLLECTOR(int_mark)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2006-11-10 07:19:14 +08:00
|
|
|
dst->value = skb->mark;
|
2005-07-25 10:44:23 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* Traffic Control
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
META_COLLECTOR(int_tcindex)
|
|
|
|
{
|
|
|
|
dst->value = skb->tc_index;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* Routing
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
META_COLLECTOR(int_rtclassid)
|
|
|
|
{
|
2009-06-02 13:19:30 +08:00
|
|
|
if (unlikely(skb_dst(skb) == NULL))
|
2005-04-17 06:20:36 +08:00
|
|
|
*err = -1;
|
|
|
|
else
|
2011-01-14 20:36:42 +08:00
|
|
|
#ifdef CONFIG_IP_ROUTE_CLASSID
|
2009-06-02 13:19:30 +08:00
|
|
|
dst->value = skb_dst(skb)->tclassid;
|
2005-07-25 10:44:23 +08:00
|
|
|
#else
|
|
|
|
dst->value = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif
|
2005-07-25 10:44:23 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
META_COLLECTOR(int_rtiif)
|
|
|
|
{
|
2009-06-02 13:14:27 +08:00
|
|
|
if (unlikely(skb_rtable(skb) == NULL))
|
2005-04-17 06:20:36 +08:00
|
|
|
*err = -1;
|
|
|
|
else
|
2012-07-24 07:29:00 +08:00
|
|
|
dst->value = inet_iif(skb);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2005-06-09 06:10:48 +08:00
|
|
|
/**************************************************************************
|
|
|
|
* Socket Attributes
|
|
|
|
**************************************************************************/
|
|
|
|
|
2013-12-11 15:17:11 +08:00
|
|
|
#define skip_nonlocal(skb) \
|
|
|
|
(unlikely(skb->sk == NULL))
|
2005-06-09 06:10:48 +08:00
|
|
|
|
|
|
|
META_COLLECTOR(int_sk_family)
|
|
|
|
{
|
2013-12-11 15:17:11 +08:00
|
|
|
if (skip_nonlocal(skb)) {
|
|
|
|
*err = -1;
|
|
|
|
return;
|
|
|
|
}
|
2005-06-09 06:10:48 +08:00
|
|
|
dst->value = skb->sk->sk_family;
|
|
|
|
}
|
|
|
|
|
|
|
|
META_COLLECTOR(int_sk_state)
|
|
|
|
{
|
2013-12-11 15:17:11 +08:00
|
|
|
if (skip_nonlocal(skb)) {
|
|
|
|
*err = -1;
|
|
|
|
return;
|
|
|
|
}
|
2005-06-09 06:10:48 +08:00
|
|
|
dst->value = skb->sk->sk_state;
|
|
|
|
}
|
|
|
|
|
|
|
|
META_COLLECTOR(int_sk_reuse)
|
|
|
|
{
|
2013-12-11 15:17:11 +08:00
|
|
|
if (skip_nonlocal(skb)) {
|
|
|
|
*err = -1;
|
|
|
|
return;
|
|
|
|
}
|
2005-06-09 06:10:48 +08:00
|
|
|
dst->value = skb->sk->sk_reuse;
|
|
|
|
}
|
|
|
|
|
|
|
|
META_COLLECTOR(int_sk_bound_if)
|
|
|
|
{
|
2013-12-11 15:17:11 +08:00
|
|
|
if (skip_nonlocal(skb)) {
|
|
|
|
*err = -1;
|
|
|
|
return;
|
|
|
|
}
|
2005-06-09 06:10:48 +08:00
|
|
|
/* No error if bound_dev_if is 0, legal userspace check */
|
|
|
|
dst->value = skb->sk->sk_bound_dev_if;
|
|
|
|
}
|
|
|
|
|
|
|
|
META_COLLECTOR(var_sk_bound_if)
|
|
|
|
{
|
2013-12-11 15:17:11 +08:00
|
|
|
if (skip_nonlocal(skb)) {
|
|
|
|
*err = -1;
|
|
|
|
return;
|
|
|
|
}
|
2005-06-09 06:10:48 +08:00
|
|
|
|
2009-11-04 21:23:31 +08:00
|
|
|
if (skb->sk->sk_bound_dev_if == 0) {
|
2005-06-09 06:10:48 +08:00
|
|
|
dst->value = (unsigned long) "any";
|
|
|
|
dst->len = 3;
|
2009-11-04 21:23:31 +08:00
|
|
|
} else {
|
2005-06-09 06:10:48 +08:00
|
|
|
struct net_device *dev;
|
2007-02-09 22:25:16 +08:00
|
|
|
|
2009-11-04 21:23:31 +08:00
|
|
|
rcu_read_lock();
|
2009-11-19 15:24:41 +08:00
|
|
|
dev = dev_get_by_index_rcu(sock_net(skb->sk),
|
|
|
|
skb->sk->sk_bound_dev_if);
|
2005-06-09 06:10:48 +08:00
|
|
|
*err = var_dev(dev, dst);
|
2009-11-04 21:23:31 +08:00
|
|
|
rcu_read_unlock();
|
|
|
|
}
|
2005-06-09 06:10:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
META_COLLECTOR(int_sk_refcnt)
|
|
|
|
{
|
2013-12-11 15:17:11 +08:00
|
|
|
if (skip_nonlocal(skb)) {
|
|
|
|
*err = -1;
|
|
|
|
return;
|
|
|
|
}
|
2005-06-09 06:10:48 +08:00
|
|
|
dst->value = atomic_read(&skb->sk->sk_refcnt);
|
|
|
|
}
|
|
|
|
|
|
|
|
META_COLLECTOR(int_sk_rcvbuf)
|
|
|
|
{
|
2015-11-09 02:54:11 +08:00
|
|
|
const struct sock *sk = skb_to_full_sk(skb);
|
|
|
|
|
|
|
|
if (!sk) {
|
2013-12-11 15:17:11 +08:00
|
|
|
*err = -1;
|
|
|
|
return;
|
|
|
|
}
|
2015-11-09 02:54:11 +08:00
|
|
|
dst->value = sk->sk_rcvbuf;
|
2005-06-09 06:10:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
META_COLLECTOR(int_sk_shutdown)
|
|
|
|
{
|
2015-11-09 02:54:11 +08:00
|
|
|
const struct sock *sk = skb_to_full_sk(skb);
|
|
|
|
|
|
|
|
if (!sk) {
|
2013-12-11 15:17:11 +08:00
|
|
|
*err = -1;
|
|
|
|
return;
|
|
|
|
}
|
2015-11-09 02:54:11 +08:00
|
|
|
dst->value = sk->sk_shutdown;
|
2005-06-09 06:10:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
META_COLLECTOR(int_sk_proto)
|
|
|
|
{
|
2015-11-09 02:54:11 +08:00
|
|
|
const struct sock *sk = skb_to_full_sk(skb);
|
|
|
|
|
|
|
|
if (!sk) {
|
2013-12-11 15:17:11 +08:00
|
|
|
*err = -1;
|
|
|
|
return;
|
|
|
|
}
|
2015-11-09 02:54:11 +08:00
|
|
|
dst->value = sk->sk_protocol;
|
2005-06-09 06:10:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
META_COLLECTOR(int_sk_type)
|
|
|
|
{
|
2015-11-09 02:54:11 +08:00
|
|
|
const struct sock *sk = skb_to_full_sk(skb);
|
|
|
|
|
|
|
|
if (!sk) {
|
2013-12-11 15:17:11 +08:00
|
|
|
*err = -1;
|
|
|
|
return;
|
|
|
|
}
|
2015-11-09 02:54:11 +08:00
|
|
|
dst->value = sk->sk_type;
|
2005-06-09 06:10:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
META_COLLECTOR(int_sk_rmem_alloc)
|
|
|
|
{
|
2015-11-09 02:54:11 +08:00
|
|
|
const struct sock *sk = skb_to_full_sk(skb);
|
|
|
|
|
|
|
|
if (!sk) {
|
2013-12-11 15:17:11 +08:00
|
|
|
*err = -1;
|
|
|
|
return;
|
|
|
|
}
|
2015-11-09 02:54:11 +08:00
|
|
|
dst->value = sk_rmem_alloc_get(sk);
|
2005-06-09 06:10:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
META_COLLECTOR(int_sk_wmem_alloc)
|
|
|
|
{
|
2015-11-09 02:54:11 +08:00
|
|
|
const struct sock *sk = skb_to_full_sk(skb);
|
|
|
|
|
|
|
|
if (!sk) {
|
2013-12-11 15:17:11 +08:00
|
|
|
*err = -1;
|
|
|
|
return;
|
|
|
|
}
|
2015-11-09 02:54:11 +08:00
|
|
|
dst->value = sk_wmem_alloc_get(sk);
|
2005-06-09 06:10:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
META_COLLECTOR(int_sk_omem_alloc)
|
|
|
|
{
|
2015-11-09 02:54:11 +08:00
|
|
|
const struct sock *sk = skb_to_full_sk(skb);
|
|
|
|
|
|
|
|
if (!sk) {
|
2013-12-11 15:17:11 +08:00
|
|
|
*err = -1;
|
|
|
|
return;
|
|
|
|
}
|
2015-11-09 02:54:11 +08:00
|
|
|
dst->value = atomic_read(&sk->sk_omem_alloc);
|
2005-06-09 06:10:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
META_COLLECTOR(int_sk_rcv_qlen)
|
|
|
|
{
|
2015-11-09 02:54:11 +08:00
|
|
|
const struct sock *sk = skb_to_full_sk(skb);
|
|
|
|
|
|
|
|
if (!sk) {
|
2013-12-11 15:17:11 +08:00
|
|
|
*err = -1;
|
|
|
|
return;
|
|
|
|
}
|
2015-11-09 02:54:11 +08:00
|
|
|
dst->value = sk->sk_receive_queue.qlen;
|
2005-06-09 06:10:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
META_COLLECTOR(int_sk_snd_qlen)
|
|
|
|
{
|
2015-11-09 02:54:11 +08:00
|
|
|
const struct sock *sk = skb_to_full_sk(skb);
|
|
|
|
|
|
|
|
if (!sk) {
|
2013-12-11 15:17:11 +08:00
|
|
|
*err = -1;
|
|
|
|
return;
|
|
|
|
}
|
2015-11-09 02:54:11 +08:00
|
|
|
dst->value = sk->sk_write_queue.qlen;
|
2005-06-09 06:10:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
META_COLLECTOR(int_sk_wmem_queued)
|
|
|
|
{
|
2015-11-09 02:54:11 +08:00
|
|
|
const struct sock *sk = skb_to_full_sk(skb);
|
|
|
|
|
|
|
|
if (!sk) {
|
2013-12-11 15:17:11 +08:00
|
|
|
*err = -1;
|
|
|
|
return;
|
|
|
|
}
|
2015-11-09 02:54:11 +08:00
|
|
|
dst->value = sk->sk_wmem_queued;
|
2005-06-09 06:10:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
META_COLLECTOR(int_sk_fwd_alloc)
|
|
|
|
{
|
2015-11-09 02:54:11 +08:00
|
|
|
const struct sock *sk = skb_to_full_sk(skb);
|
|
|
|
|
|
|
|
if (!sk) {
|
2013-12-11 15:17:11 +08:00
|
|
|
*err = -1;
|
|
|
|
return;
|
|
|
|
}
|
2015-11-09 02:54:11 +08:00
|
|
|
dst->value = sk->sk_forward_alloc;
|
2005-06-09 06:10:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
META_COLLECTOR(int_sk_sndbuf)
|
|
|
|
{
|
2015-11-09 02:54:11 +08:00
|
|
|
const struct sock *sk = skb_to_full_sk(skb);
|
|
|
|
|
|
|
|
if (!sk) {
|
2013-12-11 15:17:11 +08:00
|
|
|
*err = -1;
|
|
|
|
return;
|
|
|
|
}
|
2015-11-09 02:54:11 +08:00
|
|
|
dst->value = sk->sk_sndbuf;
|
2005-06-09 06:10:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
META_COLLECTOR(int_sk_alloc)
|
|
|
|
{
|
2015-11-09 02:54:11 +08:00
|
|
|
const struct sock *sk = skb_to_full_sk(skb);
|
|
|
|
|
|
|
|
if (!sk) {
|
2013-12-11 15:17:11 +08:00
|
|
|
*err = -1;
|
|
|
|
return;
|
|
|
|
}
|
2015-11-09 02:54:11 +08:00
|
|
|
dst->value = (__force int) sk->sk_allocation;
|
2005-06-09 06:10:48 +08:00
|
|
|
}
|
|
|
|
|
[INET]: speedup inet (tcp/dccp) lookups
Arnaldo and I agreed it could be applied now, because I have other
pending patches depending on this one (Thank you Arnaldo)
(The other important patch moves skc_refcnt in a separate cache line,
so that the SMP/NUMA performance doesnt suffer from cache line ping pongs)
1) First some performance data :
--------------------------------
tcp_v4_rcv() wastes a *lot* of time in __inet_lookup_established()
The most time critical code is :
sk_for_each(sk, node, &head->chain) {
if (INET_MATCH(sk, acookie, saddr, daddr, ports, dif))
goto hit; /* You sunk my battleship! */
}
The sk_for_each() does use prefetch() hints but only the begining of
"struct sock" is prefetched.
As INET_MATCH first comparison uses inet_sk(__sk)->daddr, wich is far
away from the begining of "struct sock", it has to bring into CPU
cache cold cache line. Each iteration has to use at least 2 cache
lines.
This can be problematic if some chains are very long.
2) The goal
-----------
The idea I had is to change things so that INET_MATCH() may return
FALSE in 99% of cases only using the data already in the CPU cache,
using one cache line per iteration.
3) Description of the patch
---------------------------
Adds a new 'unsigned int skc_hash' field in 'struct sock_common',
filling a 32 bits hole on 64 bits platform.
struct sock_common {
unsigned short skc_family;
volatile unsigned char skc_state;
unsigned char skc_reuse;
int skc_bound_dev_if;
struct hlist_node skc_node;
struct hlist_node skc_bind_node;
atomic_t skc_refcnt;
+ unsigned int skc_hash;
struct proto *skc_prot;
};
Store in this 32 bits field the full hash, not masked by (ehash_size -
1) Using this full hash as the first comparison done in INET_MATCH
permits us immediatly skip the element without touching a second cache
line in case of a miss.
Suppress the sk_hashent/tw_hashent fields since skc_hash (aliased to
sk_hash and tw_hash) already contains the slot number if we mask with
(ehash_size - 1)
File include/net/inet_hashtables.h
64 bits platforms :
#define INET_MATCH(__sk, __hash, __cookie, __saddr, __daddr, __ports, __dif)\
(((__sk)->sk_hash == (__hash))
((*((__u64 *)&(inet_sk(__sk)->daddr)))== (__cookie)) && \
((*((__u32 *)&(inet_sk(__sk)->dport))) == (__ports)) && \
(!((__sk)->sk_bound_dev_if) || ((__sk)->sk_bound_dev_if == (__dif))))
32bits platforms:
#define TCP_IPV4_MATCH(__sk, __hash, __cookie, __saddr, __daddr, __ports, __dif)\
(((__sk)->sk_hash == (__hash)) && \
(inet_sk(__sk)->daddr == (__saddr)) && \
(inet_sk(__sk)->rcv_saddr == (__daddr)) && \
(!((__sk)->sk_bound_dev_if) || ((__sk)->sk_bound_dev_if == (__dif))))
- Adds a prefetch(head->chain.first) in
__inet_lookup_established()/__tcp_v4_check_established() and
__inet6_lookup_established()/__tcp_v6_check_established() and
__dccp_v4_check_established() to bring into cache the first element of the
list, before the {read|write}_lock(&head->lock);
Signed-off-by: Eric Dumazet <dada1@cosmosbay.com>
Acked-by: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
2005-10-04 05:13:38 +08:00
|
|
|
META_COLLECTOR(int_sk_hash)
|
2005-06-09 06:10:48 +08:00
|
|
|
{
|
2013-12-11 15:17:11 +08:00
|
|
|
if (skip_nonlocal(skb)) {
|
|
|
|
*err = -1;
|
|
|
|
return;
|
|
|
|
}
|
[INET]: speedup inet (tcp/dccp) lookups
Arnaldo and I agreed it could be applied now, because I have other
pending patches depending on this one (Thank you Arnaldo)
(The other important patch moves skc_refcnt in a separate cache line,
so that the SMP/NUMA performance doesnt suffer from cache line ping pongs)
1) First some performance data :
--------------------------------
tcp_v4_rcv() wastes a *lot* of time in __inet_lookup_established()
The most time critical code is :
sk_for_each(sk, node, &head->chain) {
if (INET_MATCH(sk, acookie, saddr, daddr, ports, dif))
goto hit; /* You sunk my battleship! */
}
The sk_for_each() does use prefetch() hints but only the begining of
"struct sock" is prefetched.
As INET_MATCH first comparison uses inet_sk(__sk)->daddr, wich is far
away from the begining of "struct sock", it has to bring into CPU
cache cold cache line. Each iteration has to use at least 2 cache
lines.
This can be problematic if some chains are very long.
2) The goal
-----------
The idea I had is to change things so that INET_MATCH() may return
FALSE in 99% of cases only using the data already in the CPU cache,
using one cache line per iteration.
3) Description of the patch
---------------------------
Adds a new 'unsigned int skc_hash' field in 'struct sock_common',
filling a 32 bits hole on 64 bits platform.
struct sock_common {
unsigned short skc_family;
volatile unsigned char skc_state;
unsigned char skc_reuse;
int skc_bound_dev_if;
struct hlist_node skc_node;
struct hlist_node skc_bind_node;
atomic_t skc_refcnt;
+ unsigned int skc_hash;
struct proto *skc_prot;
};
Store in this 32 bits field the full hash, not masked by (ehash_size -
1) Using this full hash as the first comparison done in INET_MATCH
permits us immediatly skip the element without touching a second cache
line in case of a miss.
Suppress the sk_hashent/tw_hashent fields since skc_hash (aliased to
sk_hash and tw_hash) already contains the slot number if we mask with
(ehash_size - 1)
File include/net/inet_hashtables.h
64 bits platforms :
#define INET_MATCH(__sk, __hash, __cookie, __saddr, __daddr, __ports, __dif)\
(((__sk)->sk_hash == (__hash))
((*((__u64 *)&(inet_sk(__sk)->daddr)))== (__cookie)) && \
((*((__u32 *)&(inet_sk(__sk)->dport))) == (__ports)) && \
(!((__sk)->sk_bound_dev_if) || ((__sk)->sk_bound_dev_if == (__dif))))
32bits platforms:
#define TCP_IPV4_MATCH(__sk, __hash, __cookie, __saddr, __daddr, __ports, __dif)\
(((__sk)->sk_hash == (__hash)) && \
(inet_sk(__sk)->daddr == (__saddr)) && \
(inet_sk(__sk)->rcv_saddr == (__daddr)) && \
(!((__sk)->sk_bound_dev_if) || ((__sk)->sk_bound_dev_if == (__dif))))
- Adds a prefetch(head->chain.first) in
__inet_lookup_established()/__tcp_v4_check_established() and
__inet6_lookup_established()/__tcp_v6_check_established() and
__dccp_v4_check_established() to bring into cache the first element of the
list, before the {read|write}_lock(&head->lock);
Signed-off-by: Eric Dumazet <dada1@cosmosbay.com>
Acked-by: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
2005-10-04 05:13:38 +08:00
|
|
|
dst->value = skb->sk->sk_hash;
|
2005-06-09 06:10:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
META_COLLECTOR(int_sk_lingertime)
|
|
|
|
{
|
2015-11-09 02:54:11 +08:00
|
|
|
const struct sock *sk = skb_to_full_sk(skb);
|
|
|
|
|
|
|
|
if (!sk) {
|
2013-12-11 15:17:11 +08:00
|
|
|
*err = -1;
|
|
|
|
return;
|
|
|
|
}
|
2015-11-09 02:54:11 +08:00
|
|
|
dst->value = sk->sk_lingertime / HZ;
|
2005-06-09 06:10:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
META_COLLECTOR(int_sk_err_qlen)
|
|
|
|
{
|
2015-11-09 02:54:11 +08:00
|
|
|
const struct sock *sk = skb_to_full_sk(skb);
|
|
|
|
|
|
|
|
if (!sk) {
|
2013-12-11 15:17:11 +08:00
|
|
|
*err = -1;
|
|
|
|
return;
|
|
|
|
}
|
2015-11-09 02:54:11 +08:00
|
|
|
dst->value = sk->sk_error_queue.qlen;
|
2005-06-09 06:10:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
META_COLLECTOR(int_sk_ack_bl)
|
|
|
|
{
|
2015-11-09 02:54:11 +08:00
|
|
|
const struct sock *sk = skb_to_full_sk(skb);
|
|
|
|
|
|
|
|
if (!sk) {
|
2013-12-11 15:17:11 +08:00
|
|
|
*err = -1;
|
|
|
|
return;
|
|
|
|
}
|
2015-11-09 02:54:11 +08:00
|
|
|
dst->value = sk->sk_ack_backlog;
|
2005-06-09 06:10:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
META_COLLECTOR(int_sk_max_ack_bl)
|
|
|
|
{
|
2015-11-09 02:54:11 +08:00
|
|
|
const struct sock *sk = skb_to_full_sk(skb);
|
|
|
|
|
|
|
|
if (!sk) {
|
2013-12-11 15:17:11 +08:00
|
|
|
*err = -1;
|
|
|
|
return;
|
|
|
|
}
|
2015-11-09 02:54:11 +08:00
|
|
|
dst->value = sk->sk_max_ack_backlog;
|
2005-06-09 06:10:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
META_COLLECTOR(int_sk_prio)
|
|
|
|
{
|
2015-11-09 02:54:11 +08:00
|
|
|
const struct sock *sk = skb_to_full_sk(skb);
|
|
|
|
|
|
|
|
if (!sk) {
|
2013-12-11 15:17:11 +08:00
|
|
|
*err = -1;
|
|
|
|
return;
|
|
|
|
}
|
2015-11-09 02:54:11 +08:00
|
|
|
dst->value = sk->sk_priority;
|
2005-06-09 06:10:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
META_COLLECTOR(int_sk_rcvlowat)
|
|
|
|
{
|
2015-11-09 02:54:11 +08:00
|
|
|
const struct sock *sk = skb_to_full_sk(skb);
|
|
|
|
|
|
|
|
if (!sk) {
|
2013-12-11 15:17:11 +08:00
|
|
|
*err = -1;
|
|
|
|
return;
|
|
|
|
}
|
2015-11-09 02:54:11 +08:00
|
|
|
dst->value = sk->sk_rcvlowat;
|
2005-06-09 06:10:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
META_COLLECTOR(int_sk_rcvtimeo)
|
|
|
|
{
|
2015-11-09 02:54:11 +08:00
|
|
|
const struct sock *sk = skb_to_full_sk(skb);
|
|
|
|
|
|
|
|
if (!sk) {
|
2013-12-11 15:17:11 +08:00
|
|
|
*err = -1;
|
|
|
|
return;
|
|
|
|
}
|
2015-11-09 02:54:11 +08:00
|
|
|
dst->value = sk->sk_rcvtimeo / HZ;
|
2005-06-09 06:10:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
META_COLLECTOR(int_sk_sndtimeo)
|
|
|
|
{
|
2015-11-09 02:54:11 +08:00
|
|
|
const struct sock *sk = skb_to_full_sk(skb);
|
|
|
|
|
|
|
|
if (!sk) {
|
2013-12-11 15:17:11 +08:00
|
|
|
*err = -1;
|
|
|
|
return;
|
|
|
|
}
|
2015-11-09 02:54:11 +08:00
|
|
|
dst->value = sk->sk_sndtimeo / HZ;
|
2005-06-09 06:10:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
META_COLLECTOR(int_sk_sendmsg_off)
|
|
|
|
{
|
2015-11-09 02:54:11 +08:00
|
|
|
const struct sock *sk = skb_to_full_sk(skb);
|
|
|
|
|
|
|
|
if (!sk) {
|
2013-12-11 15:17:11 +08:00
|
|
|
*err = -1;
|
|
|
|
return;
|
|
|
|
}
|
2015-11-09 02:54:11 +08:00
|
|
|
dst->value = sk->sk_frag.offset;
|
2005-06-09 06:10:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
META_COLLECTOR(int_sk_write_pend)
|
|
|
|
{
|
2015-11-09 02:54:11 +08:00
|
|
|
const struct sock *sk = skb_to_full_sk(skb);
|
|
|
|
|
|
|
|
if (!sk) {
|
2013-12-11 15:17:11 +08:00
|
|
|
*err = -1;
|
|
|
|
return;
|
|
|
|
}
|
2015-11-09 02:54:11 +08:00
|
|
|
dst->value = sk->sk_write_pending;
|
2005-06-09 06:10:48 +08:00
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/**************************************************************************
|
|
|
|
* Meta value collectors assignment table
|
|
|
|
**************************************************************************/
|
|
|
|
|
2011-01-20 03:26:56 +08:00
|
|
|
struct meta_ops {
|
2005-04-17 06:20:36 +08:00
|
|
|
void (*get)(struct sk_buff *, struct tcf_pkt_info *,
|
|
|
|
struct meta_value *, struct meta_obj *, int *);
|
|
|
|
};
|
|
|
|
|
2005-06-09 06:10:48 +08:00
|
|
|
#define META_ID(name) TCF_META_ID_##name
|
|
|
|
#define META_FUNC(name) { .get = meta_##name }
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Meta value operations table listing all meta value collectors and
|
|
|
|
* assigns them to a type and meta id. */
|
2011-01-20 03:26:56 +08:00
|
|
|
static struct meta_ops __meta_ops[TCF_META_TYPE_MAX + 1][TCF_META_ID_MAX + 1] = {
|
2005-04-17 06:20:36 +08:00
|
|
|
[TCF_META_TYPE_VAR] = {
|
2005-06-09 06:10:48 +08:00
|
|
|
[META_ID(DEV)] = META_FUNC(var_dev),
|
|
|
|
[META_ID(SK_BOUND_IF)] = META_FUNC(var_sk_bound_if),
|
2005-04-17 06:20:36 +08:00
|
|
|
},
|
|
|
|
[TCF_META_TYPE_INT] = {
|
2005-06-09 06:10:48 +08:00
|
|
|
[META_ID(RANDOM)] = META_FUNC(int_random),
|
|
|
|
[META_ID(LOADAVG_0)] = META_FUNC(int_loadavg_0),
|
|
|
|
[META_ID(LOADAVG_1)] = META_FUNC(int_loadavg_1),
|
|
|
|
[META_ID(LOADAVG_2)] = META_FUNC(int_loadavg_2),
|
|
|
|
[META_ID(DEV)] = META_FUNC(int_dev),
|
|
|
|
[META_ID(PRIORITY)] = META_FUNC(int_priority),
|
|
|
|
[META_ID(PROTOCOL)] = META_FUNC(int_protocol),
|
|
|
|
[META_ID(PKTTYPE)] = META_FUNC(int_pkttype),
|
|
|
|
[META_ID(PKTLEN)] = META_FUNC(int_pktlen),
|
|
|
|
[META_ID(DATALEN)] = META_FUNC(int_datalen),
|
|
|
|
[META_ID(MACLEN)] = META_FUNC(int_maclen),
|
2006-11-10 07:19:14 +08:00
|
|
|
[META_ID(NFMARK)] = META_FUNC(int_mark),
|
2005-06-09 06:10:48 +08:00
|
|
|
[META_ID(TCINDEX)] = META_FUNC(int_tcindex),
|
|
|
|
[META_ID(RTCLASSID)] = META_FUNC(int_rtclassid),
|
|
|
|
[META_ID(RTIIF)] = META_FUNC(int_rtiif),
|
|
|
|
[META_ID(SK_FAMILY)] = META_FUNC(int_sk_family),
|
|
|
|
[META_ID(SK_STATE)] = META_FUNC(int_sk_state),
|
|
|
|
[META_ID(SK_REUSE)] = META_FUNC(int_sk_reuse),
|
|
|
|
[META_ID(SK_BOUND_IF)] = META_FUNC(int_sk_bound_if),
|
|
|
|
[META_ID(SK_REFCNT)] = META_FUNC(int_sk_refcnt),
|
|
|
|
[META_ID(SK_RCVBUF)] = META_FUNC(int_sk_rcvbuf),
|
|
|
|
[META_ID(SK_SNDBUF)] = META_FUNC(int_sk_sndbuf),
|
|
|
|
[META_ID(SK_SHUTDOWN)] = META_FUNC(int_sk_shutdown),
|
|
|
|
[META_ID(SK_PROTO)] = META_FUNC(int_sk_proto),
|
|
|
|
[META_ID(SK_TYPE)] = META_FUNC(int_sk_type),
|
|
|
|
[META_ID(SK_RMEM_ALLOC)] = META_FUNC(int_sk_rmem_alloc),
|
|
|
|
[META_ID(SK_WMEM_ALLOC)] = META_FUNC(int_sk_wmem_alloc),
|
|
|
|
[META_ID(SK_OMEM_ALLOC)] = META_FUNC(int_sk_omem_alloc),
|
|
|
|
[META_ID(SK_WMEM_QUEUED)] = META_FUNC(int_sk_wmem_queued),
|
|
|
|
[META_ID(SK_RCV_QLEN)] = META_FUNC(int_sk_rcv_qlen),
|
|
|
|
[META_ID(SK_SND_QLEN)] = META_FUNC(int_sk_snd_qlen),
|
|
|
|
[META_ID(SK_ERR_QLEN)] = META_FUNC(int_sk_err_qlen),
|
|
|
|
[META_ID(SK_FORWARD_ALLOCS)] = META_FUNC(int_sk_fwd_alloc),
|
|
|
|
[META_ID(SK_ALLOCS)] = META_FUNC(int_sk_alloc),
|
[INET]: speedup inet (tcp/dccp) lookups
Arnaldo and I agreed it could be applied now, because I have other
pending patches depending on this one (Thank you Arnaldo)
(The other important patch moves skc_refcnt in a separate cache line,
so that the SMP/NUMA performance doesnt suffer from cache line ping pongs)
1) First some performance data :
--------------------------------
tcp_v4_rcv() wastes a *lot* of time in __inet_lookup_established()
The most time critical code is :
sk_for_each(sk, node, &head->chain) {
if (INET_MATCH(sk, acookie, saddr, daddr, ports, dif))
goto hit; /* You sunk my battleship! */
}
The sk_for_each() does use prefetch() hints but only the begining of
"struct sock" is prefetched.
As INET_MATCH first comparison uses inet_sk(__sk)->daddr, wich is far
away from the begining of "struct sock", it has to bring into CPU
cache cold cache line. Each iteration has to use at least 2 cache
lines.
This can be problematic if some chains are very long.
2) The goal
-----------
The idea I had is to change things so that INET_MATCH() may return
FALSE in 99% of cases only using the data already in the CPU cache,
using one cache line per iteration.
3) Description of the patch
---------------------------
Adds a new 'unsigned int skc_hash' field in 'struct sock_common',
filling a 32 bits hole on 64 bits platform.
struct sock_common {
unsigned short skc_family;
volatile unsigned char skc_state;
unsigned char skc_reuse;
int skc_bound_dev_if;
struct hlist_node skc_node;
struct hlist_node skc_bind_node;
atomic_t skc_refcnt;
+ unsigned int skc_hash;
struct proto *skc_prot;
};
Store in this 32 bits field the full hash, not masked by (ehash_size -
1) Using this full hash as the first comparison done in INET_MATCH
permits us immediatly skip the element without touching a second cache
line in case of a miss.
Suppress the sk_hashent/tw_hashent fields since skc_hash (aliased to
sk_hash and tw_hash) already contains the slot number if we mask with
(ehash_size - 1)
File include/net/inet_hashtables.h
64 bits platforms :
#define INET_MATCH(__sk, __hash, __cookie, __saddr, __daddr, __ports, __dif)\
(((__sk)->sk_hash == (__hash))
((*((__u64 *)&(inet_sk(__sk)->daddr)))== (__cookie)) && \
((*((__u32 *)&(inet_sk(__sk)->dport))) == (__ports)) && \
(!((__sk)->sk_bound_dev_if) || ((__sk)->sk_bound_dev_if == (__dif))))
32bits platforms:
#define TCP_IPV4_MATCH(__sk, __hash, __cookie, __saddr, __daddr, __ports, __dif)\
(((__sk)->sk_hash == (__hash)) && \
(inet_sk(__sk)->daddr == (__saddr)) && \
(inet_sk(__sk)->rcv_saddr == (__daddr)) && \
(!((__sk)->sk_bound_dev_if) || ((__sk)->sk_bound_dev_if == (__dif))))
- Adds a prefetch(head->chain.first) in
__inet_lookup_established()/__tcp_v4_check_established() and
__inet6_lookup_established()/__tcp_v6_check_established() and
__dccp_v4_check_established() to bring into cache the first element of the
list, before the {read|write}_lock(&head->lock);
Signed-off-by: Eric Dumazet <dada1@cosmosbay.com>
Acked-by: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
2005-10-04 05:13:38 +08:00
|
|
|
[META_ID(SK_HASH)] = META_FUNC(int_sk_hash),
|
2005-06-09 06:10:48 +08:00
|
|
|
[META_ID(SK_LINGERTIME)] = META_FUNC(int_sk_lingertime),
|
|
|
|
[META_ID(SK_ACK_BACKLOG)] = META_FUNC(int_sk_ack_bl),
|
|
|
|
[META_ID(SK_MAX_ACK_BACKLOG)] = META_FUNC(int_sk_max_ack_bl),
|
|
|
|
[META_ID(SK_PRIO)] = META_FUNC(int_sk_prio),
|
|
|
|
[META_ID(SK_RCVLOWAT)] = META_FUNC(int_sk_rcvlowat),
|
|
|
|
[META_ID(SK_RCVTIMEO)] = META_FUNC(int_sk_rcvtimeo),
|
|
|
|
[META_ID(SK_SNDTIMEO)] = META_FUNC(int_sk_sndtimeo),
|
|
|
|
[META_ID(SK_SENDMSG_OFF)] = META_FUNC(int_sk_sendmsg_off),
|
|
|
|
[META_ID(SK_WRITE_PENDING)] = META_FUNC(int_sk_write_pend),
|
2008-02-05 19:20:13 +08:00
|
|
|
[META_ID(VLAN_TAG)] = META_FUNC(int_vlan_tag),
|
2010-08-25 05:48:10 +08:00
|
|
|
[META_ID(RXHASH)] = META_FUNC(int_rxhash),
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-01-20 03:26:56 +08:00
|
|
|
static inline struct meta_ops *meta_ops(struct meta_value *val)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
return &__meta_ops[meta_type(val)][meta_id(val)];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* Type specific operations for TCF_META_TYPE_VAR
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
static int meta_var_compare(struct meta_obj *a, struct meta_obj *b)
|
|
|
|
{
|
|
|
|
int r = a->len - b->len;
|
|
|
|
|
|
|
|
if (r == 0)
|
|
|
|
r = memcmp((void *) a->value, (void *) b->value, a->len);
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2008-01-23 14:11:33 +08:00
|
|
|
static int meta_var_change(struct meta_value *dst, struct nlattr *nla)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-01-23 14:11:33 +08:00
|
|
|
int len = nla_len(nla);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-01-23 14:11:33 +08:00
|
|
|
dst->val = (unsigned long)kmemdup(nla_data(nla), len, GFP_KERNEL);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (dst->val == 0UL)
|
|
|
|
return -ENOMEM;
|
|
|
|
dst->len = len;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void meta_var_destroy(struct meta_value *v)
|
|
|
|
{
|
2005-11-09 01:41:34 +08:00
|
|
|
kfree((void *) v->val);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void meta_var_apply_extras(struct meta_value *v,
|
|
|
|
struct meta_obj *dst)
|
|
|
|
{
|
|
|
|
int shift = v->hdr.shift;
|
|
|
|
|
|
|
|
if (shift && shift < dst->len)
|
|
|
|
dst->len -= shift;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int meta_var_dump(struct sk_buff *skb, struct meta_value *v, int tlv)
|
|
|
|
{
|
2012-03-29 17:11:39 +08:00
|
|
|
if (v->val && v->len &&
|
|
|
|
nla_put(skb, tlv, v->len, (void *) v->val))
|
|
|
|
goto nla_put_failure;
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
|
2008-01-23 14:11:33 +08:00
|
|
|
nla_put_failure:
|
2005-04-17 06:20:36 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* Type specific operations for TCF_META_TYPE_INT
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
static int meta_int_compare(struct meta_obj *a, struct meta_obj *b)
|
|
|
|
{
|
|
|
|
/* Let gcc optimize it, the unlikely is not really based on
|
|
|
|
* some numbers but jump free code for mismatches seems
|
|
|
|
* more logical. */
|
2005-06-09 06:11:19 +08:00
|
|
|
if (unlikely(a->value == b->value))
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
2005-06-09 06:11:19 +08:00
|
|
|
else if (a->value < b->value)
|
2005-04-17 06:20:36 +08:00
|
|
|
return -1;
|
|
|
|
else
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2008-01-23 14:11:33 +08:00
|
|
|
static int meta_int_change(struct meta_value *dst, struct nlattr *nla)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-01-23 14:11:33 +08:00
|
|
|
if (nla_len(nla) >= sizeof(unsigned long)) {
|
|
|
|
dst->val = *(unsigned long *) nla_data(nla);
|
2005-04-17 06:20:36 +08:00
|
|
|
dst->len = sizeof(unsigned long);
|
2008-01-23 14:11:33 +08:00
|
|
|
} else if (nla_len(nla) == sizeof(u32)) {
|
2008-01-24 12:35:03 +08:00
|
|
|
dst->val = nla_get_u32(nla);
|
2005-04-17 06:20:36 +08:00
|
|
|
dst->len = sizeof(u32);
|
|
|
|
} else
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void meta_int_apply_extras(struct meta_value *v,
|
|
|
|
struct meta_obj *dst)
|
|
|
|
{
|
|
|
|
if (v->hdr.shift)
|
|
|
|
dst->value >>= v->hdr.shift;
|
|
|
|
|
|
|
|
if (v->val)
|
|
|
|
dst->value &= v->val;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int meta_int_dump(struct sk_buff *skb, struct meta_value *v, int tlv)
|
|
|
|
{
|
2012-03-29 17:11:39 +08:00
|
|
|
if (v->len == sizeof(unsigned long)) {
|
|
|
|
if (nla_put(skb, tlv, sizeof(unsigned long), &v->val))
|
|
|
|
goto nla_put_failure;
|
|
|
|
} else if (v->len == sizeof(u32)) {
|
|
|
|
if (nla_put_u32(skb, tlv, v->val))
|
|
|
|
goto nla_put_failure;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
2008-01-23 14:11:33 +08:00
|
|
|
nla_put_failure:
|
2005-04-17 06:20:36 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* Type specific operations table
|
|
|
|
**************************************************************************/
|
|
|
|
|
2011-01-20 03:26:56 +08:00
|
|
|
struct meta_type_ops {
|
2005-04-17 06:20:36 +08:00
|
|
|
void (*destroy)(struct meta_value *);
|
|
|
|
int (*compare)(struct meta_obj *, struct meta_obj *);
|
2008-01-23 14:11:33 +08:00
|
|
|
int (*change)(struct meta_value *, struct nlattr *);
|
2005-04-17 06:20:36 +08:00
|
|
|
void (*apply_extras)(struct meta_value *, struct meta_obj *);
|
|
|
|
int (*dump)(struct sk_buff *, struct meta_value *, int);
|
|
|
|
};
|
|
|
|
|
2016-04-09 16:49:22 +08:00
|
|
|
static const struct meta_type_ops __meta_type_ops[TCF_META_TYPE_MAX + 1] = {
|
2005-04-17 06:20:36 +08:00
|
|
|
[TCF_META_TYPE_VAR] = {
|
|
|
|
.destroy = meta_var_destroy,
|
|
|
|
.compare = meta_var_compare,
|
|
|
|
.change = meta_var_change,
|
|
|
|
.apply_extras = meta_var_apply_extras,
|
|
|
|
.dump = meta_var_dump
|
|
|
|
},
|
|
|
|
[TCF_META_TYPE_INT] = {
|
|
|
|
.compare = meta_int_compare,
|
|
|
|
.change = meta_int_change,
|
|
|
|
.apply_extras = meta_int_apply_extras,
|
|
|
|
.dump = meta_int_dump
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-04-09 16:49:22 +08:00
|
|
|
static inline const struct meta_type_ops *meta_type_ops(struct meta_value *v)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
return &__meta_type_ops[meta_type(v)];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* Core
|
|
|
|
**************************************************************************/
|
|
|
|
|
2008-02-10 15:26:17 +08:00
|
|
|
static int meta_get(struct sk_buff *skb, struct tcf_pkt_info *info,
|
|
|
|
struct meta_value *v, struct meta_obj *dst)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int err = 0;
|
|
|
|
|
|
|
|
if (meta_id(v) == TCF_META_ID_VALUE) {
|
|
|
|
dst->value = v->val;
|
|
|
|
dst->len = v->len;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
meta_ops(v)->get(skb, info, v, dst, &err);
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
if (meta_type_ops(v)->apply_extras)
|
2011-01-20 03:26:56 +08:00
|
|
|
meta_type_ops(v)->apply_extras(v, dst);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int em_meta_match(struct sk_buff *skb, struct tcf_ematch *m,
|
|
|
|
struct tcf_pkt_info *info)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
struct meta_match *meta = (struct meta_match *) m->data;
|
|
|
|
struct meta_obj l_value, r_value;
|
|
|
|
|
|
|
|
if (meta_get(skb, info, &meta->lvalue, &l_value) < 0 ||
|
|
|
|
meta_get(skb, info, &meta->rvalue, &r_value) < 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
r = meta_type_ops(&meta->lvalue)->compare(&l_value, &r_value);
|
|
|
|
|
|
|
|
switch (meta->lvalue.hdr.op) {
|
2011-01-20 03:26:56 +08:00
|
|
|
case TCF_EM_OPND_EQ:
|
|
|
|
return !r;
|
|
|
|
case TCF_EM_OPND_LT:
|
|
|
|
return r < 0;
|
|
|
|
case TCF_EM_OPND_GT:
|
|
|
|
return r > 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-02-10 15:26:17 +08:00
|
|
|
static void meta_delete(struct meta_match *meta)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-02-08 10:13:00 +08:00
|
|
|
if (meta) {
|
2016-04-09 16:49:22 +08:00
|
|
|
const struct meta_type_ops *ops = meta_type_ops(&meta->lvalue);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-02-08 10:13:00 +08:00
|
|
|
if (ops && ops->destroy) {
|
|
|
|
ops->destroy(&meta->lvalue);
|
|
|
|
ops->destroy(&meta->rvalue);
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
kfree(meta);
|
|
|
|
}
|
|
|
|
|
2008-01-23 14:11:33 +08:00
|
|
|
static inline int meta_change_data(struct meta_value *dst, struct nlattr *nla)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-01-23 14:11:33 +08:00
|
|
|
if (nla) {
|
|
|
|
if (nla_len(nla) == 0)
|
2005-04-17 06:20:36 +08:00
|
|
|
return -EINVAL;
|
|
|
|
|
2008-01-23 14:11:33 +08:00
|
|
|
return meta_type_ops(dst)->change(dst, nla);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int meta_is_supported(struct meta_value *val)
|
|
|
|
{
|
2011-01-20 03:26:56 +08:00
|
|
|
return !meta_id(val) || meta_ops(val)->get;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2008-01-24 12:36:45 +08:00
|
|
|
static const struct nla_policy meta_policy[TCA_EM_META_MAX + 1] = {
|
|
|
|
[TCA_EM_META_HDR] = { .len = sizeof(struct tcf_meta_hdr) },
|
|
|
|
};
|
|
|
|
|
2014-10-06 12:27:53 +08:00
|
|
|
static int em_meta_change(struct net *net, void *data, int len,
|
2005-04-17 06:20:36 +08:00
|
|
|
struct tcf_ematch *m)
|
|
|
|
{
|
2008-01-24 12:33:32 +08:00
|
|
|
int err;
|
2008-01-23 14:11:33 +08:00
|
|
|
struct nlattr *tb[TCA_EM_META_MAX + 1];
|
2005-04-17 06:20:36 +08:00
|
|
|
struct tcf_meta_hdr *hdr;
|
|
|
|
struct meta_match *meta = NULL;
|
2007-02-09 22:25:16 +08:00
|
|
|
|
2017-04-12 20:34:07 +08:00
|
|
|
err = nla_parse(tb, TCA_EM_META_MAX, data, len, meta_policy, NULL);
|
2008-01-24 12:33:32 +08:00
|
|
|
if (err < 0)
|
2005-04-17 06:20:36 +08:00
|
|
|
goto errout;
|
|
|
|
|
2008-01-24 12:33:32 +08:00
|
|
|
err = -EINVAL;
|
2008-01-24 12:36:45 +08:00
|
|
|
if (tb[TCA_EM_META_HDR] == NULL)
|
2005-04-17 06:20:36 +08:00
|
|
|
goto errout;
|
2008-01-23 14:11:33 +08:00
|
|
|
hdr = nla_data(tb[TCA_EM_META_HDR]);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (TCF_META_TYPE(hdr->left.kind) != TCF_META_TYPE(hdr->right.kind) ||
|
|
|
|
TCF_META_TYPE(hdr->left.kind) > TCF_META_TYPE_MAX ||
|
|
|
|
TCF_META_ID(hdr->left.kind) > TCF_META_ID_MAX ||
|
|
|
|
TCF_META_ID(hdr->right.kind) > TCF_META_ID_MAX)
|
|
|
|
goto errout;
|
|
|
|
|
2006-07-22 05:51:30 +08:00
|
|
|
meta = kzalloc(sizeof(*meta), GFP_KERNEL);
|
2013-09-27 08:40:11 +08:00
|
|
|
if (meta == NULL) {
|
|
|
|
err = -ENOMEM;
|
2005-04-17 06:20:36 +08:00
|
|
|
goto errout;
|
2013-09-27 08:40:11 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
memcpy(&meta->lvalue.hdr, &hdr->left, sizeof(hdr->left));
|
|
|
|
memcpy(&meta->rvalue.hdr, &hdr->right, sizeof(hdr->right));
|
|
|
|
|
|
|
|
if (!meta_is_supported(&meta->lvalue) ||
|
|
|
|
!meta_is_supported(&meta->rvalue)) {
|
|
|
|
err = -EOPNOTSUPP;
|
|
|
|
goto errout;
|
|
|
|
}
|
|
|
|
|
2008-01-23 14:11:33 +08:00
|
|
|
if (meta_change_data(&meta->lvalue, tb[TCA_EM_META_LVALUE]) < 0 ||
|
|
|
|
meta_change_data(&meta->rvalue, tb[TCA_EM_META_RVALUE]) < 0)
|
2005-04-17 06:20:36 +08:00
|
|
|
goto errout;
|
|
|
|
|
|
|
|
m->datalen = sizeof(*meta);
|
|
|
|
m->data = (unsigned long) meta;
|
|
|
|
|
|
|
|
err = 0;
|
|
|
|
errout:
|
|
|
|
if (err && meta)
|
|
|
|
meta_delete(meta);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2014-10-06 12:27:53 +08:00
|
|
|
static void em_meta_destroy(struct tcf_ematch *m)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
if (m)
|
|
|
|
meta_delete((struct meta_match *) m->data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int em_meta_dump(struct sk_buff *skb, struct tcf_ematch *em)
|
|
|
|
{
|
|
|
|
struct meta_match *meta = (struct meta_match *) em->data;
|
|
|
|
struct tcf_meta_hdr hdr;
|
2016-04-09 16:49:22 +08:00
|
|
|
const struct meta_type_ops *ops;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
memset(&hdr, 0, sizeof(hdr));
|
|
|
|
memcpy(&hdr.left, &meta->lvalue.hdr, sizeof(hdr.left));
|
|
|
|
memcpy(&hdr.right, &meta->rvalue.hdr, sizeof(hdr.right));
|
|
|
|
|
2012-03-29 17:11:39 +08:00
|
|
|
if (nla_put(skb, TCA_EM_META_HDR, sizeof(hdr), &hdr))
|
|
|
|
goto nla_put_failure;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
ops = meta_type_ops(&meta->lvalue);
|
|
|
|
if (ops->dump(skb, &meta->lvalue, TCA_EM_META_LVALUE) < 0 ||
|
|
|
|
ops->dump(skb, &meta->rvalue, TCA_EM_META_RVALUE) < 0)
|
2008-01-23 14:11:33 +08:00
|
|
|
goto nla_put_failure;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
2008-01-23 14:11:33 +08:00
|
|
|
nla_put_failure:
|
2005-04-17 06:20:36 +08:00
|
|
|
return -1;
|
2007-02-09 22:25:16 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
static struct tcf_ematch_ops em_meta_ops = {
|
|
|
|
.kind = TCF_EM_META,
|
|
|
|
.change = em_meta_change,
|
|
|
|
.match = em_meta_match,
|
|
|
|
.destroy = em_meta_destroy,
|
|
|
|
.dump = em_meta_dump,
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.link = LIST_HEAD_INIT(em_meta_ops.link)
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init init_em_meta(void)
|
|
|
|
{
|
|
|
|
return tcf_em_register(&em_meta_ops);
|
|
|
|
}
|
|
|
|
|
2007-02-09 22:25:16 +08:00
|
|
|
static void __exit exit_em_meta(void)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
tcf_em_unregister(&em_meta_ops);
|
|
|
|
}
|
|
|
|
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
|
|
|
module_init(init_em_meta);
|
|
|
|
module_exit(exit_em_meta);
|
2007-07-12 10:46:26 +08:00
|
|
|
|
|
|
|
MODULE_ALIAS_TCF_EMATCH(TCF_EM_META);
|