Deleted Added
full compact
in.c (198418) in.c (201282)
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 198418 2009-10-23 18:27:34Z qingli $");
34__FBSDID("$FreeBSD: head/sys/netinet/in.c 201282 2009-12-30 21:35:34Z qingli $");
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>

--- 876 unchanged lines hidden (view full) ---

919 return (error);
920
921 if (ia->ia_addr.sin_addr.s_addr == INADDR_ANY)
922 return (0);
923
924 /*
925 * add a loopback route to self
926 */
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>

--- 876 unchanged lines hidden (view full) ---

919 return (error);
920
921 if (ia->ia_addr.sin_addr.s_addr == INADDR_ANY)
922 return (0);
923
924 /*
925 * add a loopback route to self
926 */
927 if (V_useloopback && !(ifp->if_flags & IFF_LOOPBACK))
928 error = ifa_add_loopback_route((struct ifaddr *)ia,
927 if (V_useloopback && !(ifp->if_flags & IFF_LOOPBACK)) {
928 struct route ia_ro;
929
930 bzero(&ia_ro, sizeof(ia_ro));
931 *((struct sockaddr_in *)(&ia_ro.ro_dst)) = ia->ia_addr;
932 rtalloc_ign_fib(&ia_ro, 0, 0);
933 if ((ia_ro.ro_rt != NULL) && (ia_ro.ro_rt->rt_ifp != NULL) &&
934 (ia_ro.ro_rt->rt_ifp == V_loif)) {
935 RT_LOCK(ia_ro.ro_rt);
936 RT_ADDREF(ia_ro.ro_rt);
937 RTFREE_LOCKED(ia_ro.ro_rt);
938 } else
939 error = ifa_add_loopback_route((struct ifaddr *)ia,
929 (struct sockaddr *)&ia->ia_addr);
940 (struct sockaddr *)&ia->ia_addr);
941 if (error == 0)
942 ia->ia_flags |= IFA_RTSELF;
943 if (ia_ro.ro_rt != NULL)
944 RTFREE(ia_ro.ro_rt);
945 }
930
931 return (error);
932}
933
934#define rtinitflags(x) \
935 ((((x)->ia_ifp->if_flags & (IFF_LOOPBACK | IFF_POINTOPOINT)) != 0) \
936 ? RTF_HOST : 0)
937/*

--- 100 unchanged lines hidden (view full) ---

1038 * same prefix, remove the route. Hand over the route to the new address
1039 * otherwise.
1040 */
1041static int
1042in_scrubprefix(struct in_ifaddr *target)
1043{
1044 struct in_ifaddr *ia;
1045 struct in_addr prefix, mask, p;
946
947 return (error);
948}
949
950#define rtinitflags(x) \
951 ((((x)->ia_ifp->if_flags & (IFF_LOOPBACK | IFF_POINTOPOINT)) != 0) \
952 ? RTF_HOST : 0)
953/*

--- 100 unchanged lines hidden (view full) ---

1054 * same prefix, remove the route. Hand over the route to the new address
1055 * otherwise.
1056 */
1057static int
1058in_scrubprefix(struct in_ifaddr *target)
1059{
1060 struct in_ifaddr *ia;
1061 struct in_addr prefix, mask, p;
1046 int error;
1062 int error = 0;
1047 struct sockaddr_in prefix0, mask0;
1048
1049 /*
1050 * Remove the loopback route to the interface address.
1051 * The "useloopback" setting is not consulted because if the
1052 * user configures an interface address, turns off this
1053 * setting, and then tries to delete that interface address,
1054 * checking the current setting of "useloopback" would leave
1055 * that interface address loopback route untouched, which
1056 * would be wrong. Therefore the interface address loopback route
1057 * deletion is unconditional.
1058 */
1059 if ((target->ia_addr.sin_addr.s_addr != INADDR_ANY) &&
1063 struct sockaddr_in prefix0, mask0;
1064
1065 /*
1066 * Remove the loopback route to the interface address.
1067 * The "useloopback" setting is not consulted because if the
1068 * user configures an interface address, turns off this
1069 * setting, and then tries to delete that interface address,
1070 * checking the current setting of "useloopback" would leave
1071 * that interface address loopback route untouched, which
1072 * would be wrong. Therefore the interface address loopback route
1073 * deletion is unconditional.
1074 */
1075 if ((target->ia_addr.sin_addr.s_addr != INADDR_ANY) &&
1060 !(target->ia_ifp->if_flags & IFF_LOOPBACK)) {
1061 error = ifa_del_loopback_route((struct ifaddr *)target,
1076 !(target->ia_ifp->if_flags & IFF_LOOPBACK) &&
1077 (target->ia_flags & IFA_RTSELF)) {
1078 struct route ia_ro;
1079 int freeit = 0;
1080
1081 bzero(&ia_ro, sizeof(ia_ro));
1082 *((struct sockaddr_in *)(&ia_ro.ro_dst)) = target->ia_addr;
1083 rtalloc_ign_fib(&ia_ro, 0, 0);
1084 if ((ia_ro.ro_rt != NULL) && (ia_ro.ro_rt->rt_ifp != NULL) &&
1085 (ia_ro.ro_rt->rt_ifp == V_loif)) {
1086 RT_LOCK(ia_ro.ro_rt);
1087 if (ia_ro.ro_rt->rt_refcnt <= 1)
1088 freeit = 1;
1089 else
1090 RT_REMREF(ia_ro.ro_rt);
1091 RTFREE_LOCKED(ia_ro.ro_rt);
1092 }
1093 if (freeit)
1094 error = ifa_del_loopback_route((struct ifaddr *)target,
1062 (struct sockaddr *)&target->ia_addr);
1095 (struct sockaddr *)&target->ia_addr);
1096 if (error == 0)
1097 target->ia_flags &= ~IFA_RTSELF;
1063 /* remove arp cache */
1064 arp_ifscrub(target->ia_ifp, IA_SIN(target)->sin_addr.s_addr);
1065 }
1066
1067 if ((target->ia_flags & IFA_ROUTE) == 0) {
1068 struct rtentry rt;
1069
1070 /* QL: XXX

--- 241 unchanged lines hidden (view full) ---

1312 llentry_free(lle);
1313 }
1314 }
1315 }
1316}
1317
1318
1319static int
1098 /* remove arp cache */
1099 arp_ifscrub(target->ia_ifp, IA_SIN(target)->sin_addr.s_addr);
1100 }
1101
1102 if ((target->ia_flags & IFA_ROUTE) == 0) {
1103 struct rtentry rt;
1104
1105 /* QL: XXX

--- 241 unchanged lines hidden (view full) ---

1347 llentry_free(lle);
1348 }
1349 }
1350 }
1351}
1352
1353
1354static int
1320in_lltable_rtcheck(struct ifnet *ifp, const struct sockaddr *l3addr)
1355in_lltable_rtcheck(struct ifnet *ifp, u_int flags, const struct sockaddr *l3addr)
1321{
1322 struct rtentry *rt;
1323
1324 KASSERT(l3addr->sa_family == AF_INET,
1325 ("sin_family %d", l3addr->sa_family));
1326
1327 /* XXX rtalloc1 should take a const param */
1328 rt = rtalloc1(__DECONST(struct sockaddr *, l3addr), 0, 0);
1356{
1357 struct rtentry *rt;
1358
1359 KASSERT(l3addr->sa_family == AF_INET,
1360 ("sin_family %d", l3addr->sa_family));
1361
1362 /* XXX rtalloc1 should take a const param */
1363 rt = rtalloc1(__DECONST(struct sockaddr *, l3addr), 0, 0);
1329 if (rt == NULL || (rt->rt_flags & RTF_GATEWAY) || rt->rt_ifp != ifp) {
1364 if (rt == NULL || (rt->rt_flags & RTF_GATEWAY) ||
1365 ((rt->rt_ifp != ifp) && !(flags & LLE_PUB))) {
1330#ifdef DIAGNOSTIC
1331 log(LOG_INFO, "IPv4 address: \"%s\" is not on the network\n",
1332 inet_ntoa(((const struct sockaddr_in *)l3addr)->sin_addr));
1333#endif
1334 if (rt != NULL)
1335 RTFREE_LOCKED(rt);
1336 return (EINVAL);
1337 }

--- 35 unchanged lines hidden (view full) ---

1373 if (!(flags & LLE_CREATE))
1374 return (NULL);
1375 /*
1376 * A route that covers the given address must have
1377 * been installed 1st because we are doing a resolution,
1378 * verify this.
1379 */
1380 if (!(flags & LLE_IFADDR) &&
1366#ifdef DIAGNOSTIC
1367 log(LOG_INFO, "IPv4 address: \"%s\" is not on the network\n",
1368 inet_ntoa(((const struct sockaddr_in *)l3addr)->sin_addr));
1369#endif
1370 if (rt != NULL)
1371 RTFREE_LOCKED(rt);
1372 return (EINVAL);
1373 }

--- 35 unchanged lines hidden (view full) ---

1409 if (!(flags & LLE_CREATE))
1410 return (NULL);
1411 /*
1412 * A route that covers the given address must have
1413 * been installed 1st because we are doing a resolution,
1414 * verify this.
1415 */
1416 if (!(flags & LLE_IFADDR) &&
1381 in_lltable_rtcheck(ifp, l3addr) != 0)
1417 in_lltable_rtcheck(ifp, flags, l3addr) != 0)
1382 goto done;
1383
1384 lle = in_lltable_new(l3addr, flags);
1385 if (lle == NULL) {
1386 log(LOG_INFO, "lla_lookup: new lle malloc failed\n");
1387 goto done;
1388 }
1389 lle->la_flags = flags & ~LLE_CREATE;

--- 143 unchanged lines hidden ---
1418 goto done;
1419
1420 lle = in_lltable_new(l3addr, flags);
1421 if (lle == NULL) {
1422 log(LOG_INFO, "lla_lookup: new lle malloc failed\n");
1423 goto done;
1424 }
1425 lle->la_flags = flags & ~LLE_CREATE;

--- 143 unchanged lines hidden ---