xref: /illumos-gate/usr/src/cmd/cmd-inet/sbin/dhcpagent/agent.h (revision 2a8bcb4efb45d99ac41c94a75c396b362c414f7f)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5985c053eSmeem  * Common Development and Distribution License (the "License").
6985c053eSmeem  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*d04ccbb3Scarlsonj  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifndef	AGENT_H
277c478bd9Sstevel@tonic-gate #define	AGENT_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #include <sys/types.h>
307c478bd9Sstevel@tonic-gate #include <libinetutil.h>
31*d04ccbb3Scarlsonj #include <dhcpagent_ipc.h>
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate /*
347c478bd9Sstevel@tonic-gate  * agent.h contains general symbols that should be available to all
357c478bd9Sstevel@tonic-gate  * source programs that are part of the agent.  in general, files
367c478bd9Sstevel@tonic-gate  * specific to a given collection of code (such as interface.h or
377c478bd9Sstevel@tonic-gate  * dhcpmsg.h) are to be preferred to this dumping ground.  use only
387c478bd9Sstevel@tonic-gate  * when necessary.
397c478bd9Sstevel@tonic-gate  */
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
427c478bd9Sstevel@tonic-gate extern "C" {
437c478bd9Sstevel@tonic-gate #endif
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate /*
467c478bd9Sstevel@tonic-gate  * global variables: `tq' and `eh' represent the global timer queue
477c478bd9Sstevel@tonic-gate  * and event handler, as described in the README. `class_id' is our
487c478bd9Sstevel@tonic-gate  * vendor class id set early on in main().  `inactivity_id' is the
497c478bd9Sstevel@tonic-gate  * timer id of the global inactivity timer, which shuts down the agent
50*d04ccbb3Scarlsonj  * if there are no state machines to manage for DHCP_INACTIVITY_WAIT
517c478bd9Sstevel@tonic-gate  * seconds. `grandparent' is the pid of the original process when in
5269bb4bb4Scarlsonj  * adopt mode.  `rtsock_fd' is the global routing socket file descriptor.
537c478bd9Sstevel@tonic-gate  */
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate extern iu_tq_t		*tq;
567c478bd9Sstevel@tonic-gate extern iu_eh_t		*eh;
577c478bd9Sstevel@tonic-gate extern char		*class_id;
587c478bd9Sstevel@tonic-gate extern int		class_id_len;
597c478bd9Sstevel@tonic-gate extern iu_timer_id_t	inactivity_id;
607c478bd9Sstevel@tonic-gate extern pid_t		grandparent;
6169bb4bb4Scarlsonj extern int		rtsock_fd;
627c478bd9Sstevel@tonic-gate 
637c478bd9Sstevel@tonic-gate boolean_t	drain_script(iu_eh_t *, void *);
64*d04ccbb3Scarlsonj boolean_t	check_cmd_allowed(DHCPSTATE, dhcp_ipc_type_t);
657c478bd9Sstevel@tonic-gate 
667c478bd9Sstevel@tonic-gate /*
677c478bd9Sstevel@tonic-gate  * global tunable parameters.  an `I' in the preceding comment indicates
687c478bd9Sstevel@tonic-gate  * an implementation artifact; a `R' in the preceding comment indicates
697c478bd9Sstevel@tonic-gate  * that the value was suggested (or required) by RFC2131.
707c478bd9Sstevel@tonic-gate  */
717c478bd9Sstevel@tonic-gate 
727c478bd9Sstevel@tonic-gate /* I: how many seconds to wait before restarting DHCP on an interface */
737c478bd9Sstevel@tonic-gate #define	DHCP_RESTART_WAIT	10
747c478bd9Sstevel@tonic-gate 
757c478bd9Sstevel@tonic-gate /*
767c478bd9Sstevel@tonic-gate  * I: the maximum number of milliseconds to wait before SELECTING on an
777c478bd9Sstevel@tonic-gate  * interface. RFC2131 recommends a random wait of between one and ten seconds,
787c478bd9Sstevel@tonic-gate  * to speed up DHCP at boot we wait between zero and two seconds.
797c478bd9Sstevel@tonic-gate  */
807c478bd9Sstevel@tonic-gate #define	DHCP_SELECT_WAIT	2000
817c478bd9Sstevel@tonic-gate 
827c478bd9Sstevel@tonic-gate /* R: how many seconds before lease expiration we give up trying to rebind */
837c478bd9Sstevel@tonic-gate #define	DHCP_REBIND_MIN		60
847c478bd9Sstevel@tonic-gate 
857c478bd9Sstevel@tonic-gate /* I: seconds to wait retrying dhcp_expire() if uncancellable async event */
867c478bd9Sstevel@tonic-gate #define	DHCP_EXPIRE_WAIT	10
877c478bd9Sstevel@tonic-gate 
887c478bd9Sstevel@tonic-gate /* R: approximate percentage of lease time to wait until RENEWING state */
897c478bd9Sstevel@tonic-gate #define	DHCP_T1_FACT		.5
907c478bd9Sstevel@tonic-gate 
917c478bd9Sstevel@tonic-gate /* R: approximate percentage of lease time to wait until REBINDING state */
927c478bd9Sstevel@tonic-gate #define	DHCP_T2_FACT		.875
937c478bd9Sstevel@tonic-gate 
947c478bd9Sstevel@tonic-gate /* I: number of REQUEST attempts before assuming something is awry */
957c478bd9Sstevel@tonic-gate #define	DHCP_MAX_REQUESTS	4
967c478bd9Sstevel@tonic-gate 
977c478bd9Sstevel@tonic-gate /* I: epsilon in seconds used to check if old and new lease times are same */
987c478bd9Sstevel@tonic-gate #define	DHCP_LEASE_EPS		30
997c478bd9Sstevel@tonic-gate 
1007c478bd9Sstevel@tonic-gate /* I: if lease is not being extended, seconds left before alerting user */
101985c053eSmeem #define	DHCP_LEASE_ERROR_THRESH	(60*60)	/* one hour */
1027c478bd9Sstevel@tonic-gate 
1037c478bd9Sstevel@tonic-gate /* I: how many seconds before bailing out if there's no work to do */
1047c478bd9Sstevel@tonic-gate #define	DHCP_INACTIVITY_WAIT	(60*3)		/* three minutes */
1057c478bd9Sstevel@tonic-gate 
1067c478bd9Sstevel@tonic-gate /* I: the maximum amount of seconds we use an adopted lease */
1077c478bd9Sstevel@tonic-gate #define	DHCP_ADOPT_LEASE_MAX	(60*60)		/* one hour */
1087c478bd9Sstevel@tonic-gate 
1097c478bd9Sstevel@tonic-gate /* I: number of seconds grandparent waits for child to finish adoption. */
1107c478bd9Sstevel@tonic-gate #define	DHCP_ADOPT_SLEEP	30
1117c478bd9Sstevel@tonic-gate 
1127c478bd9Sstevel@tonic-gate /* I: the maximum amount of milliseconds to wait for an ipc request */
1137c478bd9Sstevel@tonic-gate #define	DHCP_IPC_REQUEST_WAIT	(3*1000)	/* three seconds */
1147c478bd9Sstevel@tonic-gate 
1157c478bd9Sstevel@tonic-gate /*
116*d04ccbb3Scarlsonj  * DHCPv6 timer and retransmit values from RFC 3315.
117*d04ccbb3Scarlsonj  */
118*d04ccbb3Scarlsonj #define	DHCPV6_SOL_MAX_DELAY	1000	/* Max delay of first Solicit; 1s */
119*d04ccbb3Scarlsonj #define	DHCPV6_CNF_MAX_DELAY	1000	/* Max delay of first Confirm; 1s */
120*d04ccbb3Scarlsonj #define	DHCPV6_INF_MAX_DELAY	1000	/* Max delay of first Info-req; 1s */
121*d04ccbb3Scarlsonj #define	DHCPV6_SOL_TIMEOUT	1000	/* Initial Solicit timeout; 1s */
122*d04ccbb3Scarlsonj #define	DHCPV6_REQ_TIMEOUT	1000	/* Initial Request timeout; 1s */
123*d04ccbb3Scarlsonj #define	DHCPV6_CNF_TIMEOUT	1000	/* Initial Confirm timeout; 1s */
124*d04ccbb3Scarlsonj #define	DHCPV6_REN_TIMEOUT	10000	/* Initial Renew timeout; 10s */
125*d04ccbb3Scarlsonj #define	DHCPV6_REB_TIMEOUT	10000	/* Initial Rebind timeout; 10s */
126*d04ccbb3Scarlsonj #define	DHCPV6_INF_TIMEOUT	1000	/* Initial Info-req timeout; 1s */
127*d04ccbb3Scarlsonj #define	DHCPV6_REL_TIMEOUT	1000	/* Initial Release timeout; 1s */
128*d04ccbb3Scarlsonj #define	DHCPV6_DEC_TIMEOUT	1000	/* Initial Decline timeout; 1s */
129*d04ccbb3Scarlsonj #define	DHCPV6_SOL_MAX_RT	120000	/* Max Solicit timeout; 2m */
130*d04ccbb3Scarlsonj #define	DHCPV6_REQ_MAX_RT	30000	/* Max Request timeout; 30s */
131*d04ccbb3Scarlsonj #define	DHCPV6_CNF_MAX_RT	4000	/* Max Confirm timeout; 4s */
132*d04ccbb3Scarlsonj #define	DHCPV6_REN_MAX_RT	600000	/* Max Renew timeout; 5m */
133*d04ccbb3Scarlsonj #define	DHCPV6_REB_MAX_RT	600000	/* Max Rebind timeout; 5m */
134*d04ccbb3Scarlsonj #define	DHCPV6_INF_MAX_RT	120000	/* Max Info-req timeout; 2m */
135*d04ccbb3Scarlsonj #define	DHCPV6_CNF_MAX_RD	10000	/* Max Confirm duration; 10s */
136*d04ccbb3Scarlsonj #define	DHCPV6_REQ_MAX_RC	10	/* Max Request attempts */
137*d04ccbb3Scarlsonj #define	DHCPV6_REL_MAX_RC	5	/* Max Release attempts */
138*d04ccbb3Scarlsonj #define	DHCPV6_DEC_MAX_RC	5	/* Max Decline attempts */
139*d04ccbb3Scarlsonj 
140*d04ccbb3Scarlsonj /*
1417c478bd9Sstevel@tonic-gate  * reasons for why iu_handle_events() returned
1427c478bd9Sstevel@tonic-gate  */
1437c478bd9Sstevel@tonic-gate enum { DHCP_REASON_INACTIVITY, DHCP_REASON_SIGNAL, DHCP_REASON_TERMINATE };
1447c478bd9Sstevel@tonic-gate 
1457c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1467c478bd9Sstevel@tonic-gate }
1477c478bd9Sstevel@tonic-gate #endif
1487c478bd9Sstevel@tonic-gate 
1497c478bd9Sstevel@tonic-gate #endif	/* AGENT_H */
150