1 /* SPDX-License-Identifier: LGPL-2.1-or-later
2  * Copyright © 2019 VMware, Inc. */
3 #pragma once
4 
5 #include "conf-parser.h"
6 #include "networkd-util.h"
7 
8 typedef struct Link Link;
9 typedef struct Manager Manager;
10 typedef struct Network Network;
11 
12 typedef enum TClassKind {
13         TCLASS_KIND_DRR,
14         TCLASS_KIND_HTB,
15         TCLASS_KIND_QFQ,
16         _TCLASS_KIND_MAX,
17         _TCLASS_KIND_INVALID = -EINVAL,
18 } TClassKind;
19 
20 typedef struct TClass {
21         Link *link;
22         Network *network;
23         ConfigSection *section;
24         NetworkConfigSource source;
25         NetworkConfigState state;
26 
27         uint32_t classid;
28         uint32_t parent;
29 
30         TClassKind kind;
31         char *tca_kind;
32 } TClass;
33 
34 typedef struct TClassVTable {
35         size_t object_size;
36         const char *tca_kind;
37         /* called in tclass_new() */
38         int (*init)(TClass *tclass);
39         int (*fill_message)(Link *link, TClass *tclass, sd_netlink_message *m);
40         int (*verify)(TClass *tclass);
41 } TClassVTable;
42 
43 extern const TClassVTable * const tclass_vtable[_TCLASS_KIND_MAX];
44 
45 #define TCLASS_VTABLE(t) ((t)->kind != _TCLASS_KIND_INVALID ? tclass_vtable[(t)->kind] : NULL)
46 
47 /* For casting a tclass into the various tclass kinds */
48 #define DEFINE_TCLASS_CAST(UPPERCASE, MixedCase)                          \
49         static inline MixedCase* TCLASS_TO_##UPPERCASE(TClass *t) {       \
50                 if (_unlikely_(!t || t->kind != TCLASS_KIND_##UPPERCASE)) \
51                         return NULL;                                      \
52                                                                           \
53                 return (MixedCase*) t;                                    \
54         }
55 
56 DEFINE_NETWORK_CONFIG_STATE_FUNCTIONS(TClass, tclass);
57 
58 TClass* tclass_free(TClass *tclass);
59 int tclass_new_static(TClassKind kind, Network *network, const char *filename, unsigned section_line, TClass **ret);
60 
61 int link_find_tclass(Link *link, uint32_t classid, TClass **ret);
62 
63 int link_request_tclass(Link *link, TClass *tclass);
64 
65 void network_drop_invalid_tclass(Network *network);
66 
67 int manager_rtnl_process_tclass(sd_netlink *rtnl, sd_netlink_message *message, Manager *m);
68 
69 DEFINE_SECTION_CLEANUP_FUNCTIONS(TClass, tclass_free);
70 
71 CONFIG_PARSER_PROTOTYPE(config_parse_tclass_parent);
72 CONFIG_PARSER_PROTOTYPE(config_parse_tclass_classid);
73 
74 #include "drr.h"
75 #include "htb.h"
76 #include "qfq.h"
77