1 /* SPDX-License-Identifier: LGPL-2.1-or-later
2 * Copyright © 2019 VMware, Inc. */
5 #include "conf-parser.h"
6 #include "networkd-link.h"
7 #include "networkd-network.h"
8 #include "networkd-util.h"
11 typedef enum TClassKind
{
16 _TCLASS_KIND_INVALID
= -1,
19 typedef struct TClass
{
22 NetworkConfigSection
*section
;
31 typedef struct TClassVTable
{
34 /* called in tclass_new() */
35 int (*init
)(TClass
*tclass
);
36 int (*fill_message
)(Link
*link
, TClass
*tclass
, sd_netlink_message
*m
);
37 int (*verify
)(TClass
*tclass
);
40 extern const TClassVTable
* const tclass_vtable
[_TCLASS_KIND_MAX
];
42 #define TCLASS_VTABLE(t) ((t)->kind != _TCLASS_KIND_INVALID ? tclass_vtable[(t)->kind] : NULL)
44 /* For casting a tclass into the various tclass kinds */
45 #define DEFINE_TCLASS_CAST(UPPERCASE, MixedCase) \
46 static inline MixedCase* TCLASS_TO_##UPPERCASE(TClass *t) { \
47 if (_unlikely_(!t || t->kind != TCLASS_KIND_##UPPERCASE)) \
50 return (MixedCase*) t; \
53 /* For casting the various tclass kinds into a tclass */
54 #define TCLASS(t) (&(t)->meta)
56 void tclass_free(TClass
*tclass
);
57 int tclass_new_static(TClassKind kind
, Network
*network
, const char *filename
, unsigned section_line
, TClass
**ret
);
59 int tclass_configure(Link
*link
, TClass
*tclass
);
60 int tclass_section_verify(TClass
*tclass
);
62 DEFINE_NETWORK_SECTION_FUNCTIONS(TClass
, tclass_free
);
64 DEFINE_TC_CAST(TCLASS
, TClass
);
66 CONFIG_PARSER_PROTOTYPE(config_parse_tclass_parent
);
67 CONFIG_PARSER_PROTOTYPE(config_parse_tclass_classid
);