4 * Copyright (C) 1997-2001 by Darren Reed.
6 * See the IPFILTER.LICENCE file for details on licencing.
9 * Id: ip_proxy.h,v 2.31.2.2 2005/03/12 19:33:48 darrenr Exp
12 #ifndef __IP_PROXY_H__
13 #define __IP_PROXY_H__
16 #define SOLARIS (defined(sun) && (defined(__svr4__) || defined(__SVR4)))
19 #if defined(__STDC__) || defined(__GNUC__) || defined(_AIX51)
20 #define SIOCPROXY _IOWR('r', 64, struct ap_control)
22 #define SIOCPROXY _IOWR(r, 64, struct ap_control)
26 #define APR_LABELLEN 16
28 #define AP_SESS_SIZE 53
34 typedef struct ap_tcp {
35 u_short apt_sport; /* source port */
36 u_short apt_dport; /* destination port */
37 short apt_sel[2]; /* {seq,ack}{off,min} set selector */
38 short apt_seqoff[2]; /* sequence # difference */
39 u_32_t apt_seqmin[2]; /* don't change seq-off until after this */
40 short apt_ackoff[2]; /* sequence # difference */
41 u_32_t apt_ackmin[2]; /* don't change seq-off until after this */
42 u_char apt_state[2]; /* connection state */
45 typedef struct ap_udp {
46 u_short apu_sport; /* source port */
47 u_short apu_dport; /* destination port */
50 typedef struct ap_session {
51 struct aproxy *aps_apr;
53 struct ap_tcp apu_tcp;
54 struct ap_udp apu_udp;
57 U_QUAD_T aps_bytes; /* bytes sent */
58 U_QUAD_T aps_pkts; /* packets sent */
59 void *aps_nat; /* pointer back to nat struct */
60 void *aps_data; /* private data */
61 int aps_p; /* protocol */
62 int aps_psiz; /* size of private data */
63 struct ap_session *aps_hnext;
64 struct ap_session *aps_next;
67 #define aps_sport aps_un.apu_tcp.apt_sport
68 #define aps_dport aps_un.apu_tcp.apt_dport
69 #define aps_sel aps_un.apu_tcp.apt_sel
70 #define aps_seqoff aps_un.apu_tcp.apt_seqoff
71 #define aps_seqmin aps_un.apu_tcp.apt_seqmin
72 #define aps_state aps_un.apu_tcp.apt_state
73 #define aps_ackoff aps_un.apu_tcp.apt_ackoff
74 #define aps_ackmin aps_un.apu_tcp.apt_ackmin
77 typedef struct ap_control {
78 char apc_label[APR_LABELLEN];
81 * The following fields are upto the proxy's apr_ctl routine to deal
82 * with. When the proxy gets this in kernel space, apc_data will
83 * point to a malloc'd region of memory of apc_dsize bytes. If the
84 * proxy wants to keep that memory, it must set apc_data to NULL
85 * before it returns. It is expected if this happens that it will
86 * take care to free it in apr_fini or otherwise as appropriate.
87 * apc_cmd is provided as a standard place to put simple commands,
88 * with apc_arg being available to put a simple arg.
97 typedef struct aproxy {
98 struct aproxy *apr_next;
99 char apr_label[APR_LABELLEN]; /* Proxy label # */
100 u_char apr_p; /* protocol */
101 int apr_ref; /* +1 per rule referencing it */
103 int (* apr_init) __P((void));
104 void (* apr_fini) __P((void));
105 int (* apr_new) __P((fr_info_t *, ap_session_t *, struct nat *));
106 void (* apr_del) __P((ap_session_t *));
107 int (* apr_inpkt) __P((fr_info_t *, ap_session_t *, struct nat *));
108 int (* apr_outpkt) __P((fr_info_t *, ap_session_t *, struct nat *));
109 int (* apr_match) __P((fr_info_t *, ap_session_t *, struct nat *));
110 int (* apr_ctl) __P((struct aproxy *, struct ap_control *));
115 #define APR_ERR(x) ((x) << 16)
116 #define APR_EXIT(x) (((x) >> 16) & 0xffff)
117 #define APR_INC(x) ((x) & 0xffff)
120 * Generic #define's to cover missing things in the kernel
123 #define isdigit(x) ((x) >= '0' && (x) <= '9')
126 #define isupper(x) (((unsigned)(x) >= 'A') && ((unsigned)(x) <= 'Z'))
129 #define islower(x) (((unsigned)(x) >= 'a') && ((unsigned)(x) <= 'z'))
132 #define isalpha(x) (isupper(x) || islower(x))
135 #define toupper(x) (isupper(x) ? (x) : (x) - 'a' + 'A')
138 #define isspace(x) (((x) == ' ') || ((x) == '\r') || ((x) == '\n') || \
139 ((x) == '\t') || ((x) == '\b'))
143 * This is the scratch buffer size used to hold strings from the TCP stream
144 * that we may want to parse. It's an arbitrary size, really, but it must
145 * be at least as large as IPF_FTPBUFSZ.
147 #define FTP_BUFSZ 120
150 * This buffer, however, doesn't need to be nearly so big. It just needs to
151 * be able to squeeze in the largest command it needs to rewrite, Which ones
152 * does it rewrite? EPRT, PORT, 227 replies.
154 #define IPF_FTPBUFSZ 80 /* This *MUST* be >= 53! */
156 typedef struct ftpside {
162 int ftps_junk; /* 2 = no cr/lf yet, 1 = cannot parse */
164 char ftps_buf[FTP_BUFSZ];
167 typedef struct ftpinfo {
170 ftpside_t ftp_side[2];
177 typedef struct ircinfo {
190 * Real audio proxy structure and #defines
192 typedef struct raudio_s {
196 int rap_eos; /* End Of Startup */
205 u_32_t rap_sbf; /* flag to indicate which of the 19 bytes have
213 #define RA_ID_ROBUST 7
216 #define RAP_M_ROBUST 2
218 #define RAP_M_UDP_ROBUST (RAP_M_UDP|RAP_M_ROBUST)
224 typedef struct msnrpcinfo {
228 struct in_addr mri_raddr;
236 typedef u_32_t ipsec_cookie_t[2];
238 typedef struct ipsec_pxy {
239 ipsec_cookie_t ipsc_icookie;
240 ipsec_cookie_t ipsc_rcookie;
244 struct ipstate *ipsc_state;
250 typedef struct pptp_side {
251 u_32_t pptps_nexthdr;
258 char pptps_buffer[512];
261 typedef struct pptp_pxy {
264 struct ipstate *pptp_state;
265 u_short pptp_call[2];
266 pptp_side_t pptp_side[2];
273 #define RPCB_MAXMSG 888
274 #define RPCB_RES_PMAP 0 /* Response contains a v2 port. */
275 #define RPCB_RES_STRING 1 /* " " " v3 (GETADDR) string. */
276 #define RPCB_RES_LIST 2 /* " " " v4 (GETADDRLIST) list. */
277 #define RPCB_MAXREQS 32 /* Arbitrary limit on tracked transactions */
279 #define RPCB_REQMIN 40
280 #define RPCB_REQMAX 888
281 #define RPCB_REPMIN 20
282 #define RPCB_REPMAX 604 /* XXX double check this! */
285 * These macros determine the number of bytes between p and the end of
286 * r->rs_buf relative to l.
288 #define RPCB_BUF_END(r) (char *)((r)->rm_msgbuf + (r)->rm_buflen)
289 #define RPCB_BUF_GEQ(r, p, l) \
290 ((RPCB_BUF_END((r)) > (char *)(p)) && \
291 ((RPCB_BUF_END((r)) - (char *)(p)) >= (l)))
292 #define RPCB_BUF_EQ(r, p, l) \
293 (RPCB_BUF_END((r)) == ((char *)(p) + (l)))
296 * The following correspond to RPC(B) detailed in RFC183[13].
300 #define RPCB_MSG_VERSION 2
301 #define RPCB_PROG 100000
302 #define RPCB_GETPORT 3
303 #define RPCB_GETADDR 3
304 #define RPCB_GETADDRLIST 11
305 #define RPCB_MSG_ACCEPTED 0
306 #define RPCB_MSG_DENIED 1
308 /* BEGIN (Generic XDR structures) */
309 typedef struct xdr_string {
314 typedef struct xdr_auth {
315 /* u_32_t xa_flavor; */
316 xdr_string_t xa_string;
319 typedef struct xdr_uaddr {
325 typedef struct xdr_proto {
330 #define xu_xslen xu_str.xs_len
331 #define xu_xsstr xu_str.xs_str
332 #define xp_xslen xp_str.xs_len
333 #define xp_xsstr xp_str.xs_str
334 /* END (Generic XDR structures) */
336 /* BEGIN (RPC call structures) */
337 typedef struct pmap_args {
338 /* u_32_t pa_prog; */
339 /* u_32_t pa_vers; */
341 /* u_32_t pa_port; */
344 typedef struct rpcb_args {
345 /* u_32_t *ra_prog; */
346 /* u_32_t *ra_vers; */
347 xdr_proto_t ra_netid;
348 xdr_uaddr_t ra_maddr;
349 /* xdr_string_t ra_owner; */
352 typedef struct rpc_call {
353 /* u_32_t rc_rpcvers; */
354 /* u_32_t rc_prog; */
357 xdr_auth_t rc_authcred;
358 xdr_auth_t rc_authverf;
360 pmap_args_t ra_pmapargs;
361 rpcb_args_t ra_rpcbargs;
365 #define rc_pmapargs rpcb_args.ra_pmapargs
366 #define rc_rpcbargs rpcb_args.ra_rpcbargs
367 /* END (RPC call structures) */
369 /* BEGIN (RPC reply structures) */
370 typedef struct rpcb_entry {
371 xdr_uaddr_t re_maddr;
372 xdr_proto_t re_netid;
373 /* u_32_t re_semantics; */
374 xdr_string_t re_family;
375 xdr_proto_t re_proto;
376 u_32_t *re_more; /* 1 == another entry follows */
379 typedef struct rpcb_listp {
380 u_32_t *rl_list; /* 1 == list follows */
382 rpcb_entry_t rl_entries[2]; /* TCP / UDP only */
385 typedef struct rpc_resp {
386 /* u_32_t rr_acceptdeny; */
387 /* Omitted 'message denied' fork; we don't care about rejects. */
388 xdr_auth_t rr_authverf;
389 /* u_32_t *rr_astat; */
392 xdr_uaddr_t resp_getaddr;
393 rpcb_listp_t resp_getaddrlist;
397 #define rr_v2 rpcb_reply.resp_pmap
398 #define rr_v3 rpcb_reply.resp_getaddr
399 #define rr_v4 rpcb_reply.resp_getaddrlist
400 /* END (RPC reply structures) */
402 /* BEGIN (RPC message structure & macros) */
403 typedef struct rpc_msg {
404 char rm_msgbuf[RPCB_MAXMSG]; /* RPCB data buffer */
407 /* u_32_t Call vs Reply */
414 #define rm_call rm_body.rb_call
415 #define rm_resp rm_body.rb_resp
416 /* END (RPC message structure & macros) */
419 * These code paths aren't hot enough to warrant per transaction
422 typedef struct rpcb_xact {
423 struct rpcb_xact *rx_next;
424 struct rpcb_xact **rx_pnext;
425 u_32_t rx_xid; /* RPC transmission ID */
426 u_int rx_type; /* RPCB response type */
427 u_int rx_ref; /* reference count */
428 u_int rx_proto; /* transport protocol (v2 only) */
431 typedef struct rpcb_session {
432 ipfmutex_t rs_rxlock;
433 rpcb_xact_t *rs_rxlist;
437 * For an explanation, please see the following:
438 * RFC1832 - Sections 3.11, 4.4, and 4.5.
440 #define XDRALIGN(x) ((((x) % 4) != 0) ? ((((x) + 3) / 4) * 4) : (x))
442 extern ap_session_t *ap_sess_tab[AP_SESS_SIZE];
443 extern ap_session_t *ap_sess_list;
444 extern aproxy_t ap_proxies[];
445 extern int ippr_ftp_pasvonly;
446 extern int ipf_proxy_debug;
448 extern int appr_add __P((aproxy_t *));
449 extern int appr_ctl __P((ap_ctl_t *));
450 extern int appr_del __P((aproxy_t *));
451 extern int appr_init __P((void));
452 extern void appr_unload __P((void));
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 *));
457 extern int appr_check __P((fr_info_t *, struct nat *));
458 extern aproxy_t *appr_lookup __P((u_int, char *));
459 extern int appr_new __P((fr_info_t *, struct nat *));
460 extern int appr_ioctl __P((caddr_t, ioctlcmd_t, int, void *));
462 #endif /* __IP_PROXY_H__ */