Re: [PATCH v3 iproute2] bridge: add support for L2 multicast groups

2020-11-29 Thread David Ahern
On 11/25/20 7:36 AM, Vladimir Oltean wrote:
> Extend the 'bridge mdb' command for the following syntax:
> bridge mdb add dev br0 port swp0 grp 01:02:03:04:05:06 permanent
> 
> Signed-off-by: Vladimir Oltean 
> ---
> Changes in v3:
> - Using rt_addr_n2a_r instead of inet_ntop/ll_addr_n2a directly.
> - Updated the bridge manpage.
> 
> Changes in v2:
> - Removed the const void casts.
> - Removed MDB_FLAGS_L2 from the UAPI to be in sync with the latest
>   kernel patch:
>   
> https://patchwork.ozlabs.org/project/netdev/patch/20201028233831.610076-1-vladimir.olt...@nxp.com/
> 
>  bridge/mdb.c   | 54 ++
>  include/uapi/linux/if_bridge.h |  1 +
>  man/man8/bridge.8  |  8 ++---
>  3 files changed, 46 insertions(+), 17 deletions(-)
> 

applied to iproute2-next



[PATCH v3 iproute2] bridge: add support for L2 multicast groups

2020-11-25 Thread Vladimir Oltean
Extend the 'bridge mdb' command for the following syntax:
bridge mdb add dev br0 port swp0 grp 01:02:03:04:05:06 permanent

Signed-off-by: Vladimir Oltean 
---
Changes in v3:
- Using rt_addr_n2a_r instead of inet_ntop/ll_addr_n2a directly.
- Updated the bridge manpage.

Changes in v2:
- Removed the const void casts.
- Removed MDB_FLAGS_L2 from the UAPI to be in sync with the latest
  kernel patch:
  
https://patchwork.ozlabs.org/project/netdev/patch/20201028233831.610076-1-vladimir.olt...@nxp.com/

 bridge/mdb.c   | 54 ++
 include/uapi/linux/if_bridge.h |  1 +
 man/man8/bridge.8  |  8 ++---
 3 files changed, 46 insertions(+), 17 deletions(-)

diff --git a/bridge/mdb.c b/bridge/mdb.c
index 4cd7ca762b78..ef89258bc5c3 100644
--- a/bridge/mdb.c
+++ b/bridge/mdb.c
@@ -149,6 +149,7 @@ static void print_mdb_entry(FILE *f, int ifindex, const 
struct br_mdb_entry *e,
struct nlmsghdr *n, struct rtattr **tb)
 {
const void *grp, *src;
+   const char *addr;
SPRINT_BUF(abuf);
const char *dev;
int af;
@@ -156,9 +157,16 @@ static void print_mdb_entry(FILE *f, int ifindex, const 
struct br_mdb_entry *e,
if (filter_vlan && e->vid != filter_vlan)
return;
 
-   af = e->addr.proto == htons(ETH_P_IP) ? AF_INET : AF_INET6;
-   grp = af == AF_INET ? (const void *)>addr.u.ip4 :
- (const void *)>addr.u.ip6;
+   if (!e->addr.proto) {
+   af = AF_PACKET;
+   grp = >addr.u.mac_addr;
+   } else if (e->addr.proto == htons(ETH_P_IP)) {
+   af = AF_INET;
+   grp = >addr.u.ip4;
+   } else {
+   af = AF_INET6;
+   grp = >addr.u.ip6;
+   }
dev = ll_index_to_name(ifindex);
 
open_json_object(NULL);
@@ -168,9 +176,14 @@ static void print_mdb_entry(FILE *f, int ifindex, const 
struct br_mdb_entry *e,
print_string(PRINT_ANY, "port", " port %s",
 ll_index_to_name(e->ifindex));
 
+   /* The ETH_ALEN argument is ignored for all cases but AF_PACKET */
+   addr = rt_addr_n2a_r(af, ETH_ALEN, grp, abuf, sizeof(abuf));
+   if (!addr)
+   return;
+
print_color_string(PRINT_ANY, ifa_family_color(af),
-   "grp", " grp %s",
-   inet_ntop(af, grp, abuf, sizeof(abuf)));
+   "grp", " grp %s", addr);
+
if (tb && tb[MDBA_MDB_EATTR_SOURCE]) {
src = (const void *)RTA_DATA(tb[MDBA_MDB_EATTR_SOURCE]);
print_color_string(PRINT_ANY, ifa_family_color(af),
@@ -440,6 +453,25 @@ static int mdb_show(int argc, char **argv)
return 0;
 }
 
+static int mdb_parse_grp(const char *grp, struct br_mdb_entry *e)
+{
+   if (inet_pton(AF_INET, grp, >addr.u.ip4)) {
+   e->addr.proto = htons(ETH_P_IP);
+   return 0;
+   }
+   if (inet_pton(AF_INET6, grp, >addr.u.ip6)) {
+   e->addr.proto = htons(ETH_P_IPV6);
+   return 0;
+   }
+   if (ll_addr_a2n((char *)e->addr.u.mac_addr, sizeof(e->addr.u.mac_addr),
+   grp) == ETH_ALEN) {
+   e->addr.proto = 0;
+   return 0;
+   }
+
+   return -1;
+}
+
 static int mdb_modify(int cmd, int flags, int argc, char **argv)
 {
struct {
@@ -497,14 +529,10 @@ static int mdb_modify(int cmd, int flags, int argc, char 
**argv)
if (!entry.ifindex)
return nodev(p);
 
-   if (!inet_pton(AF_INET, grp, )) {
-   if (!inet_pton(AF_INET6, grp, )) {
-   fprintf(stderr, "Invalid address \"%s\"\n", grp);
-   return -1;
-   } else
-   entry.addr.proto = htons(ETH_P_IPV6);
-   } else
-   entry.addr.proto = htons(ETH_P_IP);
+   if (mdb_parse_grp(grp, )) {
+   fprintf(stderr, "Invalid address \"%s\"\n", grp);
+   return -1;
+   }
 
entry.vid = vid;
addattr_l(, sizeof(req), MDBA_SET_ENTRY, , sizeof(entry));
diff --git a/include/uapi/linux/if_bridge.h b/include/uapi/linux/if_bridge.h
index 69b99901fc5a..db41a5ff34af 100644
--- a/include/uapi/linux/if_bridge.h
+++ b/include/uapi/linux/if_bridge.h
@@ -526,6 +526,7 @@ struct br_mdb_entry {
union {
__be32  ip4;
struct in6_addr ip6;
+   unsigned char mac_addr[ETH_ALEN];
} u;
__be16  proto;
} addr;
diff --git a/man/man8/bridge.8 b/man/man8/bridge.8
index 84b9b70c7dea..b3414ae31faf 100644
--- a/man/man8/bridge.8
+++ b/man/man8/bridge.8
@@ -665,7 +665,7 @@ the bridge to which this address is associated.
 .SH bridge mdb - multicast group database management
 
 .B mdb
-objects contain known IP multicast group addresses on a link.
+objects contain