in_pcb.c (192116) | in_pcb.c (192895) |
---|---|
1/*- 2 * Copyright (c) 1982, 1986, 1991, 1993, 1995 3 * The Regents of the University of California. 4 * Copyright (c) 2007-2009 Robert N. M. Watson 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions --- 18 unchanged lines hidden (view full) --- 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 * SUCH DAMAGE. 30 * 31 * @(#)in_pcb.c 8.4 (Berkeley) 5/24/95 32 */ 33 34#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 1982, 1986, 1991, 1993, 1995 3 * The Regents of the University of California. 4 * Copyright (c) 2007-2009 Robert N. M. Watson 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions --- 18 unchanged lines hidden (view full) --- 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 * SUCH DAMAGE. 30 * 31 * @(#)in_pcb.c 8.4 (Berkeley) 5/24/95 32 */ 33 34#include <sys/cdefs.h> |
35__FBSDID("$FreeBSD: head/sys/netinet/in_pcb.c 192116 2009-05-14 20:59:36Z rwatson $"); | 35__FBSDID("$FreeBSD: head/sys/netinet/in_pcb.c 192895 2009-05-27 14:11:23Z jamie $"); |
36 37#include "opt_ddb.h" 38#include "opt_inet.h" 39#include "opt_ipsec.h" 40#include "opt_inet6.h" 41#include "opt_mac.h" 42 43#include <sys/param.h> --- 553 unchanged lines hidden (view full) --- 597 ia = ifatoia(ifa_ifwithdstaddr((struct sockaddr *)sin)); 598 if (ia == NULL) 599 ia = ifatoia(ifa_ifwithnet((struct sockaddr *)sin)); 600 if (ia == NULL) { 601 error = ENETUNREACH; 602 goto done; 603 } 604 | 36 37#include "opt_ddb.h" 38#include "opt_inet.h" 39#include "opt_ipsec.h" 40#include "opt_inet6.h" 41#include "opt_mac.h" 42 43#include <sys/param.h> --- 553 unchanged lines hidden (view full) --- 597 ia = ifatoia(ifa_ifwithdstaddr((struct sockaddr *)sin)); 598 if (ia == NULL) 599 ia = ifatoia(ifa_ifwithnet((struct sockaddr *)sin)); 600 if (ia == NULL) { 601 error = ENETUNREACH; 602 goto done; 603 } 604 |
605 if (cred == NULL || !jailed(cred)) { | 605 if (cred == NULL || !prison_flag(cred, PR_IP4)) { |
606 laddr->s_addr = ia->ia_addr.sin_addr.s_addr; 607 goto done; 608 } 609 610 ifp = ia->ia_ifp; 611 ia = NULL; 612 IF_ADDR_LOCK(ifp); 613 TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) { --- 27 unchanged lines hidden (view full) --- 641 * 2. check if we have any address on the outgoing interface 642 * belonging to this jail. If so use it. 643 * 3. as a last resort return the 'default' jail address. 644 */ 645 if ((sro.ro_rt->rt_ifp->if_flags & IFF_LOOPBACK) == 0) { 646 struct ifnet *ifp; 647 648 /* If not jailed, use the default returned. */ | 606 laddr->s_addr = ia->ia_addr.sin_addr.s_addr; 607 goto done; 608 } 609 610 ifp = ia->ia_ifp; 611 ia = NULL; 612 IF_ADDR_LOCK(ifp); 613 TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) { --- 27 unchanged lines hidden (view full) --- 641 * 2. check if we have any address on the outgoing interface 642 * belonging to this jail. If so use it. 643 * 3. as a last resort return the 'default' jail address. 644 */ 645 if ((sro.ro_rt->rt_ifp->if_flags & IFF_LOOPBACK) == 0) { 646 struct ifnet *ifp; 647 648 /* If not jailed, use the default returned. */ |
649 if (cred == NULL || !jailed(cred)) { | 649 if (cred == NULL || !prison_flag(cred, PR_IP4)) { |
650 ia = (struct in_ifaddr *)sro.ro_rt->rt_ifa; 651 laddr->s_addr = ia->ia_addr.sin_addr.s_addr; 652 goto done; 653 } 654 655 /* Jailed. */ 656 /* 1. Check if the iface address belongs to the jail. */ 657 sin = (struct sockaddr_in *)sro.ro_rt->rt_ifa->ifa_addr; --- 48 unchanged lines hidden (view full) --- 706 sain.sin_family = AF_INET; 707 sain.sin_len = sizeof(struct sockaddr_in); 708 sain.sin_addr.s_addr = faddr->s_addr; 709 710 ia = ifatoia(ifa_ifwithdstaddr(sintosa(&sain))); 711 if (ia == NULL) 712 ia = ifatoia(ifa_ifwithnet(sintosa(&sain))); 713 | 650 ia = (struct in_ifaddr *)sro.ro_rt->rt_ifa; 651 laddr->s_addr = ia->ia_addr.sin_addr.s_addr; 652 goto done; 653 } 654 655 /* Jailed. */ 656 /* 1. Check if the iface address belongs to the jail. */ 657 sin = (struct sockaddr_in *)sro.ro_rt->rt_ifa->ifa_addr; --- 48 unchanged lines hidden (view full) --- 706 sain.sin_family = AF_INET; 707 sain.sin_len = sizeof(struct sockaddr_in); 708 sain.sin_addr.s_addr = faddr->s_addr; 709 710 ia = ifatoia(ifa_ifwithdstaddr(sintosa(&sain))); 711 if (ia == NULL) 712 ia = ifatoia(ifa_ifwithnet(sintosa(&sain))); 713 |
714 if (cred == NULL || !jailed(cred)) { | 714 if (cred == NULL || !prison_flag(cred, PR_IP4)) { |
715#if __FreeBSD_version < 800000 716 if (ia == NULL) 717 ia = (struct in_ifaddr *)sro.ro_rt->rt_ifa; 718#endif 719 if (ia == NULL) { 720 error = ENETUNREACH; 721 goto done; 722 } --- 494 unchanged lines hidden (view full) --- 1217#endif 1218 if (inp->inp_faddr.s_addr == INADDR_ANY && 1219 inp->inp_laddr.s_addr == laddr.s_addr && 1220 inp->inp_lport == lport) { 1221 /* 1222 * Found? 1223 */ 1224 if (cred == NULL || | 715#if __FreeBSD_version < 800000 716 if (ia == NULL) 717 ia = (struct in_ifaddr *)sro.ro_rt->rt_ifa; 718#endif 719 if (ia == NULL) { 720 error = ENETUNREACH; 721 goto done; 722 } --- 494 unchanged lines hidden (view full) --- 1217#endif 1218 if (inp->inp_faddr.s_addr == INADDR_ANY && 1219 inp->inp_laddr.s_addr == laddr.s_addr && 1220 inp->inp_lport == lport) { 1221 /* 1222 * Found? 1223 */ 1224 if (cred == NULL || |
1225 inp->inp_cred->cr_prison == cred->cr_prison) | 1225 prison_equal_ip4(cred->cr_prison, 1226 inp->inp_cred->cr_prison)) |
1226 return (inp); 1227 } 1228 } 1229 /* 1230 * Not found. 1231 */ 1232 return (NULL); 1233 } else { --- 15 unchanged lines hidden (view full) --- 1249 if (phd != NULL) { 1250 /* 1251 * Port is in use by one or more PCBs. Look for best 1252 * fit. 1253 */ 1254 LIST_FOREACH(inp, &phd->phd_pcblist, inp_portlist) { 1255 wildcard = 0; 1256 if (cred != NULL && | 1227 return (inp); 1228 } 1229 } 1230 /* 1231 * Not found. 1232 */ 1233 return (NULL); 1234 } else { --- 15 unchanged lines hidden (view full) --- 1250 if (phd != NULL) { 1251 /* 1252 * Port is in use by one or more PCBs. Look for best 1253 * fit. 1254 */ 1255 LIST_FOREACH(inp, &phd->phd_pcblist, inp_portlist) { 1256 wildcard = 0; 1257 if (cred != NULL && |
1257 inp->inp_cred->cr_prison != cred->cr_prison) | 1258 !prison_equal_ip4(inp->inp_cred->cr_prison, 1259 cred->cr_prison)) |
1258 continue; 1259#ifdef INET6 1260 /* XXX inp locking */ 1261 if ((inp->inp_vflag & INP_IPV4) == 0) 1262 continue; 1263 /* 1264 * We never select the PCB that has 1265 * INP_IPV6 flag and is bound to :: if --- 64 unchanged lines hidden (view full) --- 1330 inp->inp_laddr.s_addr == laddr.s_addr && 1331 inp->inp_fport == fport && 1332 inp->inp_lport == lport) { 1333 /* 1334 * XXX We should be able to directly return 1335 * the inp here, without any checks. 1336 * Well unless both bound with SO_REUSEPORT? 1337 */ | 1260 continue; 1261#ifdef INET6 1262 /* XXX inp locking */ 1263 if ((inp->inp_vflag & INP_IPV4) == 0) 1264 continue; 1265 /* 1266 * We never select the PCB that has 1267 * INP_IPV6 flag and is bound to :: if --- 64 unchanged lines hidden (view full) --- 1332 inp->inp_laddr.s_addr == laddr.s_addr && 1333 inp->inp_fport == fport && 1334 inp->inp_lport == lport) { 1335 /* 1336 * XXX We should be able to directly return 1337 * the inp here, without any checks. 1338 * Well unless both bound with SO_REUSEPORT? 1339 */ |
1338 if (jailed(inp->inp_cred)) | 1340 if (prison_flag(inp->inp_cred, PR_IP4)) |
1339 return (inp); 1340 if (tmpinp == NULL) 1341 tmpinp = inp; 1342 } 1343 } 1344 if (tmpinp != NULL) 1345 return (tmpinp); 1346 --- 28 unchanged lines hidden (view full) --- 1375 inp->inp_lport != lport) 1376 continue; 1377 1378 /* XXX inp locking */ 1379 if (ifp && ifp->if_type == IFT_FAITH && 1380 (inp->inp_flags & INP_FAITH) == 0) 1381 continue; 1382 | 1341 return (inp); 1342 if (tmpinp == NULL) 1343 tmpinp = inp; 1344 } 1345 } 1346 if (tmpinp != NULL) 1347 return (tmpinp); 1348 --- 28 unchanged lines hidden (view full) --- 1377 inp->inp_lport != lport) 1378 continue; 1379 1380 /* XXX inp locking */ 1381 if (ifp && ifp->if_type == IFT_FAITH && 1382 (inp->inp_flags & INP_FAITH) == 0) 1383 continue; 1384 |
1383 injail = jailed(inp->inp_cred); | 1385 injail = prison_flag(inp->inp_cred, PR_IP4); |
1384 if (injail) { 1385 if (prison_check_ip4(inp->inp_cred, 1386 &laddr) != 0) 1387 continue; 1388 } else { 1389 if (local_exact != NULL) 1390 continue; 1391 } --- 560 unchanged lines hidden --- | 1386 if (injail) { 1387 if (prison_check_ip4(inp->inp_cred, 1388 &laddr) != 0) 1389 continue; 1390 } else { 1391 if (local_exact != NULL) 1392 continue; 1393 } --- 560 unchanged lines hidden --- |