Line data Source code
1 : /* SPDX-License-Identifier: LGPL-2.1+ */ 2 : #pragma once 3 : 4 : #include "sd-device.h" 5 : 6 : #include "condition.h" 7 : #include "conf-parser.h" 8 : #include "ethtool-util.h" 9 : #include "list.h" 10 : #include "set.h" 11 : 12 : typedef struct link_config_ctx link_config_ctx; 13 : typedef struct link_config link_config; 14 : 15 : typedef enum MACAddressPolicy { 16 : MAC_ADDRESS_POLICY_PERSISTENT, 17 : MAC_ADDRESS_POLICY_RANDOM, 18 : MAC_ADDRESS_POLICY_NONE, 19 : _MAC_ADDRESS_POLICY_MAX, 20 : _MAC_ADDRESS_POLICY_INVALID = -1 21 : } MACAddressPolicy; 22 : 23 : typedef enum NamePolicy { 24 : NAMEPOLICY_KERNEL, 25 : NAMEPOLICY_KEEP, 26 : NAMEPOLICY_DATABASE, 27 : NAMEPOLICY_ONBOARD, 28 : NAMEPOLICY_SLOT, 29 : NAMEPOLICY_PATH, 30 : NAMEPOLICY_MAC, 31 : _NAMEPOLICY_MAX, 32 : _NAMEPOLICY_INVALID = -1 33 : } NamePolicy; 34 : 35 : struct link_config { 36 : char *filename; 37 : 38 : Set *match_mac; 39 : char **match_path; 40 : char **match_driver; 41 : char **match_type; 42 : char **match_name; 43 : char **match_property; 44 : LIST_HEAD(Condition, conditions); 45 : 46 : char *description; 47 : struct ether_addr *mac; 48 : MACAddressPolicy mac_address_policy; 49 : NamePolicy *name_policy; 50 : char *name; 51 : char *alias; 52 : uint32_t mtu; 53 : size_t speed; 54 : Duplex duplex; 55 : int autonegotiation; 56 : uint32_t advertise[N_ADVERTISE]; 57 : WakeOnLan wol; 58 : NetDevPort port; 59 : int features[_NET_DEV_FEAT_MAX]; 60 : netdev_channels channels; 61 : 62 : LIST_FIELDS(link_config, links); 63 : }; 64 : 65 : int link_config_ctx_new(link_config_ctx **ret); 66 : void link_config_ctx_free(link_config_ctx *ctx); 67 0 : DEFINE_TRIVIAL_CLEANUP_FUNC(link_config_ctx*, link_config_ctx_free); 68 : 69 : int link_load_one(link_config_ctx *ctx, const char *filename); 70 : int link_config_load(link_config_ctx *ctx); 71 : bool link_config_should_reload(link_config_ctx *ctx); 72 : 73 : int link_config_get(link_config_ctx *ctx, sd_device *device, struct link_config **ret); 74 : int link_config_apply(link_config_ctx *ctx, struct link_config *config, sd_device *device, const char **name); 75 : int link_get_driver(link_config_ctx *ctx, sd_device *device, char **ret); 76 : 77 : const char *name_policy_to_string(NamePolicy p) _const_; 78 : NamePolicy name_policy_from_string(const char *p) _pure_; 79 : 80 : const char *mac_address_policy_to_string(MACAddressPolicy p) _const_; 81 : MACAddressPolicy mac_address_policy_from_string(const char *p) _pure_; 82 : 83 : /* gperf lookup function */ 84 : const struct ConfigPerfItem* link_config_gperf_lookup(const char *key, GPERF_LEN_TYPE length); 85 : 86 : CONFIG_PARSER_PROTOTYPE(config_parse_mac_address_policy); 87 : CONFIG_PARSER_PROTOTYPE(config_parse_name_policy);