summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Gundersen <teg@jklm.no>2014-05-10 19:38:32 +0200
committerTom Gundersen <teg@jklm.no>2014-05-10 20:56:37 +0200
commit897e184c7d54156357fd204beafe06ab9bd0341a (patch)
tree5eb46a4155f02af130eefc56d61e23c6feabe900 /src
parent389cc5f74368a18fd5991e4647e7ba86319c473f (diff)
rtnl: change from bitmask to enum for rtnl groups
The bitmask is deprecated in the kernel, so move to the new interface. At the moment this does not make a difference for us, but it avoids having to change the API in the future.
Diffstat (limited to 'src')
-rw-r--r--src/libsystemd/sd-rtnl/sd-rtnl.c27
-rw-r--r--src/network/networkd-manager.c3
-rw-r--r--src/systemd/sd-rtnl.h2
3 files changed, 28 insertions, 4 deletions
diff --git a/src/libsystemd/sd-rtnl/sd-rtnl.c b/src/libsystemd/sd-rtnl/sd-rtnl.c
index 543bad9f4f..4ee360c0a8 100644
--- a/src/libsystemd/sd-rtnl/sd-rtnl.c
+++ b/src/libsystemd/sd-rtnl/sd-rtnl.c
@@ -75,8 +75,27 @@ static bool rtnl_pid_changed(sd_rtnl *rtnl) {
return rtnl->original_pid != getpid();
}
-int sd_rtnl_open(sd_rtnl **ret, uint32_t groups) {
+static int rtnl_compute_groups_ap(uint32_t *_groups, unsigned n_groups, va_list ap) {
+ uint32_t groups = 0;
+ unsigned i;
+
+ for (i = 0; i < n_groups; i++) {
+ unsigned group;
+
+ group = va_arg(ap, unsigned);
+ assert_return(group < 32, -EINVAL);
+
+ groups |= group ? (1 << (group - 1)) : 0;
+ }
+
+ *_groups = groups;
+
+ return 0;
+}
+
+int sd_rtnl_open(sd_rtnl **ret, unsigned n_groups, ...) {
_cleanup_rtnl_unref_ sd_rtnl *rtnl = NULL;
+ va_list ap;
socklen_t addrlen;
int r, one = 1;
@@ -93,7 +112,11 @@ int sd_rtnl_open(sd_rtnl **ret, uint32_t groups) {
if (setsockopt(rtnl->fd, SOL_SOCKET, SO_PASSCRED, &one, sizeof(one)) < 0)
return -errno;
- rtnl->sockaddr.nl.nl_groups = groups;
+ va_start(ap, n_groups);
+ r = rtnl_compute_groups_ap(&rtnl->sockaddr.nl.nl_groups, n_groups, ap);
+ va_end(ap);
+ if (r < 0)
+ return r;
addrlen = sizeof(rtnl->sockaddr);
diff --git a/src/network/networkd-manager.c b/src/network/networkd-manager.c
index 0456eef0d3..61be347ebf 100644
--- a/src/network/networkd-manager.c
+++ b/src/network/networkd-manager.c
@@ -91,7 +91,8 @@ int manager_new(Manager **ret) {
sd_event_set_watchdog(m->event, true);
- r = sd_rtnl_open(&m->rtnl, RTMGRP_LINK | RTMGRP_IPV4_IFADDR);
+ r = sd_rtnl_open(&m->rtnl, 3, RTNLGRP_LINK, RTNLGRP_IPV4_IFADDR,
+ RTNLGRP_IPV6_IFADDR);
if (r < 0)
return r;
diff --git a/src/systemd/sd-rtnl.h b/src/systemd/sd-rtnl.h
index 9059ed4ddf..b5aa634d05 100644
--- a/src/systemd/sd-rtnl.h
+++ b/src/systemd/sd-rtnl.h
@@ -40,7 +40,7 @@ typedef struct sd_rtnl_message sd_rtnl_message;
typedef int (*sd_rtnl_message_handler_t)(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata);
/* bus */
-int sd_rtnl_open(sd_rtnl **nl, uint32_t groups);
+int sd_rtnl_open(sd_rtnl **nl, unsigned n_groups, ...);
sd_rtnl *sd_rtnl_ref(sd_rtnl *nl);
sd_rtnl *sd_rtnl_unref(sd_rtnl *nl);