mirror of
https://github.com/systemd/systemd
synced 2026-03-16 18:14:46 +01:00
Compare commits
6 Commits
113d94c393
...
8a2f7b7c9b
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8a2f7b7c9b | ||
|
|
341d883ad6 | ||
|
|
70f32a260b | ||
|
|
f25e642bca | ||
|
|
ce01c07f1c | ||
|
|
afca7ac13d |
@ -34,7 +34,7 @@ def rearrange_bin_sbin(path):
|
|||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
path = os.environ['PATH'] # This should be always set.
|
path = os.environ['PATH'] # This should be always set.
|
||||||
# If it's not, we'll just crash, we is OK too.
|
# If it's not, we'll just crash, which is OK too.
|
||||||
new = rearrange_bin_sbin(path)
|
new = rearrange_bin_sbin(path)
|
||||||
if new != path:
|
if new != path:
|
||||||
print('PATH={}'.format(new))
|
print('PATH={}'.format(new))
|
||||||
|
|||||||
@ -302,10 +302,18 @@ int rtnl_resolve_link_alternative_name(sd_netlink **rtnl, const char *name) {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int rtnl_get_link_iftype(sd_netlink **rtnl, int ifindex, unsigned short *ret) {
|
int rtnl_get_link_info(sd_netlink **rtnl, int ifindex, unsigned short *ret_iftype, unsigned *ret_flags) {
|
||||||
_cleanup_(sd_netlink_message_unrefp) sd_netlink_message *message = NULL, *reply = NULL;
|
_cleanup_(sd_netlink_message_unrefp) sd_netlink_message *message = NULL, *reply = NULL;
|
||||||
|
unsigned short iftype;
|
||||||
|
unsigned flags;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
|
assert(rtnl);
|
||||||
|
assert(ifindex > 0);
|
||||||
|
|
||||||
|
if (!ret_iftype && !ret_flags)
|
||||||
|
return 0;
|
||||||
|
|
||||||
if (!*rtnl) {
|
if (!*rtnl) {
|
||||||
r = sd_netlink_open(rtnl);
|
r = sd_netlink_open(rtnl);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
@ -322,7 +330,23 @@ int rtnl_get_link_iftype(sd_netlink **rtnl, int ifindex, unsigned short *ret) {
|
|||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
return sd_rtnl_message_link_get_type(reply, ret);
|
if (ret_iftype) {
|
||||||
|
r = sd_rtnl_message_link_get_type(reply, &iftype);
|
||||||
|
if (r < 0)
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ret_flags) {
|
||||||
|
r = sd_rtnl_message_link_get_flags(reply, &flags);
|
||||||
|
if (r < 0)
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ret_iftype)
|
||||||
|
*ret_iftype = iftype;
|
||||||
|
if (ret_flags)
|
||||||
|
*ret_flags = flags;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int rtnl_message_new_synthetic_error(sd_netlink *rtnl, int error, uint32_t serial, sd_netlink_message **ret) {
|
int rtnl_message_new_synthetic_error(sd_netlink *rtnl, int error, uint32_t serial, sd_netlink_message **ret) {
|
||||||
|
|||||||
@ -92,7 +92,7 @@ int rtnl_set_link_alternative_names(sd_netlink **rtnl, int ifindex, char * const
|
|||||||
int rtnl_set_link_alternative_names_by_ifname(sd_netlink **rtnl, const char *ifname, char * const *alternative_names);
|
int rtnl_set_link_alternative_names_by_ifname(sd_netlink **rtnl, const char *ifname, char * const *alternative_names);
|
||||||
int rtnl_delete_link_alternative_names(sd_netlink **rtnl, int ifindex, char * const *alternative_names);
|
int rtnl_delete_link_alternative_names(sd_netlink **rtnl, int ifindex, char * const *alternative_names);
|
||||||
int rtnl_resolve_link_alternative_name(sd_netlink **rtnl, const char *name);
|
int rtnl_resolve_link_alternative_name(sd_netlink **rtnl, const char *name);
|
||||||
int rtnl_get_link_iftype(sd_netlink **rtnl, int ifindex, unsigned short *ret);
|
int rtnl_get_link_info(sd_netlink **rtnl, int ifindex, unsigned short *ret_iftype, unsigned *ret_flags);
|
||||||
|
|
||||||
int rtnl_log_parse_error(int r);
|
int rtnl_log_parse_error(int r);
|
||||||
int rtnl_log_create_error(int r);
|
int rtnl_log_create_error(int r);
|
||||||
|
|||||||
@ -7,7 +7,7 @@
|
|||||||
#include "tmpfile-util.h"
|
#include "tmpfile-util.h"
|
||||||
|
|
||||||
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
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_(unlink_tempfilep) char filename[] = "/tmp/fuzz-link-config.XXXXXX";
|
||||||
_cleanup_fclose_ FILE *f = NULL;
|
_cleanup_fclose_ FILE *f = NULL;
|
||||||
|
|
||||||
|
|||||||
@ -21,54 +21,54 @@ struct ConfigPerfItem;
|
|||||||
%struct-type
|
%struct-type
|
||||||
%includes
|
%includes
|
||||||
%%
|
%%
|
||||||
Match.MACAddress, config_parse_hwaddrs, 0, offsetof(link_config, match.mac)
|
Match.MACAddress, config_parse_hwaddrs, 0, offsetof(LinkConfig, match.mac)
|
||||||
Match.PermanentMACAddress, config_parse_hwaddrs, 0, offsetof(link_config, match.permanent_mac)
|
Match.PermanentMACAddress, config_parse_hwaddrs, 0, offsetof(LinkConfig, match.permanent_mac)
|
||||||
Match.OriginalName, config_parse_match_ifnames, 0, offsetof(link_config, match.ifname)
|
Match.OriginalName, config_parse_match_ifnames, 0, offsetof(LinkConfig, match.ifname)
|
||||||
Match.Path, config_parse_match_strv, 0, offsetof(link_config, match.path)
|
Match.Path, config_parse_match_strv, 0, offsetof(LinkConfig, match.path)
|
||||||
Match.Driver, config_parse_match_strv, 0, offsetof(link_config, match.driver)
|
Match.Driver, config_parse_match_strv, 0, offsetof(LinkConfig, match.driver)
|
||||||
Match.Type, config_parse_match_strv, 0, offsetof(link_config, match.iftype)
|
Match.Type, config_parse_match_strv, 0, offsetof(LinkConfig, match.iftype)
|
||||||
Match.Property, config_parse_match_property, 0, offsetof(link_config, match.property)
|
Match.Property, config_parse_match_property, 0, offsetof(LinkConfig, match.property)
|
||||||
Match.Host, config_parse_net_condition, CONDITION_HOST, offsetof(link_config, conditions)
|
Match.Host, config_parse_net_condition, CONDITION_HOST, offsetof(LinkConfig, conditions)
|
||||||
Match.Virtualization, config_parse_net_condition, CONDITION_VIRTUALIZATION, offsetof(link_config, conditions)
|
Match.Virtualization, config_parse_net_condition, CONDITION_VIRTUALIZATION, offsetof(LinkConfig, conditions)
|
||||||
Match.KernelCommandLine, config_parse_net_condition, CONDITION_KERNEL_COMMAND_LINE, offsetof(link_config, conditions)
|
Match.KernelCommandLine, config_parse_net_condition, CONDITION_KERNEL_COMMAND_LINE, offsetof(LinkConfig, conditions)
|
||||||
Match.KernelVersion, config_parse_net_condition, CONDITION_KERNEL_VERSION, offsetof(link_config, conditions)
|
Match.KernelVersion, config_parse_net_condition, CONDITION_KERNEL_VERSION, offsetof(LinkConfig, conditions)
|
||||||
Match.Architecture, config_parse_net_condition, CONDITION_ARCHITECTURE, offsetof(link_config, conditions)
|
Match.Architecture, config_parse_net_condition, CONDITION_ARCHITECTURE, offsetof(LinkConfig, conditions)
|
||||||
Link.Description, config_parse_string, 0, offsetof(link_config, description)
|
Link.Description, config_parse_string, 0, offsetof(LinkConfig, description)
|
||||||
Link.MACAddressPolicy, config_parse_mac_address_policy, 0, offsetof(link_config, mac_address_policy)
|
Link.MACAddressPolicy, config_parse_mac_address_policy, 0, offsetof(LinkConfig, mac_address_policy)
|
||||||
Link.MACAddress, config_parse_hwaddr, 0, offsetof(link_config, mac)
|
Link.MACAddress, config_parse_hwaddr, 0, offsetof(LinkConfig, mac)
|
||||||
Link.NamePolicy, config_parse_name_policy, 0, offsetof(link_config, name_policy)
|
Link.NamePolicy, config_parse_name_policy, 0, offsetof(LinkConfig, name_policy)
|
||||||
Link.Name, config_parse_ifname, 0, offsetof(link_config, name)
|
Link.Name, config_parse_ifname, 0, offsetof(LinkConfig, name)
|
||||||
Link.AlternativeName, config_parse_ifnames, IFNAME_VALID_ALTERNATIVE, offsetof(link_config, alternative_names)
|
Link.AlternativeName, config_parse_ifnames, IFNAME_VALID_ALTERNATIVE, offsetof(LinkConfig, alternative_names)
|
||||||
Link.AlternativeNamesPolicy, config_parse_alternative_names_policy, 0, offsetof(link_config, alternative_names_policy)
|
Link.AlternativeNamesPolicy, config_parse_alternative_names_policy, 0, offsetof(LinkConfig, alternative_names_policy)
|
||||||
Link.Alias, config_parse_ifalias, 0, offsetof(link_config, alias)
|
Link.Alias, config_parse_ifalias, 0, offsetof(LinkConfig, alias)
|
||||||
Link.TransmitQueues, config_parse_rx_tx_queues, 0, offsetof(link_config, txqueues)
|
Link.TransmitQueues, config_parse_rx_tx_queues, 0, offsetof(LinkConfig, txqueues)
|
||||||
Link.ReceiveQueues, config_parse_rx_tx_queues, 0, offsetof(link_config, rxqueues)
|
Link.ReceiveQueues, config_parse_rx_tx_queues, 0, offsetof(LinkConfig, rxqueues)
|
||||||
Link.TransmitQueueLength, config_parse_txqueuelen, 0, offsetof(link_config, txqueuelen)
|
Link.TransmitQueueLength, config_parse_txqueuelen, 0, offsetof(LinkConfig, txqueuelen)
|
||||||
Link.MTUBytes, config_parse_mtu, AF_UNSPEC, offsetof(link_config, mtu)
|
Link.MTUBytes, config_parse_mtu, AF_UNSPEC, offsetof(LinkConfig, mtu)
|
||||||
Link.BitsPerSecond, config_parse_si_uint64, 0, offsetof(link_config, speed)
|
Link.BitsPerSecond, config_parse_si_uint64, 0, offsetof(LinkConfig, speed)
|
||||||
Link.Duplex, config_parse_duplex, 0, offsetof(link_config, duplex)
|
Link.Duplex, config_parse_duplex, 0, offsetof(LinkConfig, duplex)
|
||||||
Link.AutoNegotiation, config_parse_tristate, 0, offsetof(link_config, autonegotiation)
|
Link.AutoNegotiation, config_parse_tristate, 0, offsetof(LinkConfig, autonegotiation)
|
||||||
Link.WakeOnLan, config_parse_wol, 0, offsetof(link_config, wol)
|
Link.WakeOnLan, config_parse_wol, 0, offsetof(LinkConfig, wol)
|
||||||
Link.Port, config_parse_port, 0, offsetof(link_config, port)
|
Link.Port, config_parse_port, 0, offsetof(LinkConfig, port)
|
||||||
Link.ReceiveChecksumOffload, config_parse_tristate, 0, offsetof(link_config, features[NET_DEV_FEAT_RX])
|
Link.ReceiveChecksumOffload, config_parse_tristate, 0, offsetof(LinkConfig, features[NET_DEV_FEAT_RX])
|
||||||
Link.TransmitChecksumOffload, config_parse_tristate, 0, offsetof(link_config, features[NET_DEV_FEAT_TX])
|
Link.TransmitChecksumOffload, config_parse_tristate, 0, offsetof(LinkConfig, features[NET_DEV_FEAT_TX])
|
||||||
Link.GenericSegmentationOffload, config_parse_tristate, 0, offsetof(link_config, features[NET_DEV_FEAT_GSO])
|
Link.GenericSegmentationOffload, config_parse_tristate, 0, offsetof(LinkConfig, features[NET_DEV_FEAT_GSO])
|
||||||
Link.TCPSegmentationOffload, config_parse_tristate, 0, offsetof(link_config, features[NET_DEV_FEAT_TSO])
|
Link.TCPSegmentationOffload, config_parse_tristate, 0, offsetof(LinkConfig, features[NET_DEV_FEAT_TSO])
|
||||||
Link.TCP6SegmentationOffload, config_parse_tristate, 0, offsetof(link_config, features[NET_DEV_FEAT_TSO6])
|
Link.TCP6SegmentationOffload, config_parse_tristate, 0, offsetof(LinkConfig, features[NET_DEV_FEAT_TSO6])
|
||||||
Link.UDPSegmentationOffload, config_parse_warn_compat, DISABLED_LEGACY, 0
|
Link.UDPSegmentationOffload, config_parse_warn_compat, DISABLED_LEGACY, 0
|
||||||
Link.GenericReceiveOffload, config_parse_tristate, 0, offsetof(link_config, features[NET_DEV_FEAT_GRO])
|
Link.GenericReceiveOffload, config_parse_tristate, 0, offsetof(LinkConfig, features[NET_DEV_FEAT_GRO])
|
||||||
Link.LargeReceiveOffload, config_parse_tristate, 0, offsetof(link_config, features[NET_DEV_FEAT_LRO])
|
Link.LargeReceiveOffload, config_parse_tristate, 0, offsetof(LinkConfig, features[NET_DEV_FEAT_LRO])
|
||||||
Link.RxChannels, config_parse_channel, 0, offsetof(link_config, channels)
|
Link.RxChannels, config_parse_channel, 0, offsetof(LinkConfig, channels)
|
||||||
Link.TxChannels, config_parse_channel, 0, offsetof(link_config, channels)
|
Link.TxChannels, config_parse_channel, 0, offsetof(LinkConfig, channels)
|
||||||
Link.OtherChannels, config_parse_channel, 0, offsetof(link_config, channels)
|
Link.OtherChannels, config_parse_channel, 0, offsetof(LinkConfig, channels)
|
||||||
Link.CombinedChannels, config_parse_channel, 0, offsetof(link_config, channels)
|
Link.CombinedChannels, config_parse_channel, 0, offsetof(LinkConfig, channels)
|
||||||
Link.Advertise, config_parse_advertise, 0, offsetof(link_config, advertise)
|
Link.Advertise, config_parse_advertise, 0, offsetof(LinkConfig, advertise)
|
||||||
Link.RxBufferSize, config_parse_nic_buffer_size, 0, offsetof(link_config, ring)
|
Link.RxBufferSize, config_parse_nic_buffer_size, 0, offsetof(LinkConfig, ring)
|
||||||
Link.RxMiniBufferSize, config_parse_nic_buffer_size, 0, offsetof(link_config, ring)
|
Link.RxMiniBufferSize, config_parse_nic_buffer_size, 0, offsetof(LinkConfig, ring)
|
||||||
Link.RxJumboBufferSize, config_parse_nic_buffer_size, 0, offsetof(link_config, ring)
|
Link.RxJumboBufferSize, config_parse_nic_buffer_size, 0, offsetof(LinkConfig, ring)
|
||||||
Link.TxBufferSize, config_parse_nic_buffer_size, 0, offsetof(link_config, ring)
|
Link.TxBufferSize, config_parse_nic_buffer_size, 0, offsetof(LinkConfig, ring)
|
||||||
Link.RxFlowControl, config_parse_tristate, 0, offsetof(link_config, rx_flow_control)
|
Link.RxFlowControl, config_parse_tristate, 0, offsetof(LinkConfig, rx_flow_control)
|
||||||
Link.TxFlowControl, config_parse_tristate, 0, offsetof(link_config, tx_flow_control)
|
Link.TxFlowControl, config_parse_tristate, 0, offsetof(LinkConfig, tx_flow_control)
|
||||||
Link.AutoNegotiationFlowControl, config_parse_tristate, 0, offsetof(link_config, autoneg_flow_control)
|
Link.AutoNegotiationFlowControl, config_parse_tristate, 0, offsetof(LinkConfig, autoneg_flow_control)
|
||||||
Link.GenericSegmentOffloadMaxBytes, config_parse_iec_size, 0, offsetof(link_config, gso_max_size)
|
Link.GenericSegmentOffloadMaxBytes, config_parse_iec_size, 0, offsetof(LinkConfig, gso_max_size)
|
||||||
Link.GenericSegmentOffloadMaxSegments, config_parse_uint32, 0, offsetof(link_config, gso_max_segments)
|
Link.GenericSegmentOffloadMaxSegments, config_parse_uint32, 0, offsetof(LinkConfig, gso_max_segments)
|
||||||
|
|||||||
@ -33,19 +33,15 @@
|
|||||||
#include "strv.h"
|
#include "strv.h"
|
||||||
#include "utf8.h"
|
#include "utf8.h"
|
||||||
|
|
||||||
struct link_config_ctx {
|
struct LinkConfigContext {
|
||||||
LIST_HEAD(link_config, links);
|
LIST_HEAD(LinkConfig, links);
|
||||||
|
|
||||||
int ethtool_fd;
|
int ethtool_fd;
|
||||||
|
|
||||||
bool enable_name_policy;
|
bool enable_name_policy;
|
||||||
|
|
||||||
sd_netlink *rtnl;
|
sd_netlink *rtnl;
|
||||||
|
|
||||||
usec_t network_dirs_ts_usec;
|
usec_t network_dirs_ts_usec;
|
||||||
};
|
};
|
||||||
|
|
||||||
static link_config* link_config_free(link_config *link) {
|
static LinkConfig* link_config_free(LinkConfig *link) {
|
||||||
if (!link)
|
if (!link)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
@ -65,10 +61,10 @@ static link_config* link_config_free(link_config *link) {
|
|||||||
return mfree(link);
|
return mfree(link);
|
||||||
}
|
}
|
||||||
|
|
||||||
DEFINE_TRIVIAL_CLEANUP_FUNC(link_config*, link_config_free);
|
DEFINE_TRIVIAL_CLEANUP_FUNC(LinkConfig*, link_config_free);
|
||||||
|
|
||||||
static void link_configs_free(link_config_ctx *ctx) {
|
static void link_configs_free(LinkConfigContext *ctx) {
|
||||||
link_config *link, *link_next;
|
LinkConfig *link, *link_next;
|
||||||
|
|
||||||
if (!ctx)
|
if (!ctx)
|
||||||
return;
|
return;
|
||||||
@ -77,7 +73,7 @@ static void link_configs_free(link_config_ctx *ctx) {
|
|||||||
link_config_free(link);
|
link_config_free(link);
|
||||||
}
|
}
|
||||||
|
|
||||||
link_config_ctx* link_config_ctx_free(link_config_ctx *ctx) {
|
LinkConfigContext *link_config_ctx_free(LinkConfigContext *ctx) {
|
||||||
if (!ctx)
|
if (!ctx)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
@ -87,29 +83,28 @@ link_config_ctx* link_config_ctx_free(link_config_ctx *ctx) {
|
|||||||
return mfree(ctx);
|
return mfree(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
int link_config_ctx_new(link_config_ctx **ret) {
|
int link_config_ctx_new(LinkConfigContext **ret) {
|
||||||
_cleanup_(link_config_ctx_freep) link_config_ctx *ctx = NULL;
|
_cleanup_(link_config_ctx_freep) LinkConfigContext *ctx = NULL;
|
||||||
|
|
||||||
if (!ret)
|
if (!ret)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
ctx = new0(link_config_ctx, 1);
|
ctx = new(LinkConfigContext, 1);
|
||||||
if (!ctx)
|
if (!ctx)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
LIST_HEAD_INIT(ctx->links);
|
*ctx = (LinkConfigContext) {
|
||||||
|
.ethtool_fd = -1,
|
||||||
ctx->ethtool_fd = -1;
|
.enable_name_policy = true,
|
||||||
|
};
|
||||||
ctx->enable_name_policy = true;
|
|
||||||
|
|
||||||
*ret = TAKE_PTR(ctx);
|
*ret = TAKE_PTR(ctx);
|
||||||
|
|
||||||
return 0;
|
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_(link_config_freep) LinkConfig *link = NULL;
|
||||||
_cleanup_free_ char *name = NULL;
|
_cleanup_free_ char *name = NULL;
|
||||||
const char *dropin_dirname;
|
const char *dropin_dirname;
|
||||||
size_t i;
|
size_t i;
|
||||||
@ -132,11 +127,11 @@ int link_load_one(link_config_ctx *ctx, const char *filename) {
|
|||||||
if (!name)
|
if (!name)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
link = new(link_config, 1);
|
link = new(LinkConfig, 1);
|
||||||
if (!link)
|
if (!link)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
*link = (link_config) {
|
*link = (LinkConfig) {
|
||||||
.filename = TAKE_PTR(name),
|
.filename = TAKE_PTR(name),
|
||||||
.mac_address_policy = _MAC_ADDRESS_POLICY_INVALID,
|
.mac_address_policy = _MAC_ADDRESS_POLICY_INVALID,
|
||||||
.wol = _WOL_INVALID,
|
.wol = _WOL_INVALID,
|
||||||
@ -210,7 +205,7 @@ static int link_unsigned_attribute(sd_device *device, const char *attr, unsigned
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int link_config_load(link_config_ctx *ctx) {
|
int link_config_load(LinkConfigContext *ctx) {
|
||||||
_cleanup_strv_free_ char **files = NULL;
|
_cleanup_strv_free_ char **files = NULL;
|
||||||
char **f;
|
char **f;
|
||||||
int r;
|
int r;
|
||||||
@ -238,16 +233,17 @@ int link_config_load(link_config_ctx *ctx) {
|
|||||||
return 0;
|
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);
|
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, LinkConfig **ret) {
|
||||||
unsigned name_assign_type = NET_NAME_UNKNOWN;
|
unsigned name_assign_type = NET_NAME_UNKNOWN;
|
||||||
struct ether_addr permanent_mac = {};
|
struct ether_addr permanent_mac = {};
|
||||||
unsigned short iftype = 0;
|
unsigned short iftype;
|
||||||
link_config *link;
|
LinkConfig *link;
|
||||||
const char *name;
|
const char *name;
|
||||||
|
unsigned flags;
|
||||||
int ifindex, r;
|
int ifindex, r;
|
||||||
|
|
||||||
assert(ctx);
|
assert(ctx);
|
||||||
@ -262,10 +258,14 @@ int link_config_get(link_config_ctx *ctx, sd_device *device, link_config **ret)
|
|||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
r = rtnl_get_link_iftype(&ctx->rtnl, ifindex, &iftype);
|
r = rtnl_get_link_info(&ctx->rtnl, ifindex, &iftype, &flags);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
|
/* Do not configure loopback interfaces by .link files. */
|
||||||
|
if (flags & IFF_LOOPBACK)
|
||||||
|
return -ENOENT;
|
||||||
|
|
||||||
r = ethtool_get_permanent_macaddr(&ctx->ethtool_fd, name, &permanent_mac);
|
r = ethtool_get_permanent_macaddr(&ctx->ethtool_fd, name, &permanent_mac);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
log_device_debug_errno(device, r, "Failed to get permanent MAC address, ignoring: %m");
|
log_device_debug_errno(device, r, "Failed to get permanent MAC address, ignoring: %m");
|
||||||
@ -292,7 +292,7 @@ int link_config_get(link_config_ctx *ctx, sd_device *device, link_config **ret)
|
|||||||
return -ENOENT;
|
return -ENOENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int link_config_apply_ethtool_settings(int *ethtool_fd, const link_config *config, sd_device *device) {
|
static int link_config_apply_ethtool_settings(int *ethtool_fd, const LinkConfig *config, sd_device *device) {
|
||||||
const char *name;
|
const char *name;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
@ -412,7 +412,7 @@ static int get_mac(sd_device *device, MACAddressPolicy policy, struct ether_addr
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int link_config_apply_rtnl_settings(sd_netlink **rtnl, const link_config *config, sd_device *device) {
|
static int link_config_apply_rtnl_settings(sd_netlink **rtnl, const LinkConfig *config, sd_device *device) {
|
||||||
struct ether_addr generated_mac, *mac = NULL;
|
struct ether_addr generated_mac, *mac = NULL;
|
||||||
int ifindex, r;
|
int ifindex, r;
|
||||||
|
|
||||||
@ -443,7 +443,7 @@ static int link_config_apply_rtnl_settings(sd_netlink **rtnl, const link_config
|
|||||||
return 0;
|
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 LinkConfig *config, sd_device *device, const char **ret_name) {
|
||||||
unsigned name_type = NET_NAME_UNKNOWN;
|
unsigned name_type = NET_NAME_UNKNOWN;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
@ -521,7 +521,7 @@ no_rename:
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int link_config_apply_alternative_names(sd_netlink **rtnl, const link_config *config, sd_device *device, const char *new_name) {
|
static int link_config_apply_alternative_names(sd_netlink **rtnl, const LinkConfig *config, sd_device *device, const char *new_name) {
|
||||||
_cleanup_strv_free_ char **altnames = NULL, **current_altnames = NULL;
|
_cleanup_strv_free_ char **altnames = NULL, **current_altnames = NULL;
|
||||||
const char *current_name;
|
const char *current_name;
|
||||||
int ifindex, r;
|
int ifindex, r;
|
||||||
@ -596,7 +596,7 @@ static int link_config_apply_alternative_names(sd_netlink **rtnl, const link_con
|
|||||||
return 0;
|
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 LinkConfig *config, sd_device *device, const char **ret_name) {
|
||||||
const char *new_name;
|
const char *new_name;
|
||||||
sd_device_action_t a;
|
sd_device_action_t a;
|
||||||
int r;
|
int r;
|
||||||
@ -648,7 +648,7 @@ int link_config_apply(link_config_ctx *ctx, const link_config *config, sd_device
|
|||||||
return 0;
|
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;
|
const char *name;
|
||||||
char *driver = NULL;
|
char *driver = NULL;
|
||||||
int r;
|
int r;
|
||||||
|
|||||||
@ -9,8 +9,8 @@
|
|||||||
#include "list.h"
|
#include "list.h"
|
||||||
#include "net-condition.h"
|
#include "net-condition.h"
|
||||||
|
|
||||||
typedef struct link_config_ctx link_config_ctx;
|
typedef struct LinkConfigContext LinkConfigContext;
|
||||||
typedef struct link_config link_config;
|
typedef struct LinkConfig LinkConfig;
|
||||||
|
|
||||||
typedef enum MACAddressPolicy {
|
typedef enum MACAddressPolicy {
|
||||||
MAC_ADDRESS_POLICY_PERSISTENT,
|
MAC_ADDRESS_POLICY_PERSISTENT,
|
||||||
@ -32,7 +32,7 @@ typedef enum NamePolicy {
|
|||||||
_NAMEPOLICY_INVALID = -EINVAL,
|
_NAMEPOLICY_INVALID = -EINVAL,
|
||||||
} NamePolicy;
|
} NamePolicy;
|
||||||
|
|
||||||
struct link_config {
|
struct LinkConfig {
|
||||||
char *filename;
|
char *filename;
|
||||||
|
|
||||||
NetMatch match;
|
NetMatch match;
|
||||||
@ -65,20 +65,20 @@ struct link_config {
|
|||||||
int tx_flow_control;
|
int tx_flow_control;
|
||||||
int autoneg_flow_control;
|
int autoneg_flow_control;
|
||||||
|
|
||||||
LIST_FIELDS(link_config, links);
|
LIST_FIELDS(LinkConfig, links);
|
||||||
};
|
};
|
||||||
|
|
||||||
int link_config_ctx_new(link_config_ctx **ret);
|
int link_config_ctx_new(LinkConfigContext **ret);
|
||||||
link_config_ctx* link_config_ctx_free(link_config_ctx *ctx);
|
LinkConfigContext* link_config_ctx_free(LinkConfigContext *ctx);
|
||||||
DEFINE_TRIVIAL_CLEANUP_FUNC(link_config_ctx*, link_config_ctx_free);
|
DEFINE_TRIVIAL_CLEANUP_FUNC(LinkConfigContext*, link_config_ctx_free);
|
||||||
|
|
||||||
int link_load_one(link_config_ctx *ctx, const char *filename);
|
int link_load_one(LinkConfigContext *ctx, const char *filename);
|
||||||
int link_config_load(link_config_ctx *ctx);
|
int link_config_load(LinkConfigContext *ctx);
|
||||||
bool link_config_should_reload(link_config_ctx *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_get(LinkConfigContext *ctx, sd_device *device, LinkConfig **ret);
|
||||||
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 LinkConfig *config, sd_device *device, const char **ret_name);
|
||||||
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_policy_to_string(NamePolicy p) _const_;
|
const char *name_policy_to_string(NamePolicy p) _const_;
|
||||||
NamePolicy name_policy_from_string(const char *p) _pure_;
|
NamePolicy name_policy_from_string(const char *p) _pure_;
|
||||||
|
|||||||
@ -8,12 +8,12 @@
|
|||||||
#include "string-util.h"
|
#include "string-util.h"
|
||||||
#include "udev-builtin.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) {
|
static int builtin_net_setup_link(sd_device *dev, int argc, char **argv, bool test) {
|
||||||
_cleanup_free_ char *driver = NULL;
|
_cleanup_free_ char *driver = NULL;
|
||||||
const char *name = NULL;
|
const char *name = NULL;
|
||||||
link_config *link;
|
LinkConfig *link;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
if (argc > 1)
|
if (argc > 1)
|
||||||
@ -69,8 +69,7 @@ static int builtin_net_setup_link_init(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void builtin_net_setup_link_exit(void) {
|
static void builtin_net_setup_link_exit(void) {
|
||||||
link_config_ctx_free(ctx);
|
ctx = link_config_ctx_free(ctx);
|
||||||
ctx = NULL;
|
|
||||||
log_debug("Unloaded link configuration context.");
|
log_debug("Unloaded link configuration context.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -762,7 +762,7 @@ class NetworkctlTests(unittest.TestCase, Utilities):
|
|||||||
|
|
||||||
output = check_output(*networkctl_cmd, '-n', '0', 'status', 'lo', env=env)
|
output = check_output(*networkctl_cmd, '-n', '0', 'status', 'lo', env=env)
|
||||||
print(output)
|
print(output)
|
||||||
self.assertRegex(output, r'Link File: (/usr)?/lib/systemd/network/99-default.link')
|
self.assertRegex(output, r'Link File: n/a')
|
||||||
self.assertRegex(output, r'Network File: n/a')
|
self.assertRegex(output, r'Network File: n/a')
|
||||||
|
|
||||||
def test_delete_links(self):
|
def test_delete_links(self):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user