link-config.c revision 187dc6e554f2d5b4b5a3bee72c73ff5df6418aa6
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer/***
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer This file is part of systemd.
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer Copyright (C) 2013 Tom Gundersen <teg@jklm.no>
0fe15dc8ddddeb39a5cad1f4f4afa25fa074a5d1Evgeny Vereshchagin
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer systemd is free software; you can redistribute it and/or modify it
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer under the terms of the GNU Lesser General Public License as published by
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer the Free Software Foundation; either version 2.1 of the License, or
3486cb6cfa3d32a95c0daf02c7510fdf372507bfMartin Pitt (at your option) any later version.
3486cb6cfa3d32a95c0daf02c7510fdf372507bfMartin Pitt
3486cb6cfa3d32a95c0daf02c7510fdf372507bfMartin Pitt systemd is distributed in the hope that it will be useful, but
3486cb6cfa3d32a95c0daf02c7510fdf372507bfMartin Pitt WITHOUT ANY WARRANTY; without even the implied warranty of
3486cb6cfa3d32a95c0daf02c7510fdf372507bfMartin Pitt MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1c36b4a73b876258fbe01fbe9bc9b750b7dcc9ceEvgeny Vereshchagin Lesser General Public License for more details.
c50a4525aa8151b180d5a325e88c5f3812e66c36Martin Pitt
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier You should have received a copy of the GNU Lesser General Public License
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier along with systemd; If not, see <http://www.gnu.org/licenses/>.
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier***/
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier#include <netinet/ether.h>
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier#include <net/if.h>
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier#include "sd-id128.h"
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier#include "link-config.h"
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier#include "ethtool-util.h"
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier#include "libudev-private.h"
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier#include "sd-rtnl.h"
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier#include "util.h"
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier#include "log.h"
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier#include "strv.h"
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier#include "path-util.h"
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier#include "conf-parser.h"
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier#include "conf-files.h"
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier#include "fileio.h"
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier#include "hashmap.h"
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier#include "rtnl-util.h"
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier#include "net-util.h"
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalierstruct link_config_ctx {
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier LIST_HEAD(link_config, links);
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
b6f0c419e38a960873fe68bf8f89bbb0268eed02Harald Hoyer int ethtool_fd;
b6f0c419e38a960873fe68bf8f89bbb0268eed02Harald Hoyer
b6f0c419e38a960873fe68bf8f89bbb0268eed02Harald Hoyer bool enable_name_policy;
b6f0c419e38a960873fe68bf8f89bbb0268eed02Harald Hoyer
b6f0c419e38a960873fe68bf8f89bbb0268eed02Harald Hoyer sd_rtnl *rtnl;
b6f0c419e38a960873fe68bf8f89bbb0268eed02Harald Hoyer
b6f0c419e38a960873fe68bf8f89bbb0268eed02Harald Hoyer char **link_dirs;
b6f0c419e38a960873fe68bf8f89bbb0268eed02Harald Hoyer usec_t link_dirs_ts_usec;
61fea35e14d84144e6e2122f5cd247f9c7e6245eEvgeny Vereshchagin};
61fea35e14d84144e6e2122f5cd247f9c7e6245eEvgeny Vereshchagin
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny ChevalierDEFINE_TRIVIAL_CLEANUP_FUNC(link_config_ctx*, link_config_ctx_free);
61fea35e14d84144e6e2122f5cd247f9c7e6245eEvgeny Vereshchagin#define _cleanup_link_config_ctx_free_ _cleanup_(link_config_ctx_freep)
61fea35e14d84144e6e2122f5cd247f9c7e6245eEvgeny Vereshchagin
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalierint link_config_ctx_new(link_config_ctx **ret) {
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier _cleanup_link_config_ctx_free_ link_config_ctx *ctx = NULL;
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier if (!ret)
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier return -EINVAL;
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier ctx = new0(link_config_ctx, 1);
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier if (!ctx)
3486cb6cfa3d32a95c0daf02c7510fdf372507bfMartin Pitt return -ENOMEM;
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier LIST_HEAD_INIT(ctx->links);
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier ctx->ethtool_fd = -1;
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier ctx->enable_name_policy = true;
dbf43a42b8bb66d53c7cbab05f104c28097f811eDaniel Mack
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier ctx->link_dirs = strv_new("/etc/systemd/network",
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier "/run/systemd/network",
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier "/usr/lib/systemd/network",
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier#ifdef HAVE_SPLIT_USR
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier "/lib/systemd/network",
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier#endif
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier NULL);
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier if (!ctx->link_dirs) {
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier log_error("failed to build link config directory array");
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier return -ENOMEM;
dbf43a42b8bb66d53c7cbab05f104c28097f811eDaniel Mack }
dbf43a42b8bb66d53c7cbab05f104c28097f811eDaniel Mack
dbf43a42b8bb66d53c7cbab05f104c28097f811eDaniel Mack if (!path_strv_canonicalize_uniq(ctx->link_dirs)) {
dbf43a42b8bb66d53c7cbab05f104c28097f811eDaniel Mack log_error("failed to canonicalize link config directories\n");
8a8332f77e61d41f3bb28b8f929ed41e0ffaf721Zbigniew Jędrzejewski-Szmek return -ENOMEM;
8a8332f77e61d41f3bb28b8f929ed41e0ffaf721Zbigniew Jędrzejewski-Szmek }
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier *ret = ctx;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier ctx = NULL;
8a8332f77e61d41f3bb28b8f929ed41e0ffaf721Zbigniew Jędrzejewski-Szmek
24be78d72b931b0175f08cee12fd23d631c024bfEvgeny Vereshchagin return 0;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier}
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalierstatic int link_config_ctx_connect(link_config_ctx *ctx) {
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier int r;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier if (ctx->ethtool_fd >= 0 && ctx->rtnl)
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier return 0;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier r = ethtool_connect(&ctx->ethtool_fd);
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier if (r < 0)
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier return r;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier r = sd_rtnl_open(0, &ctx->rtnl);
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier if (r < 0)
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier return r;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier return 0;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier}
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalierstatic void link_configs_free(link_config_ctx *ctx) {
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier link_config *link, *link_next;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier if (!ctx)
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier return;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier LIST_FOREACH_SAFE(links, link, link_next, ctx->links) {
a2fbff31c9c319da51528f85ae97d019f1e61a86Evgeny Vereshchagin free(link->filename);
a2fbff31c9c319da51528f85ae97d019f1e61a86Evgeny Vereshchagin free(link->match_path);
a2fbff31c9c319da51528f85ae97d019f1e61a86Evgeny Vereshchagin free(link->match_driver);
a2fbff31c9c319da51528f85ae97d019f1e61a86Evgeny Vereshchagin free(link->match_type);
a2fbff31c9c319da51528f85ae97d019f1e61a86Evgeny Vereshchagin free(link->description);
a2fbff31c9c319da51528f85ae97d019f1e61a86Evgeny Vereshchagin free(link->alias);
a2fbff31c9c319da51528f85ae97d019f1e61a86Evgeny Vereshchagin
a2fbff31c9c319da51528f85ae97d019f1e61a86Evgeny Vereshchagin free(link);
a2fbff31c9c319da51528f85ae97d019f1e61a86Evgeny Vereshchagin }
a2fbff31c9c319da51528f85ae97d019f1e61a86Evgeny Vereshchagin}
a2fbff31c9c319da51528f85ae97d019f1e61a86Evgeny Vereshchagin
a2fbff31c9c319da51528f85ae97d019f1e61a86Evgeny Vereshchaginvoid link_config_ctx_free(link_config_ctx *ctx) {
a2fbff31c9c319da51528f85ae97d019f1e61a86Evgeny Vereshchagin if (!ctx)
a2fbff31c9c319da51528f85ae97d019f1e61a86Evgeny Vereshchagin return;
a2fbff31c9c319da51528f85ae97d019f1e61a86Evgeny Vereshchagin
a2fbff31c9c319da51528f85ae97d019f1e61a86Evgeny Vereshchagin if (ctx->ethtool_fd >= 0)
a2fbff31c9c319da51528f85ae97d019f1e61a86Evgeny Vereshchagin close_nointr_nofail(ctx->ethtool_fd);
a2fbff31c9c319da51528f85ae97d019f1e61a86Evgeny Vereshchagin
a2fbff31c9c319da51528f85ae97d019f1e61a86Evgeny Vereshchagin sd_rtnl_unref(ctx->rtnl);
cb2f9d3f296bc80b55f09880d61dfdf47fc98212Evgeny Vereshchagin
cb2f9d3f296bc80b55f09880d61dfdf47fc98212Evgeny Vereshchagin strv_free(ctx->link_dirs);
cb2f9d3f296bc80b55f09880d61dfdf47fc98212Evgeny Vereshchagin link_configs_free(ctx);
cb2f9d3f296bc80b55f09880d61dfdf47fc98212Evgeny Vereshchagin
cb2f9d3f296bc80b55f09880d61dfdf47fc98212Evgeny Vereshchagin free(ctx);
cb2f9d3f296bc80b55f09880d61dfdf47fc98212Evgeny Vereshchagin
cb2f9d3f296bc80b55f09880d61dfdf47fc98212Evgeny Vereshchagin return;
cb2f9d3f296bc80b55f09880d61dfdf47fc98212Evgeny Vereshchagin}
cb2f9d3f296bc80b55f09880d61dfdf47fc98212Evgeny Vereshchagin
cb2f9d3f296bc80b55f09880d61dfdf47fc98212Evgeny Vereshchaginstatic int load_link(link_config_ctx *ctx, const char *filename) {
cb2f9d3f296bc80b55f09880d61dfdf47fc98212Evgeny Vereshchagin link_config *link;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier _cleanup_fclose_ FILE *file;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier int r;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier assert(ctx);
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier assert(filename);
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier file = fopen(filename, "re");
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier if (!file) {
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier if (errno == ENOENT)
8a8332f77e61d41f3bb28b8f929ed41e0ffaf721Zbigniew Jędrzejewski-Szmek return 0;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier else
2375607039517c88df51ef16ddbb624ec1c10654Kay Sievers return errno;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier }
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier link = new0(link_config, 1);
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier if (!link) {
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier r = log_oom();
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier goto failure;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier }
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier link->mac_policy = _MACPOLICY_INVALID;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier link->wol = _WOL_INVALID;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier link->duplex = _DUP_INVALID;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier r = config_parse(NULL, filename, file, "Match\0Link\0Ethernet\0", config_item_perf_lookup,
739d81ddd005fae2bb82edce5b8a6173c7c48b34Zbigniew Jędrzejewski-Szmek (void*) link_config_gperf_lookup, false, false, link);
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier if (r < 0) {
1b1eae69ce52ef6c89a1200e8d3758549b291991Daniel Mack log_warning("Could not parse config file %s: %s", filename, strerror(-r));
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier goto failure;
739d81ddd005fae2bb82edce5b8a6173c7c48b34Zbigniew Jędrzejewski-Szmek } else
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier log_debug("Parsed configuration file %s", filename);
edbced8a151c1b7ded685e2ec644950d2adec5f5Harald Hoyer
1b1eae69ce52ef6c89a1200e8d3758549b291991Daniel Mack link->filename = strdup(filename);
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier LIST_PREPEND(links, ctx->links, link);
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
739d81ddd005fae2bb82edce5b8a6173c7c48b34Zbigniew Jędrzejewski-Szmek return 0;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalierfailure:
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier free(link);
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier return r;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier}
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalierstatic bool enable_name_policy(void) {
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier _cleanup_free_ char *line;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier char *w, *state;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier int r;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier size_t l;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier r = proc_cmdline(&line);
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier if (r < 0)
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier log_warning("Failed to read /proc/cmdline, ignoring: %s", strerror(-r));
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier if (r <= 0)
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier return true;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier FOREACH_WORD_QUOTED(w, l, line, state)
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier if (strneq(w, "net.ifnames=0", l))
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier return false;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier return true;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier}
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalierint link_config_load(link_config_ctx *ctx) {
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier int r;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier char **files, **f;
c7eda0133b6bf13a182337cbe8a61bf2faf9b32eEvgeny Vereshchagin
c7eda0133b6bf13a182337cbe8a61bf2faf9b32eEvgeny Vereshchagin link_configs_free(ctx);
c7eda0133b6bf13a182337cbe8a61bf2faf9b32eEvgeny Vereshchagin
c7eda0133b6bf13a182337cbe8a61bf2faf9b32eEvgeny Vereshchagin if (!enable_name_policy()) {
c7eda0133b6bf13a182337cbe8a61bf2faf9b32eEvgeny Vereshchagin ctx->enable_name_policy = false;
c7eda0133b6bf13a182337cbe8a61bf2faf9b32eEvgeny Vereshchagin log_info("Network interface NamePolicy= disabled on kernel commandline, ignoring.");
c7eda0133b6bf13a182337cbe8a61bf2faf9b32eEvgeny Vereshchagin }
c7eda0133b6bf13a182337cbe8a61bf2faf9b32eEvgeny Vereshchagin
c7eda0133b6bf13a182337cbe8a61bf2faf9b32eEvgeny Vereshchagin /* update timestamp */
c7eda0133b6bf13a182337cbe8a61bf2faf9b32eEvgeny Vereshchagin paths_check_timestamp(ctx->link_dirs, &ctx->link_dirs_ts_usec, true);
c7eda0133b6bf13a182337cbe8a61bf2faf9b32eEvgeny Vereshchagin
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier r = conf_files_list_strv(&files, ".link", NULL, (const char **)ctx->link_dirs);
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier if (r < 0) {
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier log_error("failed to enumerate link files: %s", strerror(-r));
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier return r;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier }
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier STRV_FOREACH_BACKWARDS(f, files) {
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier r = load_link(ctx, *f);
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier if (r < 0)
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier return r;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier }
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier return 0;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier}
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalierbool link_config_should_reload(link_config_ctx *ctx) {
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier return paths_check_timestamp(ctx->link_dirs, &ctx->link_dirs_ts_usec, false);
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier}
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalierint link_config_get(link_config_ctx *ctx, struct udev_device *device, link_config **ret) {
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier link_config *link;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier LIST_FOREACH(links, link, ctx->links) {
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier if (net_match_config(link->match_mac, link->match_path,
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier link->match_driver, link->match_type, NULL,
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier udev_device_get_sysattr_value(device, "address"),
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier udev_device_get_property_value(device, "ID_PATH"),
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier udev_device_get_driver(device),
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier udev_device_get_devtype(device),
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier NULL)) {
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier log_debug("Config file %s applies to device %s",
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier link->filename,
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier udev_device_get_sysname(device));
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier *ret = link;
bf3a947cb44f31359bba313e0252cbcc0dc95b03Evgeny Vereshchagin return 0;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier }
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier }
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier *ret = NULL;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier return -ENOENT;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier}
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalierstatic bool mac_is_random(struct udev_device *device) {
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier const char *s;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier unsigned type;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier int r;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier s = udev_device_get_sysattr_value(device, "addr_assign_type");
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier if (!s)
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier return false; /* if we don't know, assume it is not random */
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier r = safe_atou(s, &type);
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier if (r < 0)
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier return false;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
4be4833ece2856e0cacc09f8f8b2c02b320751faMartin Pitt /* check for NET_ADDR_RANDOM */
7d023341c765c205068e33d23d63a4000ec211dfMartin Pitt return type == 1;
7d023341c765c205068e33d23d63a4000ec211dfMartin Pitt}
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalierstatic bool mac_is_permanent(struct udev_device *device) {
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier const char *s;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier unsigned type;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier int r;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier s = udev_device_get_sysattr_value(device, "addr_assign_type");
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier if (!s)
cffae62bcb6912fbaf1b7b282d9d170c9d308897Martin Pitt return true; /* if we don't know, assume it is permanent */
99877b7e3782a51b31bf191825f0335500f52fe5Harald Hoyer r = safe_atou(s, &type);
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier if (r < 0)
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier return true;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
3486cb6cfa3d32a95c0daf02c7510fdf372507bfMartin Pitt /* check for NET_ADDR_PERM */
3486cb6cfa3d32a95c0daf02c7510fdf372507bfMartin Pitt return type == 0;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier}
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
e63b61be5350dbe92ea12e1eeb96dde251ed9292Evgeny Vereshchaginstatic int get_mac(struct udev_device *device, bool want_random, struct ether_addr *mac) {
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier unsigned int seed;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier int r, i;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier if (want_random)
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier seed = random_u();
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier else {
0fe15dc8ddddeb39a5cad1f4f4afa25fa074a5d1Evgeny Vereshchagin const char *name;
0fe15dc8ddddeb39a5cad1f4f4afa25fa074a5d1Evgeny Vereshchagin sd_id128_t machine;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier char machineid_buf[33];
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier const char *seed_str;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier /* fetch some persistent data unique (on this machine) to this device */
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier name = udev_device_get_property_value(device, "ID_NET_NAME_ONBOARD");
0fe15dc8ddddeb39a5cad1f4f4afa25fa074a5d1Evgeny Vereshchagin if (!name) {
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier name = udev_device_get_property_value(device, "ID_NET_NAME_SLOT");
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier if (!name) {
417491f122b346a31cf8dc406c4f9195a5900cecEvgeny Vereshchagin name = udev_device_get_property_value(device, "ID_NET_NAME_PATH");
417491f122b346a31cf8dc406c4f9195a5900cecEvgeny Vereshchagin if (!name)
417491f122b346a31cf8dc406c4f9195a5900cecEvgeny Vereshchagin return -ENOENT;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier }
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier }
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier /* fetch some persistent data unique to this machine */
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier r = sd_id128_get_machine(&machine);
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier if (r < 0)
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier return r;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier /* combine the data */
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier seed_str = strappenda(name, sd_id128_to_string(machine, machineid_buf));
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier /* hash to get seed */
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier seed = string_hash_func(seed_str);
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier }
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
25b47f96d9601ff566257b2a31bfb5f4bd25d661Marko Myllynen srandom(seed);
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier for (i = 0; i < ETH_ALEN; i++) {
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier mac->ether_addr_octet[i] = random();
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier }
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier /* see eth_random_addr in the kernel */
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier mac->ether_addr_octet[0] &= 0xfe; /* clear multicast bit */
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier mac->ether_addr_octet[0] |= 0x02; /* set local assignment bit (IEEE802) */
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier return 0;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier}
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalierint link_config_apply(link_config_ctx *ctx, link_config *config, struct udev_device *device, const char **name) {
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier const char *old_name;
53d90f9582f96208b3674da823ad1a3d2c3b1aa4Martin Pitt const char *new_name = NULL;
5c404f1ab8e96efedb983806443ca982a1b2a372Evgeny Vereshchagin struct ether_addr generated_mac;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier struct ether_addr *mac = NULL;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier int r, ifindex;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier assert(ctx);
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier assert(config);
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier assert(device);
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier assert(name);
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier r = link_config_ctx_connect(ctx);
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier if (r < 0)
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier return r;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier old_name = udev_device_get_sysname(device);
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier if (!old_name)
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier return -EINVAL;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier r = ethtool_set_speed(ctx->ethtool_fd, old_name, config->speed, config->duplex);
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer if (r < 0)
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier log_warning("Could not set speed or duplex of %s to %u Mbytes (%s): %s",
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier old_name, config->speed, duplex_to_string(config->duplex), strerror(-r));
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier r = ethtool_set_wol(ctx->ethtool_fd, old_name, config->wol);
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer if (r < 0)
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer log_warning("Could not set WakeOnLan of %s to %s: %s",
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer old_name, wol_to_string(config->wol), strerror(-r));
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer ifindex = udev_device_get_ifindex(device);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer if (ifindex <= 0) {
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer log_warning("Could not find ifindex");
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer return -ENODEV;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer }
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer if (ctx->enable_name_policy && config->name_policy) {
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer NamePolicy *policy;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer for (policy = config->name_policy; !new_name && *policy != _NAMEPOLICY_INVALID; policy++) {
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer switch (*policy) {
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer case NAMEPOLICY_ONBOARD:
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer new_name = udev_device_get_property_value(device, "ID_NET_NAME_ONBOARD");
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer break;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer case NAMEPOLICY_SLOT:
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer new_name = udev_device_get_property_value(device, "ID_NET_NAME_SLOT");
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer break;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer case NAMEPOLICY_PATH:
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer new_name = udev_device_get_property_value(device, "ID_NET_NAME_PATH");
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer break;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer case NAMEPOLICY_MAC:
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer new_name = udev_device_get_property_value(device, "ID_NET_NAME_MAC");
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer break;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer default:
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer break;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer }
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer }
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer }
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer if (new_name)
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer *name = new_name; /* a name was set by a policy */
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer else if (config->name)
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer *name = config->name; /* a name was set manually in the config */
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer else
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer *name = NULL;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer switch (config->mac_policy) {
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer case MACPOLICY_PERSISTENT:
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer if (!mac_is_permanent(device)) {
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer r = get_mac(device, false, &generated_mac);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer if (r < 0)
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer return r;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer mac = &generated_mac;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier }
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier break;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier case MACPOLICY_RANDOM:
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier if (!mac_is_random(device)) {
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier r = get_mac(device, true, &generated_mac);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer if (r < 0)
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer return r;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer mac = &generated_mac;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer }
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer break;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer default:
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer mac = config->mac;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer }
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer r = rtnl_set_link_properties(ctx->rtnl, ifindex, config->alias, mac, config->mtu);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer if (r < 0) {
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer log_warning("Could not set Alias, MACAddress or MTU on %s: %s", old_name, strerror(-r));
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer return r;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer }
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer return 0;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer}
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyerstatic const char* const mac_policy_table[] = {
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer [MACPOLICY_PERSISTENT] = "persistent",
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer [MACPOLICY_RANDOM] = "random"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer};
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald HoyerDEFINE_STRING_TABLE_LOOKUP(mac_policy, MACPolicy);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald HoyerDEFINE_CONFIG_PARSE_ENUM(config_parse_mac_policy, mac_policy, MACPolicy, "Failed to parse MAC address policy");
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyerstatic const char* const name_policy_table[] = {
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer [NAMEPOLICY_ONBOARD] = "onboard",
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer [NAMEPOLICY_SLOT] = "slot",
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer [NAMEPOLICY_PATH] = "path",
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer [NAMEPOLICY_MAC] = "mac"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer};
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald HoyerDEFINE_STRING_TABLE_LOOKUP(name_policy, NamePolicy);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald HoyerDEFINE_CONFIG_PARSE_ENUMV(config_parse_name_policy, name_policy, NamePolicy, _NAMEPOLICY_INVALID, "Failed to parse interface name policy");
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer