X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fudev%2Fnet%2Flink-config.c;h=fe916a4326755e7fc0be49d2c89d77db6e831533;hp=8215c40d5d2cd9730353f0c61cb50dcd2b05d231;hb=e9f3d2d508bfd9fb5b54e82994bda365a71eb864;hpb=505f8da7325591defe5f751f328bd26915267602 diff --git a/src/udev/net/link-config.c b/src/udev/net/link-config.c index 8215c40d5..fe916a432 100644 --- a/src/udev/net/link-config.c +++ b/src/udev/net/link-config.c @@ -92,14 +92,20 @@ static int link_config_ctx_connect(link_config_ctx *ctx) { if (ctx->ethtool_fd == -1) { r = ethtool_connect(&ctx->ethtool_fd); - if (r < 0) + if (r < 0) { + log_warning("link_config: could not connect to ethtool: %s", + strerror(-r)); return r; + } } if (!ctx->rtnl) { r = sd_rtnl_open(&ctx->rtnl, 0); - if (r < 0) + if (r < 0) { + log_warning("link_config: could not connect to rtnl: %s", + strerror(-r)); return r; + } } return 0; @@ -118,6 +124,7 @@ static void link_configs_free(link_config_ctx *ctx) { free(link->match_type); free(link->description); free(link->alias); + free(link->name_policy); free(link); } @@ -140,12 +147,17 @@ void link_config_ctx_free(link_config_ctx *ctx) { static int load_link(link_config_ctx *ctx, const char *filename) { _cleanup_free_ link_config *link = NULL; - _cleanup_fclose_ FILE *file; + _cleanup_fclose_ FILE *file = NULL; int r; assert(ctx); assert(filename); + if (null_or_empty_path(filename)) { + log_debug("skipping empty file: %s", filename); + return 0; + } + file = fopen(filename, "re"); if (!file) { if (errno == ENOENT) @@ -162,8 +174,10 @@ static int load_link(link_config_ctx *ctx, const char *filename) { link->wol = _WOL_INVALID; link->duplex = _DUP_INVALID; - r = config_parse(NULL, filename, file, "Match\0Link\0Ethernet\0", config_item_perf_lookup, - (void*) link_config_gperf_lookup, false, false, link); + r = config_parse(NULL, filename, file, + "Match\0Link\0Ethernet\0", + config_item_perf_lookup, link_config_gperf_lookup, + false, false, link); if (r < 0) { log_warning("Could not parse config file %s: %s", filename, strerror(-r)); return r; @@ -179,7 +193,7 @@ static int load_link(link_config_ctx *ctx, const char *filename) { } static bool enable_name_policy(void) { - _cleanup_free_ char *line; + _cleanup_free_ char *line = NULL; char *w, *state; int r; size_t l; @@ -199,7 +213,8 @@ static bool enable_name_policy(void) { int link_config_load(link_config_ctx *ctx) { int r; - char **files, **f; + _cleanup_strv_free_ char **files; + char **f; link_configs_free(ctx); @@ -273,22 +288,6 @@ static bool mac_is_random(struct udev_device *device) { return type == 1; } -static bool mac_is_permanent(struct udev_device *device) { - const char *s; - unsigned type; - int r; - - s = udev_device_get_sysattr_value(device, "addr_assign_type"); - if (!s) - return true; /* if we don't know, assume it is permanent */ - r = safe_atou(s, &type); - if (r < 0) - return true; - - /* check for NET_ADDR_PERM */ - return type == 0; -} - static int get_mac(struct udev_device *device, bool want_random, struct ether_addr *mac) { int r; @@ -384,9 +383,11 @@ int link_config_apply(link_config_ctx *ctx, link_config *config, struct udev_dev switch (config->mac_policy) { case MACPOLICY_PERSISTENT: - if (!mac_is_permanent(device)) { + if (mac_is_random(device)) { r = get_mac(device, false, &generated_mac); - if (r < 0) + if (r == -ENOENT) + break; + else if (r < 0) return r; mac = &generated_mac; } @@ -394,7 +395,9 @@ int link_config_apply(link_config_ctx *ctx, link_config *config, struct udev_dev case MACPOLICY_RANDOM: if (!mac_is_random(device)) { r = get_mac(device, true, &generated_mac); - if (r < 0) + if (r == -ENOENT) + break; + else if (r < 0) return r; mac = &generated_mac; }