]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/udev/udev-builtin-net_setup_link.c
resolved: add code to map DNSSEC digest types to strings and back
[thirdparty/systemd.git] / src / udev / udev-builtin-net_setup_link.c
CommitLineData
af6f0d42
TG
1/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3/***
4 This file is part of systemd.
5
6 Copyright 2013 Tom Gundersen
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
b5efdb8a 22#include "alloc-util.h"
af6f0d42 23#include "link-config.h"
af6f0d42 24#include "log.h"
b5efdb8a 25#include "udev.h"
af6f0d42 26
9588bc32 27static link_config_ctx *ctx = NULL;
af6f0d42 28
0b99c9f8 29static int builtin_net_setup_link(struct udev_device *dev, int argc, char **argv, bool test) {
847a8a5f 30 _cleanup_free_ char *driver = NULL;
c487c9ce 31 const char *name = NULL;
af6f0d42
TG
32 link_config *link;
33 int r;
34
35 if (argc > 1) {
36 log_error("This program takes no arguments.");
37 return EXIT_FAILURE;
38 }
39
847a8a5f
TG
40 r = link_get_driver(ctx, dev, &driver);
41 if (r >= 0)
42 udev_builtin_add_property(dev, test, "ID_NET_DRIVER", driver);
43
af6f0d42
TG
44 r = link_config_get(ctx, dev, &link);
45 if (r < 0) {
46 if (r == -ENOENT) {
01d4590b 47 log_debug("No matching link configuration found.");
af6f0d42
TG
48 return EXIT_SUCCESS;
49 } else {
da927ba9 50 log_error_errno(r, "Could not get link config: %m");
af6f0d42
TG
51 return EXIT_FAILURE;
52 }
53 }
54
3e137a1b 55 r = link_config_apply(ctx, link, dev, &name);
af6f0d42 56 if (r < 0) {
da927ba9 57 log_error_errno(r, "Could not apply link config to %s: %m", udev_device_get_sysname(dev));
af6f0d42
TG
58 return EXIT_FAILURE;
59 }
60
ad6e5b34
TG
61 udev_builtin_add_property(dev, test, "ID_NET_LINK_FILE", link->filename);
62
3e137a1b
TG
63 if (name)
64 udev_builtin_add_property(dev, test, "ID_NET_NAME", name);
65
af6f0d42
TG
66 return EXIT_SUCCESS;
67}
68
0b99c9f8 69static int builtin_net_setup_link_init(struct udev *udev) {
af6f0d42
TG
70 int r;
71
72 if (ctx)
73 return 0;
74
75 r = link_config_ctx_new(&ctx);
76 if (r < 0)
77 return r;
78
79 r = link_config_load(ctx);
80 if (r < 0)
81 return r;
82
01d4590b 83 log_debug("Created link configuration context.");
af6f0d42
TG
84 return 0;
85}
86
0b99c9f8 87static void builtin_net_setup_link_exit(struct udev *udev) {
af6f0d42 88 link_config_ctx_free(ctx);
e0221a35 89 ctx = NULL;
01d4590b 90 log_debug("Unloaded link configuration context.");
af6f0d42
TG
91}
92
0b99c9f8 93static bool builtin_net_setup_link_validate(struct udev *udev) {
01d4590b 94 log_debug("Check if link configuration needs reloading.");
af6f0d42
TG
95 if (!ctx)
96 return false;
97
98 return link_config_should_reload(ctx);
99}
100
0b99c9f8
TG
101const struct udev_builtin udev_builtin_net_setup_link = {
102 .name = "net_setup_link",
103 .cmd = builtin_net_setup_link,
104 .init = builtin_net_setup_link_init,
105 .exit = builtin_net_setup_link_exit,
106 .validate = builtin_net_setup_link_validate,
5ac0162c 107 .help = "Configure network link",
af6f0d42
TG
108 .run_once = false,
109};