]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/udev/udev-builtin-net_setup_link.c
udev: net_setup_link: don't error out when we couldn't apply link config (#7328)
[thirdparty/systemd.git] / src / udev / udev-builtin-net_setup_link.c
1 /***
2 This file is part of systemd.
3
4 Copyright 2013 Tom Gundersen
5
6 systemd is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
10
11 systemd is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public License
17 along with systemd; If not, see <http://www.gnu.org/licenses/>.
18 ***/
19
20 #include "alloc-util.h"
21 #include "link-config.h"
22 #include "log.h"
23 #include "udev.h"
24
25 static link_config_ctx *ctx = NULL;
26
27 static int builtin_net_setup_link(struct udev_device *dev, int argc, char **argv, bool test) {
28 _cleanup_free_ char *driver = NULL;
29 const char *name = NULL;
30 link_config *link;
31 int r;
32
33 if (argc > 1) {
34 log_error("This program takes no arguments.");
35 return EXIT_FAILURE;
36 }
37
38 r = link_get_driver(ctx, dev, &driver);
39 if (r >= 0)
40 udev_builtin_add_property(dev, test, "ID_NET_DRIVER", driver);
41
42 r = link_config_get(ctx, dev, &link);
43 if (r < 0) {
44 if (r == -ENOENT) {
45 log_debug("No matching link configuration found.");
46 return EXIT_SUCCESS;
47 } else {
48 log_error_errno(r, "Could not get link config: %m");
49 return EXIT_FAILURE;
50 }
51 }
52
53 r = link_config_apply(ctx, link, dev, &name);
54 if (r < 0)
55 log_warning_errno(r, "Could not apply link config to %s, ignoring: %m", udev_device_get_sysname(dev));
56
57 udev_builtin_add_property(dev, test, "ID_NET_LINK_FILE", link->filename);
58
59 if (name)
60 udev_builtin_add_property(dev, test, "ID_NET_NAME", name);
61
62 return EXIT_SUCCESS;
63 }
64
65 static int builtin_net_setup_link_init(struct udev *udev) {
66 int r;
67
68 if (ctx)
69 return 0;
70
71 r = link_config_ctx_new(&ctx);
72 if (r < 0)
73 return r;
74
75 r = link_config_load(ctx);
76 if (r < 0)
77 return r;
78
79 log_debug("Created link configuration context.");
80 return 0;
81 }
82
83 static void builtin_net_setup_link_exit(struct udev *udev) {
84 link_config_ctx_free(ctx);
85 ctx = NULL;
86 log_debug("Unloaded link configuration context.");
87 }
88
89 static bool builtin_net_setup_link_validate(struct udev *udev) {
90 log_debug("Check if link configuration needs reloading.");
91 if (!ctx)
92 return false;
93
94 return link_config_should_reload(ctx);
95 }
96
97 const struct udev_builtin udev_builtin_net_setup_link = {
98 .name = "net_setup_link",
99 .cmd = builtin_net_setup_link,
100 .init = builtin_net_setup_link_init,
101 .exit = builtin_net_setup_link_exit,
102 .validate = builtin_net_setup_link_validate,
103 .help = "Configure network link",
104 .run_once = false,
105 };