]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/udev/net/link-config.h
tree-wide: drop 'This file is part of systemd' blurb
[thirdparty/systemd.git] / src / udev / net / link-config.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 #pragma once
3
4 /***
5 Copyright (C) 2013 Tom Gundersen <teg@jklm.no>
6 ***/
7
8 #include "libudev.h"
9
10 #include "condition.h"
11 #include "ethtool-util.h"
12 #include "list.h"
13 #include "set.h"
14
15 typedef struct link_config_ctx link_config_ctx;
16 typedef struct link_config link_config;
17
18 typedef enum MACPolicy {
19 MACPOLICY_PERSISTENT,
20 MACPOLICY_RANDOM,
21 MACPOLICY_NONE,
22 _MACPOLICY_MAX,
23 _MACPOLICY_INVALID = -1
24 } MACPolicy;
25
26 typedef enum NamePolicy {
27 NAMEPOLICY_KERNEL,
28 NAMEPOLICY_DATABASE,
29 NAMEPOLICY_ONBOARD,
30 NAMEPOLICY_SLOT,
31 NAMEPOLICY_PATH,
32 NAMEPOLICY_MAC,
33 _NAMEPOLICY_MAX,
34 _NAMEPOLICY_INVALID = -1
35 } NamePolicy;
36
37 struct link_config {
38 char *filename;
39
40 Set *match_mac;
41 char **match_path;
42 char **match_driver;
43 char **match_type;
44 char **match_name;
45 Condition *match_host;
46 Condition *match_virt;
47 Condition *match_kernel_cmdline;
48 Condition *match_kernel_version;
49 Condition *match_arch;
50
51 char *description;
52 struct ether_addr *mac;
53 MACPolicy mac_policy;
54 NamePolicy *name_policy;
55 char *name;
56 char *alias;
57 uint32_t mtu;
58 size_t speed;
59 Duplex duplex;
60 int autonegotiation;
61 WakeOnLan wol;
62 NetDevPort port;
63 NetDevFeature features[_NET_DEV_FEAT_MAX];
64 netdev_channels channels;
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);