link: fix type for link-config's "features" array of tristates

The "features" fields is parsed as a tristate value. The values
are thus not of type NetDevFeature enum but int. The NetDevFeature
enum is instead the index for the features array.

Adjust the type. In practice, this had no impact because NetDevFeature
enum commonly has size of int.

Also, don't use memset() 0xFF to initilize the int with -1. While
it works correctly in practice, it feels ugly.
This commit is contained in:
Thomas Haller 2018-08-07 08:55:07 +02:00 committed by Lennart Poettering
parent ef6e83f02b
commit cc2ff878fa
4 changed files with 6 additions and 4 deletions

View File

@ -302,7 +302,7 @@ static int find_feature_index(struct ethtool_gstrings *strings, const char *feat
return -1;
}
int ethtool_set_features(int *fd, const char *ifname, NetDevFeature *features) {
int ethtool_set_features(int *fd, const char *ifname, int *features) {
_cleanup_free_ struct ethtool_gstrings *strings = NULL;
struct ethtool_sfeatures *sfeatures;
int block, bit, i, r;

View File

@ -83,7 +83,7 @@ int ethtool_connect(int *ret);
int ethtool_get_driver(int *fd, const char *ifname, char **ret);
int ethtool_set_speed(int *fd, const char *ifname, unsigned int speed, Duplex duplex);
int ethtool_set_wol(int *fd, const char *ifname, WakeOnLan wol);
int ethtool_set_features(int *fd, const char *ifname, NetDevFeature *features);
int ethtool_set_features(int *fd, const char *ifname, int *features);
int ethtool_set_glinksettings(int *fd, const char *ifname, struct link_config *link);
int ethtool_set_channels(int *fd, const char *ifname, netdev_channels *channels);

View File

@ -125,6 +125,7 @@ int link_config_ctx_new(link_config_ctx **ret) {
static int load_link(link_config_ctx *ctx, const char *filename) {
_cleanup_(link_config_freep) link_config *link = NULL;
_cleanup_fclose_ FILE *file = NULL;
int i;
int r;
assert(ctx);
@ -153,7 +154,8 @@ static int load_link(link_config_ctx *ctx, const char *filename) {
link->port = _NET_DEV_PORT_INVALID;
link->autonegotiation = -1;
memset(&link->features, 0xFF, sizeof(link->features));
for (i = 0; i < (int)ELEMENTSOF(link->features); i++)
link->features[i] = -1;
r = config_parse(NULL, filename, file,
"Match\0Link\0Ethernet\0",

View File

@ -56,7 +56,7 @@ struct link_config {
int autonegotiation;
WakeOnLan wol;
NetDevPort port;
NetDevFeature features[_NET_DEV_FEAT_MAX];
int features[_NET_DEV_FEAT_MAX];
netdev_channels channels;
LIST_FIELDS(link_config, links);