uint32_t ipv6_init(const ipv6_init_t * p_init) { uint32_t index; uint32_t err_code; ble_6lowpan_init_t init_params; NULL_PARAM_CHECK(p_init); NULL_PARAM_CHECK(p_init->p_eui64); NULL_PARAM_CHECK(p_init->event_handler); SDK_MUTEX_INIT(m_ipv6_mutex); IPV6_MUTEX_LOCK(); IPV6_ENTRY(); // Initialize related modules. UNUSED_VARIABLE(nrf_mem_init()); UNUSED_VARIABLE(iot_pbuffer_init()); // Initialize submodules of IPv6 stack. UNUSED_VARIABLE(udp_init()); UNUSED_VARIABLE(icmp6_init()); // Initialize context manager. UNUSED_VARIABLE(iot_context_manager_init()); IPV6_ADDRESS_INITIALIZE(IPV6_ADDR_ANY); // Set application event handler. m_event_handler = p_init->event_handler; // Clear number of interfaces. m_interfaces_count = 0; // Clear network interfaces. for (index = 0; index < IPV6_MAX_INTERFACE; index++) { interface_reset(&m_interfaces[index]); } // Clear all addresses. for (index = 0; index < IPV6_MAX_ADDRESS_COUNT; index++) { addr_free(index, false); } // 6LoWPAN module initialization. init_params.p_eui64 = p_init->p_eui64; init_params.event_handler = ble_6lowpan_evt_handler; err_code = ble_6lowpan_init(&init_params); IPV6_EXIT(); IPV6_MUTEX_UNLOCK(); return err_code; }
static status_t icmp6_std_ops(int32 op, ...) { switch (op) { case B_MODULE_INIT: return icmp6_init(); case B_MODULE_UNINIT: return B_OK; default: return B_ERROR; } }
/* * 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; struct timeval tv; #if 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; for (pr = (struct ip6protosw*)inet6domain.dom_protosw; pr; pr = pr->pr_next) { if(!((unsigned int)pr->pr_domain)) continue; /* If uninitialized, skip */ if (pr->pr_domain->dom_family == PF_INET6 && pr->pr_protocol && pr->pr_protocol != IPPROTO_RAW) { ip6_protox[pr->pr_protocol] = pr; } } ip6intrq.ifq_maxlen = ip6qmaxlen; #ifndef __APPLE__ register_netisr(NETISR_IPV6, ip6intr); #endif nd6_init(); frag6_init(); icmp6_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 = random() ^ tv.tv_usec; microtime(&tv); ip6_desync_factor = (random() ^ tv.tv_usec) % MAX_TEMP_DESYNC_FACTOR; timeout(ip6_init2, (caddr_t)0, 2 * hz); }
/* * 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; struct timeval tv; #if DIAGNOSTIC if (sizeof(struct protosw) != sizeof(struct ip6protosw)) panic("sizeof(protosw) != sizeof(ip6protosw)"); #endif pr = (struct ip6protosw *)pffindproto_locked(PF_INET6, IPPROTO_RAW, SOCK_RAW); if (pr == 0) panic("ip6_init"); for (i = 0; i < IPPROTO_MAX; i++) ip6_protox[i] = pr; for (pr = (struct ip6protosw*)inet6domain.dom_protosw; pr; pr = pr->pr_next) { if(!(pr->pr_domain)) continue; /* If uninitialized, skip */ if (pr->pr_domain->dom_family == PF_INET6 && pr->pr_protocol && pr->pr_protocol != IPPROTO_RAW) { ip6_protox[pr->pr_protocol] = pr; } } ip6_mutex_grp_attr = lck_grp_attr_alloc_init(); ip6_mutex_grp = lck_grp_alloc_init("ip6", ip6_mutex_grp_attr); ip6_mutex_attr = lck_attr_alloc_init(); if ((ip6_mutex = lck_mtx_alloc_init(ip6_mutex_grp, ip6_mutex_attr)) == NULL) { panic("ip6_init: can't alloc ip6_mutex\n"); } if ((dad6_mutex = lck_mtx_alloc_init(ip6_mutex_grp, ip6_mutex_attr)) == NULL) { panic("ip6_init: can't alloc dad6_mutex\n"); } if ((nd6_mutex = lck_mtx_alloc_init(ip6_mutex_grp, ip6_mutex_attr)) == NULL) { panic("ip6_init: can't alloc nd6_mutex\n"); } if ((prefix6_mutex = lck_mtx_alloc_init(ip6_mutex_grp, ip6_mutex_attr)) == NULL) { panic("ip6_init: can't alloc prefix6_mutex\n"); } if ((scope6_mutex = lck_mtx_alloc_init(ip6_mutex_grp, ip6_mutex_attr)) == NULL) { panic("ip6_init: can't alloc scope6_mutex\n"); } inet6domain.dom_flags = DOM_REENTRANT; ip6intrq.ifq_maxlen = ip6qmaxlen; in6_ifaddr_init(); nd6_init(); frag6_init(); icmp6_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 = random() ^ tv.tv_usec; microtime(&tv); ip6_desync_factor = (random() ^ tv.tv_usec) % MAX_TEMP_DESYNC_FACTOR; timeout(ip6_init2, (caddr_t)0, 1 * hz); lck_mtx_unlock(domain_proto_mtx); proto_register_input(PF_INET6, ip6_proto_input, NULL, 0); lck_mtx_lock(domain_proto_mtx); }
int main(int argc, char **argv) { pthread_t sigth; sigset_t sigblock; int logflags = 0; int ret = 1; debug_init(); sigemptyset(&sigblock); sigaddset(&sigblock, SIGHUP); sigaddset(&sigblock, SIGINT); sigaddset(&sigblock, SIGTERM); #ifdef ENABLE_VT sigaddset(&sigblock, SIGPIPE); #endif pthread_sigmask(SIG_BLOCK, &sigblock, NULL); if (conf_parse(&conf, argc, argv)) return 1; if (conf.debug_level > 0) logflags = LOG_PERROR; openlog(basename(argv[0]), LOG_PID|logflags, LOG_DAEMON); syslog(LOG_INFO, "%s v%s started (%s)", PACKAGE_NAME, PACKAGE_VERSION, entity_string[conf.mip6_entity]); #ifdef ENABLE_VT if (vt_init() < 0) goto vt_failed; #endif /* if not debugging, detach from tty */ if (conf.debug_level == 0) daemon_start(1); else { /* if debugging with debug log file, detach from tty */ if (conf.debug_log_file) { daemon_start(1); ret = debug_open(conf.debug_log_file); if (ret < 0) { fprintf(stderr, "can't init debug log:%s\n", strerror(-ret)); goto debug_failed; } dbg("%s started in debug mode\n", PACKAGE_NAME); } else { dbg("%s started in debug mode, not detaching from terminal\n", PACKAGE_NAME); } conf_show(&conf); } srandom(time(NULL)); if (rr_cn_init() < 0) goto rr_cn_failed; if (policy_init() < 0) goto policy_failed; if (taskqueue_init() < 0) goto taskqueue_failed; if (bcache_init() < 0) goto bcache_failed; if (mh_init() < 0) goto mh_failed; if (icmp6_init() < 0) goto icmp6_failed; if (xfrm_init() < 0) goto xfrm_failed; cn_init(); if ((is_ha() || is_mn()) && tunnelctl_init() < 0) goto tunnelctl_failed; if (is_ha() && ha_init() < 0) goto ha_failed; if (is_mn() && mn_init() < 0) goto mn_failed; #ifdef ENABLE_VT if (vt_start(conf.vt_hostname, conf.vt_service) < 0) goto vt_start_failed; #endif if (pthread_create(&sigth, NULL, sigh, NULL)) goto sigth_failed; pthread_join(sigth, NULL); ret = 0; sigth_failed: #ifdef ENABLE_VT vt_fini(); vt_start_failed: #endif if (is_mn()) mn_cleanup(); mn_failed: if (is_ha()) ha_cleanup(); ha_failed: if (is_ha() || is_mn()) tunnelctl_cleanup(); tunnelctl_failed: cn_cleanup(); xfrm_cleanup(); xfrm_failed: icmp6_cleanup(); icmp6_failed: mh_cleanup(); mh_failed: bcache_cleanup(); bcache_failed: taskqueue_destroy(); taskqueue_failed: policy_cleanup(); policy_failed: rr_cn_failed: debug_close(); debug_failed: #ifdef ENABLE_VT vt_failed: #endif syslog(LOG_INFO, "%s v%s stopped (%s)", PACKAGE_NAME, PACKAGE_VERSION, entity_string[conf.mip6_entity]); closelog(); return ret; }