OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [ecos-2.0/] [packages/] [net/] [tcpip/] [v2_0/] [include/] [netinet/] [ip_nat.h] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1254 phoenix
//==========================================================================
2
//
3
//      include/netinet/ip_nat.h
4
//
5
//      
6
//
7
//==========================================================================
8
//####BSDCOPYRIGHTBEGIN####
9
//
10
// -------------------------------------------
11
//
12
// Portions of this software may have been derived from OpenBSD or other sources,
13
// and are covered by the appropriate copyright disclaimers included herein.
14
//
15
// -------------------------------------------
16
//
17
//####BSDCOPYRIGHTEND####
18
//==========================================================================
19
//#####DESCRIPTIONBEGIN####
20
//
21
// Author(s):    gthomas
22
// Contributors: gthomas
23
// Date:         2000-01-10
24
// Purpose:      
25
// Description:  
26
//              
27
//
28
//####DESCRIPTIONEND####
29
//
30
//==========================================================================
31
 
32
 
33
/* $OpenBSD: ip_nat.h,v 1.13 1999/12/15 05:20:22 kjell Exp $ */
34
/*
35
 * Copyright (C) 1995-1998 by Darren Reed.
36
 *
37
 * Redistribution and use in source and binary forms are permitted
38
 * provided that this notice is preserved and due credit is given
39
 * to the original author and the contributors.
40
 *
41
 * @(#)ip_nat.h 1.5 2/4/96
42
 */
43
 
44
#ifndef _NETINET_IP_NAT_H__
45
#define _NETINET_IP_NAT_H__
46
 
47
#ifndef SOLARIS
48
#define SOLARIS (defined(sun) && (defined(__svr4__) || defined(__SVR4)))
49
#endif
50
 
51
#if defined(__STDC__) || defined(__GNUC__)
52
#define SIOCADNAT       _IOW('r', 80, struct ipnat)
53
#define SIOCRMNAT       _IOW('r', 81, struct ipnat)
54
#define SIOCGNATS       _IOR('r', 82, struct natstat)
55
#define SIOCGNATL       _IOWR('r', 83, struct natlookup)
56
#define SIOCGFRST       _IOR('r', 84, struct ipfrstat)
57
#define SIOCGIPST       _IOR('r', 85, struct ips_stat)
58
#define SIOCFLNAT       _IOWR('r', 86, int)
59
#define SIOCCNATL       _IOWR('r', 87, int)
60
#else
61
#define SIOCADNAT       _IOW(r, 80, struct ipnat)
62
#define SIOCRMNAT       _IOW(r, 81, struct ipnat)
63
#define SIOCGNATS       _IOR(r, 82, struct natstat)
64
#define SIOCGNATL       _IOWR(r, 83, struct natlookup)
65
#define SIOCGFRST       _IOR(r, 84, struct ipfrstat)
66
#define SIOCGIPST       _IOR(r, 85, struct ips_stat)
67
#define SIOCFLNAT       _IOWR(r, 86, int)
68
#define SIOCCNATL       _IOWR(r, 87, int)
69
#endif
70
 
71
#undef  LARGE_NAT       /* define this if you're setting up a system to NAT
72
                         * LARGE numbers of networks/hosts - i.e. in the
73
                         * hundreds or thousands.  In such a case, you should
74
                         * also change the RDR_SIZE and NAT_SIZE below to more
75
                         * appropriate sizes.  The figures below were used for
76
                         * a setup with 1000-2000 networks to NAT.
77
                         */
78
#define NAT_SIZE        127
79
#define RDR_SIZE        127
80
#define NAT_TABLE_SZ    127
81
#ifdef  LARGE_NAT
82
#undef  NAT_SIZE
83
#undef  RDR_SIZE
84
#undef  NAT_TABLE_SZ
85
#define NAT_SIZE        2047
86
#define RDR_SIZE        2047
87
#define NAT_TABLE_SZ    16383
88
#endif
89
#ifndef APR_LABELLEN
90
#define APR_LABELLEN    16
91
#endif
92
#define NAT_HW_CKSUM    0x80000000
93
 
94
#define DEF_NAT_AGE     1200     /* 10 minutes (600 seconds) */
95
 
96
typedef struct  nat     {
97
        u_long  nat_age;
98
        int     nat_flags;
99
        u_32_t  nat_sumd[2];
100
        u_32_t  nat_ipsumd;
101
        void    *nat_data;
102
        void    *nat_aps;               /* proxy session */
103
        frentry_t       *nat_fr;        /* filter rule ptr if appropriate */
104
        struct  in_addr nat_inip;
105
        struct  in_addr nat_outip;
106
        struct  in_addr nat_oip;        /* other ip */
107
        U_QUAD_T        nat_pkts;
108
        U_QUAD_T        nat_bytes;
109
        u_short nat_oport;              /* other port */
110
        u_short nat_inport;
111
        u_short nat_outport;
112
        u_short nat_use;
113
        u_char  nat_tcpstate[2];
114
        u_char  nat_p;                  /* protocol for NAT */
115
        struct  ipnat   *nat_ptr;       /* pointer back to the rule */
116
        struct  nat     *nat_next;
117
        struct  nat     *nat_hnext[2];
118
        struct  nat     **nat_hstart[2];
119
        void    *nat_ifp;
120
        int     nat_dir;
121
} nat_t;
122
 
123
typedef struct  ipnat   {
124
        struct  ipnat   *in_next;
125
        struct  ipnat   *in_rnext;
126
        struct  ipnat   *in_mnext;
127
        void    *in_ifp;
128
        void    *in_apr;
129
        u_long  in_space;
130
        u_int   in_use;
131
        u_int   in_hits;
132
        struct  in_addr in_nextip;
133
        u_short in_pnext;
134
        u_short in_ppip;        /* ports per IP */
135
        u_short in_ippip;       /* IP #'s per IP# */
136
        u_short in_flags;       /* From here to in_dport must be reflected */
137
        u_short in_port[2];     /* correctly in IPN_CMPSIZ */
138
        struct  in_addr in_in[2];
139
        struct  in_addr in_out[2];
140
        struct  in_addr in_src[2];
141
        int     in_redir; /* 0 if it's a mapping, 1 if it's a hard redir */
142
        char    in_ifname[IFNAMSIZ];
143
        char    in_plabel[APR_LABELLEN];        /* proxy label */
144
        char    in_p;   /* protocol */
145
        u_short in_dport;
146
} ipnat_t;
147
 
148
#define in_pmin         in_port[0]      /* Also holds static redir port */
149
#define in_pmax         in_port[1]
150
#define in_nip          in_nextip.s_addr
151
#define in_inip         in_in[0].s_addr
152
#define in_inmsk        in_in[1].s_addr
153
#define in_outip        in_out[0].s_addr
154
#define in_outmsk       in_out[1].s_addr
155
#define in_srcip        in_src[0].s_addr
156
#define in_srcmsk       in_src[1].s_addr
157
 
158
#define NAT_OUTBOUND    0
159
#define NAT_INBOUND     1
160
 
161
#define NAT_MAP         0x01
162
#define NAT_REDIRECT    0x02
163
#define NAT_BIMAP       (NAT_MAP|NAT_REDIRECT)
164
#define NAT_MAPBLK      0x04
165
 
166
#define MAPBLK_MINPORT  1024    /* don't use reserved ports for src port */
167
#define USABLE_PORTS    (65536 - MAPBLK_MINPORT)
168
 
169
#define IPN_CMPSIZ      (sizeof(ipnat_t) - offsetof(ipnat_t, in_flags))
170
 
171
typedef struct  natlookup {
172
        struct  in_addr nl_inip;
173
        struct  in_addr nl_outip;
174
        struct  in_addr nl_realip;
175
        int     nl_flags;
176
        u_short nl_inport;
177
        u_short nl_outport;
178
        u_short nl_realport;
179
} natlookup_t;
180
 
181
typedef struct  natstat {
182
        u_long  ns_mapped[2];
183
        u_long  ns_rules;
184
        u_long  ns_added;
185
        u_long  ns_expire;
186
        u_long  ns_inuse;
187
        u_long  ns_logged;
188
        u_long  ns_logfail;
189
        nat_t   **ns_table[2];
190
        ipnat_t *ns_list;
191
        void    *ns_apslist;
192
        u_int   ns_nattab_sz;
193
        u_int   ns_rultab_sz;
194
        u_int   ns_rdrtab_sz;
195
        nat_t   *ns_instances;
196
} natstat_t;
197
 
198
#define IPN_ANY         0x00
199
#define IPN_TCP         0x01
200
#define IPN_UDP         0x02
201
#define IPN_TCPUDP      (IPN_TCP|IPN_UDP)
202
#define IPN_DELETE      0x04
203
#define IPN_ICMPERR     0x08
204
#define IPN_RF          (IPN_TCPUDP|IPN_DELETE|IPN_ICMPERR)
205
#define IPN_AUTOPORTMAP 0x10
206
#define IPN_RANGE       0x20
207
#define IPN_USERFLAGS   (IPN_TCPUDP|IPN_AUTOPORTMAP|IPN_RANGE)
208
 
209
 
210
typedef struct  natlog {
211
        struct  in_addr nl_origip;
212
        struct  in_addr nl_outip;
213
        struct  in_addr nl_inip;
214
        u_short nl_origport;
215
        u_short nl_outport;
216
        u_short nl_inport;
217
        u_short nl_type;
218
        int     nl_rule;
219
        U_QUAD_T        nl_pkts;
220
        U_QUAD_T        nl_bytes;
221
} natlog_t;
222
 
223
 
224
#define NL_NEWMAP       NAT_MAP
225
#define NL_NEWRDR       NAT_REDIRECT
226
#define NL_EXPIRE       0xffff
227
 
228
#define NAT_HASH_FN(k,m)        (((k) + ((k) >> 12)) % (m))
229
 
230
#define LONG_SUM(in)    (((in) & 0xffff) + ((in) >> 16))
231
 
232
#define CALC_SUMD(s1, s2, sd) { \
233
                            (s1) = ((s1) & 0xffff) + ((s1) >> 16); \
234
                            (s2) = ((s2) & 0xffff) + ((s2) >> 16); \
235
                            /* Do it twice */ \
236
                            (s1) = ((s1) & 0xffff) + ((s1) >> 16); \
237
                            (s2) = ((s2) & 0xffff) + ((s2) >> 16); \
238
                            /* Because ~1 == -2, We really need ~1 == -1 */ \
239
                            if ((s1) > (s2)) (s2)--; \
240
                            (sd) = (s2) - (s1); \
241
                            (sd) = ((sd) & 0xffff) + ((sd) >> 16); }
242
 
243
 
244
extern  u_int   ipf_nattable_sz;
245
extern  u_int   ipf_natrules_sz;
246
extern  u_int   ipf_rdrrules_sz;
247
extern  void    ip_natsync __P((void *));
248
extern  u_long  fr_defnatage;
249
extern  u_long  fr_defnaticmpage;
250
extern  nat_t   **nat_table[2];
251
extern  nat_t   *nat_instances;
252
extern  ipnat_t **nat_rules;
253
extern  ipnat_t **rdr_rules;
254
extern  natstat_t       nat_stats;
255
#if defined(__NetBSD__) || defined(__OpenBSD__)
256
extern  int     nat_ioctl __P((caddr_t, u_long, int));
257
#else
258
extern  int     nat_ioctl __P((caddr_t, int, int));
259
#endif
260
extern  void    nat_ifdetach __P((struct ifnet *));
261
extern  int     nat_init __P((void));
262
extern  nat_t   *nat_new __P((ipnat_t *, ip_t *, fr_info_t *, u_int, int));
263
extern  nat_t   *nat_outlookup __P((void *, u_int, u_int, struct in_addr,
264
                                 struct in_addr, u_32_t));
265
extern  nat_t   *nat_inlookup __P((void *, u_int, u_int, struct in_addr,
266
                                struct in_addr, u_32_t));
267
extern  nat_t   *nat_maplookup __P((void *, u_int, struct in_addr,
268
                                struct in_addr));
269
extern  nat_t   *nat_lookupredir __P((natlookup_t *));
270
extern  nat_t   *nat_icmpinlookup __P((ip_t *, fr_info_t *));
271
extern  nat_t   *nat_icmpin __P((ip_t *, fr_info_t *, u_int *));
272
 
273
extern  int     ip_natout __P((ip_t *, fr_info_t *));
274
extern  int     ip_natin __P((ip_t *, fr_info_t *));
275
extern  void    ip_natunload __P((void)), ip_natexpire __P((void));
276
extern  void    nat_log __P((struct nat *, u_int));
277
extern  void    fix_incksum __P((u_short *, u_32_t, int));
278
extern  void    fix_outcksum __P((u_short *, u_32_t, int));
279
 
280
#endif /* _NETINET_IP_NAT_H__ */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.