]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
VLAN: Clean up RTM_NEW/DELLINK processing
authorJouni Malinen <jouni@qca.qualcomm.com>
Wed, 11 Feb 2015 08:29:52 +0000 (10:29 +0200)
committerJouni Malinen <j@w1.fi>
Wed, 11 Feb 2015 08:31:12 +0000 (10:31 +0200)
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>
src/ap/vlan_init.c

index 2af2cbce0dac0c0d428490c48010668f8a36c08b..dc6501997db03c80550ad5fc2fc3dd63ddb9c3fa 100644 (file)
@@ -617,6 +617,7 @@ vlan_read_ifnames(struct nlmsghdr *h, size_t len, int del,
        struct ifinfomsg *ifi;
        int attrlen, nlmsg_len, rta_len;
        struct rtattr *attr;
+       char ifname[IFNAMSIZ + 1];
 
        if (len < sizeof(*ifi))
                return;
@@ -631,29 +632,39 @@ vlan_read_ifnames(struct nlmsghdr *h, size_t len, int del,
 
        attr = (struct rtattr *) (((char *) ifi) + nlmsg_len);
 
+       os_memset(ifname, 0, sizeof(ifname));
        rta_len = RTA_ALIGN(sizeof(struct rtattr));
        while (RTA_OK(attr, attrlen)) {
-               char ifname[IFNAMSIZ + 1];
-
                if (attr->rta_type == IFLA_IFNAME) {
                        int n = attr->rta_len - rta_len;
                        if (n < 0)
                                break;
 
-                       os_memset(ifname, 0, sizeof(ifname));
-
-                       if ((size_t) n > sizeof(ifname))
-                               n = sizeof(ifname);
+                       if ((size_t) n >= sizeof(ifname))
+                               n = sizeof(ifname) - 1;
                        os_memcpy(ifname, ((char *) attr) + rta_len, n);
 
-                       if (del)
-                               vlan_dellink(ifname, hapd);
-                       else
-                               vlan_newlink(ifname, hapd);
                }
 
                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)
+               vlan_dellink(ifname, hapd);
+       else
+               vlan_newlink(ifname, hapd);
 }
 
 
@@ -677,7 +688,7 @@ static void vlan_event_receive(int sock, void *eloop_ctx, void *sock_ctx)
        }
 
        h = (struct nlmsghdr *) buf;
-       while (left >= (int) sizeof(*h)) {
+       while (NLMSG_OK(h, left)) {
                int len, plen;
 
                len = h->nlmsg_len;
@@ -698,9 +709,7 @@ static void vlan_event_receive(int sock, void *eloop_ctx, void *sock_ctx)
                        break;
                }
 
-               len = NLMSG_ALIGN(len);
-               left -= len;
-               h = (struct nlmsghdr *) ((char *) h + len);
+               h = NLMSG_NEXT(h, left);
        }
 
        if (left > 0) {