Commit 4e902c57 authored by Thomas Graf's avatar Thomas Graf Committed by David S. Miller

[IPv4]: FIB configuration using struct fib_config

Introduces struct fib_config replacing the ugly struct kern_rta
prone to ordering issues. Avoids creating faked netlink messages
for auto generated routes or requests via ioctl.

A new interface net/nexthop.h is added to help navigate through
nexthop configuration arrays.

A new struct nl_info will be used to carry the necessary netlink
information to be used for notifications later on.
Signed-off-by: default avatarThomas Graf <tgraf@suug.ch>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent ab32ea5d
...@@ -20,25 +20,32 @@ ...@@ -20,25 +20,32 @@
#include <linux/seq_file.h> #include <linux/seq_file.h>
#include <net/fib_rules.h> #include <net/fib_rules.h>
/* WARNING: The ordering of these elements must match ordering struct fib_config {
* of RTA_* rtnetlink attribute numbers. u8 fc_family;
*/ u8 fc_dst_len;
struct kern_rta { u8 fc_src_len;
void *rta_dst; u8 fc_tos;
void *rta_src; u8 fc_protocol;
int *rta_iif; u8 fc_scope;
int *rta_oif; u8 fc_type;
void *rta_gw; /* 1 byte unused */
u32 *rta_priority; u32 fc_table;
void *rta_prefsrc; u32 fc_dst;
struct rtattr *rta_mx; u32 fc_src;
struct rtattr *rta_mp; u32 fc_gw;
unsigned char *rta_protoinfo; int fc_oif;
u32 *rta_flow; u32 fc_flags;
struct rta_cacheinfo *rta_ci; u32 fc_priority;
struct rta_session *rta_sess; u32 fc_prefsrc;
u32 *rta_mp_alg; struct nlattr *fc_mx;
}; struct rtnexthop *fc_mp;
int fc_mx_len;
int fc_mp_len;
u32 fc_flow;
u32 fc_mp_alg;
u32 fc_nlflags;
struct nl_info fc_nlinfo;
};
struct fib_info; struct fib_info;
...@@ -154,12 +161,8 @@ struct fib_table { ...@@ -154,12 +161,8 @@ struct fib_table {
u32 tb_id; u32 tb_id;
unsigned tb_stamp; unsigned tb_stamp;
int (*tb_lookup)(struct fib_table *tb, const struct flowi *flp, struct fib_result *res); int (*tb_lookup)(struct fib_table *tb, const struct flowi *flp, struct fib_result *res);
int (*tb_insert)(struct fib_table *table, struct rtmsg *r, int (*tb_insert)(struct fib_table *, struct fib_config *);
struct kern_rta *rta, struct nlmsghdr *n, int (*tb_delete)(struct fib_table *, struct fib_config *);
struct netlink_skb_parms *req);
int (*tb_delete)(struct fib_table *table, struct rtmsg *r,
struct kern_rta *rta, struct nlmsghdr *n,
struct netlink_skb_parms *req);
int (*tb_dump)(struct fib_table *table, struct sk_buff *skb, int (*tb_dump)(struct fib_table *table, struct sk_buff *skb,
struct netlink_callback *cb); struct netlink_callback *cb);
int (*tb_flush)(struct fib_table *table); int (*tb_flush)(struct fib_table *table);
...@@ -228,8 +231,6 @@ struct rtentry; ...@@ -228,8 +231,6 @@ struct rtentry;
extern int ip_fib_check_default(u32 gw, struct net_device *dev); extern int ip_fib_check_default(u32 gw, struct net_device *dev);
extern int fib_sync_down(u32 local, struct net_device *dev, int force); extern int fib_sync_down(u32 local, struct net_device *dev, int force);
extern int fib_sync_up(struct net_device *dev); extern int fib_sync_up(struct net_device *dev);
extern int fib_convert_rtentry(int cmd, struct nlmsghdr *nl, struct rtmsg *rtm,
struct kern_rta *rta, struct rtentry *r);
extern u32 __fib_res_prefsrc(struct fib_result *res); extern u32 __fib_res_prefsrc(struct fib_result *res);
/* Exported by fib_hash.c */ /* Exported by fib_hash.c */
......
...@@ -192,6 +192,16 @@ struct nla_policy { ...@@ -192,6 +192,16 @@ struct nla_policy {
u16 minlen; u16 minlen;
}; };
/**
* struct nl_info - netlink source information
* @nlh: Netlink message header of original request
* @pid: Netlink PID of requesting application
*/
struct nl_info {
struct nlmsghdr *nlh;
u32 pid;
};
extern void netlink_run_queue(struct sock *sk, unsigned int *qlen, extern void netlink_run_queue(struct sock *sk, unsigned int *qlen,
int (*cb)(struct sk_buff *, int (*cb)(struct sk_buff *,
struct nlmsghdr *, int *)); struct nlmsghdr *, int *));
......
#ifndef __NET_NEXTHOP_H
#define __NET_NEXTHOP_H
#include <linux/rtnetlink.h>
#include <net/netlink.h>
static inline int rtnh_ok(const struct rtnexthop *rtnh, int remaining)
{
return remaining >= sizeof(*rtnh) &&
rtnh->rtnh_len >= sizeof(*rtnh) &&
rtnh->rtnh_len <= remaining;
}
static inline struct rtnexthop *rtnh_next(const struct rtnexthop *rtnh,
int *remaining)
{
int totlen = NLA_ALIGN(rtnh->rtnh_len);
*remaining -= totlen;
return (struct rtnexthop *) ((char *) rtnh + totlen);
}
static inline struct nlattr *rtnh_attrs(const struct rtnexthop *rtnh)
{
return (struct nlattr *) ((char *) rtnh + NLA_ALIGN(sizeof(*rtnh)));
}
static inline int rtnh_attrlen(const struct rtnexthop *rtnh)
{
return rtnh->rtnh_len - NLA_ALIGN(sizeof(*rtnh));
}
#endif
This diff is collapsed.
...@@ -379,42 +379,39 @@ static struct fib_node *fib_find_node(struct fn_zone *fz, u32 key) ...@@ -379,42 +379,39 @@ static struct fib_node *fib_find_node(struct fn_zone *fz, u32 key)
return NULL; return NULL;
} }
static int static int fn_hash_insert(struct fib_table *tb, struct fib_config *cfg)
fn_hash_insert(struct fib_table *tb, struct rtmsg *r, struct kern_rta *rta,
struct nlmsghdr *n, struct netlink_skb_parms *req)
{ {
struct fn_hash *table = (struct fn_hash *) tb->tb_data; struct fn_hash *table = (struct fn_hash *) tb->tb_data;
struct fib_node *new_f, *f; struct fib_node *new_f, *f;
struct fib_alias *fa, *new_fa; struct fib_alias *fa, *new_fa;
struct fn_zone *fz; struct fn_zone *fz;
struct fib_info *fi; struct fib_info *fi;
int z = r->rtm_dst_len; u8 tos = cfg->fc_tos;
int type = r->rtm_type;
u8 tos = r->rtm_tos;
u32 key; u32 key;
int err; int err;
if (z > 32) if (cfg->fc_dst_len > 32)
return -EINVAL; return -EINVAL;
fz = table->fn_zones[z];
if (!fz && !(fz = fn_new_zone(table, z))) fz = table->fn_zones[cfg->fc_dst_len];
if (!fz && !(fz = fn_new_zone(table, cfg->fc_dst_len)))
return -ENOBUFS; return -ENOBUFS;
key = 0; key = 0;
if (rta->rta_dst) { if (cfg->fc_dst) {
u32 dst; if (cfg->fc_dst & ~FZ_MASK(fz))
memcpy(&dst, rta->rta_dst, 4);
if (dst & ~FZ_MASK(fz))
return -EINVAL; return -EINVAL;
key = fz_key(dst, fz); key = fz_key(cfg->fc_dst, fz);
} }
if ((fi = fib_create_info(r, rta, n, &err)) == NULL) fi = fib_create_info(cfg);
return err; if (IS_ERR(fi))
return PTR_ERR(fi);
if (fz->fz_nent > (fz->fz_divisor<<1) && if (fz->fz_nent > (fz->fz_divisor<<1) &&
fz->fz_divisor < FZ_MAX_DIVISOR && fz->fz_divisor < FZ_MAX_DIVISOR &&
(z==32 || (1<<z) > fz->fz_divisor)) (cfg->fc_dst_len == 32 ||
(1 << cfg->fc_dst_len) > fz->fz_divisor))
fn_rehash_zone(fz); fn_rehash_zone(fz);
f = fib_find_node(fz, key); f = fib_find_node(fz, key);
...@@ -440,18 +437,18 @@ fn_hash_insert(struct fib_table *tb, struct rtmsg *r, struct kern_rta *rta, ...@@ -440,18 +437,18 @@ fn_hash_insert(struct fib_table *tb, struct rtmsg *r, struct kern_rta *rta,
struct fib_alias *fa_orig; struct fib_alias *fa_orig;
err = -EEXIST; err = -EEXIST;
if (n->nlmsg_flags & NLM_F_EXCL) if (cfg->fc_nlflags & NLM_F_EXCL)
goto out; goto out;
if (n->nlmsg_flags & NLM_F_REPLACE) { if (cfg->fc_nlflags & NLM_F_REPLACE) {
struct fib_info *fi_drop; struct fib_info *fi_drop;
u8 state; u8 state;
write_lock_bh(&fib_hash_lock); write_lock_bh(&fib_hash_lock);
fi_drop = fa->fa_info; fi_drop = fa->fa_info;
fa->fa_info = fi; fa->fa_info = fi;
fa->fa_type = type; fa->fa_type = cfg->fc_type;
fa->fa_scope = r->rtm_scope; fa->fa_scope = cfg->fc_scope;
state = fa->fa_state; state = fa->fa_state;
fa->fa_state &= ~FA_S_ACCESSED; fa->fa_state &= ~FA_S_ACCESSED;
fib_hash_genid++; fib_hash_genid++;
...@@ -474,17 +471,17 @@ fn_hash_insert(struct fib_table *tb, struct rtmsg *r, struct kern_rta *rta, ...@@ -474,17 +471,17 @@ fn_hash_insert(struct fib_table *tb, struct rtmsg *r, struct kern_rta *rta,
break; break;
if (fa->fa_info->fib_priority != fi->fib_priority) if (fa->fa_info->fib_priority != fi->fib_priority)
break; break;
if (fa->fa_type == type && if (fa->fa_type == cfg->fc_type &&
fa->fa_scope == r->rtm_scope && fa->fa_scope == cfg->fc_scope &&
fa->fa_info == fi) fa->fa_info == fi)
goto out; goto out;
} }
if (!(n->nlmsg_flags & NLM_F_APPEND)) if (!(cfg->fc_nlflags & NLM_F_APPEND))
fa = fa_orig; fa = fa_orig;
} }
err = -ENOENT; err = -ENOENT;
if (!(n->nlmsg_flags&NLM_F_CREATE)) if (!(cfg->fc_nlflags & NLM_F_CREATE))
goto out; goto out;
err = -ENOBUFS; err = -ENOBUFS;
...@@ -506,8 +503,8 @@ fn_hash_insert(struct fib_table *tb, struct rtmsg *r, struct kern_rta *rta, ...@@ -506,8 +503,8 @@ fn_hash_insert(struct fib_table *tb, struct rtmsg *r, struct kern_rta *rta,
new_fa->fa_info = fi; new_fa->fa_info = fi;
new_fa->fa_tos = tos; new_fa->fa_tos = tos;
new_fa->fa_type = type; new_fa->fa_type = cfg->fc_type;
new_fa->fa_scope = r->rtm_scope; new_fa->fa_scope = cfg->fc_scope;
new_fa->fa_state = 0; new_fa->fa_state = 0;
/* /*
...@@ -526,7 +523,8 @@ fn_hash_insert(struct fib_table *tb, struct rtmsg *r, struct kern_rta *rta, ...@@ -526,7 +523,8 @@ fn_hash_insert(struct fib_table *tb, struct rtmsg *r, struct kern_rta *rta,
fz->fz_nent++; fz->fz_nent++;
rt_cache_flush(-1); rt_cache_flush(-1);
rtmsg_fib(RTM_NEWROUTE, key, new_fa, z, tb->tb_id, n, req); rtmsg_fib(RTM_NEWROUTE, key, new_fa, cfg->fc_dst_len, tb->tb_id,
&cfg->fc_nlinfo);
return 0; return 0;
out_free_new_fa: out_free_new_fa:
...@@ -537,30 +535,25 @@ fn_hash_insert(struct fib_table *tb, struct rtmsg *r, struct kern_rta *rta, ...@@ -537,30 +535,25 @@ fn_hash_insert(struct fib_table *tb, struct rtmsg *r, struct kern_rta *rta,
} }
static int static int fn_hash_delete(struct fib_table *tb, struct fib_config *cfg)
fn_hash_delete(struct fib_table *tb, struct rtmsg *r, struct kern_rta *rta,
struct nlmsghdr *n, struct netlink_skb_parms *req)
{ {
struct fn_hash *table = (struct fn_hash*)tb->tb_data; struct fn_hash *table = (struct fn_hash*)tb->tb_data;
struct fib_node *f; struct fib_node *f;
struct fib_alias *fa, *fa_to_delete; struct fib_alias *fa, *fa_to_delete;
int z = r->rtm_dst_len;
struct fn_zone *fz; struct fn_zone *fz;
u32 key; u32 key;
u8 tos = r->rtm_tos;
if (z > 32) if (cfg->fc_dst_len > 32)
return -EINVAL; return -EINVAL;
if ((fz = table->fn_zones[z]) == NULL)
if ((fz = table->fn_zones[cfg->fc_dst_len]) == NULL)
return -ESRCH; return -ESRCH;
key = 0; key = 0;
if (rta->rta_dst) { if (cfg->fc_dst) {
u32 dst; if (cfg->fc_dst & ~FZ_MASK(fz))
memcpy(&dst, rta->rta_dst, 4);
if (dst & ~FZ_MASK(fz))
return -EINVAL; return -EINVAL;
key = fz_key(dst, fz); key = fz_key(cfg->fc_dst, fz);
} }
f = fib_find_node(fz, key); f = fib_find_node(fz, key);
...@@ -568,7 +561,7 @@ fn_hash_delete(struct fib_table *tb, struct rtmsg *r, struct kern_rta *rta, ...@@ -568,7 +561,7 @@ fn_hash_delete(struct fib_table *tb, struct rtmsg *r, struct kern_rta *rta,
if (!f) if (!f)
fa = NULL; fa = NULL;
else else
fa = fib_find_alias(&f->fn_alias, tos, 0); fa = fib_find_alias(&f->fn_alias, cfg->fc_tos, 0);
if (!fa) if (!fa)
return -ESRCH; return -ESRCH;
...@@ -577,16 +570,16 @@ fn_hash_delete(struct fib_table *tb, struct rtmsg *r, struct kern_rta *rta, ...@@ -577,16 +570,16 @@ fn_hash_delete(struct fib_table *tb, struct rtmsg *r, struct kern_rta *rta,
list_for_each_entry_continue(fa, &f->fn_alias, fa_list) { list_for_each_entry_continue(fa, &f->fn_alias, fa_list) {
struct fib_info *fi = fa->fa_info; struct fib_info *fi = fa->fa_info;
if (fa->fa_tos != tos) if (fa->fa_tos != cfg->fc_tos)
break; break;
if ((!r->rtm_type || if ((!cfg->fc_type ||
fa->fa_type == r->rtm_type) && fa->fa_type == cfg->fc_type) &&
(r->rtm_scope == RT_SCOPE_NOWHERE || (cfg->fc_scope == RT_SCOPE_NOWHERE ||
fa->fa_scope == r->rtm_scope) && fa->fa_scope == cfg->fc_scope) &&
(!r->rtm_protocol || (!cfg->fc_protocol ||
fi->fib_protocol == r->rtm_protocol) && fi->fib_protocol == cfg->fc_protocol) &&
fib_nh_match(r, n, rta, fi) == 0) { fib_nh_match(cfg, fi) == 0) {
fa_to_delete = fa; fa_to_delete = fa;
break; break;
} }
...@@ -596,7 +589,8 @@ fn_hash_delete(struct fib_table *tb, struct rtmsg *r, struct kern_rta *rta, ...@@ -596,7 +589,8 @@ fn_hash_delete(struct fib_table *tb, struct rtmsg *r, struct kern_rta *rta,
int kill_fn; int kill_fn;
fa = fa_to_delete; fa = fa_to_delete;
rtmsg_fib(RTM_DELROUTE, key, fa, z, tb->tb_id, n, req); rtmsg_fib(RTM_DELROUTE, key, fa, cfg->fc_dst_len,
tb->tb_id, &cfg->fc_nlinfo);
kill_fn = 0; kill_fn = 0;
write_lock_bh(&fib_hash_lock); write_lock_bh(&fib_hash_lock);
......
...@@ -23,19 +23,14 @@ extern int fib_semantic_match(struct list_head *head, ...@@ -23,19 +23,14 @@ extern int fib_semantic_match(struct list_head *head,
struct fib_result *res, __u32 zone, __u32 mask, struct fib_result *res, __u32 zone, __u32 mask,
int prefixlen); int prefixlen);
extern void fib_release_info(struct fib_info *); extern void fib_release_info(struct fib_info *);
extern struct fib_info *fib_create_info(const struct rtmsg *r, extern struct fib_info *fib_create_info(struct fib_config *cfg);
struct kern_rta *rta, extern int fib_nh_match(struct fib_config *cfg, struct fib_info *fi);
const struct nlmsghdr *,
int *err);
extern int fib_nh_match(struct rtmsg *r, struct nlmsghdr *,
struct kern_rta *rta, struct fib_info *fi);
extern int fib_dump_info(struct sk_buff *skb, u32 pid, u32 seq, int event, extern int fib_dump_info(struct sk_buff *skb, u32 pid, u32 seq, int event,
u32 tb_id, u8 type, u8 scope, void *dst, u32 tb_id, u8 type, u8 scope, void *dst,
int dst_len, u8 tos, struct fib_info *fi, int dst_len, u8 tos, struct fib_info *fi,
unsigned int); unsigned int);
extern void rtmsg_fib(int event, u32 key, struct fib_alias *fa, extern void rtmsg_fib(int event, u32 key, struct fib_alias *fa,
int z, u32 tb_id, int dst_len, u32 tb_id, struct nl_info *info);
struct nlmsghdr *n, struct netlink_skb_parms *req);
extern struct fib_alias *fib_find_alias(struct list_head *fah, extern struct fib_alias *fib_find_alias(struct list_head *fah,
u8 tos, u32 prio); u8 tos, u32 prio);
extern int fib_detect_death(struct fib_info *fi, int order, extern int fib_detect_death(struct fib_info *fi, int order,
......
This diff is collapsed.
...@@ -1124,17 +1124,14 @@ fib_insert_node(struct trie *t, int *err, u32 key, int plen) ...@@ -1124,17 +1124,14 @@ fib_insert_node(struct trie *t, int *err, u32 key, int plen)
return fa_head; return fa_head;
} }
static int static int fn_trie_insert(struct fib_table *tb, struct fib_config *cfg)
fn_trie_insert(struct fib_table *tb, struct rtmsg *r, struct kern_rta *rta,
struct nlmsghdr *nlhdr, struct netlink_skb_parms *req)
{ {
struct trie *t = (struct trie *) tb->tb_data; struct trie *t = (struct trie *) tb->tb_data;
struct fib_alias *fa, *new_fa; struct fib_alias *fa, *new_fa;
struct list_head *fa_head = NULL; struct list_head *fa_head = NULL;
struct fib_info *fi; struct fib_info *fi;
int plen = r->rtm_dst_len; int plen = cfg->fc_dst_len;
int type = r->rtm_type; u8 tos = cfg->fc_tos;
u8 tos = r->rtm_tos;
u32 key, mask; u32 key, mask;
int err; int err;
struct leaf *l; struct leaf *l;
...@@ -1142,11 +1139,7 @@ fn_trie_insert(struct fib_table *tb, struct rtmsg *r, struct kern_rta *rta, ...@@ -1142,11 +1139,7 @@ fn_trie_insert(struct fib_table *tb, struct rtmsg *r, struct kern_rta *rta,
if (plen > 32) if (plen > 32)
return -EINVAL; return -EINVAL;
key = 0; key = ntohl(cfg->fc_dst);
if (rta->rta_dst)
memcpy(&key, rta->rta_dst, 4);
key = ntohl(key);
pr_debug("Insert table=%u %08x/%d\n", tb->tb_id, key, plen); pr_debug("Insert table=%u %08x/%d\n", tb->tb_id, key, plen);
...@@ -1157,10 +1150,11 @@ fn_trie_insert(struct fib_table *tb, struct rtmsg *r, struct kern_rta *rta, ...@@ -1157,10 +1150,11 @@ fn_trie_insert(struct fib_table *tb, struct rtmsg *r, struct kern_rta *rta,
key = key & mask; key = key & mask;
fi = fib_create_info(r, rta, nlhdr, &err); fi = fib_create_info(cfg);
if (IS_ERR(fi)) {
if (!fi) err = PTR_ERR(fi);
goto err; goto err;
}
l = fib_find_node(t, key); l = fib_find_node(t, key);
fa = NULL; fa = NULL;
...@@ -1185,10 +1179,10 @@ fn_trie_insert(struct fib_table *tb, struct rtmsg *r, struct kern_rta *rta, ...@@ -1185,10 +1179,10 @@ fn_trie_insert(struct fib_table *tb, struct rtmsg *r, struct kern_rta *rta,
struct fib_alias *fa_orig; struct fib_alias *fa_orig;
err = -EEXIST; err = -EEXIST;
if (nlhdr->nlmsg_flags & NLM_F_EXCL) if (cfg->fc_nlflags & NLM_F_EXCL)
goto out; goto out;
if (nlhdr->nlmsg_flags & NLM_F_REPLACE) { if (cfg->fc_nlflags & NLM_F_REPLACE) {
struct fib_info *fi_drop; struct fib_info *fi_drop;
u8 state; u8 state;
...@@ -1200,8 +1194,8 @@ fn_trie_insert(struct fib_table *tb, struct rtmsg *r, struct kern_rta *rta, ...@@ -1200,8 +1194,8 @@ fn_trie_insert(struct fib_table *tb, struct rtmsg *r, struct kern_rta *rta,
fi_drop = fa->fa_info; fi_drop = fa->fa_info;
new_fa->fa_tos = fa->fa_tos; new_fa->fa_tos = fa->fa_tos;
new_fa->fa_info = fi; new_fa->fa_info = fi;
new_fa->fa_type = type; new_fa->fa_type = cfg->fc_type;
new_fa->fa_scope = r->rtm_scope; new_fa->fa_scope = cfg->fc_scope;
state = fa->fa_state; state = fa->fa_state;
new_fa->fa_state &= ~FA_S_ACCESSED; new_fa->fa_state &= ~FA_S_ACCESSED;
...@@ -1224,17 +1218,17 @@ fn_trie_insert(struct fib_table *tb, struct rtmsg *r, struct kern_rta *rta, ...@@ -1224,17 +1218,17 @@ fn_trie_insert(struct fib_table *tb, struct rtmsg *r, struct kern_rta *rta,
break; break;
if (fa->fa_info->fib_priority != fi->fib_priority) if (fa->fa_info->fib_priority != fi->fib_priority)
break; break;
if (fa->fa_type == type && if (fa->fa_type == cfg->fc_type &&
fa->fa_scope == r->rtm_scope && fa->fa_scope == cfg->fc_scope &&
fa->fa_info == fi) { fa->fa_info == fi) {
goto out; goto out;
} }
} }
if (!(nlhdr->nlmsg_flags & NLM_F_APPEND)) if (!(cfg->fc_nlflags & NLM_F_APPEND))
fa = fa_orig; fa = fa_orig;
} }
err = -ENOENT; err = -ENOENT;
if (!(nlhdr->nlmsg_flags & NLM_F_CREATE)) if (!(cfg->fc_nlflags & NLM_F_CREATE))
goto out; goto out;
err = -ENOBUFS; err = -ENOBUFS;
...@@ -1244,8 +1238,8 @@ fn_trie_insert(struct fib_table *tb, struct rtmsg *r, struct kern_rta *rta, ...@@ -1244,8 +1238,8 @@ fn_trie_insert(struct fib_table *tb, struct rtmsg *r, struct kern_rta *rta,
new_fa->fa_info = fi; new_fa->fa_info = fi;
new_fa->fa_tos = tos; new_fa->fa_tos = tos;
new_fa->fa_type = type; new_fa->fa_type = cfg->fc_type;
new_fa->fa_scope = r->rtm_scope; new_fa->fa_scope = cfg->fc_scope;
new_fa->fa_state = 0; new_fa->fa_state = 0;
/* /*
* Insert new entry to the list. * Insert new entry to the list.
...@@ -1262,7 +1256,8 @@ fn_trie_insert(struct fib_table *tb, struct rtmsg *r, struct kern_rta *rta, ...@@ -1262,7 +1256,8 @@ fn_trie_insert(struct fib_table *tb, struct rtmsg *r, struct kern_rta *rta,
(fa ? &fa->fa_list : fa_head)); (fa ? &fa->fa_list : fa_head));
rt_cache_flush(-1); rt_cache_flush(-1);
rtmsg_fib(RTM_NEWROUTE, htonl(key), new_fa, plen, tb->tb_id, nlhdr, req); rtmsg_fib(RTM_NEWROUTE, htonl(key), new_fa, plen, tb->tb_id,
&cfg->fc_nlinfo);
succeeded: succeeded:
return 0; return 0;
...@@ -1548,28 +1543,21 @@ static int trie_leaf_remove(struct trie *t, t_key key) ...@@ -1548,28 +1543,21 @@ static int trie_leaf_remove(struct trie *t, t_key key)
return 1; return 1;
} }
static int static int fn_trie_delete(struct fib_table *tb, struct fib_config *cfg)
fn_trie_delete(struct fib_table *tb, struct rtmsg *r, struct kern_rta *rta,
struct nlmsghdr *nlhdr, struct netlink_skb_parms *req)
{ {
struct trie *t = (struct trie *) tb->tb_data; struct trie *t = (struct trie *) tb->tb_data;
u32 key, mask; u32 key, mask;
int plen = r->rtm_dst_len; int plen = cfg->fc_dst_len;
u8 tos = r->rtm_tos; u8 tos = cfg->fc_tos;
struct fib_alias *fa, *fa_to_delete; struct fib_alias *fa, *fa_to_delete;
struct list_head *fa_head; struct list_head *fa_head;
struct leaf *l; struct leaf *l;
struct leaf_info *li; struct leaf_info *li;
if (plen > 32) if (plen > 32)
return -EINVAL; return -EINVAL;
key = 0; key = ntohl(cfg->fc_dst);
if (rta->rta_dst)
memcpy(&key, rta->rta_dst, 4);
key = ntohl(key);
mask = ntohl(inet_make_mask(plen)); mask = ntohl(inet_make_mask(plen));
if (key & ~mask) if (key & ~mask)
...@@ -1598,13 +1586,12 @@ fn_trie_delete(struct fib_table *tb, struct rtmsg *r, struct kern_rta *rta, ...@@ -1598,13 +1586,12 @@ fn_trie_delete(struct fib_table *tb, struct rtmsg *r, struct kern_rta *rta,
if (fa->fa_tos != tos) if (fa->fa_tos != tos)
break; break;
if ((!r->rtm_type || if ((!cfg->fc_type || fa->fa_type == cfg->fc_type) &&
fa->fa_type == r->rtm_type) && (cfg->fc_scope == RT_SCOPE_NOWHERE ||
(r->rtm_scope == RT_SCOPE_NOWHERE || fa->fa_scope == cfg->fc_scope) &&
fa->fa_scope == r->rtm_scope) && (!cfg->fc_protocol ||
(!r->rtm_protocol || fi->fib_protocol == cfg->fc_protocol) &&
fi->fib_protocol == r->rtm_protocol) && fib_nh_match(cfg, fi) == 0) {
fib_nh_match(r, nlhdr, rta, fi) == 0) {
fa_to_delete = fa; fa_to_delete = fa;
break; break;
} }
...@@ -1614,7 +1601,8 @@ fn_trie_delete(struct fib_table *tb, struct rtmsg *r, struct kern_rta *rta, ...@@ -1614,7 +1601,8 @@ fn_trie_delete(struct fib_table *tb, struct rtmsg *r, struct kern_rta *rta,
return -ESRCH; return -ESRCH;
fa = fa_to_delete; fa = fa_to_delete;
rtmsg_fib(RTM_DELROUTE, htonl(key), fa, plen, tb->tb_id, nlhdr, req); rtmsg_fib(RTM_DELROUTE, htonl(key), fa, plen, tb->tb_id,
&cfg->fc_nlinfo);
l = fib_find_node(t, key); l = fib_find_node(t, key);
li = find_leaf_info(l, plen); li = find_leaf_info(l, plen);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment