1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 #pragma once
3 
4 #include "macro.h"
5 #include "netlink-types.h"
6 
7 struct NLType {
8         uint16_t type;
9         size_t size;
10         const NLTypeSystem *type_system;
11         const NLTypeSystemUnion *type_system_union;
12 };
13 
14 struct NLTypeSystem {
15         uint16_t count;
16         const NLType *types;
17 };
18 
19 typedef struct NLTypeSystemUnionElement {
20         union {
21                 int protocol;
22                 const char *name;
23         };
24         NLTypeSystem type_system;
25 } NLTypeSystemUnionElement;
26 
27 struct NLTypeSystemUnion {
28         size_t count;
29         const NLTypeSystemUnionElement *elements;
30         NLMatchType match_type;
31         uint16_t match_attribute;
32 };
33 
34 #define TYPE_SYSTEM_FROM_TYPE(name)                                     \
35         { .count = ELEMENTSOF(name##_types), .types = name##_types }
36 #define DEFINE_TYPE_SYSTEM(name)                                        \
37         static const NLTypeSystem name##_type_system = TYPE_SYSTEM_FROM_TYPE(name)
38 
39 #define _DEFINE_TYPE_SYSTEM_UNION(name, type, attr)                     \
40         static const NLTypeSystemUnion name##_type_system_union = {     \
41                 .count = ELEMENTSOF(name##_type_systems),               \
42                 .elements = name##_type_systems,                        \
43                 .match_type = type,                                     \
44                 .match_attribute = attr,                                \
45         }
46 #define DEFINE_TYPE_SYSTEM_UNION_MATCH_PROTOCOL(name)           \
47         _DEFINE_TYPE_SYSTEM_UNION(name, NL_MATCH_PROTOCOL, 0)
48 #define DEFINE_TYPE_SYSTEM_UNION_MATCH_SIBLING(name, attr)      \
49         _DEFINE_TYPE_SYSTEM_UNION(name, NL_MATCH_SIBLING, attr)
50