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()
690 bundle_UnlockTun(struct bundle *bundle) in bundle_UnlockTun() argument
694 snprintf(pidfile, sizeof pidfile, "%stun%d.pid", _PATH_VARRUN, bundle->unit); in bundle_UnlockTun()
698 struct bundle *
701 static struct bundle bundle; /* there can be only one */ in bundle_Create() local
711 if (bundle.iface != NULL) { /* Already allocated ! */ in bundle_Create()
728 for (bundle.unit = minunit; bundle.unit != maxunit; bundle.unit++) { in bundle_Create()
729 snprintf(bundle.dev.Name, sizeof bundle.dev.Name, "%s%d", in bundle_Create()
730 prefix, bundle.unit); in bundle_Create()
731 bundle.dev.fd = ID0open(bundle.dev.Name, O_RDWR); in bundle_Create()
732 if (bundle.dev.fd >= 0) in bundle_Create()
736 if (bundle.unit == minunit && !kldtried++) { in bundle_Create()
742 bundle.unit--; in bundle_Create()
754 if (bundle.dev.fd < 0) { in bundle_Create()
763 log_SetTun(bundle.unit, NULL); in bundle_Create()
765 ifname = strrchr(bundle.dev.Name, '/'); in bundle_Create()
767 ifname = bundle.dev.Name; in bundle_Create()
771 bundle.iface = iface_Create(ifname); in bundle_Create()
772 if (bundle.iface == NULL) { in bundle_Create()
773 close(bundle.dev.fd); in bundle_Create()
780 if (ID0ioctl(bundle.dev.fd, TUNSIFMODE, &iff) < 0) in bundle_Create()
788 if (ID0ioctl(bundle.dev.fd, TUNSLMODE, &iff) < 0) in bundle_Create()
796 if (ID0ioctl(bundle.dev.fd, TUNSIFHEAD, &iff) < 0) { in bundle_Create()
799 bundle.dev.header = 0; in bundle_Create()
801 bundle.dev.header = 1; in bundle_Create()
805 bundle.dev.header = 1; in bundle_Create()
812 bundle.dev.header = 0; in bundle_Create()
818 bundle.bandwidth = 0; in bundle_Create()
819 bundle.routing_seq = 0; in bundle_Create()
820 bundle.phase = PHASE_DEAD; in bundle_Create()
821 bundle.CleaningUp = 0; in bundle_Create()
822 bundle.NatEnabled = 0; in bundle_Create()
824 bundle.fsm.LayerStart = bundle_LayerStart; in bundle_Create()
825 bundle.fsm.LayerUp = bundle_LayerUp; in bundle_Create()
826 bundle.fsm.LayerDown = bundle_LayerDown; in bundle_Create()
827 bundle.fsm.LayerFinish = bundle_LayerFinish; in bundle_Create()
828 bundle.fsm.object = &bundle; in bundle_Create()
830 bundle.cfg.idle.timeout = NCP_IDLE_TIMEOUT; in bundle_Create()
831 bundle.cfg.idle.min_timeout = 0; in bundle_Create()
832 *bundle.cfg.auth.name = '\0'; in bundle_Create()
833 *bundle.cfg.auth.key = '\0'; in bundle_Create()
834 bundle.cfg.optmask = (1ull << OPT_IDCHECK) | (1ull << OPT_LOOPBACK) | in bundle_Create()
840 opt_enable(&bundle, OPT_IPCP); in bundle_Create()
842 opt_enable(&bundle, OPT_IPV6CP); in bundle_Create()
844 *bundle.cfg.label = '\0'; in bundle_Create()
845 bundle.cfg.ifqueue = DEF_IFQUEUE; in bundle_Create()
846 bundle.cfg.choked.timeout = CHOKED_TIMEOUT; in bundle_Create()
847 bundle.phys_type.all = type; in bundle_Create()
848 bundle.phys_type.open = 0; in bundle_Create()
849 bundle.upat = 0; in bundle_Create()
851 bundle.links = datalink_Create("deflink", &bundle, type); in bundle_Create()
852 if (bundle.links == NULL) { in bundle_Create()
854 iface_Free(bundle.iface); in bundle_Create()
855 bundle.iface = NULL; in bundle_Create()
856 close(bundle.dev.fd); in bundle_Create()
860 bundle.desc.type = BUNDLE_DESCRIPTOR; in bundle_Create()
861 bundle.desc.UpdateSet = bundle_UpdateSet; in bundle_Create()
862 bundle.desc.IsSet = bundle_IsSet; in bundle_Create()
863 bundle.desc.Read = bundle_DescriptorRead; in bundle_Create()
864 bundle.desc.Write = bundle_DescriptorWrite; in bundle_Create()
866 ncp_Init(&bundle.ncp, &bundle); in bundle_Create()
868 memset(&bundle.filter, '\0', sizeof bundle.filter); in bundle_Create()
869 bundle.filter.in.fragok = bundle.filter.in.logok = 1; in bundle_Create()
870 bundle.filter.in.name = "IN"; in bundle_Create()
871 bundle.filter.out.fragok = bundle.filter.out.logok = 1; in bundle_Create()
872 bundle.filter.out.name = "OUT"; in bundle_Create()
873 bundle.filter.dial.name = "DIAL"; in bundle_Create()
874 bundle.filter.dial.logok = 1; in bundle_Create()
875 bundle.filter.alive.name = "ALIVE"; in bundle_Create()
876 bundle.filter.alive.logok = 1; in bundle_Create()
880 bundle.filter.in.rule[i].f_action = A_NONE; in bundle_Create()
881 bundle.filter.out.rule[i].f_action = A_NONE; in bundle_Create()
882 bundle.filter.dial.rule[i].f_action = A_NONE; in bundle_Create()
883 bundle.filter.alive.rule[i].f_action = A_NONE; in bundle_Create()
886 memset(&bundle.idle.timer, '\0', sizeof bundle.idle.timer); in bundle_Create()
887 bundle.idle.done = 0; in bundle_Create()
888 bundle.notify.fd = -1; in bundle_Create()
889 memset(&bundle.choked.timer, '\0', sizeof bundle.choked.timer); in bundle_Create()
891 radius_Init(&bundle.radius); in bundle_Create()
895 iface_Clear(bundle.iface, &bundle.ncp, 0, IFACE_CLEAR_ALL); in bundle_Create()
897 bundle_LockTun(&bundle); in bundle_Create()
899 return &bundle; in bundle_Create()
903 bundle_DownInterface(struct bundle *bundle) in bundle_DownInterface() argument
905 route_IfDelete(bundle, 1); in bundle_DownInterface()
906 iface_ClearFlags(bundle->iface->name, IFF_UP); in bundle_DownInterface()
910 bundle_Destroy(struct bundle *bundle) in bundle_Destroy() argument
919 timer_Stop(&bundle->idle.timer); in bundle_Destroy()
920 timer_Stop(&bundle->choked.timer); in bundle_Destroy()
921 mp_Down(&bundle->ncp.mp); in bundle_Destroy()
922 iface_Clear(bundle->iface, &bundle->ncp, 0, IFACE_CLEAR_ALL); in bundle_Destroy()
923 bundle_DownInterface(bundle); in bundle_Destroy()
927 radius_Destroy(&bundle->radius); in bundle_Destroy()
931 dl = bundle->links; in bundle_Destroy()
935 ncp_Destroy(&bundle->ncp); in bundle_Destroy()
937 close(bundle->dev.fd); in bundle_Destroy()
938 bundle_UnlockTun(bundle); in bundle_Destroy()
941 bundle_Notify(bundle, EX_ERRDEAD); in bundle_Destroy()
943 iface_Destroy(bundle->iface); in bundle_Destroy()
944 bundle->iface = NULL; in bundle_Destroy()
948 bundle_LinkClosed(struct bundle *bundle, struct datalink *dl) in bundle_LinkClosed() argument
965 for (odl = bundle->links; odl; odl = odl->next) in bundle_LinkClosed()
971 bundle_DownInterface(bundle); in bundle_LinkClosed()
972 ncp2initial(&bundle->ncp); in bundle_LinkClosed()
973 mp_Down(&bundle->ncp.mp); in bundle_LinkClosed()
974 bundle_NewPhase(bundle, PHASE_DEAD); in bundle_LinkClosed()
976 if (bundle->radius.sessiontime) in bundle_LinkClosed()
977 bundle_StopSessionTimer(bundle); in bundle_LinkClosed()
979 bundle_StopIdleTimer(bundle); in bundle_LinkClosed()
984 bundle_Open(struct bundle *bundle, const char *name, int mask, int force) in bundle_Open() argument
991 for (dl = bundle->links; dl; dl = dl->next) in bundle_Open()
1009 bundle2datalink(struct bundle *bundle, const char *name) in bundle2datalink() argument
1014 for (dl = bundle->links; dl; dl = dl->next) in bundle2datalink()
1017 } else if (bundle->links && !bundle->links->next) in bundle2datalink()
1018 return bundle->links; in bundle2datalink()
1031 for (dl = arg->bundle->links; dl; dl = dl->next) { in bundle_ShowLinks()
1045 t = &arg->bundle->ncp.mp.link.stats.total; in bundle_ShowLinks()
1058 optval(struct bundle *bundle, int opt) in optval() argument
1060 return Enabled(bundle, opt) ? "enabled" : "disabled"; in optval()
1068 prompt_Printf(arg->prompt, "Phase %s\n", bundle_PhaseName(arg->bundle)); in bundle_ShowStatus()
1069 prompt_Printf(arg->prompt, " Device: %s\n", arg->bundle->dev.Name); in bundle_ShowStatus()
1071 arg->bundle->iface->name, arg->bundle->bandwidth); in bundle_ShowStatus()
1073 if (arg->bundle->upat) { in bundle_ShowStatus()
1074 int secs = bundle_Uptime(arg->bundle); in bundle_ShowStatus()
1080 (unsigned long)ncp_QueueLen(&arg->bundle->ncp), in bundle_ShowStatus()
1081 arg->bundle->cfg.ifqueue); in bundle_ShowStatus()
1085 arg->bundle->cfg.label); in bundle_ShowStatus()
1087 arg->bundle->cfg.auth.name); in bundle_ShowStatus()
1101 arg->bundle->cfg.choked.timeout); in bundle_ShowStatus()
1104 radius_Show(&arg->bundle->radius, arg->prompt); in bundle_ShowStatus()
1108 if (arg->bundle->cfg.idle.timeout) { in bundle_ShowStatus()
1109 prompt_Printf(arg->prompt, "%us", arg->bundle->cfg.idle.timeout); in bundle_ShowStatus()
1110 if (arg->bundle->cfg.idle.min_timeout) in bundle_ShowStatus()
1112 arg->bundle->cfg.idle.min_timeout); in bundle_ShowStatus()
1113 remaining = bundle_RemainingIdleTime(arg->bundle); in bundle_ShowStatus()
1121 optval(arg->bundle, OPT_FILTERDECAP)); in bundle_ShowStatus()
1123 optval(arg->bundle, OPT_IDCHECK)); in bundle_ShowStatus()
1125 optval(arg->bundle, OPT_IFACEALIAS)); in bundle_ShowStatus()
1128 optval(arg->bundle, OPT_IPCP)); in bundle_ShowStatus()
1130 optval(arg->bundle, OPT_IPV6CP)); in bundle_ShowStatus()
1133 optval(arg->bundle, OPT_KEEPSESSION)); in bundle_ShowStatus()
1135 optval(arg->bundle, OPT_LOOPBACK)); in bundle_ShowStatus()
1137 optval(arg->bundle, OPT_PASSWDAUTH)); in bundle_ShowStatus()
1139 optval(arg->bundle, OPT_PROXY)); in bundle_ShowStatus()
1141 optval(arg->bundle, OPT_PROXYALL)); in bundle_ShowStatus()
1143 optval(arg->bundle, OPT_SROUTES)); in bundle_ShowStatus()
1145 optval(arg->bundle, OPT_TCPMSSFIXUP)); in bundle_ShowStatus()
1147 optval(arg->bundle, OPT_THROUGHPUT)); in bundle_ShowStatus()
1149 optval(arg->bundle, OPT_UTMP)); in bundle_ShowStatus()
1151 optval(arg->bundle, OPT_NAS_IP_ADDRESS)); in bundle_ShowStatus()
1153 optval(arg->bundle, OPT_NAS_IDENTIFIER)); in bundle_ShowStatus()
1161 struct bundle *bundle = (struct bundle *)v; in bundle_IdleTimeout() local
1164 bundle_StopIdleTimer(bundle); in bundle_IdleTimeout()
1165 bundle_Close(bundle, NULL, CLOSE_STAYDOWN); in bundle_IdleTimeout()
1173 bundle_StartIdleTimer(struct bundle *bundle, unsigned secs) in bundle_StartIdleTimer() argument
1175 timer_Stop(&bundle->idle.timer); in bundle_StartIdleTimer()
1176 if ((bundle->phys_type.open & (PHYS_DEDICATED|PHYS_DDIAL)) != in bundle_StartIdleTimer()
1177 bundle->phys_type.open && bundle->cfg.idle.timeout) { in bundle_StartIdleTimer()
1181 secs = bundle->cfg.idle.timeout; in bundle_StartIdleTimer()
1184 if (bundle->cfg.idle.min_timeout > secs && bundle->upat) { in bundle_StartIdleTimer()
1185 unsigned up = now - bundle->upat; in bundle_StartIdleTimer()
1187 if (bundle->cfg.idle.min_timeout > up && in bundle_StartIdleTimer()
1188 bundle->cfg.idle.min_timeout - up > (long long)secs) in bundle_StartIdleTimer()
1190 secs = bundle->cfg.idle.min_timeout - up; in bundle_StartIdleTimer()
1192 bundle->idle.timer.func = bundle_IdleTimeout; in bundle_StartIdleTimer()
1193 bundle->idle.timer.name = "idle"; in bundle_StartIdleTimer()
1194 bundle->idle.timer.load = secs * SECTICKS; in bundle_StartIdleTimer()
1195 bundle->idle.timer.arg = bundle; in bundle_StartIdleTimer()
1196 timer_Start(&bundle->idle.timer); in bundle_StartIdleTimer()
1197 bundle->idle.done = now + secs; in bundle_StartIdleTimer()
1202 bundle_SetIdleTimer(struct bundle *bundle, unsigned timeout, in bundle_SetIdleTimer() argument
1205 bundle->cfg.idle.timeout = timeout; in bundle_SetIdleTimer()
1206 bundle->cfg.idle.min_timeout = min_timeout; in bundle_SetIdleTimer()
1207 if (ncp_LayersOpen(&bundle->ncp)) in bundle_SetIdleTimer()
1208 bundle_StartIdleTimer(bundle, 0); in bundle_SetIdleTimer()
1212 bundle_StopIdleTimer(struct bundle *bundle) in bundle_StopIdleTimer() argument
1214 timer_Stop(&bundle->idle.timer); in bundle_StopIdleTimer()
1215 bundle->idle.done = 0; in bundle_StopIdleTimer()
1219 bundle_RemainingIdleTime(struct bundle *bundle) in bundle_RemainingIdleTime() argument
1221 if (bundle->idle.done) in bundle_RemainingIdleTime()
1222 return bundle->idle.done - time(NULL); in bundle_RemainingIdleTime()
1231 struct bundle *bundle = (struct bundle *)v; in bundle_SessionTimeout() local
1234 bundle_StopSessionTimer(bundle); in bundle_SessionTimeout()
1235 bundle_Close(bundle, NULL, CLOSE_STAYDOWN); in bundle_SessionTimeout()
1239 bundle_StartSessionTimer(struct bundle *bundle, unsigned secs) in bundle_StartSessionTimer() argument
1241 timer_Stop(&bundle->session.timer); in bundle_StartSessionTimer()
1242 if ((bundle->phys_type.open & (PHYS_DEDICATED|PHYS_DDIAL)) != in bundle_StartSessionTimer()
1243 bundle->phys_type.open && bundle->radius.sessiontime) { in bundle_StartSessionTimer()
1247 secs = bundle->radius.sessiontime; in bundle_StartSessionTimer()
1249 bundle->session.timer.func = bundle_SessionTimeout; in bundle_StartSessionTimer()
1250 bundle->session.timer.name = "session"; in bundle_StartSessionTimer()
1251 bundle->session.timer.load = secs * SECTICKS; in bundle_StartSessionTimer()
1252 bundle->session.timer.arg = bundle; in bundle_StartSessionTimer()
1253 timer_Start(&bundle->session.timer); in bundle_StartSessionTimer()
1254 bundle->session.done = now + secs; in bundle_StartSessionTimer()
1259 bundle_StopSessionTimer(struct bundle *bundle) in bundle_StopSessionTimer() argument
1261 timer_Stop(&bundle->session.timer); in bundle_StopSessionTimer()
1262 bundle->session.done = 0; in bundle_StopSessionTimer()
1268 bundle_IsDead(struct bundle *bundle) in bundle_IsDead() argument
1270 return !bundle->links || (bundle->phase == PHASE_DEAD && bundle->CleaningUp); in bundle_IsDead()
1274 bundle_DatalinkLinkout(struct bundle *bundle, struct datalink *dl) in bundle_DatalinkLinkout() argument
1278 for (dlp = &bundle->links; *dlp; dlp = &(*dlp)->next) in bundle_DatalinkLinkout()
1282 bundle_LinksRemoved(bundle); in bundle_DatalinkLinkout()
1290 bundle_DatalinkLinkin(struct bundle *bundle, struct datalink *dl) in bundle_DatalinkLinkin() argument
1292 struct datalink **dlp = &bundle->links; in bundle_DatalinkLinkin()
1300 bundle_LinkAdded(bundle, dl); in bundle_DatalinkLinkin()
1301 mp_CheckAutoloadTimer(&bundle->ncp.mp); in bundle_DatalinkLinkin()
1305 bundle_CleanDatalinks(struct bundle *bundle) in bundle_CleanDatalinks() argument
1307 struct datalink **dlp = &bundle->links; in bundle_CleanDatalinks()
1320 bundle_LinksRemoved(bundle); in bundle_CleanDatalinks()
1324 bundle_DatalinkClone(struct bundle *bundle, struct datalink *dl, in bundle_DatalinkClone() argument
1327 if (bundle2datalink(bundle, name)) { in bundle_DatalinkClone()
1332 bundle_DatalinkLinkin(bundle, datalink_Clone(dl, name)); in bundle_DatalinkClone()
1337 bundle_DatalinkRemove(struct bundle *bundle, struct datalink *dl) in bundle_DatalinkRemove() argument
1339 dl = bundle_DatalinkLinkout(bundle, dl); in bundle_DatalinkRemove()
1345 bundle_SetLabel(struct bundle *bundle, const char *label) in bundle_SetLabel() argument
1348 strncpy(bundle->cfg.label, label, sizeof bundle->cfg.label - 1); in bundle_SetLabel()
1350 *bundle->cfg.label = '\0'; in bundle_SetLabel()
1354 bundle_GetLabel(struct bundle *bundle) in bundle_GetLabel() argument
1356 return *bundle->cfg.label ? bundle->cfg.label : NULL; in bundle_GetLabel()
1380 bundle_ReceiveDatalink(struct bundle *bundle, int s) in bundle_ReceiveDatalink() argument
1515 dl = iov2datalink(bundle, iov, &niov, sizeof iov / sizeof *iov, fd[0], in bundle_ReceiveDatalink()
1527 bundle_DatalinkLinkin(bundle, dl); in bundle_ReceiveDatalink()
1529 bundle_CalculateBandwidth(dl->bundle); in bundle_ReceiveDatalink()
1564 bundle_LinkClosed(dl->bundle, dl); in bundle_SendDatalink()
1565 bundle_DatalinkLinkout(dl->bundle, dl); in bundle_SendDatalink()
1656 newsid = Enabled(dl->bundle, OPT_KEEPSESSION) || in bundle_SendDatalink()
1661 bundle_setsid(dl->bundle, got != -1); in bundle_SendDatalink()
1670 bundle_RenameDatalink(struct bundle *bundle, struct datalink *ndl, in bundle_RenameDatalink() argument
1678 for (dl = bundle->links; dl; dl = dl->next) in bundle_RenameDatalink()
1687 bundle_SetMode(struct bundle *bundle, struct datalink *dl, int mode) in bundle_SetMode() argument
1695 if (mode == PHYS_AUTO && !(bundle->phys_type.all & PHYS_AUTO)) in bundle_SetMode()
1697 if (bundle->ncp.ipcp.peer_ip.s_addr == INADDR_ANY) { in bundle_SetMode()
1706 if (mode == PHYS_AUTO && !(bundle->phys_type.all & PHYS_AUTO) && in bundle_SetMode()
1707 bundle->phase != PHASE_NETWORK) in bundle_SetMode()
1709 ipcp_InterfaceUp(&bundle->ncp.ipcp); in bundle_SetMode()
1712 bundle_LinksRemoved(bundle); in bundle_SetMode()
1718 bundle_setsid(struct bundle *bundle, int holdsession) in bundle_setsid() argument
1730 if (!holdsession && bundle_IsDead(bundle)) { in bundle_setsid()
1767 bundle_LockTun(bundle); /* update pid */ in bundle_setsid()
1771 bundle_ChangedPID(bundle); in bundle_setsid()
1780 for (dl = bundle->links; dl; dl = dl->next) in bundle_setsid()
1792 for (dl = bundle->links; dl; dl = dl->next) in bundle_setsid()
1835 bundle_HighestState(struct bundle *bundle) in bundle_HighestState() argument
1840 for (dl = bundle->links; dl; dl = dl->next) in bundle_HighestState()
1848 bundle_Exception(struct bundle *bundle, int fd) in bundle_Exception() argument
1852 for (dl = bundle->links; dl; dl = dl->next) in bundle_Exception()
1862 bundle_AdjustFilters(struct bundle *bundle, struct ncpaddr *local, in bundle_AdjustFilters() argument
1865 filter_AdjustAddr(&bundle->filter.in, local, remote, NULL); in bundle_AdjustFilters()
1866 filter_AdjustAddr(&bundle->filter.out, local, remote, NULL); in bundle_AdjustFilters()
1867 filter_AdjustAddr(&bundle->filter.dial, local, remote, NULL); in bundle_AdjustFilters()
1868 filter_AdjustAddr(&bundle->filter.alive, local, remote, NULL); in bundle_AdjustFilters()
1872 bundle_AdjustDNS(struct bundle *bundle) in bundle_AdjustDNS() argument
1874 struct in_addr *dns = bundle->ncp.ipcp.ns.dns; in bundle_AdjustDNS()
1876 filter_AdjustAddr(&bundle->filter.in, NULL, NULL, dns); in bundle_AdjustDNS()
1877 filter_AdjustAddr(&bundle->filter.out, NULL, NULL, dns); in bundle_AdjustDNS()
1878 filter_AdjustAddr(&bundle->filter.dial, NULL, NULL, dns); in bundle_AdjustDNS()
1879 filter_AdjustAddr(&bundle->filter.alive, NULL, NULL, dns); in bundle_AdjustDNS()
1883 bundle_CalculateBandwidth(struct bundle *bundle) in bundle_CalculateBandwidth() argument
1888 bundle->bandwidth = 0; in bundle_CalculateBandwidth()
1889 bundle->iface->mtu = 0; in bundle_CalculateBandwidth()
1892 for (dl = bundle->links; dl; dl = dl->next) { in bundle_CalculateBandwidth()
1902 bundle->bandwidth += sp; in bundle_CalculateBandwidth()
1903 if (!bundle->ncp.mp.active) { in bundle_CalculateBandwidth()
1904 bundle->iface->mtu = dl->physical->link.lcp.his_mru; in bundle_CalculateBandwidth()
1910 if (bundle->bandwidth == 0) in bundle_CalculateBandwidth()
1911 bundle->bandwidth = 115200; /* Shrug */ in bundle_CalculateBandwidth()
1913 if (bundle->ncp.mp.active) { in bundle_CalculateBandwidth()
1914 bundle->iface->mtu = bundle->ncp.mp.peer_mrru; in bundle_CalculateBandwidth()
1915 overhead = ccp_MTUOverhead(&bundle->ncp.mp.link.ccp); in bundle_CalculateBandwidth()
1918 } else if (!bundle->iface->mtu) in bundle_CalculateBandwidth()
1919 bundle->iface->mtu = DEF_MRU; in bundle_CalculateBandwidth()
1922 if (bundle->radius.valid && bundle->radius.mtu && in bundle_CalculateBandwidth()
1923 bundle->radius.mtu < bundle->iface->mtu) { in bundle_CalculateBandwidth()
1925 bundle->radius.mtu); in bundle_CalculateBandwidth()
1926 bundle->iface->mtu = bundle->radius.mtu; in bundle_CalculateBandwidth()
1932 bundle->iface->mtu, bundle->iface->mtu - maxoverhead); in bundle_CalculateBandwidth()
1933 bundle->iface->mtu -= maxoverhead; in bundle_CalculateBandwidth()
1936 tun_configure(bundle); in bundle_CalculateBandwidth()
1938 route_UpdateMTU(bundle); in bundle_CalculateBandwidth()
1942 bundle_AutoAdjust(struct bundle *bundle, int percent, int what) in bundle_AutoAdjust() argument
1947 for (dl = bundle->links; dl; dl = dl->next) in bundle_AutoAdjust()
1973 mp_CheckAutoloadTimer(&bundle->ncp.mp); in bundle_AutoAdjust()
1978 mp_CheckAutoloadTimer(&bundle->ncp.mp); in bundle_AutoAdjust()
1984 bundle_WantAutoloadTimer(struct bundle *bundle) in bundle_WantAutoloadTimer() argument
1989 if (bundle->phase == PHASE_NETWORK) { in bundle_WantAutoloadTimer()
1990 for (autolink = opened = 0, dl = bundle->links; dl; dl = dl->next) in bundle_WantAutoloadTimer()
2007 bundle_ChangedPID(struct bundle *bundle) in bundle_ChangedPID() argument
2010 ioctl(bundle->dev.fd, TUNSIFPID, 0); in bundle_ChangedPID()
2015 bundle_Uptime(struct bundle *bundle) in bundle_Uptime() argument
2017 if (bundle->upat) in bundle_Uptime()
2018 return time(NULL) - bundle->upat; in bundle_Uptime()