mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-01-10 01:17:44 +03:00
network: Use ordered_hashmap_ensure_put (#18233)
This commit is contained in:
parent
f9ead1a2f4
commit
ebffea2a25
@ -80,11 +80,11 @@ static int option_append(uint8_t options[], size_t size, size_t *offset,
|
||||
|
||||
break;
|
||||
case SD_DHCP_OPTION_VENDOR_SPECIFIC: {
|
||||
OrderedHashmap *s = (OrderedHashmap *) optval;
|
||||
OrderedSet *s = (OrderedSet *) optval;
|
||||
struct sd_dhcp_option *p;
|
||||
size_t l = 0;
|
||||
|
||||
ORDERED_HASHMAP_FOREACH(p, s)
|
||||
ORDERED_SET_FOREACH(p, s)
|
||||
l += p->length + 2;
|
||||
|
||||
if (*offset + l + 2 > size)
|
||||
@ -95,7 +95,7 @@ static int option_append(uint8_t options[], size_t size, size_t *offset,
|
||||
|
||||
*offset += 2;
|
||||
|
||||
ORDERED_HASHMAP_FOREACH(p, s) {
|
||||
ORDERED_SET_FOREACH(p, s) {
|
||||
options[*offset] = p->option;
|
||||
options[*offset + 1] = p->length;
|
||||
memcpy(&options[*offset + 2], p->data, p->length);
|
||||
|
@ -9,7 +9,7 @@
|
||||
#include "sd-event.h"
|
||||
|
||||
#include "dhcp-internal.h"
|
||||
#include "hashmap.h"
|
||||
#include "ordered-set.h"
|
||||
#include "log.h"
|
||||
#include "time-util.h"
|
||||
|
||||
@ -58,8 +58,8 @@ struct sd_dhcp_server {
|
||||
|
||||
DHCPServerData servers[_SD_DHCP_LEASE_SERVER_TYPE_MAX];
|
||||
|
||||
OrderedHashmap *extra_options;
|
||||
OrderedHashmap *vendor_options;
|
||||
OrderedSet *extra_options;
|
||||
OrderedSet *vendor_options;
|
||||
|
||||
bool emit_router;
|
||||
|
||||
|
@ -629,11 +629,7 @@ int sd_dhcp_client_add_option(sd_dhcp_client *client, sd_dhcp_option *v) {
|
||||
assert_return(client, -EINVAL);
|
||||
assert_return(v, -EINVAL);
|
||||
|
||||
r = ordered_hashmap_ensure_allocated(&client->extra_options, &dhcp_option_hash_ops);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = ordered_hashmap_put(client->extra_options, UINT_TO_PTR(v->option), v);
|
||||
r = ordered_hashmap_ensure_put(&client->extra_options, &dhcp_option_hash_ops, UINT_TO_PTR(v->option), v);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include "fd-util.h"
|
||||
#include "in-addr-util.h"
|
||||
#include "io-util.h"
|
||||
#include "ordered-set.h"
|
||||
#include "siphash24.h"
|
||||
#include "string-util.h"
|
||||
#include "unaligned.h"
|
||||
@ -153,8 +154,8 @@ static sd_dhcp_server *dhcp_server_free(sd_dhcp_server *server) {
|
||||
|
||||
hashmap_free(server->leases_by_client_id);
|
||||
|
||||
ordered_hashmap_free(server->extra_options);
|
||||
ordered_hashmap_free(server->vendor_options);
|
||||
ordered_set_free(server->extra_options);
|
||||
ordered_set_free(server->vendor_options);
|
||||
|
||||
free(server->bound_leases);
|
||||
return mfree(server);
|
||||
@ -531,18 +532,18 @@ static int server_send_ack(
|
||||
return r;
|
||||
}
|
||||
|
||||
ORDERED_HASHMAP_FOREACH(j, server->extra_options) {
|
||||
ORDERED_SET_FOREACH(j, server->extra_options) {
|
||||
r = dhcp_option_append(&packet->dhcp, req->max_optlen, &offset, 0,
|
||||
j->option, j->length, j->data);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
|
||||
if (!ordered_hashmap_isempty(server->vendor_options)) {
|
||||
if (!ordered_set_isempty(server->vendor_options)) {
|
||||
r = dhcp_option_append(
|
||||
&packet->dhcp, req->max_optlen, &offset, 0,
|
||||
SD_DHCP_OPTION_VENDOR_SPECIFIC,
|
||||
ordered_hashmap_size(server->vendor_options), server->vendor_options);
|
||||
ordered_set_size(server->vendor_options), server->vendor_options);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
@ -1181,11 +1182,7 @@ int sd_dhcp_server_add_option(sd_dhcp_server *server, sd_dhcp_option *v) {
|
||||
assert_return(server, -EINVAL);
|
||||
assert_return(v, -EINVAL);
|
||||
|
||||
r = ordered_hashmap_ensure_allocated(&server->extra_options, &dhcp_option_hash_ops);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = ordered_hashmap_put(server->extra_options, UINT_TO_PTR(v->option), v);
|
||||
r = ordered_set_ensure_put(&server->extra_options, &dhcp_option_hash_ops, v);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@ -1199,11 +1196,7 @@ int sd_dhcp_server_add_vendor_option(sd_dhcp_server *server, sd_dhcp_option *v)
|
||||
assert_return(server, -EINVAL);
|
||||
assert_return(v, -EINVAL);
|
||||
|
||||
r = ordered_hashmap_ensure_allocated(&server->vendor_options, &dhcp_option_hash_ops);
|
||||
if (r < 0)
|
||||
return -ENOMEM;
|
||||
|
||||
r = ordered_hashmap_put(server->vendor_options, v, v);
|
||||
r = ordered_set_ensure_put(&server->vendor_options, &dhcp_option_hash_ops, v);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
@ -85,11 +85,7 @@ static int l2tp_session_new_static(L2tpTunnel *t, const char *filename, unsigned
|
||||
.section = TAKE_PTR(n),
|
||||
};
|
||||
|
||||
r = ordered_hashmap_ensure_allocated(&t->sessions_by_section, &network_config_hash_ops);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = ordered_hashmap_put(t->sessions_by_section, s->section, s);
|
||||
r = ordered_hashmap_ensure_put(&t->sessions_by_section, &network_config_hash_ops, s->section, s);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
@ -58,11 +58,7 @@ static int sr_iov_new_static(Network *network, const char *filename, unsigned se
|
||||
sr_iov->network = network;
|
||||
sr_iov->section = TAKE_PTR(n);
|
||||
|
||||
r = ordered_hashmap_ensure_allocated(&network->sr_iov_by_section, &network_config_hash_ops);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = ordered_hashmap_put(network->sr_iov_by_section, sr_iov->section, sr_iov);
|
||||
r = ordered_hashmap_ensure_put(&network->sr_iov_by_section, &network_config_hash_ops, sr_iov->section, sr_iov);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
@ -126,11 +126,7 @@ int qdisc_new_static(QDiscKind kind, Network *network, const char *filename, uns
|
||||
qdisc->network = network;
|
||||
qdisc->section = TAKE_PTR(n);
|
||||
|
||||
r = ordered_hashmap_ensure_allocated(&network->tc_by_section, &network_config_hash_ops);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = ordered_hashmap_put(network->tc_by_section, qdisc->section, TC(qdisc));
|
||||
r = ordered_hashmap_ensure_put(&network->tc_by_section, &network_config_hash_ops, qdisc->section, TC(qdisc));
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
@ -82,11 +82,7 @@ int tclass_new_static(TClassKind kind, Network *network, const char *filename, u
|
||||
tclass->network = network;
|
||||
tclass->section = TAKE_PTR(n);
|
||||
|
||||
r = ordered_hashmap_ensure_allocated(&network->tc_by_section, &network_config_hash_ops);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = ordered_hashmap_put(network->tc_by_section, tclass->section, tclass);
|
||||
r = ordered_hashmap_ensure_put(&network->tc_by_section, &network_config_hash_ops, tclass->section, tclass);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user