1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21/*
22 * Copyright (c) 1993, 2010, Oracle and/or its affiliates. All rights reserved.
23 */
24
25#ifndef	_DHCPD_H
26#define	_DHCPD_H
27
28#ifdef	__cplusplus
29extern "C" {
30#endif
31
32/*
33 * dhcpd.h -- common header file for all the modules of the in.dhcpd program.
34 */
35
36#include <dhcp_svc_confopt.h>
37#include <dhcp_svc_private.h>
38#include <dhcp_svc_public.h>
39#include <dhcp_impl.h>
40#include <dhcp_symbol.h>
41#include <libinetutil.h>
42#include "hash.h"
43#include "per_dnet.h"
44
45/*
46 * Raw encoded packet data. The final state. Note that 'code' not only
47 * describes options: predefined: 1-60, site: 128-254, vendor: 42(*),
48 * but it also defines packet fields for packet data as well.
49 * Note that due to overlap of codes between various DSYM categories,
50 * category must be used to distinguish (see libdhcputil).
51 */
52typedef	struct encoded {
53	uchar_t		category; /* Option category */
54	ushort_t	code;	/* Option code: 1--254, pkt loc */
55	uchar_t		len;	/* len of data */
56	uchar_t		*data;	/* Encoded DHCP packet field / option */
57	struct encoded	*prev;	/* previous in list */
58	struct encoded	*next;	/* next in list */
59} ENCODE;
60
61typedef struct {
62	char	class[DSYM_CLASS_SIZE + 1];	/* client class */
63	ENCODE	*head;				/* options of this class */
64} VNDLIST;
65
66typedef struct {
67	char	nm[DN_MAX_CID_LEN + 1];		/* Macro name */
68	ENCODE	*head;				/* head of encoded opts */
69	int	classes;			/* num of client classes */
70	VNDLIST	**list;				/* table of client classes */
71} MACRO;
72
73/* logging message categories */
74typedef enum {
75	L_ASSIGN =	0,	/* New assignment */
76	L_REPLY =	1,	/* respond to existing client */
77	L_RELEASE =	2,	/* client released IP */
78	L_DECLINE =	3,	/* client declined IP */
79	L_INFORM =	4,	/* client requested information only */
80	L_NAK =		5,	/* client NAK'ed */
81	L_ICMP_ECHO =	6,	/* Server detected IP in use */
82	L_RELAY_REQ =	7,	/* Relay request to server(s) */
83	L_RELAY_REP =	8	/* Relay reply to client */
84} DHCP_MSG_CATEGORIES;
85
86typedef enum {
87	P_BOOTP =	0,	/* BOOT Protocol */
88	P_DHCP =	1	/* DHC Protocol */
89} DHCP_PROTO;
90
91#define	DHCPD			"in.dhcpd"	/* daemon's name */
92#define	DAEMON_VERS		"3.5"		/* daemon's version number */
93#define	ENC_COPY		0		/* Copy encode list */
94#define	ENC_DONT_COPY		1		/* don't copy encode list */
95#define	DHCP_MAX_REPLY_SIZE	8192		/* should be big enough */
96#define	DHCP_MIN_RECORDS	32		/* should be big enough */
97#define	DHCP_ICMP_ATTEMPTS	1		/* Number of ping attempts */
98#define	DHCP_ICMP_TIMEOUT	1000		/* Wait # millisecs for resp */
99#define	DHCP_ARP_ADD		0		/* Add an ARP table entry */
100#define	DHCP_ARP_DEL		1		/* Del an ARP table entry */
101#define	DHCP_SCRATCH		128		/* scratch buffer size */
102#define	NEW_DHCPTAB		0		/* load initial dhcptab */
103#define	PRESERVE_DHCPTAB	1		/* preserve previous dhcptab */
104#define	DEFAULT_LEASE		3600		/* Default if not specified */
105#define	DHCP_RDCOP_RETRIES	3		/* Attempts to read options */
106#define	HASHTABLESIZE		257		/* must be a prime number */
107#define	DHCP_RESCAN_SCALE	60L		/* scale rescan_interval */
108
109#define	DHCP_MIN_CLIENTS	32		/* minimum client structs */
110#define	DHCP_DEFAULT_CLIENTS	1024		/* default client structs */
111#define	DHCP_MINFREE_CLIENTS	8		/* minimum free clients */
112#define	DHCP_NSS_LWP		32		/* free lwps for nss lib use */
113#define	DHCP_NSS_TIME		3		/* name service cache time */
114#define	DHCP_NO_NSU		(-1)		/* No Name service updates */
115
116/* load option flags */
117#define	DHCP_DHCP_CLNT		1		/* It's a DHCP client */
118#define	DHCP_SEND_LEASE		2		/* Send lease parameters */
119#define	DHCP_NON_RFC1048	4		/* non-rfc1048 magic cookie */
120#define	DHCP_OVRLD_CLR		((uchar_t)0x00)	/* SNAME/FILE clear */
121#define	DHCP_OVRLD_FILE		((uchar_t)0x01)	/* FILE in use */
122#define	DHCP_OVRLD_SNAME	((uchar_t)0x02)	/* SNAME in use */
123#define	DHCP_OVRLD_ALL		((uchar_t)0x03)	/* All overload space in use */
124
125/* dhcp_lookup_dd_classify search flags */
126#define	S_CID		0x01		/* find a client match */
127#define	S_FREE		0x02		/* find a free record */
128#define	S_LRU		0x04		/* find an lru record */
129
130/* DHCP client states */
131#define	INIT_STATE		1
132#define	INIT_REBOOT_STATE	2
133#define	RENEW_REBIND_STATE	3
134
135extern int		debug;
136extern boolean_t	verbose;
137extern boolean_t	noping;
138extern boolean_t	no_dhcptab;
139extern boolean_t	server_mode;
140extern boolean_t	be_automatic;
141extern uchar_t		max_hops;
142extern int		log_local;
143extern int		icmp_tries;
144extern time_t		off_secs;
145extern time_t		cache_secs;
146extern time_t		renog_secs;
147extern time_t		min_lru;
148extern time_t		icmp_timeout;
149extern time_t		nsutimeout_secs;
150extern boolean_t	time_to_go;
151extern struct in_addr	server_ip;
152extern struct in_addr	*owner_ip;
153extern dsvc_datastore_t datastore;
154extern int		max_threads;	/* maximum number of threads per net */
155extern int		max_clients;	/* maximum number of clients per net */
156extern ushort_t		port_offset;	/* offset to port for multiple server */
157extern int 		net_thresh;	/* secs to keep pernet reference */
158extern int 		clnt_thresh;	/* secs to keep client reference */
159extern time_t		reinit_time;	/* reinitialization time */
160extern struct __res_state resolv_conf;
161#ifdef	DEBUG
162extern char		*dbg_net;	/* simulated debug net (see misc.c) */
163#endif	/* DEBUG */
164
165extern void	*reinitialize(void *);
166extern PKT	*gen_bootp_pkt(int, PKT *);
167extern int	initmtab(void);
168extern int	initntab(void);
169extern int	checktab(void);
170extern int	readtab(int);
171extern void	resettab(boolean_t);
172extern int	relay_agent_init(char *);
173extern void	dhcpmsg(int, const char *, ...);
174extern void 	*smalloc(unsigned);
175extern void	*srealloc(void *, uint_t);
176extern struct in_addr	*match_ownerip(in_addr_t);
177extern void	*stack_create(unsigned int);
178extern ENCODE 	*combine_encodes(ENCODE *, ENCODE *, int);
179extern void	open_macros(void);
180extern void	close_macros(void);
181extern MACRO	*get_macro(char *);
182extern ENCODE	*find_encode(ENCODE *, uchar_t, ushort_t);
183extern ENCODE	*dup_encode(ENCODE *);
184extern ENCODE	*make_encode(uchar_t, ushort_t, uchar_t, void *, int);
185extern ENCODE	*dup_encode_list(ENCODE *);
186extern void	free_encode_list(ENCODE *);
187extern void	free_encode(ENCODE *);
188extern void	replace_encode(ENCODE **, ENCODE *, int);
189extern ENCODE	*vendor_encodes(MACRO *, char *);
190extern char 	*disp_cid(PKT_LIST *, char *, int);
191extern void	get_clnt_id(PKT_LIST *, uchar_t *, int, uchar_t *);
192extern char	*get_class_id(PKT_LIST *, char *, int);
193extern int	load_options(int, PKT_LIST *, PKT *, int, uchar_t *, ENCODE *,
194		    ENCODE *);
195extern void	free_plp(PKT_LIST *);
196extern void	logtrans(DHCP_PROTO, DHCP_MSG_CATEGORIES, time_t,
197		    struct in_addr, struct in_addr, PKT_LIST *);
198extern int	icmp_echo_check(struct in_addr *, boolean_t *);
199extern void	*monitor_client(void *);
200
201extern void	dhcp(dsvc_clnt_t *, PKT_LIST *);
202boolean_t	update_offer(dsvc_clnt_t *, dn_rec_list_t **, lease_t,
203		    struct in_addr *, boolean_t);
204extern void	bootp(dsvc_clnt_t *, PKT_LIST *);
205extern void	get_netmask(struct in_addr *, struct in_addr *);
206extern boolean_t select_offer(dsvc_dnet_t *dbp, PKT_LIST *, dsvc_clnt_t *,
207		    dn_rec_list_t **);
208
209extern int dhcp_open_dd(dsvc_handle_t *, dsvc_datastore_t *, dsvc_contype_t,
210	    const char *, uint_t);
211extern int dhcp_close_dd(dsvc_handle_t *);
212extern int dhcp_modify_dd_entry(dsvc_handle_t, const void *, void *);
213extern void dhcp_free_dd_list(dsvc_handle_t, void *);
214
215extern void *dhcp_lookup_dd_classify(dsvc_dnet_t *, boolean_t, uint_t, int,
216	    const dn_rec_t *, void **, int);
217
218extern dn_rec_list_t *detach_dnrec_from_list(dn_rec_list_t *, dn_rec_list_t *,
219			dn_rec_list_t **);
220
221extern int qualify_hostname(char *, const char *, const char *, int, int);
222
223#ifdef	__cplusplus
224}
225#endif
226
227#endif	/* _DHCPD_H */
228