ISC DHCP 4.4.3-P1
A reference DHCPv4 and DHCPv6 implementation
 
Loading...
Searching...
No Matches
dhcp.c File Reference
#include "dhcpd.h"
#include <errno.h>
#include <limits.h>
#include <sys/time.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.
 
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.
 
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 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.
 
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.
 

Variables

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

Function Documentation

◆ ack_lease()

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 2201 of file dhcp.c.

◆ allocate_lease()

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

Definition at line 5019 of file dhcp.c.

◆ check_pool_threshold()

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

Definition at line 2109 of file dhcp.c.

◆ dhcp()

void dhcp ( struct packet * packet)

Definition at line 133 of file dhcp.c.

◆ dhcp_reply()

void dhcp_reply ( struct lease * lease)

Definition at line 3924 of file dhcp.c.

◆ dhcpdecline()

void dhcpdecline ( struct packet * packet,
int ms_nulltp )

Definition at line 964 of file dhcp.c.

◆ dhcpdiscover()

void dhcpdiscover ( struct packet * packet,
int ms_nulltp )

Definition at line 330 of file dhcp.c.

◆ dhcpinform()

void dhcpinform ( struct packet * packet,
int ms_nulltp )

Definition at line 1117 of file dhcp.c.

◆ dhcprelease()

void dhcprelease ( struct packet * packet,
int ms_nulltp )

Definition at line 810 of file dhcp.c.

◆ dhcprequest()

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

Definition at line 488 of file dhcp.c.

◆ echo_client_id()

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 2058 of file dhcp.c.

◆ eval_network_statements()

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 5573 of file dhcp.c.

◆ find_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 )

Definition at line 4213 of file dhcp.c.

◆ get_server_source_address()

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

Definition at line 5487 of file dhcp.c.

◆ locate_network()

int locate_network ( struct packet * packet)

Definition at line 5363 of file dhcp.c.

◆ mockup_lease()

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

Definition at line 4969 of file dhcp.c.

◆ nak_lease()

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 1810 of file dhcp.c.

◆ permitted()

int permitted ( struct packet * packet,
struct permit * permit_list )

Definition at line 5178 of file dhcp.c.

◆ print_client_identifier_from_packet()

char * print_client_identifier_from_packet ( struct packet * packet)

Definition at line 96 of file dhcp.c.

◆ print_hw_addr_or_client_id()

char * print_hw_addr_or_client_id ( struct packet * packet)

Definition at line 121 of file dhcp.c.

◆ use_host_decl_name()

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 5732 of file dhcp.c.

Variable Documentation

◆ dhcp_type_name_max

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

Definition at line 88 of file dhcp.c.

◆ outstanding_pings

int outstanding_pings

Definition at line 49 of file dhcp.c.