chiark / gitweb /
sd-rtnl: do not blindly enter containers in message_read()
[elogind.git] / src / libsystemd / sd-rtnl / rtnl-message.c
index 27b606593b072cde49f719d17562ce6bce44ae6a..41a6e4ea85a504ec0ebe29c46baeb56c98cb3a25 100644 (file)
@@ -85,6 +85,20 @@ int sd_rtnl_message_route_set_dst_prefixlen(sd_rtnl_message *m, unsigned char pr
         return 0;
 }
 
+int sd_rtnl_message_route_set_scope(sd_rtnl_message *m, unsigned char scope) {
+        struct rtmsg *rtm;
+
+        assert_return(m, -EINVAL);
+        assert_return(m->hdr, -EINVAL);
+        assert_return(rtnl_message_type_is_route(m->hdr->nlmsg_type), -EINVAL);
+
+        rtm = NLMSG_DATA(m->hdr);
+
+        rtm->rtm_scope = scope;
+
+        return 0;
+}
+
 int sd_rtnl_message_new_route(sd_rtnl *rtnl, sd_rtnl_message **ret,
                               uint16_t nlmsg_type, unsigned char rtm_family) {
         struct rtmsg *rtm;
@@ -764,7 +778,7 @@ int sd_rtnl_message_read(sd_rtnl_message *m, unsigned short *type, void **data)
         if (!RTA_OK(NEXT_RTA(m), remaining_size))
                 return 0;
 
-        /* if we read a container, enter it and return its type */
+        /* if we read a container, return its type, but do not enter it*/
         r = sd_rtnl_message_get_type(m, &rtm_type);
         if (r < 0)
                 return r;
@@ -776,14 +790,12 @@ int sd_rtnl_message_read(sd_rtnl_message *m, unsigned short *type, void **data)
               NEXT_RTA(m)->rta_type == IFLA_LINKINFO) ||
              (m->n_containers == 1 &&
               GET_CONTAINER(m, 0)->rta_type == IFLA_LINKINFO &&
-              NEXT_RTA(m)->rta_type == IFLA_INFO_DATA))) {
+              NEXT_RTA(m)->rta_type == IFLA_INFO_DATA)))
                 *data = NULL;
-                PUSH_CONTAINER(m, NEXT_RTA(m));
-                UPDATE_RTA(m, RTA_DATA(NEXT_RTA(m)));
-        } else {
+        else
                 *data = RTA_DATA(NEXT_RTA(m));
-                UPDATE_RTA(m, RTA_NEXT(NEXT_RTA(m), remaining_size));
-        }
+
+        UPDATE_RTA(m, RTA_NEXT(NEXT_RTA(m), remaining_size));
 
         return 1;
 }