Deleted Added
full compact
bundle.c (79165) bundle.c (81634)
1/*-
2 * Copyright (c) 1998 Brian Somers <brian@Awfulhak.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 9 unchanged lines hidden (view full) ---

18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
1/*-
2 * Copyright (c) 1998 Brian Somers <brian@Awfulhak.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 9 unchanged lines hidden (view full) ---

18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 * $FreeBSD: head/usr.sbin/ppp/bundle.c 79165 2001-07-03 22:20:19Z brian $
26 * $FreeBSD: head/usr.sbin/ppp/bundle.c 81634 2001-08-14 16:05:52Z brian $
27 */
28
29#include <sys/param.h>
30#include <sys/socket.h>
31#include <netinet/in.h>
32#include <net/if.h>
33#include <net/if_tun.h> /* For TUNS* ioctls */
34#include <net/route.h>

--- 31 unchanged lines hidden (view full) ---

66#include "id.h"
67#include "timer.h"
68#include "fsm.h"
69#include "iplist.h"
70#include "lqr.h"
71#include "hdlc.h"
72#include "throughput.h"
73#include "slcompress.h"
27 */
28
29#include <sys/param.h>
30#include <sys/socket.h>
31#include <netinet/in.h>
32#include <net/if.h>
33#include <net/if_tun.h> /* For TUNS* ioctls */
34#include <net/route.h>

--- 31 unchanged lines hidden (view full) ---

66#include "id.h"
67#include "timer.h"
68#include "fsm.h"
69#include "iplist.h"
70#include "lqr.h"
71#include "hdlc.h"
72#include "throughput.h"
73#include "slcompress.h"
74#include "ncpaddr.h"
75#include "ip.h"
74#include "ipcp.h"
75#include "filter.h"
76#include "descriptor.h"
77#include "route.h"
78#include "lcp.h"
79#include "ccp.h"
80#include "link.h"
81#include "mp.h"
82#ifndef NORADIUS
83#include "radius.h"
84#endif
76#include "ipcp.h"
77#include "filter.h"
78#include "descriptor.h"
79#include "route.h"
80#include "lcp.h"
81#include "ccp.h"
82#include "link.h"
83#include "mp.h"
84#ifndef NORADIUS
85#include "radius.h"
86#endif
87#include "ipv6cp.h"
88#include "ncp.h"
85#include "bundle.h"
86#include "async.h"
87#include "physical.h"
88#include "auth.h"
89#include "proto.h"
90#include "chap.h"
91#include "tun.h"
92#include "prompt.h"
93#include "chat.h"
94#include "cbcp.h"
95#include "datalink.h"
89#include "bundle.h"
90#include "async.h"
91#include "physical.h"
92#include "auth.h"
93#include "proto.h"
94#include "chap.h"
95#include "tun.h"
96#include "prompt.h"
97#include "chat.h"
98#include "cbcp.h"
99#include "datalink.h"
96#include "ip.h"
97#include "iface.h"
98#include "server.h"
99#ifdef HAVE_DES
100#include "mppe.h"
101#endif
102
103#define SCATTER_SEGMENTS 7 /* version, datalink, name, physical,
104 throughput, throughput, device */

--- 37 unchanged lines hidden (view full) ---

142 break;
143
144 case PHASE_AUTHENTICATE:
145 bundle->phase = new;
146 log_DisplayPrompts();
147 break;
148
149 case PHASE_NETWORK:
100#include "iface.h"
101#include "server.h"
102#ifdef HAVE_DES
103#include "mppe.h"
104#endif
105
106#define SCATTER_SEGMENTS 7 /* version, datalink, name, physical,
107 throughput, throughput, device */

--- 37 unchanged lines hidden (view full) ---

145 break;
146
147 case PHASE_AUTHENTICATE:
148 bundle->phase = new;
149 log_DisplayPrompts();
150 break;
151
152 case PHASE_NETWORK:
150 fsm_Up(&bundle->ncp.ipcp.fsm);
151 fsm_Open(&bundle->ncp.ipcp.fsm);
152 bundle->phase = new;
153 log_DisplayPrompts();
153 if (ncp_fsmStart(&bundle->ncp, bundle)) {
154 bundle->phase = new;
155 log_DisplayPrompts();
156 } else {
157 log_Printf(LogPHASE, "bundle: All NCPs are disabled\n");
158 bundle_Close(bundle, NULL, CLOSE_STAYDOWN);
159 }
154 break;
155
156 case PHASE_TERMINATE:
157 bundle->phase = new;
158 mp_Down(&bundle->ncp.mp);
159 log_DisplayPrompts();
160 break;
161 }

--- 47 unchanged lines hidden (view full) ---

209 * us from reading the TUN_NAME device (we don't want to buffer stuff
210 * indefinitely), we may as well nuke this data and start with a clean
211 * slate !
212 *
213 * Unfortunately, this has the side effect of shafting any compression
214 * dictionaries in use (causing the relevant RESET_REQ/RESET_ACK).
215 */
216
160 break;
161
162 case PHASE_TERMINATE:
163 bundle->phase = new;
164 mp_Down(&bundle->ncp.mp);
165 log_DisplayPrompts();
166 break;
167 }

--- 47 unchanged lines hidden (view full) ---

215 * us from reading the TUN_NAME device (we don't want to buffer stuff
216 * indefinitely), we may as well nuke this data and start with a clean
217 * slate !
218 *
219 * Unfortunately, this has the side effect of shafting any compression
220 * dictionaries in use (causing the relevant RESET_REQ/RESET_ACK).
221 */
222
217 ip_DeleteQueue(&bundle->ncp.ipcp);
218 mp_DeleteQueue(&bundle->ncp.mp);
223 ncp_DeleteQueues(&bundle->ncp);
219 for (dl = bundle->links; dl; dl = dl->next)
220 physical_DeleteQueue(dl->physical);
221}
222
223static void
224bundle_LinkAdded(struct bundle *bundle, struct datalink *dl)
225{
226 bundle->phys_type.all |= dl->physical->type;

--- 38 unchanged lines hidden (view full) ---

265 */
266 struct bundle *bundle = (struct bundle *)v;
267
268 if (fp->proto == PROTO_LCP) {
269 struct physical *p = link2physical(fp->link);
270
271 bundle_LinkAdded(bundle, p->dl);
272 mp_CheckAutoloadTimer(&bundle->ncp.mp);
224 for (dl = bundle->links; dl; dl = dl->next)
225 physical_DeleteQueue(dl->physical);
226}
227
228static void
229bundle_LinkAdded(struct bundle *bundle, struct datalink *dl)
230{
231 bundle->phys_type.all |= dl->physical->type;

--- 38 unchanged lines hidden (view full) ---

270 */
271 struct bundle *bundle = (struct bundle *)v;
272
273 if (fp->proto == PROTO_LCP) {
274 struct physical *p = link2physical(fp->link);
275
276 bundle_LinkAdded(bundle, p->dl);
277 mp_CheckAutoloadTimer(&bundle->ncp.mp);
273 } else if (fp->proto == PROTO_IPCP) {
274 bundle_CalculateBandwidth(fp->bundle);
275 time(&bundle->upat);
276 bundle_StartIdleTimer(bundle, 0);
278 } else if (isncp(fp->proto)) {
279 if (ncp_LayersOpen(&fp->bundle->ncp) == 1) {
280 bundle_CalculateBandwidth(fp->bundle);
281 time(&bundle->upat);
282 bundle_StartIdleTimer(bundle, 0);
283 mp_CheckAutoloadTimer(&fp->bundle->ncp.mp);
284 }
277 bundle_Notify(bundle, EX_NORMAL);
285 bundle_Notify(bundle, EX_NORMAL);
278 mp_CheckAutoloadTimer(&fp->bundle->ncp.mp);
279 } else if (fp->proto == PROTO_CCP)
280 bundle_CalculateBandwidth(fp->bundle); /* Against ccp_MTUOverhead */
281}
282
283static void
284bundle_LayerDown(void *v, struct fsm *fp)
285{
286 /*

--- 4 unchanged lines hidden (view full) ---

291 * If it's an LCP, adjust our phys_type.open value and any timers.
292 * If it's an LCP and we're in multilink mode, adjust our tun
293 * If it's the last LCP, down all NCPs
294 * speed and make sure our minimum sequence number is adjusted.
295 */
296
297 struct bundle *bundle = (struct bundle *)v;
298
286 } else if (fp->proto == PROTO_CCP)
287 bundle_CalculateBandwidth(fp->bundle); /* Against ccp_MTUOverhead */
288}
289
290static void
291bundle_LayerDown(void *v, struct fsm *fp)
292{
293 /*

--- 4 unchanged lines hidden (view full) ---

298 * If it's an LCP, adjust our phys_type.open value and any timers.
299 * If it's an LCP and we're in multilink mode, adjust our tun
300 * If it's the last LCP, down all NCPs
301 * speed and make sure our minimum sequence number is adjusted.
302 */
303
304 struct bundle *bundle = (struct bundle *)v;
305
299 if (fp->proto == PROTO_IPCP) {
300 bundle_StopIdleTimer(bundle);
301 bundle->upat = 0;
302 mp_StopAutoloadTimer(&bundle->ncp.mp);
306 if (isncp(fp->proto)) {
307 if (ncp_LayersOpen(&fp->bundle->ncp) == 0) {
308 bundle_StopIdleTimer(bundle);
309 bundle->upat = 0;
310 mp_StopAutoloadTimer(&bundle->ncp.mp);
311 }
303 } else if (fp->proto == PROTO_LCP) {
304 struct datalink *dl;
305 struct datalink *lost;
306 int others_active;
307
308 bundle_LinksRemoved(bundle); /* adjust timers & phys_type values */
309
310 lost = NULL;

--- 12 unchanged lines hidden (view full) ---

323 mp_LinkLost(&bundle->ncp.mp, lost);
324 else
325 log_Printf(LogALERT, "Oops, lost an unrecognised datalink (%s) !\n",
326 fp->link->name);
327 }
328
329 if (!others_active)
330 /* Down the NCPs. We don't expect to get fsm_Close()d ourself ! */
312 } else if (fp->proto == PROTO_LCP) {
313 struct datalink *dl;
314 struct datalink *lost;
315 int others_active;
316
317 bundle_LinksRemoved(bundle); /* adjust timers & phys_type values */
318
319 lost = NULL;

--- 12 unchanged lines hidden (view full) ---

332 mp_LinkLost(&bundle->ncp.mp, lost);
333 else
334 log_Printf(LogALERT, "Oops, lost an unrecognised datalink (%s) !\n",
335 fp->link->name);
336 }
337
338 if (!others_active)
339 /* Down the NCPs. We don't expect to get fsm_Close()d ourself ! */
331 fsm2initial(&bundle->ncp.ipcp.fsm);
340 ncp2initial(&bundle->ncp);
332 }
333}
334
335static void
336bundle_LayerFinish(void *v, struct fsm *fp)
337{
338 /* The given fsm is now down (fp cannot be NULL)
339 *
340 * If it's the last NCP, fsm_Close all LCPs
341 */
342
343 struct bundle *bundle = (struct bundle *)v;
344 struct datalink *dl;
345
341 }
342}
343
344static void
345bundle_LayerFinish(void *v, struct fsm *fp)
346{
347 /* The given fsm is now down (fp cannot be NULL)
348 *
349 * If it's the last NCP, fsm_Close all LCPs
350 */
351
352 struct bundle *bundle = (struct bundle *)v;
353 struct datalink *dl;
354
346 if (fp->proto == PROTO_IPCP) {
355 if (isncp(fp->proto) && !ncp_LayersUnfinished(&bundle->ncp)) {
347 if (bundle_Phase(bundle) != PHASE_DEAD)
348 bundle_NewPhase(bundle, PHASE_TERMINATE);
349 for (dl = bundle->links; dl; dl = dl->next)
350 if (dl->state == DATALINK_OPEN)
351 datalink_Close(dl, CLOSE_STAYDOWN);
352 fsm2initial(fp);
353 }
354}
355
356 if (bundle_Phase(bundle) != PHASE_DEAD)
357 bundle_NewPhase(bundle, PHASE_TERMINATE);
358 for (dl = bundle->links; dl; dl = dl->next)
359 if (dl->state == DATALINK_OPEN)
360 datalink_Close(dl, CLOSE_STAYDOWN);
361 fsm2initial(fp);
362 }
363}
364
356int
357bundle_LinkIsUp(const struct bundle *bundle)
358{
359 return bundle->ncp.ipcp.fsm.state == ST_OPENED;
360}
361
362void
363bundle_Close(struct bundle *bundle, const char *name, int how)
364{
365 /*
366 * Please close the given datalink.
367 * If name == NULL or name is the last datalink, fsm_Close all NCPs
368 * (except our MP)
369 * If it isn't the last datalink, just Close that datalink.

--- 23 unchanged lines hidden (view full) ---

393
394 if (name && this_dl == NULL) {
395 log_Printf(LogWARN, "%s: Invalid datalink name\n", name);
396 return;
397 }
398
399 if (!others_active) {
400 bundle_StopIdleTimer(bundle);
365void
366bundle_Close(struct bundle *bundle, const char *name, int how)
367{
368 /*
369 * Please close the given datalink.
370 * If name == NULL or name is the last datalink, fsm_Close all NCPs
371 * (except our MP)
372 * If it isn't the last datalink, just Close that datalink.

--- 23 unchanged lines hidden (view full) ---

396
397 if (name && this_dl == NULL) {
398 log_Printf(LogWARN, "%s: Invalid datalink name\n", name);
399 return;
400 }
401
402 if (!others_active) {
403 bundle_StopIdleTimer(bundle);
401 if (bundle->ncp.ipcp.fsm.state > ST_CLOSED ||
402 bundle->ncp.ipcp.fsm.state == ST_STARTING)
403 fsm_Close(&bundle->ncp.ipcp.fsm);
404 if (ncp_LayersUnfinished(&bundle->ncp))
405 ncp_Close(&bundle->ncp);
404 else {
406 else {
405 fsm2initial(&bundle->ncp.ipcp.fsm);
407 ncp2initial(&bundle->ncp);
406 for (dl = bundle->links; dl; dl = dl->next)
407 datalink_Close(dl, how);
408 }
409 } else if (this_dl && this_dl->state != DATALINK_CLOSED &&
410 this_dl->state != DATALINK_HANGUP)
411 datalink_Close(this_dl, how);
412}
413
414void
415bundle_Down(struct bundle *bundle, int how)
416{
417 struct datalink *dl;
418
419 for (dl = bundle->links; dl; dl = dl->next)
420 datalink_Down(dl, how);
421}
422
408 for (dl = bundle->links; dl; dl = dl->next)
409 datalink_Close(dl, how);
410 }
411 } else if (this_dl && this_dl->state != DATALINK_CLOSED &&
412 this_dl->state != DATALINK_HANGUP)
413 datalink_Close(this_dl, how);
414}
415
416void
417bundle_Down(struct bundle *bundle, int how)
418{
419 struct datalink *dl;
420
421 for (dl = bundle->links; dl; dl = dl->next)
422 datalink_Down(dl, how);
423}
424
423static size_t
424bundle_FillQueues(struct bundle *bundle)
425{
426 size_t total;
427
428 if (bundle->ncp.mp.active)
429 total = mp_FillQueues(bundle);
430 else {
431 struct datalink *dl;
432 size_t add;
433
434 for (total = 0, dl = bundle->links; dl; dl = dl->next)
435 if (dl->state == DATALINK_OPEN) {
436 add = link_QueueLen(&dl->physical->link);
437 if (add == 0 && dl->physical->out == NULL)
438 add = ip_PushPacket(&dl->physical->link, bundle);
439 total += add;
440 }
441 }
442
443 return total + ip_QueueLen(&bundle->ncp.ipcp);
444}
445
446static int
447bundle_UpdateSet(struct fdescriptor *d, fd_set *r, fd_set *w, fd_set *e, int *n)
448{
449 struct bundle *bundle = descriptor2bundle(d);
450 struct datalink *dl;
451 int result, nlinks;
452 u_short ifqueue;
453 size_t queued;
454
455 result = 0;
456
457 /* If there are aren't many packets queued, look for some more. */
458 for (nlinks = 0, dl = bundle->links; dl; dl = dl->next)
459 nlinks++;
460
461 if (nlinks) {
425static int
426bundle_UpdateSet(struct fdescriptor *d, fd_set *r, fd_set *w, fd_set *e, int *n)
427{
428 struct bundle *bundle = descriptor2bundle(d);
429 struct datalink *dl;
430 int result, nlinks;
431 u_short ifqueue;
432 size_t queued;
433
434 result = 0;
435
436 /* If there are aren't many packets queued, look for some more. */
437 for (nlinks = 0, dl = bundle->links; dl; dl = dl->next)
438 nlinks++;
439
440 if (nlinks) {
462 queued = r ? bundle_FillQueues(bundle) : ip_QueueLen(&bundle->ncp.ipcp);
441 queued = r ? ncp_FillPhysicalQueues(&bundle->ncp, bundle) :
442 ncp_QueueLen(&bundle->ncp);
463
464 if (r && (bundle->phase == PHASE_NETWORK ||
465 bundle->phys_type.all & PHYS_AUTO)) {
466 /* enough surplus so that we can tell if we're getting swamped */
467 ifqueue = nlinks > bundle->cfg.ifqueue ? nlinks : bundle->cfg.ifqueue;
468 if (queued < ifqueue) {
469 /* Not enough - select() for more */
470 if (bundle->choked.timer.state == TIMER_RUNNING)

--- 53 unchanged lines hidden (view full) ---

524}
525
526static void
527bundle_DescriptorRead(struct fdescriptor *d, struct bundle *bundle,
528 const fd_set *fdset)
529{
530 struct datalink *dl;
531 unsigned secs;
443
444 if (r && (bundle->phase == PHASE_NETWORK ||
445 bundle->phys_type.all & PHYS_AUTO)) {
446 /* enough surplus so that we can tell if we're getting swamped */
447 ifqueue = nlinks > bundle->cfg.ifqueue ? nlinks : bundle->cfg.ifqueue;
448 if (queued < ifqueue) {
449 /* Not enough - select() for more */
450 if (bundle->choked.timer.state == TIMER_RUNNING)

--- 53 unchanged lines hidden (view full) ---

504}
505
506static void
507bundle_DescriptorRead(struct fdescriptor *d, struct bundle *bundle,
508 const fd_set *fdset)
509{
510 struct datalink *dl;
511 unsigned secs;
512 u_int32_t af;
532
533 if (descriptor_IsSet(&bundle->ncp.mp.server.desc, fdset))
534 descriptor_Read(&bundle->ncp.mp.server.desc, bundle, fdset);
535
536 for (dl = bundle->links; dl; dl = dl->next)
537 if (descriptor_IsSet(&dl->desc, fdset))
538 descriptor_Read(&dl->desc, bundle, fdset);
539

--- 26 unchanged lines hidden (view full) ---

566
567 if (bundle->dev.header) {
568 n -= sz - sizeof tun.data;
569 if (n <= 0) {
570 log_Printf(LogERROR, "%s: read: Got only %d bytes of data !\n",
571 bundle->dev.Name, n);
572 return;
573 }
513
514 if (descriptor_IsSet(&bundle->ncp.mp.server.desc, fdset))
515 descriptor_Read(&bundle->ncp.mp.server.desc, bundle, fdset);
516
517 for (dl = bundle->links; dl; dl = dl->next)
518 if (descriptor_IsSet(&dl->desc, fdset))
519 descriptor_Read(&dl->desc, bundle, fdset);
520

--- 26 unchanged lines hidden (view full) ---

547
548 if (bundle->dev.header) {
549 n -= sz - sizeof tun.data;
550 if (n <= 0) {
551 log_Printf(LogERROR, "%s: read: Got only %d bytes of data !\n",
552 bundle->dev.Name, n);
553 return;
554 }
574 if (ntohl(tun.header.family) != AF_INET)
555 af = ntohl(tun.header.family);
556#ifndef NOINET6
557 if (af != AF_INET && af != AF_INET6)
558#else
559 if (af != AF_INET)
560#endif
575 /* XXX: Should be maintaining drop/family counts ! */
576 return;
561 /* XXX: Should be maintaining drop/family counts ! */
562 return;
577 }
563 } else
564 af = AF_INET;
578
565
579 if (((struct ip *)tun.data)->ip_dst.s_addr ==
566 if (af == AF_INET && ((struct ip *)tun.data)->ip_dst.s_addr ==
580 bundle->ncp.ipcp.my_ip.s_addr) {
581 /* we've been asked to send something addressed *to* us :( */
582 if (Enabled(bundle, OPT_LOOPBACK)) {
567 bundle->ncp.ipcp.my_ip.s_addr) {
568 /* we've been asked to send something addressed *to* us :( */
569 if (Enabled(bundle, OPT_LOOPBACK)) {
583 pri = PacketCheck(bundle, tun.data, n, &bundle->filter.in, NULL, NULL);
570 pri = PacketCheck(bundle, af, tun.data, n, &bundle->filter.in,
571 NULL, NULL);
584 if (pri >= 0) {
585 n += sz - sizeof tun.data;
586 write(bundle->dev.fd, data, n);
587 log_Printf(LogDEBUG, "Looped back packet addressed to myself\n");
588 }
589 return;
590 } else
591 log_Printf(LogDEBUG, "Oops - forwarding packet addressed to myself\n");
592 }
593
594 /*
572 if (pri >= 0) {
573 n += sz - sizeof tun.data;
574 write(bundle->dev.fd, data, n);
575 log_Printf(LogDEBUG, "Looped back packet addressed to myself\n");
576 }
577 return;
578 } else
579 log_Printf(LogDEBUG, "Oops - forwarding packet addressed to myself\n");
580 }
581
582 /*
595 * Process on-demand dialup. Output packets are queued within tunnel
596 * device until IPCP is opened.
583 * Process on-demand dialup. Output packets are queued within the tunnel
584 * device until the appropriate NCP is opened.
597 */
598
599 if (bundle_Phase(bundle) == PHASE_DEAD) {
600 /*
601 * Note, we must be in AUTO mode :-/ otherwise our interface should
602 * *not* be UP and we can't receive data
603 */
585 */
586
587 if (bundle_Phase(bundle) == PHASE_DEAD) {
588 /*
589 * Note, we must be in AUTO mode :-/ otherwise our interface should
590 * *not* be UP and we can't receive data
591 */
604 pri = PacketCheck(bundle, tun.data, n, &bundle->filter.dial, NULL, NULL);
592 pri = PacketCheck(bundle, af, tun.data, n, &bundle->filter.dial,
593 NULL, NULL);
605 if (pri >= 0)
606 bundle_Open(bundle, NULL, PHYS_AUTO, 0);
607 else
608 /*
609 * Drop the packet. If we were to queue it, we'd just end up with
610 * a pile of timed-out data in our output queue by the time we get
611 * around to actually dialing. We'd also prematurely reach the
612 * threshold at which we stop select()ing to read() the tun
613 * device - breaking auto-dial.
614 */
615 return;
616 }
617
618 secs = 0;
594 if (pri >= 0)
595 bundle_Open(bundle, NULL, PHYS_AUTO, 0);
596 else
597 /*
598 * Drop the packet. If we were to queue it, we'd just end up with
599 * a pile of timed-out data in our output queue by the time we get
600 * around to actually dialing. We'd also prematurely reach the
601 * threshold at which we stop select()ing to read() the tun
602 * device - breaking auto-dial.
603 */
604 return;
605 }
606
607 secs = 0;
619 pri = PacketCheck(bundle, tun.data, n, &bundle->filter.out, NULL, &secs);
608 pri = PacketCheck(bundle, af, tun.data, n, &bundle->filter.out,
609 NULL, &secs);
620 if (pri >= 0) {
621 /* Prepend the number of seconds timeout given in the filter */
622 tun.header.timeout = secs;
610 if (pri >= 0) {
611 /* Prepend the number of seconds timeout given in the filter */
612 tun.header.timeout = secs;
623 ip_Enqueue(&bundle->ncp.ipcp, pri, (char *)&tun, n + sizeof tun.header);
613 ncp_Enqueue(&bundle->ncp, af, pri, (char *)&tun, n + sizeof tun.header);
624 }
625 }
626}
627
628static int
629bundle_DescriptorWrite(struct fdescriptor *d, struct bundle *bundle,
630 const fd_set *fdset)
631{

--- 181 unchanged lines hidden (view full) ---

813 bundle.fsm.LayerDown = bundle_LayerDown;
814 bundle.fsm.LayerFinish = bundle_LayerFinish;
815 bundle.fsm.object = &bundle;
816
817 bundle.cfg.idle.timeout = NCP_IDLE_TIMEOUT;
818 bundle.cfg.idle.min_timeout = 0;
819 *bundle.cfg.auth.name = '\0';
820 *bundle.cfg.auth.key = '\0';
614 }
615 }
616}
617
618static int
619bundle_DescriptorWrite(struct fdescriptor *d, struct bundle *bundle,
620 const fd_set *fdset)
621{

--- 181 unchanged lines hidden (view full) ---

803 bundle.fsm.LayerDown = bundle_LayerDown;
804 bundle.fsm.LayerFinish = bundle_LayerFinish;
805 bundle.fsm.object = &bundle;
806
807 bundle.cfg.idle.timeout = NCP_IDLE_TIMEOUT;
808 bundle.cfg.idle.min_timeout = 0;
809 *bundle.cfg.auth.name = '\0';
810 *bundle.cfg.auth.key = '\0';
821 bundle.cfg.opt = OPT_SROUTES | OPT_IDCHECK | OPT_LOOPBACK | OPT_TCPMSSFIXUP |
811 bundle.cfg.opt = OPT_IDCHECK | OPT_LOOPBACK | OPT_SROUTES | OPT_TCPMSSFIXUP |
812#ifndef NOINET6
813 OPT_IPCP | OPT_IPV6CP |
814#endif
822 OPT_THROUGHPUT | OPT_UTMP;
823 *bundle.cfg.label = '\0';
824 bundle.cfg.ifqueue = DEF_IFQUEUE;
825 bundle.cfg.choked.timeout = CHOKED_TIMEOUT;
826 bundle.phys_type.all = type;
827 bundle.phys_type.open = 0;
828 bundle.upat = 0;
829

--- 7 unchanged lines hidden (view full) ---

837 }
838
839 bundle.desc.type = BUNDLE_DESCRIPTOR;
840 bundle.desc.UpdateSet = bundle_UpdateSet;
841 bundle.desc.IsSet = bundle_IsSet;
842 bundle.desc.Read = bundle_DescriptorRead;
843 bundle.desc.Write = bundle_DescriptorWrite;
844
815 OPT_THROUGHPUT | OPT_UTMP;
816 *bundle.cfg.label = '\0';
817 bundle.cfg.ifqueue = DEF_IFQUEUE;
818 bundle.cfg.choked.timeout = CHOKED_TIMEOUT;
819 bundle.phys_type.all = type;
820 bundle.phys_type.open = 0;
821 bundle.upat = 0;
822

--- 7 unchanged lines hidden (view full) ---

830 }
831
832 bundle.desc.type = BUNDLE_DESCRIPTOR;
833 bundle.desc.UpdateSet = bundle_UpdateSet;
834 bundle.desc.IsSet = bundle_IsSet;
835 bundle.desc.Read = bundle_DescriptorRead;
836 bundle.desc.Write = bundle_DescriptorWrite;
837
845 mp_Init(&bundle.ncp.mp, &bundle);
838 ncp_Init(&bundle.ncp, &bundle);
846
839
847 /* Send over the first physical link by default */
848 ipcp_Init(&bundle.ncp.ipcp, &bundle, &bundle.links->physical->link,
849 &bundle.fsm);
850
851 memset(&bundle.filter, '\0', sizeof bundle.filter);
852 bundle.filter.in.fragok = bundle.filter.in.logok = 1;
853 bundle.filter.in.name = "IN";
854 bundle.filter.out.fragok = bundle.filter.out.logok = 1;
855 bundle.filter.out.name = "OUT";
856 bundle.filter.dial.name = "DIAL";
857 bundle.filter.dial.logok = 1;
858 bundle.filter.alive.name = "ALIVE";

--- 11 unchanged lines hidden (view full) ---

870 bundle.idle.done = 0;
871 bundle.notify.fd = -1;
872 memset(&bundle.choked.timer, '\0', sizeof bundle.choked.timer);
873#ifndef NORADIUS
874 radius_Init(&bundle.radius);
875#endif
876
877 /* Clean out any leftover crud */
840 memset(&bundle.filter, '\0', sizeof bundle.filter);
841 bundle.filter.in.fragok = bundle.filter.in.logok = 1;
842 bundle.filter.in.name = "IN";
843 bundle.filter.out.fragok = bundle.filter.out.logok = 1;
844 bundle.filter.out.name = "OUT";
845 bundle.filter.dial.name = "DIAL";
846 bundle.filter.dial.logok = 1;
847 bundle.filter.alive.name = "ALIVE";

--- 11 unchanged lines hidden (view full) ---

859 bundle.idle.done = 0;
860 bundle.notify.fd = -1;
861 memset(&bundle.choked.timer, '\0', sizeof bundle.choked.timer);
862#ifndef NORADIUS
863 radius_Init(&bundle.radius);
864#endif
865
866 /* Clean out any leftover crud */
878 iface_Clear(bundle.iface, IFACE_CLEAR_ALL);
867 iface_Clear(bundle.iface, &bundle.ncp, 0, IFACE_CLEAR_ALL);
879
880 bundle_LockTun(&bundle);
881
882 return &bundle;
883}
884
885static void
886bundle_DownInterface(struct bundle *bundle)
887{
888 route_IfDelete(bundle, 1);
889 iface_ClearFlags(bundle->iface->name, IFF_UP);
890}
891
892void
893bundle_Destroy(struct bundle *bundle)
894{
895 struct datalink *dl;
896
897 /*
868
869 bundle_LockTun(&bundle);
870
871 return &bundle;
872}
873
874static void
875bundle_DownInterface(struct bundle *bundle)
876{
877 route_IfDelete(bundle, 1);
878 iface_ClearFlags(bundle->iface->name, IFF_UP);
879}
880
881void
882bundle_Destroy(struct bundle *bundle)
883{
884 struct datalink *dl;
885
886 /*
898 * Clean up the interface. We don't need to timer_Stop()s, mp_Down(),
899 * ipcp_CleanInterface() and bundle_DownInterface() unless we're getting
887 * Clean up the interface. We don't really need to do the timer_Stop()s,
888 * mp_Down(), iface_Clear() and bundle_DownInterface() unless we're getting
900 * out under exceptional conditions such as a descriptor exception.
901 */
902 timer_Stop(&bundle->idle.timer);
903 timer_Stop(&bundle->choked.timer);
904 mp_Down(&bundle->ncp.mp);
889 * out under exceptional conditions such as a descriptor exception.
890 */
891 timer_Stop(&bundle->idle.timer);
892 timer_Stop(&bundle->choked.timer);
893 mp_Down(&bundle->ncp.mp);
905 ipcp_CleanInterface(&bundle->ncp.ipcp);
894 iface_Clear(bundle->iface, &bundle->ncp, 0, IFACE_CLEAR_ALL);
906 bundle_DownInterface(bundle);
907
908#ifndef NORADIUS
909 /* Tell the radius server the bad news */
895 bundle_DownInterface(bundle);
896
897#ifndef NORADIUS
898 /* Tell the radius server the bad news */
910 log_Printf(LogDEBUG, "Radius: Destroy called from bundle_Destroy\n");
911 radius_Destroy(&bundle->radius);
912#endif
913
914 /* Again, these are all DATALINK_CLOSED unless we're abending */
915 dl = bundle->links;
916 while (dl)
917 dl = datalink_Destroy(dl);
918
899 radius_Destroy(&bundle->radius);
900#endif
901
902 /* Again, these are all DATALINK_CLOSED unless we're abending */
903 dl = bundle->links;
904 while (dl)
905 dl = datalink_Destroy(dl);
906
919 ipcp_Destroy(&bundle->ncp.ipcp);
907 ncp_Destroy(&bundle->ncp);
920
921 close(bundle->dev.fd);
922 bundle_UnlockTun(bundle);
923
924 /* In case we never made PHASE_NETWORK */
925 bundle_Notify(bundle, EX_ERRDEAD);
926
927 iface_Destroy(bundle->iface);

--- 20 unchanged lines hidden (view full) ---

948 other_links = 0;
949 for (odl = bundle->links; odl; odl = odl->next)
950 if (odl != dl && odl->state != DATALINK_CLOSED)
951 other_links++;
952
953 if (!other_links) {
954 if (dl->physical->type != PHYS_AUTO) /* Not in -auto mode */
955 bundle_DownInterface(bundle);
908
909 close(bundle->dev.fd);
910 bundle_UnlockTun(bundle);
911
912 /* In case we never made PHASE_NETWORK */
913 bundle_Notify(bundle, EX_ERRDEAD);
914
915 iface_Destroy(bundle->iface);

--- 20 unchanged lines hidden (view full) ---

936 other_links = 0;
937 for (odl = bundle->links; odl; odl = odl->next)
938 if (odl != dl && odl->state != DATALINK_CLOSED)
939 other_links++;
940
941 if (!other_links) {
942 if (dl->physical->type != PHYS_AUTO) /* Not in -auto mode */
943 bundle_DownInterface(bundle);
956 fsm2initial(&bundle->ncp.ipcp.fsm);
944 ncp2initial(&bundle->ncp);
957 bundle_NewPhase(bundle, PHASE_DEAD);
958 bundle_StopIdleTimer(bundle);
959 }
960}
961
962void
963bundle_Open(struct bundle *bundle, const char *name, int mask, int force)
964{

--- 86 unchanged lines hidden (view full) ---

1051
1052 if (arg->bundle->upat) {
1053 int secs = time(NULL) - arg->bundle->upat;
1054
1055 prompt_Printf(arg->prompt, ", up time %d:%02d:%02d", secs / 3600,
1056 (secs / 60) % 60, secs % 60);
1057 }
1058 prompt_Printf(arg->prompt, "\n Queued: %lu of %u\n",
945 bundle_NewPhase(bundle, PHASE_DEAD);
946 bundle_StopIdleTimer(bundle);
947 }
948}
949
950void
951bundle_Open(struct bundle *bundle, const char *name, int mask, int force)
952{

--- 86 unchanged lines hidden (view full) ---

1039
1040 if (arg->bundle->upat) {
1041 int secs = time(NULL) - arg->bundle->upat;
1042
1043 prompt_Printf(arg->prompt, ", up time %d:%02d:%02d", secs / 3600,
1044 (secs / 60) % 60, secs % 60);
1045 }
1046 prompt_Printf(arg->prompt, "\n Queued: %lu of %u\n",
1059 (unsigned long)ip_QueueLen(&arg->bundle->ncp.ipcp),
1047 (unsigned long)ncp_QueueLen(&arg->bundle->ncp),
1060 arg->bundle->cfg.ifqueue);
1061
1062 prompt_Printf(arg->prompt, "\nDefaults:\n");
1063 prompt_Printf(arg->prompt, " Label: %s\n",
1064 arg->bundle->cfg.label);
1065 prompt_Printf(arg->prompt, " Auth name: %s\n",
1066 arg->bundle->cfg.auth.name);
1067 prompt_Printf(arg->prompt, " Diagnostic socket: ");

--- 23 unchanged lines hidden (view full) ---

1091 arg->bundle->cfg.idle.min_timeout);
1092 remaining = bundle_RemainingIdleTime(arg->bundle);
1093 if (remaining != -1)
1094 prompt_Printf(arg->prompt, " (%ds remaining)", remaining);
1095 prompt_Printf(arg->prompt, "\n");
1096 } else
1097 prompt_Printf(arg->prompt, "disabled\n");
1098
1048 arg->bundle->cfg.ifqueue);
1049
1050 prompt_Printf(arg->prompt, "\nDefaults:\n");
1051 prompt_Printf(arg->prompt, " Label: %s\n",
1052 arg->bundle->cfg.label);
1053 prompt_Printf(arg->prompt, " Auth name: %s\n",
1054 arg->bundle->cfg.auth.name);
1055 prompt_Printf(arg->prompt, " Diagnostic socket: ");

--- 23 unchanged lines hidden (view full) ---

1079 arg->bundle->cfg.idle.min_timeout);
1080 remaining = bundle_RemainingIdleTime(arg->bundle);
1081 if (remaining != -1)
1082 prompt_Printf(arg->prompt, " (%ds remaining)", remaining);
1083 prompt_Printf(arg->prompt, "\n");
1084 } else
1085 prompt_Printf(arg->prompt, "disabled\n");
1086
1099 prompt_Printf(arg->prompt, " sendpipe: ");
1100 if (arg->bundle->ncp.ipcp.cfg.sendpipe > 0)
1101 prompt_Printf(arg->prompt, "%-20ld", arg->bundle->ncp.ipcp.cfg.sendpipe);
1102 else
1103 prompt_Printf(arg->prompt, "unspecified ");
1104 prompt_Printf(arg->prompt, " recvpipe: ");
1105 if (arg->bundle->ncp.ipcp.cfg.recvpipe > 0)
1106 prompt_Printf(arg->prompt, "%ld\n", arg->bundle->ncp.ipcp.cfg.recvpipe);
1107 else
1108 prompt_Printf(arg->prompt, "unspecified\n");
1109
1110 prompt_Printf(arg->prompt, " Sticky Routes: %-20.20s",
1111 optval(arg->bundle, OPT_SROUTES));
1112 prompt_Printf(arg->prompt, " Filter Decap: %s\n",
1087 prompt_Printf(arg->prompt, " Filter Decap: %-20.20s",
1113 optval(arg->bundle, OPT_FILTERDECAP));
1088 optval(arg->bundle, OPT_FILTERDECAP));
1114 prompt_Printf(arg->prompt, " ID check: %-20.20s",
1089 prompt_Printf(arg->prompt, " ID check: %s\n",
1115 optval(arg->bundle, OPT_IDCHECK));
1090 optval(arg->bundle, OPT_IDCHECK));
1091 prompt_Printf(arg->prompt, " Iface-Alias: %-20.20s",
1092 optval(arg->bundle, OPT_IFACEALIAS));
1093#ifndef NOINET6
1094 prompt_Printf(arg->prompt, " IPCP: %s\n",
1095 optval(arg->bundle, OPT_IPCP));
1096 prompt_Printf(arg->prompt, " IPV6CP: %-20.20s",
1097 optval(arg->bundle, OPT_IPV6CP));
1098#endif
1116 prompt_Printf(arg->prompt, " Keep-Session: %s\n",
1117 optval(arg->bundle, OPT_KEEPSESSION));
1118 prompt_Printf(arg->prompt, " Loopback: %-20.20s",
1119 optval(arg->bundle, OPT_LOOPBACK));
1120 prompt_Printf(arg->prompt, " PasswdAuth: %s\n",
1121 optval(arg->bundle, OPT_PASSWDAUTH));
1122 prompt_Printf(arg->prompt, " Proxy: %-20.20s",
1123 optval(arg->bundle, OPT_PROXY));
1124 prompt_Printf(arg->prompt, " Proxyall: %s\n",
1125 optval(arg->bundle, OPT_PROXYALL));
1099 prompt_Printf(arg->prompt, " Keep-Session: %s\n",
1100 optval(arg->bundle, OPT_KEEPSESSION));
1101 prompt_Printf(arg->prompt, " Loopback: %-20.20s",
1102 optval(arg->bundle, OPT_LOOPBACK));
1103 prompt_Printf(arg->prompt, " PasswdAuth: %s\n",
1104 optval(arg->bundle, OPT_PASSWDAUTH));
1105 prompt_Printf(arg->prompt, " Proxy: %-20.20s",
1106 optval(arg->bundle, OPT_PROXY));
1107 prompt_Printf(arg->prompt, " Proxyall: %s\n",
1108 optval(arg->bundle, OPT_PROXYALL));
1126 prompt_Printf(arg->prompt, " TCPMSS Fixup: %-20.20s",
1109 prompt_Printf(arg->prompt, " Sticky Routes: %-20.20s",
1110 optval(arg->bundle, OPT_SROUTES));
1111 prompt_Printf(arg->prompt, " TCPMSS Fixup: %s\n",
1127 optval(arg->bundle, OPT_TCPMSSFIXUP));
1112 optval(arg->bundle, OPT_TCPMSSFIXUP));
1128 prompt_Printf(arg->prompt, " Throughput: %s\n",
1113 prompt_Printf(arg->prompt, " Throughput: %-20.20s",
1129 optval(arg->bundle, OPT_THROUGHPUT));
1114 optval(arg->bundle, OPT_THROUGHPUT));
1130 prompt_Printf(arg->prompt, " Utmp Logging: %-20.20s",
1115 prompt_Printf(arg->prompt, " Utmp Logging: %s\n",
1131 optval(arg->bundle, OPT_UTMP));
1116 optval(arg->bundle, OPT_UTMP));
1132 prompt_Printf(arg->prompt, " Iface-Alias: %s\n",
1133 optval(arg->bundle, OPT_IFACEALIAS));
1134
1135 return 0;
1136}
1137
1138static void
1139bundle_IdleTimeout(void *v)
1140{
1141 struct bundle *bundle = (struct bundle *)v;

--- 36 unchanged lines hidden (view full) ---

1178}
1179
1180void
1181bundle_SetIdleTimer(struct bundle *bundle, int timeout, int min_timeout)
1182{
1183 bundle->cfg.idle.timeout = timeout;
1184 if (min_timeout >= 0)
1185 bundle->cfg.idle.min_timeout = min_timeout;
1117
1118 return 0;
1119}
1120
1121static void
1122bundle_IdleTimeout(void *v)
1123{
1124 struct bundle *bundle = (struct bundle *)v;

--- 36 unchanged lines hidden (view full) ---

1161}
1162
1163void
1164bundle_SetIdleTimer(struct bundle *bundle, int timeout, int min_timeout)
1165{
1166 bundle->cfg.idle.timeout = timeout;
1167 if (min_timeout >= 0)
1168 bundle->cfg.idle.min_timeout = min_timeout;
1186 if (bundle_LinkIsUp(bundle))
1169 if (ncp_LayersOpen(&bundle->ncp))
1187 bundle_StartIdleTimer(bundle, 0);
1188}
1189
1190void
1191bundle_StopIdleTimer(struct bundle *bundle)
1192{
1193 timer_Stop(&bundle->idle.timer);
1194 bundle->idle.done = 0;

--- 595 unchanged lines hidden (view full) ---

1790 datalink_Down(dl, CLOSE_NORMAL);
1791 return 1;
1792 }
1793
1794 return 0;
1795}
1796
1797void
1170 bundle_StartIdleTimer(bundle, 0);
1171}
1172
1173void
1174bundle_StopIdleTimer(struct bundle *bundle)
1175{
1176 timer_Stop(&bundle->idle.timer);
1177 bundle->idle.done = 0;

--- 595 unchanged lines hidden (view full) ---

1773 datalink_Down(dl, CLOSE_NORMAL);
1774 return 1;
1775 }
1776
1777 return 0;
1778}
1779
1780void
1798bundle_AdjustFilters(struct bundle *bundle, struct in_addr *my_ip,
1799 struct in_addr *peer_ip)
1781bundle_AdjustFilters(struct bundle *bundle, struct ncpaddr *local,
1782 struct ncpaddr *remote)
1800{
1783{
1801 filter_AdjustAddr(&bundle->filter.in, my_ip, peer_ip, NULL);
1802 filter_AdjustAddr(&bundle->filter.out, my_ip, peer_ip, NULL);
1803 filter_AdjustAddr(&bundle->filter.dial, my_ip, peer_ip, NULL);
1804 filter_AdjustAddr(&bundle->filter.alive, my_ip, peer_ip, NULL);
1784 filter_AdjustAddr(&bundle->filter.in, local, remote, NULL);
1785 filter_AdjustAddr(&bundle->filter.out, local, remote, NULL);
1786 filter_AdjustAddr(&bundle->filter.dial, local, remote, NULL);
1787 filter_AdjustAddr(&bundle->filter.alive, local, remote, NULL);
1805}
1806
1807void
1788}
1789
1790void
1808bundle_AdjustDNS(struct bundle *bundle, struct in_addr dns[2])
1791bundle_AdjustDNS(struct bundle *bundle)
1809{
1792{
1793 struct in_addr *dns = bundle->ncp.ipcp.ns.dns;
1794
1810 filter_AdjustAddr(&bundle->filter.in, NULL, NULL, dns);
1811 filter_AdjustAddr(&bundle->filter.out, NULL, NULL, dns);
1812 filter_AdjustAddr(&bundle->filter.dial, NULL, NULL, dns);
1813 filter_AdjustAddr(&bundle->filter.alive, NULL, NULL, dns);
1814}
1815
1816void
1817bundle_CalculateBandwidth(struct bundle *bundle)

--- 129 unchanged lines hidden ---
1795 filter_AdjustAddr(&bundle->filter.in, NULL, NULL, dns);
1796 filter_AdjustAddr(&bundle->filter.out, NULL, NULL, dns);
1797 filter_AdjustAddr(&bundle->filter.dial, NULL, NULL, dns);
1798 filter_AdjustAddr(&bundle->filter.alive, NULL, NULL, dns);
1799}
1800
1801void
1802bundle_CalculateBandwidth(struct bundle *bundle)

--- 129 unchanged lines hidden ---