]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/udev/net/link-config.h
Merge pull request #8902 from yuwata/link-multiple-mac
[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 #include "set.h"
16
17 typedef struct link_config_ctx link_config_ctx;
18 typedef struct link_config link_config;
19
20 typedef enum MACPolicy {
21 MACPOLICY_PERSISTENT,
22 MACPOLICY_RANDOM,
23 MACPOLICY_NONE,
24 _MACPOLICY_MAX,
25 _MACPOLICY_INVALID = -1
26 } MACPolicy;
27
28 typedef enum NamePolicy {
29 NAMEPOLICY_KERNEL,
30 NAMEPOLICY_DATABASE,
31 NAMEPOLICY_ONBOARD,
32 NAMEPOLICY_SLOT,
33 NAMEPOLICY_PATH,
34 NAMEPOLICY_MAC,
35 _NAMEPOLICY_MAX,
36 _NAMEPOLICY_INVALID = -1
37 } NamePolicy;
38
39 struct link_config {
40 char *filename;
41
42 Set *match_mac;
43 char **match_path;
44 char **match_driver;
45 char **match_type;
46 char **match_name;
47 Condition *match_host;
48 Condition *match_virt;
49 Condition *match_kernel_cmdline;
50 Condition *match_kernel_version;
51 Condition *match_arch;
52
53 char *description;
54 struct ether_addr *mac;
55 MACPolicy mac_policy;
56 NamePolicy *name_policy;
57 char *name;
58 char *alias;
59 uint32_t mtu;
60 size_t speed;
61 Duplex duplex;
62 int autonegotiation;
63 WakeOnLan wol;
64 NetDevPort port;
65 NetDevFeature features[_NET_DEV_FEAT_MAX];
66 netdev_channels channels;
67
68 LIST_FIELDS(link_config, links);
69 };
70
71 int link_config_ctx_new(link_config_ctx **ret);
72 void link_config_ctx_free(link_config_ctx *ctx);
73
74 int link_config_load(link_config_ctx *ctx);
75 bool link_config_should_reload(link_config_ctx *ctx);
76
77 int link_config_get(link_config_ctx *ctx, struct udev_device *device, struct link_config **ret);
78 int link_config_apply(link_config_ctx *ctx, struct link_config *config, struct udev_device *device, const char **name);
79
80 int link_get_driver(link_config_ctx *ctx, struct udev_device *device, char **ret);
81
82 const char *name_policy_to_string(NamePolicy p) _const_;
83 NamePolicy name_policy_from_string(const char *p) _pure_;
84
85 const char *mac_policy_to_string(MACPolicy p) _const_;
86 MACPolicy mac_policy_from_string(const char *p) _pure_;
87
88 /* gperf lookup function */
89 const struct ConfigPerfItem* link_config_gperf_lookup(const char *key, GPERF_LEN_TYPE length);
90
91 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);
92 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);