]> git.proxmox.com Git - mirror_iproute2.git/blobdiff - tc/f_rsvp.c
f_u32: fix compiler gcc-10 compiler warning
[mirror_iproute2.git] / tc / f_rsvp.c
index 13fcf9790680a49739821f3919a610b4cac3f1d6..388e9ee59ad39e266e3f02375a658453b4082306 100644 (file)
@@ -13,7 +13,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
-#include <syslog.h>
 #include <fcntl.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
 
 static void explain(void)
 {
-       fprintf(stderr, "Usage: ... rsvp ipproto PROTOCOL session DST[/PORT | GPI ]\n");
-       fprintf(stderr, "                [ sender SRC[/PORT | GPI ]\n");
-       fprintf(stderr, "                [ classid CLASSID ] [ police POLICE_SPEC ]\n");
-       fprintf(stderr, "                [ tunnelid ID ] [ tunnel ID skip NUMBER ]\n");
-       fprintf(stderr, "Where: GPI := { flowlabel NUMBER | spi/ah SPI | spi/esp SPI |\n");
-       fprintf(stderr, "                u{8|16|32} NUMBER mask MASK at OFFSET}\n");
-       fprintf(stderr, "       POLICE_SPEC := ... look at TBF\n");
-       fprintf(stderr, "       FILTERID := X:Y\n");
+       fprintf(stderr,
+               "Usage: ... rsvp ipproto PROTOCOL session DST[/PORT | GPI ]\n"
+               "               [ sender SRC[/PORT | GPI ] ]\n"
+               "               [ classid CLASSID ] [ action ACTION_SPEC ]\n"
+               "               [ tunnelid ID ] [ tunnel ID skip NUMBER ]\n"
+               "Where: GPI := { flowlabel NUMBER | spi/ah SPI | spi/esp SPI |\n"
+               "               u{8|16|32} NUMBER mask MASK at OFFSET}\n"
+               "       ACTION_SPEC := ... look at individual actions\n"
+               "       FILTERID := X:Y\n"
+               "\nNOTE: CLASSID is parsed as hexadecimal input.\n");
 }
 
-#define usage() return(-1)
-
-int get_addr_and_pi(int *argc_p, char ***argv_p, inet_prefix * addr,
+static int get_addr_and_pi(int *argc_p, char ***argv_p, inet_prefix *addr,
                    struct tc_rsvp_pinfo *pinfo, int dir, int family)
 {
        int argc = *argc_p;
@@ -77,6 +76,7 @@ int get_addr_and_pi(int *argc_p, char ***argv_p, inet_prefix * addr,
        if (strcmp(*argv, "spi/ah") == 0 ||
            strcmp(*argv, "gpi/ah") == 0) {
                __u32 gpi;
+
                NEXT_ARG();
                if (get_u32(&gpi, *argv, 0))
                        return -1;
@@ -89,6 +89,7 @@ int get_addr_and_pi(int *argc_p, char ***argv_p, inet_prefix * addr,
        } else if (strcmp(*argv, "spi/esp") == 0 ||
                   strcmp(*argv, "gpi/esp") == 0) {
                __u32 gpi;
+
                NEXT_ARG();
                if (get_u32(&gpi, *argv, 0))
                        return -1;
@@ -100,6 +101,7 @@ int get_addr_and_pi(int *argc_p, char ***argv_p, inet_prefix * addr,
                argc--; argv++;
        } else if (strcmp(*argv, "flowlabel") == 0) {
                __u32 flabel;
+
                NEXT_ARG();
                if (get_u32(&flabel, *argv, 0))
                        return -1;
@@ -115,6 +117,7 @@ int get_addr_and_pi(int *argc_p, char ***argv_p, inet_prefix * addr,
                int sz = 1;
                __u32 tmp;
                __u32 mask = 0xff;
+
                if (strcmp(*argv, "u32") == 0) {
                        sz = 4;
                        mask = 0xffff;
@@ -167,18 +170,15 @@ done:
 }
 
 
-static int rsvp_parse_opt(struct filter_util *qu, char *handle, int argc, char **argv, struct nlmsghdr *n)
+static int rsvp_parse_opt(struct filter_util *qu, char *handle, int argc,
+                         char **argv, struct nlmsghdr *n)
 {
        int family = strcmp(qu->id, "rsvp") == 0 ? AF_INET : AF_INET6;
-       struct tc_rsvp_pinfo pinfo;
-       struct tc_police tp;
+       struct tc_rsvp_pinfo pinfo = {};
        struct tcmsg *t = NLMSG_DATA(n);
        int pinfo_ok = 0;
        struct rtattr *tail;
 
-       memset(&pinfo, 0, sizeof(pinfo));
-       memset(&tp, 0, sizeof(tp));
-
        if (handle) {
                if (get_u32(&t->tcm_handle, handle, 0)) {
                        fprintf(stderr, "Illegal \"handle\"\n");
@@ -189,12 +189,12 @@ static int rsvp_parse_opt(struct filter_util *qu, char *handle, int argc, char *
        if (argc == 0)
                return 0;
 
-       tail = NLMSG_TAIL(n);
-       addattr_l(n, 4096, TCA_OPTIONS, NULL, 0);
+       tail = addattr_nest(n, 4096, TCA_OPTIONS);
 
        while (argc > 0) {
                if (matches(*argv, "session") == 0) {
                        inet_prefix addr;
+
                        NEXT_ARG();
                        if (get_addr_and_pi(&argc, &argv, &addr, &pinfo, 1, family)) {
                                fprintf(stderr, "Illegal \"session\"\n");
@@ -207,6 +207,7 @@ static int rsvp_parse_opt(struct filter_util *qu, char *handle, int argc, char *
                } else if (matches(*argv, "sender") == 0 ||
                           matches(*argv, "flowspec") == 0) {
                        inet_prefix addr;
+
                        NEXT_ARG();
                        if (get_addr_and_pi(&argc, &argv, &addr, &pinfo, 0, family)) {
                                fprintf(stderr, "Illegal \"sender\"\n");
@@ -218,6 +219,7 @@ static int rsvp_parse_opt(struct filter_util *qu, char *handle, int argc, char *
                        continue;
                } else if (matches("ipproto", *argv) == 0) {
                        int num;
+
                        NEXT_ARG();
                        num = inet_proto_a2n(*argv);
                        if (num < 0) {
@@ -228,7 +230,8 @@ static int rsvp_parse_opt(struct filter_util *qu, char *handle, int argc, char *
                        pinfo_ok++;
                } else if (matches(*argv, "classid") == 0 ||
                           strcmp(*argv, "flowid") == 0) {
-                       unsigned handle;
+                       unsigned int handle;
+
                        NEXT_ARG();
                        if (get_tc_classid(&handle, *argv)) {
                                fprintf(stderr, "Illegal \"classid\"\n");
@@ -236,7 +239,8 @@ static int rsvp_parse_opt(struct filter_util *qu, char *handle, int argc, char *
                        }
                        addattr_l(n, 4096, TCA_RSVP_CLASSID, &handle, 4);
                } else if (strcmp(*argv, "tunnelid") == 0) {
-                       unsigned tid;
+                       unsigned int tid;
+
                        NEXT_ARG();
                        if (get_unsigned(&tid, *argv, 0)) {
                                fprintf(stderr, "Illegal \"tunnelid\"\n");
@@ -245,7 +249,8 @@ static int rsvp_parse_opt(struct filter_util *qu, char *handle, int argc, char *
                        pinfo.tunnelid = tid;
                        pinfo_ok++;
                } else if (strcmp(*argv, "tunnel") == 0) {
-                       unsigned tid;
+                       unsigned int tid;
+
                        NEXT_ARG();
                        if (get_unsigned(&tid, *argv, 0)) {
                                fprintf(stderr, "Illegal \"tunnel\"\n");
@@ -262,6 +267,13 @@ static int rsvp_parse_opt(struct filter_util *qu, char *handle, int argc, char *
                        }
                        pinfo.tunnelhdr = tid;
                        pinfo_ok++;
+               } else if (matches(*argv, "action") == 0) {
+                       NEXT_ARG();
+                       if (parse_action(&argc, &argv, TCA_RSVP_ACT, n)) {
+                               fprintf(stderr, "Illegal \"action\"\n");
+                               return -1;
+                       }
+                       continue;
                } else if (matches(*argv, "police") == 0) {
                        NEXT_ARG();
                        if (parse_police(&argc, &argv, TCA_RSVP_POLICE, n)) {
@@ -282,11 +294,11 @@ static int rsvp_parse_opt(struct filter_util *qu, char *handle, int argc, char *
 
        if (pinfo_ok)
                addattr_l(n, 4096, TCA_RSVP_PINFO, &pinfo, sizeof(pinfo));
-       tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
+       addattr_nest_end(n, tail);
        return 0;
 }
 
-static char * sprint_spi(struct tc_rsvp_gpi *pi, int dir, char *buf)
+static char *sprint_spi(struct tc_rsvp_gpi *pi, int dir, char *buf)
 {
        if (pi->offset == 0) {
                if (dir && pi->mask == htonl(0xFFFF)) {
@@ -337,14 +349,15 @@ static int rsvp_print_opt(struct filter_util *qu, FILE *f, struct rtattr *opt, _
        if (tb[TCA_RSVP_CLASSID]) {
                SPRINT_BUF(b1);
                if (!pinfo || pinfo->tunnelhdr == 0)
-                       fprintf(f, "flowid %s ", sprint_tc_classid(*(__u32*)RTA_DATA(tb[TCA_RSVP_CLASSID]), b1));
+                       fprintf(f, "flowid %s ", sprint_tc_classid(rta_getattr_u32(tb[TCA_RSVP_CLASSID]), b1));
                else
-                       fprintf(f, "tunnel %d skip %d ", *(__u32*)RTA_DATA(tb[TCA_RSVP_CLASSID]), pinfo->tunnelhdr);
+                       fprintf(f, "tunnel %d skip %d ", rta_getattr_u32(tb[TCA_RSVP_CLASSID]), pinfo->tunnelhdr);
        } else if (pinfo && pinfo->tunnelhdr)
                fprintf(f, "tunnel [BAD] skip %d ", pinfo->tunnelhdr);
 
        if (tb[TCA_RSVP_DST]) {
                char buf[128];
+
                fprintf(f, "session ");
                if (inet_ntop(family, RTA_DATA(tb[TCA_RSVP_DST]), buf, sizeof(buf)) == 0)
                        fprintf(f, " [INVALID DADDR] ");
@@ -371,6 +384,7 @@ static int rsvp_print_opt(struct filter_util *qu, FILE *f, struct rtattr *opt, _
                fprintf(f, "tunnelid %d ", pinfo->tunnelid);
        if (tb[TCA_RSVP_SRC]) {
                char buf[128];
+
                fprintf(f, "sender ");
                if (inet_ntop(family, RTA_DATA(tb[TCA_RSVP_SRC]), buf, sizeof(buf)) == 0) {
                        fprintf(f, "[BAD]");
@@ -386,6 +400,10 @@ static int rsvp_print_opt(struct filter_util *qu, FILE *f, struct rtattr *opt, _
                SPRINT_BUF(b2);
                fprintf(f, "sender [NONE]%s ", sprint_spi(&pinfo->spi, 0, b2));
        }
+
+       if (tb[TCA_RSVP_ACT]) {
+               tc_print_action(f, tb[TCA_RSVP_ACT], 0);
+       }
        if (tb[TCA_RSVP_POLICE])
                tc_print_police(f, tb[TCA_RSVP_POLICE]);
        return 0;