xref: /onnv-gate/usr/src/cmd/cmd-inet/sbin/dhcpagent/packet.h (revision 3431:9f2d277dcffa)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*3431Scarlsonj  * Common Development and Distribution License (the "License").
6*3431Scarlsonj  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*3431Scarlsonj  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23*3431Scarlsonj  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #ifndef	_PACKET_H
270Sstevel@tonic-gate #define	_PACKET_H
280Sstevel@tonic-gate 
290Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
300Sstevel@tonic-gate 
310Sstevel@tonic-gate #include <sys/types.h>
320Sstevel@tonic-gate #include <netinet/in.h>
330Sstevel@tonic-gate #include <netinet/dhcp.h>
34*3431Scarlsonj #include <netinet/dhcp6.h>
350Sstevel@tonic-gate #include <dhcp_impl.h>
360Sstevel@tonic-gate 
37*3431Scarlsonj #include "common.h"
380Sstevel@tonic-gate 
390Sstevel@tonic-gate /*
400Sstevel@tonic-gate  * packet.[ch] contain routines for manipulating, setting, and
410Sstevel@tonic-gate  * transmitting DHCP/BOOTP packets.  see packet.c for descriptions on
420Sstevel@tonic-gate  * how to use the exported functions.
430Sstevel@tonic-gate  */
440Sstevel@tonic-gate 
450Sstevel@tonic-gate #ifdef	__cplusplus
460Sstevel@tonic-gate extern "C" {
470Sstevel@tonic-gate #endif
480Sstevel@tonic-gate 
490Sstevel@tonic-gate /*
500Sstevel@tonic-gate  * data type for recv_pkt().  needed because we may want to wait for
510Sstevel@tonic-gate  * several kinds of packets at once, and the existing enumeration of
520Sstevel@tonic-gate  * DHCP packet types does not provide a way to do that easily.  here,
530Sstevel@tonic-gate  * we light a different bit in the enumeration for each type of packet
540Sstevel@tonic-gate  * we want to receive.
55*3431Scarlsonj  *
56*3431Scarlsonj  * Note that for DHCPv6, types 4 (CONFIRM), 5 (RENEW), 6 (REBIND), 12
57*3431Scarlsonj  * (RELAY-FORW, and 13 (RELAY-REPL) are not in the table.  They're never
58*3431Scarlsonj  * received by a client, so there's no reason to process them.  (SOLICIT,
59*3431Scarlsonj  * REQUEST, DECLINE, RELEASE, and INFORMATION-REQUEST are also never seen by
60*3431Scarlsonj  * clients, but are included for consistency.)
61*3431Scarlsonj  *
62*3431Scarlsonj  * Note also that the symbols are named for the DHCPv4 message types, and that
63*3431Scarlsonj  * DHCPv6 has analogous message types.
640Sstevel@tonic-gate  */
650Sstevel@tonic-gate 
660Sstevel@tonic-gate typedef enum {
670Sstevel@tonic-gate 
680Sstevel@tonic-gate 	DHCP_PUNTYPED	= 0x001,	/* untyped (BOOTP) message */
69*3431Scarlsonj 	DHCP_PDISCOVER	= 0x002,	/* in v6: SOLICIT (1) */
70*3431Scarlsonj 	DHCP_POFFER 	= 0x004,	/* in v6: ADVERTISE (2) */
71*3431Scarlsonj 	DHCP_PREQUEST	= 0x008,	/* in v6: REQUEST (3) */
72*3431Scarlsonj 	DHCP_PDECLINE	= 0x010,	/* in v6: DECLINE (9) */
73*3431Scarlsonj 	DHCP_PACK	= 0x020,	/* in v6: REPLY (7), status == 0 */
74*3431Scarlsonj 	DHCP_PNAK	= 0x040,	/* in v6: REPLY (7), status != 0 */
75*3431Scarlsonj 	DHCP_PRELEASE	= 0x080,	/* in v6: RELEASE (8) */
76*3431Scarlsonj 	DHCP_PINFORM	= 0x100,	/* in v6: INFORMATION-REQUEST (11) */
77*3431Scarlsonj 	DHCP_PRECONFIG	= 0x200		/* v6 only: RECONFIGURE (10) */
780Sstevel@tonic-gate 
790Sstevel@tonic-gate } dhcp_message_type_t;
800Sstevel@tonic-gate 
810Sstevel@tonic-gate /*
82*3431Scarlsonj  * A dhcp_pkt_t is used by the output-side packet manipulation functions.
83*3431Scarlsonj  * While the structure is not strictly necessary, it allows a better separation
84*3431Scarlsonj  * of functionality since metadata about the packet (such as its current
85*3431Scarlsonj  * length) is stored along with the packet.
86*3431Scarlsonj  *
87*3431Scarlsonj  * Note that 'pkt' points to a dhcpv6_message_t if the packet is IPv6.
880Sstevel@tonic-gate  */
890Sstevel@tonic-gate 
90*3431Scarlsonj typedef struct dhcp_pkt_s {
910Sstevel@tonic-gate 	PKT		*pkt;		/* the real underlying packet */
920Sstevel@tonic-gate 	unsigned int	pkt_max_len; 	/* its maximum length */
930Sstevel@tonic-gate 	unsigned int	pkt_cur_len;	/* its current length */
94*3431Scarlsonj 	boolean_t	pkt_isv6;
950Sstevel@tonic-gate } dhcp_pkt_t;
960Sstevel@tonic-gate 
970Sstevel@tonic-gate /*
980Sstevel@tonic-gate  * a `stop_func_t' is used by parts of dhcpagent that use the
990Sstevel@tonic-gate  * retransmission capability of send_pkt().  this makes it so the
1000Sstevel@tonic-gate  * callers of send_pkt() decide when to stop retransmitting, which
1010Sstevel@tonic-gate  * makes more sense than hardcoding their instance-specific cases into
1020Sstevel@tonic-gate  * packet.c
1030Sstevel@tonic-gate  */
1040Sstevel@tonic-gate 
105*3431Scarlsonj typedef boolean_t stop_func_t(dhcp_smach_t *, unsigned int);
1060Sstevel@tonic-gate 
107*3431Scarlsonj /*
108*3431Scarlsonj  * Default I/O and interface control sockets.
109*3431Scarlsonj  */
110*3431Scarlsonj extern int v6_sock_fd;
111*3431Scarlsonj extern int v4_sock_fd;
112*3431Scarlsonj 
113*3431Scarlsonj extern const in6_addr_t ipv6_all_dhcp_relay_and_servers;
114*3431Scarlsonj extern const in6_addr_t my_in6addr_any;
115*3431Scarlsonj 
116*3431Scarlsonj PKT_LIST	*alloc_pkt_entry(size_t, boolean_t);
117*3431Scarlsonj void		free_pkt_entry(PKT_LIST *);
1180Sstevel@tonic-gate void		free_pkt_list(PKT_LIST **);
119*3431Scarlsonj uchar_t		pkt_recv_type(const PKT_LIST *);
120*3431Scarlsonj uint_t		pkt_get_xid(const PKT *, boolean_t);
121*3431Scarlsonj dhcp_pkt_t	*init_pkt(dhcp_smach_t *, uchar_t);
122*3431Scarlsonj boolean_t	remove_pkt_opt(dhcp_pkt_t *, uint_t);
123*3431Scarlsonj boolean_t	update_v6opt_len(dhcpv6_option_t *, int);
124*3431Scarlsonj void		*add_pkt_opt(dhcp_pkt_t *, uint_t, const void *, uint_t);
125*3431Scarlsonj void		*add_pkt_subopt(dhcp_pkt_t *, dhcpv6_option_t *, uint_t,
126*3431Scarlsonj 		    const void *, uint_t);
127*3431Scarlsonj void		*add_pkt_opt16(dhcp_pkt_t *, uint_t, uint16_t);
128*3431Scarlsonj void		*add_pkt_opt32(dhcp_pkt_t *, uint_t, uint32_t);
129*3431Scarlsonj void		*add_pkt_prl(dhcp_pkt_t *, dhcp_smach_t *);
130*3431Scarlsonj boolean_t	add_pkt_lif(dhcp_pkt_t *, dhcp_lif_t *, int, const char *);
131*3431Scarlsonj void		stop_pkt_retransmission(dhcp_smach_t *);
132*3431Scarlsonj void		retransmit_now(dhcp_smach_t *);
133*3431Scarlsonj PKT_LIST	*recv_pkt(int, int, boolean_t, boolean_t);
134*3431Scarlsonj boolean_t	pkt_v4_match(uchar_t, dhcp_message_type_t);
135*3431Scarlsonj void		pkt_smach_enqueue(dhcp_smach_t *, PKT_LIST *);
136*3431Scarlsonj boolean_t	send_pkt(dhcp_smach_t *, dhcp_pkt_t *, in_addr_t,
1370Sstevel@tonic-gate 		    stop_func_t *);
138*3431Scarlsonj boolean_t	send_pkt_v6(dhcp_smach_t *, dhcp_pkt_t *, in6_addr_t,
139*3431Scarlsonj 		    stop_func_t *, uint_t, uint_t);
140*3431Scarlsonj boolean_t	dhcp_ip_default(void);
1410Sstevel@tonic-gate 
1420Sstevel@tonic-gate #ifdef	__cplusplus
1430Sstevel@tonic-gate }
1440Sstevel@tonic-gate #endif
1450Sstevel@tonic-gate 
1460Sstevel@tonic-gate #endif	/* _PACKET_H */
147