chiark / gitweb /
sd-netlink: make NLTypeSystem internal
[elogind.git] / src / libsystemd / sd-netlink / netlink-types.c
index 72799da8870c94382289b14b8f87058f04abc725..70dbd4f8dcc8aaf043a87b50be71d234f2669d1c 100644 (file)
 #include "netlink-types.h"
 #include "missing.h"
 
+struct NLType {
+        uint16_t type;
+        size_t size;
+        const NLTypeSystem *type_system;
+        const NLTypeSystemUnion *type_system_union;
+};
+
+struct NLTypeSystem {
+        uint16_t max;
+        const NLType *types;
+};
+
 static const NLTypeSystem rtnl_link_type_system;
 
 static const NLType rtnl_link_info_data_veth_types[VETH_INFO_MAX + 1] = {
@@ -460,6 +472,39 @@ const NLTypeSystem rtnl_type_system = {
         .types = rtnl_types,
 };
 
+uint16_t type_get_type(const NLType *type) {
+        assert(type);
+        return type->type;
+}
+
+size_t type_get_size(const NLType *type) {
+        assert(type);
+        return type->size;
+}
+
+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;
+}
+
+uint16_t type_system_get_max(const NLTypeSystem *type_system) {
+        assert(type_system);
+        return type_system->max;
+}
+
 int type_system_get_type(const NLTypeSystem *type_system, const NLType **ret, uint16_t type) {
         const NLType *nl_type;
 
@@ -493,11 +538,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 +552,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;
 }