]> git.proxmox.com Git - mirror_iproute2.git/blobdiff - tc/m_sample.c
Merge branch 'main' into next
[mirror_iproute2.git] / tc / m_sample.c
index fe892adcac89ada853c8cd6568b8b87c94c79de0..696d76095ae6d0df9e016ea518381379f0c5debf 100644 (file)
 
 static void explain(void)
 {
-       fprintf(stderr, "Usage: sample SAMPLE_CONF\n");
-       fprintf(stderr, "where:\n");
-       fprintf(stderr, "\tSAMPLE_CONF := SAMPLE_PARAMS | SAMPLE_INDEX\n");
-       fprintf(stderr, "\tSAMPLE_PARAMS := rate RATE group GROUP [trunc SIZE] [SAMPLE_INDEX]\n");
-       fprintf(stderr, "\tSAMPLE_INDEX := index INDEX\n");
-       fprintf(stderr, "\tRATE := The ratio of packets observed at the data source to the samples generated.\n");
-       fprintf(stderr, "\tGROUP := the psample sampling group\n");
-       fprintf(stderr, "\tSIZE := the truncation size\n");
-       fprintf(stderr, "\tINDEX := integer index of the sample action\n");
+       fprintf(stderr,
+               "Usage: sample SAMPLE_CONF\n"
+               "where:\n"
+               "\tSAMPLE_CONF := SAMPLE_PARAMS | SAMPLE_INDEX\n"
+               "\tSAMPLE_PARAMS := rate RATE group GROUP [trunc SIZE] [SAMPLE_INDEX]\n"
+               "\tSAMPLE_INDEX := index INDEX\n"
+               "\tRATE := The ratio of packets observed at the data source to the samples generated.\n"
+               "\tGROUP := the psample sampling group\n"
+               "\tSIZE := the truncation size\n"
+               "\tINDEX := integer index of the sample action\n");
 }
 
 static void usage(void)
@@ -65,7 +66,7 @@ static int parse_sample(struct action_util *a, int *argc_p, char ***argv_p,
        while (argc > 0) {
                if (matches(*argv, "rate") == 0) {
                        NEXT_ARG();
-                       if (get_unsigned(&rate, *argv, 10) != 0) {
+                       if (get_u32(&rate, *argv, 10) != 0) {
                                fprintf(stderr, "Illegal rate %s\n", *argv);
                                usage();
                                return -1;
@@ -73,7 +74,7 @@ static int parse_sample(struct action_util *a, int *argc_p, char ***argv_p,
                        rate_set = true;
                } else if (matches(*argv, "group") == 0) {
                        NEXT_ARG();
-                       if (get_unsigned(&group, *argv, 10) != 0) {
+                       if (get_u32(&group, *argv, 10) != 0) {
                                fprintf(stderr, "Illegal group num %s\n",
                                        *argv);
                                usage();
@@ -82,7 +83,7 @@ static int parse_sample(struct action_util *a, int *argc_p, char ***argv_p,
                        group_set = true;
                } else if (matches(*argv, "trunc") == 0) {
                        NEXT_ARG();
-                       if (get_unsigned(&trunc, *argv, 10) != 0) {
+                       if (get_u32(&trunc, *argv, 10) != 0) {
                                fprintf(stderr, "Illegal truncation size %s\n",
                                        *argv);
                                usage();
@@ -100,7 +101,6 @@ static int parse_sample(struct action_util *a, int *argc_p, char ***argv_p,
 
        parse_action_control_dflt(&argc, &argv, &p.action, false, TC_ACT_PIPE);
 
-       NEXT_ARG_FWD();
        if (argc) {
                if (matches(*argv, "index") == 0) {
                        NEXT_ARG();
@@ -143,28 +143,34 @@ static int print_sample(struct action_util *au, FILE *f, struct rtattr *arg)
        struct rtattr *tb[TCA_SAMPLE_MAX + 1];
        struct tc_sample *p;
 
+       print_string(PRINT_ANY, "kind", "%s ", "sample");
        if (arg == NULL)
-               return -1;
+               return 0;
 
        parse_rtattr_nested(tb, TCA_SAMPLE_MAX, arg);
 
        if (!tb[TCA_SAMPLE_PARMS] || !tb[TCA_SAMPLE_RATE] ||
            !tb[TCA_SAMPLE_PSAMPLE_GROUP]) {
-               fprintf(f, "[NULL sample parameters]");
+               fprintf(stderr, "Missing sample parameters\n");
                return -1;
        }
        p = RTA_DATA(tb[TCA_SAMPLE_PARMS]);
 
-       fprintf(f, "sample rate 1/%d group %d",
-               rta_getattr_u32(tb[TCA_SAMPLE_RATE]),
-               rta_getattr_u32(tb[TCA_SAMPLE_PSAMPLE_GROUP]));
+       print_uint(PRINT_ANY, "rate", "rate 1/%u ",
+                  rta_getattr_u32(tb[TCA_SAMPLE_RATE]));
+       print_uint(PRINT_ANY, "group", "group %u",
+                  rta_getattr_u32(tb[TCA_SAMPLE_PSAMPLE_GROUP]));
 
        if (tb[TCA_SAMPLE_TRUNC_SIZE])
-               fprintf(f, " trunc_size %d",
-                       rta_getattr_u32(tb[TCA_SAMPLE_TRUNC_SIZE]));
+               print_uint(PRINT_ANY, "trunc_size", " trunc_size %u",
+                          rta_getattr_u32(tb[TCA_SAMPLE_TRUNC_SIZE]));
+
+       print_action_control(f, " ", p->action, "");
 
-       fprintf(f, "\n\tindex %d ref %d bind %d", p->index, p->refcnt,
-               p->bindcnt);
+       print_nl();
+       print_uint(PRINT_ANY, "index", "\t index %u", p->index);
+       print_int(PRINT_ANY, "ref", " ref %d", p->refcnt);
+       print_int(PRINT_ANY, "bind", " bind %d", p->bindcnt);
 
        if (show_stats) {
                if (tb[TCA_SAMPLE_TM]) {
@@ -173,7 +179,7 @@ static int print_sample(struct action_util *au, FILE *f, struct rtattr *arg)
                        print_tm(f, tm);
                }
        }
-       fprintf(f, "\n");
+       print_nl();
        return 0;
 }