ISC DHCP  4.3.5
A reference DHCPv4 and DHCPv6 implementation
options.c File Reference
#include "dhcpd.h"
#include <omapip/omapip_p.h>
#include <limits.h>

Go to the source code of this file.

Data Structures

struct  vsio_state
 

Macros

#define DHCP_OPTION_DATA
 
#define PRIORITY_COUNT   300
 

Functions

int parse_options (struct packet *packet)
 
int parse_option_buffer (struct option_state *options, const unsigned char *buffer, unsigned length, struct universe *universe)
 
struct universefind_option_universe (struct option *eopt, const char *uname)
 
int parse_encapsulated_suboptions (struct option_state *options, struct option *eopt, const unsigned char *buffer, unsigned len, struct universe *eu, const char *uname)
 
int fqdn_universe_decode (struct option_state *options, const unsigned char *buffer, unsigned length, struct universe *u)
 
int cons_options (struct packet *inpacket, struct dhcp_packet *outpacket, struct lease *lease, struct client_state *client_state, int mms, struct option_state *in_options, struct option_state *cfg_options, struct binding_scope **scope, int overload_avail, int terminate, int bootpp, struct data_string *prl, const char *vuname)
 
int store_options6 (char *buf, int buflen, struct option_state *opt_state, struct packet *packet, const int *required_opts, struct data_string *oro)
 
int store_options (int *ocount, unsigned char *buffer, unsigned index, unsigned buflen, struct packet *packet, struct lease *lease, struct client_state *client_state, struct option_state *in_options, struct option_state *cfg_options, struct binding_scope **scope, unsigned *priority_list, int priority_len, unsigned first_cutoff, int second_cutoff, int terminate, const char *vuname)
 
int format_has_text (char *format) const
 
int format_min_length (char *format, struct option_cache *oc) const
 
const char * pretty_print_option (struct option *option, const unsigned char *data, unsigned len, int emit_commas, int emit_quotes)
 
int get_option (struct data_string *result, struct universe *universe, struct packet *packet, struct lease *lease, struct client_state *client_state, struct option_state *in_options, struct option_state *cfg_options, struct option_state *options, struct binding_scope **scope, unsigned code, const char *file, int line)
 
int get_option_int (int *result, struct universe *universe, struct packet *packet, struct lease *lease, struct client_state *client_state, struct option_state *in_options, struct option_state *cfg_options, struct option_state *options, struct binding_scope **scope, unsigned code, const char *file, int line)
 
void set_option (struct universe *universe, struct option_state *options, struct option_cache *option, enum statement_op op)
 
struct option_cachelookup_option (struct universe *universe, struct option_state *options, unsigned code)
 
struct option_cachelookup_hashed_option (struct universe *universe, struct option_state *options, unsigned code)
 
int save_option_buffer (struct universe *universe, struct option_state *options, struct buffer *bp, unsigned char *buffer, unsigned length, unsigned code, int terminatep)
 
int append_option_buffer (struct universe *universe, struct option_state *options, struct buffer *bp, unsigned char *buffer, unsigned length, unsigned code, int terminatep)
 
void build_server_oro (struct data_string *server_oro, struct option_state *options, const char *file, int line)
 
void save_option (struct universe *universe, struct option_state *options, struct option_cache *oc)
 
void also_save_option (struct universe *universe, struct option_state *options, struct option_cache *oc)
 
void save_hashed_option (struct universe *universe, struct option_state *options, struct option_cache *oc, isc_boolean_t appendp)
 
void delete_option (struct universe *universe, struct option_state *options, int code)
 
void delete_hashed_option (struct universe *universe, struct option_state *options, int code)
 
int option_cache_dereference (struct option_cache **ptr, const char *file, int line)
 
int hashed_option_state_dereference (struct universe *universe, struct option_state *state, const char *file, int line)
 
int append_option (struct data_string *dst, struct universe *universe, struct option *option, struct data_string *src)
 
int store_option (struct data_string *result, struct universe *universe, struct packet *packet, struct lease *lease, struct client_state *client_state, struct option_state *in_options, struct option_state *cfg_options, struct binding_scope **scope, struct option_cache *oc)
 
int option_space_encapsulate (struct data_string *result, struct packet *packet, struct lease *lease, struct client_state *client_state, struct option_state *in_options, struct option_state *cfg_options, struct binding_scope **scope, struct data_string *name)
 
int hashed_option_space_encapsulate (struct data_string *result, struct packet *packet, struct lease *lease, struct client_state *client_state, struct option_state *in_options, struct option_state *cfg_options, struct binding_scope **scope, struct universe *universe)
 
int nwip_option_space_encapsulate (struct data_string *result, struct packet *packet, struct lease *lease, struct client_state *client_state, struct option_state *in_options, struct option_state *cfg_options, struct binding_scope **scope, struct universe *universe)
 
int fqdn_option_space_encapsulate (struct data_string *result, struct packet *packet, struct lease *lease, struct client_state *client_state, struct option_state *in_options, struct option_state *cfg_options, struct binding_scope **scope, struct universe *universe)
 
struct option_cachelookup_fqdn6_option (struct universe *universe, struct option_state *options, unsigned code)
 
void save_fqdn6_option (struct universe *universe, struct option_state *options, struct option_cache *oc, isc_boolean_t appendp)
 
void delete_fqdn6_option (struct universe *universe, struct option_state *options, int code)
 
void fqdn6_option_space_foreach (struct packet *packet, struct lease *lease, struct client_state *client_state, struct option_state *in_options, struct option_state *cfg_options, struct binding_scope **scope, struct universe *u, void *stuff, void(*func)(struct option_cache *, struct packet *, struct lease *, struct client_state *, struct option_state *, struct option_state *, struct binding_scope **, struct universe *, void *))
 
int fqdn6_option_space_encapsulate (struct data_string *result, struct packet *packet, struct lease *lease, struct client_state *client_state, struct option_state *in_options, struct option_state *cfg_options, struct binding_scope **scope, struct universe *universe)
 
int fqdn6_universe_decode (struct option_state *options, const unsigned char *buffer, unsigned length, struct universe *u)
 
void option_space_foreach (struct packet *packet, struct lease *lease, struct client_state *client_state, struct option_state *in_options, struct option_state *cfg_options, struct binding_scope **scope, struct universe *u, void *stuff, void(*func)(struct option_cache *, struct packet *, struct lease *, struct client_state *, struct option_state *, struct option_state *, struct binding_scope **, struct universe *, void *))
 
void suboption_foreach (struct packet *packet, struct lease *lease, struct client_state *client_state, struct option_state *in_options, struct option_state *cfg_options, struct binding_scope **scope, struct universe *u, void *stuff, void(*func)(struct option_cache *, struct packet *, struct lease *, struct client_state *, struct option_state *, struct option_state *, struct binding_scope **, struct universe *, void *), struct option_cache *oc, const char *vsname)
 
void hashed_option_space_foreach (struct packet *packet, struct lease *lease, struct client_state *client_state, struct option_state *in_options, struct option_state *cfg_options, struct binding_scope **scope, struct universe *u, void *stuff, void(*func)(struct option_cache *, struct packet *, struct lease *, struct client_state *, struct option_state *, struct option_state *, struct binding_scope **, struct universe *, void *))
 
void save_linked_option (struct universe *universe, struct option_state *options, struct option_cache *oc, isc_boolean_t appendp)
 
int linked_option_space_encapsulate (struct data_string *result, struct packet *packet, struct lease *lease, struct client_state *client_state, struct option_state *in_options, struct option_state *cfg_options, struct binding_scope **scope, struct universe *universe)
 
void delete_linked_option (struct universe *universe, struct option_state *options, int code)
 
struct option_cachelookup_linked_option (struct universe *universe, struct option_state *options, unsigned code)
 
int linked_option_state_dereference (struct universe *universe, struct option_state *state, const char *file, int line)
 
void linked_option_space_foreach (struct packet *packet, struct lease *lease, struct client_state *client_state, struct option_state *in_options, struct option_state *cfg_options, struct binding_scope **scope, struct universe *u, void *stuff, void(*func)(struct option_cache *, struct packet *, struct lease *, struct client_state *, struct option_state *, struct option_state *, struct binding_scope **, struct universe *, void *))
 
void do_packet (struct interface_info *interface, struct dhcp_packet *packet, unsigned len, unsigned int from_port, struct iaddr from, struct hardware *hfrom)
 
int packet6_len_okay (const char *packet, int len)
 
int pretty_escape (char **dst, char *dend, const unsigned char **src, const unsigned char *send)
 
int add_option (struct option_state *options, unsigned int option_num, void *data, unsigned int data_len)
 
int validate_packet (struct packet *packet)
 
void parse_vendor_option (struct packet *packet, struct lease *lease, struct client_state *client_state, struct option_state *in_options, struct option_state *out_options, struct binding_scope **scope)
 Parse a vendor option (option 43) More...
 

Variables

struct optionvendor_cfg_option
 
struct option_cachefree_option_caches
 

Macro Definition Documentation

§ DHCP_OPTION_DATA

#define DHCP_OPTION_DATA

Definition at line 29 of file options.c.

§ PRIORITY_COUNT

#define PRIORITY_COUNT   300

Function Documentation

§ add_option()

int add_option ( struct option_state options,
unsigned int  option_num,
void *  data,
unsigned int  data_len 
)

Definition at line 4363 of file options.c.

§ also_save_option()

void also_save_option ( struct universe universe,
struct option_state options,
struct option_cache oc 
)

Definition at line 2764 of file options.c.

§ append_option()

int append_option ( struct data_string dst,
struct universe universe,
struct option option,
struct data_string src 
)

Definition at line 2976 of file options.c.

§ append_option_buffer()

int append_option_buffer ( struct universe universe,
struct option_state options,
struct buffer bp,
unsigned char *  buffer,
unsigned  length,
unsigned  code,
int  terminatep 
)

Definition at line 2504 of file options.c.

§ build_server_oro()

void build_server_oro ( struct data_string server_oro,
struct option_state options,
const char *  file,
int  line 
)

Definition at line 2688 of file options.c.

§ cons_options()

int cons_options ( struct packet inpacket,
struct dhcp_packet outpacket,
struct lease lease,
struct client_state client_state,
int  mms,
struct option_state in_options,
struct option_state cfg_options,
struct binding_scope **  scope,
int  overload_avail,
int  terminate,
int  bootpp,
struct data_string prl,
const char *  vuname 
)

Definition at line 517 of file options.c.

§ delete_fqdn6_option()

void delete_fqdn6_option ( struct universe universe,
struct option_state options,
int  code 
)

Definition at line 3491 of file options.c.

§ delete_hashed_option()

void delete_hashed_option ( struct universe universe,
struct option_state options,
int  code 
)

Definition at line 2853 of file options.c.

§ delete_linked_option()

void delete_linked_option ( struct universe universe,
struct option_state options,
int  code 
)

Definition at line 3882 of file options.c.

§ delete_option()

void delete_option ( struct universe universe,
struct option_state options,
int  code 
)

Definition at line 2841 of file options.c.

§ do_packet()

void do_packet ( struct interface_info interface,
struct dhcp_packet packet,
unsigned  len,
unsigned int  from_port,
struct iaddr  from,
struct hardware hfrom 
)

Definition at line 3978 of file options.c.

§ find_option_universe()

struct universe* find_option_universe ( struct option eopt,
const char *  uname 
)

Definition at line 271 of file options.c.

§ format_has_text()

int format_has_text ( char *  format) const

Definition at line 1605 of file options.c.

§ format_min_length()

int format_min_length ( char *  format,
struct option_cache oc 
) const

Definition at line 1667 of file options.c.

§ fqdn6_option_space_encapsulate()

int fqdn6_option_space_encapsulate ( struct data_string result,
struct packet packet,
struct lease lease,
struct client_state client_state,
struct option_state in_options,
struct option_state cfg_options,
struct binding_scope **  scope,
struct universe universe 
)

Definition at line 3527 of file options.c.

§ fqdn6_option_space_foreach()

void fqdn6_option_space_foreach ( struct packet packet,
struct lease lease,
struct client_state client_state,
struct option_state in_options,
struct option_state cfg_options,
struct binding_scope **  scope,
struct universe u,
void *  stuff,
void(*)(struct option_cache *, struct packet *, struct lease *, struct client_state *, struct option_state *, struct option_state *, struct binding_scope **, struct universe *, void *)  func 
)

Definition at line 3505 of file options.c.

§ fqdn6_universe_decode()

int fqdn6_universe_decode ( struct option_state options,
const unsigned char *  buffer,
unsigned  length,
struct universe u 
)

Definition at line 3627 of file options.c.

§ fqdn_option_space_encapsulate()

int fqdn_option_space_encapsulate ( struct data_string result,
struct packet packet,
struct lease lease,
struct client_state client_state,
struct option_state in_options,
struct option_state cfg_options,
struct binding_scope **  scope,
struct universe universe 
)

Definition at line 3352 of file options.c.

§ fqdn_universe_decode()

int fqdn_universe_decode ( struct option_state options,
const unsigned char *  buffer,
unsigned  length,
struct universe u 
)

Definition at line 345 of file options.c.

§ get_option()

int get_option ( struct data_string result,
struct universe universe,
struct packet packet,
struct lease lease,
struct client_state client_state,
struct option_state in_options,
struct option_state cfg_options,
struct option_state options,
struct binding_scope **  scope,
unsigned  code,
const char *  file,
int  line 
)

Definition at line 2258 of file options.c.

§ get_option_int()

int get_option_int ( int result,
struct universe universe,
struct packet packet,
struct lease lease,
struct client_state client_state,
struct option_state in_options,
struct option_state cfg_options,
struct option_state options,
struct binding_scope **  scope,
unsigned  code,
const char *  file,
int  line 
)

Definition at line 2293 of file options.c.

§ hashed_option_space_encapsulate()

int hashed_option_space_encapsulate ( struct data_string result,
struct packet packet,
struct lease lease,
struct client_state client_state,
struct option_state in_options,
struct option_state cfg_options,
struct binding_scope **  scope,
struct universe universe 
)

Definition at line 3184 of file options.c.

§ hashed_option_space_foreach()

void hashed_option_space_foreach ( struct packet packet,
struct lease lease,
struct client_state client_state,
struct option_state in_options,
struct option_state cfg_options,
struct binding_scope **  scope,
struct universe u,
void *  stuff,
void(*)(struct option_cache *, struct packet *, struct lease *, struct client_state *, struct option_state *, struct option_state *, struct binding_scope **, struct universe *, void *)  func 
)

Definition at line 3765 of file options.c.

§ hashed_option_state_dereference()

int hashed_option_state_dereference ( struct universe universe,
struct option_state state,
const char *  file,
int  line 
)

Definition at line 2938 of file options.c.

§ linked_option_space_encapsulate()

int linked_option_space_encapsulate ( struct data_string result,
struct packet packet,
struct lease lease,
struct client_state client_state,
struct option_state in_options,
struct option_state cfg_options,
struct binding_scope **  scope,
struct universe universe 
)

Definition at line 3846 of file options.c.

§ linked_option_space_foreach()

void linked_option_space_foreach ( struct packet packet,
struct lease lease,
struct client_state client_state,
struct option_state in_options,
struct option_state cfg_options,
struct binding_scope **  scope,
struct universe u,
void *  stuff,
void(*)(struct option_cache *, struct packet *, struct lease *, struct client_state *, struct option_state *, struct option_state *, struct binding_scope **, struct universe *, void *)  func 
)

Definition at line 3947 of file options.c.

§ linked_option_state_dereference()

int linked_option_state_dereference ( struct universe universe,
struct option_state state,
const char *  file,
int  line 
)

Definition at line 3936 of file options.c.

§ lookup_fqdn6_option()

struct option_cache* lookup_fqdn6_option ( struct universe universe,
struct option_state options,
unsigned  code 
)

Definition at line 3470 of file options.c.

§ lookup_hashed_option()

struct option_cache* lookup_hashed_option ( struct universe universe,
struct option_state options,
unsigned  code 
)

Definition at line 2453 of file options.c.

§ lookup_linked_option()

struct option_cache* lookup_linked_option ( struct universe universe,
struct option_state options,
unsigned  code 
)

Definition at line 3911 of file options.c.

§ lookup_option()

struct option_cache* lookup_option ( struct universe universe,
struct option_state options,
unsigned  code 
)

Definition at line 2438 of file options.c.

§ nwip_option_space_encapsulate()

int nwip_option_space_encapsulate ( struct data_string result,
struct packet packet,
struct lease lease,
struct client_state client_state,
struct option_state in_options,
struct option_state cfg_options,
struct binding_scope **  scope,
struct universe universe 
)

Definition at line 3227 of file options.c.

§ option_cache_dereference()

int option_cache_dereference ( struct option_cache **  ptr,
const char *  file,
int  line 
)

Definition at line 2888 of file options.c.

§ option_space_encapsulate()

int option_space_encapsulate ( struct data_string result,
struct packet packet,
struct lease lease,
struct client_state client_state,
struct option_state in_options,
struct option_state cfg_options,
struct binding_scope **  scope,
struct data_string name 
)

Definition at line 3096 of file options.c.

§ option_space_foreach()

void option_space_foreach ( struct packet packet,
struct lease lease,
struct client_state client_state,
struct option_state in_options,
struct option_state cfg_options,
struct binding_scope **  scope,
struct universe u,
void *  stuff,
void(*)(struct option_cache *, struct packet *, struct lease *, struct client_state *, struct option_state *, struct option_state *, struct binding_scope **, struct universe *, void *)  func 
)

Definition at line 3722 of file options.c.

§ packet6_len_okay()

int packet6_len_okay ( const char *  packet,
int  len 
)

Definition at line 4068 of file options.c.

§ parse_encapsulated_suboptions()

int parse_encapsulated_suboptions ( struct option_state options,
struct option eopt,
const unsigned char *  buffer,
unsigned  len,
struct universe eu,
const char *  uname 
)

Definition at line 316 of file options.c.

§ parse_option_buffer()

int parse_option_buffer ( struct option_state options,
const unsigned char *  buffer,
unsigned  length,
struct universe universe 
)

Definition at line 117 of file options.c.

§ parse_options()

int parse_options ( struct packet packet)

Definition at line 47 of file options.c.

§ parse_vendor_option()

void parse_vendor_option ( struct packet packet,
struct lease lease,
struct client_state client_state,
struct option_state in_options,
struct option_state out_options,
struct binding_scope **  scope 
)

Parse a vendor option (option 43)

After the server has parsed most of the options and presented the result to the user the user can set the proper vendor option space using vendor-option-space in the config file and then cause this routine to be called via parse-vendor-option in the config file. This routine will then try and find the proper universe for the vendor-option-space and parse the vendor option string based on that universe.

If the information isn't available (no vendor space, no universe for the vendor space, no vendor option in the options) or the decode fails we simply ignore the option and continue processing.

Parameters
packet- structure to hold information about the packet being processed
lease- lease structure
client_state
in_options- The incoming options, we expect to find the vendor-option (option 43, containing the string to parse) there. We shall attach decoded options there.
out_options- The options we have added as we process the packet. We expect to find the vendor-option-space there and use that to find the name of the vendor universe to use
scope
Returns
- void as there isn't much we can do about failures.

Definition at line 4494 of file options.c.

§ pretty_escape()

int pretty_escape ( char **  dst,
char *  dend,
const unsigned char **  src,
const unsigned char *  send 
)

Definition at line 4220 of file options.c.

§ pretty_print_option()

const char* pretty_print_option ( struct option option,
const unsigned char *  data,
unsigned  len,
int  emit_commas,
int  emit_quotes 
)

Definition at line 1766 of file options.c.

§ save_fqdn6_option()

void save_fqdn6_option ( struct universe universe,
struct option_state options,
struct option_cache oc,
isc_boolean_t  appendp 
)

Definition at line 3481 of file options.c.

§ save_hashed_option()

void save_hashed_option ( struct universe universe,
struct option_state options,
struct option_cache oc,
isc_boolean_t  appendp 
)

Definition at line 2774 of file options.c.

§ save_linked_option()

void save_linked_option ( struct universe universe,
struct option_state options,
struct option_cache oc,
isc_boolean_t  appendp 
)

Definition at line 3802 of file options.c.

§ save_option()

void save_option ( struct universe universe,
struct option_state options,
struct option_cache oc 
)

Definition at line 2753 of file options.c.

§ save_option_buffer()

int save_option_buffer ( struct universe universe,
struct option_state options,
struct buffer bp,
unsigned char *  buffer,
unsigned  length,
unsigned  code,
int  terminatep 
)

Definition at line 2480 of file options.c.

§ set_option()

void set_option ( struct universe universe,
struct option_state options,
struct option_cache option,
enum statement_op  op 
)

Definition at line 2338 of file options.c.

§ store_option()

int store_option ( struct data_string result,
struct universe universe,
struct packet packet,
struct lease lease,
struct client_state client_state,
struct option_state in_options,
struct option_state cfg_options,
struct binding_scope **  scope,
struct option_cache oc 
)

Definition at line 3026 of file options.c.

§ store_options()

int store_options ( int ocount,
unsigned char *  buffer,
unsigned  index,
unsigned  buflen,
struct packet packet,
struct lease lease,
struct client_state client_state,
struct option_state in_options,
struct option_state cfg_options,
struct binding_scope **  scope,
unsigned *  priority_list,
int  priority_len,
unsigned  first_cutoff,
int  second_cutoff,
int  terminate,
const char *  vuname 
)

Definition at line 1213 of file options.c.

§ store_options6()

int store_options6 ( char *  buf,
int  buflen,
struct option_state opt_state,
struct packet packet,
const int required_opts,
struct data_string oro 
)

Definition at line 1027 of file options.c.

§ suboption_foreach()

void suboption_foreach ( struct packet packet,
struct lease lease,
struct client_state client_state,
struct option_state in_options,
struct option_state cfg_options,
struct binding_scope **  scope,
struct universe u,
void *  stuff,
void(*)(struct option_cache *, struct packet *, struct lease *, struct client_state *, struct option_state *, struct option_state *, struct binding_scope **, struct universe *, void *)  func,
struct option_cache oc,
const char *  vsname 
)

Definition at line 3741 of file options.c.

§ validate_packet()

int validate_packet ( struct packet packet)

Checks if received BOOTP/DHCPv4 packet is sane

Parameters
packetreceived, decoded packet
Returns
1 if packet is sane, 0 if it is not

Definition at line 4414 of file options.c.

Variable Documentation

§ free_option_caches

struct option_cache* free_option_caches

Definition at line 614 of file alloc.c.

§ vendor_cfg_option

struct option* vendor_cfg_option

Definition at line 34 of file options.c.