]>
Commit | Line | Data |
---|---|---|
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 | ||
22 | #include "link-config.h" | |
23 | #include "udev.h" | |
24 | #include "log.h" | |
25 | ||
26 | link_config_ctx *ctx; | |
27 | ||
0b99c9f8 | 28 | static int builtin_net_setup_link(struct udev_device *dev, int argc, char **argv, bool test) { |
af6f0d42 TG |
29 | link_config *link; |
30 | int r; | |
31 | ||
32 | if (argc > 1) { | |
33 | log_error("This program takes no arguments."); | |
34 | return EXIT_FAILURE; | |
35 | } | |
36 | ||
37 | r = link_config_get(ctx, dev, &link); | |
38 | if (r < 0) { | |
39 | if (r == -ENOENT) { | |
43b3a5ef | 40 | log_debug("No matching link configuration found"); |
af6f0d42 TG |
41 | return EXIT_SUCCESS; |
42 | } else { | |
43 | log_error("Could not get link config"); | |
44 | return EXIT_FAILURE; | |
45 | } | |
46 | } | |
47 | ||
48 | r = link_config_apply(ctx, link, dev); | |
49 | if (r < 0) { | |
43b3a5ef | 50 | log_error("Could not apply link config to %s", udev_device_get_sysname(dev)); |
af6f0d42 TG |
51 | return EXIT_FAILURE; |
52 | } | |
53 | ||
54 | return EXIT_SUCCESS; | |
55 | } | |
56 | ||
0b99c9f8 | 57 | static int builtin_net_setup_link_init(struct udev *udev) { |
af6f0d42 TG |
58 | int r; |
59 | ||
60 | if (ctx) | |
61 | return 0; | |
62 | ||
63 | r = link_config_ctx_new(&ctx); | |
64 | if (r < 0) | |
65 | return r; | |
66 | ||
67 | r = link_config_load(ctx); | |
68 | if (r < 0) | |
69 | return r; | |
70 | ||
71 | log_debug("Created link configuration context"); | |
72 | return 0; | |
73 | } | |
74 | ||
0b99c9f8 | 75 | static void builtin_net_setup_link_exit(struct udev *udev) { |
af6f0d42 TG |
76 | link_config_ctx_free(ctx); |
77 | log_debug("Unloaded link configuration context"); | |
78 | } | |
79 | ||
0b99c9f8 | 80 | static bool builtin_net_setup_link_validate(struct udev *udev) { |
af6f0d42 TG |
81 | log_debug("Check if link configuration needs reloading"); |
82 | if (!ctx) | |
83 | return false; | |
84 | ||
85 | return link_config_should_reload(ctx); | |
86 | } | |
87 | ||
0b99c9f8 TG |
88 | const struct udev_builtin udev_builtin_net_setup_link = { |
89 | .name = "net_setup_link", | |
90 | .cmd = builtin_net_setup_link, | |
91 | .init = builtin_net_setup_link_init, | |
92 | .exit = builtin_net_setup_link_exit, | |
93 | .validate = builtin_net_setup_link_validate, | |
af6f0d42 TG |
94 | .help = "configure network link", |
95 | .run_once = false, | |
96 | }; |