Define _KERNEL_STRUCTURES instead of _KERNEL to get just the
[dragonfly.git] / contrib / ipfilter / ip_proxy.h
1 /*
2  * Copyright (C) 1997-2001 by Darren Reed.
3  *
4  * See the IPFILTER.LICENCE file for details on licencing.
5  *
6  * $Id: ip_proxy.h,v 2.8.2.14 2002/09/02 12:19:26 darrenr Exp $
7  */
8
9 #ifndef __IP_PROXY_H__
10 #define __IP_PROXY_H__
11
12 #ifndef SOLARIS
13 #define SOLARIS (defined(sun) && (defined(__svr4__) || defined(__SVR4)))
14 #endif
15
16 #ifndef APR_LABELLEN
17 #define APR_LABELLEN    16
18 #endif
19 #define AP_SESS_SIZE    53
20
21 struct  nat;
22 struct  ipnat;
23
24 typedef struct  ap_tcp {
25         u_short apt_sport;      /* source port */
26         u_short apt_dport;      /* destination port */
27         short   apt_sel[2];     /* {seq,ack}{off,min} set selector */
28         short   apt_seqoff[2];  /* sequence # difference */
29         tcp_seq apt_seqmin[2];  /* don't change seq-off until after this */
30         short   apt_ackoff[2];  /* sequence # difference */
31         tcp_seq apt_ackmin[2];  /* don't change seq-off until after this */
32         u_char  apt_state[2];   /* connection state */
33 } ap_tcp_t;
34
35 typedef struct  ap_udp {
36         u_short apu_sport;      /* source port */
37         u_short apu_dport;      /* destination port */
38 } ap_udp_t;
39
40 typedef struct ap_session {
41         struct  aproxy  *aps_apr;
42         union {
43                 struct  ap_tcp  apu_tcp;
44                 struct  ap_udp  apu_udp;
45         } aps_un;
46         u_int   aps_flags;
47         U_QUAD_T aps_bytes;     /* bytes sent */
48         U_QUAD_T aps_pkts;      /* packets sent */
49         void    *aps_nat;       /* pointer back to nat struct */
50         void    *aps_data;      /* private data */
51         int     aps_p;          /* protocol */
52         int     aps_psiz;       /* size of private data */
53         struct  ap_session      *aps_hnext;
54         struct  ap_session      *aps_next;
55 } ap_session_t;
56
57 #define aps_sport       aps_un.apu_tcp.apt_sport
58 #define aps_dport       aps_un.apu_tcp.apt_dport
59 #define aps_sel         aps_un.apu_tcp.apt_sel
60 #define aps_seqoff      aps_un.apu_tcp.apt_seqoff
61 #define aps_seqmin      aps_un.apu_tcp.apt_seqmin
62 #define aps_state       aps_un.apu_tcp.apt_state
63 #define aps_ackoff      aps_un.apu_tcp.apt_ackoff
64 #define aps_ackmin      aps_un.apu_tcp.apt_ackmin
65
66
67 typedef struct  aproxy  {
68         struct  aproxy  *apr_next;
69         char    apr_label[APR_LABELLEN];        /* Proxy label # */
70         u_char  apr_p;          /* protocol */
71         int     apr_ref;        /* +1 per rule referencing it */
72         int     apr_flags;
73         int     (* apr_init) __P((void));
74         void    (* apr_fini) __P((void));
75         int     (* apr_new) __P((fr_info_t *, ip_t *,
76                                  ap_session_t *, struct nat *));
77         void    (* apr_del) __P((ap_session_t *));
78         int     (* apr_inpkt) __P((fr_info_t *, ip_t *,
79                                    ap_session_t *, struct nat *));
80         int     (* apr_outpkt) __P((fr_info_t *, ip_t *,
81                                     ap_session_t *, struct nat *));
82         int     (* apr_match) __P((fr_info_t *, ap_session_t *, struct nat *));
83 } aproxy_t;
84
85 #define APR_DELETE      1
86
87 #define APR_ERR(x)      (((x) & 0xffff) << 16)
88 #define APR_EXIT(x)     (((x) >> 16) & 0xffff)
89 #define APR_INC(x)      ((x) & 0xffff)
90
91 #define FTP_BUFSZ       160
92 /*
93  * For the ftp proxy.
94  */
95 typedef struct  ftpside {
96         char    *ftps_rptr;
97         char    *ftps_wptr;
98         u_32_t  ftps_seq[2];
99         u_32_t  ftps_len;
100         int     ftps_junk;
101         int     ftps_cmds;
102         int     ftps_cmd;
103         char    ftps_buf[FTP_BUFSZ];
104 } ftpside_t;
105
106 typedef struct  ftpinfo {
107         int             ftp_passok;
108         int             ftp_incok;
109         ftpside_t       ftp_side[2];
110 } ftpinfo_t;
111
112 /*
113  * Real audio proxy structure and #defines
114  */
115 typedef struct  raudio_s {
116         int     rap_seenpna;
117         int     rap_seenver;
118         int     rap_version;
119         int     rap_eos;        /* End Of Startup */
120         int     rap_gotid;
121         int     rap_gotlen;
122         int     rap_mode;
123         int     rap_sdone;
124         u_short rap_plport;
125         u_short rap_prport;
126         u_short rap_srport;
127         char    rap_svr[19];
128         u_32_t  rap_sbf;        /* flag to indicate which of the 19 bytes have
129                                  * been filled
130                                  */
131         tcp_seq rap_sseq;
132 } raudio_t;
133
134 #define RA_ID_END       0
135 #define RA_ID_UDP       1
136 #define RA_ID_ROBUST    7
137
138 #define RAP_M_UDP       1
139 #define RAP_M_ROBUST    2
140 #define RAP_M_TCP       4
141 #define RAP_M_UDP_ROBUST        (RAP_M_UDP|RAP_M_ROBUST)
142
143 /*
144  * IPSec proxy
145  */
146 typedef u_32_t  ipsec_cookie_t[2];
147
148 typedef struct ipsec_pxy {
149         ipsec_cookie_t  ipsc_icookie;
150         ipsec_cookie_t  ipsc_rcookie;
151         int             ipsc_rckset;
152         ipnat_t         ipsc_rule;
153         nat_t           *ipsc_nat;
154         ipstate_t       *ipsc_state;
155 } ipsec_pxy_t;
156
157 extern  ap_session_t    *ap_sess_tab[AP_SESS_SIZE];
158 extern  ap_session_t    *ap_sess_list;
159 extern  aproxy_t        ap_proxies[];
160 extern  int             ippr_ftp_pasvonly;
161
162 extern  int     appr_add __P((aproxy_t *));
163 extern  int     appr_del __P((aproxy_t *));
164 extern  int     appr_init __P((void));
165 extern  void    appr_unload __P((void));
166 extern  int     appr_ok __P((ip_t *, tcphdr_t *, struct ipnat *));
167 extern  int     appr_match __P((fr_info_t *, struct nat *));
168 extern  void    appr_free __P((aproxy_t *));
169 extern  void    aps_free __P((ap_session_t *));
170 extern  int     appr_check __P((ip_t *, fr_info_t *, struct nat *));
171 extern  aproxy_t        *appr_lookup __P((u_int, char *));
172 extern  int     appr_new __P((fr_info_t *, ip_t *, struct nat *));
173
174 #endif /* __IP_PROXY_H__ */