2012-08-02 06:23:49 +08:00
|
|
|
/*
|
|
|
|
* Get/set/delete fdb table with netlink
|
|
|
|
*
|
2012-10-02 04:58:01 +08:00
|
|
|
* TODO: merge/replace this with ip neighbour
|
|
|
|
*
|
2012-08-02 06:23:49 +08:00
|
|
|
* Authors: Stephen Hemminger <shemminger@vyatta.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
2013-05-01 11:21:22 +08:00
|
|
|
#include <netdb.h>
|
2012-08-02 06:23:49 +08:00
|
|
|
#include <time.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <linux/if_bridge.h>
|
|
|
|
#include <linux/if_ether.h>
|
|
|
|
#include <linux/neighbour.h>
|
|
|
|
#include <string.h>
|
2014-05-27 15:40:10 +08:00
|
|
|
#include <limits.h>
|
bridge: add json support for bridge fdb show
Sample output:
$bridge -j fdb show
[{
"mac": "44:38:39:00:69:88",
"dev": "swp2s0",
"vlan": 2,
"master": "br0",
"state": "permanent"
},{
"mac": "00:02:00:00:00:01",
"dev": "swp2s0",
"vlan": 2,
"master": "br0"
},{
"mac": "00:02:00:00:00:02",
"dev": "swp2s1",
"vlan": 2,
"master": "br0"
},{
"mac": "44:38:39:00:69:89",
"dev": "swp2s1",
"master": "br0",
"state": "permanent"
},{
"mac": "44:38:39:00:69:89",
"dev": "swp2s1",
"vlan": 2,
"master": "br0",
"state": "permanent"
},{
"mac": "44:38:39:00:69:88",
"dev": "br0",
"master": "br0",
"state": "permanent"
}
]
Signed-off-by: Anuradha Karuppiah <anuradhak@cumulusnetworks.com>
Signed-off-by: Roopa Prabhu <roopa@cumulusnetworks.com>
2016-06-22 21:45:53 +08:00
|
|
|
#include <json_writer.h>
|
|
|
|
#include <stdbool.h>
|
2012-08-02 06:23:49 +08:00
|
|
|
|
|
|
|
#include "libnetlink.h"
|
|
|
|
#include "br_common.h"
|
2012-10-02 04:58:01 +08:00
|
|
|
#include "rt_names.h"
|
2012-08-02 06:23:49 +08:00
|
|
|
#include "utils.h"
|
|
|
|
|
2017-01-13 00:47:39 +08:00
|
|
|
static unsigned int filter_index, filter_vlan, filter_state;
|
2012-08-02 06:23:49 +08:00
|
|
|
|
bridge: add json support for bridge fdb show
Sample output:
$bridge -j fdb show
[{
"mac": "44:38:39:00:69:88",
"dev": "swp2s0",
"vlan": 2,
"master": "br0",
"state": "permanent"
},{
"mac": "00:02:00:00:00:01",
"dev": "swp2s0",
"vlan": 2,
"master": "br0"
},{
"mac": "00:02:00:00:00:02",
"dev": "swp2s1",
"vlan": 2,
"master": "br0"
},{
"mac": "44:38:39:00:69:89",
"dev": "swp2s1",
"master": "br0",
"state": "permanent"
},{
"mac": "44:38:39:00:69:89",
"dev": "swp2s1",
"vlan": 2,
"master": "br0",
"state": "permanent"
},{
"mac": "44:38:39:00:69:88",
"dev": "br0",
"master": "br0",
"state": "permanent"
}
]
Signed-off-by: Anuradha Karuppiah <anuradhak@cumulusnetworks.com>
Signed-off-by: Roopa Prabhu <roopa@cumulusnetworks.com>
2016-06-22 21:45:53 +08:00
|
|
|
json_writer_t *jw_global;
|
|
|
|
|
2012-08-02 06:23:49 +08:00
|
|
|
static void usage(void)
|
|
|
|
{
|
2015-10-29 17:55:24 +08:00
|
|
|
fprintf(stderr, "Usage: bridge fdb { add | append | del | replace } ADDR dev DEV\n"
|
2015-07-31 05:37:02 +08:00
|
|
|
" [ self ] [ master ] [ use ] [ router ]\n"
|
2016-02-20 13:34:52 +08:00
|
|
|
" [ local | static | dynamic ] [ dst IPADDR ] [ vlan VID ]\n"
|
2016-03-22 02:56:01 +08:00
|
|
|
" [ port PORT] [ vni VNI ] [ via DEV ]\n");
|
2017-01-13 00:47:39 +08:00
|
|
|
fprintf(stderr, " bridge fdb [ show [ br BRDEV ] [ brport DEV ] [ vlan VID ] [ state STATE ] ]\n");
|
2012-08-02 06:23:49 +08:00
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
|
2016-03-22 02:56:01 +08:00
|
|
|
static const char *state_n2a(unsigned int s)
|
2012-08-02 06:23:49 +08:00
|
|
|
{
|
|
|
|
static char buf[32];
|
|
|
|
|
2012-10-02 04:58:01 +08:00
|
|
|
if (s & NUD_PERMANENT)
|
|
|
|
return "permanent";
|
2012-08-02 06:23:49 +08:00
|
|
|
|
|
|
|
if (s & NUD_NOARP)
|
|
|
|
return "static";
|
|
|
|
|
|
|
|
if (s & NUD_STALE)
|
|
|
|
return "stale";
|
2012-10-02 04:58:01 +08:00
|
|
|
|
2012-08-02 06:23:49 +08:00
|
|
|
if (s & NUD_REACHABLE)
|
|
|
|
return "";
|
|
|
|
|
|
|
|
sprintf(buf, "state=%#x", s);
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2017-01-13 00:47:39 +08:00
|
|
|
static int state_a2n(unsigned int *s, const char *arg)
|
|
|
|
{
|
|
|
|
if (matches(arg, "permanent") == 0)
|
|
|
|
*s = NUD_PERMANENT;
|
|
|
|
else if (matches(arg, "static") == 0 || matches(arg, "temp") == 0)
|
|
|
|
*s = NUD_NOARP;
|
|
|
|
else if (matches(arg, "stale") == 0)
|
|
|
|
*s = NUD_STALE;
|
|
|
|
else if (matches(arg, "reachable") == 0 || matches(arg, "dynamic") == 0)
|
|
|
|
*s = NUD_REACHABLE;
|
|
|
|
else if (strcmp(arg, "all") == 0)
|
|
|
|
*s = ~0;
|
|
|
|
else if (get_unsigned(s, arg, 0))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
bridge: add json support for bridge fdb show
Sample output:
$bridge -j fdb show
[{
"mac": "44:38:39:00:69:88",
"dev": "swp2s0",
"vlan": 2,
"master": "br0",
"state": "permanent"
},{
"mac": "00:02:00:00:00:01",
"dev": "swp2s0",
"vlan": 2,
"master": "br0"
},{
"mac": "00:02:00:00:00:02",
"dev": "swp2s1",
"vlan": 2,
"master": "br0"
},{
"mac": "44:38:39:00:69:89",
"dev": "swp2s1",
"master": "br0",
"state": "permanent"
},{
"mac": "44:38:39:00:69:89",
"dev": "swp2s1",
"vlan": 2,
"master": "br0",
"state": "permanent"
},{
"mac": "44:38:39:00:69:88",
"dev": "br0",
"master": "br0",
"state": "permanent"
}
]
Signed-off-by: Anuradha Karuppiah <anuradhak@cumulusnetworks.com>
Signed-off-by: Roopa Prabhu <roopa@cumulusnetworks.com>
2016-06-22 21:45:53 +08:00
|
|
|
static void start_json_fdb_flags_array(bool *fdb_flags)
|
|
|
|
{
|
|
|
|
if (*fdb_flags)
|
|
|
|
return;
|
|
|
|
jsonw_name(jw_global, "flags");
|
|
|
|
jsonw_start_array(jw_global);
|
|
|
|
*fdb_flags = true;
|
|
|
|
}
|
|
|
|
|
2012-08-02 06:23:49 +08:00
|
|
|
int print_fdb(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
|
|
|
|
{
|
2012-10-02 04:58:01 +08:00
|
|
|
FILE *fp = arg;
|
2012-08-02 06:23:49 +08:00
|
|
|
struct ndmsg *r = NLMSG_DATA(n);
|
|
|
|
int len = n->nlmsg_len;
|
2016-03-22 02:56:01 +08:00
|
|
|
struct rtattr *tb[NDA_MAX+1];
|
2016-04-11 23:45:14 +08:00
|
|
|
__u16 vid = 0;
|
bridge: add json support for bridge fdb show
Sample output:
$bridge -j fdb show
[{
"mac": "44:38:39:00:69:88",
"dev": "swp2s0",
"vlan": 2,
"master": "br0",
"state": "permanent"
},{
"mac": "00:02:00:00:00:01",
"dev": "swp2s0",
"vlan": 2,
"master": "br0"
},{
"mac": "00:02:00:00:00:02",
"dev": "swp2s1",
"vlan": 2,
"master": "br0"
},{
"mac": "44:38:39:00:69:89",
"dev": "swp2s1",
"master": "br0",
"state": "permanent"
},{
"mac": "44:38:39:00:69:89",
"dev": "swp2s1",
"vlan": 2,
"master": "br0",
"state": "permanent"
},{
"mac": "44:38:39:00:69:88",
"dev": "br0",
"master": "br0",
"state": "permanent"
}
]
Signed-off-by: Anuradha Karuppiah <anuradhak@cumulusnetworks.com>
Signed-off-by: Roopa Prabhu <roopa@cumulusnetworks.com>
2016-06-22 21:45:53 +08:00
|
|
|
bool fdb_flags = false;
|
|
|
|
const char *state_s;
|
2012-10-02 04:58:01 +08:00
|
|
|
|
|
|
|
if (n->nlmsg_type != RTM_NEWNEIGH && n->nlmsg_type != RTM_DELNEIGH) {
|
|
|
|
fprintf(stderr, "Not RTM_NEWNEIGH: %08x %08x %08x\n",
|
|
|
|
n->nlmsg_len, n->nlmsg_type, n->nlmsg_flags);
|
|
|
|
return 0;
|
|
|
|
}
|
2012-08-02 06:23:49 +08:00
|
|
|
|
|
|
|
len -= NLMSG_LENGTH(sizeof(*r));
|
|
|
|
if (len < 0) {
|
|
|
|
fprintf(stderr, "BUG: wrong nlmsg len %d\n", len);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (r->ndm_family != AF_BRIDGE)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (filter_index && filter_index != r->ndm_ifindex)
|
|
|
|
return 0;
|
|
|
|
|
2017-01-13 00:47:39 +08:00
|
|
|
if (filter_state && !(r->ndm_state & filter_state))
|
|
|
|
return 0;
|
|
|
|
|
2012-08-02 06:23:49 +08:00
|
|
|
parse_rtattr(tb, NDA_MAX, NDA_RTA(r),
|
|
|
|
n->nlmsg_len - NLMSG_LENGTH(sizeof(*r)));
|
|
|
|
|
2016-04-11 23:45:14 +08:00
|
|
|
if (tb[NDA_VLAN])
|
|
|
|
vid = rta_getattr_u16(tb[NDA_VLAN]);
|
|
|
|
|
|
|
|
if (filter_vlan && filter_vlan != vid)
|
|
|
|
return 0;
|
|
|
|
|
2016-10-08 00:40:18 +08:00
|
|
|
if (jw_global) {
|
|
|
|
jsonw_pretty(jw_global, 1);
|
|
|
|
jsonw_start_object(jw_global);
|
|
|
|
}
|
|
|
|
|
bridge: add json support for bridge fdb show
Sample output:
$bridge -j fdb show
[{
"mac": "44:38:39:00:69:88",
"dev": "swp2s0",
"vlan": 2,
"master": "br0",
"state": "permanent"
},{
"mac": "00:02:00:00:00:01",
"dev": "swp2s0",
"vlan": 2,
"master": "br0"
},{
"mac": "00:02:00:00:00:02",
"dev": "swp2s1",
"vlan": 2,
"master": "br0"
},{
"mac": "44:38:39:00:69:89",
"dev": "swp2s1",
"master": "br0",
"state": "permanent"
},{
"mac": "44:38:39:00:69:89",
"dev": "swp2s1",
"vlan": 2,
"master": "br0",
"state": "permanent"
},{
"mac": "44:38:39:00:69:88",
"dev": "br0",
"master": "br0",
"state": "permanent"
}
]
Signed-off-by: Anuradha Karuppiah <anuradhak@cumulusnetworks.com>
Signed-off-by: Roopa Prabhu <roopa@cumulusnetworks.com>
2016-06-22 21:45:53 +08:00
|
|
|
if (n->nlmsg_type == RTM_DELNEIGH) {
|
|
|
|
if (jw_global)
|
|
|
|
jsonw_string_field(jw_global, "opCode", "deleted");
|
|
|
|
else
|
|
|
|
fprintf(fp, "Deleted ");
|
|
|
|
}
|
2012-10-02 04:58:01 +08:00
|
|
|
|
|
|
|
if (tb[NDA_LLADDR]) {
|
|
|
|
SPRINT_BUF(b1);
|
bridge: add json support for bridge fdb show
Sample output:
$bridge -j fdb show
[{
"mac": "44:38:39:00:69:88",
"dev": "swp2s0",
"vlan": 2,
"master": "br0",
"state": "permanent"
},{
"mac": "00:02:00:00:00:01",
"dev": "swp2s0",
"vlan": 2,
"master": "br0"
},{
"mac": "00:02:00:00:00:02",
"dev": "swp2s1",
"vlan": 2,
"master": "br0"
},{
"mac": "44:38:39:00:69:89",
"dev": "swp2s1",
"master": "br0",
"state": "permanent"
},{
"mac": "44:38:39:00:69:89",
"dev": "swp2s1",
"vlan": 2,
"master": "br0",
"state": "permanent"
},{
"mac": "44:38:39:00:69:88",
"dev": "br0",
"master": "br0",
"state": "permanent"
}
]
Signed-off-by: Anuradha Karuppiah <anuradhak@cumulusnetworks.com>
Signed-off-by: Roopa Prabhu <roopa@cumulusnetworks.com>
2016-06-22 21:45:53 +08:00
|
|
|
ll_addr_n2a(RTA_DATA(tb[NDA_LLADDR]),
|
|
|
|
RTA_PAYLOAD(tb[NDA_LLADDR]),
|
|
|
|
ll_index_to_type(r->ndm_ifindex),
|
|
|
|
b1, sizeof(b1));
|
|
|
|
if (jw_global)
|
|
|
|
jsonw_string_field(jw_global, "mac", b1);
|
|
|
|
else
|
|
|
|
fprintf(fp, "%s ", b1);
|
2012-08-02 06:23:49 +08:00
|
|
|
}
|
2012-10-30 08:48:55 +08:00
|
|
|
|
bridge: add json support for bridge fdb show
Sample output:
$bridge -j fdb show
[{
"mac": "44:38:39:00:69:88",
"dev": "swp2s0",
"vlan": 2,
"master": "br0",
"state": "permanent"
},{
"mac": "00:02:00:00:00:01",
"dev": "swp2s0",
"vlan": 2,
"master": "br0"
},{
"mac": "00:02:00:00:00:02",
"dev": "swp2s1",
"vlan": 2,
"master": "br0"
},{
"mac": "44:38:39:00:69:89",
"dev": "swp2s1",
"master": "br0",
"state": "permanent"
},{
"mac": "44:38:39:00:69:89",
"dev": "swp2s1",
"vlan": 2,
"master": "br0",
"state": "permanent"
},{
"mac": "44:38:39:00:69:88",
"dev": "br0",
"master": "br0",
"state": "permanent"
}
]
Signed-off-by: Anuradha Karuppiah <anuradhak@cumulusnetworks.com>
Signed-off-by: Roopa Prabhu <roopa@cumulusnetworks.com>
2016-06-22 21:45:53 +08:00
|
|
|
if (!filter_index && r->ndm_ifindex) {
|
|
|
|
if (jw_global)
|
|
|
|
jsonw_string_field(jw_global, "dev",
|
|
|
|
ll_index_to_name(r->ndm_ifindex));
|
|
|
|
else
|
|
|
|
fprintf(fp, "dev %s ",
|
|
|
|
ll_index_to_name(r->ndm_ifindex));
|
|
|
|
}
|
2012-10-02 04:58:01 +08:00
|
|
|
|
|
|
|
if (tb[NDA_DST]) {
|
2014-03-20 19:06:10 +08:00
|
|
|
int family = AF_INET;
|
bridge: add json support for bridge fdb show
Sample output:
$bridge -j fdb show
[{
"mac": "44:38:39:00:69:88",
"dev": "swp2s0",
"vlan": 2,
"master": "br0",
"state": "permanent"
},{
"mac": "00:02:00:00:00:01",
"dev": "swp2s0",
"vlan": 2,
"master": "br0"
},{
"mac": "00:02:00:00:00:02",
"dev": "swp2s1",
"vlan": 2,
"master": "br0"
},{
"mac": "44:38:39:00:69:89",
"dev": "swp2s1",
"master": "br0",
"state": "permanent"
},{
"mac": "44:38:39:00:69:89",
"dev": "swp2s1",
"vlan": 2,
"master": "br0",
"state": "permanent"
},{
"mac": "44:38:39:00:69:88",
"dev": "br0",
"master": "br0",
"state": "permanent"
}
]
Signed-off-by: Anuradha Karuppiah <anuradhak@cumulusnetworks.com>
Signed-off-by: Roopa Prabhu <roopa@cumulusnetworks.com>
2016-06-22 21:45:53 +08:00
|
|
|
const char *abuf_s;
|
2014-03-20 19:06:10 +08:00
|
|
|
|
|
|
|
if (RTA_PAYLOAD(tb[NDA_DST]) == sizeof(struct in6_addr))
|
|
|
|
family = AF_INET6;
|
|
|
|
|
bridge: add json support for bridge fdb show
Sample output:
$bridge -j fdb show
[{
"mac": "44:38:39:00:69:88",
"dev": "swp2s0",
"vlan": 2,
"master": "br0",
"state": "permanent"
},{
"mac": "00:02:00:00:00:01",
"dev": "swp2s0",
"vlan": 2,
"master": "br0"
},{
"mac": "00:02:00:00:00:02",
"dev": "swp2s1",
"vlan": 2,
"master": "br0"
},{
"mac": "44:38:39:00:69:89",
"dev": "swp2s1",
"master": "br0",
"state": "permanent"
},{
"mac": "44:38:39:00:69:89",
"dev": "swp2s1",
"vlan": 2,
"master": "br0",
"state": "permanent"
},{
"mac": "44:38:39:00:69:88",
"dev": "br0",
"master": "br0",
"state": "permanent"
}
]
Signed-off-by: Anuradha Karuppiah <anuradhak@cumulusnetworks.com>
Signed-off-by: Roopa Prabhu <roopa@cumulusnetworks.com>
2016-06-22 21:45:53 +08:00
|
|
|
abuf_s = format_host(family,
|
|
|
|
RTA_PAYLOAD(tb[NDA_DST]),
|
|
|
|
RTA_DATA(tb[NDA_DST]));
|
|
|
|
if (jw_global)
|
|
|
|
jsonw_string_field(jw_global, "dst", abuf_s);
|
|
|
|
else
|
|
|
|
fprintf(fp, "dst %s ", abuf_s);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vid) {
|
|
|
|
if (jw_global)
|
|
|
|
jsonw_uint_field(jw_global, "vlan", vid);
|
|
|
|
else
|
|
|
|
fprintf(fp, "vlan %hu ", vid);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tb[NDA_PORT]) {
|
|
|
|
if (jw_global)
|
|
|
|
jsonw_uint_field(jw_global, "port",
|
2016-12-02 19:25:13 +08:00
|
|
|
rta_getattr_be16(tb[NDA_PORT]));
|
bridge: add json support for bridge fdb show
Sample output:
$bridge -j fdb show
[{
"mac": "44:38:39:00:69:88",
"dev": "swp2s0",
"vlan": 2,
"master": "br0",
"state": "permanent"
},{
"mac": "00:02:00:00:00:01",
"dev": "swp2s0",
"vlan": 2,
"master": "br0"
},{
"mac": "00:02:00:00:00:02",
"dev": "swp2s1",
"vlan": 2,
"master": "br0"
},{
"mac": "44:38:39:00:69:89",
"dev": "swp2s1",
"master": "br0",
"state": "permanent"
},{
"mac": "44:38:39:00:69:89",
"dev": "swp2s1",
"vlan": 2,
"master": "br0",
"state": "permanent"
},{
"mac": "44:38:39:00:69:88",
"dev": "br0",
"master": "br0",
"state": "permanent"
}
]
Signed-off-by: Anuradha Karuppiah <anuradhak@cumulusnetworks.com>
Signed-off-by: Roopa Prabhu <roopa@cumulusnetworks.com>
2016-06-22 21:45:53 +08:00
|
|
|
else
|
|
|
|
fprintf(fp, "port %d ",
|
2016-12-02 19:25:13 +08:00
|
|
|
rta_getattr_be16(tb[NDA_PORT]));
|
2012-10-02 04:58:01 +08:00
|
|
|
}
|
2012-10-30 08:48:55 +08:00
|
|
|
|
bridge: add json support for bridge fdb show
Sample output:
$bridge -j fdb show
[{
"mac": "44:38:39:00:69:88",
"dev": "swp2s0",
"vlan": 2,
"master": "br0",
"state": "permanent"
},{
"mac": "00:02:00:00:00:01",
"dev": "swp2s0",
"vlan": 2,
"master": "br0"
},{
"mac": "00:02:00:00:00:02",
"dev": "swp2s1",
"vlan": 2,
"master": "br0"
},{
"mac": "44:38:39:00:69:89",
"dev": "swp2s1",
"master": "br0",
"state": "permanent"
},{
"mac": "44:38:39:00:69:89",
"dev": "swp2s1",
"vlan": 2,
"master": "br0",
"state": "permanent"
},{
"mac": "44:38:39:00:69:88",
"dev": "br0",
"master": "br0",
"state": "permanent"
}
]
Signed-off-by: Anuradha Karuppiah <anuradhak@cumulusnetworks.com>
Signed-off-by: Roopa Prabhu <roopa@cumulusnetworks.com>
2016-06-22 21:45:53 +08:00
|
|
|
if (tb[NDA_VNI]) {
|
|
|
|
if (jw_global)
|
|
|
|
jsonw_uint_field(jw_global, "vni",
|
|
|
|
rta_getattr_u32(tb[NDA_VNI]));
|
|
|
|
else
|
|
|
|
fprintf(fp, "vni %d ",
|
|
|
|
rta_getattr_u32(tb[NDA_VNI]));
|
|
|
|
}
|
2013-02-28 18:04:04 +08:00
|
|
|
|
2013-05-01 11:21:22 +08:00
|
|
|
if (tb[NDA_IFINDEX]) {
|
|
|
|
unsigned int ifindex = rta_getattr_u32(tb[NDA_IFINDEX]);
|
|
|
|
|
|
|
|
if (ifindex) {
|
|
|
|
char ifname[IF_NAMESIZE];
|
|
|
|
|
2015-02-18 00:30:39 +08:00
|
|
|
if (!tb[NDA_LINK_NETNSID] &&
|
bridge: add json support for bridge fdb show
Sample output:
$bridge -j fdb show
[{
"mac": "44:38:39:00:69:88",
"dev": "swp2s0",
"vlan": 2,
"master": "br0",
"state": "permanent"
},{
"mac": "00:02:00:00:00:01",
"dev": "swp2s0",
"vlan": 2,
"master": "br0"
},{
"mac": "00:02:00:00:00:02",
"dev": "swp2s1",
"vlan": 2,
"master": "br0"
},{
"mac": "44:38:39:00:69:89",
"dev": "swp2s1",
"master": "br0",
"state": "permanent"
},{
"mac": "44:38:39:00:69:89",
"dev": "swp2s1",
"vlan": 2,
"master": "br0",
"state": "permanent"
},{
"mac": "44:38:39:00:69:88",
"dev": "br0",
"master": "br0",
"state": "permanent"
}
]
Signed-off-by: Anuradha Karuppiah <anuradhak@cumulusnetworks.com>
Signed-off-by: Roopa Prabhu <roopa@cumulusnetworks.com>
2016-06-22 21:45:53 +08:00
|
|
|
if_indextoname(ifindex, ifname)) {
|
|
|
|
if (jw_global)
|
|
|
|
jsonw_string_field(jw_global, "viaIf",
|
|
|
|
ifname);
|
|
|
|
else
|
|
|
|
fprintf(fp, "via %s ", ifname);
|
|
|
|
} else {
|
|
|
|
if (jw_global)
|
|
|
|
jsonw_uint_field(jw_global, "viaIfIndex",
|
|
|
|
ifindex);
|
|
|
|
else
|
|
|
|
fprintf(fp, "via ifindex %u ", ifindex);
|
|
|
|
}
|
2013-05-01 11:21:22 +08:00
|
|
|
}
|
|
|
|
}
|
bridge: add json support for bridge fdb show
Sample output:
$bridge -j fdb show
[{
"mac": "44:38:39:00:69:88",
"dev": "swp2s0",
"vlan": 2,
"master": "br0",
"state": "permanent"
},{
"mac": "00:02:00:00:00:01",
"dev": "swp2s0",
"vlan": 2,
"master": "br0"
},{
"mac": "00:02:00:00:00:02",
"dev": "swp2s1",
"vlan": 2,
"master": "br0"
},{
"mac": "44:38:39:00:69:89",
"dev": "swp2s1",
"master": "br0",
"state": "permanent"
},{
"mac": "44:38:39:00:69:89",
"dev": "swp2s1",
"vlan": 2,
"master": "br0",
"state": "permanent"
},{
"mac": "44:38:39:00:69:88",
"dev": "br0",
"master": "br0",
"state": "permanent"
}
]
Signed-off-by: Anuradha Karuppiah <anuradhak@cumulusnetworks.com>
Signed-off-by: Roopa Prabhu <roopa@cumulusnetworks.com>
2016-06-22 21:45:53 +08:00
|
|
|
|
|
|
|
if (tb[NDA_LINK_NETNSID]) {
|
|
|
|
if (jw_global)
|
|
|
|
jsonw_uint_field(jw_global, "linkNetNsId",
|
|
|
|
rta_getattr_u32(tb[NDA_LINK_NETNSID]));
|
|
|
|
else
|
|
|
|
fprintf(fp, "link-netnsid %d ",
|
|
|
|
rta_getattr_u32(tb[NDA_LINK_NETNSID]));
|
|
|
|
}
|
2013-05-01 11:21:22 +08:00
|
|
|
|
2012-08-02 06:23:49 +08:00
|
|
|
if (show_stats && tb[NDA_CACHEINFO]) {
|
|
|
|
struct nda_cacheinfo *ci = RTA_DATA(tb[NDA_CACHEINFO]);
|
2012-10-02 04:58:01 +08:00
|
|
|
int hz = get_user_hz();
|
2012-08-02 06:23:49 +08:00
|
|
|
|
bridge: add json support for bridge fdb show
Sample output:
$bridge -j fdb show
[{
"mac": "44:38:39:00:69:88",
"dev": "swp2s0",
"vlan": 2,
"master": "br0",
"state": "permanent"
},{
"mac": "00:02:00:00:00:01",
"dev": "swp2s0",
"vlan": 2,
"master": "br0"
},{
"mac": "00:02:00:00:00:02",
"dev": "swp2s1",
"vlan": 2,
"master": "br0"
},{
"mac": "44:38:39:00:69:89",
"dev": "swp2s1",
"master": "br0",
"state": "permanent"
},{
"mac": "44:38:39:00:69:89",
"dev": "swp2s1",
"vlan": 2,
"master": "br0",
"state": "permanent"
},{
"mac": "44:38:39:00:69:88",
"dev": "br0",
"master": "br0",
"state": "permanent"
}
]
Signed-off-by: Anuradha Karuppiah <anuradhak@cumulusnetworks.com>
Signed-off-by: Roopa Prabhu <roopa@cumulusnetworks.com>
2016-06-22 21:45:53 +08:00
|
|
|
if (jw_global) {
|
|
|
|
jsonw_uint_field(jw_global, "used",
|
|
|
|
ci->ndm_used/hz);
|
|
|
|
jsonw_uint_field(jw_global, "updated",
|
|
|
|
ci->ndm_updated/hz);
|
|
|
|
} else {
|
|
|
|
fprintf(fp, "used %d/%d ", ci->ndm_used/hz,
|
|
|
|
ci->ndm_updated/hz);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (jw_global) {
|
|
|
|
if (r->ndm_flags & NTF_SELF) {
|
|
|
|
start_json_fdb_flags_array(&fdb_flags);
|
|
|
|
jsonw_string(jw_global, "self");
|
|
|
|
}
|
|
|
|
if (r->ndm_flags & NTF_ROUTER) {
|
|
|
|
start_json_fdb_flags_array(&fdb_flags);
|
|
|
|
jsonw_string(jw_global, "router");
|
|
|
|
}
|
|
|
|
if (r->ndm_flags & NTF_EXT_LEARNED) {
|
2017-06-05 18:07:05 +08:00
|
|
|
start_json_fdb_flags_array(&fdb_flags);
|
|
|
|
jsonw_string(jw_global, "extern_learn");
|
|
|
|
}
|
|
|
|
if (r->ndm_flags & NTF_OFFLOADED) {
|
bridge: add json support for bridge fdb show
Sample output:
$bridge -j fdb show
[{
"mac": "44:38:39:00:69:88",
"dev": "swp2s0",
"vlan": 2,
"master": "br0",
"state": "permanent"
},{
"mac": "00:02:00:00:00:01",
"dev": "swp2s0",
"vlan": 2,
"master": "br0"
},{
"mac": "00:02:00:00:00:02",
"dev": "swp2s1",
"vlan": 2,
"master": "br0"
},{
"mac": "44:38:39:00:69:89",
"dev": "swp2s1",
"master": "br0",
"state": "permanent"
},{
"mac": "44:38:39:00:69:89",
"dev": "swp2s1",
"vlan": 2,
"master": "br0",
"state": "permanent"
},{
"mac": "44:38:39:00:69:88",
"dev": "br0",
"master": "br0",
"state": "permanent"
}
]
Signed-off-by: Anuradha Karuppiah <anuradhak@cumulusnetworks.com>
Signed-off-by: Roopa Prabhu <roopa@cumulusnetworks.com>
2016-06-22 21:45:53 +08:00
|
|
|
start_json_fdb_flags_array(&fdb_flags);
|
|
|
|
jsonw_string(jw_global, "offload");
|
|
|
|
}
|
|
|
|
if (r->ndm_flags & NTF_MASTER)
|
|
|
|
jsonw_string(jw_global, "master");
|
|
|
|
if (fdb_flags)
|
|
|
|
jsonw_end_array(jw_global);
|
|
|
|
|
|
|
|
if (tb[NDA_MASTER])
|
|
|
|
jsonw_string_field(jw_global,
|
|
|
|
"master",
|
|
|
|
ll_index_to_name(rta_getattr_u32(tb[NDA_MASTER])));
|
|
|
|
|
|
|
|
} else {
|
|
|
|
if (r->ndm_flags & NTF_SELF)
|
|
|
|
fprintf(fp, "self ");
|
|
|
|
if (r->ndm_flags & NTF_ROUTER)
|
|
|
|
fprintf(fp, "router ");
|
|
|
|
if (r->ndm_flags & NTF_EXT_LEARNED)
|
2017-06-05 18:07:05 +08:00
|
|
|
fprintf(fp, "extern_learn ");
|
|
|
|
if (r->ndm_flags & NTF_OFFLOADED)
|
bridge: add json support for bridge fdb show
Sample output:
$bridge -j fdb show
[{
"mac": "44:38:39:00:69:88",
"dev": "swp2s0",
"vlan": 2,
"master": "br0",
"state": "permanent"
},{
"mac": "00:02:00:00:00:01",
"dev": "swp2s0",
"vlan": 2,
"master": "br0"
},{
"mac": "00:02:00:00:00:02",
"dev": "swp2s1",
"vlan": 2,
"master": "br0"
},{
"mac": "44:38:39:00:69:89",
"dev": "swp2s1",
"master": "br0",
"state": "permanent"
},{
"mac": "44:38:39:00:69:89",
"dev": "swp2s1",
"vlan": 2,
"master": "br0",
"state": "permanent"
},{
"mac": "44:38:39:00:69:88",
"dev": "br0",
"master": "br0",
"state": "permanent"
}
]
Signed-off-by: Anuradha Karuppiah <anuradhak@cumulusnetworks.com>
Signed-off-by: Roopa Prabhu <roopa@cumulusnetworks.com>
2016-06-22 21:45:53 +08:00
|
|
|
fprintf(fp, "offload ");
|
|
|
|
if (tb[NDA_MASTER]) {
|
|
|
|
fprintf(fp, "master %s ",
|
|
|
|
ll_index_to_name(rta_getattr_u32(tb[NDA_MASTER])));
|
|
|
|
} else if (r->ndm_flags & NTF_MASTER) {
|
|
|
|
fprintf(fp, "master ");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
state_s = state_n2a(r->ndm_state);
|
|
|
|
if (jw_global) {
|
|
|
|
if (state_s[0])
|
|
|
|
jsonw_string_field(jw_global, "state", state_s);
|
|
|
|
|
|
|
|
jsonw_end_object(jw_global);
|
|
|
|
} else {
|
|
|
|
fprintf(fp, "%s\n", state_s);
|
|
|
|
|
|
|
|
fflush(fp);
|
2012-08-02 06:23:49 +08:00
|
|
|
}
|
2015-10-16 05:53:17 +08:00
|
|
|
|
2012-08-02 06:23:49 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int fdb_show(int argc, char **argv)
|
|
|
|
{
|
2014-07-04 20:37:10 +08:00
|
|
|
struct {
|
2016-03-22 02:56:01 +08:00
|
|
|
struct nlmsghdr n;
|
2014-07-04 20:37:10 +08:00
|
|
|
struct ifinfomsg ifm;
|
2016-03-22 02:56:01 +08:00
|
|
|
char buf[256];
|
2016-07-18 22:48:42 +08:00
|
|
|
} req = {
|
|
|
|
.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg)),
|
|
|
|
.ifm.ifi_family = PF_BRIDGE,
|
|
|
|
};
|
2014-07-04 20:37:10 +08:00
|
|
|
|
2012-08-02 06:23:49 +08:00
|
|
|
char *filter_dev = NULL;
|
2014-07-04 20:37:10 +08:00
|
|
|
char *br = NULL;
|
|
|
|
int msg_size = sizeof(struct ifinfomsg);
|
|
|
|
|
2012-08-02 06:23:49 +08:00
|
|
|
while (argc > 0) {
|
2014-07-04 20:37:10 +08:00
|
|
|
if ((strcmp(*argv, "brport") == 0) || strcmp(*argv, "dev") == 0) {
|
2012-08-02 06:23:49 +08:00
|
|
|
NEXT_ARG();
|
|
|
|
filter_dev = *argv;
|
2014-07-04 20:37:10 +08:00
|
|
|
} else if (strcmp(*argv, "br") == 0) {
|
|
|
|
NEXT_ARG();
|
|
|
|
br = *argv;
|
2016-04-11 23:45:14 +08:00
|
|
|
} else if (strcmp(*argv, "vlan") == 0) {
|
|
|
|
NEXT_ARG();
|
|
|
|
if (filter_vlan)
|
|
|
|
duparg("vlan", *argv);
|
|
|
|
filter_vlan = atoi(*argv);
|
2017-01-13 00:47:39 +08:00
|
|
|
} else if (strcmp(*argv, "state") == 0) {
|
|
|
|
unsigned int state;
|
|
|
|
|
|
|
|
NEXT_ARG();
|
|
|
|
if (state_a2n(&state, *argv))
|
|
|
|
invarg("invalid state", *argv);
|
|
|
|
filter_state |= state;
|
2014-07-04 20:37:10 +08:00
|
|
|
} else {
|
|
|
|
if (matches(*argv, "help") == 0)
|
|
|
|
usage();
|
2012-08-02 06:23:49 +08:00
|
|
|
}
|
|
|
|
argc--; argv++;
|
|
|
|
}
|
|
|
|
|
2014-07-04 20:37:10 +08:00
|
|
|
if (br) {
|
|
|
|
int br_ifindex = ll_name_to_index(br);
|
2016-03-22 02:56:01 +08:00
|
|
|
|
2014-07-04 20:37:10 +08:00
|
|
|
if (br_ifindex == 0) {
|
|
|
|
fprintf(stderr, "Cannot find bridge device \"%s\"\n", br);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
addattr32(&req.n, sizeof(req), IFLA_MASTER, br_ifindex);
|
|
|
|
msg_size += RTA_LENGTH(4);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*we'll keep around filter_dev for older kernels */
|
2012-08-02 06:23:49 +08:00
|
|
|
if (filter_dev) {
|
2012-10-02 04:58:01 +08:00
|
|
|
filter_index = if_nametoindex(filter_dev);
|
|
|
|
if (filter_index == 0) {
|
|
|
|
fprintf(stderr, "Cannot find device \"%s\"\n",
|
|
|
|
filter_dev);
|
2012-08-02 06:23:49 +08:00
|
|
|
return -1;
|
|
|
|
}
|
2014-07-04 20:37:10 +08:00
|
|
|
req.ifm.ifi_index = filter_index;
|
2012-08-02 06:23:49 +08:00
|
|
|
}
|
|
|
|
|
2014-07-04 20:37:10 +08:00
|
|
|
if (rtnl_dump_request(&rth, RTM_GETNEIGH, &req.ifm, msg_size) < 0) {
|
2012-08-02 06:23:49 +08:00
|
|
|
perror("Cannot send dump request");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
bridge: add json support for bridge fdb show
Sample output:
$bridge -j fdb show
[{
"mac": "44:38:39:00:69:88",
"dev": "swp2s0",
"vlan": 2,
"master": "br0",
"state": "permanent"
},{
"mac": "00:02:00:00:00:01",
"dev": "swp2s0",
"vlan": 2,
"master": "br0"
},{
"mac": "00:02:00:00:00:02",
"dev": "swp2s1",
"vlan": 2,
"master": "br0"
},{
"mac": "44:38:39:00:69:89",
"dev": "swp2s1",
"master": "br0",
"state": "permanent"
},{
"mac": "44:38:39:00:69:89",
"dev": "swp2s1",
"vlan": 2,
"master": "br0",
"state": "permanent"
},{
"mac": "44:38:39:00:69:88",
"dev": "br0",
"master": "br0",
"state": "permanent"
}
]
Signed-off-by: Anuradha Karuppiah <anuradhak@cumulusnetworks.com>
Signed-off-by: Roopa Prabhu <roopa@cumulusnetworks.com>
2016-06-22 21:45:53 +08:00
|
|
|
if (json_output) {
|
|
|
|
jw_global = jsonw_new(stdout);
|
|
|
|
if (!jw_global) {
|
|
|
|
fprintf(stderr, "Error allocation json object\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
jsonw_start_array(jw_global);
|
|
|
|
}
|
2012-10-02 04:58:01 +08:00
|
|
|
if (rtnl_dump_filter(&rth, print_fdb, stdout) < 0) {
|
2012-08-02 06:23:49 +08:00
|
|
|
fprintf(stderr, "Dump terminated\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
bridge: add json support for bridge fdb show
Sample output:
$bridge -j fdb show
[{
"mac": "44:38:39:00:69:88",
"dev": "swp2s0",
"vlan": 2,
"master": "br0",
"state": "permanent"
},{
"mac": "00:02:00:00:00:01",
"dev": "swp2s0",
"vlan": 2,
"master": "br0"
},{
"mac": "00:02:00:00:00:02",
"dev": "swp2s1",
"vlan": 2,
"master": "br0"
},{
"mac": "44:38:39:00:69:89",
"dev": "swp2s1",
"master": "br0",
"state": "permanent"
},{
"mac": "44:38:39:00:69:89",
"dev": "swp2s1",
"vlan": 2,
"master": "br0",
"state": "permanent"
},{
"mac": "44:38:39:00:69:88",
"dev": "br0",
"master": "br0",
"state": "permanent"
}
]
Signed-off-by: Anuradha Karuppiah <anuradhak@cumulusnetworks.com>
Signed-off-by: Roopa Prabhu <roopa@cumulusnetworks.com>
2016-06-22 21:45:53 +08:00
|
|
|
if (jw_global) {
|
|
|
|
jsonw_end_array(jw_global);
|
|
|
|
jsonw_destroy(&jw_global);
|
|
|
|
}
|
2012-08-02 06:23:49 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int fdb_modify(int cmd, int flags, int argc, char **argv)
|
|
|
|
{
|
|
|
|
struct {
|
2016-03-22 02:56:01 +08:00
|
|
|
struct nlmsghdr n;
|
|
|
|
struct ndmsg ndm;
|
|
|
|
char buf[256];
|
2016-07-18 22:48:42 +08:00
|
|
|
} req = {
|
|
|
|
.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ndmsg)),
|
|
|
|
.n.nlmsg_flags = NLM_F_REQUEST | flags,
|
|
|
|
.n.nlmsg_type = cmd,
|
|
|
|
.ndm.ndm_family = PF_BRIDGE,
|
|
|
|
.ndm.ndm_state = NUD_NOARP,
|
|
|
|
};
|
2012-08-02 06:23:49 +08:00
|
|
|
char *addr = NULL;
|
|
|
|
char *d = NULL;
|
|
|
|
char abuf[ETH_ALEN];
|
2012-10-02 04:58:01 +08:00
|
|
|
int dst_ok = 0;
|
|
|
|
inet_prefix dst;
|
2013-05-01 11:21:22 +08:00
|
|
|
unsigned long port = 0;
|
|
|
|
unsigned long vni = ~0;
|
|
|
|
unsigned int via = 0;
|
|
|
|
char *endptr;
|
2013-02-28 18:04:04 +08:00
|
|
|
short vid = -1;
|
2012-08-02 06:23:49 +08:00
|
|
|
|
|
|
|
while (argc > 0) {
|
|
|
|
if (strcmp(*argv, "dev") == 0) {
|
|
|
|
NEXT_ARG();
|
|
|
|
d = *argv;
|
2012-10-02 04:58:01 +08:00
|
|
|
} else if (strcmp(*argv, "dst") == 0) {
|
|
|
|
NEXT_ARG();
|
|
|
|
if (dst_ok)
|
|
|
|
duparg2("dst", *argv);
|
|
|
|
get_addr(&dst, *argv, preferred_family);
|
|
|
|
dst_ok = 1;
|
2013-05-01 11:21:22 +08:00
|
|
|
} else if (strcmp(*argv, "port") == 0) {
|
|
|
|
|
|
|
|
NEXT_ARG();
|
|
|
|
port = strtoul(*argv, &endptr, 0);
|
|
|
|
if (endptr && *endptr) {
|
|
|
|
struct servent *pse;
|
|
|
|
|
|
|
|
pse = getservbyname(*argv, "udp");
|
|
|
|
if (!pse)
|
|
|
|
invarg("invalid port\n", *argv);
|
|
|
|
port = ntohs(pse->s_port);
|
|
|
|
} else if (port > 0xffff)
|
|
|
|
invarg("invalid port\n", *argv);
|
|
|
|
} else if (strcmp(*argv, "vni") == 0) {
|
|
|
|
NEXT_ARG();
|
|
|
|
vni = strtoul(*argv, &endptr, 0);
|
|
|
|
if ((endptr && *endptr) ||
|
|
|
|
(vni >> 24) || vni == ULONG_MAX)
|
|
|
|
invarg("invalid VNI\n", *argv);
|
|
|
|
} else if (strcmp(*argv, "via") == 0) {
|
|
|
|
NEXT_ARG();
|
|
|
|
via = if_nametoindex(*argv);
|
|
|
|
if (via == 0)
|
|
|
|
invarg("invalid device\n", *argv);
|
2012-08-24 04:37:19 +08:00
|
|
|
} else if (strcmp(*argv, "self") == 0) {
|
|
|
|
req.ndm.ndm_flags |= NTF_SELF;
|
2012-10-02 04:58:01 +08:00
|
|
|
} else if (matches(*argv, "master") == 0) {
|
2012-08-24 04:37:19 +08:00
|
|
|
req.ndm.ndm_flags |= NTF_MASTER;
|
2013-05-06 20:11:46 +08:00
|
|
|
} else if (matches(*argv, "router") == 0) {
|
|
|
|
req.ndm.ndm_flags |= NTF_ROUTER;
|
2016-03-28 01:47:46 +08:00
|
|
|
} else if (matches(*argv, "local") == 0 ||
|
2012-10-02 04:58:01 +08:00
|
|
|
matches(*argv, "permanent") == 0) {
|
|
|
|
req.ndm.ndm_state |= NUD_PERMANENT;
|
2016-01-28 01:09:37 +08:00
|
|
|
} else if (matches(*argv, "temp") == 0 ||
|
|
|
|
matches(*argv, "static") == 0) {
|
2012-10-02 04:58:01 +08:00
|
|
|
req.ndm.ndm_state |= NUD_REACHABLE;
|
2016-02-20 13:34:52 +08:00
|
|
|
} else if (matches(*argv, "dynamic") == 0) {
|
|
|
|
req.ndm.ndm_state |= NUD_REACHABLE;
|
|
|
|
req.ndm.ndm_state &= ~NUD_NOARP;
|
2013-02-28 18:04:04 +08:00
|
|
|
} else if (matches(*argv, "vlan") == 0) {
|
|
|
|
if (vid >= 0)
|
|
|
|
duparg2("vlan", *argv);
|
|
|
|
NEXT_ARG();
|
|
|
|
vid = atoi(*argv);
|
2015-07-31 05:37:02 +08:00
|
|
|
} else if (matches(*argv, "use") == 0) {
|
|
|
|
req.ndm.ndm_flags |= NTF_USE;
|
2012-08-02 06:23:49 +08:00
|
|
|
} else {
|
|
|
|
if (strcmp(*argv, "to") == 0) {
|
|
|
|
NEXT_ARG();
|
|
|
|
}
|
2012-10-02 04:58:01 +08:00
|
|
|
if (matches(*argv, "help") == 0)
|
|
|
|
usage();
|
2012-08-02 06:23:49 +08:00
|
|
|
if (addr)
|
|
|
|
duparg2("to", *argv);
|
|
|
|
addr = *argv;
|
|
|
|
}
|
|
|
|
argc--; argv++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (d == NULL || addr == NULL) {
|
|
|
|
fprintf(stderr, "Device and address are required arguments.\n");
|
2015-03-18 10:26:32 +08:00
|
|
|
return -1;
|
2012-08-02 06:23:49 +08:00
|
|
|
}
|
|
|
|
|
2012-10-02 04:58:01 +08:00
|
|
|
/* Assume self */
|
|
|
|
if (!(req.ndm.ndm_flags&(NTF_SELF|NTF_MASTER)))
|
|
|
|
req.ndm.ndm_flags |= NTF_SELF;
|
|
|
|
|
|
|
|
/* Assume permanent */
|
|
|
|
if (!(req.ndm.ndm_state&(NUD_PERMANENT|NUD_REACHABLE)))
|
|
|
|
req.ndm.ndm_state |= NUD_PERMANENT;
|
|
|
|
|
|
|
|
if (sscanf(addr, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx",
|
2012-08-02 06:23:49 +08:00
|
|
|
abuf, abuf+1, abuf+2,
|
|
|
|
abuf+3, abuf+4, abuf+5) != 6) {
|
|
|
|
fprintf(stderr, "Invalid mac address %s\n", addr);
|
2015-03-18 10:26:32 +08:00
|
|
|
return -1;
|
2012-08-02 06:23:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
addattr_l(&req.n, sizeof(req), NDA_LLADDR, abuf, ETH_ALEN);
|
2012-10-02 04:58:01 +08:00
|
|
|
if (dst_ok)
|
|
|
|
addattr_l(&req.n, sizeof(req), NDA_DST, &dst.data, dst.bytelen);
|
2012-08-02 06:23:49 +08:00
|
|
|
|
2013-02-28 18:04:04 +08:00
|
|
|
if (vid >= 0)
|
2013-03-07 03:04:29 +08:00
|
|
|
addattr16(&req.n, sizeof(req), NDA_VLAN, vid);
|
2013-02-28 18:04:04 +08:00
|
|
|
|
2013-05-01 11:21:22 +08:00
|
|
|
if (port) {
|
|
|
|
unsigned short dport;
|
|
|
|
|
|
|
|
dport = htons((unsigned short)port);
|
|
|
|
addattr16(&req.n, sizeof(req), NDA_PORT, dport);
|
|
|
|
}
|
|
|
|
if (vni != ~0)
|
|
|
|
addattr32(&req.n, sizeof(req), NDA_VNI, vni);
|
|
|
|
if (via)
|
|
|
|
addattr32(&req.n, sizeof(req), NDA_IFINDEX, via);
|
|
|
|
|
2012-08-02 06:23:49 +08:00
|
|
|
req.ndm.ndm_ifindex = ll_name_to_index(d);
|
|
|
|
if (req.ndm.ndm_ifindex == 0) {
|
|
|
|
fprintf(stderr, "Cannot find device \"%s\"\n", d);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-05-28 03:26:14 +08:00
|
|
|
if (rtnl_talk(&rth, &req.n, NULL, 0) < 0)
|
2015-03-18 10:26:32 +08:00
|
|
|
return -1;
|
2012-08-02 06:23:49 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int do_fdb(int argc, char **argv)
|
|
|
|
{
|
|
|
|
ll_init_map(&rth);
|
|
|
|
|
|
|
|
if (argc > 0) {
|
|
|
|
if (matches(*argv, "add") == 0)
|
|
|
|
return fdb_modify(RTM_NEWNEIGH, NLM_F_CREATE|NLM_F_EXCL, argc-1, argv+1);
|
2013-05-01 11:21:22 +08:00
|
|
|
if (matches(*argv, "append") == 0)
|
|
|
|
return fdb_modify(RTM_NEWNEIGH, NLM_F_CREATE|NLM_F_APPEND, argc-1, argv+1);
|
2013-07-30 14:16:41 +08:00
|
|
|
if (matches(*argv, "replace") == 0)
|
|
|
|
return fdb_modify(RTM_NEWNEIGH, NLM_F_CREATE|NLM_F_REPLACE, argc-1, argv+1);
|
2012-08-02 06:23:49 +08:00
|
|
|
if (matches(*argv, "delete") == 0)
|
|
|
|
return fdb_modify(RTM_DELNEIGH, 0, argc-1, argv+1);
|
|
|
|
if (matches(*argv, "show") == 0 ||
|
|
|
|
matches(*argv, "lst") == 0 ||
|
|
|
|
matches(*argv, "list") == 0)
|
|
|
|
return fdb_show(argc-1, argv+1);
|
|
|
|
if (matches(*argv, "help") == 0)
|
|
|
|
usage();
|
|
|
|
} else
|
|
|
|
return fdb_show(0, NULL);
|
|
|
|
|
2012-08-20 14:28:47 +08:00
|
|
|
fprintf(stderr, "Command \"%s\" is unknown, try \"bridge fdb help\".\n", *argv);
|
2012-08-02 06:23:49 +08:00
|
|
|
exit(-1);
|
|
|
|
}
|