4 * Copyright (C) 1997-2001 by Darren Reed.
6 * See the IPFILTER.LICENCE file for details on licencing.
8 * Id: ip_proxy.h,v 2.31.2.6 2007/10/26 12:15:13 darrenr Exp
11 #ifndef _NETINET_IP_PROXY_H_
12 #define _NETINET_IP_PROXY_H_
15 #define SOLARIS (defined(sun) && (defined(__svr4__) || defined(__SVR4)))
18 #if defined(__STDC__) || defined(__GNUC__) || defined(_AIX51)
19 #define SIOCPROXY _IOWR('r', 64, struct ap_control)
21 #define SIOCPROXY _IOWR(r, 64, struct ap_control)
25 #define APR_LABELLEN 16
27 #define AP_SESS_SIZE 53
33 typedef struct ap_tcp
{
34 u_short apt_sport
; /* source port */
35 u_short apt_dport
; /* destination port */
36 short apt_sel
[2]; /* {seq,ack}{off,min} set selector */
37 short apt_seqoff
[2]; /* sequence # difference */
38 u_32_t apt_seqmin
[2]; /* don't change seq-off until after this */
39 short apt_ackoff
[2]; /* sequence # difference */
40 u_32_t apt_ackmin
[2]; /* don't change seq-off until after this */
41 u_char apt_state
[2]; /* connection state */
44 typedef struct ap_udp
{
45 u_short apu_sport
; /* source port */
46 u_short apu_dport
; /* destination port */
49 typedef struct ap_session
{
50 struct aproxy
*aps_apr
;
52 struct ap_tcp apu_tcp
;
53 struct ap_udp apu_udp
;
56 U_QUAD_T aps_bytes
; /* bytes sent */
57 U_QUAD_T aps_pkts
; /* packets sent */
58 void *aps_nat
; /* pointer back to nat struct */
59 void *aps_data
; /* private data */
60 int aps_p
; /* protocol */
61 int aps_psiz
; /* size of private data */
62 struct ap_session
*aps_hnext
;
63 struct ap_session
*aps_next
;
66 #define aps_sport aps_un.apu_tcp.apt_sport
67 #define aps_dport aps_un.apu_tcp.apt_dport
68 #define aps_sel aps_un.apu_tcp.apt_sel
69 #define aps_seqoff aps_un.apu_tcp.apt_seqoff
70 #define aps_seqmin aps_un.apu_tcp.apt_seqmin
71 #define aps_state aps_un.apu_tcp.apt_state
72 #define aps_ackoff aps_un.apu_tcp.apt_ackoff
73 #define aps_ackmin aps_un.apu_tcp.apt_ackmin
76 typedef struct ap_control
{
77 char apc_label
[APR_LABELLEN
];
80 * The following fields are upto the proxy's apr_ctl routine to deal
81 * with. When the proxy gets this in kernel space, apc_data will
82 * point to a malloc'd region of memory of apc_dsize bytes. If the
83 * proxy wants to keep that memory, it must set apc_data to NULL
84 * before it returns. It is expected if this happens that it will
85 * take care to free it in apr_fini or otherwise as appropriate.
86 * apc_cmd is provided as a standard place to put simple commands,
87 * with apc_arg being available to put a simple arg.
96 typedef struct aproxy
{
97 struct aproxy
*apr_next
;
98 char apr_label
[APR_LABELLEN
]; /* Proxy label # */
99 u_char apr_p
; /* protocol */
100 int apr_ref
; /* +1 per rule referencing it */
102 int (* apr_init
) __P((void));
103 void (* apr_fini
) __P((void));
104 int (* apr_new
) __P((fr_info_t
*, ap_session_t
*, struct nat
*));
105 void (* apr_del
) __P((ap_session_t
*));
106 int (* apr_inpkt
) __P((fr_info_t
*, ap_session_t
*, struct nat
*));
107 int (* apr_outpkt
) __P((fr_info_t
*, ap_session_t
*, struct nat
*));
108 int (* apr_match
) __P((fr_info_t
*, ap_session_t
*, struct nat
*));
109 int (* apr_ctl
) __P((struct aproxy
*, struct ap_control
*));
114 #define APR_ERR(x) ((x) << 16)
115 #define APR_EXIT(x) (((x) >> 16) & 0xffff)
116 #define APR_INC(x) ((x) & 0xffff)
119 * Generic #define's to cover missing things in the kernel
122 #define isdigit(x) ((x) >= '0' && (x) <= '9')
125 #define isupper(x) (((unsigned)(x) >= 'A') && ((unsigned)(x) <= 'Z'))
128 #define islower(x) (((unsigned)(x) >= 'a') && ((unsigned)(x) <= 'z'))
131 #define isalpha(x) (isupper(x) || islower(x))
134 #define toupper(x) (isupper(x) ? (x) : (x) - 'a' + 'A')
137 #define isspace(x) (((x) == ' ') || ((x) == '\r') || ((x) == '\n') || \
138 ((x) == '\t') || ((x) == '\b'))
142 * This is the scratch buffer size used to hold strings from the TCP stream
143 * that we may want to parse. It's an arbitrary size, really, but it must
144 * be at least as large as IPF_FTPBUFSZ.
146 #define FTP_BUFSZ 120
149 * This buffer, however, doesn't need to be nearly so big. It just needs to
150 * be able to squeeze in the largest command it needs to rewrite, Which ones
151 * does it rewrite? EPRT, PORT, 227 replies.
153 #define IPF_FTPBUFSZ 80 /* This *MUST* be >= 53! */
155 typedef struct ftpside
{
161 int ftps_junk
; /* 2 = no cr/lf yet, 1 = cannot parse */
163 char ftps_buf
[FTP_BUFSZ
];
166 typedef struct ftpinfo
{
169 ftpside_t ftp_side
[2];
176 typedef struct ircinfo
{
189 * Real audio proxy structure and #defines
191 typedef struct raudio_s
{
195 int rap_eos
; /* End Of Startup */
204 u_32_t rap_sbf
; /* flag to indicate which of the 19 bytes have
212 #define RA_ID_ROBUST 7
215 #define RAP_M_ROBUST 2
217 #define RAP_M_UDP_ROBUST (RAP_M_UDP|RAP_M_ROBUST)
223 typedef struct msnrpcinfo
{
227 struct in_addr mri_raddr
;
235 typedef u_32_t ipsec_cookie_t
[2];
237 typedef struct ipsec_pxy
{
238 ipsec_cookie_t ipsc_icookie
;
239 ipsec_cookie_t ipsc_rcookie
;
243 struct ipstate
*ipsc_state
;
249 typedef struct pptp_side
{
250 u_32_t pptps_nexthdr
;
257 char pptps_buffer
[512];
260 typedef struct pptp_pxy
{
263 struct ipstate
*pptp_state
;
264 u_short pptp_call
[2];
265 pptp_side_t pptp_side
[2];
272 #define RPCB_MAXMSG 888
273 #define RPCB_RES_PMAP 0 /* Response contains a v2 port. */
274 #define RPCB_RES_STRING 1 /* " " " v3 (GETADDR) string. */
275 #define RPCB_RES_LIST 2 /* " " " v4 (GETADDRLIST) list. */
276 #define RPCB_MAXREQS 32 /* Arbitrary limit on tracked transactions */
278 #define RPCB_REQMIN 40
279 #define RPCB_REQMAX 888
280 #define RPCB_REPMIN 20
281 #define RPCB_REPMAX 604 /* XXX double check this! */
284 * These macros determine the number of bytes between p and the end of
285 * r->rs_buf relative to l.
287 #define RPCB_BUF_END(r) (char *)((r)->rm_msgbuf + (r)->rm_buflen)
288 #define RPCB_BUF_GEQ(r, p, l) \
289 ((RPCB_BUF_END((r)) > (char *)(p)) && \
290 ((RPCB_BUF_END((r)) - (char *)(p)) >= (l)))
291 #define RPCB_BUF_EQ(r, p, l) \
292 (RPCB_BUF_END((r)) == ((char *)(p) + (l)))
295 * The following correspond to RPC(B) detailed in RFC183[13].
299 #define RPCB_MSG_VERSION 2
300 #define RPCB_PROG 100000
301 #define RPCB_GETPORT 3
302 #define RPCB_GETADDR 3
303 #define RPCB_GETADDRLIST 11
304 #define RPCB_MSG_ACCEPTED 0
305 #define RPCB_MSG_DENIED 1
307 /* BEGIN (Generic XDR structures) */
308 typedef struct xdr_string
{
313 typedef struct xdr_auth
{
314 /* u_32_t xa_flavor; */
315 xdr_string_t xa_string
;
318 typedef struct xdr_uaddr
{
324 typedef struct xdr_proto
{
329 #define xu_xslen xu_str.xs_len
330 #define xu_xsstr xu_str.xs_str
331 #define xp_xslen xp_str.xs_len
332 #define xp_xsstr xp_str.xs_str
333 /* END (Generic XDR structures) */
335 /* BEGIN (RPC call structures) */
336 typedef struct pmap_args
{
337 /* u_32_t pa_prog; */
338 /* u_32_t pa_vers; */
340 /* u_32_t pa_port; */
343 typedef struct rpcb_args
{
344 /* u_32_t *ra_prog; */
345 /* u_32_t *ra_vers; */
346 xdr_proto_t ra_netid
;
347 xdr_uaddr_t ra_maddr
;
348 /* xdr_string_t ra_owner; */
351 typedef struct rpc_call
{
352 /* u_32_t rc_rpcvers; */
353 /* u_32_t rc_prog; */
356 xdr_auth_t rc_authcred
;
357 xdr_auth_t rc_authverf
;
359 pmap_args_t ra_pmapargs
;
360 rpcb_args_t ra_rpcbargs
;
364 #define rc_pmapargs rpcb_args.ra_pmapargs
365 #define rc_rpcbargs rpcb_args.ra_rpcbargs
366 /* END (RPC call structures) */
368 /* BEGIN (RPC reply structures) */
369 typedef struct rpcb_entry
{
370 xdr_uaddr_t re_maddr
;
371 xdr_proto_t re_netid
;
372 /* u_32_t re_semantics; */
373 xdr_string_t re_family
;
374 xdr_proto_t re_proto
;
375 u_32_t
*re_more
; /* 1 == another entry follows */
378 typedef struct rpcb_listp
{
379 u_32_t
*rl_list
; /* 1 == list follows */
381 rpcb_entry_t rl_entries
[2]; /* TCP / UDP only */
384 typedef struct rpc_resp
{
385 /* u_32_t rr_acceptdeny; */
386 /* Omitted 'message denied' fork; we don't care about rejects. */
387 xdr_auth_t rr_authverf
;
388 /* u_32_t *rr_astat; */
391 xdr_uaddr_t resp_getaddr
;
392 rpcb_listp_t resp_getaddrlist
;
396 #define rr_v2 rpcb_reply.resp_pmap
397 #define rr_v3 rpcb_reply.resp_getaddr
398 #define rr_v4 rpcb_reply.resp_getaddrlist
399 /* END (RPC reply structures) */
401 /* BEGIN (RPC message structure & macros) */
402 typedef struct rpc_msg
{
403 char rm_msgbuf
[RPCB_MAXMSG
]; /* RPCB data buffer */
406 /* u_32_t Call vs Reply */
413 #define rm_call rm_body.rb_call
414 #define rm_resp rm_body.rb_resp
415 /* END (RPC message structure & macros) */
418 * These code paths aren't hot enough to warrant per transaction
421 typedef struct rpcb_xact
{
422 struct rpcb_xact
*rx_next
;
423 struct rpcb_xact
**rx_pnext
;
424 u_32_t rx_xid
; /* RPC transmission ID */
425 u_int rx_type
; /* RPCB response type */
426 u_int rx_ref
; /* reference count */
427 u_int rx_proto
; /* transport protocol (v2 only) */
430 typedef struct rpcb_session
{
431 ipfmutex_t rs_rxlock
;
432 rpcb_xact_t
*rs_rxlist
;
436 * For an explanation, please see the following:
437 * RFC1832 - Sections 3.11, 4.4, and 4.5.
439 #define XDRALIGN(x) ((((x) % 4) != 0) ? ((((x) + 3) / 4) * 4) : (x))
441 extern ap_session_t
*ap_sess_tab
[AP_SESS_SIZE
];
442 extern ap_session_t
*ap_sess_list
;
443 extern aproxy_t ap_proxies
[];
444 extern int ippr_ftp_pasvonly
;
445 extern int ipf_proxy_debug
;
447 extern int appr_add
__P((aproxy_t
*));
448 extern int appr_ctl
__P((ap_ctl_t
*));
449 extern int appr_del
__P((aproxy_t
*));
450 extern int appr_init
__P((void));
451 extern void appr_unload
__P((void));
452 extern int appr_ok
__P((fr_info_t
*, tcphdr_t
*, struct ipnat
*));
453 extern int appr_match
__P((fr_info_t
*, struct nat
*));
454 extern void appr_free
__P((aproxy_t
*));
455 extern void aps_free
__P((ap_session_t
*));
456 extern int appr_check
__P((fr_info_t
*, struct nat
*));
457 extern aproxy_t
*appr_lookup
__P((u_int
, char *));
458 extern int appr_new
__P((fr_info_t
*, struct nat
*));
459 extern int appr_ioctl
__P((void *, ioctlcmd_t
, int, void *));
461 #endif /* _NETINET_IP_PROXY_H_ */