xref: /illumos-gate/usr/src/cmd/cmd-inet/sbin/dhcpagent/agent.h (revision 2a8bcb4efb45d99ac41c94a75c396b362c414f7f)
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 2007 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	AGENT_H
27 #define	AGENT_H
28 
29 #include <sys/types.h>
30 #include <libinetutil.h>
31 #include <dhcpagent_ipc.h>
32 
33 /*
34  * agent.h contains general symbols that should be available to all
35  * source programs that are part of the agent.  in general, files
36  * specific to a given collection of code (such as interface.h or
37  * dhcpmsg.h) are to be preferred to this dumping ground.  use only
38  * when necessary.
39  */
40 
41 #ifdef	__cplusplus
42 extern "C" {
43 #endif
44 
45 /*
46  * global variables: `tq' and `eh' represent the global timer queue
47  * and event handler, as described in the README. `class_id' is our
48  * vendor class id set early on in main().  `inactivity_id' is the
49  * timer id of the global inactivity timer, which shuts down the agent
50  * if there are no state machines to manage for DHCP_INACTIVITY_WAIT
51  * seconds. `grandparent' is the pid of the original process when in
52  * adopt mode.  `rtsock_fd' is the global routing socket file descriptor.
53  */
54 
55 extern iu_tq_t		*tq;
56 extern iu_eh_t		*eh;
57 extern char		*class_id;
58 extern int		class_id_len;
59 extern iu_timer_id_t	inactivity_id;
60 extern pid_t		grandparent;
61 extern int		rtsock_fd;
62 
63 boolean_t	drain_script(iu_eh_t *, void *);
64 boolean_t	check_cmd_allowed(DHCPSTATE, dhcp_ipc_type_t);
65 
66 /*
67  * global tunable parameters.  an `I' in the preceding comment indicates
68  * an implementation artifact; a `R' in the preceding comment indicates
69  * that the value was suggested (or required) by RFC2131.
70  */
71 
72 /* I: how many seconds to wait before restarting DHCP on an interface */
73 #define	DHCP_RESTART_WAIT	10
74 
75 /*
76  * I: the maximum number of milliseconds to wait before SELECTING on an
77  * interface. RFC2131 recommends a random wait of between one and ten seconds,
78  * to speed up DHCP at boot we wait between zero and two seconds.
79  */
80 #define	DHCP_SELECT_WAIT	2000
81 
82 /* R: how many seconds before lease expiration we give up trying to rebind */
83 #define	DHCP_REBIND_MIN		60
84 
85 /* I: seconds to wait retrying dhcp_expire() if uncancellable async event */
86 #define	DHCP_EXPIRE_WAIT	10
87 
88 /* R: approximate percentage of lease time to wait until RENEWING state */
89 #define	DHCP_T1_FACT		.5
90 
91 /* R: approximate percentage of lease time to wait until REBINDING state */
92 #define	DHCP_T2_FACT		.875
93 
94 /* I: number of REQUEST attempts before assuming something is awry */
95 #define	DHCP_MAX_REQUESTS	4
96 
97 /* I: epsilon in seconds used to check if old and new lease times are same */
98 #define	DHCP_LEASE_EPS		30
99 
100 /* I: if lease is not being extended, seconds left before alerting user */
101 #define	DHCP_LEASE_ERROR_THRESH	(60*60)	/* one hour */
102 
103 /* I: how many seconds before bailing out if there's no work to do */
104 #define	DHCP_INACTIVITY_WAIT	(60*3)		/* three minutes */
105 
106 /* I: the maximum amount of seconds we use an adopted lease */
107 #define	DHCP_ADOPT_LEASE_MAX	(60*60)		/* one hour */
108 
109 /* I: number of seconds grandparent waits for child to finish adoption. */
110 #define	DHCP_ADOPT_SLEEP	30
111 
112 /* I: the maximum amount of milliseconds to wait for an ipc request */
113 #define	DHCP_IPC_REQUEST_WAIT	(3*1000)	/* three seconds */
114 
115 /*
116  * DHCPv6 timer and retransmit values from RFC 3315.
117  */
118 #define	DHCPV6_SOL_MAX_DELAY	1000	/* Max delay of first Solicit; 1s */
119 #define	DHCPV6_CNF_MAX_DELAY	1000	/* Max delay of first Confirm; 1s */
120 #define	DHCPV6_INF_MAX_DELAY	1000	/* Max delay of first Info-req; 1s */
121 #define	DHCPV6_SOL_TIMEOUT	1000	/* Initial Solicit timeout; 1s */
122 #define	DHCPV6_REQ_TIMEOUT	1000	/* Initial Request timeout; 1s */
123 #define	DHCPV6_CNF_TIMEOUT	1000	/* Initial Confirm timeout; 1s */
124 #define	DHCPV6_REN_TIMEOUT	10000	/* Initial Renew timeout; 10s */
125 #define	DHCPV6_REB_TIMEOUT	10000	/* Initial Rebind timeout; 10s */
126 #define	DHCPV6_INF_TIMEOUT	1000	/* Initial Info-req timeout; 1s */
127 #define	DHCPV6_REL_TIMEOUT	1000	/* Initial Release timeout; 1s */
128 #define	DHCPV6_DEC_TIMEOUT	1000	/* Initial Decline timeout; 1s */
129 #define	DHCPV6_SOL_MAX_RT	120000	/* Max Solicit timeout; 2m */
130 #define	DHCPV6_REQ_MAX_RT	30000	/* Max Request timeout; 30s */
131 #define	DHCPV6_CNF_MAX_RT	4000	/* Max Confirm timeout; 4s */
132 #define	DHCPV6_REN_MAX_RT	600000	/* Max Renew timeout; 5m */
133 #define	DHCPV6_REB_MAX_RT	600000	/* Max Rebind timeout; 5m */
134 #define	DHCPV6_INF_MAX_RT	120000	/* Max Info-req timeout; 2m */
135 #define	DHCPV6_CNF_MAX_RD	10000	/* Max Confirm duration; 10s */
136 #define	DHCPV6_REQ_MAX_RC	10	/* Max Request attempts */
137 #define	DHCPV6_REL_MAX_RC	5	/* Max Release attempts */
138 #define	DHCPV6_DEC_MAX_RC	5	/* Max Decline attempts */
139 
140 /*
141  * reasons for why iu_handle_events() returned
142  */
143 enum { DHCP_REASON_INACTIVITY, DHCP_REASON_SIGNAL, DHCP_REASON_TERMINATE };
144 
145 #ifdef	__cplusplus
146 }
147 #endif
148 
149 #endif	/* AGENT_H */
150