summaryrefslogtreecommitdiff
path: root/src/libsystemd/sd-rtnl/sd-rtnl.c
diff options
context:
space:
mode:
authorTom Gundersen <teg@jklm.no>2014-03-23 21:45:46 +0100
committerTom Gundersen <teg@jklm.no>2014-03-24 16:59:30 +0100
commit3dd215e056ee9ff23175eca66686ff9b7a566dbf (patch)
treeaf3b74f8d0dc50f4f537f5986996264f74ff6c7f /src/libsystemd/sd-rtnl/sd-rtnl.c
parent48791a98be997ed22e8c45a89d8d728a2151c074 (diff)
sd-rtnl: add sd_rtnl_message_enter_container()
Extend rta_offset_tb into a stack of offset tables, one for each parent of the current container, and make sd_rtnl_message_{enter,exit}_container() pop/push to this stack. Also make sd_rtnl_message_rewind() parse the top-level container, and use this when reading a message from the socket. This changes the API by dropping the now redundant sd_rtnl_message_read() method.
Diffstat (limited to 'src/libsystemd/sd-rtnl/sd-rtnl.c')
-rw-r--r--src/libsystemd/sd-rtnl/sd-rtnl.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/src/libsystemd/sd-rtnl/sd-rtnl.c b/src/libsystemd/sd-rtnl/sd-rtnl.c
index a2760d056b..551e95b592 100644
--- a/src/libsystemd/sd-rtnl/sd-rtnl.c
+++ b/src/libsystemd/sd-rtnl/sd-rtnl.c
@@ -190,6 +190,19 @@ sd_rtnl *sd_rtnl_unref(sd_rtnl *rtnl) {
return NULL;
}
+static void rtnl_seal_message(sd_rtnl *rtnl, sd_rtnl_message *m) {
+ assert(rtnl);
+ assert(!rtnl_pid_changed(rtnl));
+ assert(m);
+ assert(m->hdr);
+
+ m->hdr->nlmsg_seq = rtnl->serial++;
+
+ rtnl_message_seal(m);
+
+ return;
+}
+
int sd_rtnl_send(sd_rtnl *nl,
sd_rtnl_message *message,
uint32_t *serial) {
@@ -198,10 +211,9 @@ int sd_rtnl_send(sd_rtnl *nl,
assert_return(nl, -EINVAL);
assert_return(!rtnl_pid_changed(nl), -ECHILD);
assert_return(message, -EINVAL);
+ assert_return(!message->sealed, -EPERM);
- r = rtnl_message_seal(nl, message);
- if (r < 0)
- return r;
+ rtnl_seal_message(nl, message);
if (nl->wqueue_size <= 0) {
/* send directly */
@@ -254,10 +266,8 @@ static int dispatch_rqueue(sd_rtnl *rtnl, sd_rtnl_message **message) {
/* Try to read a new message */
r = socket_read_message(rtnl, &z);
- if (r < 0)
+ if (r <= 0)
return r;
- if (r == 0)
- return 0;
*message = z;