2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* DECnet An implementation of the DECnet protocol suite for the LINUX
|
|
|
|
* operating system. DECnet is implemented using the BSD Socket
|
|
|
|
* interface as the means of communication with the user level.
|
|
|
|
*
|
|
|
|
* DECnet Routing Forwarding Information Base (Routing Tables)
|
|
|
|
*
|
|
|
|
* Author: Steve Whitehouse <SteveW@ACM.org>
|
|
|
|
* Mostly copied from the IPv4 routing code
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Changes:
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/net.h>
|
|
|
|
#include <linux/socket.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 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/sockios.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/skbuff.h>
|
|
|
|
#include <linux/rtnetlink.h>
|
|
|
|
#include <linux/proc_fs.h>
|
|
|
|
#include <linux/netdevice.h>
|
|
|
|
#include <linux/timer.h>
|
|
|
|
#include <linux/spinlock.h>
|
2011-07-27 07:09:06 +08:00
|
|
|
#include <linux/atomic.h>
|
2016-12-25 03:46:01 +08:00
|
|
|
#include <linux/uaccess.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/route.h> /* RTF_xxx */
|
|
|
|
#include <net/neighbour.h>
|
2007-03-26 14:06:12 +08:00
|
|
|
#include <net/netlink.h>
|
2015-01-06 06:57:47 +08:00
|
|
|
#include <net/tcp.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <net/dst.h>
|
|
|
|
#include <net/flow.h>
|
2006-08-10 06:56:46 +08:00
|
|
|
#include <net/fib_rules.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <net/dn.h>
|
|
|
|
#include <net/dn_route.h>
|
|
|
|
#include <net/dn_fib.h>
|
|
|
|
#include <net/dn_neigh.h>
|
|
|
|
#include <net/dn_dev.h>
|
|
|
|
|
|
|
|
struct dn_zone
|
|
|
|
{
|
|
|
|
struct dn_zone *dz_next;
|
|
|
|
struct dn_fib_node **dz_hash;
|
|
|
|
int dz_nent;
|
|
|
|
int dz_divisor;
|
|
|
|
u32 dz_hashmask;
|
|
|
|
#define DZ_HASHMASK(dz) ((dz)->dz_hashmask)
|
|
|
|
int dz_order;
|
2006-03-21 14:42:39 +08:00
|
|
|
__le16 dz_mask;
|
2005-04-17 06:20:36 +08:00
|
|
|
#define DZ_MASK(dz) ((dz)->dz_mask)
|
|
|
|
};
|
|
|
|
|
|
|
|
struct dn_hash
|
|
|
|
{
|
|
|
|
struct dn_zone *dh_zones[17];
|
|
|
|
struct dn_zone *dh_zone_list;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define dz_key_0(key) ((key).datum = 0)
|
|
|
|
|
|
|
|
#define for_nexthops(fi) { int nhsel; const struct dn_fib_nh *nh;\
|
2007-02-09 22:24:40 +08:00
|
|
|
for(nhsel = 0, nh = (fi)->fib_nh; nhsel < (fi)->fib_nhs; nh++, nhsel++)
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#define endfor_nexthops(fi) }
|
|
|
|
|
|
|
|
#define DN_MAX_DIVISOR 1024
|
|
|
|
#define DN_S_ZOMBIE 1
|
|
|
|
#define DN_S_ACCESSED 2
|
|
|
|
|
|
|
|
#define DN_FIB_SCAN(f, fp) \
|
|
|
|
for( ; ((f) = *(fp)) != NULL; (fp) = &(f)->fn_next)
|
|
|
|
|
|
|
|
#define DN_FIB_SCAN_KEY(f, fp, key) \
|
|
|
|
for( ; ((f) = *(fp)) != NULL && dn_key_eq((f)->fn_key, (key)); (fp) = &(f)->fn_next)
|
|
|
|
|
|
|
|
#define RT_TABLE_MIN 1
|
2006-08-11 14:11:47 +08:00
|
|
|
#define DN_FIB_TABLE_HASHSZ 256
|
|
|
|
static struct hlist_head dn_fib_table_hash[DN_FIB_TABLE_HASHSZ];
|
2005-04-17 06:20:36 +08:00
|
|
|
static DEFINE_RWLOCK(dn_fib_tables_lock);
|
|
|
|
|
2006-12-07 12:33:20 +08:00
|
|
|
static struct kmem_cache *dn_hash_kmem __read_mostly;
|
2005-04-17 06:20:36 +08:00
|
|
|
static int dn_fib_hash_zombies;
|
|
|
|
|
|
|
|
static inline dn_fib_idx_t dn_hash(dn_fib_key_t key, struct dn_zone *dz)
|
|
|
|
{
|
2008-11-27 16:12:47 +08:00
|
|
|
u16 h = le16_to_cpu(key.datum)>>(16 - dz->dz_order);
|
2005-04-17 06:20:36 +08:00
|
|
|
h ^= (h >> 10);
|
|
|
|
h ^= (h >> 6);
|
|
|
|
h &= DZ_HASHMASK(dz);
|
|
|
|
return *(dn_fib_idx_t *)&h;
|
|
|
|
}
|
|
|
|
|
2006-03-21 14:42:39 +08:00
|
|
|
static inline dn_fib_key_t dz_key(__le16 dst, struct dn_zone *dz)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
dn_fib_key_t k;
|
|
|
|
k.datum = dst & DZ_MASK(dz);
|
|
|
|
return k;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline struct dn_fib_node **dn_chain_p(dn_fib_key_t key, struct dn_zone *dz)
|
|
|
|
{
|
|
|
|
return &dz->dz_hash[dn_hash(key, dz).datum];
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline struct dn_fib_node *dz_chain(dn_fib_key_t key, struct dn_zone *dz)
|
|
|
|
{
|
|
|
|
return dz->dz_hash[dn_hash(key, dz).datum];
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int dn_key_eq(dn_fib_key_t a, dn_fib_key_t b)
|
|
|
|
{
|
|
|
|
return a.datum == b.datum;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int dn_key_leq(dn_fib_key_t a, dn_fib_key_t b)
|
|
|
|
{
|
|
|
|
return a.datum <= b.datum;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void dn_rebuild_zone(struct dn_zone *dz,
|
|
|
|
struct dn_fib_node **old_ht,
|
|
|
|
int old_divisor)
|
|
|
|
{
|
2011-04-18 11:47:07 +08:00
|
|
|
struct dn_fib_node *f, **fp, *next;
|
2005-04-17 06:20:36 +08:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for(i = 0; i < old_divisor; i++) {
|
2011-04-18 11:47:07 +08:00
|
|
|
for(f = old_ht[i]; f; f = next) {
|
|
|
|
next = f->fn_next;
|
2005-04-17 06:20:36 +08:00
|
|
|
for(fp = dn_chain_p(f->fn_key, dz);
|
|
|
|
*fp && dn_key_leq((*fp)->fn_key, f->fn_key);
|
|
|
|
fp = &(*fp)->fn_next)
|
|
|
|
/* NOTHING */;
|
|
|
|
f->fn_next = *fp;
|
|
|
|
*fp = f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dn_rehash_zone(struct dn_zone *dz)
|
|
|
|
{
|
|
|
|
struct dn_fib_node **ht, **old_ht;
|
|
|
|
int old_divisor, new_divisor;
|
|
|
|
u32 new_hashmask;
|
|
|
|
|
|
|
|
old_divisor = dz->dz_divisor;
|
|
|
|
|
2011-07-01 17:43:03 +08:00
|
|
|
switch (old_divisor) {
|
|
|
|
case 16:
|
|
|
|
new_divisor = 256;
|
|
|
|
new_hashmask = 0xFF;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printk(KERN_DEBUG "DECnet: dn_rehash_zone: BUG! %d\n",
|
|
|
|
old_divisor);
|
|
|
|
case 256:
|
|
|
|
new_divisor = 1024;
|
|
|
|
new_hashmask = 0x3FF;
|
|
|
|
break;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2006-07-22 05:51:30 +08:00
|
|
|
ht = kcalloc(new_divisor, sizeof(struct dn_fib_node*), GFP_KERNEL);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (ht == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
write_lock_bh(&dn_fib_tables_lock);
|
|
|
|
old_ht = dz->dz_hash;
|
|
|
|
dz->dz_hash = ht;
|
|
|
|
dz->dz_hashmask = new_hashmask;
|
|
|
|
dz->dz_divisor = new_divisor;
|
|
|
|
dn_rebuild_zone(dz, old_ht, old_divisor);
|
|
|
|
write_unlock_bh(&dn_fib_tables_lock);
|
|
|
|
kfree(old_ht);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dn_free_node(struct dn_fib_node *f)
|
|
|
|
{
|
|
|
|
dn_fib_release_info(DN_FIB_INFO(f));
|
|
|
|
kmem_cache_free(dn_hash_kmem, f);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static struct dn_zone *dn_new_zone(struct dn_hash *table, int z)
|
|
|
|
{
|
|
|
|
int i;
|
2006-07-22 05:51:30 +08:00
|
|
|
struct dn_zone *dz = kzalloc(sizeof(struct dn_zone), GFP_KERNEL);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!dz)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (z) {
|
|
|
|
dz->dz_divisor = 16;
|
|
|
|
dz->dz_hashmask = 0x0F;
|
|
|
|
} else {
|
|
|
|
dz->dz_divisor = 1;
|
|
|
|
dz->dz_hashmask = 0;
|
|
|
|
}
|
|
|
|
|
2006-07-22 05:51:30 +08:00
|
|
|
dz->dz_hash = kcalloc(dz->dz_divisor, sizeof(struct dn_fib_node *), GFP_KERNEL);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!dz->dz_hash) {
|
|
|
|
kfree(dz);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
dz->dz_order = z;
|
|
|
|
dz->dz_mask = dnet_make_mask(z);
|
|
|
|
|
|
|
|
for(i = z + 1; i <= 16; i++)
|
|
|
|
if (table->dh_zones[i])
|
|
|
|
break;
|
|
|
|
|
|
|
|
write_lock_bh(&dn_fib_tables_lock);
|
|
|
|
if (i>16) {
|
|
|
|
dz->dz_next = table->dh_zone_list;
|
|
|
|
table->dh_zone_list = dz;
|
|
|
|
} else {
|
|
|
|
dz->dz_next = table->dh_zones[i]->dz_next;
|
|
|
|
table->dh_zones[i]->dz_next = dz;
|
|
|
|
}
|
|
|
|
table->dh_zones[z] = dz;
|
|
|
|
write_unlock_bh(&dn_fib_tables_lock);
|
|
|
|
return dz;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-21 15:45:28 +08:00
|
|
|
static int dn_fib_nh_match(struct rtmsg *r, struct nlmsghdr *nlh, struct nlattr *attrs[], struct dn_fib_info *fi)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct rtnexthop *nhp;
|
|
|
|
int nhlen;
|
|
|
|
|
2013-03-21 15:45:28 +08:00
|
|
|
if (attrs[RTA_PRIORITY] &&
|
|
|
|
nla_get_u32(attrs[RTA_PRIORITY]) != fi->fib_priority)
|
2005-04-17 06:20:36 +08:00
|
|
|
return 1;
|
|
|
|
|
2013-03-21 15:45:28 +08:00
|
|
|
if (attrs[RTA_OIF] || attrs[RTA_GATEWAY]) {
|
|
|
|
if ((!attrs[RTA_OIF] || nla_get_u32(attrs[RTA_OIF]) == fi->fib_nh->nh_oif) &&
|
|
|
|
(!attrs[RTA_GATEWAY] || nla_get_le16(attrs[RTA_GATEWAY]) != fi->fib_nh->nh_gw))
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2013-03-21 15:45:28 +08:00
|
|
|
if (!attrs[RTA_MULTIPATH])
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
|
2013-03-21 15:45:28 +08:00
|
|
|
nhp = nla_data(attrs[RTA_MULTIPATH]);
|
|
|
|
nhlen = nla_len(attrs[RTA_MULTIPATH]);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
for_nexthops(fi) {
|
|
|
|
int attrlen = nhlen - sizeof(struct rtnexthop);
|
2006-03-21 14:42:39 +08:00
|
|
|
__le16 gw;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (attrlen < 0 || (nhlen -= nhp->rtnh_len) < 0)
|
|
|
|
return -EINVAL;
|
|
|
|
if (nhp->rtnh_ifindex && nhp->rtnh_ifindex != nh->nh_oif)
|
|
|
|
return 1;
|
|
|
|
if (attrlen) {
|
2013-03-21 15:45:28 +08:00
|
|
|
struct nlattr *gw_attr;
|
|
|
|
|
|
|
|
gw_attr = nla_find((struct nlattr *) (nhp + 1), attrlen, RTA_GATEWAY);
|
|
|
|
gw = gw_attr ? nla_get_le16(gw_attr) : 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (gw && gw != nh->nh_gw)
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
nhp = RTNH_NEXT(nhp);
|
|
|
|
} endfor_nexthops(fi);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-11-11 06:10:15 +08:00
|
|
|
static inline size_t dn_fib_nlmsg_size(struct dn_fib_info *fi)
|
|
|
|
{
|
2006-11-13 15:02:01 +08:00
|
|
|
size_t payload = NLMSG_ALIGN(sizeof(struct rtmsg))
|
2006-11-11 06:10:15 +08:00
|
|
|
+ nla_total_size(4) /* RTA_TABLE */
|
|
|
|
+ nla_total_size(2) /* RTA_DST */
|
2015-01-06 06:57:47 +08:00
|
|
|
+ nla_total_size(4) /* RTA_PRIORITY */
|
|
|
|
+ nla_total_size(TCP_CA_NAME_MAX); /* RTAX_CC_ALGO */
|
2006-11-11 06:10:15 +08:00
|
|
|
|
|
|
|
/* space for nested metrics */
|
|
|
|
payload += nla_total_size((RTAX_MAX * nla_total_size(4)));
|
|
|
|
|
|
|
|
if (fi->fib_nhs) {
|
|
|
|
/* Also handles the special case fib_nhs == 1 */
|
|
|
|
|
|
|
|
/* each nexthop is packed in an attribute */
|
|
|
|
size_t nhsize = nla_total_size(sizeof(struct rtnexthop));
|
|
|
|
|
|
|
|
/* may contain a gateway attribute */
|
|
|
|
nhsize += nla_total_size(4);
|
|
|
|
|
|
|
|
/* all nexthops are packed in a nested attribute */
|
|
|
|
payload += nla_total_size(fi->fib_nhs * nhsize);
|
|
|
|
}
|
|
|
|
|
|
|
|
return payload;
|
|
|
|
}
|
|
|
|
|
2012-09-08 04:12:54 +08:00
|
|
|
static int dn_fib_dump_info(struct sk_buff *skb, u32 portid, u32 seq, int event,
|
2007-02-09 22:24:40 +08:00
|
|
|
u32 tb_id, u8 type, u8 scope, void *dst, int dst_len,
|
|
|
|
struct dn_fib_info *fi, unsigned int flags)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2007-02-09 22:24:40 +08:00
|
|
|
struct rtmsg *rtm;
|
|
|
|
struct nlmsghdr *nlh;
|
|
|
|
|
2012-09-08 04:12:54 +08:00
|
|
|
nlh = nlmsg_put(skb, portid, seq, event, sizeof(*rtm), flags);
|
2012-06-27 12:47:21 +08:00
|
|
|
if (!nlh)
|
2012-06-27 07:36:15 +08:00
|
|
|
return -EMSGSIZE;
|
|
|
|
|
2012-06-27 12:47:21 +08:00
|
|
|
rtm = nlmsg_data(nlh);
|
2007-02-09 22:24:40 +08:00
|
|
|
rtm->rtm_family = AF_DECnet;
|
|
|
|
rtm->rtm_dst_len = dst_len;
|
|
|
|
rtm->rtm_src_len = 0;
|
|
|
|
rtm->rtm_tos = 0;
|
|
|
|
rtm->rtm_table = tb_id;
|
|
|
|
rtm->rtm_flags = fi->fib_flags;
|
|
|
|
rtm->rtm_scope = scope;
|
2005-04-17 06:20:36 +08:00
|
|
|
rtm->rtm_type = type;
|
2007-02-09 22:24:40 +08:00
|
|
|
rtm->rtm_protocol = fi->fib_protocol;
|
2012-06-27 07:36:15 +08:00
|
|
|
|
|
|
|
if (nla_put_u32(skb, RTA_TABLE, tb_id) < 0)
|
|
|
|
goto errout;
|
|
|
|
|
|
|
|
if (rtm->rtm_dst_len &&
|
|
|
|
nla_put(skb, RTA_DST, 2, dst) < 0)
|
|
|
|
goto errout;
|
|
|
|
|
|
|
|
if (fi->fib_priority &&
|
|
|
|
nla_put_u32(skb, RTA_PRIORITY, fi->fib_priority) < 0)
|
|
|
|
goto errout;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (rtnetlink_put_metrics(skb, fi->fib_metrics) < 0)
|
2012-06-27 07:36:15 +08:00
|
|
|
goto errout;
|
|
|
|
|
2007-02-09 22:24:40 +08:00
|
|
|
if (fi->fib_nhs == 1) {
|
2012-06-27 07:36:15 +08:00
|
|
|
if (fi->fib_nh->nh_gw &&
|
|
|
|
nla_put_le16(skb, RTA_GATEWAY, fi->fib_nh->nh_gw) < 0)
|
|
|
|
goto errout;
|
|
|
|
|
|
|
|
if (fi->fib_nh->nh_oif &&
|
|
|
|
nla_put_u32(skb, RTA_OIF, fi->fib_nh->nh_oif) < 0)
|
|
|
|
goto errout;
|
2007-02-09 22:24:40 +08:00
|
|
|
}
|
2012-06-27 07:36:15 +08:00
|
|
|
|
2007-02-09 22:24:40 +08:00
|
|
|
if (fi->fib_nhs > 1) {
|
|
|
|
struct rtnexthop *nhp;
|
2012-06-27 07:36:15 +08:00
|
|
|
struct nlattr *mp_head;
|
|
|
|
|
|
|
|
if (!(mp_head = nla_nest_start(skb, RTA_MULTIPATH)))
|
|
|
|
goto errout;
|
2007-02-09 22:24:40 +08:00
|
|
|
|
|
|
|
for_nexthops(fi) {
|
2012-06-27 07:36:15 +08:00
|
|
|
if (!(nhp = nla_reserve_nohdr(skb, sizeof(*nhp))))
|
|
|
|
goto errout;
|
|
|
|
|
2007-02-09 22:24:40 +08:00
|
|
|
nhp->rtnh_flags = nh->nh_flags & 0xFF;
|
|
|
|
nhp->rtnh_hops = nh->nh_weight - 1;
|
|
|
|
nhp->rtnh_ifindex = nh->nh_oif;
|
2012-06-27 07:36:15 +08:00
|
|
|
|
|
|
|
if (nh->nh_gw &&
|
|
|
|
nla_put_le16(skb, RTA_GATEWAY, nh->nh_gw) < 0)
|
|
|
|
goto errout;
|
|
|
|
|
2007-04-20 11:29:13 +08:00
|
|
|
nhp->rtnh_len = skb_tail_pointer(skb) - (unsigned char *)nhp;
|
2007-02-09 22:24:40 +08:00
|
|
|
} endfor_nexthops(fi);
|
2012-06-27 07:36:15 +08:00
|
|
|
|
|
|
|
nla_nest_end(skb, mp_head);
|
2007-02-09 22:24:40 +08:00
|
|
|
}
|
|
|
|
|
2015-01-17 05:09:00 +08:00
|
|
|
nlmsg_end(skb, nlh);
|
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-06-27 07:36:15 +08:00
|
|
|
errout:
|
|
|
|
nlmsg_cancel(skb, nlh);
|
2007-02-09 22:24:40 +08:00
|
|
|
return -EMSGSIZE;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-08-11 14:08:33 +08:00
|
|
|
static void dn_rtmsg_fib(int event, struct dn_fib_node *f, int z, u32 tb_id,
|
2007-02-09 22:24:40 +08:00
|
|
|
struct nlmsghdr *nlh, struct netlink_skb_parms *req)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2007-02-09 22:24:40 +08:00
|
|
|
struct sk_buff *skb;
|
2012-09-08 04:12:54 +08:00
|
|
|
u32 portid = req ? req->portid : 0;
|
2006-08-15 15:33:35 +08:00
|
|
|
int err = -ENOBUFS;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-02-09 22:24:40 +08:00
|
|
|
skb = nlmsg_new(dn_fib_nlmsg_size(DN_FIB_INFO(f)), GFP_KERNEL);
|
|
|
|
if (skb == NULL)
|
2006-08-15 15:33:35 +08:00
|
|
|
goto errout;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-09-08 04:12:54 +08:00
|
|
|
err = dn_fib_dump_info(skb, portid, nlh->nlmsg_seq, event, tb_id,
|
2006-08-15 15:33:35 +08:00
|
|
|
f->fn_type, f->fn_scope, &f->fn_key, z,
|
|
|
|
DN_FIB_INFO(f), 0);
|
2007-02-01 15:16:40 +08:00
|
|
|
if (err < 0) {
|
|
|
|
/* -EMSGSIZE implies BUG in dn_fib_nlmsg_size() */
|
|
|
|
WARN_ON(err == -EMSGSIZE);
|
|
|
|
kfree_skb(skb);
|
|
|
|
goto errout;
|
|
|
|
}
|
2012-09-08 04:12:54 +08:00
|
|
|
rtnl_notify(skb, &init_net, portid, RTNLGRP_DECnet_ROUTE, nlh, GFP_KERNEL);
|
2009-02-25 15:18:28 +08:00
|
|
|
return;
|
2006-08-15 15:33:35 +08:00
|
|
|
errout:
|
|
|
|
if (err < 0)
|
2007-11-20 14:26:51 +08:00
|
|
|
rtnl_set_sk_err(&init_net, RTNLGRP_DECnet_ROUTE, err);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2007-02-09 22:24:40 +08:00
|
|
|
static __inline__ int dn_hash_dump_bucket(struct sk_buff *skb,
|
2005-04-17 06:20:36 +08:00
|
|
|
struct netlink_callback *cb,
|
|
|
|
struct dn_fib_table *tb,
|
|
|
|
struct dn_zone *dz,
|
|
|
|
struct dn_fib_node *f)
|
|
|
|
{
|
|
|
|
int i, s_i;
|
|
|
|
|
2006-08-11 14:11:47 +08:00
|
|
|
s_i = cb->args[4];
|
2005-04-17 06:20:36 +08:00
|
|
|
for(i = 0; f; i++, f = f->fn_next) {
|
|
|
|
if (i < s_i)
|
|
|
|
continue;
|
|
|
|
if (f->fn_state & DN_S_ZOMBIE)
|
|
|
|
continue;
|
2012-09-08 04:12:54 +08:00
|
|
|
if (dn_fib_dump_info(skb, NETLINK_CB(cb->skb).portid,
|
2005-04-17 06:20:36 +08:00
|
|
|
cb->nlh->nlmsg_seq,
|
|
|
|
RTM_NEWROUTE,
|
2007-02-09 22:24:40 +08:00
|
|
|
tb->n,
|
2005-04-17 06:20:36 +08:00
|
|
|
(f->fn_state & DN_S_ZOMBIE) ? 0 : f->fn_type,
|
2007-02-09 22:24:40 +08:00
|
|
|
f->fn_scope, &f->fn_key, dz->dz_order,
|
2005-06-19 13:54:12 +08:00
|
|
|
f->fn_info, NLM_F_MULTI) < 0) {
|
2006-08-11 14:11:47 +08:00
|
|
|
cb->args[4] = i;
|
2005-04-17 06:20:36 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
2006-08-11 14:11:47 +08:00
|
|
|
cb->args[4] = i;
|
2005-04-17 06:20:36 +08:00
|
|
|
return skb->len;
|
|
|
|
}
|
|
|
|
|
2007-02-09 22:24:40 +08:00
|
|
|
static __inline__ int dn_hash_dump_zone(struct sk_buff *skb,
|
2005-04-17 06:20:36 +08:00
|
|
|
struct netlink_callback *cb,
|
|
|
|
struct dn_fib_table *tb,
|
|
|
|
struct dn_zone *dz)
|
|
|
|
{
|
|
|
|
int h, s_h;
|
|
|
|
|
2006-08-11 14:11:47 +08:00
|
|
|
s_h = cb->args[3];
|
2005-04-17 06:20:36 +08:00
|
|
|
for(h = 0; h < dz->dz_divisor; h++) {
|
|
|
|
if (h < s_h)
|
|
|
|
continue;
|
|
|
|
if (h > s_h)
|
2006-08-11 14:11:47 +08:00
|
|
|
memset(&cb->args[4], 0, sizeof(cb->args) - 4*sizeof(cb->args[0]));
|
2005-04-17 06:20:36 +08:00
|
|
|
if (dz->dz_hash == NULL || dz->dz_hash[h] == NULL)
|
|
|
|
continue;
|
|
|
|
if (dn_hash_dump_bucket(skb, cb, tb, dz, dz->dz_hash[h]) < 0) {
|
2006-08-11 14:11:47 +08:00
|
|
|
cb->args[3] = h;
|
2005-04-17 06:20:36 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
2006-08-11 14:11:47 +08:00
|
|
|
cb->args[3] = h;
|
2005-04-17 06:20:36 +08:00
|
|
|
return skb->len;
|
|
|
|
}
|
|
|
|
|
2007-02-09 22:24:40 +08:00
|
|
|
static int dn_fib_table_dump(struct dn_fib_table *tb, struct sk_buff *skb,
|
|
|
|
struct netlink_callback *cb)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2007-02-09 22:24:40 +08:00
|
|
|
int m, s_m;
|
2005-04-17 06:20:36 +08:00
|
|
|
struct dn_zone *dz;
|
|
|
|
struct dn_hash *table = (struct dn_hash *)tb->data;
|
|
|
|
|
2006-08-11 14:11:47 +08:00
|
|
|
s_m = cb->args[2];
|
2005-04-17 06:20:36 +08:00
|
|
|
read_lock(&dn_fib_tables_lock);
|
|
|
|
for(dz = table->dh_zone_list, m = 0; dz; dz = dz->dz_next, m++) {
|
|
|
|
if (m < s_m)
|
|
|
|
continue;
|
|
|
|
if (m > s_m)
|
2006-08-11 14:11:47 +08:00
|
|
|
memset(&cb->args[3], 0, sizeof(cb->args) - 3*sizeof(cb->args[0]));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (dn_hash_dump_zone(skb, cb, tb, dz) < 0) {
|
2006-08-11 14:11:47 +08:00
|
|
|
cb->args[2] = m;
|
2005-04-17 06:20:36 +08:00
|
|
|
read_unlock(&dn_fib_tables_lock);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
read_unlock(&dn_fib_tables_lock);
|
2006-08-11 14:11:47 +08:00
|
|
|
cb->args[2] = m;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-02-09 22:24:40 +08:00
|
|
|
return skb->len;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2006-08-11 14:11:47 +08:00
|
|
|
int dn_fib_dump(struct sk_buff *skb, struct netlink_callback *cb)
|
|
|
|
{
|
2008-03-26 01:26:21 +08:00
|
|
|
struct net *net = sock_net(skb->sk);
|
2006-08-11 14:11:47 +08:00
|
|
|
unsigned int h, s_h;
|
|
|
|
unsigned int e = 0, s_e;
|
|
|
|
struct dn_fib_table *tb;
|
|
|
|
int dumped = 0;
|
|
|
|
|
2009-11-26 07:14:13 +08:00
|
|
|
if (!net_eq(net, &init_net))
|
2007-11-30 21:21:31 +08:00
|
|
|
return 0;
|
|
|
|
|
2013-03-27 14:47:04 +08:00
|
|
|
if (nlmsg_len(cb->nlh) >= sizeof(struct rtmsg) &&
|
2012-06-27 12:47:21 +08:00
|
|
|
((struct rtmsg *)nlmsg_data(cb->nlh))->rtm_flags&RTM_F_CLONED)
|
2006-08-11 14:11:47 +08:00
|
|
|
return dn_cache_dump(skb, cb);
|
|
|
|
|
|
|
|
s_h = cb->args[0];
|
|
|
|
s_e = cb->args[1];
|
|
|
|
|
|
|
|
for (h = s_h; h < DN_FIB_TABLE_HASHSZ; h++, s_h = 0) {
|
|
|
|
e = 0;
|
hlist: drop the node parameter from iterators
I'm not sure why, but the hlist for each entry iterators were conceived
list_for_each_entry(pos, head, member)
The hlist ones were greedy and wanted an extra parameter:
hlist_for_each_entry(tpos, pos, head, member)
Why did they need an extra pos parameter? I'm not quite sure. Not only
they don't really need it, it also prevents the iterator from looking
exactly like the list iterator, which is unfortunate.
Besides the semantic patch, there was some manual work required:
- Fix up the actual hlist iterators in linux/list.h
- Fix up the declaration of other iterators based on the hlist ones.
- A very small amount of places were using the 'node' parameter, this
was modified to use 'obj->member' instead.
- Coccinelle didn't handle the hlist_for_each_entry_safe iterator
properly, so those had to be fixed up manually.
The semantic patch which is mostly the work of Peter Senna Tschudin is here:
@@
iterator name hlist_for_each_entry, hlist_for_each_entry_continue, hlist_for_each_entry_from, hlist_for_each_entry_rcu, hlist_for_each_entry_rcu_bh, hlist_for_each_entry_continue_rcu_bh, for_each_busy_worker, ax25_uid_for_each, ax25_for_each, inet_bind_bucket_for_each, sctp_for_each_hentry, sk_for_each, sk_for_each_rcu, sk_for_each_from, sk_for_each_safe, sk_for_each_bound, hlist_for_each_entry_safe, hlist_for_each_entry_continue_rcu, nr_neigh_for_each, nr_neigh_for_each_safe, nr_node_for_each, nr_node_for_each_safe, for_each_gfn_indirect_valid_sp, for_each_gfn_sp, for_each_host;
type T;
expression a,c,d,e;
identifier b;
statement S;
@@
-T b;
<+... when != b
(
hlist_for_each_entry(a,
- b,
c, d) S
|
hlist_for_each_entry_continue(a,
- b,
c) S
|
hlist_for_each_entry_from(a,
- b,
c) S
|
hlist_for_each_entry_rcu(a,
- b,
c, d) S
|
hlist_for_each_entry_rcu_bh(a,
- b,
c, d) S
|
hlist_for_each_entry_continue_rcu_bh(a,
- b,
c) S
|
for_each_busy_worker(a, c,
- b,
d) S
|
ax25_uid_for_each(a,
- b,
c) S
|
ax25_for_each(a,
- b,
c) S
|
inet_bind_bucket_for_each(a,
- b,
c) S
|
sctp_for_each_hentry(a,
- b,
c) S
|
sk_for_each(a,
- b,
c) S
|
sk_for_each_rcu(a,
- b,
c) S
|
sk_for_each_from
-(a, b)
+(a)
S
+ sk_for_each_from(a) S
|
sk_for_each_safe(a,
- b,
c, d) S
|
sk_for_each_bound(a,
- b,
c) S
|
hlist_for_each_entry_safe(a,
- b,
c, d, e) S
|
hlist_for_each_entry_continue_rcu(a,
- b,
c) S
|
nr_neigh_for_each(a,
- b,
c) S
|
nr_neigh_for_each_safe(a,
- b,
c, d) S
|
nr_node_for_each(a,
- b,
c) S
|
nr_node_for_each_safe(a,
- b,
c, d) S
|
- for_each_gfn_sp(a, c, d, b) S
+ for_each_gfn_sp(a, c, d) S
|
- for_each_gfn_indirect_valid_sp(a, c, d, b) S
+ for_each_gfn_indirect_valid_sp(a, c, d) S
|
for_each_host(a,
- b,
c) S
|
for_each_host_safe(a,
- b,
c, d) S
|
for_each_mesh_entry(a,
- b,
c, d) S
)
...+>
[akpm@linux-foundation.org: drop bogus change from net/ipv4/raw.c]
[akpm@linux-foundation.org: drop bogus hunk from net/ipv6/raw.c]
[akpm@linux-foundation.org: checkpatch fixes]
[akpm@linux-foundation.org: fix warnings]
[akpm@linux-foudnation.org: redo intrusive kvm changes]
Tested-by: Peter Senna Tschudin <peter.senna@gmail.com>
Acked-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
Cc: Wu Fengguang <fengguang.wu@intel.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-02-28 09:06:00 +08:00
|
|
|
hlist_for_each_entry(tb, &dn_fib_table_hash[h], hlist) {
|
2006-08-11 14:11:47 +08:00
|
|
|
if (e < s_e)
|
|
|
|
goto next;
|
|
|
|
if (dumped)
|
|
|
|
memset(&cb->args[2], 0, sizeof(cb->args) -
|
2007-02-09 22:24:40 +08:00
|
|
|
2 * sizeof(cb->args[0]));
|
2006-08-11 14:11:47 +08:00
|
|
|
if (tb->dump(tb, skb, cb) < 0)
|
|
|
|
goto out;
|
|
|
|
dumped = 1;
|
|
|
|
next:
|
|
|
|
e++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
out:
|
|
|
|
cb->args[1] = e;
|
|
|
|
cb->args[0] = h;
|
|
|
|
|
|
|
|
return skb->len;
|
|
|
|
}
|
|
|
|
|
2013-03-21 15:45:28 +08:00
|
|
|
static int dn_fib_table_insert(struct dn_fib_table *tb, struct rtmsg *r, struct nlattr *attrs[],
|
|
|
|
struct nlmsghdr *n, struct netlink_skb_parms *req)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct dn_hash *table = (struct dn_hash *)tb->data;
|
|
|
|
struct dn_fib_node *new_f, *f, **fp, **del_fp;
|
|
|
|
struct dn_zone *dz;
|
|
|
|
struct dn_fib_info *fi;
|
2007-02-09 22:24:40 +08:00
|
|
|
int z = r->rtm_dst_len;
|
2005-04-17 06:20:36 +08:00
|
|
|
int type = r->rtm_type;
|
|
|
|
dn_fib_key_t key;
|
2007-02-09 22:24:40 +08:00
|
|
|
int err;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-02-09 22:24:40 +08:00
|
|
|
if (z > 16)
|
|
|
|
return -EINVAL;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
dz = table->dh_zones[z];
|
|
|
|
if (!dz && !(dz = dn_new_zone(table, z)))
|
|
|
|
return -ENOBUFS;
|
|
|
|
|
|
|
|
dz_key_0(key);
|
2013-03-21 15:45:28 +08:00
|
|
|
if (attrs[RTA_DST]) {
|
|
|
|
__le16 dst = nla_get_le16(attrs[RTA_DST]);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (dst & ~DZ_MASK(dz))
|
|
|
|
return -EINVAL;
|
|
|
|
key = dz_key(dst, dz);
|
|
|
|
}
|
|
|
|
|
2013-03-21 15:45:28 +08:00
|
|
|
if ((fi = dn_fib_create_info(r, attrs, n, &err)) == NULL)
|
2007-02-09 22:24:40 +08:00
|
|
|
return err;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (dz->dz_nent > (dz->dz_divisor << 2) &&
|
|
|
|
dz->dz_divisor > DN_MAX_DIVISOR &&
|
|
|
|
(z==16 || (1<<z) > dz->dz_divisor))
|
|
|
|
dn_rehash_zone(dz);
|
|
|
|
|
|
|
|
fp = dn_chain_p(key, dz);
|
|
|
|
|
|
|
|
DN_FIB_SCAN(f, fp) {
|
|
|
|
if (dn_key_leq(key, f->fn_key))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
del_fp = NULL;
|
|
|
|
|
|
|
|
if (f && (f->fn_state & DN_S_ZOMBIE) &&
|
|
|
|
dn_key_eq(f->fn_key, key)) {
|
|
|
|
del_fp = fp;
|
|
|
|
fp = &f->fn_next;
|
|
|
|
f = *fp;
|
|
|
|
goto create;
|
|
|
|
}
|
|
|
|
|
|
|
|
DN_FIB_SCAN_KEY(f, fp, key) {
|
|
|
|
if (fi->fib_priority <= DN_FIB_INFO(f)->fib_priority)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (f && dn_key_eq(f->fn_key, key) &&
|
|
|
|
fi->fib_priority == DN_FIB_INFO(f)->fib_priority) {
|
|
|
|
struct dn_fib_node **ins_fp;
|
|
|
|
|
|
|
|
err = -EEXIST;
|
|
|
|
if (n->nlmsg_flags & NLM_F_EXCL)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (n->nlmsg_flags & NLM_F_REPLACE) {
|
|
|
|
del_fp = fp;
|
|
|
|
fp = &f->fn_next;
|
|
|
|
f = *fp;
|
|
|
|
goto replace;
|
|
|
|
}
|
|
|
|
|
|
|
|
ins_fp = fp;
|
|
|
|
err = -EEXIST;
|
|
|
|
|
|
|
|
DN_FIB_SCAN_KEY(f, fp, key) {
|
|
|
|
if (fi->fib_priority != DN_FIB_INFO(f)->fib_priority)
|
|
|
|
break;
|
2009-11-30 08:55:45 +08:00
|
|
|
if (f->fn_type == type &&
|
|
|
|
f->fn_scope == r->rtm_scope &&
|
|
|
|
DN_FIB_INFO(f) == fi)
|
2005-04-17 06:20:36 +08:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(n->nlmsg_flags & NLM_F_APPEND)) {
|
|
|
|
fp = ins_fp;
|
|
|
|
f = *fp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
create:
|
|
|
|
err = -ENOENT;
|
|
|
|
if (!(n->nlmsg_flags & NLM_F_CREATE))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
replace:
|
|
|
|
err = -ENOBUFS;
|
2007-02-10 17:45:03 +08:00
|
|
|
new_f = kmem_cache_zalloc(dn_hash_kmem, GFP_KERNEL);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (new_f == NULL)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
new_f->fn_key = key;
|
|
|
|
new_f->fn_type = type;
|
|
|
|
new_f->fn_scope = r->rtm_scope;
|
|
|
|
DN_FIB_INFO(new_f) = fi;
|
|
|
|
|
|
|
|
new_f->fn_next = f;
|
|
|
|
write_lock_bh(&dn_fib_tables_lock);
|
|
|
|
*fp = new_f;
|
|
|
|
write_unlock_bh(&dn_fib_tables_lock);
|
|
|
|
dz->dz_nent++;
|
|
|
|
|
|
|
|
if (del_fp) {
|
|
|
|
f = *del_fp;
|
|
|
|
write_lock_bh(&dn_fib_tables_lock);
|
|
|
|
*del_fp = f->fn_next;
|
|
|
|
write_unlock_bh(&dn_fib_tables_lock);
|
|
|
|
|
|
|
|
if (!(f->fn_state & DN_S_ZOMBIE))
|
|
|
|
dn_rtmsg_fib(RTM_DELROUTE, f, z, tb->n, n, req);
|
|
|
|
if (f->fn_state & DN_S_ACCESSED)
|
|
|
|
dn_rt_cache_flush(-1);
|
|
|
|
dn_free_node(f);
|
|
|
|
dz->dz_nent--;
|
|
|
|
} else {
|
|
|
|
dn_rt_cache_flush(-1);
|
|
|
|
}
|
|
|
|
|
2007-02-09 22:24:40 +08:00
|
|
|
dn_rtmsg_fib(RTM_NEWROUTE, new_f, z, tb->n, n, req);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-02-09 22:24:40 +08:00
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
out:
|
|
|
|
dn_fib_release_info(fi);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-21 15:45:28 +08:00
|
|
|
static int dn_fib_table_delete(struct dn_fib_table *tb, struct rtmsg *r, struct nlattr *attrs[],
|
|
|
|
struct nlmsghdr *n, struct netlink_skb_parms *req)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct dn_hash *table = (struct dn_hash*)tb->data;
|
|
|
|
struct dn_fib_node **fp, **del_fp, *f;
|
2007-02-09 22:24:40 +08:00
|
|
|
int z = r->rtm_dst_len;
|
2005-04-17 06:20:36 +08:00
|
|
|
struct dn_zone *dz;
|
|
|
|
dn_fib_key_t key;
|
|
|
|
int matched;
|
|
|
|
|
|
|
|
|
2007-02-09 22:24:40 +08:00
|
|
|
if (z > 16)
|
|
|
|
return -EINVAL;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if ((dz = table->dh_zones[z]) == NULL)
|
|
|
|
return -ESRCH;
|
|
|
|
|
|
|
|
dz_key_0(key);
|
2013-03-21 15:45:28 +08:00
|
|
|
if (attrs[RTA_DST]) {
|
|
|
|
__le16 dst = nla_get_le16(attrs[RTA_DST]);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (dst & ~DZ_MASK(dz))
|
|
|
|
return -EINVAL;
|
|
|
|
key = dz_key(dst, dz);
|
|
|
|
}
|
|
|
|
|
|
|
|
fp = dn_chain_p(key, dz);
|
|
|
|
|
|
|
|
DN_FIB_SCAN(f, fp) {
|
|
|
|
if (dn_key_eq(f->fn_key, key))
|
|
|
|
break;
|
|
|
|
if (dn_key_leq(key, f->fn_key))
|
|
|
|
return -ESRCH;
|
|
|
|
}
|
|
|
|
|
|
|
|
matched = 0;
|
|
|
|
del_fp = NULL;
|
|
|
|
DN_FIB_SCAN_KEY(f, fp, key) {
|
|
|
|
struct dn_fib_info *fi = DN_FIB_INFO(f);
|
|
|
|
|
|
|
|
if (f->fn_state & DN_S_ZOMBIE)
|
|
|
|
return -ESRCH;
|
|
|
|
|
|
|
|
matched++;
|
|
|
|
|
|
|
|
if (del_fp == NULL &&
|
|
|
|
(!r->rtm_type || f->fn_type == r->rtm_type) &&
|
|
|
|
(r->rtm_scope == RT_SCOPE_NOWHERE || f->fn_scope == r->rtm_scope) &&
|
2007-02-09 22:24:40 +08:00
|
|
|
(!r->rtm_protocol ||
|
2005-04-17 06:20:36 +08:00
|
|
|
fi->fib_protocol == r->rtm_protocol) &&
|
2013-03-21 15:45:28 +08:00
|
|
|
dn_fib_nh_match(r, n, attrs, fi) == 0)
|
2005-04-17 06:20:36 +08:00
|
|
|
del_fp = fp;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (del_fp) {
|
|
|
|
f = *del_fp;
|
2007-02-09 22:24:40 +08:00
|
|
|
dn_rtmsg_fib(RTM_DELROUTE, f, z, tb->n, n, req);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (matched != 1) {
|
|
|
|
write_lock_bh(&dn_fib_tables_lock);
|
|
|
|
*del_fp = f->fn_next;
|
|
|
|
write_unlock_bh(&dn_fib_tables_lock);
|
|
|
|
|
|
|
|
if (f->fn_state & DN_S_ACCESSED)
|
|
|
|
dn_rt_cache_flush(-1);
|
|
|
|
dn_free_node(f);
|
|
|
|
dz->dz_nent--;
|
|
|
|
} else {
|
|
|
|
f->fn_state |= DN_S_ZOMBIE;
|
|
|
|
if (f->fn_state & DN_S_ACCESSED) {
|
|
|
|
f->fn_state &= ~DN_S_ACCESSED;
|
|
|
|
dn_rt_cache_flush(-1);
|
|
|
|
}
|
|
|
|
if (++dn_fib_hash_zombies > 128)
|
|
|
|
dn_fib_flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-02-09 22:24:40 +08:00
|
|
|
return -ESRCH;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline int dn_flush_list(struct dn_fib_node **fp, int z, struct dn_hash *table)
|
|
|
|
{
|
|
|
|
int found = 0;
|
|
|
|
struct dn_fib_node *f;
|
|
|
|
|
|
|
|
while((f = *fp) != NULL) {
|
|
|
|
struct dn_fib_info *fi = DN_FIB_INFO(f);
|
|
|
|
|
|
|
|
if (fi && ((f->fn_state & DN_S_ZOMBIE) || (fi->fib_flags & RTNH_F_DEAD))) {
|
|
|
|
write_lock_bh(&dn_fib_tables_lock);
|
|
|
|
*fp = f->fn_next;
|
|
|
|
write_unlock_bh(&dn_fib_tables_lock);
|
|
|
|
|
|
|
|
dn_free_node(f);
|
|
|
|
found++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
fp = &f->fn_next;
|
|
|
|
}
|
|
|
|
|
|
|
|
return found;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int dn_fib_table_flush(struct dn_fib_table *tb)
|
|
|
|
{
|
|
|
|
struct dn_hash *table = (struct dn_hash *)tb->data;
|
|
|
|
struct dn_zone *dz;
|
|
|
|
int found = 0;
|
|
|
|
|
|
|
|
dn_fib_hash_zombies = 0;
|
|
|
|
for(dz = table->dh_zone_list; dz; dz = dz->dz_next) {
|
|
|
|
int i;
|
|
|
|
int tmp = 0;
|
|
|
|
for(i = dz->dz_divisor-1; i >= 0; i--)
|
|
|
|
tmp += dn_flush_list(&dz->dz_hash[i], dz->dz_order, table);
|
|
|
|
dz->dz_nent -= tmp;
|
|
|
|
found += tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
return found;
|
|
|
|
}
|
|
|
|
|
2011-03-13 06:17:10 +08:00
|
|
|
static int dn_fib_table_lookup(struct dn_fib_table *tb, const struct flowidn *flp, struct dn_fib_res *res)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2007-02-09 22:24:40 +08:00
|
|
|
int err;
|
2005-04-17 06:20:36 +08:00
|
|
|
struct dn_zone *dz;
|
|
|
|
struct dn_hash *t = (struct dn_hash *)tb->data;
|
|
|
|
|
|
|
|
read_lock(&dn_fib_tables_lock);
|
|
|
|
for(dz = t->dh_zone_list; dz; dz = dz->dz_next) {
|
|
|
|
struct dn_fib_node *f;
|
2011-03-13 06:17:10 +08:00
|
|
|
dn_fib_key_t k = dz_key(flp->daddr, dz);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
for(f = dz_chain(k, dz); f; f = f->fn_next) {
|
|
|
|
if (!dn_key_eq(k, f->fn_key)) {
|
|
|
|
if (dn_key_leq(k, f->fn_key))
|
|
|
|
break;
|
|
|
|
else
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
f->fn_state |= DN_S_ACCESSED;
|
|
|
|
|
|
|
|
if (f->fn_state&DN_S_ZOMBIE)
|
|
|
|
continue;
|
|
|
|
|
2011-03-13 06:17:10 +08:00
|
|
|
if (f->fn_scope < flp->flowidn_scope)
|
2005-04-17 06:20:36 +08:00
|
|
|
continue;
|
|
|
|
|
|
|
|
err = dn_fib_semantic_match(f->fn_type, DN_FIB_INFO(f), flp, res);
|
|
|
|
|
|
|
|
if (err == 0) {
|
|
|
|
res->type = f->fn_type;
|
2007-02-09 22:24:40 +08:00
|
|
|
res->scope = f->fn_scope;
|
2005-04-17 06:20:36 +08:00
|
|
|
res->prefixlen = dz->dz_order;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
if (err < 0)
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
err = 1;
|
|
|
|
out:
|
|
|
|
read_unlock(&dn_fib_tables_lock);
|
2007-02-09 22:24:40 +08:00
|
|
|
return err;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-08-11 14:08:33 +08:00
|
|
|
struct dn_fib_table *dn_fib_get_table(u32 n, int create)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2007-02-09 22:24:40 +08:00
|
|
|
struct dn_fib_table *t;
|
2006-08-11 14:11:47 +08:00
|
|
|
unsigned int h;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-02-09 22:24:40 +08:00
|
|
|
if (n < RT_TABLE_MIN)
|
|
|
|
return NULL;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-02-09 22:24:40 +08:00
|
|
|
if (n > RT_TABLE_MAX)
|
|
|
|
return NULL;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-08-11 14:11:47 +08:00
|
|
|
h = n & (DN_FIB_TABLE_HASHSZ - 1);
|
|
|
|
rcu_read_lock();
|
hlist: drop the node parameter from iterators
I'm not sure why, but the hlist for each entry iterators were conceived
list_for_each_entry(pos, head, member)
The hlist ones were greedy and wanted an extra parameter:
hlist_for_each_entry(tpos, pos, head, member)
Why did they need an extra pos parameter? I'm not quite sure. Not only
they don't really need it, it also prevents the iterator from looking
exactly like the list iterator, which is unfortunate.
Besides the semantic patch, there was some manual work required:
- Fix up the actual hlist iterators in linux/list.h
- Fix up the declaration of other iterators based on the hlist ones.
- A very small amount of places were using the 'node' parameter, this
was modified to use 'obj->member' instead.
- Coccinelle didn't handle the hlist_for_each_entry_safe iterator
properly, so those had to be fixed up manually.
The semantic patch which is mostly the work of Peter Senna Tschudin is here:
@@
iterator name hlist_for_each_entry, hlist_for_each_entry_continue, hlist_for_each_entry_from, hlist_for_each_entry_rcu, hlist_for_each_entry_rcu_bh, hlist_for_each_entry_continue_rcu_bh, for_each_busy_worker, ax25_uid_for_each, ax25_for_each, inet_bind_bucket_for_each, sctp_for_each_hentry, sk_for_each, sk_for_each_rcu, sk_for_each_from, sk_for_each_safe, sk_for_each_bound, hlist_for_each_entry_safe, hlist_for_each_entry_continue_rcu, nr_neigh_for_each, nr_neigh_for_each_safe, nr_node_for_each, nr_node_for_each_safe, for_each_gfn_indirect_valid_sp, for_each_gfn_sp, for_each_host;
type T;
expression a,c,d,e;
identifier b;
statement S;
@@
-T b;
<+... when != b
(
hlist_for_each_entry(a,
- b,
c, d) S
|
hlist_for_each_entry_continue(a,
- b,
c) S
|
hlist_for_each_entry_from(a,
- b,
c) S
|
hlist_for_each_entry_rcu(a,
- b,
c, d) S
|
hlist_for_each_entry_rcu_bh(a,
- b,
c, d) S
|
hlist_for_each_entry_continue_rcu_bh(a,
- b,
c) S
|
for_each_busy_worker(a, c,
- b,
d) S
|
ax25_uid_for_each(a,
- b,
c) S
|
ax25_for_each(a,
- b,
c) S
|
inet_bind_bucket_for_each(a,
- b,
c) S
|
sctp_for_each_hentry(a,
- b,
c) S
|
sk_for_each(a,
- b,
c) S
|
sk_for_each_rcu(a,
- b,
c) S
|
sk_for_each_from
-(a, b)
+(a)
S
+ sk_for_each_from(a) S
|
sk_for_each_safe(a,
- b,
c, d) S
|
sk_for_each_bound(a,
- b,
c) S
|
hlist_for_each_entry_safe(a,
- b,
c, d, e) S
|
hlist_for_each_entry_continue_rcu(a,
- b,
c) S
|
nr_neigh_for_each(a,
- b,
c) S
|
nr_neigh_for_each_safe(a,
- b,
c, d) S
|
nr_node_for_each(a,
- b,
c) S
|
nr_node_for_each_safe(a,
- b,
c, d) S
|
- for_each_gfn_sp(a, c, d, b) S
+ for_each_gfn_sp(a, c, d) S
|
- for_each_gfn_indirect_valid_sp(a, c, d, b) S
+ for_each_gfn_indirect_valid_sp(a, c, d) S
|
for_each_host(a,
- b,
c) S
|
for_each_host_safe(a,
- b,
c, d) S
|
for_each_mesh_entry(a,
- b,
c, d) S
)
...+>
[akpm@linux-foundation.org: drop bogus change from net/ipv4/raw.c]
[akpm@linux-foundation.org: drop bogus hunk from net/ipv6/raw.c]
[akpm@linux-foundation.org: checkpatch fixes]
[akpm@linux-foundation.org: fix warnings]
[akpm@linux-foudnation.org: redo intrusive kvm changes]
Tested-by: Peter Senna Tschudin <peter.senna@gmail.com>
Acked-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
Cc: Wu Fengguang <fengguang.wu@intel.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-02-28 09:06:00 +08:00
|
|
|
hlist_for_each_entry_rcu(t, &dn_fib_table_hash[h], hlist) {
|
2006-08-11 14:11:47 +08:00
|
|
|
if (t->n == n) {
|
|
|
|
rcu_read_unlock();
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rcu_read_unlock();
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-02-09 22:24:40 +08:00
|
|
|
if (!create)
|
|
|
|
return NULL;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-05-14 05:56:26 +08:00
|
|
|
if (in_interrupt()) {
|
|
|
|
net_dbg_ratelimited("DECnet: BUG! Attempt to create routing table from interrupt\n");
|
2007-02-09 22:24:40 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-02-09 22:24:40 +08:00
|
|
|
t = kzalloc(sizeof(struct dn_fib_table) + sizeof(struct dn_hash),
|
2006-11-21 11:16:24 +08:00
|
|
|
GFP_KERNEL);
|
2007-02-09 22:24:40 +08:00
|
|
|
if (t == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
t->n = n;
|
|
|
|
t->insert = dn_fib_table_insert;
|
|
|
|
t->delete = dn_fib_table_delete;
|
|
|
|
t->lookup = dn_fib_table_lookup;
|
|
|
|
t->flush = dn_fib_table_flush;
|
|
|
|
t->dump = dn_fib_table_dump;
|
2006-08-11 14:11:47 +08:00
|
|
|
hlist_add_head_rcu(&t->hlist, &dn_fib_table_hash[h]);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-02-09 22:24:40 +08:00
|
|
|
return t;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
struct dn_fib_table *dn_fib_empty_table(void)
|
|
|
|
{
|
2007-02-09 22:24:40 +08:00
|
|
|
u32 id;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-02-09 22:24:40 +08:00
|
|
|
for(id = RT_TABLE_MIN; id <= RT_TABLE_MAX; id++)
|
2006-08-11 14:11:47 +08:00
|
|
|
if (dn_fib_get_table(id, 0) == NULL)
|
2007-02-09 22:24:40 +08:00
|
|
|
return dn_fib_get_table(id, 1);
|
|
|
|
return NULL;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2006-08-11 14:11:47 +08:00
|
|
|
void dn_fib_flush(void)
|
|
|
|
{
|
2007-02-09 22:24:40 +08:00
|
|
|
int flushed = 0;
|
|
|
|
struct dn_fib_table *tb;
|
2006-08-11 14:11:47 +08:00
|
|
|
unsigned int h;
|
|
|
|
|
|
|
|
for (h = 0; h < DN_FIB_TABLE_HASHSZ; h++) {
|
hlist: drop the node parameter from iterators
I'm not sure why, but the hlist for each entry iterators were conceived
list_for_each_entry(pos, head, member)
The hlist ones were greedy and wanted an extra parameter:
hlist_for_each_entry(tpos, pos, head, member)
Why did they need an extra pos parameter? I'm not quite sure. Not only
they don't really need it, it also prevents the iterator from looking
exactly like the list iterator, which is unfortunate.
Besides the semantic patch, there was some manual work required:
- Fix up the actual hlist iterators in linux/list.h
- Fix up the declaration of other iterators based on the hlist ones.
- A very small amount of places were using the 'node' parameter, this
was modified to use 'obj->member' instead.
- Coccinelle didn't handle the hlist_for_each_entry_safe iterator
properly, so those had to be fixed up manually.
The semantic patch which is mostly the work of Peter Senna Tschudin is here:
@@
iterator name hlist_for_each_entry, hlist_for_each_entry_continue, hlist_for_each_entry_from, hlist_for_each_entry_rcu, hlist_for_each_entry_rcu_bh, hlist_for_each_entry_continue_rcu_bh, for_each_busy_worker, ax25_uid_for_each, ax25_for_each, inet_bind_bucket_for_each, sctp_for_each_hentry, sk_for_each, sk_for_each_rcu, sk_for_each_from, sk_for_each_safe, sk_for_each_bound, hlist_for_each_entry_safe, hlist_for_each_entry_continue_rcu, nr_neigh_for_each, nr_neigh_for_each_safe, nr_node_for_each, nr_node_for_each_safe, for_each_gfn_indirect_valid_sp, for_each_gfn_sp, for_each_host;
type T;
expression a,c,d,e;
identifier b;
statement S;
@@
-T b;
<+... when != b
(
hlist_for_each_entry(a,
- b,
c, d) S
|
hlist_for_each_entry_continue(a,
- b,
c) S
|
hlist_for_each_entry_from(a,
- b,
c) S
|
hlist_for_each_entry_rcu(a,
- b,
c, d) S
|
hlist_for_each_entry_rcu_bh(a,
- b,
c, d) S
|
hlist_for_each_entry_continue_rcu_bh(a,
- b,
c) S
|
for_each_busy_worker(a, c,
- b,
d) S
|
ax25_uid_for_each(a,
- b,
c) S
|
ax25_for_each(a,
- b,
c) S
|
inet_bind_bucket_for_each(a,
- b,
c) S
|
sctp_for_each_hentry(a,
- b,
c) S
|
sk_for_each(a,
- b,
c) S
|
sk_for_each_rcu(a,
- b,
c) S
|
sk_for_each_from
-(a, b)
+(a)
S
+ sk_for_each_from(a) S
|
sk_for_each_safe(a,
- b,
c, d) S
|
sk_for_each_bound(a,
- b,
c) S
|
hlist_for_each_entry_safe(a,
- b,
c, d, e) S
|
hlist_for_each_entry_continue_rcu(a,
- b,
c) S
|
nr_neigh_for_each(a,
- b,
c) S
|
nr_neigh_for_each_safe(a,
- b,
c, d) S
|
nr_node_for_each(a,
- b,
c) S
|
nr_node_for_each_safe(a,
- b,
c, d) S
|
- for_each_gfn_sp(a, c, d, b) S
+ for_each_gfn_sp(a, c, d) S
|
- for_each_gfn_indirect_valid_sp(a, c, d, b) S
+ for_each_gfn_indirect_valid_sp(a, c, d) S
|
for_each_host(a,
- b,
c) S
|
for_each_host_safe(a,
- b,
c, d) S
|
for_each_mesh_entry(a,
- b,
c, d) S
)
...+>
[akpm@linux-foundation.org: drop bogus change from net/ipv4/raw.c]
[akpm@linux-foundation.org: drop bogus hunk from net/ipv6/raw.c]
[akpm@linux-foundation.org: checkpatch fixes]
[akpm@linux-foundation.org: fix warnings]
[akpm@linux-foudnation.org: redo intrusive kvm changes]
Tested-by: Peter Senna Tschudin <peter.senna@gmail.com>
Acked-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
Cc: Wu Fengguang <fengguang.wu@intel.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-02-28 09:06:00 +08:00
|
|
|
hlist_for_each_entry(tb, &dn_fib_table_hash[h], hlist)
|
2007-02-09 22:24:40 +08:00
|
|
|
flushed += tb->flush(tb);
|
|
|
|
}
|
2006-08-11 14:11:47 +08:00
|
|
|
|
2007-02-09 22:24:40 +08:00
|
|
|
if (flushed)
|
|
|
|
dn_rt_cache_flush(-1);
|
2006-08-11 14:11:47 +08:00
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
void __init dn_fib_table_init(void)
|
|
|
|
{
|
|
|
|
dn_hash_kmem = kmem_cache_create("dn_fib_info_cache",
|
|
|
|
sizeof(struct dn_fib_info),
|
|
|
|
0, SLAB_HWCACHE_ALIGN,
|
2007-07-20 09:11:58 +08:00
|
|
|
NULL);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void __exit dn_fib_table_cleanup(void)
|
|
|
|
{
|
2006-08-11 14:11:47 +08:00
|
|
|
struct dn_fib_table *t;
|
hlist: drop the node parameter from iterators
I'm not sure why, but the hlist for each entry iterators were conceived
list_for_each_entry(pos, head, member)
The hlist ones were greedy and wanted an extra parameter:
hlist_for_each_entry(tpos, pos, head, member)
Why did they need an extra pos parameter? I'm not quite sure. Not only
they don't really need it, it also prevents the iterator from looking
exactly like the list iterator, which is unfortunate.
Besides the semantic patch, there was some manual work required:
- Fix up the actual hlist iterators in linux/list.h
- Fix up the declaration of other iterators based on the hlist ones.
- A very small amount of places were using the 'node' parameter, this
was modified to use 'obj->member' instead.
- Coccinelle didn't handle the hlist_for_each_entry_safe iterator
properly, so those had to be fixed up manually.
The semantic patch which is mostly the work of Peter Senna Tschudin is here:
@@
iterator name hlist_for_each_entry, hlist_for_each_entry_continue, hlist_for_each_entry_from, hlist_for_each_entry_rcu, hlist_for_each_entry_rcu_bh, hlist_for_each_entry_continue_rcu_bh, for_each_busy_worker, ax25_uid_for_each, ax25_for_each, inet_bind_bucket_for_each, sctp_for_each_hentry, sk_for_each, sk_for_each_rcu, sk_for_each_from, sk_for_each_safe, sk_for_each_bound, hlist_for_each_entry_safe, hlist_for_each_entry_continue_rcu, nr_neigh_for_each, nr_neigh_for_each_safe, nr_node_for_each, nr_node_for_each_safe, for_each_gfn_indirect_valid_sp, for_each_gfn_sp, for_each_host;
type T;
expression a,c,d,e;
identifier b;
statement S;
@@
-T b;
<+... when != b
(
hlist_for_each_entry(a,
- b,
c, d) S
|
hlist_for_each_entry_continue(a,
- b,
c) S
|
hlist_for_each_entry_from(a,
- b,
c) S
|
hlist_for_each_entry_rcu(a,
- b,
c, d) S
|
hlist_for_each_entry_rcu_bh(a,
- b,
c, d) S
|
hlist_for_each_entry_continue_rcu_bh(a,
- b,
c) S
|
for_each_busy_worker(a, c,
- b,
d) S
|
ax25_uid_for_each(a,
- b,
c) S
|
ax25_for_each(a,
- b,
c) S
|
inet_bind_bucket_for_each(a,
- b,
c) S
|
sctp_for_each_hentry(a,
- b,
c) S
|
sk_for_each(a,
- b,
c) S
|
sk_for_each_rcu(a,
- b,
c) S
|
sk_for_each_from
-(a, b)
+(a)
S
+ sk_for_each_from(a) S
|
sk_for_each_safe(a,
- b,
c, d) S
|
sk_for_each_bound(a,
- b,
c) S
|
hlist_for_each_entry_safe(a,
- b,
c, d, e) S
|
hlist_for_each_entry_continue_rcu(a,
- b,
c) S
|
nr_neigh_for_each(a,
- b,
c) S
|
nr_neigh_for_each_safe(a,
- b,
c, d) S
|
nr_node_for_each(a,
- b,
c) S
|
nr_node_for_each_safe(a,
- b,
c, d) S
|
- for_each_gfn_sp(a, c, d, b) S
+ for_each_gfn_sp(a, c, d) S
|
- for_each_gfn_indirect_valid_sp(a, c, d, b) S
+ for_each_gfn_indirect_valid_sp(a, c, d) S
|
for_each_host(a,
- b,
c) S
|
for_each_host_safe(a,
- b,
c, d) S
|
for_each_mesh_entry(a,
- b,
c, d) S
)
...+>
[akpm@linux-foundation.org: drop bogus change from net/ipv4/raw.c]
[akpm@linux-foundation.org: drop bogus hunk from net/ipv6/raw.c]
[akpm@linux-foundation.org: checkpatch fixes]
[akpm@linux-foundation.org: fix warnings]
[akpm@linux-foudnation.org: redo intrusive kvm changes]
Tested-by: Peter Senna Tschudin <peter.senna@gmail.com>
Acked-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
Cc: Wu Fengguang <fengguang.wu@intel.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-02-28 09:06:00 +08:00
|
|
|
struct hlist_node *next;
|
2006-08-11 14:11:47 +08:00
|
|
|
unsigned int h;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-08-11 14:11:47 +08:00
|
|
|
write_lock(&dn_fib_tables_lock);
|
|
|
|
for (h = 0; h < DN_FIB_TABLE_HASHSZ; h++) {
|
hlist: drop the node parameter from iterators
I'm not sure why, but the hlist for each entry iterators were conceived
list_for_each_entry(pos, head, member)
The hlist ones were greedy and wanted an extra parameter:
hlist_for_each_entry(tpos, pos, head, member)
Why did they need an extra pos parameter? I'm not quite sure. Not only
they don't really need it, it also prevents the iterator from looking
exactly like the list iterator, which is unfortunate.
Besides the semantic patch, there was some manual work required:
- Fix up the actual hlist iterators in linux/list.h
- Fix up the declaration of other iterators based on the hlist ones.
- A very small amount of places were using the 'node' parameter, this
was modified to use 'obj->member' instead.
- Coccinelle didn't handle the hlist_for_each_entry_safe iterator
properly, so those had to be fixed up manually.
The semantic patch which is mostly the work of Peter Senna Tschudin is here:
@@
iterator name hlist_for_each_entry, hlist_for_each_entry_continue, hlist_for_each_entry_from, hlist_for_each_entry_rcu, hlist_for_each_entry_rcu_bh, hlist_for_each_entry_continue_rcu_bh, for_each_busy_worker, ax25_uid_for_each, ax25_for_each, inet_bind_bucket_for_each, sctp_for_each_hentry, sk_for_each, sk_for_each_rcu, sk_for_each_from, sk_for_each_safe, sk_for_each_bound, hlist_for_each_entry_safe, hlist_for_each_entry_continue_rcu, nr_neigh_for_each, nr_neigh_for_each_safe, nr_node_for_each, nr_node_for_each_safe, for_each_gfn_indirect_valid_sp, for_each_gfn_sp, for_each_host;
type T;
expression a,c,d,e;
identifier b;
statement S;
@@
-T b;
<+... when != b
(
hlist_for_each_entry(a,
- b,
c, d) S
|
hlist_for_each_entry_continue(a,
- b,
c) S
|
hlist_for_each_entry_from(a,
- b,
c) S
|
hlist_for_each_entry_rcu(a,
- b,
c, d) S
|
hlist_for_each_entry_rcu_bh(a,
- b,
c, d) S
|
hlist_for_each_entry_continue_rcu_bh(a,
- b,
c) S
|
for_each_busy_worker(a, c,
- b,
d) S
|
ax25_uid_for_each(a,
- b,
c) S
|
ax25_for_each(a,
- b,
c) S
|
inet_bind_bucket_for_each(a,
- b,
c) S
|
sctp_for_each_hentry(a,
- b,
c) S
|
sk_for_each(a,
- b,
c) S
|
sk_for_each_rcu(a,
- b,
c) S
|
sk_for_each_from
-(a, b)
+(a)
S
+ sk_for_each_from(a) S
|
sk_for_each_safe(a,
- b,
c, d) S
|
sk_for_each_bound(a,
- b,
c) S
|
hlist_for_each_entry_safe(a,
- b,
c, d, e) S
|
hlist_for_each_entry_continue_rcu(a,
- b,
c) S
|
nr_neigh_for_each(a,
- b,
c) S
|
nr_neigh_for_each_safe(a,
- b,
c, d) S
|
nr_node_for_each(a,
- b,
c) S
|
nr_node_for_each_safe(a,
- b,
c, d) S
|
- for_each_gfn_sp(a, c, d, b) S
+ for_each_gfn_sp(a, c, d) S
|
- for_each_gfn_indirect_valid_sp(a, c, d, b) S
+ for_each_gfn_indirect_valid_sp(a, c, d) S
|
for_each_host(a,
- b,
c) S
|
for_each_host_safe(a,
- b,
c, d) S
|
for_each_mesh_entry(a,
- b,
c, d) S
)
...+>
[akpm@linux-foundation.org: drop bogus change from net/ipv4/raw.c]
[akpm@linux-foundation.org: drop bogus hunk from net/ipv6/raw.c]
[akpm@linux-foundation.org: checkpatch fixes]
[akpm@linux-foundation.org: fix warnings]
[akpm@linux-foudnation.org: redo intrusive kvm changes]
Tested-by: Peter Senna Tschudin <peter.senna@gmail.com>
Acked-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
Cc: Wu Fengguang <fengguang.wu@intel.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-02-28 09:06:00 +08:00
|
|
|
hlist_for_each_entry_safe(t, next, &dn_fib_table_hash[h],
|
2007-02-09 22:24:40 +08:00
|
|
|
hlist) {
|
2006-08-11 14:11:47 +08:00
|
|
|
hlist_del(&t->hlist);
|
|
|
|
kfree(t);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
write_unlock(&dn_fib_tables_lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|