chiark / gitweb /
sd-rtnl: always include linux/rtnetlink.h
[elogind.git] / src / libsystemd / sd-rtnl / rtnl-message.c
index 625d54a72aeffdfb9b5a6b59042ff96e0bd5c652..15e3247aca90dff62178320b78a8c3d7f5647664 100644 (file)
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
-#include <linux/rtnetlink.h>
 #include <netinet/in.h>
 #include <netinet/ether.h>
 #include <stdbool.h>
 #include <unistd.h>
+#include <linux/veth.h>
 
 #include "util.h"
 #include "refcnt.h"
@@ -32,7 +32,7 @@
 #include "rtnl-util.h"
 #include "rtnl-internal.h"
 
-#define GET_CONTAINER(m, i) (i < (m)->n_containers ? (struct rtattr*)((uint8_t*)(m)->hdr + (m)->container_offsets[i]) : NULL)
+#define GET_CONTAINER(m, i) ((i) < (m)->n_containers ? (struct rtattr*)((uint8_t*)(m)->hdr + (m)->container_offsets[i]) : NULL)
 #define NEXT_RTA(m) ((struct rtattr*)((uint8_t*)(m)->hdr + (m)->next_rta_offset))
 #define UPDATE_RTA(m, new) (m)->next_rta_offset = (uint8_t*)(new) - (uint8_t*)(m)->hdr;
 #define PUSH_CONTAINER(m, new) (m)->container_offsets[(m)->n_containers ++] = (uint8_t*)(new) - (uint8_t*)(m)->hdr;
@@ -81,7 +81,7 @@ int sd_rtnl_message_route_set_dst_prefixlen(sd_rtnl_message *m, unsigned char pr
         return 0;
 }
 
-int sd_rtnl_message_route_new(uint16_t nlmsg_type, unsigned char rtm_family,
+int sd_rtnl_message_new_route(uint16_t nlmsg_type, unsigned char rtm_family,
                               sd_rtnl_message **ret) {
         struct rtmsg *rtm;
         int r;
@@ -118,14 +118,12 @@ int sd_rtnl_message_link_set_flags(sd_rtnl_message *m, unsigned flags, unsigned
         assert_return(m, -EINVAL);
         assert_return(m->hdr, -EINVAL);
         assert_return(rtnl_message_type_is_link(m->hdr->nlmsg_type), -EINVAL);
+        assert_return(change, -EINVAL);
 
         ifi = NLMSG_DATA(m->hdr);
 
         ifi->ifi_flags = flags;
-        if (change)
-                ifi->ifi_change = change;
-        else
-                ifi->ifi_change = 0xffffffff;
+        ifi->ifi_change = change;
 
         return 0;
 }
@@ -144,7 +142,7 @@ int sd_rtnl_message_link_set_type(sd_rtnl_message *m, unsigned type) {
         return 0;
 }
 
-int sd_rtnl_message_link_new(uint16_t nlmsg_type, int index, sd_rtnl_message **ret) {
+int sd_rtnl_message_new_link(uint16_t nlmsg_type, int index, sd_rtnl_message **ret) {
         struct ifinfomsg *ifi;
         int r;
 
@@ -217,7 +215,7 @@ int sd_rtnl_message_addr_set_scope(sd_rtnl_message *m, unsigned char scope) {
         return 0;
 }
 
-int sd_rtnl_message_addr_new(uint16_t nlmsg_type, int index, unsigned char family,
+int sd_rtnl_message_new_addr(uint16_t nlmsg_type, int index, unsigned char family,
                              sd_rtnl_message **ret) {
         struct ifaddrmsg *ifa;
         int r;
@@ -233,6 +231,8 @@ int sd_rtnl_message_addr_new(uint16_t nlmsg_type, int index, unsigned char famil
 
         (*ret)->hdr->nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrmsg));
         (*ret)->hdr->nlmsg_type = nlmsg_type;
+        if (nlmsg_type == RTM_GETADDR && family == AF_INET)
+                (*ret)->hdr->nlmsg_flags |= NLM_F_DUMP;
 
         ifa = NLMSG_DATA((*ret)->hdr);
 
@@ -709,16 +709,18 @@ int sd_rtnl_message_open_container(sd_rtnl_message *m, unsigned short type) {
         sd_rtnl_message_get_type(m, &rtm_type);
 
         if (rtnl_message_type_is_link(rtm_type)) {
+
                 if ((type == IFLA_LINKINFO && m->n_containers == 0) ||
                     (type == IFLA_INFO_DATA && m->n_containers == 1 &&
                      GET_CONTAINER(m, 0)->rta_type == IFLA_LINKINFO))
                         return add_rtattr(m, type, NULL, 0);
-                else
-                        return -ENOTSUP;
-        } else
-                return -ENOTSUP;
+                else if (type == VETH_INFO_PEER && m->n_containers == 2 &&
+                         GET_CONTAINER(m, 1)->rta_type == IFLA_INFO_DATA &&
+                         GET_CONTAINER(m, 0)->rta_type == IFLA_LINKINFO)
+                        return add_rtattr(m, type, NULL, sizeof(struct ifinfomsg));
+        }
 
-        return 0;
+        return -ENOTSUP;
 }
 
 int sd_rtnl_message_close_container(sd_rtnl_message *m) {