]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
xshared: Share print_match_save() between legacy ip*tables
authorPhil Sutter <phil@nwl.cc>
Thu, 21 Oct 2021 01:00:57 +0000 (03:00 +0200)
committerPhil Sutter <phil@nwl.cc>
Thu, 16 Dec 2021 13:30:29 +0000 (14:30 +0100)
The only difference between the former two copies was the type of
ip*_entry parameter. But since it is treated opaque, just hide that
detail by casting to void.

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

index 5a64566eecd2a138989db4b1fa121c48e04aacac..0509c36c839b7941d7edf28a128bf6566c32961f 100644 (file)
@@ -644,37 +644,6 @@ list_entries(const xt_chainlabel chain, int rulenum, int verbose, int numeric,
        return found;
 }
 
-static int print_match_save(const struct xt_entry_match *e,
-                       const struct ip6t_ip6 *ip)
-{
-       const char *name = e->u.user.name;
-       const int revision = e->u.user.revision;
-       struct xtables_match *match, *mt, *mt2;
-
-       match = xtables_find_match(name, XTF_TRY_LOAD, NULL);
-       if (match) {
-               mt = mt2 = xtables_find_match_revision(name, XTF_TRY_LOAD,
-                                                      match, revision);
-               if (!mt2)
-                       mt2 = match;
-               printf(" -m %s", mt2->alias ? mt2->alias(e) : name);
-
-               /* some matches don't provide a save function */
-               if (mt && mt->save)
-                       mt->save(ip, e);
-               else if (match->save)
-                       printf(unsupported_rev);
-       } else {
-               if (e->u.match_size) {
-                       fprintf(stderr,
-                               "Can't find library for match `%s'\n",
-                               name);
-                       exit(1);
-               }
-       }
-       return 0;
-}
-
 /* We want this to be readable, so only print out necessary fields.
  * Because that's the kind of world I want to live in.
  */
index ac51c612d92f24e65dc5a36eeed103071aab4de2..a69d42387f062a0aead9528c66013af79cabb5fe 100644 (file)
@@ -642,37 +642,6 @@ list_entries(const xt_chainlabel chain, int rulenum, int verbose, int numeric,
 
 #define IP_PARTS(n) IP_PARTS_NATIVE(ntohl(n))
 
-static int print_match_save(const struct xt_entry_match *e,
-                       const struct ipt_ip *ip)
-{
-       const char *name = e->u.user.name;
-       const int revision = e->u.user.revision;
-       struct xtables_match *match, *mt, *mt2;
-
-       match = xtables_find_match(name, XTF_TRY_LOAD, NULL);
-       if (match) {
-               mt = mt2 = xtables_find_match_revision(name, XTF_TRY_LOAD,
-                                                      match, revision);
-               if (!mt2)
-                       mt2 = match;
-               printf(" -m %s", mt2->alias ? mt2->alias(e) : name);
-
-               /* some matches don't provide a save function */
-               if (mt && mt->save)
-                       mt->save(ip, e);
-               else if (match->save)
-                       printf(unsupported_rev);
-       } else {
-               if (e->u.match_size) {
-                       fprintf(stderr,
-                               "Can't find library for match `%s'\n",
-                               name);
-                       exit(1);
-               }
-       }
-       return 0;
-}
-
 /* We want this to be readable, so only print out necessary fields.
  * Because that's the kind of world I want to live in.
  */
index a1ca2b0fd7e3ef6e507d6aa7c1b755f4afd4228b..94a2d08815d92ebea7119e9806be1b8e999c59c9 100644 (file)
@@ -1119,3 +1119,33 @@ void save_rule_details(const char *iniface, unsigned const char *iniface_mask,
                printf(" -f");
        }
 }
+
+int print_match_save(const struct xt_entry_match *e, const void *ip)
+{
+       const char *name = e->u.user.name;
+       const int revision = e->u.user.revision;
+       struct xtables_match *match, *mt, *mt2;
+
+       match = xtables_find_match(name, XTF_TRY_LOAD, NULL);
+       if (match) {
+               mt = mt2 = xtables_find_match_revision(name, XTF_TRY_LOAD,
+                                                      match, revision);
+               if (!mt2)
+                       mt2 = match;
+               printf(" -m %s", mt2->alias ? mt2->alias(e) : name);
+
+               /* some matches don't provide a save function */
+               if (mt && mt->save)
+                       mt->save(ip, e);
+               else if (match->save)
+                       printf(" [unsupported revision]");
+       } else {
+               if (e->u.match_size) {
+                       fprintf(stderr,
+                               "Can't find library for match `%s'\n",
+                               name);
+                       exit(1);
+               }
+       }
+       return 0;
+}
index 060c62ef0b5caa8b2a684d5a06f5610e2dce297c..1ee64d9e4010ddf0b50e712a5beec9e5b4561ba9 100644 (file)
@@ -257,4 +257,6 @@ 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);
 
+int print_match_save(const struct xt_entry_match *e, const void *ip);
+
 #endif /* IPTABLES_XSHARED_H */