Exemple #1
0
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);
    }
  }
}
Exemple #2
0
void
olsr_remove_interface(struct olsr_if * iface)
{
  struct interface *ifp, *tmp_ifp;
  ifp = iface->interf;

  OLSR_PRINTF(1, "Removing interface %s (%d)\n", iface->name, ifp->if_index);
  olsr_syslog(OLSR_LOG_INFO, "Removing interface %s\n", iface->name);

  olsr_delete_link_entry_by_ip(&ifp->ip_addr);

  /*
   *Call possible ifchange functions registered by plugins
   */
  olsr_trigger_ifchange(ifp->if_index, ifp, IFCHG_IF_REMOVE);

  /* cleanup routes over this interface */
  olsr_delete_interface_routes(ifp->if_index);

  /* Dequeue */
  if (ifp == ifnet) {
    ifnet = ifp->int_next;
  } else {
    tmp_ifp = ifnet;
    while (tmp_ifp->int_next != ifp) {
      tmp_ifp = tmp_ifp->int_next;
    }
    tmp_ifp->int_next = ifp->int_next;
  }

  /* Remove output buffer */
  net_remove_buffer(ifp);

  /* Check main addr */
  /* deactivated to prevent change of originator IP */
#if 0
  if (ipequal(&olsr_cnf->main_addr, &ifp->ip_addr)) {
    if (ifnet == NULL) {
      /* No more interfaces */
      memset(&olsr_cnf->main_addr, 0, olsr_cnf->ipsize);
      OLSR_PRINTF(1, "No more interfaces...\n");
    } else {
      struct ipaddr_str buf;
      olsr_cnf->main_addr = ifnet->ip_addr;
      OLSR_PRINTF(1, "New main address: %s\n", olsr_ip_to_string(&buf, &olsr_cnf->main_addr));
      olsr_syslog(OLSR_LOG_INFO, "New main address: %s\n", olsr_ip_to_string(&buf, &olsr_cnf->main_addr));
    }
  }
#endif /* 0 */
  /*
   * Deregister functions for periodic message generation
   */
  olsr_stop_timer(ifp->hello_gen_timer);
  olsr_stop_timer(ifp->tc_gen_timer);
  olsr_stop_timer(ifp->mid_gen_timer);
  olsr_stop_timer(ifp->hna_gen_timer);

  iface->configured = 0;
  iface->interf = NULL;

  /* Close olsr socket */
  remove_olsr_socket(ifp->olsr_socket, &olsr_input, NULL);
  close(ifp->olsr_socket);

  remove_olsr_socket(ifp->send_socket, &olsr_input, NULL);
  close(ifp->send_socket);

  /* Free memory */
  free(ifp->int_name);
  free(ifp);

  if ((ifnet == NULL) && (!olsr_cnf->allow_no_interfaces)) {
    olsr_syslog(OLSR_LOG_INFO, "No more active interfaces - exiting.\n");
    olsr_exit("No more active interfaces - exiting.\n", EXIT_FAILURE);
  }
}