1
0
mirror of https://github.com/systemd/systemd.git synced 2024-10-30 14:55:37 +03:00

udev/net: rename link_config_ctx -> LinkConfigContext

This commit is contained in:
Yu Watanabe 2021-05-23 16:37:28 +09:00
parent 2a5a844259
commit afca7ac13d
4 changed files with 30 additions and 36 deletions

View File

@ -7,7 +7,7 @@
#include "tmpfile-util.h"
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
_cleanup_(link_config_ctx_freep) link_config_ctx *ctx = NULL;
_cleanup_(link_config_ctx_freep) LinkConfigContext *ctx = NULL;
_cleanup_(unlink_tempfilep) char filename[] = "/tmp/fuzz-link-config.XXXXXX";
_cleanup_fclose_ FILE *f = NULL;

View File

@ -33,15 +33,11 @@
#include "strv.h"
#include "utf8.h"
struct link_config_ctx {
struct LinkConfigContext {
LIST_HEAD(link_config, links);
int ethtool_fd;
bool enable_name_policy;
sd_netlink *rtnl;
usec_t network_dirs_ts_usec;
};
@ -67,7 +63,7 @@ static link_config* link_config_free(link_config *link) {
DEFINE_TRIVIAL_CLEANUP_FUNC(link_config*, link_config_free);
static void link_configs_free(link_config_ctx *ctx) {
static void link_configs_free(LinkConfigContext *ctx) {
link_config *link, *link_next;
if (!ctx)
@ -77,7 +73,7 @@ static void link_configs_free(link_config_ctx *ctx) {
link_config_free(link);
}
link_config_ctx* link_config_ctx_free(link_config_ctx *ctx) {
LinkConfigContext *link_config_ctx_free(LinkConfigContext *ctx) {
if (!ctx)
return NULL;
@ -87,28 +83,27 @@ link_config_ctx* link_config_ctx_free(link_config_ctx *ctx) {
return mfree(ctx);
}
int link_config_ctx_new(link_config_ctx **ret) {
_cleanup_(link_config_ctx_freep) link_config_ctx *ctx = NULL;
int link_config_ctx_new(LinkConfigContext **ret) {
_cleanup_(link_config_ctx_freep) LinkConfigContext *ctx = NULL;
if (!ret)
return -EINVAL;
ctx = new0(link_config_ctx, 1);
ctx = new(LinkConfigContext, 1);
if (!ctx)
return -ENOMEM;
LIST_HEAD_INIT(ctx->links);
ctx->ethtool_fd = -1;
ctx->enable_name_policy = true;
*ctx = (LinkConfigContext) {
.ethtool_fd = -1,
.enable_name_policy = true,
};
*ret = TAKE_PTR(ctx);
return 0;
}
int link_load_one(link_config_ctx *ctx, const char *filename) {
int link_load_one(LinkConfigContext *ctx, const char *filename) {
_cleanup_(link_config_freep) link_config *link = NULL;
_cleanup_free_ char *name = NULL;
const char *dropin_dirname;
@ -210,7 +205,7 @@ static int link_unsigned_attribute(sd_device *device, const char *attr, unsigned
return 0;
}
int link_config_load(link_config_ctx *ctx) {
int link_config_load(LinkConfigContext *ctx) {
_cleanup_strv_free_ char **files = NULL;
char **f;
int r;
@ -238,11 +233,11 @@ int link_config_load(link_config_ctx *ctx) {
return 0;
}
bool link_config_should_reload(link_config_ctx *ctx) {
bool link_config_should_reload(LinkConfigContext *ctx) {
return paths_check_timestamp(NETWORK_DIRS, &ctx->network_dirs_ts_usec, false);
}
int link_config_get(link_config_ctx *ctx, sd_device *device, link_config **ret) {
int link_config_get(LinkConfigContext *ctx, sd_device *device, link_config **ret) {
unsigned name_assign_type = NET_NAME_UNKNOWN;
struct ether_addr permanent_mac = {};
unsigned short iftype = 0;
@ -443,7 +438,7 @@ static int link_config_apply_rtnl_settings(sd_netlink **rtnl, const link_config
return 0;
}
static int link_config_generate_new_name(const link_config_ctx *ctx, const link_config *config, sd_device *device, const char **ret_name) {
static int link_config_generate_new_name(const LinkConfigContext *ctx, const link_config *config, sd_device *device, const char **ret_name) {
unsigned name_type = NET_NAME_UNKNOWN;
int r;
@ -596,7 +591,7 @@ static int link_config_apply_alternative_names(sd_netlink **rtnl, const link_con
return 0;
}
int link_config_apply(link_config_ctx *ctx, const link_config *config, sd_device *device, const char **ret_name) {
int link_config_apply(LinkConfigContext *ctx, const link_config *config, sd_device *device, const char **ret_name) {
const char *new_name;
sd_device_action_t a;
int r;
@ -648,7 +643,7 @@ int link_config_apply(link_config_ctx *ctx, const link_config *config, sd_device
return 0;
}
int link_get_driver(link_config_ctx *ctx, sd_device *device, char **ret) {
int link_get_driver(LinkConfigContext *ctx, sd_device *device, char **ret) {
const char *name;
char *driver = NULL;
int r;

View File

@ -9,7 +9,7 @@
#include "list.h"
#include "net-condition.h"
typedef struct link_config_ctx link_config_ctx;
typedef struct LinkConfigContext LinkConfigContext;
typedef struct link_config link_config;
typedef enum MACAddressPolicy {
@ -68,17 +68,17 @@ struct link_config {
LIST_FIELDS(link_config, links);
};
int link_config_ctx_new(link_config_ctx **ret);
link_config_ctx* link_config_ctx_free(link_config_ctx *ctx);
DEFINE_TRIVIAL_CLEANUP_FUNC(link_config_ctx*, link_config_ctx_free);
int link_config_ctx_new(LinkConfigContext **ret);
LinkConfigContext* link_config_ctx_free(LinkConfigContext *ctx);
DEFINE_TRIVIAL_CLEANUP_FUNC(LinkConfigContext*, link_config_ctx_free);
int link_load_one(link_config_ctx *ctx, const char *filename);
int link_config_load(link_config_ctx *ctx);
bool link_config_should_reload(link_config_ctx *ctx);
int link_load_one(LinkConfigContext *ctx, const char *filename);
int link_config_load(LinkConfigContext *ctx);
bool link_config_should_reload(LinkConfigContext *ctx);
int link_config_get(link_config_ctx *ctx, sd_device *device, link_config **ret);
int link_config_apply(link_config_ctx *ctx, const link_config *config, sd_device *device, const char **ret_name);
int link_get_driver(link_config_ctx *ctx, sd_device *device, char **ret);
int link_config_get(LinkConfigContext *ctx, sd_device *device, link_config **ret);
int link_config_apply(LinkConfigContext *ctx, const link_config *config, sd_device *device, const char **ret_name);
int link_get_driver(LinkConfigContext *ctx, sd_device *device, char **ret);
const char *name_policy_to_string(NamePolicy p) _const_;
NamePolicy name_policy_from_string(const char *p) _pure_;

View File

@ -8,7 +8,7 @@
#include "string-util.h"
#include "udev-builtin.h"
static link_config_ctx *ctx = NULL;
static LinkConfigContext *ctx = NULL;
static int builtin_net_setup_link(sd_device *dev, int argc, char **argv, bool test) {
_cleanup_free_ char *driver = NULL;
@ -69,8 +69,7 @@ static int builtin_net_setup_link_init(void) {
}
static void builtin_net_setup_link_exit(void) {
link_config_ctx_free(ctx);
ctx = NULL;
ctx = link_config_ctx_free(ctx);
log_debug("Unloaded link configuration context.");
}