]> git.proxmox.com Git - mirror_iproute2.git/blobdiff - tc/m_connmark.c
Replace open-coded instances of print_nl()
[mirror_iproute2.git] / tc / m_connmark.c
index 143d75de66b8b01b02cd0cf68787dcec7054a566..4b2dc4e25ef8fad3dab9b68c82afbdb584871f0d 100644 (file)
 static void
 explain(void)
 {
-       fprintf(stderr, "Usage: ... connmark [zone ZONE] [CONTROL] [index <INDEX>]\n");
-       fprintf(stderr, "where :\n"
+       fprintf(stderr,
+               "Usage: ... connmark [zone ZONE] [CONTROL] [index <INDEX>]\n"
+               "where :\n"
                "\tZONE is the conntrack zone\n"
-               "\tCONTROL := reclassify|pipe|drop|continue|ok\n");
+               "\tCONTROL := reclassify | pipe | drop | continue | ok |\n"
+               "\t           goto chain <CHAIN_INDEX>\n");
 }
 
 static void
@@ -72,7 +74,7 @@ parse_connmark(struct action_util *a, int *argc_p, char ***argv_p, int tca_id,
                if (matches(*argv, "zone") == 0) {
                        NEXT_ARG();
                        if (get_u16(&sel.zone, *argv, 10)) {
-                               fprintf(stderr, "simple: Illegal \"index\"\n");
+                               fprintf(stderr, "connmark: Illegal \"zone\"\n");
                                return -1;
                        }
                        argc--;
@@ -80,38 +82,13 @@ parse_connmark(struct action_util *a, int *argc_p, char ***argv_p, int tca_id,
                }
        }
 
-       sel.action = TC_ACT_PIPE;
-       if (argc) {
-               if (matches(*argv, "reclassify") == 0) {
-                       sel.action = TC_ACT_RECLASSIFY;
-                       argc--;
-                       argv++;
-               } else if (matches(*argv, "pipe") == 0) {
-                       sel.action = TC_ACT_PIPE;
-                       argc--;
-                       argv++;
-               } else if (matches(*argv, "drop") == 0 ||
-                          matches(*argv, "shot") == 0) {
-                       sel.action = TC_ACT_SHOT;
-                       argc--;
-                       argv++;
-               } else if (matches(*argv, "continue") == 0) {
-                       sel.action = TC_ACT_UNSPEC;
-                       argc--;
-                       argv++;
-               } else if (matches(*argv, "pass") == 0 ||
-                          matches(*argv, "ok") == 0) {
-                       sel.action = TC_ACT_OK;
-                       argc--;
-                       argv++;
-               }
-       }
+       parse_action_control_dflt(&argc, &argv, &sel.action, false, TC_ACT_PIPE);
 
        if (argc) {
                if (matches(*argv, "index") == 0) {
                        NEXT_ARG();
                        if (get_u32(&sel.index, *argv, 10)) {
-                               fprintf(stderr, "simple: Illegal \"index\"\n");
+                               fprintf(stderr, "connmark: Illegal \"index\"\n");
                                return -1;
                        }
                        argc--;
@@ -119,10 +96,9 @@ parse_connmark(struct action_util *a, int *argc_p, char ***argv_p, int tca_id,
                }
        }
 
-       tail = NLMSG_TAIL(n);
-       addattr_l(n, MAX_MSG, tca_id, NULL, 0);
+       tail = addattr_nest(n, MAX_MSG, tca_id);
        addattr_l(n, MAX_MSG, TCA_CONNMARK_PARMS, &sel, sizeof(sel));
-       tail->rta_len = (char *)NLMSG_TAIL(n) - (char *)tail;
+       addattr_nest_end(n, tail);
 
        *argc_p = argc;
        *argv_p = argv;
@@ -139,15 +115,20 @@ static int print_connmark(struct action_util *au, FILE *f, struct rtattr *arg)
 
        parse_rtattr_nested(tb, TCA_CONNMARK_MAX, arg);
        if (tb[TCA_CONNMARK_PARMS] == NULL) {
-               fprintf(f, "[NULL connmark parameters]");
+               fprintf(stderr, "Missing connmark parameters\n");
                return -1;
        }
 
        ci = RTA_DATA(tb[TCA_CONNMARK_PARMS]);
 
-       fprintf(f, " connmark zone %d\n", ci->zone);
-       fprintf(f, "\t index %d ref %d bind %d", ci->index,
-               ci->refcnt, ci->bindcnt);
+       print_string(PRINT_ANY, "kind", "%s ", "connmark");
+       print_uint(PRINT_ANY, "zone", "zone %u", ci->zone);
+       print_action_control(f, " ", ci->action, "");
+
+       print_nl();
+       print_uint(PRINT_ANY, "index", "\t index %u", ci->index);
+       print_int(PRINT_ANY, "ref", " ref %d", ci->refcnt);
+       print_int(PRINT_ANY, "bind", " bind %d", ci->bindcnt);
 
        if (show_stats) {
                if (tb[TCA_CONNMARK_TM]) {
@@ -156,7 +137,7 @@ static int print_connmark(struct action_util *au, FILE *f, struct rtattr *arg)
                        print_tm(f, tm);
                }
        }
-       fprintf(f, "\n");
+       print_nl();
 
        return 0;
 }