1#ifndef _S_IPCONFIGD_TYPES_H
2#define _S_IPCONFIGD_TYPES_H
3
4/*
5 * Copyright (c) 2000-2009 Apple Inc. All rights reserved.
6 *
7 * @APPLE_LICENSE_HEADER_START@
8 *
9 * This file contains Original Code and/or Modifications of Original Code
10 * as defined in and that are subject to the Apple Public Source License
11 * Version 2.0 (the 'License'). You may not use this file except in
12 * compliance with the License. Please obtain a copy of the License at
13 * http://www.opensource.apple.com/apsl/ and read it before using this
14 * file.
15 *
16 * The Original Code and all software distributed under the License are
17 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
18 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
19 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
21 * Please see the License for the specific language governing rights and
22 * limitations under the License.
23 *
24 * @APPLE_LICENSE_HEADER_END@
25 */
26
27#include <mach/boolean.h>
28#include <netinet/in.h>
29#include "DHCPv6.h"
30#include "DHCPv6Options.h"
31#include "timer.h"
32#include "dhcp_options.h"
33
34#define IPV4_METHOD_BIT		0x100
35#define IPV6_METHOD_BIT		0x200
36
37typedef enum {
38    ipconfig_method_none_e 	= 0x0,
39
40    /* IPv4 */
41    ipconfig_method_none_v4_e	= 0x100,
42    ipconfig_method_manual_e 	= 0x101,
43    ipconfig_method_bootp_e 	= 0x102,
44    ipconfig_method_dhcp_e 	= 0x103,
45    ipconfig_method_inform_e 	= 0x104,
46    ipconfig_method_linklocal_e = 0x105,
47    ipconfig_method_failover_e 	= 0x106,
48
49    /* IPv6 */
50    ipconfig_method_none_v6_e	= 0x200,
51    ipconfig_method_manual_v6_e	= 0x201,
52    ipconfig_method_automatic_v6_e = 0x202,
53    ipconfig_method_rtadv_e 	= 0x203,
54    ipconfig_method_stf_e 	= 0x204,
55    ipconfig_method_linklocal_v6_e = 0x205,
56} ipconfig_method_t;
57
58static __inline__ const char *
59ipconfig_method_string(ipconfig_method_t m)
60{
61    switch (m) {
62    case ipconfig_method_none_e:
63	return ("NONE");
64    case ipconfig_method_none_v4_e:
65	return ("NONE-V4");
66    case ipconfig_method_none_v6_e:
67	return ("NONE-V6");
68    case ipconfig_method_manual_e:
69	return ("MANUAL");
70    case ipconfig_method_bootp_e:
71	return ("BOOTP");
72    case ipconfig_method_dhcp_e:
73	return ("DHCP");
74    case ipconfig_method_inform_e:
75	return ("INFORM");
76    case ipconfig_method_linklocal_e:
77	return ("LINKLOCAL");
78    case ipconfig_method_failover_e:
79	return ("FAILOVER");
80    case ipconfig_method_manual_v6_e:
81	return ("MANUAL-V6");
82    case ipconfig_method_automatic_v6_e:
83	return ("AUTOMATIC-V6");
84    case ipconfig_method_rtadv_e:
85	return ("RTADV");
86    case ipconfig_method_stf_e:
87	return ("6TO4");
88    case ipconfig_method_linklocal_v6_e:
89	return ("LINKLOCAL-V6");
90    default:
91	break;
92    }
93    return ("<unknown>");
94}
95
96static __inline__ boolean_t
97ipconfig_method_is_dhcp_or_bootp(ipconfig_method_t method)
98{
99    if (method == ipconfig_method_dhcp_e
100	|| method == ipconfig_method_bootp_e) {
101	return (TRUE);
102    }
103    return (FALSE);
104}
105
106static __inline__ boolean_t
107ipconfig_method_is_manual(ipconfig_method_t method)
108{
109    if (method == ipconfig_method_manual_e
110	|| method == ipconfig_method_failover_e
111	|| method == ipconfig_method_inform_e) {
112	return (TRUE);
113    }
114    return (FALSE);
115}
116
117static __inline__ boolean_t
118ipconfig_method_is_v4(ipconfig_method_t method)
119{
120    return ((method & IPV4_METHOD_BIT) != 0);
121}
122
123static __inline__ boolean_t
124ipconfig_method_is_v6(ipconfig_method_t method)
125{
126    return ((method & IPV6_METHOD_BIT) != 0);
127}
128
129typedef struct {
130    struct in_addr	addr;
131    struct in_addr	mask;
132    struct in_addr	router;
133    boolean_t		ignore_link_status;
134    int32_t		failover_timeout;
135} ipconfig_method_data_manual_t;
136
137typedef struct {
138    int			client_id_len;
139    uint8_t		client_id[1];
140} ipconfig_method_data_dhcp_t;
141
142#define LINKLOCAL_ALLOCATE	TRUE
143#define LINKLOCAL_NO_ALLOCATE	FALSE
144typedef struct {
145    boolean_t	allocate;
146} ipconfig_method_data_linklocal_t;
147
148typedef struct {
149    struct in6_addr	addr;
150    int			prefix_length;
151} ipconfig_method_data_manual_v6_t;
152
153typedef enum {
154    address_type_none_e,
155    address_type_ipv4_e,
156    address_type_ipv6_e,
157    address_type_dns_e
158} address_type_t;
159
160typedef struct {
161    address_type_t	relay_addr_type;
162    union {
163	struct in_addr	v4;
164	struct in6_addr	v6;
165	char 		dns[1];
166    } relay_addr;
167} ipconfig_method_data_stf_t;
168
169/*
170 * Type: ipconfig_method_data_t
171 * Purpose:
172 *   Used internally by IPConfiguration to communicate the config to
173 *   the various methods.
174 */
175typedef union {
176    ipconfig_method_data_manual_t	manual;
177    ipconfig_method_data_dhcp_t		dhcp;
178    ipconfig_method_data_linklocal_t	linklocal;
179    ipconfig_method_data_manual_v6_t	manual_v6;
180    ipconfig_method_data_stf_t		stf;
181} ipconfig_method_data_t;
182
183/*
184 * Types to hold DHCP/auto-configuration information
185 */
186typedef struct {
187    const uint8_t *		pkt;
188    int				pkt_size;
189    dhcpol_t *			options;
190    absolute_time_t		lease_start;
191    absolute_time_t		lease_expiration;
192} dhcp_info_t;
193
194typedef struct {
195    DHCPv6PacketRef		pkt;
196    int				pkt_len;
197    DHCPv6OptionListRef		options;
198    struct in6_addr		addr;
199    const struct in6_addr *	dns_servers;
200    int				dns_servers_count;
201} dhcpv6_info_t;
202
203#endif /* _S_IPCONFIGD_TYPES_H */
204