string: factorize skip_spaces and export it to be generally available
[safe/jmp/linux-2.6] / net / sched / cls_fw.c
index 5dbb9d4..6d6e875 100644 (file)
  */
 
 #include <linux/module.h>
-#include <asm/uaccess.h>
-#include <asm/system.h>
-#include <linux/bitops.h>
 #include <linux/types.h>
 #include <linux/kernel.h>
 #include <linux/string.h>
-#include <linux/mm.h>
-#include <linux/socket.h>
-#include <linux/sockios.h>
-#include <linux/in.h>
 #include <linux/errno.h>
-#include <linux/interrupt.h>
-#include <linux/if_ether.h>
-#include <linux/inet.h>
-#include <linux/netdevice.h>
-#include <linux/etherdevice.h>
-#include <linux/notifier.h>
-#include <linux/netfilter.h>
-#include <net/ip.h>
-#include <net/route.h>
 #include <linux/skbuff.h>
-#include <net/sock.h>
+#include <net/netlink.h>
 #include <net/act_api.h>
 #include <net/pkt_cls.h>
 
@@ -63,7 +47,7 @@ struct fw_filter
        struct tcf_exts         exts;
 };
 
-static struct tcf_ext_map fw_ext_map = {
+static const struct tcf_ext_map fw_ext_map = {
        .action = TCA_FW_ACT,
        .police = TCA_FW_POLICE
 };
@@ -164,7 +148,7 @@ fw_delete_filter(struct tcf_proto *tp, struct fw_filter *f)
 
 static void fw_destroy(struct tcf_proto *tp)
 {
-       struct fw_head *head = (struct fw_head*)xchg(&tp->root, NULL);
+       struct fw_head *head = tp->root;
        struct fw_filter *f;
        int h;
 
@@ -202,39 +186,41 @@ out:
        return -EINVAL;
 }
 
+static const struct nla_policy fw_policy[TCA_FW_MAX + 1] = {
+       [TCA_FW_CLASSID]        = { .type = NLA_U32 },
+       [TCA_FW_INDEV]          = { .type = NLA_STRING, .len = IFNAMSIZ },
+       [TCA_FW_MASK]           = { .type = NLA_U32 },
+};
+
 static int
 fw_change_attrs(struct tcf_proto *tp, struct fw_filter *f,
-       struct rtattr **tb, struct rtattr **tca, unsigned long base)
+       struct nlattr **tb, struct nlattr **tca, unsigned long base)
 {
        struct fw_head *head = (struct fw_head *)tp->root;
        struct tcf_exts e;
        u32 mask;
        int err;
 
-       err = tcf_exts_validate(tp, tb, tca[TCA_RATE-1], &e, &fw_ext_map);
+       err = tcf_exts_validate(tp, tb, tca[TCA_RATE], &e, &fw_ext_map);
        if (err < 0)
                return err;
 
        err = -EINVAL;
-       if (tb[TCA_FW_CLASSID-1]) {
-               if (RTA_PAYLOAD(tb[TCA_FW_CLASSID-1]) != sizeof(u32))
-                       goto errout;
-               f->res.classid = *(u32*)RTA_DATA(tb[TCA_FW_CLASSID-1]);
+       if (tb[TCA_FW_CLASSID]) {
+               f->res.classid = nla_get_u32(tb[TCA_FW_CLASSID]);
                tcf_bind_filter(tp, &f->res, base);
        }
 
 #ifdef CONFIG_NET_CLS_IND
-       if (tb[TCA_FW_INDEV-1]) {
-               err = tcf_change_indev(tp, f->indev, tb[TCA_FW_INDEV-1]);
+       if (tb[TCA_FW_INDEV]) {
+               err = tcf_change_indev(tp, f->indev, tb[TCA_FW_INDEV]);
                if (err < 0)
                        goto errout;
        }
 #endif /* CONFIG_NET_CLS_IND */
 
-       if (tb[TCA_FW_MASK-1]) {
-               if (RTA_PAYLOAD(tb[TCA_FW_MASK-1]) != sizeof(u32))
-                       goto errout;
-               mask = *(u32*)RTA_DATA(tb[TCA_FW_MASK-1]);
+       if (tb[TCA_FW_MASK]) {
+               mask = nla_get_u32(tb[TCA_FW_MASK]);
                if (mask != head->mask)
                        goto errout;
        } else if (head->mask != 0xFFFFFFFF)
@@ -250,20 +236,21 @@ errout:
 
 static int fw_change(struct tcf_proto *tp, unsigned long base,
                     u32 handle,
-                    struct rtattr **tca,
+                    struct nlattr **tca,
                     unsigned long *arg)
 {
        struct fw_head *head = (struct fw_head*)tp->root;
        struct fw_filter *f = (struct fw_filter *) *arg;
-       struct rtattr *opt = tca[TCA_OPTIONS-1];
-       struct rtattr *tb[TCA_FW_MAX];
+       struct nlattr *opt = tca[TCA_OPTIONS];
+       struct nlattr *tb[TCA_FW_MAX + 1];
        int err;
 
        if (!opt)
                return handle ? -EINVAL : 0;
 
-       if (rtattr_parse_nested(tb, TCA_FW_MAX, opt) < 0)
-               return -EINVAL;
+       err = nla_parse_nested(tb, TCA_FW_MAX, opt, fw_policy);
+       if (err < 0)
+               return err;
 
        if (f != NULL) {
                if (f->id != handle && handle)
@@ -276,11 +263,8 @@ static int fw_change(struct tcf_proto *tp, unsigned long base,
 
        if (head == NULL) {
                u32 mask = 0xFFFFFFFF;
-               if (tb[TCA_FW_MASK-1]) {
-                       if (RTA_PAYLOAD(tb[TCA_FW_MASK-1]) != sizeof(u32))
-                               return -EINVAL;
-                       mask = *(u32*)RTA_DATA(tb[TCA_FW_MASK-1]);
-               }
+               if (tb[TCA_FW_MASK])
+                       mask = nla_get_u32(tb[TCA_FW_MASK]);
 
                head = kzalloc(sizeof(struct fw_head), GFP_KERNEL);
                if (head == NULL)
@@ -348,8 +332,8 @@ static int fw_dump(struct tcf_proto *tp, unsigned long fh,
 {
        struct fw_head *head = (struct fw_head *)tp->root;
        struct fw_filter *f = (struct fw_filter*)fh;
-       unsigned char    *b = skb->tail;
-       struct rtattr *rta;
+       unsigned char *b = skb_tail_pointer(skb);
+       struct nlattr *nest;
 
        if (f == NULL)
                return skb->len;
@@ -359,35 +343,35 @@ static int fw_dump(struct tcf_proto *tp, unsigned long fh,
        if (!f->res.classid && !tcf_exts_is_available(&f->exts))
                return skb->len;
 
-       rta = (struct rtattr*)b;
-       RTA_PUT(skb, TCA_OPTIONS, 0, NULL);
+       nest = nla_nest_start(skb, TCA_OPTIONS);
+       if (nest == NULL)
+               goto nla_put_failure;
 
        if (f->res.classid)
-               RTA_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))
-               RTA_PUT(skb, TCA_FW_INDEV, IFNAMSIZ, f->indev);
+               NLA_PUT_STRING(skb, TCA_FW_INDEV, f->indev);
 #endif /* CONFIG_NET_CLS_IND */
        if (head->mask != 0xFFFFFFFF)
-               RTA_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 rtattr_failure;
+               goto nla_put_failure;
 
-       rta->rta_len = skb->tail - b;
+       nla_nest_end(skb, nest);
 
        if (tcf_exts_dump_stats(skb, &f->exts, &fw_ext_map) < 0)
-               goto rtattr_failure;
+               goto nla_put_failure;
 
        return skb->len;
 
-rtattr_failure:
-       skb_trim(skb, b - skb->data);
+nla_put_failure:
+       nlmsg_trim(skb, b);
        return -1;
 }
 
-static struct tcf_proto_ops cls_fw_ops = {
-       .next           =       NULL,
+static struct tcf_proto_ops cls_fw_ops __read_mostly = {
        .kind           =       "fw",
        .classify       =       fw_classify,
        .init           =       fw_init,