Пример #1
0
void process_link_status_change(
    lispd_iface_elt     *iface,
    int                 new_status)
{
    if (iface->status == new_status) {
        lispd_log_msg(LISP_LOG_DEBUG_2,"process_link_status_change: The detected change of status doesn't affect");
        return;
    }

    if (iface->status_changed == TRUE) {
        iface->status_changed = FALSE;
    } else {
        iface->status_changed = TRUE;
    }

    // Change status of the interface
    iface->status = new_status;

    /*
     * If the affected interface is the default control or output iface, recalculate it
     */

    if (default_ctrl_iface_v4 == iface
            || default_ctrl_iface_v6 == iface
            || default_ctrl_iface_v4 == NULL
            || default_ctrl_iface_v6 == NULL) {
        lispd_log_msg(LISP_LOG_DEBUG_2,"Default control interface down. Recalculate new control interface");
        set_default_ctrl_ifaces();
    }

    if (default_out_iface_v4 == iface
            || default_out_iface_v6 == iface
            || default_out_iface_v4 == NULL
            || default_out_iface_v6 == NULL) {
        lispd_log_msg(LISP_LOG_DEBUG_2,"Default output interface down. Recalculate new output interface");
        set_default_output_ifaces();
    }
    iface_balancing_vectors_calc(iface);

    /* When NAT aware, if address has change when interface down, when UP init info request process */
    if(new_status == UP && nat_aware==TRUE && nat_aware_iface_address_change == TRUE) {
        initial_info_request_process();
        nat_aware_iface_address_change = FALSE;
    }

    /* Reprograming SMR timer*/
    if (smr_timer == NULL) {
        smr_timer = create_timer (SMR_TIMER);
    }

    start_timer(smr_timer, LISPD_SMR_TIMEOUT,(timer_callback)init_smr, NULL);

}
Пример #2
0
JNIEXPORT void JNICALL Java_org_lispmob_noroot_LISPmob_1JNI_lispd_1loop(JNIEnv * env, jclass cl)
{
    int    max_fd;
    fd_set readfds;
    int    retval;

    if (nat_aware == TRUE){
        initial_info_request_process();
    }else{
        initial_map_register_process();
        /*
         * SMR proxy-ITRs list to be updated with new mappings
         */

        init_smr(NULL,NULL);
    }

    /*
     * RLOC Probing proxy ETRs
     */
    programming_petr_rloc_probing();

    /*
     *  calculate the max_fd for select.
     */

        max_fd = tun_fd;
        if (default_rloc_afi != AF_INET6){
            max_fd = (max_fd > ipv4_data_input_fd)      ? max_fd : ipv4_data_input_fd;
            max_fd = (max_fd > ipv4_control_input_fd)   ? max_fd : ipv4_control_input_fd;
        }
        if (default_rloc_afi != AF_INET){
            max_fd = (max_fd > ipv6_data_input_fd)      ? max_fd : ipv6_data_input_fd;
            max_fd = (max_fd > ipv6_control_input_fd)   ? max_fd : ipv6_control_input_fd;
        }
        max_fd = (max_fd > timers_fd)               ? max_fd : timers_fd;
        max_fd = (max_fd > netlink_fd)              ? max_fd : netlink_fd;

        lispd_running = TRUE;

        while (lispd_running) {
            FD_ZERO(&readfds);
            FD_SET(tun_fd, &readfds);
            if (default_rloc_afi != AF_INET6){
                FD_SET(ipv4_data_input_fd, &readfds);
                FD_SET(ipv4_control_input_fd, &readfds);
            }
            if (default_rloc_afi != AF_INET){
                FD_SET(ipv6_data_input_fd, &readfds);
                FD_SET(ipv6_control_input_fd, &readfds);
            }
            FD_SET(timers_fd, &readfds);
            FD_SET(netlink_fd, &readfds);

            retval = have_input(max_fd, &readfds);

            if (retval != GOOD) {
                continue;        /* interrupted */
            }
            if (default_rloc_afi != AF_INET6){
                if (FD_ISSET(ipv4_data_input_fd, &readfds)) {
                    lispd_log_msg(LISP_LOG_DEBUG_3,"Received input IPv4 packet");
                    process_input_packet(ipv4_data_input_fd, AF_INET);
                }
                if (FD_ISSET(ipv4_control_input_fd, &readfds)) {
                    lispd_log_msg(LISP_LOG_DEBUG_3,"Received IPv4 packet in the control input buffer (4342)");
                    process_ctr_msg(ipv4_control_input_fd, AF_INET);
                }
            }
            if (default_rloc_afi != AF_INET){

                if (FD_ISSET(ipv6_data_input_fd, &readfds)) {
                    //lispd_log_msg(LISP_LOG_DEBUG_3,"Received input IPv6 packet");
                    process_input_packet(ipv6_data_input_fd, AF_INET6);
                }

                if (FD_ISSET(ipv6_control_input_fd, &readfds)) {
                    lispd_log_msg(LISP_LOG_DEBUG_3,"Received IPv6 packet in the control input buffer (4342)");
                    process_ctr_msg(ipv6_control_input_fd, AF_INET6);
                }
            }

            if (FD_ISSET(tun_fd, &readfds)) {
                lispd_log_msg(LISP_LOG_DEBUG_3,"Received packet in the tun buffer");
                process_output_packet(tun_fd);
            }

            if (FD_ISSET(timers_fd,&readfds)){
                //lispd_log_msg(LISP_LOG_DEBUG_3,"Received something in the timer fd");
                process_timer_signal(timers_fd);
            }

            if (FD_ISSET(netlink_fd,&readfds)){
                lispd_log_msg(LISP_LOG_DEBUG_3,"Received notification from net link");
                process_netlink_msg(netlink_fd);
            }
     }
     lispd_log_msg(LISP_LOG_DEBUG_2,"event_loop: Exiting from event loop");
}
Пример #3
0
int main(int argc, char **argv)
{
    uint32_t            iseed         = 0;  /* initial random number generator */
    pid_t               pid           = 0;    /* child pid */
    pid_t               sid           = 0;


    init_globales();

    /*
     *  Parse command line options
     */

    handle_lispd_command_line(argc, argv);

#ifndef ANDROID
    /*
     *  Check for required capabilities and drop unnecssary privileges
     */

    if(check_capabilities() != GOOD) {
        exit_cleanup();
    }
#else

    /*
     * Check for superuser privileges
     */
    if (geteuid() != 0) {
        lispd_log_msg(LISP_LOG_INFO,"Running %s requires superuser privileges! Exiting...\n", LISPD);
        exit_cleanup();
    }
#endif

    /*
     *  Initialize the random number generator
     */

    iseed = (unsigned int) time (NULL);
    srandom(iseed);

    /*
     * Set up signal handlers
     */
    signal(SIGHUP,  signal_handler);
    signal(SIGTERM, signal_handler);
    signal(SIGINT,  signal_handler);
    signal(SIGQUIT, signal_handler);


    /*
     *  set up databases
     */
    if (db_init() != GOOD ||
            map_cache_init() != GOOD ||
            init_referral_cache() != GOOD){
        exit_cleanup();
    }


    /*
     *  see if we need to daemonize, and if so, do it
     */

    if (daemonize) {
        lispd_log_msg(LISP_LOG_DEBUG_1, "Starting the daemonizing process1");
        if ((pid = fork()) < 0) {
            exit_cleanup();
        }
        umask(0);
        if (pid > 0){
            exit(EXIT_SUCCESS);
        }
        if ((sid = setsid()) < 0){
            exit_cleanup();
        }
        if ((chdir("/")) < 0){
            exit_cleanup();
        }
    }



    /*
     *  create timers
     */

    if (build_timers_event_socket(&timers_fd) != GOOD)
    {
        lispd_log_msg(LISP_LOG_CRIT, " Error programing the timer signal. Exiting...");
        exit_cleanup();
    }
    init_timers();



    /*
     * Create net_link socket to receive notifications of changes of RLOC status.
     */
    if ((netlink_fd = opent_netlink_socket()) == -1){
        lispd_log_msg(LISP_LOG_CRIT, " Error programing netlink socket. Exiting...");
        exit_cleanup();
    }

    /*
     *  Parse config file. Format of the file depends on the node: Linux Box or OpenWRT router
     */

#ifdef OPENWRT
    if (config_file == NULL){
        config_file = strdup("/etc/config/lispd");
    }
    err = handle_uci_lispd_config_file(config_file);
#else
    if (config_file == NULL){
        config_file = strdup("/etc/lispd.conf");
    }
    err = handle_lispd_config_file(config_file);
#endif

    if (err != GOOD){
        lispd_log_msg(LISP_LOG_CRIT,"Wrong configuration.");
        exit_cleanup();
    }

    if (ddt_client == FALSE){
        drop_referral_cache();
    }

    if (nat_aware == TRUE){
        nat_set_xTR_ID();
    }
    /*
     * Select the default rlocs for output data packets and output control packets
     */
    set_default_output_ifaces();

    set_default_ctrl_ifaces();

    /*
     * Create tun interface
     */

    if (create_tun(TUN_IFACE_NAME,
            TUN_RECEIVE_SIZE,
            TUN_MTU) != GOOD){
        exit_cleanup();
    }

    /*
     * Assign address to the tun interface and add routing to this interface
     */
    if (configure_routing_to_tun() != GOOD){
        exit_cleanup();
    }

    /*
     * Generate receive sockets for control (4342) and data port (4341)
     */

    if (default_rloc_afi == AF_UNSPEC || default_rloc_afi == AF_INET){
        ipv4_control_input_fd = open_control_input_socket(AF_INET);
        ipv4_data_input_fd = open_data_input_socket(AF_INET);
    }

    if (default_rloc_afi == AF_UNSPEC || default_rloc_afi == AF_INET6){
        ipv6_control_input_fd = open_control_input_socket(AF_INET6);
        ipv6_data_input_fd = open_data_input_socket(AF_INET6);
    }



    /*
     * Request to dump the routing tables to obtain the gatways when processing the netlink messages
     */

    request_route_table(RT_TABLE_MAIN, AF_INET);
    process_netlink_msg(netlink_fd);
    request_route_table(RT_TABLE_MAIN, AF_INET6);
    process_netlink_msg(netlink_fd);


#ifdef OPENWRT
    lispd_log_msg(LISP_LOG_INFO,"LISPmob %s compiled for openWRT\n", LISPD_VERSION);
#else
#ifdef ANDROID
    lispd_log_msg(LISP_LOG_INFO,"LISPmob %s compiled for Android\n", LISPD_VERSION);
#else
    lispd_log_msg(LISP_LOG_INFO,"LISPmob %s compiled for Linux\n", LISPD_VERSION);
#endif
#endif

    lispd_log_msg(LISP_LOG_INFO,"LISPmob (%s): 'lispd' started...", LISPD_VERSION);
    if (router_mode == TRUE){
        lispd_log_msg(LISP_LOG_INFO,"Running as an xTR router");
    }else{
        lispd_log_msg(LISP_LOG_INFO,"Running as a LISP mobile node");
    }



    /*
     *  Register to the Map-Server(s)
     */

    if (nat_aware == TRUE){
        initial_info_request_process();
    }else{
        initial_map_register_process();
        /*
         * SMR proxy-ITRs list to be updated with new mappings
         */

        init_smr(NULL,NULL);
    }


    /*
     * RLOC Probing proxy ETRs
     */
    programming_petr_rloc_probing();


    event_loop();

    lispd_log_msg(LISP_LOG_INFO, "Exiting...");         /* event_loop returned bad */
    closelog();
    return(0);
}
Пример #4
0
void process_address_change (
    lispd_iface_elt     *iface,
    lisp_addr_t         new_addr)
{
    lisp_addr_t                 *iface_addr         = NULL;
    lispd_iface_mappings_list   *mapping_list       = NULL;
    int                         aux_afi             = 0;

    // XXX To be modified when full NAT implemented --> When Nat Aware active no IPv6 RLOCs supported
    if (nat_aware == TRUE && new_addr.afi == AF_INET6) {
        return;
    }

    /* Check if the addres is a global address*/
    if (is_link_local_addr(new_addr) == TRUE) {
        lispd_log_msg(LISP_LOG_DEBUG_2,"precess_address_change: the extractet address from the netlink "
                      "messages is a local link address: %s discarded", get_char_from_lisp_addr_t(new_addr));
        return;
    }
    /* If default RLOC afi defined (-a 4 or 6), only accept addresses of the specified afi */
    if (default_rloc_afi != AF_UNSPEC && default_rloc_afi != new_addr.afi) {
        lispd_log_msg(LISP_LOG_DEBUG_2,"precess_address_change: Default RLOC afi defined (-a #): Skipped %s address in iface %s",
                      (new_addr.afi == AF_INET) ? "IPv4" : "IPv6",iface->iface_name);
        return;
    }
    /*
     * Actions to be done due to a change of address: SMR
     */

    switch (new_addr.afi) {
    case AF_INET:
        iface_addr = iface->ipv4_address;
        break;
    case AF_INET6:
        iface_addr = iface->ipv6_address;
        break;
    }

    // Same address that we already have
    if (compare_lisp_addr_t(iface_addr,&new_addr)==0) {
        lispd_log_msg(LISP_LOG_DEBUG_2,"precess_address_change: The detected change of address for interface %s "
                      "doesn't affect",iface->iface_name);
        /* We must rebind the socket just in case the address is from a virtual interface who has changed its interafce number */
        switch (new_addr.afi) {
        case AF_INET:
            bind_socket_src_address(iface->out_socket_v4,&new_addr);
            break;
        case AF_INET6:
            bind_socket_src_address(iface->out_socket_v6,&new_addr);
            break;
        }

        return;
    }

    /*
     * Change source routing rules for this interface and binding
     */

    if (iface_addr->afi != AF_UNSPEC) {
        del_rule(iface_addr->afi,
                 0,
                 iface->iface_index,
                 iface->iface_index,
                 RTN_UNICAST,
                 iface_addr,
                 (iface_addr->afi == AF_INET) ? 32 : 128,
                 NULL,0,0);
    }
    add_rule(new_addr.afi,
             0,
             iface->iface_index,
             iface->iface_index,
             RTN_UNICAST,
             &new_addr,
             (new_addr.afi == AF_INET) ? 32 : 128,
             NULL,0,0);

    switch (new_addr.afi) {
    case AF_INET:
        bind_socket_src_address(iface->out_socket_v4,&new_addr);
        break;
    case AF_INET6:
        bind_socket_src_address(iface->out_socket_v6,&new_addr);
        break;
    }


    aux_afi = iface_addr->afi;
    // Update the new address
    copy_lisp_addr(iface_addr, &new_addr);


    /* The interface was down during initial configuratiopn process and now it is up. Activate address */
    if (aux_afi == AF_UNSPEC) {
        lispd_log_msg(LISP_LOG_DEBUG_1,"process_address_change: Activating the locator address %s"
                      , get_char_from_lisp_addr_t(new_addr));
        activate_interface_address(iface, new_addr);
        if (iface->status == UP) {
            iface_balancing_vectors_calc(iface);

            /*
             * If no default control and data interface, recalculate it
             */

            if ((default_ctrl_iface_v4 == NULL && new_addr.afi == AF_INET) ||
                    (default_ctrl_iface_v6 == NULL && new_addr.afi == AF_INET6)) {
                lispd_log_msg(LISP_LOG_DEBUG_2,"No default control interface. Recalculate new control interface");
                set_default_ctrl_ifaces();
            }

            if ((default_out_iface_v4 == NULL && new_addr.afi == AF_INET) ||
                    (default_out_iface_v6 == NULL && new_addr.afi == AF_INET6)) {
                lispd_log_msg(LISP_LOG_DEBUG_2,"No default output interface. Recalculate new output interface");
                set_default_output_ifaces();
            }
        }
    }

    lispd_log_msg(LISP_LOG_DEBUG_1,"precess_address_change: New address detected for interface %s -> %s",
                  iface->iface_name, get_char_from_lisp_addr_t(new_addr));

    mapping_list = iface->head_mappings_list;
    /* Sort again the locators list of the affected mappings*/
    while (mapping_list != NULL) {
        if (aux_afi != AF_UNSPEC && // When the locator is activated, it is automatically sorted
                ((new_addr.afi == AF_INET && mapping_list->use_ipv4_address == TRUE) ||
                 (new_addr.afi == AF_INET6 && mapping_list->use_ipv6_address == TRUE))) {
            sort_locators_list_elt (mapping_list->mapping, iface_addr);
        }
        mapping_list = mapping_list->next;
    }

    /* Indicate change of address in the interface */

    switch (new_addr.afi) {
    case AF_INET:
        iface->ipv4_changed = TRUE;
        break;
    case AF_INET6:
        iface->ipv6_changed = TRUE;
        break;
    }


    /* If it is compiled in router mode, then recompile default routes changing the indicated src address*/

    if (router_mode == TRUE) {
        switch (new_addr.afi) {
        case AF_INET:
            if (iface == default_out_iface_v4) {
                set_tun_default_route_v4();
            }
            break;
        case AF_INET6:
            if (iface == default_out_iface_v6) {
                del_tun_default_route_v6();
                set_tun_default_route_v6();
            }
            break;
        }
    }

    /* Check if the new address is behind NAT */

    if(nat_aware==TRUE) {
        // TODO : To be modified when implementing NAT per multiple interfaces
        nat_status = UNKNOWN;
        clear_rtr_from_locators (iface);

        if (iface->status == UP) {
            initial_info_request_process();
        } else {
            nat_aware_iface_address_change = TRUE;
        }
    }

    /* Reprograming SMR timer*/
    if (smr_timer == NULL) {
        smr_timer = create_timer (SMR_TIMER);
    }

    start_timer(smr_timer, LISPD_SMR_TIMEOUT,(timer_callback)init_smr, NULL);
}