if.c (108533) | if.c (126250) |
---|---|
1/* 2 * Copyright (c) 1983, 1993 3 * The Regents of the University of California. 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 --- 16 unchanged lines hidden (view full) --- 25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * | 1/* 2 * Copyright (c) 1983, 1993 3 * The Regents of the University of California. 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 --- 16 unchanged lines hidden (view full) --- 25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * |
33 * $FreeBSD: head/sbin/routed/if.c 108533 2003-01-01 18:49:04Z schweikh $ | 33 * $FreeBSD: head/sbin/routed/if.c 126250 2004-02-25 23:45:57Z bms $ |
34 */ 35 36#include "defs.h" 37#include "pathnames.h" 38 | 34 */ 35 36#include "defs.h" 37#include "pathnames.h" 38 |
39#if !defined(sgi) && !defined(__NetBSD__) 40static char sccsid[] __attribute__((unused)) = "@(#)if.c 8.1 (Berkeley) 6/5/93"; 41#elif defined(__NetBSD__) 42#include <sys/cdefs.h> | 39#ifdef __NetBSD__ |
43__RCSID("$NetBSD$"); | 40__RCSID("$NetBSD$"); |
41#elif defined(__FreeBSD__) 42__RCSID("$FreeBSD: head/sbin/routed/if.c 126250 2004-02-25 23:45:57Z bms $"); 43#else 44__RCSID("$Revision: 2.27 $"); 45#ident "$Revision: 2.27 $" |
|
44#endif | 46#endif |
45#ident "$FreeBSD: head/sbin/routed/if.c 108533 2003-01-01 18:49:04Z schweikh $" 46 | 47#ident "$FreeBSD: head/sbin/routed/if.c 126250 2004-02-25 23:45:57Z bms $" |
47struct interface *ifnet; /* all interfaces */ 48 49/* hash table for all interfaces, big enough to tolerate ridiculous 50 * numbers of IP aliases. Crazy numbers of aliases such as 7000 51 * still will not do well, but not just in looking up interfaces 52 * by name or address. 53 */ 54#define AHASH_LEN 211 /* must be prime */ --- 154 unchanged lines hidden (view full) --- 209 if (IF_RESCAN_DELAY()) 210 return 0; 211 ifinit(); 212 } 213} 214 215 216struct interface * | 48struct interface *ifnet; /* all interfaces */ 49 50/* hash table for all interfaces, big enough to tolerate ridiculous 51 * numbers of IP aliases. Crazy numbers of aliases such as 7000 52 * still will not do well, but not just in looking up interfaces 53 * by name or address. 54 */ 55#define AHASH_LEN 211 /* must be prime */ --- 154 unchanged lines hidden (view full) --- 210 if (IF_RESCAN_DELAY()) 211 return 0; 212 ifinit(); 213 } 214} 215 216 217struct interface * |
217ifwithindex(u_short index, | 218ifwithindex(u_short ifindex, |
218 int rescan_ok) 219{ 220 struct interface *ifp; 221 222 for (;;) { 223 for (ifp = ifnet; 0 != ifp; ifp = ifp->int_next) { | 219 int rescan_ok) 220{ 221 struct interface *ifp; 222 223 for (;;) { 224 for (ifp = ifnet; 0 != ifp; ifp = ifp->int_next) { |
224 if (ifp->int_index == index) | 225 if (ifp->int_index == ifindex) |
225 return ifp; 226 } 227 228 /* If there is no known interface, maybe there is a 229 * new interface. So just once look for new interfaces. 230 */ 231 if (!rescan_ok 232 || IF_RESCAN_DELAY()) --- 6 unchanged lines hidden (view full) --- 239/* Find an interface from which the specified address 240 * should have come from. Used for figuring out which 241 * interface a packet came in on. 242 */ 243struct interface * 244iflookup(naddr addr) 245{ 246 struct interface *ifp, *maybe; | 226 return ifp; 227 } 228 229 /* If there is no known interface, maybe there is a 230 * new interface. So just once look for new interfaces. 231 */ 232 if (!rescan_ok 233 || IF_RESCAN_DELAY()) --- 6 unchanged lines hidden (view full) --- 240/* Find an interface from which the specified address 241 * should have come from. Used for figuring out which 242 * interface a packet came in on. 243 */ 244struct interface * 245iflookup(naddr addr) 246{ 247 struct interface *ifp, *maybe; |
248 int once = 0; |
|
247 248 maybe = 0; 249 for (;;) { 250 for (ifp = ifnet; ifp; ifp = ifp->int_next) { 251 if (ifp->int_if_flags & IFF_POINTOPOINT) { 252 /* finished with a match */ 253 if (ifp->int_dstaddr == addr) 254 return ifp; --- 7 unchanged lines hidden (view full) --- 262 */ 263 if (on_net(addr, ifp->int_net, ifp->int_mask) 264 && (maybe == 0 265 || ifp->int_mask > maybe->int_mask)) 266 maybe = ifp; 267 } 268 } 269 | 249 250 maybe = 0; 251 for (;;) { 252 for (ifp = ifnet; ifp; ifp = ifp->int_next) { 253 if (ifp->int_if_flags & IFF_POINTOPOINT) { 254 /* finished with a match */ 255 if (ifp->int_dstaddr == addr) 256 return ifp; --- 7 unchanged lines hidden (view full) --- 264 */ 265 if (on_net(addr, ifp->int_net, ifp->int_mask) 266 && (maybe == 0 267 || ifp->int_mask > maybe->int_mask)) 268 maybe = ifp; 269 } 270 } 271 |
270 if (maybe != 0 271 || IF_RESCAN_DELAY()) | 272 if (maybe != 0 || once || IF_RESCAN_DELAY()) |
272 return maybe; | 273 return maybe; |
274 once = 1; |
|
273 274 /* If there is no known interface, maybe there is a 275 * new interface. So just once look for new interfaces. 276 */ 277 ifinit(); 278 } 279} 280 --- 120 unchanged lines hidden (view full) --- 401 continue; 402 403 if (!iff_up(ifp->int_if_flags)) 404 continue; 405 406 /* The local address can only be shared with a point-to-point 407 * link. 408 */ | 275 276 /* If there is no known interface, maybe there is a 277 * new interface. So just once look for new interfaces. 278 */ 279 ifinit(); 280 } 281} 282 --- 120 unchanged lines hidden (view full) --- 403 continue; 404 405 if (!iff_up(ifp->int_if_flags)) 406 continue; 407 408 /* The local address can only be shared with a point-to-point 409 * link. 410 */ |
409 if (ifp->int_addr == addr | 411 if ((!(ifp->int_state & IS_REMOTE) || !(if_flags & IS_REMOTE)) 412 && ifp->int_addr == addr |
410 && (((if_flags|ifp->int_if_flags) & IFF_POINTOPOINT) == 0)) 411 return ifp; 412 413 if (on_net(ifp->int_dstaddr, ntohl(dstaddr),mask)) 414 return ifp; 415 } 416 return 0; 417} --- 75 unchanged lines hidden (view full) --- 493 } 494 495 if ((ifp->int_if_flags & IFF_MULTICAST) 496#ifdef MCAST_PPP_BUG 497 && !(ifp->int_if_flags & IFF_POINTOPOINT) 498#endif 499 && rip_sock >= 0) { 500 m.imr_multiaddr.s_addr = htonl(INADDR_RIP_GROUP); | 413 && (((if_flags|ifp->int_if_flags) & IFF_POINTOPOINT) == 0)) 414 return ifp; 415 416 if (on_net(ifp->int_dstaddr, ntohl(dstaddr),mask)) 417 return ifp; 418 } 419 return 0; 420} --- 75 unchanged lines hidden (view full) --- 496 } 497 498 if ((ifp->int_if_flags & IFF_MULTICAST) 499#ifdef MCAST_PPP_BUG 500 && !(ifp->int_if_flags & IFF_POINTOPOINT) 501#endif 502 && rip_sock >= 0) { 503 m.imr_multiaddr.s_addr = htonl(INADDR_RIP_GROUP); |
504#ifdef MCAST_IFINDEX 505 m.imr_interface.s_addr = htonl(ifp->int_index); 506#else |
|
501 m.imr_interface.s_addr = ((ifp->int_if_flags 502 & IFF_POINTOPOINT) 503 ? ifp->int_dstaddr 504 : ifp->int_addr); | 507 m.imr_interface.s_addr = ((ifp->int_if_flags 508 & IFF_POINTOPOINT) 509 ? ifp->int_dstaddr 510 : ifp->int_addr); |
511#endif |
|
505 if (setsockopt(rip_sock,IPPROTO_IP,IP_DROP_MEMBERSHIP, 506 &m, sizeof(m)) < 0 507 && errno != EADDRNOTAVAIL 508 && !TRACEACTIONS) 509 LOGERR("setsockopt(IP_DROP_MEMBERSHIP RIP)"); 510 if (rip_sock_mcast == ifp) 511 rip_sock_mcast = 0; 512 } --- 219 unchanged lines hidden (view full) --- 732 733 ifam_lim = (struct ifa_msghdr *)(sysctl_buf + needed); 734 for (ifam = (struct ifa_msghdr *)sysctl_buf; 735 ifam < ifam_lim; 736 ifam = ifam2) { 737 738 ifam2 = (struct ifa_msghdr*)((char*)ifam + ifam->ifam_msglen); 739 | 512 if (setsockopt(rip_sock,IPPROTO_IP,IP_DROP_MEMBERSHIP, 513 &m, sizeof(m)) < 0 514 && errno != EADDRNOTAVAIL 515 && !TRACEACTIONS) 516 LOGERR("setsockopt(IP_DROP_MEMBERSHIP RIP)"); 517 if (rip_sock_mcast == ifp) 518 rip_sock_mcast = 0; 519 } --- 219 unchanged lines hidden (view full) --- 739 740 ifam_lim = (struct ifa_msghdr *)(sysctl_buf + needed); 741 for (ifam = (struct ifa_msghdr *)sysctl_buf; 742 ifam < ifam_lim; 743 ifam = ifam2) { 744 745 ifam2 = (struct ifa_msghdr*)((char*)ifam + ifam->ifam_msglen); 746 |
747#ifdef RTM_OIFINFO 748 if (ifam->ifam_type == RTM_OIFINFO) 749 continue; /* just ignore compat message */ 750#endif |
|
740 if (ifam->ifam_type == RTM_IFINFO) { 741 struct sockaddr_dl *sdl; 742 743 ifm = (struct if_msghdr *)ifam; 744 /* make prototype structure for the IP aliases 745 */ 746 memset(&ifs0, 0, sizeof(ifs0)); 747 ifs0.int_rip_sock = -1; --- 658 unchanged lines hidden --- | 751 if (ifam->ifam_type == RTM_IFINFO) { 752 struct sockaddr_dl *sdl; 753 754 ifm = (struct if_msghdr *)ifam; 755 /* make prototype structure for the IP aliases 756 */ 757 memset(&ifs0, 0, sizeof(ifs0)); 758 ifs0.int_rip_sock = -1; --- 658 unchanged lines hidden --- |