diff options
author | David Herrmann <dh.herrmann@gmail.com> | 2015-06-23 10:51:25 +0200 |
---|---|---|
committer | David Herrmann <dh.herrmann@gmail.com> | 2015-06-24 13:45:47 +0200 |
commit | c658008f50fdbc617e6f7ad321c058f3a6f175f5 (patch) | |
tree | c2fb5229335daa4dadbbd0c8faf541e862418934 /src/libsystemd | |
parent | cafbc790d1affec2c9524c5ee1915485a1ac6879 (diff) |
sd-netlink: don't access type->type_system[_union] directly
Make sure we never access type->type_system or type->type_system_union
directly. This is an implementation detail of the type-system and we
should always use the accessors. Right now, they only exist for 2-level
accesses (type-system to type-system). This patch introduces the 1-level
accessors (type to type-system) and makes use of it.
This patch makes sure the proper assertions are in place, so we never
accidentally access sub-type-systems for non-nested/union types.
Note that this places hard-asserts on the accessors. This should be fine,
as we expect callers to only access sub type-systems if they *know*
they're dealing with nested types.
Diffstat (limited to 'src/libsystemd')
-rw-r--r-- | src/libsystemd/sd-netlink/netlink-message.c | 7 | ||||
-rw-r--r-- | src/libsystemd/sd-netlink/netlink-types.c | 30 | ||||
-rw-r--r-- | src/libsystemd/sd-netlink/netlink-types.h | 2 |
3 files changed, 26 insertions, 13 deletions
diff --git a/src/libsystemd/sd-netlink/netlink-message.c b/src/libsystemd/sd-netlink/netlink-message.c index 601124cc05..887327c9ae 100644 --- a/src/libsystemd/sd-netlink/netlink-message.c +++ b/src/libsystemd/sd-netlink/netlink-message.c @@ -85,7 +85,8 @@ int message_new(sd_netlink *rtnl, sd_netlink_message **ret, uint16_t type) { m->hdr->nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK; - m->container_type_system[0] = nl_type->type_system; + if (nl_type->type == NETLINK_TYPE_NESTED) + type_get_type_system(nl_type, &m->container_type_system[0]); m->hdr->nlmsg_len = size; m->hdr->nlmsg_type = type; @@ -872,9 +873,9 @@ int sd_netlink_message_rewind(sd_netlink_message *m) { return r; if (type->type == NETLINK_TYPE_NESTED) { - const NLTypeSystem *type_system = type->type_system; + const NLTypeSystem *type_system; - assert(type_system); + type_get_type_system(type, &type_system); m->container_type_system[0] = type_system; diff --git a/src/libsystemd/sd-netlink/netlink-types.c b/src/libsystemd/sd-netlink/netlink-types.c index 72799da887..fe9e5f9826 100644 --- a/src/libsystemd/sd-netlink/netlink-types.c +++ b/src/libsystemd/sd-netlink/netlink-types.c @@ -460,6 +460,24 @@ const NLTypeSystem rtnl_type_system = { .types = rtnl_types, }; +void type_get_type_system(const NLType *nl_type, const NLTypeSystem **ret) { + assert(nl_type); + assert(ret); + assert(nl_type->type == NETLINK_TYPE_NESTED); + assert(nl_type->type_system); + + *ret = nl_type->type_system; +} + +void type_get_type_system_union(const NLType *nl_type, const NLTypeSystemUnion **ret) { + assert(nl_type); + assert(ret); + assert(nl_type->type == NETLINK_TYPE_UNION); + assert(nl_type->type_system_union); + + *ret = nl_type->type_system_union; +} + int type_system_get_type(const NLTypeSystem *type_system, const NLType **ret, uint16_t type) { const NLType *nl_type; @@ -493,11 +511,7 @@ int type_system_get_type_system(const NLTypeSystem *type_system, const NLTypeSys if (r < 0) return r; - assert(nl_type->type == NETLINK_TYPE_NESTED); - assert(nl_type->type_system); - - *ret = nl_type->type_system; - + type_get_type_system(nl_type, ret); return 0; } @@ -511,11 +525,7 @@ int type_system_get_type_system_union(const NLTypeSystem *type_system, const NLT if (r < 0) return r; - assert(nl_type->type == NETLINK_TYPE_UNION); - assert(nl_type->type_system_union); - - *ret = nl_type->type_system_union; - + type_get_type_system_union(nl_type, ret); return 0; } diff --git a/src/libsystemd/sd-netlink/netlink-types.h b/src/libsystemd/sd-netlink/netlink-types.h index 1bb1b21da9..74a59bb7c2 100644 --- a/src/libsystemd/sd-netlink/netlink-types.h +++ b/src/libsystemd/sd-netlink/netlink-types.h @@ -65,6 +65,8 @@ struct NLType { const NLTypeSystemUnion *type_system_union; }; +void type_get_type_system(const NLType *type, const NLTypeSystem **ret); +void type_get_type_system_union(const NLType *type, const NLTypeSystemUnion **ret); int type_system_get_type(const NLTypeSystem *type_system, const NLType **ret, uint16_t type); int type_system_get_type_system(const NLTypeSystem *type_system, const NLTypeSystem **ret, uint16_t type); int type_system_get_type_system_union(const NLTypeSystem *type_system, const NLTypeSystemUnion **ret, uint16_t type); |