chiark / gitweb /
sd-netlink: don't treat NULL as root type-system
authorDavid Herrmann <dh.herrmann@gmail.com>
Tue, 23 Jun 2015 10:10:38 +0000 (12:10 +0200)
committerSven Eden <yamakuzure@gmx.net>
Tue, 14 Mar 2017 09:04:18 +0000 (10:04 +0100)
Explicitly export the root type-system to the type-system callers. This
avoids treating NULL as root, which for one really looks backwards (NULL
is usually a leaf, not root), and secondly prevents us from properly
debugging calling into non-nested types.

Also rename the root to "type_system_root". Once we support more than
rtnl, well will have to revisit that, anyway.

src/libsystemd/sd-netlink/netlink-message.c
src/libsystemd/sd-netlink/netlink-types.c
src/libsystemd/sd-netlink/netlink-types.h

index bfbc0e6c95d63afc1cf20d582ae3db344e232a80..3f8bf018268d29c9c58538a855544fd9afc7ab27 100644 (file)
@@ -68,7 +68,7 @@ int message_new(sd_netlink *rtnl, sd_netlink_message **ret, uint16_t type) {
         size_t size;
         int r;
 
-        r = type_system_get_type(NULL, &nl_type, type);
+        r = type_system_get_type(&type_system_root, &nl_type, type);
         if (r < 0)
                 return r;
 
@@ -872,7 +872,7 @@ int sd_netlink_message_rewind(sd_netlink_message *m) {
 
         assert(m->hdr);
 
-        r = type_system_get_type(NULL, &nl_type, m->hdr->nlmsg_type);
+        r = type_system_get_type(&type_system_root, &nl_type, m->hdr->nlmsg_type);
         if (r < 0)
                 return r;
 
index d22194ad717f7a06d7861716e46e69c62875695f..40548dcbc0ee79c56380b6c1d853925b622e76d8 100644 (file)
@@ -476,7 +476,7 @@ static const NLType rtnl_types[RTM_MAX + 1] = {
         [RTM_GETNEIGH] = { .type = NETLINK_TYPE_NESTED, .type_system = &rtnl_neigh_type_system, .size = sizeof(struct ndmsg) },
 };
 
-const NLTypeSystem rtnl_type_system = {
+const NLTypeSystem type_system_root = {
         .count = ELEMENTSOF(rtnl_types),
         .types = rtnl_types,
 };
@@ -518,10 +518,7 @@ int type_system_get_type(const NLTypeSystem *type_system, const NLType **ret, ui
         const NLType *nl_type;
 
         assert(ret);
-
-        if (!type_system)
-                type_system = &rtnl_type_system;
-
+        assert(type_system);
         assert(type_system->types);
 
         if (type >= type_system->count)
index d64229546417c568fb67499dc31707c018e6e88d..b1ef7af421a15c64b305b2544942cdd595c860bd 100644 (file)
@@ -52,6 +52,8 @@ struct NLTypeSystemUnion {
         const NLTypeSystem *type_systems;
 };
 
+extern const NLTypeSystem type_system_root;
+
 uint16_t type_get_type(const NLType *type);
 size_t type_get_size(const NLType *type);
 void type_get_type_system(const NLType *type, const NLTypeSystem **ret);