diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2021-07-03 06:53:08 +0900 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2021-08-29 18:10:47 +0900 |
commit | 44f1072a9ddf9ad33a1fe76bae3d16f4a818ea79 (patch) | |
tree | b2e16acb7a136899d3412d5378baea8a0f79557e | |
parent | 52313394ba4f2e57156d0ba1a4c4ddc669dbf7f0 (diff) | |
download | systemd-44f1072a9ddf9ad33a1fe76bae3d16f4a818ea79.tar.gz |
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.
-rw-r--r-- | src/libsystemd/sd-netlink/netlink-genl.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/src/libsystemd/sd-netlink/netlink-genl.c b/src/libsystemd/sd-netlink/netlink-genl.c index f454dbd837..8537e13316 100644 --- a/src/libsystemd/sd-netlink/netlink-genl.c +++ b/src/libsystemd/sd-netlink/netlink-genl.c @@ -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; } |