1
0
mirror of https://github.com/systemd/systemd.git synced 2025-01-26 14:04:03 +03:00

sd-netlink: constify parameters in public api and adjust pointer formatting

In the internal api, 'char* const*' is used instead of 'const char* const*'
because otherwise we'd get a mismatch with the various strv apis.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2022-08-18 11:04:16 +02:00
parent b44662fee5
commit f4f81a6b35
6 changed files with 24 additions and 15 deletions

View File

@ -256,7 +256,7 @@ _public_ int sd_netlink_message_append_string(sd_netlink_message *m, uint16_t at
return 0;
}
_public_ int sd_netlink_message_append_strv(sd_netlink_message *m, uint16_t attr_type, char * const *data) {
_public_ int sd_netlink_message_append_strv(sd_netlink_message *m, uint16_t attr_type, const char* const *data) {
size_t length, size;
int r;

View File

@ -187,7 +187,12 @@ int rtnl_get_link_alternative_names(sd_netlink **rtnl, int ifindex, char ***ret)
return 0;
}
static int rtnl_update_link_alternative_names(sd_netlink **rtnl, uint16_t nlmsg_type, int ifindex, char * const *alternative_names) {
static int rtnl_update_link_alternative_names(
sd_netlink **rtnl,
uint16_t nlmsg_type,
int ifindex,
char* const *alternative_names) {
_cleanup_(sd_netlink_message_unrefp) sd_netlink_message *message = NULL;
int r;
@ -212,7 +217,7 @@ static int rtnl_update_link_alternative_names(sd_netlink **rtnl, uint16_t nlmsg_
if (r < 0)
return r;
r = sd_netlink_message_append_strv(message, IFLA_ALT_IFNAME, alternative_names);
r = sd_netlink_message_append_strv(message, IFLA_ALT_IFNAME, (const char**) alternative_names);
if (r < 0)
return r;
@ -227,15 +232,19 @@ static int rtnl_update_link_alternative_names(sd_netlink **rtnl, uint16_t nlmsg_
return 0;
}
int rtnl_set_link_alternative_names(sd_netlink **rtnl, int ifindex, char * const *alternative_names) {
int rtnl_set_link_alternative_names(sd_netlink **rtnl, int ifindex, char* const *alternative_names) {
return rtnl_update_link_alternative_names(rtnl, RTM_NEWLINKPROP, ifindex, 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) {
return rtnl_update_link_alternative_names(rtnl, RTM_DELLINKPROP, ifindex, alternative_names);
}
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) {
_cleanup_(sd_netlink_message_unrefp) sd_netlink_message *message = NULL;
int r;
@ -263,7 +272,7 @@ int rtnl_set_link_alternative_names_by_ifname(sd_netlink **rtnl, const char *ifn
if (r < 0)
return r;
r = sd_netlink_message_append_strv(message, IFLA_ALT_IFNAME, alternative_names);
r = sd_netlink_message_append_strv(message, IFLA_ALT_IFNAME, (const char**) alternative_names);
if (r < 0)
return r;

View File

@ -42,9 +42,9 @@ int rtnl_set_link_properties(
uint32_t gso_max_size,
size_t gso_max_segments);
int rtnl_get_link_alternative_names(sd_netlink **rtnl, int ifindex, char ***ret);
int rtnl_set_link_alternative_names(sd_netlink **rtnl, int ifindex, 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_set_link_alternative_names(sd_netlink **rtnl, int ifindex, 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_resolve_link_alternative_name(sd_netlink **rtnl, const char *name, char **ret);
int rtnl_resolve_ifname(sd_netlink **rtnl, const char *name);
int rtnl_resolve_interface(sd_netlink **rtnl, const char *name);

View File

@ -947,7 +947,7 @@ _public_ int sd_netlink_add_match(
destroy_callback, userdata, description);
}
_public_ int sd_netlink_attach_filter(sd_netlink *nl, size_t len, struct sock_filter *filter) {
_public_ int sd_netlink_attach_filter(sd_netlink *nl, size_t len, const struct sock_filter *filter) {
assert_return(nl, -EINVAL);
assert_return(len == 0 || filter, -EINVAL);
@ -955,7 +955,7 @@ _public_ int sd_netlink_attach_filter(sd_netlink *nl, size_t len, struct sock_fi
len == 0 ? SO_DETACH_FILTER : SO_ATTACH_FILTER,
&(struct sock_fprog) {
.len = len,
.filter = filter,
.filter = (struct sock_filter*) filter,
}, sizeof(struct sock_fprog)) < 0)
return -errno;

View File

@ -572,7 +572,7 @@ static void test_strv(sd_netlink *rtnl) {
}
assert_se(sd_netlink_message_open_container(m, IFLA_PROP_LIST) >= 0);
assert_se(sd_netlink_message_append_strv(m, IFLA_ALT_IFNAME, names_in) >= 0);
assert_se(sd_netlink_message_append_strv(m, IFLA_ALT_IFNAME, (const char**) names_in) >= 0);
assert_se(sd_netlink_message_close_container(m) >= 0);
message_seal(m);

View File

@ -68,11 +68,11 @@ int sd_netlink_add_match(sd_netlink *nl, sd_netlink_slot **ret_slot, uint16_t ma
int sd_netlink_attach_event(sd_netlink *nl, sd_event *e, int64_t priority);
int sd_netlink_detach_event(sd_netlink *nl);
int sd_netlink_attach_filter(sd_netlink *nl, size_t len, struct sock_filter *filter);
int sd_netlink_attach_filter(sd_netlink *nl, size_t len, const struct sock_filter *filter);
/* message */
int sd_netlink_message_append_string(sd_netlink_message *m, uint16_t attr_type, const char *data);
int sd_netlink_message_append_strv(sd_netlink_message *m, uint16_t attr_type, char * const *data);
int sd_netlink_message_append_strv(sd_netlink_message *m, uint16_t attr_type, const char* const *data);
int sd_netlink_message_append_flag(sd_netlink_message *m, uint16_t attr_type);
int sd_netlink_message_append_u8(sd_netlink_message *m, uint16_t attr_type, uint8_t data);
int sd_netlink_message_append_u16(sd_netlink_message *m, uint16_t attr_type, uint16_t data);