mirror of
https://git.proxmox.com/git/mirror_iproute2
synced 2025-12-10 07:22:40 +00:00
bridge: isolate vlans parsing code in a separate API
IFLA_BRIDGE_VLAN_INFO parsing logic will be used in link and vlan processing code, so it makes sense to move it in the separate function. Signed-off-by: Roman Mashak <mrv@mojatatu.com>
This commit is contained in:
parent
5a9bca7145
commit
b97c679c9f
@ -4,6 +4,7 @@
|
|||||||
#define MDB_RTR_RTA(r) \
|
#define MDB_RTR_RTA(r) \
|
||||||
((struct rtattr *)(((char *)(r)) + RTA_ALIGN(sizeof(__u32))))
|
((struct rtattr *)(((char *)(r)) + RTA_ALIGN(sizeof(__u32))))
|
||||||
|
|
||||||
|
extern void print_vlan_info(FILE *fp, struct rtattr *tb, int ifindex);
|
||||||
extern int print_linkinfo(const struct sockaddr_nl *who,
|
extern int print_linkinfo(const struct sockaddr_nl *who,
|
||||||
struct nlmsghdr *n,
|
struct nlmsghdr *n,
|
||||||
void *arg);
|
void *arg);
|
||||||
|
|||||||
145
bridge/vlan.c
145
bridge/vlan.c
@ -189,7 +189,6 @@ static int print_vlan(const struct sockaddr_nl *who,
|
|||||||
struct ifinfomsg *ifm = NLMSG_DATA(n);
|
struct ifinfomsg *ifm = NLMSG_DATA(n);
|
||||||
int len = n->nlmsg_len;
|
int len = n->nlmsg_len;
|
||||||
struct rtattr *tb[IFLA_MAX+1];
|
struct rtattr *tb[IFLA_MAX+1];
|
||||||
bool vlan_flags = false;
|
|
||||||
|
|
||||||
if (n->nlmsg_type != RTM_NEWLINK) {
|
if (n->nlmsg_type != RTM_NEWLINK) {
|
||||||
fprintf(stderr, "Not RTM_NEWLINK: %08x %08x %08x\n",
|
fprintf(stderr, "Not RTM_NEWLINK: %08x %08x %08x\n",
|
||||||
@ -218,75 +217,7 @@ static int print_vlan(const struct sockaddr_nl *who,
|
|||||||
ll_index_to_name(ifm->ifi_index));
|
ll_index_to_name(ifm->ifi_index));
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
struct rtattr *i, *list = tb[IFLA_AF_SPEC];
|
print_vlan_info(fp, tb[IFLA_AF_SPEC], ifm->ifi_index);
|
||||||
int rem = RTA_PAYLOAD(list);
|
|
||||||
__u16 last_vid_start = 0;
|
|
||||||
|
|
||||||
if (!filter_vlan)
|
|
||||||
print_vlan_port(fp, ifm->ifi_index);
|
|
||||||
|
|
||||||
for (i = RTA_DATA(list); RTA_OK(i, rem); i = RTA_NEXT(i, rem)) {
|
|
||||||
struct bridge_vlan_info *vinfo;
|
|
||||||
int vcheck_ret;
|
|
||||||
|
|
||||||
if (i->rta_type != IFLA_BRIDGE_VLAN_INFO)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
vinfo = RTA_DATA(i);
|
|
||||||
|
|
||||||
if (!(vinfo->flags & BRIDGE_VLAN_INFO_RANGE_END))
|
|
||||||
last_vid_start = vinfo->vid;
|
|
||||||
vcheck_ret = filter_vlan_check(vinfo);
|
|
||||||
if (vcheck_ret == -1)
|
|
||||||
break;
|
|
||||||
else if (vcheck_ret == 0)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (filter_vlan)
|
|
||||||
print_vlan_port(fp, ifm->ifi_index);
|
|
||||||
if (jw_global) {
|
|
||||||
jsonw_start_object(jw_global);
|
|
||||||
jsonw_uint_field(jw_global, "vlan",
|
|
||||||
last_vid_start);
|
|
||||||
if (vinfo->flags & BRIDGE_VLAN_INFO_RANGE_BEGIN)
|
|
||||||
continue;
|
|
||||||
} else {
|
|
||||||
fprintf(fp, "\t %hu", last_vid_start);
|
|
||||||
}
|
|
||||||
if (last_vid_start != vinfo->vid) {
|
|
||||||
if (jw_global)
|
|
||||||
jsonw_uint_field(jw_global, "vlanEnd",
|
|
||||||
vinfo->vid);
|
|
||||||
else
|
|
||||||
fprintf(fp, "-%hu", vinfo->vid);
|
|
||||||
}
|
|
||||||
if (vinfo->flags & BRIDGE_VLAN_INFO_PVID) {
|
|
||||||
if (jw_global) {
|
|
||||||
start_json_vlan_flags_array(&vlan_flags);
|
|
||||||
jsonw_string(jw_global, "PVID");
|
|
||||||
} else {
|
|
||||||
fprintf(fp, " PVID");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (vinfo->flags & BRIDGE_VLAN_INFO_UNTAGGED) {
|
|
||||||
if (jw_global) {
|
|
||||||
start_json_vlan_flags_array(&vlan_flags);
|
|
||||||
jsonw_string(jw_global,
|
|
||||||
"Egress Untagged");
|
|
||||||
} else {
|
|
||||||
fprintf(fp, " Egress Untagged");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (jw_global && vlan_flags) {
|
|
||||||
jsonw_end_array(jw_global);
|
|
||||||
vlan_flags = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (jw_global)
|
|
||||||
jsonw_end_object(jw_global);
|
|
||||||
else
|
|
||||||
fprintf(fp, "\n");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (!filter_vlan) {
|
if (!filter_vlan) {
|
||||||
if (jw_global)
|
if (jw_global)
|
||||||
@ -470,6 +401,80 @@ static int vlan_show(int argc, char **argv)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void print_vlan_info(FILE *fp, struct rtattr *tb, int ifindex)
|
||||||
|
{
|
||||||
|
struct rtattr *i, *list = tb;
|
||||||
|
int rem = RTA_PAYLOAD(list);
|
||||||
|
__u16 last_vid_start = 0;
|
||||||
|
bool vlan_flags = false;
|
||||||
|
|
||||||
|
if (!filter_vlan)
|
||||||
|
print_vlan_port(fp, ifindex);
|
||||||
|
|
||||||
|
for (i = RTA_DATA(list); RTA_OK(i, rem); i = RTA_NEXT(i, rem)) {
|
||||||
|
struct bridge_vlan_info *vinfo;
|
||||||
|
int vcheck_ret;
|
||||||
|
|
||||||
|
if (i->rta_type != IFLA_BRIDGE_VLAN_INFO)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
vinfo = RTA_DATA(i);
|
||||||
|
|
||||||
|
if (!(vinfo->flags & BRIDGE_VLAN_INFO_RANGE_END))
|
||||||
|
last_vid_start = vinfo->vid;
|
||||||
|
vcheck_ret = filter_vlan_check(vinfo);
|
||||||
|
if (vcheck_ret == -1)
|
||||||
|
break;
|
||||||
|
else if (vcheck_ret == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (filter_vlan)
|
||||||
|
print_vlan_port(fp, ifindex);
|
||||||
|
if (jw_global) {
|
||||||
|
jsonw_start_object(jw_global);
|
||||||
|
jsonw_uint_field(jw_global, "vlan",
|
||||||
|
last_vid_start);
|
||||||
|
if (vinfo->flags & BRIDGE_VLAN_INFO_RANGE_BEGIN)
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
fprintf(fp, "\t %hu", last_vid_start);
|
||||||
|
}
|
||||||
|
if (last_vid_start != vinfo->vid) {
|
||||||
|
if (jw_global)
|
||||||
|
jsonw_uint_field(jw_global, "vlanEnd",
|
||||||
|
vinfo->vid);
|
||||||
|
else
|
||||||
|
fprintf(fp, "-%hu", vinfo->vid);
|
||||||
|
}
|
||||||
|
if (vinfo->flags & BRIDGE_VLAN_INFO_PVID) {
|
||||||
|
if (jw_global) {
|
||||||
|
start_json_vlan_flags_array(&vlan_flags);
|
||||||
|
jsonw_string(jw_global, "PVID");
|
||||||
|
} else {
|
||||||
|
fprintf(fp, " PVID");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (vinfo->flags & BRIDGE_VLAN_INFO_UNTAGGED) {
|
||||||
|
if (jw_global) {
|
||||||
|
start_json_vlan_flags_array(&vlan_flags);
|
||||||
|
jsonw_string(jw_global,
|
||||||
|
"Egress Untagged");
|
||||||
|
} else {
|
||||||
|
fprintf(fp, " Egress Untagged");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (jw_global && vlan_flags) {
|
||||||
|
jsonw_end_array(jw_global);
|
||||||
|
vlan_flags = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (jw_global)
|
||||||
|
jsonw_end_object(jw_global);
|
||||||
|
else
|
||||||
|
fprintf(fp, "\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int do_vlan(int argc, char **argv)
|
int do_vlan(int argc, char **argv)
|
||||||
{
|
{
|
||||||
ll_init_map(&rth);
|
ll_init_map(&rth);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user