bundle.c (36714) | bundle.c (36928) |
---|---|
1/*- 2 * Copyright (c) 1998 Brian Somers <brian@Awfulhak.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 9 unchanged lines hidden (view full) --- 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * | 1/*- 2 * Copyright (c) 1998 Brian Somers <brian@Awfulhak.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 9 unchanged lines hidden (view full) --- 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * |
26 * $Id: bundle.c,v 1.13 1998/06/06 20:50:54 brian Exp $ | 26 * $Id: bundle.c,v 1.14 1998/06/07 00:16:37 brian Exp $ |
27 */ 28 29#include <sys/param.h> 30#include <sys/socket.h> 31#include <netinet/in.h> 32#include <net/if.h> 33#include <arpa/inet.h> 34#include <net/route.h> --- 260 unchanged lines hidden (view full) --- 295static int 296bundle_RemainingAutoLoadTime(struct bundle *bundle) 297{ 298 if (bundle->autoload.done) 299 return bundle->autoload.done - time(NULL); 300 return -1; 301} 302 | 27 */ 28 29#include <sys/param.h> 30#include <sys/socket.h> 31#include <netinet/in.h> 32#include <net/if.h> 33#include <arpa/inet.h> 34#include <net/route.h> --- 260 unchanged lines hidden (view full) --- 295static int 296bundle_RemainingAutoLoadTime(struct bundle *bundle) 297{ 298 if (bundle->autoload.done) 299 return bundle->autoload.done - time(NULL); 300 return -1; 301} 302 |
303static void 304bundle_LinkAdded(struct bundle *bundle, struct datalink *dl) 305{ 306 bundle->phys_type.all |= dl->physical->type; 307 if (dl->state == DATALINK_OPEN) 308 bundle->phys_type.open |= dl->physical->type; |
|
303 | 309 |
310 /* Note: We only re-add links that are DATALINK_OPEN */ 311 if (dl->physical->type == PHYS_AUTO && 312 bundle->autoload.timer.state == TIMER_STOPPED && 313 dl->state != DATALINK_OPEN && 314 bundle->phase == PHASE_NETWORK) 315 bundle->autoload.running = 1; 316 317 if ((bundle->phys_type.open & (PHYS_DEDICATED|PHYS_DDIAL)) 318 != bundle->phys_type.open && bundle->idle.timer.state == TIMER_STOPPED) 319 /* We may need to start our idle timer */ 320 bundle_StartIdleTimer(bundle); 321} 322 |
|
304static void | 323static void |
324bundle_LinksRemoved(struct bundle *bundle) 325{ 326 struct datalink *dl; 327 328 bundle->phys_type.all = bundle->phys_type.open = 0; 329 for (dl = bundle->links; dl; dl = dl->next) 330 bundle_LinkAdded(bundle, dl); 331 332 if ((bundle->phys_type.open & (PHYS_DEDICATED|PHYS_DDIAL)) 333 == bundle->phys_type.open) 334 bundle_StopIdleTimer(bundle); 335} 336 337static void |
|
305bundle_LayerUp(void *v, struct fsm *fp) 306{ 307 /* 308 * The given fsm is now up | 338bundle_LayerUp(void *v, struct fsm *fp) 339{ 340 /* 341 * The given fsm is now up |
342 * If it's an LCP, adjust our phys_mode.open value. |
|
309 * If it's an LCP set our mtu (if we're multilink, add up the link 310 * speeds and set the MRRU) and start our autoload timer. 311 * If it's an NCP, tell our -background parent to go away. 312 * If it's the first NCP, start the idle timer. 313 */ 314 struct bundle *bundle = (struct bundle *)v; 315 316 if (fp->proto == PROTO_LCP) { | 343 * If it's an LCP set our mtu (if we're multilink, add up the link 344 * speeds and set the MRRU) and start our autoload timer. 345 * If it's an NCP, tell our -background parent to go away. 346 * If it's the first NCP, start the idle timer. 347 */ 348 struct bundle *bundle = (struct bundle *)v; 349 350 if (fp->proto == PROTO_LCP) { |
351 struct physical *p = link2physical(fp->link); 352 353 bundle_LinkAdded(bundle, p->dl); |
|
317 if (bundle->ncp.mp.active) { 318 struct datalink *dl; 319 320 bundle->ifp.Speed = 0; 321 for (dl = bundle->links; dl; dl = dl->next) 322 if (dl->state == DATALINK_OPEN) 323 bundle->ifp.Speed += modem_Speed(dl->physical); 324 tun_configure(bundle, bundle->ncp.mp.peer_mrru); 325 bundle->autoload.running = 1; 326 } else { | 354 if (bundle->ncp.mp.active) { 355 struct datalink *dl; 356 357 bundle->ifp.Speed = 0; 358 for (dl = bundle->links; dl; dl = dl->next) 359 if (dl->state == DATALINK_OPEN) 360 bundle->ifp.Speed += modem_Speed(dl->physical); 361 tun_configure(bundle, bundle->ncp.mp.peer_mrru); 362 bundle->autoload.running = 1; 363 } else { |
327 bundle->ifp.Speed = modem_Speed(link2physical(fp->link)); | 364 bundle->ifp.Speed = modem_Speed(p); |
328 tun_configure(bundle, fsm2lcp(fp)->his_mru); 329 } 330 } else if (fp->proto == PROTO_IPCP) { 331 bundle_StartIdleTimer(bundle); 332 bundle_Notify(bundle, EX_NORMAL); 333 } 334} 335 336static void 337bundle_LayerDown(void *v, struct fsm *fp) 338{ 339 /* 340 * The given FSM has been told to come down. 341 * If it's our last NCP, stop the idle timer. | 365 tun_configure(bundle, fsm2lcp(fp)->his_mru); 366 } 367 } else if (fp->proto == PROTO_IPCP) { 368 bundle_StartIdleTimer(bundle); 369 bundle_Notify(bundle, EX_NORMAL); 370 } 371} 372 373static void 374bundle_LayerDown(void *v, struct fsm *fp) 375{ 376 /* 377 * The given FSM has been told to come down. 378 * If it's our last NCP, stop the idle timer. |
379 * If it's an LCP, adjust our phys_type.open value and any timers. |
|
342 * If it's an LCP and we're in multilink mode, adjust our tun 343 * speed and make sure our minimum sequence number is adjusted. 344 */ 345 346 struct bundle *bundle = (struct bundle *)v; 347 348 if (fp->proto == PROTO_IPCP) 349 bundle_StopIdleTimer(bundle); | 380 * If it's an LCP and we're in multilink mode, adjust our tun 381 * speed and make sure our minimum sequence number is adjusted. 382 */ 383 384 struct bundle *bundle = (struct bundle *)v; 385 386 if (fp->proto == PROTO_IPCP) 387 bundle_StopIdleTimer(bundle); |
350 else if (fp->proto == PROTO_LCP && bundle->ncp.mp.active) { 351 struct datalink *dl; 352 struct datalink *lost; | 388 else if (fp->proto == PROTO_LCP) { 389 bundle_LinksRemoved(bundle); /* adjust timers & phys_type values */ 390 if (bundle->ncp.mp.active) { 391 struct datalink *dl; 392 struct datalink *lost; |
353 | 393 |
354 bundle->ifp.Speed = 0; 355 lost = NULL; 356 for (dl = bundle->links; dl; dl = dl->next) 357 if (fp == &dl->physical->link.lcp.fsm) 358 lost = dl; 359 else if (dl->state == DATALINK_OPEN) 360 bundle->ifp.Speed += modem_Speed(dl->physical); | 394 bundle->ifp.Speed = 0; 395 lost = NULL; 396 for (dl = bundle->links; dl; dl = dl->next) 397 if (fp == &dl->physical->link.lcp.fsm) 398 lost = dl; 399 else if (dl->state == DATALINK_OPEN) 400 bundle->ifp.Speed += modem_Speed(dl->physical); |
361 | 401 |
362 if (bundle->ifp.Speed) 363 /* Don't configure down to a speed of 0 */ 364 tun_configure(bundle, bundle->ncp.mp.link.lcp.his_mru); | 402 if (bundle->ifp.Speed) 403 /* Don't configure down to a speed of 0 */ 404 tun_configure(bundle, bundle->ncp.mp.link.lcp.his_mru); |
365 | 405 |
366 if (lost) 367 mp_LinkLost(&bundle->ncp.mp, lost); 368 else 369 log_Printf(LogERROR, "Oops, lost an unrecognised datalink (%s) !\n", 370 fp->link->name); | 406 if (lost) 407 mp_LinkLost(&bundle->ncp.mp, lost); 408 else 409 log_Printf(LogERROR, "Oops, lost an unrecognised datalink (%s) !\n", 410 fp->link->name); 411 } |
371 } 372} 373 374static void 375bundle_LayerFinish(void *v, struct fsm *fp) 376{ 377 /* The given fsm is now down (fp cannot be NULL) 378 * --- 117 unchanged lines hidden (view full) --- 496 else if (bundle->autoload.timer.state != TIMER_RUNNING || 497 bundle->autoload.comingup) 498 bundle_StartAutoLoadTimer(bundle, 0); 499 } else if (bundle->autoload.timer.state != TIMER_RUNNING || 500 !bundle->autoload.comingup) 501 bundle_StartAutoLoadTimer(bundle, 1); 502 } 503 | 412 } 413} 414 415static void 416bundle_LayerFinish(void *v, struct fsm *fp) 417{ 418 /* The given fsm is now down (fp cannot be NULL) 419 * --- 117 unchanged lines hidden (view full) --- 537 else if (bundle->autoload.timer.state != TIMER_RUNNING || 538 bundle->autoload.comingup) 539 bundle_StartAutoLoadTimer(bundle, 0); 540 } else if (bundle->autoload.timer.state != TIMER_RUNNING || 541 !bundle->autoload.comingup) 542 bundle_StartAutoLoadTimer(bundle, 1); 543 } 544 |
504 if (r && 505 (bundle->phase == PHASE_NETWORK || bundle->phys_type & PHYS_AUTO)) { | 545 if (r && (bundle->phase == PHASE_NETWORK || 546 bundle->phys_type.all & PHYS_AUTO)) { |
506 /* enough surplus so that we can tell if we're getting swamped */ 507 want = bundle->cfg.autoload.max.packets + nlinks * 2; 508 /* but at least 20 packets ! */ 509 if (want < 20) 510 want = 20; 511 if (queued < want) { 512 /* Not enough - select() for more */ 513 FD_SET(bundle->dev.fd, r); --- 273 unchanged lines hidden (view full) --- 787 bundle.cfg.opt = OPT_SROUTES | OPT_IDCHECK | OPT_LOOPBACK | 788 OPT_THROUGHPUT | OPT_UTMP; 789 *bundle.cfg.label = '\0'; 790 bundle.cfg.mtu = DEF_MTU; 791 bundle.cfg.autoload.max.packets = 0; 792 bundle.cfg.autoload.max.timeout = 0; 793 bundle.cfg.autoload.min.packets = 0; 794 bundle.cfg.autoload.min.timeout = 0; | 547 /* enough surplus so that we can tell if we're getting swamped */ 548 want = bundle->cfg.autoload.max.packets + nlinks * 2; 549 /* but at least 20 packets ! */ 550 if (want < 20) 551 want = 20; 552 if (queued < want) { 553 /* Not enough - select() for more */ 554 FD_SET(bundle->dev.fd, r); --- 273 unchanged lines hidden (view full) --- 828 bundle.cfg.opt = OPT_SROUTES | OPT_IDCHECK | OPT_LOOPBACK | 829 OPT_THROUGHPUT | OPT_UTMP; 830 *bundle.cfg.label = '\0'; 831 bundle.cfg.mtu = DEF_MTU; 832 bundle.cfg.autoload.max.packets = 0; 833 bundle.cfg.autoload.max.timeout = 0; 834 bundle.cfg.autoload.min.packets = 0; 835 bundle.cfg.autoload.min.timeout = 0; |
795 bundle.phys_type = type; | 836 bundle.phys_type.all = type; 837 bundle.phys_type.open = 0; |
796 797 bundle.links = datalink_Create("deflink", &bundle, type); 798 if (bundle.links == NULL) { 799 log_Printf(LogERROR, "Cannot create data link: %s\n", strerror(errno)); 800 close(bundle.dev.fd); 801 bundle.ifp.Name = NULL; 802 return NULL; 803 } --- 414 unchanged lines hidden (view full) --- 1218/* 1219 * Start Idle timer. If timeout is reached, we call bundle_Close() to 1220 * close LCP and link. 1221 */ 1222void 1223bundle_StartIdleTimer(struct bundle *bundle) 1224{ 1225 timer_Stop(&bundle->idle.timer); | 838 839 bundle.links = datalink_Create("deflink", &bundle, type); 840 if (bundle.links == NULL) { 841 log_Printf(LogERROR, "Cannot create data link: %s\n", strerror(errno)); 842 close(bundle.dev.fd); 843 bundle.ifp.Name = NULL; 844 return NULL; 845 } --- 414 unchanged lines hidden (view full) --- 1260/* 1261 * Start Idle timer. If timeout is reached, we call bundle_Close() to 1262 * close LCP and link. 1263 */ 1264void 1265bundle_StartIdleTimer(struct bundle *bundle) 1266{ 1267 timer_Stop(&bundle->idle.timer); |
1226 if ((bundle->phys_type & (PHYS_DEDICATED|PHYS_DDIAL)) != bundle->phys_type && 1227 bundle->cfg.idle_timeout) { | 1268 if ((bundle->phys_type.open & (PHYS_DEDICATED|PHYS_DDIAL)) != 1269 bundle->phys_type.open && bundle->cfg.idle_timeout) { |
1228 bundle->idle.timer.func = bundle_IdleTimeout; 1229 bundle->idle.timer.name = "idle"; 1230 bundle->idle.timer.load = bundle->cfg.idle_timeout * SECTICKS; 1231 bundle->idle.timer.arg = bundle; 1232 timer_Start(&bundle->idle.timer); 1233 bundle->idle.done = time(NULL) + bundle->cfg.idle_timeout; 1234 } 1235} --- 22 unchanged lines hidden (view full) --- 1258} 1259 1260int 1261bundle_IsDead(struct bundle *bundle) 1262{ 1263 return !bundle->links || (bundle->phase == PHASE_DEAD && bundle->CleaningUp); 1264} 1265 | 1270 bundle->idle.timer.func = bundle_IdleTimeout; 1271 bundle->idle.timer.name = "idle"; 1272 bundle->idle.timer.load = bundle->cfg.idle_timeout * SECTICKS; 1273 bundle->idle.timer.arg = bundle; 1274 timer_Start(&bundle->idle.timer); 1275 bundle->idle.done = time(NULL) + bundle->cfg.idle_timeout; 1276 } 1277} --- 22 unchanged lines hidden (view full) --- 1300} 1301 1302int 1303bundle_IsDead(struct bundle *bundle) 1304{ 1305 return !bundle->links || (bundle->phase == PHASE_DEAD && bundle->CleaningUp); 1306} 1307 |
1266static void 1267bundle_LinkAdded(struct bundle *bundle, struct datalink *dl) 1268{ 1269 bundle->phys_type |= dl->physical->type; 1270 if (dl->physical->type == PHYS_AUTO && 1271 bundle->autoload.timer.state == TIMER_STOPPED && 1272 bundle->phase == PHASE_NETWORK) 1273 bundle->autoload.running = 1; 1274} 1275 1276static void 1277bundle_LinksRemoved(struct bundle *bundle) 1278{ 1279 struct datalink *dl; 1280 1281 bundle->phys_type = 0; 1282 for (dl = bundle->links; dl; dl = dl->next) 1283 bundle_LinkAdded(bundle, dl); 1284 1285 if ((bundle->phys_type & (PHYS_DEDICATED|PHYS_DDIAL)) == bundle->phys_type) 1286 timer_Stop(&bundle->idle.timer); 1287} 1288 | |
1289static struct datalink * 1290bundle_DatalinkLinkout(struct bundle *bundle, struct datalink *dl) 1291{ 1292 struct datalink **dlp; 1293 1294 for (dlp = &bundle->links; *dlp; dlp = &(*dlp)->next) 1295 if (*dlp == dl) { 1296 *dlp = dl->next; --- 245 unchanged lines hidden (view full) --- 1542bundle_SetMode(struct bundle *bundle, struct datalink *dl, int mode) 1543{ 1544 int omode; 1545 1546 omode = dl->physical->type; 1547 if (omode == mode) 1548 return 1; 1549 | 1308static struct datalink * 1309bundle_DatalinkLinkout(struct bundle *bundle, struct datalink *dl) 1310{ 1311 struct datalink **dlp; 1312 1313 for (dlp = &bundle->links; *dlp; dlp = &(*dlp)->next) 1314 if (*dlp == dl) { 1315 *dlp = dl->next; --- 245 unchanged lines hidden (view full) --- 1561bundle_SetMode(struct bundle *bundle, struct datalink *dl, int mode) 1562{ 1563 int omode; 1564 1565 omode = dl->physical->type; 1566 if (omode == mode) 1567 return 1; 1568 |
1550 if (mode == PHYS_AUTO && !(bundle->phys_type & PHYS_AUTO)) 1551 /* Changing to demand-dial mode */ | 1569 if (mode == PHYS_AUTO && !(bundle->phys_type.all & PHYS_AUTO)) 1570 /* First auto link */ |
1552 if (bundle->ncp.ipcp.peer_ip.s_addr == INADDR_ANY) { | 1571 if (bundle->ncp.ipcp.peer_ip.s_addr == INADDR_ANY) { |
1553 log_Printf(LogWARN, "You must `set ifaddr' before changing mode to %s\n", 1554 mode2Nam(mode)); | 1572 log_Printf(LogWARN, "You must `set ifaddr' or `open' before" 1573 " changing mode to %s\n", mode2Nam(mode)); |
1555 return 0; 1556 } 1557 1558 if (!datalink_SetMode(dl, mode)) 1559 return 0; 1560 | 1574 return 0; 1575 } 1576 1577 if (!datalink_SetMode(dl, mode)) 1578 return 0; 1579 |
1561 if (mode == PHYS_AUTO && !(bundle->phys_type & PHYS_AUTO)) | 1580 if (mode == PHYS_AUTO && !(bundle->phys_type.all & PHYS_AUTO) && 1581 bundle->phase != PHASE_NETWORK) 1582 /* First auto link, we need an interface */ |
1562 ipcp_InterfaceUp(&bundle->ncp.ipcp); 1563 1564 /* Regenerate phys_type and adjust autoload & idle timers */ 1565 bundle_LinksRemoved(bundle); 1566 | 1583 ipcp_InterfaceUp(&bundle->ncp.ipcp); 1584 1585 /* Regenerate phys_type and adjust autoload & idle timers */ 1586 bundle_LinksRemoved(bundle); 1587 |
1567 if (omode == PHYS_AUTO && !(bundle->phys_type & PHYS_AUTO)) 1568 /* Changing from demand-dial mode */ | 1588 if (omode == PHYS_AUTO && !(bundle->phys_type.all & PHYS_AUTO) && 1589 bundle->phase != PHASE_NETWORK) 1590 /* No auto links left */ |
1569 ipcp_CleanInterface(&bundle->ncp.ipcp); 1570 1571 return 1; 1572} 1573 1574void 1575bundle_setsid(struct bundle *bundle, int holdsession) 1576{ --- 100 unchanged lines hidden --- | 1591 ipcp_CleanInterface(&bundle->ncp.ipcp); 1592 1593 return 1; 1594} 1595 1596void 1597bundle_setsid(struct bundle *bundle, int holdsession) 1598{ --- 100 unchanged lines hidden --- |