VLAN: Clean up RTM_NEW/DELLINK processing

This uses couple of additional helper macros and prints more debug
information to make the VLAN events easier to analyze.

Signed-off-by: Jouni Malinen <jouni@qca.qualcomm.com>
This commit is contained in:
Jouni Malinen 2015-02-11 10:29:52 +02:00 committed by Jouni Malinen
parent 47e5fbde44
commit eeb1cb28a2

View File

@ -617,6 +617,7 @@ vlan_read_ifnames(struct nlmsghdr *h, size_t len, int del,
struct ifinfomsg *ifi; struct ifinfomsg *ifi;
int attrlen, nlmsg_len, rta_len; int attrlen, nlmsg_len, rta_len;
struct rtattr *attr; struct rtattr *attr;
char ifname[IFNAMSIZ + 1];
if (len < sizeof(*ifi)) if (len < sizeof(*ifi))
return; return;
@ -631,29 +632,39 @@ vlan_read_ifnames(struct nlmsghdr *h, size_t len, int del,
attr = (struct rtattr *) (((char *) ifi) + nlmsg_len); attr = (struct rtattr *) (((char *) ifi) + nlmsg_len);
os_memset(ifname, 0, sizeof(ifname));
rta_len = RTA_ALIGN(sizeof(struct rtattr)); rta_len = RTA_ALIGN(sizeof(struct rtattr));
while (RTA_OK(attr, attrlen)) { while (RTA_OK(attr, attrlen)) {
char ifname[IFNAMSIZ + 1];
if (attr->rta_type == IFLA_IFNAME) { if (attr->rta_type == IFLA_IFNAME) {
int n = attr->rta_len - rta_len; int n = attr->rta_len - rta_len;
if (n < 0) if (n < 0)
break; break;
os_memset(ifname, 0, sizeof(ifname)); if ((size_t) n >= sizeof(ifname))
n = sizeof(ifname) - 1;
if ((size_t) n > sizeof(ifname))
n = sizeof(ifname);
os_memcpy(ifname, ((char *) attr) + rta_len, n); os_memcpy(ifname, ((char *) attr) + rta_len, n);
}
attr = RTA_NEXT(attr, attrlen);
}
if (!ifname[0])
return;
wpa_printf(MSG_DEBUG,
"VLAN: RTM_%sLINK: ifi_index=%d ifname=%s ifi_family=%d ifi_flags=0x%x (%s%s%s%s)",
del ? "DEL" : "NEW",
ifi->ifi_index, ifname, ifi->ifi_family, ifi->ifi_flags,
(ifi->ifi_flags & IFF_UP) ? "[UP]" : "",
(ifi->ifi_flags & IFF_RUNNING) ? "[RUNNING]" : "",
(ifi->ifi_flags & IFF_LOWER_UP) ? "[LOWER_UP]" : "",
(ifi->ifi_flags & IFF_DORMANT) ? "[DORMANT]" : "");
if (del) if (del)
vlan_dellink(ifname, hapd); vlan_dellink(ifname, hapd);
else else
vlan_newlink(ifname, hapd); vlan_newlink(ifname, hapd);
}
attr = RTA_NEXT(attr, attrlen);
}
} }
@ -677,7 +688,7 @@ static void vlan_event_receive(int sock, void *eloop_ctx, void *sock_ctx)
} }
h = (struct nlmsghdr *) buf; h = (struct nlmsghdr *) buf;
while (left >= (int) sizeof(*h)) { while (NLMSG_OK(h, left)) {
int len, plen; int len, plen;
len = h->nlmsg_len; len = h->nlmsg_len;
@ -698,9 +709,7 @@ static void vlan_event_receive(int sock, void *eloop_ctx, void *sock_ctx)
break; break;
} }
len = NLMSG_ALIGN(len); h = NLMSG_NEXT(h, left);
left -= len;
h = (struct nlmsghdr *) ((char *) h + len);
} }
if (left > 0) { if (left > 0) {