From: Mitesh Kanjariya Date: Wed, 12 Jul 2017 21:27:24 +0000 (-0700) Subject: lib: changes needed for mac access-list any command X-Git-Tag: frr-4.0-dev~431^2~9 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=69b61704b8c125b34d3b8efe8fb6d1477c895eef;p=mirror%2Ffrr.git lib: changes needed for mac access-list any command Ticket: CM-17074 Review: CCR-6453 Unit-test: Manual Signed-off-by: Mitesh Kanjariya --- diff --git a/lib/filter.c b/lib/filter.c index 186b32bbba..c01ee4ee10 100644 --- a/lib/filter.c +++ b/lib/filter.c @@ -169,6 +169,10 @@ static int mac_filter_match(struct prefix *n, struct ethaddr *p) if (!n || !p) return 0; + /* check if we are matching on any mac */ + if (is_zero_mac(&(n->u.prefix_eth))) + return 1; + if (memcmp(&(n->u.prefix), p, sizeof(struct ethaddr)) == 0) return 1; @@ -1398,7 +1402,7 @@ DEFUN (no_mac_access_list_any, "Specify packets to forward\n" "MAC address to match. e.g. 00:01:00:01:00:01\n") { - return filter_set_zebra(vty, argv[2]->arg, argv[3]->arg, AFI_L2VPN, + return filter_set_zebra(vty, argv[3]->arg, argv[4]->arg, AFI_L2VPN, "00:00:00:00:00:00", 0, 0); } @@ -1994,9 +1998,13 @@ void config_write_access_zebra(struct vty *vty, struct filter *mfilter) vty_out(vty, " %s/%d%s", inet_ntop(p->family, &p->u.prefix, buf, BUFSIZ), p->prefixlen, filter->exact ? " exact-match" : ""); - else - vty_out(vty, " %s", - prefix_mac2str(&(p->u.prefix_eth), buf, sizeof(buf))); + else if (p->family == AF_ETHERNET) { + if (is_zero_mac(&(p->u.prefix_eth))) + vty_out(vty, " any"); + else + vty_out(vty, " %s", prefix_mac2str(&(p->u.prefix_eth), + buf, sizeof(buf))); + } vty_out(vty, "\n"); } diff --git a/lib/prefix.c b/lib/prefix.c index e67184f52b..edfc22fb42 100644 --- a/lib/prefix.c +++ b/lib/prefix.c @@ -301,6 +301,18 @@ static const struct in6_addr maskbytes6[] = { #define MASKBIT(offset) ((0xff << (PNBBY - (offset))) & 0xff) +int is_zero_mac(struct ethaddr *mac) +{ + int i = 0; + + for (i = 0; i < ETH_ALEN; i++) { + if (mac->octet[i]) + return 0; + } + + return 1; +} + unsigned int prefix_bit(const u_char *prefix, const u_char prefixlen) { unsigned int offset = prefixlen / 8; diff --git a/lib/prefix.h b/lib/prefix.h index 0f3ad562d9..f665f55dfd 100644 --- a/lib/prefix.h +++ b/lib/prefix.h @@ -265,6 +265,7 @@ union prefixconstptr { #endif /*s6_addr32*/ /* Prototypes. */ +extern int is_zero_mac(struct ethaddr *mac); extern int str2family(const char *); extern int afi2family(afi_t); extern afi_t family2afi(int);