nfsd4: simplify lease/grace interaction
[safe/jmp/linux-2.6] / net / sched / cls_rsvp.h
index 5747408..dd9414e 100644 (file)
@@ -170,21 +170,23 @@ restart:
        for (s = sht[h1]; s; s = s->next) {
                if (dst[RSVP_DST_LEN-1] == s->dst[RSVP_DST_LEN-1] &&
                    protocol == s->protocol &&
-                   !(s->dpi.mask & (*(u32*)(xprt+s->dpi.offset)^s->dpi.key))
+                   !(s->dpi.mask &
+                     (*(u32*)(xprt+s->dpi.offset)^s->dpi.key)) &&
 #if RSVP_DST_LEN == 4
-                   && dst[0] == s->dst[0]
-                   && dst[1] == s->dst[1]
-                   && dst[2] == s->dst[2]
+                   dst[0] == s->dst[0] &&
+                   dst[1] == s->dst[1] &&
+                   dst[2] == s->dst[2] &&
 #endif
-                   && tunnelid == s->tunnelid) {
+                   tunnelid == s->tunnelid) {
 
                        for (f = s->ht[h2]; f; f = f->next) {
                                if (src[RSVP_DST_LEN-1] == f->src[RSVP_DST_LEN-1] &&
                                    !(f->spi.mask & (*(u32*)(xprt+f->spi.offset)^f->spi.key))
 #if RSVP_DST_LEN == 4
-                                   && src[0] == f->src[0]
-                                   && src[1] == f->src[1]
-                                   && src[2] == f->src[2]
+                                   &&
+                                   src[0] == f->src[0] &&
+                                   src[1] == f->src[1] &&
+                                   src[2] == f->src[2]
 #endif
                                    ) {
                                        *res = f->res;
@@ -397,6 +399,15 @@ static u32 gen_tunnel(struct rsvp_head *data)
        return 0;
 }
 
+static const struct nla_policy rsvp_policy[TCA_RSVP_MAX + 1] = {
+       [TCA_RSVP_CLASSID]      = { .type = NLA_U32 },
+       [TCA_RSVP_DST]          = { .type = NLA_BINARY,
+                                   .len = RSVP_DST_LEN * sizeof(u32) },
+       [TCA_RSVP_SRC]          = { .type = NLA_BINARY,
+                                   .len = RSVP_DST_LEN * sizeof(u32) },
+       [TCA_RSVP_PINFO]        = { .len = sizeof(struct tc_rsvp_pinfo) },
+};
+
 static int rsvp_change(struct tcf_proto *tp, unsigned long base,
                       u32 handle,
                       struct nlattr **tca,
@@ -416,7 +427,7 @@ static int rsvp_change(struct tcf_proto *tp, unsigned long base,
        if (opt == NULL)
                return handle ? -EINVAL : 0;
 
-       err = nla_parse_nested(tb, TCA_RSVP_MAX, opt, NULL);
+       err = nla_parse_nested(tb, TCA_RSVP_MAX, opt, rsvp_policy);
        if (err < 0)
                return err;
 
@@ -430,7 +441,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);
                }
 
@@ -452,30 +463,17 @@ static int rsvp_change(struct tcf_proto *tp, unsigned long base,
 
        h2 = 16;
        if (tb[TCA_RSVP_SRC-1]) {
-               err = -EINVAL;
-               if (nla_len(tb[TCA_RSVP_SRC-1]) != sizeof(f->src))
-                       goto errout;
                memcpy(f->src, nla_data(tb[TCA_RSVP_SRC-1]), sizeof(f->src));
                h2 = hash_src(f->src);
        }
        if (tb[TCA_RSVP_PINFO-1]) {
-               err = -EINVAL;
-               if (nla_len(tb[TCA_RSVP_PINFO-1]) < sizeof(struct tc_rsvp_pinfo))
-                       goto errout;
                pinfo = nla_data(tb[TCA_RSVP_PINFO-1]);
                f->spi = pinfo->spi;
                f->tunnelhdr = pinfo->tunnelhdr;
        }
-       if (tb[TCA_RSVP_CLASSID-1]) {
-               err = -EINVAL;
-               if (nla_len(tb[TCA_RSVP_CLASSID-1]) != 4)
-                       goto errout;
-               f->res.classid = *(u32*)nla_data(tb[TCA_RSVP_CLASSID-1]);
-       }
+       if (tb[TCA_RSVP_CLASSID-1])
+               f->res.classid = nla_get_u32(tb[TCA_RSVP_CLASSID-1]);
 
-       err = -EINVAL;
-       if (nla_len(tb[TCA_RSVP_DST-1]) != sizeof(f->src))
-               goto errout;
        dst = nla_data(tb[TCA_RSVP_DST-1]);
        h1 = hash_dst(dst, pinfo ? pinfo->protocol : 0, pinfo ? pinfo->tunnelid : 0);
 
@@ -497,13 +495,13 @@ static int rsvp_change(struct tcf_proto *tp, unsigned long base,
        for (sp = &data->ht[h1]; (s=*sp) != NULL; sp = &s->next) {
                if (dst[RSVP_DST_LEN-1] == s->dst[RSVP_DST_LEN-1] &&
                    pinfo && pinfo->protocol == s->protocol &&
-                   memcmp(&pinfo->dpi, &s->dpi, sizeof(s->dpi)) == 0
+                   memcmp(&pinfo->dpi, &s->dpi, sizeof(s->dpi)) == 0 &&
 #if RSVP_DST_LEN == 4
-                   && dst[0] == s->dst[0]
-                   && dst[1] == s->dst[1]
-                   && dst[2] == s->dst[2]
+                   dst[0] == s->dst[0] &&
+                   dst[1] == s->dst[1] &&
+                   dst[2] == s->dst[2] &&
 #endif
-                   && pinfo->tunnelid == s->tunnelid) {
+                   pinfo->tunnelid == s->tunnelid) {
 
 insert:
                        /* OK, we found appropriate session */
@@ -595,7 +593,7 @@ static int rsvp_dump(struct tcf_proto *tp, unsigned long fh,
        struct rsvp_filter *f = (struct rsvp_filter*)fh;
        struct rsvp_session *s;
        unsigned char *b = skb_tail_pointer(skb);
-       struct nlattr *nla;
+       struct nlattr *nest;
        struct tc_rsvp_pinfo pinfo;
 
        if (f == NULL)
@@ -604,9 +602,9 @@ static int rsvp_dump(struct tcf_proto *tp, unsigned long fh,
 
        t->tcm_handle = f->handle;
 
-
-       nla = (struct nlattr*)b;
-       NLA_PUT(skb, TCA_OPTIONS, 0, NULL);
+       nest = nla_nest_start(skb, TCA_OPTIONS);
+       if (nest == NULL)
+               goto nla_put_failure;
 
        NLA_PUT(skb, TCA_RSVP_DST, sizeof(s->dst), &s->dst);
        pinfo.dpi = s->dpi;
@@ -617,14 +615,14 @@ 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);
 
        if (tcf_exts_dump(skb, &f->exts, &rsvp_ext_map) < 0)
                goto nla_put_failure;
 
-       nla->nla_len = skb_tail_pointer(skb) - b;
+       nla_nest_end(skb, nest);
 
        if (tcf_exts_dump_stats(skb, &f->exts, &rsvp_ext_map) < 0)
                goto nla_put_failure;