route6d.c (62607) | route6d.c (62921) |
---|---|
1/* $FreeBSD: head/usr.sbin/route6d/route6d.c 62607 2000-07-05 02:14:16Z itojun $ */ | 1/* $FreeBSD: head/usr.sbin/route6d/route6d.c 62921 2000-07-10 18:27:55Z ume $ */ |
2/* $KAME: route6d.c,v 1.30 2000/06/04 06:48:03 itojun Exp $ */ 3 4/* 5 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions --- 42 unchanged lines hidden (view full) --- 52#include <err.h> 53 54#include <sys/types.h> 55#include <sys/param.h> 56#include <sys/file.h> 57#include <sys/socket.h> 58#include <sys/ioctl.h> 59#include <sys/sysctl.h> | 2/* $KAME: route6d.c,v 1.30 2000/06/04 06:48:03 itojun Exp $ */ 3 4/* 5 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions --- 42 unchanged lines hidden (view full) --- 52#include <err.h> 53 54#include <sys/types.h> 55#include <sys/param.h> 56#include <sys/file.h> 57#include <sys/socket.h> 58#include <sys/ioctl.h> 59#include <sys/sysctl.h> |
60#ifdef ADVAPI | |
61#include <sys/uio.h> | 60#include <sys/uio.h> |
62#endif | |
63#include <net/if.h> 64#if defined(__FreeBSD__) && __FreeBSD__ >= 3 65#include <net/if_var.h> 66#endif /* __FreeBSD__ >= 3 */ 67#define KERNEL 1 68#define _KERNEL 1 69#include <net/route.h> 70#undef KERNEL --- 440 unchanged lines hidden (view full) --- 511 ripsend(ifcp, &ifcp->ifc_ripsin, 0); 512 } 513 alarm(ripinterval(SUPPLY_INTERVAL6)); 514} 515 516void 517init() 518{ | 61#include <net/if.h> 62#if defined(__FreeBSD__) && __FreeBSD__ >= 3 63#include <net/if_var.h> 64#endif /* __FreeBSD__ >= 3 */ 65#define KERNEL 1 66#define _KERNEL 1 67#include <net/route.h> 68#undef KERNEL --- 440 unchanged lines hidden (view full) --- 509 ripsend(ifcp, &ifcp->ifc_ripsin, 0); 510 } 511 alarm(ripinterval(SUPPLY_INTERVAL6)); 512} 513 514void 515init() 516{ |
519#ifdef ADVAPI 520 int i; 521#endif 522 int int0, int255, error; | 517 int i, int0, int255, error; |
523 struct addrinfo hints, *res; 524 char port[10]; 525 526 ifc = (struct ifc *)NULL; 527 nifc = 0; 528 nindex2ifc = 0; /*initial guess*/ 529 index2ifc = NULL; 530 snprintf(port, sizeof(port), "%d", RIP6_PORT); --- 15 unchanged lines hidden (view full) --- 546 if (bind(ripsock, res->ai_addr, res->ai_addrlen) < 0) 547 fatal("rip bind"); 548 if (setsockopt(ripsock, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, 549 &int255, sizeof(int255)) < 0) 550 fatal("rip IPV6_MULTICAST_HOPS"); 551 if (setsockopt(ripsock, IPPROTO_IPV6, IPV6_MULTICAST_LOOP, 552 &int0, sizeof(int0)) < 0) 553 fatal("rip IPV6_MULTICAST_LOOP"); | 518 struct addrinfo hints, *res; 519 char port[10]; 520 521 ifc = (struct ifc *)NULL; 522 nifc = 0; 523 nindex2ifc = 0; /*initial guess*/ 524 index2ifc = NULL; 525 snprintf(port, sizeof(port), "%d", RIP6_PORT); --- 15 unchanged lines hidden (view full) --- 541 if (bind(ripsock, res->ai_addr, res->ai_addrlen) < 0) 542 fatal("rip bind"); 543 if (setsockopt(ripsock, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, 544 &int255, sizeof(int255)) < 0) 545 fatal("rip IPV6_MULTICAST_HOPS"); 546 if (setsockopt(ripsock, IPPROTO_IPV6, IPV6_MULTICAST_LOOP, 547 &int0, sizeof(int0)) < 0) 548 fatal("rip IPV6_MULTICAST_LOOP"); |
554#ifdef ADVAPI | 549 |
555 i = 1; 556#ifdef IPV6_RECVPKTINFO 557 if (setsockopt(ripsock, IPPROTO_IPV6, IPV6_RECVPKTINFO, &i, 558 sizeof(i)) < 0) 559 fatal("rip IPV6_RECVPKTINFO"); 560#else /* old adv. API */ 561 if (setsockopt(ripsock, IPPROTO_IPV6, IPV6_PKTINFO, &i, 562 sizeof(i)) < 0) 563 fatal("rip IPV6_PKTINFO"); 564#endif | 550 i = 1; 551#ifdef IPV6_RECVPKTINFO 552 if (setsockopt(ripsock, IPPROTO_IPV6, IPV6_RECVPKTINFO, &i, 553 sizeof(i)) < 0) 554 fatal("rip IPV6_RECVPKTINFO"); 555#else /* old adv. API */ 556 if (setsockopt(ripsock, IPPROTO_IPV6, IPV6_PKTINFO, &i, 557 sizeof(i)) < 0) 558 fatal("rip IPV6_PKTINFO"); 559#endif |
565#endif /*ADVAPI*/ | |
566 567 memset(&hints, 0, sizeof(hints)); 568 hints.ai_family = PF_INET6; 569 hints.ai_socktype = SOCK_DGRAM; 570 error = getaddrinfo(RIP6_DEST, port, &hints, &res); 571 if (error) 572 fatal(gai_strerror(error)); 573 if (res->ai_next) --- 252 unchanged lines hidden (view full) --- 826 struct sockaddr_in6 *sin; 827 int len; 828{ 829 /* 830 * MSG_DONTROUTE should not be specified when it responds with a 831 * RIP6_REQUEST message. SO_DONTROUTE has been specified to 832 * other sockets. 833 */ | 560 561 memset(&hints, 0, sizeof(hints)); 562 hints.ai_family = PF_INET6; 563 hints.ai_socktype = SOCK_DGRAM; 564 error = getaddrinfo(RIP6_DEST, port, &hints, &res); 565 if (error) 566 fatal(gai_strerror(error)); 567 if (res->ai_next) --- 252 unchanged lines hidden (view full) --- 820 struct sockaddr_in6 *sin; 821 int len; 822{ 823 /* 824 * MSG_DONTROUTE should not be specified when it responds with a 825 * RIP6_REQUEST message. SO_DONTROUTE has been specified to 826 * other sockets. 827 */ |
834#ifdef ADVAPI | |
835 struct msghdr m; 836 struct cmsghdr *cm; 837 struct iovec iov[2]; 838 u_char cmsgbuf[256]; 839 struct in6_pktinfo *pi; 840 int index; 841 struct sockaddr_in6 sincopy; 842 --- 30 unchanged lines hidden (view full) --- 873 memset(&pi->ipi6_addr, 0, sizeof(pi->ipi6_addr)); /*::*/ 874 pi->ipi6_ifindex = index; 875 } 876 877 if (sendmsg(ripsock, &m, 0 /*MSG_DONTROUTE*/) < 0) { 878 trace(1, "sendmsg: %s\n", strerror(errno)); 879 return errno; 880 } | 828 struct msghdr m; 829 struct cmsghdr *cm; 830 struct iovec iov[2]; 831 u_char cmsgbuf[256]; 832 struct in6_pktinfo *pi; 833 int index; 834 struct sockaddr_in6 sincopy; 835 --- 30 unchanged lines hidden (view full) --- 866 memset(&pi->ipi6_addr, 0, sizeof(pi->ipi6_addr)); /*::*/ 867 pi->ipi6_ifindex = index; 868 } 869 870 if (sendmsg(ripsock, &m, 0 /*MSG_DONTROUTE*/) < 0) { 871 trace(1, "sendmsg: %s\n", strerror(errno)); 872 return errno; 873 } |
881#else 882 if (sendto(ripsock, ripbuf, len, 0 /*MSG_DONTROUTE*/, 883 (struct sockaddr *)sin, sizeof(struct sockaddr_in6)) < 0) { 884 trace(1, "sendto: %s\n", strerror(errno)); 885 return errno; 886 } 887#endif | 874 |
888 return 0; 889} 890 891/* 892 * Receive and process RIP packets. Update the routes/kernel forwarding 893 * table if necessary. 894 */ 895void 896riprecv() 897{ 898 struct ifc *ifcp, *ic; 899 struct sockaddr_in6 fsock; 900 struct in6_addr nh; /* next hop */ 901 struct rip6 *rp; 902 struct netinfo6 *np, *nq; 903 struct riprt *rrt; 904 int len, nn, need_trigger, index; | 875 return 0; 876} 877 878/* 879 * Receive and process RIP packets. Update the routes/kernel forwarding 880 * table if necessary. 881 */ 882void 883riprecv() 884{ 885 struct ifc *ifcp, *ic; 886 struct sockaddr_in6 fsock; 887 struct in6_addr nh; /* next hop */ 888 struct rip6 *rp; 889 struct netinfo6 *np, *nq; 890 struct riprt *rrt; 891 int len, nn, need_trigger, index; |
905#ifndef ADVAPI 906 int flen; 907#endif | |
908 char buf[4 * RIP6_MAXMTU]; 909 time_t t; | 892 char buf[4 * RIP6_MAXMTU]; 893 time_t t; |
910#ifdef ADVAPI | |
911 struct msghdr m; 912 struct cmsghdr *cm; 913 struct iovec iov[2]; 914 u_char cmsgbuf[256]; 915 struct in6_pktinfo *pi; | 894 struct msghdr m; 895 struct cmsghdr *cm; 896 struct iovec iov[2]; 897 u_char cmsgbuf[256]; 898 struct in6_pktinfo *pi; |
916#endif /*ADVAPI*/ | |
917 struct iff *iffp; 918 struct in6_addr ia; 919 int ok; 920 921 need_trigger = 0; | 899 struct iff *iffp; 900 struct in6_addr ia; 901 int ok; 902 903 need_trigger = 0; |
922#ifdef ADVAPI | 904 |
923 m.msg_name = (caddr_t)&fsock; 924 m.msg_namelen = sizeof(fsock); 925 iov[0].iov_base = (caddr_t)buf; 926 iov[0].iov_len = sizeof(buf); 927 m.msg_iov = iov; 928 m.msg_iovlen = 1; 929 cm = (struct cmsghdr *)cmsgbuf; 930 m.msg_control = (caddr_t)cm; --- 8 unchanged lines hidden (view full) --- 939 && cm->cmsg_type == IPV6_PKTINFO) { 940 pi = (struct in6_pktinfo *)(CMSG_DATA(cm)); 941 index = pi->ipi6_ifindex; 942 break; 943 } 944 } 945 if (index && IN6_IS_ADDR_LINKLOCAL(&fsock.sin6_addr)) 946 SET_IN6_LINKLOCAL_IFINDEX(fsock.sin6_addr, index); | 905 m.msg_name = (caddr_t)&fsock; 906 m.msg_namelen = sizeof(fsock); 907 iov[0].iov_base = (caddr_t)buf; 908 iov[0].iov_len = sizeof(buf); 909 m.msg_iov = iov; 910 m.msg_iovlen = 1; 911 cm = (struct cmsghdr *)cmsgbuf; 912 m.msg_control = (caddr_t)cm; --- 8 unchanged lines hidden (view full) --- 921 && cm->cmsg_type == IPV6_PKTINFO) { 922 pi = (struct in6_pktinfo *)(CMSG_DATA(cm)); 923 index = pi->ipi6_ifindex; 924 break; 925 } 926 } 927 if (index && IN6_IS_ADDR_LINKLOCAL(&fsock.sin6_addr)) 928 SET_IN6_LINKLOCAL_IFINDEX(fsock.sin6_addr, index); |
947#else 948 flen = sizeof(struct sockaddr_in6); 949 if ((len = recvfrom(ripsock, buf, sizeof(buf), 0, 950 (struct sockaddr *)&fsock, &flen)) < 0) 951 fatal("recvfrom"); 952 if (IN6_IS_ADDR_LINKLOCAL(&fsock.sin6_addr)) 953 index = IN6_LINKLOCAL_IFINDEX(fsock.sin6_addr); 954 else 955 index = 0; 956#endif /*ADVAPI*/ | |
957 958 nh = fsock.sin6_addr; 959 nn = (len - sizeof(struct rip6) + sizeof(struct netinfo6)) / 960 sizeof(struct netinfo6); 961 rp = (struct rip6 *)buf; 962 np = rp->rip6_nets; 963 964 if (rp->rip6_vers != RIP6_VERSION) { --- 2201 unchanged lines hidden --- | 929 930 nh = fsock.sin6_addr; 931 nn = (len - sizeof(struct rip6) + sizeof(struct netinfo6)) / 932 sizeof(struct netinfo6); 933 rp = (struct rip6 *)buf; 934 np = rp->rip6_nets; 935 936 if (rp->rip6_vers != RIP6_VERSION) { --- 2201 unchanged lines hidden --- |