2020-11-09 05:23:58 +01:00
|
|
|
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
2014-02-04 23:13:52 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
/***
|
2018-06-12 17:15:23 +02:00
|
|
|
Copyright © 2013 Intel Corporation. All rights reserved.
|
2014-02-04 23:13:52 +01:00
|
|
|
***/
|
|
|
|
|
2015-11-18 22:46:33 +01:00
|
|
|
#include "sd-dhcp-client.h"
|
2014-02-04 23:13:52 +01:00
|
|
|
|
2020-05-29 11:26:24 +02:00
|
|
|
#include "dhcp-internal.h"
|
2014-02-04 23:13:52 +01:00
|
|
|
#include "dhcp-protocol.h"
|
2015-11-18 22:46:33 +01:00
|
|
|
#include "list.h"
|
|
|
|
#include "util.h"
|
2014-02-04 23:13:52 +01:00
|
|
|
|
2014-06-28 00:00:06 +02:00
|
|
|
struct sd_dhcp_route {
|
|
|
|
struct in_addr dst_addr;
|
|
|
|
struct in_addr gw_addr;
|
2014-11-01 19:02:44 +01:00
|
|
|
unsigned char dst_prefixlen;
|
2018-01-20 00:42:45 +01:00
|
|
|
|
|
|
|
uint8_t option;
|
2014-06-28 00:00:06 +02:00
|
|
|
};
|
|
|
|
|
2015-08-01 05:02:22 +02:00
|
|
|
struct sd_dhcp_raw_option {
|
|
|
|
LIST_FIELDS(struct sd_dhcp_raw_option, options);
|
|
|
|
|
|
|
|
uint8_t tag;
|
|
|
|
uint8_t length;
|
|
|
|
void *data;
|
|
|
|
};
|
|
|
|
|
2014-02-04 23:13:52 +01:00
|
|
|
struct sd_dhcp_lease {
|
2015-08-27 19:55:29 +02:00
|
|
|
unsigned n_ref;
|
2014-02-04 23:13:52 +01:00
|
|
|
|
dhcp: clean up dhcp4 lease object
a) drop handling of obsolete or unused DHCP options time_offset,
mtu_aging_timeout, policy filter, mdr, ttl, ip forwarding settings.
Should this become useful one day we can readd support for this.
b) For subnet mask and broadcast it is not always clear whether 0 or
255.255.255.255 might be valid, hence maintain a boolean indicating
validity next to it.
c) serialize/deserialize broadcast address, lifetime, T1 and T2 together
with the rest of the fields in dhcp_lease_save() and
dhcp_lease_load().
d) consistently return ENODATA from getter functions for data that is
missing in the lease.
e) add missing getter calls for broadcast, lifetime, T1, T2.
f) when decoding DHCP options, generate debug messages on parse
failures, but try to proceed if possible.
g) Similar, when deserializing a lease in dhcp_lease_load(), make sure
we deal nicely with unparsable fields, to provide upgrade compat.
h) fix some memory allocations
2015-08-27 01:05:13 +02:00
|
|
|
/* each 0 if unset */
|
2014-02-04 23:13:52 +01:00
|
|
|
uint32_t t1;
|
|
|
|
uint32_t t2;
|
|
|
|
uint32_t lifetime;
|
dhcp: clean up dhcp4 lease object
a) drop handling of obsolete or unused DHCP options time_offset,
mtu_aging_timeout, policy filter, mdr, ttl, ip forwarding settings.
Should this become useful one day we can readd support for this.
b) For subnet mask and broadcast it is not always clear whether 0 or
255.255.255.255 might be valid, hence maintain a boolean indicating
validity next to it.
c) serialize/deserialize broadcast address, lifetime, T1 and T2 together
with the rest of the fields in dhcp_lease_save() and
dhcp_lease_load().
d) consistently return ENODATA from getter functions for data that is
missing in the lease.
e) add missing getter calls for broadcast, lifetime, T1, T2.
f) when decoding DHCP options, generate debug messages on parse
failures, but try to proceed if possible.
g) Similar, when deserializing a lease in dhcp_lease_load(), make sure
we deal nicely with unparsable fields, to provide upgrade compat.
h) fix some memory allocations
2015-08-27 01:05:13 +02:00
|
|
|
|
|
|
|
/* each 0 if unset */
|
2014-02-04 23:13:52 +01:00
|
|
|
be32_t address;
|
|
|
|
be32_t server_address;
|
2014-03-03 17:13:59 +01:00
|
|
|
be32_t next_server;
|
dhcp: clean up dhcp4 lease object
a) drop handling of obsolete or unused DHCP options time_offset,
mtu_aging_timeout, policy filter, mdr, ttl, ip forwarding settings.
Should this become useful one day we can readd support for this.
b) For subnet mask and broadcast it is not always clear whether 0 or
255.255.255.255 might be valid, hence maintain a boolean indicating
validity next to it.
c) serialize/deserialize broadcast address, lifetime, T1 and T2 together
with the rest of the fields in dhcp_lease_save() and
dhcp_lease_load().
d) consistently return ENODATA from getter functions for data that is
missing in the lease.
e) add missing getter calls for broadcast, lifetime, T1, T2.
f) when decoding DHCP options, generate debug messages on parse
failures, but try to proceed if possible.
g) Similar, when deserializing a lease in dhcp_lease_load(), make sure
we deal nicely with unparsable fields, to provide upgrade compat.
h) fix some memory allocations
2015-08-27 01:05:13 +02:00
|
|
|
|
|
|
|
bool have_subnet_mask;
|
|
|
|
be32_t subnet_mask;
|
|
|
|
|
|
|
|
bool have_broadcast;
|
2014-05-20 22:02:49 +02:00
|
|
|
be32_t broadcast;
|
dhcp: clean up dhcp4 lease object
a) drop handling of obsolete or unused DHCP options time_offset,
mtu_aging_timeout, policy filter, mdr, ttl, ip forwarding settings.
Should this become useful one day we can readd support for this.
b) For subnet mask and broadcast it is not always clear whether 0 or
255.255.255.255 might be valid, hence maintain a boolean indicating
validity next to it.
c) serialize/deserialize broadcast address, lifetime, T1 and T2 together
with the rest of the fields in dhcp_lease_save() and
dhcp_lease_load().
d) consistently return ENODATA from getter functions for data that is
missing in the lease.
e) add missing getter calls for broadcast, lifetime, T1, T2.
f) when decoding DHCP options, generate debug messages on parse
failures, but try to proceed if possible.
g) Similar, when deserializing a lease in dhcp_lease_load(), make sure
we deal nicely with unparsable fields, to provide upgrade compat.
h) fix some memory allocations
2015-08-27 01:05:13 +02:00
|
|
|
|
2018-12-14 11:10:57 +01:00
|
|
|
struct in_addr *router;
|
|
|
|
size_t router_size;
|
|
|
|
|
2020-05-29 11:26:24 +02:00
|
|
|
DHCPServerData servers[_SD_DHCP_LEASE_SERVER_TYPE_MAX];
|
2020-04-22 14:48:11 +02:00
|
|
|
|
2014-06-28 00:00:06 +02:00
|
|
|
struct sd_dhcp_route *static_route;
|
dhcp: clean up dhcp4 lease object
a) drop handling of obsolete or unused DHCP options time_offset,
mtu_aging_timeout, policy filter, mdr, ttl, ip forwarding settings.
Should this become useful one day we can readd support for this.
b) For subnet mask and broadcast it is not always clear whether 0 or
255.255.255.255 might be valid, hence maintain a boolean indicating
validity next to it.
c) serialize/deserialize broadcast address, lifetime, T1 and T2 together
with the rest of the fields in dhcp_lease_save() and
dhcp_lease_load().
d) consistently return ENODATA from getter functions for data that is
missing in the lease.
e) add missing getter calls for broadcast, lifetime, T1, T2.
f) when decoding DHCP options, generate debug messages on parse
failures, but try to proceed if possible.
g) Similar, when deserializing a lease in dhcp_lease_load(), make sure
we deal nicely with unparsable fields, to provide upgrade compat.
h) fix some memory allocations
2015-08-27 01:05:13 +02:00
|
|
|
size_t static_route_size, static_route_allocated;
|
|
|
|
|
|
|
|
uint16_t mtu; /* 0 if unset */
|
|
|
|
|
2014-02-04 23:13:52 +01:00
|
|
|
char *domainname;
|
2017-05-13 16:19:32 +02:00
|
|
|
char **search_domains;
|
2014-02-04 23:13:52 +01:00
|
|
|
char *hostname;
|
2014-03-03 15:43:02 +01:00
|
|
|
char *root_path;
|
dhcp: clean up dhcp4 lease object
a) drop handling of obsolete or unused DHCP options time_offset,
mtu_aging_timeout, policy filter, mdr, ttl, ip forwarding settings.
Should this become useful one day we can readd support for this.
b) For subnet mask and broadcast it is not always clear whether 0 or
255.255.255.255 might be valid, hence maintain a boolean indicating
validity next to it.
c) serialize/deserialize broadcast address, lifetime, T1 and T2 together
with the rest of the fields in dhcp_lease_save() and
dhcp_lease_load().
d) consistently return ENODATA from getter functions for data that is
missing in the lease.
e) add missing getter calls for broadcast, lifetime, T1, T2.
f) when decoding DHCP options, generate debug messages on parse
failures, but try to proceed if possible.
g) Similar, when deserializing a lease in dhcp_lease_load(), make sure
we deal nicely with unparsable fields, to provide upgrade compat.
h) fix some memory allocations
2015-08-27 01:05:13 +02:00
|
|
|
|
2015-08-26 23:05:34 +02:00
|
|
|
void *client_id;
|
2014-11-19 00:13:12 +01:00
|
|
|
size_t client_id_len;
|
dhcp: clean up dhcp4 lease object
a) drop handling of obsolete or unused DHCP options time_offset,
mtu_aging_timeout, policy filter, mdr, ttl, ip forwarding settings.
Should this become useful one day we can readd support for this.
b) For subnet mask and broadcast it is not always clear whether 0 or
255.255.255.255 might be valid, hence maintain a boolean indicating
validity next to it.
c) serialize/deserialize broadcast address, lifetime, T1 and T2 together
with the rest of the fields in dhcp_lease_save() and
dhcp_lease_load().
d) consistently return ENODATA from getter functions for data that is
missing in the lease.
e) add missing getter calls for broadcast, lifetime, T1, T2.
f) when decoding DHCP options, generate debug messages on parse
failures, but try to proceed if possible.
g) Similar, when deserializing a lease in dhcp_lease_load(), make sure
we deal nicely with unparsable fields, to provide upgrade compat.
h) fix some memory allocations
2015-08-27 01:05:13 +02:00
|
|
|
|
2015-08-26 23:05:34 +02:00
|
|
|
void *vendor_specific;
|
2015-07-09 18:04:01 +02:00
|
|
|
size_t vendor_specific_len;
|
dhcp: clean up dhcp4 lease object
a) drop handling of obsolete or unused DHCP options time_offset,
mtu_aging_timeout, policy filter, mdr, ttl, ip forwarding settings.
Should this become useful one day we can readd support for this.
b) For subnet mask and broadcast it is not always clear whether 0 or
255.255.255.255 might be valid, hence maintain a boolean indicating
validity next to it.
c) serialize/deserialize broadcast address, lifetime, T1 and T2 together
with the rest of the fields in dhcp_lease_save() and
dhcp_lease_load().
d) consistently return ENODATA from getter functions for data that is
missing in the lease.
e) add missing getter calls for broadcast, lifetime, T1, T2.
f) when decoding DHCP options, generate debug messages on parse
failures, but try to proceed if possible.
g) Similar, when deserializing a lease in dhcp_lease_load(), make sure
we deal nicely with unparsable fields, to provide upgrade compat.
h) fix some memory allocations
2015-08-27 01:05:13 +02:00
|
|
|
|
2015-08-26 19:19:32 +02:00
|
|
|
char *timezone;
|
dhcp: clean up dhcp4 lease object
a) drop handling of obsolete or unused DHCP options time_offset,
mtu_aging_timeout, policy filter, mdr, ttl, ip forwarding settings.
Should this become useful one day we can readd support for this.
b) For subnet mask and broadcast it is not always clear whether 0 or
255.255.255.255 might be valid, hence maintain a boolean indicating
validity next to it.
c) serialize/deserialize broadcast address, lifetime, T1 and T2 together
with the rest of the fields in dhcp_lease_save() and
dhcp_lease_load().
d) consistently return ENODATA from getter functions for data that is
missing in the lease.
e) add missing getter calls for broadcast, lifetime, T1, T2.
f) when decoding DHCP options, generate debug messages on parse
failures, but try to proceed if possible.
g) Similar, when deserializing a lease in dhcp_lease_load(), make sure
we deal nicely with unparsable fields, to provide upgrade compat.
h) fix some memory allocations
2015-08-27 01:05:13 +02:00
|
|
|
|
2015-08-01 05:02:22 +02:00
|
|
|
LIST_HEAD(struct sd_dhcp_raw_option, private_options);
|
2014-02-04 23:13:52 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
int dhcp_lease_new(sd_dhcp_lease **ret);
|
|
|
|
|
dhcp: clean up dhcp4 lease object
a) drop handling of obsolete or unused DHCP options time_offset,
mtu_aging_timeout, policy filter, mdr, ttl, ip forwarding settings.
Should this become useful one day we can readd support for this.
b) For subnet mask and broadcast it is not always clear whether 0 or
255.255.255.255 might be valid, hence maintain a boolean indicating
validity next to it.
c) serialize/deserialize broadcast address, lifetime, T1 and T2 together
with the rest of the fields in dhcp_lease_save() and
dhcp_lease_load().
d) consistently return ENODATA from getter functions for data that is
missing in the lease.
e) add missing getter calls for broadcast, lifetime, T1, T2.
f) when decoding DHCP options, generate debug messages on parse
failures, but try to proceed if possible.
g) Similar, when deserializing a lease in dhcp_lease_load(), make sure
we deal nicely with unparsable fields, to provide upgrade compat.
h) fix some memory allocations
2015-08-27 01:05:13 +02:00
|
|
|
int dhcp_lease_parse_options(uint8_t code, uint8_t len, const void *option, void *userdata);
|
2017-05-13 16:19:32 +02:00
|
|
|
int dhcp_lease_parse_search_domains(const uint8_t *option, size_t len, char ***domains);
|
dhcp: clean up dhcp4 lease object
a) drop handling of obsolete or unused DHCP options time_offset,
mtu_aging_timeout, policy filter, mdr, ttl, ip forwarding settings.
Should this become useful one day we can readd support for this.
b) For subnet mask and broadcast it is not always clear whether 0 or
255.255.255.255 might be valid, hence maintain a boolean indicating
validity next to it.
c) serialize/deserialize broadcast address, lifetime, T1 and T2 together
with the rest of the fields in dhcp_lease_save() and
dhcp_lease_load().
d) consistently return ENODATA from getter functions for data that is
missing in the lease.
e) add missing getter calls for broadcast, lifetime, T1, T2.
f) when decoding DHCP options, generate debug messages on parse
failures, but try to proceed if possible.
g) Similar, when deserializing a lease in dhcp_lease_load(), make sure
we deal nicely with unparsable fields, to provide upgrade compat.
h) fix some memory allocations
2015-08-27 01:05:13 +02:00
|
|
|
int dhcp_lease_insert_private_option(sd_dhcp_lease *lease, uint8_t tag, const void *data, uint8_t len);
|
2014-03-19 16:05:44 +01:00
|
|
|
|
dhcp: clean up dhcp4 lease object
a) drop handling of obsolete or unused DHCP options time_offset,
mtu_aging_timeout, policy filter, mdr, ttl, ip forwarding settings.
Should this become useful one day we can readd support for this.
b) For subnet mask and broadcast it is not always clear whether 0 or
255.255.255.255 might be valid, hence maintain a boolean indicating
validity next to it.
c) serialize/deserialize broadcast address, lifetime, T1 and T2 together
with the rest of the fields in dhcp_lease_save() and
dhcp_lease_load().
d) consistently return ENODATA from getter functions for data that is
missing in the lease.
e) add missing getter calls for broadcast, lifetime, T1, T2.
f) when decoding DHCP options, generate debug messages on parse
failures, but try to proceed if possible.
g) Similar, when deserializing a lease in dhcp_lease_load(), make sure
we deal nicely with unparsable fields, to provide upgrade compat.
h) fix some memory allocations
2015-08-27 01:05:13 +02:00
|
|
|
int dhcp_lease_set_default_subnet_mask(sd_dhcp_lease *lease);
|
2014-11-19 00:13:12 +01:00
|
|
|
|
dhcp: clean up dhcp4 lease object
a) drop handling of obsolete or unused DHCP options time_offset,
mtu_aging_timeout, policy filter, mdr, ttl, ip forwarding settings.
Should this become useful one day we can readd support for this.
b) For subnet mask and broadcast it is not always clear whether 0 or
255.255.255.255 might be valid, hence maintain a boolean indicating
validity next to it.
c) serialize/deserialize broadcast address, lifetime, T1 and T2 together
with the rest of the fields in dhcp_lease_save() and
dhcp_lease_load().
d) consistently return ENODATA from getter functions for data that is
missing in the lease.
e) add missing getter calls for broadcast, lifetime, T1, T2.
f) when decoding DHCP options, generate debug messages on parse
failures, but try to proceed if possible.
g) Similar, when deserializing a lease in dhcp_lease_load(), make sure
we deal nicely with unparsable fields, to provide upgrade compat.
h) fix some memory allocations
2015-08-27 01:05:13 +02:00
|
|
|
int dhcp_lease_set_client_id(sd_dhcp_lease *lease, const void *client_id, size_t client_id_len);
|