Lines Matching refs:bundle

110 static int bundle_RemainingIdleTime(struct bundle *);
117 bundle_PhaseName(struct bundle *bundle) in bundle_PhaseName() argument
119 return bundle->phase <= PHASE_TERMINATE ? in bundle_PhaseName()
120 PhaseNames[bundle->phase] : "unknown"; in bundle_PhaseName()
124 bundle_NewPhase(struct bundle *bundle, u_int new) in bundle_NewPhase() argument
126 if (new == bundle->phase) in bundle_NewPhase()
134 bundle->phase = new; in bundle_NewPhase()
142 bundle->phase = new; in bundle_NewPhase()
146 bundle->phase = new; in bundle_NewPhase()
151 if (ncp_fsmStart(&bundle->ncp, bundle)) { in bundle_NewPhase()
152 bundle->phase = new; in bundle_NewPhase()
156 bundle_Close(bundle, NULL, CLOSE_STAYDOWN); in bundle_NewPhase()
161 bundle->phase = new; in bundle_NewPhase()
162 mp_Down(&bundle->ncp.mp); in bundle_NewPhase()
176 bundle_Notify(struct bundle *bundle, char c) in bundle_Notify() argument
178 if (bundle->notify.fd != -1) { in bundle_Notify()
181 ret = write(bundle->notify.fd, &c, 1); in bundle_Notify()
188 close(bundle->notify.fd); in bundle_Notify()
189 bundle->notify.fd = -1; in bundle_Notify()
200 struct bundle *bundle = (struct bundle *)v; in bundle_ClearQueues() local
204 timer_Stop(&bundle->choked.timer); in bundle_ClearQueues()
221 ncp_DeleteQueues(&bundle->ncp); in bundle_ClearQueues()
222 for (dl = bundle->links; dl; dl = dl->next) in bundle_ClearQueues()
227 bundle_LinkAdded(struct bundle *bundle, struct datalink *dl) in bundle_LinkAdded() argument
229 bundle->phys_type.all |= dl->physical->type; in bundle_LinkAdded()
231 bundle->phys_type.open |= dl->physical->type; in bundle_LinkAdded()
234 if ((bundle->phys_type.open & (PHYS_DEDICATED|PHYS_DDIAL)) in bundle_LinkAdded()
235 != bundle->phys_type.open && bundle->session.timer.state == TIMER_STOPPED) in bundle_LinkAdded()
236 if (bundle->radius.sessiontime) in bundle_LinkAdded()
237 bundle_StartSessionTimer(bundle, 0); in bundle_LinkAdded()
240 if ((bundle->phys_type.open & (PHYS_DEDICATED|PHYS_DDIAL)) in bundle_LinkAdded()
241 != bundle->phys_type.open && bundle->idle.timer.state == TIMER_STOPPED) in bundle_LinkAdded()
243 bundle_StartIdleTimer(bundle, 0); in bundle_LinkAdded()
247 bundle_LinksRemoved(struct bundle *bundle) in bundle_LinksRemoved() argument
251 bundle->phys_type.all = bundle->phys_type.open = 0; in bundle_LinksRemoved()
252 for (dl = bundle->links; dl; dl = dl->next) in bundle_LinksRemoved()
253 bundle_LinkAdded(bundle, dl); in bundle_LinksRemoved()
255 bundle_CalculateBandwidth(bundle); in bundle_LinksRemoved()
256 mp_CheckAutoloadTimer(&bundle->ncp.mp); in bundle_LinksRemoved()
258 if ((bundle->phys_type.open & (PHYS_DEDICATED|PHYS_DDIAL)) in bundle_LinksRemoved()
259 == bundle->phys_type.open) { in bundle_LinksRemoved()
261 if (bundle->radius.sessiontime) in bundle_LinksRemoved()
262 bundle_StopSessionTimer(bundle); in bundle_LinksRemoved()
264 bundle_StopIdleTimer(bundle); in bundle_LinksRemoved()
281 struct bundle *bundle = (struct bundle *)v; in bundle_LayerUp() local
286 bundle_LinkAdded(bundle, p->dl); in bundle_LayerUp()
287 mp_CheckAutoloadTimer(&bundle->ncp.mp); in bundle_LayerUp()
289 if (ncp_LayersOpen(&fp->bundle->ncp) == 1) { in bundle_LayerUp()
290 bundle_CalculateBandwidth(fp->bundle); in bundle_LayerUp()
291 time(&bundle->upat); in bundle_LayerUp()
293 if (bundle->radius.sessiontime) in bundle_LayerUp()
294 bundle_StartSessionTimer(bundle, 0); in bundle_LayerUp()
296 bundle_StartIdleTimer(bundle, 0); in bundle_LayerUp()
297 mp_CheckAutoloadTimer(&fp->bundle->ncp.mp); in bundle_LayerUp()
299 bundle_Notify(bundle, EX_NORMAL); in bundle_LayerUp()
301 bundle_CalculateBandwidth(fp->bundle); /* Against ccp_MTUOverhead */ in bundle_LayerUp()
318 struct bundle *bundle = (struct bundle *)v; in bundle_LayerDown() local
321 if (ncp_LayersOpen(&fp->bundle->ncp) == 0) { in bundle_LayerDown()
323 if (bundle->radius.sessiontime) in bundle_LayerDown()
324 bundle_StopSessionTimer(bundle); in bundle_LayerDown()
326 bundle_StopIdleTimer(bundle); in bundle_LayerDown()
327 bundle->upat = 0; in bundle_LayerDown()
328 mp_StopAutoloadTimer(&bundle->ncp.mp); in bundle_LayerDown()
335 bundle_LinksRemoved(bundle); /* adjust timers & phys_type values */ in bundle_LayerDown()
339 for (dl = bundle->links; dl; dl = dl->next) { in bundle_LayerDown()
346 if (bundle->ncp.mp.active) { in bundle_LayerDown()
347 bundle_CalculateBandwidth(bundle); in bundle_LayerDown()
350 mp_LinkLost(&bundle->ncp.mp, lost); in bundle_LayerDown()
358 ncp2initial(&bundle->ncp); in bundle_LayerDown()
359 mp_Down(&bundle->ncp.mp); in bundle_LayerDown()
373 struct bundle *bundle = (struct bundle *)v; in bundle_LayerFinish() local
376 if (isncp(fp->proto) && !ncp_LayersUnfinished(&bundle->ncp)) { in bundle_LayerFinish()
377 if (bundle_Phase(bundle) != PHASE_DEAD) in bundle_LayerFinish()
378 bundle_NewPhase(bundle, PHASE_TERMINATE); in bundle_LayerFinish()
379 for (dl = bundle->links; dl; dl = dl->next) in bundle_LayerFinish()
383 mp_Down(&bundle->ncp.mp); in bundle_LayerFinish()
388 bundle_Close(struct bundle *bundle, const char *name, int how) in bundle_Close() argument
403 for (dl = bundle->links; dl; dl = dl->next) { in bundle_Close()
426 if (bundle->radius.sessiontime) in bundle_Close()
427 bundle_StopSessionTimer(bundle); in bundle_Close()
429 bundle_StopIdleTimer(bundle); in bundle_Close()
430 if (ncp_LayersUnfinished(&bundle->ncp)) in bundle_Close()
431 ncp_Close(&bundle->ncp); in bundle_Close()
433 ncp2initial(&bundle->ncp); in bundle_Close()
434 mp_Down(&bundle->ncp.mp); in bundle_Close()
435 for (dl = bundle->links; dl; dl = dl->next) in bundle_Close()
444 bundle_Down(struct bundle *bundle, int how) in bundle_Down() argument
448 for (dl = bundle->links; dl; dl = dl->next) in bundle_Down()
455 struct bundle *bundle = descriptor2bundle(d); in bundle_UpdateSet() local
464 for (nlinks = 0, dl = bundle->links; dl; dl = dl->next) in bundle_UpdateSet()
468 queued = r ? ncp_FillPhysicalQueues(&bundle->ncp, bundle) : in bundle_UpdateSet()
469 ncp_QueueLen(&bundle->ncp); in bundle_UpdateSet()
471 if (r && (bundle->phase == PHASE_NETWORK || in bundle_UpdateSet()
472 bundle->phys_type.all & PHYS_AUTO)) { in bundle_UpdateSet()
474 ifqueue = nlinks > bundle->cfg.ifqueue ? nlinks : bundle->cfg.ifqueue; in bundle_UpdateSet()
477 if (bundle->choked.timer.state == TIMER_RUNNING) in bundle_UpdateSet()
478 timer_Stop(&bundle->choked.timer); /* Not needed any more */ in bundle_UpdateSet()
479 FD_SET(bundle->dev.fd, r); in bundle_UpdateSet()
480 if (*n < bundle->dev.fd + 1) in bundle_UpdateSet()
481 *n = bundle->dev.fd + 1; in bundle_UpdateSet()
482 log_Printf(LogTIMER, "%s: fdset(r) %d\n", TUN_NAME, bundle->dev.fd); in bundle_UpdateSet()
484 } else if (bundle->choked.timer.state == TIMER_STOPPED) { in bundle_UpdateSet()
485 bundle->choked.timer.func = bundle_ClearQueues; in bundle_UpdateSet()
486 bundle->choked.timer.name = "output choke"; in bundle_UpdateSet()
487 bundle->choked.timer.load = bundle->cfg.choked.timeout * SECTICKS; in bundle_UpdateSet()
488 bundle->choked.timer.arg = bundle; in bundle_UpdateSet()
489 timer_Start(&bundle->choked.timer); in bundle_UpdateSet()
495 result += descriptor_UpdateSet(&bundle->radius.desc, r, w, e, n); in bundle_UpdateSet()
499 for (dl = bundle->links; dl; dl = dl->next) in bundle_UpdateSet()
507 result += descriptor_UpdateSet(&bundle->ncp.mp.server.desc, r, w, e, n); in bundle_UpdateSet()
515 struct bundle *bundle = descriptor2bundle(d); in bundle_IsSet() local
518 for (dl = bundle->links; dl; dl = dl->next) in bundle_IsSet()
523 if (descriptor_IsSet(&bundle->radius.desc, fdset)) in bundle_IsSet()
527 if (descriptor_IsSet(&bundle->ncp.mp.server.desc, fdset)) in bundle_IsSet()
530 return FD_ISSET(bundle->dev.fd, fdset); in bundle_IsSet()
534 bundle_DescriptorRead(struct fdescriptor *d __unused, struct bundle *bundle, in bundle_DescriptorRead() argument
541 if (descriptor_IsSet(&bundle->ncp.mp.server.desc, fdset)) in bundle_DescriptorRead()
542 descriptor_Read(&bundle->ncp.mp.server.desc, bundle, fdset); in bundle_DescriptorRead()
544 for (dl = bundle->links; dl; dl = dl->next) in bundle_DescriptorRead()
546 descriptor_Read(&dl->desc, bundle, fdset); in bundle_DescriptorRead()
549 if (descriptor_IsSet(&bundle->radius.desc, fdset)) in bundle_DescriptorRead()
550 descriptor_Read(&bundle->radius.desc, bundle, fdset); in bundle_DescriptorRead()
553 if (FD_ISSET(bundle->dev.fd, fdset)) { in bundle_DescriptorRead()
559 if (bundle->dev.header) { in bundle_DescriptorRead()
569 n = read(bundle->dev.fd, data, sz); in bundle_DescriptorRead()
571 log_Printf(LogWARN, "%s: read: %s\n", bundle->dev.Name, strerror(errno)); in bundle_DescriptorRead()
575 if (bundle->dev.header) { in bundle_DescriptorRead()
579 bundle->dev.Name, n); in bundle_DescriptorRead()
594 bundle->ncp.ipcp.my_ip.s_addr) { in bundle_DescriptorRead()
596 if (Enabled(bundle, OPT_LOOPBACK)) { in bundle_DescriptorRead()
597 pri = PacketCheck(bundle, af, tun.data, n, &bundle->filter.in, in bundle_DescriptorRead()
601 write(bundle->dev.fd, data, n); in bundle_DescriptorRead()
614 if (bundle_Phase(bundle) == PHASE_DEAD) { in bundle_DescriptorRead()
619 pri = PacketCheck(bundle, af, tun.data, n, &bundle->filter.dial, in bundle_DescriptorRead()
622 bundle_Open(bundle, NULL, PHYS_AUTO, 0); in bundle_DescriptorRead()
635 pri = PacketCheck(bundle, af, tun.data, n, &bundle->filter.out, in bundle_DescriptorRead()
640 ncp_Enqueue(&bundle->ncp, af, pri, (char *)&tun, n + sizeof tun.header); in bundle_DescriptorRead()
646 bundle_DescriptorWrite(struct fdescriptor *d __unused, struct bundle *bundle, in bundle_DescriptorWrite() argument
653 if (descriptor_IsSet(&bundle->ncp.mp.server.desc, fdset)) in bundle_DescriptorWrite()
654 if (descriptor_Write(&bundle->ncp.mp.server.desc, bundle, fdset) == 1) in bundle_DescriptorWrite()
657 for (dl = bundle->links; dl; dl = dl->next) in bundle_DescriptorWrite()
659 switch (descriptor_Write(&dl->desc, bundle, fdset)) { in bundle_DescriptorWrite()
671 bundle_LockTun(struct bundle *bundle) in bundle_LockTun() argument
676 snprintf(pidfile, sizeof pidfile, "%stun%d.pid", _PATH_VARRUN, bundle->unit); in bundle_LockTun()
687 bundle_UnlockTun(struct bundle *bundle) in bundle_UnlockTun() argument
691 snprintf(pidfile, sizeof pidfile, "%stun%d.pid", _PATH_VARRUN, bundle->unit); in bundle_UnlockTun()
695 struct bundle *
698 static struct bundle bundle; /* there can be only one */ in bundle_Create() local
708 if (bundle.iface != NULL) { /* Already allocated ! */ in bundle_Create()
725 for (bundle.unit = minunit; bundle.unit != maxunit; bundle.unit++) { in bundle_Create()
726 snprintf(bundle.dev.Name, sizeof bundle.dev.Name, "%s%d", in bundle_Create()
727 prefix, bundle.unit); in bundle_Create()
728 bundle.dev.fd = ID0open(bundle.dev.Name, O_RDWR); in bundle_Create()
729 if (bundle.dev.fd >= 0) in bundle_Create()
733 if (bundle.unit == minunit && !kldtried++) { in bundle_Create()
739 bundle.unit--; in bundle_Create()
751 if (bundle.dev.fd < 0) { in bundle_Create()
760 log_SetTun(bundle.unit, NULL); in bundle_Create()
762 ifname = strrchr(bundle.dev.Name, '/'); in bundle_Create()
764 ifname = bundle.dev.Name; in bundle_Create()
768 bundle.iface = iface_Create(ifname); in bundle_Create()
769 if (bundle.iface == NULL) { in bundle_Create()
770 close(bundle.dev.fd); in bundle_Create()
777 if (ID0ioctl(bundle.dev.fd, TUNSIFMODE, &iff) < 0) in bundle_Create()
785 if (ID0ioctl(bundle.dev.fd, TUNSLMODE, &iff) < 0) in bundle_Create()
793 if (ID0ioctl(bundle.dev.fd, TUNSIFHEAD, &iff) < 0) { in bundle_Create()
796 bundle.dev.header = 0; in bundle_Create()
798 bundle.dev.header = 1; in bundle_Create()
802 bundle.dev.header = 1; in bundle_Create()
809 bundle.dev.header = 0; in bundle_Create()
815 bundle.bandwidth = 0; in bundle_Create()
816 bundle.routing_seq = 0; in bundle_Create()
817 bundle.phase = PHASE_DEAD; in bundle_Create()
818 bundle.CleaningUp = 0; in bundle_Create()
819 bundle.NatEnabled = 0; in bundle_Create()
821 bundle.fsm.LayerStart = bundle_LayerStart; in bundle_Create()
822 bundle.fsm.LayerUp = bundle_LayerUp; in bundle_Create()
823 bundle.fsm.LayerDown = bundle_LayerDown; in bundle_Create()
824 bundle.fsm.LayerFinish = bundle_LayerFinish; in bundle_Create()
825 bundle.fsm.object = &bundle; in bundle_Create()
827 bundle.cfg.idle.timeout = NCP_IDLE_TIMEOUT; in bundle_Create()
828 bundle.cfg.idle.min_timeout = 0; in bundle_Create()
829 *bundle.cfg.auth.name = '\0'; in bundle_Create()
830 *bundle.cfg.auth.key = '\0'; in bundle_Create()
831 bundle.cfg.optmask = (1ull << OPT_IDCHECK) | (1ull << OPT_LOOPBACK) | in bundle_Create()
837 opt_enable(&bundle, OPT_IPCP); in bundle_Create()
839 opt_enable(&bundle, OPT_IPV6CP); in bundle_Create()
841 *bundle.cfg.label = '\0'; in bundle_Create()
842 bundle.cfg.ifqueue = DEF_IFQUEUE; in bundle_Create()
843 bundle.cfg.choked.timeout = CHOKED_TIMEOUT; in bundle_Create()
844 bundle.phys_type.all = type; in bundle_Create()
845 bundle.phys_type.open = 0; in bundle_Create()
846 bundle.upat = 0; in bundle_Create()
848 bundle.links = datalink_Create("deflink", &bundle, type); in bundle_Create()
849 if (bundle.links == NULL) { in bundle_Create()
851 iface_Free(bundle.iface); in bundle_Create()
852 bundle.iface = NULL; in bundle_Create()
853 close(bundle.dev.fd); in bundle_Create()
857 bundle.desc.type = BUNDLE_DESCRIPTOR; in bundle_Create()
858 bundle.desc.UpdateSet = bundle_UpdateSet; in bundle_Create()
859 bundle.desc.IsSet = bundle_IsSet; in bundle_Create()
860 bundle.desc.Read = bundle_DescriptorRead; in bundle_Create()
861 bundle.desc.Write = bundle_DescriptorWrite; in bundle_Create()
863 ncp_Init(&bundle.ncp, &bundle); in bundle_Create()
865 memset(&bundle.filter, '\0', sizeof bundle.filter); in bundle_Create()
866 bundle.filter.in.fragok = bundle.filter.in.logok = 1; in bundle_Create()
867 bundle.filter.in.name = "IN"; in bundle_Create()
868 bundle.filter.out.fragok = bundle.filter.out.logok = 1; in bundle_Create()
869 bundle.filter.out.name = "OUT"; in bundle_Create()
870 bundle.filter.dial.name = "DIAL"; in bundle_Create()
871 bundle.filter.dial.logok = 1; in bundle_Create()
872 bundle.filter.alive.name = "ALIVE"; in bundle_Create()
873 bundle.filter.alive.logok = 1; in bundle_Create()
877 bundle.filter.in.rule[i].f_action = A_NONE; in bundle_Create()
878 bundle.filter.out.rule[i].f_action = A_NONE; in bundle_Create()
879 bundle.filter.dial.rule[i].f_action = A_NONE; in bundle_Create()
880 bundle.filter.alive.rule[i].f_action = A_NONE; in bundle_Create()
883 memset(&bundle.idle.timer, '\0', sizeof bundle.idle.timer); in bundle_Create()
884 bundle.idle.done = 0; in bundle_Create()
885 bundle.notify.fd = -1; in bundle_Create()
886 memset(&bundle.choked.timer, '\0', sizeof bundle.choked.timer); in bundle_Create()
888 radius_Init(&bundle.radius); in bundle_Create()
892 iface_Clear(bundle.iface, &bundle.ncp, 0, IFACE_CLEAR_ALL); in bundle_Create()
894 bundle_LockTun(&bundle); in bundle_Create()
896 return &bundle; in bundle_Create()
900 bundle_DownInterface(struct bundle *bundle) in bundle_DownInterface() argument
902 route_IfDelete(bundle, 1); in bundle_DownInterface()
903 iface_ClearFlags(bundle->iface->name, IFF_UP); in bundle_DownInterface()
907 bundle_Destroy(struct bundle *bundle) in bundle_Destroy() argument
916 timer_Stop(&bundle->idle.timer); in bundle_Destroy()
917 timer_Stop(&bundle->choked.timer); in bundle_Destroy()
918 mp_Down(&bundle->ncp.mp); in bundle_Destroy()
919 iface_Clear(bundle->iface, &bundle->ncp, 0, IFACE_CLEAR_ALL); in bundle_Destroy()
920 bundle_DownInterface(bundle); in bundle_Destroy()
924 radius_Destroy(&bundle->radius); in bundle_Destroy()
928 dl = bundle->links; in bundle_Destroy()
932 ncp_Destroy(&bundle->ncp); in bundle_Destroy()
934 close(bundle->dev.fd); in bundle_Destroy()
935 bundle_UnlockTun(bundle); in bundle_Destroy()
938 bundle_Notify(bundle, EX_ERRDEAD); in bundle_Destroy()
940 iface_Destroy(bundle->iface); in bundle_Destroy()
941 bundle->iface = NULL; in bundle_Destroy()
945 bundle_LinkClosed(struct bundle *bundle, struct datalink *dl) in bundle_LinkClosed() argument
962 for (odl = bundle->links; odl; odl = odl->next) in bundle_LinkClosed()
968 bundle_DownInterface(bundle); in bundle_LinkClosed()
969 ncp2initial(&bundle->ncp); in bundle_LinkClosed()
970 mp_Down(&bundle->ncp.mp); in bundle_LinkClosed()
971 bundle_NewPhase(bundle, PHASE_DEAD); in bundle_LinkClosed()
973 if (bundle->radius.sessiontime) in bundle_LinkClosed()
974 bundle_StopSessionTimer(bundle); in bundle_LinkClosed()
976 bundle_StopIdleTimer(bundle); in bundle_LinkClosed()
981 bundle_Open(struct bundle *bundle, const char *name, int mask, int force) in bundle_Open() argument
988 for (dl = bundle->links; dl; dl = dl->next) in bundle_Open()
1006 bundle2datalink(struct bundle *bundle, const char *name) in bundle2datalink() argument
1011 for (dl = bundle->links; dl; dl = dl->next) in bundle2datalink()
1014 } else if (bundle->links && !bundle->links->next) in bundle2datalink()
1015 return bundle->links; in bundle2datalink()
1028 for (dl = arg->bundle->links; dl; dl = dl->next) { in bundle_ShowLinks()
1042 t = &arg->bundle->ncp.mp.link.stats.total; in bundle_ShowLinks()
1055 optval(struct bundle *bundle, int opt) in optval() argument
1057 return Enabled(bundle, opt) ? "enabled" : "disabled"; in optval()
1065 prompt_Printf(arg->prompt, "Phase %s\n", bundle_PhaseName(arg->bundle)); in bundle_ShowStatus()
1066 prompt_Printf(arg->prompt, " Device: %s\n", arg->bundle->dev.Name); in bundle_ShowStatus()
1068 arg->bundle->iface->name, arg->bundle->bandwidth); in bundle_ShowStatus()
1070 if (arg->bundle->upat) { in bundle_ShowStatus()
1071 int secs = bundle_Uptime(arg->bundle); in bundle_ShowStatus()
1077 (unsigned long)ncp_QueueLen(&arg->bundle->ncp), in bundle_ShowStatus()
1078 arg->bundle->cfg.ifqueue); in bundle_ShowStatus()
1082 arg->bundle->cfg.label); in bundle_ShowStatus()
1084 arg->bundle->cfg.auth.name); in bundle_ShowStatus()
1098 arg->bundle->cfg.choked.timeout); in bundle_ShowStatus()
1101 radius_Show(&arg->bundle->radius, arg->prompt); in bundle_ShowStatus()
1105 if (arg->bundle->cfg.idle.timeout) { in bundle_ShowStatus()
1106 prompt_Printf(arg->prompt, "%us", arg->bundle->cfg.idle.timeout); in bundle_ShowStatus()
1107 if (arg->bundle->cfg.idle.min_timeout) in bundle_ShowStatus()
1109 arg->bundle->cfg.idle.min_timeout); in bundle_ShowStatus()
1110 remaining = bundle_RemainingIdleTime(arg->bundle); in bundle_ShowStatus()
1118 optval(arg->bundle, OPT_FILTERDECAP)); in bundle_ShowStatus()
1120 optval(arg->bundle, OPT_IDCHECK)); in bundle_ShowStatus()
1122 optval(arg->bundle, OPT_IFACEALIAS)); in bundle_ShowStatus()
1125 optval(arg->bundle, OPT_IPCP)); in bundle_ShowStatus()
1127 optval(arg->bundle, OPT_IPV6CP)); in bundle_ShowStatus()
1130 optval(arg->bundle, OPT_KEEPSESSION)); in bundle_ShowStatus()
1132 optval(arg->bundle, OPT_LOOPBACK)); in bundle_ShowStatus()
1134 optval(arg->bundle, OPT_PASSWDAUTH)); in bundle_ShowStatus()
1136 optval(arg->bundle, OPT_PROXY)); in bundle_ShowStatus()
1138 optval(arg->bundle, OPT_PROXYALL)); in bundle_ShowStatus()
1140 optval(arg->bundle, OPT_SROUTES)); in bundle_ShowStatus()
1142 optval(arg->bundle, OPT_TCPMSSFIXUP)); in bundle_ShowStatus()
1144 optval(arg->bundle, OPT_THROUGHPUT)); in bundle_ShowStatus()
1146 optval(arg->bundle, OPT_UTMP)); in bundle_ShowStatus()
1148 optval(arg->bundle, OPT_NAS_IP_ADDRESS)); in bundle_ShowStatus()
1150 optval(arg->bundle, OPT_NAS_IDENTIFIER)); in bundle_ShowStatus()
1158 struct bundle *bundle = (struct bundle *)v; in bundle_IdleTimeout() local
1161 bundle_StopIdleTimer(bundle); in bundle_IdleTimeout()
1162 bundle_Close(bundle, NULL, CLOSE_STAYDOWN); in bundle_IdleTimeout()
1170 bundle_StartIdleTimer(struct bundle *bundle, unsigned secs) in bundle_StartIdleTimer() argument
1172 timer_Stop(&bundle->idle.timer); in bundle_StartIdleTimer()
1173 if ((bundle->phys_type.open & (PHYS_DEDICATED|PHYS_DDIAL)) != in bundle_StartIdleTimer()
1174 bundle->phys_type.open && bundle->cfg.idle.timeout) { in bundle_StartIdleTimer()
1178 secs = bundle->cfg.idle.timeout; in bundle_StartIdleTimer()
1181 if (bundle->cfg.idle.min_timeout > secs && bundle->upat) { in bundle_StartIdleTimer()
1182 unsigned up = now - bundle->upat; in bundle_StartIdleTimer()
1184 if (bundle->cfg.idle.min_timeout > up && in bundle_StartIdleTimer()
1185 bundle->cfg.idle.min_timeout - up > (long long)secs) in bundle_StartIdleTimer()
1187 secs = bundle->cfg.idle.min_timeout - up; in bundle_StartIdleTimer()
1189 bundle->idle.timer.func = bundle_IdleTimeout; in bundle_StartIdleTimer()
1190 bundle->idle.timer.name = "idle"; in bundle_StartIdleTimer()
1191 bundle->idle.timer.load = secs * SECTICKS; in bundle_StartIdleTimer()
1192 bundle->idle.timer.arg = bundle; in bundle_StartIdleTimer()
1193 timer_Start(&bundle->idle.timer); in bundle_StartIdleTimer()
1194 bundle->idle.done = now + secs; in bundle_StartIdleTimer()
1199 bundle_SetIdleTimer(struct bundle *bundle, unsigned timeout, in bundle_SetIdleTimer() argument
1202 bundle->cfg.idle.timeout = timeout; in bundle_SetIdleTimer()
1203 bundle->cfg.idle.min_timeout = min_timeout; in bundle_SetIdleTimer()
1204 if (ncp_LayersOpen(&bundle->ncp)) in bundle_SetIdleTimer()
1205 bundle_StartIdleTimer(bundle, 0); in bundle_SetIdleTimer()
1209 bundle_StopIdleTimer(struct bundle *bundle) in bundle_StopIdleTimer() argument
1211 timer_Stop(&bundle->idle.timer); in bundle_StopIdleTimer()
1212 bundle->idle.done = 0; in bundle_StopIdleTimer()
1216 bundle_RemainingIdleTime(struct bundle *bundle) in bundle_RemainingIdleTime() argument
1218 if (bundle->idle.done) in bundle_RemainingIdleTime()
1219 return bundle->idle.done - time(NULL); in bundle_RemainingIdleTime()
1228 struct bundle *bundle = (struct bundle *)v; in bundle_SessionTimeout() local
1231 bundle_StopSessionTimer(bundle); in bundle_SessionTimeout()
1232 bundle_Close(bundle, NULL, CLOSE_STAYDOWN); in bundle_SessionTimeout()
1236 bundle_StartSessionTimer(struct bundle *bundle, unsigned secs) in bundle_StartSessionTimer() argument
1238 timer_Stop(&bundle->session.timer); in bundle_StartSessionTimer()
1239 if ((bundle->phys_type.open & (PHYS_DEDICATED|PHYS_DDIAL)) != in bundle_StartSessionTimer()
1240 bundle->phys_type.open && bundle->radius.sessiontime) { in bundle_StartSessionTimer()
1244 secs = bundle->radius.sessiontime; in bundle_StartSessionTimer()
1246 bundle->session.timer.func = bundle_SessionTimeout; in bundle_StartSessionTimer()
1247 bundle->session.timer.name = "session"; in bundle_StartSessionTimer()
1248 bundle->session.timer.load = secs * SECTICKS; in bundle_StartSessionTimer()
1249 bundle->session.timer.arg = bundle; in bundle_StartSessionTimer()
1250 timer_Start(&bundle->session.timer); in bundle_StartSessionTimer()
1251 bundle->session.done = now + secs; in bundle_StartSessionTimer()
1256 bundle_StopSessionTimer(struct bundle *bundle) in bundle_StopSessionTimer() argument
1258 timer_Stop(&bundle->session.timer); in bundle_StopSessionTimer()
1259 bundle->session.done = 0; in bundle_StopSessionTimer()
1265 bundle_IsDead(struct bundle *bundle) in bundle_IsDead() argument
1267 return !bundle->links || (bundle->phase == PHASE_DEAD && bundle->CleaningUp); in bundle_IsDead()
1271 bundle_DatalinkLinkout(struct bundle *bundle, struct datalink *dl) in bundle_DatalinkLinkout() argument
1275 for (dlp = &bundle->links; *dlp; dlp = &(*dlp)->next) in bundle_DatalinkLinkout()
1279 bundle_LinksRemoved(bundle); in bundle_DatalinkLinkout()
1287 bundle_DatalinkLinkin(struct bundle *bundle, struct datalink *dl) in bundle_DatalinkLinkin() argument
1289 struct datalink **dlp = &bundle->links; in bundle_DatalinkLinkin()
1297 bundle_LinkAdded(bundle, dl); in bundle_DatalinkLinkin()
1298 mp_CheckAutoloadTimer(&bundle->ncp.mp); in bundle_DatalinkLinkin()
1302 bundle_CleanDatalinks(struct bundle *bundle) in bundle_CleanDatalinks() argument
1304 struct datalink **dlp = &bundle->links; in bundle_CleanDatalinks()
1317 bundle_LinksRemoved(bundle); in bundle_CleanDatalinks()
1321 bundle_DatalinkClone(struct bundle *bundle, struct datalink *dl, in bundle_DatalinkClone() argument
1324 if (bundle2datalink(bundle, name)) { in bundle_DatalinkClone()
1329 bundle_DatalinkLinkin(bundle, datalink_Clone(dl, name)); in bundle_DatalinkClone()
1334 bundle_DatalinkRemove(struct bundle *bundle, struct datalink *dl) in bundle_DatalinkRemove() argument
1336 dl = bundle_DatalinkLinkout(bundle, dl); in bundle_DatalinkRemove()
1342 bundle_SetLabel(struct bundle *bundle, const char *label) in bundle_SetLabel() argument
1345 strncpy(bundle->cfg.label, label, sizeof bundle->cfg.label - 1); in bundle_SetLabel()
1347 *bundle->cfg.label = '\0'; in bundle_SetLabel()
1351 bundle_GetLabel(struct bundle *bundle) in bundle_GetLabel() argument
1353 return *bundle->cfg.label ? bundle->cfg.label : NULL; in bundle_GetLabel()
1377 bundle_ReceiveDatalink(struct bundle *bundle, int s) in bundle_ReceiveDatalink() argument
1512 dl = iov2datalink(bundle, iov, &niov, sizeof iov / sizeof *iov, fd[0], in bundle_ReceiveDatalink()
1524 bundle_DatalinkLinkin(bundle, dl); in bundle_ReceiveDatalink()
1526 bundle_CalculateBandwidth(dl->bundle); in bundle_ReceiveDatalink()
1561 bundle_LinkClosed(dl->bundle, dl); in bundle_SendDatalink()
1562 bundle_DatalinkLinkout(dl->bundle, dl); in bundle_SendDatalink()
1653 newsid = Enabled(dl->bundle, OPT_KEEPSESSION) || in bundle_SendDatalink()
1658 bundle_setsid(dl->bundle, got != -1); in bundle_SendDatalink()
1667 bundle_RenameDatalink(struct bundle *bundle, struct datalink *ndl, in bundle_RenameDatalink() argument
1675 for (dl = bundle->links; dl; dl = dl->next) in bundle_RenameDatalink()
1684 bundle_SetMode(struct bundle *bundle, struct datalink *dl, int mode) in bundle_SetMode() argument
1692 if (mode == PHYS_AUTO && !(bundle->phys_type.all & PHYS_AUTO)) in bundle_SetMode()
1694 if (bundle->ncp.ipcp.peer_ip.s_addr == INADDR_ANY) { in bundle_SetMode()
1703 if (mode == PHYS_AUTO && !(bundle->phys_type.all & PHYS_AUTO) && in bundle_SetMode()
1704 bundle->phase != PHASE_NETWORK) in bundle_SetMode()
1706 ipcp_InterfaceUp(&bundle->ncp.ipcp); in bundle_SetMode()
1709 bundle_LinksRemoved(bundle); in bundle_SetMode()
1715 bundle_setsid(struct bundle *bundle, int holdsession) in bundle_setsid() argument
1727 if (!holdsession && bundle_IsDead(bundle)) { in bundle_setsid()
1764 bundle_LockTun(bundle); /* update pid */ in bundle_setsid()
1768 bundle_ChangedPID(bundle); in bundle_setsid()
1777 for (dl = bundle->links; dl; dl = dl->next) in bundle_setsid()
1789 for (dl = bundle->links; dl; dl = dl->next) in bundle_setsid()
1832 bundle_HighestState(struct bundle *bundle) in bundle_HighestState() argument
1837 for (dl = bundle->links; dl; dl = dl->next) in bundle_HighestState()
1845 bundle_Exception(struct bundle *bundle, int fd) in bundle_Exception() argument
1849 for (dl = bundle->links; dl; dl = dl->next) in bundle_Exception()
1859 bundle_AdjustFilters(struct bundle *bundle, struct ncpaddr *local, in bundle_AdjustFilters() argument
1862 filter_AdjustAddr(&bundle->filter.in, local, remote, NULL); in bundle_AdjustFilters()
1863 filter_AdjustAddr(&bundle->filter.out, local, remote, NULL); in bundle_AdjustFilters()
1864 filter_AdjustAddr(&bundle->filter.dial, local, remote, NULL); in bundle_AdjustFilters()
1865 filter_AdjustAddr(&bundle->filter.alive, local, remote, NULL); in bundle_AdjustFilters()
1869 bundle_AdjustDNS(struct bundle *bundle) in bundle_AdjustDNS() argument
1871 struct in_addr *dns = bundle->ncp.ipcp.ns.dns; in bundle_AdjustDNS()
1873 filter_AdjustAddr(&bundle->filter.in, NULL, NULL, dns); in bundle_AdjustDNS()
1874 filter_AdjustAddr(&bundle->filter.out, NULL, NULL, dns); in bundle_AdjustDNS()
1875 filter_AdjustAddr(&bundle->filter.dial, NULL, NULL, dns); in bundle_AdjustDNS()
1876 filter_AdjustAddr(&bundle->filter.alive, NULL, NULL, dns); in bundle_AdjustDNS()
1880 bundle_CalculateBandwidth(struct bundle *bundle) in bundle_CalculateBandwidth() argument
1885 bundle->bandwidth = 0; in bundle_CalculateBandwidth()
1886 bundle->iface->mtu = 0; in bundle_CalculateBandwidth()
1889 for (dl = bundle->links; dl; dl = dl->next) { in bundle_CalculateBandwidth()
1899 bundle->bandwidth += sp; in bundle_CalculateBandwidth()
1900 if (!bundle->ncp.mp.active) { in bundle_CalculateBandwidth()
1901 bundle->iface->mtu = dl->physical->link.lcp.his_mru; in bundle_CalculateBandwidth()
1907 if (bundle->bandwidth == 0) in bundle_CalculateBandwidth()
1908 bundle->bandwidth = 115200; /* Shrug */ in bundle_CalculateBandwidth()
1910 if (bundle->ncp.mp.active) { in bundle_CalculateBandwidth()
1911 bundle->iface->mtu = bundle->ncp.mp.peer_mrru; in bundle_CalculateBandwidth()
1912 overhead = ccp_MTUOverhead(&bundle->ncp.mp.link.ccp); in bundle_CalculateBandwidth()
1915 } else if (!bundle->iface->mtu) in bundle_CalculateBandwidth()
1916 bundle->iface->mtu = DEF_MRU; in bundle_CalculateBandwidth()
1919 if (bundle->radius.valid && bundle->radius.mtu && in bundle_CalculateBandwidth()
1920 bundle->radius.mtu < bundle->iface->mtu) { in bundle_CalculateBandwidth()
1922 bundle->radius.mtu); in bundle_CalculateBandwidth()
1923 bundle->iface->mtu = bundle->radius.mtu; in bundle_CalculateBandwidth()
1929 bundle->iface->mtu, bundle->iface->mtu - maxoverhead); in bundle_CalculateBandwidth()
1930 bundle->iface->mtu -= maxoverhead; in bundle_CalculateBandwidth()
1933 tun_configure(bundle); in bundle_CalculateBandwidth()
1935 route_UpdateMTU(bundle); in bundle_CalculateBandwidth()
1939 bundle_AutoAdjust(struct bundle *bundle, int percent, int what) in bundle_AutoAdjust() argument
1944 for (dl = bundle->links; dl; dl = dl->next) in bundle_AutoAdjust()
1970 mp_CheckAutoloadTimer(&bundle->ncp.mp); in bundle_AutoAdjust()
1975 mp_CheckAutoloadTimer(&bundle->ncp.mp); in bundle_AutoAdjust()
1981 bundle_WantAutoloadTimer(struct bundle *bundle) in bundle_WantAutoloadTimer() argument
1986 if (bundle->phase == PHASE_NETWORK) { in bundle_WantAutoloadTimer()
1987 for (autolink = opened = 0, dl = bundle->links; dl; dl = dl->next) in bundle_WantAutoloadTimer()
2004 bundle_ChangedPID(struct bundle *bundle) in bundle_ChangedPID() argument
2007 ioctl(bundle->dev.fd, TUNSIFPID, 0); in bundle_ChangedPID()
2012 bundle_Uptime(struct bundle *bundle) in bundle_Uptime() argument
2014 if (bundle->upat) in bundle_Uptime()
2015 return time(NULL) - bundle->upat; in bundle_Uptime()