]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/udev/net/link-config.h
tree-wide: drop license boilerplate
[thirdparty/systemd.git] / src / udev / net / link-config.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 #pragma once
3
4 /***
5 This file is part of systemd.
6
7 Copyright (C) 2013 Tom Gundersen <teg@jklm.no>
8 ***/
9
10 #include "libudev.h"
11
12 #include "condition.h"
13 #include "ethtool-util.h"
14 #include "list.h"
15
16 typedef struct link_config_ctx link_config_ctx;
17 typedef struct link_config link_config;
18
19 typedef enum MACPolicy {
20 MACPOLICY_PERSISTENT,
21 MACPOLICY_RANDOM,
22 MACPOLICY_NONE,
23 _MACPOLICY_MAX,
24 _MACPOLICY_INVALID = -1
25 } MACPolicy;
26
27 typedef enum NamePolicy {
28 NAMEPOLICY_KERNEL,
29 NAMEPOLICY_DATABASE,
30 NAMEPOLICY_ONBOARD,
31 NAMEPOLICY_SLOT,
32 NAMEPOLICY_PATH,
33 NAMEPOLICY_MAC,
34 _NAMEPOLICY_MAX,
35 _NAMEPOLICY_INVALID = -1
36 } NamePolicy;
37
38 struct link_config {
39 char *filename;
40
41 struct ether_addr *match_mac;
42 char **match_path;
43 char **match_driver;
44 char **match_type;
45 char **match_name;
46 Condition *match_host;
47 Condition *match_virt;
48 Condition *match_kernel_cmdline;
49 Condition *match_kernel_version;
50 Condition *match_arch;
51
52 char *description;
53 struct ether_addr *mac;
54 MACPolicy mac_policy;
55 NamePolicy *name_policy;
56 char *name;
57 char *alias;
58 size_t mtu;
59 size_t speed;
60 Duplex duplex;
61 int autonegotiation;
62 WakeOnLan wol;
63 NetDevPort port;
64 NetDevFeature features[_NET_DEV_FEAT_MAX];
65
66 LIST_FIELDS(link_config, links);
67 };
68
69 int link_config_ctx_new(link_config_ctx **ret);
70 void link_config_ctx_free(link_config_ctx *ctx);
71
72 int link_config_load(link_config_ctx *ctx);
73 bool link_config_should_reload(link_config_ctx *ctx);
74
75 int link_config_get(link_config_ctx *ctx, struct udev_device *device, struct link_config **ret);
76 int link_config_apply(link_config_ctx *ctx, struct link_config *config, struct udev_device *device, const char **name);
77
78 int link_get_driver(link_config_ctx *ctx, struct udev_device *device, char **ret);
79
80 const char *name_policy_to_string(NamePolicy p) _const_;
81 NamePolicy name_policy_from_string(const char *p) _pure_;
82
83 const char *mac_policy_to_string(MACPolicy p) _const_;
84 MACPolicy mac_policy_from_string(const char *p) _pure_;
85
86 /* gperf lookup function */
87 const struct ConfigPerfItem* link_config_gperf_lookup(const char *key, GPERF_LEN_TYPE length);
88
89 int config_parse_mac_policy(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
90 int config_parse_name_policy(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);