From: Ethan Jackson Date: Wed, 24 Aug 2011 22:17:32 +0000 (-0700) Subject: netlink-notifier: Rename rtnetlink code. X-Git-Tag: v1.3.0~361 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=0a811051ffd7f836f66ef770d7a3dcc92ec7d51a;p=sliver-openvswitch.git netlink-notifier: Rename rtnetlink code. This patch renames the rtnetlink module's code to "nln" for "netlink notifier". Callers are now required to pass in the netlink protocol to he newly renamed nln_create() function. --- diff --git a/lib/dpif-linux.c b/lib/dpif-linux.c index 88707d8df..f22970da5 100644 --- a/lib/dpif-linux.c +++ b/lib/dpif-linux.c @@ -138,7 +138,7 @@ struct dpif_linux { /* Change notification. */ struct sset changed_ports; /* Ports that have changed. */ - struct rtnetlink_notifier port_notifier; + struct nln_notifier port_notifier; bool change_error; /* Queue of unused ports. */ diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c index d924cf365..6d44581bf 100644 --- a/lib/netdev-linux.c +++ b/lib/netdev-linux.c @@ -105,7 +105,7 @@ COVERAGE_DEFINE(netdev_ethtool); #define TC_RTAB_SIZE 1024 #endif -static struct rtnetlink_notifier netdev_linux_cache_notifier; +static struct nln_notifier netdev_linux_cache_notifier; static int cache_notifier_refcount; enum { diff --git a/lib/netlink-notifier.c b/lib/netlink-notifier.c index 5635cf882..1b7529dd7 100644 --- a/lib/netlink-notifier.c +++ b/lib/netlink-notifier.c @@ -28,52 +28,55 @@ #include "ofpbuf.h" #include "vlog.h" -VLOG_DEFINE_THIS_MODULE(rtnetlink); +VLOG_DEFINE_THIS_MODULE(netlink_notifier); -COVERAGE_DEFINE(rtnetlink_changed); +COVERAGE_DEFINE(nln_changed); -static void rtnetlink_report(struct rtnetlink *rtn, void *change); +static void nln_report(struct nln *nln, void *change); -struct rtnetlink { - struct nl_sock *notify_sock; /* Rtnetlink socket. */ - struct list all_notifiers; /* All rtnetlink notifiers. */ +struct nln { + struct nl_sock *notify_sock; /* Netlink socket. */ + struct list all_notifiers; /* All nln notifiers. */ bool has_run; /* Guard for run and wait functions. */ - /* Passed in by rtnetlink_create(). */ + /* Passed in by nln_create(). */ int multicast_group; /* Multicast group we listen on. */ - rtnetlink_parse_func *parse; /* Message parsing function. */ + int protocol; /* Protocal passed to nl_sock_create(). */ + nln_parse_func *parse; /* Message parsing function. */ void *change; /* Change passed to parse. */ }; -/* Creates an rtnetlink handle which may be used to manage change - * notifications. The created handle will listen for rtnetlink messages on - * 'multicast_group'. Incoming messages will be parsed with 'parse' which will - * be passed 'change' as an argument. */ -struct rtnetlink * -rtnetlink_create(int multicast_group, rtnetlink_parse_func *parse, - void *change) +/* Creates an nln handle which may be used to manage change notifications. The + * created handle will listen for netlink messages on 'multicast_group' using + * netlink protocol 'protocol' (e.g. NETLINK_ROUTE, NETLINK_GENERIC, ...). + * Incoming messages will be parsed with 'parse' which will be passed 'change' + * as an argument. */ +struct nln * +nln_create(int protocol, int multicast_group, nln_parse_func *parse, + void *change) { - struct rtnetlink *rtn; - - rtn = xzalloc(sizeof *rtn); - rtn->notify_sock = NULL; - rtn->multicast_group = multicast_group; - rtn->parse = parse; - rtn->change = change; - rtn->has_run = false; - - list_init(&rtn->all_notifiers); - return rtn; + struct nln *nln; + + nln = xzalloc(sizeof *nln); + nln->notify_sock = NULL; + nln->protocol = protocol; + nln->multicast_group = multicast_group; + nln->parse = parse; + nln->change = change; + nln->has_run = false; + + list_init(&nln->all_notifiers); + return nln; } -/* Destroys 'rtn' by freeing any memory it has reserved and closing any sockets +/* Destroys 'nln' by freeing any memory it has reserved and closing any sockets * it has opened. */ void -rtnetlink_destroy(struct rtnetlink *rtn) +nln_destroy(struct nln *nln) { - if (rtn) { - nl_sock_destroy(rtn->notify_sock); - free(rtn); + if (nln) { + nl_sock_destroy(nln->notify_sock); + free(nln); } } @@ -86,110 +89,106 @@ rtnetlink_destroy(struct rtnetlink *rtn) * * Returns 0 if successful, otherwise a positive errno value. */ int -rtnetlink_notifier_register(struct rtnetlink *rtn, - struct rtnetlink_notifier *notifier, - rtnetlink_notify_func *cb, void *aux) +nln_notifier_register(struct nln *nln, struct nln_notifier *notifier, + nln_notify_func *cb, void *aux) { - if (!rtn->notify_sock) { + if (!nln->notify_sock) { struct nl_sock *sock; int error; - error = nl_sock_create(NETLINK_ROUTE, &sock); + error = nl_sock_create(nln->protocol, &sock); if (!error) { - error = nl_sock_join_mcgroup(sock, rtn->multicast_group); + error = nl_sock_join_mcgroup(sock, nln->multicast_group); } if (error) { nl_sock_destroy(sock); - VLOG_WARN("could not create rtnetlink socket: %s", - strerror(error)); + VLOG_WARN("could not create netlink socket: %s", strerror(error)); return error; } - rtn->notify_sock = sock; + nln->notify_sock = sock; } else { /* Catch up on notification work so that the new notifier won't * receive any stale notifications. */ - rtnetlink_notifier_run(rtn); + nln_notifier_run(nln); } - list_push_back(&rtn->all_notifiers, ¬ifier->node); + list_push_back(&nln->all_notifiers, ¬ifier->node); notifier->cb = cb; notifier->aux = aux; return 0; } /* Cancels notification on 'notifier', which must have previously been - * registered with rtnetlink_notifier_register(). */ + * registered with nln_notifier_register(). */ void -rtnetlink_notifier_unregister(struct rtnetlink *rtn, - struct rtnetlink_notifier *notifier) +nln_notifier_unregister(struct nln *nln, struct nln_notifier *notifier) { list_remove(¬ifier->node); - if (list_is_empty(&rtn->all_notifiers)) { - nl_sock_destroy(rtn->notify_sock); - rtn->notify_sock = NULL; + if (list_is_empty(&nln->all_notifiers)) { + nl_sock_destroy(nln->notify_sock); + nln->notify_sock = NULL; } } /* Calls all of the registered notifiers, passing along any as-yet-unreported * change events. */ void -rtnetlink_notifier_run(struct rtnetlink *rtn) +nln_notifier_run(struct nln *nln) { static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5); - if (!rtn->notify_sock || rtn->has_run) { + if (!nln->notify_sock || nln->has_run) { return; } - rtn->has_run = true; + nln->has_run = true; for (;;) { struct ofpbuf *buf; int error; - error = nl_sock_recv(rtn->notify_sock, &buf, false); + error = nl_sock_recv(nln->notify_sock, &buf, false); if (!error) { - if (rtn->parse(buf, rtn->change)) { - rtnetlink_report(rtn, rtn->change); + if (nln->parse(buf, nln->change)) { + nln_report(nln, nln->change); } else { - VLOG_WARN_RL(&rl, "received bad rtnl message"); - rtnetlink_report(rtn, NULL); + VLOG_WARN_RL(&rl, "received bad netlink message"); + nln_report(nln, NULL); } ofpbuf_delete(buf); } else if (error == EAGAIN) { return; } else { if (error == ENOBUFS) { - VLOG_WARN_RL(&rl, "rtnetlink receive buffer overflowed"); + VLOG_WARN_RL(&rl, "netlink receive buffer overflowed"); } else { - VLOG_WARN_RL(&rl, "error reading rtnetlink socket: %s", + VLOG_WARN_RL(&rl, "error reading netlink socket: %s", strerror(error)); } - rtnetlink_report(rtn, NULL); + nln_report(nln, NULL); } } } /* Causes poll_block() to wake up when change notifications are ready. */ void -rtnetlink_notifier_wait(struct rtnetlink *rtn) +nln_notifier_wait(struct nln *nln) { - rtn->has_run = false; - if (rtn->notify_sock) { - nl_sock_wait(rtn->notify_sock, POLLIN); + nln->has_run = false; + if (nln->notify_sock) { + nl_sock_wait(nln->notify_sock, POLLIN); } } static void -rtnetlink_report(struct rtnetlink *rtn, void *change) +nln_report(struct nln *nln, void *change) { - struct rtnetlink_notifier *notifier; + struct nln_notifier *notifier; if (change) { - COVERAGE_INC(rtnetlink_changed); + COVERAGE_INC(nln_changed); } - LIST_FOR_EACH (notifier, node, &rtn->all_notifiers) { + LIST_FOR_EACH (notifier, node, &nln->all_notifiers) { notifier->cb(change, notifier->aux); } } - diff --git a/lib/netlink-notifier.h b/lib/netlink-notifier.h index 8d6f2bb10..60b5991b1 100644 --- a/lib/netlink-notifier.h +++ b/lib/netlink-notifier.h @@ -14,46 +14,41 @@ * limitations under the License. */ -#ifndef RTNETLINK_H -#define RTNETLINK_H 1 +#ifndef NETLINK_NOTIFIER_H +#define NETLINK_NOTIFIER_H 1 /* These functions are Linux specific, so they should be used directly only by * Linux-specific code. */ #include "list.h" -struct rtnetlink; +struct nln; struct nlattr; struct ofpbuf; -/* Function called to report rtnetlink notifications. 'change' describes the - * specific change filled out by an rtnetlink_parse_func. It may be null if - * the buffer of change information overflowed, in which case the function must +/* Function called to report netlink notifications. 'change' describes the + * specific change filled out by an nln_parse_func. It may be null if the + * buffer of change information overflowed, in which case the function must * assume that everything may have changed. 'aux' is as specified in - * rtnetlink_notifier_register(). - */ -typedef void rtnetlink_notify_func(const void *change, void *aux); + * nln_notifier_register(). */ +typedef void nln_notify_func(const void *change, void *aux); -/* Function called to parse incoming rtnetlink notifications. The 'buf' - * message should be parsed into 'change' as specified in rtnetlink_create(). - */ -typedef bool rtnetlink_parse_func(struct ofpbuf *buf, void *change); +/* Function called to parse incoming nln notifications. The 'buf' message + * should be parsed into 'change' as specified in nln_create(). */ +typedef bool nln_parse_func(struct ofpbuf *buf, void *change); -struct rtnetlink_notifier { +struct nln_notifier { struct list node; - rtnetlink_notify_func *cb; + nln_notify_func *cb; void *aux; }; -struct rtnetlink *rtnetlink_create(int multicast_group, - rtnetlink_parse_func *, - void *change); -void rtnetlink_destroy(struct rtnetlink *rtn); -int rtnetlink_notifier_register(struct rtnetlink *, - struct rtnetlink_notifier *, - rtnetlink_notify_func *, void *aux); -void rtnetlink_notifier_unregister(struct rtnetlink *, - struct rtnetlink_notifier *); -void rtnetlink_notifier_run(struct rtnetlink *); -void rtnetlink_notifier_wait(struct rtnetlink *); -#endif /* rtnetlink.h */ +struct nln *nln_create(int protocol, int multicast_group, nln_parse_func *, + void *change); +void nln_destroy(struct nln *); +int nln_notifier_register(struct nln *, struct nln_notifier *, + nln_notify_func *, void *aux); +void nln_notifier_unregister(struct nln *, struct nln_notifier *); +void nln_notifier_run(struct nln *); +void nln_notifier_wait(struct nln *); +#endif /* netlink-notifier.h */ diff --git a/lib/route-table.c b/lib/route-table.c index 22d12f7a1..de335f57b 100644 --- a/lib/route-table.c +++ b/lib/route-table.c @@ -67,10 +67,10 @@ struct name_node { static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 20); static unsigned int register_count = 0; -static struct rtnetlink *rtn = NULL; +static struct nln *nln = NULL; static struct route_table_msg rtmsg; -static struct rtnetlink_notifier route_notifier; -static struct rtnetlink_notifier name_notifier; +static struct nln_notifier route_notifier; +static struct nln_notifier name_notifier; static bool route_table_valid = false; static bool name_table_valid = false; @@ -161,16 +161,12 @@ void route_table_register(void) { if (!register_count) { - rtnetlink_parse_func *pf; - rtnetlink_notify_func *nf; + assert(!nln); - assert(!rtn); - - pf = (rtnetlink_parse_func *) route_table_parse; - nf = (rtnetlink_notify_func *) route_table_change; - - rtn = rtnetlink_create(RTNLGRP_IPV4_ROUTE, pf, &rtmsg); - rtnetlink_notifier_register(rtn, &route_notifier, nf, NULL); + nln = nln_create(NETLINK_ROUTE, RTNLGRP_IPV4_ROUTE, + (nln_parse_func *) route_table_parse, &rtmsg); + nln_notifier_register(nln, &route_notifier, + (nln_notify_func *) route_table_change, NULL); hmap_init(&route_map); route_table_reset(); @@ -189,8 +185,8 @@ route_table_unregister(void) register_count--; if (!register_count) { - rtnetlink_destroy(rtn); - rtn = NULL; + nln_destroy(nln); + nln = NULL; route_map_clear(); hmap_destroy(&route_map); @@ -202,9 +198,9 @@ route_table_unregister(void) void route_table_run(void) { - if (rtn) { + if (nln) { rtnetlink_link_notifier_run(); - rtnetlink_notifier_run(rtn); + nln_notifier_run(nln); } } @@ -212,9 +208,9 @@ route_table_run(void) void route_table_wait(void) { - if (rtn) { + if (nln) { rtnetlink_link_notifier_wait(); - rtnetlink_notifier_wait(rtn); + nln_notifier_wait(nln); } } diff --git a/lib/rtnetlink-link.c b/lib/rtnetlink-link.c index 750358581..dbdf724ba 100644 --- a/lib/rtnetlink-link.c +++ b/lib/rtnetlink-link.c @@ -26,7 +26,7 @@ #include "netlink-notifier.h" #include "ofpbuf.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, @@ -87,25 +87,23 @@ rtnetlink_link_parse_cb(struct ofpbuf *buf, void *change) * * Returns 0 if successful, otherwise a positive errno value. */ int -rtnetlink_link_notifier_register(struct rtnetlink_notifier *notifier, +rtnetlink_link_notifier_register(struct nln_notifier *notifier, rtnetlink_link_notify_func *cb, void *aux) { - rtnetlink_notify_func *nf = (rtnetlink_notify_func *) cb; - - if (!rtn) { - rtn = rtnetlink_create(RTNLGRP_LINK, rtnetlink_link_parse_cb, - &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_register(nln, notifier, (nln_notify_func *) cb, aux); } /* Cancels notification on 'notifier', which must have previously been * registered with rtnetlink_link_notifier_register(). */ void -rtnetlink_link_notifier_unregister(struct rtnetlink_notifier *notifier) +rtnetlink_link_notifier_unregister(struct nln_notifier *notifier) { - rtnetlink_notifier_unregister(rtn, notifier); + nln_notifier_unregister(nln, notifier); } /* Calls all of the registered notifiers, passing along any as-yet-unreported @@ -113,8 +111,8 @@ rtnetlink_link_notifier_unregister(struct rtnetlink_notifier *notifier) void rtnetlink_link_notifier_run(void) { - if (rtn) { - rtnetlink_notifier_run(rtn); + if (nln) { + nln_notifier_run(nln); } } @@ -123,7 +121,7 @@ rtnetlink_link_notifier_run(void) void rtnetlink_link_notifier_wait(void) { - if (rtn) { - rtnetlink_notifier_wait(rtn); + if (nln) { + nln_notifier_wait(nln); } } diff --git a/lib/rtnetlink-link.h b/lib/rtnetlink-link.h index c41612d11..1e52a7dc3 100644 --- a/lib/rtnetlink-link.h +++ b/lib/rtnetlink-link.h @@ -20,7 +20,7 @@ #include struct ofpbuf; -struct rtnetlink_notifier; +struct nln_notifier; /* These functions are Linux specific, so they should be used directly only by * Linux-specific code. */ @@ -50,9 +50,9 @@ void rtnetlink_link_notify_func(const struct rtnetlink_link_change *change, bool rtnetlink_link_parse(struct ofpbuf *buf, struct rtnetlink_link_change *change); -int rtnetlink_link_notifier_register(struct rtnetlink_notifier *, +int rtnetlink_link_notifier_register(struct nln_notifier*, rtnetlink_link_notify_func *, void *aux); -void rtnetlink_link_notifier_unregister(struct rtnetlink_notifier *); +void rtnetlink_link_notifier_unregister(struct nln_notifier *); void rtnetlink_link_notifier_run(void); void rtnetlink_link_notifier_wait(void); #endif /* rtnetlink-link.h */ diff --git a/vswitchd/ovs-brcompatd.c b/vswitchd/ovs-brcompatd.c index f42f01b49..41187b171 100644 --- a/vswitchd/ovs-brcompatd.c +++ b/vswitchd/ovs-brcompatd.c @@ -799,7 +799,7 @@ int main(int argc, char *argv[]) { extern struct vlog_module VLM_reconnect; - struct rtnetlink_notifier link_notifier; + struct nln_notifier link_notifier; struct unixctl_server *unixctl; int retval;