]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
xshared: Share print_rule_details() with legacy
authorPhil Sutter <phil@nwl.cc>
Fri, 5 Nov 2021 21:02:45 +0000 (22:02 +0100)
committerPhil Sutter <phil@nwl.cc>
Tue, 23 Nov 2021 14:01:23 +0000 (15:01 +0100)
Have to pass pointer to counters directly since different fields are
being used for some reason.

Since proto_to_name() is not used outside of xshared.c anymore, make it
static.

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

index 5c118626a5d23f6b7a69667b38b524a95ab7aa02..e0cc4e898fe6a22a5ccb18c72d60cdff1647fa17 100644 (file)
@@ -329,25 +329,8 @@ print_firewall(const struct ip6t_entry *fw,
 
        t = ip6t_get_target((struct ip6t_entry *)fw);
 
-       if (format & FMT_LINENUMBERS)
-               printf(FMT("%-4u ", "%u "), num);
-
-       if (!(format & FMT_NOCOUNTS)) {
-               xtables_print_num(fw->counters.pcnt, format);
-               xtables_print_num(fw->counters.bcnt, format);
-       }
-
-       if (!(format & FMT_NOTARGET))
-               printf(FMT("%-9s ", "%s "), targname);
-
-       fputc(fw->ipv6.invflags & XT_INV_PROTO ? '!' : ' ', stdout);
-       {
-               const char *pname = proto_to_name(fw->ipv6.proto, format&FMT_NUMERIC);
-               if (pname)
-                       printf(FMT("%-5s", "%s "), pname);
-               else
-                       printf(FMT("%-5hu", "%hu "), fw->ipv6.proto);
-       }
+       print_rule_details(num, &fw->counters, targname, fw->ipv6.proto,
+                          fw->ipv6.flags, fw->ipv6.invflags, format);
 
        if (format & FMT_OPTIONS) {
                if (format & FMT_NOTABLE)
index 0d8beb04c0f997fa8ef7d4fdd4d995e592210872..29da40b1328d418940e9ded28691385e85d514b4 100644 (file)
@@ -322,25 +322,8 @@ print_firewall(const struct ipt_entry *fw,
        t = ipt_get_target((struct ipt_entry *)fw);
        flags = fw->ip.flags;
 
-       if (format & FMT_LINENUMBERS)
-               printf(FMT("%-4u ", "%u "), num);
-
-       if (!(format & FMT_NOCOUNTS)) {
-               xtables_print_num(fw->counters.pcnt, format);
-               xtables_print_num(fw->counters.bcnt, format);
-       }
-
-       if (!(format & FMT_NOTARGET))
-               printf(FMT("%-9s ", "%s "), targname);
-
-       fputc(fw->ip.invflags & XT_INV_PROTO ? '!' : ' ', stdout);
-       {
-               const char *pname = proto_to_name(fw->ip.proto, format&FMT_NUMERIC);
-               if (pname)
-                       printf(FMT("%-5s", "%s "), pname);
-               else
-                       printf(FMT("%-5hu", "%hu "), fw->ip.proto);
-       }
+       print_rule_details(num, &fw->counters, targname, fw->ip.proto,
+                          fw->ip.flags, fw->ip.invflags, format);
 
        if (format & FMT_OPTIONS) {
                if (format & FMT_NOTABLE)
index dcc009cf67a81a5fabd4258db65c258f72d5f269..6b044642bd775054017ad36a5633096da28496a3 100644 (file)
@@ -246,8 +246,8 @@ static void nft_ipv4_print_rule(struct nft_handle *h, struct nftnl_rule *r,
 
        nft_rule_to_iptables_command_state(h, r, &cs);
 
-       print_rule_details(&cs, cs.jumpto, cs.fw.ip.flags,
-                          cs.fw.ip.invflags, cs.fw.ip.proto, num, format);
+       print_rule_details(num, &cs.counters, cs.jumpto, cs.fw.ip.proto,
+                          cs.fw.ip.flags, cs.fw.ip.invflags, format);
        print_fragment(cs.fw.ip.flags, cs.fw.ip.invflags, format);
        print_ifaces(cs.fw.ip.iniface, cs.fw.ip.outiface, cs.fw.ip.invflags,
                     format);
index 0b35e0457a067fc8d43af74bdf7eb6d041aea9a6..cb83f9e132e2425bb5889ee00975f601a9fe17c4 100644 (file)
@@ -198,9 +198,8 @@ static void nft_ipv6_print_rule(struct nft_handle *h, struct nftnl_rule *r,
 
        nft_rule_to_iptables_command_state(h, r, &cs);
 
-       print_rule_details(&cs, cs.jumpto, cs.fw6.ipv6.flags,
-                          cs.fw6.ipv6.invflags, cs.fw6.ipv6.proto,
-                          num, format);
+       print_rule_details(num, &cs.counters, cs.jumpto, cs.fw6.ipv6.proto,
+                          cs.fw6.ipv6.flags, cs.fw6.ipv6.invflags, format);
        if (format & FMT_OPTIONS) {
                if (format & FMT_NOTABLE)
                        fputs("opt ", stdout);
index 168c224627fd0c6a78a681bffe728247c4c19b49..eb0070075d9eb8e7e54f9fb129884db3ea4454ac 100644 (file)
@@ -758,33 +758,6 @@ void print_header(unsigned int format, const char *chain, const char *pol,
        printf("\n");
 }
 
-void print_rule_details(const struct iptables_command_state *cs,
-                       const char *targname, uint8_t flags,
-                       uint8_t invflags, uint8_t proto,
-                       unsigned int num, unsigned int format)
-{
-       if (format & FMT_LINENUMBERS)
-               printf(FMT("%-4u ", "%u "), num);
-
-       if (!(format & FMT_NOCOUNTS)) {
-               xtables_print_num(cs->counters.pcnt, format);
-               xtables_print_num(cs->counters.bcnt, format);
-       }
-
-       if (!(format & FMT_NOTARGET))
-               printf(FMT("%-9s ", "%s "), targname ? targname : "");
-
-       fputc(invflags & XT_INV_PROTO ? '!' : ' ', stdout);
-       {
-               const char *pname =
-                       proto_to_name(proto, format&FMT_NUMERIC);
-               if (pname)
-                       printf(FMT("%-5s", "%s "), pname);
-               else
-                       printf(FMT("%-5hu", "%hu "), proto);
-       }
-}
-
 void nft_ipv46_save_chain(const struct nftnl_chain *c, const char *policy)
 {
        const char *chain = nftnl_chain_get_str(c, NFTNL_CHAIN_NAME);
index cac5757ff0708e8fd775102c791029b211db24a3..e18df20d9fc380869d60bb792cd26649a337b39b 100644 (file)
@@ -167,10 +167,6 @@ void nft_clear_iptables_command_state(struct iptables_command_state *cs);
 void print_header(unsigned int format, const char *chain, const char *pol,
                  const struct xt_counters *counters, bool basechain,
                  uint32_t refs, uint32_t entries);
-void print_rule_details(const struct iptables_command_state *cs,
-                       const char *targname, uint8_t flags,
-                       uint8_t invflags, uint8_t proto,
-                       unsigned int num, unsigned int format);
 void print_matches_and_target(struct iptables_command_state *cs,
                              unsigned int format);
 void nft_ipv46_save_chain(const struct nftnl_chain *c, const char *policy);
index 3e06960fcf015ac723642cfed3cb7c775340d54d..7f2e1a32914b0c810c149c5838d618e096d5feea 100644 (file)
@@ -48,7 +48,7 @@ void print_extension_helps(const struct xtables_target *t,
        }
 }
 
-const char *
+static const char *
 proto_to_name(uint16_t proto, int nolookup)
 {
        unsigned int i;
@@ -999,6 +999,31 @@ void parse_chain(const char *chainname)
                                      "Invalid chain name `%s'", chainname);
 }
 
+void print_rule_details(unsigned int linenum, const struct xt_counters *ctrs,
+                       const char *targname, uint8_t proto, uint8_t flags,
+                       uint8_t invflags, unsigned int format)
+{
+       const char *pname = proto_to_name(proto, format&FMT_NUMERIC);
+
+       if (format & FMT_LINENUMBERS)
+               printf(FMT("%-4u ", "%u "), linenum);
+
+       if (!(format & FMT_NOCOUNTS)) {
+               xtables_print_num(ctrs->pcnt, format);
+               xtables_print_num(ctrs->bcnt, format);
+       }
+
+       if (!(format & FMT_NOTARGET))
+               printf(FMT("%-9s ", "%s "), targname ? targname : "");
+
+       fputc(invflags & XT_INV_PROTO ? '!' : ' ', stdout);
+
+       if (pname)
+               printf(FMT("%-5s", "%s "), pname);
+       else
+               printf(FMT("%-5hu", "%hu "), proto);
+}
+
 void save_rule_details(const char *iniface, unsigned const char *iniface_mask,
                       const char *outiface, unsigned const char *outiface_mask,
                       uint16_t proto, int frag, uint8_t invflags)
index 46ad5a2962c711bd1837a5fe5f0cfea0966c2e38..9f0fa1438bdd39492e0d049988b2f00474f54846 100644 (file)
@@ -164,7 +164,6 @@ enum {
 
 extern void print_extension_helps(const struct xtables_target *,
        const struct xtables_rule_match *);
-extern const char *proto_to_name(uint16_t, int);
 extern int command_default(struct iptables_command_state *,
        struct xtables_globals *, bool invert);
 extern struct xtables_match *load_proto(struct iptables_command_state *);
@@ -246,6 +245,9 @@ void parse_chain(const char *chainname);
 void generic_opt_check(int command, int options);
 char opt2char(int option);
 
+void print_rule_details(unsigned int linenum, const struct xt_counters *ctrs,
+                       const char *targname, uint8_t proto, uint8_t flags,
+                       uint8_t invflags, unsigned int format);
 void save_rule_details(const char *iniface, unsigned const char *iniface_mask,
                       const char *outiface, unsigned const char *outiface_mask,
                       uint16_t proto, int frag, uint8_t invflags);