Lines Matching +full:software +full:- +full:dl
1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
117 return bundle->phase <= PHASE_TERMINATE ? in bundle_PhaseName()
118 PhaseNames[bundle->phase] : "unknown"; in bundle_PhaseName()
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()
159 bundle->phase = new; in bundle_NewPhase()
160 mp_Down(&bundle->ncp.mp); in bundle_NewPhase()
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()
199 struct datalink *dl; 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()
221 physical_DeleteQueue(dl->physical); 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()
228 if (dl->state == DATALINK_OPEN) 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()
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()
247 struct datalink *dl; in bundle_LinksRemoved() local
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()
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()
276 * If it's an NCP, tell our -background parent to go away. in bundle_LayerUp()
281 if (fp->proto == PROTO_LCP) { in bundle_LayerUp()
282 struct physical *p = link2physical(fp->link); in bundle_LayerUp()
284 bundle_LinkAdded(bundle, p->dl); in bundle_LayerUp()
285 mp_CheckAutoloadTimer(&bundle->ncp.mp); in bundle_LayerUp()
286 } else if (isncp(fp->proto)) { 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()
295 mp_CheckAutoloadTimer(&fp->bundle->ncp.mp); in bundle_LayerUp()
298 } else if (fp->proto == PROTO_CCP) in bundle_LayerUp()
299 bundle_CalculateBandwidth(fp->bundle); /* Against ccp_MTUOverhead */ in bundle_LayerUp()
318 if (isncp(fp->proto)) { in bundle_LayerDown()
319 if (ncp_LayersOpen(&fp->bundle->ncp) == 0) { in bundle_LayerDown()
321 if (bundle->radius.sessiontime) in bundle_LayerDown()
325 bundle->upat = 0; in bundle_LayerDown()
326 mp_StopAutoloadTimer(&bundle->ncp.mp); in bundle_LayerDown()
328 } else if (fp->proto == PROTO_LCP) { in bundle_LayerDown()
329 struct datalink *dl; in bundle_LayerDown() local
337 for (dl = bundle->links; dl; dl = dl->next) { in bundle_LayerDown()
338 if (fp == &dl->physical->link.lcp.fsm) in bundle_LayerDown()
339 lost = dl; in bundle_LayerDown()
340 else if (dl->state != DATALINK_CLOSED && dl->state != DATALINK_HANGUP) in bundle_LayerDown()
344 if (bundle->ncp.mp.active) { in bundle_LayerDown()
348 mp_LinkLost(&bundle->ncp.mp, lost); in bundle_LayerDown()
351 fp->link->name); in bundle_LayerDown()
356 ncp2initial(&bundle->ncp); in bundle_LayerDown()
357 mp_Down(&bundle->ncp.mp); in bundle_LayerDown()
372 struct datalink *dl; in bundle_LayerFinish() local
374 if (isncp(fp->proto) && !ncp_LayersUnfinished(&bundle->ncp)) { in bundle_LayerFinish()
377 for (dl = bundle->links; dl; dl = dl->next) in bundle_LayerFinish()
378 if (dl->state == DATALINK_OPEN) in bundle_LayerFinish()
379 datalink_Close(dl, CLOSE_STAYDOWN); in bundle_LayerFinish()
381 mp_Down(&bundle->ncp.mp); in bundle_LayerFinish()
395 struct datalink *dl, *this_dl; in bundle_Close() local
401 for (dl = bundle->links; dl; dl = dl->next) { in bundle_Close()
402 if (name && !strcasecmp(name, dl->name)) in bundle_Close()
403 this_dl = dl; in bundle_Close()
404 if (name == NULL || this_dl == dl) { in bundle_Close()
407 datalink_DontHangup(dl); in bundle_Close()
410 datalink_StayDown(dl); in bundle_Close()
413 } else if (dl->state != DATALINK_CLOSED && dl->state != DATALINK_HANGUP) in bundle_Close()
424 if (bundle->radius.sessiontime) 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()
434 datalink_Close(dl, how); in bundle_Close()
436 } else if (this_dl && this_dl->state != DATALINK_CLOSED && in bundle_Close()
437 this_dl->state != DATALINK_HANGUP) in bundle_Close()
444 struct datalink *dl; in bundle_Down() local
446 for (dl = bundle->links; dl; dl = dl->next) in bundle_Down()
447 datalink_Down(dl, how); in bundle_Down()
454 struct datalink *dl; 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()
474 /* Not enough - select() for more */ 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()
498 result += descriptor_UpdateSet(&dl->desc, r, w, e, n); in bundle_UpdateSet()
502 * might be ``holding'' one of the datalinks (death-row) and in bundle_UpdateSet()
503 * wants to be able to de-select() it from the descriptor set. in bundle_UpdateSet()
505 result += descriptor_UpdateSet(&bundle->ncp.mp.server.desc, r, w, e, n); in bundle_UpdateSet()
514 struct datalink *dl; in bundle_IsSet() local
516 for (dl = bundle->links; dl; dl = dl->next) in bundle_IsSet()
517 if (descriptor_IsSet(&dl->desc, fdset)) 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()
535 struct datalink *dl; in bundle_DescriptorRead() local
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()
543 if (descriptor_IsSet(&dl->desc, fdset)) 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()
574 n -= sz - sizeof tun.data; in bundle_DescriptorRead()
577 bundle->dev.Name, n); in bundle_DescriptorRead()
591 if (af == AF_INET && ((struct ip *)tun.data)->ip_dst.s_addr == in bundle_DescriptorRead()
592 bundle->ncp.ipcp.my_ip.s_addr) { in bundle_DescriptorRead()
595 pri = PacketCheck(bundle, af, tun.data, n, &bundle->filter.in, in bundle_DescriptorRead()
598 n += sz - sizeof tun.data; in bundle_DescriptorRead()
599 write(bundle->dev.fd, data, n); in bundle_DescriptorRead()
604 log_Printf(LogDEBUG, "Oops - forwarding packet addressed to myself\n"); in bundle_DescriptorRead()
608 * Process on-demand dialup. Output packets are queued within the tunnel in bundle_DescriptorRead()
614 * Note, we must be in AUTO mode :-/ otherwise our interface should in bundle_DescriptorRead()
617 pri = PacketCheck(bundle, af, tun.data, n, &bundle->filter.dial, in bundle_DescriptorRead()
624 * a pile of timed-out data in our output queue by the time we get in bundle_DescriptorRead()
627 * device - breaking auto-dial. 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()
647 struct datalink *dl; in bundle_DescriptorWrite() local
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()
656 if (descriptor_IsSet(&dl->desc, fdset)) in bundle_DescriptorWrite()
657 switch (descriptor_Write(&dl->desc, bundle, fdset)) { in bundle_DescriptorWrite()
658 case -1: in bundle_DescriptorWrite()
659 datalink_ComeDown(dl, CLOSE_NORMAL); in bundle_DescriptorWrite()
674 snprintf(pidfile, sizeof pidfile, "%stun%d.pid", _PATH_VARRUN, bundle->unit); in bundle_LockTun()
689 snprintf(pidfile, sizeof pidfile, "%stun%d.pid", _PATH_VARRUN, bundle->unit); in bundle_UnlockTun()
711 if (unit == -1) { in bundle_Create()
713 maxunit = -1; in bundle_Create()
737 bundle.unit--; in bundle_Create()
750 if (unit == -1) in bundle_Create()
883 bundle.notify.fd = -1; in bundle_Create()
901 iface_ClearFlags(bundle->iface->name, IFF_UP); in bundle_DownInterface()
907 struct datalink *dl; in bundle_Destroy() local
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()
922 radius_Destroy(&bundle->radius); in bundle_Destroy()
926 dl = bundle->links; in bundle_Destroy()
927 while (dl) in bundle_Destroy()
928 dl = datalink_Destroy(dl); in bundle_Destroy()
930 ncp_Destroy(&bundle->ncp); in bundle_Destroy()
932 close(bundle->dev.fd); 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
951 * NOTE: dl may not be in our list (bundle_SendDatalink()) ! in bundle_LinkClosed()
957 log_SetTtyCommandMode(dl); in bundle_LinkClosed()
960 for (odl = bundle->links; odl; odl = odl->next) in bundle_LinkClosed()
961 if (odl != dl && odl->state != DATALINK_CLOSED) in bundle_LinkClosed()
965 if (dl->physical->type != PHYS_AUTO) /* Not in -auto mode */ in bundle_LinkClosed()
967 ncp2initial(&bundle->ncp); in bundle_LinkClosed()
968 mp_Down(&bundle->ncp.mp); in bundle_LinkClosed()
971 if (bundle->radius.sessiontime) in bundle_LinkClosed()
984 struct datalink *dl; in bundle_Open() local
986 for (dl = bundle->links; dl; dl = dl->next) in bundle_Open()
987 if (name == NULL || !strcasecmp(dl->name, name)) { in bundle_Open()
988 if ((mask & dl->physical->type) && in bundle_Open()
989 (dl->state == DATALINK_CLOSED || in bundle_Open()
990 (force && dl->state == DATALINK_OPENING && in bundle_Open()
991 dl->dial.timer.state == TIMER_RUNNING) || in bundle_Open()
992 dl->state == DATALINK_READY)) { in bundle_Open()
993 timer_Stop(&dl->dial.timer); /* We're finished with this */ in bundle_Open()
994 datalink_Up(dl, 1, 1); in bundle_Open()
1006 struct datalink *dl; in bundle2datalink() local
1009 for (dl = bundle->links; dl; dl = dl->next) in bundle2datalink()
1010 if (!strcasecmp(dl->name, name)) in bundle2datalink()
1011 return dl; in bundle2datalink()
1012 } else if (bundle->links && !bundle->links->next) in bundle2datalink()
1013 return bundle->links; in bundle2datalink()
1021 struct datalink *dl; in bundle_ShowLinks() local
1026 for (dl = arg->bundle->links; dl; dl = dl->next) { in bundle_ShowLinks()
1027 octets = MAX(dl->physical->link.stats.total.in.OctetsPerSecond, in bundle_ShowLinks()
1028 dl->physical->link.stats.total.out.OctetsPerSecond); in bundle_ShowLinks()
1030 prompt_Printf(arg->prompt, "Name: %s [%s, %s]", in bundle_ShowLinks()
1031 dl->name, mode2Nam(dl->physical->type), datalink_State(dl)); in bundle_ShowLinks()
1032 if (dl->physical->link.stats.total.rolling && dl->state == DATALINK_OPEN) in bundle_ShowLinks()
1033 prompt_Printf(arg->prompt, " bandwidth %d, %llu bps (%llu bytes/sec)", in bundle_ShowLinks()
1034 dl->mp.bandwidth ? dl->mp.bandwidth : in bundle_ShowLinks()
1035 physical_GetSpeed(dl->physical), in bundle_ShowLinks()
1037 prompt_Printf(arg->prompt, "\n"); in bundle_ShowLinks()
1040 t = &arg->bundle->ncp.mp.link.stats.total; in bundle_ShowLinks()
1041 octets = MAX(t->in.OctetsPerSecond, t->out.OctetsPerSecond); in bundle_ShowLinks()
1042 secs = t->downtime ? 0 : throughput_uptime(t); in bundle_ShowLinks()
1043 if (secs > t->SamplePeriod) in bundle_ShowLinks()
1044 secs = t->SamplePeriod; in bundle_ShowLinks()
1046 prompt_Printf(arg->prompt, "Currently averaging %llu bps (%llu bytes/sec)" in bundle_ShowLinks()
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()
1065 prompt_Printf(arg->prompt, " Interface: %s @ %lubps", 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()
1071 prompt_Printf(arg->prompt, ", up time %d:%02d:%02d", secs / 3600, in bundle_ShowStatus()
1074 prompt_Printf(arg->prompt, "\n Queued: %lu of %u\n", in bundle_ShowStatus()
1075 (unsigned long)ncp_QueueLen(&arg->bundle->ncp), in bundle_ShowStatus()
1076 arg->bundle->cfg.ifqueue); in bundle_ShowStatus()
1078 prompt_Printf(arg->prompt, "\nDefaults:\n"); in bundle_ShowStatus()
1079 prompt_Printf(arg->prompt, " Label: %s\n", in bundle_ShowStatus()
1080 arg->bundle->cfg.label); in bundle_ShowStatus()
1081 prompt_Printf(arg->prompt, " Auth name: %s\n", in bundle_ShowStatus()
1082 arg->bundle->cfg.auth.name); in bundle_ShowStatus()
1083 prompt_Printf(arg->prompt, " Diagnostic socket: "); in bundle_ShowStatus()
1085 prompt_Printf(arg->prompt, "%s", server.cfg.sockname); in bundle_ShowStatus()
1086 if (server.cfg.mask != (mode_t)-1) in bundle_ShowStatus()
1087 prompt_Printf(arg->prompt, ", mask 0%03o", (int)server.cfg.mask); in bundle_ShowStatus()
1088 prompt_Printf(arg->prompt, "%s\n", server.fd == -1 ? " (not open)" : ""); in bundle_ShowStatus()
1090 prompt_Printf(arg->prompt, "TCP port %d%s\n", server.cfg.port, in bundle_ShowStatus()
1091 server.fd == -1 ? " (not open)" : ""); in bundle_ShowStatus()
1093 prompt_Printf(arg->prompt, "none\n"); in bundle_ShowStatus()
1095 prompt_Printf(arg->prompt, " Choked Timer: %us\n", in bundle_ShowStatus()
1096 arg->bundle->cfg.choked.timeout); in bundle_ShowStatus()
1099 radius_Show(&arg->bundle->radius, arg->prompt); in bundle_ShowStatus()
1102 prompt_Printf(arg->prompt, " Idle Timer: "); 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()
1106 prompt_Printf(arg->prompt, ", min %us", in bundle_ShowStatus()
1107 arg->bundle->cfg.idle.min_timeout); in bundle_ShowStatus()
1108 remaining = bundle_RemainingIdleTime(arg->bundle); in bundle_ShowStatus()
1109 if (remaining != -1) in bundle_ShowStatus()
1110 prompt_Printf(arg->prompt, " (%ds remaining)", remaining); in bundle_ShowStatus()
1111 prompt_Printf(arg->prompt, "\n"); in bundle_ShowStatus()
1113 prompt_Printf(arg->prompt, "disabled\n"); in bundle_ShowStatus()
1115 prompt_Printf(arg->prompt, " Filter Decap: %-20.20s", in bundle_ShowStatus()
1116 optval(arg->bundle, OPT_FILTERDECAP)); in bundle_ShowStatus()
1117 prompt_Printf(arg->prompt, " ID check: %s\n", in bundle_ShowStatus()
1118 optval(arg->bundle, OPT_IDCHECK)); in bundle_ShowStatus()
1119 prompt_Printf(arg->prompt, " Iface-Alias: %-20.20s", in bundle_ShowStatus()
1120 optval(arg->bundle, OPT_IFACEALIAS)); in bundle_ShowStatus()
1122 prompt_Printf(arg->prompt, " IPCP: %s\n", in bundle_ShowStatus()
1123 optval(arg->bundle, OPT_IPCP)); in bundle_ShowStatus()
1124 prompt_Printf(arg->prompt, " IPV6CP: %-20.20s", in bundle_ShowStatus()
1125 optval(arg->bundle, OPT_IPV6CP)); in bundle_ShowStatus()
1127 prompt_Printf(arg->prompt, " Keep-Session: %s\n", in bundle_ShowStatus()
1128 optval(arg->bundle, OPT_KEEPSESSION)); in bundle_ShowStatus()
1129 prompt_Printf(arg->prompt, " Loopback: %-20.20s", in bundle_ShowStatus()
1130 optval(arg->bundle, OPT_LOOPBACK)); in bundle_ShowStatus()
1131 prompt_Printf(arg->prompt, " PasswdAuth: %s\n", in bundle_ShowStatus()
1132 optval(arg->bundle, OPT_PASSWDAUTH)); in bundle_ShowStatus()
1133 prompt_Printf(arg->prompt, " Proxy: %-20.20s", in bundle_ShowStatus()
1134 optval(arg->bundle, OPT_PROXY)); in bundle_ShowStatus()
1135 prompt_Printf(arg->prompt, " Proxyall: %s\n", in bundle_ShowStatus()
1136 optval(arg->bundle, OPT_PROXYALL)); in bundle_ShowStatus()
1137 prompt_Printf(arg->prompt, " Sticky Routes: %-20.20s", in bundle_ShowStatus()
1138 optval(arg->bundle, OPT_SROUTES)); in bundle_ShowStatus()
1139 prompt_Printf(arg->prompt, " TCPMSS Fixup: %s\n", in bundle_ShowStatus()
1140 optval(arg->bundle, OPT_TCPMSSFIXUP)); in bundle_ShowStatus()
1141 prompt_Printf(arg->prompt, " Throughput: %-20.20s", in bundle_ShowStatus()
1142 optval(arg->bundle, OPT_THROUGHPUT)); in bundle_ShowStatus()
1143 prompt_Printf(arg->prompt, " Utmp Logging: %s\n", in bundle_ShowStatus()
1144 optval(arg->bundle, OPT_UTMP)); in bundle_ShowStatus()
1145 prompt_Printf(arg->prompt, " NAS-IP-Address: %-20.20s", in bundle_ShowStatus()
1146 optval(arg->bundle, OPT_NAS_IP_ADDRESS)); in bundle_ShowStatus()
1147 prompt_Printf(arg->prompt, " NAS-Identifier: %s\n", in bundle_ShowStatus()
1148 optval(arg->bundle, OPT_NAS_IDENTIFIER)); in bundle_ShowStatus()
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()
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()
1209 timer_Stop(&bundle->idle.timer); in bundle_StopIdleTimer()
1210 bundle->idle.done = 0; in bundle_StopIdleTimer()
1216 if (bundle->idle.done) in bundle_RemainingIdleTime()
1217 return bundle->idle.done - time(NULL); in bundle_RemainingIdleTime()
1218 return -1; in bundle_RemainingIdleTime()
1228 log_Printf(LogPHASE, "Session-Timeout timer expired\n"); in bundle_SessionTimeout()
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()
1256 timer_Stop(&bundle->session.timer); in bundle_StopSessionTimer()
1257 bundle->session.done = 0; in bundle_StopSessionTimer()
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()
1274 if (*dlp == dl) { in bundle_DatalinkLinkout()
1275 *dlp = dl->next; in bundle_DatalinkLinkout()
1276 dl->next = NULL; in bundle_DatalinkLinkout()
1278 return dl; 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()
1290 dlp = &(*dlp)->next; in bundle_DatalinkLinkin()
1292 *dlp = dl; in bundle_DatalinkLinkin()
1293 dl->next = NULL; in bundle_DatalinkLinkin()
1295 bundle_LinkAdded(bundle, dl); in bundle_DatalinkLinkin()
1296 mp_CheckAutoloadTimer(&bundle->ncp.mp); in bundle_DatalinkLinkin()
1302 struct datalink **dlp = &bundle->links; in bundle_CleanDatalinks()
1306 if ((*dlp)->state == DATALINK_CLOSED && in bundle_CleanDatalinks()
1307 (*dlp)->physical->type & in bundle_CleanDatalinks()
1312 dlp = &(*dlp)->next; in bundle_CleanDatalinks()
1319 bundle_DatalinkClone(struct bundle *bundle, struct datalink *dl, in bundle_DatalinkClone() argument
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()
1335 if (dl) in bundle_DatalinkRemove()
1336 datalink_Destroy(dl); in bundle_DatalinkRemove()
1343 strncpy(bundle->cfg.label, label, sizeof bundle->cfg.label - 1); in bundle_SetLabel()
1345 *bundle->cfg.label = '\0'; in bundle_SetLabel()
1351 return *bundle->cfg.label ? bundle->cfg.label : NULL; in bundle_GetLabel()
1363 if (datalink2iov(NULL, iov, &niov, SCATTER_SEGMENTS, NULL, NULL) == -1) { in bundle_LinkSize()
1383 struct datalink *dl; in bundle_ReceiveDatalink() local
1389 * Create our scatter/gather array - passing NULL gets the space in bundle_ReceiveDatalink()
1396 if (datalink2iov(NULL, iov, &niov, SCATTER_SEGMENTS, NULL, NULL) == -1) { in bundle_ReceiveDatalink()
1413 cmsg->cmsg_len = sizeof cmsgbuf; in bundle_ReceiveDatalink()
1414 cmsg->cmsg_level = SOL_SOCKET; in bundle_ReceiveDatalink()
1415 cmsg->cmsg_type = 0; in bundle_ReceiveDatalink()
1429 if (got == -1) in bundle_ReceiveDatalink()
1434 while (niov--) in bundle_ReceiveDatalink()
1439 if (cmsg->cmsg_level != SOL_SOCKET || cmsg->cmsg_type != SCM_RIGHTS) { in bundle_ReceiveDatalink()
1441 while (niov--) in bundle_ReceiveDatalink()
1447 nfd = ((caddr_t)cmsg + cmsg->cmsg_len - (caddr_t)fd) / sizeof(int); in bundle_ReceiveDatalink()
1452 while (nfd--) in bundle_ReceiveDatalink()
1454 while (niov--) in bundle_ReceiveDatalink()
1468 while (nfd--) in bundle_ReceiveDatalink()
1470 while (niov--) in bundle_ReceiveDatalink()
1482 if (got == -1) in bundle_ReceiveDatalink()
1487 while (nfd--) in bundle_ReceiveDatalink()
1489 while (niov--) in bundle_ReceiveDatalink()
1494 if ((got = readv(fd[1], iov + 1, niov - 1)) != expect) { in bundle_ReceiveDatalink()
1495 if (got == -1) in bundle_ReceiveDatalink()
1499 while (nfd--) in bundle_ReceiveDatalink()
1501 while (niov--) in bundle_ReceiveDatalink()
1508 nfd -= 2; /* Don't include p->fd and our reply descriptor */ in bundle_ReceiveDatalink()
1510 dl = iov2datalink(bundle, iov, &niov, sizeof iov / sizeof *iov, fd[0], in bundle_ReceiveDatalink()
1512 if (dl) { in bundle_ReceiveDatalink()
1517 datalink_Destroy(dl); in bundle_ReceiveDatalink()
1518 while (nfd--) in bundle_ReceiveDatalink()
1519 close(fd[onfd--]); in bundle_ReceiveDatalink()
1522 bundle_DatalinkLinkin(bundle, dl); in bundle_ReceiveDatalink()
1523 datalink_AuthOk(dl); in bundle_ReceiveDatalink()
1524 bundle_CalculateBandwidth(dl->bundle); in bundle_ReceiveDatalink()
1527 while (nfd--) in bundle_ReceiveDatalink()
1528 close(fd[onfd--]); in bundle_ReceiveDatalink()
1537 bundle_SendDatalink(struct datalink *dl, int s, struct sockaddr_un *sun) in bundle_SendDatalink() argument
1549 log_Printf(LogPHASE, "Transmitting datalink %s\n", dl->name); in bundle_SendDatalink()
1552 constlock = physical_LockedDevice(dl->physical); in bundle_SendDatalink()
1559 bundle_LinkClosed(dl->bundle, dl); in bundle_SendDatalink()
1560 bundle_DatalinkLinkout(dl->bundle, dl); in bundle_SendDatalink()
1568 fd[0] = datalink2iov(dl, iov, &niov, SCATTER_SEGMENTS, fd + 2, &nfd); in bundle_SendDatalink()
1570 if (fd[0] != -1 && socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, reply) != -1) { in bundle_SendDatalink()
1594 cmsg->cmsg_len = msg.msg_controllen; in bundle_SendDatalink()
1595 cmsg->cmsg_level = SOL_SOCKET; in bundle_SendDatalink()
1596 cmsg->cmsg_type = SCM_RIGHTS; in bundle_SendDatalink()
1604 if (setsockopt(reply[0], SOL_SOCKET, SO_SNDBUF, &expect, sizeof(int)) == -1) in bundle_SendDatalink()
1607 if (setsockopt(reply[1], SOL_SOCKET, SO_RCVBUF, &expect, sizeof(int)) == -1) in bundle_SendDatalink()
1615 if ((got = sendmsg(s, &msg, 0)) == -1) in bundle_SendDatalink()
1617 sun->sun_path, strerror(errno)); in bundle_SendDatalink()
1620 sun->sun_path, got, (unsigned)iov[0].iov_len); in bundle_SendDatalink()
1632 if ((got = writev(reply[0], iov + 1, niov - 1)) != expect) { in bundle_SendDatalink()
1633 if (got == -1) in bundle_SendDatalink()
1635 sun->sun_path, strerror(errno)); in bundle_SendDatalink()
1638 sun->sun_path, got, expect); in bundle_SendDatalink()
1640 } else if (got == -1) in bundle_SendDatalink()
1642 sun->sun_path, strerror(errno)); in bundle_SendDatalink()
1645 sun->sun_path, got, (int)(sizeof newpid)); in bundle_SendDatalink()
1651 newsid = Enabled(dl->bundle, OPT_KEEPSESSION) || in bundle_SendDatalink()
1654 close(fd[--nfd]); in bundle_SendDatalink()
1656 bundle_setsid(dl->bundle, got != -1); in bundle_SendDatalink()
1660 while (niov--) in bundle_SendDatalink()
1668 struct datalink *dl; in bundle_RenameDatalink() local
1670 if (!strcasecmp(ndl->name, name)) in bundle_RenameDatalink()
1673 for (dl = bundle->links; dl; dl = dl->next) in bundle_RenameDatalink()
1674 if (!strcasecmp(dl->name, name)) in bundle_RenameDatalink()
1682 bundle_SetMode(struct bundle *bundle, struct datalink *dl, int mode) in bundle_SetMode() argument
1686 omode = dl->physical->type; in bundle_SetMode()
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()
1698 if (!datalink_SetMode(dl, mode)) 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()
1723 struct datalink *dl; in bundle_setsid() local
1730 * the bundle's dead, but that leaves other resources lying about :-( in bundle_setsid()
1736 if (pipe(fds) == -1) { in bundle_setsid()
1741 case -1: in bundle_setsid()
1750 if (pipe(fds) == -1) { in bundle_setsid()
1755 case -1: in bundle_setsid()
1767 log_Printf(LogDEBUG, "%ld -> %ld: %s session control\n", in bundle_setsid()
1775 for (dl = bundle->links; dl; dl = dl->next) in bundle_setsid()
1776 if (dl->state != DATALINK_CLOSED) in bundle_setsid()
1777 physical_ChangedPid(dl->physical, pid); in bundle_setsid()
1787 for (dl = bundle->links; dl; dl = dl->next) in bundle_setsid()
1788 if (dl->state != DATALINK_CLOSED) in bundle_setsid()
1789 physical_ChangedPid(dl->physical, pid); in bundle_setsid()
1802 for (fd = getdtablesize(); fd >= 0; fd--) in bundle_setsid()
1832 struct datalink *dl; in bundle_HighestState() local
1835 for (dl = bundle->links; dl; dl = dl->next) in bundle_HighestState()
1836 if (result < dl->state) in bundle_HighestState()
1837 result = dl->state; in bundle_HighestState()
1845 struct datalink *dl; in bundle_Exception() local
1847 for (dl = bundle->links; dl; dl = dl->next) in bundle_Exception()
1848 if (dl->physical->fd == fd) { in bundle_Exception()
1849 datalink_Down(dl, CLOSE_NORMAL); in bundle_Exception()
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()
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()
1880 struct datalink *dl; in bundle_CalculateBandwidth() local
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()
1888 overhead = ccp_MTUOverhead(&dl->physical->link.ccp); in bundle_CalculateBandwidth()
1891 if (dl->state == DATALINK_OPEN) { in bundle_CalculateBandwidth()
1892 if ((sp = dl->mp.bandwidth) == 0 && in bundle_CalculateBandwidth()
1893 (sp = physical_GetSpeed(dl->physical)) == 0) in bundle_CalculateBandwidth()
1895 dl->name, dl->physical->name.full); 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()
1939 struct datalink *dl, *choice, *otherlinkup; in bundle_AutoAdjust() local
1942 for (dl = bundle->links; dl; dl = dl->next) in bundle_AutoAdjust()
1943 if (dl->physical->type == PHYS_AUTO) { in bundle_AutoAdjust()
1944 if (dl->state == DATALINK_OPEN) { in bundle_AutoAdjust()
1948 choice = dl; in bundle_AutoAdjust()
1950 } else if (dl->state == DATALINK_CLOSED) { in bundle_AutoAdjust()
1952 choice = dl; in bundle_AutoAdjust()
1956 /* An auto link in an intermediate state - forget it for the moment */ in bundle_AutoAdjust()
1960 } else if (dl->state == DATALINK_OPEN && what == AUTO_DOWN) in bundle_AutoAdjust()
1961 otherlinkup = dl; in bundle_AutoAdjust()
1965 log_Printf(LogPHASE, "%d%% saturation -> Opening link ``%s''\n", in bundle_AutoAdjust()
1966 percent, choice->name); in bundle_AutoAdjust()
1968 mp_CheckAutoloadTimer(&bundle->ncp.mp); in bundle_AutoAdjust()
1969 } else if (otherlinkup) { /* Only bring the second-last link down */ in bundle_AutoAdjust()
1970 log_Printf(LogPHASE, "%d%% saturation -> Closing link ``%s''\n", in bundle_AutoAdjust()
1971 percent, choice->name); in bundle_AutoAdjust()
1973 mp_CheckAutoloadTimer(&bundle->ncp.mp); in bundle_AutoAdjust()
1981 struct datalink *dl; in bundle_WantAutoloadTimer() local
1984 if (bundle->phase == PHASE_NETWORK) { in bundle_WantAutoloadTimer()
1985 for (autolink = opened = 0, dl = bundle->links; dl; dl = dl->next) in bundle_WantAutoloadTimer()
1986 if (dl->physical->type == PHYS_AUTO) { in bundle_WantAutoloadTimer()
1990 } else if (dl->state == DATALINK_OPEN) { in bundle_WantAutoloadTimer()
2005 ioctl(bundle->dev.fd, TUNSIFPID, 0); in bundle_ChangedPID()
2012 if (bundle->upat) in bundle_Uptime()
2013 return time(NULL) - bundle->upat; in bundle_Uptime()