xref: /titanic_44/usr/src/cmd/cmd-inet/sbin/dhcpagent/packet.h (revision 45916cd2fec6e79bca5dee0421bd39e3c2910d1e)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright (c) 1999-2001 by Sun Microsystems, Inc.
24  * All rights reserved.
25  */
26 
27 #ifndef	_PACKET_H
28 #define	_PACKET_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <sys/types.h>
33 #include <sys/sysmacros.h>		/* MIN, MAX, ... */
34 #include <netinet/in.h>
35 #include <netinet/dhcp.h>
36 #include <dhcp_impl.h>
37 
38 #include "agent.h"
39 
40 /*
41  * packet.[ch] contain routines for manipulating, setting, and
42  * transmitting DHCP/BOOTP packets.  see packet.c for descriptions on
43  * how to use the exported functions.
44  */
45 
46 #ifdef	__cplusplus
47 extern "C" {
48 #endif
49 
50 struct ifslist;				/* forward declaration */
51 
52 /*
53  * data type for recv_pkt().  needed because we may want to wait for
54  * several kinds of packets at once, and the existing enumeration of
55  * DHCP packet types does not provide a way to do that easily.  here,
56  * we light a different bit in the enumeration for each type of packet
57  * we want to receive.
58  */
59 
60 typedef enum {
61 
62 	DHCP_PUNTYPED	= 0x001,	/* untyped (BOOTP) message */
63 	DHCP_PDISCOVER	= 0x002,
64 	DHCP_POFFER 	= 0x004,
65 	DHCP_PREQUEST	= 0x008,
66 	DHCP_PDECLINE	= 0x010,
67 	DHCP_PACK	= 0x020,
68 	DHCP_PNAK	= 0x040,
69 	DHCP_PRELEASE	= 0x080,
70 	DHCP_PINFORM	= 0x100
71 
72 } dhcp_message_type_t;
73 
74 /*
75  * a dhcp_pkt_t is (right now) what is used by the packet manipulation
76  * functions.  while the structure is not strictly necessary, it allows
77  * a better separation of functionality since metadata about the packet
78  * (such as its current length) is stored along with the packet.
79  */
80 
81 typedef struct dhcp_pkt {
82 
83 	PKT		*pkt;		/* the real underlying packet */
84 	unsigned int	pkt_max_len; 	/* its maximum length */
85 	unsigned int	pkt_cur_len;	/* its current length */
86 
87 } dhcp_pkt_t;
88 
89 /*
90  * a `stop_func_t' is used by parts of dhcpagent that use the
91  * retransmission capability of send_pkt().  this makes it so the
92  * callers of send_pkt() decide when to stop retransmitting, which
93  * makes more sense than hardcoding their instance-specific cases into
94  * packet.c
95  */
96 
97 typedef boolean_t stop_func_t(struct ifslist *, unsigned int);
98 
99 dhcp_pkt_t	*init_pkt(struct ifslist *, uchar_t);
100 void		add_pkt_opt(dhcp_pkt_t *, uchar_t, const void *, uchar_t);
101 void		add_pkt_opt16(dhcp_pkt_t *, uchar_t, uint16_t);
102 void		add_pkt_opt32(dhcp_pkt_t *, uchar_t, uint32_t);
103 void		free_pkt_list(PKT_LIST **);
104 void		remove_from_pkt_list(PKT_LIST **, PKT_LIST *);
105 void		stop_pkt_retransmission(struct ifslist *);
106 int		recv_pkt(struct ifslist *, int, dhcp_message_type_t, boolean_t);
107 int		send_pkt(struct ifslist *, dhcp_pkt_t *, in_addr_t,
108 		    stop_func_t *);
109 void		get_pkt_times(PKT_LIST *, uint32_t *, uint32_t *, uint32_t *);
110 
111 #ifdef	__cplusplus
112 }
113 #endif
114 
115 #endif	/* _PACKET_H */
116