ip_pptp_pxy.c revision 1.1 1 1.1 christos /* $NetBSD: ip_pptp_pxy.c,v 1.1 2012/03/23 20:37:01 christos Exp $ */
2 1.1 christos
3 1.1 christos /*
4 1.1 christos * Copyright (C) 2011 by Darren Reed.
5 1.1 christos *
6 1.1 christos * Simple PPTP transparent proxy for in-kernel use. For use with the NAT
7 1.1 christos * code.
8 1.1 christos *
9 1.1 christos * Id
10 1.1 christos *
11 1.1 christos */
12 1.1 christos #define IPF_PPTP_PROXY
13 1.1 christos
14 1.1 christos typedef struct pptp_hdr {
15 1.1 christos u_short pptph_len;
16 1.1 christos u_short pptph_type;
17 1.1 christos u_32_t pptph_cookie;
18 1.1 christos } pptp_hdr_t;
19 1.1 christos
20 1.1 christos #define PPTP_MSGTYPE_CTL 1
21 1.1 christos #define PPTP_MTCTL_STARTREQ 1
22 1.1 christos #define PPTP_MTCTL_STARTREP 2
23 1.1 christos #define PPTP_MTCTL_STOPREQ 3
24 1.1 christos #define PPTP_MTCTL_STOPREP 4
25 1.1 christos #define PPTP_MTCTL_ECHOREQ 5
26 1.1 christos #define PPTP_MTCTL_ECHOREP 6
27 1.1 christos #define PPTP_MTCTL_OUTREQ 7
28 1.1 christos #define PPTP_MTCTL_OUTREP 8
29 1.1 christos #define PPTP_MTCTL_INREQ 9
30 1.1 christos #define PPTP_MTCTL_INREP 10
31 1.1 christos #define PPTP_MTCTL_INCONNECT 11
32 1.1 christos #define PPTP_MTCTL_CLEAR 12
33 1.1 christos #define PPTP_MTCTL_DISCONNECT 13
34 1.1 christos #define PPTP_MTCTL_WANERROR 14
35 1.1 christos #define PPTP_MTCTL_LINKINFO 15
36 1.1 christos
37 1.1 christos
38 1.1 christos void ipf_p_pptp_main_load __P((void));
39 1.1 christos void ipf_p_pptp_main_unload __P((void));
40 1.1 christos int ipf_p_pptp_new __P((void *, fr_info_t *, ap_session_t *, nat_t *));
41 1.1 christos void ipf_p_pptp_del __P((ipf_main_softc_t *, ap_session_t *));
42 1.1 christos int ipf_p_pptp_inout __P((void *, fr_info_t *, ap_session_t *, nat_t *));
43 1.1 christos void ipf_p_pptp_donatstate __P((fr_info_t *, nat_t *, pptp_pxy_t *));
44 1.1 christos int ipf_p_pptp_message __P((fr_info_t *, nat_t *, pptp_pxy_t *, pptp_side_t *));
45 1.1 christos int ipf_p_pptp_nextmessage __P((fr_info_t *, nat_t *, pptp_pxy_t *, int));
46 1.1 christos int ipf_p_pptp_mctl __P((fr_info_t *, nat_t *, pptp_pxy_t *, pptp_side_t *));
47 1.1 christos
48 1.1 christos static frentry_t pptpfr;
49 1.1 christos
50 1.1 christos static int pptp_proxy_init = 0;
51 1.1 christos static int ipf_p_pptp_debug = 0;
52 1.1 christos static int ipf_p_pptp_gretimeout = IPF_TTLVAL(120); /* 2 minutes */
53 1.1 christos
54 1.1 christos
55 1.1 christos /*
56 1.1 christos * PPTP application proxy initialization.
57 1.1 christos */
58 1.1 christos void
59 1.1 christos ipf_p_pptp_main_load()
60 1.1 christos {
61 1.1 christos bzero((char *)&pptpfr, sizeof(pptpfr));
62 1.1 christos pptpfr.fr_ref = 1;
63 1.1 christos pptpfr.fr_age[0] = ipf_p_pptp_gretimeout;
64 1.1 christos pptpfr.fr_age[1] = ipf_p_pptp_gretimeout;
65 1.1 christos pptpfr.fr_flags = FR_OUTQUE|FR_PASS|FR_QUICK|FR_KEEPSTATE;
66 1.1 christos MUTEX_INIT(&pptpfr.fr_lock, "PPTP proxy rule lock");
67 1.1 christos pptp_proxy_init = 1;
68 1.1 christos }
69 1.1 christos
70 1.1 christos
71 1.1 christos void
72 1.1 christos ipf_p_pptp_main_unload()
73 1.1 christos {
74 1.1 christos if (pptp_proxy_init == 1) {
75 1.1 christos MUTEX_DESTROY(&pptpfr.fr_lock);
76 1.1 christos pptp_proxy_init = 0;
77 1.1 christos }
78 1.1 christos }
79 1.1 christos
80 1.1 christos
81 1.1 christos /*
82 1.1 christos * Setup for a new PPTP proxy.
83 1.1 christos *
84 1.1 christos * NOTE: The printf's are broken up with %s in them to prevent them being
85 1.1 christos * optimised into puts statements on FreeBSD (this doesn't exist in the kernel)
86 1.1 christos */
87 1.1 christos int
88 1.1 christos ipf_p_pptp_new(arg, fin, aps, nat)
89 1.1 christos void *arg;
90 1.1 christos fr_info_t *fin;
91 1.1 christos ap_session_t *aps;
92 1.1 christos nat_t *nat;
93 1.1 christos {
94 1.1 christos pptp_pxy_t *pptp;
95 1.1 christos ipnat_t *ipn, *np;
96 1.1 christos ip_t *ip;
97 1.1 christos
98 1.1 christos ip = fin->fin_ip;
99 1.1 christos
100 1.1 christos if (ipf_nat_outlookup(fin, 0, IPPROTO_GRE, nat->nat_osrcip,
101 1.1 christos ip->ip_dst) != NULL) {
102 1.1 christos if (ipf_p_pptp_debug > 0)
103 1.1 christos printf("ipf_p_pptp_new: GRE session already exists\n");
104 1.1 christos return -1;
105 1.1 christos }
106 1.1 christos np = nat->nat_ptr;
107 1.1 christos
108 1.1 christos aps->aps_psiz = sizeof(*pptp) + np->in_namelen;
109 1.1 christos KMALLOCS(aps->aps_data, pptp_pxy_t *, aps->aps_psiz);
110 1.1 christos if (aps->aps_data == NULL) {
111 1.1 christos if (ipf_p_pptp_debug > 0)
112 1.1 christos printf("ipf_p_pptp_new: malloc for aps_data failed\n");
113 1.1 christos return -1;
114 1.1 christos }
115 1.1 christos
116 1.1 christos /*
117 1.1 christos * Create NAT rule against which the tunnel/transport mapping is
118 1.1 christos * created. This is required because the current NAT rule does not
119 1.1 christos * describe GRE but TCP instead.
120 1.1 christos */
121 1.1 christos pptp = aps->aps_data;
122 1.1 christos bzero((char *)pptp, sizeof(*pptp));
123 1.1 christos ipn = &pptp->pptp_rule;
124 1.1 christos ipn->in_ifps[0] = fin->fin_ifp;
125 1.1 christos ipn->in_apr = NULL;
126 1.1 christos ipn->in_use = 1;
127 1.1 christos ipn->in_hits = 1;
128 1.1 christos ipn->in_ippip = 1;
129 1.1 christos ipn->in_snip = ntohl(nat->nat_nsrcaddr);
130 1.1 christos ipn->in_nsrcaddr = fin->fin_saddr;
131 1.1 christos ipn->in_dnip = ntohl(nat->nat_ndstaddr);
132 1.1 christos ipn->in_ndstaddr = nat->nat_ndstaddr;
133 1.1 christos ipn->in_redir = np->in_redir;
134 1.1 christos ipn->in_osrcaddr = nat->nat_osrcaddr;
135 1.1 christos ipn->in_odstaddr = nat->nat_odstaddr;
136 1.1 christos ipn->in_osrcmsk = 0xffffffff;
137 1.1 christos ipn->in_nsrcmsk = 0xffffffff;
138 1.1 christos ipn->in_odstmsk = 0xffffffff;
139 1.1 christos ipn->in_ndstmsk = 0xffffffff;
140 1.1 christos MUTEX_INIT(&ipn->in_lock, "pptp proxy NAT rule");
141 1.1 christos
142 1.1 christos ipn->in_namelen = np->in_namelen;
143 1.1 christos bcopy(np->in_names, ipn->in_ifnames, ipn->in_namelen);
144 1.1 christos ipn->in_ifnames[0] = np->in_ifnames[0];
145 1.1 christos ipn->in_ifnames[1] = np->in_ifnames[1];
146 1.1 christos
147 1.1 christos ipn->in_pr[0] = IPPROTO_GRE;
148 1.1 christos ipn->in_pr[1] = IPPROTO_GRE;
149 1.1 christos
150 1.1 christos pptp->pptp_side[0].pptps_wptr = pptp->pptp_side[0].pptps_buffer;
151 1.1 christos pptp->pptp_side[1].pptps_wptr = pptp->pptp_side[1].pptps_buffer;
152 1.1 christos return 0;
153 1.1 christos }
154 1.1 christos
155 1.1 christos
156 1.1 christos void
157 1.1 christos ipf_p_pptp_donatstate(fin, nat, pptp)
158 1.1 christos fr_info_t *fin;
159 1.1 christos nat_t *nat;
160 1.1 christos pptp_pxy_t *pptp;
161 1.1 christos {
162 1.1 christos ipf_main_softc_t *softc = fin->fin_main_soft;
163 1.1 christos fr_info_t fi;
164 1.1 christos grehdr_t gre;
165 1.1 christos nat_t *nat2;
166 1.1 christos u_char p;
167 1.1 christos ip_t *ip;
168 1.1 christos
169 1.1 christos ip = fin->fin_ip;
170 1.1 christos p = ip->ip_p;
171 1.1 christos
172 1.1 christos nat2 = pptp->pptp_nat;
173 1.1 christos if ((nat2 == NULL) || (pptp->pptp_state == NULL)) {
174 1.1 christos bcopy((char *)fin, (char *)&fi, sizeof(fi));
175 1.1 christos bzero((char *)&gre, sizeof(gre));
176 1.1 christos fi.fin_fi.fi_p = IPPROTO_GRE;
177 1.1 christos fi.fin_fr = &pptpfr;
178 1.1 christos if ((nat->nat_dir == NAT_OUTBOUND && fin->fin_out) ||
179 1.1 christos (nat->nat_dir == NAT_INBOUND && !fin->fin_out)) {
180 1.1 christos fi.fin_data[0] = pptp->pptp_call[0];
181 1.1 christos fi.fin_data[1] = pptp->pptp_call[1];
182 1.1 christos } else {
183 1.1 christos fi.fin_data[0] = pptp->pptp_call[1];
184 1.1 christos fi.fin_data[1] = pptp->pptp_call[0];
185 1.1 christos }
186 1.1 christos ip = fin->fin_ip;
187 1.1 christos ip->ip_p = IPPROTO_GRE;
188 1.1 christos fi.fin_flx &= ~(FI_TCPUDP|FI_STATE|FI_FRAG);
189 1.1 christos fi.fin_flx |= FI_IGNORE;
190 1.1 christos fi.fin_dp = &gre;
191 1.1 christos gre.gr_flags = htons(1 << 13);
192 1.1 christos
193 1.1 christos fi.fin_fi.fi_saddr = nat->nat_osrcaddr;
194 1.1 christos fi.fin_fi.fi_daddr = nat->nat_odstaddr;
195 1.1 christos }
196 1.1 christos
197 1.1 christos /*
198 1.1 christos * Update NAT timeout/create NAT if missing.
199 1.1 christos */
200 1.1 christos if (nat2 != NULL)
201 1.1 christos ipf_queueback(softc->ipf_ticks, &nat2->nat_tqe);
202 1.1 christos else {
203 1.1 christos #ifdef USE_MUTEXES
204 1.1 christos ipf_nat_softc_t *softn = softc->ipf_nat_soft;
205 1.1 christos #endif
206 1.1 christos
207 1.1 christos MUTEX_ENTER(&softn->ipf_nat_new);
208 1.1 christos nat2 = ipf_nat_add(&fi, &pptp->pptp_rule, &pptp->pptp_nat,
209 1.1 christos NAT_SLAVE, nat->nat_dir);
210 1.1 christos MUTEX_EXIT(&softn->ipf_nat_new);
211 1.1 christos pptp->pptp_nat = nat2;
212 1.1 christos if (nat2 != NULL) {
213 1.1 christos (void) ipf_nat_proto(&fi, nat2, 0);
214 1.1 christos MUTEX_ENTER(&nat2->nat_lock);
215 1.1 christos ipf_nat_update(&fi, nat2);
216 1.1 christos MUTEX_EXIT(&nat2->nat_lock);
217 1.1 christos }
218 1.1 christos }
219 1.1 christos
220 1.1 christos READ_ENTER(&softc->ipf_state);
221 1.1 christos if (pptp->pptp_state != NULL) {
222 1.1 christos ipf_queueback(softc->ipf_ticks, &pptp->pptp_state->is_sti);
223 1.1 christos RWLOCK_EXIT(&softc->ipf_state);
224 1.1 christos } else {
225 1.1 christos RWLOCK_EXIT(&softc->ipf_state);
226 1.1 christos if (nat2 != NULL) {
227 1.1 christos if (nat->nat_dir == NAT_INBOUND)
228 1.1 christos fi.fin_fi.fi_daddr = nat2->nat_ndstaddr;
229 1.1 christos else
230 1.1 christos fi.fin_fi.fi_saddr = nat2->nat_osrcaddr;
231 1.1 christos }
232 1.1 christos fi.fin_ifp = NULL;
233 1.1 christos (void) ipf_state_add(softc, &fi, &pptp->pptp_state, 0);
234 1.1 christos }
235 1.1 christos ip->ip_p = p;
236 1.1 christos return;
237 1.1 christos }
238 1.1 christos
239 1.1 christos
240 1.1 christos /*
241 1.1 christos * Try and build up the next PPTP message in the TCP stream and if we can
242 1.1 christos * build it up completely (fits in our buffer) then pass it off to the message
243 1.1 christos * parsing function.
244 1.1 christos */
245 1.1 christos int
246 1.1 christos ipf_p_pptp_nextmessage(fin, nat, pptp, rev)
247 1.1 christos fr_info_t *fin;
248 1.1 christos nat_t *nat;
249 1.1 christos pptp_pxy_t *pptp;
250 1.1 christos int rev;
251 1.1 christos {
252 1.1 christos static const char *funcname = "ipf_p_pptp_nextmessage";
253 1.1 christos pptp_side_t *pptps;
254 1.1 christos u_32_t start, end;
255 1.1 christos pptp_hdr_t *hdr;
256 1.1 christos tcphdr_t *tcp;
257 1.1 christos int dlen, off;
258 1.1 christos u_short len;
259 1.1 christos char *msg;
260 1.1 christos
261 1.1 christos tcp = fin->fin_dp;
262 1.1 christos dlen = fin->fin_dlen - (TCP_OFF(tcp) << 2);
263 1.1 christos start = ntohl(tcp->th_seq);
264 1.1 christos pptps = &pptp->pptp_side[rev];
265 1.1 christos off = (char *)tcp - (char *)fin->fin_ip + (TCP_OFF(tcp) << 2) +
266 1.1 christos fin->fin_ipoff;
267 1.1 christos
268 1.1 christos if (dlen <= 0)
269 1.1 christos return 0;
270 1.1 christos /*
271 1.1 christos * If the complete data packet is before what we expect to see
272 1.1 christos * "next", just ignore it as the chances are we've already seen it.
273 1.1 christos * The next if statement following this one really just causes packets
274 1.1 christos * ahead of what we've seen to be dropped, implying that something in
275 1.1 christos * the middle went missing and we want to see that first.
276 1.1 christos */
277 1.1 christos end = start + dlen;
278 1.1 christos if (pptps->pptps_next > end && pptps->pptps_next > start)
279 1.1 christos return 0;
280 1.1 christos
281 1.1 christos if (pptps->pptps_next != start) {
282 1.1 christos if (ipf_p_pptp_debug > 5)
283 1.1 christos printf("%s: next (%x) != start (%x)\n", funcname,
284 1.1 christos pptps->pptps_next, start);
285 1.1 christos return -1;
286 1.1 christos }
287 1.1 christos
288 1.1 christos msg = (char *)fin->fin_dp + (TCP_OFF(tcp) << 2);
289 1.1 christos
290 1.1 christos while (dlen > 0) {
291 1.1 christos off += pptps->pptps_bytes;
292 1.1 christos if (pptps->pptps_gothdr == 0) {
293 1.1 christos /*
294 1.1 christos * PPTP has an 8 byte header that inclues the cookie.
295 1.1 christos * The start of every message should include one and
296 1.1 christos * it should match 1a2b3c4d. Byte order is ignored,
297 1.1 christos * deliberately, when printing out the error.
298 1.1 christos */
299 1.1 christos len = MIN(8 - pptps->pptps_bytes, dlen);
300 1.1 christos COPYDATA(fin->fin_m, off, len, pptps->pptps_wptr);
301 1.1 christos pptps->pptps_bytes += len;
302 1.1 christos pptps->pptps_wptr += len;
303 1.1 christos hdr = (pptp_hdr_t *)pptps->pptps_buffer;
304 1.1 christos if (pptps->pptps_bytes == 8) {
305 1.1 christos pptps->pptps_next += 8;
306 1.1 christos if (ntohl(hdr->pptph_cookie) != 0x1a2b3c4d) {
307 1.1 christos if (ipf_p_pptp_debug > 1)
308 1.1 christos printf("%s: bad cookie (%x)\n",
309 1.1 christos funcname,
310 1.1 christos hdr->pptph_cookie);
311 1.1 christos return -1;
312 1.1 christos }
313 1.1 christos }
314 1.1 christos dlen -= len;
315 1.1 christos msg += len;
316 1.1 christos off += len;
317 1.1 christos
318 1.1 christos pptps->pptps_gothdr = 1;
319 1.1 christos len = ntohs(hdr->pptph_len);
320 1.1 christos pptps->pptps_len = len;
321 1.1 christos pptps->pptps_nexthdr += len;
322 1.1 christos
323 1.1 christos /*
324 1.1 christos * If a message is too big for the buffer, just set
325 1.1 christos * the fields for the next message to come along.
326 1.1 christos * The messages defined in RFC 2637 will not exceed
327 1.1 christos * 512 bytes (in total length) so this is likely a
328 1.1 christos * bad data packet, anyway.
329 1.1 christos */
330 1.1 christos if (len > sizeof(pptps->pptps_buffer)) {
331 1.1 christos if (ipf_p_pptp_debug > 3)
332 1.1 christos printf("%s: message too big (%d)\n",
333 1.1 christos funcname, len);
334 1.1 christos pptps->pptps_next = pptps->pptps_nexthdr;
335 1.1 christos pptps->pptps_wptr = pptps->pptps_buffer;
336 1.1 christos pptps->pptps_gothdr = 0;
337 1.1 christos pptps->pptps_bytes = 0;
338 1.1 christos pptps->pptps_len = 0;
339 1.1 christos break;
340 1.1 christos }
341 1.1 christos }
342 1.1 christos
343 1.1 christos len = MIN(pptps->pptps_len - pptps->pptps_bytes, dlen);
344 1.1 christos COPYDATA(fin->fin_m, off, len, pptps->pptps_wptr);
345 1.1 christos pptps->pptps_bytes += len;
346 1.1 christos pptps->pptps_wptr += len;
347 1.1 christos pptps->pptps_next += len;
348 1.1 christos
349 1.1 christos if (pptps->pptps_len > pptps->pptps_bytes)
350 1.1 christos break;
351 1.1 christos
352 1.1 christos ipf_p_pptp_message(fin, nat, pptp, pptps);
353 1.1 christos pptps->pptps_wptr = pptps->pptps_buffer;
354 1.1 christos pptps->pptps_gothdr = 0;
355 1.1 christos pptps->pptps_bytes = 0;
356 1.1 christos pptps->pptps_len = 0;
357 1.1 christos
358 1.1 christos start += len;
359 1.1 christos msg += len;
360 1.1 christos dlen -= len;
361 1.1 christos }
362 1.1 christos
363 1.1 christos return 0;
364 1.1 christos }
365 1.1 christos
366 1.1 christos
367 1.1 christos /*
368 1.1 christos * handle a complete PPTP message
369 1.1 christos */
370 1.1 christos int
371 1.1 christos ipf_p_pptp_message(fin, nat, pptp, pptps)
372 1.1 christos fr_info_t *fin;
373 1.1 christos nat_t *nat;
374 1.1 christos pptp_pxy_t *pptp;
375 1.1 christos pptp_side_t *pptps;
376 1.1 christos {
377 1.1 christos pptp_hdr_t *hdr = (pptp_hdr_t *)pptps->pptps_buffer;
378 1.1 christos
379 1.1 christos switch (ntohs(hdr->pptph_type))
380 1.1 christos {
381 1.1 christos case PPTP_MSGTYPE_CTL :
382 1.1 christos ipf_p_pptp_mctl(fin, nat, pptp, pptps);
383 1.1 christos break;
384 1.1 christos
385 1.1 christos default :
386 1.1 christos break;
387 1.1 christos }
388 1.1 christos return 0;
389 1.1 christos }
390 1.1 christos
391 1.1 christos
392 1.1 christos /*
393 1.1 christos * handle a complete PPTP control message
394 1.1 christos */
395 1.1 christos int
396 1.1 christos ipf_p_pptp_mctl(fin, nat, pptp, pptps)
397 1.1 christos fr_info_t *fin;
398 1.1 christos nat_t *nat;
399 1.1 christos pptp_pxy_t *pptp;
400 1.1 christos pptp_side_t *pptps;
401 1.1 christos {
402 1.1 christos u_short *buffer = (u_short *)(pptps->pptps_buffer);
403 1.1 christos pptp_side_t *pptpo;
404 1.1 christos
405 1.1 christos if (pptps == &pptp->pptp_side[0])
406 1.1 christos pptpo = &pptp->pptp_side[1];
407 1.1 christos else
408 1.1 christos pptpo = &pptp->pptp_side[0];
409 1.1 christos
410 1.1 christos /*
411 1.1 christos * Breakout to handle all the various messages. Most are just state
412 1.1 christos * transition.
413 1.1 christos */
414 1.1 christos switch (ntohs(buffer[4]))
415 1.1 christos {
416 1.1 christos case PPTP_MTCTL_STARTREQ :
417 1.1 christos pptps->pptps_state = PPTP_MTCTL_STARTREQ;
418 1.1 christos break;
419 1.1 christos case PPTP_MTCTL_STARTREP :
420 1.1 christos if (pptpo->pptps_state == PPTP_MTCTL_STARTREQ)
421 1.1 christos pptps->pptps_state = PPTP_MTCTL_STARTREP;
422 1.1 christos break;
423 1.1 christos case PPTP_MTCTL_STOPREQ :
424 1.1 christos pptps->pptps_state = PPTP_MTCTL_STOPREQ;
425 1.1 christos break;
426 1.1 christos case PPTP_MTCTL_STOPREP :
427 1.1 christos if (pptpo->pptps_state == PPTP_MTCTL_STOPREQ)
428 1.1 christos pptps->pptps_state = PPTP_MTCTL_STOPREP;
429 1.1 christos break;
430 1.1 christos case PPTP_MTCTL_ECHOREQ :
431 1.1 christos pptps->pptps_state = PPTP_MTCTL_ECHOREQ;
432 1.1 christos break;
433 1.1 christos case PPTP_MTCTL_ECHOREP :
434 1.1 christos if (pptpo->pptps_state == PPTP_MTCTL_ECHOREQ)
435 1.1 christos pptps->pptps_state = PPTP_MTCTL_ECHOREP;
436 1.1 christos break;
437 1.1 christos case PPTP_MTCTL_OUTREQ :
438 1.1 christos pptps->pptps_state = PPTP_MTCTL_OUTREQ;
439 1.1 christos break;
440 1.1 christos case PPTP_MTCTL_OUTREP :
441 1.1 christos if (pptpo->pptps_state == PPTP_MTCTL_OUTREQ) {
442 1.1 christos pptps->pptps_state = PPTP_MTCTL_OUTREP;
443 1.1 christos pptp->pptp_call[0] = buffer[7];
444 1.1 christos pptp->pptp_call[1] = buffer[6];
445 1.1 christos ipf_p_pptp_donatstate(fin, nat, pptp);
446 1.1 christos }
447 1.1 christos break;
448 1.1 christos case PPTP_MTCTL_INREQ :
449 1.1 christos pptps->pptps_state = PPTP_MTCTL_INREQ;
450 1.1 christos break;
451 1.1 christos case PPTP_MTCTL_INREP :
452 1.1 christos if (pptpo->pptps_state == PPTP_MTCTL_INREQ) {
453 1.1 christos pptps->pptps_state = PPTP_MTCTL_INREP;
454 1.1 christos pptp->pptp_call[0] = buffer[7];
455 1.1 christos pptp->pptp_call[1] = buffer[6];
456 1.1 christos ipf_p_pptp_donatstate(fin, nat, pptp);
457 1.1 christos }
458 1.1 christos break;
459 1.1 christos case PPTP_MTCTL_INCONNECT :
460 1.1 christos pptps->pptps_state = PPTP_MTCTL_INCONNECT;
461 1.1 christos break;
462 1.1 christos case PPTP_MTCTL_CLEAR :
463 1.1 christos pptps->pptps_state = PPTP_MTCTL_CLEAR;
464 1.1 christos break;
465 1.1 christos case PPTP_MTCTL_DISCONNECT :
466 1.1 christos pptps->pptps_state = PPTP_MTCTL_DISCONNECT;
467 1.1 christos break;
468 1.1 christos case PPTP_MTCTL_WANERROR :
469 1.1 christos pptps->pptps_state = PPTP_MTCTL_WANERROR;
470 1.1 christos break;
471 1.1 christos case PPTP_MTCTL_LINKINFO :
472 1.1 christos pptps->pptps_state = PPTP_MTCTL_LINKINFO;
473 1.1 christos break;
474 1.1 christos }
475 1.1 christos
476 1.1 christos return 0;
477 1.1 christos }
478 1.1 christos
479 1.1 christos
480 1.1 christos /*
481 1.1 christos * For outgoing PPTP packets. refresh timeouts for NAT & state entries, if
482 1.1 christos * we can. If they have disappeared, recreate them.
483 1.1 christos */
484 1.1 christos int
485 1.1 christos ipf_p_pptp_inout(arg, fin, aps, nat)
486 1.1 christos void *arg;
487 1.1 christos fr_info_t *fin;
488 1.1 christos ap_session_t *aps;
489 1.1 christos nat_t *nat;
490 1.1 christos {
491 1.1 christos pptp_pxy_t *pptp;
492 1.1 christos tcphdr_t *tcp;
493 1.1 christos int rev;
494 1.1 christos
495 1.1 christos if ((fin->fin_out == 1) && (nat->nat_dir == NAT_INBOUND))
496 1.1 christos rev = 1;
497 1.1 christos else if ((fin->fin_out == 0) && (nat->nat_dir == NAT_OUTBOUND))
498 1.1 christos rev = 1;
499 1.1 christos else
500 1.1 christos rev = 0;
501 1.1 christos
502 1.1 christos tcp = (tcphdr_t *)fin->fin_dp;
503 1.1 christos if ((tcp->th_flags & TH_OPENING) == TH_OPENING) {
504 1.1 christos pptp = (pptp_pxy_t *)aps->aps_data;
505 1.1 christos pptp->pptp_side[1 - rev].pptps_next = ntohl(tcp->th_ack);
506 1.1 christos pptp->pptp_side[1 - rev].pptps_nexthdr = ntohl(tcp->th_ack);
507 1.1 christos pptp->pptp_side[rev].pptps_next = ntohl(tcp->th_seq) + 1;
508 1.1 christos pptp->pptp_side[rev].pptps_nexthdr = ntohl(tcp->th_seq) + 1;
509 1.1 christos }
510 1.1 christos return ipf_p_pptp_nextmessage(fin, nat, (pptp_pxy_t *)aps->aps_data,
511 1.1 christos rev);
512 1.1 christos }
513 1.1 christos
514 1.1 christos
515 1.1 christos /*
516 1.1 christos * clean up after ourselves.
517 1.1 christos */
518 1.1 christos void
519 1.1 christos ipf_p_pptp_del(softc, aps)
520 1.1 christos ipf_main_softc_t *softc;
521 1.1 christos ap_session_t *aps;
522 1.1 christos {
523 1.1 christos pptp_pxy_t *pptp;
524 1.1 christos
525 1.1 christos pptp = aps->aps_data;
526 1.1 christos
527 1.1 christos if (pptp != NULL) {
528 1.1 christos /*
529 1.1 christos * Don't bother changing any of the NAT structure details,
530 1.1 christos * *_del() is on a callback from aps_free(), from nat_delete()
531 1.1 christos */
532 1.1 christos
533 1.1 christos READ_ENTER(&softc->ipf_state);
534 1.1 christos if (pptp->pptp_state != NULL) {
535 1.1 christos ipf_state_setpending(softc, pptp->pptp_state);
536 1.1 christos }
537 1.1 christos RWLOCK_EXIT(&softc->ipf_state);
538 1.1 christos
539 1.1 christos if (pptp->pptp_nat != NULL)
540 1.1 christos ipf_nat_setpending(softc, pptp->pptp_nat);
541 1.1 christos MUTEX_DESTROY(&pptp->pptp_rule.in_lock);
542 1.1 christos }
543 1.1 christos }
544