ipcp.c (8fa6ebe47d24a6621f1be15f3157e2e1a046596e) | ipcp.c (3afe5ccb7512f2632ee714e310b46470f2e4d6fa) |
---|---|
1/* 2 * PPP IP Control Protocol (IPCP) Module 3 * 4 * Written by Toshiharu OHNO (tony-o@iij.ad.jp) 5 * 6 * Copyright (C) 1993, Internet Initiative Japan, Inc. All rights reserverd. 7 * 8 * Redistribution and use in source and binary forms are permitted 9 * provided that the above copyright notice and this paragraph are 10 * duplicated in all such forms and that any documentation, 11 * advertising materials, and other materials related to such 12 * distribution and use acknowledge that the software was developed 13 * by the Internet Initiative Japan, Inc. The name of the 14 * IIJ may not be used to endorse or promote products derived 15 * from this software without specific prior written permission. 16 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 18 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 19 * | 1/* 2 * PPP IP Control Protocol (IPCP) Module 3 * 4 * Written by Toshiharu OHNO (tony-o@iij.ad.jp) 5 * 6 * Copyright (C) 1993, Internet Initiative Japan, Inc. All rights reserverd. 7 * 8 * Redistribution and use in source and binary forms are permitted 9 * provided that the above copyright notice and this paragraph are 10 * duplicated in all such forms and that any documentation, 11 * advertising materials, and other materials related to such 12 * distribution and use acknowledge that the software was developed 13 * by the Internet Initiative Japan, Inc. The name of the 14 * IIJ may not be used to endorse or promote products derived 15 * from this software without specific prior written permission. 16 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 18 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 19 * |
20 * $Id: ipcp.c,v 1.66 1998/09/17 00:45:26 brian Exp $ | 20 * $Id: ipcp.c,v 1.67 1998/10/22 02:32:49 brian Exp $ |
21 * 22 * TODO: 23 * o More RFC1772 backward compatibility 24 */ 25#include <sys/param.h> 26#include <netinet/in_systm.h> 27#include <netinet/in.h> 28#include <netinet/ip.h> 29#include <arpa/inet.h> 30#include <sys/socket.h> | 21 * 22 * TODO: 23 * o More RFC1772 backward compatibility 24 */ 25#include <sys/param.h> 26#include <netinet/in_systm.h> 27#include <netinet/in.h> 28#include <netinet/ip.h> 29#include <arpa/inet.h> 30#include <sys/socket.h> |
31#include <net/route.h> |
|
31#include <netdb.h> 32#include <net/if.h> 33#include <sys/sockio.h> 34#include <sys/un.h> | 32#include <netdb.h> 33#include <net/if.h> 34#include <sys/sockio.h> 35#include <sys/un.h> |
36#include <arpa/nameser.h> |
|
35 36#include <fcntl.h> 37#include <resolv.h> 38#include <stdlib.h> 39#include <string.h> 40#include <sys/errno.h> 41#include <termios.h> 42#include <unistd.h> --- 409 unchanged lines hidden (view full) --- 452 ipcp->my_compproto = 0; 453 sl_compress_init(&ipcp->vj.cslc, ipcp->cfg.vj.slots - 1); 454 455 ipcp->peer_reject = 0; 456 ipcp->my_reject = 0; 457} 458 459static int | 37 38#include <fcntl.h> 39#include <resolv.h> 40#include <stdlib.h> 41#include <string.h> 42#include <sys/errno.h> 43#include <termios.h> 44#include <unistd.h> --- 409 unchanged lines hidden (view full) --- 454 ipcp->my_compproto = 0; 455 sl_compress_init(&ipcp->vj.cslc, ipcp->cfg.vj.slots - 1); 456 457 ipcp->peer_reject = 0; 458 ipcp->my_reject = 0; 459} 460 461static int |
462ipcp_doproxyall(struct bundle *bundle, 463 int (*proxyfun)(struct bundle *, struct in_addr, int), int s) 464{ 465 int n, ret; 466 struct sticky_route *rp; 467 struct in_addr addr; 468 struct ipcp *ipcp; 469 470 ipcp = &bundle->ncp.ipcp; 471 for (rp = ipcp->route; rp != NULL; rp = rp->next) { 472 if (ntohl(rp->mask.s_addr) == INADDR_BROADCAST) 473 continue; 474 n = INADDR_BROADCAST - ntohl(rp->mask.s_addr) - 1; 475 if (n > 0 && n <= 254 && rp->dst.s_addr != INADDR_ANY) { 476 addr = rp->dst; 477 while (n--) { 478 addr.s_addr = htonl(ntohl(addr.s_addr) + 1); 479 log_Printf(LogDEBUG, "ipcp_doproxyall: %s\n", inet_ntoa(addr)); 480 ret = (*proxyfun)(bundle, addr, s); 481 if (!ret) 482 return ret; 483 } 484 } 485 } 486 487 return 0; 488} 489 490static int |
|
460ipcp_SetIPaddress(struct bundle *bundle, struct in_addr myaddr, 461 struct in_addr hisaddr, int silent) 462{ | 491ipcp_SetIPaddress(struct bundle *bundle, struct in_addr myaddr, 492 struct in_addr hisaddr, int silent) 493{ |
494 static struct in_addr none = { INADDR_ANY }; |
|
463 struct in_addr mask, oaddr; 464 u_int32_t addr; 465 466 addr = htonl(myaddr.s_addr); 467 if (IN_CLASSA(addr)) 468 mask.s_addr = htonl(IN_CLASSA_NET); 469 else if (IN_CLASSB(addr)) 470 mask.s_addr = htonl(IN_CLASSB_NET); --- 10 unchanged lines hidden (view full) --- 481 IFACE_ADD_FIRST|IFACE_FORCE_ADD)) 482 return -1; 483 484 if (!Enabled(bundle, OPT_IFACEALIAS) && bundle->iface->in_addrs > 1 485 && myaddr.s_addr != oaddr.s_addr) 486 /* Nuke the old one */ 487 iface_inDelete(bundle->iface, oaddr); 488 | 495 struct in_addr mask, oaddr; 496 u_int32_t addr; 497 498 addr = htonl(myaddr.s_addr); 499 if (IN_CLASSA(addr)) 500 mask.s_addr = htonl(IN_CLASSA_NET); 501 else if (IN_CLASSB(addr)) 502 mask.s_addr = htonl(IN_CLASSB_NET); --- 10 unchanged lines hidden (view full) --- 513 IFACE_ADD_FIRST|IFACE_FORCE_ADD)) 514 return -1; 515 516 if (!Enabled(bundle, OPT_IFACEALIAS) && bundle->iface->in_addrs > 1 517 && myaddr.s_addr != oaddr.s_addr) 518 /* Nuke the old one */ 519 iface_inDelete(bundle->iface, oaddr); 520 |
521 if (bundle->ncp.ipcp.cfg.sendpipe > 0 || bundle->ncp.ipcp.cfg.recvpipe > 0) 522 bundle_SetRoute(bundle, RTM_CHANGE, hisaddr, myaddr, none, 0, 0); 523 |
|
489 if (Enabled(bundle, OPT_SROUTES)) 490 route_Change(bundle, bundle->ncp.ipcp.route, myaddr, hisaddr); 491 | 524 if (Enabled(bundle, OPT_SROUTES)) 525 route_Change(bundle, bundle->ncp.ipcp.route, myaddr, hisaddr); 526 |
492 if (Enabled(bundle, OPT_PROXY)) { | 527 if (Enabled(bundle, OPT_PROXY) || Enabled(bundle, OPT_PROXYALL)) { |
493 int s = ID0socket(AF_INET, SOCK_DGRAM, 0); 494 if (s < 0) 495 log_Printf(LogERROR, "ipcp_SetIPaddress: socket(): %s\n", 496 strerror(errno)); 497 else { | 528 int s = ID0socket(AF_INET, SOCK_DGRAM, 0); 529 if (s < 0) 530 log_Printf(LogERROR, "ipcp_SetIPaddress: socket(): %s\n", 531 strerror(errno)); 532 else { |
498 arp_SetProxy(bundle, hisaddr, s); | 533 if (Enabled(bundle, OPT_PROXYALL)) 534 ipcp_doproxyall(bundle, arp_SetProxy, s); 535 else if (Enabled(bundle, OPT_PROXY)) 536 arp_SetProxy(bundle, hisaddr, s); |
499 close(s); 500 } 501 } 502 503 return 0; 504} 505 506static struct in_addr --- 111 unchanged lines hidden (view full) --- 618 619void 620ipcp_CleanInterface(struct ipcp *ipcp) 621{ 622 struct iface *iface = ipcp->fsm.bundle->iface; 623 624 route_Clean(ipcp->fsm.bundle, ipcp->route); 625 | 537 close(s); 538 } 539 } 540 541 return 0; 542} 543 544static struct in_addr --- 111 unchanged lines hidden (view full) --- 656 657void 658ipcp_CleanInterface(struct ipcp *ipcp) 659{ 660 struct iface *iface = ipcp->fsm.bundle->iface; 661 662 route_Clean(ipcp->fsm.bundle, ipcp->route); 663 |
626 if (iface->in_addrs && Enabled(ipcp->fsm.bundle, OPT_PROXY)) { | 664 if (iface->in_addrs && (Enabled(ipcp->fsm.bundle, OPT_PROXY) || 665 Enabled(ipcp->fsm.bundle, OPT_PROXYALL))) { |
627 int s = ID0socket(AF_INET, SOCK_DGRAM, 0); 628 if (s < 0) 629 log_Printf(LogERROR, "ipcp_CleanInterface: socket: %s\n", 630 strerror(errno)); 631 else { | 666 int s = ID0socket(AF_INET, SOCK_DGRAM, 0); 667 if (s < 0) 668 log_Printf(LogERROR, "ipcp_CleanInterface: socket: %s\n", 669 strerror(errno)); 670 else { |
632 arp_ClearProxy(ipcp->fsm.bundle, iface->in_addr[0].brd, s); | 671 if (Enabled(ipcp->fsm.bundle, OPT_PROXYALL)) 672 ipcp_doproxyall(ipcp->fsm.bundle, arp_ClearProxy, s); 673 else if (Enabled(ipcp->fsm.bundle, OPT_PROXY)) 674 arp_ClearProxy(ipcp->fsm.bundle, iface->in_addr[0].brd, s); |
633 close(s); 634 } 635 } 636 637 iface_inClear(ipcp->fsm.bundle->iface, IFACE_CLEAR_ALL); 638} 639 640static void --- 471 unchanged lines hidden --- | 675 close(s); 676 } 677 } 678 679 iface_inClear(ipcp->fsm.bundle->iface, IFACE_CLEAR_ALL); 680} 681 682static void --- 471 unchanged lines hidden --- |