]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
nft: Change whitespace printing in save_rule callback
authorPhil Sutter <phil@nwl.cc>
Fri, 5 Nov 2021 16:45:48 +0000 (17:45 +0100)
committerPhil Sutter <phil@nwl.cc>
Tue, 23 Nov 2021 14:01:23 +0000 (15:01 +0100)
This aligns whitespace printing with legacy iptables' print_rule4() in
order to prepare for further code-sharing.

Signed-off-by: Phil Sutter <phil@nwl.cc>
iptables/nft-arp.c
iptables/nft-bridge.c
iptables/nft-ipv4.c
iptables/nft-ipv6.c
iptables/nft-shared.c
iptables/nft.c

index 32eb91add4f1e2c88a2594fdcd886c68c96732c3..b7536e61a255fad343185a7107a55f6f9999921a 100644 (file)
@@ -479,6 +479,7 @@ nft_arp_save_rule(const void *data, unsigned int format)
 
        format |= FMT_NUMERIC;
 
+       printf(" ");
        nft_arp_print_rule_details(cs, format);
        if (cs->target && cs->target->save)
                cs->target->save(&cs->fw, cs->target->t);
index 11f3df3582aa5a013a7d719919a001e9619482bf..cc2a48dbf7741453c272992d2a62d83c7df6e029 100644 (file)
@@ -601,7 +601,7 @@ static void print_protocol(uint16_t ethproto, bool invert, unsigned int bitmask)
                printf("%s ", ent->e_name);
 }
 
-static void nft_bridge_save_rule(const void *data, unsigned int format)
+static void __nft_bridge_save_rule(const void *data, unsigned int format)
 {
        const struct iptables_command_state *cs = data;
 
@@ -652,6 +652,12 @@ static void nft_bridge_save_rule(const void *data, unsigned int format)
                fputc('\n', stdout);
 }
 
+static void nft_bridge_save_rule(const void *data, unsigned int format)
+{
+       printf(" ");
+       __nft_bridge_save_rule(data, format);
+}
+
 static void nft_bridge_print_rule(struct nft_handle *h, struct nftnl_rule *r,
                                  unsigned int num, unsigned int format)
 {
@@ -661,7 +667,7 @@ static void nft_bridge_print_rule(struct nft_handle *h, struct nftnl_rule *r,
                printf("%d ", num);
 
        nft_rule_to_ebtables_command_state(h, r, &cs);
-       nft_bridge_save_rule(&cs, format);
+       __nft_bridge_save_rule(&cs, format);
        ebt_cs_clean(&cs);
 }
 
index febd7673af4f82e25fb506ca7d3b1f8f5fe0ff3d..287112d0e6b993f8d22190d0bf4b17a91690a29e 100644 (file)
@@ -303,7 +303,7 @@ static void save_ipv4_addr(char letter, const struct in_addr *addr,
        if (!mask && !invert && !addr->s_addr)
                return;
 
-       printf("%s-%c %s/%s ", invert ? "! " : "", letter,
+       printf("%s -%c %s/%s", invert ? " !" : "", letter,
               inet_ntop(AF_INET, addr, addrbuf, sizeof(addrbuf)),
               mask_to_str(mask));
 }
@@ -323,8 +323,8 @@ static void nft_ipv4_save_rule(const void *data, unsigned int format)
 
        if (cs->fw.ip.flags & IPT_F_FRAG) {
                if (cs->fw.ip.invflags & IPT_INV_FRAG)
-                       printf("");
-               printf("-f ");
+                       printf(" !");
+               printf(" -f");
        }
 
        save_matches_and_target(cs, cs->fw.ip.flags & IPT_F_GOTO,
index f0e64bbd4ab231a9dad3d639e8455a803279f540..845937b180b068c8921f118a11f55e28f09f7ef5 100644 (file)
@@ -234,14 +234,14 @@ static void save_ipv6_addr(char letter, const struct in6_addr *addr,
        if (!invert && l == 0)
                return;
 
-       printf("%s-%c %s",
-               invert ? "" : "", letter,
+       printf("%s -%c %s",
+               invert ? " !" : "", letter,
                inet_ntop(AF_INET6, addr, addr_str, sizeof(addr_str)));
 
        if (l == -1)
-               printf("/%s ", inet_ntop(AF_INET6, mask, addr_str, sizeof(addr_str)));
+               printf("/%s", inet_ntop(AF_INET6, mask, addr_str, sizeof(addr_str)));
        else
-               printf("/%d ", l);
+               printf("/%d", l);
 }
 
 static void nft_ipv6_save_rule(const void *data, unsigned int format)
index 72727270026eebdc08480c6c484a6aa5dcbe50e5..082cc0e2df7454a5057f0736e9d4e0a3d48e5cba 100644 (file)
@@ -793,7 +793,7 @@ print_iface(char letter, const char *iface, const unsigned char *mask, int inv)
        if (mask[0] == 0)
                return;
 
-       printf("%s-%c ", inv ? "! " : "", letter);
+       printf("%s -%c ", inv ? " !" : "", letter);
 
        for (i = 0; i < IFNAMSIZ; i++) {
                if (mask[i] != 0) {
@@ -805,8 +805,6 @@ print_iface(char letter, const char *iface, const unsigned char *mask, int inv)
                                break;
                }
        }
-
-       printf(" ");
 }
 
 void save_rule_details(const struct iptables_command_state *cs,
@@ -829,12 +827,12 @@ void save_rule_details(const struct iptables_command_state *cs,
                const char *pname = proto_to_name(proto, 0);
 
                if (invflags & XT_INV_PROTO)
-                       printf("");
+                       printf(" !");
 
                if (pname)
-                       printf("-p %s ", pname);
+                       printf(" -p %s", pname);
                else
-                       printf("-p %u ", proto);
+                       printf(" -p %u", proto);
        }
 }
 
@@ -856,33 +854,33 @@ void save_matches_and_target(const struct iptables_command_state *cs,
 
        for (matchp = cs->matches; matchp; matchp = matchp->next) {
                if (matchp->match->alias) {
-                       printf("-m %s",
+                       printf(" -m %s",
                               matchp->match->alias(matchp->match->m));
                } else
-                       printf("-m %s", matchp->match->name);
+                       printf(" -m %s", matchp->match->name);
 
                if (matchp->match->save != NULL) {
                        /* cs->fw union makes the trick */
                        matchp->match->save(fw, matchp->match->m);
                }
-               printf(" ");
        }
 
        if ((format & (FMT_NOCOUNTS | FMT_C_COUNTS)) == FMT_C_COUNTS)
-               printf("-c %llu %llu ",
+               printf(" -c %llu %llu",
                       (unsigned long long)cs->counters.pcnt,
                       (unsigned long long)cs->counters.bcnt);
 
        if (cs->target != NULL) {
                if (cs->target->alias) {
-                       printf("-j %s", cs->target->alias(cs->target->t));
+                       printf(" -j %s", cs->target->alias(cs->target->t));
                } else
-                       printf("-j %s", cs->jumpto);
+                       printf(" -j %s", cs->jumpto);
 
-               if (cs->target->save != NULL)
+               if (cs->target->save != NULL) {
                        cs->target->save(fw, cs->target->t);
+               }
        } else if (strlen(cs->jumpto) > 0) {
-               printf("-%c %s", goto_flag ? 'g' : 'j', cs->jumpto);
+               printf(" -%c %s", goto_flag ? 'g' : 'j', cs->jumpto);
        }
 
        printf("\n");
index 1d3f3a3da1cbbedd899a9ed9ccb361f153ecfcdc..282d417f3bc85341b1a01a5546fb301fa5da05cb 100644 (file)
@@ -1513,10 +1513,10 @@ nft_rule_print_save(struct nft_handle *h, const struct nftnl_rule *r,
        /* print chain name */
        switch(type) {
        case NFT_RULE_APPEND:
-               printf("-A %s ", chain);
+               printf("-A %s", chain);
                break;
        case NFT_RULE_DEL:
-               printf("-D %s ", chain);
+               printf("-D %s", chain);
                break;
        }