X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=lib%2Frtnetlink-link.c;h=0a40ceaf9c8bfbb5569f4b6de3430439b35dcc3a;hb=ce27cbee00fa713c419d5fd5f7dece469f41c0a7;hp=ffd615bfaf2e79a44088fea5c61f3c5cfd67a0db;hpb=21d6e22eeec05a1c382178dc2eb840afe3b9cca6;p=openvswitch diff --git a/lib/rtnetlink-link.c b/lib/rtnetlink-link.c index ffd615bf..0a40ceaf 100644 --- a/lib/rtnetlink-link.c +++ b/lib/rtnetlink-link.c @@ -23,13 +23,16 @@ #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; -static bool +/* Parses a rtnetlink message 'buf' into 'change'. If 'buf' is unparseable, + * leaves 'change' untouched and returns false. Otherwise, populates 'change' + * and returns true. */ +bool rtnetlink_link_parse(struct ofpbuf *buf, struct rtnetlink_link_change *change) { @@ -68,53 +71,56 @@ rtnetlink_link_parse(struct ofpbuf *buf, 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. * * This is probably not the function that you want. You should probably be - * using dpif_port_poll() or netdev_monitor_create(), which unlike this - * function are not Linux-specific. + * 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); } }