예제 #1
0
/* router-only functions from net/gnrc/sixlowpan/nd.h */
void gnrc_sixlowpan_nd_opt_abr_handle(kernel_pid_t iface, ndp_rtr_adv_t *rtr_adv, int sicmpv6_size,
                                      sixlowpan_nd_opt_abr_t *abr_opt)
{
    uint16_t opt_offset = 0;
    uint8_t *buf = (uint8_t *)(rtr_adv + 1);
    gnrc_sixlowpan_nd_router_abr_t *abr;
    timex_t t = { 0, 0 };

    /* validity and version was checked in previously called
     * gnrc_sixlowpan_nd_router_abr_older() */

    abr = _get_abr(&abr_opt->braddr);

    if (abr == NULL) {
        return;
    }

    abr->ltime = byteorder_ntohs(abr_opt->ltime);

    if (abr->ltime == 0) {
        gnrc_sixlowpan_nd_router_abr_remove(abr);
        return;
    }

    sicmpv6_size -= sizeof(ndp_rtr_adv_t);

    while (sicmpv6_size > 0) {
        ndp_opt_t *opt = (ndp_opt_t *)(buf + opt_offset);

        switch (opt->type) {
            case NDP_OPT_PI:
                _add_prefix(iface, abr, (ndp_opt_pi_t *)opt);

            case NDP_OPT_6CTX:
                _add_ctx(abr, (sixlowpan_nd_opt_6ctx_t *)opt);

            default:
                break;
        }

        opt_offset += (opt->len * 8);
        sicmpv6_size -= (opt->len * 8);
    }

    abr->version = byteorder_ntohs(abr_opt->vlow);
    abr->version |= byteorder_ntohs(abr_opt->vhigh) << 16;
    abr->addr.u64[0] = abr_opt->braddr.u64[0];
    abr->addr.u64[1] = abr_opt->braddr.u64[1];
    memset(abr->ctxs, 0, sizeof(abr->ctxs));
    abr->prfs = NULL;

    t.seconds = abr->ltime * 60;

    vtimer_set_msg(&abr->ltimer, t, gnrc_ipv6_pid,
                   GNRC_SIXLOWPAN_ND_MSG_ABR_TIMEOUT, abr);
}
예제 #2
0
static void *_event_loop(void *args)
{
    msg_t msg, reply, msg_q[GNRC_IPV6_MSG_QUEUE_SIZE];
    gnrc_netreg_entry_t me_reg;

    (void)args;
    msg_init_queue(msg_q, GNRC_IPV6_MSG_QUEUE_SIZE);

    me_reg.demux_ctx = GNRC_NETREG_DEMUX_CTX_ALL;
    me_reg.pid = thread_getpid();

    /* register interest in all IPv6 packets */
    gnrc_netreg_register(GNRC_NETTYPE_IPV6, &me_reg);

    /* preinitialize ACK */
    reply.type = GNRC_NETAPI_MSG_TYPE_ACK;

    /* start event loop */
    while (1) {
        DEBUG("ipv6: waiting for incoming message.\n");
        msg_receive(&msg);

        switch (msg.type) {
            case GNRC_NETAPI_MSG_TYPE_RCV:
                DEBUG("ipv6: GNRC_NETAPI_MSG_TYPE_RCV received\n");
                _receive(msg.content.ptr);
                break;

            case GNRC_NETAPI_MSG_TYPE_SND:
                DEBUG("ipv6: GNRC_NETAPI_MSG_TYPE_SND received\n");
                _send(msg.content.ptr, true);
                break;

            case GNRC_NETAPI_MSG_TYPE_GET:
            case GNRC_NETAPI_MSG_TYPE_SET:
                DEBUG("ipv6: reply to unsupported get/set\n");
                reply.content.value = -ENOTSUP;
                msg_reply(&msg, &reply);
                break;

#ifdef MODULE_GNRC_NDP
            case GNRC_NDP_MSG_RTR_TIMEOUT:
                DEBUG("ipv6: Router timeout received\n");
                ((gnrc_ipv6_nc_t *)msg.content.ptr)->flags &= ~GNRC_IPV6_NC_IS_ROUTER;
                break;

            /* XXX reactivate when https://github.com/RIOT-OS/RIOT/issues/5122 is
             * solved properly */
            /* case GNRC_NDP_MSG_ADDR_TIMEOUT: */
            /*     DEBUG("ipv6: Router advertisement timer event received\n"); */
            /*     gnrc_ipv6_netif_remove_addr(KERNEL_PID_UNDEF, */
            /*                                 msg.content.ptr); */
            /*     break; */

            case GNRC_NDP_MSG_NBR_SOL_RETRANS:
                DEBUG("ipv6: Neigbor solicitation retransmission timer event received\n");
                gnrc_ndp_retrans_nbr_sol(msg.content.ptr);
                break;

            case GNRC_NDP_MSG_NC_STATE_TIMEOUT:
                DEBUG("ipv6: Neigbor cache state timeout received\n");
                gnrc_ndp_state_timeout(msg.content.ptr);
                break;
#endif
#ifdef MODULE_GNRC_NDP_ROUTER
            case GNRC_NDP_MSG_RTR_ADV_RETRANS:
                DEBUG("ipv6: Router advertisement retransmission event received\n");
                gnrc_ndp_router_retrans_rtr_adv(msg.content.ptr);
                break;
            case GNRC_NDP_MSG_RTR_ADV_DELAY:
                DEBUG("ipv6: Delayed router advertisement event received\n");
                gnrc_ndp_router_send_rtr_adv(msg.content.ptr);
                break;
#endif
#ifdef MODULE_GNRC_NDP_HOST
            case GNRC_NDP_MSG_RTR_SOL_RETRANS:
                DEBUG("ipv6: Router solicitation retransmission event received\n");
                gnrc_ndp_host_retrans_rtr_sol(msg.content.ptr);
                break;
#endif
#ifdef MODULE_GNRC_SIXLOWPAN_ND
            case GNRC_SIXLOWPAN_ND_MSG_MC_RTR_SOL:
                DEBUG("ipv6: Multicast router solicitation event received\n");
                gnrc_sixlowpan_nd_mc_rtr_sol(msg.content.ptr);
                break;
            case GNRC_SIXLOWPAN_ND_MSG_UC_RTR_SOL:
                DEBUG("ipv6: Unicast router solicitation event received\n");
                gnrc_sixlowpan_nd_uc_rtr_sol(msg.content.ptr);
                break;
#   ifdef MODULE_GNRC_SIXLOWPAN_CTX
            case GNRC_SIXLOWPAN_ND_MSG_DELETE_CTX:
                DEBUG("ipv6: Delete 6LoWPAN context event received\n");
                gnrc_sixlowpan_ctx_remove(((((gnrc_sixlowpan_ctx_t *)msg.content.ptr)->flags_id) &
                                           GNRC_SIXLOWPAN_CTX_FLAGS_CID_MASK));
                break;
#   endif
#endif
#ifdef MODULE_GNRC_SIXLOWPAN_ND_ROUTER
            case GNRC_SIXLOWPAN_ND_MSG_ABR_TIMEOUT:
                DEBUG("ipv6: border router timeout event received\n");
                gnrc_sixlowpan_nd_router_abr_remove(msg.content.ptr);
                break;
            /* XXX reactivate when https://github.com/RIOT-OS/RIOT/issues/5122 is
             * solved properly */
            /* case GNRC_SIXLOWPAN_ND_MSG_AR_TIMEOUT: */
            /*     DEBUG("ipv6: address registration timeout received\n"); */
            /*     gnrc_sixlowpan_nd_router_gc_nc(msg.content.ptr); */
            /*     break; */
            case GNRC_NDP_MSG_RTR_ADV_SIXLOWPAN_DELAY:
                DEBUG("ipv6: Delayed router advertisement event received\n");
                gnrc_ipv6_nc_t *nc_entry = msg.content.ptr;
                gnrc_ndp_internal_send_rtr_adv(nc_entry->iface, NULL,
                                               &(nc_entry->ipv6_addr), false);
                break;
#endif
            default:
                break;
        }
    }

    return NULL;
}