2017-11-18 19:09:20 +03:00
/* SPDX-License-Identifier: LGPL-2.1+ */
2014-02-05 02:13:52 +04:00
/***
This file is part of systemd .
Copyright ( C ) 2013 Intel Corporation . All rights reserved .
Copyright ( C ) 2014 Tom Gundersen
* * */
2015-10-24 23:58:24 +03:00
# include <arpa/inet.h>
2014-02-05 02:13:52 +04:00
# include <errno.h>
# include <stdio.h>
2017-12-11 21:50:30 +03:00
# include <stdio_ext.h>
2015-10-24 23:58:24 +03:00
# include <stdlib.h>
# include <string.h>
# include "sd-dhcp-lease.h"
2014-02-05 02:13:52 +04:00
2015-10-27 05:01:06 +03:00
# include "alloc-util.h"
2015-10-24 23:58:24 +03:00
# include "dhcp-lease-internal.h"
# include "dhcp-protocol.h"
# include "dns-domain.h"
2015-10-25 15:14:12 +03:00
# include "fd-util.h"
2014-02-27 04:24:05 +04:00
# include "fileio.h"
2015-11-03 14:25:29 +03:00
# include "hexdecoct.h"
2015-05-18 18:10:07 +03:00
# include "hostname-util.h"
2015-10-24 23:58:24 +03:00
# include "in-addr-util.h"
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 02:05:13 +03:00
# include "network-internal.h"
2015-10-26 18:18:16 +03:00
# include "parse-util.h"
2016-01-12 17:34:20 +03:00
# include "stdio-util.h"
2015-11-03 14:25:29 +03:00
# include "string-util.h"
2015-10-24 23:58:24 +03:00
# include "unaligned.h"
2014-02-05 02:13:52 +04:00
int sd_dhcp_lease_get_address ( sd_dhcp_lease * lease , struct in_addr * addr ) {
assert_return ( lease , - EINVAL ) ;
assert_return ( addr , - EINVAL ) ;
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 02:05:13 +03:00
if ( lease - > address = = 0 )
return - ENODATA ;
2014-02-05 02:13:52 +04:00
addr - > s_addr = lease - > address ;
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 02:05:13 +03:00
return 0 ;
}
2014-02-05 02:13:52 +04: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 02:05:13 +03:00
int sd_dhcp_lease_get_broadcast ( sd_dhcp_lease * lease , struct in_addr * addr ) {
assert_return ( lease , - EINVAL ) ;
assert_return ( addr , - EINVAL ) ;
if ( ! lease - > have_broadcast )
return - ENODATA ;
addr - > s_addr = lease - > broadcast ;
2014-02-05 02:13:52 +04:00
return 0 ;
}
2014-06-26 17:18:43 +04:00
int sd_dhcp_lease_get_lifetime ( sd_dhcp_lease * lease , uint32_t * lifetime ) {
assert_return ( lease , - EINVAL ) ;
2014-11-19 15:57:08 +03:00
assert_return ( lifetime , - EINVAL ) ;
2014-06-26 17:18:43 +04: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 02:05:13 +03:00
if ( lease - > lifetime < = 0 )
return - ENODATA ;
2014-06-26 17:18:43 +04:00
* lifetime = lease - > 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 02:05:13 +03:00
return 0 ;
}
2014-06-26 17:18:43 +04: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 02:05:13 +03:00
int sd_dhcp_lease_get_t1 ( sd_dhcp_lease * lease , uint32_t * t1 ) {
assert_return ( lease , - EINVAL ) ;
assert_return ( t1 , - EINVAL ) ;
if ( lease - > t1 < = 0 )
return - ENODATA ;
* t1 = lease - > t1 ;
return 0 ;
}
int sd_dhcp_lease_get_t2 ( sd_dhcp_lease * lease , uint32_t * t2 ) {
assert_return ( lease , - EINVAL ) ;
assert_return ( t2 , - EINVAL ) ;
if ( lease - > t2 < = 0 )
return - ENODATA ;
* t2 = lease - > t2 ;
2014-06-26 17:18:43 +04:00
return 0 ;
}
2014-02-05 02:13:52 +04:00
int sd_dhcp_lease_get_mtu ( sd_dhcp_lease * lease , uint16_t * mtu ) {
assert_return ( lease , - EINVAL ) ;
assert_return ( mtu , - EINVAL ) ;
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 02:05:13 +03:00
if ( lease - > mtu < = 0 )
return - ENODATA ;
2014-02-05 02:13:52 +04: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 02:05:13 +03:00
* mtu = lease - > mtu ;
2014-02-05 02:13:52 +04:00
return 0 ;
}
2014-07-17 03:39:46 +04:00
int sd_dhcp_lease_get_dns ( sd_dhcp_lease * lease , const struct in_addr * * addr ) {
2014-02-05 02:13:52 +04:00
assert_return ( lease , - EINVAL ) ;
assert_return ( addr , - EINVAL ) ;
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 02:05:13 +03:00
if ( lease - > dns_size < = 0 )
return - ENODATA ;
2014-02-05 02:13:52 +04: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 02:05:13 +03:00
* addr = lease - > dns ;
return ( int ) lease - > dns_size ;
2014-02-05 02:13:52 +04:00
}
2014-07-17 03:39:46 +04:00
int sd_dhcp_lease_get_ntp ( sd_dhcp_lease * lease , const struct in_addr * * addr ) {
2014-04-29 14:17:27 +04:00
assert_return ( lease , - EINVAL ) ;
assert_return ( addr , - EINVAL ) ;
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 02:05:13 +03:00
if ( lease - > ntp_size < = 0 )
return - ENODATA ;
2014-04-29 14:17:27 +04: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 02:05:13 +03:00
* addr = lease - > ntp ;
return ( int ) lease - > ntp_size ;
2014-04-29 14:17:27 +04:00
}
2014-02-05 02:13:52 +04:00
int sd_dhcp_lease_get_domainname ( sd_dhcp_lease * lease , const char * * domainname ) {
assert_return ( lease , - EINVAL ) ;
assert_return ( domainname , - EINVAL ) ;
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 02:05:13 +03:00
if ( ! lease - > domainname )
return - ENODATA ;
2014-02-05 02:13:52 +04: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 02:05:13 +03:00
* domainname = lease - > domainname ;
2014-02-05 02:13:52 +04:00
return 0 ;
}
int sd_dhcp_lease_get_hostname ( sd_dhcp_lease * lease , const char * * hostname ) {
assert_return ( lease , - EINVAL ) ;
assert_return ( hostname , - EINVAL ) ;
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 02:05:13 +03:00
if ( ! lease - > hostname )
return - ENODATA ;
2014-02-05 02:13:52 +04: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 02:05:13 +03:00
* hostname = lease - > hostname ;
2014-02-05 02:13:52 +04:00
return 0 ;
}
2014-03-03 18:43:02 +04:00
int sd_dhcp_lease_get_root_path ( sd_dhcp_lease * lease , const char * * root_path ) {
assert_return ( lease , - EINVAL ) ;
assert_return ( root_path , - EINVAL ) ;
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 02:05:13 +03:00
if ( ! lease - > root_path )
return - ENODATA ;
2014-03-03 18:43:02 +04: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 02:05:13 +03:00
* root_path = lease - > root_path ;
2014-03-03 18:43:02 +04:00
return 0 ;
}
2014-02-05 02:13:52 +04:00
int sd_dhcp_lease_get_router ( sd_dhcp_lease * lease , struct in_addr * addr ) {
assert_return ( lease , - EINVAL ) ;
assert_return ( addr , - EINVAL ) ;
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 02:05:13 +03:00
if ( lease - > router = = 0 )
return - ENODATA ;
2014-02-05 02:13:52 +04: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 02:05:13 +03:00
addr - > s_addr = lease - > router ;
2014-02-05 02:13:52 +04:00
return 0 ;
}
int sd_dhcp_lease_get_netmask ( sd_dhcp_lease * lease , struct in_addr * addr ) {
assert_return ( lease , - EINVAL ) ;
assert_return ( addr , - EINVAL ) ;
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 02:05:13 +03:00
if ( ! lease - > have_subnet_mask )
return - ENODATA ;
2014-02-05 02:13:52 +04: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 02:05:13 +03:00
addr - > s_addr = lease - > subnet_mask ;
2014-02-05 02:13:52 +04:00
return 0 ;
}
2014-03-03 19:46:10 +04:00
int sd_dhcp_lease_get_server_identifier ( sd_dhcp_lease * lease , struct in_addr * addr ) {
assert_return ( lease , - EINVAL ) ;
assert_return ( addr , - EINVAL ) ;
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 02:05:13 +03:00
if ( lease - > server_address = = 0 )
return - ENODATA ;
2014-03-03 19:46:10 +04: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 02:05:13 +03:00
addr - > s_addr = lease - > server_address ;
2014-03-03 19:46:10 +04:00
return 0 ;
}
2014-03-03 20:13:59 +04:00
int sd_dhcp_lease_get_next_server ( sd_dhcp_lease * lease , struct in_addr * addr ) {
assert_return ( lease , - EINVAL ) ;
assert_return ( addr , - EINVAL ) ;
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 02:05:13 +03:00
if ( lease - > next_server = = 0 )
return - ENODATA ;
2014-03-03 20:13:59 +04: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 02:05:13 +03:00
addr - > s_addr = lease - > next_server ;
2014-03-03 20:13:59 +04:00
return 0 ;
}
2016-01-20 16:44:14 +03:00
/*
* The returned routes array must be freed by the caller .
* Route objects have the same lifetime of the lease and must not be freed .
*/
int sd_dhcp_lease_get_routes ( sd_dhcp_lease * lease , sd_dhcp_route * * * routes ) {
sd_dhcp_route * * ret ;
unsigned i ;
2014-06-28 02:00:06 +04:00
assert_return ( lease , - EINVAL ) ;
assert_return ( routes , - EINVAL ) ;
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 02:05:13 +03:00
if ( lease - > static_route_size < = 0 )
return - ENODATA ;
2014-06-28 02:00:06 +04:00
2016-01-20 16:44:14 +03:00
ret = new ( sd_dhcp_route * , lease - > static_route_size ) ;
if ( ! ret )
return - ENOMEM ;
for ( i = 0 ; i < lease - > static_route_size ; i + + )
ret [ i ] = & lease - > static_route [ i ] ;
* routes = 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 02:05:13 +03:00
return ( int ) lease - > static_route_size ;
2014-06-28 02:00:06 +04:00
}
2017-05-13 17:19:32 +03:00
int sd_dhcp_lease_get_search_domains ( sd_dhcp_lease * lease , char * * * domains ) {
unsigned r ;
assert_return ( lease , - EINVAL ) ;
assert_return ( domains , - EINVAL ) ;
r = strv_length ( lease - > search_domains ) ;
if ( r > 0 ) {
* domains = lease - > search_domains ;
return ( int ) r ;
}
return - ENODATA ;
}
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 02:05:13 +03:00
int sd_dhcp_lease_get_vendor_specific ( sd_dhcp_lease * lease , const void * * data , size_t * data_len ) {
2015-07-09 19:04:01 +03:00
assert_return ( lease , - EINVAL ) ;
assert_return ( data , - EINVAL ) ;
assert_return ( data_len , - EINVAL ) ;
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 02:05:13 +03:00
if ( lease - > vendor_specific_len < = 0 )
return - ENODATA ;
2015-07-09 19:04:01 +03:00
* data = lease - > vendor_specific ;
* data_len = lease - > vendor_specific_len ;
return 0 ;
}
2014-02-05 02:13:52 +04:00
sd_dhcp_lease * sd_dhcp_lease_ref ( sd_dhcp_lease * lease ) {
2015-08-26 22:05:53 +03:00
if ( ! lease )
return NULL ;
assert ( lease - > n_ref > = 1 ) ;
lease - > n_ref + + ;
2014-02-05 02:13:52 +04:00
return lease ;
}
sd_dhcp_lease * sd_dhcp_lease_unref ( sd_dhcp_lease * lease ) {
2015-08-01 06:02:22 +03:00
2015-08-26 22:05:53 +03:00
if ( ! lease )
return NULL ;
2015-08-01 06:02:22 +03:00
2015-08-26 22:05:53 +03:00
assert ( lease - > n_ref > = 1 ) ;
lease - > n_ref - - ;
if ( lease - > n_ref > 0 )
return NULL ;
while ( lease - > private_options ) {
struct sd_dhcp_raw_option * option = lease - > private_options ;
LIST_REMOVE ( options , lease - > private_options , option ) ;
free ( option - > data ) ;
free ( option ) ;
2014-02-05 02:13:52 +04:00
}
2015-08-26 22:05:53 +03:00
free ( lease - > hostname ) ;
free ( lease - > domainname ) ;
free ( lease - > dns ) ;
free ( lease - > ntp ) ;
free ( lease - > static_route ) ;
free ( lease - > client_id ) ;
free ( lease - > vendor_specific ) ;
2017-05-13 17:19:32 +03:00
strv_free ( lease - > search_domains ) ;
2016-10-17 01:28:30 +03:00
return mfree ( lease ) ;
2014-02-05 02:13:52 +04: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 02:05:13 +03:00
static int lease_parse_u32 ( const uint8_t * option , size_t len , uint32_t * ret , uint32_t min ) {
2014-05-20 18:40:59 +04:00
assert ( option ) ;
assert ( 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 02:05:13 +03:00
if ( len ! = 4 )
return - EINVAL ;
2014-05-20 18:40:59 +04: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 02:05:13 +03:00
* ret = unaligned_read_be32 ( ( be32_t * ) option ) ;
if ( * ret < min )
* ret = min ;
2014-05-20 18:40:59 +04: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 02:05:13 +03:00
return 0 ;
2014-05-20 18:40:59 +04: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 02:05:13 +03:00
static int lease_parse_u16 ( const uint8_t * option , size_t len , uint16_t * ret , uint16_t min ) {
2014-05-20 18:40:59 +04:00
assert ( option ) ;
assert ( 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 02:05:13 +03:00
if ( len ! = 2 )
return - EINVAL ;
2014-05-20 18:40:59 +04: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 02:05:13 +03:00
* ret = unaligned_read_be16 ( ( be16_t * ) option ) ;
if ( * ret < min )
* ret = min ;
2014-05-21 00:02:49 +04: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 02:05:13 +03:00
return 0 ;
2014-05-21 00:02:49 +04: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 02:05:13 +03:00
static int lease_parse_be32 ( const uint8_t * option , size_t len , be32_t * ret ) {
2014-05-21 00:02:49 +04:00
assert ( option ) ;
assert ( 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 02:05:13 +03:00
if ( len ! = 4 )
return - EINVAL ;
2014-05-21 00:02:49 +04: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 02:05:13 +03:00
memcpy ( ret , option , 4 ) ;
return 0 ;
2014-05-21 00:02:49 +04:00
}
2014-05-20 18:40:59 +04:00
static int lease_parse_string ( const uint8_t * option , size_t len , char * * ret ) {
assert ( option ) ;
assert ( 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 02:05:13 +03:00
if ( len < = 0 )
* ret = mfree ( * ret ) ;
else {
2014-05-20 18:40:59 +04:00
char * string ;
2015-10-01 00:35:18 +03:00
/*
* One trailing NUL byte is OK , we don ' t mind . See :
* https : //github.com/systemd/systemd/issues/1337
*/
if ( memchr ( option , 0 , len - 1 ) )
2015-08-26 20:18:11 +03:00
return - EINVAL ;
2015-10-01 00:35:18 +03:00
string = strndup ( ( const char * ) option , len ) ;
2014-05-20 18:40:59 +04:00
if ( ! string )
2015-08-26 20:18:11 +03:00
return - ENOMEM ;
2014-05-20 18:40:59 +04:00
free ( * ret ) ;
* ret = string ;
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 02:05:13 +03:00
}
2014-05-20 18:40:59 +04:00
return 0 ;
}
2016-01-25 22:48:07 +03:00
static int lease_parse_domain ( const uint8_t * option , size_t len , char * * ret ) {
_cleanup_free_ char * name = NULL , * normalized = NULL ;
int r ;
assert ( option ) ;
assert ( ret ) ;
r = lease_parse_string ( option , len , & name ) ;
if ( r < 0 )
return r ;
if ( ! name ) {
* ret = mfree ( * ret ) ;
return 0 ;
}
r = dns_name_normalize ( name , & normalized ) ;
if ( r < 0 )
return r ;
if ( is_localhost ( normalized ) )
return - EINVAL ;
if ( dns_name_is_root ( normalized ) )
return - EINVAL ;
2017-11-24 13:33:41 +03:00
free_and_replace ( * ret , normalized ) ;
2016-01-25 22:48:07 +03:00
return 0 ;
}
2016-11-18 19:19:44 +03:00
static void filter_bogus_addresses ( struct in_addr * addresses , size_t * n ) {
size_t i , j ;
/* Silently filter DNS/NTP servers supplied to us that do not make outside of the local scope. */
for ( i = 0 , j = 0 ; i < * n ; i + + ) {
if ( in4_addr_is_null ( addresses + i ) | |
in4_addr_is_localhost ( addresses + i ) )
continue ;
addresses [ j + + ] = addresses [ i ] ;
}
* n = j ;
}
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 02:05:13 +03:00
static int lease_parse_in_addrs ( const uint8_t * option , size_t len , struct in_addr * * ret , size_t * n_ret ) {
2014-05-20 18:40:59 +04:00
assert ( option ) ;
assert ( 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 02:05:13 +03:00
assert ( n_ret ) ;
2014-05-20 18:40:59 +04: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 02:05:13 +03:00
if ( len < = 0 ) {
* ret = mfree ( * ret ) ;
* n_ret = 0 ;
} else {
size_t n_addresses ;
2014-05-20 18:40:59 +04:00
struct in_addr * addresses ;
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 02:05:13 +03:00
if ( len % 4 ! = 0 )
return - EINVAL ;
2014-05-20 18:40:59 +04: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 02:05:13 +03:00
n_addresses = len / 4 ;
addresses = newdup ( struct in_addr , option , n_addresses ) ;
2014-05-20 18:40:59 +04:00
if ( ! addresses )
return - ENOMEM ;
2016-11-18 19:19:44 +03:00
filter_bogus_addresses ( addresses , & n_addresses ) ;
2014-05-20 18:40:59 +04:00
free ( * ret ) ;
* ret = addresses ;
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 02:05:13 +03:00
* n_ret = n_addresses ;
2014-05-20 18:40:59 +04:00
}
return 0 ;
}
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 02:05:13 +03:00
static int lease_parse_routes (
const uint8_t * option , size_t len ,
struct sd_dhcp_route * * routes , size_t * routes_size , size_t * routes_allocated ) {
2014-06-28 02:00:06 +04:00
struct in_addr addr ;
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 02:05:13 +03:00
assert ( option | | len < = 0 ) ;
2014-06-28 02:00:06 +04:00
assert ( routes ) ;
assert ( routes_size ) ;
assert ( routes_allocated ) ;
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 02:05:13 +03:00
if ( len < = 0 )
2014-06-28 02:00:06 +04:00
return 0 ;
if ( len % 8 ! = 0 )
return - EINVAL ;
if ( ! GREEDY_REALLOC ( * routes , * routes_allocated , * routes_size + ( len / 8 ) ) )
return - ENOMEM ;
while ( len > = 8 ) {
struct sd_dhcp_route * route = * routes + * routes_size ;
2014-11-01 21:02:44 +03:00
int r ;
2014-06-28 02:00:06 +04:00
2018-01-20 02:42:45 +03:00
route - > option = SD_DHCP_OPTION_STATIC_ROUTE ;
2017-09-01 15:40:02 +03:00
r = in4_addr_default_prefixlen ( ( struct in_addr * ) option , & route - > dst_prefixlen ) ;
2014-11-01 21:02:44 +03:00
if ( r < 0 ) {
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 02:05:13 +03:00
log_debug ( " Failed to determine destination prefix length from class based IP, ignoring " ) ;
2014-06-28 02:00:06 +04:00
continue ;
}
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 02:05:13 +03:00
assert_se ( lease_parse_be32 ( option , 4 , & addr . s_addr ) > = 0 ) ;
2014-06-28 02:00:06 +04:00
route - > dst_addr = inet_makeaddr ( inet_netof ( addr ) , 0 ) ;
option + = 4 ;
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 02:05:13 +03:00
assert_se ( lease_parse_be32 ( option , 4 , & route - > gw_addr . s_addr ) > = 0 ) ;
2014-06-28 02:00:06 +04:00
option + = 4 ;
len - = 8 ;
( * routes_size ) + + ;
}
return 0 ;
}
/* parses RFC3442 Classless Static Route Option */
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 02:05:13 +03:00
static int lease_parse_classless_routes (
const uint8_t * option , size_t len ,
struct sd_dhcp_route * * routes , size_t * routes_size , size_t * routes_allocated ) {
2014-06-28 02:00:06 +04: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 02:05:13 +03:00
assert ( option | | len < = 0 ) ;
2014-06-28 02:00:06 +04:00
assert ( routes ) ;
assert ( routes_size ) ;
assert ( routes_allocated ) ;
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 02:05:13 +03:00
if ( len < = 0 )
return 0 ;
2014-06-28 02:00:06 +04:00
/* option format: (subnet-mask-width significant-subnet-octets gateway-ip)* */
while ( len > 0 ) {
uint8_t dst_octets ;
struct sd_dhcp_route * route ;
if ( ! GREEDY_REALLOC ( * routes , * routes_allocated , * routes_size + 1 ) )
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 02:05:13 +03:00
return - ENOMEM ;
2014-06-28 02:00:06 +04:00
route = * routes + * routes_size ;
2018-01-20 02:42:45 +03:00
route - > option = SD_DHCP_OPTION_CLASSLESS_STATIC_ROUTE ;
2014-06-28 02:00:06 +04:00
dst_octets = ( * option = = 0 ? 0 : ( ( * option - 1 ) / 8 ) + 1 ) ;
route - > dst_prefixlen = * option ;
option + + ;
len - - ;
/* can't have more than 4 octets in IPv4 */
if ( dst_octets > 4 | | len < dst_octets )
return - EINVAL ;
route - > dst_addr . s_addr = 0 ;
memcpy ( & route - > dst_addr . s_addr , option , dst_octets ) ;
option + = dst_octets ;
len - = dst_octets ;
if ( len < 4 )
return - EINVAL ;
2016-01-20 03:45:58 +03:00
assert_se ( lease_parse_be32 ( option , 4 , & route - > gw_addr . s_addr ) > = 0 ) ;
2014-06-28 02:00:06 +04:00
option + = 4 ;
len - = 4 ;
( * routes_size ) + + ;
}
return 0 ;
}
2015-08-27 00:05:34 +03:00
int dhcp_lease_parse_options ( uint8_t code , uint8_t len , const void * option , void * userdata ) {
2015-08-26 21:11:35 +03:00
sd_dhcp_lease * lease = userdata ;
2014-05-20 18:40:59 +04:00
int r ;
assert ( lease ) ;
2014-02-05 02:13:52 +04:00
switch ( code ) {
2016-01-20 16:44:24 +03:00
case SD_DHCP_OPTION_IP_ADDRESS_LEASE_TIME :
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 02:05:13 +03:00
r = lease_parse_u32 ( option , len , & lease - > lifetime , 1 ) ;
if ( r < 0 )
log_debug_errno ( r , " Failed to parse lease time, ignoring: %m " ) ;
2014-02-05 02:13:52 +04:00
break ;
2016-01-20 16:44:24 +03:00
case SD_DHCP_OPTION_SERVER_IDENTIFIER :
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 02:05:13 +03:00
r = lease_parse_be32 ( option , len , & lease - > server_address ) ;
if ( r < 0 )
log_debug_errno ( r , " Failed to parse server identifier, ignoring: %m " ) ;
2014-02-05 02:13:52 +04:00
break ;
2016-01-20 16:44:24 +03:00
case SD_DHCP_OPTION_SUBNET_MASK :
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 02:05:13 +03:00
r = lease_parse_be32 ( option , len , & lease - > subnet_mask ) ;
if ( r < 0 )
log_debug_errno ( r , " Failed to parse subnet mask, ignoring: %m " ) ;
else
lease - > have_subnet_mask = true ;
2014-02-05 02:13:52 +04:00
break ;
2016-01-20 16:44:24 +03:00
case SD_DHCP_OPTION_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 02:05:13 +03:00
r = lease_parse_be32 ( option , len , & lease - > broadcast ) ;
if ( r < 0 )
log_debug_errno ( r , " Failed to parse broadcast address, ignoring: %m " ) ;
else
lease - > have_broadcast = true ;
2014-05-21 00:02:49 +04:00
break ;
2016-01-20 16:44:24 +03:00
case SD_DHCP_OPTION_ROUTER :
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 02:05:13 +03:00
if ( len > = 4 ) {
r = lease_parse_be32 ( option , 4 , & lease - > router ) ;
if ( r < 0 )
log_debug_errno ( r , " Failed to parse router address, ignoring: %m " ) ;
}
2014-02-05 02:13:52 +04:00
break ;
2016-01-20 16:44:24 +03:00
case SD_DHCP_OPTION_DOMAIN_NAME_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 02:05:13 +03:00
r = lease_parse_in_addrs ( option , len , & lease - > dns , & lease - > dns_size ) ;
if ( r < 0 )
log_debug_errno ( r , " Failed to parse DNS server, ignoring: %m " ) ;
2014-02-05 02:13:52 +04:00
break ;
2016-01-20 16:44:24 +03:00
case SD_DHCP_OPTION_NTP_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 02:05:13 +03:00
r = lease_parse_in_addrs ( option , len , & lease - > ntp , & lease - > ntp_size ) ;
if ( r < 0 )
log_debug_errno ( r , " Failed to parse NTP server, ignoring: %m " ) ;
2014-05-21 00:02:49 +04:00
break ;
2016-01-20 16:44:24 +03:00
case SD_DHCP_OPTION_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 02:05:13 +03:00
r = lease_parse_routes ( option , len , & lease - > static_route , & lease - > static_route_size , & lease - > static_route_allocated ) ;
if ( r < 0 )
log_debug_errno ( r , " Failed to parse static routes, ignoring: %m " ) ;
2014-05-21 00:02:49 +04:00
break ;
2016-01-20 16:44:24 +03:00
case SD_DHCP_OPTION_INTERFACE_MTU :
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 02:05:13 +03:00
r = lease_parse_u16 ( option , len , & lease - > mtu , 68 ) ;
if ( r < 0 )
log_debug_errno ( r , " Failed to parse MTU, ignoring: %m " ) ;
2017-05-22 04:11:25 +03:00
if ( lease - > mtu < DHCP_DEFAULT_MIN_SIZE ) {
2017-05-22 15:38:01 +03:00
log_debug ( " MTU value of % " PRIu16 " too small. Using default MTU value of %d instead. " , lease - > mtu , DHCP_DEFAULT_MIN_SIZE ) ;
2017-05-22 04:11:25 +03:00
lease - > mtu = DHCP_DEFAULT_MIN_SIZE ;
}
2014-05-21 00:02:49 +04:00
break ;
2016-01-25 22:48:07 +03:00
case SD_DHCP_OPTION_DOMAIN_NAME :
r = lease_parse_domain ( option , len , & lease - > domainname ) ;
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 02:05:13 +03:00
if ( r < 0 ) {
log_debug_errno ( r , " Failed to parse domain name, ignoring: %m " ) ;
return 0 ;
}
2014-02-05 02:13:52 +04:00
2014-08-15 03:04:53 +04:00
break ;
2017-05-13 17:19:32 +03:00
case SD_DHCP_OPTION_DOMAIN_SEARCH_LIST :
r = dhcp_lease_parse_search_domains ( option , len , & lease - > search_domains ) ;
if ( r < 0 )
log_debug_errno ( r , " Failed to parse Domain Search List, ignoring: %m " ) ;
break ;
2016-01-25 22:48:07 +03:00
case SD_DHCP_OPTION_HOST_NAME :
r = lease_parse_domain ( option , len , & lease - > hostname ) ;
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 02:05:13 +03:00
if ( r < 0 ) {
log_debug_errno ( r , " Failed to parse host name, ignoring: %m " ) ;
return 0 ;
}
2014-02-05 02:13:52 +04:00
2014-08-15 03:04:53 +04:00
break ;
2014-03-03 18:43:02 +04:00
2016-01-20 16:44:24 +03:00
case SD_DHCP_OPTION_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 02:05:13 +03:00
r = lease_parse_string ( option , len , & lease - > root_path ) ;
if ( r < 0 )
log_debug_errno ( r , " Failed to parse root path, ignoring: %m " ) ;
break ;
2014-03-03 18:43:02 +04:00
2016-01-20 16:44:24 +03:00
case SD_DHCP_OPTION_RENEWAL_T1_TIME :
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 02:05:13 +03:00
r = lease_parse_u32 ( option , len , & lease - > t1 , 1 ) ;
if ( r < 0 )
log_debug_errno ( r , " Failed to parse T1 time, ignoring: %m " ) ;
2014-02-05 02:13:52 +04:00
break ;
2016-01-20 16:44:24 +03:00
case SD_DHCP_OPTION_REBINDING_T2_TIME :
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 02:05:13 +03:00
r = lease_parse_u32 ( option , len , & lease - > t2 , 1 ) ;
if ( r < 0 )
log_debug_errno ( r , " Failed to parse T2 time, ignoring: %m " ) ;
2014-02-05 02:13:52 +04:00
break ;
2014-06-28 02:00:06 +04:00
2016-01-20 16:44:24 +03:00
case SD_DHCP_OPTION_CLASSLESS_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 02:05:13 +03:00
r = lease_parse_classless_routes (
2015-08-26 21:11:35 +03:00
option , len ,
& lease - > static_route ,
& lease - > static_route_size ,
& lease - > static_route_allocated ) ;
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 02:05:13 +03:00
if ( r < 0 )
log_debug_errno ( r , " Failed to parse classless routes, ignoring: %m " ) ;
break ;
2015-07-09 19:04:01 +03:00
2016-01-20 16:44:24 +03:00
case SD_DHCP_OPTION_NEW_TZDB_TIMEZONE : {
2015-08-26 20:19:32 +03:00
_cleanup_free_ char * tz = NULL ;
r = lease_parse_string ( option , len , & tz ) ;
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 02:05:13 +03:00
if ( r < 0 ) {
log_debug_errno ( r , " Failed to parse timezone option, ignoring: %m " ) ;
return 0 ;
}
2015-08-26 20:19:32 +03: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 02:05:13 +03:00
if ( ! timezone_is_valid ( tz ) ) {
log_debug_errno ( r , " Timezone is not valid, ignoring: %m " ) ;
return 0 ;
}
2015-08-26 20:19:32 +03:00
2017-11-24 13:33:41 +03:00
free_and_replace ( lease - > timezone , tz ) ;
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 02:05:13 +03:00
2015-08-26 20:19:32 +03:00
break ;
}
2016-01-20 16:44:24 +03:00
case SD_DHCP_OPTION_VENDOR_SPECIFIC :
2015-08-26 21:11:35 +03: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 02:05:13 +03:00
if ( len < = 0 )
lease - > vendor_specific = mfree ( lease - > vendor_specific ) ;
else {
void * p ;
p = memdup ( option , len ) ;
if ( ! p )
2015-07-09 19:04:01 +03:00
return - ENOMEM ;
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 02:05:13 +03:00
free ( lease - > vendor_specific ) ;
lease - > vendor_specific = p ;
}
2015-08-01 06:02:22 +03: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 02:05:13 +03:00
lease - > vendor_specific_len = len ;
break ;
2015-08-01 06:02:22 +03:00
2016-01-20 16:44:24 +03:00
case SD_DHCP_OPTION_PRIVATE_BASE . . . SD_DHCP_OPTION_PRIVATE_LAST :
2015-08-01 06:02:22 +03:00
r = dhcp_lease_insert_private_option ( lease , code , option , len ) ;
if ( r < 0 )
return r ;
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 02:05:13 +03:00
break ;
default :
2015-11-25 19:29:30 +03:00
log_debug ( " Ignoring option DHCP option % " PRIu8 " while parsing. " , code ) ;
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 02:05:13 +03:00
break ;
2014-02-05 02:13:52 +04:00
}
return 0 ;
}
2017-05-13 17:19:32 +03:00
/* Parses compressed domain names. */
int dhcp_lease_parse_search_domains ( const uint8_t * option , size_t len , char * * * domains ) {
_cleanup_strv_free_ char * * names = NULL ;
size_t pos = 0 , cnt = 0 ;
int r ;
assert ( domains ) ;
assert_return ( option & & len > 0 , - ENODATA ) ;
while ( pos < len ) {
_cleanup_free_ char * name = NULL ;
size_t n = 0 , allocated = 0 ;
size_t jump_barrier = pos , next_chunk = 0 ;
bool first = true ;
for ( ; ; ) {
uint8_t c ;
c = option [ pos + + ] ;
if ( c = = 0 ) {
/* End of name */
break ;
} else if ( c < = 63 ) {
const char * label ;
/* Literal label */
label = ( const char * ) ( option + pos ) ;
pos + = c ;
if ( pos > = len )
return - EBADMSG ;
if ( ! GREEDY_REALLOC ( name , allocated , n + ! first + DNS_LABEL_ESCAPED_MAX ) )
return - ENOMEM ;
if ( first )
first = false ;
else
name [ n + + ] = ' . ' ;
r = dns_label_escape ( label , c , name + n , DNS_LABEL_ESCAPED_MAX ) ;
if ( r < 0 )
return r ;
n + = r ;
} else if ( ( c & 0xc0 ) = = 0xc0 ) {
/* Pointer */
uint8_t d ;
uint16_t ptr ;
if ( pos > = len )
return - EBADMSG ;
d = option [ pos + + ] ;
ptr = ( uint16_t ) ( c & ~ 0xc0 ) < < 8 | ( uint16_t ) d ;
/* Jumps are limited to a "prior occurrence" (RFC-1035 4.1.4) */
if ( ptr > = jump_barrier )
return - EBADMSG ;
jump_barrier = ptr ;
/* Save current location so we don't end up re-parsing what's parsed so far. */
if ( next_chunk = = 0 )
next_chunk = pos ;
pos = ptr ;
} else
return - EBADMSG ;
}
if ( ! GREEDY_REALLOC ( name , allocated , n + 1 ) )
return - ENOMEM ;
name [ n ] = 0 ;
r = strv_extend ( & names , name ) ;
if ( r < 0 )
return r ;
cnt + + ;
if ( next_chunk ! = 0 )
pos = next_chunk ;
}
2018-03-22 18:53:26 +03:00
* domains = TAKE_PTR ( names ) ;
2017-05-13 17:19:32 +03:00
return cnt ;
}
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 02:05:13 +03:00
int dhcp_lease_insert_private_option ( sd_dhcp_lease * lease , uint8_t tag , const void * data , uint8_t len ) {
2015-08-01 06:02:22 +03:00
struct sd_dhcp_raw_option * cur , * option ;
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 02:05:13 +03:00
assert ( lease ) ;
2015-08-01 06:02:22 +03:00
LIST_FOREACH ( options , cur , lease - > private_options ) {
if ( tag < cur - > tag )
break ;
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 02:05:13 +03:00
if ( tag = = cur - > tag ) {
log_debug ( " Ignoring duplicate option, tagged %i. " , tag ) ;
2015-08-01 06:02:22 +03:00
return 0 ;
}
}
option = new ( struct sd_dhcp_raw_option , 1 ) ;
if ( ! option )
return - ENOMEM ;
option - > tag = tag ;
option - > length = len ;
option - > data = memdup ( data , len ) ;
if ( ! option - > data ) {
free ( option ) ;
return - ENOMEM ;
}
LIST_INSERT_BEFORE ( options , lease - > private_options , cur , option ) ;
return 0 ;
}
2014-02-05 02:13:52 +04:00
int dhcp_lease_new ( sd_dhcp_lease * * ret ) {
2014-04-11 07:45:46 +04:00
sd_dhcp_lease * lease ;
2014-02-05 02:13:52 +04:00
lease = new0 ( sd_dhcp_lease , 1 ) ;
if ( ! lease )
return - ENOMEM ;
2014-04-30 00:40:38 +04:00
lease - > router = INADDR_ANY ;
2015-08-26 22:05:53 +03:00
lease - > n_ref = 1 ;
2014-02-05 02:13:52 +04:00
* ret = lease ;
return 0 ;
}
2014-02-27 04:24:05 +04:00
2015-08-26 21:48:21 +03:00
int dhcp_lease_save ( sd_dhcp_lease * lease , const char * lease_file ) {
2014-02-27 04:24:05 +04:00
_cleanup_free_ char * temp_path = NULL ;
_cleanup_fclose_ FILE * f = NULL ;
2015-08-01 06:18:51 +03:00
struct sd_dhcp_raw_option * option ;
2014-02-27 04:24:05 +04:00
struct in_addr address ;
2014-07-17 03:39:46 +04:00
const struct in_addr * addresses ;
2015-08-27 00:05:34 +03:00
const void * client_id , * data ;
2015-07-09 19:04:01 +03:00
size_t client_id_len , data_len ;
2014-02-27 04:24:05 +04:00
const char * string ;
uint16_t mtu ;
2016-01-20 16:44:14 +03:00
_cleanup_free_ sd_dhcp_route * * routes = NULL ;
2017-05-13 17:19:32 +03:00
char * * search_domains = NULL ;
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 02:05:13 +03:00
uint32_t t1 , t2 , lifetime ;
2014-02-27 04:24:05 +04:00
int r ;
assert ( lease ) ;
assert ( lease_file ) ;
r = fopen_temporary ( lease_file , & f , & temp_path ) ;
if ( r < 0 )
2015-07-29 21:31:07 +03:00
goto fail ;
2014-02-27 04:24:05 +04:00
2017-12-11 21:50:30 +03:00
( void ) __fsetlocking ( f , FSETLOCKING_BYCALLER ) ;
( void ) fchmod ( fileno ( f ) , 0644 ) ;
2014-02-27 04:24:05 +04:00
fprintf ( f ,
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 02:05:13 +03:00
" # This is private data. Do not parse. \n " ) ;
2014-02-27 04:24:05 +04: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 02:05:13 +03:00
r = sd_dhcp_lease_get_address ( lease , & address ) ;
if ( r > = 0 )
fprintf ( f , " ADDRESS=%s \n " , inet_ntoa ( address ) ) ;
2014-02-27 04:24:05 +04: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 02:05:13 +03:00
r = sd_dhcp_lease_get_netmask ( lease , & address ) ;
if ( r > = 0 )
fprintf ( f , " NETMASK=%s \n " , inet_ntoa ( address ) ) ;
2014-02-27 04:24:05 +04:00
2014-04-30 00:40:38 +04:00
r = sd_dhcp_lease_get_router ( lease , & address ) ;
if ( r > = 0 )
fprintf ( f , " ROUTER=%s \n " , inet_ntoa ( address ) ) ;
2014-03-03 19:46:10 +04:00
r = sd_dhcp_lease_get_server_identifier ( lease , & address ) ;
2014-04-29 15:29:12 +04:00
if ( r > = 0 )
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 02:05:13 +03:00
fprintf ( f , " SERVER_ADDRESS=%s \n " , inet_ntoa ( address ) ) ;
2014-03-03 19:46:10 +04:00
2014-03-03 20:13:59 +04:00
r = sd_dhcp_lease_get_next_server ( lease , & address ) ;
2014-04-29 15:29:12 +04:00
if ( r > = 0 )
fprintf ( f , " NEXT_SERVER=%s \n " , inet_ntoa ( address ) ) ;
2014-03-03 20:13:59 +04: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 02:05:13 +03:00
r = sd_dhcp_lease_get_broadcast ( lease , & address ) ;
if ( r > = 0 )
fprintf ( f , " BROADCAST=%s \n " , inet_ntoa ( address ) ) ;
2014-02-27 04:24:05 +04:00
r = sd_dhcp_lease_get_mtu ( lease , & mtu ) ;
if ( r > = 0 )
fprintf ( f , " MTU=% " PRIu16 " \n " , mtu ) ;
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 02:05:13 +03:00
r = sd_dhcp_lease_get_t1 ( lease , & t1 ) ;
if ( r > = 0 )
fprintf ( f , " T1=% " PRIu32 " \n " , t1 ) ;
r = sd_dhcp_lease_get_t2 ( lease , & t2 ) ;
2014-04-29 15:29:12 +04:00
if ( r > = 0 )
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 02:05:13 +03:00
fprintf ( f , " T2=% " PRIu32 " \n " , t2 ) ;
r = sd_dhcp_lease_get_lifetime ( lease , & lifetime ) ;
if ( r > = 0 )
fprintf ( f , " LIFETIME=% " PRIu32 " \n " , lifetime ) ;
r = sd_dhcp_lease_get_dns ( lease , & addresses ) ;
if ( r > 0 ) {
2017-12-11 21:50:30 +03:00
fputs ( " DNS= " , f ) ;
2014-07-23 15:48:18 +04:00
serialize_in_addrs ( f , addresses , r ) ;
2017-12-11 21:50:30 +03:00
fputs ( " \n " , f ) ;
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 02:05:13 +03:00
}
2014-04-29 15:29:12 +04:00
2014-07-17 03:39:46 +04:00
r = sd_dhcp_lease_get_ntp ( lease , & addresses ) ;
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 02:05:13 +03:00
if ( r > 0 ) {
2017-12-11 21:50:30 +03:00
fputs ( " NTP= " , f ) ;
2014-07-23 15:48:18 +04:00
serialize_in_addrs ( f , addresses , r ) ;
2017-12-11 21:50:30 +03:00
fputs ( " \n " , f ) ;
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 02:05:13 +03:00
}
2014-02-27 04:24:05 +04:00
r = sd_dhcp_lease_get_domainname ( lease , & string ) ;
if ( r > = 0 )
fprintf ( f , " DOMAINNAME=%s \n " , string ) ;
2017-05-13 17:19:32 +03:00
r = sd_dhcp_lease_get_search_domains ( lease , & search_domains ) ;
if ( r > 0 ) {
2017-12-11 21:50:30 +03:00
fputs ( " DOMAIN_SEARCH_LIST= " , f ) ;
2017-05-13 17:19:32 +03:00
fputstrv ( f , search_domains , NULL , NULL ) ;
2017-12-11 21:50:30 +03:00
fputs ( " \n " , f ) ;
2017-05-13 17:19:32 +03:00
}
2014-02-27 04:24:05 +04:00
r = sd_dhcp_lease_get_hostname ( lease , & string ) ;
if ( r > = 0 )
fprintf ( f , " HOSTNAME=%s \n " , string ) ;
2014-03-03 18:43:02 +04:00
r = sd_dhcp_lease_get_root_path ( lease , & string ) ;
if ( r > = 0 )
fprintf ( f , " ROOT_PATH=%s \n " , string ) ;
2014-07-17 03:39:46 +04:00
r = sd_dhcp_lease_get_routes ( lease , & routes ) ;
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 02:05:13 +03:00
if ( r > 0 )
2014-07-17 03:39:46 +04:00
serialize_dhcp_routes ( f , " ROUTES " , routes , r ) ;
2014-06-28 02:00:06 +04:00
2015-08-26 20:19:32 +03:00
r = sd_dhcp_lease_get_timezone ( lease , & string ) ;
if ( r > = 0 )
fprintf ( f , " TIMEZONE=%s \n " , string ) ;
2014-11-19 02:13:12 +03:00
r = sd_dhcp_lease_get_client_id ( lease , & client_id , & client_id_len ) ;
if ( r > = 0 ) {
2016-02-27 15:40:50 +03:00
_cleanup_free_ char * client_id_hex = NULL ;
2014-11-19 02:13:12 +03:00
2015-05-22 00:30:37 +03:00
client_id_hex = hexmem ( client_id , client_id_len ) ;
2014-11-19 02:13:12 +03:00
if ( ! client_id_hex ) {
r = - ENOMEM ;
2015-07-29 21:31:07 +03:00
goto fail ;
2014-11-19 02:13:12 +03:00
}
fprintf ( f , " CLIENTID=%s \n " , client_id_hex ) ;
}
2015-07-09 19:04:01 +03:00
r = sd_dhcp_lease_get_vendor_specific ( lease , & data , & data_len ) ;
if ( r > = 0 ) {
_cleanup_free_ char * option_hex = NULL ;
option_hex = hexmem ( data , data_len ) ;
if ( ! option_hex ) {
r = - ENOMEM ;
2015-07-29 21:31:07 +03:00
goto fail ;
2015-07-09 19:04:01 +03:00
}
fprintf ( f , " VENDOR_SPECIFIC=%s \n " , option_hex ) ;
}
2015-08-01 06:18:51 +03:00
LIST_FOREACH ( options , option , lease - > private_options ) {
2017-12-13 10:41:11 +03:00
char key [ STRLEN ( " OPTION_000 " ) + 1 ] ;
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 02:05:13 +03:00
2016-01-12 17:34:20 +03:00
xsprintf ( key , " OPTION_% " PRIu8 , option - > tag ) ;
2015-08-01 06:18:51 +03:00
r = serialize_dhcp_option ( f , key , option - > data , option - > length ) ;
if ( r < 0 )
goto fail ;
}
2015-07-29 21:31:07 +03:00
r = fflush_and_check ( f ) ;
if ( r < 0 )
goto fail ;
2014-02-27 04:24:05 +04:00
2015-07-29 21:31:07 +03:00
if ( rename ( temp_path , lease_file ) < 0 ) {
2014-02-27 04:24:05 +04:00
r = - errno ;
2015-07-29 21:31:07 +03:00
goto fail ;
2014-02-27 04:24:05 +04:00
}
2015-07-29 21:31:07 +03:00
return 0 ;
fail :
if ( temp_path )
( void ) unlink ( temp_path ) ;
2014-02-27 04:24:05 +04:00
2015-07-29 21:31:07 +03:00
return log_error_errno ( r , " Failed to save lease data %s: %m " , lease_file ) ;
2014-02-27 04:24:05 +04:00
}
2015-08-26 21:48:21 +03:00
int dhcp_lease_load ( sd_dhcp_lease * * ret , const char * lease_file ) {
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 02:05:13 +03:00
tree-wide: expose "p"-suffix unref calls in public APIs to make gcc cleanup easy
GLIB has recently started to officially support the gcc cleanup
attribute in its public API, hence let's do the same for our APIs.
With this patch we'll define an xyz_unrefp() call for each public
xyz_unref() call, to make it easy to use inside a
__attribute__((cleanup())) expression. Then, all code is ported over to
make use of this.
The new calls are also documented in the man pages, with examples how to
use them (well, I only added docs where the _unref() call itself already
had docs, and the examples, only cover sd_bus_unrefp() and
sd_event_unrefp()).
This also renames sd_lldp_free() to sd_lldp_unref(), since that's how we
tend to call our destructors these days.
Note that this defines no public macro that wraps gcc's attribute and
makes it easier to use. While I think it's our duty in the library to
make our stuff easy to use, I figure it's not our duty to make gcc's own
features easy to use on its own. Most likely, client code which wants to
make use of this should define its own:
#define _cleanup_(function) __attribute__((cleanup(function)))
Or similar, to make the gcc feature easier to use.
Making this logic public has the benefit that we can remove three header
files whose only purpose was to define these functions internally.
See #2008.
2015-11-27 21:13:45 +03:00
_cleanup_ ( sd_dhcp_lease_unrefp ) sd_dhcp_lease * lease = NULL ;
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 02:05:13 +03:00
_cleanup_free_ char
* address = NULL ,
* router = NULL ,
* netmask = NULL ,
* server_address = NULL ,
* next_server = NULL ,
* broadcast = NULL ,
* dns = NULL ,
* ntp = NULL ,
* mtu = NULL ,
* routes = NULL ,
2017-05-13 17:19:32 +03:00
* domains = NULL ,
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 02:05:13 +03:00
* client_id_hex = NULL ,
* vendor_specific_hex = NULL ,
* lifetime = NULL ,
* t1 = NULL ,
* t2 = NULL ,
2016-01-20 16:44:24 +03:00
* options [ SD_DHCP_OPTION_PRIVATE_LAST - SD_DHCP_OPTION_PRIVATE_BASE + 1 ] = { } ;
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 02:05:13 +03:00
2015-08-01 06:18:51 +03:00
int r , i ;
2014-02-27 04:24:05 +04:00
assert ( lease_file ) ;
assert ( ret ) ;
r = dhcp_lease_new ( & lease ) ;
if ( r < 0 )
return r ;
r = parse_env_file ( lease_file , NEWLINE ,
" ADDRESS " , & address ,
" ROUTER " , & router ,
" NETMASK " , & netmask ,
2014-03-03 19:46:10 +04:00
" SERVER_IDENTIFIER " , & server_address ,
2014-03-03 20:13:59 +04:00
" NEXT_SERVER " , & 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 02:05:13 +03:00
" BROADCAST " , & broadcast ,
2014-04-29 15:29:12 +04:00
" DNS " , & dns ,
" NTP " , & ntp ,
2014-02-27 04:24:05 +04:00
" MTU " , & mtu ,
" DOMAINNAME " , & lease - > domainname ,
" HOSTNAME " , & lease - > hostname ,
2017-05-13 17:19:32 +03:00
" DOMAIN_SEARCH_LIST " , & domains ,
2014-03-03 18:43:02 +04:00
" ROOT_PATH " , & lease - > root_path ,
2014-06-28 02:00:06 +04:00
" ROUTES " , & routes ,
2014-11-19 02:13:12 +03:00
" CLIENTID " , & client_id_hex ,
2015-08-26 20:19:32 +03:00
" TIMEZONE " , & lease - > timezone ,
2015-07-09 19:04:01 +03:00
" VENDOR_SPECIFIC " , & vendor_specific_hex ,
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 02:05:13 +03:00
" LIFETIME " , & lifetime ,
" T1 " , & t1 ,
" T2 " , & t2 ,
2015-08-01 06:18:51 +03:00
" OPTION_224 " , & options [ 0 ] ,
" OPTION_225 " , & options [ 1 ] ,
" OPTION_226 " , & options [ 2 ] ,
" OPTION_227 " , & options [ 3 ] ,
" OPTION_228 " , & options [ 4 ] ,
" OPTION_229 " , & options [ 5 ] ,
" OPTION_230 " , & options [ 6 ] ,
" OPTION_231 " , & options [ 7 ] ,
" OPTION_232 " , & options [ 8 ] ,
" OPTION_233 " , & options [ 9 ] ,
" OPTION_234 " , & options [ 10 ] ,
" OPTION_235 " , & options [ 11 ] ,
" OPTION_236 " , & options [ 12 ] ,
" OPTION_237 " , & options [ 13 ] ,
" OPTION_238 " , & options [ 14 ] ,
" OPTION_239 " , & options [ 15 ] ,
" OPTION_240 " , & options [ 16 ] ,
" OPTION_241 " , & options [ 17 ] ,
" OPTION_242 " , & options [ 18 ] ,
" OPTION_243 " , & options [ 19 ] ,
" OPTION_244 " , & options [ 20 ] ,
" OPTION_245 " , & options [ 21 ] ,
" OPTION_246 " , & options [ 22 ] ,
" OPTION_247 " , & options [ 23 ] ,
" OPTION_248 " , & options [ 24 ] ,
" OPTION_249 " , & options [ 25 ] ,
" OPTION_250 " , & options [ 26 ] ,
" OPTION_251 " , & options [ 27 ] ,
" OPTION_252 " , & options [ 28 ] ,
" OPTION_253 " , & options [ 29 ] ,
" OPTION_254 " , & options [ 30 ] ,
2014-02-27 04:24:05 +04:00
NULL ) ;
if ( r < 0 )
return r ;
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 02:05:13 +03:00
if ( address ) {
r = inet_pton ( AF_INET , address , & lease - > address ) ;
if ( r < = 0 )
2015-11-05 15:44:10 +03:00
log_debug ( " Failed to parse address %s, ignoring. " , address ) ;
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 02:05:13 +03:00
}
2014-02-27 04:24:05 +04:00
2014-04-30 00:40:38 +04:00
if ( router ) {
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 02:05:13 +03:00
r = inet_pton ( AF_INET , router , & lease - > router ) ;
if ( r < = 0 )
2015-11-05 15:44:10 +03:00
log_debug ( " Failed to parse router %s, ignoring. " , router ) ;
2014-04-30 00:40:38 +04:00
}
2014-02-27 04:24:05 +04: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 02:05:13 +03:00
if ( netmask ) {
r = inet_pton ( AF_INET , netmask , & lease - > subnet_mask ) ;
if ( r < = 0 )
2015-11-05 15:44:10 +03:00
log_debug ( " Failed to parse netmask %s, ignoring. " , netmask ) ;
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 02:05:13 +03:00
else
lease - > have_subnet_mask = true ;
}
2014-02-27 04:24:05 +04:00
2014-03-03 19:46:10 +04:00
if ( server_address ) {
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 02:05:13 +03:00
r = inet_pton ( AF_INET , server_address , & lease - > server_address ) ;
if ( r < = 0 )
2015-11-05 15:44:10 +03:00
log_debug ( " Failed to parse server address %s, ignoring. " , server_address ) ;
2014-03-03 19:46:10 +04:00
}
2014-03-03 20:13:59 +04:00
if ( 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 02:05:13 +03:00
r = inet_pton ( AF_INET , next_server , & lease - > next_server ) ;
if ( r < = 0 )
2015-11-05 15:44:10 +03:00
log_debug ( " Failed to parse next server %s, ignoring. " , 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 02:05:13 +03:00
}
2014-03-03 20:13:59 +04: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 02:05:13 +03:00
if ( broadcast ) {
r = inet_pton ( AF_INET , broadcast , & lease - > broadcast ) ;
if ( r < = 0 )
2015-11-05 15:44:10 +03:00
log_debug ( " Failed to parse broadcast address %s, ignoring. " , 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 02:05:13 +03:00
else
lease - > have_broadcast = true ;
2014-03-03 20:13:59 +04:00
}
2014-04-29 15:29:12 +04:00
if ( dns ) {
2014-07-17 03:39:46 +04:00
r = deserialize_in_addrs ( & lease - > dns , dns ) ;
2014-04-29 15:29:12 +04:00
if ( r < 0 )
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 02:05:13 +03:00
log_debug_errno ( r , " Failed to deserialize DNS servers %s, ignoring: %m " , dns ) ;
else
lease - > dns_size = r ;
2014-04-29 15:29:12 +04:00
}
if ( ntp ) {
2014-07-17 03:39:46 +04:00
r = deserialize_in_addrs ( & lease - > ntp , ntp ) ;
2014-04-29 15:29:12 +04:00
if ( r < 0 )
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 02:05:13 +03:00
log_debug_errno ( r , " Failed to deserialize NTP servers %s, ignoring: %m " , ntp ) ;
else
lease - > ntp_size = r ;
2014-04-29 15:29:12 +04:00
}
2014-02-27 04:24:05 +04:00
if ( mtu ) {
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 02:05:13 +03:00
r = safe_atou16 ( mtu , & lease - > mtu ) ;
if ( r < 0 )
log_debug_errno ( r , " Failed to parse MTU %s, ignoring: %m " , mtu ) ;
2014-02-27 04:24:05 +04:00
}
2017-05-13 17:19:32 +03:00
if ( domains ) {
_cleanup_strv_free_ char * * a = NULL ;
a = strv_split ( domains , " " ) ;
if ( ! a )
return - ENOMEM ;
if ( ! strv_isempty ( a ) ) {
lease - > search_domains = a ;
a = NULL ;
}
}
2014-06-28 02:00:06 +04:00
if ( routes ) {
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 02:05:13 +03:00
r = deserialize_dhcp_routes (
& lease - > static_route ,
& lease - > static_route_size ,
& lease - > static_route_allocated ,
routes ) ;
if ( r < 0 )
log_debug_errno ( r , " Failed to parse DHCP routes %s, ignoring: %m " , routes ) ;
}
if ( lifetime ) {
r = safe_atou32 ( lifetime , & lease - > lifetime ) ;
if ( r < 0 )
log_debug_errno ( r , " Failed to parse lifetime %s, ignoring: %m " , lifetime ) ;
}
if ( t1 ) {
r = safe_atou32 ( t1 , & lease - > t1 ) ;
if ( r < 0 )
log_debug_errno ( r , " Failed to parse T1 %s, ignoring: %m " , t1 ) ;
}
if ( t2 ) {
r = safe_atou32 ( t2 , & lease - > t2 ) ;
2014-06-28 02:00:06 +04:00
if ( r < 0 )
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 02:05:13 +03:00
log_debug_errno ( r , " Failed to parse T2 %s, ignoring: %m " , t2 ) ;
2014-06-28 02:00:06 +04:00
}
2014-11-19 02:13:12 +03:00
if ( client_id_hex ) {
2015-08-01 07:48:47 +03:00
r = deserialize_dhcp_option ( & lease - > client_id , & lease - > client_id_len , client_id_hex ) ;
2015-07-11 20:14:52 +03:00
if ( r < 0 )
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 02:05:13 +03:00
log_debug_errno ( r , " Failed to parse client ID %s, ignoring: %m " , client_id_hex ) ;
2014-11-19 02:13:12 +03:00
}
2015-07-09 19:04:01 +03:00
if ( vendor_specific_hex ) {
2015-08-01 07:48:47 +03:00
r = deserialize_dhcp_option ( & lease - > vendor_specific , & lease - > vendor_specific_len , vendor_specific_hex ) ;
2015-07-09 19:04:01 +03:00
if ( r < 0 )
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 02:05:13 +03:00
log_debug_errno ( r , " Failed to parse vendor specific data %s, ignoring: %m " , vendor_specific_hex ) ;
2015-07-09 19:04:01 +03:00
}
2016-01-20 16:44:24 +03:00
for ( i = 0 ; i < = SD_DHCP_OPTION_PRIVATE_LAST - SD_DHCP_OPTION_PRIVATE_BASE ; i + + ) {
2015-08-27 00:05:34 +03:00
_cleanup_free_ void * data = NULL ;
2015-08-01 06:18:51 +03:00
size_t len ;
if ( ! options [ i ] )
continue ;
r = deserialize_dhcp_option ( & data , & len , options [ i ] ) ;
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 02:05:13 +03:00
if ( r < 0 ) {
log_debug_errno ( r , " Failed to parse private DHCP option %s, ignoring: %m " , options [ i ] ) ;
continue ;
}
2015-08-01 06:18:51 +03:00
2016-01-20 16:44:24 +03:00
r = dhcp_lease_insert_private_option ( lease , SD_DHCP_OPTION_PRIVATE_BASE + i , data , len ) ;
2015-08-08 14:24:11 +03:00
if ( r < 0 )
2015-08-01 06:18:51 +03:00
return r ;
}
2018-04-05 08:26:26 +03:00
* ret = TAKE_PTR ( lease ) ;
2014-02-27 04:24:05 +04:00
return 0 ;
}
2014-03-19 19:05:44 +04:00
int dhcp_lease_set_default_subnet_mask ( sd_dhcp_lease * lease ) {
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 02:05:13 +03:00
struct in_addr address , mask ;
2014-10-27 19:38:03 +03:00
int r ;
2014-03-19 19:05:44 +04:00
assert ( lease ) ;
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 02:05:13 +03:00
if ( lease - > address = = 0 )
return - ENODATA ;
2014-10-27 19:38:03 +03:00
address . s_addr = lease - > address ;
2014-03-19 19:05:44 +04:00
/* fall back to the default subnet masks based on address class */
2017-09-01 15:40:02 +03:00
r = in4_addr_default_subnet_mask ( & address , & mask ) ;
2014-10-27 19:38:03 +03:00
if ( r < 0 )
return r ;
2014-03-19 19:05:44 +04:00
2014-10-27 19:38:03 +03:00
lease - > subnet_mask = mask . s_addr ;
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 02:05:13 +03:00
lease - > have_subnet_mask = true ;
2014-03-19 19:05:44 +04:00
return 0 ;
}
2014-11-19 02:13:12 +03: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 02:05:13 +03:00
int sd_dhcp_lease_get_client_id ( sd_dhcp_lease * lease , const void * * client_id , size_t * client_id_len ) {
2014-11-19 02:13:12 +03:00
assert_return ( lease , - EINVAL ) ;
assert_return ( client_id , - EINVAL ) ;
assert_return ( client_id_len , - EINVAL ) ;
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 02:05:13 +03:00
if ( ! lease - > client_id )
return - ENODATA ;
2014-11-19 02:13:12 +03:00
* client_id = lease - > client_id ;
* client_id_len = lease - > 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 02:05:13 +03:00
2014-11-19 02:13:12 +03:00
return 0 ;
}
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 02:05:13 +03:00
int dhcp_lease_set_client_id ( sd_dhcp_lease * lease , const void * client_id , size_t client_id_len ) {
2014-11-19 02:13:12 +03:00
assert_return ( lease , - EINVAL ) ;
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 02:05:13 +03:00
assert_return ( client_id | | client_id_len < = 0 , - EINVAL ) ;
if ( client_id_len < = 0 )
lease - > client_id = mfree ( lease - > client_id ) ;
else {
void * p ;
2014-11-19 02:13:12 +03: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 02:05:13 +03:00
p = memdup ( client_id , client_id_len ) ;
if ( ! p )
return - ENOMEM ;
2014-11-19 02:13:12 +03: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 02:05:13 +03:00
free ( lease - > client_id ) ;
lease - > client_id = p ;
2014-11-19 02:13:12 +03:00
lease - > client_id_len = client_id_len ;
}
return 0 ;
}
2015-08-26 20:19:32 +03:00
2015-08-30 04:18:33 +03:00
int sd_dhcp_lease_get_timezone ( sd_dhcp_lease * lease , const char * * tz ) {
2015-08-26 20:19:32 +03:00
assert_return ( lease , - EINVAL ) ;
2015-08-30 04:18:33 +03:00
assert_return ( tz , - EINVAL ) ;
2015-08-26 20:19:32 +03:00
if ( ! lease - > 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 02:05:13 +03:00
return - ENODATA ;
2015-08-26 20:19:32 +03:00
2015-08-30 04:18:33 +03:00
* tz = lease - > timezone ;
2015-08-26 20:19:32 +03:00
return 0 ;
}
2016-01-20 16:44:14 +03:00
int sd_dhcp_route_get_destination ( sd_dhcp_route * route , struct in_addr * destination ) {
assert_return ( route , - EINVAL ) ;
assert_return ( destination , - EINVAL ) ;
* destination = route - > dst_addr ;
return 0 ;
}
int sd_dhcp_route_get_destination_prefix_length ( sd_dhcp_route * route , uint8_t * length ) {
assert_return ( route , - EINVAL ) ;
assert_return ( length , - EINVAL ) ;
* length = route - > dst_prefixlen ;
return 0 ;
}
int sd_dhcp_route_get_gateway ( sd_dhcp_route * route , struct in_addr * gateway ) {
assert_return ( route , - EINVAL ) ;
assert_return ( gateway , - EINVAL ) ;
* gateway = route - > gw_addr ;
return 0 ;
}