sd-netlink: determine header size of genl message by using CTRL_ATTR_HDRSIZE attribute
Fortunately, all genl families we currently use do not require additional header size.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user