diff options
author | Phil Sutter <phil@nwl.cc> | 2021-11-05 18:50:21 +0100 |
---|---|---|
committer | Phil Sutter <phil@nwl.cc> | 2021-11-23 15:01:23 +0100 |
commit | e5fb9f8efaa0643a566d079c8201082822a0dc81 (patch) | |
tree | 69e09ca9df14c500c707499badcb3058708752b8 /iptables/iptables.c | |
parent | 22f2e1fca127b014dccf1006544e3179c9dc9764 (diff) |
xshared: Share save_ipv{4,6}_addr() with legacy
While being at it, make save_ipv4_addr() accept an in_addr* as mask -
mask_to_str() needs it anyway.
Signed-off-by: Phil Sutter <phil@nwl.cc>
Diffstat (limited to 'iptables/iptables.c')
-rw-r--r-- | iptables/iptables.c | 36 |
1 files changed, 3 insertions, 33 deletions
diff --git a/iptables/iptables.c b/iptables/iptables.c index 85fb7bdc..0d8beb04 100644 --- a/iptables/iptables.c +++ b/iptables/iptables.c @@ -738,36 +738,6 @@ static int print_match_save(const struct xt_entry_match *e, return 0; } -/* Print a given ip including mask if necessary. */ -static void print_ip(const char *prefix, uint32_t ip, - uint32_t mask, int invert) -{ - uint32_t bits, hmask = ntohl(mask); - int i; - - if (!mask && !ip && !invert) - return; - - printf("%s %s %u.%u.%u.%u", - invert ? " !" : "", - prefix, - IP_PARTS(ip)); - - if (mask == 0xFFFFFFFFU) { - printf("/32"); - return; - } - - i = 32; - bits = 0xFFFFFFFEU; - while (--i >= 0 && hmask != bits) - bits <<= 1; - if (i >= 0) - printf("/%u", i); - else - printf("/%u.%u.%u.%u", IP_PARTS(mask)); -} - /* We want this to be readable, so only print out necessary fields. * Because that's the kind of world I want to live in. */ @@ -785,10 +755,10 @@ void print_rule4(const struct ipt_entry *e, printf("-A %s", chain); /* Print IP part. */ - print_ip("-s", e->ip.src.s_addr,e->ip.smsk.s_addr, - e->ip.invflags & IPT_INV_SRCIP); + save_ipv4_addr('s', &e->ip.src, &e->ip.smsk, + e->ip.invflags & IPT_INV_SRCIP); - print_ip("-d", e->ip.dst.s_addr, e->ip.dmsk.s_addr, + save_ipv4_addr('d', &e->ip.dst, &e->ip.dmsk, e->ip.invflags & IPT_INV_DSTIP); save_rule_details(e->ip.iniface, e->ip.iniface_mask, |