Lines Matching refs:bundle

108 static int bundle_RemainingIdleTime(struct bundle *);
115 bundle_PhaseName(struct bundle *bundle) in bundle_PhaseName() argument
117 return bundle->phase <= PHASE_TERMINATE ? in bundle_PhaseName()
118 PhaseNames[bundle->phase] : "unknown"; in bundle_PhaseName()
122 bundle_NewPhase(struct bundle *bundle, u_int new) in bundle_NewPhase() argument
124 if (new == bundle->phase) in bundle_NewPhase()
132 bundle->phase = new; in bundle_NewPhase()
140 bundle->phase = new; in bundle_NewPhase()
144 bundle->phase = new; in bundle_NewPhase()
149 if (ncp_fsmStart(&bundle->ncp, bundle)) { in bundle_NewPhase()
150 bundle->phase = new; in bundle_NewPhase()
154 bundle_Close(bundle, NULL, CLOSE_STAYDOWN); in bundle_NewPhase()
159 bundle->phase = new; in bundle_NewPhase()
160 mp_Down(&bundle->ncp.mp); in bundle_NewPhase()
174 bundle_Notify(struct bundle *bundle, char c) in bundle_Notify() argument
176 if (bundle->notify.fd != -1) { in bundle_Notify()
179 ret = write(bundle->notify.fd, &c, 1); in bundle_Notify()
186 close(bundle->notify.fd); in bundle_Notify()
187 bundle->notify.fd = -1; in bundle_Notify()
198 struct bundle *bundle = (struct bundle *)v; in bundle_ClearQueues() local
202 timer_Stop(&bundle->choked.timer); in bundle_ClearQueues()
219 ncp_DeleteQueues(&bundle->ncp); in bundle_ClearQueues()
220 for (dl = bundle->links; dl; dl = dl->next) in bundle_ClearQueues()
225 bundle_LinkAdded(struct bundle *bundle, struct datalink *dl) in bundle_LinkAdded() argument
227 bundle->phys_type.all |= dl->physical->type; in bundle_LinkAdded()
229 bundle->phys_type.open |= dl->physical->type; in bundle_LinkAdded()
232 if ((bundle->phys_type.open & (PHYS_DEDICATED|PHYS_DDIAL)) in bundle_LinkAdded()
233 != bundle->phys_type.open && bundle->session.timer.state == TIMER_STOPPED) in bundle_LinkAdded()
234 if (bundle->radius.sessiontime) in bundle_LinkAdded()
235 bundle_StartSessionTimer(bundle, 0); in bundle_LinkAdded()
238 if ((bundle->phys_type.open & (PHYS_DEDICATED|PHYS_DDIAL)) in bundle_LinkAdded()
239 != bundle->phys_type.open && bundle->idle.timer.state == TIMER_STOPPED) in bundle_LinkAdded()
241 bundle_StartIdleTimer(bundle, 0); in bundle_LinkAdded()
245 bundle_LinksRemoved(struct bundle *bundle) in bundle_LinksRemoved() argument
249 bundle->phys_type.all = bundle->phys_type.open = 0; in bundle_LinksRemoved()
250 for (dl = bundle->links; dl; dl = dl->next) in bundle_LinksRemoved()
251 bundle_LinkAdded(bundle, dl); in bundle_LinksRemoved()
253 bundle_CalculateBandwidth(bundle); in bundle_LinksRemoved()
254 mp_CheckAutoloadTimer(&bundle->ncp.mp); in bundle_LinksRemoved()
256 if ((bundle->phys_type.open & (PHYS_DEDICATED|PHYS_DDIAL)) in bundle_LinksRemoved()
257 == bundle->phys_type.open) { in bundle_LinksRemoved()
259 if (bundle->radius.sessiontime) in bundle_LinksRemoved()
260 bundle_StopSessionTimer(bundle); in bundle_LinksRemoved()
262 bundle_StopIdleTimer(bundle); in bundle_LinksRemoved()
279 struct bundle *bundle = (struct bundle *)v; in bundle_LayerUp() local
284 bundle_LinkAdded(bundle, p->dl); in bundle_LayerUp()
285 mp_CheckAutoloadTimer(&bundle->ncp.mp); in bundle_LayerUp()
287 if (ncp_LayersOpen(&fp->bundle->ncp) == 1) { in bundle_LayerUp()
288 bundle_CalculateBandwidth(fp->bundle); in bundle_LayerUp()
289 time(&bundle->upat); in bundle_LayerUp()
291 if (bundle->radius.sessiontime) in bundle_LayerUp()
292 bundle_StartSessionTimer(bundle, 0); in bundle_LayerUp()
294 bundle_StartIdleTimer(bundle, 0); in bundle_LayerUp()
295 mp_CheckAutoloadTimer(&fp->bundle->ncp.mp); in bundle_LayerUp()
297 bundle_Notify(bundle, EX_NORMAL); in bundle_LayerUp()
299 bundle_CalculateBandwidth(fp->bundle); /* Against ccp_MTUOverhead */ in bundle_LayerUp()
316 struct bundle *bundle = (struct bundle *)v; in bundle_LayerDown() local
319 if (ncp_LayersOpen(&fp->bundle->ncp) == 0) { in bundle_LayerDown()
321 if (bundle->radius.sessiontime) in bundle_LayerDown()
322 bundle_StopSessionTimer(bundle); in bundle_LayerDown()
324 bundle_StopIdleTimer(bundle); in bundle_LayerDown()
325 bundle->upat = 0; in bundle_LayerDown()
326 mp_StopAutoloadTimer(&bundle->ncp.mp); in bundle_LayerDown()
333 bundle_LinksRemoved(bundle); /* adjust timers & phys_type values */ in bundle_LayerDown()
337 for (dl = bundle->links; dl; dl = dl->next) { in bundle_LayerDown()
344 if (bundle->ncp.mp.active) { in bundle_LayerDown()
345 bundle_CalculateBandwidth(bundle); in bundle_LayerDown()
348 mp_LinkLost(&bundle->ncp.mp, lost); in bundle_LayerDown()
356 ncp2initial(&bundle->ncp); in bundle_LayerDown()
357 mp_Down(&bundle->ncp.mp); in bundle_LayerDown()
371 struct bundle *bundle = (struct bundle *)v; in bundle_LayerFinish() local
374 if (isncp(fp->proto) && !ncp_LayersUnfinished(&bundle->ncp)) { in bundle_LayerFinish()
375 if (bundle_Phase(bundle) != PHASE_DEAD) in bundle_LayerFinish()
376 bundle_NewPhase(bundle, PHASE_TERMINATE); in bundle_LayerFinish()
377 for (dl = bundle->links; dl; dl = dl->next) in bundle_LayerFinish()
381 mp_Down(&bundle->ncp.mp); in bundle_LayerFinish()
386 bundle_Close(struct bundle *bundle, const char *name, int how) in bundle_Close() argument
401 for (dl = bundle->links; dl; dl = dl->next) { in bundle_Close()
424 if (bundle->radius.sessiontime) in bundle_Close()
425 bundle_StopSessionTimer(bundle); in bundle_Close()
427 bundle_StopIdleTimer(bundle); in bundle_Close()
428 if (ncp_LayersUnfinished(&bundle->ncp)) in bundle_Close()
429 ncp_Close(&bundle->ncp); in bundle_Close()
431 ncp2initial(&bundle->ncp); in bundle_Close()
432 mp_Down(&bundle->ncp.mp); in bundle_Close()
433 for (dl = bundle->links; dl; dl = dl->next) in bundle_Close()
442 bundle_Down(struct bundle *bundle, int how) in bundle_Down() argument
446 for (dl = bundle->links; dl; dl = dl->next) in bundle_Down()
453 struct bundle *bundle = descriptor2bundle(d); in bundle_UpdateSet() local
462 for (nlinks = 0, dl = bundle->links; dl; dl = dl->next) in bundle_UpdateSet()
466 queued = r ? ncp_FillPhysicalQueues(&bundle->ncp, bundle) : in bundle_UpdateSet()
467 ncp_QueueLen(&bundle->ncp); in bundle_UpdateSet()
469 if (r && (bundle->phase == PHASE_NETWORK || in bundle_UpdateSet()
470 bundle->phys_type.all & PHYS_AUTO)) { in bundle_UpdateSet()
472 ifqueue = nlinks > bundle->cfg.ifqueue ? nlinks : bundle->cfg.ifqueue; in bundle_UpdateSet()
475 if (bundle->choked.timer.state == TIMER_RUNNING) in bundle_UpdateSet()
476 timer_Stop(&bundle->choked.timer); /* Not needed any more */ in bundle_UpdateSet()
477 FD_SET(bundle->dev.fd, r); in bundle_UpdateSet()
478 if (*n < bundle->dev.fd + 1) in bundle_UpdateSet()
479 *n = bundle->dev.fd + 1; in bundle_UpdateSet()
480 log_Printf(LogTIMER, "%s: fdset(r) %d\n", TUN_NAME, bundle->dev.fd); in bundle_UpdateSet()
482 } else if (bundle->choked.timer.state == TIMER_STOPPED) { in bundle_UpdateSet()
483 bundle->choked.timer.func = bundle_ClearQueues; in bundle_UpdateSet()
484 bundle->choked.timer.name = "output choke"; in bundle_UpdateSet()
485 bundle->choked.timer.load = bundle->cfg.choked.timeout * SECTICKS; in bundle_UpdateSet()
486 bundle->choked.timer.arg = bundle; in bundle_UpdateSet()
487 timer_Start(&bundle->choked.timer); in bundle_UpdateSet()
493 result += descriptor_UpdateSet(&bundle->radius.desc, r, w, e, n); in bundle_UpdateSet()
497 for (dl = bundle->links; dl; dl = dl->next) in bundle_UpdateSet()
505 result += descriptor_UpdateSet(&bundle->ncp.mp.server.desc, r, w, e, n); in bundle_UpdateSet()
513 struct bundle *bundle = descriptor2bundle(d); in bundle_IsSet() local
516 for (dl = bundle->links; dl; dl = dl->next) in bundle_IsSet()
521 if (descriptor_IsSet(&bundle->radius.desc, fdset)) in bundle_IsSet()
525 if (descriptor_IsSet(&bundle->ncp.mp.server.desc, fdset)) in bundle_IsSet()
528 return FD_ISSET(bundle->dev.fd, fdset); in bundle_IsSet()
532 bundle_DescriptorRead(struct fdescriptor *d __unused, struct bundle *bundle, in bundle_DescriptorRead() argument
539 if (descriptor_IsSet(&bundle->ncp.mp.server.desc, fdset)) in bundle_DescriptorRead()
540 descriptor_Read(&bundle->ncp.mp.server.desc, bundle, fdset); in bundle_DescriptorRead()
542 for (dl = bundle->links; dl; dl = dl->next) in bundle_DescriptorRead()
544 descriptor_Read(&dl->desc, bundle, fdset); in bundle_DescriptorRead()
547 if (descriptor_IsSet(&bundle->radius.desc, fdset)) in bundle_DescriptorRead()
548 descriptor_Read(&bundle->radius.desc, bundle, fdset); in bundle_DescriptorRead()
551 if (FD_ISSET(bundle->dev.fd, fdset)) { in bundle_DescriptorRead()
557 if (bundle->dev.header) { in bundle_DescriptorRead()
567 n = read(bundle->dev.fd, data, sz); in bundle_DescriptorRead()
569 log_Printf(LogWARN, "%s: read: %s\n", bundle->dev.Name, strerror(errno)); in bundle_DescriptorRead()
573 if (bundle->dev.header) { in bundle_DescriptorRead()
577 bundle->dev.Name, n); in bundle_DescriptorRead()
592 bundle->ncp.ipcp.my_ip.s_addr) { in bundle_DescriptorRead()
594 if (Enabled(bundle, OPT_LOOPBACK)) { in bundle_DescriptorRead()
595 pri = PacketCheck(bundle, af, tun.data, n, &bundle->filter.in, in bundle_DescriptorRead()
599 write(bundle->dev.fd, data, n); in bundle_DescriptorRead()
612 if (bundle_Phase(bundle) == PHASE_DEAD) { in bundle_DescriptorRead()
617 pri = PacketCheck(bundle, af, tun.data, n, &bundle->filter.dial, in bundle_DescriptorRead()
620 bundle_Open(bundle, NULL, PHYS_AUTO, 0); in bundle_DescriptorRead()
633 pri = PacketCheck(bundle, af, tun.data, n, &bundle->filter.out, in bundle_DescriptorRead()
638 ncp_Enqueue(&bundle->ncp, af, pri, (char *)&tun, n + sizeof tun.header); in bundle_DescriptorRead()
644 bundle_DescriptorWrite(struct fdescriptor *d __unused, struct bundle *bundle, in bundle_DescriptorWrite() argument
651 if (descriptor_IsSet(&bundle->ncp.mp.server.desc, fdset)) in bundle_DescriptorWrite()
652 if (descriptor_Write(&bundle->ncp.mp.server.desc, bundle, fdset) == 1) in bundle_DescriptorWrite()
655 for (dl = bundle->links; dl; dl = dl->next) in bundle_DescriptorWrite()
657 switch (descriptor_Write(&dl->desc, bundle, fdset)) { in bundle_DescriptorWrite()
669 bundle_LockTun(struct bundle *bundle) in bundle_LockTun() argument
674 snprintf(pidfile, sizeof pidfile, "%stun%d.pid", _PATH_VARRUN, bundle->unit); in bundle_LockTun()
685 bundle_UnlockTun(struct bundle *bundle) in bundle_UnlockTun() argument
689 snprintf(pidfile, sizeof pidfile, "%stun%d.pid", _PATH_VARRUN, bundle->unit); in bundle_UnlockTun()
693 struct bundle *
696 static struct bundle bundle; /* there can be only one */ in bundle_Create() local
706 if (bundle.iface != NULL) { /* Already allocated ! */ in bundle_Create()
723 for (bundle.unit = minunit; bundle.unit != maxunit; bundle.unit++) { in bundle_Create()
724 snprintf(bundle.dev.Name, sizeof bundle.dev.Name, "%s%d", in bundle_Create()
725 prefix, bundle.unit); in bundle_Create()
726 bundle.dev.fd = ID0open(bundle.dev.Name, O_RDWR); in bundle_Create()
727 if (bundle.dev.fd >= 0) in bundle_Create()
731 if (bundle.unit == minunit && !kldtried++) { in bundle_Create()
737 bundle.unit--; in bundle_Create()
749 if (bundle.dev.fd < 0) { in bundle_Create()
758 log_SetTun(bundle.unit, NULL); in bundle_Create()
760 ifname = strrchr(bundle.dev.Name, '/'); in bundle_Create()
762 ifname = bundle.dev.Name; in bundle_Create()
766 bundle.iface = iface_Create(ifname); in bundle_Create()
767 if (bundle.iface == NULL) { in bundle_Create()
768 close(bundle.dev.fd); in bundle_Create()
775 if (ID0ioctl(bundle.dev.fd, TUNSIFMODE, &iff) < 0) in bundle_Create()
783 if (ID0ioctl(bundle.dev.fd, TUNSLMODE, &iff) < 0) in bundle_Create()
791 if (ID0ioctl(bundle.dev.fd, TUNSIFHEAD, &iff) < 0) { in bundle_Create()
794 bundle.dev.header = 0; in bundle_Create()
796 bundle.dev.header = 1; in bundle_Create()
800 bundle.dev.header = 1; in bundle_Create()
807 bundle.dev.header = 0; in bundle_Create()
813 bundle.bandwidth = 0; in bundle_Create()
814 bundle.routing_seq = 0; in bundle_Create()
815 bundle.phase = PHASE_DEAD; in bundle_Create()
816 bundle.CleaningUp = 0; in bundle_Create()
817 bundle.NatEnabled = 0; in bundle_Create()
819 bundle.fsm.LayerStart = bundle_LayerStart; in bundle_Create()
820 bundle.fsm.LayerUp = bundle_LayerUp; in bundle_Create()
821 bundle.fsm.LayerDown = bundle_LayerDown; in bundle_Create()
822 bundle.fsm.LayerFinish = bundle_LayerFinish; in bundle_Create()
823 bundle.fsm.object = &bundle; in bundle_Create()
825 bundle.cfg.idle.timeout = NCP_IDLE_TIMEOUT; in bundle_Create()
826 bundle.cfg.idle.min_timeout = 0; in bundle_Create()
827 *bundle.cfg.auth.name = '\0'; in bundle_Create()
828 *bundle.cfg.auth.key = '\0'; in bundle_Create()
829 bundle.cfg.optmask = (1ull << OPT_IDCHECK) | (1ull << OPT_LOOPBACK) | in bundle_Create()
835 opt_enable(&bundle, OPT_IPCP); in bundle_Create()
837 opt_enable(&bundle, OPT_IPV6CP); in bundle_Create()
839 *bundle.cfg.label = '\0'; in bundle_Create()
840 bundle.cfg.ifqueue = DEF_IFQUEUE; in bundle_Create()
841 bundle.cfg.choked.timeout = CHOKED_TIMEOUT; in bundle_Create()
842 bundle.phys_type.all = type; in bundle_Create()
843 bundle.phys_type.open = 0; in bundle_Create()
844 bundle.upat = 0; in bundle_Create()
846 bundle.links = datalink_Create("deflink", &bundle, type); in bundle_Create()
847 if (bundle.links == NULL) { in bundle_Create()
849 iface_Free(bundle.iface); in bundle_Create()
850 bundle.iface = NULL; in bundle_Create()
851 close(bundle.dev.fd); in bundle_Create()
855 bundle.desc.type = BUNDLE_DESCRIPTOR; in bundle_Create()
856 bundle.desc.UpdateSet = bundle_UpdateSet; in bundle_Create()
857 bundle.desc.IsSet = bundle_IsSet; in bundle_Create()
858 bundle.desc.Read = bundle_DescriptorRead; in bundle_Create()
859 bundle.desc.Write = bundle_DescriptorWrite; in bundle_Create()
861 ncp_Init(&bundle.ncp, &bundle); in bundle_Create()
863 memset(&bundle.filter, '\0', sizeof bundle.filter); in bundle_Create()
864 bundle.filter.in.fragok = bundle.filter.in.logok = 1; in bundle_Create()
865 bundle.filter.in.name = "IN"; in bundle_Create()
866 bundle.filter.out.fragok = bundle.filter.out.logok = 1; in bundle_Create()
867 bundle.filter.out.name = "OUT"; in bundle_Create()
868 bundle.filter.dial.name = "DIAL"; in bundle_Create()
869 bundle.filter.dial.logok = 1; in bundle_Create()
870 bundle.filter.alive.name = "ALIVE"; in bundle_Create()
871 bundle.filter.alive.logok = 1; in bundle_Create()
875 bundle.filter.in.rule[i].f_action = A_NONE; in bundle_Create()
876 bundle.filter.out.rule[i].f_action = A_NONE; in bundle_Create()
877 bundle.filter.dial.rule[i].f_action = A_NONE; in bundle_Create()
878 bundle.filter.alive.rule[i].f_action = A_NONE; in bundle_Create()
881 memset(&bundle.idle.timer, '\0', sizeof bundle.idle.timer); in bundle_Create()
882 bundle.idle.done = 0; in bundle_Create()
883 bundle.notify.fd = -1; in bundle_Create()
884 memset(&bundle.choked.timer, '\0', sizeof bundle.choked.timer); in bundle_Create()
886 radius_Init(&bundle.radius); in bundle_Create()
890 iface_Clear(bundle.iface, &bundle.ncp, 0, IFACE_CLEAR_ALL); in bundle_Create()
892 bundle_LockTun(&bundle); in bundle_Create()
894 return &bundle; in bundle_Create()
898 bundle_DownInterface(struct bundle *bundle) in bundle_DownInterface() argument
900 route_IfDelete(bundle, 1); in bundle_DownInterface()
901 iface_ClearFlags(bundle->iface->name, IFF_UP); in bundle_DownInterface()
905 bundle_Destroy(struct bundle *bundle) in bundle_Destroy() argument
914 timer_Stop(&bundle->idle.timer); in bundle_Destroy()
915 timer_Stop(&bundle->choked.timer); in bundle_Destroy()
916 mp_Down(&bundle->ncp.mp); in bundle_Destroy()
917 iface_Clear(bundle->iface, &bundle->ncp, 0, IFACE_CLEAR_ALL); in bundle_Destroy()
918 bundle_DownInterface(bundle); in bundle_Destroy()
922 radius_Destroy(&bundle->radius); in bundle_Destroy()
926 dl = bundle->links; in bundle_Destroy()
930 ncp_Destroy(&bundle->ncp); in bundle_Destroy()
932 close(bundle->dev.fd); in bundle_Destroy()
933 bundle_UnlockTun(bundle); in bundle_Destroy()
936 bundle_Notify(bundle, EX_ERRDEAD); in bundle_Destroy()
938 iface_Destroy(bundle->iface); in bundle_Destroy()
939 bundle->iface = NULL; in bundle_Destroy()
943 bundle_LinkClosed(struct bundle *bundle, struct datalink *dl) in bundle_LinkClosed() argument
960 for (odl = bundle->links; odl; odl = odl->next) in bundle_LinkClosed()
966 bundle_DownInterface(bundle); in bundle_LinkClosed()
967 ncp2initial(&bundle->ncp); in bundle_LinkClosed()
968 mp_Down(&bundle->ncp.mp); in bundle_LinkClosed()
969 bundle_NewPhase(bundle, PHASE_DEAD); in bundle_LinkClosed()
971 if (bundle->radius.sessiontime) in bundle_LinkClosed()
972 bundle_StopSessionTimer(bundle); in bundle_LinkClosed()
974 bundle_StopIdleTimer(bundle); in bundle_LinkClosed()
979 bundle_Open(struct bundle *bundle, const char *name, int mask, int force) in bundle_Open() argument
986 for (dl = bundle->links; dl; dl = dl->next) in bundle_Open()
1004 bundle2datalink(struct bundle *bundle, const char *name) in bundle2datalink() argument
1009 for (dl = bundle->links; dl; dl = dl->next) in bundle2datalink()
1012 } else if (bundle->links && !bundle->links->next) in bundle2datalink()
1013 return bundle->links; in bundle2datalink()
1026 for (dl = arg->bundle->links; dl; dl = dl->next) { in bundle_ShowLinks()
1040 t = &arg->bundle->ncp.mp.link.stats.total; in bundle_ShowLinks()
1053 optval(struct bundle *bundle, int opt) in optval() argument
1055 return Enabled(bundle, opt) ? "enabled" : "disabled"; in optval()
1063 prompt_Printf(arg->prompt, "Phase %s\n", bundle_PhaseName(arg->bundle)); in bundle_ShowStatus()
1064 prompt_Printf(arg->prompt, " Device: %s\n", arg->bundle->dev.Name); in bundle_ShowStatus()
1066 arg->bundle->iface->name, arg->bundle->bandwidth); in bundle_ShowStatus()
1068 if (arg->bundle->upat) { in bundle_ShowStatus()
1069 int secs = bundle_Uptime(arg->bundle); in bundle_ShowStatus()
1075 (unsigned long)ncp_QueueLen(&arg->bundle->ncp), in bundle_ShowStatus()
1076 arg->bundle->cfg.ifqueue); in bundle_ShowStatus()
1080 arg->bundle->cfg.label); in bundle_ShowStatus()
1082 arg->bundle->cfg.auth.name); in bundle_ShowStatus()
1096 arg->bundle->cfg.choked.timeout); in bundle_ShowStatus()
1099 radius_Show(&arg->bundle->radius, arg->prompt); in bundle_ShowStatus()
1103 if (arg->bundle->cfg.idle.timeout) { in bundle_ShowStatus()
1104 prompt_Printf(arg->prompt, "%us", arg->bundle->cfg.idle.timeout); in bundle_ShowStatus()
1105 if (arg->bundle->cfg.idle.min_timeout) in bundle_ShowStatus()
1107 arg->bundle->cfg.idle.min_timeout); in bundle_ShowStatus()
1108 remaining = bundle_RemainingIdleTime(arg->bundle); in bundle_ShowStatus()
1116 optval(arg->bundle, OPT_FILTERDECAP)); in bundle_ShowStatus()
1118 optval(arg->bundle, OPT_IDCHECK)); in bundle_ShowStatus()
1120 optval(arg->bundle, OPT_IFACEALIAS)); in bundle_ShowStatus()
1123 optval(arg->bundle, OPT_IPCP)); in bundle_ShowStatus()
1125 optval(arg->bundle, OPT_IPV6CP)); in bundle_ShowStatus()
1128 optval(arg->bundle, OPT_KEEPSESSION)); in bundle_ShowStatus()
1130 optval(arg->bundle, OPT_LOOPBACK)); in bundle_ShowStatus()
1132 optval(arg->bundle, OPT_PASSWDAUTH)); in bundle_ShowStatus()
1134 optval(arg->bundle, OPT_PROXY)); in bundle_ShowStatus()
1136 optval(arg->bundle, OPT_PROXYALL)); in bundle_ShowStatus()
1138 optval(arg->bundle, OPT_SROUTES)); in bundle_ShowStatus()
1140 optval(arg->bundle, OPT_TCPMSSFIXUP)); in bundle_ShowStatus()
1142 optval(arg->bundle, OPT_THROUGHPUT)); in bundle_ShowStatus()
1144 optval(arg->bundle, OPT_UTMP)); in bundle_ShowStatus()
1146 optval(arg->bundle, OPT_NAS_IP_ADDRESS)); in bundle_ShowStatus()
1148 optval(arg->bundle, OPT_NAS_IDENTIFIER)); in bundle_ShowStatus()
1156 struct bundle *bundle = (struct bundle *)v; in bundle_IdleTimeout() local
1159 bundle_StopIdleTimer(bundle); in bundle_IdleTimeout()
1160 bundle_Close(bundle, NULL, CLOSE_STAYDOWN); in bundle_IdleTimeout()
1168 bundle_StartIdleTimer(struct bundle *bundle, unsigned secs) in bundle_StartIdleTimer() argument
1170 timer_Stop(&bundle->idle.timer); in bundle_StartIdleTimer()
1171 if ((bundle->phys_type.open & (PHYS_DEDICATED|PHYS_DDIAL)) != in bundle_StartIdleTimer()
1172 bundle->phys_type.open && bundle->cfg.idle.timeout) { in bundle_StartIdleTimer()
1176 secs = bundle->cfg.idle.timeout; in bundle_StartIdleTimer()
1179 if (bundle->cfg.idle.min_timeout > secs && bundle->upat) { in bundle_StartIdleTimer()
1180 unsigned up = now - bundle->upat; in bundle_StartIdleTimer()
1182 if (bundle->cfg.idle.min_timeout > up && in bundle_StartIdleTimer()
1183 bundle->cfg.idle.min_timeout - up > (long long)secs) in bundle_StartIdleTimer()
1185 secs = bundle->cfg.idle.min_timeout - up; in bundle_StartIdleTimer()
1187 bundle->idle.timer.func = bundle_IdleTimeout; in bundle_StartIdleTimer()
1188 bundle->idle.timer.name = "idle"; in bundle_StartIdleTimer()
1189 bundle->idle.timer.load = secs * SECTICKS; in bundle_StartIdleTimer()
1190 bundle->idle.timer.arg = bundle; in bundle_StartIdleTimer()
1191 timer_Start(&bundle->idle.timer); in bundle_StartIdleTimer()
1192 bundle->idle.done = now + secs; in bundle_StartIdleTimer()
1197 bundle_SetIdleTimer(struct bundle *bundle, unsigned timeout, in bundle_SetIdleTimer() argument
1200 bundle->cfg.idle.timeout = timeout; in bundle_SetIdleTimer()
1201 bundle->cfg.idle.min_timeout = min_timeout; in bundle_SetIdleTimer()
1202 if (ncp_LayersOpen(&bundle->ncp)) in bundle_SetIdleTimer()
1203 bundle_StartIdleTimer(bundle, 0); in bundle_SetIdleTimer()
1207 bundle_StopIdleTimer(struct bundle *bundle) in bundle_StopIdleTimer() argument
1209 timer_Stop(&bundle->idle.timer); in bundle_StopIdleTimer()
1210 bundle->idle.done = 0; in bundle_StopIdleTimer()
1214 bundle_RemainingIdleTime(struct bundle *bundle) in bundle_RemainingIdleTime() argument
1216 if (bundle->idle.done) in bundle_RemainingIdleTime()
1217 return bundle->idle.done - time(NULL); in bundle_RemainingIdleTime()
1226 struct bundle *bundle = (struct bundle *)v; in bundle_SessionTimeout() local
1229 bundle_StopSessionTimer(bundle); in bundle_SessionTimeout()
1230 bundle_Close(bundle, NULL, CLOSE_STAYDOWN); in bundle_SessionTimeout()
1234 bundle_StartSessionTimer(struct bundle *bundle, unsigned secs) in bundle_StartSessionTimer() argument
1236 timer_Stop(&bundle->session.timer); in bundle_StartSessionTimer()
1237 if ((bundle->phys_type.open & (PHYS_DEDICATED|PHYS_DDIAL)) != in bundle_StartSessionTimer()
1238 bundle->phys_type.open && bundle->radius.sessiontime) { in bundle_StartSessionTimer()
1242 secs = bundle->radius.sessiontime; in bundle_StartSessionTimer()
1244 bundle->session.timer.func = bundle_SessionTimeout; in bundle_StartSessionTimer()
1245 bundle->session.timer.name = "session"; in bundle_StartSessionTimer()
1246 bundle->session.timer.load = secs * SECTICKS; in bundle_StartSessionTimer()
1247 bundle->session.timer.arg = bundle; in bundle_StartSessionTimer()
1248 timer_Start(&bundle->session.timer); in bundle_StartSessionTimer()
1249 bundle->session.done = now + secs; in bundle_StartSessionTimer()
1254 bundle_StopSessionTimer(struct bundle *bundle) in bundle_StopSessionTimer() argument
1256 timer_Stop(&bundle->session.timer); in bundle_StopSessionTimer()
1257 bundle->session.done = 0; in bundle_StopSessionTimer()
1263 bundle_IsDead(struct bundle *bundle) in bundle_IsDead() argument
1265 return !bundle->links || (bundle->phase == PHASE_DEAD && bundle->CleaningUp); in bundle_IsDead()
1269 bundle_DatalinkLinkout(struct bundle *bundle, struct datalink *dl) in bundle_DatalinkLinkout() argument
1273 for (dlp = &bundle->links; *dlp; dlp = &(*dlp)->next) in bundle_DatalinkLinkout()
1277 bundle_LinksRemoved(bundle); in bundle_DatalinkLinkout()
1285 bundle_DatalinkLinkin(struct bundle *bundle, struct datalink *dl) in bundle_DatalinkLinkin() argument
1287 struct datalink **dlp = &bundle->links; in bundle_DatalinkLinkin()
1295 bundle_LinkAdded(bundle, dl); in bundle_DatalinkLinkin()
1296 mp_CheckAutoloadTimer(&bundle->ncp.mp); in bundle_DatalinkLinkin()
1300 bundle_CleanDatalinks(struct bundle *bundle) in bundle_CleanDatalinks() argument
1302 struct datalink **dlp = &bundle->links; in bundle_CleanDatalinks()
1315 bundle_LinksRemoved(bundle); in bundle_CleanDatalinks()
1319 bundle_DatalinkClone(struct bundle *bundle, struct datalink *dl, in bundle_DatalinkClone() argument
1322 if (bundle2datalink(bundle, name)) { in bundle_DatalinkClone()
1327 bundle_DatalinkLinkin(bundle, datalink_Clone(dl, name)); in bundle_DatalinkClone()
1332 bundle_DatalinkRemove(struct bundle *bundle, struct datalink *dl) in bundle_DatalinkRemove() argument
1334 dl = bundle_DatalinkLinkout(bundle, dl); in bundle_DatalinkRemove()
1340 bundle_SetLabel(struct bundle *bundle, const char *label) in bundle_SetLabel() argument
1343 strncpy(bundle->cfg.label, label, sizeof bundle->cfg.label - 1); in bundle_SetLabel()
1345 *bundle->cfg.label = '\0'; in bundle_SetLabel()
1349 bundle_GetLabel(struct bundle *bundle) in bundle_GetLabel() argument
1351 return *bundle->cfg.label ? bundle->cfg.label : NULL; in bundle_GetLabel()
1375 bundle_ReceiveDatalink(struct bundle *bundle, int s) in bundle_ReceiveDatalink() argument
1510 dl = iov2datalink(bundle, iov, &niov, sizeof iov / sizeof *iov, fd[0], in bundle_ReceiveDatalink()
1522 bundle_DatalinkLinkin(bundle, dl); in bundle_ReceiveDatalink()
1524 bundle_CalculateBandwidth(dl->bundle); in bundle_ReceiveDatalink()
1559 bundle_LinkClosed(dl->bundle, dl); in bundle_SendDatalink()
1560 bundle_DatalinkLinkout(dl->bundle, dl); in bundle_SendDatalink()
1651 newsid = Enabled(dl->bundle, OPT_KEEPSESSION) || in bundle_SendDatalink()
1656 bundle_setsid(dl->bundle, got != -1); in bundle_SendDatalink()
1665 bundle_RenameDatalink(struct bundle *bundle, struct datalink *ndl, in bundle_RenameDatalink() argument
1673 for (dl = bundle->links; dl; dl = dl->next) in bundle_RenameDatalink()
1682 bundle_SetMode(struct bundle *bundle, struct datalink *dl, int mode) in bundle_SetMode() argument
1690 if (mode == PHYS_AUTO && !(bundle->phys_type.all & PHYS_AUTO)) in bundle_SetMode()
1692 if (bundle->ncp.ipcp.peer_ip.s_addr == INADDR_ANY) { in bundle_SetMode()
1701 if (mode == PHYS_AUTO && !(bundle->phys_type.all & PHYS_AUTO) && in bundle_SetMode()
1702 bundle->phase != PHASE_NETWORK) in bundle_SetMode()
1704 ipcp_InterfaceUp(&bundle->ncp.ipcp); in bundle_SetMode()
1707 bundle_LinksRemoved(bundle); in bundle_SetMode()
1713 bundle_setsid(struct bundle *bundle, int holdsession) in bundle_setsid() argument
1725 if (!holdsession && bundle_IsDead(bundle)) { in bundle_setsid()
1762 bundle_LockTun(bundle); /* update pid */ in bundle_setsid()
1766 bundle_ChangedPID(bundle); in bundle_setsid()
1775 for (dl = bundle->links; dl; dl = dl->next) in bundle_setsid()
1787 for (dl = bundle->links; dl; dl = dl->next) in bundle_setsid()
1830 bundle_HighestState(struct bundle *bundle) in bundle_HighestState() argument
1835 for (dl = bundle->links; dl; dl = dl->next) in bundle_HighestState()
1843 bundle_Exception(struct bundle *bundle, int fd) in bundle_Exception() argument
1847 for (dl = bundle->links; dl; dl = dl->next) in bundle_Exception()
1857 bundle_AdjustFilters(struct bundle *bundle, struct ncpaddr *local, in bundle_AdjustFilters() argument
1860 filter_AdjustAddr(&bundle->filter.in, local, remote, NULL); in bundle_AdjustFilters()
1861 filter_AdjustAddr(&bundle->filter.out, local, remote, NULL); in bundle_AdjustFilters()
1862 filter_AdjustAddr(&bundle->filter.dial, local, remote, NULL); in bundle_AdjustFilters()
1863 filter_AdjustAddr(&bundle->filter.alive, local, remote, NULL); in bundle_AdjustFilters()
1867 bundle_AdjustDNS(struct bundle *bundle) in bundle_AdjustDNS() argument
1869 struct in_addr *dns = bundle->ncp.ipcp.ns.dns; in bundle_AdjustDNS()
1871 filter_AdjustAddr(&bundle->filter.in, NULL, NULL, dns); in bundle_AdjustDNS()
1872 filter_AdjustAddr(&bundle->filter.out, NULL, NULL, dns); in bundle_AdjustDNS()
1873 filter_AdjustAddr(&bundle->filter.dial, NULL, NULL, dns); in bundle_AdjustDNS()
1874 filter_AdjustAddr(&bundle->filter.alive, NULL, NULL, dns); in bundle_AdjustDNS()
1878 bundle_CalculateBandwidth(struct bundle *bundle) in bundle_CalculateBandwidth() argument
1883 bundle->bandwidth = 0; in bundle_CalculateBandwidth()
1884 bundle->iface->mtu = 0; in bundle_CalculateBandwidth()
1887 for (dl = bundle->links; dl; dl = dl->next) { in bundle_CalculateBandwidth()
1897 bundle->bandwidth += sp; in bundle_CalculateBandwidth()
1898 if (!bundle->ncp.mp.active) { in bundle_CalculateBandwidth()
1899 bundle->iface->mtu = dl->physical->link.lcp.his_mru; in bundle_CalculateBandwidth()
1905 if (bundle->bandwidth == 0) in bundle_CalculateBandwidth()
1906 bundle->bandwidth = 115200; /* Shrug */ in bundle_CalculateBandwidth()
1908 if (bundle->ncp.mp.active) { in bundle_CalculateBandwidth()
1909 bundle->iface->mtu = bundle->ncp.mp.peer_mrru; in bundle_CalculateBandwidth()
1910 overhead = ccp_MTUOverhead(&bundle->ncp.mp.link.ccp); in bundle_CalculateBandwidth()
1913 } else if (!bundle->iface->mtu) in bundle_CalculateBandwidth()
1914 bundle->iface->mtu = DEF_MRU; in bundle_CalculateBandwidth()
1917 if (bundle->radius.valid && bundle->radius.mtu && in bundle_CalculateBandwidth()
1918 bundle->radius.mtu < bundle->iface->mtu) { in bundle_CalculateBandwidth()
1920 bundle->radius.mtu); in bundle_CalculateBandwidth()
1921 bundle->iface->mtu = bundle->radius.mtu; in bundle_CalculateBandwidth()
1927 bundle->iface->mtu, bundle->iface->mtu - maxoverhead); in bundle_CalculateBandwidth()
1928 bundle->iface->mtu -= maxoverhead; in bundle_CalculateBandwidth()
1931 tun_configure(bundle); in bundle_CalculateBandwidth()
1933 route_UpdateMTU(bundle); in bundle_CalculateBandwidth()
1937 bundle_AutoAdjust(struct bundle *bundle, int percent, int what) in bundle_AutoAdjust() argument
1942 for (dl = bundle->links; dl; dl = dl->next) in bundle_AutoAdjust()
1968 mp_CheckAutoloadTimer(&bundle->ncp.mp); in bundle_AutoAdjust()
1973 mp_CheckAutoloadTimer(&bundle->ncp.mp); in bundle_AutoAdjust()
1979 bundle_WantAutoloadTimer(struct bundle *bundle) in bundle_WantAutoloadTimer() argument
1984 if (bundle->phase == PHASE_NETWORK) { in bundle_WantAutoloadTimer()
1985 for (autolink = opened = 0, dl = bundle->links; dl; dl = dl->next) in bundle_WantAutoloadTimer()
2002 bundle_ChangedPID(struct bundle *bundle) in bundle_ChangedPID() argument
2005 ioctl(bundle->dev.fd, TUNSIFPID, 0); in bundle_ChangedPID()
2010 bundle_Uptime(struct bundle *bundle) in bundle_Uptime() argument
2012 if (bundle->upat) in bundle_Uptime()
2013 return time(NULL) - bundle->upat; in bundle_Uptime()