Commit ab27cfb8 authored by Patrick McHardy's avatar Patrick McHardy Committed by David S. Miller

[NET_SCHED]: act_api: use PTR_ERR in tcf_action_init/tcf_action_get

Signed-off-by: default avatarPatrick McHardy <kaber@trash.net>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent c96c9471
...@@ -114,8 +114,8 @@ extern int tcf_register_action(struct tc_action_ops *a); ...@@ -114,8 +114,8 @@ extern int tcf_register_action(struct tc_action_ops *a);
extern int tcf_unregister_action(struct tc_action_ops *a); extern int tcf_unregister_action(struct tc_action_ops *a);
extern void tcf_action_destroy(struct tc_action *a, int bind); extern void tcf_action_destroy(struct tc_action *a, int bind);
extern int tcf_action_exec(struct sk_buff *skb, struct tc_action *a, struct tcf_result *res); extern int tcf_action_exec(struct sk_buff *skb, struct tc_action *a, struct tcf_result *res);
extern struct tc_action *tcf_action_init(struct nlattr *nla, struct nlattr *est, char *n, int ovr, int bind, int *err); extern struct tc_action *tcf_action_init(struct nlattr *nla, struct nlattr *est, char *n, int ovr, int bind);
extern struct tc_action *tcf_action_init_1(struct nlattr *nla, struct nlattr *est, char *n, int ovr, int bind, int *err); extern struct tc_action *tcf_action_init_1(struct nlattr *nla, struct nlattr *est, char *n, int ovr, int bind);
extern int tcf_action_dump(struct sk_buff *skb, struct tc_action *a, int, int); extern int tcf_action_dump(struct sk_buff *skb, struct tc_action *a, int, int);
extern int tcf_action_dump_old(struct sk_buff *skb, struct tc_action *a, int, int); extern int tcf_action_dump_old(struct sk_buff *skb, struct tc_action *a, int, int);
extern int tcf_action_dump_1(struct sk_buff *skb, struct tc_action *a, int, int); extern int tcf_action_dump_1(struct sk_buff *skb, struct tc_action *a, int, int);
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include <linux/skbuff.h> #include <linux/skbuff.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/kmod.h> #include <linux/kmod.h>
#include <linux/err.h>
#include <net/net_namespace.h> #include <net/net_namespace.h>
#include <net/sock.h> #include <net/sock.h>
#include <net/sch_generic.h> #include <net/sch_generic.h>
...@@ -463,15 +464,16 @@ tcf_action_dump(struct sk_buff *skb, struct tc_action *act, int bind, int ref) ...@@ -463,15 +464,16 @@ tcf_action_dump(struct sk_buff *skb, struct tc_action *act, int bind, int ref)
} }
struct tc_action *tcf_action_init_1(struct nlattr *nla, struct nlattr *est, struct tc_action *tcf_action_init_1(struct nlattr *nla, struct nlattr *est,
char *name, int ovr, int bind, int *err) char *name, int ovr, int bind)
{ {
struct tc_action *a; struct tc_action *a;
struct tc_action_ops *a_o; struct tc_action_ops *a_o;
char act_name[IFNAMSIZ]; char act_name[IFNAMSIZ];
struct nlattr *tb[TCA_ACT_MAX+1]; struct nlattr *tb[TCA_ACT_MAX+1];
struct nlattr *kind; struct nlattr *kind;
int err;
*err = -EINVAL; err = -EINVAL;
if (name == NULL) { if (name == NULL) {
if (nla_parse_nested(tb, TCA_ACT_MAX, nla, NULL) < 0) if (nla_parse_nested(tb, TCA_ACT_MAX, nla, NULL) < 0)
...@@ -502,36 +504,35 @@ struct tc_action *tcf_action_init_1(struct nlattr *nla, struct nlattr *est, ...@@ -502,36 +504,35 @@ struct tc_action *tcf_action_init_1(struct nlattr *nla, struct nlattr *est,
* indicate this using -EAGAIN. * indicate this using -EAGAIN.
*/ */
if (a_o != NULL) { if (a_o != NULL) {
*err = -EAGAIN; err = -EAGAIN;
goto err_mod; goto err_mod;
} }
#endif #endif
*err = -ENOENT; err = -ENOENT;
goto err_out; goto err_out;
} }
*err = -ENOMEM; err = -ENOMEM;
a = kzalloc(sizeof(*a), GFP_KERNEL); a = kzalloc(sizeof(*a), GFP_KERNEL);
if (a == NULL) if (a == NULL)
goto err_mod; goto err_mod;
/* backward compatibility for policer */ /* backward compatibility for policer */
if (name == NULL) if (name == NULL)
*err = a_o->init(tb[TCA_ACT_OPTIONS], est, a, ovr, bind); err = a_o->init(tb[TCA_ACT_OPTIONS], est, a, ovr, bind);
else else
*err = a_o->init(nla, est, a, ovr, bind); err = a_o->init(nla, est, a, ovr, bind);
if (*err < 0) if (err < 0)
goto err_free; goto err_free;
/* module count goes up only when brand new policy is created /* module count goes up only when brand new policy is created
if it exists and is only bound to in a_o->init() then if it exists and is only bound to in a_o->init() then
ACT_P_CREATED is not returned (a zero is). ACT_P_CREATED is not returned (a zero is).
*/ */
if (*err != ACT_P_CREATED) if (err != ACT_P_CREATED)
module_put(a_o->owner); module_put(a_o->owner);
a->ops = a_o; a->ops = a_o;
*err = 0;
return a; return a;
err_free: err_free:
...@@ -539,24 +540,22 @@ struct tc_action *tcf_action_init_1(struct nlattr *nla, struct nlattr *est, ...@@ -539,24 +540,22 @@ struct tc_action *tcf_action_init_1(struct nlattr *nla, struct nlattr *est,
err_mod: err_mod:
module_put(a_o->owner); module_put(a_o->owner);
err_out: err_out:
return NULL; return ERR_PTR(err);
} }
struct tc_action *tcf_action_init(struct nlattr *nla, struct nlattr *est, struct tc_action *tcf_action_init(struct nlattr *nla, struct nlattr *est,
char *name, int ovr, int bind, int *err) char *name, int ovr, int bind)
{ {
struct nlattr *tb[TCA_ACT_MAX_PRIO+1]; struct nlattr *tb[TCA_ACT_MAX_PRIO+1];
struct tc_action *head = NULL, *act, *act_prev = NULL; struct tc_action *head = NULL, *act, *act_prev = NULL;
int i; int i;
if (nla_parse_nested(tb, TCA_ACT_MAX_PRIO, nla, NULL) < 0) { if (nla_parse_nested(tb, TCA_ACT_MAX_PRIO, nla, NULL) < 0)
*err = -EINVAL; return ERR_PTR(-EINVAL);
return head;
}
for (i = 1; i <= TCA_ACT_MAX_PRIO && tb[i]; i++) { for (i = 1; i <= TCA_ACT_MAX_PRIO && tb[i]; i++) {
act = tcf_action_init_1(tb[i], est, name, ovr, bind, err); act = tcf_action_init_1(tb[i], est, name, ovr, bind);
if (act == NULL) if (IS_ERR(act))
goto err; goto err;
act->order = i; act->order = i;
...@@ -571,7 +570,7 @@ struct tc_action *tcf_action_init(struct nlattr *nla, struct nlattr *est, ...@@ -571,7 +570,7 @@ struct tc_action *tcf_action_init(struct nlattr *nla, struct nlattr *est,
err: err:
if (head != NULL) if (head != NULL)
tcf_action_destroy(head, bind); tcf_action_destroy(head, bind);
return NULL; return act;
} }
int tcf_action_copy_stats(struct sk_buff *skb, struct tc_action *a, int tcf_action_copy_stats(struct sk_buff *skb, struct tc_action *a,
...@@ -668,44 +667,46 @@ act_get_notify(u32 pid, struct nlmsghdr *n, struct tc_action *a, int event) ...@@ -668,44 +667,46 @@ act_get_notify(u32 pid, struct nlmsghdr *n, struct tc_action *a, int event)
} }
static struct tc_action * static struct tc_action *
tcf_action_get_1(struct nlattr *nla, struct nlmsghdr *n, u32 pid, int *err) tcf_action_get_1(struct nlattr *nla, struct nlmsghdr *n, u32 pid)
{ {
struct nlattr *tb[TCA_ACT_MAX+1]; struct nlattr *tb[TCA_ACT_MAX+1];
struct tc_action *a; struct tc_action *a;
int index; int index;
int err;
*err = -EINVAL; err = -EINVAL;
if (nla_parse_nested(tb, TCA_ACT_MAX, nla, NULL) < 0) if (nla_parse_nested(tb, TCA_ACT_MAX, nla, NULL) < 0)
return NULL; goto err_out;
if (tb[TCA_ACT_INDEX] == NULL || if (tb[TCA_ACT_INDEX] == NULL ||
nla_len(tb[TCA_ACT_INDEX]) < sizeof(index)) nla_len(tb[TCA_ACT_INDEX]) < sizeof(index))
return NULL; goto err_out;
index = *(int *)nla_data(tb[TCA_ACT_INDEX]); index = *(int *)nla_data(tb[TCA_ACT_INDEX]);
*err = -ENOMEM; err = -ENOMEM;
a = kzalloc(sizeof(struct tc_action), GFP_KERNEL); a = kzalloc(sizeof(struct tc_action), GFP_KERNEL);
if (a == NULL) if (a == NULL)
return NULL; goto err_out;
*err = -EINVAL; err = -EINVAL;
a->ops = tc_lookup_action(tb[TCA_ACT_KIND]); a->ops = tc_lookup_action(tb[TCA_ACT_KIND]);
if (a->ops == NULL) if (a->ops == NULL)
goto err_free; goto err_free;
if (a->ops->lookup == NULL) if (a->ops->lookup == NULL)
goto err_mod; goto err_mod;
*err = -ENOENT; err = -ENOENT;
if (a->ops->lookup(a, index) == 0) if (a->ops->lookup(a, index) == 0)
goto err_mod; goto err_mod;
module_put(a->ops->owner); module_put(a->ops->owner);
*err = 0;
return a; return a;
err_mod: err_mod:
module_put(a->ops->owner); module_put(a->ops->owner);
err_free: err_free:
kfree(a); kfree(a);
return NULL; err_out:
return ERR_PTR(err);
} }
static void cleanup_a(struct tc_action *act) static void cleanup_a(struct tc_action *act)
...@@ -816,9 +817,11 @@ tca_action_gd(struct nlattr *nla, struct nlmsghdr *n, u32 pid, int event) ...@@ -816,9 +817,11 @@ tca_action_gd(struct nlattr *nla, struct nlmsghdr *n, u32 pid, int event)
} }
for (i = 1; i <= TCA_ACT_MAX_PRIO && tb[i]; i++) { for (i = 1; i <= TCA_ACT_MAX_PRIO && tb[i]; i++) {
act = tcf_action_get_1(tb[i], n, pid, &ret); act = tcf_action_get_1(tb[i], n, pid);
if (act == NULL) if (IS_ERR(act)) {
ret = PTR_ERR(act);
goto err; goto err;
}
act->order = i; act->order = i;
if (head == NULL) if (head == NULL)
...@@ -912,9 +915,13 @@ tcf_action_add(struct nlattr *nla, struct nlmsghdr *n, u32 pid, int ovr) ...@@ -912,9 +915,13 @@ tcf_action_add(struct nlattr *nla, struct nlmsghdr *n, u32 pid, int ovr)
struct tc_action *a; struct tc_action *a;
u32 seq = n->nlmsg_seq; u32 seq = n->nlmsg_seq;
act = tcf_action_init(nla, NULL, NULL, ovr, 0, &ret); act = tcf_action_init(nla, NULL, NULL, ovr, 0);
if (act == NULL) if (act == NULL)
goto done; goto done;
if (IS_ERR(act)) {
ret = PTR_ERR(act);
goto done;
}
/* dump then free all the actions after update; inserted policy /* dump then free all the actions after update; inserted policy
* stays intact * stays intact
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include <linux/init.h> #include <linux/init.h>
#include <linux/kmod.h> #include <linux/kmod.h>
#include <linux/netlink.h> #include <linux/netlink.h>
#include <linux/err.h>
#include <net/net_namespace.h> #include <net/net_namespace.h>
#include <net/sock.h> #include <net/sock.h>
#include <net/netlink.h> #include <net/netlink.h>
...@@ -487,23 +488,22 @@ int tcf_exts_validate(struct tcf_proto *tp, struct nlattr **tb, ...@@ -487,23 +488,22 @@ int tcf_exts_validate(struct tcf_proto *tp, struct nlattr **tb,
#ifdef CONFIG_NET_CLS_ACT #ifdef CONFIG_NET_CLS_ACT
{ {
int err;
struct tc_action *act; struct tc_action *act;
if (map->police && tb[map->police]) { if (map->police && tb[map->police]) {
act = tcf_action_init_1(tb[map->police], rate_tlv, act = tcf_action_init_1(tb[map->police], rate_tlv,
"police", TCA_ACT_NOREPLACE, "police", TCA_ACT_NOREPLACE,
TCA_ACT_BIND, &err); TCA_ACT_BIND);
if (act == NULL) if (IS_ERR(act))
return err; return PTR_ERR(act);
act->type = TCA_OLD_COMPAT; act->type = TCA_OLD_COMPAT;
exts->action = act; exts->action = act;
} else if (map->action && tb[map->action]) { } else if (map->action && tb[map->action]) {
act = tcf_action_init(tb[map->action], rate_tlv, NULL, act = tcf_action_init(tb[map->action], rate_tlv, NULL,
TCA_ACT_NOREPLACE, TCA_ACT_BIND, &err); TCA_ACT_NOREPLACE, TCA_ACT_BIND);
if (act == NULL) if (IS_ERR(act))
return err; return PTR_ERR(act);
exts->action = act; exts->action = act;
} }
......
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