From 3d33da3dbb05354b5b3c39abdfdd967b5e5ca2d1 Mon Sep 17 00:00:00 2001 From: Bart De Schuymer Date: Sat, 3 May 2003 20:28:22 +0000 Subject: use print_mac_and_mask() --- userspace/ebtables2/ebtables.c | 57 ++++++++++++++++++++------------ userspace/ebtables2/extensions/ebt_arp.c | 29 ++-------------- userspace/ebtables2/include/ebtables_u.h | 2 ++ 3 files changed, 40 insertions(+), 48 deletions(-) diff --git a/userspace/ebtables2/ebtables.c b/userspace/ebtables2/ebtables.c index 21a9a47..29bccfe 100644 --- a/userspace/ebtables2/ebtables.c +++ b/userspace/ebtables2/ebtables.c @@ -79,6 +79,7 @@ static struct option ebt_original_options[] = { "Lc" , no_argument , 0, 4 }, { "Ln" , no_argument , 0, 5 }, { "Lx" , no_argument , 0, 6 }, + { "Lmac2" , no_argument , 0, 12 }, { "zero" , optional_argument, 0, 'Z' }, { "flush" , optional_argument, 0, 'F' }, { "policy" , required_argument, 0, 'P' }, @@ -465,9 +466,33 @@ static void list_extensions() * we use replace.flags, so we can't use the following values: * 0x01 == OPT_COMMAND, 0x02 == OPT_TABLE, 0x100 == OPT_ZERO */ -#define LIST_N 0x04 -#define LIST_C 0x08 -#define LIST_X 0x10 +#define LIST_N 0x04 +#define LIST_C 0x08 +#define LIST_X 0x10 +#define LIST_MAC2 0x20 + +void print_mac(const char *mac) +{ + if (replace.flags & LIST_MAC2) { + int j; + for (j = 0; j < ETH_ALEN; j++) + printf("%02x%s", (unsigned char)mac[j], + (j==ETH_ALEN-1) ? "" : ":"); + } else + printf("%s", ether_ntoa((struct ether_addr *) mac)); +} + +void print_mac_and_mask(const char *mac, const char *mask) +{ + char hlpmsk[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; + + print_mac(mac); + if (memcmp(mask, hlpmsk, 6)) { + printf("/"); + print_mac(mask); + } +} + /* * helper function for list_rules() */ @@ -535,8 +560,6 @@ static void list_em(struct ebt_u_entries *entries) } } if (hlp->bitmask & EBT_SOURCEMAC) { - char hlpmsk[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; - printf("-s "); if (hlp->invflags & EBT_ISOURCE) printf("! "); @@ -555,19 +578,11 @@ static void list_em(struct ebt_u_entries *entries) printf("Broadcast"); goto endsrc; } - printf("%s", ether_ntoa((struct ether_addr *) - hlp->sourcemac)); - if (memcmp(hlp->sourcemsk, hlpmsk, 6)) { - printf("/"); - printf("%s", ether_ntoa((struct ether_addr *) - hlp->sourcemsk)); - } + print_mac_and_mask(hlp->sourcemac, hlp->sourcemsk); endsrc: printf(" "); } if (hlp->bitmask & EBT_DESTMAC) { - char hlpmsk[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; - printf("-d "); if (hlp->invflags & EBT_IDEST) printf("! "); @@ -586,13 +601,7 @@ endsrc: printf("Broadcast"); goto enddst; } - printf("%s", ether_ntoa((struct ether_addr *) - hlp->destmac)); - if (memcmp(hlp->destmsk, hlpmsk, 6)) { - printf("/"); - printf("%s", ether_ntoa((struct ether_addr *) - hlp->destmsk)); - } + print_mac_and_mask(hlp->destmac, hlp->destmsk); enddst: printf(" "); } @@ -2118,6 +2127,12 @@ int main(int argc, char *argv[]) print_error("--Lx not compatible with --Ln"); replace.flags |= LIST_X; break; + case 12 : /* Lmac2 */ + check_option(&replace.flags, LIST_MAC2); + if (replace.command != 'L') + print_error("Use --Lmac2 with -L"); + replace.flags |= LIST_MAC2; + break; case 8 : /* atomic-commit */ replace.command = c; if (replace.flags & OPT_COMMAND) diff --git a/userspace/ebtables2/extensions/ebt_arp.c b/userspace/ebtables2/extensions/ebt_arp.c index 4df650b..13cbc7b 100644 --- a/userspace/ebtables2/extensions/ebt_arp.c +++ b/userspace/ebtables2/extensions/ebt_arp.c @@ -284,41 +284,16 @@ static void print(const struct ebt_u_entry *entry, printf("%s ", mask_to_dotted(arpinfo->dmsk)); } if (arpinfo->bitmask & EBT_ARP_SRC_MAC) { - int verdict; printf("--arp-mac-src "); if (arpinfo->invflags & EBT_ARP_SRC_MAC) printf("! "); - for (i = 0; i < 6; i++) - printf("%x%s", ((unsigned char *)&arpinfo->smaddr)[i], - (i == 5) ? "" : ":"); - verdict = 0; - for (i = 0; i < 6; i++) - verdict = (arpinfo->smmsk[i] ^ 0xFF); - if (verdict != 0) { - printf("%s", "/"); - for (i = 0; i < 6; i++) - printf("%x%s", ((unsigned char *)&arpinfo->smmsk)[i], - (i == 5) ? "" : ":"); - printf("%s", " "); - } + print_mac_and_mask(arpinfo->smaddr, arpinfo->smmsk); } if (arpinfo->bitmask & EBT_ARP_DST_MAC) { - int verdict; printf("--arp-mac-dst "); if (arpinfo->invflags & EBT_ARP_DST_MAC) printf("! "); - for (i = 0; i < 6; i++) - printf("%x%s", ((unsigned char *)&arpinfo->dmaddr)[i], - (i == 5) ? "" : ":"); - verdict = 0; - for (i = 0; i < 6; i++) - verdict = (arpinfo->dmmsk[i] ^ 0xFF); - if (verdict != 0) { - printf("%s", "/"); - for (i = 0; i < 6; i++) - printf("%x%s", ((unsigned char *)&arpinfo->dmmsk)[i], - (i == 5) ? "" : ":"); - } + print_mac_and_mask(arpinfo->dmaddr, arpinfo->dmmsk); } } diff --git a/userspace/ebtables2/include/ebtables_u.h b/userspace/ebtables2/include/ebtables_u.h index 3fb9a5c..741b00d 100644 --- a/userspace/ebtables2/include/ebtables_u.h +++ b/userspace/ebtables2/include/ebtables_u.h @@ -208,6 +208,8 @@ void deliver_counters(struct ebt_u_replace *repl); void deliver_table(struct ebt_u_replace *repl); void check_option(unsigned int *flags, unsigned int mask); int check_inverse(const char option[]); +void print_mac(const char *mac); +void print_mac_and_mask(const char *mac, const char *mask); void __print_bug(char *file, int line, char *format, ...); #define print_bug(format, args...) \ __print_bug(__FILE__, __LINE__, format, ##args) -- cgit v1.2.3