ISC DHCP  4.3.5
A reference DHCPv4 and DHCPv6 implementation
mdb6.c File Reference
#include "config.h"
#include <sys/types.h>
#include <time.h>
#include <netinet/in.h>
#include <stdarg.h>
#include "dhcpd.h"
#include "omapip/omapip.h"
#include "omapip/hash.h"
#include <isc/md5.h>

Go to the source code of this file.

Functions

 HASH_FUNCTIONS (ia, unsigned char *, struct ia_xx, ia_hash_t, ia_reference, ia_dereference, do_string_hash)
 
isc_result_t iasubopt_reference (struct iasubopt **iasubopt, struct iasubopt *src, const char *file, int line)
 
isc_result_t iasubopt_dereference (struct iasubopt **iasubopt, const char *file, int line)
 
isc_result_t ia_make_key (struct data_string *key, u_int32_t iaid, const char *duid, unsigned int duid_len, const char *file, int line)
 
isc_result_t ia_allocate (struct ia_xx **ia, u_int32_t iaid, const char *duid, unsigned int duid_len, const char *file, int line)
 
isc_result_t ia_reference (struct ia_xx **ia, struct ia_xx *src, const char *file, int line)
 
isc_result_t ia_dereference (struct ia_xx **ia, const char *file, int line)
 
isc_result_t ia_add_iasubopt (struct ia_xx *ia, struct iasubopt *iasubopt, const char *file, int line)
 
void ia_remove_iasubopt (struct ia_xx *ia, struct iasubopt *iasubopt, const char *file, int line)
 
void ia_remove_all_lease (struct ia_xx *ia, const char *file, int line)
 
isc_boolean_t ia_equal (const struct ia_xx *a, const struct ia_xx *b)
 
isc_result_t ipv6_pool_allocate (struct ipv6_pool **pool, u_int16_t type, const struct in6_addr *start_addr, int bits, int units, const char *file, int line)
 Create a new IPv6 lease pool structure. More...
 
isc_result_t ipv6_pool_reference (struct ipv6_pool **pool, struct ipv6_pool *src, const char *file, int line)
 reference an IPv6 pool structure. More...
 
isc_result_t ipv6_pool_dereference (struct ipv6_pool **pool, const char *file, int line)
 de-reference an IPv6 pool structure. More...
 
isc_result_t create_lease6 (struct ipv6_pool *pool, struct iasubopt **addr, unsigned int *attempts, const struct data_string *uid, time_t soft_lifetime_end_time)
 
isc_result_t cleanup_lease6 (ia_hash_t *ia_table, struct ipv6_pool *pool, struct iasubopt *lease, struct ia_xx *ia)
 Cleans up leases when reading from a lease file. More...
 
isc_result_t add_lease6 (struct ipv6_pool *pool, struct iasubopt *lease, time_t valid_lifetime_end_time)
 
isc_boolean_t lease6_exists (const struct ipv6_pool *pool, const struct in6_addr *addr)
 
isc_boolean_t lease6_usable (struct iasubopt *lease)
 Check if address is available to a lease. More...
 
isc_result_t renew_lease6 (struct ipv6_pool *pool, struct iasubopt *lease)
 Renew a lease in the pool. More...
 
isc_result_t expire_lease6 (struct iasubopt **leasep, struct ipv6_pool *pool, time_t now)
 
isc_result_t decline_lease6 (struct ipv6_pool *pool, struct iasubopt *lease)
 
isc_result_t release_lease6 (struct ipv6_pool *pool, struct iasubopt *lease)
 
void build_prefix6 (struct in6_addr *pref, const struct in6_addr *net_start_pref, int pool_bits, int pref_bits, const struct data_string *input)
 
isc_result_t create_prefix6 (struct ipv6_pool *pool, struct iasubopt **pref, unsigned int *attempts, const struct data_string *uid, time_t soft_lifetime_end_time)
 
isc_boolean_t prefix6_exists (const struct ipv6_pool *pool, const struct in6_addr *pref, u_int8_t plen)
 
isc_result_t mark_lease_unavailable (struct ipv6_pool *pool, const struct in6_addr *addr)
 
isc_result_t add_ipv6_pool (struct ipv6_pool *pool)
 
void schedule_lease_timeout (struct ipv6_pool *pool)
 
void schedule_all_ipv6_lease_timeouts (void)
 
isc_boolean_t ipv6_in_pool (const struct in6_addr *addr, const struct ipv6_pool *pool)
 
isc_result_t find_ipv6_pool (struct ipv6_pool **pool, u_int16_t type, const struct in6_addr *addr)
 
isc_result_t renew_leases (struct ia_xx *ia)
 
isc_result_t release_leases (struct ia_xx *ia)
 
isc_result_t decline_leases (struct ia_xx *ia)
 
void mark_hosts_unavailable (void)
 
void mark_phosts_unavailable (void)
 
void mark_interfaces_unavailable (void)
 
isc_result_t ipv6_pond_allocate (struct ipv6_pond **pond, const char *file, int line)
 Create a new IPv6 pond structure. More...
 
isc_result_t ipv6_pond_reference (struct ipv6_pond **pond, struct ipv6_pond *src, const char *file, int line)
 reference an IPv6 pond structure. More...
 
isc_result_t ipv6_pond_dereference (struct ipv6_pond **pond, const char *file, int line)
 de-reference an IPv6 pond structure. More...
 
void report_jumbo_ranges ()
 
int htype_bounds_check (uint16_t htype)
 
int find_hosts_by_haddr6 (struct host_decl **hp, struct packet *packet, struct option_state *opt_state, const char *file, int line)
 Look for hosts by MAC address if it's available. More...
 
int find_hosts_by_duid_chaddr (struct host_decl **host, const struct data_string *client_id)
 
int find_hosts6 (struct host_decl **host, struct packet *packet, const struct data_string *client_id, char *file, int line)
 

Detailed Description

Todo:

assert()

simplify functions, as pool is now in iaaddr

Definition in file mdb6.c.

Function Documentation

◆ add_ipv6_pool()

isc_result_t add_ipv6_pool ( struct ipv6_pool pool)

Definition at line 1845 of file mdb6.c.

◆ add_lease6()

isc_result_t add_lease6 ( struct ipv6_pool pool,
struct iasubopt lease,
time_t  valid_lifetime_end_time 
)

Definition at line 1234 of file mdb6.c.

◆ build_prefix6()

void build_prefix6 ( struct in6_addr *  pref,
const struct in6_addr *  net_start_pref,
int  pool_bits,
int  pref_bits,
const struct data_string input 
)

Definition at line 1635 of file mdb6.c.

◆ cleanup_lease6()

isc_result_t cleanup_lease6 ( ia_hash_t ia_table,
struct ipv6_pool pool,
struct iasubopt lease,
struct ia_xx ia 
)

Cleans up leases when reading from a lease file.

This function is only expected to be run when reading leases in from a file. It checks to see if a lease already exists for the new leases's address. We don't add expired leases to the structures when reading a lease file which limits what can happen. We have two variables the owners of the leases being the same or different and the new lease being active or non-active: Owners active same no remove old lease and its connections same yes nothing to do, other code will update the structures. diff no nothing to do diff yes this combination shouldn't happen, we should only have a single active lease per address at a time and that lease should move to non-active before any other lease can become active for that address. Currently we delete the previous lease and pass an error to the caller who should log an error.

When we remove a lease we remove it from the hash table and active heap (remember only active leases are in the structures at this time) for the pool, and from the IA's array. If, after we've removed the pointer from IA's array to the lease, the IA has no more pointers we remove it from the appropriate hash table as well.

Parameters
[in]ia_table= the hash table for the IA
[in]pool= the pool to update
[in]lease= the new lease we want to add
[in]ia= the new ia we are building
Returns
ISC_R_SUCCESS = the incoming lease and any previous lease were in an expected state - one of the first 3 options above. If necessary the old lease was removed. ISC_R_FAILURE = there is already an active lease for the address in the incoming lease. This shouldn't happen if it does flag an error for the caller to log.

Definition at line 1124 of file mdb6.c.

◆ create_lease6()

isc_result_t create_lease6 ( struct ipv6_pool pool,
struct iasubopt **  addr,
unsigned int attempts,
const struct data_string uid,
time_t  soft_lifetime_end_time 
)

Definition at line 953 of file mdb6.c.

◆ create_prefix6()

isc_result_t create_prefix6 ( struct ipv6_pool pool,
struct iasubopt **  pref,
unsigned int attempts,
const struct data_string uid,
time_t  soft_lifetime_end_time 
)

Definition at line 1715 of file mdb6.c.

◆ decline_lease6()

isc_result_t decline_lease6 ( struct ipv6_pool pool,
struct iasubopt lease 
)

Definition at line 1597 of file mdb6.c.

◆ decline_leases()

isc_result_t decline_leases ( struct ia_xx ia)

Definition at line 2189 of file mdb6.c.

◆ expire_lease6()

isc_result_t expire_lease6 ( struct iasubopt **  leasep,
struct ipv6_pool pool,
time_t  now 
)

Definition at line 1563 of file mdb6.c.

◆ find_hosts6()

int find_hosts6 ( struct host_decl **  host,
struct packet packet,
const struct data_string client_id,
char *  file,
int  line 
)

Definition at line 2771 of file mdb6.c.

◆ find_hosts_by_duid_chaddr()

int find_hosts_by_duid_chaddr ( struct host_decl **  host,
const struct data_string client_id 
)

Definition at line 2700 of file mdb6.c.

◆ find_hosts_by_haddr6()

int find_hosts_by_haddr6 ( struct host_decl **  hp,
struct packet packet,
struct option_state opt_state,
const char *  file,
int  line 
)

Look for hosts by MAC address if it's available.

Checks the inbound packet against host declarations which specified:

 "hardware ethernet <MAC>;"

For directly connected clients, the function will use the MAC address contained in packet:haddr if it's populated. - While the logic is in place for this search, the socket layer does not yet populate packet:haddr, this is to be done under rt41523.

For relayed clients, the function will use the MAC address from the client-linklayer-address option if it has been supplied by the relay directly connected to the client.

Parameters
hp[out]- pointer to storage for the host delcaration if found
packet- received packet
opt_state- option state to search
file- source file
line- line number
Returns
non-zero if a matching host was found, zero otherwise

Definition at line 2624 of file mdb6.c.

◆ find_ipv6_pool()

isc_result_t find_ipv6_pool ( struct ipv6_pool **  pool,
u_int16_t  type,
const struct in6_addr *  addr 
)

Definition at line 2112 of file mdb6.c.

◆ HASH_FUNCTIONS()

HASH_FUNCTIONS ( ia  ,
unsigned char *  ,
struct ia_xx  ,
ia_hash_t  ,
ia_reference  ,
ia_dereference  ,
do_string_hash   
)

Definition at line 180 of file mdb6.c.

◆ htype_bounds_check()

int htype_bounds_check ( uint16_t  htype)

Definition at line 2583 of file mdb6.c.

◆ ia_add_iasubopt()

isc_result_t ia_add_iasubopt ( struct ia_xx ia,
struct iasubopt iasubopt,
const char *  file,
int  line 
)

Definition at line 438 of file mdb6.c.

◆ ia_allocate()

isc_result_t ia_allocate ( struct ia_xx **  ia,
u_int32_t  iaid,
const char *  duid,
unsigned int  duid_len,
const char *  file,
int  line 
)

Definition at line 338 of file mdb6.c.

◆ ia_dereference()

isc_result_t ia_dereference ( struct ia_xx **  ia,
const char *  file,
int  line 
)

Definition at line 402 of file mdb6.c.

◆ ia_equal()

isc_boolean_t ia_equal ( const struct ia_xx a,
const struct ia_xx b 
)

Definition at line 517 of file mdb6.c.

◆ ia_make_key()

isc_result_t ia_make_key ( struct data_string key,
u_int32_t  iaid,
const char *  duid,
unsigned int  duid_len,
const char *  file,
int  line 
)

Definition at line 310 of file mdb6.c.

◆ ia_reference()

isc_result_t ia_reference ( struct ia_xx **  ia,
struct ia_xx src,
const char *  file,
int  line 
)

Definition at line 376 of file mdb6.c.

◆ ia_remove_all_lease()

void ia_remove_all_lease ( struct ia_xx ia,
const char *  file,
int  line 
)

Definition at line 503 of file mdb6.c.

◆ ia_remove_iasubopt()

void ia_remove_iasubopt ( struct ia_xx ia,
struct iasubopt iasubopt,
const char *  file,
int  line 
)

Definition at line 475 of file mdb6.c.

◆ iasubopt_dereference()

isc_result_t iasubopt_dereference ( struct iasubopt **  iasubopt,
const char *  file,
int  line 
)

Definition at line 260 of file mdb6.c.

◆ iasubopt_reference()

isc_result_t iasubopt_reference ( struct iasubopt **  iasubopt,
struct iasubopt src,
const char *  file,
int  line 
)

Definition at line 233 of file mdb6.c.

◆ ipv6_in_pool()

isc_boolean_t ipv6_in_pool ( const struct in6_addr *  addr,
const struct ipv6_pool pool 
)

Definition at line 2094 of file mdb6.c.

◆ ipv6_pond_allocate()

isc_result_t ipv6_pond_allocate ( struct ipv6_pond **  pond,
const char *  file,
int  line 
)

Create a new IPv6 pond structure.

Allocate space for a new ipv6_pond structure and return a reference to it, includes setting the reference count to 1.

Parameters
pond= space for returning a referenced pointer to the pond. This must point to a space that has been initialzied to NULL by the caller.
Returns
ISC_R_SUCCESS = The pond was successfully created, pond points to it. DHCP_R_INVALIDARG = One of the arugments was invalid, pond has not been modified ISC_R_NOMEMORY = The system wasn't able to allocate memory, pond has not been modified.

Definition at line 2391 of file mdb6.c.

◆ ipv6_pond_dereference()

isc_result_t ipv6_pond_dereference ( struct ipv6_pond **  pond,
const char *  file,
int  line 
)

de-reference an IPv6 pond structure.

This function decrements the reference count in an ipv6_pond structure. If this was the last reference then the memory for the structure is freed.

Parameters
[in]pond= A pointer to the pointer to the pond that should be de-referenced. On success the pointer to the pond is cleared. It must not be NULL and must not point to NULL.
Returns
ISC_R_SUCCESS = The pond was successfully de-referenced, pond now points to NULL DHCP_R_INVALIDARG = One of the arugments was invalid, pond has not been modified.

Definition at line 2474 of file mdb6.c.

◆ ipv6_pond_reference()

isc_result_t ipv6_pond_reference ( struct ipv6_pond **  pond,
struct ipv6_pond src,
const char *  file,
int  line 
)

reference an IPv6 pond structure.

This function genreates a reference to an ipv6_pond structure and increments the reference count on the structure.

Parameters
[out]pond= space for returning a referenced pointer to the pond. This must point to a space that has been initialzied to NULL by the caller.
[in]src= A pointer to the pond to reference. This must not be NULL.
Returns
ISC_R_SUCCESS = The pond was successfully referenced, pond now points to src. DHCP_R_INVALIDARG = One of the arugments was invalid, pond has not been modified.

Definition at line 2434 of file mdb6.c.

◆ ipv6_pool_allocate()

isc_result_t ipv6_pool_allocate ( struct ipv6_pool **  pool,
u_int16_t  type,
const struct in6_addr *  start_addr,
int  bits,
int  units,
const char *  file,
int  line 
)

Create a new IPv6 lease pool structure.

Allocate space for a new ipv6_pool structure and return a reference to it, includes setting the reference count to 1.

Parameters
pool= space for returning a referenced pointer to the pool. This must point to a space that has been initialzied to NULL by the caller.
[in]type= The type of the pool NA, TA or PD
[in]start_addr= The first address in the range for the pool
[in]bits= The contiguous bits of the pool
Returns
ISC_R_SUCCESS = The pool was successfully created, pool points to it. DHCP_R_INVALIDARG = One of the arugments was invalid, pool has not been modified ISC_R_NOMEMORY = The system wasn't able to allocate memory, pool has not been modified.

Definition at line 635 of file mdb6.c.

◆ ipv6_pool_dereference()

isc_result_t ipv6_pool_dereference ( struct ipv6_pool **  pool,
const char *  file,
int  line 
)

de-reference an IPv6 pool structure.

This function decrements the reference count in an ipv6_pool structure. If this was the last reference then the memory for the structure is freed.

Parameters
[in]pool= A pointer to the pointer to the pool that should be de-referenced. On success the pointer to the pool is cleared. It must not be NULL and must not point to NULL.
Returns
ISC_R_SUCCESS = The pool was successfully de-referenced, pool now points to NULL DHCP_R_INVALIDARG = One of the arugments was invalid, pool has not been modified.

Definition at line 772 of file mdb6.c.

◆ ipv6_pool_reference()

isc_result_t ipv6_pool_reference ( struct ipv6_pool **  pool,
struct ipv6_pool src,
const char *  file,
int  line 
)

reference an IPv6 pool structure.

This function genreates a reference to an ipv6_pool structure and increments the reference count on the structure.

Parameters
[out]pool= space for returning a referenced pointer to the pool. This must point to a space that has been initialzied to NULL by the caller.
[in]src= A pointer to the pool to reference. This must not be NULL.
Returns
ISC_R_SUCCESS = The pool was successfully referenced, pool now points to src. DHCP_R_INVALIDARG = One of the arugments was invalid, pool has not been modified.

Definition at line 701 of file mdb6.c.

◆ lease6_exists()

isc_boolean_t lease6_exists ( const struct ipv6_pool pool,
const struct in6_addr *  addr 
)

Definition at line 1344 of file mdb6.c.

◆ lease6_usable()

isc_boolean_t lease6_usable ( struct iasubopt lease)

Check if address is available to a lease.

Determine if the address in the lease is available to that lease. Either the address isn't in use or it is in use but by that lease.

Parameters
[in]lease= lease to check
Returns
ISC_TRUE = The lease is allowed to use that address ISC_FALSE = The lease isn't allowed to use that address

Definition at line 1372 of file mdb6.c.

◆ mark_hosts_unavailable()

void mark_hosts_unavailable ( void  )

Definition at line 2292 of file mdb6.c.

◆ mark_interfaces_unavailable()

void mark_interfaces_unavailable ( void  )

Definition at line 2347 of file mdb6.c.

◆ mark_lease_unavailable()

isc_result_t mark_lease_unavailable ( struct ipv6_pool pool,
const struct in6_addr *  addr 
)

Definition at line 1827 of file mdb6.c.

◆ mark_phosts_unavailable()

void mark_phosts_unavailable ( void  )

Definition at line 2342 of file mdb6.c.

◆ prefix6_exists()

isc_boolean_t prefix6_exists ( const struct ipv6_pool pool,
const struct in6_addr *  pref,
u_int8_t  plen 
)

Definition at line 1804 of file mdb6.c.

◆ release_lease6()

isc_result_t release_lease6 ( struct ipv6_pool pool,
struct iasubopt lease 
)

Definition at line 1622 of file mdb6.c.

◆ release_leases()

isc_result_t release_leases ( struct ia_xx ia)

Definition at line 2181 of file mdb6.c.

◆ renew_lease6()

isc_result_t renew_lease6 ( struct ipv6_pool pool,
struct iasubopt lease 
)

Renew a lease in the pool.

The hard_lifetime_end_time of the lease should be set to the current expiration time. The soft_lifetime_end_time of the lease should be set to the desired expiration time.

This routine will compare the two and call the correct heap routine to move the lease. If the lease is active and the new expiration time is greater (the normal case) then we call isc_heap_decreased() as a larger time is a lower priority. If the new expiration time is less then we call isc_heap_increased().

If the lease is abandoned then it will be on the active list and we will always call isc_heap_increased() as the previous expiration would have been all 1s (as close as we can get to infinite).

If the lease is moving to active we call that routine which will move it from the inactive list to the active list.

Parameters
pool= a pool the lease belongs to
lease= the lease to be renewed
Returns
result of the renew operation (ISC_R_SUCCESS if successful, ISC_R_NOMEMORY when run out of memory)

Definition at line 1444 of file mdb6.c.

◆ renew_leases()

isc_result_t renew_leases ( struct ia_xx ia)

Definition at line 2173 of file mdb6.c.

◆ report_jumbo_ranges()

void report_jumbo_ranges ( )

Definition at line 2510 of file mdb6.c.

◆ schedule_all_ipv6_lease_timeouts()

void schedule_all_ipv6_lease_timeouts ( void  )

Definition at line 2029 of file mdb6.c.

◆ schedule_lease_timeout()

void schedule_lease_timeout ( struct ipv6_pool pool)

Definition at line 1986 of file mdb6.c.