Пример #1
0
/*
 * IP6 initialization: fill in IP6 protocol switch table.
 * All protocols not implemented in kernel go to raw IP6 protocol handler.
 */
void
ip6_init(void)
{
	struct ip6protosw *pr;
	int i;

	TUNABLE_INT_FETCH("net.inet6.ip6.auto_linklocal",
	    &V_ip6_auto_linklocal);
	TUNABLE_INT_FETCH("net.inet6.ip6.accept_rtadv", &V_ip6_accept_rtadv);
	TUNABLE_INT_FETCH("net.inet6.ip6.no_radr", &V_ip6_no_radr);

	TAILQ_INIT(&V_in6_ifaddrhead);
	V_in6_ifaddrhashtbl = hashinit(IN6ADDR_NHASH, M_IFADDR,
	    &V_in6_ifaddrhmask);

	/* Initialize packet filter hooks. */
	V_inet6_pfil_hook.ph_type = PFIL_TYPE_AF;
	V_inet6_pfil_hook.ph_af = AF_INET6;
	if ((i = pfil_head_register(&V_inet6_pfil_hook)) != 0)
		printf("%s: WARNING: unable to register pfil hook, "
			"error %d\n", __func__, i);

	scope6_init();
	addrsel_policy_init();
	nd6_init();
	frag6_init();

	V_ip6_desync_factor = arc4random() % MAX_TEMP_DESYNC_FACTOR;

	/* Skip global initialization stuff for non-default instances. */
	if (!IS_DEFAULT_VNET(curvnet))
		return;

#ifdef DIAGNOSTIC
	if (sizeof(struct protosw) != sizeof(struct ip6protosw))
		panic("sizeof(protosw) != sizeof(ip6protosw)");
#endif
	pr = (struct ip6protosw *)pffindproto(PF_INET6, IPPROTO_RAW, SOCK_RAW);
	if (pr == NULL)
		panic("ip6_init");

	/* Initialize the entire ip6_protox[] array to IPPROTO_RAW. */
	for (i = 0; i < IPPROTO_MAX; i++)
		ip6_protox[i] = pr - inet6sw;
	/*
	 * Cycle through IP protocols and put them into the appropriate place
	 * in ip6_protox[].
	 */
	for (pr = (struct ip6protosw *)inet6domain.dom_protosw;
	    pr < (struct ip6protosw *)inet6domain.dom_protoswNPROTOSW; pr++)
		if (pr->pr_domain->dom_family == PF_INET6 &&
		    pr->pr_protocol && pr->pr_protocol != IPPROTO_RAW) {
			/* Be careful to only index valid IP protocols. */
			if (pr->pr_protocol < IPPROTO_MAX)
				ip6_protox[pr->pr_protocol] = pr - inet6sw;
		}

	netisr_register(&ip6_nh);
}
Пример #2
0
/*
 * IP6 initialization: fill in IP6 protocol switch table.
 * All protocols not implemented in kernel go to raw IP6 protocol handler.
 */
void
ip6_init(void)
{
	struct protosw *pr;
	int i;
	struct timeval tv;

	pr = pffindproto(PF_INET6, IPPROTO_RAW, SOCK_RAW);
	if (pr == NULL)
		panic("ip6_init");
	for (i = 0; i < IPPROTO_MAX; i++)
		ip6_protox[i] = pr - inet6sw;
	for (pr = inet6domain.dom_protosw;
	    pr < inet6domain.dom_protoswNPROTOSW; pr++)
		if (pr->pr_domain->dom_family == PF_INET6 &&
		    pr->pr_protocol && pr->pr_protocol != IPPROTO_RAW)
			ip6_protox[pr->pr_protocol] = pr - inet6sw;

	inet6_pfil_hook.ph_type = PFIL_TYPE_AF;
	inet6_pfil_hook.ph_af = AF_INET6;
	if ((i = pfil_head_register(&inet6_pfil_hook)) != 0) {
		kprintf("%s: WARNING: unable to register pfil hook, "
			"error %d\n", __func__, i);
	}

	netisr_register(NETISR_IPV6, ip6_input, NULL); /* XXX cpufn */
	scope6_init();
	addrsel_policy_init();
	nd6_init();
	frag6_init();
	/*
	 * in many cases, random() here does NOT return random number
	 * as initialization during bootstrap time occur in fixed order.
	 */
	microtime(&tv);
	ip6_flow_seq = krandom() ^ tv.tv_usec;
	microtime(&tv);
	ip6_desync_factor = (krandom() ^ tv.tv_usec) % MAX_TEMP_DESYNC_FACTOR;
}
Пример #3
0
/*
 * IP6 initialization: fill in IP6 protocol switch table.
 * All protocols not implemented in kernel go to raw IP6 protocol handler.
 */
void
ip6_init()
{
    struct ip6protosw *pr;
    int i;

#ifdef DIAGNOSTIC
    if (sizeof(struct protosw) != sizeof(struct ip6protosw))
        panic("sizeof(protosw) != sizeof(ip6protosw)");
#endif
    pr = (struct ip6protosw *)pffindproto(PF_INET6, IPPROTO_RAW, SOCK_RAW);
    if (pr == 0)
        panic("ip6_init");
    for (i = 0; i < IPPROTO_MAX; i++)
        ip6_protox[i] = pr - inet6sw;
    for (pr = (struct ip6protosw *)inet6domain.dom_protosw;
            pr < (struct ip6protosw *)inet6domain.dom_protoswNPROTOSW; pr++)
        if (pr->pr_domain->dom_family == PF_INET6 &&
                pr->pr_protocol && pr->pr_protocol != IPPROTO_RAW)
            ip6_protox[pr->pr_protocol] = pr - inet6sw;

    /* Initialize packet filter hooks. */
    inet6_pfil_hook.ph_type = PFIL_TYPE_AF;
    inet6_pfil_hook.ph_af = AF_INET6;
    if ((i = pfil_head_register(&inet6_pfil_hook)) != 0)
        printf("%s: WARNING: unable to register pfil hook, "
               "error %d\n", __func__, i);

    ip6intrq.ifq_maxlen = ip6qmaxlen;
    mtx_init(&ip6intrq.ifq_mtx, "ip6_inq", NULL, MTX_DEF);
    netisr_register(NETISR_IPV6, ip6_input, &ip6intrq, 0);
    scope6_init();
    addrsel_policy_init();
    nd6_init();
    frag6_init();
    ip6_desync_factor = arc4random() % MAX_TEMP_DESYNC_FACTOR;
}
Пример #4
0
/*
 * IP6 initialization: fill in IP6 protocol switch table.
 * All protocols not implemented in kernel go to raw IP6 protocol handler.
 */
void
ip6_init(void)
{
	struct ip6protosw *pr;
	int i;

	TUNABLE_INT_FETCH("net.inet6.ip6.auto_linklocal",
	    &V_ip6_auto_linklocal);

	TAILQ_INIT(&V_in6_ifaddrhead);

	/* Initialize packet filter hooks. */
	V_inet6_pfil_hook.ph_type = PFIL_TYPE_AF;
	V_inet6_pfil_hook.ph_af = AF_INET6;
	if ((i = pfil_head_register(&V_inet6_pfil_hook)) != 0)
		printf("%s: WARNING: unable to register pfil hook, "
			"error %d\n", __func__, i);

	scope6_init();
	addrsel_policy_init();
	nd6_init();
	frag6_init();

#ifdef FLOWTABLE
	if (TUNABLE_INT_FETCH("net.inet6.ip6.output_flowtable_size",
		&V_ip6_output_flowtable_size)) {
		if (V_ip6_output_flowtable_size < 256)
			V_ip6_output_flowtable_size = 256;
		if (!powerof2(V_ip6_output_flowtable_size)) {
			printf("flowtable must be power of 2 size\n");
			V_ip6_output_flowtable_size = 2048;
		}
	} else {
		/*
		 * round up to the next power of 2
		 */
		V_ip6_output_flowtable_size = 1 << fls((1024 + maxusers * 64)-1);
	}
	V_ip6_ft = flowtable_alloc("ipv6", V_ip6_output_flowtable_size, FL_IPV6|FL_PCPU);
#endif	
	
	V_ip6_desync_factor = arc4random() % MAX_TEMP_DESYNC_FACTOR;

	/* Skip global initialization stuff for non-default instances. */
	if (!IS_DEFAULT_VNET(curvnet))
		return;

#ifdef DIAGNOSTIC
	if (sizeof(struct protosw) != sizeof(struct ip6protosw))
		panic("sizeof(protosw) != sizeof(ip6protosw)");
#endif
	pr = (struct ip6protosw *)pffindproto(PF_INET6, IPPROTO_RAW, SOCK_RAW);
	if (pr == NULL)
		panic("ip6_init");

	/* Initialize the entire ip6_protox[] array to IPPROTO_RAW. */
	for (i = 0; i < IPPROTO_MAX; i++)
		ip6_protox[i] = pr - inet6sw;
	/*
	 * Cycle through IP protocols and put them into the appropriate place
	 * in ip6_protox[].
	 */
	for (pr = (struct ip6protosw *)inet6domain.dom_protosw;
	    pr < (struct ip6protosw *)inet6domain.dom_protoswNPROTOSW; pr++)
		if (pr->pr_domain->dom_family == PF_INET6 &&
		    pr->pr_protocol && pr->pr_protocol != IPPROTO_RAW) {
			/* Be careful to only index valid IP protocols. */
			if (pr->pr_protocol < IPPROTO_MAX)
				ip6_protox[pr->pr_protocol] = pr - inet6sw;
		}

	netisr_register(&ip6_nh);
}