ISC DHCP  4.3.2
A reference DHCPv4 and DHCPv6 implementation
dhcp.c File Reference
#include "dhcpd.h"
#include <errno.h>
#include <limits.h>
#include <sys/time.h>
#include "trace.h"

Go to the source code of this file.

Functions

char * print_client_identifier_from_packet (struct packet *packet)
 
char * print_hw_addr_or_client_id (struct packet *packet)
 
void dhcp (struct packet *packet)
 
void dhcpdiscover (struct packet *packet, int ms_nulltp)
 
void dhcprequest (struct packet *packet, int ms_nulltp, struct lease *ip_lease)
 
void dhcprelease (struct packet *packet, int ms_nulltp)
 
void dhcpdecline (struct packet *packet, int ms_nulltp)
 
void dhcpinform (struct packet *packet, int ms_nulltp)
 
void nak_lease (struct packet *packet, struct iaddr *cip, struct group *network_group)
 Constructs and sends a DHCP Nak. More...
 
void echo_client_id (struct packet *packet, struct lease *lease, struct option_state *in_options, struct option_state *out_options)
 Adds a dhcp-client-id option to a set of options Given a set of input options, it searches for echo-client-id. If it is defined and enabled, the given packet is searched for dhcp-client-id. If the option is found it is replicated into the given set of output options. This allows us to provide compliance with RFC 6842. It is called when we ack or nak a lease. In the latter case we may or may not have created the requisite scope to lookup echo-client-id. More...
 
void check_pool_threshold (struct packet *packet, struct lease *lease, struct lease_state *state)
 
void ack_lease (struct packet *packet, struct lease *lease, unsigned int offer, TIME when, char *msg, int ms_nulltp, struct host_decl *hp)
 
void delayed_ack_enqueue (struct lease *lease)
 
void flush_ackqueue (void *foo)
 
void dhcp_reply (struct lease *lease)
 
int find_lease (struct lease **lp, struct packet *packet, struct shared_network *share, int *ours, int *peer_has_leases, struct lease *ip_lease_in, const char *file, int line)
 
int mockup_lease (struct lease **lp, struct packet *packet, struct shared_network *share, struct host_decl *hp)
 
int allocate_lease (struct lease **lp, struct packet *packet, struct pool *pool, int *peer_has_leases)
 
int permitted (struct packet *packet, struct permit *permit_list)
 
int locate_network (struct packet *packet)
 
void get_server_source_address (struct in_addr *from, struct option_state *options, struct option_state *out_options, struct packet *packet)
 
void eval_network_statements (struct option_state **network_options, struct packet *packet, struct group *network_group)
 Builds option set from statements at the global and network scope. More...
 
void use_host_decl_name (struct packet *packet, struct lease *lease, struct option_state *options)
 Adds hostname option when use-host-decl-names is enabled. More...
 

Variables

int outstanding_pings
 
struct leasequeueackqueue_head
 
struct leasequeueackqueue_tail
 
int outstanding_acks
 
int max_outstanding_acks = DEFAULT_DELAYED_ACK
 
int max_ack_delay_secs = DEFAULT_ACK_DELAY_SECS
 
int max_ack_delay_usecs = DEFAULT_ACK_DELAY_USECS
 
int min_ack_delay_usecs = DEFAULT_MIN_ACK_DELAY_USECS
 
const int dhcp_type_name_max = ((sizeof dhcp_type_names) / sizeof (char *))
 

Function Documentation

void ack_lease ( struct packet packet,
struct lease lease,
unsigned int  offer,
TIME  when,
char *  msg,
int  ms_nulltp,
struct host_decl hp 
)

Definition at line 1992 of file dhcp.c.

int allocate_lease ( struct lease **  lp,
struct packet packet,
struct pool pool,
int peer_has_leases 
)

Definition at line 4621 of file dhcp.c.

void check_pool_threshold ( struct packet packet,
struct lease lease,
struct lease_state state 
)

Definition at line 1900 of file dhcp.c.

void delayed_ack_enqueue ( struct lease lease)

Definition at line 3447 of file dhcp.c.

void dhcp ( struct packet packet)

Definition at line 117 of file dhcp.c.

void dhcp_reply ( struct lease lease)

Definition at line 3569 of file dhcp.c.

void dhcpdecline ( struct packet packet,
int  ms_nulltp 
)

Definition at line 891 of file dhcp.c.

void dhcpdiscover ( struct packet packet,
int  ms_nulltp 
)

Definition at line 300 of file dhcp.c.

void dhcpinform ( struct packet packet,
int  ms_nulltp 
)

Definition at line 1018 of file dhcp.c.

void dhcprelease ( struct packet packet,
int  ms_nulltp 
)

Definition at line 752 of file dhcp.c.

void dhcprequest ( struct packet packet,
int  ms_nulltp,
struct lease ip_lease 
)

Definition at line 441 of file dhcp.c.

void echo_client_id ( struct packet packet,
struct lease lease,
struct option_state in_options,
struct option_state out_options 
)

Adds a dhcp-client-id option to a set of options Given a set of input options, it searches for echo-client-id. If it is defined and enabled, the given packet is searched for dhcp-client-id. If the option is found it is replicated into the given set of output options. This allows us to provide compliance with RFC 6842. It is called when we ack or nak a lease. In the latter case we may or may not have created the requisite scope to lookup echo-client-id.

Note the flag packet.sv_echo_client_id is set to reflect the configuration option. This bypases inaccessiblity of server_universe in cons_options() which must amend the PRL (when not empty) if echoing is enabled.

Parameters
packetinbound packet received from the client
leaselease associated with this client (if one)
in_optionsoptions in which to search for echo-client-id
out_optionsoptions to which to save the client-id

Definition at line 1849 of file dhcp.c.

void eval_network_statements ( struct option_state **  network_options,
struct packet packet,
struct group network_group 
)

Builds option set from statements at the global and network scope.

Set up an option state list based on the global and network scopes. These are primarily used by NAK logic to locate dhcp-server-id and echo-client-id.

We don't go through all possible options - in particualr we skip the hosts and we don't include the lease to avoid making changes to it. This means that using these, we won't get the correct server id if the admin puts them on hosts or builds the server id with information from the lease.

As this is a fallback function (used to handle NAKs or sort out server id mismatch in failover) and requires configuration by the admin, it should be okay.

Parameters
network_optionsoption_state to which options will be added. If it refers to NULL, it will be allocated. Caller is responsible to delete it.
packetinbound packet
network_groupscope group to use if packet->shared_network is null.

Definition at line 5038 of file dhcp.c.

int find_lease ( struct lease **  lp,
struct packet packet,
struct shared_network share,
int ours,
int peer_has_leases,
struct lease ip_lease_in,
const char *  file,
int  line 
)

Definition at line 3814 of file dhcp.c.

void flush_ackqueue ( void *  foo)

Definition at line 3529 of file dhcp.c.

void get_server_source_address ( struct in_addr *  from,
struct option_state options,
struct option_state out_options,
struct packet packet 
)

Definition at line 4952 of file dhcp.c.

int locate_network ( struct packet packet)

Definition at line 4837 of file dhcp.c.

int mockup_lease ( struct lease **  lp,
struct packet packet,
struct shared_network share,
struct host_decl hp 
)

Definition at line 4571 of file dhcp.c.

void nak_lease ( struct packet packet,
struct iaddr cip,
struct group network_group 
)

Constructs and sends a DHCP Nak.

In order to populate options such as dhcp-server-id and dhcp-client-identifier, the function creates a temporary option cache and evaluates options based on the packet's shared-network or the network_group in its absence, as well as the packet->clasess (if any).

Parameters
packetinbound packet received from the client
cipaddress requested by the client
network_groupoptional scope for use in setting up options

Definition at line 1634 of file dhcp.c.

int permitted ( struct packet packet,
struct permit permit_list 
)

Definition at line 4778 of file dhcp.c.

char* print_client_identifier_from_packet ( struct packet packet)

Definition at line 80 of file dhcp.c.

char* print_hw_addr_or_client_id ( struct packet packet)

Definition at line 105 of file dhcp.c.

void use_host_decl_name ( struct packet packet,
struct lease lease,
struct option_state options 
)

Adds hostname option when use-host-decl-names is enabled.

Constructs a hostname option from the name of the host declaration if there is one and no hostname has otherwise been provided and the use-host-decl-names flag is set, then adds the new option to the given option_state. This funciton is used for both bootp and dhcp.

Parameters
packetinbound packet received from the client
leaselease associated with the client
optionsoption state to search and update

Definition at line 5197 of file dhcp.c.

Variable Documentation

struct leasequeue* ackqueue_head

Definition at line 43 of file dhcp.c.

struct leasequeue * ackqueue_tail

Definition at line 43 of file dhcp.c.

const int dhcp_type_name_max = ((sizeof dhcp_type_names) / sizeof (char *))

Definition at line 74 of file dhcp.c.

int max_ack_delay_secs = DEFAULT_ACK_DELAY_SECS

Definition at line 49 of file dhcp.c.

int max_ack_delay_usecs = DEFAULT_ACK_DELAY_USECS

Definition at line 50 of file dhcp.c.

int max_outstanding_acks = DEFAULT_DELAYED_ACK

Definition at line 48 of file dhcp.c.

int min_ack_delay_usecs = DEFAULT_MIN_ACK_DELAY_USECS

Definition at line 51 of file dhcp.c.

int outstanding_acks

Definition at line 47 of file dhcp.c.

int outstanding_pings

Definition at line 41 of file dhcp.c.