in.c (179971) | in.c (181803) |
---|---|
1/*- 2 * Copyright (c) 1982, 1986, 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * Copyright (C) 2001 WIDE Project. All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 17 unchanged lines hidden (view full) --- 26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * SUCH DAMAGE. 29 * 30 * @(#)in.c 8.4 (Berkeley) 1/9/95 31 */ 32 33#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 1982, 1986, 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * Copyright (C) 2001 WIDE Project. All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 17 unchanged lines hidden (view full) --- 26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * SUCH DAMAGE. 29 * 30 * @(#)in.c 8.4 (Berkeley) 1/9/95 31 */ 32 33#include <sys/cdefs.h> |
34__FBSDID("$FreeBSD: head/sys/netinet/in.c 179971 2008-06-24 13:58:28Z gonzo $"); | 34__FBSDID("$FreeBSD: head/sys/netinet/in.c 181803 2008-08-17 23:27:27Z bz $"); |
35 36#include "opt_carp.h" 37 38#include <sys/param.h> 39#include <sys/systm.h> 40#include <sys/sockio.h> 41#include <sys/malloc.h> 42#include <sys/priv.h> 43#include <sys/socket.h> 44#include <sys/kernel.h> 45#include <sys/sysctl.h> | 35 36#include "opt_carp.h" 37 38#include <sys/param.h> 39#include <sys/systm.h> 40#include <sys/sockio.h> 41#include <sys/malloc.h> 42#include <sys/priv.h> 43#include <sys/socket.h> 44#include <sys/kernel.h> 45#include <sys/sysctl.h> |
46#include <sys/vimage.h> |
|
46 47#include <net/if.h> 48#include <net/if_types.h> 49#include <net/route.h> 50 51#include <netinet/in.h> 52#include <netinet/in_var.h> 53#include <netinet/in_pcb.h> --- 29 unchanged lines hidden (view full) --- 83 * Otherwise, it includes only the directly-connected (sub)nets. 84 */ 85int 86in_localaddr(struct in_addr in) 87{ 88 register u_long i = ntohl(in.s_addr); 89 register struct in_ifaddr *ia; 90 | 47 48#include <net/if.h> 49#include <net/if_types.h> 50#include <net/route.h> 51 52#include <netinet/in.h> 53#include <netinet/in_var.h> 54#include <netinet/in_pcb.h> --- 29 unchanged lines hidden (view full) --- 84 * Otherwise, it includes only the directly-connected (sub)nets. 85 */ 86int 87in_localaddr(struct in_addr in) 88{ 89 register u_long i = ntohl(in.s_addr); 90 register struct in_ifaddr *ia; 91 |
91 if (subnetsarelocal) { 92 TAILQ_FOREACH(ia, &in_ifaddrhead, ia_link) | 92 if (V_subnetsarelocal) { 93 TAILQ_FOREACH(ia, &V_in_ifaddrhead, ia_link) |
93 if ((i & ia->ia_netmask) == ia->ia_net) 94 return (1); 95 } else { | 94 if ((i & ia->ia_netmask) == ia->ia_net) 95 return (1); 96 } else { |
96 TAILQ_FOREACH(ia, &in_ifaddrhead, ia_link) | 97 TAILQ_FOREACH(ia, &V_in_ifaddrhead, ia_link) |
97 if ((i & ia->ia_subnetmask) == ia->ia_subnet) 98 return (1); 99 } 100 return (0); 101} 102 103/* 104 * Return 1 if an internet address is for the local host and configured --- 218 unchanged lines hidden (view full) --- 323 ia->ia_sockmask.sin_len = 8; 324 ia->ia_sockmask.sin_family = AF_INET; 325 if (ifp->if_flags & IFF_BROADCAST) { 326 ia->ia_broadaddr.sin_len = sizeof(ia->ia_addr); 327 ia->ia_broadaddr.sin_family = AF_INET; 328 } 329 ia->ia_ifp = ifp; 330 | 98 if ((i & ia->ia_subnetmask) == ia->ia_subnet) 99 return (1); 100 } 101 return (0); 102} 103 104/* 105 * Return 1 if an internet address is for the local host and configured --- 218 unchanged lines hidden (view full) --- 324 ia->ia_sockmask.sin_len = 8; 325 ia->ia_sockmask.sin_family = AF_INET; 326 if (ifp->if_flags & IFF_BROADCAST) { 327 ia->ia_broadaddr.sin_len = sizeof(ia->ia_addr); 328 ia->ia_broadaddr.sin_family = AF_INET; 329 } 330 ia->ia_ifp = ifp; 331 |
331 TAILQ_INSERT_TAIL(&in_ifaddrhead, ia, ia_link); | 332 TAILQ_INSERT_TAIL(&V_in_ifaddrhead, ia, ia_link); |
332 splx(s); 333 iaIsNew = 1; 334 } 335 break; 336 337 case SIOCSIFBRDADDR: 338 if (td != NULL) { 339 error = priv_check(td, PRIV_NET_ADDIFADDR); --- 147 unchanged lines hidden (view full) --- 487 } 488 489 /* 490 * Protect from ipintr() traversing address list while we're modifying 491 * it. 492 */ 493 s = splnet(); 494 TAILQ_REMOVE(&ifp->if_addrhead, &ia->ia_ifa, ifa_link); | 333 splx(s); 334 iaIsNew = 1; 335 } 336 break; 337 338 case SIOCSIFBRDADDR: 339 if (td != NULL) { 340 error = priv_check(td, PRIV_NET_ADDIFADDR); --- 147 unchanged lines hidden (view full) --- 488 } 489 490 /* 491 * Protect from ipintr() traversing address list while we're modifying 492 * it. 493 */ 494 s = splnet(); 495 TAILQ_REMOVE(&ifp->if_addrhead, &ia->ia_ifa, ifa_link); |
495 TAILQ_REMOVE(&in_ifaddrhead, ia, ia_link); | 496 TAILQ_REMOVE(&V_in_ifaddrhead, ia, ia_link); |
496 if (ia->ia_addr.sin_family == AF_INET) { 497 LIST_REMOVE(ia, ia_hash); 498 /* 499 * If this is the last IPv4 address configured on this 500 * interface, leave the all-hosts group. 501 * XXX: This is quite ugly because of locking and structure. 502 */ 503 oia = NULL; --- 313 unchanged lines hidden (view full) --- 817 prefix = target->ia_dstaddr.sin_addr; 818 mask.s_addr = 0; 819 } else { 820 prefix = target->ia_addr.sin_addr; 821 mask = target->ia_sockmask.sin_addr; 822 prefix.s_addr &= mask.s_addr; 823 } 824 | 497 if (ia->ia_addr.sin_family == AF_INET) { 498 LIST_REMOVE(ia, ia_hash); 499 /* 500 * If this is the last IPv4 address configured on this 501 * interface, leave the all-hosts group. 502 * XXX: This is quite ugly because of locking and structure. 503 */ 504 oia = NULL; --- 313 unchanged lines hidden (view full) --- 818 prefix = target->ia_dstaddr.sin_addr; 819 mask.s_addr = 0; 820 } else { 821 prefix = target->ia_addr.sin_addr; 822 mask = target->ia_sockmask.sin_addr; 823 prefix.s_addr &= mask.s_addr; 824 } 825 |
825 TAILQ_FOREACH(ia, &in_ifaddrhead, ia_link) { | 826 TAILQ_FOREACH(ia, &V_in_ifaddrhead, ia_link) { |
826 if (rtinitflags(ia)) { 827 p = ia->ia_addr.sin_addr; 828 829 if (prefix.s_addr != p.s_addr) 830 continue; 831 } else { 832 p = ia->ia_addr.sin_addr; 833 m = ia->ia_sockmask.sin_addr; --- 4 unchanged lines hidden (view full) --- 838 continue; 839 } 840 841 /* 842 * If we got a matching prefix route inserted by other 843 * interface address, we are done here. 844 */ 845 if (ia->ia_flags & IFA_ROUTE) { | 827 if (rtinitflags(ia)) { 828 p = ia->ia_addr.sin_addr; 829 830 if (prefix.s_addr != p.s_addr) 831 continue; 832 } else { 833 p = ia->ia_addr.sin_addr; 834 m = ia->ia_sockmask.sin_addr; --- 4 unchanged lines hidden (view full) --- 839 continue; 840 } 841 842 /* 843 * If we got a matching prefix route inserted by other 844 * interface address, we are done here. 845 */ 846 if (ia->ia_flags & IFA_ROUTE) { |
846 if (sameprefixcarponly && | 847 if (V_sameprefixcarponly && |
847 target->ia_ifp->if_type != IFT_CARP && 848 ia->ia_ifp->if_type != IFT_CARP) 849 return (EEXIST); 850 else 851 return (0); 852 } 853 } 854 --- 24 unchanged lines hidden (view full) --- 879 if (rtinitflags(target)) 880 prefix = target->ia_dstaddr.sin_addr; 881 else { 882 prefix = target->ia_addr.sin_addr; 883 mask = target->ia_sockmask.sin_addr; 884 prefix.s_addr &= mask.s_addr; 885 } 886 | 848 target->ia_ifp->if_type != IFT_CARP && 849 ia->ia_ifp->if_type != IFT_CARP) 850 return (EEXIST); 851 else 852 return (0); 853 } 854 } 855 --- 24 unchanged lines hidden (view full) --- 880 if (rtinitflags(target)) 881 prefix = target->ia_dstaddr.sin_addr; 882 else { 883 prefix = target->ia_addr.sin_addr; 884 mask = target->ia_sockmask.sin_addr; 885 prefix.s_addr &= mask.s_addr; 886 } 887 |
887 TAILQ_FOREACH(ia, &in_ifaddrhead, ia_link) { | 888 TAILQ_FOREACH(ia, &V_in_ifaddrhead, ia_link) { |
888 if (rtinitflags(ia)) 889 p = ia->ia_dstaddr.sin_addr; 890 else { 891 p = ia->ia_addr.sin_addr; 892 p.s_addr &= ia->ia_sockmask.sin_addr.s_addr; 893 } 894 895 if (prefix.s_addr != p.s_addr) --- 82 unchanged lines hidden (view full) --- 978 struct in_multi *inm; 979 struct in_multi *oinm; 980 981#ifdef DIAGNOSTIC 982 printf("%s: purging ifp %p\n", __func__, ifp); 983#endif 984 IFF_LOCKGIANT(ifp); 985 IN_MULTI_LOCK(); | 889 if (rtinitflags(ia)) 890 p = ia->ia_dstaddr.sin_addr; 891 else { 892 p = ia->ia_addr.sin_addr; 893 p.s_addr &= ia->ia_sockmask.sin_addr.s_addr; 894 } 895 896 if (prefix.s_addr != p.s_addr) --- 82 unchanged lines hidden (view full) --- 979 struct in_multi *inm; 980 struct in_multi *oinm; 981 982#ifdef DIAGNOSTIC 983 printf("%s: purging ifp %p\n", __func__, ifp); 984#endif 985 IFF_LOCKGIANT(ifp); 986 IN_MULTI_LOCK(); |
986 LIST_FOREACH_SAFE(inm, &in_multihead, inm_link, oinm) { | 987 LIST_FOREACH_SAFE(inm, &V_in_multihead, inm_link, oinm) { |
987 if (inm->inm_ifp == ifp) 988 in_delmulti_locked(inm); 989 } 990 IN_MULTI_UNLOCK(); 991 IFF_UNLOCKGIANT(ifp); 992} 993 994/* 995 * On interface removal, clean up IPv4 data structures hung off of the ifnet. 996 */ 997void 998in_ifdetach(struct ifnet *ifp) 999{ 1000 | 988 if (inm->inm_ifp == ifp) 989 in_delmulti_locked(inm); 990 } 991 IN_MULTI_UNLOCK(); 992 IFF_UNLOCKGIANT(ifp); 993} 994 995/* 996 * On interface removal, clean up IPv4 data structures hung off of the ifnet. 997 */ 998void 999in_ifdetach(struct ifnet *ifp) 1000{ 1001 |
1001 in_pcbpurgeif0(&ripcbinfo, ifp); 1002 in_pcbpurgeif0(&udbinfo, ifp); | 1002 in_pcbpurgeif0(&V_ripcbinfo, ifp); 1003 in_pcbpurgeif0(&V_udbinfo, ifp); |
1003 in_purgemaddrs(ifp); 1004} | 1004 in_purgemaddrs(ifp); 1005} |