]> rtime.felk.cvut.cz Git - lisovros/iproute2_canprio.git/blobdiff - tc/em_meta.c
Convert to use rta_getattr_ functions
[lisovros/iproute2_canprio.git] / tc / em_meta.c
index bd1e15128e0e927393e2aa3d7643ab1ecf949392..fad6b1222adfb8af98eed135f54c0a3dcd3ab1de 100644 (file)
@@ -18,7 +18,6 @@
 #include <netinet/in.h>
 #include <arpa/inet.h>
 #include <string.h>
-#include <dlfcn.h>
 #include <errno.h>
 
 #include "m_ematch.h"
@@ -34,9 +33,8 @@ static void meta_print_usage(FILE *fd)
            "       META_ID := id [ shift SHIFT ] [ mask MASK ]\n" \
            "\n" \
            "Example: meta(nfmark gt 24)\n" \
-           "         meta(indev shift 1 eq \"ppp\"\n" \
+           "         meta(indev shift 1 eq \"ppp\")\n" \
            "         meta(tcindex mask 0xf0 eq 0xf0)\n" \
-           "         meta(dev eq indev)\n" \
            "\n" \
            "For a list of meta identifiers, use meta(list).\n");
 }
@@ -89,6 +87,7 @@ struct meta_entry {
                                "Routing ClassID (cls_route)"),
        __A(RTIIF,              "rt_iif",       "i",
                                "Incoming interface index"),
+       __A(VLAN_TAG,           "vlan",         "i",    "Vlan tag"),
 
        __A(SECTION,            "Sockets", "", ""),
        __A(SK_FAMILY,          "sk_family",    "i",    "Address family"),
@@ -131,7 +130,7 @@ static struct meta_entry * lookup_meta_entry(struct bstr *kind)
                if (!bstrcmp(kind, meta_table[i].kind) &&
                    meta_table[i].id != 0)
                        return &meta_table[i];
-       
+
        return NULL;
 }
 
@@ -142,7 +141,7 @@ static struct meta_entry * lookup_meta_entry_byid(int id)
        for (i = 0; i < (sizeof(meta_table)/sizeof(meta_table[0])); i++)
                if (meta_table[i].id == id)
                        return &meta_table[i];
-       
+
        return NULL;
 }
 
@@ -171,12 +170,12 @@ static inline int is_compatible(struct tcf_meta_val *what,
 {
        char *p;
        struct meta_entry *entry;
-       
+
        entry = lookup_meta_entry_byid(TCF_META_ID(what->kind));
 
        if (entry == NULL)
                return 0;
-       
+
        for (p = entry->mask; p; p++)
                if (map_type(*p) == TCF_META_TYPE(needed->kind))
                        return 1;
@@ -244,7 +243,7 @@ static inline int overwrite_type(struct tcf_meta_val *src,
 {
        return (TCF_META_TYPE(dst->kind) << 12) | TCF_META_ID(src->kind);
 }
-       
+
 
 static inline struct bstr *
 parse_object(struct bstr *args, struct bstr *arg, struct tcf_meta_val *obj,
@@ -262,7 +261,7 @@ parse_object(struct bstr *args, struct bstr *arg, struct tcf_meta_val *obj,
        }
 
        num = bstrtoul(arg);
-       if (num != LONG_MAX) {
+       if (num != ULONG_MAX) {
                obj->kind = TCF_META_TYPE_INT << 12;
                obj->kind |= TCF_META_ID_VALUE;
                *dst = (unsigned long) num;
@@ -280,7 +279,7 @@ parse_object(struct bstr *args, struct bstr *arg, struct tcf_meta_val *obj,
 
        if (left) {
                struct tcf_meta_val *right = obj;
-               
+
                if (TCF_META_TYPE(right->kind) == TCF_META_TYPE(left->kind))
                        goto compatible;
 
@@ -301,7 +300,7 @@ parse_object(struct bstr *args, struct bstr *arg, struct tcf_meta_val *obj,
                                right->kind = overwrite_type(right, left);
                        else
                                goto not_compatible;
-               } else 
+               } else
                        goto not_compatible;
        }
 
@@ -318,9 +317,9 @@ compatible:
                                return PARSE_FAILURE;
                        }
                        a = bstr_next(a);
-                       
+
                        shift = bstrtoul(a);
-                       if (shift == LONG_MAX) {
+                       if (shift == ULONG_MAX) {
                                PARSE_ERR(a, "meta: invalid shift, must " \
                                    "be numeric");
                                return PARSE_FAILURE;
@@ -336,9 +335,9 @@ compatible:
                                return PARSE_FAILURE;
                        }
                        a = bstr_next(a);
-                       
+
                        mask = bstrtoul(a);
-                       if (mask == LONG_MAX) {
+                       if (mask == ULONG_MAX) {
                                PARSE_ERR(a, "meta: invalid mask, must be " \
                                    "numeric");
                                return PARSE_FAILURE;
@@ -400,17 +399,14 @@ static int meta_parse_eopt(struct nlmsghdr *n, struct tcf_ematch_hdr *hdr,
                return -1;
        else if (a != NULL)
                return PARSE_ERR(a, "meta: unexpected trailer");
-       
+
 
        addraw_l(n, MAX_MSG, hdr, sizeof(*hdr));
 
        addattr_l(n, MAX_MSG, TCA_EM_META_HDR, &meta_hdr, sizeof(meta_hdr));
 
-       if (lvalue)
-               dump_value(n, TCA_EM_META_LVALUE, lvalue, &meta_hdr.left);
-
-       if (rvalue)
-               dump_value(n, TCA_EM_META_RVALUE, rvalue, &meta_hdr.right);
+       dump_value(n, TCA_EM_META_LVALUE, lvalue, &meta_hdr.left);
+       dump_value(n, TCA_EM_META_RVALUE, rvalue, &meta_hdr.right);
 
        return 0;
 }
@@ -452,7 +448,7 @@ static inline int print_value(FILE *fd, int type, struct rtattr *rta)
                                    "size mismatch.\n");
                                return -1;
                        }
-                       fprintf(fd, "%d", *(__u32 *) RTA_DATA(rta));
+                       fprintf(fd, "%d", rta_getattr_u32(rta));
                        break;
 
                case TCF_META_TYPE_VAR:
@@ -489,7 +485,7 @@ static int print_object(FILE *fd, struct tcf_meta_val *obj, struct rtattr *rta)
                                        goto size_mismatch;
 
                                fprintf(fd, " mask 0x%08x",
-                                   *(__u32*) RTA_DATA(rta));
+                                   rta_getattr_u32(rta));
                        }
                        break;
        }