xref: /titanic_41/usr/src/cmd/cmd-inet/sbin/dhcpagent/agent.h (revision d04ccbb3f3163ae5962a8b7465d9796bff6ca434)
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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate #include <sys/types.h>
327c478bd9Sstevel@tonic-gate #include <libinetutil.h>
33*d04ccbb3Scarlsonj #include <dhcpagent_ipc.h>
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate /*
367c478bd9Sstevel@tonic-gate  * agent.h contains general symbols that should be available to all
377c478bd9Sstevel@tonic-gate  * source programs that are part of the agent.  in general, files
387c478bd9Sstevel@tonic-gate  * specific to a given collection of code (such as interface.h or
397c478bd9Sstevel@tonic-gate  * dhcpmsg.h) are to be preferred to this dumping ground.  use only
407c478bd9Sstevel@tonic-gate  * when necessary.
417c478bd9Sstevel@tonic-gate  */
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
447c478bd9Sstevel@tonic-gate extern "C" {
457c478bd9Sstevel@tonic-gate #endif
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate /*
487c478bd9Sstevel@tonic-gate  * global variables: `tq' and `eh' represent the global timer queue
497c478bd9Sstevel@tonic-gate  * and event handler, as described in the README. `class_id' is our
507c478bd9Sstevel@tonic-gate  * vendor class id set early on in main().  `inactivity_id' is the
517c478bd9Sstevel@tonic-gate  * timer id of the global inactivity timer, which shuts down the agent
52*d04ccbb3Scarlsonj  * if there are no state machines to manage for DHCP_INACTIVITY_WAIT
537c478bd9Sstevel@tonic-gate  * seconds. `grandparent' is the pid of the original process when in
5469bb4bb4Scarlsonj  * adopt mode.  `rtsock_fd' is the global routing socket file descriptor.
557c478bd9Sstevel@tonic-gate  */
567c478bd9Sstevel@tonic-gate 
577c478bd9Sstevel@tonic-gate extern iu_tq_t		*tq;
587c478bd9Sstevel@tonic-gate extern iu_eh_t		*eh;
597c478bd9Sstevel@tonic-gate extern char		*class_id;
607c478bd9Sstevel@tonic-gate extern int		class_id_len;
617c478bd9Sstevel@tonic-gate extern iu_timer_id_t	inactivity_id;
627c478bd9Sstevel@tonic-gate extern pid_t		grandparent;
6369bb4bb4Scarlsonj extern int		rtsock_fd;
647c478bd9Sstevel@tonic-gate 
657c478bd9Sstevel@tonic-gate boolean_t	drain_script(iu_eh_t *, void *);
66*d04ccbb3Scarlsonj boolean_t	check_cmd_allowed(DHCPSTATE, dhcp_ipc_type_t);
677c478bd9Sstevel@tonic-gate 
687c478bd9Sstevel@tonic-gate /*
697c478bd9Sstevel@tonic-gate  * global tunable parameters.  an `I' in the preceding comment indicates
707c478bd9Sstevel@tonic-gate  * an implementation artifact; a `R' in the preceding comment indicates
717c478bd9Sstevel@tonic-gate  * that the value was suggested (or required) by RFC2131.
727c478bd9Sstevel@tonic-gate  */
737c478bd9Sstevel@tonic-gate 
747c478bd9Sstevel@tonic-gate /* I: how many seconds to wait before restarting DHCP on an interface */
757c478bd9Sstevel@tonic-gate #define	DHCP_RESTART_WAIT	10
767c478bd9Sstevel@tonic-gate 
777c478bd9Sstevel@tonic-gate /*
787c478bd9Sstevel@tonic-gate  * I: the maximum number of milliseconds to wait before SELECTING on an
797c478bd9Sstevel@tonic-gate  * interface. RFC2131 recommends a random wait of between one and ten seconds,
807c478bd9Sstevel@tonic-gate  * to speed up DHCP at boot we wait between zero and two seconds.
817c478bd9Sstevel@tonic-gate  */
827c478bd9Sstevel@tonic-gate #define	DHCP_SELECT_WAIT	2000
837c478bd9Sstevel@tonic-gate 
847c478bd9Sstevel@tonic-gate /* R: how many seconds before lease expiration we give up trying to rebind */
857c478bd9Sstevel@tonic-gate #define	DHCP_REBIND_MIN		60
867c478bd9Sstevel@tonic-gate 
877c478bd9Sstevel@tonic-gate /* I: seconds to wait retrying dhcp_expire() if uncancellable async event */
887c478bd9Sstevel@tonic-gate #define	DHCP_EXPIRE_WAIT	10
897c478bd9Sstevel@tonic-gate 
907c478bd9Sstevel@tonic-gate /* R: approximate percentage of lease time to wait until RENEWING state */
917c478bd9Sstevel@tonic-gate #define	DHCP_T1_FACT		.5
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate /* R: approximate percentage of lease time to wait until REBINDING state */
947c478bd9Sstevel@tonic-gate #define	DHCP_T2_FACT		.875
957c478bd9Sstevel@tonic-gate 
967c478bd9Sstevel@tonic-gate /* I: number of REQUEST attempts before assuming something is awry */
977c478bd9Sstevel@tonic-gate #define	DHCP_MAX_REQUESTS	4
987c478bd9Sstevel@tonic-gate 
997c478bd9Sstevel@tonic-gate /* I: epsilon in seconds used to check if old and new lease times are same */
1007c478bd9Sstevel@tonic-gate #define	DHCP_LEASE_EPS		30
1017c478bd9Sstevel@tonic-gate 
1027c478bd9Sstevel@tonic-gate /* I: if lease is not being extended, seconds left before alerting user */
103985c053eSmeem #define	DHCP_LEASE_ERROR_THRESH	(60*60)	/* one hour */
1047c478bd9Sstevel@tonic-gate 
1057c478bd9Sstevel@tonic-gate /* I: how many seconds before bailing out if there's no work to do */
1067c478bd9Sstevel@tonic-gate #define	DHCP_INACTIVITY_WAIT	(60*3)		/* three minutes */
1077c478bd9Sstevel@tonic-gate 
1087c478bd9Sstevel@tonic-gate /* I: the maximum amount of seconds we use an adopted lease */
1097c478bd9Sstevel@tonic-gate #define	DHCP_ADOPT_LEASE_MAX	(60*60)		/* one hour */
1107c478bd9Sstevel@tonic-gate 
1117c478bd9Sstevel@tonic-gate /* I: number of seconds grandparent waits for child to finish adoption. */
1127c478bd9Sstevel@tonic-gate #define	DHCP_ADOPT_SLEEP	30
1137c478bd9Sstevel@tonic-gate 
1147c478bd9Sstevel@tonic-gate /* I: the maximum amount of milliseconds to wait for an ipc request */
1157c478bd9Sstevel@tonic-gate #define	DHCP_IPC_REQUEST_WAIT	(3*1000)	/* three seconds */
1167c478bd9Sstevel@tonic-gate 
1177c478bd9Sstevel@tonic-gate /*
118*d04ccbb3Scarlsonj  * DHCPv6 timer and retransmit values from RFC 3315.
119*d04ccbb3Scarlsonj  */
120*d04ccbb3Scarlsonj #define	DHCPV6_SOL_MAX_DELAY	1000	/* Max delay of first Solicit; 1s */
121*d04ccbb3Scarlsonj #define	DHCPV6_CNF_MAX_DELAY	1000	/* Max delay of first Confirm; 1s */
122*d04ccbb3Scarlsonj #define	DHCPV6_INF_MAX_DELAY	1000	/* Max delay of first Info-req; 1s */
123*d04ccbb3Scarlsonj #define	DHCPV6_SOL_TIMEOUT	1000	/* Initial Solicit timeout; 1s */
124*d04ccbb3Scarlsonj #define	DHCPV6_REQ_TIMEOUT	1000	/* Initial Request timeout; 1s */
125*d04ccbb3Scarlsonj #define	DHCPV6_CNF_TIMEOUT	1000	/* Initial Confirm timeout; 1s */
126*d04ccbb3Scarlsonj #define	DHCPV6_REN_TIMEOUT	10000	/* Initial Renew timeout; 10s */
127*d04ccbb3Scarlsonj #define	DHCPV6_REB_TIMEOUT	10000	/* Initial Rebind timeout; 10s */
128*d04ccbb3Scarlsonj #define	DHCPV6_INF_TIMEOUT	1000	/* Initial Info-req timeout; 1s */
129*d04ccbb3Scarlsonj #define	DHCPV6_REL_TIMEOUT	1000	/* Initial Release timeout; 1s */
130*d04ccbb3Scarlsonj #define	DHCPV6_DEC_TIMEOUT	1000	/* Initial Decline timeout; 1s */
131*d04ccbb3Scarlsonj #define	DHCPV6_SOL_MAX_RT	120000	/* Max Solicit timeout; 2m */
132*d04ccbb3Scarlsonj #define	DHCPV6_REQ_MAX_RT	30000	/* Max Request timeout; 30s */
133*d04ccbb3Scarlsonj #define	DHCPV6_CNF_MAX_RT	4000	/* Max Confirm timeout; 4s */
134*d04ccbb3Scarlsonj #define	DHCPV6_REN_MAX_RT	600000	/* Max Renew timeout; 5m */
135*d04ccbb3Scarlsonj #define	DHCPV6_REB_MAX_RT	600000	/* Max Rebind timeout; 5m */
136*d04ccbb3Scarlsonj #define	DHCPV6_INF_MAX_RT	120000	/* Max Info-req timeout; 2m */
137*d04ccbb3Scarlsonj #define	DHCPV6_CNF_MAX_RD	10000	/* Max Confirm duration; 10s */
138*d04ccbb3Scarlsonj #define	DHCPV6_REQ_MAX_RC	10	/* Max Request attempts */
139*d04ccbb3Scarlsonj #define	DHCPV6_REL_MAX_RC	5	/* Max Release attempts */
140*d04ccbb3Scarlsonj #define	DHCPV6_DEC_MAX_RC	5	/* Max Decline attempts */
141*d04ccbb3Scarlsonj 
142*d04ccbb3Scarlsonj /*
1437c478bd9Sstevel@tonic-gate  * reasons for why iu_handle_events() returned
1447c478bd9Sstevel@tonic-gate  */
1457c478bd9Sstevel@tonic-gate enum { DHCP_REASON_INACTIVITY, DHCP_REASON_SIGNAL, DHCP_REASON_TERMINATE };
1467c478bd9Sstevel@tonic-gate 
1477c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1487c478bd9Sstevel@tonic-gate }
1497c478bd9Sstevel@tonic-gate #endif
1507c478bd9Sstevel@tonic-gate 
1517c478bd9Sstevel@tonic-gate #endif	/* AGENT_H */
152