static void netlink_process_link(struct nlmsghdr *h) { struct ifinfomsg *ifi = (struct ifinfomsg *) NLMSG_DATA(h); struct interface *iface; struct olsr_if *oif; char namebuffer[IF_NAMESIZE]; iface = if_ifwithindex(ifi->ifi_index); oif = NULL; if (iface == NULL && (ifi->ifi_flags & IFF_UP) == IFF_UP) { if (if_indextoname(ifi->ifi_index, namebuffer)) { if ((oif = olsrif_ifwithname(namebuffer)) != NULL) { /* try to take interface up, will trigger ifchange */ chk_if_up(oif, 3); } } } else if (iface != NULL && (ifi->ifi_flags & IFF_UP) == 0) { /* try to take interface down, will trigger ifchange */ olsr_remove_interface(iface->olsr_if); } if (iface == NULL && oif == NULL) { /* this is not an OLSR interface */ if ((ifi->ifi_flags & IFF_UP) != 0) { olsr_trigger_ifchange(ifi->ifi_index, NULL, IFCHG_IF_ADD); } else if ((ifi->ifi_flags & IFF_UP) == 0){ olsr_trigger_ifchange(ifi->ifi_index, NULL, IFCHG_IF_REMOVE); } } }
/** *Do initialization of various data needed for *network interface management. *This function also tries to set up the given interfaces. * *@return the number of interfaces configured */ int olsr_init_interfacedb(void) { struct olsr_if *tmp_if; /* Initial values */ ifnet = NULL; /* * Get some cookies for getting stats to ease troubleshooting. */ interface_poll_timer_cookie = olsr_alloc_cookie("Interface Polling", OLSR_COOKIE_TYPE_TIMER); hello_gen_timer_cookie = olsr_alloc_cookie("Hello Generation", OLSR_COOKIE_TYPE_TIMER); tc_gen_timer_cookie = olsr_alloc_cookie("TC Generation", OLSR_COOKIE_TYPE_TIMER); mid_gen_timer_cookie = olsr_alloc_cookie("MID Generation", OLSR_COOKIE_TYPE_TIMER); hna_gen_timer_cookie = olsr_alloc_cookie("HNA Generation", OLSR_COOKIE_TYPE_TIMER); OLSR_PRINTF(1, "\n ---- Interface configuration ---- \n\n"); /* Run trough all interfaces immedeatly */ for (tmp_if = olsr_cnf->interfaces; tmp_if != NULL; tmp_if = tmp_if->next) { if (!tmp_if->host_emul) { if (!olsr_cnf->host_emul) /* XXX: TEMPORARY! */ chk_if_up(tmp_if, 1); } else { add_hemu_if(tmp_if); } } /* Kick a periodic timer for the network interface update function */ olsr_start_timer((unsigned int)olsr_cnf->nic_chgs_pollrate * MSEC_PER_SEC, 5, OLSR_TIMER_PERIODIC, &check_interface_updates, NULL, interface_poll_timer_cookie); return (ifnet == NULL) ? 0 : 1; }