-/* 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.
+ /* Passed in by rtnetlink_create(). */
+ int multicast_group; /* Multicast group we listen on. */
+ rtnetlink_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)
+{
+ 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;
+}
+
+/* Destroys 'rtn' by freeing any memory it has reserved and closing any sockets
+ * it has opened. */
+void
+rtnetlink_destroy(struct rtnetlink *rtn)
+{
+ if (rtn) {
+ nl_sock_destroy(rtn->notify_sock);
+ free(rtn);
+ }
+}
+
+/* Registers 'cb' to be called with auxiliary data 'aux' with change
+ * notifications. The notifier is stored in 'notifier', which the caller must
+ * not modify or free.