chiark / gitweb /
24fdb87e4c5c013e5eb9e15cfd56a2d4a6c1b4da
[elogind.git] / src / udev / net / link-config.h
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3 /***
4  This file is part of systemd.
5
6  Copyright (C) 2013 Tom Gundersen <teg@jklm.no>
7
8   systemd is free software; you can redistribute it and/or modify it
9   under the terms of the GNU Lesser General Public License as published by
10   the Free Software Foundation; either version 2.1 of the License, or
11   (at your option) any later version.
12
13   systemd is distributed in the hope that it will be useful, but
14   WITHOUT ANY WARRANTY; without even the implied warranty of
15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16   Lesser General Public License for more details.
17
18   You should have received a copy of the GNU Lesser General Public License
19   along with systemd; If not, see <http://www.gnu.org/licenses/>.
20 ***/
21
22 #pragma once
23
24 #include "ethtool-util.h"
25
26 #include "condition-util.h"
27 #include "libudev.h"
28 #include "util.h"
29 #include "list.h"
30
31 typedef struct link_config_ctx link_config_ctx;
32 typedef struct link_config link_config;
33
34 typedef enum MACPolicy {
35         MACPOLICY_PERSISTENT,
36         MACPOLICY_RANDOM,
37         _MACPOLICY_MAX,
38         _MACPOLICY_INVALID = -1
39 } MACPolicy;
40
41 typedef enum NamePolicy {
42         NAMEPOLICY_DATABASE,
43         NAMEPOLICY_ONBOARD,
44         NAMEPOLICY_SLOT,
45         NAMEPOLICY_PATH,
46         NAMEPOLICY_MAC,
47         _NAMEPOLICY_MAX,
48         _NAMEPOLICY_INVALID = -1
49 } NamePolicy;
50
51 struct link_config {
52         char *filename;
53
54         struct ether_addr *match_mac;
55         char *match_path;
56         char *match_driver;
57         char *match_type;
58         Condition *match_host;
59         Condition *match_virt;
60         Condition *match_kernel;
61         Condition *match_arch;
62
63         char *description;
64         struct ether_addr *mac;
65         MACPolicy mac_policy;
66         NamePolicy *name_policy;
67         char *name;
68         char *alias;
69         unsigned int mtu;
70         unsigned int speed;
71         Duplex duplex;
72         WakeOnLan wol;
73
74         LIST_FIELDS(link_config, links);
75 };
76
77 int link_config_ctx_new(link_config_ctx **ret);
78 void link_config_ctx_free(link_config_ctx *ctx);
79
80 int link_config_load(link_config_ctx *ctx);
81 bool link_config_should_reload(link_config_ctx *ctx);
82
83 int link_config_get(link_config_ctx *ctx, struct udev_device *device, struct link_config **ret);
84 int link_config_apply(link_config_ctx *ctx, struct link_config *config, struct udev_device *device, const char **name);
85
86 int link_get_driver(link_config_ctx *ctx, struct udev_device *device, char **ret);
87
88 const char *name_policy_to_string(NamePolicy p) _const_;
89 NamePolicy name_policy_from_string(const char *p) _pure_;
90
91 const char *mac_policy_to_string(MACPolicy p) _const_;
92 MACPolicy mac_policy_from_string(const char *p) _pure_;
93
94 /* gperf lookup function */
95 const struct ConfigPerfItem* link_config_gperf_lookup(const char *key, unsigned length);
96
97 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);
98 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);