1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2025-01-11 05:17:44 +03:00

dhcp: generic data should be void*, not uint8_t*

If we handly arbitrary data we should use "void*" pointers, not
"uint8_t*", how go intended C to be used.
This commit is contained in:
Lennart Poettering 2015-08-26 23:05:34 +02:00
parent 89ca10c6a6
commit e473522841
9 changed files with 28 additions and 28 deletions

View File

@ -45,7 +45,7 @@ int dhcp_option_append(DHCPMessage *message, size_t size, size_t *offset, uint8_
uint8_t code, size_t optlen, const void *optval);
typedef int (*dhcp_option_cb_t)(uint8_t code, uint8_t len,
const uint8_t *option, void *userdata);
const void *option, void *userdata);
int dhcp_option_parse(DHCPMessage *message, size_t len,
dhcp_option_cb_t cb, void *userdata);

View File

@ -78,23 +78,23 @@ struct sd_dhcp_lease {
char *domainname;
char *hostname;
char *root_path;
uint8_t *client_id;
void *client_id;
size_t client_id_len;
uint8_t *vendor_specific;
void *vendor_specific;
size_t vendor_specific_len;
char *timezone;
LIST_HEAD(struct sd_dhcp_raw_option, private_options);
};
int dhcp_lease_new(sd_dhcp_lease **ret);
int dhcp_lease_parse_options(uint8_t code, uint8_t len, const uint8_t *option,
int dhcp_lease_parse_options(uint8_t code, uint8_t len, const void *option,
void *userdata);
int dhcp_lease_insert_private_option(sd_dhcp_lease *lease, uint8_t tag,
const uint8_t *data, uint8_t len);
const void *data, uint8_t len);
int dhcp_lease_set_default_subnet_mask(sd_dhcp_lease *lease);
int dhcp_lease_set_client_id(sd_dhcp_lease *lease, const uint8_t *client_id,
int dhcp_lease_set_client_id(sd_dhcp_lease *lease, const void *client_id,
size_t client_id_len);
DEFINE_TRIVIAL_CLEANUP_FUNC(sd_dhcp_lease*, sd_dhcp_lease_unref);

View File

@ -525,7 +525,7 @@ int deserialize_dhcp_routes(struct sd_dhcp_route **ret, size_t *ret_size, size_t
return 0;
}
int serialize_dhcp_option(FILE *f, const char *key, const uint8_t *data, size_t size) {
int serialize_dhcp_option(FILE *f, const char *key, const void *data, size_t size) {
_cleanup_free_ char *hex_buf = NULL;
assert(f);
@ -541,7 +541,7 @@ int serialize_dhcp_option(FILE *f, const char *key, const uint8_t *data, size_t
return 0;
}
int deserialize_dhcp_option(uint8_t **data, size_t *data_len, const char *string) {
int deserialize_dhcp_option(void **data, size_t *data_len, const char *string) {
assert(data);
assert(data_len);
assert(string);

View File

@ -77,5 +77,5 @@ struct sd_dhcp_route;
void serialize_dhcp_routes(FILE *f, const char *key, struct sd_dhcp_route *routes, size_t size);
int deserialize_dhcp_routes(struct sd_dhcp_route **ret, size_t *ret_size, size_t *ret_allocated, const char *string);
int serialize_dhcp_option(FILE *f, const char *key, const uint8_t *data, size_t size);
int deserialize_dhcp_option(uint8_t **data, size_t *data_len, const char *string);
int serialize_dhcp_option(FILE *f, const char *key, const void *data, size_t size);
int deserialize_dhcp_option(void **data, size_t *data_len, const char *string);

View File

@ -179,7 +179,7 @@ int sd_dhcp_lease_get_routes(sd_dhcp_lease *lease, struct sd_dhcp_route **routes
return 0;
}
int sd_dhcp_lease_get_vendor_specific(sd_dhcp_lease *lease, const uint8_t **data,
int sd_dhcp_lease_get_vendor_specific(sd_dhcp_lease *lease, const void **data,
size_t *data_len) {
assert_return(lease, -EINVAL);
assert_return(data, -EINVAL);
@ -436,7 +436,7 @@ static int lease_parse_classless_routes(const uint8_t *option, size_t len, struc
return 0;
}
int dhcp_lease_parse_options(uint8_t code, uint8_t len, const uint8_t *option, void *userdata) {
int dhcp_lease_parse_options(uint8_t code, uint8_t len, const void *option, void *userdata) {
sd_dhcp_lease *lease = userdata;
int r;
@ -619,7 +619,7 @@ int dhcp_lease_parse_options(uint8_t code, uint8_t len, const uint8_t *option, v
}
int dhcp_lease_insert_private_option(sd_dhcp_lease *lease, uint8_t tag,
const uint8_t *data, uint8_t len) {
const void *data, uint8_t len) {
struct sd_dhcp_raw_option *cur, *option;
LIST_FOREACH(options, cur, lease->private_options) {
@ -669,7 +669,7 @@ int dhcp_lease_save(sd_dhcp_lease *lease, const char *lease_file) {
struct sd_dhcp_raw_option *option;
struct in_addr address;
const struct in_addr *addresses;
const uint8_t *client_id, *data;
const void *client_id, *data;
size_t client_id_len, data_len;
const char *string;
uint16_t mtu;
@ -950,7 +950,7 @@ int dhcp_lease_load(sd_dhcp_lease **ret, const char *lease_file) {
}
for (i = 0; i <= DHCP_OPTION_PRIVATE_LAST - DHCP_OPTION_PRIVATE_BASE; i++) {
_cleanup_free_ uint8_t *data = NULL;
_cleanup_free_ void *data = NULL;
size_t len;
if (!options[i])
@ -990,7 +990,7 @@ int dhcp_lease_set_default_subnet_mask(sd_dhcp_lease *lease) {
return 0;
}
int sd_dhcp_lease_get_client_id(sd_dhcp_lease *lease, const uint8_t **client_id,
int sd_dhcp_lease_get_client_id(sd_dhcp_lease *lease, const void **client_id,
size_t *client_id_len) {
assert_return(lease, -EINVAL);
assert_return(client_id, -EINVAL);
@ -1001,7 +1001,7 @@ int sd_dhcp_lease_get_client_id(sd_dhcp_lease *lease, const uint8_t **client_id,
return 0;
}
int dhcp_lease_set_client_id(sd_dhcp_lease *lease, const uint8_t *client_id,
int dhcp_lease_set_client_id(sd_dhcp_lease *lease, const void *client_id,
size_t client_id_len) {
assert_return(lease, -EINVAL);
assert_return((!client_id && !client_id_len) ||

View File

@ -550,7 +550,7 @@ static int server_send_forcerenew(sd_dhcp_server *server, be32_t address,
return 0;
}
static int parse_request(uint8_t code, uint8_t len, const uint8_t *option,
static int parse_request(uint8_t code, uint8_t len, const void *option,
void *userdata) {
DHCPRequest *req = userdata;

View File

@ -126,7 +126,7 @@ static void test_checksum(void)
assert_se(dhcp_packet_checksum((uint8_t*)&buf, 20) == be16toh(0x78ae));
}
static int check_options(uint8_t code, uint8_t len, const uint8_t *option,
static int check_options(uint8_t code, uint8_t len, const void *option,
void *userdata)
{
switch(code) {
@ -141,10 +141,10 @@ static int check_options(uint8_t code, uint8_t len, const uint8_t *option,
assert_se(len == sizeof(uint8_t) + sizeof(uint32_t) + duid_len);
assert_se(len == 19);
assert_se(option[0] == 0xff);
assert_se(((uint8_t*) option)[0] == 0xff);
assert_se(memcmp(&option[1], &iaid, sizeof(iaid)) == 0);
assert_se(memcmp(&option[5], &duid, duid_len) == 0);
assert_se(memcmp((uint8_t*) option + 1, &iaid, sizeof(iaid)) == 0);
assert_se(memcmp((uint8_t*) option + 5, &duid, duid_len) == 0);
break;
}

View File

@ -145,7 +145,7 @@ static void test_ignore_opts(uint8_t *descoption, int *descpos, int *desclen) {
}
}
static int test_options_cb(uint8_t code, uint8_t len, const uint8_t *option, void *userdata) {
static int test_options_cb(uint8_t code, uint8_t len, const void *option, void *userdata) {
struct option_desc *desc = userdata;
uint8_t *descoption = NULL;
int *desclen = NULL, *descpos = NULL;
@ -207,10 +207,10 @@ static int test_options_cb(uint8_t code, uint8_t len, const uint8_t *option, voi
for (i = 0; i < len; i++) {
if (verbose)
printf("0x%02x(0x%02x) ", option[i],
printf("0x%02x(0x%02x) ", ((uint8_t*) option)[i],
descoption[*descpos + 2 + i]);
assert_se(option[i] == descoption[*descpos + 2 + i]);
assert_se(((uint8_t*) option)[i] == descoption[*descpos + 2 + i]);
}
if (verbose)

View File

@ -44,10 +44,10 @@ int sd_dhcp_lease_get_mtu(sd_dhcp_lease *lease, uint16_t *mtu);
int sd_dhcp_lease_get_domainname(sd_dhcp_lease *lease, const char **domainname);
int sd_dhcp_lease_get_hostname(sd_dhcp_lease *lease, const char **hostname);
int sd_dhcp_lease_get_root_path(sd_dhcp_lease *lease, const char **root_path);
int sd_dhcp_lease_get_routes(sd_dhcp_lease *lease, struct sd_dhcp_route **routesgn);
int sd_dhcp_lease_get_vendor_specific(sd_dhcp_lease *lease, const uint8_t **data,
int sd_dhcp_lease_get_routes(sd_dhcp_lease *lease, struct sd_dhcp_route **routes);
int sd_dhcp_lease_get_vendor_specific(sd_dhcp_lease *lease, const void **data,
size_t *data_len);
int sd_dhcp_lease_get_client_id(sd_dhcp_lease *lease, const uint8_t **client_id,
int sd_dhcp_lease_get_client_id(sd_dhcp_lease *lease, const void **client_id,
size_t *client_id_len);
int sd_dhcp_lease_get_timezone(sd_dhcp_lease *lease, const char **timezone);