1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright 2013 Tom Gundersen
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.
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.
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/>.
22 #include "link-config.h"
26 static link_config_ctx *ctx = NULL;
28 static int builtin_net_setup_link(struct udev_device *dev, int argc, char **argv, bool test) {
29 _cleanup_free_ char *driver = NULL;
35 log_error("This program takes no arguments.");
39 r = link_get_driver(ctx, dev, &driver);
41 udev_builtin_add_property(dev, test, "ID_NET_DRIVER", driver);
43 r = link_config_get(ctx, dev, &link);
46 log_debug("No matching link configuration found.");
49 log_error("Could not get link config: %s", strerror(-r));
54 r = link_config_apply(ctx, link, dev, &name);
56 log_error("Could not apply link config to %s: %s", udev_device_get_sysname(dev), strerror(-r));
60 udev_builtin_add_property(dev, test, "ID_NET_LINK_FILE", link->filename);
63 udev_builtin_add_property(dev, test, "ID_NET_NAME", name);
68 static int builtin_net_setup_link_init(struct udev *udev) {
74 r = link_config_ctx_new(&ctx);
78 r = link_config_load(ctx);
82 log_debug("Created link configuration context.");
86 static void builtin_net_setup_link_exit(struct udev *udev) {
87 link_config_ctx_free(ctx);
89 log_debug("Unloaded link configuration context.");
92 static bool builtin_net_setup_link_validate(struct udev *udev) {
93 log_debug("Check if link configuration needs reloading.");
97 return link_config_should_reload(ctx);
100 const struct udev_builtin udev_builtin_net_setup_link = {
101 .name = "net_setup_link",
102 .cmd = builtin_net_setup_link,
103 .init = builtin_net_setup_link_init,
104 .exit = builtin_net_setup_link_exit,
105 .validate = builtin_net_setup_link_validate,
106 .help = "configure network link",