]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-netlink: determine header size of genl message by using CTRL_ATTR_HDRSIZE attribute
authorYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 2 Jul 2021 21:53:08 +0000 (06:53 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 29 Aug 2021 09:10:47 +0000 (18:10 +0900)
Fortunately, all genl families we currently use do not require additional
header size.

src/libsystemd/sd-netlink/netlink-genl.c

index f454dbd8373cbc2114bd040149eafbf60410ea8c..8537e13316c78d91b5f1e19e2612b845b491bc6d 100644 (file)
@@ -17,6 +17,7 @@ typedef struct GenericNetlinkFamily {
         uint16_t id; /* a.k.a nlmsg_type */
         char *name;
         uint32_t version;
+        uint32_t additional_header_size;
 } GenericNetlinkFamily;
 
 static const GenericNetlinkFamily nlctrl_static = {
@@ -119,6 +120,10 @@ static int genl_family_new(
         if (r < 0)
                 return r;
 
+        r = sd_netlink_message_read_u32(message, CTRL_ATTR_HDRSIZE, &f->additional_header_size);
+        if (r < 0)
+                return r;
+
         r = hashmap_ensure_put(&nl->genl_family_by_id, NULL, UINT_TO_PTR(f->id), f);
         if (r < 0)
                 return r;
@@ -165,7 +170,8 @@ static int genl_message_new(
         if (r < 0)
                 return r;
 
-        r = message_new_full(nl, family->id, type_system, sizeof(struct genlmsghdr), &m);
+        r = message_new_full(nl, family->id, type_system,
+                             sizeof(struct genlmsghdr) + family->additional_header_size, &m);
         if (r < 0)
                 return r;
 
@@ -287,7 +293,7 @@ int genl_get_type_system_and_header_size(
                         return r;
         }
         if (ret_header_size)
-                *ret_header_size = sizeof(struct genlmsghdr);
+                *ret_header_size = sizeof(struct genlmsghdr) + f->additional_header_size;
         return 0;
 }