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(pidfilename, sizeof pidfilename, "%stun%d.pid", _PATH_VARRUN, bundle->unit); in bundle_LockTun()
686 bundle_UnlockTun(struct bundle *bundle) in bundle_UnlockTun() argument
690 snprintf(pidfilename, sizeof pidfilename, "%stun%d.pid", _PATH_VARRUN, bundle->unit); in bundle_UnlockTun()
694 struct bundle *
697 static struct bundle bundle; /* there can be only one */ in bundle_Create() local
707 if (bundle.iface != NULL) { /* Already allocated ! */ in bundle_Create()
724 for (bundle.unit = minunit; bundle.unit != maxunit; bundle.unit++) { in bundle_Create()
725 snprintf(bundle.dev.Name, sizeof bundle.dev.Name, "%s%d", in bundle_Create()
726 prefix, bundle.unit); in bundle_Create()
727 bundle.dev.fd = ID0open(bundle.dev.Name, O_RDWR); in bundle_Create()
728 if (bundle.dev.fd >= 0) in bundle_Create()
732 if (bundle.unit == minunit && !kldtried++) { in bundle_Create()
738 bundle.unit--; in bundle_Create()
750 if (bundle.dev.fd < 0) { in bundle_Create()
759 log_SetTun(bundle.unit); in bundle_Create()
761 ifname = strrchr(bundle.dev.Name, '/'); in bundle_Create()
763 ifname = bundle.dev.Name; in bundle_Create()
767 bundle.iface = iface_Create(ifname); in bundle_Create()
768 if (bundle.iface == NULL) { in bundle_Create()
769 close(bundle.dev.fd); in bundle_Create()
776 if (ID0ioctl(bundle.dev.fd, TUNSIFMODE, &iff) < 0) in bundle_Create()
784 if (ID0ioctl(bundle.dev.fd, TUNSLMODE, &iff) < 0) in bundle_Create()
792 if (ID0ioctl(bundle.dev.fd, TUNSIFHEAD, &iff) < 0) { in bundle_Create()
795 bundle.dev.header = 0; in bundle_Create()
797 bundle.dev.header = 1; in bundle_Create()
801 bundle.dev.header = 1; in bundle_Create()
808 bundle.dev.header = 0; in bundle_Create()
814 bundle.bandwidth = 0; in bundle_Create()
815 bundle.routing_seq = 0; in bundle_Create()
816 bundle.phase = PHASE_DEAD; in bundle_Create()
817 bundle.CleaningUp = 0; in bundle_Create()
818 bundle.NatEnabled = 0; in bundle_Create()
820 bundle.fsm.LayerStart = bundle_LayerStart; in bundle_Create()
821 bundle.fsm.LayerUp = bundle_LayerUp; in bundle_Create()
822 bundle.fsm.LayerDown = bundle_LayerDown; in bundle_Create()
823 bundle.fsm.LayerFinish = bundle_LayerFinish; in bundle_Create()
824 bundle.fsm.object = &bundle; in bundle_Create()
826 bundle.cfg.idle.timeout = NCP_IDLE_TIMEOUT; in bundle_Create()
827 bundle.cfg.idle.min_timeout = 0; in bundle_Create()
828 *bundle.cfg.auth.name = '\0'; in bundle_Create()
829 *bundle.cfg.auth.key = '\0'; in bundle_Create()
830 bundle.cfg.opt = OPT_IDCHECK | OPT_LOOPBACK | OPT_SROUTES | OPT_TCPMSSFIXUP | in bundle_Create()
833 bundle.cfg.opt |= OPT_IPCP; in bundle_Create()
835 bundle.cfg.opt |= OPT_IPV6CP; in bundle_Create()
837 *bundle.cfg.label = '\0'; in bundle_Create()
838 bundle.cfg.ifqueue = DEF_IFQUEUE; in bundle_Create()
839 bundle.cfg.choked.timeout = CHOKED_TIMEOUT; in bundle_Create()
840 bundle.phys_type.all = type; in bundle_Create()
841 bundle.phys_type.open = 0; in bundle_Create()
842 bundle.upat = 0; in bundle_Create()
844 bundle.links = datalink_Create("deflink", &bundle, type); in bundle_Create()
845 if (bundle.links == NULL) { in bundle_Create()
847 iface_Destroy(bundle.iface); in bundle_Create()
848 bundle.iface = NULL; in bundle_Create()
849 close(bundle.dev.fd); in bundle_Create()
853 bundle.desc.type = BUNDLE_DESCRIPTOR; in bundle_Create()
854 bundle.desc.UpdateSet = bundle_UpdateSet; in bundle_Create()
855 bundle.desc.IsSet = bundle_IsSet; in bundle_Create()
856 bundle.desc.Read = bundle_DescriptorRead; in bundle_Create()
857 bundle.desc.Write = bundle_DescriptorWrite; in bundle_Create()
859 ncp_Init(&bundle.ncp, &bundle); in bundle_Create()
861 memset(&bundle.filter, '\0', sizeof bundle.filter); in bundle_Create()
862 bundle.filter.in.fragok = bundle.filter.in.logok = 1; in bundle_Create()
863 bundle.filter.in.name = "IN"; in bundle_Create()
864 bundle.filter.out.fragok = bundle.filter.out.logok = 1; in bundle_Create()
865 bundle.filter.out.name = "OUT"; in bundle_Create()
866 bundle.filter.dial.name = "DIAL"; in bundle_Create()
867 bundle.filter.dial.logok = 1; in bundle_Create()
868 bundle.filter.alive.name = "ALIVE"; in bundle_Create()
869 bundle.filter.alive.logok = 1; in bundle_Create()
873 bundle.filter.in.rule[i].f_action = A_NONE; in bundle_Create()
874 bundle.filter.out.rule[i].f_action = A_NONE; in bundle_Create()
875 bundle.filter.dial.rule[i].f_action = A_NONE; in bundle_Create()
876 bundle.filter.alive.rule[i].f_action = A_NONE; in bundle_Create()
879 memset(&bundle.idle.timer, '\0', sizeof bundle.idle.timer); in bundle_Create()
880 bundle.idle.done = 0; in bundle_Create()
881 bundle.notify.fd = -1; in bundle_Create()
882 memset(&bundle.choked.timer, '\0', sizeof bundle.choked.timer); in bundle_Create()
884 radius_Init(&bundle.radius); in bundle_Create()
888 iface_Clear(bundle.iface, &bundle.ncp, 0, IFACE_CLEAR_ALL); in bundle_Create()
890 bundle_LockTun(&bundle); in bundle_Create()
892 return &bundle; in bundle_Create()
896 bundle_DownInterface(struct bundle *bundle) in bundle_DownInterface() argument
898 route_IfDelete(bundle, 1); in bundle_DownInterface()
899 iface_ClearFlags(bundle->iface->name, IFF_UP); in bundle_DownInterface()
903 bundle_Destroy(struct bundle *bundle) in bundle_Destroy() argument
912 timer_Stop(&bundle->idle.timer); in bundle_Destroy()
913 timer_Stop(&bundle->choked.timer); in bundle_Destroy()
914 mp_Down(&bundle->ncp.mp); in bundle_Destroy()
915 iface_Clear(bundle->iface, &bundle->ncp, 0, IFACE_CLEAR_ALL); in bundle_Destroy()
916 bundle_DownInterface(bundle); in bundle_Destroy()
920 radius_Destroy(&bundle->radius); in bundle_Destroy()
924 dl = bundle->links; in bundle_Destroy()
928 ncp_Destroy(&bundle->ncp); in bundle_Destroy()
930 close(bundle->dev.fd); in bundle_Destroy()
931 bundle_UnlockTun(bundle); in bundle_Destroy()
934 bundle_Notify(bundle, EX_ERRDEAD); in bundle_Destroy()
936 iface_Destroy(bundle->iface); in bundle_Destroy()
937 bundle->iface = NULL; in bundle_Destroy()
941 bundle_LinkClosed(struct bundle *bundle, struct datalink *dl) in bundle_LinkClosed() argument
958 for (odl = bundle->links; odl; odl = odl->next) in bundle_LinkClosed()
964 bundle_DownInterface(bundle); in bundle_LinkClosed()
965 ncp2initial(&bundle->ncp); in bundle_LinkClosed()
966 mp_Down(&bundle->ncp.mp); in bundle_LinkClosed()
967 bundle_NewPhase(bundle, PHASE_DEAD); in bundle_LinkClosed()
969 if (bundle->radius.sessiontime) in bundle_LinkClosed()
970 bundle_StopSessionTimer(bundle); in bundle_LinkClosed()
972 bundle_StopIdleTimer(bundle); in bundle_LinkClosed()
977 bundle_Open(struct bundle *bundle, const char *name, int mask, int force) in bundle_Open() argument
984 for (dl = bundle->links; dl; dl = dl->next) in bundle_Open()
1002 bundle2datalink(struct bundle *bundle, const char *name) in bundle2datalink() argument
1007 for (dl = bundle->links; dl; dl = dl->next) in bundle2datalink()
1010 } else if (bundle->links && !bundle->links->next) in bundle2datalink()
1011 return bundle->links; in bundle2datalink()
1024 for (dl = arg->bundle->links; dl; dl = dl->next) { in bundle_ShowLinks()
1038 t = &arg->bundle->ncp.mp.link.stats.total; in bundle_ShowLinks()
1051 optval(struct bundle *bundle, int bit) in optval() argument
1053 return (bundle->cfg.opt & bit) ? "enabled" : "disabled"; in optval()
1061 prompt_Printf(arg->prompt, "Phase %s\n", bundle_PhaseName(arg->bundle)); in bundle_ShowStatus()
1062 prompt_Printf(arg->prompt, " Device: %s\n", arg->bundle->dev.Name); in bundle_ShowStatus()
1064 arg->bundle->iface->name, arg->bundle->bandwidth); in bundle_ShowStatus()
1066 if (arg->bundle->upat) { in bundle_ShowStatus()
1067 int secs = bundle_Uptime(arg->bundle); in bundle_ShowStatus()
1073 (unsigned long)ncp_QueueLen(&arg->bundle->ncp), in bundle_ShowStatus()
1074 arg->bundle->cfg.ifqueue); in bundle_ShowStatus()
1078 arg->bundle->cfg.label); in bundle_ShowStatus()
1080 arg->bundle->cfg.auth.name); in bundle_ShowStatus()
1094 arg->bundle->cfg.choked.timeout); in bundle_ShowStatus()
1097 radius_Show(&arg->bundle->radius, arg->prompt); in bundle_ShowStatus()
1101 if (arg->bundle->cfg.idle.timeout) { in bundle_ShowStatus()
1102 prompt_Printf(arg->prompt, "%us", arg->bundle->cfg.idle.timeout); in bundle_ShowStatus()
1103 if (arg->bundle->cfg.idle.min_timeout) in bundle_ShowStatus()
1105 arg->bundle->cfg.idle.min_timeout); in bundle_ShowStatus()
1106 remaining = bundle_RemainingIdleTime(arg->bundle); in bundle_ShowStatus()
1114 optval(arg->bundle, OPT_FILTERDECAP)); in bundle_ShowStatus()
1116 optval(arg->bundle, OPT_IDCHECK)); in bundle_ShowStatus()
1118 optval(arg->bundle, OPT_IFACEALIAS)); in bundle_ShowStatus()
1121 optval(arg->bundle, OPT_IPCP)); in bundle_ShowStatus()
1123 optval(arg->bundle, OPT_IPV6CP)); in bundle_ShowStatus()
1126 optval(arg->bundle, OPT_KEEPSESSION)); in bundle_ShowStatus()
1128 optval(arg->bundle, OPT_LOOPBACK)); in bundle_ShowStatus()
1130 optval(arg->bundle, OPT_PASSWDAUTH)); in bundle_ShowStatus()
1132 optval(arg->bundle, OPT_PROXY)); in bundle_ShowStatus()
1134 optval(arg->bundle, OPT_PROXYALL)); in bundle_ShowStatus()
1136 optval(arg->bundle, OPT_SROUTES)); in bundle_ShowStatus()
1138 optval(arg->bundle, OPT_TCPMSSFIXUP)); in bundle_ShowStatus()
1140 optval(arg->bundle, OPT_THROUGHPUT)); in bundle_ShowStatus()
1142 optval(arg->bundle, OPT_UTMP)); in bundle_ShowStatus()
1150 struct bundle *bundle = (struct bundle *)v; in bundle_IdleTimeout() local
1153 bundle_StopIdleTimer(bundle); in bundle_IdleTimeout()
1154 bundle_Close(bundle, NULL, CLOSE_STAYDOWN); in bundle_IdleTimeout()
1162 bundle_StartIdleTimer(struct bundle *bundle, unsigned secs) in bundle_StartIdleTimer() argument
1164 timer_Stop(&bundle->idle.timer); in bundle_StartIdleTimer()
1165 if ((bundle->phys_type.open & (PHYS_DEDICATED|PHYS_DDIAL)) != in bundle_StartIdleTimer()
1166 bundle->phys_type.open && bundle->cfg.idle.timeout) { in bundle_StartIdleTimer()
1170 secs = bundle->cfg.idle.timeout; in bundle_StartIdleTimer()
1173 if (bundle->cfg.idle.min_timeout > secs && bundle->upat) { in bundle_StartIdleTimer()
1174 unsigned up = now - bundle->upat; in bundle_StartIdleTimer()
1176 if (bundle->cfg.idle.min_timeout > up && in bundle_StartIdleTimer()
1177 bundle->cfg.idle.min_timeout - up > (long long)secs) in bundle_StartIdleTimer()
1179 secs = bundle->cfg.idle.min_timeout - up; in bundle_StartIdleTimer()
1181 bundle->idle.timer.func = bundle_IdleTimeout; in bundle_StartIdleTimer()
1182 bundle->idle.timer.name = "idle"; in bundle_StartIdleTimer()
1183 bundle->idle.timer.load = secs * SECTICKS; in bundle_StartIdleTimer()
1184 bundle->idle.timer.arg = bundle; in bundle_StartIdleTimer()
1185 timer_Start(&bundle->idle.timer); in bundle_StartIdleTimer()
1186 bundle->idle.done = now + secs; in bundle_StartIdleTimer()
1191 bundle_SetIdleTimer(struct bundle *bundle, unsigned timeout, in bundle_SetIdleTimer() argument
1194 bundle->cfg.idle.timeout = timeout; in bundle_SetIdleTimer()
1195 bundle->cfg.idle.min_timeout = min_timeout; in bundle_SetIdleTimer()
1196 if (ncp_LayersOpen(&bundle->ncp)) in bundle_SetIdleTimer()
1197 bundle_StartIdleTimer(bundle, 0); in bundle_SetIdleTimer()
1201 bundle_StopIdleTimer(struct bundle *bundle) in bundle_StopIdleTimer() argument
1203 timer_Stop(&bundle->idle.timer); in bundle_StopIdleTimer()
1204 bundle->idle.done = 0; in bundle_StopIdleTimer()
1208 bundle_RemainingIdleTime(struct bundle *bundle) in bundle_RemainingIdleTime() argument
1210 if (bundle->idle.done) in bundle_RemainingIdleTime()
1211 return bundle->idle.done - time(NULL); in bundle_RemainingIdleTime()
1220 struct bundle *bundle = (struct bundle *)v; in bundle_SessionTimeout() local
1223 bundle_StopSessionTimer(bundle); in bundle_SessionTimeout()
1224 bundle_Close(bundle, NULL, CLOSE_STAYDOWN); in bundle_SessionTimeout()
1228 bundle_StartSessionTimer(struct bundle *bundle, unsigned secs) in bundle_StartSessionTimer() argument
1230 timer_Stop(&bundle->session.timer); in bundle_StartSessionTimer()
1231 if ((bundle->phys_type.open & (PHYS_DEDICATED|PHYS_DDIAL)) != in bundle_StartSessionTimer()
1232 bundle->phys_type.open && bundle->radius.sessiontime) { in bundle_StartSessionTimer()
1236 secs = bundle->radius.sessiontime; in bundle_StartSessionTimer()
1238 bundle->session.timer.func = bundle_SessionTimeout; in bundle_StartSessionTimer()
1239 bundle->session.timer.name = "session"; in bundle_StartSessionTimer()
1240 bundle->session.timer.load = secs * SECTICKS; in bundle_StartSessionTimer()
1241 bundle->session.timer.arg = bundle; in bundle_StartSessionTimer()
1242 timer_Start(&bundle->session.timer); in bundle_StartSessionTimer()
1243 bundle->session.done = now + secs; in bundle_StartSessionTimer()
1248 bundle_StopSessionTimer(struct bundle *bundle) in bundle_StopSessionTimer() argument
1250 timer_Stop(&bundle->session.timer); in bundle_StopSessionTimer()
1251 bundle->session.done = 0; in bundle_StopSessionTimer()
1257 bundle_IsDead(struct bundle *bundle) in bundle_IsDead() argument
1259 return !bundle->links || (bundle->phase == PHASE_DEAD && bundle->CleaningUp); in bundle_IsDead()
1263 bundle_DatalinkLinkout(struct bundle *bundle, struct datalink *dl) in bundle_DatalinkLinkout() argument
1267 for (dlp = &bundle->links; *dlp; dlp = &(*dlp)->next) in bundle_DatalinkLinkout()
1271 bundle_LinksRemoved(bundle); in bundle_DatalinkLinkout()
1279 bundle_DatalinkLinkin(struct bundle *bundle, struct datalink *dl) in bundle_DatalinkLinkin() argument
1281 struct datalink **dlp = &bundle->links; in bundle_DatalinkLinkin()
1289 bundle_LinkAdded(bundle, dl); in bundle_DatalinkLinkin()
1290 mp_CheckAutoloadTimer(&bundle->ncp.mp); in bundle_DatalinkLinkin()
1294 bundle_CleanDatalinks(struct bundle *bundle) in bundle_CleanDatalinks() argument
1296 struct datalink **dlp = &bundle->links; in bundle_CleanDatalinks()
1309 bundle_LinksRemoved(bundle); in bundle_CleanDatalinks()
1313 bundle_DatalinkClone(struct bundle *bundle, struct datalink *dl, in bundle_DatalinkClone() argument
1316 if (bundle2datalink(bundle, name)) { in bundle_DatalinkClone()
1321 bundle_DatalinkLinkin(bundle, datalink_Clone(dl, name)); in bundle_DatalinkClone()
1326 bundle_DatalinkRemove(struct bundle *bundle, struct datalink *dl) in bundle_DatalinkRemove() argument
1328 dl = bundle_DatalinkLinkout(bundle, dl); in bundle_DatalinkRemove()
1334 bundle_SetLabel(struct bundle *bundle, const char *label) in bundle_SetLabel() argument
1337 strncpy(bundle->cfg.label, label, sizeof bundle->cfg.label - 1); in bundle_SetLabel()
1339 *bundle->cfg.label = '\0'; in bundle_SetLabel()
1343 bundle_GetLabel(struct bundle *bundle) in bundle_GetLabel() argument
1345 return *bundle->cfg.label ? bundle->cfg.label : NULL; in bundle_GetLabel()
1369 bundle_ReceiveDatalink(struct bundle *bundle, int s) in bundle_ReceiveDatalink() argument
1504 dl = iov2datalink(bundle, iov, &niov, NELEM(iov), fd[0], in bundle_ReceiveDatalink()
1516 bundle_DatalinkLinkin(bundle, dl); in bundle_ReceiveDatalink()
1518 bundle_CalculateBandwidth(dl->bundle); in bundle_ReceiveDatalink()
1553 bundle_LinkClosed(dl->bundle, dl); in bundle_SendDatalink()
1554 bundle_DatalinkLinkout(dl->bundle, dl); in bundle_SendDatalink()
1645 newsid = Enabled(dl->bundle, OPT_KEEPSESSION) || in bundle_SendDatalink()
1650 bundle_setsid(dl->bundle, got != -1); in bundle_SendDatalink()
1659 bundle_RenameDatalink(struct bundle *bundle, struct datalink *ndl, in bundle_RenameDatalink() argument
1667 for (dl = bundle->links; dl; dl = dl->next) in bundle_RenameDatalink()
1676 bundle_SetMode(struct bundle *bundle, struct datalink *dl, int mode) in bundle_SetMode() argument
1684 if (mode == PHYS_AUTO && !(bundle->phys_type.all & PHYS_AUTO)) in bundle_SetMode()
1686 if (bundle->ncp.ipcp.peer_ip.s_addr == INADDR_ANY) { in bundle_SetMode()
1695 if (mode == PHYS_AUTO && !(bundle->phys_type.all & PHYS_AUTO) && in bundle_SetMode()
1696 bundle->phase != PHASE_NETWORK) in bundle_SetMode()
1698 ipcp_InterfaceUp(&bundle->ncp.ipcp); in bundle_SetMode()
1701 bundle_LinksRemoved(bundle); in bundle_SetMode()
1707 bundle_setsid(struct bundle *bundle, int holdsession) in bundle_setsid() argument
1719 if (!holdsession && bundle_IsDead(bundle)) { in bundle_setsid()
1756 bundle_LockTun(bundle); /* update pid */ in bundle_setsid()
1760 bundle_ChangedPID(bundle); in bundle_setsid()
1769 for (dl = bundle->links; dl; dl = dl->next) in bundle_setsid()
1781 for (dl = bundle->links; dl; dl = dl->next) in bundle_setsid()
1824 bundle_HighestState(struct bundle *bundle) in bundle_HighestState() argument
1829 for (dl = bundle->links; dl; dl = dl->next) in bundle_HighestState()
1837 bundle_Exception(struct bundle *bundle, int fd) in bundle_Exception() argument
1841 for (dl = bundle->links; dl; dl = dl->next) in bundle_Exception()
1851 bundle_AdjustFilters(struct bundle *bundle, struct ncpaddr *local, in bundle_AdjustFilters() argument
1854 filter_AdjustAddr(&bundle->filter.in, local, remote, NULL); in bundle_AdjustFilters()
1855 filter_AdjustAddr(&bundle->filter.out, local, remote, NULL); in bundle_AdjustFilters()
1856 filter_AdjustAddr(&bundle->filter.dial, local, remote, NULL); in bundle_AdjustFilters()
1857 filter_AdjustAddr(&bundle->filter.alive, local, remote, NULL); in bundle_AdjustFilters()
1861 bundle_AdjustDNS(struct bundle *bundle) in bundle_AdjustDNS() argument
1863 struct in_addr *dns = bundle->ncp.ipcp.ns.dns; in bundle_AdjustDNS()
1865 filter_AdjustAddr(&bundle->filter.in, NULL, NULL, dns); in bundle_AdjustDNS()
1866 filter_AdjustAddr(&bundle->filter.out, NULL, NULL, dns); in bundle_AdjustDNS()
1867 filter_AdjustAddr(&bundle->filter.dial, NULL, NULL, dns); in bundle_AdjustDNS()
1868 filter_AdjustAddr(&bundle->filter.alive, NULL, NULL, dns); in bundle_AdjustDNS()
1872 bundle_CalculateBandwidth(struct bundle *bundle) in bundle_CalculateBandwidth() argument
1877 bundle->bandwidth = 0; in bundle_CalculateBandwidth()
1878 bundle->iface->mtu = 0; in bundle_CalculateBandwidth()
1881 for (dl = bundle->links; dl; dl = dl->next) { in bundle_CalculateBandwidth()
1891 bundle->bandwidth += sp; in bundle_CalculateBandwidth()
1892 if (!bundle->ncp.mp.active) { in bundle_CalculateBandwidth()
1893 bundle->iface->mtu = dl->physical->link.lcp.his_mru; in bundle_CalculateBandwidth()
1899 if (bundle->bandwidth == 0) in bundle_CalculateBandwidth()
1900 bundle->bandwidth = 115200; /* Shrug */ in bundle_CalculateBandwidth()
1902 if (bundle->ncp.mp.active) { in bundle_CalculateBandwidth()
1903 bundle->iface->mtu = bundle->ncp.mp.peer_mrru; in bundle_CalculateBandwidth()
1904 overhead = ccp_MTUOverhead(&bundle->ncp.mp.link.ccp); in bundle_CalculateBandwidth()
1907 } else if (!bundle->iface->mtu) in bundle_CalculateBandwidth()
1908 bundle->iface->mtu = DEF_MRU; in bundle_CalculateBandwidth()
1911 if (bundle->radius.valid && bundle->radius.mtu && in bundle_CalculateBandwidth()
1912 bundle->radius.mtu < bundle->iface->mtu) { in bundle_CalculateBandwidth()
1914 bundle->radius.mtu); in bundle_CalculateBandwidth()
1915 bundle->iface->mtu = bundle->radius.mtu; in bundle_CalculateBandwidth()
1921 bundle->iface->mtu, bundle->iface->mtu - maxoverhead); in bundle_CalculateBandwidth()
1922 bundle->iface->mtu -= maxoverhead; in bundle_CalculateBandwidth()
1925 tun_configure(bundle); in bundle_CalculateBandwidth()
1927 route_UpdateMTU(bundle); in bundle_CalculateBandwidth()
1931 bundle_AutoAdjust(struct bundle *bundle, int percent, int what) in bundle_AutoAdjust() argument
1936 for (dl = bundle->links; dl; dl = dl->next) in bundle_AutoAdjust()
1962 mp_CheckAutoloadTimer(&bundle->ncp.mp); in bundle_AutoAdjust()
1967 mp_CheckAutoloadTimer(&bundle->ncp.mp); in bundle_AutoAdjust()
1973 bundle_WantAutoloadTimer(struct bundle *bundle) in bundle_WantAutoloadTimer() argument
1978 if (bundle->phase == PHASE_NETWORK) { in bundle_WantAutoloadTimer()
1979 for (autolink = opened = 0, dl = bundle->links; dl; dl = dl->next) in bundle_WantAutoloadTimer()
1996 bundle_ChangedPID(struct bundle *bundle) in bundle_ChangedPID() argument
1999 ioctl(bundle->dev.fd, TUNSIFPID, 0); in bundle_ChangedPID()
2004 bundle_Uptime(struct bundle *bundle) in bundle_Uptime() argument
2006 if (bundle->upat) in bundle_Uptime()
2007 return time(NULL) - bundle->upat; in bundle_Uptime()