1/*
2 * Copyright (c) 2010 Apple Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * 1.  Redistributions of source code must retain the above copyright
11 *     notice, this list of conditions and the following disclaimer.
12 * 2.  Redistributions in binary form must reproduce the above copyright
13 *     notice, this list of conditions and the following disclaimer in the
14 *     documentation and/or other materials provided with the distribution.
15 * 3.  Neither the name of Apple Inc. ("Apple") nor the names of its
16 *     contributors may be used to endorse or promote products derived from
17 *     this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
20 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 *
30 * Portions of this software have been released under the following terms:
31 *
32 * (c) Copyright 1989-1993 OPEN SOFTWARE FOUNDATION, INC.
33 * (c) Copyright 1989-1993 HEWLETT-PACKARD COMPANY
34 * (c) Copyright 1989-1993 DIGITAL EQUIPMENT CORPORATION
35 *
36 * To anyone who acknowledges that this file is provided "AS IS"
37 * without any express or implied warranty:
38 * permission to use, copy, modify, and distribute this file for any
39 * purpose is hereby granted without fee, provided that the above
40 * copyright notices and this notice appears in all source code copies,
41 * and that none of the names of Open Software Foundation, Inc., Hewlett-
42 * Packard Company or Digital Equipment Corporation be used
43 * in advertising or publicity pertaining to distribution of the software
44 * without specific, written prior permission.  Neither Open Software
45 * Foundation, Inc., Hewlett-Packard Company nor Digital
46 * Equipment Corporation makes any representations about the suitability
47 * of this software for any purpose.
48 *
49 * Copyright (c) 2007, Novell, Inc. All rights reserved.
50 * Redistribution and use in source and binary forms, with or without
51 * modification, are permitted provided that the following conditions
52 * are met:
53 *
54 * 1.  Redistributions of source code must retain the above copyright
55 *     notice, this list of conditions and the following disclaimer.
56 * 2.  Redistributions in binary form must reproduce the above copyright
57 *     notice, this list of conditions and the following disclaimer in the
58 *     documentation and/or other materials provided with the distribution.
59 * 3.  Neither the name of Novell Inc. nor the names of its contributors
60 *     may be used to endorse or promote products derived from this
61 *     this software without specific prior written permission.
62 *
63 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
64 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
65 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
66 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY
67 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
68 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
69 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
70 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
71 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
72 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
73 *
74 * @APPLE_LICENSE_HEADER_END@
75 */
76
77/*
78**
79**  NAME
80**
81**      ipnaf.h
82**
83**  FACILITY:
84**
85**      Remote Procedure Call (RPC)
86**
87**  ABSTRACT:
88**
89**  Definitions and Data Type declarations
90**  used by the Internet Network Address Family Extension
91**  service.
92**
93**
94*/
95
96#ifndef _IPNAF_H
97#define _IPNAF_H	1
98
99/***********************************************************************
100 *
101 *  Include the Internet specific socket address
102 */
103
104#include <netinet/in.h>
105#include <netinet/tcp.h>
106#include <arpa/inet.h>
107
108/***********************************************************************
109 *
110 * provides a masked unsigned8 required in conversion of IP network
111 * address to ascii dot notation string.
112 */
113
114#define UC(b)               (((int) b) & 0xff)
115
116/***********************************************************************
117 *
118 *  The representation of an RPC Address that holds an IP address.
119 */
120
121typedef struct rpc_addr_ip_t
122{
123    rpc_protseq_id_t        rpc_protseq_id;
124    unsigned32              len;
125    struct sockaddr_in      sa;
126} rpc_ip_addr_t, *rpc_ip_addr_p_t;
127
128/***********************************************************************
129 *
130 * Define some TPDU/TSDU constants, if they haven't already been defined
131 * (typically in a system header file).
132 */
133
134/*
135 * The max # of data bytes that can go into a UDP packet body such that
136 * the resulting IP packet can fit through any of the local network
137 * interfaces without inducing IP fragmentation.
138 *
139 * NOTE WELL:  This value is derived from
140 *
141 *      (1) The size of the data section of data link packets.  For the
142 *          time being, the data link is assumed to be ethernet.
143 *
144 *      (2) The size of the LLC frame.  RFC 1042, which specifies IP
145 *          over 802 networks, calls for the use of the SNAP protocol.
146 *          SNAP takes up 8 bytes of the ethernet frame's data section.
147 *
148 *      (3) The size of the UDP and IP headers, from RFCs 768 and 791.
149 *
150 *      (4) The length of the IP options part of the header.  Since we
151 *          do not currently use any of the IP options, this value is
152 *          0.   *** This constant must be modified if we ever make use
153 *          of IP options in the future. ***
154 *
155 * !!! THIS VALUE SHOULD BE COMPUTED AT RUNTIME and with a little work
156 * could be.
157 */
158
159#define RPC_C_ETHER_MAX_DATA_SIZE 1500
160#define RPC_C_IP_LLC_SIZE            8 /* LLC frame for SNAP protocol */
161#define RPC_C_IP_HDR_SIZE           20 /* Base IP header */
162#define RPC_C_IP_OPTS_SIZE           0 /* IP options length */
163#define RPC_C_UDP_HDR_SIZE           8 /* UDP header */
164#ifndef RPC_C_IP_UDP_MAX_LOC_UNFRG_TPDU
165#define RPC_C_IP_UDP_MAX_LOC_UNFRG_TPDU ( \
166        RPC_C_ETHER_MAX_DATA_SIZE - \
167        (RPC_C_IP_LLC_SIZE + RPC_C_IP_HDR_SIZE + \
168         RPC_C_IP_OPTS_SIZE + RPC_C_UDP_HDR_SIZE) \
169)
170#endif /* RPC_C_IP_UDP_MAX_LOC_UNFRG_TPDU */
171
172#define RPC_C_FDDI_MAX_DATA_SIZE 4352
173
174/*
175 * The max # of data bytes that can go into a UDP packet body such that
176 * the resulting IP packet can be sent to some host without being
177 * fragmented along the path.
178 *
179 * For now, we just set this value to be the same as above.  In general,
180 * this value would be <= the above value.
181 *
182 * !!! THIS VALUE SHOULD BE COMPUTED AT RUNTIME as a function of the
183 * target host address but can't be given the tools we have today.
184 *
185 */
186#ifndef RPC_C_IP_UDP_MAX_PTH_UNFRG_TPDU
187#define RPC_C_IP_UDP_MAX_PTH_UNFRG_TPDU RPC_C_IP_UDP_MAX_LOC_UNFRG_TPDU
188#endif
189
190/*
191 * The max # of data bytes that can go into a UDP packet body and be
192 * accepted through the transport service interface (i.e., sockets).
193 * While logically this value is 2**16-1 (see RFC 768), in practice many
194 * systems don't support such a large value.
195 * This value is really only useful when it is necessary to *limit*
196 * the fragment size because of a limitation in the service
197 * interface.
198 */
199#ifndef RPC_C_IP_UDP_MAX_TSDU
200#define RPC_C_IP_UDP_MAX_TSDU ( \
201        64 * 1024 - \
202        (RPC_C_IP_HDR_SIZE + RPC_C_IP_OPTS_SIZE + RPC_C_UDP_HDR_SIZE) \
203)
204#endif
205
206/*
207 * Max Path DG Fragment Size:
208 *
209 *   The size in bytes of the largest DG fragment that can be sent to
210 *   a particular address. This is determined when the call handle to
211 *   a particular address is created and may change in the life of the
212 *   call handle.
213 *
214 * The constant defined here is based on experimentation.
215 *
216 * Caution: This must be less than RPC_C_DG_MAX_FRAG_SIZE::dg.h!
217 */
218
219#ifndef RPC_C_IP_UDP_MAX_PATH_FRAG_SIZE
220#define RPC_C_IP_UDP_MAX_PATH_FRAG_SIZE ( \
221        RPC_C_FDDI_MAX_DATA_SIZE - \
222        (RPC_C_IP_LLC_SIZE + RPC_C_IP_HDR_SIZE + \
223         RPC_C_IP_OPTS_SIZE + RPC_C_UDP_HDR_SIZE) \
224)
225#endif
226
227/*
228 * Max Local DG Fragment Size:
229 *
230 *   The size in bytes of the largest DG fragment that can be sent to
231 *   a "local" address. The data won't be transmitted over the "wire"
232 *   by the transport service, i.e., the loopback is done on the local
233 *   host. This is determined when the socket is created and won't
234 *   change in the life of the socket.
235 *
236 * The constant defined here is based on experimentation.
237 *
238 * Caution: This must be less than RPC_C_DG_MAX_FRAG_SIZE::dg.h!
239 */
240
241#ifndef RPC_C_IP_UDP_MAX_LOCAL_FRAG_SIZE
242#define RPC_C_IP_UDP_MAX_LOCAL_FRAG_SIZE (8 * 1024)
243#endif
244
245/***********************************************************************
246 *
247 * The IP-specific representation of rpc_port_restriction_list_t.range_list
248 * (see com.h).  The low and high are in native machine representation, not
249 * network rep.
250 */
251
252typedef struct struct_rpc_port_range_element
253{
254    unsigned32                      low;
255    unsigned32                      high;
256} rpc_port_range_element_t, *rpc_port_range_element_p_t;
257
258/***********************************************************************
259 *
260 *  Routine Prototypes for the Internet Extension service routines.
261 */
262
263#ifdef __cplusplus
264extern "C" {
265#endif
266
267PRIVATE void rpc__ip_init (
268        rpc_naf_epv_p_t             * /*naf_epv*/,
269        unsigned32                  * /*status*/
270    );
271
272PRIVATE void rpc__ip_desc_inq_addr (
273        rpc_protseq_id_t             /*protseq_id*/,
274        rpc_socket_t                 /*desc*/,
275        rpc_addr_vector_p_t         * /*rpc_addr_vec*/,
276        unsigned32                  * /*st*/
277    );
278
279PRIVATE void rpc__ip_get_broadcast (
280        rpc_naf_id_t                 /*naf_id*/,
281        rpc_protseq_id_t             /*rpc_protseq_id*/,
282        rpc_addr_vector_p_t         * /*rpc_addrs*/,
283        unsigned32                  * /*status*/
284    );
285
286PRIVATE void rpc__ip_init_local_addr_vec (
287        unsigned32                  * /*status*/
288    );
289
290PRIVATE boolean32 rpc__ip_is_local_network (
291        rpc_addr_p_t                 /*rpc_addr*/,
292        unsigned32                  * /*status*/
293    );
294
295PRIVATE boolean32 rpc__ip_is_local_addr (
296        rpc_addr_p_t                 /*rpc_addr*/,
297        unsigned32                  * /*status*/
298    );
299
300PRIVATE void rpc__ip_naf_init_func(void);
301
302#ifdef __cplusplus
303}
304#endif
305
306#endif /* _IPNAF_H */
307