]> git.proxmox.com Git - mirror_iproute2.git/blobdiff - tc/em_meta.c
tc: Remove pointless assignments in batch()
[mirror_iproute2.git] / tc / em_meta.c
index df39eb1bd51827374aaafc8855a796b5c02a0e04..d94fe88d9b2f67edcb15983324bc06f8ac78a582 100644 (file)
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
-#include <syslog.h>
 #include <fcntl.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
 #include <string.h>
-#include <dlfcn.h>
 #include <errno.h>
 
 #include "m_ematch.h"
@@ -33,19 +31,18 @@ static void meta_print_usage(FILE *fd)
            "where: OBJECT  := { META_ID | VALUE }\n" \
            "       META_ID := id [ shift SHIFT ] [ mask MASK ]\n" \
            "\n" \
-           "Example: meta(nfmark gt 24)\n" \
-           "         meta(indev shift 1 eq \"ppp\"\n" \
+           "Example: meta(nf_mark gt 24)\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");
 }
 
 struct meta_entry {
        int             id;
-       char *          kind;
-       char *          mask;
-       char *          desc;
+       char *kind;
+       char *mask;
+       char *desc;
 } meta_table[] = {
 #define TCF_META_ID_SECTION 0
 #define __A(id, name, mask, desc) { TCF_META_ID_##id, name, mask, desc }
@@ -104,7 +101,7 @@ struct meta_entry {
        __A(SK_RMEM_ALLOC,      "sk_rmem",      "i",    "RMEM"),
        __A(SK_WMEM_ALLOC,      "sk_wmem",      "i",    "WMEM"),
        __A(SK_OMEM_ALLOC,      "sk_omem",      "i",    "OMEM"),
-       __A(SK_WMEM_QUEUED,     "sk_wmem_queue","i",    "WMEM queue"),
+       __A(SK_WMEM_QUEUED,     "sk_wmem_queue", "i",   "WMEM queue"),
        __A(SK_SND_QLEN,        "sk_snd_queue", "i",    "Send queue length"),
        __A(SK_RCV_QLEN,        "sk_rcv_queue", "i",    "Receive queue length"),
        __A(SK_ERR_QLEN,        "sk_err_queue", "i",    "Error queue length"),
@@ -124,11 +121,11 @@ static inline int map_type(char k)
        return INT_MAX;
 }
 
-static struct meta_entry * lookup_meta_entry(struct bstr *kind)
+static struct meta_entry *lookup_meta_entry(struct bstr *kind)
 {
        int i;
 
-       for (i = 0; i < (sizeof(meta_table)/sizeof(meta_table[0])); i++)
+       for (i = 0; i < ARRAY_SIZE(meta_table); i++)
                if (!bstrcmp(kind, meta_table[i].kind) &&
                    meta_table[i].id != 0)
                        return &meta_table[i];
@@ -136,11 +133,11 @@ static struct meta_entry * lookup_meta_entry(struct bstr *kind)
        return NULL;
 }
 
-static struct meta_entry * lookup_meta_entry_byid(int id)
+static struct meta_entry *lookup_meta_entry_byid(int id)
 {
        int i;
 
-       for (i = 0; i < (sizeof(meta_table)/sizeof(meta_table[0])); i++)
+       for (i = 0; i < ARRAY_SIZE(meta_table); i++)
                if (meta_table[i].id == id)
                        return &meta_table[i];
 
@@ -161,6 +158,7 @@ static inline void dump_value(struct nlmsghdr *n, int tlv, unsigned long val,
                case TCF_META_TYPE_VAR:
                        if (TCF_META_ID(hdr->kind) == TCF_META_ID_VALUE) {
                                struct bstr *a = (struct bstr *) val;
+
                                addattr_l(n, MAX_MSG, tlv, a->data, a->len);
                        }
                        break;
@@ -194,7 +192,7 @@ static void list_meta_ids(FILE *fd)
            "  ID               Type       Description\n" \
            "--------------------------------------------------------");
 
-       for (i = 0; i < (sizeof(meta_table)/sizeof(meta_table[0])); i++) {
+       for (i = 0; i < ARRAY_SIZE(meta_table); i++) {
                if (meta_table[i].id == TCF_META_ID_SECTION) {
                        fprintf(fd, "\n%s:\n", meta_table[i].kind);
                } else {
@@ -233,7 +231,7 @@ static void list_meta_ids(FILE *fd)
 #define PARSE_FAILURE ((void *) (-1))
 
 #define PARSE_ERR(CARG, FMT, ARGS...) \
-       em_parse_error(EINVAL, args, CARG, &meta_ematch_util, FMT ,##ARGS)
+       em_parse_error(EINVAL, args, CARG, &meta_ematch_util, FMT##ARGS)
 
 static inline int can_adopt(struct tcf_meta_val *val)
 {
@@ -263,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;
@@ -310,7 +308,7 @@ compatible:
 
        a = bstr_next(arg);
 
-       while(a) {
+       while (a) {
                if (!bstrcmp(a, "shift")) {
                        unsigned long shift;
 
@@ -321,7 +319,7 @@ compatible:
                        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;
@@ -339,7 +337,7 @@ compatible:
                        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;
@@ -362,11 +360,9 @@ static int meta_parse_eopt(struct nlmsghdr *n, struct tcf_ematch_hdr *hdr,
 {
        int opnd;
        struct bstr *a;
-       struct tcf_meta_hdr meta_hdr;
+       struct tcf_meta_hdr meta_hdr = {};
        unsigned long lvalue = 0, rvalue = 0;
 
-       memset(&meta_hdr, 0, sizeof(meta_hdr));
-
        if (args == NULL)
                return PARSE_ERR(args, "meta: missing arguments");
 
@@ -443,14 +439,14 @@ static inline int print_value(FILE *fd, int type, struct rtattr *rta)
                return -1;
        }
 
-       switch(type) {
+       switch (type) {
                case TCF_META_TYPE_INT:
                        if (RTA_PAYLOAD(rta) < sizeof(__u32)) {
                                fprintf(stderr, "meta int type value TLV " \
                                    "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:
@@ -486,8 +482,9 @@ static int print_object(FILE *fd, struct tcf_meta_val *obj, struct rtattr *rta)
                                if (RTA_PAYLOAD(rta) < sizeof(__u32))
                                        goto size_mismatch;
 
-                               fprintf(fd, " mask 0x%08x",
-                                   *(__u32*) RTA_DATA(rta));
+                               if (rta_getattr_u32(rta))
+                                       fprintf(fd, " mask 0x%08x",
+                                               rta_getattr_u32(rta));
                        }
                        break;
        }