|
|
1.1 root 1: /*
2: * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3: *
4: * @APPLE_LICENSE_HEADER_START@
5: *
6: * The contents of this file constitute Original Code as defined in and
7: * are subject to the Apple Public Source License Version 1.1 (the
8: * "License"). You may not use this file except in compliance with the
9: * License. Please obtain a copy of the License at
10: * http://www.apple.com/publicsource and read it before using this file.
11: *
12: * This Original Code and all software distributed under the License are
13: * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14: * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15: * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16: * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17: * License for the specific language governing rights and limitations
18: * under the License.
19: *
20: * @APPLE_LICENSE_HEADER_END@
21: */
22: /*
23: * Copyright (C) 1995-1997 by Darren Reed.
24: *
25: * Redistribution and use in source and binary forms are permitted
26: * provided that this notice is preserved and due credit is given
27: * to the original author and the contributors.
28: *
29: * @(#)ip_nat.h 1.5 2/4/96
30: */
31:
32: #ifndef __IP_NAT_H__
33: #define __IP_NAT_H__
34:
35: #ifndef SOLARIS
36: #define SOLARIS (defined(sun) && (defined(__svr4__) || defined(__SVR4)))
37: #endif
38:
39: #if defined(__STDC__) || defined(__GNUC__)
40: #define SIOCADNAT _IOW('r', 80, struct ipnat)
41: #define SIOCRMNAT _IOW('r', 81, struct ipnat)
42: #define SIOCGNATS _IOR('r', 82, struct natstat)
43: #define SIOCGNATL _IOWR('r', 83, struct natlookup)
44: #define SIOCGFRST _IOR('r', 84, struct ipfrstat)
45: #define SIOCGIPST _IOR('r', 85, struct ips_stat)
46: #define SIOCFLNAT _IOWR('r', 86, int)
47: #define SIOCCNATL _IOWR('r', 87, int)
48: #else
49: #define SIOCADNAT _IOW(r, 80, struct ipnat)
50: #define SIOCRMNAT _IOW(r, 81, struct ipnat)
51: #define SIOCGNATS _IOR(r, 82, struct natstat)
52: #define SIOCGNATL _IOWR(r, 83, struct natlookup)
53: #define SIOCGFRST _IOR(r, 84, struct ipfrstat)
54: #define SIOCGIPST _IOR(r, 85, struct ips_stat)
55: #define SIOCFLNAT _IOWR(r, 86, int)
56: #define SIOCCNATL _IOWR(r, 87, int)
57: #endif
58:
59: #define NAT_SIZE 367
60: #ifndef APR_LABELLEN
61: #define APR_LABELLEN 16
62: #endif
63:
64: typedef struct nat {
65: u_long nat_age;
66: int nat_flags;
67: u_32_t nat_sumd;
68: u_32_t nat_ipsumd;
69: void *nat_data;
70: struct in_addr nat_inip;
71: struct in_addr nat_outip;
72: struct in_addr nat_oip; /* other ip */
73: U_QUAD_T nat_pkts;
74: U_QUAD_T nat_bytes;
75: u_short nat_oport; /* other port */
76: u_short nat_inport;
77: u_short nat_outport;
78: u_short nat_use;
79: u_char nat_state[2];
80: struct ipnat *nat_ptr;
81: struct nat *nat_next;
82: struct nat *nat_hnext[2];
83: struct nat **nat_hstart[2];
84: void *nat_ifp;
85: int nat_dir;
86: } nat_t;
87:
88: typedef struct ipnat {
89: struct ipnat *in_next;
90: void *in_ifp;
91: void *in_apr;
92: u_int in_space;
93: u_int in_use;
94: struct in_addr in_nextip;
95: u_short in_pnext;
96: u_short in_flags;
97: u_short in_port[2];
98: struct in_addr in_in[2];
99: struct in_addr in_out[2];
100: int in_redir; /* 0 if it's a mapping, 1 if it's a hard redir */
101: char in_ifname[IFNAMSIZ];
102: char in_plabel[APR_LABELLEN]; /* proxy label */
103: char in_p; /* protocol */
104: u_short in_dport;
105: } ipnat_t;
106:
107: #define in_pmin in_port[0] /* Also holds static redir port */
108: #define in_pmax in_port[1]
109: #define in_nip in_nextip.s_addr
110: #define in_inip in_in[0].s_addr
111: #define in_inmsk in_in[1].s_addr
112: #define in_outip in_out[0].s_addr
113: #define in_outmsk in_out[1].s_addr
114:
115: #define NAT_OUTBOUND 0
116: #define NAT_INBOUND 1
117:
118: #define NAT_MAP 0x01
119: #define NAT_REDIRECT 0x02
120: #define NAT_BIMAP (NAT_MAP|NAT_REDIRECT)
121:
122: #define IPN_CMPSIZ (sizeof(struct in_addr) * 4 + sizeof(u_short) * 3 + \
123: sizeof(int) + IFNAMSIZ + APR_LABELLEN + sizeof(char))
124:
125: typedef struct natlookup {
126: struct in_addr nl_inip;
127: struct in_addr nl_outip;
128: struct in_addr nl_realip;
129: int nl_flags;
130: u_short nl_inport;
131: u_short nl_outport;
132: u_short nl_realport;
133: } natlookup_t;
134:
135: typedef struct natstat {
136: u_long ns_mapped[2];
137: u_long ns_rules;
138: u_long ns_added;
139: u_long ns_expire;
140: u_long ns_inuse;
141: u_long ns_logged;
142: u_long ns_logfail;
143: nat_t **ns_table[2];
144: ipnat_t *ns_list;
145: } natstat_t;
146:
147: #define IPN_ANY 0x00
148: #define IPN_TCP 0x01
149: #define IPN_UDP 0x02
150: #define IPN_TCPUDP 0x03
151: #define IPN_DELETE 0x04
152: #define IPN_ICMPERR 0x08
153:
154:
155: typedef struct natlog {
156: struct in_addr nl_origip;
157: struct in_addr nl_outip;
158: struct in_addr nl_inip;
159: u_short nl_origport;
160: u_short nl_outport;
161: u_short nl_inport;
162: u_short nl_type;
163: int nl_rule;
164: U_QUAD_T nl_pkts;
165: U_QUAD_T nl_bytes;
166: } natlog_t;
167:
168:
169: #define NL_NEWMAP NAT_MAP
170: #define NL_NEWRDR NAT_REDIRECT
171: #define NL_EXPIRE 0xffff
172:
173:
174: extern void ip_natsync __P((void *));
175: extern u_long fr_defnatage;
176: extern u_long fr_defnaticmpage;
177: extern nat_t *nat_table[2][NAT_SIZE];
178: #if defined(__NetBSD__) || defined(__OpenBSD__) || (__FreeBSD_version >= 300003)
179: extern int nat_ioctl __P((caddr_t, u_long, int));
180: #else
181: extern int nat_ioctl __P((caddr_t, int, int));
182: #endif
183: extern nat_t *nat_new __P((ipnat_t *, ip_t *, fr_info_t *, u_short, int));
184: extern nat_t *nat_outlookup __P((void *, int, struct in_addr, u_short,
185: struct in_addr, u_short));
186: extern nat_t *nat_inlookup __P((void *, int, struct in_addr, u_short,
187: struct in_addr, u_short));
188: extern nat_t *nat_lookupredir __P((natlookup_t *));
189: extern nat_t *nat_lookupmapip __P((void *, int, struct in_addr, u_short,
190: struct in_addr, u_short));
191: extern nat_t *nat_icmpinlookup __P((ip_t *, fr_info_t *));
192: extern nat_t *nat_icmpin __P((ip_t *, fr_info_t *, int *));
193:
194: extern int ip_natout __P((ip_t *, int, fr_info_t *));
195: extern int ip_natin __P((ip_t *, int, fr_info_t *));
196: extern void ip_natunload __P((void)), ip_natexpire __P((void));
197: extern void nat_log __P((struct nat *, u_short));
198: extern void fix_incksum __P((u_short *, u_32_t));
199: extern void fix_outcksum __P((u_short *, u_32_t));
200:
201: #endif /* __IP_NAT_H__ */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.