link-config.c revision 3aeb37bc4f32b5edc334f2ac7c5d3c7b0a121328
813e3a6ffcd094696001716480bbd68008cc54c8Patrik Flykt/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
813e3a6ffcd094696001716480bbd68008cc54c8Patrik Flykt
813e3a6ffcd094696001716480bbd68008cc54c8Patrik Flykt/***
813e3a6ffcd094696001716480bbd68008cc54c8Patrik Flykt This file is part of systemd.
813e3a6ffcd094696001716480bbd68008cc54c8Patrik Flykt
813e3a6ffcd094696001716480bbd68008cc54c8Patrik Flykt Copyright (C) 2013 Tom Gundersen <teg@jklm.no>
813e3a6ffcd094696001716480bbd68008cc54c8Patrik Flykt
813e3a6ffcd094696001716480bbd68008cc54c8Patrik Flykt systemd is free software; you can redistribute it and/or modify it
813e3a6ffcd094696001716480bbd68008cc54c8Patrik Flykt under the terms of the GNU Lesser General Public License as published by
813e3a6ffcd094696001716480bbd68008cc54c8Patrik Flykt the Free Software Foundation; either version 2.1 of the License, or
813e3a6ffcd094696001716480bbd68008cc54c8Patrik Flykt (at your option) any later version.
813e3a6ffcd094696001716480bbd68008cc54c8Patrik Flykt
813e3a6ffcd094696001716480bbd68008cc54c8Patrik Flykt systemd is distributed in the hope that it will be useful, but
813e3a6ffcd094696001716480bbd68008cc54c8Patrik Flykt WITHOUT ANY WARRANTY; without even the implied warranty of
813e3a6ffcd094696001716480bbd68008cc54c8Patrik Flykt MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
813e3a6ffcd094696001716480bbd68008cc54c8Patrik Flykt Lesser General Public License for more details.
813e3a6ffcd094696001716480bbd68008cc54c8Patrik Flykt
813e3a6ffcd094696001716480bbd68008cc54c8Patrik Flykt You should have received a copy of the GNU Lesser General Public License
813e3a6ffcd094696001716480bbd68008cc54c8Patrik Flykt along with systemd; If not, see <http://www.gnu.org/licenses/>.
813e3a6ffcd094696001716480bbd68008cc54c8Patrik Flykt***/
813e3a6ffcd094696001716480bbd68008cc54c8Patrik Flykt
813e3a6ffcd094696001716480bbd68008cc54c8Patrik Flykt#include <netinet/ether.h>
813e3a6ffcd094696001716480bbd68008cc54c8Patrik Flykt#include <net/if.h>
2ea8857effb833615b16d10fc7a19a7104c19e13Patrik Flykt
2ea8857effb833615b16d10fc7a19a7104c19e13Patrik Flykt#include "sd-id128.h"
2ea8857effb833615b16d10fc7a19a7104c19e13Patrik Flykt
2ea8857effb833615b16d10fc7a19a7104c19e13Patrik Flykt#include "link-config.h"
813e3a6ffcd094696001716480bbd68008cc54c8Patrik Flykt#include "ethtool-util.h"
2ea8857effb833615b16d10fc7a19a7104c19e13Patrik Flykt
813e3a6ffcd094696001716480bbd68008cc54c8Patrik Flykt#include "libudev-private.h"
813e3a6ffcd094696001716480bbd68008cc54c8Patrik Flykt#include "sd-rtnl.h"
813e3a6ffcd094696001716480bbd68008cc54c8Patrik Flykt#include "util.h"
2ea8857effb833615b16d10fc7a19a7104c19e13Patrik Flykt#include "log.h"
813e3a6ffcd094696001716480bbd68008cc54c8Patrik Flykt#include "strv.h"
813e3a6ffcd094696001716480bbd68008cc54c8Patrik Flykt#include "path-util.h"
813e3a6ffcd094696001716480bbd68008cc54c8Patrik Flykt#include "conf-parser.h"
f12ed3bf0b315fc88d5fbdf5bdca14b218c86e0cPatrik Flykt#include "conf-files.h"
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt#include "fileio.h"
813e3a6ffcd094696001716480bbd68008cc54c8Patrik Flykt#include "hashmap.h"
813e3a6ffcd094696001716480bbd68008cc54c8Patrik Flykt#include "rtnl-util.h"
813e3a6ffcd094696001716480bbd68008cc54c8Patrik Flykt
813e3a6ffcd094696001716480bbd68008cc54c8Patrik Flyktstruct link_config_ctx {
813e3a6ffcd094696001716480bbd68008cc54c8Patrik Flykt LIST_HEAD(link_config, links);
c4e8ceddccfbb14e475e74eb5c57ba32c3c6cf86Patrik Flykt
813e3a6ffcd094696001716480bbd68008cc54c8Patrik Flykt int ethtool_fd;
2ea8857effb833615b16d10fc7a19a7104c19e13Patrik Flykt
2ea8857effb833615b16d10fc7a19a7104c19e13Patrik Flykt sd_rtnl *rtnl;
2ea8857effb833615b16d10fc7a19a7104c19e13Patrik Flykt
5e256ea7d3d556b3a1fb5c1faa94ec6a8833e53ePatrik Flykt char **link_dirs;
5e256ea7d3d556b3a1fb5c1faa94ec6a8833e53ePatrik Flykt usec_t link_dirs_ts_usec;
5e256ea7d3d556b3a1fb5c1faa94ec6a8833e53ePatrik Flykt};
2ea8857effb833615b16d10fc7a19a7104c19e13Patrik Flykt
813e3a6ffcd094696001716480bbd68008cc54c8Patrik FlyktDEFINE_TRIVIAL_CLEANUP_FUNC(link_config_ctx*, link_config_ctx_free);
813e3a6ffcd094696001716480bbd68008cc54c8Patrik Flykt#define _cleanup_link_config_ctx_free_ _cleanup_(link_config_ctx_freep)
813e3a6ffcd094696001716480bbd68008cc54c8Patrik Flykt
813e3a6ffcd094696001716480bbd68008cc54c8Patrik Flyktint link_config_ctx_new(link_config_ctx **ret) {
813e3a6ffcd094696001716480bbd68008cc54c8Patrik Flykt _cleanup_link_config_ctx_free_ link_config_ctx *ctx = NULL;
813e3a6ffcd094696001716480bbd68008cc54c8Patrik Flykt
813e3a6ffcd094696001716480bbd68008cc54c8Patrik Flykt if (!ret)
813e3a6ffcd094696001716480bbd68008cc54c8Patrik Flykt return -EINVAL;
813e3a6ffcd094696001716480bbd68008cc54c8Patrik Flykt
813e3a6ffcd094696001716480bbd68008cc54c8Patrik Flykt ctx = new0(link_config_ctx, 1);
813e3a6ffcd094696001716480bbd68008cc54c8Patrik Flykt if (!ctx)
813e3a6ffcd094696001716480bbd68008cc54c8Patrik Flykt return -ENOMEM;
813e3a6ffcd094696001716480bbd68008cc54c8Patrik Flykt
813e3a6ffcd094696001716480bbd68008cc54c8Patrik Flykt LIST_HEAD_INIT(ctx->links);
813e3a6ffcd094696001716480bbd68008cc54c8Patrik Flykt
813e3a6ffcd094696001716480bbd68008cc54c8Patrik Flykt ctx->ethtool_fd = -1;
76253e73f9c9c24fec755e485516f3b55d0707b4Dan Williams
76253e73f9c9c24fec755e485516f3b55d0707b4Dan Williams ctx->link_dirs = strv_new("/etc/systemd/network",
76253e73f9c9c24fec755e485516f3b55d0707b4Dan Williams "/run/systemd/network",
813e3a6ffcd094696001716480bbd68008cc54c8Patrik Flykt "/usr/lib/systemd/network",
da6fe470e17fa02f3adedc779585caf8669252bdPatrik Flykt NULL);
da6fe470e17fa02f3adedc779585caf8669252bdPatrik Flykt if (!ctx->link_dirs) {
da6fe470e17fa02f3adedc779585caf8669252bdPatrik Flykt log_error("failed to build link config directory array");
da6fe470e17fa02f3adedc779585caf8669252bdPatrik Flykt return -ENOMEM;
da6fe470e17fa02f3adedc779585caf8669252bdPatrik Flykt }
da6fe470e17fa02f3adedc779585caf8669252bdPatrik Flykt
da6fe470e17fa02f3adedc779585caf8669252bdPatrik Flykt if (!path_strv_canonicalize_uniq(ctx->link_dirs)) {
813e3a6ffcd094696001716480bbd68008cc54c8Patrik Flykt log_error("failed to canonicalize link config directories\n");
813e3a6ffcd094696001716480bbd68008cc54c8Patrik Flykt return -ENOMEM;
813e3a6ffcd094696001716480bbd68008cc54c8Patrik Flykt }
813e3a6ffcd094696001716480bbd68008cc54c8Patrik Flykt
813e3a6ffcd094696001716480bbd68008cc54c8Patrik Flykt *ret = ctx;
813e3a6ffcd094696001716480bbd68008cc54c8Patrik Flykt ctx = NULL;
813e3a6ffcd094696001716480bbd68008cc54c8Patrik Flykt
813e3a6ffcd094696001716480bbd68008cc54c8Patrik Flykt return 0;
f12ed3bf0b315fc88d5fbdf5bdca14b218c86e0cPatrik Flykt}
f12ed3bf0b315fc88d5fbdf5bdca14b218c86e0cPatrik Flykt
f12ed3bf0b315fc88d5fbdf5bdca14b218c86e0cPatrik Flyktstatic int link_config_ctx_connect(link_config_ctx *ctx) {
f12ed3bf0b315fc88d5fbdf5bdca14b218c86e0cPatrik Flykt int r;
f12ed3bf0b315fc88d5fbdf5bdca14b218c86e0cPatrik Flykt
f12ed3bf0b315fc88d5fbdf5bdca14b218c86e0cPatrik Flykt if (ctx->ethtool_fd >= 0 && ctx->rtnl)
f12ed3bf0b315fc88d5fbdf5bdca14b218c86e0cPatrik Flykt return 0;
f12ed3bf0b315fc88d5fbdf5bdca14b218c86e0cPatrik Flykt
f12ed3bf0b315fc88d5fbdf5bdca14b218c86e0cPatrik Flykt r = ethtool_connect(&ctx->ethtool_fd);
f12ed3bf0b315fc88d5fbdf5bdca14b218c86e0cPatrik Flykt if (r < 0)
f12ed3bf0b315fc88d5fbdf5bdca14b218c86e0cPatrik Flykt return r;
f12ed3bf0b315fc88d5fbdf5bdca14b218c86e0cPatrik Flykt
f12ed3bf0b315fc88d5fbdf5bdca14b218c86e0cPatrik Flykt r = sd_rtnl_open(0, &ctx->rtnl);
f12ed3bf0b315fc88d5fbdf5bdca14b218c86e0cPatrik Flykt if (r < 0)
f12ed3bf0b315fc88d5fbdf5bdca14b218c86e0cPatrik Flykt return r;
f12ed3bf0b315fc88d5fbdf5bdca14b218c86e0cPatrik Flykt
f12ed3bf0b315fc88d5fbdf5bdca14b218c86e0cPatrik Flykt return 0;
f12ed3bf0b315fc88d5fbdf5bdca14b218c86e0cPatrik Flykt}
f12ed3bf0b315fc88d5fbdf5bdca14b218c86e0cPatrik Flykt
f12ed3bf0b315fc88d5fbdf5bdca14b218c86e0cPatrik Flyktstatic void link_configs_free(link_config_ctx *ctx) {
f12ed3bf0b315fc88d5fbdf5bdca14b218c86e0cPatrik Flykt link_config *link, *link_next;
f12ed3bf0b315fc88d5fbdf5bdca14b218c86e0cPatrik Flykt
f12ed3bf0b315fc88d5fbdf5bdca14b218c86e0cPatrik Flykt if (!ctx)
f12ed3bf0b315fc88d5fbdf5bdca14b218c86e0cPatrik Flykt return;
f12ed3bf0b315fc88d5fbdf5bdca14b218c86e0cPatrik Flykt
f12ed3bf0b315fc88d5fbdf5bdca14b218c86e0cPatrik Flykt LIST_FOREACH_SAFE(links, link, link_next, ctx->links) {
f12ed3bf0b315fc88d5fbdf5bdca14b218c86e0cPatrik Flykt free(link->filename);
f12ed3bf0b315fc88d5fbdf5bdca14b218c86e0cPatrik Flykt free(link->match_path);
f12ed3bf0b315fc88d5fbdf5bdca14b218c86e0cPatrik Flykt free(link->match_driver);
f12ed3bf0b315fc88d5fbdf5bdca14b218c86e0cPatrik Flykt free(link->match_type);
f12ed3bf0b315fc88d5fbdf5bdca14b218c86e0cPatrik Flykt free(link->description);
f12ed3bf0b315fc88d5fbdf5bdca14b218c86e0cPatrik Flykt
f12ed3bf0b315fc88d5fbdf5bdca14b218c86e0cPatrik Flykt free(link);
f12ed3bf0b315fc88d5fbdf5bdca14b218c86e0cPatrik Flykt }
f12ed3bf0b315fc88d5fbdf5bdca14b218c86e0cPatrik Flykt}
f12ed3bf0b315fc88d5fbdf5bdca14b218c86e0cPatrik Flykt
f12ed3bf0b315fc88d5fbdf5bdca14b218c86e0cPatrik Flyktvoid link_config_ctx_free(link_config_ctx *ctx) {
f12ed3bf0b315fc88d5fbdf5bdca14b218c86e0cPatrik Flykt if (!ctx)
f12ed3bf0b315fc88d5fbdf5bdca14b218c86e0cPatrik Flykt return;
f12ed3bf0b315fc88d5fbdf5bdca14b218c86e0cPatrik Flykt
f12ed3bf0b315fc88d5fbdf5bdca14b218c86e0cPatrik Flykt if (ctx->ethtool_fd >= 0)
f12ed3bf0b315fc88d5fbdf5bdca14b218c86e0cPatrik Flykt close_nointr_nofail(ctx->ethtool_fd);
f12ed3bf0b315fc88d5fbdf5bdca14b218c86e0cPatrik Flykt
f12ed3bf0b315fc88d5fbdf5bdca14b218c86e0cPatrik Flykt sd_rtnl_unref(ctx->rtnl);
f12ed3bf0b315fc88d5fbdf5bdca14b218c86e0cPatrik Flykt
f12ed3bf0b315fc88d5fbdf5bdca14b218c86e0cPatrik Flykt strv_free(ctx->link_dirs);
f12ed3bf0b315fc88d5fbdf5bdca14b218c86e0cPatrik Flykt link_configs_free(ctx);
f12ed3bf0b315fc88d5fbdf5bdca14b218c86e0cPatrik Flykt
f12ed3bf0b315fc88d5fbdf5bdca14b218c86e0cPatrik Flykt free(ctx);
f12ed3bf0b315fc88d5fbdf5bdca14b218c86e0cPatrik Flykt
f12ed3bf0b315fc88d5fbdf5bdca14b218c86e0cPatrik Flykt return;
f12ed3bf0b315fc88d5fbdf5bdca14b218c86e0cPatrik Flykt}
f12ed3bf0b315fc88d5fbdf5bdca14b218c86e0cPatrik Flykt
f12ed3bf0b315fc88d5fbdf5bdca14b218c86e0cPatrik Flyktstatic int load_link(link_config_ctx *ctx, const char *filename) {
f12ed3bf0b315fc88d5fbdf5bdca14b218c86e0cPatrik Flykt link_config *link;
f12ed3bf0b315fc88d5fbdf5bdca14b218c86e0cPatrik Flykt FILE *file;
f12ed3bf0b315fc88d5fbdf5bdca14b218c86e0cPatrik Flykt int r;
f12ed3bf0b315fc88d5fbdf5bdca14b218c86e0cPatrik Flykt
f12ed3bf0b315fc88d5fbdf5bdca14b218c86e0cPatrik Flykt file = fopen(filename, "re");
f12ed3bf0b315fc88d5fbdf5bdca14b218c86e0cPatrik Flykt if (!file) {
f12ed3bf0b315fc88d5fbdf5bdca14b218c86e0cPatrik Flykt if (errno == ENOENT)
f12ed3bf0b315fc88d5fbdf5bdca14b218c86e0cPatrik Flykt return 0;
f12ed3bf0b315fc88d5fbdf5bdca14b218c86e0cPatrik Flykt else
f12ed3bf0b315fc88d5fbdf5bdca14b218c86e0cPatrik Flykt return errno;
f12ed3bf0b315fc88d5fbdf5bdca14b218c86e0cPatrik Flykt }
f12ed3bf0b315fc88d5fbdf5bdca14b218c86e0cPatrik Flykt
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt link = new0(link_config, 1);
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt if (!link) {
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt r = log_oom();
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt goto failure;
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt }
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt link->mac_policy = _MACPOLICY_INVALID;
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt link->wol = _WOL_INVALID;
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt link->duplex = _DUP_INVALID;
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt r = config_parse(NULL, filename, file, "Match\0Link\0Ethernet\0", config_item_perf_lookup,
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt (void*) link_config_gperf_lookup, false, false, link);
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt if (r < 0) {
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt log_warning("Colud not parse config file %s: %s", filename, strerror(-r));
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt goto failure;
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt } else
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt log_info("Parsed configuration file %s", filename);
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt link->filename = strdup(filename);
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt LIST_PREPEND(links, ctx->links, link);
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt return 0;
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flyktfailure:
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt free(link);
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt return r;
947527f8326d3591f252c48fee5426a563f03544Patrik Flykt}
947527f8326d3591f252c48fee5426a563f03544Patrik Flykt
947527f8326d3591f252c48fee5426a563f03544Patrik Flyktint link_config_load(link_config_ctx *ctx) {
947527f8326d3591f252c48fee5426a563f03544Patrik Flykt int r;
947527f8326d3591f252c48fee5426a563f03544Patrik Flykt char **files, **f;
947527f8326d3591f252c48fee5426a563f03544Patrik Flykt
947527f8326d3591f252c48fee5426a563f03544Patrik Flykt link_configs_free(ctx);
947527f8326d3591f252c48fee5426a563f03544Patrik Flykt
947527f8326d3591f252c48fee5426a563f03544Patrik Flykt /* update timestamp */
947527f8326d3591f252c48fee5426a563f03544Patrik Flykt paths_check_timestamp(ctx->link_dirs, &ctx->link_dirs_ts_usec, true);
947527f8326d3591f252c48fee5426a563f03544Patrik Flykt
947527f8326d3591f252c48fee5426a563f03544Patrik Flykt r = conf_files_list_strv(&files, ".link", NULL, (const char **)ctx->link_dirs);
947527f8326d3591f252c48fee5426a563f03544Patrik Flykt if (r < 0) {
947527f8326d3591f252c48fee5426a563f03544Patrik Flykt log_error("failed to enumerate link files: %s", strerror(-r));
947527f8326d3591f252c48fee5426a563f03544Patrik Flykt return r;
947527f8326d3591f252c48fee5426a563f03544Patrik Flykt }
947527f8326d3591f252c48fee5426a563f03544Patrik Flykt
947527f8326d3591f252c48fee5426a563f03544Patrik Flykt STRV_FOREACH_BACKWARDS(f, files) {
947527f8326d3591f252c48fee5426a563f03544Patrik Flykt r = load_link(ctx, *f);
947527f8326d3591f252c48fee5426a563f03544Patrik Flykt if (r < 0)
947527f8326d3591f252c48fee5426a563f03544Patrik Flykt return r;
947527f8326d3591f252c48fee5426a563f03544Patrik Flykt }
947527f8326d3591f252c48fee5426a563f03544Patrik Flykt
947527f8326d3591f252c48fee5426a563f03544Patrik Flykt return 0;
947527f8326d3591f252c48fee5426a563f03544Patrik Flykt}
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flyktbool link_config_should_reload(link_config_ctx *ctx) {
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt return paths_check_timestamp(ctx->link_dirs, &ctx->link_dirs_ts_usec, false);
44481a8b537839cd9ffead4d261491641f5b5260Zbigniew Jędrzejewski-Szmek}
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt
d182960ae974a0074010a058d0d909846a2f3f79Patrik Flyktstatic bool match_config(link_config *match, struct udev_device *device) {
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt const char *property;
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt if (match->match_mac) {
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt property = udev_device_get_sysattr_value(device, "address");
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt if (!property || memcmp(match->match_mac, ether_aton(property), ETH_ALEN)) {
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt log_debug("Device MAC address (%s) did not match MACAddress=%s",
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt property, ether_ntoa(match->match_mac));
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt return 0;
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt }
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt }
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt if (match->match_path) {
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt property = udev_device_get_property_value(device, "ID_PATH");
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt if (!streq_ptr(match->match_path, property)) {
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt log_debug("Device's persistent path (%s) did not match Path=%s",
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt property, match->match_path);
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt return 0;
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt }
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt }
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt if (match->match_driver) {
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt property = udev_device_get_driver(device);
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt if (!streq_ptr(match->match_driver, property)) {
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt log_debug("Device driver (%s) did not match Driver=%s",
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt property, match->match_driver);
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt return 0;
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt }
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt }
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt if (match->match_type) {
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt property = udev_device_get_devtype(device);
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt if (!streq_ptr(match->match_type, property)) {
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt log_debug("Device type (%s) did not match Type=%s",
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt property, match->match_type);
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt return 0;
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt }
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt }
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt return 1;
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt}
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flyktint link_config_get(link_config_ctx *ctx, struct udev_device *device, link_config **ret) {
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt link_config *link;
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt LIST_FOREACH(links, link, ctx->links) {
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt if (!match_config(link, device)) {
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt log_info("Config file %s does not apply to device %s", link->filename, udev_device_get_sysname(device));
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt } else {
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt log_info("Config file %s applies to device %s", link->filename, udev_device_get_sysname(device));
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt *ret = link;
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt return 0;
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt }
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt }
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt return -ENOENT;
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt}
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flyktstatic bool enable_name_policy(void) {
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt _cleanup_free_ char *line;
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt char *w, *state;
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt int r;
d63be95a306bf1e262c7e1c7ad4b2c12b49d371ePatrik Flykt size_t l;
d63be95a306bf1e262c7e1c7ad4b2c12b49d371ePatrik Flykt
d63be95a306bf1e262c7e1c7ad4b2c12b49d371ePatrik Flykt r = read_one_line_file("/proc/cmdline", &line);
d63be95a306bf1e262c7e1c7ad4b2c12b49d371ePatrik Flykt if (r < 0) {
d63be95a306bf1e262c7e1c7ad4b2c12b49d371ePatrik Flykt log_warning("Failed to read /proc/cmdline, ignoring: %s", strerror(-r));
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt return true; /* something is very wrong, let's not make it worse */
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt }
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt FOREACH_WORD_QUOTED(w, l, line, state)
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt if (strneq(w, "net.ifnames=0", l))
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt return false;
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt return true;
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt}
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt
e7504d95479455be5cef120fc8e0a48fd74ad5caPatrik Flyktstatic bool mac_is_random(struct udev_device *device) {
e7504d95479455be5cef120fc8e0a48fd74ad5caPatrik Flykt const char *s;
e7504d95479455be5cef120fc8e0a48fd74ad5caPatrik Flykt unsigned type;
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt int r;
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt s = udev_device_get_sysattr_value(device, "addr_assign_type");
e7504d95479455be5cef120fc8e0a48fd74ad5caPatrik Flykt if (!s)
e7504d95479455be5cef120fc8e0a48fd74ad5caPatrik Flykt return false; /* if we don't know, assume it is not random */
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt r = safe_atou(s, &type);
e7504d95479455be5cef120fc8e0a48fd74ad5caPatrik Flykt if (r < 0)
e7504d95479455be5cef120fc8e0a48fd74ad5caPatrik Flykt return false;
e7504d95479455be5cef120fc8e0a48fd74ad5caPatrik Flykt
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt /* check for NET_ADDR_RANDOM */
e7504d95479455be5cef120fc8e0a48fd74ad5caPatrik Flykt return type == 1;
e7504d95479455be5cef120fc8e0a48fd74ad5caPatrik Flykt}
e7504d95479455be5cef120fc8e0a48fd74ad5caPatrik Flykt
e7504d95479455be5cef120fc8e0a48fd74ad5caPatrik Flyktstatic bool mac_is_permanent(struct udev_device *device) {
e7504d95479455be5cef120fc8e0a48fd74ad5caPatrik Flykt const char *s;
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt unsigned type;
e7504d95479455be5cef120fc8e0a48fd74ad5caPatrik Flykt int r;
e7504d95479455be5cef120fc8e0a48fd74ad5caPatrik Flykt
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt s = udev_device_get_sysattr_value(device, "addr_assign_type");
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt if (!s)
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt return true; /* if we don't know, assume it is permanent */
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt r = safe_atou(s, &type);
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt if (r < 0)
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt return true;
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt /* check for NET_ADDR_PERM */
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt return type == 0;
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt}
859cca44f834ab1cc3e41fa6b94744f1856ab027Patrik Flykt
2ea8857effb833615b16d10fc7a19a7104c19e13Patrik Flyktstatic int get_mac(struct udev_device *device, bool want_random, struct ether_addr *mac) {
2ea8857effb833615b16d10fc7a19a7104c19e13Patrik Flykt unsigned int seed;
2ea8857effb833615b16d10fc7a19a7104c19e13Patrik Flykt int r, i;
2ea8857effb833615b16d10fc7a19a7104c19e13Patrik Flykt
2ea8857effb833615b16d10fc7a19a7104c19e13Patrik Flykt if (want_random)
2ea8857effb833615b16d10fc7a19a7104c19e13Patrik Flykt seed = random_u();
2ea8857effb833615b16d10fc7a19a7104c19e13Patrik Flykt else {
2ea8857effb833615b16d10fc7a19a7104c19e13Patrik Flykt const char *name;
2ea8857effb833615b16d10fc7a19a7104c19e13Patrik Flykt sd_id128_t machine;
2ea8857effb833615b16d10fc7a19a7104c19e13Patrik Flykt char machineid_buf[33];
2ea8857effb833615b16d10fc7a19a7104c19e13Patrik Flykt const char *seed_str;
2ea8857effb833615b16d10fc7a19a7104c19e13Patrik Flykt
2ea8857effb833615b16d10fc7a19a7104c19e13Patrik Flykt /* fetch some persistent data unique (on this machine) to this device */
2ea8857effb833615b16d10fc7a19a7104c19e13Patrik Flykt name = udev_device_get_property_value(device, "ID_NET_NAME_ONBOARD");
2ea8857effb833615b16d10fc7a19a7104c19e13Patrik Flykt if (!name) {
2ea8857effb833615b16d10fc7a19a7104c19e13Patrik Flykt name = udev_device_get_property_value(device, "ID_NET_NAME_SLOT");
2ea8857effb833615b16d10fc7a19a7104c19e13Patrik Flykt if (!name) {
2ea8857effb833615b16d10fc7a19a7104c19e13Patrik Flykt name = udev_device_get_property_value(device, "ID_NET_NAME_PATH");
c4e8ceddccfbb14e475e74eb5c57ba32c3c6cf86Patrik Flykt if (!name)
c4e8ceddccfbb14e475e74eb5c57ba32c3c6cf86Patrik Flykt return -ENOENT;
c4e8ceddccfbb14e475e74eb5c57ba32c3c6cf86Patrik Flykt }
2ea8857effb833615b16d10fc7a19a7104c19e13Patrik Flykt }
c4e8ceddccfbb14e475e74eb5c57ba32c3c6cf86Patrik Flykt /* fetch some persistent data unique to this machine */
c4e8ceddccfbb14e475e74eb5c57ba32c3c6cf86Patrik Flykt r = sd_id128_get_machine(&machine);
2ea8857effb833615b16d10fc7a19a7104c19e13Patrik Flykt if (r < 0)
c4e8ceddccfbb14e475e74eb5c57ba32c3c6cf86Patrik Flykt return r;
c4e8ceddccfbb14e475e74eb5c57ba32c3c6cf86Patrik Flykt
c4e8ceddccfbb14e475e74eb5c57ba32c3c6cf86Patrik Flykt /* combine the data */
c4e8ceddccfbb14e475e74eb5c57ba32c3c6cf86Patrik Flykt seed_str = strappenda(name, sd_id128_to_string(machine, machineid_buf));
c4e8ceddccfbb14e475e74eb5c57ba32c3c6cf86Patrik Flykt
c4e8ceddccfbb14e475e74eb5c57ba32c3c6cf86Patrik Flykt /* hash to get seed */
2ea8857effb833615b16d10fc7a19a7104c19e13Patrik Flykt seed = string_hash_func(seed_str);
2ea8857effb833615b16d10fc7a19a7104c19e13Patrik Flykt }
5e256ea7d3d556b3a1fb5c1faa94ec6a8833e53ePatrik Flykt
947527f8326d3591f252c48fee5426a563f03544Patrik Flykt srandom(seed);
947527f8326d3591f252c48fee5426a563f03544Patrik Flykt
947527f8326d3591f252c48fee5426a563f03544Patrik Flykt for(i = 0; i < ETH_ALEN; i++) {
947527f8326d3591f252c48fee5426a563f03544Patrik Flykt mac->ether_addr_octet[i] = random();
947527f8326d3591f252c48fee5426a563f03544Patrik Flykt }
947527f8326d3591f252c48fee5426a563f03544Patrik Flykt
947527f8326d3591f252c48fee5426a563f03544Patrik Flykt /* see eth_random_addr in the kernel */
947527f8326d3591f252c48fee5426a563f03544Patrik Flykt mac->ether_addr_octet[0] &= 0xfe; /* clear multicast bit */
947527f8326d3591f252c48fee5426a563f03544Patrik Flykt mac->ether_addr_octet[0] |= 0x02; /* set local assignment bit (IEEE802) */
947527f8326d3591f252c48fee5426a563f03544Patrik Flykt
947527f8326d3591f252c48fee5426a563f03544Patrik Flykt return 0;
947527f8326d3591f252c48fee5426a563f03544Patrik Flykt}
947527f8326d3591f252c48fee5426a563f03544Patrik Flykt
947527f8326d3591f252c48fee5426a563f03544Patrik Flyktint link_config_apply(link_config_ctx *ctx, link_config *config, struct udev_device *device) {
5e256ea7d3d556b3a1fb5c1faa94ec6a8833e53ePatrik Flykt const char *name;
5e256ea7d3d556b3a1fb5c1faa94ec6a8833e53ePatrik Flykt const char *new_name = NULL;
5e256ea7d3d556b3a1fb5c1faa94ec6a8833e53ePatrik Flykt struct ether_addr generated_mac;
5e256ea7d3d556b3a1fb5c1faa94ec6a8833e53ePatrik Flykt struct ether_addr *mac = NULL;
5e256ea7d3d556b3a1fb5c1faa94ec6a8833e53ePatrik Flykt int r, ifindex;
5e256ea7d3d556b3a1fb5c1faa94ec6a8833e53ePatrik Flykt
5e256ea7d3d556b3a1fb5c1faa94ec6a8833e53ePatrik Flykt r = link_config_ctx_connect(ctx);
5e256ea7d3d556b3a1fb5c1faa94ec6a8833e53ePatrik Flykt if (r < 0)
5e256ea7d3d556b3a1fb5c1faa94ec6a8833e53ePatrik Flykt return r;
d63be95a306bf1e262c7e1c7ad4b2c12b49d371ePatrik Flykt
d63be95a306bf1e262c7e1c7ad4b2c12b49d371ePatrik Flykt name = udev_device_get_sysname(device);
5e256ea7d3d556b3a1fb5c1faa94ec6a8833e53ePatrik Flykt if (!name)
5e256ea7d3d556b3a1fb5c1faa94ec6a8833e53ePatrik Flykt return -EINVAL;
5e256ea7d3d556b3a1fb5c1faa94ec6a8833e53ePatrik Flykt
5e256ea7d3d556b3a1fb5c1faa94ec6a8833e53ePatrik Flykt log_info("Configuring %s", name);
5e256ea7d3d556b3a1fb5c1faa94ec6a8833e53ePatrik Flykt
5e256ea7d3d556b3a1fb5c1faa94ec6a8833e53ePatrik Flykt if (config->description) {
5e256ea7d3d556b3a1fb5c1faa94ec6a8833e53ePatrik Flykt r = udev_device_set_sysattr_value(device, "ifalias",
5e256ea7d3d556b3a1fb5c1faa94ec6a8833e53ePatrik Flykt config->description);
5e256ea7d3d556b3a1fb5c1faa94ec6a8833e53ePatrik Flykt if (r < 0)
5e256ea7d3d556b3a1fb5c1faa94ec6a8833e53ePatrik Flykt log_warning("Could not set description of %s to '%s': %s",
5e256ea7d3d556b3a1fb5c1faa94ec6a8833e53ePatrik Flykt name, config->description, strerror(-r));
5e256ea7d3d556b3a1fb5c1faa94ec6a8833e53ePatrik Flykt }
5e256ea7d3d556b3a1fb5c1faa94ec6a8833e53ePatrik Flykt
5e256ea7d3d556b3a1fb5c1faa94ec6a8833e53ePatrik Flykt r = ethtool_set_speed(ctx->ethtool_fd, name, config->speed, config->duplex);
5e256ea7d3d556b3a1fb5c1faa94ec6a8833e53ePatrik Flykt if (r < 0)
5e256ea7d3d556b3a1fb5c1faa94ec6a8833e53ePatrik Flykt log_warning("Could not set speed or duplex of %s to %u Mbytes (%s): %s",
5e256ea7d3d556b3a1fb5c1faa94ec6a8833e53ePatrik Flykt name, config->speed, duplex_to_string(config->duplex), strerror(-r));
5e256ea7d3d556b3a1fb5c1faa94ec6a8833e53ePatrik Flykt
5e256ea7d3d556b3a1fb5c1faa94ec6a8833e53ePatrik Flykt r = ethtool_set_wol(ctx->ethtool_fd, name, config->wol);
5e256ea7d3d556b3a1fb5c1faa94ec6a8833e53ePatrik Flykt if (r < 0)
5e256ea7d3d556b3a1fb5c1faa94ec6a8833e53ePatrik Flykt log_warning("Could not set WakeOnLan of %s to %s: %s",
5e256ea7d3d556b3a1fb5c1faa94ec6a8833e53ePatrik Flykt name, wol_to_string(config->wol), strerror(-r));
5e256ea7d3d556b3a1fb5c1faa94ec6a8833e53ePatrik Flykt
5e256ea7d3d556b3a1fb5c1faa94ec6a8833e53ePatrik Flykt ifindex = udev_device_get_ifindex(device);
5e256ea7d3d556b3a1fb5c1faa94ec6a8833e53ePatrik Flykt if (ifindex <= 0) {
5e256ea7d3d556b3a1fb5c1faa94ec6a8833e53ePatrik Flykt log_warning("Could not find ifindex");
5e256ea7d3d556b3a1fb5c1faa94ec6a8833e53ePatrik Flykt return -ENODEV;
5e256ea7d3d556b3a1fb5c1faa94ec6a8833e53ePatrik Flykt }
5e256ea7d3d556b3a1fb5c1faa94ec6a8833e53ePatrik Flykt
5e256ea7d3d556b3a1fb5c1faa94ec6a8833e53ePatrik Flykt if (config->name_policy && enable_name_policy()) {
5e256ea7d3d556b3a1fb5c1faa94ec6a8833e53ePatrik Flykt NamePolicy *policy;
5e256ea7d3d556b3a1fb5c1faa94ec6a8833e53ePatrik Flykt
5e256ea7d3d556b3a1fb5c1faa94ec6a8833e53ePatrik Flykt for (policy = config->name_policy; !new_name && *policy != _NAMEPOLICY_INVALID; policy++) {
5e256ea7d3d556b3a1fb5c1faa94ec6a8833e53ePatrik Flykt switch (*policy) {
5e256ea7d3d556b3a1fb5c1faa94ec6a8833e53ePatrik Flykt case NAMEPOLICY_ONBOARD:
5e256ea7d3d556b3a1fb5c1faa94ec6a8833e53ePatrik Flykt new_name = udev_device_get_property_value(device, "ID_NET_NAME_ONBOARD");
5e256ea7d3d556b3a1fb5c1faa94ec6a8833e53ePatrik Flykt break;
5e256ea7d3d556b3a1fb5c1faa94ec6a8833e53ePatrik Flykt case NAMEPOLICY_SLOT:
5e256ea7d3d556b3a1fb5c1faa94ec6a8833e53ePatrik Flykt new_name = udev_device_get_property_value(device, "ID_NET_NAME_SLOT");
5e256ea7d3d556b3a1fb5c1faa94ec6a8833e53ePatrik Flykt break;
5e256ea7d3d556b3a1fb5c1faa94ec6a8833e53ePatrik Flykt case NAMEPOLICY_PATH:
5e256ea7d3d556b3a1fb5c1faa94ec6a8833e53ePatrik Flykt new_name = udev_device_get_property_value(device, "ID_NET_NAME_PATH");
5e256ea7d3d556b3a1fb5c1faa94ec6a8833e53ePatrik Flykt break;
5e256ea7d3d556b3a1fb5c1faa94ec6a8833e53ePatrik Flykt case NAMEPOLICY_MAC:
5e256ea7d3d556b3a1fb5c1faa94ec6a8833e53ePatrik Flykt new_name = udev_device_get_property_value(device, "ID_NET_NAME_MAC");
5e256ea7d3d556b3a1fb5c1faa94ec6a8833e53ePatrik Flykt break;
5e256ea7d3d556b3a1fb5c1faa94ec6a8833e53ePatrik Flykt default:
d63be95a306bf1e262c7e1c7ad4b2c12b49d371ePatrik Flykt break;
d63be95a306bf1e262c7e1c7ad4b2c12b49d371ePatrik Flykt }
d63be95a306bf1e262c7e1c7ad4b2c12b49d371ePatrik Flykt }
d63be95a306bf1e262c7e1c7ad4b2c12b49d371ePatrik Flykt }
d63be95a306bf1e262c7e1c7ad4b2c12b49d371ePatrik Flykt
d63be95a306bf1e262c7e1c7ad4b2c12b49d371ePatrik Flykt if (!new_name && config->name) {
d63be95a306bf1e262c7e1c7ad4b2c12b49d371ePatrik Flykt new_name = config->name;
d63be95a306bf1e262c7e1c7ad4b2c12b49d371ePatrik Flykt }
5e256ea7d3d556b3a1fb5c1faa94ec6a8833e53ePatrik Flykt
5e256ea7d3d556b3a1fb5c1faa94ec6a8833e53ePatrik Flykt switch (config->mac_policy) {
5e256ea7d3d556b3a1fb5c1faa94ec6a8833e53ePatrik Flykt case MACPOLICY_PERSISTENT:
5e256ea7d3d556b3a1fb5c1faa94ec6a8833e53ePatrik Flykt if (!mac_is_permanent(device)) {
5e256ea7d3d556b3a1fb5c1faa94ec6a8833e53ePatrik Flykt r = get_mac(device, false, &generated_mac);
d63be95a306bf1e262c7e1c7ad4b2c12b49d371ePatrik Flykt if (r < 0)
d63be95a306bf1e262c7e1c7ad4b2c12b49d371ePatrik Flykt return r;
5e256ea7d3d556b3a1fb5c1faa94ec6a8833e53ePatrik Flykt mac = &generated_mac;
e7504d95479455be5cef120fc8e0a48fd74ad5caPatrik Flykt }
e7504d95479455be5cef120fc8e0a48fd74ad5caPatrik Flykt break;
e7504d95479455be5cef120fc8e0a48fd74ad5caPatrik Flykt case MACPOLICY_RANDOM:
5e256ea7d3d556b3a1fb5c1faa94ec6a8833e53ePatrik Flykt if (!mac_is_random(device)) {
5e256ea7d3d556b3a1fb5c1faa94ec6a8833e53ePatrik Flykt r = get_mac(device, true, &generated_mac);
5e256ea7d3d556b3a1fb5c1faa94ec6a8833e53ePatrik Flykt if (r < 0)
5e256ea7d3d556b3a1fb5c1faa94ec6a8833e53ePatrik Flykt return r;
e7504d95479455be5cef120fc8e0a48fd74ad5caPatrik Flykt mac = &generated_mac;
e7504d95479455be5cef120fc8e0a48fd74ad5caPatrik Flykt }
5e256ea7d3d556b3a1fb5c1faa94ec6a8833e53ePatrik Flykt break;
5e256ea7d3d556b3a1fb5c1faa94ec6a8833e53ePatrik Flykt default:
5e256ea7d3d556b3a1fb5c1faa94ec6a8833e53ePatrik Flykt mac = config->mac;
5e256ea7d3d556b3a1fb5c1faa94ec6a8833e53ePatrik Flykt }
5e256ea7d3d556b3a1fb5c1faa94ec6a8833e53ePatrik Flykt
5e256ea7d3d556b3a1fb5c1faa94ec6a8833e53ePatrik Flykt r = rtnl_set_link_properties(ctx->rtnl, ifindex, new_name, mac, config->mtu);
5e256ea7d3d556b3a1fb5c1faa94ec6a8833e53ePatrik Flykt if (r < 0) {
5e256ea7d3d556b3a1fb5c1faa94ec6a8833e53ePatrik Flykt log_warning("Could not set Name, MACAddress or MTU on %s: %s", name, strerror(-r));
5e256ea7d3d556b3a1fb5c1faa94ec6a8833e53ePatrik Flykt return r;
5e256ea7d3d556b3a1fb5c1faa94ec6a8833e53ePatrik Flykt }
5e256ea7d3d556b3a1fb5c1faa94ec6a8833e53ePatrik Flykt
5e256ea7d3d556b3a1fb5c1faa94ec6a8833e53ePatrik Flykt return 0;
5e256ea7d3d556b3a1fb5c1faa94ec6a8833e53ePatrik Flykt}
5e256ea7d3d556b3a1fb5c1faa94ec6a8833e53ePatrik Flykt