xref: /illumos-gate/usr/src/common/net/dhcp/dhcp_impl.h (revision b31320a7)
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
5d04ccbb3Scarlsonj  * Common Development and Distribution License (the "License").
6d04ccbb3Scarlsonj  * 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 /*
22d04ccbb3Scarlsonj  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
24*b31320a7SChris Fraire  * Copyright (c) 2016, Chris Fraire <cfraire@me.com>.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #ifndef	_DHCP_IMPL_H
287c478bd9Sstevel@tonic-gate #define	_DHCP_IMPL_H
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate /*
317c478bd9Sstevel@tonic-gate  * Common definitions used by Sun DHCP implementations
327c478bd9Sstevel@tonic-gate  */
337c478bd9Sstevel@tonic-gate 
347c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
357c478bd9Sstevel@tonic-gate extern "C" {
367c478bd9Sstevel@tonic-gate #endif
377c478bd9Sstevel@tonic-gate 
387c478bd9Sstevel@tonic-gate #include <sys/types.h>
397c478bd9Sstevel@tonic-gate #include <sys/socket.h>
407c478bd9Sstevel@tonic-gate #include <netinet/in.h>
417c478bd9Sstevel@tonic-gate #include <netinet/udp.h>
427c478bd9Sstevel@tonic-gate #include <netinet/dhcp.h>
43d04ccbb3Scarlsonj #include <netinet/dhcp6.h>
447c478bd9Sstevel@tonic-gate #include <dhcp_symbol_common.h>
457c478bd9Sstevel@tonic-gate #include <sys/sunos_dhcp_class.h>
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate /* Packet fields */
487c478bd9Sstevel@tonic-gate #define	CD_PACKET_START		0
497c478bd9Sstevel@tonic-gate #define	CD_POPCODE		0	/* packet opcode */
507c478bd9Sstevel@tonic-gate #define	CD_PHTYPE		1	/* packet header type */
517c478bd9Sstevel@tonic-gate #define	CD_PHLEN		2	/* packet header len */
527c478bd9Sstevel@tonic-gate #define	CD_PHOPS		3	/* packet header len */
537c478bd9Sstevel@tonic-gate #define	CD_PXID			4	/* packet hops */
547c478bd9Sstevel@tonic-gate #define	CD_PSECS		8	/* packet xid */
557c478bd9Sstevel@tonic-gate #define	CD_PFLAGS		10	/* packet secs */
567c478bd9Sstevel@tonic-gate #define	CD_PCIADDR		12	/* packet flags */
577c478bd9Sstevel@tonic-gate #define	CD_YIADDR		16	/* client's ip address */
587c478bd9Sstevel@tonic-gate #define	CD_SIADDR		20	/* Bootserver's ip address */
597c478bd9Sstevel@tonic-gate #define	CD_GIADDR		24	/* BOOTP relay agent address */
607c478bd9Sstevel@tonic-gate #define	CD_PCHADDR		28	/* BOOTP relay agent address */
617c478bd9Sstevel@tonic-gate #define	CD_SNAME		44	/* Hostname of Bootserver, or opts */
627c478bd9Sstevel@tonic-gate #define	CD_BOOTFILE		108	/* File to boot or opts */
637c478bd9Sstevel@tonic-gate #define	CD_PCOOKIE		236	/* packet cookie */
647c478bd9Sstevel@tonic-gate #define	CD_POPTIONS		240	/* packet options */
657c478bd9Sstevel@tonic-gate #define	CD_PACKET_END		CD_POPTIONS
667c478bd9Sstevel@tonic-gate 
677c478bd9Sstevel@tonic-gate /* Internal server options */
687c478bd9Sstevel@tonic-gate #define	CD_INTRNL_START		1024
697c478bd9Sstevel@tonic-gate #define	CD_BOOL_HOSTNAME	1024	/* Entry wants hostname (Nameserv) */
707c478bd9Sstevel@tonic-gate #define	CD_BOOL_LEASENEG	1025	/* Entry's lease is negotiable */
717c478bd9Sstevel@tonic-gate #define	CD_BOOL_ECHO_VCLASS	1026	/* Echo Vendor class back to Entry */
727c478bd9Sstevel@tonic-gate #define	CD_BOOTPATH		1027	/* prefix path to File to boot */
737c478bd9Sstevel@tonic-gate #define	CD_INTRNL_END		1027
747c478bd9Sstevel@tonic-gate 
757c478bd9Sstevel@tonic-gate /* Error codes that could be generated while parsing packets */
767c478bd9Sstevel@tonic-gate #define	DHCP_ERR_OFFSET		512
777c478bd9Sstevel@tonic-gate #define	DHCP_GARBLED_MSG_TYPE	(DHCP_ERR_OFFSET+0)
787c478bd9Sstevel@tonic-gate #define	DHCP_WRONG_MSG_TYPE	(DHCP_ERR_OFFSET+1)
797c478bd9Sstevel@tonic-gate #define	DHCP_BAD_OPT_OVLD	(DHCP_ERR_OFFSET+2)
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate /*
827c478bd9Sstevel@tonic-gate  * Arbitrary "maximum" client ID length (in bytes), used by various bits
837c478bd9Sstevel@tonic-gate  * of the standalone code.  This needs to go away someday.
847c478bd9Sstevel@tonic-gate  */
857c478bd9Sstevel@tonic-gate #define	DHCP_MAX_CID_LEN	64
867c478bd9Sstevel@tonic-gate 
877c478bd9Sstevel@tonic-gate /*
887c478bd9Sstevel@tonic-gate  * Generic DHCP option structure.
897c478bd9Sstevel@tonic-gate  */
907c478bd9Sstevel@tonic-gate typedef struct {
917c478bd9Sstevel@tonic-gate 	uint8_t    code;
927c478bd9Sstevel@tonic-gate 	uint8_t    len;
937c478bd9Sstevel@tonic-gate 	uint8_t    value[1];
947c478bd9Sstevel@tonic-gate } DHCP_OPT;
957c478bd9Sstevel@tonic-gate 
96*b31320a7SChris Fraire /*
97*b31320a7SChris Fraire  * Defines the size of DHCP_OPT code + len
98*b31320a7SChris Fraire  */
99*b31320a7SChris Fraire #define	DHCP_OPT_META_LEN	2
100*b31320a7SChris Fraire 
101d04ccbb3Scarlsonj typedef union sockaddr46_s {
102d04ccbb3Scarlsonj 	struct sockaddr_in v4;
103d04ccbb3Scarlsonj 	struct sockaddr_in6 v6;
104d04ccbb3Scarlsonj } sockaddr46_t;
105d04ccbb3Scarlsonj 
1067c478bd9Sstevel@tonic-gate /*
1077c478bd9Sstevel@tonic-gate  * Generic DHCP packet list. Ensure that _REENTRANT bracketed code stays at
1087c478bd9Sstevel@tonic-gate  * bottom of this definition - the client doesn't include it. Scan.c in
1097c478bd9Sstevel@tonic-gate  * libdhcp isn't aware of it either...
110d04ccbb3Scarlsonj  *
111d04ccbb3Scarlsonj  * The PKT * pointer here actually points to a dhcpv6_message_t if the packet
112d04ccbb3Scarlsonj  * is DHCPv6.  We assume that PKT * the same or stricter alignment
113d04ccbb3Scarlsonj  * requirements, and that the unused elements are not a significant burden.
1147c478bd9Sstevel@tonic-gate  */
1157c478bd9Sstevel@tonic-gate #define	MAX_PKT_LIST	5	/* maximum list size */
1167c478bd9Sstevel@tonic-gate typedef struct  dhcp_list {
117d04ccbb3Scarlsonj 	struct dhcp_list 	*next;		/* keep first and in this */
118d04ccbb3Scarlsonj 	struct dhcp_list 	*prev;		/* order for insque/remque */
119d04ccbb3Scarlsonj 
1207c478bd9Sstevel@tonic-gate 	PKT			*pkt;		/* client packet */
1217c478bd9Sstevel@tonic-gate 	uint_t			len;		/* packet len */
1227c478bd9Sstevel@tonic-gate 	int			rfc1048;	/* RFC1048 options - boolean */
1237c478bd9Sstevel@tonic-gate 	uint8_t			offset;		/* BOOTP packet offset */
124d04ccbb3Scarlsonj 	uint8_t			isv6;		/* DHCPv6 packet - boolean */
1257c478bd9Sstevel@tonic-gate 				/*
1267c478bd9Sstevel@tonic-gate 				 * standard/site options
1277c478bd9Sstevel@tonic-gate 				 */
1287c478bd9Sstevel@tonic-gate 	DHCP_OPT		*opts[DHCP_LAST_OPT + 1];
1297c478bd9Sstevel@tonic-gate 
1307c478bd9Sstevel@tonic-gate 				/*
1317c478bd9Sstevel@tonic-gate 				 * Vendor specific options (client only)
1327c478bd9Sstevel@tonic-gate 				 */
1337c478bd9Sstevel@tonic-gate 	DHCP_OPT		*vs[VS_OPTION_END - VS_OPTION_START + 1];
1347c478bd9Sstevel@tonic-gate 
1357c478bd9Sstevel@tonic-gate 	struct in_addr		off_ip;		/* Address OFFERed */
1367c478bd9Sstevel@tonic-gate 
137d04ccbb3Scarlsonj 	uint_t			ifindex; /* received ifindex (if any) */
138d04ccbb3Scarlsonj 	sockaddr46_t		pktfrom; /* source (peer) address on input */
139d04ccbb3Scarlsonj 	sockaddr46_t		pktto;	/* destination (local) address */
140d04ccbb3Scarlsonj 
1417c478bd9Sstevel@tonic-gate } PKT_LIST;
1427c478bd9Sstevel@tonic-gate 
1437c478bd9Sstevel@tonic-gate extern int dhcp_options_scan(PKT_LIST *, boolean_t);
1447c478bd9Sstevel@tonic-gate extern boolean_t dhcp_getinfo_pl(PKT_LIST *, uchar_t, uint16_t, uint16_t,
1457c478bd9Sstevel@tonic-gate     void *, size_t *);
146d04ccbb3Scarlsonj extern dhcpv6_option_t *dhcpv6_find_option(const void *, size_t,
147d04ccbb3Scarlsonj     const dhcpv6_option_t *, uint16_t, uint_t *);
148d04ccbb3Scarlsonj extern dhcpv6_option_t *dhcpv6_pkt_option(const PKT_LIST *,
149d04ccbb3Scarlsonj     const dhcpv6_option_t *, uint16_t, uint_t *);
1507c478bd9Sstevel@tonic-gate 
1517c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1527c478bd9Sstevel@tonic-gate }
1537c478bd9Sstevel@tonic-gate #endif
1547c478bd9Sstevel@tonic-gate 
1557c478bd9Sstevel@tonic-gate #endif	/* _DHCP_IMPL_H */
156