#include "connman.h"
-static void parse_link(struct nlmsghdr *hdr)
+static inline void print_char(struct rtattr *attr, const char *name)
{
+ printf(" attr %s (len %d) %s", name, RTA_PAYLOAD(attr),
+ (char *) RTA_DATA(attr));
+}
+
+static inline void print_attr(struct rtattr *attr, const char *name)
+{
+ if (name)
+ printf(" attr %s (len %d)", name, RTA_PAYLOAD(attr));
+ else
+ printf(" attr %d (len %d)", attr->rta_type, RTA_PAYLOAD(attr));
+}
+
+static void rtnl_link(struct nlmsghdr *hdr)
+{
+ struct connman_iface *iface;
struct ifinfomsg *msg;
struct rtattr *attr;
int bytes;
DBG("ifi_index %d ifi_flags %d", msg->ifi_index, msg->ifi_flags);
+ iface = __connman_iface_find(msg->ifi_index);
+ if (iface == NULL)
+ return;
+
+ if ((iface->flags & CONNMAN_IFACE_FLAG_RTNL) == 0)
+ return;
+
for (attr = IFLA_RTA(msg); RTA_OK(attr, bytes);
attr = RTA_NEXT(attr, bytes)) {
- int len = RTA_PAYLOAD(attr);
-
switch (attr->rta_type) {
case IFLA_ADDRESS:
- DBG(" rta_type address len %d", len);
+ print_attr(attr, "address");
break;
case IFLA_BROADCAST:
- DBG(" rta_type broadcast len %d", len);
+ print_attr(attr, "broadcast");
break;
case IFLA_IFNAME:
- DBG(" rta_type ifname %s", (char *) RTA_DATA(attr));
+ print_char(attr, "ifname");
break;
case IFLA_MTU:
- DBG(" rta_type mtu len %d", len);
+ print_attr(attr, "mtu");
break;
case IFLA_LINK:
- DBG(" rta_type link len %d", len);
+ print_attr(attr, "link");
break;
case IFLA_QDISC:
- DBG(" rta_type qdisc len %d", len);
+ print_attr(attr, "qdisc");
break;
case IFLA_STATS:
- DBG(" rta_type stats len %d", len);
+ print_attr(attr, "stats");
break;
case IFLA_COST:
- DBG(" rta_type cost len %d", len);
+ print_attr(attr, "cost");
break;
case IFLA_PRIORITY:
- DBG(" rta_type priority len %d", len);
+ print_attr(attr, "priority");
break;
case IFLA_MASTER:
- DBG(" rta_type master len %d", len);
+ print_attr(attr, "master");
break;
case IFLA_WIRELESS:
- DBG(" rta_type wireless len %d", len);
- {
- unsigned char *data = RTA_DATA(attr);
- int i;
- for (i = 0; i < len; i++)
- printf(" %02x", data[i]);
- printf("\n");
- }
+ if (iface->driver->rtnl_wireless)
+ iface->driver->rtnl_wireless(iface,
+ RTA_DATA(attr), RTA_PAYLOAD(attr));
break;
case IFLA_PROTINFO:
- DBG(" rta_type protinfo len %d", len);
+ print_attr(attr, "protinfo");
break;
case IFLA_TXQLEN:
- DBG(" rta_type txqlen len %d", len);
+ print_attr(attr, "txqlen");
break;
case IFLA_MAP:
- DBG(" rta_type map len %d", len);
+ print_attr(attr, "map");
break;
case IFLA_WEIGHT:
- DBG(" rta_type widght len %d", len);
+ print_attr(attr, "weight");
break;
case IFLA_OPERSTATE:
- DBG(" rta_type operstate len %d", len);
+ print_attr(attr, "operstate");
break;
case IFLA_LINKMODE:
- DBG(" rta_type linkmode len %d", len);
+ print_attr(attr, "linkmode");
break;
default:
- DBG(" rta_type %d len %d", attr->rta_type, len);
+ print_attr(attr, NULL);
break;
}
}
}
-static void parse_addr(struct nlmsghdr *hdr)
+static void rtnl_addr(struct nlmsghdr *hdr)
{
+ struct connman_iface *iface;
struct ifaddrmsg *msg;
struct rtattr *attr;
int bytes;
DBG("ifa_family %d ifa_index %d", msg->ifa_family, msg->ifa_index);
+ iface = __connman_iface_find(msg->ifa_index);
+ if (iface == NULL)
+ return;
+
+ if ((iface->flags & CONNMAN_IFACE_FLAG_RTNL) == 0)
+ return;
+
for (attr = IFA_RTA(msg); RTA_OK(attr, bytes);
attr = RTA_NEXT(attr, bytes)) {
- int len = RTA_PAYLOAD(attr);
-
switch (attr->rta_type) {
case IFA_ADDRESS:
- DBG(" rta_type address len %d", len);
+ print_attr(attr, "address");
if (msg->ifa_family == AF_INET) {
struct in_addr addr;
addr = *((struct in_addr *) RTA_DATA(attr));
}
break;
case IFA_LOCAL:
- DBG(" rta_type local len %d", len);
+ print_attr(attr, "local");
if (msg->ifa_family == AF_INET) {
struct in_addr addr;
addr = *((struct in_addr *) RTA_DATA(attr));
}
break;
case IFA_LABEL:
- DBG(" rta_type label %s", (char *) RTA_DATA(attr));
+ print_char(attr, "label");
break;
case IFA_BROADCAST:
- DBG(" rta_type broadcast len %d", len);
+ print_attr(attr, "broadcast");
if (msg->ifa_family == AF_INET) {
struct in_addr addr;
addr = *((struct in_addr *) RTA_DATA(attr));
}
break;
case IFA_ANYCAST:
- DBG(" rta_type anycast len %d", len);
+ print_attr(attr, "anycast");
break;
case IFA_CACHEINFO:
- DBG(" rta_type cacheinfo len %d", len);
+ print_attr(attr, "cacheinfo");
break;
case IFA_MULTICAST:
- DBG(" rta_type multicast len %d", len);
+ print_attr(attr, "multicast");
break;
default:
- DBG(" rta_type %d len %d", attr->rta_type, len);
+ print_attr(attr, NULL);
break;
}
}
}
-static void parse_route(struct nlmsghdr *hdr)
+static void rtnl_route(struct nlmsghdr *hdr)
{
struct rtmsg *msg;
struct rtattr *attr;
for (attr = RTM_RTA(msg); RTA_OK(attr, bytes);
attr = RTA_NEXT(attr, bytes)) {
- int len = RTA_PAYLOAD(attr);
-
switch (attr->rta_type) {
case RTA_DST:
- DBG(" rta_type dst len %d", len);
+ print_attr(attr, "dst");
if (msg->rtm_family == AF_INET) {
struct in_addr addr;
addr = *((struct in_addr *) RTA_DATA(attr));
}
break;
case RTA_SRC:
- DBG(" rta_type src len %d", len);
+ print_attr(attr, "src");
if (msg->rtm_family == AF_INET) {
struct in_addr addr;
addr = *((struct in_addr *) RTA_DATA(attr));
}
break;
case RTA_IIF:
- DBG(" rta_type iff len %d", len);
+ print_char(attr, "iif");
break;
case RTA_OIF:
- DBG(" rta_type oif len %d", len);
+ print_attr(attr, "oif");
break;
case RTA_GATEWAY:
- DBG(" rta_type gateway len %d", len);
+ print_attr(attr, "gateway");
if (msg->rtm_family == AF_INET) {
struct in_addr addr;
addr = *((struct in_addr *) RTA_DATA(attr));
}
break;
case RTA_PRIORITY:
- DBG(" rta_type priority len %d", len);
+ print_attr(attr, "priority");
break;
case RTA_PREFSRC:
- DBG(" rta_type prefsrc len %d", len);
+ print_attr(attr, "prefsrc");
if (msg->rtm_family == AF_INET) {
struct in_addr addr;
addr = *((struct in_addr *) RTA_DATA(attr));
}
break;
case RTA_METRICS:
- DBG(" rta_type metrics len %d", len);
+ print_attr(attr, "metrics");
break;
case RTA_TABLE:
- DBG(" rta_type table len %d", len);
+ print_attr(attr, "table");
break;
default:
- DBG(" rta_type %d len %d", attr->rta_type, len);
+ print_attr(attr, NULL);
break;
}
}
}
-static void parse_message(unsigned char *buf, size_t size)
+static void rtnl_message(unsigned char *buf, size_t size)
{
struct nlmsghdr *hdr = (void *) buf;
switch (hdr->nlmsg_type) {
case NLMSG_DONE:
- DBG("nlmsg_type done");
+ DBG("done");
return;
case NLMSG_NOOP:
- DBG("nlmsg_type noop");
+ DBG("noop");
return;
case NLMSG_OVERRUN:
- DBG("nlmsg_type overrun");
+ DBG("overrun");
return;
case NLMSG_ERROR:
- DBG("nlmsg_type error");
+ DBG("error");
return;
case RTM_NEWLINK:
- DBG("nlmsg_type RTM_NEWLINK");
- parse_link(hdr);
+ rtnl_link(hdr);
break;
case RTM_DELLINK:
- DBG("nlmsg_type RTM_DELLINK");
- parse_link(hdr);
+ rtnl_link(hdr);
break;
case RTM_NEWADDR:
- DBG("nlmsg_type RTM_NEWADDR");
- parse_addr(hdr);
+ rtnl_addr(hdr);
break;
case RTM_DELADDR:
- DBG("nlmsg_type RTM_DELADDR");
- parse_addr(hdr);
+ rtnl_addr(hdr);
break;
case RTM_NEWROUTE:
- DBG("nlmsg_type RTM_NEWROUTE");
- parse_route(hdr);
+ rtnl_route(hdr);
break;
case RTM_DELROUTE:
- DBG("nlmsg_type RTM_DELROUTE");
- parse_route(hdr);
+ rtnl_route(hdr);
break;
default:
- DBG("nlmsg_type %d", hdr->nlmsg_type);
+ DBG("type %d", hdr->nlmsg_type);
break;
}
}
return FALSE;
}
- parse_message(buf, len);
+ rtnl_message(buf, len);
return TRUE;
}
memset(&addr, 0, sizeof(addr));
addr.nl_family = AF_NETLINK;
- addr.nl_groups = RTMGRP_LINK | RTMGRP_IPV4_IFADDR | RTMGRP_IPV4_ROUTE;
+ addr.nl_groups = RTMGRP_LINK;
+ //addr.nl_groups = RTMGRP_LINK | RTMGRP_IPV4_IFADDR | RTMGRP_IPV4_ROUTE;
addr.nl_pid = getpid();
if (bind(sk, (struct sockaddr *) &addr, sizeof(addr)) < 0) {