Debian Codegraph @

src/udev/net/link-config.h

raw
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 #pragma once
3
4 #include <limits.h>
5
6 #include "sd-device.h"
7
8 #include "cpu-set-util.h"
9 #include "ether-addr-util.h"
10 #include "ethtool-util.h"
11 #include "shared-forward.h"
12 #include "list.h"
13 #include "net-condition.h"
14
15 typedef struct LinkConfigContext LinkConfigContext;
16 typedef struct LinkConfig LinkConfig;
17 typedef struct UdevEvent UdevEvent;
18
19 typedef enum MACAddressPolicy {
20 MAC_ADDRESS_POLICY_PERSISTENT,
21 MAC_ADDRESS_POLICY_RANDOM,
22 MAC_ADDRESS_POLICY_NONE,
23 _MAC_ADDRESS_POLICY_MAX,
24 _MAC_ADDRESS_POLICY_INVALID = -EINVAL,
25 } MACAddressPolicy;
26
27 typedef enum IRQAffinityPolicy {
28 IRQ_AFFINITY_POLICY_SINGLE,
29 IRQ_AFFINITY_POLICY_SPREAD,
30 _IRQ_AFFINITY_POLICY_MAX,
31 _IRQ_AFFINITY_POLICY_INVALID = -EINVAL,
32 } IRQAffinityPolicy;
33
34 /* Special values for IRQAffinityNUMA= */
35 #define IRQ_AFFINITY_NUMA_UNSET UINT_MAX
36 #define IRQ_AFFINITY_NUMA_LOCAL (IRQ_AFFINITY_NUMA_UNSET - 1)
37
38 typedef struct Link {
39 UdevEvent *event;
40 LinkConfig *config;
41
42 /* from sd_device */
43 const char *ifname;
44 int ifindex;
45 sd_device_action_t action;
46
47 /* from rtnl */
48 char *kind;
49 const char *driver;
50 uint16_t iftype;
51 uint32_t flags;
52 struct hw_addr_data hw_addr;
53 struct hw_addr_data permanent_hw_addr;
54 unsigned name_assign_type;
55 unsigned addr_assign_type;
56
57 /* generated name */
58 const char *new_name;
59 } Link;
60
61 struct LinkConfig {
62 char *filename;
63 char **dropins;
64
65 NetMatch match;
66 LIST_HEAD(Condition, conditions);
67
68 char *description;
69
70 /* udev property */
71 char **properties;
72 char **import_properties;
73 char **unset_properties;
74
75 /* rtnl setlink */
76 struct hw_addr_data hw_addr;
77 MACAddressPolicy mac_address_policy;
78 NamePolicy *name_policy;
79 NamePolicy *alternative_names_policy;
80 char *name;
81 char **alternative_names;
82 char *alias;
83 uint32_t txqueues;
84 uint32_t rxqueues;
85 uint32_t txqueuelen;
86 uint32_t mtu;
87 uint32_t gso_max_segments;
88 size_t gso_max_size;
89
90 /* ethtool link settings */
91 uint64_t speed;
92 Duplex duplex;
93 int autonegotiation;
94 uint32_t advertise[N_ADVERTISE];
95 NetDevPort port;
96 uint8_t mdi;
97
98 /* ethtool WoL */
99 uint32_t wol;
100 char *wol_password_file;
101 uint8_t *wol_password;
102
103 /* ethtool features */
104 int features[_NET_DEV_FEAT_MAX];
105
106 /* ethtool channels */
107 netdev_channels channels;
108
109 /* ethtool ring parameters */
110 netdev_ring_param ring;
111
112 /* ethtool pause parameters */
113 int rx_flow_control;
114 int tx_flow_control;
115 int autoneg_flow_control;
116
117 /* ethtool coalesce settings */
118 netdev_coalesce_param coalesce;
119
120 /* ethtool energy efficient ethernet settings */
121 int eee_enabled;
122 int eee_tx_lpi_enabled;
123 usec_t eee_tx_lpi_timer_usec;
124 uint32_t eee_advertise[N_ADVERTISE];
125
126 /* Rx RPS CPU mask */
127 CPUSet rps_cpu_mask;
128
129 /* IRQ affinity */
130 IRQAffinityPolicy irq_affinity_policy;
131 CPUSet irq_affinity_cpus;
132 unsigned irq_affinity_numa;
133
134 /* SR-IOV */
135 uint32_t sr_iov_num_vfs;
136 OrderedHashmap *sr_iov_by_section;
137
138 LIST_FIELDS(LinkConfig, configs);
139 };
140
141 int link_config_ctx_new(LinkConfigContext **ret);
142 LinkConfigContext* link_config_ctx_free(LinkConfigContext *ctx);
143 DEFINE_TRIVIAL_CLEANUP_FUNC(LinkConfigContext*, link_config_ctx_free);
144
145 int link_load_one(LinkConfigContext *ctx, const char *filename);
146 int link_config_load(LinkConfigContext *ctx);
147 bool link_config_should_reload(LinkConfigContext *ctx);
148
149 int link_new(LinkConfigContext *ctx, UdevEvent *event, Link **ret);
150 Link* link_free(Link *link);
151 DEFINE_TRIVIAL_CLEANUP_FUNC(Link*, link_free);
152
153 int link_get_config(LinkConfigContext *ctx, Link *link);
154 int link_apply_config(LinkConfigContext *ctx, Link *link);
155
156 DECLARE_STRING_TABLE_LOOKUP(mac_address_policy, MACAddressPolicy);
157 DECLARE_STRING_TABLE_LOOKUP(irq_affinity_policy, IRQAffinityPolicy);
158
159 /* gperf lookup function */
160 const struct ConfigPerfItem* link_config_gperf_lookup(const char *str, GPERF_LEN_TYPE length);
161
162 CONFIG_PARSER_PROTOTYPE(config_parse_udev_property);
163 CONFIG_PARSER_PROTOTYPE(config_parse_udev_property_name);
164 CONFIG_PARSER_PROTOTYPE(config_parse_ifalias);
165 CONFIG_PARSER_PROTOTYPE(config_parse_rx_tx_queues);
166 CONFIG_PARSER_PROTOTYPE(config_parse_txqueuelen);
167 CONFIG_PARSER_PROTOTYPE(config_parse_wol_password);
168 CONFIG_PARSER_PROTOTYPE(config_parse_mac_address_policy);
169 CONFIG_PARSER_PROTOTYPE(config_parse_name_policy);
170 CONFIG_PARSER_PROTOTYPE(config_parse_alternative_names_policy);
171 CONFIG_PARSER_PROTOTYPE(config_parse_rps_cpu_mask);
172 CONFIG_PARSER_PROTOTYPE(config_parse_irq_affinity_policy);
173 CONFIG_PARSER_PROTOTYPE(config_parse_irq_affinity_numa);