link-config.c revision 733f7a2c69c794a81978a08a79916c224ba355a6
91f9dcaf9270fe465525638cc08bd94590273349Lennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
5430f7f2bc7330f3088b894166bf3524a067e3d8Lennart Poettering This file is part of systemd.
91f9dcaf9270fe465525638cc08bd94590273349Lennart Poettering Copyright (C) 2013 Tom Gundersen <teg@jklm.no>
91f9dcaf9270fe465525638cc08bd94590273349Lennart Poettering systemd is free software; you can redistribute it and/or modify it
91f9dcaf9270fe465525638cc08bd94590273349Lennart Poettering under the terms of the GNU Lesser General Public License as published by
3f612b9123208577736957786633ead53ae41b66Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
49dbfa7b2b0bf3906704dac1eaeb4eba91056a19Lennart Poettering (at your option) any later version.
91f9dcaf9270fe465525638cc08bd94590273349Lennart Poettering systemd is distributed in the hope that it will be useful, but
91f9dcaf9270fe465525638cc08bd94590273349Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
91f9dcaf9270fe465525638cc08bd94590273349Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
454591be36880b0300b0448576c483a39d9cc611Lennart Poettering Lesser General Public License for more details.
91f9dcaf9270fe465525638cc08bd94590273349Lennart Poettering You should have received a copy of the GNU Lesser General Public License
9c07474c6fa296195dcdc734d77792dff95f5c35Mike Kazantsev along with systemd; If not, see <http://www.gnu.org/licenses/>.
#include "sd-id128.h"
#include "link-config.h"
#include "ethtool-util.h"
#include "libudev-private.h"
#include "sd-rtnl.h"
#include "util.h"
#include "log.h"
#include "strv.h"
#include "path-util.h"
#include "conf-parser.h"
#include "conf-files.h"
#include "fileio.h"
#include "hashmap.h"
#include "rtnl-util.h"
#include "net-util.h"
#include "siphash24.h"
struct link_config_ctx {
int ethtool_fd;
bool enable_name_policy;
static const char* const link_dirs[] = {
#ifdef HAVE_SPLIT_USR
NULL};
if (!ret)
return -EINVAL;
if (!ctx)
return -ENOMEM;
if (!ctx)
if (!ctx)
if (!file) {
return errno;
if (!link) {
r = log_oom();
goto failure;
goto failure;
static bool enable_name_policy(void) {
char *w, *state;
size_t l;
char **files, **f;
if (!enable_name_policy()) {
NULL)) {
return -ENOENT;
unsigned type;
unsigned type;
return type == 0;
if (want_random)
const char *name;
uint8_t *v;
if (!name) {
if (!name) {
if (!name)
return -ENOENT;
int link_config_apply(link_config_ctx *ctx, link_config *config, struct udev_device *device, const char **name) {
const char *old_name;
int r, ifindex;
if (!old_name)
return -EINVAL;
strerror(-r));
if (ifindex <= 0) {
return -ENODEV;
switch (*policy) {
case NAMEPOLICY_DATABASE:
case NAMEPOLICY_ONBOARD:
case NAMEPOLICY_SLOT:
case NAMEPOLICY_PATH:
case NAMEPOLICY_MAC:
if (new_name)
case MACPOLICY_PERSISTENT:
case MACPOLICY_RANDOM:
const char *name;
char *driver;
if (!name)
return -EINVAL;
static const char* const mac_policy_table[] = {
DEFINE_CONFIG_PARSE_ENUM(config_parse_mac_policy, mac_policy, MACPolicy, "Failed to parse MAC address policy");
static const char* const name_policy_table[] = {
DEFINE_CONFIG_PARSE_ENUMV(config_parse_name_policy, name_policy, NamePolicy, _NAMEPOLICY_INVALID, "Failed to parse interface name policy");