2 * Copyright (C) 1997-2001 by Darren Reed.
4 * See the IPFILTER.LICENCE file for details on licencing.
6 * $Id: ip_proxy.h,v 2.31.2.3 2005/06/18 02:41:33 darrenr Exp $
8 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
9 * Use is subject to license terms.
12 #ifndef __IP_PROXY_H__
13 #define __IP_PROXY_H__
18 #if (defined(sun) && (defined(__svr4__) || defined(__SVR4)))
24 #if defined(__STDC__) || defined(__GNUC__) || defined(_AIX51)
25 #define SIOCPROXY _IOWR('r', 64, struct ap_control)
27 #define SIOCPROXY _IOWR(r, 64, struct ap_control)
31 #define APR_LABELLEN 16
33 #define AP_SESS_SIZE 53
39 typedef struct ap_tcp
{
40 u_short apt_sport
; /* source port */
41 u_short apt_dport
; /* destination port */
42 short apt_sel
[2]; /* {seq,ack}{off,min} set selector */
43 short apt_seqoff
[2]; /* sequence # difference */
44 u_32_t apt_seqmin
[2]; /* don't change seq-off until after this */
45 short apt_ackoff
[2]; /* sequence # difference */
46 u_32_t apt_ackmin
[2]; /* don't change seq-off until after this */
47 u_char apt_state
[2]; /* connection state */
50 typedef struct ap_udp
{
51 u_short apu_sport
; /* source port */
52 u_short apu_dport
; /* destination port */
55 typedef struct ap_session
{
56 struct aproxy
*aps_apr
;
58 struct ap_tcp apu_tcp
;
59 struct ap_udp apu_udp
;
62 U_QUAD_T aps_bytes
; /* bytes sent */
63 U_QUAD_T aps_pkts
; /* packets sent */
64 void *aps_nat
; /* pointer back to nat struct */
65 void *aps_data
; /* private data */
66 int aps_p
; /* protocol */
67 int aps_psiz
; /* size of private data */
68 struct ap_session
*aps_hnext
;
69 struct ap_session
*aps_next
;
72 #define aps_sport aps_un.apu_tcp.apt_sport
73 #define aps_dport aps_un.apu_tcp.apt_dport
74 #define aps_sel aps_un.apu_tcp.apt_sel
75 #define aps_seqoff aps_un.apu_tcp.apt_seqoff
76 #define aps_seqmin aps_un.apu_tcp.apt_seqmin
77 #define aps_state aps_un.apu_tcp.apt_state
78 #define aps_ackoff aps_un.apu_tcp.apt_ackoff
79 #define aps_ackmin aps_un.apu_tcp.apt_ackmin
82 typedef struct ap_control
{
83 char apc_label
[APR_LABELLEN
];
86 * The following fields are upto the proxy's apr_ctl routine to deal
87 * with. When the proxy gets this in kernel space, apc_data will
88 * point to a malloc'd region of memory of apc_dsize bytes. If the
89 * proxy wants to keep that memory, it must set apc_data to NULL
90 * before it returns. It is expected if this happens that it will
91 * take care to free it in apr_fini or otherwise as appropriate.
92 * apc_cmd is provided as a standard place to put simple commands,
93 * with apc_arg being available to put a simple arg.
102 typedef struct aproxy
{
103 struct aproxy
*apr_next
;
104 char apr_label
[APR_LABELLEN
]; /* Proxy label # */
105 u_char apr_p
; /* protocol */
106 int apr_ref
; /* +1 per rule referencing it */
108 void *apr_private
; /* proxy private data */
109 int (* apr_init
) __P((void **, ipf_stack_t
*));
110 void (* apr_fini
) __P((void **, ipf_stack_t
*));
111 int (* apr_new
) __P((fr_info_t
*, ap_session_t
*, struct nat
*, void *));
112 void (* apr_del
) __P((ap_session_t
*, void *, ipf_stack_t
*));
113 int (* apr_inpkt
) __P((fr_info_t
*, ap_session_t
*, struct nat
*, void *));
114 int (* apr_outpkt
) __P((fr_info_t
*, ap_session_t
*, struct nat
*, void *));
115 int (* apr_match
) __P((fr_info_t
*, ap_session_t
*, struct nat
*, void *));
116 int (* apr_ctl
) __P((struct aproxy
*, struct ap_control
*, void *));
121 #define APR_ERR(x) ((x) << 16)
122 #define APR_EXIT(x) (((x) >> 16) & 0xffff)
123 #define APR_INC(x) ((x) & 0xffff)
126 * Generic #define's to cover missing things in the kernel
129 #define isdigit(x) ((x) >= '0' && (x) <= '9')
132 #define isupper(x) (((unsigned)(x) >= 'A') && ((unsigned)(x) <= 'Z'))
135 #define islower(x) (((unsigned)(x) >= 'a') && ((unsigned)(x) <= 'z'))
138 #define isalpha(x) (isupper(x) || islower(x))
141 #define toupper(x) (isupper(x) ? (x) : (x) - 'a' + 'A')
144 #define isspace(x) (((x) == ' ') || ((x) == '\r') || ((x) == '\n') || \
145 ((x) == '\t') || ((x) == '\b'))
149 * This is the scratch buffer size used to hold strings from the TCP stream
150 * that we may want to parse. It's an arbitrary size, really, but it must
151 * be at least as large as IPF_FTPBUFSZ.
153 #define FTP_BUFSZ 120
156 * This buffer, however, doesn't need to be nearly so big. It just needs to
157 * be able to squeeze in the largest command it needs to rewrite, Which ones
158 * does it rewrite? EPRT, PORT, 227 replies.
160 #define IPF_FTPBUFSZ 80 /* This *MUST* be >= 53! */
162 typedef struct ftpside
{
168 int ftps_junk
; /* 2 = no cr/lf yet, 1 = cannot parse */
170 char ftps_buf
[FTP_BUFSZ
];
173 typedef struct ftpinfo
{
176 ftpside_t ftp_side
[2];
183 typedef struct ircinfo
{
196 * Real audio proxy structure and #defines
198 typedef struct raudio_s
{
202 int rap_eos
; /* End Of Startup */
211 u_32_t rap_sbf
; /* flag to indicate which of the 19 bytes have
219 #define RA_ID_ROBUST 7
222 #define RAP_M_ROBUST 2
224 #define RAP_M_UDP_ROBUST (RAP_M_UDP|RAP_M_ROBUST)
230 typedef struct msnrpcinfo
{
234 struct in_addr mri_raddr
;
242 typedef u_32_t ipsec_cookie_t
[2];
244 typedef struct ipsec_pxy
{
245 ipsec_cookie_t ipsc_icookie
;
246 ipsec_cookie_t ipsc_rcookie
;
250 struct ipstate
*ipsc_state
;
256 typedef struct pptp_side
{
257 u_32_t pptps_nexthdr
;
264 char pptps_buffer
[512];
267 typedef struct pptp_pxy
{
270 struct ipstate
*pptp_state
;
271 u_short pptp_call
[2];
272 pptp_side_t pptp_side
[2];
279 #define RPCB_MAXMSG 888
280 #define RPCB_RES_PMAP 0 /* Response contains a v2 port. */
281 #define RPCB_RES_STRING 1 /* " " " v3 (GETADDR) string. */
282 #define RPCB_RES_LIST 2 /* " " " v4 (GETADDRLIST) list. */
283 #define RPCB_MAXREQS 32 /* Arbitrary limit on tracked transactions */
285 #define RPCB_REQMIN 40
286 #define RPCB_REQMAX 888
287 #define RPCB_REPMIN 20
288 #define RPCB_REPMAX 604 /* XXX double check this! */
291 * These macros determine the number of bytes between p and the end of
292 * r->rs_buf relative to l.
294 #define RPCB_BUF_END(r) (char *)((r)->rm_msgbuf + (r)->rm_buflen)
295 #define RPCB_BUF_GEQ(r, p, l) \
296 ((RPCB_BUF_END((r)) > (char *)(p)) && \
297 ((RPCB_BUF_END((r)) - (char *)(p)) >= (l)))
298 #define RPCB_BUF_EQ(r, p, l) \
299 (RPCB_BUF_END((r)) == ((char *)(p) + (l)))
302 * The following correspond to RPC(B) detailed in RFC183[13].
306 #define RPCB_MSG_VERSION 2
307 #define RPCB_PROG 100000
308 #define RPCB_GETPORT 3
309 #define RPCB_GETADDR 3
310 #define RPCB_GETADDRLIST 11
311 #define RPCB_MSG_ACCEPTED 0
312 #define RPCB_MSG_DENIED 1
314 /* BEGIN (Generic XDR structures) */
315 typedef struct xdr_string
{
320 typedef struct xdr_auth
{
321 /* u_32_t xa_flavor; */
322 xdr_string_t xa_string
;
325 typedef struct xdr_uaddr
{
331 typedef struct xdr_proto
{
336 #define xu_xslen xu_str.xs_len
337 #define xu_xsstr xu_str.xs_str
338 #define xp_xslen xp_str.xs_len
339 #define xp_xsstr xp_str.xs_str
340 /* END (Generic XDR structures) */
342 /* BEGIN (RPC call structures) */
343 typedef struct pmap_args
{
344 /* u_32_t pa_prog; */
345 /* u_32_t pa_vers; */
347 /* u_32_t pa_port; */
350 typedef struct rpcb_args
{
351 /* u_32_t *ra_prog; */
352 /* u_32_t *ra_vers; */
353 xdr_proto_t ra_netid
;
354 xdr_uaddr_t ra_maddr
;
355 /* xdr_string_t ra_owner; */
358 typedef struct rpc_call
{
359 /* u_32_t rc_rpcvers; */
360 /* u_32_t rc_prog; */
363 xdr_auth_t rc_authcred
;
364 xdr_auth_t rc_authverf
;
366 pmap_args_t ra_pmapargs
;
367 rpcb_args_t ra_rpcbargs
;
371 #define rc_pmapargs rpcb_args.ra_pmapargs
372 #define rc_rpcbargs rpcb_args.ra_rpcbargs
373 /* END (RPC call structures) */
375 /* BEGIN (RPC reply structures) */
376 typedef struct rpcb_entry
{
377 xdr_uaddr_t re_maddr
;
378 xdr_proto_t re_netid
;
379 /* u_32_t re_semantics; */
380 xdr_string_t re_family
;
381 xdr_proto_t re_proto
;
382 u_32_t
*re_more
; /* 1 == another entry follows */
385 typedef struct rpcb_listp
{
386 u_32_t
*rl_list
; /* 1 == list follows */
388 rpcb_entry_t rl_entries
[2]; /* TCP / UDP only */
391 typedef struct rpc_resp
{
392 /* u_32_t rr_acceptdeny; */
393 /* Omitted 'message denied' fork; we don't care about rejects. */
394 xdr_auth_t rr_authverf
;
395 /* u_32_t *rr_astat; */
398 xdr_uaddr_t resp_getaddr
;
399 rpcb_listp_t resp_getaddrlist
;
403 #define rr_v2 rpcb_reply.resp_pmap
404 #define rr_v3 rpcb_reply.resp_getaddr
405 #define rr_v4 rpcb_reply.resp_getaddrlist
406 /* END (RPC reply structures) */
408 /* BEGIN (RPC message structure & macros) */
409 typedef struct rpc_msg
{
410 char rm_msgbuf
[RPCB_MAXMSG
]; /* RPCB data buffer */
413 /* u_32_t Call vs Reply */
420 #define rm_call rm_body.rb_call
421 #define rm_resp rm_body.rb_resp
422 /* END (RPC message structure & macros) */
425 * These code paths aren't hot enough to warrant per transaction
428 typedef struct rpcb_xact
{
429 struct rpcb_xact
*rx_next
;
430 struct rpcb_xact
**rx_pnext
;
431 u_32_t rx_xid
; /* RPC transmission ID */
432 u_int rx_type
; /* RPCB response type */
433 u_int rx_ref
; /* reference count */
434 u_int rx_proto
; /* transport protocol (v2 only) */
437 typedef struct rpcb_session
{
438 ipfmutex_t rs_rxlock
;
439 rpcb_xact_t
*rs_rxlist
;
443 * For an explanation, please see the following:
444 * RFC1832 - Sections 3.11, 4.4, and 4.5.
446 #define XDRALIGN(x) ((((x) % 4) != 0) ? ((((x) + 3) / 4) * 4) : (x))
448 extern int appr_add
__P((aproxy_t
*, ipf_stack_t
*));
449 extern int appr_ctl
__P((ap_ctl_t
*, ipf_stack_t
*));
450 extern int appr_del
__P((aproxy_t
*, ipf_stack_t
*));
451 extern int appr_init
__P((ipf_stack_t
*));
452 extern void appr_unload
__P((ipf_stack_t
*));
453 extern int appr_ok
__P((fr_info_t
*, tcphdr_t
*, struct ipnat
*));
454 extern int appr_match
__P((fr_info_t
*, struct nat
*));
455 extern void appr_free
__P((aproxy_t
*));
456 extern void aps_free
__P((ap_session_t
*, ipf_stack_t
*));
457 extern int appr_check
__P((fr_info_t
*, struct nat
*));
458 extern aproxy_t
*appr_lookup
__P((u_int
, char *, ipf_stack_t
*));
459 extern int appr_new
__P((fr_info_t
*, struct nat
*));
460 extern int appr_ioctl
__P((caddr_t
, ioctlcmd_t
, int, ipf_stack_t
*));
462 #endif /* __IP_PROXY_H__ */