void event_loop(void) { int max_fd; fd_set readfds; time_t curr,prev; //Modified by acabello /* * calculate the max_fd for select. Is there a better way * to do this? */ max_fd = (v4_receive_fd > v6_receive_fd) ? v4_receive_fd : v6_receive_fd; max_fd = (max_fd > netlink_fd) ? max_fd : netlink_fd; max_fd = (max_fd > nlh.fd) ? max_fd : nlh.fd; max_fd = (max_fd > map_register_timer_fd)? max_fd : map_register_timer_fd; // Modified by acabello prev=time(NULL); for (EVER) { FD_ZERO(&readfds); FD_SET(v4_receive_fd,&readfds); FD_SET(v6_receive_fd,&readfds); FD_SET(netlink_fd,&readfds); FD_SET(nlh.fd, &readfds); FD_SET(map_register_timer_fd, &readfds); if (have_input(max_fd,&readfds) == -1) break; /* news is bad */ if (FD_ISSET(v4_receive_fd,&readfds)) process_lisp_msg(v4_receive_fd, AF_INET); if (FD_ISSET(v6_receive_fd,&readfds)) process_lisp_msg(v6_receive_fd, AF_INET6); if (FD_ISSET(netlink_fd,&readfds)) process_netlink_msg(); if (FD_ISSET(nlh.fd,&readfds)) process_netlink_iface(); if (FD_ISSET(map_register_timer_fd,&readfds)) periodic_map_register(); // Modified by acabello // Each second expire_datacache // This can be improved by using threading and timer_create() curr=time(NULL); if ((curr-prev)>LISPD_EXPIRE_TIMEOUT) { expire_datacache(); prev=time(NULL); } } }
void event_loop() { int max_fd; fd_set readfds; int retval; /* * 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); } } }
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"); }
void event_loop() { int max_fd; fd_set readfds; int retval; /* * calculate the max_fd for select. */ max_fd = ipv4_data_input_fd; max_fd = (max_fd > ipv6_data_input_fd) ? max_fd : ipv6_data_input_fd; max_fd = (max_fd > ipv4_control_input_fd) ? max_fd : ipv4_control_input_fd; max_fd = (max_fd > ipv6_control_input_fd) ? max_fd : ipv6_control_input_fd; max_fd = (max_fd > tun_receive_fd) ? max_fd : tun_receive_fd; max_fd = (max_fd > timers_fd) ? max_fd : timers_fd; max_fd = (max_fd > netlink_fd) ? max_fd : netlink_fd; for (;;) { FD_ZERO(&readfds); FD_SET(tun_receive_fd, &readfds); FD_SET(ipv4_data_input_fd, &readfds); FD_SET(ipv6_data_input_fd, &readfds); FD_SET(ipv4_control_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 (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, tun_receive_fd); } 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, tun_receive_fd); } 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_lisp_ctr_msg(ipv4_control_input_fd, AF_INET); } 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_lisp_ctr_msg(ipv6_control_input_fd, AF_INET6); } if (FD_ISSET(tun_receive_fd, &readfds)) { lispd_log_msg(LISP_LOG_DEBUG_3,"Received packet in the tun buffer"); process_output_packet(tun_receive_fd, tun_receive_buf, TUN_RECEIVE_SIZE); } 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); } } }