aboutsummaryrefslogtreecommitdiffstats
path: root/src/drivers/netlink.c
diff options
context:
space:
mode:
authorJouni Malinen <j@w1.fi>2009-12-18 15:49:07 (GMT)
committerJouni Malinen <j@w1.fi>2009-12-18 15:49:07 (GMT)
commit62d680c3cabb860a31bec4e044d6cc9309449a80 (patch)
treeb464cae415ce44ff1c90fbd5e2ede00887c6d568 /src/drivers/netlink.c
parentf37cf89ccb4f9c8a74ba8979f60bf3979f44d87e (diff)
downloadhostap-62d680c3cabb860a31bec4e044d6cc9309449a80.zip
hostap-62d680c3cabb860a31bec4e044d6cc9309449a80.tar.gz
hostap-62d680c3cabb860a31bec4e044d6cc9309449a80.tar.bz2
netlink: Move more of the newlink/dellink parsing into shared code
Diffstat (limited to 'src/drivers/netlink.c')
-rw-r--r--src/drivers/netlink.c27
1 files changed, 17 insertions, 10 deletions
diff --git a/src/drivers/netlink.c b/src/drivers/netlink.c
index a788e0b..ad15b1d 100644
--- a/src/drivers/netlink.c
+++ b/src/drivers/netlink.c
@@ -26,6 +26,19 @@ struct netlink_data {
};
+static void netlink_receive_link(struct netlink_data *netlink,
+ void (*cb)(void *ctx, struct ifinfomsg *ifi,
+ u8 *buf, size_t len),
+ struct nlmsghdr *h)
+{
+ if (cb == NULL || NLMSG_PAYLOAD(h, 0) < sizeof(struct ifinfomsg))
+ return;
+ cb(netlink->cfg->ctx, NLMSG_DATA(h),
+ NLMSG_DATA(h) + NLMSG_ALIGN(sizeof(struct ifinfomsg)),
+ NLMSG_PAYLOAD(h, sizeof(struct ifinfomsg)));
+}
+
+
static void netlink_receive(int sock, void *eloop_ctx, void *sock_ctx)
{
struct netlink_data *netlink = eloop_ctx;
@@ -49,20 +62,14 @@ try_again:
h = (struct nlmsghdr *) buf;
while (NLMSG_OK(h, left)) {
- int plen;
-
- plen = h->nlmsg_len - sizeof(*h);
-
switch (h->nlmsg_type) {
case RTM_NEWLINK:
- if (netlink->cfg->newlink_cb)
- netlink->cfg->newlink_cb(netlink->cfg->ctx,
- h, plen);
+ netlink_receive_link(netlink, netlink->cfg->newlink_cb,
+ h);
break;
case RTM_DELLINK:
- if (netlink->cfg->dellink_cb)
- netlink->cfg->dellink_cb(netlink->cfg->ctx,
- h, plen);
+ netlink_receive_link(netlink, netlink->cfg->dellink_cb,
+ h);
break;
}