chiark / gitweb /
sd-rtnl: message_open_container - don't take a 'size' argument
authorTom Gundersen <teg@jklm.no>
Fri, 14 Feb 2014 21:39:48 +0000 (22:39 +0100)
committerTom Gundersen <teg@jklm.no>
Sat, 15 Feb 2014 11:14:45 +0000 (12:14 +0100)
We can always know the size based on the type, so let's do this inside the library.

TODO
src/libsystemd/sd-rtnl/rtnl-message.c
src/libsystemd/sd-rtnl/test-rtnl.c
src/network/networkd-netdev.c
src/nspawn/nspawn.c
src/systemd/sd-rtnl.h

diff --git a/TODO b/TODO
index db2c623..299f450 100644 (file)
--- a/TODO
+++ b/TODO
@@ -648,7 +648,6 @@ Features:
 * networkd:
    - add more keys to [Route] and [Address] sections
    - add support for more DHCPv4 options (and, longer term, other kinds of dynamic config)
-   - allow opting out of receiving DNS servers over DHCPv4
    - add proper initrd support (in particular generate .network/.link files based on /proc/cmdline)
 
 External:
index 226329f..096a322 100644 (file)
@@ -699,7 +699,7 @@ int sd_rtnl_message_append_ether_addr(sd_rtnl_message *m, unsigned short type, c
         return 0;
 }
 
-int sd_rtnl_message_open_container(sd_rtnl_message *m, unsigned short type, size_t extra) {
+int sd_rtnl_message_open_container(sd_rtnl_message *m, unsigned short type) {
         uint16_t rtm_type;
 
         assert_return(m, -EINVAL);
@@ -710,9 +710,13 @@ int sd_rtnl_message_open_container(sd_rtnl_message *m, unsigned short type, size
         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) ||
-                    (type == VETH_INFO_PEER && m->n_containers == 2 && GET_CONTAINER(m, 1)->rta_type == IFLA_INFO_DATA))
-                        return add_rtattr(m, type, NULL, extra);
+                    (type == IFLA_INFO_DATA && m->n_containers == 1 &&
+                     GET_CONTAINER(m, 0)->rta_type == IFLA_LINKINFO))
+                        return add_rtattr(m, type, NULL, 0);
+                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 -ENOTSUP;
index 9de3806..53efed5 100644 (file)
@@ -287,11 +287,11 @@ static void test_container(void) {
 
         assert(sd_rtnl_message_new_link(RTM_NEWLINK, 0, &m) >= 0);
 
-        assert(sd_rtnl_message_open_container(m, IFLA_LINKINFO, 0) >= 0);
-        assert(sd_rtnl_message_open_container(m, IFLA_LINKINFO, 0) == -ENOTSUP);
+        assert(sd_rtnl_message_open_container(m, IFLA_LINKINFO) >= 0);
+        assert(sd_rtnl_message_open_container(m, IFLA_LINKINFO) == -ENOTSUP);
         assert(sd_rtnl_message_append_string(m, IFLA_INFO_KIND, "kind") >= 0);
-        assert(sd_rtnl_message_open_container(m, IFLA_INFO_DATA, 0) >= 0);
-        assert(sd_rtnl_message_open_container(m, IFLA_INFO_DATA, 0) == -ENOTSUP);
+        assert(sd_rtnl_message_open_container(m, IFLA_INFO_DATA) >= 0);
+        assert(sd_rtnl_message_open_container(m, IFLA_INFO_DATA) == -ENOTSUP);
         assert(sd_rtnl_message_append_u16(m, IFLA_VLAN_ID, 100) >= 0);
         assert(sd_rtnl_message_close_container(m) >= 0);
         assert(sd_rtnl_message_append_string(m, IFLA_INFO_KIND, "kind") >= 0);
index a452e0d..30eb77d 100644 (file)
@@ -194,7 +194,7 @@ static int netdev_create(NetDev *netdev, Link *link, sd_rtnl_message_handler_t c
                 return r;
         }
 
-        r = sd_rtnl_message_open_container(req, IFLA_LINKINFO, 0);
+        r = sd_rtnl_message_open_container(req, IFLA_LINKINFO);
         if (r < 0) {
                 log_error_netdev(netdev,
                                  "Could not open IFLA_LINKINFO container: %s",
@@ -217,7 +217,7 @@ static int netdev_create(NetDev *netdev, Link *link, sd_rtnl_message_handler_t c
         }
 
         if (netdev->vlanid <= VLANID_MAX) {
-                r = sd_rtnl_message_open_container(req, IFLA_INFO_DATA, 0);
+                r = sd_rtnl_message_open_container(req, IFLA_INFO_DATA);
                 if (r < 0) {
                         log_error_netdev(netdev,
                                          "Could not open IFLA_INFO_DATA container: %s",
index 51a1a66..fcc0f17 100644 (file)
@@ -1303,7 +1303,7 @@ static int setup_veth(int netns_fd) {
                 return r;
         }
 
-        r = sd_rtnl_message_open_container(m, IFLA_LINKINFO, 0);
+        r = sd_rtnl_message_open_container(m, IFLA_LINKINFO);
         if (r < 0) {
                 log_error("Failed to open netlink container: %s", strerror(-r));
                 return r;
@@ -1315,13 +1315,13 @@ static int setup_veth(int netns_fd) {
                 return r;
         }
 
-        r = sd_rtnl_message_open_container(m, IFLA_INFO_DATA, 0);
+        r = sd_rtnl_message_open_container(m, IFLA_INFO_DATA);
         if (r < 0) {
                 log_error("Failed to open netlink container: %s", strerror(-r));
                 return r;
         }
 
-        r = sd_rtnl_message_open_container(m, VETH_INFO_PEER, sizeof(struct ifinfomsg));
+        r = sd_rtnl_message_open_container(m, VETH_INFO_PEER);
         if (r < 0) {
                 log_error("z Failed to open netlink container: %s", strerror(-r));
                 return r;
index 93edbcb..5506bfa 100644 (file)
@@ -102,7 +102,7 @@ int sd_rtnl_message_append_in_addr(sd_rtnl_message *m, unsigned short type, cons
 int sd_rtnl_message_append_in6_addr(sd_rtnl_message *m, unsigned short type, const struct in6_addr *data);
 int sd_rtnl_message_append_ether_addr(sd_rtnl_message *m, unsigned short type, const struct ether_addr *data);
 
-int sd_rtnl_message_open_container(sd_rtnl_message *m, unsigned short type, size_t extra);
+int sd_rtnl_message_open_container(sd_rtnl_message *m, unsigned short type);
 int sd_rtnl_message_close_container(sd_rtnl_message *m);
 
 int sd_rtnl_message_read(sd_rtnl_message *m, unsigned short *type, void **data);