Merge pull request #18685 from poettering/network-type-tweaks

sd-network.h type tweaks
This commit is contained in:
Lennart Poettering 2021-02-18 21:19:51 +01:00 committed by GitHub
commit 988338eb19
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
25 changed files with 71 additions and 71 deletions

View File

@ -35,5 +35,5 @@ struct sd_lldp {
#define log_lldp_errno(error, fmt, ...) log_internal(LOG_DEBUG, error, PROJECT_FILE, __LINE__, __func__, "LLDP: " fmt, ##__VA_ARGS__)
#define log_lldp(fmt, ...) log_lldp_errno(0, fmt, ##__VA_ARGS__)
const char* lldp_event_to_string(sd_lldp_event e) _const_;
sd_lldp_event lldp_event_from_string(const char *s) _pure_;
const char* lldp_event_to_string(sd_lldp_event_t e) _const_;
sd_lldp_event_t lldp_event_from_string(const char *s) _pure_;

View File

@ -40,5 +40,5 @@ struct sd_ndisc {
#define log_ndisc_errno(error, fmt, ...) log_internal(LOG_DEBUG, error, PROJECT_FILE, __LINE__, __func__, "NDISC: " fmt, ##__VA_ARGS__)
#define log_ndisc(fmt, ...) log_ndisc_errno(0, fmt, ##__VA_ARGS__)
const char* ndisc_event_to_string(sd_ndisc_event e) _const_;
sd_ndisc_event ndisc_event_from_string(const char *s) _pure_;
const char* ndisc_event_to_string(sd_ndisc_event_t e) _const_;
sd_ndisc_event_t ndisc_event_from_string(const char *s) _pure_;

View File

@ -99,7 +99,7 @@ int sd_dhcp_lease_get_mtu(sd_dhcp_lease *lease, uint16_t *mtu) {
int sd_dhcp_lease_get_servers(
sd_dhcp_lease *lease,
sd_dhcp_lease_server_type what,
sd_dhcp_lease_server_type_t what,
const struct in_addr **addr) {
assert_return(lease, -EINVAL);
@ -281,7 +281,7 @@ static sd_dhcp_lease *dhcp_lease_free(sd_dhcp_lease *lease) {
free(lease->hostname);
free(lease->domainname);
for (sd_dhcp_lease_server_type i = 0; i < _SD_DHCP_LEASE_SERVER_TYPE_MAX; i++)
for (sd_dhcp_lease_server_type_t i = 0; i < _SD_DHCP_LEASE_SERVER_TYPE_MAX; i++)
free(lease->servers[i].addr);
free(lease->static_route);

View File

@ -149,7 +149,7 @@ static sd_dhcp_server *dhcp_server_free(sd_dhcp_server *server) {
free(server->timezone);
for (sd_dhcp_lease_server_type i = 0; i < _SD_DHCP_LEASE_SERVER_TYPE_MAX; i++)
for (sd_dhcp_lease_server_type_t i = 0; i < _SD_DHCP_LEASE_SERVER_TYPE_MAX; i++)
free(server->servers[i].addr);
hashmap_free(server->leases_by_client_id);
@ -509,7 +509,7 @@ static int server_send_ack(
return r;
}
for (sd_dhcp_lease_server_type k = 0; k < _SD_DHCP_LEASE_SERVER_TYPE_MAX; k++) {
for (sd_dhcp_lease_server_type_t k = 0; k < _SD_DHCP_LEASE_SERVER_TYPE_MAX; k++) {
if (server->servers[k].size <= 0)
continue;
@ -1118,7 +1118,7 @@ int sd_dhcp_server_set_default_lease_time(sd_dhcp_server *server, uint32_t t) {
int sd_dhcp_server_set_servers(
sd_dhcp_server *server,
sd_dhcp_lease_server_type what,
sd_dhcp_lease_server_type_t what,
const struct in_addr addresses[],
size_t n_addresses) {

View File

@ -21,13 +21,13 @@
#define LLDP_DEFAULT_NEIGHBORS_MAX 128U
static const char * const lldp_event_table[_SD_LLDP_EVENT_MAX] = {
[SD_LLDP_EVENT_ADDED] = "added",
[SD_LLDP_EVENT_REMOVED] = "removed",
[SD_LLDP_EVENT_ADDED] = "added",
[SD_LLDP_EVENT_REMOVED] = "removed",
[SD_LLDP_EVENT_UPDATED] = "updated",
[SD_LLDP_EVENT_REFRESHED] = "refreshed",
};
DEFINE_STRING_TABLE_LOOKUP(lldp_event, sd_lldp_event);
DEFINE_STRING_TABLE_LOOKUP(lldp_event, sd_lldp_event_t);
static void lldp_flush_neighbors(sd_lldp *lldp) {
assert(lldp);
@ -35,7 +35,7 @@ static void lldp_flush_neighbors(sd_lldp *lldp) {
hashmap_clear(lldp->neighbor_by_id);
}
static void lldp_callback(sd_lldp *lldp, sd_lldp_event event, sd_lldp_neighbor *n) {
static void lldp_callback(sd_lldp *lldp, sd_lldp_event_t event, sd_lldp_neighbor *n) {
assert(lldp);
assert(event >= 0 && event < _SD_LLDP_EVENT_MAX);

View File

@ -28,9 +28,9 @@ static const char * const ndisc_event_table[_SD_NDISC_EVENT_MAX] = {
[SD_NDISC_EVENT_ROUTER] = "router",
};
DEFINE_STRING_TABLE_LOOKUP(ndisc_event, sd_ndisc_event);
DEFINE_STRING_TABLE_LOOKUP(ndisc_event, sd_ndisc_event_t);
static void ndisc_callback(sd_ndisc *ndisc, sd_ndisc_event event, sd_ndisc_router *rt) {
static void ndisc_callback(sd_ndisc *ndisc, sd_ndisc_event_t event, sd_ndisc_router *rt) {
assert(ndisc);
assert(event >= 0 && event < _SD_NDISC_EVENT_MAX);

View File

@ -30,7 +30,7 @@ int lldp_network_bind_raw_socket(int ifindex) {
return test_fd[0];
}
static void lldp_handler(sd_lldp *lldp, sd_lldp_event event, sd_lldp_neighbor *n, void *userdata) {
static void lldp_handler(sd_lldp *lldp, sd_lldp_event_t event, sd_lldp_neighbor *n, void *userdata) {
lldp_handler_calls++;
}

View File

@ -232,7 +232,7 @@ int icmp6_send_router_solicitation(int s, const struct ether_addr *ether_addr) {
return send_ra_function(0);
}
static void test_callback(sd_ndisc *nd, sd_ndisc_event event, sd_ndisc_router *rt, void *userdata) {
static void test_callback(sd_ndisc *nd, sd_ndisc_event_t event, sd_ndisc_router *rt, void *userdata) {
sd_event *e = userdata;
static unsigned idx = 0;
uint64_t flags_array[] = {

View File

@ -25,9 +25,9 @@ static const genl_family genl_families[] = {
int sd_genl_socket_open(sd_netlink **ret) {
return netlink_open_family(ret, NETLINK_GENERIC);
}
static int lookup_id(sd_netlink *nl, sd_genl_family family, uint16_t *id);
static int lookup_id(sd_netlink *nl, sd_genl_family_t family, uint16_t *id);
static int genl_message_new(sd_netlink *nl, sd_genl_family family, uint16_t nlmsg_type, uint8_t cmd, sd_netlink_message **ret) {
static int genl_message_new(sd_netlink *nl, sd_genl_family_t family, uint16_t nlmsg_type, uint8_t cmd, sd_netlink_message **ret) {
_cleanup_(sd_netlink_message_unrefp) sd_netlink_message *m = NULL;
const NLType *genl_cmd_type, *nl_type;
const NLTypeSystem *type_system;
@ -71,7 +71,7 @@ static int genl_message_new(sd_netlink *nl, sd_genl_family family, uint16_t nlms
return 0;
}
int sd_genl_message_new(sd_netlink *nl, sd_genl_family family, uint8_t cmd, sd_netlink_message **ret) {
int sd_genl_message_new(sd_netlink *nl, sd_genl_family_t family, uint8_t cmd, sd_netlink_message **ret) {
uint16_t id;
int r;
@ -82,7 +82,7 @@ int sd_genl_message_new(sd_netlink *nl, sd_genl_family family, uint8_t cmd, sd_n
return genl_message_new(nl, family, id, cmd, ret);
}
static int lookup_id(sd_netlink *nl, sd_genl_family family, uint16_t *id) {
static int lookup_id(sd_netlink *nl, sd_genl_family_t family, uint16_t *id) {
_cleanup_(sd_netlink_message_unrefp) sd_netlink_message *req = NULL, *reply = NULL;
uint16_t u;
void *v;
@ -127,7 +127,7 @@ static int lookup_id(sd_netlink *nl, sd_genl_family family, uint16_t *id) {
return 0;
}
int nlmsg_type_to_genl_family(const sd_netlink *nl, uint16_t type, sd_genl_family *ret) {
int nlmsg_type_to_genl_family(const sd_netlink *nl, uint16_t type, sd_genl_family_t *ret) {
void *p;
assert_return(nl, -EINVAL);
@ -151,7 +151,7 @@ int nlmsg_type_to_genl_family(const sd_netlink *nl, uint16_t type, sd_genl_famil
return 0;
}
int sd_genl_message_get_family(const sd_netlink *nl, const sd_netlink_message *m, sd_genl_family *family) {
int sd_genl_message_get_family(const sd_netlink *nl, const sd_netlink_message *m, sd_genl_family_t *family) {
uint16_t type;
int r;

View File

@ -3,4 +3,4 @@
#include "sd-netlink.h"
int nlmsg_type_to_genl_family(const sd_netlink *nl, uint16_t type, sd_genl_family *ret);
int nlmsg_type_to_genl_family(const sd_netlink *nl, uint16_t type, sd_genl_family_t *ret);

View File

@ -1636,7 +1636,7 @@ const NLTypeSystem *type_system_get_root(int protocol) {
}
int type_system_root_get_type(sd_netlink *nl, const NLType **ret, uint16_t type) {
sd_genl_family family;
sd_genl_family_t family;
const NLType *nl_type;
int r;

View File

@ -60,7 +60,7 @@ static Address* link_find_dhcp_server_address(Link *link) {
static int link_push_uplink_to_dhcp_server(
Link *link,
sd_dhcp_lease_server_type what,
sd_dhcp_lease_server_type_t what,
sd_dhcp_server *s) {
_cleanup_free_ struct in_addr *addresses = NULL;
@ -307,7 +307,7 @@ int dhcp4_server_configure(Link *link) {
return log_link_error_errno(link, r, "Failed to set default lease time for DHCPv4 server instance: %m");
}
for (sd_dhcp_lease_server_type type = 0; type < _SD_DHCP_LEASE_SERVER_TYPE_MAX; type ++) {
for (sd_dhcp_lease_server_type_t type = 0; type < _SD_DHCP_LEASE_SERVER_TYPE_MAX; type ++) {
if (!link->network->dhcp_server_emit[type].emit)
continue;

View File

@ -2823,7 +2823,7 @@ static void serialize_addresses(
char **addresses,
sd_dhcp_lease *lease,
bool conditional,
sd_dhcp_lease_server_type what,
sd_dhcp_lease_server_type_t what,
sd_dhcp6_lease *lease6,
bool conditional6,
int (*lease6_get_addr)(sd_dhcp6_lease*, const struct in6_addr**),

View File

@ -47,7 +47,7 @@ static bool link_lldp_rx_enabled(Link *link) {
return link->network->lldp_mode != LLDP_MODE_NO;
}
static void lldp_handler(sd_lldp *lldp, sd_lldp_event event, sd_lldp_neighbor *n, void *userdata) {
static void lldp_handler(sd_lldp *lldp, sd_lldp_event_t event, sd_lldp_neighbor *n, void *userdata) {
Link *link = userdata;
int r;

View File

@ -1274,7 +1274,7 @@ static int ndisc_router_handler(Link *link, sd_ndisc_router *rt) {
return 0;
}
static void ndisc_handler(sd_ndisc *nd, sd_ndisc_event event, sd_ndisc_router *rt, void *userdata) {
static void ndisc_handler(sd_ndisc *nd, sd_ndisc_event_t event, sd_ndisc_router *rt, void *userdata) {
Link *link = userdata;
int r;

View File

@ -664,7 +664,7 @@ static Network *network_free(Network *network) {
free(network->dhcp_server_timezone);
for (sd_dhcp_lease_server_type t = 0; t < _SD_DHCP_LEASE_SERVER_TYPE_MAX; t++)
for (sd_dhcp_lease_server_type_t t = 0; t < _SD_DHCP_LEASE_SERVER_TYPE_MAX; t++)
free(network->dhcp_server_emit[t].addresses);
set_free_free(network->dnssec_negative_trust_anchors);

View File

@ -9,35 +9,35 @@
#include "util.h"
static const char* const address_family_table[_ADDRESS_FAMILY_MAX] = {
[ADDRESS_FAMILY_NO] = "no",
[ADDRESS_FAMILY_YES] = "yes",
[ADDRESS_FAMILY_IPV4] = "ipv4",
[ADDRESS_FAMILY_IPV6] = "ipv6",
[ADDRESS_FAMILY_NO] = "no",
[ADDRESS_FAMILY_YES] = "yes",
[ADDRESS_FAMILY_IPV4] = "ipv4",
[ADDRESS_FAMILY_IPV6] = "ipv6",
};
static const char* const routing_policy_rule_address_family_table[_ADDRESS_FAMILY_MAX] = {
[ADDRESS_FAMILY_YES] = "both",
[ADDRESS_FAMILY_IPV4] = "ipv4",
[ADDRESS_FAMILY_IPV6] = "ipv6",
[ADDRESS_FAMILY_YES] = "both",
[ADDRESS_FAMILY_IPV4] = "ipv4",
[ADDRESS_FAMILY_IPV6] = "ipv6",
};
static const char* const nexthop_address_family_table[_ADDRESS_FAMILY_MAX] = {
[ADDRESS_FAMILY_IPV4] = "ipv4",
[ADDRESS_FAMILY_IPV6] = "ipv6",
[ADDRESS_FAMILY_IPV4] = "ipv4",
[ADDRESS_FAMILY_IPV6] = "ipv6",
};
static const char* const duplicate_address_detection_address_family_table[_ADDRESS_FAMILY_MAX] = {
[ADDRESS_FAMILY_NO] = "none",
[ADDRESS_FAMILY_YES] = "both",
[ADDRESS_FAMILY_IPV4] = "ipv4",
[ADDRESS_FAMILY_IPV6] = "ipv6",
[ADDRESS_FAMILY_NO] = "none",
[ADDRESS_FAMILY_YES] = "both",
[ADDRESS_FAMILY_IPV4] = "ipv4",
[ADDRESS_FAMILY_IPV6] = "ipv6",
};
static const char* const dhcp_deprecated_address_family_table[_ADDRESS_FAMILY_MAX] = {
[ADDRESS_FAMILY_NO] = "none",
[ADDRESS_FAMILY_YES] = "both",
[ADDRESS_FAMILY_IPV4] = "v4",
[ADDRESS_FAMILY_IPV6] = "v6",
[ADDRESS_FAMILY_NO] = "none",
[ADDRESS_FAMILY_YES] = "both",
[ADDRESS_FAMILY_IPV4] = "v4",
[ADDRESS_FAMILY_IPV6] = "v6",
};
static const char* const dhcp_lease_server_type_table[_SD_DHCP_LEASE_SERVER_TYPE_MAX] = {
@ -65,7 +65,7 @@ DEFINE_STRING_TABLE_LOOKUP(duplicate_address_detection_address_family, AddressFa
DEFINE_CONFIG_PARSE_ENUM(config_parse_link_local_address_family, link_local_address_family,
AddressFamily, "Failed to parse option");
DEFINE_STRING_TABLE_LOOKUP_FROM_STRING(dhcp_deprecated_address_family, AddressFamily);
DEFINE_STRING_TABLE_LOOKUP(dhcp_lease_server_type, sd_dhcp_lease_server_type);
DEFINE_STRING_TABLE_LOOKUP(dhcp_lease_server_type, sd_dhcp_lease_server_type_t);
static AddressFamily address_family_compat_from_string(const char *s) {
if (streq_ptr(s, "yes")) /* compat name */

View File

@ -46,8 +46,8 @@ AddressFamily duplicate_address_detection_address_family_from_string(const char
AddressFamily dhcp_deprecated_address_family_from_string(const char *s) _pure_;
const char *dhcp_lease_server_type_to_string(sd_dhcp_lease_server_type t) _const_;
sd_dhcp_lease_server_type dhcp_lease_server_type_from_string(const char *s) _pure_;
const char *dhcp_lease_server_type_to_string(sd_dhcp_lease_server_type_t t) _const_;
sd_dhcp_lease_server_type_t dhcp_lease_server_type_from_string(const char *s) _pure_;
int kernel_route_expiration_supported(void);

View File

@ -46,10 +46,10 @@ int main(int argc, char **argv) {
test_table_sparse(macvlan_mode, NETDEV_MACVLAN_MODE);
test_table_sparse(address_family, ADDRESS_FAMILY);
assert_cc(sizeof(sd_lldp_event) == sizeof(int64_t));
assert_cc(sizeof(sd_ndisc_event) == sizeof(int64_t));
assert_cc(sizeof(sd_dhcp_lease_server_type) == sizeof(int64_t));
assert_cc(sizeof(sd_genl_family) == sizeof(int64_t));
assert_cc(sizeof(sd_lldp_event_t) == sizeof(int64_t));
assert_cc(sizeof(sd_ndisc_event_t) == sizeof(int64_t));
assert_cc(sizeof(sd_dhcp_lease_server_type_t) == sizeof(int64_t));
assert_cc(sizeof(sd_genl_family_t) == sizeof(int64_t));
return EXIT_SUCCESS;
}

View File

@ -5,7 +5,7 @@
int wifi_get_interface(sd_netlink *genl, int ifindex, enum nl80211_iftype *iftype, char **ssid) {
_cleanup_(sd_netlink_message_unrefp) sd_netlink_message *m = NULL, *reply = NULL;
sd_genl_family family;
sd_genl_family_t family;
int r;
assert(genl);
@ -75,7 +75,7 @@ nodata:
int wifi_get_station(sd_netlink *genl, int ifindex, struct ether_addr *bssid) {
_cleanup_(sd_netlink_message_unrefp) sd_netlink_message *m = NULL, *reply = NULL;
sd_genl_family family;
sd_genl_family_t family;
int r;
assert(genl);

View File

@ -34,7 +34,7 @@ typedef struct sd_dhcp_route sd_dhcp_route;
sd_dhcp_lease *sd_dhcp_lease_ref(sd_dhcp_lease *lease);
sd_dhcp_lease *sd_dhcp_lease_unref(sd_dhcp_lease *lease);
typedef enum sd_dhcp_lease_server_type {
typedef enum sd_dhcp_lease_server_type_t {
SD_DHCP_LEASE_DNS,
SD_DHCP_LEASE_NTP,
SD_DHCP_LEASE_SIP,
@ -44,7 +44,7 @@ typedef enum sd_dhcp_lease_server_type {
_SD_DHCP_LEASE_SERVER_TYPE_MAX,
_SD_DHCP_LEASE_SERVER_TYPE_INVALID = -EINVAL,
_SD_ENUM_FORCE_S64(DHCP_LEASE_SERVER_TYPE),
} sd_dhcp_lease_server_type;
} sd_dhcp_lease_server_type_t;
int sd_dhcp_lease_get_address(sd_dhcp_lease *lease, struct in_addr *addr);
int sd_dhcp_lease_get_lifetime(sd_dhcp_lease *lease, uint32_t *lifetime);
@ -55,7 +55,7 @@ int sd_dhcp_lease_get_netmask(sd_dhcp_lease *lease, struct in_addr *addr);
int sd_dhcp_lease_get_router(sd_dhcp_lease *lease, const struct in_addr **addr);
int sd_dhcp_lease_get_next_server(sd_dhcp_lease *lease, struct in_addr *addr);
int sd_dhcp_lease_get_server_identifier(sd_dhcp_lease *lease, struct in_addr *addr);
int sd_dhcp_lease_get_servers(sd_dhcp_lease *lease, sd_dhcp_lease_server_type what, const struct in_addr **addr);
int sd_dhcp_lease_get_servers(sd_dhcp_lease *lease, sd_dhcp_lease_server_type_t what, const struct in_addr **addr);
int sd_dhcp_lease_get_dns(sd_dhcp_lease *lease, const struct in_addr **addr);
int sd_dhcp_lease_get_ntp(sd_dhcp_lease *lease, const struct in_addr **addr);
int sd_dhcp_lease_get_sip(sd_dhcp_lease *lease, const struct in_addr **addr);

View File

@ -60,7 +60,7 @@ int sd_dhcp_server_set_emit_router(sd_dhcp_server *server, int enabled);
int sd_dhcp_server_set_servers(
sd_dhcp_server *server,
sd_dhcp_lease_server_type what,
sd_dhcp_lease_server_type_t what,
const struct in_addr addresses[],
size_t n_addresses);

View File

@ -122,7 +122,7 @@ enum {
typedef struct sd_lldp sd_lldp;
typedef struct sd_lldp_neighbor sd_lldp_neighbor;
typedef enum sd_lldp_event {
typedef enum sd_lldp_event_t {
SD_LLDP_EVENT_ADDED,
SD_LLDP_EVENT_REMOVED,
SD_LLDP_EVENT_UPDATED,
@ -130,9 +130,9 @@ typedef enum sd_lldp_event {
_SD_LLDP_EVENT_MAX,
_SD_LLDP_EVENT_INVALID = -EINVAL,
_SD_ENUM_FORCE_S64(LLDP_EVENT),
} sd_lldp_event;
} sd_lldp_event_t;
typedef void (*sd_lldp_callback_t)(sd_lldp *lldp, sd_lldp_event event, sd_lldp_neighbor *n, void *userdata);
typedef void (*sd_lldp_callback_t)(sd_lldp *lldp, sd_lldp_event_t event, sd_lldp_neighbor *n, void *userdata);
int sd_lldp_new(sd_lldp **ret);
sd_lldp* sd_lldp_ref(sd_lldp *lldp);

View File

@ -55,15 +55,15 @@ enum {
typedef struct sd_ndisc sd_ndisc;
typedef struct sd_ndisc_router sd_ndisc_router;
typedef enum sd_ndisc_event {
typedef enum sd_ndisc_event_t {
SD_NDISC_EVENT_TIMEOUT,
SD_NDISC_EVENT_ROUTER,
_SD_NDISC_EVENT_MAX,
_SD_NDISC_EVENT_INVALID = -EINVAL,
_SD_ENUM_FORCE_S64(NDISC_EVENT),
} sd_ndisc_event;
} sd_ndisc_event_t;
typedef void (*sd_ndisc_callback_t)(sd_ndisc *nd, sd_ndisc_event event, sd_ndisc_router *rt, void *userdata);
typedef void (*sd_ndisc_callback_t)(sd_ndisc *nd, sd_ndisc_event_t event, sd_ndisc_router *rt, void *userdata);
int sd_ndisc_new(sd_ndisc **ret);
sd_ndisc *sd_ndisc_ref(sd_ndisc *nd);

View File

@ -35,7 +35,7 @@ typedef struct sd_genl_socket sd_genl_socket;
typedef struct sd_netlink_message sd_netlink_message;
typedef struct sd_netlink_slot sd_netlink_slot;
typedef enum sd_genl_family {
typedef enum sd_genl_family_t {
SD_GENL_ERROR,
SD_GENL_DONE,
SD_GENL_ID_CTRL,
@ -47,7 +47,7 @@ typedef enum sd_genl_family {
_SD_GENL_FAMILY_MAX,
_SD_GENL_FAMILY_INVALID = -EINVAL,
_SD_ENUM_FORCE_S64(GENL_FAMILY)
} sd_genl_family;
} sd_genl_family_t;
/* callback */
@ -249,8 +249,8 @@ int sd_nfnl_nft_message_add_setelem_end(sd_netlink_message *m);
/* genl */
int sd_genl_socket_open(sd_netlink **nl);
int sd_genl_message_new(sd_netlink *nl, sd_genl_family family, uint8_t cmd, sd_netlink_message **m);
int sd_genl_message_get_family(const sd_netlink *nl, const sd_netlink_message *m, sd_genl_family *family);
int sd_genl_message_new(sd_netlink *nl, sd_genl_family_t family, uint8_t cmd, sd_netlink_message **m);
int sd_genl_message_get_family(const sd_netlink *nl, const sd_netlink_message *m, sd_genl_family_t *family);
/* slot */
sd_netlink_slot *sd_netlink_slot_ref(sd_netlink_slot *nl);