arptables-save will show
-A OUTPUT --h-length 6 --h-type 1 -j MARK --set-xmark 0x1/0xffffffff
as
--h-length 6 --h-type Ethernet -j MARK MARK set 0x1

Because it uses ->print() instead of ->save().
Switch it to use ->save, we can then also drop special handling of
CLASSIFY target.

Signed-off-by: Florian Westphal <f...@strlen.de>
---
 extensions/libarpt_mangle.c |  6 +++++
 extensions/libxt_CLASSIFY.c | 47 ++++++++++---------------------------
 iptables/nft-arp.c          | 33 +++++++++++++++++++-------
 3 files changed, 43 insertions(+), 43 deletions(-)

diff --git a/extensions/libarpt_mangle.c b/extensions/libarpt_mangle.c
index 547f5b618252..2fea6185ca1b 100644
--- a/extensions/libarpt_mangle.c
+++ b/extensions/libarpt_mangle.c
@@ -175,6 +175,11 @@ arpmangle_print(const void *ip, const struct 
xt_entry_target *target,
        }
 }
 
+static void arpmangle_save(const void *ip, const struct xt_entry_target 
*target)
+{
+       arpmangle_print(ip, target, 0);
+}
+
 static struct xtables_target arpmangle_target = {
        .name           = "mangle",
        .revision       = 0,
@@ -187,6 +192,7 @@ static struct xtables_target arpmangle_target = {
        .parse          = arpmangle_parse,
        .final_check    = arpmangle_final_check,
        .print          = arpmangle_print,
+       .save           = arpmangle_save,
        .extra_opts     = arpmangle_opts,
 };
 
diff --git a/extensions/libxt_CLASSIFY.c b/extensions/libxt_CLASSIFY.c
index ba88f7584ce4..f90082dc7c50 100644
--- a/extensions/libxt_CLASSIFY.c
+++ b/extensions/libxt_CLASSIFY.c
@@ -73,13 +73,6 @@ CLASSIFY_save(const void *ip, const struct xt_entry_target 
*target)
               TC_H_MAJ(clinfo->priority)>>16, TC_H_MIN(clinfo->priority));
 }
 
-static void
-arpCLASSIFY_print(const void *ip, const struct xt_entry_target *target,
-                 int numeric)
-{
-       CLASSIFY_save(ip, target);
-}
-
 static int CLASSIFY_xlate(struct xt_xlate *xl,
                          const struct xt_xlate_tg_params *params)
 {
@@ -105,35 +98,21 @@ static int CLASSIFY_xlate(struct xt_xlate *xl,
        return 1;
 }
 
-static struct xtables_target classify_target[] = {
-       {
-               .family         = NFPROTO_UNSPEC,
-               .name           = "CLASSIFY",
-               .version        = XTABLES_VERSION,
-               .size           = XT_ALIGN(sizeof(struct 
xt_classify_target_info)),
-               .userspacesize  = XT_ALIGN(sizeof(struct 
xt_classify_target_info)),
-               .help           = CLASSIFY_help,
-               .print          = CLASSIFY_print,
-               .save           = CLASSIFY_save,
-               .x6_parse       = CLASSIFY_parse,
-               .x6_options     = CLASSIFY_opts,
-               .xlate          = CLASSIFY_xlate,
-       },
-       {
-               .family         = NFPROTO_ARP,
-               .name           = "CLASSIFY",
-               .version        = XTABLES_VERSION,
-               .size           = XT_ALIGN(sizeof(struct 
xt_classify_target_info)),
-               .userspacesize  = XT_ALIGN(sizeof(struct 
xt_classify_target_info)),
-               .help           = CLASSIFY_help,
-               .print          = arpCLASSIFY_print,
-               .x6_parse       = CLASSIFY_parse,
-               .x6_options     = CLASSIFY_opts,
-               .xlate          = CLASSIFY_xlate,
-       },
+static struct xtables_target classify_target = { 
+       .family         = NFPROTO_UNSPEC,
+       .name           = "CLASSIFY",
+       .version        = XTABLES_VERSION,
+       .size           = XT_ALIGN(sizeof(struct xt_classify_target_info)),
+       .userspacesize  = XT_ALIGN(sizeof(struct xt_classify_target_info)),
+       .help           = CLASSIFY_help,
+       .print          = CLASSIFY_print,
+       .save           = CLASSIFY_save,
+       .x6_parse       = CLASSIFY_parse,
+       .x6_options     = CLASSIFY_opts,
+       .xlate          = CLASSIFY_xlate,
 };
 
 void _init(void)
 {
-       xtables_register_targets(classify_target, ARRAY_SIZE(classify_target));
+       xtables_register_target(&classify_target);
 }
diff --git a/iptables/nft-arp.c b/iptables/nft-arp.c
index bd78a8669bb9..3d2ae3bfc056 100644
--- a/iptables/nft-arp.c
+++ b/iptables/nft-arp.c
@@ -571,17 +571,20 @@ after_devdst:
 }
 
 static void
-__nft_arp_save_rule(const void *data, unsigned int format)
+nft_arp_save_rule(const void *data, unsigned int format)
 {
        const struct iptables_command_state *cs = data;
 
+       format |= FMT_NUMERIC;
+
        nft_arp_print_rule_details(&cs->arp, format);
 
        if (cs->jumpto != NULL && strcmp(cs->jumpto, "") != 0) {
                printf("-j %s", cs->jumpto);
        } else if (cs->target) {
                printf("-j %s", cs->target->name);
-               cs->target->print(&cs->arp, cs->target->t, format & 
FMT_NUMERIC);
+               if (cs->target->save != NULL)
+                       cs->target->save(&cs->arp, cs->target->t);
        }
 
        if (!(format & FMT_NOCOUNTS)) {
@@ -595,12 +598,6 @@ __nft_arp_save_rule(const void *data, unsigned int format)
                fputc('\n', stdout);
 }
 
-static void
-nft_arp_save_rule(const void *data, unsigned int format)
-{
-       __nft_arp_save_rule(data, format | FMT_NUMERIC);
-}
-
 static void
 nft_arp_print_rule(struct nftnl_rule *r, unsigned int num, unsigned int format)
 {
@@ -610,7 +607,25 @@ nft_arp_print_rule(struct nftnl_rule *r, unsigned int num, 
unsigned int format)
                printf("%u ", num);
 
        nft_arp_rule_to_cs(r, &cs);
-       __nft_arp_save_rule(&cs, format);
+
+       nft_arp_print_rule_details(&cs.arp, format);
+
+       if (cs.jumpto != NULL && strcmp(cs.jumpto, "") != 0) {
+               printf("-j %s", cs.jumpto);
+       } else if (cs.target) {
+               printf("-j %s", cs.target->name);
+               cs.target->print(&cs.arp, cs.target->t, format & FMT_NUMERIC);
+       }
+
+       if (!(format & FMT_NOCOUNTS)) {
+               printf(", pcnt=");
+               xtables_print_num(cs.arp.counters.pcnt, format);
+               printf("-- bcnt=");
+               xtables_print_num(cs.arp.counters.bcnt, format);
+       }
+
+       if (!(format & FMT_NONEWLINE))
+               fputc('\n', stdout);
 }
 
 static bool nft_arp_is_same(const void *data_a,
-- 
2.18.1

Reply via email to