提交 c17084d2 编写于 作者: T Thomas Graf 提交者: David S. Miller

[NET] fib_rules: Convert fib rule notification to use rtnl_notify()

Adds support for NLM_F_ECHO to simplify the process of identifying
inserted rules with an auto generated priority.
Signed-off-by: NThomas Graf <tgraf@suug.ch>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
上级 97676b6b
...@@ -18,7 +18,8 @@ static LIST_HEAD(rules_ops); ...@@ -18,7 +18,8 @@ static LIST_HEAD(rules_ops);
static DEFINE_SPINLOCK(rules_mod_lock); static DEFINE_SPINLOCK(rules_mod_lock);
static void notify_rule_change(int event, struct fib_rule *rule, static void notify_rule_change(int event, struct fib_rule *rule,
struct fib_rules_ops *ops); struct fib_rules_ops *ops, struct nlmsghdr *nlh,
u32 pid);
static struct fib_rules_ops *lookup_rules_ops(int family) static struct fib_rules_ops *lookup_rules_ops(int family)
{ {
...@@ -209,7 +210,7 @@ int fib_nl_newrule(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg) ...@@ -209,7 +210,7 @@ int fib_nl_newrule(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg)
else else
list_add_rcu(&rule->list, ops->rules_list); list_add_rcu(&rule->list, ops->rules_list);
notify_rule_change(RTM_NEWRULE, rule, ops); notify_rule_change(RTM_NEWRULE, rule, ops, nlh, NETLINK_CB(skb).pid);
rules_ops_put(ops); rules_ops_put(ops);
return 0; return 0;
...@@ -266,7 +267,8 @@ int fib_nl_delrule(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg) ...@@ -266,7 +267,8 @@ int fib_nl_delrule(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg)
list_del_rcu(&rule->list); list_del_rcu(&rule->list);
synchronize_rcu(); synchronize_rcu();
notify_rule_change(RTM_DELRULE, rule, ops); notify_rule_change(RTM_DELRULE, rule, ops, nlh,
NETLINK_CB(skb).pid);
fib_rule_put(rule); fib_rule_put(rule);
rules_ops_put(ops); rules_ops_put(ops);
return 0; return 0;
...@@ -344,18 +346,26 @@ int fib_rules_dump(struct sk_buff *skb, struct netlink_callback *cb, int family) ...@@ -344,18 +346,26 @@ int fib_rules_dump(struct sk_buff *skb, struct netlink_callback *cb, int family)
EXPORT_SYMBOL_GPL(fib_rules_dump); EXPORT_SYMBOL_GPL(fib_rules_dump);
static void notify_rule_change(int event, struct fib_rule *rule, static void notify_rule_change(int event, struct fib_rule *rule,
struct fib_rules_ops *ops) struct fib_rules_ops *ops, struct nlmsghdr *nlh,
u32 pid)
{ {
int size = nlmsg_total_size(sizeof(struct fib_rule_hdr) + 128); struct sk_buff *skb;
struct sk_buff *skb = alloc_skb(size, GFP_KERNEL); int err = -ENOBUFS;
skb = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
if (skb == NULL) if (skb == NULL)
netlink_set_err(rtnl, 0, ops->nlgroup, ENOBUFS); goto errout;
else if (fib_nl_fill_rule(skb, rule, 0, 0, event, 0, ops) < 0) {
err = fib_nl_fill_rule(skb, rule, pid, nlh->nlmsg_seq, event, 0, ops);
if (err < 0) {
kfree_skb(skb); kfree_skb(skb);
netlink_set_err(rtnl, 0, ops->nlgroup, EINVAL); goto errout;
} else }
netlink_broadcast(rtnl, skb, 0, ops->nlgroup, GFP_KERNEL);
err = rtnl_notify(skb, pid, ops->nlgroup, nlh, GFP_KERNEL);
errout:
if (err < 0)
rtnl_set_sk_err(ops->nlgroup, err);
} }
static void attach_rules(struct list_head *rules, struct net_device *dev) static void attach_rules(struct list_head *rules, struct net_device *dev)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册