scope6.c (174510) | scope6.c (181803) |
---|---|
1/*- 2 * Copyright (C) 2000 WIDE Project. 3 * 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 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 * 29 * $KAME: scope6.c,v 1.10 2000/07/24 13:29:31 itojun Exp $ 30 */ 31 32#include <sys/cdefs.h> | 1/*- 2 * Copyright (C) 2000 WIDE Project. 3 * 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 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 * 29 * $KAME: scope6.c,v 1.10 2000/07/24 13:29:31 itojun Exp $ 30 */ 31 32#include <sys/cdefs.h> |
33__FBSDID("$FreeBSD: head/sys/netinet6/scope6.c 174510 2007-12-10 16:03:40Z obrien $"); | 33__FBSDID("$FreeBSD: head/sys/netinet6/scope6.c 181803 2008-08-17 23:27:27Z bz $"); |
34 35#include <sys/param.h> 36#include <sys/malloc.h> 37#include <sys/mbuf.h> 38#include <sys/socket.h> 39#include <sys/systm.h> 40#include <sys/queue.h> 41#include <sys/syslog.h> | 34 35#include <sys/param.h> 36#include <sys/malloc.h> 37#include <sys/mbuf.h> 38#include <sys/socket.h> 39#include <sys/systm.h> 40#include <sys/queue.h> 41#include <sys/syslog.h> |
42#include <sys/vimage.h> |
|
42 43#include <net/route.h> 44#include <net/if.h> 45 46#include <netinet/in.h> 47 48#include <netinet6/in6_var.h> 49#include <netinet6/scope6_var.h> --- 18 unchanged lines hidden (view full) --- 68#define SID(ifp) \ 69 (((struct in6_ifextra *)(ifp)->if_afdata[AF_INET6])->scope6_id) 70 71void 72scope6_init(void) 73{ 74 75 SCOPE6_LOCK_INIT(); | 43 44#include <net/route.h> 45#include <net/if.h> 46 47#include <netinet/in.h> 48 49#include <netinet6/in6_var.h> 50#include <netinet6/scope6_var.h> --- 18 unchanged lines hidden (view full) --- 69#define SID(ifp) \ 70 (((struct in6_ifextra *)(ifp)->if_afdata[AF_INET6])->scope6_id) 71 72void 73scope6_init(void) 74{ 75 76 SCOPE6_LOCK_INIT(); |
76 bzero(&sid_default, sizeof(sid_default)); | 77 bzero(&V_sid_default, sizeof(V_sid_default)); |
77} 78 79struct scope6_id * 80scope6_ifattach(struct ifnet *ifp) 81{ 82 struct scope6_id *sid; 83 84 sid = (struct scope6_id *)malloc(sizeof(*sid), M_IFADDR, M_WAITOK); --- 57 unchanged lines hidden (view full) --- 142 if (i == IPV6_ADDR_SCOPE_INTFACELOCAL && 143 idlist->s6id_list[i] != ifp->if_index) { 144 IF_AFDATA_UNLOCK(ifp); 145 SCOPE6_UNLOCK(); 146 return (EINVAL); 147 } 148 149 if (i == IPV6_ADDR_SCOPE_LINKLOCAL && | 78} 79 80struct scope6_id * 81scope6_ifattach(struct ifnet *ifp) 82{ 83 struct scope6_id *sid; 84 85 sid = (struct scope6_id *)malloc(sizeof(*sid), M_IFADDR, M_WAITOK); --- 57 unchanged lines hidden (view full) --- 143 if (i == IPV6_ADDR_SCOPE_INTFACELOCAL && 144 idlist->s6id_list[i] != ifp->if_index) { 145 IF_AFDATA_UNLOCK(ifp); 146 SCOPE6_UNLOCK(); 147 return (EINVAL); 148 } 149 150 if (i == IPV6_ADDR_SCOPE_LINKLOCAL && |
150 idlist->s6id_list[i] > if_index) { | 151 idlist->s6id_list[i] > V_if_index) { |
151 /* 152 * XXX: theoretically, there should be no 153 * relationship between link IDs and interface 154 * IDs, but we check the consistency for 155 * safety in later use. 156 */ 157 IF_AFDATA_UNLOCK(ifp); 158 SCOPE6_UNLOCK(); --- 107 unchanged lines hidden (view full) --- 266 /* 267 * Currently, this function just sets the default "interfaces" 268 * and "links" according to the given interface. 269 * We might eventually have to separate the notion of "link" from 270 * "interface" and provide a user interface to set the default. 271 */ 272 SCOPE6_LOCK(); 273 if (ifp) { | 152 /* 153 * XXX: theoretically, there should be no 154 * relationship between link IDs and interface 155 * IDs, but we check the consistency for 156 * safety in later use. 157 */ 158 IF_AFDATA_UNLOCK(ifp); 159 SCOPE6_UNLOCK(); --- 107 unchanged lines hidden (view full) --- 267 /* 268 * Currently, this function just sets the default "interfaces" 269 * and "links" according to the given interface. 270 * We might eventually have to separate the notion of "link" from 271 * "interface" and provide a user interface to set the default. 272 */ 273 SCOPE6_LOCK(); 274 if (ifp) { |
274 sid_default.s6id_list[IPV6_ADDR_SCOPE_INTFACELOCAL] = | 275 V_sid_default.s6id_list[IPV6_ADDR_SCOPE_INTFACELOCAL] = |
275 ifp->if_index; | 276 ifp->if_index; |
276 sid_default.s6id_list[IPV6_ADDR_SCOPE_LINKLOCAL] = | 277 V_sid_default.s6id_list[IPV6_ADDR_SCOPE_LINKLOCAL] = |
277 ifp->if_index; 278 } else { | 278 ifp->if_index; 279 } else { |
279 sid_default.s6id_list[IPV6_ADDR_SCOPE_INTFACELOCAL] = 0; 280 sid_default.s6id_list[IPV6_ADDR_SCOPE_LINKLOCAL] = 0; | 280 V_sid_default.s6id_list[IPV6_ADDR_SCOPE_INTFACELOCAL] = 0; 281 V_sid_default.s6id_list[IPV6_ADDR_SCOPE_LINKLOCAL] = 0; |
281 } 282 SCOPE6_UNLOCK(); 283} 284 285int 286scope6_get_default(struct scope6_id *idlist) 287{ 288 289 SCOPE6_LOCK(); | 282 } 283 SCOPE6_UNLOCK(); 284} 285 286int 287scope6_get_default(struct scope6_id *idlist) 288{ 289 290 SCOPE6_LOCK(); |
290 *idlist = sid_default; | 291 *idlist = V_sid_default; |
291 SCOPE6_UNLOCK(); 292 293 return (0); 294} 295 296u_int32_t 297scope6_addr2default(struct in6_addr *addr) 298{ --- 6 unchanged lines hidden (view full) --- 305 if (IN6_IS_ADDR_LOOPBACK(addr)) 306 return (0); 307 308 /* 309 * XXX: 32-bit read is atomic on all our platforms, is it OK 310 * not to lock here? 311 */ 312 SCOPE6_LOCK(); | 292 SCOPE6_UNLOCK(); 293 294 return (0); 295} 296 297u_int32_t 298scope6_addr2default(struct in6_addr *addr) 299{ --- 6 unchanged lines hidden (view full) --- 306 if (IN6_IS_ADDR_LOOPBACK(addr)) 307 return (0); 308 309 /* 310 * XXX: 32-bit read is atomic on all our platforms, is it OK 311 * not to lock here? 312 */ 313 SCOPE6_LOCK(); |
313 id = sid_default.s6id_list[in6_addrscope(addr)]; | 314 id = V_sid_default.s6id_list[in6_addrscope(addr)]; |
314 SCOPE6_UNLOCK(); 315 return (id); 316} 317 318/* 319 * Validate the specified scope zone ID in the sin6_scope_id field. If the ID 320 * is unspecified (=0), needs to be specified, and the default zone ID can be 321 * used, the default value will be used. --- 14 unchanged lines hidden (view full) --- 336 (IN6_IS_SCOPE_LINKLOCAL(&sin6->sin6_addr) || 337 IN6_IS_ADDR_MC_INTFACELOCAL(&sin6->sin6_addr))) { 338 /* 339 * At this moment, we only check interface-local and 340 * link-local scope IDs, and use interface indices as the 341 * zone IDs assuming a one-to-one mapping between interfaces 342 * and links. 343 */ | 315 SCOPE6_UNLOCK(); 316 return (id); 317} 318 319/* 320 * Validate the specified scope zone ID in the sin6_scope_id field. If the ID 321 * is unspecified (=0), needs to be specified, and the default zone ID can be 322 * used, the default value will be used. --- 14 unchanged lines hidden (view full) --- 337 (IN6_IS_SCOPE_LINKLOCAL(&sin6->sin6_addr) || 338 IN6_IS_ADDR_MC_INTFACELOCAL(&sin6->sin6_addr))) { 339 /* 340 * At this moment, we only check interface-local and 341 * link-local scope IDs, and use interface indices as the 342 * zone IDs assuming a one-to-one mapping between interfaces 343 * and links. 344 */ |
344 if (if_index < zoneid) | 345 if (V_if_index < zoneid) |
345 return (ENXIO); 346 ifp = ifnet_byindex(zoneid); 347 if (ifp == NULL) /* XXX: this can happen for some OS */ 348 return (ENXIO); 349 350 /* XXX assignment to 16bit from 32bit variable */ 351 sin6->sin6_addr.s6_addr16[1] = htons(zoneid & 0xffff); 352 --- 21 unchanged lines hidden (view full) --- 374 if (IN6_IS_SCOPE_LINKLOCAL(&sin6->sin6_addr) || 375 IN6_IS_ADDR_MC_INTFACELOCAL(&sin6->sin6_addr)) { 376 /* 377 * KAME assumption: link id == interface id 378 */ 379 zoneid = ntohs(sin6->sin6_addr.s6_addr16[1]); 380 if (zoneid) { 381 /* sanity check */ | 346 return (ENXIO); 347 ifp = ifnet_byindex(zoneid); 348 if (ifp == NULL) /* XXX: this can happen for some OS */ 349 return (ENXIO); 350 351 /* XXX assignment to 16bit from 32bit variable */ 352 sin6->sin6_addr.s6_addr16[1] = htons(zoneid & 0xffff); 353 --- 21 unchanged lines hidden (view full) --- 375 if (IN6_IS_SCOPE_LINKLOCAL(&sin6->sin6_addr) || 376 IN6_IS_ADDR_MC_INTFACELOCAL(&sin6->sin6_addr)) { 377 /* 378 * KAME assumption: link id == interface id 379 */ 380 zoneid = ntohs(sin6->sin6_addr.s6_addr16[1]); 381 if (zoneid) { 382 /* sanity check */ |
382 if (zoneid < 0 || if_index < zoneid) | 383 if (zoneid < 0 || V_if_index < zoneid) |
383 return (ENXIO); 384 if (!ifnet_byindex(zoneid)) 385 return (ENXIO); 386 sin6->sin6_addr.s6_addr16[1] = 0; 387 sin6->sin6_scope_id = zoneid; 388 } 389 } 390 --- 97 unchanged lines hidden --- | 384 return (ENXIO); 385 if (!ifnet_byindex(zoneid)) 386 return (ENXIO); 387 sin6->sin6_addr.s6_addr16[1] = 0; 388 sin6->sin6_scope_id = zoneid; 389 } 390 } 391 --- 97 unchanged lines hidden --- |