link-config.c revision 5fde13d748749f0e06e2e6cdd15f0980a79ea82c
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright (C) 2013 Tom Gundersen <teg@jklm.no>
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
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"
struct link_config_ctx {
int ethtool_fd;
char **link_dirs;
};
int r;
if (!ret)
return -EINVAL;
if (!ctx)
return -ENOMEM;
if (r < 0) {
return r;
}
if (r < 0) {
return r;
}
NULL);
log_error("failed to build link config directory array");
return -ENOMEM;
}
log_error("failed to canonicalize link config directories\n");
return -ENOMEM;
}
if(!ctx->link_dirs_ts_usec) {
return -ENOMEM;
}
return 0;
}
if (!ctx)
return;
}
}
if (!ctx)
return;
if (ctx->ethtool_fd >= 0)
return;
}
int r;
if (!file) {
return 0;
else
return errno;
}
if (!link) {
r = log_oom();
goto failure;
}
(void*) link_config_gperf_lookup, false, false, link);
if (r < 0) {
goto failure;
} else
return 0;
return r;
}
int r;
char **files, **f;
/* update timestamps */
if (r < 0) {
return r;
}
STRV_FOREACH_BACKWARDS(f, files) {
if (r < 0)
return r;
}
return 0;
}
}
const char *property;
log_debug("Device MAC address (%s) did not match MACAddress=%s",
return 0;
}
}
if (match->match_path) {
log_debug("Device's persistent path (%s) did not match Path=%s",
return 0;
}
}
if (match->match_driver) {
log_debug("Device driver (%s) did not match Driver=%s",
return 0;
}
}
if (match->match_type) {
log_debug("Device type (%s) did not match Type=%s",
return 0;
}
}
return 1;
}
log_info("Config file %s does not apply to device %s", link->filename, udev_device_get_sysname(device));
} else {
return 0;
}
}
return -ENOENT;
}
static int rtnl_set_properties(sd_rtnl *rtnl, int ifindex, const char *name, const struct ether_addr *mac, unsigned int mtu) {
bool need_update = false;
int r;
if (r < 0)
return r;
if (name) {
if (r < 0)
return r;
need_update = true;
}
if (mac) {
if (r < 0)
return r;
need_update = true;
}
if (mtu > 0) {
if (r < 0)
return r;
need_update = true;
}
if (need_update) {
if (r < 0)
return r;
}
return 0;
}
static bool enable_name_policy(void) {
_cleanup_free_ char *line;
char *w, *state;
int r;
size_t l;
if (r < 0) {
return true; /* something is very wrong, let's not make it worse */
}
if (strneq(w, "net.ifnames=0", l))
return false;
return true;
}
const char *s;
int type;
if (!s)
return -EINVAL;
/* check for NET_ADDR_RANDOM */
return type == 1;
}
const char *s;
int type;
if (!s)
return -EINVAL;
/* check for NET_ADDR_PERM */
return type == 0;
}
unsigned int seed;
int r, i;
if (want_random)
else {
const char *name;
char machineid_buf[33];
const char *seed_str;
/* fetch some persistent data unique (on this machine) to this device */
if (!name) {
if (!name) {
if (!name)
return -1;
}
}
/* fetch some persistent data unique to this machine */
r = sd_id128_get_machine(&machine);
if (r < 0)
return -1;
/* combine the data */
/* hash to get seed */
}
for(i = 0; i < ETH_ALEN; i++) {
}
/* see eth_random_addr in the kernel */
return 0;
}
const char *name;
struct ether_addr generated_mac;
int r, ifindex;
if (!name)
return -EINVAL;
if (config->description) {
if (r < 0)
log_warning("Could not set description of %s to '%s': %s",
}
if (r < 0)
log_warning("Could not set speed or duplex of %s to %u Mbytes (%s): %s",
if (r < 0)
log_warning("Could not set WakeOnLan of %s to %s: %s",
if (ifindex <= 0) {
log_warning("Could not find ifindex");
return -ENODEV;
}
switch (*policy) {
case NAMEPOLICY_ONBOARD:
break;
case NAMEPOLICY_SLOT:
break;
case NAMEPOLICY_PATH:
break;
case NAMEPOLICY_MAC:
break;
default:
break;
}
}
}
}
switch (config->mac_policy) {
case MACPOLICY_PERSISTENT:
if (!mac_is_permanent(device)) {
if (r < 0)
return r;
mac = &generated_mac;
}
break;
case MACPOLICY_RANDOM:
if (!mac_is_random(device)) {
if (r < 0)
return r;
mac = &generated_mac;
}
break;
default:
}
if (r < 0) {
return r;
}
return 0;
}