X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=lib%2Frtnetlink-link.c;h=0b3710fb2d8735d1fa65c54f1fcd021ae15e8062;hb=9d232a6d578e1283c543b0a40f5915e39813ac21;hp=dbdf724ba30ad1abd4a7abcaa269699ecc2aef23;hpb=0a811051ffd7f836f66ef770d7a3dcc92ec7d51a;p=openvswitch diff --git a/lib/rtnetlink-link.c b/lib/rtnetlink-link.c index dbdf724b..0b3710fb 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 Nicira, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -45,6 +45,8 @@ 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)]; @@ -63,9 +65,20 @@ rtnetlink_link_parse(struct ofpbuf *buf, 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; @@ -85,43 +98,42 @@ rtnetlink_link_parse_cb(struct ofpbuf *buf, void *change) * 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 nln_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) { if (!nln) { nln = nln_create(NETLINK_ROUTE, RTNLGRP_LINK, rtnetlink_link_parse_cb, &rtn_change); } - return nln_notifier_register(nln, notifier, (nln_notify_func *) cb, 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 nln_notifier *notifier) +rtnetlink_link_notifier_destroy(struct nln_notifier *notifier) { - nln_notifier_unregister(nln, 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 (nln) { - nln_notifier_run(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 (nln) { - nln_notifier_wait(nln); + nln_wait(nln); } }