Beispiel #1
0
static void sit_add_v4_addrs(struct inet6_dev *idev)
{
    struct inet6_ifaddr * ifp;
    struct in6_addr addr;
    struct device *dev;
    int scope;

    memset(&addr, 0, sizeof(struct in6_addr));
    memcpy(&addr.s6_addr32[3], idev->dev->dev_addr, 4);

    if (idev->dev->flags&IFF_POINTOPOINT) {
        addr.s6_addr32[0] = __constant_htonl(0xfe800000);
        scope = IFA_LINK;
    } else {
        scope = IPV6_ADDR_COMPATv4;
    }

    if (addr.s6_addr32[3]) {
        ifp = ipv6_add_addr(idev, &addr, scope);
        if (ifp) {
            ifp->flags |= ADDR_PERMANENT;
            ifp->prefix_len = 128;
            ipv6_ifa_notify(RTM_NEWADDR, ifp);
        }
        return;
    }

    for (dev = dev_base; dev != NULL; dev = dev->next) {
        if (dev->ip_ptr && (dev->flags & IFF_UP)) {
            struct in_device * in_dev = dev->ip_ptr;
            struct in_ifaddr * ifa;

            int flag = scope;

            for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
                addr.s6_addr32[3] = ifa->ifa_local;

                if (ifa->ifa_scope == RT_SCOPE_LINK)
                    continue;
                if (ifa->ifa_scope >= RT_SCOPE_HOST) {
                    if (idev->dev->flags&IFF_POINTOPOINT)
                        continue;
                    flag |= IFA_HOST;
                }

                ifp = ipv6_add_addr(idev, &addr, flag);

                if (ifp == NULL)
                    continue;

                if (idev->dev->flags&IFF_POINTOPOINT)
                    ifp->prefix_len = 10;
                else
                    ifp->prefix_len = 96;
                ifp->flags |= ADDR_PERMANENT;
                ipv6_ifa_notify(RTM_NEWADDR, ifp);
            }
        }
    }
}
Beispiel #2
0
static void init_loopback(struct net_device *dev)
{
	struct in6_addr addr;
	struct inet6_dev  *idev;
	struct inet6_ifaddr * ifp;

	/* ::1 */

	ASSERT_RTNL();

	memset(&addr, 0, sizeof(struct in6_addr));
	addr.s6_addr[15] = 1;

	if ((idev = ipv6_find_idev(dev)) == NULL) {
		printk(KERN_DEBUG "init loopback: add_dev failed\n");
		return;
	}

	ifp = ipv6_add_addr(idev, &addr, 128, IFA_HOST, IFA_F_PERMANENT);
	if (ifp) {
		spin_lock_bh(&ifp->lock);
		ifp->flags &= ~IFA_F_TENTATIVE;
		spin_unlock_bh(&ifp->lock);
		ipv6_ifa_notify(RTM_NEWADDR, ifp);
		in6_ifa_put(ifp);
	}
}
Beispiel #3
0
static void init_loopback(struct device *dev)
{
    struct in6_addr addr;
    struct inet6_dev  *idev;
    struct inet6_ifaddr * ifp;

    /* ::1 */

    memset(&addr, 0, sizeof(struct in6_addr));
    addr.s6_addr[15] = 1;

    if ((idev = ipv6_find_idev(dev)) == NULL) {
        printk(KERN_DEBUG "init loopback: add_dev failed\n");
        return;
    }

    ifp = ipv6_add_addr(idev, &addr, IFA_HOST);

    if (ifp == NULL) {
        printk(KERN_DEBUG "init_loopback: add_addr failed\n");
        return;
    }

    ifp->flags |= ADDR_PERMANENT;
    ifp->prefix_len = 128;

    ipv6_ifa_notify(RTM_NEWADDR, ifp);
}
Beispiel #4
0
static void ipv6_del_addr(struct inet6_ifaddr *ifp)
{
	struct inet6_ifaddr *iter, **back;
	int hash;

	if (atomic_read(&addr_list_lock)) {
		ifp->flags |= ADDR_INVALID;
		ipv6_ifa_notify(RTM_DELADDR, ifp);
		return;
	}

	hash = ipv6_addr_hash(&ifp->addr);

	iter = inet6_addr_lst[hash];
	back = &inet6_addr_lst[hash];

	for (; iter; iter = iter->lst_next) {
		if (iter == ifp) {
			*back = ifp->lst_next;
			synchronize_bh();

			ifp->lst_next = NULL;
			break;
		}
		back = &(iter->lst_next);
	}

	iter = ifp->idev->addr_list;
	back = &ifp->idev->addr_list;

	for (; iter; iter = iter->if_next) {
		if (iter == ifp) {
			*back = ifp->if_next;
			synchronize_bh();

			ifp->if_next = NULL;
			break;
		}
		back = &(iter->if_next);
	}

	ipv6_ifa_notify(RTM_DELADDR, ifp);
	del_timer(&ifp->timer);
	
	kfree(ifp);
}
Beispiel #5
0
static void ipv6_del_addr(struct inet6_ifaddr *ifp)
{
	struct inet6_ifaddr *ifa, **ifap;
	struct inet6_dev *idev = ifp->idev;
	int hash;

	hash = ipv6_addr_hash(&ifp->addr);

	ifp->dead = 1;

	write_lock_bh(&addrconf_hash_lock);
	for (ifap = &inet6_addr_lst[hash]; (ifa=*ifap) != NULL;
	     ifap = &ifa->lst_next) {
		if (ifa == ifp) {
			*ifap = ifa->lst_next;
			__in6_ifa_put(ifp);
			ifa->lst_next = NULL;
			break;
		}
	}
	write_unlock_bh(&addrconf_hash_lock);

	write_lock_bh(&idev->lock);
	for (ifap = &idev->addr_list; (ifa=*ifap) != NULL;
	     ifap = &ifa->if_next) {
		if (ifa == ifp) {
			*ifap = ifa->if_next;
			__in6_ifa_put(ifp);
			ifa->if_next = NULL;
			break;
		}
	}
	write_unlock_bh(&idev->lock);

	ipv6_ifa_notify(RTM_DELADDR, ifp);

	notifier_call_chain(&inet6addr_chain,NETDEV_DOWN,ifp);

	addrconf_del_timer(ifp);

	in6_ifa_put(ifp);
}
Beispiel #6
0
void addrconf_prefix_rcv(struct net_device *dev, u8 *opt, int len)
{
	struct prefix_info *pinfo;
	struct rt6_info *rt;
	__u32 valid_lft;
	__u32 prefered_lft;
	int addr_type;
	unsigned long rt_expires;
	struct inet6_dev *in6_dev;

	pinfo = (struct prefix_info *) opt;
	
	if (len < sizeof(struct prefix_info)) {
		ADBG(("addrconf: prefix option too short\n"));
		return;
	}
	
	/*
	 *	Validation checks ([ADDRCONF], page 19)
	 */

	addr_type = ipv6_addr_type(&pinfo->prefix);

	if (addr_type & (IPV6_ADDR_MULTICAST|IPV6_ADDR_LINKLOCAL))
		return;

	valid_lft = ntohl(pinfo->valid);
	prefered_lft = ntohl(pinfo->prefered);

	if (prefered_lft > valid_lft) {
		if (net_ratelimit())
			printk(KERN_WARNING "addrconf: prefix option has invalid lifetime\n");
		return;
	}

	in6_dev = in6_dev_get(dev);

	if (in6_dev == NULL) {
		if (net_ratelimit())
			printk(KERN_DEBUG "addrconf: device %s not configured\n", dev->name);
		return;
	}

	/*
	 *	Two things going on here:
	 *	1) Add routes for on-link prefixes
	 *	2) Configure prefixes with the auto flag set
	 */

	/* Avoid arithemtic overflow. Really, we could
	   save rt_expires in seconds, likely valid_lft,
	   but it would require division in fib gc, that it
	   not good.
	 */
	if (valid_lft >= 0x7FFFFFFF/HZ)
		rt_expires = 0;
	else
		rt_expires = jiffies + valid_lft * HZ;

	rt = rt6_lookup(&pinfo->prefix, NULL, dev->ifindex, 1);

	if (rt && ((rt->rt6i_flags & (RTF_GATEWAY | RTF_DEFAULT)) == 0)) {
		if (rt->rt6i_flags&RTF_EXPIRES) {
			if (pinfo->onlink == 0 || valid_lft == 0) {
				ip6_del_rt(rt);
				rt = NULL;
			} else {
				rt->rt6i_expires = rt_expires;
			}
		}
	} else if (pinfo->onlink && valid_lft) {
		addrconf_prefix_route(&pinfo->prefix, pinfo->prefix_len,
				      dev, rt_expires, RTF_ADDRCONF|RTF_EXPIRES);
	}
	if (rt)
		dst_release(&rt->u.dst);

	/* Try to figure out our local address for this prefix */

	if (pinfo->autoconf && in6_dev->cnf.autoconf) {
		struct inet6_ifaddr * ifp;
		struct in6_addr addr;
		int plen;

		plen = pinfo->prefix_len >> 3;

		if (pinfo->prefix_len == 64) {
			memcpy(&addr, &pinfo->prefix, 8);
			if (ipv6_generate_eui64(addr.s6_addr + 8, dev) &&
			    ipv6_inherit_eui64(addr.s6_addr + 8, in6_dev)) {
				in6_dev_put(in6_dev);
				return;
			}
			goto ok;
		}
		if (net_ratelimit())
			printk(KERN_DEBUG "IPv6 addrconf: prefix with wrong length %d\n",
			       pinfo->prefix_len);
		in6_dev_put(in6_dev);
		return;

ok:

		ifp = ipv6_get_ifaddr(&addr, dev);

		if (ifp == NULL && valid_lft) {
			ifp = ipv6_add_addr(in6_dev, &addr, pinfo->prefix_len,
					    addr_type&IPV6_ADDR_SCOPE_MASK, 0);

			if (ifp == NULL) {
				in6_dev_put(in6_dev);
				return;
			}

			addrconf_dad_start(ifp);
		}

		if (ifp && valid_lft == 0) {
			ipv6_del_addr(ifp);
			ifp = NULL;
		}

		if (ifp) {
			int flags;

			spin_lock(&ifp->lock);
			ifp->valid_lft = valid_lft;
			ifp->prefered_lft = prefered_lft;
			ifp->tstamp = jiffies;
			flags = ifp->flags;
			ifp->flags &= ~IFA_F_DEPRECATED;
			spin_unlock(&ifp->lock);

			if (!(flags&IFA_F_TENTATIVE))
				ipv6_ifa_notify((flags&IFA_F_DEPRECATED) ?
						0 : RTM_NEWADDR, ifp);
			in6_ifa_put(ifp);
		}
	}
	in6_dev_put(in6_dev);
}
Beispiel #7
0
static void sit_add_v4_addrs(struct inet6_dev *idev)
{
	struct inet6_ifaddr * ifp;
	struct in6_addr addr;
	struct net_device *dev;
	int scope;

	ASSERT_RTNL();

	memset(&addr, 0, sizeof(struct in6_addr));
	memcpy(&addr.s6_addr32[3], idev->dev->dev_addr, 4);

	if (idev->dev->flags&IFF_POINTOPOINT) {
		addr.s6_addr32[0] = __constant_htonl(0xfe800000);
		scope = IFA_LINK;
	} else {
		scope = IPV6_ADDR_COMPATv4;
	}

	if (addr.s6_addr32[3]) {
		ifp = ipv6_add_addr(idev, &addr, 128, scope, IFA_F_PERMANENT);
		if (ifp) {
			spin_lock_bh(&ifp->lock);
			ifp->flags &= ~IFA_F_TENTATIVE;
			spin_unlock_bh(&ifp->lock);
			ipv6_ifa_notify(RTM_NEWADDR, ifp);
			in6_ifa_put(ifp);
		}
		return;
	}

        for (dev = dev_base; dev != NULL; dev = dev->next) {
		struct in_device * in_dev = __in_dev_get(dev);
		if (in_dev && (dev->flags & IFF_UP)) {
			struct in_ifaddr * ifa;

			int flag = scope;

			for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
				int plen;

				addr.s6_addr32[3] = ifa->ifa_local;

				if (ifa->ifa_scope == RT_SCOPE_LINK)
					continue;
				if (ifa->ifa_scope >= RT_SCOPE_HOST) {
					if (idev->dev->flags&IFF_POINTOPOINT)
						continue;
					flag |= IFA_HOST;
				}
				if (idev->dev->flags&IFF_POINTOPOINT)
					plen = 10;
				else
					plen = 96;

				ifp = ipv6_add_addr(idev, &addr, plen, flag,
						    IFA_F_PERMANENT);
				if (ifp) {
					spin_lock_bh(&ifp->lock);
					ifp->flags &= ~IFA_F_TENTATIVE;
					spin_unlock_bh(&ifp->lock);
					ipv6_ifa_notify(RTM_NEWADDR, ifp);
					in6_ifa_put(ifp);
				}
			}
		}
        }
}
Beispiel #8
0
void addrconf_prefix_rcv(struct device *dev, u8 *opt, int len)
{
    struct prefix_info *pinfo;
    struct rt6_info *rt;
    __u32 valid_lft;
    __u32 prefered_lft;
    int addr_type;
    unsigned long rt_expires;
    struct inet6_dev *in6_dev = ipv6_get_idev(dev);

    if (in6_dev == NULL) {
        printk(KERN_DEBUG "addrconf: device %s not configured\n", dev->name);
        return;
    }

    pinfo = (struct prefix_info *) opt;

    if (len < sizeof(struct prefix_info)) {
        ADBG(("addrconf: prefix option too short\n"));
        return;
    }

    /*
     *	Validation checks ([ADDRCONF], page 19)
     */

    addr_type = ipv6_addr_type(&pinfo->prefix);

    if (addr_type & (IPV6_ADDR_MULTICAST|IPV6_ADDR_LINKLOCAL))
        return;

    valid_lft = ntohl(pinfo->valid);
    prefered_lft = ntohl(pinfo->prefered);

    if (prefered_lft > valid_lft) {
        printk(KERN_WARNING "addrconf: prefix option has invalid lifetime\n");
        return;
    }

    /*
     *	If we where using an "all destinations on link" route
     *	delete it
     */

    rt6_purge_dflt_routers(RTF_ALLONLINK);

    /*
     *	Two things going on here:
     *	1) Add routes for on-link prefixes
     *	2) Configure prefixes with the auto flag set
     */

    /* Avoid arithemtic overflow. Really, we could
       save rt_expires in seconds, likely valid_lft,
       but it would require division in fib gc, that it
       not good.
     */
    if (valid_lft >= 0x7FFFFFFF/HZ)
        rt_expires = 0;
    else
        rt_expires = jiffies + valid_lft * HZ;

    rt = rt6_lookup(&pinfo->prefix, NULL, dev->ifindex, 1);

    if (rt && ((rt->rt6i_flags & (RTF_GATEWAY | RTF_DEFAULT)) == 0)) {
        if (rt->rt6i_flags&RTF_EXPIRES) {
            if (pinfo->onlink == 0 || valid_lft == 0) {
                ip6_del_rt(rt);
            } else {
                rt->rt6i_expires = rt_expires;
            }
        }
    } else if (pinfo->onlink && valid_lft) {
        addrconf_prefix_route(&pinfo->prefix, pinfo->prefix_len,
                              dev, rt_expires, RTF_ADDRCONF|RTF_EXPIRES);
    }
    if (rt)
        dst_release(&rt->u.dst);

    /* Try to figure out our local address for this prefix */

    if (pinfo->autoconf && in6_dev->cnf.autoconf) {
        struct inet6_ifaddr * ifp;
        struct in6_addr addr;
        int plen;

        plen = pinfo->prefix_len >> 3;

#ifdef CONFIG_IPV6_EUI64
        if (pinfo->prefix_len == 64) {
            memcpy(&addr, &pinfo->prefix, 8);
            if (ipv6_generate_eui64(addr.s6_addr + 8, dev))
                return;
            goto ok;
        }
#endif
#ifndef CONFIG_IPV6_NO_PB
        if (pinfo->prefix_len == ((sizeof(struct in6_addr) - dev->addr_len)<<3)) {
            memcpy(&addr, &pinfo->prefix, plen);
            memcpy(addr.s6_addr + plen, dev->dev_addr,
                   dev->addr_len);
            goto ok;
        }
#endif
        printk(KERN_DEBUG "IPv6 addrconf: prefix with wrong length %d\n", pinfo->prefix_len);
        return;

ok:
        ifp = ipv6_chk_addr(&addr, dev, 1);

        if ((ifp == NULL || (ifp->flags&ADDR_INVALID)) && valid_lft) {

            if (ifp == NULL)
                ifp = ipv6_add_addr(in6_dev, &addr, addr_type & IPV6_ADDR_SCOPE_MASK);

            if (ifp == NULL)
                return;

            ifp->prefix_len = pinfo->prefix_len;

            addrconf_dad_start(ifp);
        }

        if (ifp && valid_lft == 0) {
            ipv6_del_addr(ifp);
            ifp = NULL;
        }

        if (ifp) {
            int event = 0;
            ifp->valid_lft = valid_lft;
            ifp->prefered_lft = prefered_lft;
            ifp->tstamp = jiffies;
            if (ifp->flags & ADDR_INVALID)
                event = RTM_NEWADDR;
            ifp->flags &= ~(ADDR_DEPRECATED|ADDR_INVALID);
            ipv6_ifa_notify(event, ifp);
        }
    }
}