chiark / gitweb /
sd-rtnl: add sd_rtnl_message_append_u16()
authorTom Gundersen <teg@jklm.no>
Wed, 22 Jan 2014 13:16:01 +0000 (14:16 +0100)
committerTom Gundersen <teg@jklm.no>
Wed, 22 Jan 2014 16:56:49 +0000 (17:56 +0100)
src/libsystemd/sd-rtnl/rtnl-message.c
src/systemd/sd-rtnl.h

index af8f8cf76286c03502889b7406ca2602b37a3b23..d55c3673a374ede36297908b030b8b4d2912568d 100644 (file)
@@ -404,6 +404,40 @@ int sd_rtnl_message_append_string(sd_rtnl_message *m, unsigned short type, const
         return 0;
 }
 
+int sd_rtnl_message_append_u16(sd_rtnl_message *m, unsigned short type, uint16_t data) {
+        uint16_t rtm_type;
+        int r;
+
+        assert_return(m, -EINVAL);
+
+        r = sd_rtnl_message_get_type(m, &rtm_type);
+        if (r < 0)
+                return r;
+
+        /* check that the type is correct */
+        switch (rtm_type) {
+                case RTM_NEWLINK:
+                case RTM_SETLINK:
+                case RTM_GETLINK:
+                case RTM_DELLINK:
+                        switch (type) {
+                                case IFLA_VLAN_ID:
+                                        break;
+                                default:
+                                        return -ENOTSUP;
+                        }
+                        break;
+                default:
+                        return -ENOTSUP;
+        }
+
+        r = add_rtattr(m, type, &data, sizeof(uint16_t));
+        if (r < 0)
+                return r;
+
+        return 0;
+}
+
 int sd_rtnl_message_append_u32(sd_rtnl_message *m, unsigned short type, uint32_t data) {
         uint16_t rtm_type;
         int r;
index 0feb8c673e32a74e1d2fee0c82487200040a72f8..87a58a98e48d9817e2e94368437ef16cf316e641 100644 (file)
@@ -92,6 +92,7 @@ int sd_rtnl_message_link_get_flags(sd_rtnl_message *m, unsigned *flags);
 int sd_rtnl_message_route_set_dst_prefixlen(sd_rtnl_message *m, unsigned char prefixlen);
 
 int sd_rtnl_message_append_string(sd_rtnl_message *m, unsigned short type, const char *data);
+int sd_rtnl_message_append_u16(sd_rtnl_message *m, unsigned short type, uint16_t data);
 int sd_rtnl_message_append_u32(sd_rtnl_message *m, unsigned short type, uint32_t data);
 int sd_rtnl_message_append_in_addr(sd_rtnl_message *m, unsigned short type, const struct in_addr *data);
 int sd_rtnl_message_append_in6_addr(sd_rtnl_message *m, unsigned short type, const struct in6_addr *data);