addrconf.c (2ad3ed59198c5404c34515cfcfd9a2b3c54d964f) addrconf.c (4f672235cb11c49d4be7ac7d505c65e3bd367322)
1/*
2 * IPv6 Address [auto]configuration
3 * Linux INET6 implementation
4 *
5 * Authors:
6 * Pedro Roque <roque@di.fc.ul.pt>
7 * Alexey Kuznetsov <kuznet@ms2.inr.ac.ru>
8 *

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

2328}
2329
2330static bool is_addr_mode_generate_stable(struct inet6_dev *idev)
2331{
2332 return idev->addr_gen_mode == IN6_ADDR_GEN_MODE_STABLE_PRIVACY ||
2333 idev->addr_gen_mode == IN6_ADDR_GEN_MODE_RANDOM;
2334}
2335
1/*
2 * IPv6 Address [auto]configuration
3 * Linux INET6 implementation
4 *
5 * Authors:
6 * Pedro Roque <roque@di.fc.ul.pt>
7 * Alexey Kuznetsov <kuznet@ms2.inr.ac.ru>
8 *

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

2328}
2329
2330static bool is_addr_mode_generate_stable(struct inet6_dev *idev)
2331{
2332 return idev->addr_gen_mode == IN6_ADDR_GEN_MODE_STABLE_PRIVACY ||
2333 idev->addr_gen_mode == IN6_ADDR_GEN_MODE_RANDOM;
2334}
2335
2336static int addrconf_prefix_rcv_add_addr(struct net *net,
2337 struct net_device *dev,
2338 const struct prefix_info *pinfo,
2339 struct inet6_dev *in6_dev,
2340 const struct in6_addr *addr,
2341 int addr_type, u32 addr_flags,
2342 bool sllao, bool tokenized,
2343 __u32 valid_lft, u32 prefered_lft)
2344{
2345 struct inet6_ifaddr *ifp = ipv6_get_ifaddr(net, addr, dev, 1);
2346 int create = 0, update_lft = 0;
2347
2348 if (!ifp && valid_lft) {
2349 int max_addresses = in6_dev->cnf.max_addresses;
2350
2351#ifdef CONFIG_IPV6_OPTIMISTIC_DAD
2352 if (in6_dev->cnf.optimistic_dad &&
2353 !net->ipv6.devconf_all->forwarding && sllao)
2354 addr_flags |= IFA_F_OPTIMISTIC;
2355#endif
2356
2357 /* Do not allow to create too much of autoconfigured
2358 * addresses; this would be too easy way to crash kernel.
2359 */
2360 if (!max_addresses ||
2361 ipv6_count_addresses(in6_dev) < max_addresses)
2362 ifp = ipv6_add_addr(in6_dev, addr, NULL,
2363 pinfo->prefix_len,
2364 addr_type&IPV6_ADDR_SCOPE_MASK,
2365 addr_flags, valid_lft,
2366 prefered_lft);
2367
2368 if (IS_ERR_OR_NULL(ifp))
2369 return -1;
2370
2371 update_lft = 0;
2372 create = 1;
2373 spin_lock_bh(&ifp->lock);
2374 ifp->flags |= IFA_F_MANAGETEMPADDR;
2375 ifp->cstamp = jiffies;
2376 ifp->tokenized = tokenized;
2377 spin_unlock_bh(&ifp->lock);
2378 addrconf_dad_start(ifp);
2379 }
2380
2381 if (ifp) {
2382 u32 flags;
2383 unsigned long now;
2384 u32 stored_lft;
2385
2386 /* update lifetime (RFC2462 5.5.3 e) */
2387 spin_lock_bh(&ifp->lock);
2388 now = jiffies;
2389 if (ifp->valid_lft > (now - ifp->tstamp) / HZ)
2390 stored_lft = ifp->valid_lft - (now - ifp->tstamp) / HZ;
2391 else
2392 stored_lft = 0;
2393 if (!update_lft && !create && stored_lft) {
2394 const u32 minimum_lft = min_t(u32,
2395 stored_lft, MIN_VALID_LIFETIME);
2396 valid_lft = max(valid_lft, minimum_lft);
2397
2398 /* RFC4862 Section 5.5.3e:
2399 * "Note that the preferred lifetime of the
2400 * corresponding address is always reset to
2401 * the Preferred Lifetime in the received
2402 * Prefix Information option, regardless of
2403 * whether the valid lifetime is also reset or
2404 * ignored."
2405 *
2406 * So we should always update prefered_lft here.
2407 */
2408 update_lft = 1;
2409 }
2410
2411 if (update_lft) {
2412 ifp->valid_lft = valid_lft;
2413 ifp->prefered_lft = prefered_lft;
2414 ifp->tstamp = now;
2415 flags = ifp->flags;
2416 ifp->flags &= ~IFA_F_DEPRECATED;
2417 spin_unlock_bh(&ifp->lock);
2418
2419 if (!(flags&IFA_F_TENTATIVE))
2420 ipv6_ifa_notify(0, ifp);
2421 } else
2422 spin_unlock_bh(&ifp->lock);
2423
2424 manage_tempaddrs(in6_dev, ifp, valid_lft, prefered_lft,
2425 create, now);
2426
2427 in6_ifa_put(ifp);
2428 addrconf_verify();
2429 }
2430
2431 return 0;
2432}
2433
2336void addrconf_prefix_rcv(struct net_device *dev, u8 *opt, int len, bool sllao)
2337{
2338 struct prefix_info *pinfo;
2339 __u32 valid_lft;
2340 __u32 prefered_lft;
2434void addrconf_prefix_rcv(struct net_device *dev, u8 *opt, int len, bool sllao)
2435{
2436 struct prefix_info *pinfo;
2437 __u32 valid_lft;
2438 __u32 prefered_lft;
2341 int addr_type;
2439 int addr_type, err;
2342 u32 addr_flags = 0;
2343 struct inet6_dev *in6_dev;
2344 struct net *net = dev_net(dev);
2345
2346 pinfo = (struct prefix_info *) opt;
2347
2348 if (len < sizeof(struct prefix_info)) {
2349 ADBG("addrconf: prefix option too short\n");

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

2427 dev, expires, flags);
2428 }
2429 ip6_rt_put(rt);
2430 }
2431
2432 /* Try to figure out our local address for this prefix */
2433
2434 if (pinfo->autoconf && in6_dev->cnf.autoconf) {
2440 u32 addr_flags = 0;
2441 struct inet6_dev *in6_dev;
2442 struct net *net = dev_net(dev);
2443
2444 pinfo = (struct prefix_info *) opt;
2445
2446 if (len < sizeof(struct prefix_info)) {
2447 ADBG("addrconf: prefix option too short\n");

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

2525 dev, expires, flags);
2526 }
2527 ip6_rt_put(rt);
2528 }
2529
2530 /* Try to figure out our local address for this prefix */
2531
2532 if (pinfo->autoconf && in6_dev->cnf.autoconf) {
2435 struct inet6_ifaddr *ifp;
2436 struct in6_addr addr;
2533 struct in6_addr addr;
2437 int create = 0, update_lft = 0;
2438 bool tokenized = false;
2439
2440 if (pinfo->prefix_len == 64) {
2441 memcpy(&addr, &pinfo->prefix, 8);
2442
2443 if (!ipv6_addr_any(&in6_dev->token)) {
2444 read_lock_bh(&in6_dev->lock);
2445 memcpy(addr.s6_addr + 8,
2446 in6_dev->token.s6_addr + 8, 8);
2447 read_unlock_bh(&in6_dev->lock);
2448 tokenized = true;
2449 } else if (is_addr_mode_generate_stable(in6_dev) &&
2450 !ipv6_generate_stable_address(&addr, 0,
2451 in6_dev)) {
2452 addr_flags |= IFA_F_STABLE_PRIVACY;
2453 goto ok;
2454 } else if (ipv6_generate_eui64(addr.s6_addr + 8, dev) &&
2455 ipv6_inherit_eui64(addr.s6_addr + 8, in6_dev)) {
2534 bool tokenized = false;
2535
2536 if (pinfo->prefix_len == 64) {
2537 memcpy(&addr, &pinfo->prefix, 8);
2538
2539 if (!ipv6_addr_any(&in6_dev->token)) {
2540 read_lock_bh(&in6_dev->lock);
2541 memcpy(addr.s6_addr + 8,
2542 in6_dev->token.s6_addr + 8, 8);
2543 read_unlock_bh(&in6_dev->lock);
2544 tokenized = true;
2545 } else if (is_addr_mode_generate_stable(in6_dev) &&
2546 !ipv6_generate_stable_address(&addr, 0,
2547 in6_dev)) {
2548 addr_flags |= IFA_F_STABLE_PRIVACY;
2549 goto ok;
2550 } else if (ipv6_generate_eui64(addr.s6_addr + 8, dev) &&
2551 ipv6_inherit_eui64(addr.s6_addr + 8, in6_dev)) {
2456 in6_dev_put(in6_dev);
2457 return;
2552 goto put;
2458 }
2459 goto ok;
2460 }
2461 net_dbg_ratelimited("IPv6 addrconf: prefix with wrong length %d\n",
2462 pinfo->prefix_len);
2553 }
2554 goto ok;
2555 }
2556 net_dbg_ratelimited("IPv6 addrconf: prefix with wrong length %d\n",
2557 pinfo->prefix_len);
2463 in6_dev_put(in6_dev);
2464 return;
2558 goto put;
2465
2466ok:
2559
2560ok:
2467
2468 ifp = ipv6_get_ifaddr(net, &addr, dev, 1);
2469
2470 if (!ifp && valid_lft) {
2471 int max_addresses = in6_dev->cnf.max_addresses;
2472
2473#ifdef CONFIG_IPV6_OPTIMISTIC_DAD
2474 if (in6_dev->cnf.optimistic_dad &&
2475 !net->ipv6.devconf_all->forwarding && sllao)
2476 addr_flags |= IFA_F_OPTIMISTIC;
2477#endif
2478
2479 /* Do not allow to create too much of autoconfigured
2480 * addresses; this would be too easy way to crash kernel.
2481 */
2482 if (!max_addresses ||
2483 ipv6_count_addresses(in6_dev) < max_addresses)
2484 ifp = ipv6_add_addr(in6_dev, &addr, NULL,
2485 pinfo->prefix_len,
2486 addr_type&IPV6_ADDR_SCOPE_MASK,
2487 addr_flags, valid_lft,
2488 prefered_lft);
2489
2490 if (IS_ERR_OR_NULL(ifp)) {
2491 in6_dev_put(in6_dev);
2492 return;
2493 }
2494
2495 update_lft = 0;
2496 create = 1;
2497 spin_lock_bh(&ifp->lock);
2498 ifp->flags |= IFA_F_MANAGETEMPADDR;
2499 ifp->cstamp = jiffies;
2500 ifp->tokenized = tokenized;
2501 spin_unlock_bh(&ifp->lock);
2502 addrconf_dad_start(ifp);
2503 }
2504
2505 if (ifp) {
2506 u32 flags;
2507 unsigned long now;
2508 u32 stored_lft;
2509
2510 /* update lifetime (RFC2462 5.5.3 e) */
2511 spin_lock_bh(&ifp->lock);
2512 now = jiffies;
2513 if (ifp->valid_lft > (now - ifp->tstamp) / HZ)
2514 stored_lft = ifp->valid_lft - (now - ifp->tstamp) / HZ;
2515 else
2516 stored_lft = 0;
2517 if (!update_lft && !create && stored_lft) {
2518 const u32 minimum_lft = min_t(u32,
2519 stored_lft, MIN_VALID_LIFETIME);
2520 valid_lft = max(valid_lft, minimum_lft);
2521
2522 /* RFC4862 Section 5.5.3e:
2523 * "Note that the preferred lifetime of the
2524 * corresponding address is always reset to
2525 * the Preferred Lifetime in the received
2526 * Prefix Information option, regardless of
2527 * whether the valid lifetime is also reset or
2528 * ignored."
2529 *
2530 * So we should always update prefered_lft here.
2531 */
2532 update_lft = 1;
2533 }
2534
2535 if (update_lft) {
2536 ifp->valid_lft = valid_lft;
2537 ifp->prefered_lft = prefered_lft;
2538 ifp->tstamp = now;
2539 flags = ifp->flags;
2540 ifp->flags &= ~IFA_F_DEPRECATED;
2541 spin_unlock_bh(&ifp->lock);
2542
2543 if (!(flags&IFA_F_TENTATIVE))
2544 ipv6_ifa_notify(0, ifp);
2545 } else
2546 spin_unlock_bh(&ifp->lock);
2547
2548 manage_tempaddrs(in6_dev, ifp, valid_lft, prefered_lft,
2549 create, now);
2550
2551 in6_ifa_put(ifp);
2552 addrconf_verify();
2553 }
2561 err = addrconf_prefix_rcv_add_addr(net, dev, pinfo, in6_dev,
2562 &addr, addr_type,
2563 addr_flags, sllao,
2564 tokenized, valid_lft,
2565 prefered_lft);
2566 if (err)
2567 goto put;
2554 }
2555 inet6_prefix_notify(RTM_NEWPREFIX, in6_dev, pinfo);
2568 }
2569 inet6_prefix_notify(RTM_NEWPREFIX, in6_dev, pinfo);
2570put:
2556 in6_dev_put(in6_dev);
2557}
2558
2559/*
2560 * Set destination address.
2561 * Special case for SIT interfaces where we create a new "virtual"
2562 * device.
2563 */

--- 3645 unchanged lines hidden ---
2571 in6_dev_put(in6_dev);
2572}
2573
2574/*
2575 * Set destination address.
2576 * Special case for SIT interfaces where we create a new "virtual"
2577 * device.
2578 */

--- 3645 unchanged lines hidden ---