2 This file is part of systemd.
4 Copyright 2013 Tom Gundersen
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.
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.
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/>.
20 #include "alloc-util.h"
21 #include "link-config.h"
25 static link_config_ctx
*ctx
= NULL
;
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
;
34 log_error("This program takes no arguments.");
38 r
= link_get_driver(ctx
, dev
, &driver
);
40 udev_builtin_add_property(dev
, test
, "ID_NET_DRIVER", driver
);
42 r
= link_config_get(ctx
, dev
, &link
);
45 log_debug("No matching link configuration found.");
48 log_error_errno(r
, "Could not get link config: %m");
53 r
= link_config_apply(ctx
, link
, dev
, &name
);
55 log_warning_errno(r
, "Could not apply link config to %s, ignoring: %m", udev_device_get_sysname(dev
));
57 udev_builtin_add_property(dev
, test
, "ID_NET_LINK_FILE", link
->filename
);
60 udev_builtin_add_property(dev
, test
, "ID_NET_NAME", name
);
65 static int builtin_net_setup_link_init(struct udev
*udev
) {
71 r
= link_config_ctx_new(&ctx
);
75 r
= link_config_load(ctx
);
79 log_debug("Created link configuration context.");
83 static void builtin_net_setup_link_exit(struct udev
*udev
) {
84 link_config_ctx_free(ctx
);
86 log_debug("Unloaded link configuration context.");
89 static bool builtin_net_setup_link_validate(struct udev
*udev
) {
90 log_debug("Check if link configuration needs reloading.");
94 return link_config_should_reload(ctx
);
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",