From add93b610a4e66d36d0cf0b2596c3d3bcfdaee39 Mon Sep 17 00:00:00 2001 From: Patrick McHardy Date: Tue, 22 Jan 2008 22:11:33 -0800 Subject: [NET_SCHED]: Convert classifiers from rtnetlink to new netlink API Signed-off-by: Patrick McHardy Signed-off-by: David S. Miller --- net/sched/em_meta.c | 56 ++++++++++++++++++++++++++--------------------------- 1 file changed, 28 insertions(+), 28 deletions(-) (limited to 'net/sched/em_meta.c') diff --git a/net/sched/em_meta.c b/net/sched/em_meta.c index ceda8890ab0..92b6863e928 100644 --- a/net/sched/em_meta.c +++ b/net/sched/em_meta.c @@ -542,11 +542,11 @@ static int meta_var_compare(struct meta_obj *a, struct meta_obj *b) return r; } -static int meta_var_change(struct meta_value *dst, struct rtattr *rta) +static int meta_var_change(struct meta_value *dst, struct nlattr *nla) { - int len = RTA_PAYLOAD(rta); + int len = nla_len(nla); - dst->val = (unsigned long)kmemdup(RTA_DATA(rta), len, GFP_KERNEL); + dst->val = (unsigned long)kmemdup(nla_data(nla), len, GFP_KERNEL); if (dst->val == 0UL) return -ENOMEM; dst->len = len; @@ -570,10 +570,10 @@ static void meta_var_apply_extras(struct meta_value *v, static int meta_var_dump(struct sk_buff *skb, struct meta_value *v, int tlv) { if (v->val && v->len) - RTA_PUT(skb, tlv, v->len, (void *) v->val); + NLA_PUT(skb, tlv, v->len, (void *) v->val); return 0; -rtattr_failure: +nla_put_failure: return -1; } @@ -594,13 +594,13 @@ static int meta_int_compare(struct meta_obj *a, struct meta_obj *b) return 1; } -static int meta_int_change(struct meta_value *dst, struct rtattr *rta) +static int meta_int_change(struct meta_value *dst, struct nlattr *nla) { - if (RTA_PAYLOAD(rta) >= sizeof(unsigned long)) { - dst->val = *(unsigned long *) RTA_DATA(rta); + if (nla_len(nla) >= sizeof(unsigned long)) { + dst->val = *(unsigned long *) nla_data(nla); dst->len = sizeof(unsigned long); - } else if (RTA_PAYLOAD(rta) == sizeof(u32)) { - dst->val = *(u32 *) RTA_DATA(rta); + } else if (nla_len(nla) == sizeof(u32)) { + dst->val = *(u32 *) nla_data(nla); dst->len = sizeof(u32); } else return -EINVAL; @@ -621,15 +621,15 @@ static void meta_int_apply_extras(struct meta_value *v, static int meta_int_dump(struct sk_buff *skb, struct meta_value *v, int tlv) { if (v->len == sizeof(unsigned long)) - RTA_PUT(skb, tlv, sizeof(unsigned long), &v->val); + NLA_PUT(skb, tlv, sizeof(unsigned long), &v->val); else if (v->len == sizeof(u32)) { u32 d = v->val; - RTA_PUT(skb, tlv, sizeof(d), &d); + NLA_PUT(skb, tlv, sizeof(d), &d); } return 0; -rtattr_failure: +nla_put_failure: return -1; } @@ -641,7 +641,7 @@ struct meta_type_ops { void (*destroy)(struct meta_value *); int (*compare)(struct meta_obj *, struct meta_obj *); - int (*change)(struct meta_value *, struct rtattr *); + int (*change)(struct meta_value *, struct nlattr *); void (*apply_extras)(struct meta_value *, struct meta_obj *); int (*dump)(struct sk_buff *, struct meta_value *, int); }; @@ -729,13 +729,13 @@ static inline void meta_delete(struct meta_match *meta) kfree(meta); } -static inline int meta_change_data(struct meta_value *dst, struct rtattr *rta) +static inline int meta_change_data(struct meta_value *dst, struct nlattr *nla) { - if (rta) { - if (RTA_PAYLOAD(rta) == 0) + if (nla) { + if (nla_len(nla) == 0) return -EINVAL; - return meta_type_ops(dst)->change(dst, rta); + return meta_type_ops(dst)->change(dst, nla); } return 0; @@ -750,17 +750,17 @@ static int em_meta_change(struct tcf_proto *tp, void *data, int len, struct tcf_ematch *m) { int err = -EINVAL; - struct rtattr *tb[TCA_EM_META_MAX]; + struct nlattr *tb[TCA_EM_META_MAX + 1]; struct tcf_meta_hdr *hdr; struct meta_match *meta = NULL; - if (rtattr_parse(tb, TCA_EM_META_MAX, data, len) < 0) + if (nla_parse(tb, TCA_EM_META_MAX, data, len, NULL) < 0) goto errout; - if (tb[TCA_EM_META_HDR-1] == NULL || - RTA_PAYLOAD(tb[TCA_EM_META_HDR-1]) < sizeof(*hdr)) + if (tb[TCA_EM_META_HDR] == NULL || + nla_len(tb[TCA_EM_META_HDR]) < sizeof(*hdr)) goto errout; - hdr = RTA_DATA(tb[TCA_EM_META_HDR-1]); + hdr = nla_data(tb[TCA_EM_META_HDR]); if (TCF_META_TYPE(hdr->left.kind) != TCF_META_TYPE(hdr->right.kind) || TCF_META_TYPE(hdr->left.kind) > TCF_META_TYPE_MAX || @@ -781,8 +781,8 @@ static int em_meta_change(struct tcf_proto *tp, void *data, int len, goto errout; } - if (meta_change_data(&meta->lvalue, tb[TCA_EM_META_LVALUE-1]) < 0 || - meta_change_data(&meta->rvalue, tb[TCA_EM_META_RVALUE-1]) < 0) + if (meta_change_data(&meta->lvalue, tb[TCA_EM_META_LVALUE]) < 0 || + meta_change_data(&meta->rvalue, tb[TCA_EM_META_RVALUE]) < 0) goto errout; m->datalen = sizeof(*meta); @@ -811,16 +811,16 @@ static int em_meta_dump(struct sk_buff *skb, struct tcf_ematch *em) memcpy(&hdr.left, &meta->lvalue.hdr, sizeof(hdr.left)); memcpy(&hdr.right, &meta->rvalue.hdr, sizeof(hdr.right)); - RTA_PUT(skb, TCA_EM_META_HDR, sizeof(hdr), &hdr); + NLA_PUT(skb, TCA_EM_META_HDR, sizeof(hdr), &hdr); ops = meta_type_ops(&meta->lvalue); if (ops->dump(skb, &meta->lvalue, TCA_EM_META_LVALUE) < 0 || ops->dump(skb, &meta->rvalue, TCA_EM_META_RVALUE) < 0) - goto rtattr_failure; + goto nla_put_failure; return 0; -rtattr_failure: +nla_put_failure: return -1; } -- cgit v1.2.3-70-g09d2 From cee63723b358e594225e812d6e14a2a0abfd5c88 Mon Sep 17 00:00:00 2001 From: Patrick McHardy Date: Wed, 23 Jan 2008 20:33:32 -0800 Subject: [NET_SCHED]: Propagate nla_parse return value nla_parse() returns more detailed errno codes, propagate them back on error. Signed-off-by: Patrick McHardy Signed-off-by: David S. Miller --- net/sched/act_api.c | 29 ++++++++++++++++++----------- net/sched/act_gact.c | 7 ++++++- net/sched/act_ipt.c | 6 +++++- net/sched/act_mirred.c | 8 ++++++-- net/sched/act_nat.c | 8 ++++++-- net/sched/act_pedit.c | 8 ++++++-- net/sched/act_police.c | 6 +++++- net/sched/act_simple.c | 8 ++++++-- net/sched/cls_basic.c | 7 ++++--- net/sched/cls_fw.c | 5 +++-- net/sched/cls_route.c | 5 +++-- net/sched/cls_rsvp.h | 5 +++-- net/sched/cls_tcindex.c | 6 ++++-- net/sched/cls_u32.c | 5 +++-- net/sched/em_meta.c | 6 ++++-- net/sched/ematch.c | 6 ++++-- net/sched/sch_atm.c | 6 +++++- net/sched/sch_cbq.c | 14 +++++++++++--- net/sched/sch_dsmark.c | 14 ++++++++++++-- net/sched/sch_gred.c | 16 +++++++++++++--- net/sched/sch_hfsc.c | 7 ++++++- net/sched/sch_htb.c | 23 +++++++++++++++++++---- net/sched/sch_prio.c | 9 ++++++--- net/sched/sch_red.c | 7 ++++++- net/sched/sch_tbf.c | 10 +++++++--- 25 files changed, 171 insertions(+), 60 deletions(-) (limited to 'net/sched/em_meta.c') diff --git a/net/sched/act_api.c b/net/sched/act_api.c index ea80f82dbb6..87818d7fb62 100644 --- a/net/sched/act_api.c +++ b/net/sched/act_api.c @@ -473,17 +473,18 @@ struct tc_action *tcf_action_init_1(struct nlattr *nla, struct nlattr *est, struct nlattr *kind; int err; - err = -EINVAL; - if (name == NULL) { - if (nla_parse_nested(tb, TCA_ACT_MAX, nla, NULL) < 0) + err = nla_parse_nested(tb, TCA_ACT_MAX, nla, NULL); + if (err < 0) goto err_out; + err = -EINVAL; kind = tb[TCA_ACT_KIND]; if (kind == NULL) goto err_out; if (nla_strlcpy(act_name, kind, IFNAMSIZ) >= IFNAMSIZ) goto err_out; } else { + err = -EINVAL; if (strlcpy(act_name, name, IFNAMSIZ) >= IFNAMSIZ) goto err_out; } @@ -548,10 +549,12 @@ struct tc_action *tcf_action_init(struct nlattr *nla, struct nlattr *est, { struct nlattr *tb[TCA_ACT_MAX_PRIO+1]; struct tc_action *head = NULL, *act, *act_prev = NULL; + int err; int i; - if (nla_parse_nested(tb, TCA_ACT_MAX_PRIO, nla, NULL) < 0) - return ERR_PTR(-EINVAL); + err = nla_parse_nested(tb, TCA_ACT_MAX_PRIO, nla, NULL); + if (err < 0) + return ERR_PTR(err); for (i = 1; i <= TCA_ACT_MAX_PRIO && tb[i]; i++) { act = tcf_action_init_1(tb[i], est, name, ovr, bind); @@ -674,10 +677,11 @@ tcf_action_get_1(struct nlattr *nla, struct nlmsghdr *n, u32 pid) int index; int err; - err = -EINVAL; - if (nla_parse_nested(tb, TCA_ACT_MAX, nla, NULL) < 0) + err = nla_parse_nested(tb, TCA_ACT_MAX, nla, NULL); + if (err < 0) goto err_out; + err = -EINVAL; if (tb[TCA_ACT_INDEX] == NULL || nla_len(tb[TCA_ACT_INDEX]) < sizeof(index)) goto err_out; @@ -759,9 +763,11 @@ static int tca_action_flush(struct nlattr *nla, struct nlmsghdr *n, u32 pid) b = skb_tail_pointer(skb); - if (nla_parse_nested(tb, TCA_ACT_MAX, nla, NULL) < 0) + err = nla_parse_nested(tb, TCA_ACT_MAX, nla, NULL); + if (err < 0) goto err_out; + err = -EINVAL; kind = tb[TCA_ACT_KIND]; a->ops = tc_lookup_action(kind); if (a->ops == NULL) @@ -804,12 +810,13 @@ err_out: static int tca_action_gd(struct nlattr *nla, struct nlmsghdr *n, u32 pid, int event) { - int i, ret = 0; + int i, ret; struct nlattr *tb[TCA_ACT_MAX_PRIO+1]; struct tc_action *head = NULL, *act, *act_prev = NULL; - if (nla_parse_nested(tb, TCA_ACT_MAX_PRIO, nla, NULL) < 0) - return -EINVAL; + ret = nla_parse_nested(tb, TCA_ACT_MAX_PRIO, nla, NULL); + if (ret < 0) + return ret; if (event == RTM_DELACTION && n->nlmsg_flags&NLM_F_ROOT) { if (tb[0] != NULL && tb[1] == NULL) diff --git a/net/sched/act_gact.c b/net/sched/act_gact.c index 5402cf885f9..df214d47fc9 100644 --- a/net/sched/act_gact.c +++ b/net/sched/act_gact.c @@ -61,10 +61,15 @@ static int tcf_gact_init(struct nlattr *nla, struct nlattr *est, struct tcf_gact *gact; struct tcf_common *pc; int ret = 0; + int err; - if (nla == NULL || nla_parse_nested(tb, TCA_GACT_MAX, nla, NULL) < 0) + if (nla == NULL) return -EINVAL; + err = nla_parse_nested(tb, TCA_GACT_MAX, nla, NULL); + if (err < 0) + return err; + if (tb[TCA_GACT_PARMS] == NULL || nla_len(tb[TCA_GACT_PARMS]) < sizeof(*parm)) return -EINVAL; diff --git a/net/sched/act_ipt.c b/net/sched/act_ipt.c index fee5282637c..12693347d56 100644 --- a/net/sched/act_ipt.c +++ b/net/sched/act_ipt.c @@ -104,9 +104,13 @@ static int tcf_ipt_init(struct nlattr *nla, struct nlattr *est, u32 hook = 0; u32 index = 0; - if (nla == NULL || nla_parse_nested(tb, TCA_IPT_MAX, nla, NULL) < 0) + if (nla == NULL) return -EINVAL; + err = nla_parse_nested(tb, TCA_IPT_MAX, nla, NULL); + if (err < 0) + return err; + if (tb[TCA_IPT_HOOK] == NULL || nla_len(tb[TCA_IPT_HOOK]) < sizeof(u32)) return -EINVAL; diff --git a/net/sched/act_mirred.c b/net/sched/act_mirred.c index db943a8c738..6cb5e30dcf8 100644 --- a/net/sched/act_mirred.c +++ b/net/sched/act_mirred.c @@ -62,12 +62,16 @@ static int tcf_mirred_init(struct nlattr *nla, struct nlattr *est, struct tcf_mirred *m; struct tcf_common *pc; struct net_device *dev = NULL; - int ret = 0; + int ret = 0, err; int ok_push = 0; - if (nla == NULL || nla_parse_nested(tb, TCA_MIRRED_MAX, nla, NULL) < 0) + if (nla == NULL) return -EINVAL; + err = nla_parse_nested(tb, TCA_MIRRED_MAX, nla, NULL); + if (err < 0) + return err; + if (tb[TCA_MIRRED_PARMS] == NULL || nla_len(tb[TCA_MIRRED_PARMS]) < sizeof(*parm)) return -EINVAL; diff --git a/net/sched/act_nat.c b/net/sched/act_nat.c index be007bb31b5..5a512d4dc37 100644 --- a/net/sched/act_nat.c +++ b/net/sched/act_nat.c @@ -45,13 +45,17 @@ static int tcf_nat_init(struct nlattr *nla, struct nlattr *est, { struct nlattr *tb[TCA_NAT_MAX + 1]; struct tc_nat *parm; - int ret = 0; + int ret = 0, err; struct tcf_nat *p; struct tcf_common *pc; - if (nla == NULL || nla_parse_nested(tb, TCA_NAT_MAX, nla, NULL) < 0) + if (nla == NULL) return -EINVAL; + err = nla_parse_nested(tb, TCA_NAT_MAX, nla, NULL); + if (err < 0) + return err; + if (tb[TCA_NAT_PARMS] == NULL || nla_len(tb[TCA_NAT_PARMS]) < sizeof(*parm)) return -EINVAL; diff --git a/net/sched/act_pedit.c b/net/sched/act_pedit.c index 88d8a15a192..1b9ca45a78e 100644 --- a/net/sched/act_pedit.c +++ b/net/sched/act_pedit.c @@ -38,15 +38,19 @@ static int tcf_pedit_init(struct nlattr *nla, struct nlattr *est, { struct nlattr *tb[TCA_PEDIT_MAX + 1]; struct tc_pedit *parm; - int ret = 0; + int ret = 0, err; struct tcf_pedit *p; struct tcf_common *pc; struct tc_pedit_key *keys = NULL; int ksize; - if (nla == NULL || nla_parse_nested(tb, TCA_PEDIT_MAX, nla, NULL) < 0) + if (nla == NULL) return -EINVAL; + err = nla_parse_nested(tb, TCA_PEDIT_MAX, nla, NULL); + if (err < 0) + return err; + if (tb[TCA_PEDIT_PARMS] == NULL || nla_len(tb[TCA_PEDIT_PARMS]) < sizeof(*parm)) return -EINVAL; diff --git a/net/sched/act_police.c b/net/sched/act_police.c index 3af5759aac2..c0fce9b9841 100644 --- a/net/sched/act_police.c +++ b/net/sched/act_police.c @@ -129,9 +129,13 @@ static int tcf_act_police_locate(struct nlattr *nla, struct nlattr *est, struct qdisc_rate_table *R_tab = NULL, *P_tab = NULL; int size; - if (nla == NULL || nla_parse_nested(tb, TCA_POLICE_MAX, nla, NULL) < 0) + if (nla == NULL) return -EINVAL; + err = nla_parse_nested(tb, TCA_POLICE_MAX, nla, NULL); + if (err < 0) + return err; + if (tb[TCA_POLICE_TBF] == NULL) return -EINVAL; size = nla_len(tb[TCA_POLICE_TBF]); diff --git a/net/sched/act_simple.c b/net/sched/act_simple.c index d3226e24070..cedaadf18eb 100644 --- a/net/sched/act_simple.c +++ b/net/sched/act_simple.c @@ -93,11 +93,15 @@ static int tcf_simp_init(struct nlattr *nla, struct nlattr *est, struct tcf_common *pc; void *defdata; u32 datalen = 0; - int ret = 0; + int ret = 0, err; - if (nla == NULL || nla_parse_nested(tb, TCA_DEF_MAX, nla, NULL) < 0) + if (nla == NULL) return -EINVAL; + err = nla_parse_nested(tb, TCA_DEF_MAX, nla, NULL); + if (err < 0) + return err; + if (tb[TCA_DEF_PARMS] == NULL || nla_len(tb[TCA_DEF_PARMS]) < sizeof(*parm)) return -EINVAL; diff --git a/net/sched/cls_basic.c b/net/sched/cls_basic.c index 3953da33956..524b7885dc3 100644 --- a/net/sched/cls_basic.c +++ b/net/sched/cls_basic.c @@ -166,7 +166,7 @@ errout: static int basic_change(struct tcf_proto *tp, unsigned long base, u32 handle, struct nlattr **tca, unsigned long *arg) { - int err = -EINVAL; + int err; struct basic_head *head = (struct basic_head *) tp->root; struct nlattr *tb[TCA_BASIC_MAX + 1]; struct basic_filter *f = (struct basic_filter *) *arg; @@ -174,8 +174,9 @@ static int basic_change(struct tcf_proto *tp, unsigned long base, u32 handle, if (tca[TCA_OPTIONS] == NULL) return -EINVAL; - if (nla_parse_nested(tb, TCA_BASIC_MAX, tca[TCA_OPTIONS], NULL) < 0) - return -EINVAL; + err = nla_parse_nested(tb, TCA_BASIC_MAX, tca[TCA_OPTIONS], NULL); + if (err < 0) + return err; if (f != NULL) { if (handle && f->handle != handle) diff --git a/net/sched/cls_fw.c b/net/sched/cls_fw.c index db6e90a3784..a1a9f4d26b8 100644 --- a/net/sched/cls_fw.c +++ b/net/sched/cls_fw.c @@ -246,8 +246,9 @@ static int fw_change(struct tcf_proto *tp, unsigned long base, if (!opt) return handle ? -EINVAL : 0; - if (nla_parse_nested(tb, TCA_FW_MAX, opt, NULL) < 0) - return -EINVAL; + err = nla_parse_nested(tb, TCA_FW_MAX, opt, NULL); + if (err < 0) + return err; if (f != NULL) { if (f->id != handle && handle) diff --git a/net/sched/cls_route.c b/net/sched/cls_route.c index b1aae84cbad..3aa8109aa3c 100644 --- a/net/sched/cls_route.c +++ b/net/sched/cls_route.c @@ -440,8 +440,9 @@ static int route4_change(struct tcf_proto *tp, unsigned long base, if (opt == NULL) return handle ? -EINVAL : 0; - if (nla_parse_nested(tb, TCA_ROUTE4_MAX, opt, NULL) < 0) - return -EINVAL; + err = nla_parse_nested(tb, TCA_ROUTE4_MAX, opt, NULL); + if (err < 0) + return err; if ((f = (struct route4_filter*)*arg) != NULL) { if (f->handle != handle && handle) diff --git a/net/sched/cls_rsvp.h b/net/sched/cls_rsvp.h index 2364c79d083..5747408a7d4 100644 --- a/net/sched/cls_rsvp.h +++ b/net/sched/cls_rsvp.h @@ -416,8 +416,9 @@ static int rsvp_change(struct tcf_proto *tp, unsigned long base, if (opt == NULL) return handle ? -EINVAL : 0; - if (nla_parse_nested(tb, TCA_RSVP_MAX, opt, NULL) < 0) - return -EINVAL; + err = nla_parse_nested(tb, TCA_RSVP_MAX, opt, NULL); + if (err < 0) + return err; err = tcf_exts_validate(tp, tb, tca[TCA_RATE-1], &e, &rsvp_ext_map); if (err < 0) diff --git a/net/sched/cls_tcindex.c b/net/sched/cls_tcindex.c index ed8023944fe..6b84d276e5a 100644 --- a/net/sched/cls_tcindex.c +++ b/net/sched/cls_tcindex.c @@ -350,6 +350,7 @@ tcindex_change(struct tcf_proto *tp, unsigned long base, u32 handle, struct nlattr *tb[TCA_TCINDEX_MAX + 1]; struct tcindex_data *p = PRIV(tp); struct tcindex_filter_result *r = (struct tcindex_filter_result *) *arg; + int err; pr_debug("tcindex_change(tp %p,handle 0x%08x,tca %p,arg %p),opt %p," "p %p,r %p,*arg 0x%lx\n", @@ -358,8 +359,9 @@ tcindex_change(struct tcf_proto *tp, unsigned long base, u32 handle, if (!opt) return 0; - if (nla_parse_nested(tb, TCA_TCINDEX_MAX, opt, NULL) < 0) - return -EINVAL; + err = nla_parse_nested(tb, TCA_TCINDEX_MAX, opt, NULL); + if (err < 0) + return err; return tcindex_set_parms(tp, base, handle, p, r, tb, tca[TCA_RATE]); } diff --git a/net/sched/cls_u32.c b/net/sched/cls_u32.c index aaf5049f951..3228cc4ae08 100644 --- a/net/sched/cls_u32.c +++ b/net/sched/cls_u32.c @@ -531,8 +531,9 @@ static int u32_change(struct tcf_proto *tp, unsigned long base, u32 handle, if (opt == NULL) return handle ? -EINVAL : 0; - if (nla_parse_nested(tb, TCA_U32_MAX, opt, NULL) < 0) - return -EINVAL; + err = nla_parse_nested(tb, TCA_U32_MAX, opt, NULL); + if (err < 0) + return err; if ((n = (struct tc_u_knode*)*arg) != NULL) { if (TC_U32_KEY(n->handle) == 0) diff --git a/net/sched/em_meta.c b/net/sched/em_meta.c index 92b6863e928..dd5723670d3 100644 --- a/net/sched/em_meta.c +++ b/net/sched/em_meta.c @@ -749,14 +749,16 @@ static inline int meta_is_supported(struct meta_value *val) static int em_meta_change(struct tcf_proto *tp, void *data, int len, struct tcf_ematch *m) { - int err = -EINVAL; + int err; struct nlattr *tb[TCA_EM_META_MAX + 1]; struct tcf_meta_hdr *hdr; struct meta_match *meta = NULL; - if (nla_parse(tb, TCA_EM_META_MAX, data, len, NULL) < 0) + err = nla_parse(tb, TCA_EM_META_MAX, data, len, NULL); + if (err < 0) goto errout; + err = -EINVAL; if (tb[TCA_EM_META_HDR] == NULL || nla_len(tb[TCA_EM_META_HDR]) < sizeof(*hdr)) goto errout; diff --git a/net/sched/ematch.c b/net/sched/ematch.c index 72d9b273524..d2b480f01a4 100644 --- a/net/sched/ematch.c +++ b/net/sched/ematch.c @@ -301,7 +301,7 @@ errout: int tcf_em_tree_validate(struct tcf_proto *tp, struct nlattr *nla, struct tcf_ematch_tree *tree) { - int idx, list_len, matches_len, err = -EINVAL; + int idx, list_len, matches_len, err; struct nlattr *tb[TCA_EMATCH_TREE_MAX + 1]; struct nlattr *rt_match, *rt_hdr, *rt_list; struct tcf_ematch_tree_hdr *tree_hdr; @@ -312,9 +312,11 @@ int tcf_em_tree_validate(struct tcf_proto *tp, struct nlattr *nla, return 0; } - if (nla_parse_nested(tb, TCA_EMATCH_TREE_MAX, nla, NULL) < 0) + err = nla_parse_nested(tb, TCA_EMATCH_TREE_MAX, nla, NULL); + if (err < 0) goto errout; + err = -EINVAL; rt_hdr = tb[TCA_EMATCH_TREE_HDR]; rt_list = tb[TCA_EMATCH_TREE_LIST]; diff --git a/net/sched/sch_atm.c b/net/sched/sch_atm.c index e5873915378..aaa32a22726 100644 --- a/net/sched/sch_atm.c +++ b/net/sched/sch_atm.c @@ -223,8 +223,12 @@ static int atm_tc_change(struct Qdisc *sch, u32 classid, u32 parent, */ if (flow) return -EBUSY; - if (opt == NULL || nla_parse_nested(tb, TCA_ATM_MAX, opt, NULL)) + if (opt == NULL) return -EINVAL; + error = nla_parse_nested(tb, TCA_ATM_MAX, opt, NULL); + if (error < 0) + return error; + if (!tb[TCA_ATM_FD] || nla_len(tb[TCA_ATM_FD]) < sizeof(fd)) return -EINVAL; fd = *(int *)nla_data(tb[TCA_ATM_FD]); diff --git a/net/sched/sch_cbq.c b/net/sched/sch_cbq.c index 5c8667ef4ba..585f8a6ec7e 100644 --- a/net/sched/sch_cbq.c +++ b/net/sched/sch_cbq.c @@ -1382,9 +1382,13 @@ static int cbq_init(struct Qdisc *sch, struct nlattr *opt) struct cbq_sched_data *q = qdisc_priv(sch); struct nlattr *tb[TCA_CBQ_MAX + 1]; struct tc_ratespec *r; + int err; + + err = nla_parse_nested(tb, TCA_CBQ_MAX, opt, NULL); + if (err < 0) + return err; - if (nla_parse_nested(tb, TCA_CBQ_MAX, opt, NULL) < 0 || - tb[TCA_CBQ_RTAB] == NULL || tb[TCA_CBQ_RATE] == NULL || + if (tb[TCA_CBQ_RTAB] == NULL || tb[TCA_CBQ_RATE] == NULL || nla_len(tb[TCA_CBQ_RATE]) < sizeof(struct tc_ratespec)) return -EINVAL; @@ -1764,9 +1768,13 @@ cbq_change_class(struct Qdisc *sch, u32 classid, u32 parentid, struct nlattr **t struct cbq_class *parent; struct qdisc_rate_table *rtab = NULL; - if (opt==NULL || nla_parse_nested(tb, TCA_CBQ_MAX, opt, NULL)) + if (opt == NULL) return -EINVAL; + err = nla_parse_nested(tb, TCA_CBQ_MAX, opt, NULL); + if (err < 0) + return err; + if (tb[TCA_CBQ_OVL_STRATEGY] && nla_len(tb[TCA_CBQ_OVL_STRATEGY]) < sizeof(struct tc_cbq_ovl)) return -EINVAL; diff --git a/net/sched/sch_dsmark.c b/net/sched/sch_dsmark.c index f183ab76887..f1d0a08aca7 100644 --- a/net/sched/sch_dsmark.c +++ b/net/sched/sch_dsmark.c @@ -116,9 +116,14 @@ static int dsmark_change(struct Qdisc *sch, u32 classid, u32 parent, goto errout; } - if (!opt || nla_parse_nested(tb, TCA_DSMARK_MAX, opt, NULL)) + if (!opt) goto errout; + err = nla_parse_nested(tb, TCA_DSMARK_MAX, opt, NULL); + if (err < 0) + return err; + + err = -EINVAL; if (tb[TCA_DSMARK_MASK]) { if (nla_len(tb[TCA_DSMARK_MASK]) < sizeof(u8)) goto errout; @@ -351,9 +356,14 @@ static int dsmark_init(struct Qdisc *sch, struct nlattr *opt) pr_debug("dsmark_init(sch %p,[qdisc %p],opt %p)\n", sch, p, opt); - if (!opt || nla_parse_nested(tb, TCA_DSMARK_MAX, opt, NULL) < 0) + if (!opt) + goto errout; + + err = nla_parse_nested(tb, TCA_DSMARK_MAX, opt, NULL); + if (err < 0) goto errout; + err = -EINVAL; if (nla_len(tb[TCA_DSMARK_INDICES]) < sizeof(u16)) goto errout; indices = nla_get_u16(tb[TCA_DSMARK_INDICES]); diff --git a/net/sched/sch_gred.c b/net/sched/sch_gred.c index 6b784838a53..365c7d8b17a 100644 --- a/net/sched/sch_gred.c +++ b/net/sched/sch_gred.c @@ -430,12 +430,16 @@ static int gred_change(struct Qdisc *sch, struct nlattr *opt) struct gred_sched *table = qdisc_priv(sch); struct tc_gred_qopt *ctl; struct nlattr *tb[TCA_GRED_MAX + 1]; - int err = -EINVAL, prio = GRED_DEF_PRIO; + int err, prio = GRED_DEF_PRIO; u8 *stab; - if (opt == NULL || nla_parse_nested(tb, TCA_GRED_MAX, opt, NULL)) + if (opt == NULL) return -EINVAL; + err = nla_parse_nested(tb, TCA_GRED_MAX, opt, NULL); + if (err < 0) + return err; + if (tb[TCA_GRED_PARMS] == NULL && tb[TCA_GRED_STAB] == NULL) return gred_change_table_def(sch, opt); @@ -445,6 +449,7 @@ static int gred_change(struct Qdisc *sch, struct nlattr *opt) nla_len(tb[TCA_GRED_STAB]) < 256) return -EINVAL; + err = -EINVAL; ctl = nla_data(tb[TCA_GRED_PARMS]); stab = nla_data(tb[TCA_GRED_STAB]); @@ -489,10 +494,15 @@ errout: static int gred_init(struct Qdisc *sch, struct nlattr *opt) { struct nlattr *tb[TCA_GRED_MAX + 1]; + int err; - if (opt == NULL || nla_parse_nested(tb, TCA_GRED_MAX, opt, NULL)) + if (opt == NULL) return -EINVAL; + err = nla_parse_nested(tb, TCA_GRED_MAX, opt, NULL); + if (err < 0) + return err; + if (tb[TCA_GRED_PARMS] || tb[TCA_GRED_STAB]) return -EINVAL; diff --git a/net/sched/sch_hfsc.c b/net/sched/sch_hfsc.c index 4e6a164d305..fcb4826158d 100644 --- a/net/sched/sch_hfsc.c +++ b/net/sched/sch_hfsc.c @@ -997,10 +997,15 @@ hfsc_change_class(struct Qdisc *sch, u32 classid, u32 parentid, struct nlattr *tb[TCA_HFSC_MAX + 1]; struct tc_service_curve *rsc = NULL, *fsc = NULL, *usc = NULL; u64 cur_time; + int err; - if (opt == NULL || nla_parse_nested(tb, TCA_HFSC_MAX, opt, NULL)) + if (opt == NULL) return -EINVAL; + err = nla_parse_nested(tb, TCA_HFSC_MAX, opt, NULL); + if (err < 0) + return err; + if (tb[TCA_HFSC_RSC]) { if (nla_len(tb[TCA_HFSC_RSC]) < sizeof(*rsc)) return -EINVAL; diff --git a/net/sched/sch_htb.c b/net/sched/sch_htb.c index 3b3ff641b6d..512df9a0a24 100644 --- a/net/sched/sch_htb.c +++ b/net/sched/sch_htb.c @@ -997,9 +997,17 @@ static int htb_init(struct Qdisc *sch, struct nlattr *opt) struct htb_sched *q = qdisc_priv(sch); struct nlattr *tb[TCA_HTB_INIT + 1]; struct tc_htb_glob *gopt; + int err; int i; - if (!opt || nla_parse_nested(tb, TCA_HTB_INIT, opt, NULL) || - tb[TCA_HTB_INIT] == NULL || + + if (!opt) + return -EINVAL; + + err = nla_parse_nested(tb, TCA_HTB_INIT, opt, NULL); + if (err < 0) + return err; + + if (tb[TCA_HTB_INIT] == NULL || nla_len(tb[TCA_HTB_INIT]) < sizeof(*gopt)) { printk(KERN_ERR "HTB: hey probably you have bad tc tool ?\n"); return -EINVAL; @@ -1302,8 +1310,15 @@ static int htb_change_class(struct Qdisc *sch, u32 classid, struct tc_htb_opt *hopt; /* extract all subattrs from opt attr */ - if (!opt || nla_parse_nested(tb, TCA_HTB_RTAB, opt, NULL) || - tb[TCA_HTB_PARMS] == NULL || + if (!opt) + goto failure; + + err = nla_parse_nested(tb, TCA_HTB_RTAB, opt, NULL); + if (err < 0) + goto failure; + + err = -EINVAL; + if (tb[TCA_HTB_PARMS] == NULL || nla_len(tb[TCA_HTB_PARMS]) < sizeof(*hopt)) goto failure; diff --git a/net/sched/sch_prio.c b/net/sched/sch_prio.c index a4f932df86e..4aa2b45dad0 100644 --- a/net/sched/sch_prio.c +++ b/net/sched/sch_prio.c @@ -229,11 +229,14 @@ static int prio_tune(struct Qdisc *sch, struct nlattr *opt) struct prio_sched_data *q = qdisc_priv(sch); struct tc_prio_qopt *qopt; struct nlattr *tb[TCA_PRIO_MAX + 1]; + int err; int i; - if (nla_parse_nested_compat(tb, TCA_PRIO_MAX, opt, NULL, qopt, - sizeof(*qopt))) - return -EINVAL; + err = nla_parse_nested_compat(tb, TCA_PRIO_MAX, opt, NULL, qopt, + sizeof(*qopt)); + if (err < 0) + return err; + q->bands = qopt->bands; /* If we're multiqueue, make sure the number of incoming bands * matches the number of queues on the device we're associating with. diff --git a/net/sched/sch_red.c b/net/sched/sch_red.c index 6ce8da5aca0..dcf6afc196f 100644 --- a/net/sched/sch_red.c +++ b/net/sched/sch_red.c @@ -207,10 +207,15 @@ static int red_change(struct Qdisc *sch, struct nlattr *opt) struct nlattr *tb[TCA_RED_MAX + 1]; struct tc_red_qopt *ctl; struct Qdisc *child = NULL; + int err; - if (opt == NULL || nla_parse_nested(tb, TCA_RED_MAX, opt, NULL)) + if (opt == NULL) return -EINVAL; + err = nla_parse_nested(tb, TCA_RED_MAX, opt, NULL); + if (err < 0) + return err; + if (tb[TCA_RED_PARMS] == NULL || nla_len(tb[TCA_RED_PARMS]) < sizeof(*ctl) || tb[TCA_RED_STAB] == NULL || diff --git a/net/sched/sch_tbf.c b/net/sched/sch_tbf.c index 6c4ad7e677b..f9b1543e3d7 100644 --- a/net/sched/sch_tbf.c +++ b/net/sched/sch_tbf.c @@ -272,7 +272,7 @@ static struct Qdisc *tbf_create_dflt_qdisc(struct Qdisc *sch, u32 limit) static int tbf_change(struct Qdisc* sch, struct nlattr *opt) { - int err = -EINVAL; + int err; struct tbf_sched_data *q = qdisc_priv(sch); struct nlattr *tb[TCA_TBF_PTAB + 1]; struct tc_tbf_qopt *qopt; @@ -281,8 +281,12 @@ static int tbf_change(struct Qdisc* sch, struct nlattr *opt) struct Qdisc *child = NULL; int max_size,n; - if (nla_parse_nested(tb, TCA_TBF_PTAB, opt, NULL) || - tb[TCA_TBF_PARMS] == NULL || + err = nla_parse_nested(tb, TCA_TBF_PTAB, opt, NULL); + if (err < 0) + return err; + + err = -EINVAL; + if (tb[TCA_TBF_PARMS] == NULL || nla_len(tb[TCA_TBF_PARMS]) < sizeof(*qopt)) goto done; -- cgit v1.2.3-70-g09d2 From 24beeab539c6f42c4a93e2ff7c3b5f272e60da45 Mon Sep 17 00:00:00 2001 From: Patrick McHardy Date: Wed, 23 Jan 2008 20:34:48 -0800 Subject: [NET_SCHED]: Use typeful attribute construction helpers Signed-off-by: Patrick McHardy Signed-off-by: David S. Miller --- net/sched/act_api.c | 2 +- net/sched/act_ipt.c | 4 ++-- net/sched/act_police.c | 5 ++--- net/sched/cls_basic.c | 2 +- net/sched/cls_fw.c | 4 ++-- net/sched/cls_route.c | 8 ++++---- net/sched/cls_rsvp.h | 2 +- net/sched/cls_tcindex.c | 11 +++++------ net/sched/cls_u32.c | 8 ++++---- net/sched/em_meta.c | 3 +-- net/sched/sch_atm.c | 8 +++----- 11 files changed, 26 insertions(+), 31 deletions(-) (limited to 'net/sched/em_meta.c') diff --git a/net/sched/act_api.c b/net/sched/act_api.c index e33e43abe96..41fbd496aba 100644 --- a/net/sched/act_api.c +++ b/net/sched/act_api.c @@ -133,7 +133,7 @@ static int tcf_del_walker(struct sk_buff *skb, struct tc_action *a, p = s_p; } } - NLA_PUT(skb, TCA_FCNT, 4, &n_i); + NLA_PUT_U32(skb, TCA_FCNT, n_i); nla_nest_end(skb, nest); return n_i; diff --git a/net/sched/act_ipt.c b/net/sched/act_ipt.c index ecda51da9c1..5dd701a7bc5 100644 --- a/net/sched/act_ipt.c +++ b/net/sched/act_ipt.c @@ -254,8 +254,8 @@ static int tcf_ipt_dump(struct sk_buff *skb, struct tc_action *a, int bind, int strcpy(t->u.user.name, ipt->tcfi_t->u.kernel.target->name); NLA_PUT(skb, TCA_IPT_TARG, ipt->tcfi_t->u.user.target_size, t); - NLA_PUT(skb, TCA_IPT_INDEX, 4, &ipt->tcf_index); - NLA_PUT(skb, TCA_IPT_HOOK, 4, &ipt->tcfi_hook); + NLA_PUT_U32(skb, TCA_IPT_INDEX, ipt->tcf_index); + NLA_PUT_U32(skb, TCA_IPT_HOOK, ipt->tcfi_hook); NLA_PUT(skb, TCA_IPT_CNT, sizeof(struct tc_cnt), &c); NLA_PUT_STRING(skb, TCA_IPT_TABLE, ipt->tcfi_tname); tm.install = jiffies_to_clock_t(jiffies - ipt->tcf_tm.install); diff --git a/net/sched/act_police.c b/net/sched/act_police.c index ee2f1b64dd7..79db6bb8a5f 100644 --- a/net/sched/act_police.c +++ b/net/sched/act_police.c @@ -339,10 +339,9 @@ tcf_act_police_dump(struct sk_buff *skb, struct tc_action *a, int bind, int ref) memset(&opt.peakrate, 0, sizeof(opt.peakrate)); NLA_PUT(skb, TCA_POLICE_TBF, sizeof(opt), &opt); if (police->tcfp_result) - NLA_PUT(skb, TCA_POLICE_RESULT, sizeof(int), - &police->tcfp_result); + NLA_PUT_U32(skb, TCA_POLICE_RESULT, police->tcfp_result); if (police->tcfp_ewma_rate) - NLA_PUT(skb, TCA_POLICE_AVRATE, 4, &police->tcfp_ewma_rate); + NLA_PUT_U32(skb, TCA_POLICE_AVRATE, police->tcfp_ewma_rate); return skb->len; nla_put_failure: diff --git a/net/sched/cls_basic.c b/net/sched/cls_basic.c index 6d08b429635..58444fedf06 100644 --- a/net/sched/cls_basic.c +++ b/net/sched/cls_basic.c @@ -258,7 +258,7 @@ static int basic_dump(struct tcf_proto *tp, unsigned long fh, goto nla_put_failure; if (f->res.classid) - NLA_PUT(skb, TCA_BASIC_CLASSID, sizeof(u32), &f->res.classid); + NLA_PUT_U32(skb, TCA_BASIC_CLASSID, f->res.classid); if (tcf_exts_dump(skb, &f->exts, &basic_ext_map) < 0 || tcf_em_tree_dump(skb, &f->ematches, TCA_BASIC_EMATCHES) < 0) diff --git a/net/sched/cls_fw.c b/net/sched/cls_fw.c index 31074735d1b..61ebe25e5f7 100644 --- a/net/sched/cls_fw.c +++ b/net/sched/cls_fw.c @@ -349,13 +349,13 @@ static int fw_dump(struct tcf_proto *tp, unsigned long fh, goto nla_put_failure; if (f->res.classid) - NLA_PUT(skb, TCA_FW_CLASSID, 4, &f->res.classid); + NLA_PUT_U32(skb, TCA_FW_CLASSID, f->res.classid); #ifdef CONFIG_NET_CLS_IND if (strlen(f->indev)) NLA_PUT_STRING(skb, TCA_FW_INDEV, f->indev); #endif /* CONFIG_NET_CLS_IND */ if (head->mask != 0xFFFFFFFF) - NLA_PUT(skb, TCA_FW_MASK, 4, &head->mask); + NLA_PUT_U32(skb, TCA_FW_MASK, head->mask); if (tcf_exts_dump(skb, &f->exts, &fw_ext_map) < 0) goto nla_put_failure; diff --git a/net/sched/cls_route.c b/net/sched/cls_route.c index 1ce1f3623d6..7752586e918 100644 --- a/net/sched/cls_route.c +++ b/net/sched/cls_route.c @@ -565,17 +565,17 @@ static int route4_dump(struct tcf_proto *tp, unsigned long fh, if (!(f->handle&0x8000)) { id = f->id&0xFF; - NLA_PUT(skb, TCA_ROUTE4_TO, sizeof(id), &id); + NLA_PUT_U32(skb, TCA_ROUTE4_TO, id); } if (f->handle&0x80000000) { if ((f->handle>>16) != 0xFFFF) - NLA_PUT(skb, TCA_ROUTE4_IIF, sizeof(f->iif), &f->iif); + NLA_PUT_U32(skb, TCA_ROUTE4_IIF, f->iif); } else { id = f->id>>16; - NLA_PUT(skb, TCA_ROUTE4_FROM, sizeof(id), &id); + NLA_PUT_U32(skb, TCA_ROUTE4_FROM, id); } if (f->res.classid) - NLA_PUT(skb, TCA_ROUTE4_CLASSID, 4, &f->res.classid); + NLA_PUT_U32(skb, TCA_ROUTE4_CLASSID, f->res.classid); if (tcf_exts_dump(skb, &f->exts, &route_ext_map) < 0) goto nla_put_failure; diff --git a/net/sched/cls_rsvp.h b/net/sched/cls_rsvp.h index 77097e023f7..838a3ff5a2c 100644 --- a/net/sched/cls_rsvp.h +++ b/net/sched/cls_rsvp.h @@ -617,7 +617,7 @@ static int rsvp_dump(struct tcf_proto *tp, unsigned long fh, pinfo.pad = 0; NLA_PUT(skb, TCA_RSVP_PINFO, sizeof(pinfo), &pinfo); if (f->res.classid) - NLA_PUT(skb, TCA_RSVP_CLASSID, 4, &f->res.classid); + NLA_PUT_U32(skb, TCA_RSVP_CLASSID, f->res.classid); if (((f->handle>>8)&0xFF) != 16) NLA_PUT(skb, TCA_RSVP_SRC, sizeof(f->src), f->src); diff --git a/net/sched/cls_tcindex.c b/net/sched/cls_tcindex.c index cd350d38bda..7d46df7eac0 100644 --- a/net/sched/cls_tcindex.c +++ b/net/sched/cls_tcindex.c @@ -449,11 +449,10 @@ static int tcindex_dump(struct tcf_proto *tp, unsigned long fh, if (!fh) { t->tcm_handle = ~0; /* whatever ... */ - NLA_PUT(skb, TCA_TCINDEX_HASH, sizeof(p->hash), &p->hash); - NLA_PUT(skb, TCA_TCINDEX_MASK, sizeof(p->mask), &p->mask); - NLA_PUT(skb, TCA_TCINDEX_SHIFT, sizeof(p->shift), &p->shift); - NLA_PUT(skb, TCA_TCINDEX_FALL_THROUGH, sizeof(p->fall_through), - &p->fall_through); + NLA_PUT_U32(skb, TCA_TCINDEX_HASH, p->hash); + NLA_PUT_U16(skb, TCA_TCINDEX_MASK, p->mask); + NLA_PUT_U32(skb, TCA_TCINDEX_SHIFT, p->shift); + NLA_PUT_U32(skb, TCA_TCINDEX_FALL_THROUGH, p->fall_through); nla_nest_end(skb, nest); } else { if (p->perfect) { @@ -473,7 +472,7 @@ static int tcindex_dump(struct tcf_proto *tp, unsigned long fh, } pr_debug("handle = %d\n", t->tcm_handle); if (r->res.class) - NLA_PUT(skb, TCA_TCINDEX_CLASSID, 4, &r->res.classid); + NLA_PUT_U32(skb, TCA_TCINDEX_CLASSID, r->res.classid); if (tcf_exts_dump(skb, &r->exts, &tcindex_ext_map) < 0) goto nla_put_failure; diff --git a/net/sched/cls_u32.c b/net/sched/cls_u32.c index 7a1502553b3..326711eb593 100644 --- a/net/sched/cls_u32.c +++ b/net/sched/cls_u32.c @@ -708,19 +708,19 @@ static int u32_dump(struct tcf_proto *tp, unsigned long fh, if (TC_U32_KEY(n->handle) == 0) { struct tc_u_hnode *ht = (struct tc_u_hnode*)fh; u32 divisor = ht->divisor+1; - NLA_PUT(skb, TCA_U32_DIVISOR, 4, &divisor); + NLA_PUT_U32(skb, TCA_U32_DIVISOR, divisor); } else { NLA_PUT(skb, TCA_U32_SEL, sizeof(n->sel) + n->sel.nkeys*sizeof(struct tc_u32_key), &n->sel); if (n->ht_up) { u32 htid = n->handle & 0xFFFFF000; - NLA_PUT(skb, TCA_U32_HASH, 4, &htid); + NLA_PUT_U32(skb, TCA_U32_HASH, htid); } if (n->res.classid) - NLA_PUT(skb, TCA_U32_CLASSID, 4, &n->res.classid); + NLA_PUT_U32(skb, TCA_U32_CLASSID, n->res.classid); if (n->ht_down) - NLA_PUT(skb, TCA_U32_LINK, 4, &n->ht_down->handle); + NLA_PUT_U32(skb, TCA_U32_LINK, n->ht_down->handle); #ifdef CONFIG_CLS_U32_MARK if (n->mark.val || n->mark.mask) diff --git a/net/sched/em_meta.c b/net/sched/em_meta.c index dd5723670d3..63ae6a230c4 100644 --- a/net/sched/em_meta.c +++ b/net/sched/em_meta.c @@ -623,8 +623,7 @@ static int meta_int_dump(struct sk_buff *skb, struct meta_value *v, int tlv) if (v->len == sizeof(unsigned long)) NLA_PUT(skb, tlv, sizeof(unsigned long), &v->val); else if (v->len == sizeof(u32)) { - u32 d = v->val; - NLA_PUT(skb, tlv, sizeof(d), &d); + NLA_PUT_U32(skb, tlv, v->val); } return 0; diff --git a/net/sched/sch_atm.c b/net/sched/sch_atm.c index 19c00074ba1..4d876598d7d 100644 --- a/net/sched/sch_atm.c +++ b/net/sched/sch_atm.c @@ -629,14 +629,12 @@ static int atm_tc_dump_class(struct Qdisc *sch, unsigned long cl, pvc.sap_addr.vci = flow->vcc->vci; NLA_PUT(skb, TCA_ATM_ADDR, sizeof(pvc), &pvc); state = ATM_VF2VS(flow->vcc->flags); - NLA_PUT(skb, TCA_ATM_STATE, sizeof(state), &state); + NLA_PUT_U32(skb, TCA_ATM_STATE, state); } if (flow->excess) - NLA_PUT(skb, TCA_ATM_EXCESS, sizeof(u32), &flow->classid); + NLA_PUT_U32(skb, TCA_ATM_EXCESS, flow->classid); else { - static u32 zero; - - NLA_PUT(skb, TCA_ATM_EXCESS, sizeof(zero), &zero); + NLA_PUT_U32(skb, TCA_ATM_EXCESS, 0); } nla_nest_end(skb, nest); -- cgit v1.2.3-70-g09d2 From 1587bac49f8491b5006a78f8d726111b71757941 Mon Sep 17 00:00:00 2001 From: Patrick McHardy Date: Wed, 23 Jan 2008 20:35:03 -0800 Subject: [NET_SCHED]: Use typeful attribute parsing helpers Signed-off-by: Patrick McHardy Signed-off-by: David S. Miller --- net/sched/act_api.c | 2 +- net/sched/act_ipt.c | 4 ++-- net/sched/act_police.c | 5 ++--- net/sched/cls_basic.c | 2 +- net/sched/cls_fw.c | 6 +++--- net/sched/cls_route.c | 8 ++++---- net/sched/cls_rsvp.h | 4 ++-- net/sched/cls_tcindex.c | 11 +++++------ net/sched/cls_u32.c | 8 ++++---- net/sched/em_meta.c | 2 +- net/sched/sch_atm.c | 4 ++-- 11 files changed, 27 insertions(+), 29 deletions(-) (limited to 'net/sched/em_meta.c') diff --git a/net/sched/act_api.c b/net/sched/act_api.c index 41fbd496aba..0b8eb235bc1 100644 --- a/net/sched/act_api.c +++ b/net/sched/act_api.c @@ -690,7 +690,7 @@ tcf_action_get_1(struct nlattr *nla, struct nlmsghdr *n, u32 pid) if (tb[TCA_ACT_INDEX] == NULL || nla_len(tb[TCA_ACT_INDEX]) < sizeof(index)) goto err_out; - index = *(int *)nla_data(tb[TCA_ACT_INDEX]); + index = nla_get_u32(tb[TCA_ACT_INDEX]); err = -ENOMEM; a = kzalloc(sizeof(struct tc_action), GFP_KERNEL); diff --git a/net/sched/act_ipt.c b/net/sched/act_ipt.c index 5dd701a7bc5..7ab2419b44e 100644 --- a/net/sched/act_ipt.c +++ b/net/sched/act_ipt.c @@ -123,7 +123,7 @@ static int tcf_ipt_init(struct nlattr *nla, struct nlattr *est, if (tb[TCA_IPT_INDEX] != NULL && nla_len(tb[TCA_IPT_INDEX]) >= sizeof(u32)) - index = *(u32 *)nla_data(tb[TCA_IPT_INDEX]); + index = nla_get_u32(tb[TCA_IPT_INDEX]); pc = tcf_hash_check(index, a, bind, &ipt_hash_info); if (!pc) { @@ -140,7 +140,7 @@ static int tcf_ipt_init(struct nlattr *nla, struct nlattr *est, } ipt = to_ipt(pc); - hook = *(u32 *)nla_data(tb[TCA_IPT_HOOK]); + hook = nla_get_u32(tb[TCA_IPT_HOOK]); err = -ENOMEM; tname = kmalloc(IFNAMSIZ, GFP_KERNEL); diff --git a/net/sched/act_police.c b/net/sched/act_police.c index 79db6bb8a5f..62de806af3a 100644 --- a/net/sched/act_police.c +++ b/net/sched/act_police.c @@ -203,7 +203,7 @@ override: } if (tb[TCA_POLICE_RESULT]) - police->tcfp_result = *(u32*)nla_data(tb[TCA_POLICE_RESULT]); + police->tcfp_result = nla_get_u32(tb[TCA_POLICE_RESULT]); police->tcfp_toks = police->tcfp_burst = parm->burst; police->tcfp_mtu = parm->mtu; if (police->tcfp_mtu == 0) { @@ -216,8 +216,7 @@ override: police->tcf_action = parm->action; if (tb[TCA_POLICE_AVRATE]) - police->tcfp_ewma_rate = - *(u32*)nla_data(tb[TCA_POLICE_AVRATE]); + police->tcfp_ewma_rate = nla_get_u32(tb[TCA_POLICE_AVRATE]); if (est) gen_replace_estimator(&police->tcf_bstats, &police->tcf_rate_est, diff --git a/net/sched/cls_basic.c b/net/sched/cls_basic.c index 58444fedf06..0c872a76c4b 100644 --- a/net/sched/cls_basic.c +++ b/net/sched/cls_basic.c @@ -150,7 +150,7 @@ static inline int basic_set_parms(struct tcf_proto *tp, struct basic_filter *f, goto errout; if (tb[TCA_BASIC_CLASSID]) { - f->res.classid = *(u32*)nla_data(tb[TCA_BASIC_CLASSID]); + f->res.classid = nla_get_u32(tb[TCA_BASIC_CLASSID]); tcf_bind_filter(tp, &f->res, base); } diff --git a/net/sched/cls_fw.c b/net/sched/cls_fw.c index 61ebe25e5f7..b75696d67ec 100644 --- a/net/sched/cls_fw.c +++ b/net/sched/cls_fw.c @@ -203,7 +203,7 @@ fw_change_attrs(struct tcf_proto *tp, struct fw_filter *f, if (tb[TCA_FW_CLASSID]) { if (nla_len(tb[TCA_FW_CLASSID]) != sizeof(u32)) goto errout; - f->res.classid = *(u32*)nla_data(tb[TCA_FW_CLASSID]); + f->res.classid = nla_get_u32(tb[TCA_FW_CLASSID]); tcf_bind_filter(tp, &f->res, base); } @@ -218,7 +218,7 @@ fw_change_attrs(struct tcf_proto *tp, struct fw_filter *f, if (tb[TCA_FW_MASK]) { if (nla_len(tb[TCA_FW_MASK]) != sizeof(u32)) goto errout; - mask = *(u32*)nla_data(tb[TCA_FW_MASK]); + mask = nla_get_u32(tb[TCA_FW_MASK]); if (mask != head->mask) goto errout; } else if (head->mask != 0xFFFFFFFF) @@ -264,7 +264,7 @@ static int fw_change(struct tcf_proto *tp, unsigned long base, if (tb[TCA_FW_MASK]) { if (nla_len(tb[TCA_FW_MASK]) != sizeof(u32)) return -EINVAL; - mask = *(u32*)nla_data(tb[TCA_FW_MASK]); + mask = nla_get_u32(tb[TCA_FW_MASK]); } head = kzalloc(sizeof(struct fw_head), GFP_KERNEL); diff --git a/net/sched/cls_route.c b/net/sched/cls_route.c index 7752586e918..ae97238c57a 100644 --- a/net/sched/cls_route.c +++ b/net/sched/cls_route.c @@ -348,7 +348,7 @@ static int route4_set_parms(struct tcf_proto *tp, unsigned long base, goto errout; if (nla_len(tb[TCA_ROUTE4_TO]) < sizeof(u32)) goto errout; - to = *(u32*)nla_data(tb[TCA_ROUTE4_TO]); + to = nla_get_u32(tb[TCA_ROUTE4_TO]); if (to > 0xFF) goto errout; nhandle = to; @@ -359,14 +359,14 @@ static int route4_set_parms(struct tcf_proto *tp, unsigned long base, goto errout; if (nla_len(tb[TCA_ROUTE4_FROM]) < sizeof(u32)) goto errout; - id = *(u32*)nla_data(tb[TCA_ROUTE4_FROM]); + id = nla_get_u32(tb[TCA_ROUTE4_FROM]); if (id > 0xFF) goto errout; nhandle |= id << 16; } else if (tb[TCA_ROUTE4_IIF]) { if (nla_len(tb[TCA_ROUTE4_IIF]) < sizeof(u32)) goto errout; - id = *(u32*)nla_data(tb[TCA_ROUTE4_IIF]); + id = nla_get_u32(tb[TCA_ROUTE4_IIF]); if (id > 0x7FFF) goto errout; nhandle |= (id | 0x8000) << 16; @@ -411,7 +411,7 @@ static int route4_set_parms(struct tcf_proto *tp, unsigned long base, tcf_tree_unlock(tp); if (tb[TCA_ROUTE4_CLASSID]) { - f->res.classid = *(u32*)nla_data(tb[TCA_ROUTE4_CLASSID]); + f->res.classid = nla_get_u32(tb[TCA_ROUTE4_CLASSID]); tcf_bind_filter(tp, &f->res, base); } diff --git a/net/sched/cls_rsvp.h b/net/sched/cls_rsvp.h index 838a3ff5a2c..61286a0f7a3 100644 --- a/net/sched/cls_rsvp.h +++ b/net/sched/cls_rsvp.h @@ -430,7 +430,7 @@ static int rsvp_change(struct tcf_proto *tp, unsigned long base, if (f->handle != handle && handle) goto errout2; if (tb[TCA_RSVP_CLASSID-1]) { - f->res.classid = *(u32*)nla_data(tb[TCA_RSVP_CLASSID-1]); + f->res.classid = nla_get_u32(tb[TCA_RSVP_CLASSID-1]); tcf_bind_filter(tp, &f->res, base); } @@ -470,7 +470,7 @@ static int rsvp_change(struct tcf_proto *tp, unsigned long base, err = -EINVAL; if (nla_len(tb[TCA_RSVP_CLASSID-1]) != 4) goto errout; - f->res.classid = *(u32*)nla_data(tb[TCA_RSVP_CLASSID-1]); + f->res.classid = nla_get_u32(tb[TCA_RSVP_CLASSID-1]); } err = -EINVAL; diff --git a/net/sched/cls_tcindex.c b/net/sched/cls_tcindex.c index 7d46df7eac0..28098564b4d 100644 --- a/net/sched/cls_tcindex.c +++ b/net/sched/cls_tcindex.c @@ -221,19 +221,19 @@ tcindex_set_parms(struct tcf_proto *tp, unsigned long base, u32 handle, if (tb[TCA_TCINDEX_HASH]) { if (nla_len(tb[TCA_TCINDEX_HASH]) < sizeof(u32)) goto errout; - cp.hash = *(u32 *) nla_data(tb[TCA_TCINDEX_HASH]); + cp.hash = nla_get_u32(tb[TCA_TCINDEX_HASH]); } if (tb[TCA_TCINDEX_MASK]) { if (nla_len(tb[TCA_TCINDEX_MASK]) < sizeof(u16)) goto errout; - cp.mask = *(u16 *) nla_data(tb[TCA_TCINDEX_MASK]); + cp.mask = nla_get_u16(tb[TCA_TCINDEX_MASK]); } if (tb[TCA_TCINDEX_SHIFT]) { if (nla_len(tb[TCA_TCINDEX_SHIFT]) < sizeof(int)) goto errout; - cp.shift = *(int *) nla_data(tb[TCA_TCINDEX_SHIFT]); + cp.shift = nla_get_u32(tb[TCA_TCINDEX_SHIFT]); } err = -EBUSY; @@ -251,8 +251,7 @@ tcindex_set_parms(struct tcf_proto *tp, unsigned long base, u32 handle, if (tb[TCA_TCINDEX_FALL_THROUGH]) { if (nla_len(tb[TCA_TCINDEX_FALL_THROUGH]) < sizeof(u32)) goto errout; - cp.fall_through = - *(u32 *) nla_data(tb[TCA_TCINDEX_FALL_THROUGH]); + cp.fall_through = nla_get_u32(tb[TCA_TCINDEX_FALL_THROUGH]); } if (!cp.hash) { @@ -305,7 +304,7 @@ tcindex_set_parms(struct tcf_proto *tp, unsigned long base, u32 handle, } if (tb[TCA_TCINDEX_CLASSID]) { - cr.res.classid = *(u32 *) nla_data(tb[TCA_TCINDEX_CLASSID]); + cr.res.classid = nla_get_u32(tb[TCA_TCINDEX_CLASSID]); tcf_bind_filter(tp, &cr.res, base); } diff --git a/net/sched/cls_u32.c b/net/sched/cls_u32.c index 326711eb593..a4e72e8a882 100644 --- a/net/sched/cls_u32.c +++ b/net/sched/cls_u32.c @@ -474,7 +474,7 @@ static int u32_set_parms(struct tcf_proto *tp, unsigned long base, err = -EINVAL; if (tb[TCA_U32_LINK]) { - u32 handle = *(u32*)nla_data(tb[TCA_U32_LINK]); + u32 handle = nla_get_u32(tb[TCA_U32_LINK]); struct tc_u_hnode *ht_down = NULL; if (TC_U32_KEY(handle)) @@ -496,7 +496,7 @@ static int u32_set_parms(struct tcf_proto *tp, unsigned long base, ht_down->refcnt--; } if (tb[TCA_U32_CLASSID]) { - n->res.classid = *(u32*)nla_data(tb[TCA_U32_CLASSID]); + n->res.classid = nla_get_u32(tb[TCA_U32_CLASSID]); tcf_bind_filter(tp, &n->res, base); } @@ -543,7 +543,7 @@ static int u32_change(struct tcf_proto *tp, unsigned long base, u32 handle, } if (tb[TCA_U32_DIVISOR]) { - unsigned divisor = *(unsigned*)nla_data(tb[TCA_U32_DIVISOR]); + unsigned divisor = nla_get_u32(tb[TCA_U32_DIVISOR]); if (--divisor > 0x100) return -EINVAL; @@ -569,7 +569,7 @@ static int u32_change(struct tcf_proto *tp, unsigned long base, u32 handle, } if (tb[TCA_U32_HASH]) { - htid = *(unsigned*)nla_data(tb[TCA_U32_HASH]); + htid = nla_get_u32(tb[TCA_U32_HASH]); if (TC_U32_HTID(htid) == TC_U32_ROOT) { ht = tp->root; htid = ht->handle; diff --git a/net/sched/em_meta.c b/net/sched/em_meta.c index 63ae6a230c4..d9f487d813c 100644 --- a/net/sched/em_meta.c +++ b/net/sched/em_meta.c @@ -600,7 +600,7 @@ static int meta_int_change(struct meta_value *dst, struct nlattr *nla) dst->val = *(unsigned long *) nla_data(nla); dst->len = sizeof(unsigned long); } else if (nla_len(nla) == sizeof(u32)) { - dst->val = *(u32 *) nla_data(nla); + dst->val = nla_get_u32(nla); dst->len = sizeof(u32); } else return -EINVAL; diff --git a/net/sched/sch_atm.c b/net/sched/sch_atm.c index 4d876598d7d..0c71f2eb96b 100644 --- a/net/sched/sch_atm.c +++ b/net/sched/sch_atm.c @@ -231,7 +231,7 @@ static int atm_tc_change(struct Qdisc *sch, u32 classid, u32 parent, if (!tb[TCA_ATM_FD] || nla_len(tb[TCA_ATM_FD]) < sizeof(fd)) return -EINVAL; - fd = *(int *)nla_data(tb[TCA_ATM_FD]); + fd = nla_get_u32(tb[TCA_ATM_FD]); pr_debug("atm_tc_change: fd %d\n", fd); if (tb[TCA_ATM_HDR]) { hdr_len = nla_len(tb[TCA_ATM_HDR]); @@ -246,7 +246,7 @@ static int atm_tc_change(struct Qdisc *sch, u32 classid, u32 parent, if (nla_len(tb[TCA_ATM_EXCESS]) != sizeof(u32)) return -EINVAL; excess = (struct atm_flow_data *) - atm_tc_get(sch, *(u32 *)nla_data(tb[TCA_ATM_EXCESS])); + atm_tc_get(sch, nla_get_u32(tb[TCA_ATM_EXCESS])); if (!excess) return -ENOENT; } -- cgit v1.2.3-70-g09d2 From 7a9c1bd409d3522806d492aa573c1cc5384ca620 Mon Sep 17 00:00:00 2001 From: Patrick McHardy Date: Wed, 23 Jan 2008 20:36:45 -0800 Subject: [NET_SCHED]: Use nla_policy for attribute validation in ematches Signed-off-by: Patrick McHardy Signed-off-by: David S. Miller --- net/sched/em_meta.c | 9 ++++++--- net/sched/ematch.c | 11 ++++++----- 2 files changed, 12 insertions(+), 8 deletions(-) (limited to 'net/sched/em_meta.c') diff --git a/net/sched/em_meta.c b/net/sched/em_meta.c index d9f487d813c..a1e5619b187 100644 --- a/net/sched/em_meta.c +++ b/net/sched/em_meta.c @@ -745,6 +745,10 @@ static inline int meta_is_supported(struct meta_value *val) return (!meta_id(val) || meta_ops(val)->get); } +static const struct nla_policy meta_policy[TCA_EM_META_MAX + 1] = { + [TCA_EM_META_HDR] = { .len = sizeof(struct tcf_meta_hdr) }, +}; + static int em_meta_change(struct tcf_proto *tp, void *data, int len, struct tcf_ematch *m) { @@ -753,13 +757,12 @@ static int em_meta_change(struct tcf_proto *tp, void *data, int len, struct tcf_meta_hdr *hdr; struct meta_match *meta = NULL; - err = nla_parse(tb, TCA_EM_META_MAX, data, len, NULL); + err = nla_parse(tb, TCA_EM_META_MAX, data, len, meta_policy); if (err < 0) goto errout; err = -EINVAL; - if (tb[TCA_EM_META_HDR] == NULL || - nla_len(tb[TCA_EM_META_HDR]) < sizeof(*hdr)) + if (tb[TCA_EM_META_HDR] == NULL) goto errout; hdr = nla_data(tb[TCA_EM_META_HDR]); diff --git a/net/sched/ematch.c b/net/sched/ematch.c index daa9c4e7e81..74ff918455a 100644 --- a/net/sched/ematch.c +++ b/net/sched/ematch.c @@ -282,6 +282,11 @@ errout: return err; } +static const struct nla_policy em_policy[TCA_EMATCH_TREE_MAX + 1] = { + [TCA_EMATCH_TREE_HDR] = { .len = sizeof(struct tcf_ematch_tree_hdr) }, + [TCA_EMATCH_TREE_LIST] = { .type = NLA_NESTED }, +}; + /** * tcf_em_tree_validate - validate ematch config TLV and build ematch tree * @@ -312,7 +317,7 @@ int tcf_em_tree_validate(struct tcf_proto *tp, struct nlattr *nla, return 0; } - err = nla_parse_nested(tb, TCA_EMATCH_TREE_MAX, nla, NULL); + err = nla_parse_nested(tb, TCA_EMATCH_TREE_MAX, nla, em_policy); if (err < 0) goto errout; @@ -323,10 +328,6 @@ int tcf_em_tree_validate(struct tcf_proto *tp, struct nlattr *nla, if (rt_hdr == NULL || rt_list == NULL) goto errout; - if (nla_len(rt_hdr) < sizeof(*tree_hdr) || - nla_len(rt_list) < sizeof(*rt_match)) - goto errout; - tree_hdr = nla_data(rt_hdr); memcpy(&tree->hdr, tree_hdr, sizeof(*tree_hdr)); -- cgit v1.2.3-70-g09d2