bundle.c (37018) | bundle.c (37019) |
---|---|
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.17 1998/06/15 19:06:01 brian Exp $ | 26 * $Id: bundle.c,v 1.18 1998/06/16 19:40:24 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> --- 125 unchanged lines hidden (view full) --- 160 ifrq.ifr_name[sizeof ifrq.ifr_name - 1] = '\0'; 161 while (ID0ioctl(s, SIOCGIFADDR, &ifrq) == 0) { 162 memset(&ifra.ifra_mask, '\0', sizeof ifra.ifra_mask); 163 strncpy(ifra.ifra_name, bundle->ifp.Name, sizeof ifra.ifra_name - 1); 164 ifra.ifra_name[sizeof ifra.ifra_name - 1] = '\0'; 165 ifra.ifra_addr = ifrq.ifr_addr; 166 if (ID0ioctl(s, SIOCGIFDSTADDR, &ifrq) < 0) { 167 if (ifra.ifra_addr.sa_family == AF_INET) | 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> --- 125 unchanged lines hidden (view full) --- 160 ifrq.ifr_name[sizeof ifrq.ifr_name - 1] = '\0'; 161 while (ID0ioctl(s, SIOCGIFADDR, &ifrq) == 0) { 162 memset(&ifra.ifra_mask, '\0', sizeof ifra.ifra_mask); 163 strncpy(ifra.ifra_name, bundle->ifp.Name, sizeof ifra.ifra_name - 1); 164 ifra.ifra_name[sizeof ifra.ifra_name - 1] = '\0'; 165 ifra.ifra_addr = ifrq.ifr_addr; 166 if (ID0ioctl(s, SIOCGIFDSTADDR, &ifrq) < 0) { 167 if (ifra.ifra_addr.sa_family == AF_INET) |
168 log_Printf(LogERROR, 169 "bundle_CleanInterface: Can't get dst for %s on %s !\n", | 168 log_Printf(LogERROR, "Can't get dst for %s on %s !\n", |
170 inet_ntoa(((struct sockaddr_in *)&ifra.ifra_addr)->sin_addr), 171 bundle->ifp.Name); 172 close(s); 173 return 0; 174 } 175 ifra.ifra_broadaddr = ifrq.ifr_dstaddr; 176 if (ID0ioctl(s, SIOCDIFADDR, &ifra) < 0) { 177 if (ifra.ifra_addr.sa_family == AF_INET) | 169 inet_ntoa(((struct sockaddr_in *)&ifra.ifra_addr)->sin_addr), 170 bundle->ifp.Name); 171 close(s); 172 return 0; 173 } 174 ifra.ifra_broadaddr = ifrq.ifr_dstaddr; 175 if (ID0ioctl(s, SIOCDIFADDR, &ifra) < 0) { 176 if (ifra.ifra_addr.sa_family == AF_INET) |
178 log_Printf(LogERROR, 179 "bundle_CleanInterface: Can't delete %s address on %s !\n", | 177 log_Printf(LogERROR, "Can't delete %s address on %s !\n", |
180 inet_ntoa(((struct sockaddr_in *)&ifra.ifra_addr)->sin_addr), 181 bundle->ifp.Name); 182 close(s); 183 return 0; 184 } 185 } 186 close(s); 187 --- 213 unchanged lines hidden (view full) --- 401 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); 405 406 if (lost) 407 mp_LinkLost(&bundle->ncp.mp, lost); 408 else | 178 inet_ntoa(((struct sockaddr_in *)&ifra.ifra_addr)->sin_addr), 179 bundle->ifp.Name); 180 close(s); 181 return 0; 182 } 183 } 184 close(s); 185 --- 213 unchanged lines hidden (view full) --- 399 400 if (bundle->ifp.Speed) 401 /* Don't configure down to a speed of 0 */ 402 tun_configure(bundle, bundle->ncp.mp.link.lcp.his_mru); 403 404 if (lost) 405 mp_LinkLost(&bundle->ncp.mp, lost); 406 else |
409 log_Printf(LogERROR, "Oops, lost an unrecognised datalink (%s) !\n", | 407 log_Printf(LogALERT, "Oops, lost an unrecognised datalink (%s) !\n", |
410 fp->link->name); 411 } 412 } 413} 414 415static void 416bundle_LayerFinish(void *v, struct fsm *fp) 417{ --- 193 unchanged lines hidden (view full) --- 611 612 if (FD_ISSET(bundle->dev.fd, fdset)) { 613 struct tun_data tun; 614 int n, pri; 615 616 /* something to read from tun */ 617 n = read(bundle->dev.fd, &tun, sizeof tun); 618 if (n < 0) { | 408 fp->link->name); 409 } 410 } 411} 412 413static void 414bundle_LayerFinish(void *v, struct fsm *fp) 415{ --- 193 unchanged lines hidden (view full) --- 609 610 if (FD_ISSET(bundle->dev.fd, fdset)) { 611 struct tun_data tun; 612 int n, pri; 613 614 /* something to read from tun */ 615 n = read(bundle->dev.fd, &tun, sizeof tun); 616 if (n < 0) { |
619 log_Printf(LogERROR, "read from %s: %s\n", TUN_NAME, strerror(errno)); | 617 log_Printf(LogWARN, "read from %s: %s\n", TUN_NAME, strerror(errno)); |
620 return; 621 } 622 n -= sizeof tun - sizeof tun.data; 623 if (n <= 0) { | 618 return; 619 } 620 n -= sizeof tun - sizeof tun.data; 621 if (n <= 0) { |
624 log_Printf(LogERROR, "read from %s: Only %d bytes read\n", TUN_NAME, n); | 622 log_Printf(LogERROR, "read from %s: Only %d bytes read ?\n", TUN_NAME, n); |
625 return; 626 } 627 if (!tun_check_header(tun, AF_INET)) 628 return; 629 630 if (((struct ip *)tun.data)->ip_dst.s_addr == 631 bundle->ncp.ipcp.my_ip.s_addr) { 632 /* we've been asked to send something addressed *to* us :( */ --- 100 unchanged lines hidden (view full) --- 733struct bundle * 734bundle_Create(const char *prefix, int type, const char **argv) 735{ 736 int s, enoentcount, err; 737 struct ifreq ifrq; 738 static struct bundle bundle; /* there can be only one */ 739 740 if (bundle.ifp.Name != NULL) { /* Already allocated ! */ | 623 return; 624 } 625 if (!tun_check_header(tun, AF_INET)) 626 return; 627 628 if (((struct ip *)tun.data)->ip_dst.s_addr == 629 bundle->ncp.ipcp.my_ip.s_addr) { 630 /* we've been asked to send something addressed *to* us :( */ --- 100 unchanged lines hidden (view full) --- 731struct bundle * 732bundle_Create(const char *prefix, int type, const char **argv) 733{ 734 int s, enoentcount, err; 735 struct ifreq ifrq; 736 static struct bundle bundle; /* there can be only one */ 737 738 if (bundle.ifp.Name != NULL) { /* Already allocated ! */ |
741 log_Printf(LogERROR, "bundle_Create: There's only one BUNDLE !\n"); | 739 log_Printf(LogALERT, "bundle_Create: There's only one BUNDLE !\n"); |
742 return NULL; 743 } 744 745 err = ENOENT; 746 enoentcount = 0; 747 for (bundle.unit = 0; ; bundle.unit++) { 748 snprintf(bundle.dev.Name, sizeof bundle.dev.Name, "%s%d", 749 prefix, bundle.unit); --- 34 unchanged lines hidden (view full) --- 784 785 /* 786 * Now, bring up the interface. 787 */ 788 memset(&ifrq, '\0', sizeof ifrq); 789 strncpy(ifrq.ifr_name, bundle.ifp.Name, sizeof ifrq.ifr_name - 1); 790 ifrq.ifr_name[sizeof ifrq.ifr_name - 1] = '\0'; 791 if (ID0ioctl(s, SIOCGIFFLAGS, &ifrq) < 0) { | 740 return NULL; 741 } 742 743 err = ENOENT; 744 enoentcount = 0; 745 for (bundle.unit = 0; ; bundle.unit++) { 746 snprintf(bundle.dev.Name, sizeof bundle.dev.Name, "%s%d", 747 prefix, bundle.unit); --- 34 unchanged lines hidden (view full) --- 782 783 /* 784 * Now, bring up the interface. 785 */ 786 memset(&ifrq, '\0', sizeof ifrq); 787 strncpy(ifrq.ifr_name, bundle.ifp.Name, sizeof ifrq.ifr_name - 1); 788 ifrq.ifr_name[sizeof ifrq.ifr_name - 1] = '\0'; 789 if (ID0ioctl(s, SIOCGIFFLAGS, &ifrq) < 0) { |
792 log_Printf(LogERROR, "OpenTunnel: ioctl(SIOCGIFFLAGS): %s\n", | 790 log_Printf(LogERROR, "bundle_Create: ioctl(SIOCGIFFLAGS): %s\n", |
793 strerror(errno)); 794 close(s); 795 close(bundle.dev.fd); 796 bundle.ifp.Name = NULL; 797 return NULL; 798 } 799 ifrq.ifr_flags |= IFF_UP; 800 if (ID0ioctl(s, SIOCSIFFLAGS, &ifrq) < 0) { | 791 strerror(errno)); 792 close(s); 793 close(bundle.dev.fd); 794 bundle.ifp.Name = NULL; 795 return NULL; 796 } 797 ifrq.ifr_flags |= IFF_UP; 798 if (ID0ioctl(s, SIOCSIFFLAGS, &ifrq) < 0) { |
801 log_Printf(LogERROR, "OpenTunnel: ioctl(SIOCSIFFLAGS): %s\n", | 799 log_Printf(LogERROR, "bundle_Create: ioctl(SIOCSIFFLAGS): %s\n", |
802 strerror(errno)); 803 close(s); 804 close(bundle.dev.fd); 805 bundle.ifp.Name = NULL; 806 return NULL; 807 } 808 809 close(s); 810 811 if ((bundle.ifp.Index = GetIfIndex(bundle.ifp.Name)) < 0) { | 800 strerror(errno)); 801 close(s); 802 close(bundle.dev.fd); 803 bundle.ifp.Name = NULL; 804 return NULL; 805 } 806 807 close(s); 808 809 if ((bundle.ifp.Index = GetIfIndex(bundle.ifp.Name)) < 0) { |
812 log_Printf(LogERROR, "OpenTunnel: Can't find interface index.\n"); | 810 log_Printf(LogERROR, "Can't find interface index.\n"); |
813 close(bundle.dev.fd); 814 bundle.ifp.Name = NULL; 815 return NULL; 816 } 817 log_Printf(LogPHASE, "Using interface: %s\n", bundle.ifp.Name); 818 819 bundle.ifp.Speed = 0; 820 --- 18 unchanged lines hidden (view full) --- 839 bundle.cfg.autoload.max.timeout = 0; 840 bundle.cfg.autoload.min.packets = 0; 841 bundle.cfg.autoload.min.timeout = 0; 842 bundle.phys_type.all = type; 843 bundle.phys_type.open = 0; 844 845 bundle.links = datalink_Create("deflink", &bundle, type); 846 if (bundle.links == NULL) { | 811 close(bundle.dev.fd); 812 bundle.ifp.Name = NULL; 813 return NULL; 814 } 815 log_Printf(LogPHASE, "Using interface: %s\n", bundle.ifp.Name); 816 817 bundle.ifp.Speed = 0; 818 --- 18 unchanged lines hidden (view full) --- 837 bundle.cfg.autoload.max.timeout = 0; 838 bundle.cfg.autoload.min.packets = 0; 839 bundle.cfg.autoload.min.timeout = 0; 840 bundle.phys_type.all = type; 841 bundle.phys_type.open = 0; 842 843 bundle.links = datalink_Create("deflink", &bundle, type); 844 if (bundle.links == NULL) { |
847 log_Printf(LogERROR, "Cannot create data link: %s\n", strerror(errno)); | 845 log_Printf(LogALERT, "Cannot create data link: %s\n", strerror(errno)); |
848 close(bundle.dev.fd); 849 bundle.ifp.Name = NULL; 850 return NULL; 851 } 852 853 bundle.desc.type = BUNDLE_DESCRIPTOR; 854 bundle.desc.UpdateSet = bundle_UpdateSet; 855 bundle.desc.IsSet = bundle_IsSet; --- 772 unchanged lines hidden (view full) --- 1628 read(fds[1], &done, 1); /* uu_locks are mine ! */ 1629 close(fds[1]); 1630 if (pipe(fds) == -1) { 1631 log_Printf(LogERROR, "pipe(2): %s\n", strerror(errno)); 1632 return; 1633 } 1634 switch ((pid = fork())) { 1635 case -1: | 846 close(bundle.dev.fd); 847 bundle.ifp.Name = NULL; 848 return NULL; 849 } 850 851 bundle.desc.type = BUNDLE_DESCRIPTOR; 852 bundle.desc.UpdateSet = bundle_UpdateSet; 853 bundle.desc.IsSet = bundle_IsSet; --- 772 unchanged lines hidden (view full) --- 1626 read(fds[1], &done, 1); /* uu_locks are mine ! */ 1627 close(fds[1]); 1628 if (pipe(fds) == -1) { 1629 log_Printf(LogERROR, "pipe(2): %s\n", strerror(errno)); 1630 return; 1631 } 1632 switch ((pid = fork())) { 1633 case -1: |
1636 log_Printf(LogERROR, "fork: %s\n", strerror(errno)); | 1634 log_Printf(LogERROR, "fork(2): %s\n", strerror(errno)); |
1637 close(fds[0]); 1638 close(fds[1]); 1639 return; 1640 case 0: 1641 close(fds[0]); 1642 bundle_LockTun(bundle); /* update pid */ 1643 read(fds[1], &done, 1); /* uu_locks are mine ! */ 1644 close(fds[1]); --- 60 unchanged lines hidden --- | 1635 close(fds[0]); 1636 close(fds[1]); 1637 return; 1638 case 0: 1639 close(fds[0]); 1640 bundle_LockTun(bundle); /* update pid */ 1641 read(fds[1], &done, 1); /* uu_locks are mine ! */ 1642 close(fds[1]); --- 60 unchanged lines hidden --- |