mirror of
https://github.com/systemd/systemd-stable.git
synced 2024-12-22 13:33:56 +03:00
dhcp: remove struct sd_dhcp_raw_option
sd_dhcp_raw_option and sd_dhcp_option are essentially equivalent.
This commit is contained in:
parent
d8b736bd0c
commit
461dbb2fa9
@ -15,6 +15,16 @@
|
||||
#include "dhcp-protocol.h"
|
||||
#include "socket-util.h"
|
||||
|
||||
typedef struct sd_dhcp_option {
|
||||
unsigned n_ref;
|
||||
|
||||
uint8_t option;
|
||||
void *data;
|
||||
size_t length;
|
||||
} sd_dhcp_option;
|
||||
|
||||
extern const struct hash_ops dhcp_option_hash_ops;
|
||||
|
||||
int dhcp_network_bind_raw_socket(int ifindex, union sockaddr_union *link,
|
||||
uint32_t xid, const uint8_t *mac_addr,
|
||||
size_t mac_addr_len, uint16_t arp_type,
|
||||
|
@ -79,7 +79,7 @@ static int option_append(uint8_t options[], size_t size, size_t *offset,
|
||||
break;
|
||||
case SD_DHCP_OPTION_VENDOR_SPECIFIC: {
|
||||
OrderedHashmap *s = (OrderedHashmap *) optval;
|
||||
struct sd_dhcp_raw_option *p;
|
||||
struct sd_dhcp_option *p;
|
||||
size_t l = 0;
|
||||
Iterator i;
|
||||
|
||||
@ -95,7 +95,7 @@ static int option_append(uint8_t options[], size_t size, size_t *offset,
|
||||
*offset += 2;
|
||||
|
||||
ORDERED_HASHMAP_FOREACH(p, s, i) {
|
||||
options[*offset] = p->type;
|
||||
options[*offset] = p->option;
|
||||
options[*offset + 1] = p->length;
|
||||
memcpy(&options[*offset + 2], p->data, p->length);
|
||||
*offset += 2 + p->length;
|
||||
@ -315,3 +315,43 @@ int dhcp_option_parse(DHCPMessage *message, size_t len, dhcp_option_callback_t c
|
||||
|
||||
return message_type;
|
||||
}
|
||||
|
||||
static sd_dhcp_option* dhcp_option_free(sd_dhcp_option *i) {
|
||||
if (!i)
|
||||
return NULL;
|
||||
|
||||
free(i->data);
|
||||
return mfree(i);
|
||||
}
|
||||
|
||||
int sd_dhcp_option_new(uint8_t option, const void *data, size_t length, sd_dhcp_option **ret) {
|
||||
assert_return(ret, -EINVAL);
|
||||
assert_return(length == 0 || data, -EINVAL);
|
||||
|
||||
_cleanup_free_ void *q = memdup(data, length);
|
||||
if (!q)
|
||||
return -ENOMEM;
|
||||
|
||||
sd_dhcp_option *p = new(sd_dhcp_option, 1);
|
||||
if (!p)
|
||||
return -ENOMEM;
|
||||
|
||||
*p = (sd_dhcp_option) {
|
||||
.n_ref = 1,
|
||||
.option = option,
|
||||
.length = length,
|
||||
.data = TAKE_PTR(q),
|
||||
};
|
||||
|
||||
*ret = TAKE_PTR(p);
|
||||
return 0;
|
||||
}
|
||||
|
||||
DEFINE_TRIVIAL_REF_UNREF_FUNC(sd_dhcp_option, sd_dhcp_option, dhcp_option_free);
|
||||
DEFINE_HASH_OPS_WITH_VALUE_DESTRUCTOR(
|
||||
dhcp_option_hash_ops,
|
||||
void,
|
||||
trivial_hash_func,
|
||||
trivial_compare_func,
|
||||
sd_dhcp_option,
|
||||
sd_dhcp_option_unref);
|
||||
|
@ -37,15 +37,6 @@ typedef struct DHCPLease {
|
||||
usec_t expiration;
|
||||
} DHCPLease;
|
||||
|
||||
struct sd_dhcp_raw_option {
|
||||
unsigned n_ref;
|
||||
|
||||
uint8_t type;
|
||||
uint8_t length;
|
||||
|
||||
void *data;
|
||||
};
|
||||
|
||||
struct sd_dhcp_server {
|
||||
unsigned n_ref;
|
||||
|
||||
|
@ -34,14 +34,6 @@
|
||||
#define RESTART_AFTER_NAK_MIN_USEC (1 * USEC_PER_SEC)
|
||||
#define RESTART_AFTER_NAK_MAX_USEC (30 * USEC_PER_MINUTE)
|
||||
|
||||
struct sd_dhcp_option {
|
||||
unsigned n_ref;
|
||||
|
||||
uint8_t option;
|
||||
void *data;
|
||||
size_t length;
|
||||
};
|
||||
|
||||
struct sd_dhcp_client {
|
||||
unsigned n_ref;
|
||||
|
||||
@ -538,46 +530,6 @@ int sd_dhcp_client_set_max_attempts(sd_dhcp_client *client, uint64_t max_attempt
|
||||
return 0;
|
||||
}
|
||||
|
||||
static sd_dhcp_option* dhcp_option_free(sd_dhcp_option *i) {
|
||||
if (!i)
|
||||
return NULL;
|
||||
|
||||
free(i->data);
|
||||
return mfree(i);
|
||||
}
|
||||
|
||||
int sd_dhcp_option_new(uint8_t option, void *data, size_t length, sd_dhcp_option **ret) {
|
||||
assert_return(ret, -EINVAL);
|
||||
assert_return(length == 0 || data, -EINVAL);
|
||||
|
||||
_cleanup_free_ void *q = memdup(data, length);
|
||||
if (!q)
|
||||
return -ENOMEM;
|
||||
|
||||
sd_dhcp_option *p = new(sd_dhcp_option, 1);
|
||||
if (!p)
|
||||
return -ENOMEM;
|
||||
|
||||
*p = (sd_dhcp_option) {
|
||||
.n_ref = 1,
|
||||
.option = option,
|
||||
.length = length,
|
||||
.data = TAKE_PTR(q),
|
||||
};
|
||||
|
||||
*ret = TAKE_PTR(p);
|
||||
return 0;
|
||||
}
|
||||
|
||||
DEFINE_TRIVIAL_REF_UNREF_FUNC(sd_dhcp_option, sd_dhcp_option, dhcp_option_free);
|
||||
DEFINE_HASH_OPS_WITH_VALUE_DESTRUCTOR(
|
||||
dhcp_option_hash_ops,
|
||||
void,
|
||||
trivial_hash_func,
|
||||
trivial_compare_func,
|
||||
sd_dhcp_option,
|
||||
sd_dhcp_option_unref);
|
||||
|
||||
int sd_dhcp_client_set_dhcp_option(sd_dhcp_client *client, sd_dhcp_option *v) {
|
||||
int r;
|
||||
|
||||
|
@ -127,46 +127,6 @@ int client_id_compare_func(const DHCPClientId *a, const DHCPClientId *b) {
|
||||
DEFINE_PRIVATE_HASH_OPS_WITH_VALUE_DESTRUCTOR(dhcp_lease_hash_ops, DHCPClientId, client_id_hash_func, client_id_compare_func,
|
||||
DHCPLease, dhcp_lease_free);
|
||||
|
||||
static sd_dhcp_raw_option* raw_option_free(sd_dhcp_raw_option *i) {
|
||||
if (!i)
|
||||
return NULL;
|
||||
|
||||
free(i->data);
|
||||
return mfree(i);
|
||||
}
|
||||
|
||||
_public_ int sd_dhcp_raw_option_new(uint8_t type, char *data, size_t length, sd_dhcp_raw_option **ret) {
|
||||
_cleanup_(sd_dhcp_raw_option_unrefp) sd_dhcp_raw_option *p = NULL;
|
||||
|
||||
assert_return(ret, -EINVAL);
|
||||
|
||||
p = new(sd_dhcp_raw_option, 1);
|
||||
if (!p)
|
||||
return -ENOMEM;
|
||||
|
||||
*p = (sd_dhcp_raw_option) {
|
||||
.n_ref = 1,
|
||||
.data = memdup(data, length),
|
||||
.length = length,
|
||||
.type = type,
|
||||
};
|
||||
|
||||
if (!p->data)
|
||||
return -ENOMEM;
|
||||
|
||||
*ret = TAKE_PTR(p);
|
||||
return 0;
|
||||
}
|
||||
|
||||
DEFINE_TRIVIAL_REF_UNREF_FUNC(sd_dhcp_raw_option, sd_dhcp_raw_option, raw_option_free);
|
||||
DEFINE_HASH_OPS_WITH_VALUE_DESTRUCTOR(
|
||||
dhcp_raw_options_hash_ops,
|
||||
void,
|
||||
trivial_hash_func,
|
||||
trivial_compare_func,
|
||||
sd_dhcp_raw_option,
|
||||
sd_dhcp_raw_option_unref);
|
||||
|
||||
static sd_dhcp_server *dhcp_server_free(sd_dhcp_server *server) {
|
||||
assert(server);
|
||||
|
||||
@ -1222,13 +1182,13 @@ int sd_dhcp_server_set_emit_router(sd_dhcp_server *server, int enabled) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int sd_dhcp_server_add_raw_option(sd_dhcp_server *server, sd_dhcp_raw_option *v) {
|
||||
int sd_dhcp_server_add_option(sd_dhcp_server *server, sd_dhcp_option *v) {
|
||||
int r;
|
||||
|
||||
assert_return(server, -EINVAL);
|
||||
assert_return(v, -EINVAL);
|
||||
|
||||
r = ordered_hashmap_ensure_allocated(&server->raw_option, &dhcp_raw_options_hash_ops);
|
||||
r = ordered_hashmap_ensure_allocated(&server->raw_option, &dhcp_option_hash_ops);
|
||||
if (r < 0)
|
||||
return -ENOMEM;
|
||||
|
||||
@ -1236,7 +1196,7 @@ int sd_dhcp_server_add_raw_option(sd_dhcp_server *server, sd_dhcp_raw_option *v)
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
sd_dhcp_raw_option_ref(v);
|
||||
sd_dhcp_option_ref(v);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
#include "sd-dhcp-server.h"
|
||||
|
||||
#include "dhcp-internal.h"
|
||||
#include "escape.h"
|
||||
#include "networkd-dhcp-server.h"
|
||||
#include "networkd-link.h"
|
||||
@ -192,7 +193,7 @@ static int link_push_uplink_sip_to_dhcp_server(Link *link, sd_dhcp_server *s) {
|
||||
|
||||
int dhcp4_server_configure(Link *link) {
|
||||
bool acquired_uplink = false;
|
||||
sd_dhcp_raw_option *p;
|
||||
sd_dhcp_option *p;
|
||||
Link *uplink = NULL;
|
||||
Address *address;
|
||||
Iterator i;
|
||||
@ -305,8 +306,8 @@ int dhcp4_server_configure(Link *link) {
|
||||
return r;
|
||||
}
|
||||
|
||||
ORDERED_HASHMAP_FOREACH(p, link->network->dhcp_server_raw_options, i) {
|
||||
r = sd_dhcp_server_add_raw_option(link->dhcp_server, p);
|
||||
ORDERED_HASHMAP_FOREACH(p, link->network->dhcp_server_options, i) {
|
||||
r = sd_dhcp_server_add_option(link->dhcp_server, p);
|
||||
if (r == -EEXIST)
|
||||
continue;
|
||||
if (r < 0)
|
||||
@ -492,7 +493,7 @@ int config_parse_dhcp_server_option_data(
|
||||
void *data,
|
||||
void *userdata) {
|
||||
|
||||
_cleanup_(sd_dhcp_raw_option_unrefp) sd_dhcp_raw_option *opt = NULL, *old = NULL;
|
||||
_cleanup_(sd_dhcp_option_unrefp) sd_dhcp_option *opt = NULL, *old = NULL;
|
||||
_cleanup_free_ char *word = NULL, *q = NULL;
|
||||
union in_addr_union addr;
|
||||
DHCPOptionDataType type;
|
||||
@ -512,7 +513,7 @@ int config_parse_dhcp_server_option_data(
|
||||
assert(data);
|
||||
|
||||
if (isempty(rvalue)) {
|
||||
network->dhcp_server_raw_options = ordered_hashmap_free(network->dhcp_server_raw_options);
|
||||
network->dhcp_server_options = ordered_hashmap_free(network->dhcp_server_options);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -619,20 +620,20 @@ int config_parse_dhcp_server_option_data(
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
r = sd_dhcp_raw_option_new(u, udata, sz, &opt);
|
||||
r = sd_dhcp_option_new(u, udata, sz, &opt);
|
||||
if (r < 0) {
|
||||
log_syntax(unit, LOG_ERR, filename, line, r,
|
||||
"Failed to store DHCP send raw option '%s', ignoring assignment: %m", rvalue);
|
||||
return 0;
|
||||
}
|
||||
|
||||
r = ordered_hashmap_ensure_allocated(&network->dhcp_server_raw_options, &dhcp_raw_options_hash_ops);
|
||||
r = ordered_hashmap_ensure_allocated(&network->dhcp_server_options, &dhcp_option_hash_ops);
|
||||
if (r < 0)
|
||||
return log_oom();
|
||||
|
||||
/* Overwrite existing option */
|
||||
old = ordered_hashmap_remove(network->dhcp_server_raw_options, UINT_TO_PTR(u));
|
||||
r = ordered_hashmap_put(network->dhcp_server_raw_options, UINT_TO_PTR(u), opt);
|
||||
old = ordered_hashmap_remove(network->dhcp_server_options, UINT_TO_PTR(u));
|
||||
r = ordered_hashmap_put(network->dhcp_server_options, UINT_TO_PTR(u), opt);
|
||||
if (r < 0) {
|
||||
log_syntax(unit, LOG_ERR, filename, line, r,
|
||||
"Failed to store DHCP server send raw option '%s'", rvalue);
|
||||
|
@ -687,7 +687,7 @@ static Network *network_free(Network *network) {
|
||||
set_free_free(network->dnssec_negative_trust_anchors);
|
||||
|
||||
ordered_hashmap_free(network->dhcp_send_options);
|
||||
ordered_hashmap_free(network->dhcp_server_raw_options);
|
||||
ordered_hashmap_free(network->dhcp_server_options);
|
||||
|
||||
return mfree(network);
|
||||
}
|
||||
|
@ -115,7 +115,7 @@ struct Network {
|
||||
Set *dhcp_black_listed_ip;
|
||||
Set *dhcp_request_options;
|
||||
OrderedHashmap *dhcp_send_options;
|
||||
OrderedHashmap *dhcp_server_raw_options;
|
||||
OrderedHashmap *dhcp_server_options;
|
||||
|
||||
/* DHCPv6 Client support*/
|
||||
bool dhcp6_use_dns;
|
||||
|
@ -22,6 +22,7 @@ _not_installed_headers = '''
|
||||
sd-dhcp6-lease.h
|
||||
sd-dhcp-client.h
|
||||
sd-dhcp-lease.h
|
||||
sd-dhcp-option.h
|
||||
sd-dhcp-server.h
|
||||
sd-ipv4acd.h
|
||||
sd-ipv4ll.h
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "sd-dhcp-lease.h"
|
||||
#include "sd-dhcp-option.h"
|
||||
#include "sd-event.h"
|
||||
|
||||
#include "_sd-common.h"
|
||||
@ -99,7 +100,6 @@ enum {
|
||||
};
|
||||
|
||||
typedef struct sd_dhcp_client sd_dhcp_client;
|
||||
typedef struct sd_dhcp_option sd_dhcp_option;
|
||||
|
||||
typedef int (*sd_dhcp_client_callback_t)(sd_dhcp_client *client, int event, void *userdata);
|
||||
int sd_dhcp_client_set_callback(
|
||||
@ -179,9 +179,6 @@ int sd_dhcp_client_set_service_type(
|
||||
sd_dhcp_client *client,
|
||||
int type);
|
||||
|
||||
int sd_dhcp_option_new(uint8_t option, void *data, size_t length, sd_dhcp_option **ret);
|
||||
sd_dhcp_option* sd_dhcp_option_ref(sd_dhcp_option *i);
|
||||
sd_dhcp_option* sd_dhcp_option_unref(sd_dhcp_option *i);
|
||||
int sd_dhcp_client_set_dhcp_option(sd_dhcp_client *client, sd_dhcp_option *v);
|
||||
|
||||
int sd_dhcp_client_stop(sd_dhcp_client *client);
|
||||
@ -204,7 +201,6 @@ int sd_dhcp_client_detach_event(sd_dhcp_client *client);
|
||||
sd_event *sd_dhcp_client_get_event(sd_dhcp_client *client);
|
||||
|
||||
_SD_DEFINE_POINTER_CLEANUP_FUNC(sd_dhcp_client, sd_dhcp_client_unref);
|
||||
_SD_DEFINE_POINTER_CLEANUP_FUNC(sd_dhcp_option, sd_dhcp_option_unref);
|
||||
|
||||
_SD_END_DECLARATIONS;
|
||||
|
||||
|
38
src/systemd/sd-dhcp-option.h
Normal file
38
src/systemd/sd-dhcp-option.h
Normal file
@ -0,0 +1,38 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
#ifndef foosddhcpoptionhfoo
|
||||
#define foosddhcpoptionhfoo
|
||||
|
||||
/***
|
||||
Copyright © 2013 Intel Corporation. All rights reserved.
|
||||
systemd is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
systemd is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
||||
***/
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "_sd-common.h"
|
||||
|
||||
_SD_BEGIN_DECLARATIONS;
|
||||
|
||||
typedef struct sd_dhcp_option sd_dhcp_option;
|
||||
|
||||
int sd_dhcp_option_new(uint8_t option, const void *data, size_t length, sd_dhcp_option **ret);
|
||||
sd_dhcp_option *sd_dhcp_option_ref(sd_dhcp_option *ra);
|
||||
sd_dhcp_option *sd_dhcp_option_unref(sd_dhcp_option *ra);
|
||||
|
||||
_SD_DEFINE_POINTER_CLEANUP_FUNC(sd_dhcp_option, sd_dhcp_option_unref);
|
||||
|
||||
_SD_END_DECLARATIONS;
|
||||
|
||||
#endif
|
@ -21,26 +21,20 @@
|
||||
#include <inttypes.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include "sd-dhcp-option.h"
|
||||
#include "sd-event.h"
|
||||
|
||||
#include "_sd-common.h"
|
||||
|
||||
_SD_BEGIN_DECLARATIONS;
|
||||
|
||||
extern const struct hash_ops dhcp_raw_options_hash_ops;
|
||||
|
||||
typedef struct sd_dhcp_server sd_dhcp_server;
|
||||
typedef struct sd_dhcp_raw_option sd_dhcp_raw_option;
|
||||
|
||||
int sd_dhcp_server_new(sd_dhcp_server **ret, int ifindex);
|
||||
|
||||
sd_dhcp_server *sd_dhcp_server_ref(sd_dhcp_server *server);
|
||||
sd_dhcp_server *sd_dhcp_server_unref(sd_dhcp_server *server);
|
||||
|
||||
int sd_dhcp_raw_option_new(uint8_t type, char *data, size_t lengt, sd_dhcp_raw_option **ret);
|
||||
sd_dhcp_raw_option *sd_dhcp_raw_option_ref(sd_dhcp_raw_option *ra);
|
||||
sd_dhcp_raw_option *sd_dhcp_raw_option_unref(sd_dhcp_raw_option *ra);
|
||||
|
||||
int sd_dhcp_server_attach_event(sd_dhcp_server *client, sd_event *event, int64_t priority);
|
||||
int sd_dhcp_server_detach_event(sd_dhcp_server *client);
|
||||
sd_event *sd_dhcp_server_get_event(sd_dhcp_server *client);
|
||||
@ -58,7 +52,7 @@ int sd_dhcp_server_set_ntp(sd_dhcp_server *server, const struct in_addr ntp[], u
|
||||
int sd_dhcp_server_set_sip(sd_dhcp_server *server, const struct in_addr sip[], unsigned n);
|
||||
int sd_dhcp_server_set_emit_router(sd_dhcp_server *server, int enabled);
|
||||
|
||||
int sd_dhcp_server_add_raw_option(sd_dhcp_server *server, sd_dhcp_raw_option *v);
|
||||
int sd_dhcp_server_add_option(sd_dhcp_server *server, sd_dhcp_option *v);
|
||||
|
||||
int sd_dhcp_server_set_max_lease_time(sd_dhcp_server *server, uint32_t t);
|
||||
int sd_dhcp_server_set_default_lease_time(sd_dhcp_server *server, uint32_t t);
|
||||
@ -66,7 +60,6 @@ int sd_dhcp_server_set_default_lease_time(sd_dhcp_server *server, uint32_t t);
|
||||
int sd_dhcp_server_forcerenew(sd_dhcp_server *server);
|
||||
|
||||
_SD_DEFINE_POINTER_CLEANUP_FUNC(sd_dhcp_server, sd_dhcp_server_unref);
|
||||
_SD_DEFINE_POINTER_CLEANUP_FUNC(sd_dhcp_raw_option, sd_dhcp_raw_option_unref);
|
||||
|
||||
_SD_END_DECLARATIONS;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user