Skip to content

Commit

Permalink
net_sched: make traffic control network namespace aware
Browse files Browse the repository at this point in the history
Mostly minor changes to add a net argument to various functions and
remove initial network namespace checks.

Make /proc/net/psched per network namespace.

Signed-off-by: Tom Goff <thomas.goff@boeing.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Tom Goff authored and David S. Miller committed Mar 23, 2010
1 parent 300bc06 commit 7316ae8
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 80 deletions.
45 changes: 22 additions & 23 deletions net/sched/act_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,8 @@ tca_get_fill(struct sk_buff *skb, struct tc_action *a, u32 pid, u32 seq,
}

static int
act_get_notify(u32 pid, struct nlmsghdr *n, struct tc_action *a, int event)
act_get_notify(struct net *net, u32 pid, struct nlmsghdr *n,
struct tc_action *a, int event)
{
struct sk_buff *skb;

Expand All @@ -679,7 +680,7 @@ act_get_notify(u32 pid, struct nlmsghdr *n, struct tc_action *a, int event)
return -EINVAL;
}

return rtnl_unicast(skb, &init_net, pid);
return rtnl_unicast(skb, net, pid);
}

static struct tc_action *
Expand Down Expand Up @@ -749,7 +750,8 @@ static struct tc_action *create_a(int i)
return act;
}

static int tca_action_flush(struct nlattr *nla, struct nlmsghdr *n, u32 pid)
static int tca_action_flush(struct net *net, struct nlattr *nla,
struct nlmsghdr *n, u32 pid)
{
struct sk_buff *skb;
unsigned char *b;
Expand Down Expand Up @@ -808,7 +810,7 @@ static int tca_action_flush(struct nlattr *nla, struct nlmsghdr *n, u32 pid)
nlh->nlmsg_flags |= NLM_F_ROOT;
module_put(a->ops->owner);
kfree(a);
err = rtnetlink_send(skb, &init_net, pid, RTNLGRP_TC, n->nlmsg_flags&NLM_F_ECHO);
err = rtnetlink_send(skb, net, pid, RTNLGRP_TC, n->nlmsg_flags&NLM_F_ECHO);
if (err > 0)
return 0;

Expand All @@ -825,7 +827,8 @@ static int tca_action_flush(struct nlattr *nla, struct nlmsghdr *n, u32 pid)
}

static int
tca_action_gd(struct nlattr *nla, struct nlmsghdr *n, u32 pid, int event)
tca_action_gd(struct net *net, struct nlattr *nla, struct nlmsghdr *n,
u32 pid, int event)
{
int i, ret;
struct nlattr *tb[TCA_ACT_MAX_PRIO+1];
Expand All @@ -837,7 +840,7 @@ tca_action_gd(struct nlattr *nla, struct nlmsghdr *n, u32 pid, int event)

if (event == RTM_DELACTION && n->nlmsg_flags&NLM_F_ROOT) {
if (tb[1] != NULL)
return tca_action_flush(tb[1], n, pid);
return tca_action_flush(net, tb[1], n, pid);
else
return -EINVAL;
}
Expand All @@ -858,7 +861,7 @@ tca_action_gd(struct nlattr *nla, struct nlmsghdr *n, u32 pid, int event)
}

if (event == RTM_GETACTION)
ret = act_get_notify(pid, n, head, event);
ret = act_get_notify(net, pid, n, head, event);
else { /* delete */
struct sk_buff *skb;

Expand All @@ -877,7 +880,7 @@ tca_action_gd(struct nlattr *nla, struct nlmsghdr *n, u32 pid, int event)

/* now do the delete */
tcf_action_destroy(head, 0);
ret = rtnetlink_send(skb, &init_net, pid, RTNLGRP_TC,
ret = rtnetlink_send(skb, net, pid, RTNLGRP_TC,
n->nlmsg_flags&NLM_F_ECHO);
if (ret > 0)
return 0;
Expand All @@ -888,8 +891,8 @@ tca_action_gd(struct nlattr *nla, struct nlmsghdr *n, u32 pid, int event)
return ret;
}

static int tcf_add_notify(struct tc_action *a, u32 pid, u32 seq, int event,
u16 flags)
static int tcf_add_notify(struct net *net, struct tc_action *a,
u32 pid, u32 seq, int event, u16 flags)
{
struct tcamsg *t;
struct nlmsghdr *nlh;
Expand Down Expand Up @@ -922,7 +925,7 @@ static int tcf_add_notify(struct tc_action *a, u32 pid, u32 seq, int event,
nlh->nlmsg_len = skb_tail_pointer(skb) - b;
NETLINK_CB(skb).dst_group = RTNLGRP_TC;

err = rtnetlink_send(skb, &init_net, pid, RTNLGRP_TC, flags&NLM_F_ECHO);
err = rtnetlink_send(skb, net, pid, RTNLGRP_TC, flags&NLM_F_ECHO);
if (err > 0)
err = 0;
return err;
Expand All @@ -935,7 +938,8 @@ static int tcf_add_notify(struct tc_action *a, u32 pid, u32 seq, int event,


static int
tcf_action_add(struct nlattr *nla, struct nlmsghdr *n, u32 pid, int ovr)
tcf_action_add(struct net *net, struct nlattr *nla, struct nlmsghdr *n,
u32 pid, int ovr)
{
int ret = 0;
struct tc_action *act;
Expand All @@ -953,7 +957,7 @@ tcf_action_add(struct nlattr *nla, struct nlmsghdr *n, u32 pid, int ovr)
/* dump then free all the actions after update; inserted policy
* stays intact
* */
ret = tcf_add_notify(act, pid, seq, RTM_NEWACTION, n->nlmsg_flags);
ret = tcf_add_notify(net, act, pid, seq, RTM_NEWACTION, n->nlmsg_flags);
for (a = act; a; a = act) {
act = a->next;
kfree(a);
Expand All @@ -969,9 +973,6 @@ static int tc_ctl_action(struct sk_buff *skb, struct nlmsghdr *n, void *arg)
u32 pid = skb ? NETLINK_CB(skb).pid : 0;
int ret = 0, ovr = 0;

if (!net_eq(net, &init_net))
return -EINVAL;

ret = nlmsg_parse(n, sizeof(struct tcamsg), tca, TCA_ACT_MAX, NULL);
if (ret < 0)
return ret;
Expand All @@ -994,15 +995,17 @@ static int tc_ctl_action(struct sk_buff *skb, struct nlmsghdr *n, void *arg)
if (n->nlmsg_flags&NLM_F_REPLACE)
ovr = 1;
replay:
ret = tcf_action_add(tca[TCA_ACT_TAB], n, pid, ovr);
ret = tcf_action_add(net, tca[TCA_ACT_TAB], n, pid, ovr);
if (ret == -EAGAIN)
goto replay;
break;
case RTM_DELACTION:
ret = tca_action_gd(tca[TCA_ACT_TAB], n, pid, RTM_DELACTION);
ret = tca_action_gd(net, tca[TCA_ACT_TAB], n,
pid, RTM_DELACTION);
break;
case RTM_GETACTION:
ret = tca_action_gd(tca[TCA_ACT_TAB], n, pid, RTM_GETACTION);
ret = tca_action_gd(net, tca[TCA_ACT_TAB], n,
pid, RTM_GETACTION);
break;
default:
BUG();
Expand Down Expand Up @@ -1042,7 +1045,6 @@ find_dump_kind(const struct nlmsghdr *n)
static int
tc_dump_action(struct sk_buff *skb, struct netlink_callback *cb)
{
struct net *net = sock_net(skb->sk);
struct nlmsghdr *nlh;
unsigned char *b = skb_tail_pointer(skb);
struct nlattr *nest;
Expand All @@ -1052,9 +1054,6 @@ tc_dump_action(struct sk_buff *skb, struct netlink_callback *cb)
struct tcamsg *t = (struct tcamsg *) NLMSG_DATA(cb->nlh);
struct nlattr *kind = find_dump_kind(cb->nlh);

if (!net_eq(net, &init_net))
return 0;

if (kind == NULL) {
printk("tc_dump_action: action bad kind\n");
return 0;
Expand Down
30 changes: 13 additions & 17 deletions net/sched/cls_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,9 @@ int unregister_tcf_proto_ops(struct tcf_proto_ops *ops)
}
EXPORT_SYMBOL(unregister_tcf_proto_ops);

static int tfilter_notify(struct sk_buff *oskb, struct nlmsghdr *n,
struct tcf_proto *tp, unsigned long fh, int event);
static int tfilter_notify(struct net *net, struct sk_buff *oskb,
struct nlmsghdr *n, struct tcf_proto *tp,
unsigned long fh, int event);


/* Select new prio value from the range, managed by kernel. */
Expand Down Expand Up @@ -137,9 +138,6 @@ static int tc_ctl_tfilter(struct sk_buff *skb, struct nlmsghdr *n, void *arg)
int err;
int tp_created = 0;

if (!net_eq(net, &init_net))
return -EINVAL;

replay:
t = NLMSG_DATA(n);
protocol = TC_H_MIN(t->tcm_info);
Expand All @@ -158,7 +156,7 @@ static int tc_ctl_tfilter(struct sk_buff *skb, struct nlmsghdr *n, void *arg)
/* Find head of filter chain. */

/* Find link */
dev = __dev_get_by_index(&init_net, t->tcm_ifindex);
dev = __dev_get_by_index(net, t->tcm_ifindex);
if (dev == NULL)
return -ENODEV;

Expand Down Expand Up @@ -282,7 +280,7 @@ static int tc_ctl_tfilter(struct sk_buff *skb, struct nlmsghdr *n, void *arg)
*back = tp->next;
spin_unlock_bh(root_lock);

tfilter_notify(skb, n, tp, fh, RTM_DELTFILTER);
tfilter_notify(net, skb, n, tp, fh, RTM_DELTFILTER);
tcf_destroy(tp);
err = 0;
goto errout;
Expand All @@ -305,10 +303,10 @@ static int tc_ctl_tfilter(struct sk_buff *skb, struct nlmsghdr *n, void *arg)
case RTM_DELTFILTER:
err = tp->ops->delete(tp, fh);
if (err == 0)
tfilter_notify(skb, n, tp, fh, RTM_DELTFILTER);
tfilter_notify(net, skb, n, tp, fh, RTM_DELTFILTER);
goto errout;
case RTM_GETTFILTER:
err = tfilter_notify(skb, n, tp, fh, RTM_NEWTFILTER);
err = tfilter_notify(net, skb, n, tp, fh, RTM_NEWTFILTER);
goto errout;
default:
err = -EINVAL;
Expand All @@ -324,7 +322,7 @@ static int tc_ctl_tfilter(struct sk_buff *skb, struct nlmsghdr *n, void *arg)
*back = tp;
spin_unlock_bh(root_lock);
}
tfilter_notify(skb, n, tp, fh, RTM_NEWTFILTER);
tfilter_notify(net, skb, n, tp, fh, RTM_NEWTFILTER);
} else {
if (tp_created)
tcf_destroy(tp);
Expand Down Expand Up @@ -370,8 +368,9 @@ static int tcf_fill_node(struct sk_buff *skb, struct tcf_proto *tp,
return -1;
}

static int tfilter_notify(struct sk_buff *oskb, struct nlmsghdr *n,
struct tcf_proto *tp, unsigned long fh, int event)
static int tfilter_notify(struct net *net, struct sk_buff *oskb,
struct nlmsghdr *n, struct tcf_proto *tp,
unsigned long fh, int event)
{
struct sk_buff *skb;
u32 pid = oskb ? NETLINK_CB(oskb).pid : 0;
Expand All @@ -385,7 +384,7 @@ static int tfilter_notify(struct sk_buff *oskb, struct nlmsghdr *n,
return -EINVAL;
}

return rtnetlink_send(skb, &init_net, pid, RTNLGRP_TC,
return rtnetlink_send(skb, net, pid, RTNLGRP_TC,
n->nlmsg_flags & NLM_F_ECHO);
}

Expand Down Expand Up @@ -418,12 +417,9 @@ static int tc_dump_tfilter(struct sk_buff *skb, struct netlink_callback *cb)
const struct Qdisc_class_ops *cops;
struct tcf_dump_args arg;

if (!net_eq(net, &init_net))
return 0;

if (cb->nlh->nlmsg_len < NLMSG_LENGTH(sizeof(*tcm)))
return skb->len;
if ((dev = __dev_get_by_index(&init_net, tcm->tcm_ifindex)) == NULL)
if ((dev = __dev_get_by_index(net, tcm->tcm_ifindex)) == NULL)
return skb->len;

if (!tcm->tcm_parent)
Expand Down
Loading

0 comments on commit 7316ae8

Please sign in to comment.