X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=lib%2Frtnetlink-link.c;h=1c12562c5af7437cc24d32ec46b49e719b96854a;hb=7d78f21c057ff50a823220d809ac38c3d907243c;hp=09ba954ed92cb6aa7e5d69bfd9b6a14fad85ad9a;hpb=ac4d3bcb46fa0acd0b63f79449432df28569f74f;p=sliver-openvswitch.git diff --git a/lib/rtnetlink-link.c b/lib/rtnetlink-link.c index 09ba954ed..1c12562c5 100644 --- a/lib/rtnetlink-link.c +++ b/lib/rtnetlink-link.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2010 Nicira Networks. + * Copyright (c) 2009, 2010, 2013 Nicira, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,10 +23,10 @@ #include #include "netlink.h" +#include "netlink-notifier.h" #include "ofpbuf.h" -#include "rtnetlink.h" -static struct rtnetlink *rtn = NULL; +static struct nln *nln = NULL; static struct rtnetlink_link_change rtn_change; /* Parses a rtnetlink message 'buf' into 'change'. If 'buf' is unparseable, @@ -45,9 +45,11 @@ rtnetlink_link_parse(struct ofpbuf *buf, static const struct nl_policy policy[] = { [IFLA_IFNAME] = { .type = NL_A_STRING, .optional = false }, [IFLA_MASTER] = { .type = NL_A_U32, .optional = true }, + [IFLA_MTU] = { .type = NL_A_U32, .optional = true }, + [IFLA_ADDRESS] = { .type = NL_A_UNSPEC, .optional = true }, }; - static struct nlattr *attrs[ARRAY_SIZE(policy)]; + struct nlattr *attrs[ARRAY_SIZE(policy)]; parsed = nl_policy_parse(buf, NLMSG_HDRLEN + sizeof(struct ifinfomsg), policy, attrs, ARRAY_SIZE(policy)); @@ -56,21 +58,37 @@ rtnetlink_link_parse(struct ofpbuf *buf, const struct nlmsghdr *nlmsg; const struct ifinfomsg *ifinfo; - nlmsg = buf->data; - ifinfo = ((const struct ifinfomsg *) - ((const char *) buf->data + NLMSG_HDRLEN)); + nlmsg = ofpbuf_data(buf); + ifinfo = ofpbuf_at(buf, NLMSG_HDRLEN, sizeof *ifinfo); change->nlmsg_type = nlmsg->nlmsg_type; change->ifi_index = ifinfo->ifi_index; change->ifname = nl_attr_get_string(attrs[IFLA_IFNAME]); + change->ifi_flags = ifinfo->ifi_flags; change->master_ifindex = (attrs[IFLA_MASTER] ? nl_attr_get_u32(attrs[IFLA_MASTER]) : 0); + change->mtu = (attrs[IFLA_MTU] + ? nl_attr_get_u32(attrs[IFLA_MTU]) + : 0); + + if (attrs[IFLA_ADDRESS] && + nl_attr_get_size(attrs[IFLA_ADDRESS]) == ETH_ALEN) { + memcpy(change->addr, nl_attr_get(attrs[IFLA_ADDRESS]), ETH_ALEN); + } else { + memset(change->addr, 0, ETH_ALEN); + } } return parsed; } +static bool +rtnetlink_link_parse_cb(struct ofpbuf *buf, void *change) +{ + return rtnetlink_link_parse(buf, change); +} + /* Registers 'cb' to be called with auxiliary data 'aux' with network device * change notifications. The notifier is stored in 'notifier', which the * caller must not modify or free. @@ -79,45 +97,42 @@ rtnetlink_link_parse(struct ofpbuf *buf, * using dpif_port_poll() or netdev_change_seq(), which unlike this function * are not Linux-specific. * - * Returns 0 if successful, otherwise a positive errno value. */ -int -rtnetlink_link_notifier_register(struct rtnetlink_notifier *notifier, - rtnetlink_link_notify_func *cb, void *aux) + * Returns an initialized nln_notifier if successful, NULL otherwise. */ +struct nln_notifier * +rtnetlink_link_notifier_create(rtnetlink_link_notify_func *cb, void *aux) { - rtnetlink_parse_func *pf = (rtnetlink_parse_func *) rtnetlink_link_parse; - rtnetlink_notify_func *nf = (rtnetlink_notify_func *) cb; - - if (!rtn) { - rtn = rtnetlink_create(RTNLGRP_LINK, pf, &rtn_change); + if (!nln) { + nln = nln_create(NETLINK_ROUTE, RTNLGRP_LINK, rtnetlink_link_parse_cb, + &rtn_change); } - return rtnetlink_notifier_register(rtn, notifier, nf, aux); + return nln_notifier_create(nln, (nln_notify_func *) cb, aux); } -/* Cancels notification on 'notifier', which must have previously been - * registered with rtnetlink_link_notifier_register(). */ +/* Destroys 'notifier', which must have previously been created with + * rtnetlink_link_notifier_register(). */ void -rtnetlink_link_notifier_unregister(struct rtnetlink_notifier *notifier) +rtnetlink_link_notifier_destroy(struct nln_notifier *notifier) { - rtnetlink_notifier_unregister(rtn, notifier); + nln_notifier_destroy(notifier); } /* Calls all of the registered notifiers, passing along any as-yet-unreported * netdev change events. */ void -rtnetlink_link_notifier_run(void) +rtnetlink_link_run(void) { - if (rtn) { - rtnetlink_notifier_run(rtn); + if (nln) { + nln_run(nln); } } /* Causes poll_block() to wake up when network device change notifications are * ready. */ void -rtnetlink_link_notifier_wait(void) +rtnetlink_link_wait(void) { - if (rtn) { - rtnetlink_notifier_wait(rtn); + if (nln) { + nln_wait(nln); } }