if.c (72012) | if.c (72084) |
---|---|
1/* 2 * Copyright (c) 1980, 1986, 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 --- 17 unchanged lines hidden (view full) --- 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 * @(#)if.c 8.3 (Berkeley) 1/4/94 | 1/* 2 * Copyright (c) 1980, 1986, 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 --- 17 unchanged lines hidden (view full) --- 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 * @(#)if.c 8.3 (Berkeley) 1/4/94 |
34 * $FreeBSD: head/sys/net/if.c 72012 2001-02-04 16:08:18Z phk $ | 34 * $FreeBSD: head/sys/net/if.c 72084 2001-02-06 10:12:15Z phk $ |
35 */ 36 37#include "opt_compat.h" 38#include "opt_inet6.h" 39#include "opt_inet.h" 40 41#include <sys/param.h> 42#include <sys/malloc.h> --- 116 unchanged lines hidden (view full) --- 159 * XXX - 160 * The old code would work if the interface passed a pre-existing 161 * chain of ifaddrs to this code. We don't trust our callers to 162 * properly initialize the tailq, however, so we no longer allow 163 * this unlikely case. 164 */ 165 TAILQ_INIT(&ifp->if_addrhead); 166 TAILQ_INIT(&ifp->if_prefixhead); | 35 */ 36 37#include "opt_compat.h" 38#include "opt_inet6.h" 39#include "opt_inet.h" 40 41#include <sys/param.h> 42#include <sys/malloc.h> --- 116 unchanged lines hidden (view full) --- 159 * XXX - 160 * The old code would work if the interface passed a pre-existing 161 * chain of ifaddrs to this code. We don't trust our callers to 162 * properly initialize the tailq, however, so we no longer allow 163 * this unlikely case. 164 */ 165 TAILQ_INIT(&ifp->if_addrhead); 166 TAILQ_INIT(&ifp->if_prefixhead); |
167 LIST_INIT(&ifp->if_multiaddrs); | 167 TAILQ_INIT(&ifp->if_multiaddrs); |
168 getmicrotime(&ifp->if_lastchange); 169 if (ifnet_addrs == 0 || if_index >= if_indexlim) { 170 unsigned n = (if_indexlim <<= 1) * sizeof(ifa); 171 caddr_t q = malloc(n, M_IFADDR, M_WAITOK | M_ZERO); 172 if (ifnet_addrs) { 173 bcopy((caddr_t)ifnet_addrs, (caddr_t)q, n/2); 174 free((caddr_t)ifnet_addrs, M_IFADDR); 175 } --- 1001 unchanged lines hidden (view full) --- 1177 struct sockaddr *llsa, *dupsa; 1178 int error, s; 1179 struct ifmultiaddr *ifma; 1180 1181 /* 1182 * If the matching multicast address already exists 1183 * then don't add a new one, just add a reference 1184 */ | 168 getmicrotime(&ifp->if_lastchange); 169 if (ifnet_addrs == 0 || if_index >= if_indexlim) { 170 unsigned n = (if_indexlim <<= 1) * sizeof(ifa); 171 caddr_t q = malloc(n, M_IFADDR, M_WAITOK | M_ZERO); 172 if (ifnet_addrs) { 173 bcopy((caddr_t)ifnet_addrs, (caddr_t)q, n/2); 174 free((caddr_t)ifnet_addrs, M_IFADDR); 175 } --- 1001 unchanged lines hidden (view full) --- 1177 struct sockaddr *llsa, *dupsa; 1178 int error, s; 1179 struct ifmultiaddr *ifma; 1180 1181 /* 1182 * If the matching multicast address already exists 1183 * then don't add a new one, just add a reference 1184 */ |
1185 LIST_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) { | 1185 TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) { |
1186 if (equal(sa, ifma->ifma_addr)) { 1187 ifma->ifma_refcount++; 1188 if (retifma) 1189 *retifma = ifma; 1190 return 0; 1191 } 1192 } 1193 --- 20 unchanged lines hidden (view full) --- 1214 ifma->ifma_protospec = 0; 1215 rt_newmaddrmsg(RTM_NEWMADDR, ifma); 1216 1217 /* 1218 * Some network interfaces can scan the address list at 1219 * interrupt time; lock them out. 1220 */ 1221 s = splimp(); | 1186 if (equal(sa, ifma->ifma_addr)) { 1187 ifma->ifma_refcount++; 1188 if (retifma) 1189 *retifma = ifma; 1190 return 0; 1191 } 1192 } 1193 --- 20 unchanged lines hidden (view full) --- 1214 ifma->ifma_protospec = 0; 1215 rt_newmaddrmsg(RTM_NEWMADDR, ifma); 1216 1217 /* 1218 * Some network interfaces can scan the address list at 1219 * interrupt time; lock them out. 1220 */ 1221 s = splimp(); |
1222 LIST_INSERT_HEAD(&ifp->if_multiaddrs, ifma, ifma_link); | 1222 TAILQ_INSERT_HEAD(&ifp->if_multiaddrs, ifma, ifma_link); |
1223 splx(s); 1224 *retifma = ifma; 1225 1226 if (llsa != 0) { | 1223 splx(s); 1224 *retifma = ifma; 1225 1226 if (llsa != 0) { |
1227 LIST_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) { | 1227 TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) { |
1228 if (equal(ifma->ifma_addr, llsa)) 1229 break; 1230 } 1231 if (ifma) { 1232 ifma->ifma_refcount++; 1233 } else { 1234 MALLOC(ifma, struct ifmultiaddr *, sizeof *ifma, 1235 M_IFMADDR, M_WAITOK); 1236 MALLOC(dupsa, struct sockaddr *, llsa->sa_len, 1237 M_IFMADDR, M_WAITOK); 1238 bcopy(llsa, dupsa, llsa->sa_len); 1239 ifma->ifma_addr = dupsa; 1240 ifma->ifma_ifp = ifp; 1241 ifma->ifma_refcount = 1; 1242 s = splimp(); | 1228 if (equal(ifma->ifma_addr, llsa)) 1229 break; 1230 } 1231 if (ifma) { 1232 ifma->ifma_refcount++; 1233 } else { 1234 MALLOC(ifma, struct ifmultiaddr *, sizeof *ifma, 1235 M_IFMADDR, M_WAITOK); 1236 MALLOC(dupsa, struct sockaddr *, llsa->sa_len, 1237 M_IFMADDR, M_WAITOK); 1238 bcopy(llsa, dupsa, llsa->sa_len); 1239 ifma->ifma_addr = dupsa; 1240 ifma->ifma_ifp = ifp; 1241 ifma->ifma_refcount = 1; 1242 s = splimp(); |
1243 LIST_INSERT_HEAD(&ifp->if_multiaddrs, ifma, ifma_link); | 1243 TAILQ_INSERT_HEAD(&ifp->if_multiaddrs, ifma, ifma_link); |
1244 splx(s); 1245 } 1246 } 1247 /* 1248 * We are certain we have added something, so call down to the 1249 * interface to let them know about it. 1250 */ 1251 s = splimp(); --- 10 unchanged lines hidden (view full) --- 1262int 1263if_delmulti(ifp, sa) 1264 struct ifnet *ifp; 1265 struct sockaddr *sa; 1266{ 1267 struct ifmultiaddr *ifma; 1268 int s; 1269 | 1244 splx(s); 1245 } 1246 } 1247 /* 1248 * We are certain we have added something, so call down to the 1249 * interface to let them know about it. 1250 */ 1251 s = splimp(); --- 10 unchanged lines hidden (view full) --- 1262int 1263if_delmulti(ifp, sa) 1264 struct ifnet *ifp; 1265 struct sockaddr *sa; 1266{ 1267 struct ifmultiaddr *ifma; 1268 int s; 1269 |
1270 LIST_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) | 1270 TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) |
1271 if (equal(sa, ifma->ifma_addr)) 1272 break; 1273 if (ifma == 0) 1274 return ENOENT; 1275 1276 if (ifma->ifma_refcount > 1) { 1277 ifma->ifma_refcount--; 1278 return 0; 1279 } 1280 1281 rt_newmaddrmsg(RTM_DELMADDR, ifma); 1282 sa = ifma->ifma_lladdr; 1283 s = splimp(); | 1271 if (equal(sa, ifma->ifma_addr)) 1272 break; 1273 if (ifma == 0) 1274 return ENOENT; 1275 1276 if (ifma->ifma_refcount > 1) { 1277 ifma->ifma_refcount--; 1278 return 0; 1279 } 1280 1281 rt_newmaddrmsg(RTM_DELMADDR, ifma); 1282 sa = ifma->ifma_lladdr; 1283 s = splimp(); |
1284 LIST_REMOVE(ifma, ifma_link); | 1284 TAILQ_REMOVE(&ifp->if_multiaddrs, ifma, ifma_link); |
1285 splx(s); 1286 free(ifma->ifma_addr, M_IFMADDR); 1287 free(ifma, M_IFMADDR); 1288 if (sa == 0) 1289 return 0; 1290 1291 /* 1292 * Now look for the link-layer address which corresponds to 1293 * this network address. It had been squirreled away in 1294 * ifma->ifma_lladdr for this purpose (so we don't have 1295 * to call ifp->if_resolvemulti() again), and we saved that 1296 * value in sa above. If some nasty deleted the 1297 * link-layer address out from underneath us, we can deal because 1298 * the address we stored was is not the same as the one which was 1299 * in the record for the link-layer address. (So we don't complain 1300 * in that case.) 1301 */ | 1285 splx(s); 1286 free(ifma->ifma_addr, M_IFMADDR); 1287 free(ifma, M_IFMADDR); 1288 if (sa == 0) 1289 return 0; 1290 1291 /* 1292 * Now look for the link-layer address which corresponds to 1293 * this network address. It had been squirreled away in 1294 * ifma->ifma_lladdr for this purpose (so we don't have 1295 * to call ifp->if_resolvemulti() again), and we saved that 1296 * value in sa above. If some nasty deleted the 1297 * link-layer address out from underneath us, we can deal because 1298 * the address we stored was is not the same as the one which was 1299 * in the record for the link-layer address. (So we don't complain 1300 * in that case.) 1301 */ |
1302 LIST_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) | 1302 TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) |
1303 if (equal(sa, ifma->ifma_addr)) 1304 break; 1305 if (ifma == 0) 1306 return 0; 1307 1308 if (ifma->ifma_refcount > 1) { 1309 ifma->ifma_refcount--; 1310 return 0; 1311 } 1312 1313 s = splimp(); | 1303 if (equal(sa, ifma->ifma_addr)) 1304 break; 1305 if (ifma == 0) 1306 return 0; 1307 1308 if (ifma->ifma_refcount > 1) { 1309 ifma->ifma_refcount--; 1310 return 0; 1311 } 1312 1313 s = splimp(); |
1314 LIST_REMOVE(ifma, ifma_link); | 1314 TAILQ_REMOVE(&ifp->if_multiaddrs, ifma, ifma_link); |
1315 ifp->if_ioctl(ifp, SIOCDELMULTI, 0); 1316 splx(s); 1317 free(ifma->ifma_addr, M_IFMADDR); 1318 free(sa, M_IFMADDR); 1319 free(ifma, M_IFMADDR); 1320 1321 return 0; 1322} --- 46 unchanged lines hidden (view full) --- 1369 1370struct ifmultiaddr * 1371ifmaof_ifpforaddr(sa, ifp) 1372 struct sockaddr *sa; 1373 struct ifnet *ifp; 1374{ 1375 struct ifmultiaddr *ifma; 1376 | 1315 ifp->if_ioctl(ifp, SIOCDELMULTI, 0); 1316 splx(s); 1317 free(ifma->ifma_addr, M_IFMADDR); 1318 free(sa, M_IFMADDR); 1319 free(ifma, M_IFMADDR); 1320 1321 return 0; 1322} --- 46 unchanged lines hidden (view full) --- 1369 1370struct ifmultiaddr * 1371ifmaof_ifpforaddr(sa, ifp) 1372 struct sockaddr *sa; 1373 struct ifnet *ifp; 1374{ 1375 struct ifmultiaddr *ifma; 1376 |
1377 LIST_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) | 1377 TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) |
1378 if (equal(ifma->ifma_addr, sa)) 1379 break; 1380 1381 return ifma; 1382} 1383 1384SYSCTL_NODE(_net, PF_LINK, link, CTLFLAG_RW, 0, "Link layers"); 1385SYSCTL_NODE(_net_link, 0, generic, CTLFLAG_RW, 0, "Generic link-management"); | 1378 if (equal(ifma->ifma_addr, sa)) 1379 break; 1380 1381 return ifma; 1382} 1383 1384SYSCTL_NODE(_net, PF_LINK, link, CTLFLAG_RW, 0, "Link layers"); 1385SYSCTL_NODE(_net_link, 0, generic, CTLFLAG_RW, 0, "Generic link-management"); |