示例#1
0
static void
ipc_print_neigh_link(struct autobuf *abuf, const struct neighbor_entry *neighbor)
{
  static const char DASHED[] = "dashed";
  static const char SOLID[] = "solid";

  struct ipaddr_str mainaddrstrbuf, strbuf;
  olsr_linkcost etx = 0.0;
  const char *style;
  const char *adr = olsr_ip_to_string(&mainaddrstrbuf, &olsr_cnf->main_addr);
  struct link_entry *the_link;
  struct lqtextbuffer lqbuffer;

  if (neighbor->status == 0) {  /* non SYM */
    style = DASHED;
  } else {
    the_link = get_best_link_to_neighbor(&neighbor->neighbor_main_addr);
    if (the_link) {
      etx = the_link->linkcost;
    }
    style = SOLID;
  }

  abuf_appendf(abuf, "\"%s\" -> \"%s\"[label=\"%s\", style=%s];\n", adr, olsr_ip_to_string(&strbuf, &neighbor->neighbor_main_addr),
               get_linkcost_text(etx, false, &lqbuffer), style);

  if (neighbor->is_mpr) {
    abuf_appendf(abuf, "\"%s\"[shape=box];\n", adr);
  }
}
示例#2
0
olsr_u8_t
netmask_to_prefix(const olsr_u8_t *adr, int len)
{
  struct ipaddr_str buf;
  const olsr_u8_t * const a_end = adr+len;
  olsr_u16_t prefix = 0;
  const olsr_u8_t *a;
  for (a = adr; a < a_end && *a == 0xff; a++) {
    prefix += 8;
  }
  if (a < a_end) {
    /* handle the last byte */
    switch (*a) {
    case   0: prefix += 0; break;
    case 128: prefix += 1; break;
    case 192: prefix += 2; break;
    case 224: prefix += 3; break;
    case 240: prefix += 4; break;
    case 248: prefix += 5; break;
    case 252: prefix += 6; break;
    case 254: prefix += 7; break;
    case 255: prefix += 8; break; /* Shouldn't happen */
    default:
      OLSR_PRINTF(0, "%s: Got bogus netmask %s\n", __func__, olsr_ip_to_string(&buf, (const union olsr_ip_addr *)adr));
      prefix = UCHAR_MAX;
      *(int *)0 = 0;
      break;
    }
  }
#ifdef DEBUG
  OLSR_PRINTF(3, "Netmask: %s = Prefix %d\n", olsr_ip_to_string(&buf, (const union olsr_ip_addr *)adr), prefix);
#endif
  return prefix;
}
示例#3
0
/**
 * Print the routingtree to STDOUT
 *
 */
void
olsr_print_routing_table(struct avl_tree *tree)
{
#ifndef NODEBUG
  /* The whole function makes no sense without it. */
  struct avl_node *rt_tree_node;
  struct lqtextbuffer lqbuffer;

  OLSR_PRINTF(6, "ROUTING TABLE\n");

  for (rt_tree_node = avl_walk_first(tree); rt_tree_node != NULL; rt_tree_node = avl_walk_next(rt_tree_node)) {
    struct avl_node *rtp_tree_node;
    struct ipaddr_str prefixstr, origstr, gwstr;
    struct rt_entry *rt = rt_tree2rt(rt_tree_node);

    /* first the route entry */
    OLSR_PRINTF(6, "%s/%u, via %s, best-originator %s\n", olsr_ip_to_string(&prefixstr, &rt->rt_dst.prefix), rt->rt_dst.prefix_len,
                olsr_ip_to_string(&origstr, &rt->rt_nexthop.gateway), olsr_ip_to_string(&gwstr, &rt->rt_best->rtp_originator));

    /* walk the per-originator path tree of routes */
    for (rtp_tree_node = avl_walk_first(&rt->rt_path_tree); rtp_tree_node != NULL; rtp_tree_node = avl_walk_next(rtp_tree_node)) {
      struct rt_path *rtp = rtp_tree2rtp(rtp_tree_node);
      OLSR_PRINTF(6, "\tfrom %s, cost %s, metric %u, via %s, %s, v %u\n", olsr_ip_to_string(&origstr, &rtp->rtp_originator),
                  get_linkcost_text(rtp->rtp_metric.cost, true, &lqbuffer), rtp->rtp_metric.hops, olsr_ip_to_string(&gwstr,
                                                                                                                    &rtp->
                                                                                                                    rtp_nexthop.
                                                                                                                    gateway),
                  if_ifwithindex_name(rt->rt_nexthop.iif_index), rtp->rtp_version);
    }
  }
#endif /* NODEBUG */
  tree = NULL;                  /* squelch compiler warnings */
}
示例#4
0
/**
 * Insert a prefix into the prefix tree hanging off a lsdb (tc) entry.
 *
 * Check if the candidate route (we call this a rt_path) is known,
 * if not create it.
 * Upon post-SPF processing (if the node is reachable) the prefix
 * will be finally inserted into the global RIB.
 *
 *@param dst the destination
 *@param plen the prefix length
 *@param originator the originating router
 *
 *@return the new rt_path struct
 */
struct rt_path *
olsr_insert_routing_table(union olsr_ip_addr *dst, int plen,
                          union olsr_ip_addr *originator, int origin)
{
#ifdef DEBUG
  struct ipaddr_str dstbuf, origbuf;
#endif
  struct tc_entry *tc;
  struct rt_path *rtp;
  struct avl_node *node;
  struct olsr_ip_prefix prefix;

  /*
   * No bogus prefix lengths.
   */
  if (plen > olsr_cnf->maxplen) {
    return NULL;
  }

  /*
   * For all routes we use the tc_entry as an hookup point.
   * If the tc_entry is disconnected, i.e. has no edges it will not
   * be explored during SPF run.
   */
  tc = olsr_locate_tc_entry(originator);
  
  /*
   * first check if there is a rt_path for the prefix.
   */
  prefix.prefix = *dst;
  prefix.prefix_len = plen;

  node = avl_find(&tc->prefix_tree, &prefix);

  if (!node) {

    /* no rt_path for this prefix yet */
    rtp = olsr_alloc_rt_path(tc, &prefix, origin);

    if (!rtp) {
      return NULL;
    }

#ifdef DEBUG
    OLSR_PRINTF(1, "RIB: add prefix %s/%u from %s\n",
                olsr_ip_to_string(&dstbuf, dst), plen,
                olsr_ip_to_string(&origbuf, originator));
#endif

    /* overload the hna change bit for flagging a prefix change */
    changes_hna = OLSR_TRUE;

  } else {
    rtp = rtp_prefix_tree2rtp(node);
  }

  return rtp;
}
示例#5
0
int
olsr_process_hysteresis(struct link_entry *entry)
{
  //printf("PROCESSING QUALITY: %f\n", entry->L_link_quality);
  if (entry->L_link_quality > hhigh) {
    if (entry->L_link_pending == 1) {
      struct ipaddr_str buf;
      OLSR_PRINTF(1, "HYST[%s] link set to NOT pending!\n", olsr_ip_to_string(&buf, &entry->neighbor_iface_addr));
      changes_neighborhood = true;
    }

    /* Pending = false */
    entry->L_link_pending = 0;

    if (!TIMED_OUT(entry->L_LOST_LINK_time))
      changes_neighborhood = true;

    /* time = now -1 */
    entry->L_LOST_LINK_time = now_times - 1;

    return 1;
  }

  if (entry->L_link_quality < hlow) {
    if (entry->L_link_pending == 0) {
      struct ipaddr_str buf;
      OLSR_PRINTF(1, "HYST[%s] link set to pending!\n", olsr_ip_to_string(&buf, &entry->neighbor_iface_addr));
      changes_neighborhood = true;
    }

    /* Pending = true */
    entry->L_link_pending = 1;

    if (TIMED_OUT(entry->L_LOST_LINK_time))
      changes_neighborhood = true;

    /* Timer = min (L_time, current time + NEIGHB_HOLD_TIME) */
    entry->L_LOST_LINK_time = MIN(GET_TIMESTAMP(NEIGHB_HOLD_TIME * MSEC_PER_SEC), entry->link_timer->timer_clock);

    /* (the link is then considered as lost according to section
       8.5 and this may produce a neighbor loss).
       WTF?
     */
    return -1;
  }

  /*
   *If we get here then:
   *(HYST_THRESHOLD_LOW <= entry->L_link_quality <= HYST_THRESHOLD_HIGH)
   */

  /* L_link_pending and L_LOST_LINK_time remain unchanged. */
  return 0;

}
示例#6
0
/**
 * format a route entry into a buffer
 */
char *
olsr_rt_to_string(const struct rt_entry *rt)
{
  static char buff[128];
  struct ipaddr_str prefixstr, gwstr;

  snprintf(buff, sizeof(buff), "%s/%u via %s", olsr_ip_to_string(&prefixstr, &rt->rt_dst.prefix), rt->rt_dst.prefix_len,
           olsr_ip_to_string(&gwstr, &rt->rt_nexthop.gateway));

  return buff;
}
示例#7
0
int
check_gw(union olsr_ip_addr *net, union olsr_ip_addr *mask)
{
  char buff[1024], iface[17];
  uint32_t gate_addr, dest_addr, netmask;
  unsigned int iflags;
  int num, metric, refcnt, use;
  int retval = 0;

  FILE *fp = fopen(PROCENTRY_ROUTE, "r");

  if (!fp) {
    OLSR_WARN(LOG_PLUGINS, "Cannot read proc file %s: %s\n", PROCENTRY_ROUTE, strerror(errno));
    return -1;
  }

  rewind(fp);

  /*
     OLSR_PRINTF(DEBUGLEV, "Genmask         Destination     Gateway         "
     "Flags Metric Ref    Use Iface\n");
   */
  while (fgets(buff, 1023, fp)) {
#if !defined REMOVE_LOG_DEBUG
    struct ipaddr_str buf;
#endif
    num =
      sscanf(buff, "%16s %128X %128X %X %d %d %d %128X \n", iface, &dest_addr, &gate_addr, &iflags, &refcnt, &use, &metric,
             &netmask);

    if (num < 8) {
      continue;
    }
    OLSR_DEBUG(LOG_PLUGINS, "%-15s %-15s %-15s %-6d %-2d %7d %s\n",
               olsr_ip_to_string(&buf, (union olsr_ip_addr *)&netmask),
               olsr_ip_to_string(&buf, (union olsr_ip_addr *)&dest_addr),
               olsr_ip_to_string(&buf, (union olsr_ip_addr *)&gate_addr), metric, refcnt, use, iface);

    if (                        /* (iflags & RTF_GATEWAY) && */
         (iflags & RTF_UP) && (metric == 0) && (netmask == mask->v4.s_addr) && (dest_addr == net->v4.s_addr)) {
      OLSR_DEBUG(LOG_PLUGINS, "INTERNET GATEWAY VIA %s detected in routing table.\n", iface);
      retval = 1;
    }

  }

  fclose(fp);

  if (retval == 0) {
    OLSR_DEBUG(LOG_PLUGINS, "No Internet GWs detected...\n");
  }

  return retval;
}
示例#8
0
/**
 *Find the neighbor that covers the most 2 hop neighbors
 *with a given willingness
 *
 *@param willingness the willingness of the neighbor
 *
 *@return a pointer to the neighbor_entry struct
 */
static struct neighbor_entry *
olsr_find_maximum_covered(int willingness)
{
  uint16_t maximum;
  struct neighbor_entry *a_neighbor;
  struct neighbor_entry *mpr_candidate = NULL;

  maximum = 0;

  OLSR_FOR_ALL_NBR_ENTRIES(a_neighbor) {

#if 0
    printf("[%s] nocov: %d mpr: %d will: %d max: %d\n\n", olsr_ip_to_string(&buf, &a_neighbor->neighbor_main_addr),
           a_neighbor->neighbor_2_nocov, a_neighbor->is_mpr, a_neighbor->willingness, maximum);
#endif

    if ((!a_neighbor->is_mpr) && (a_neighbor->willingness == willingness) && (maximum < a_neighbor->neighbor_2_nocov)) {

      maximum = a_neighbor->neighbor_2_nocov;
      mpr_candidate = a_neighbor;
    }
  }
  OLSR_FOR_ALL_NBR_ENTRIES_END(a_neighbor);

  return mpr_candidate;
}
示例#9
0
/**
 * Adds all nodes with willingness set to WILL_ALWAYS
 */
static uint16_t
add_will_always_nodes(void)
{
  struct neighbor_entry *a_neighbor;
  uint16_t count = 0;

#if 0
  printf("\nAdding WILL ALWAYS nodes....\n");
#endif

  OLSR_FOR_ALL_NBR_ENTRIES(a_neighbor) {
    struct ipaddr_str buf;
    if ((a_neighbor->status == NOT_SYM) || (a_neighbor->willingness != WILL_ALWAYS)) {
      continue;
    }
    olsr_chosen_mpr(a_neighbor, &count);

    OLSR_PRINTF(3, "Adding WILL_ALWAYS: %s\n", olsr_ip_to_string(&buf, &a_neighbor->neighbor_main_addr));

  }
  OLSR_FOR_ALL_NBR_ENTRIES_END(a_neighbor);

#if 0
  OLSR_PRINTF(1, "Count: %d\n", count);
#endif
  return count;
}
示例#10
0
/**
 * format a route path into a buffer
 */
char *
olsr_rtp_to_string(const struct rt_path *rtp)
{
  static char buff[128];
  struct ipaddr_str prefixstr, origstr, gwstr;
  struct rt_entry *rt = rtp->rtp_rt;
  struct lqtextbuffer lqbuffer;

  snprintf(buff, sizeof(buff), "%s/%u from %s via %s, " "cost %s, metric %u, v %u",
           olsr_ip_to_string(&prefixstr, &rt->rt_dst.prefix), rt->rt_dst.prefix_len, olsr_ip_to_string(&origstr,
                                                                                                       &rtp->rtp_originator),
           olsr_ip_to_string(&gwstr, &rtp->rtp_nexthop.gateway), get_linkcost_text(rtp->rtp_metric.cost, true, &lqbuffer),
           rtp->rtp_metric.hops, rtp->rtp_version);

  return buff;
}
示例#11
0
/**
 *Prints the registered neighbors and two hop neighbors
 *to STDOUT.
 *
 *@return nada
 */
void
olsr_print_neighbor_table(void)
{
#ifdef NODEBUG
  /* The whole function doesn't do anything else. */
#ifndef NODEBUG
  const int iplen = olsr_cnf->ip_version == AF_INET ? 15 : 39;
#endif
  int idx;
  OLSR_PRINTF(1,
              "\n--- %02d:%02d:%02d.%02d ------------------------------------------------ NEIGHBORS\n\n"
              "%*s  LQ     NLQ    SYM   MPR   MPRS  will\n", nowtm->tm_hour, nowtm->tm_min, nowtm->tm_sec, (int)now.tv_usec / 10000,
              iplen, "IP address");

  for (idx = 0; idx < HASHSIZE; idx++) {
    struct neighbor_entry *neigh;
    for (neigh = neighbortable[idx].next; neigh != &neighbortable[idx]; neigh = neigh->next) {
      struct link_entry *lnk = get_best_link_to_neighbor(&neigh->neighbor_main_addr);
      if (lnk) {
        struct ipaddr_str buf;
        OLSR_PRINTF(1, "%-*s  %5.3f  %5.3f  %s  %s  %s  %d\n", iplen, olsr_ip_to_string(&buf, &neigh->neighbor_main_addr),
                    lnk->loss_link_quality, lnk->neigh_link_quality, neigh->status == SYM ? "YES " : "NO  ",
                    neigh->is_mpr ? "YES " : "NO  ", olsr_lookup_mprs_set(&neigh->neighbor_main_addr) == NULL ? "NO  " : "YES ",
                    neigh->willingness);
      }
    }
  }
#endif
}
示例#12
0
void
olsr_print_neighbor_table(void)
{
  /* The whole function doesn't do anything else. */
  const int iplen = olsr_cnf->ip_version == AF_INET ? (INET_ADDRSTRLEN - 1) : (INET6_ADDRSTRLEN - 1);
  int idx;

  OLSR_PRINTF(1,
              "\n--- %s ------------------------------------------------ NEIGHBORS\n\n"
              "%*s\tHyst\tLQ\tETX\tSYM   MPR   MPRS  will\n", olsr_wallclock_string(),
              iplen, "IP address");

  for (idx = 0; idx < HASHSIZE; idx++) {
    struct neighbor_entry *neigh;
    for (neigh = neighbortable[idx].next; neigh != &neighbortable[idx]; neigh = neigh->next) {
      struct link_entry *lnk = get_best_link_to_neighbor(&neigh->neighbor_main_addr);
      if (lnk) {
        struct ipaddr_str buf;
        struct lqtextbuffer lqbuffer1, lqbuffer2;

        OLSR_PRINTF(1, "%-*s\t%5.3f\t%s\t%s\t%s  %s  %s  %d\n", iplen, olsr_ip_to_string(&buf, &neigh->neighbor_main_addr),
                    (double)lnk->L_link_quality,
                    get_link_entry_text(lnk, '/', &lqbuffer1),
                    get_linkcost_text(lnk->linkcost,false, &lqbuffer2),
                    neigh->status == SYM ? "YES " : "NO  ",
                    neigh->is_mpr ? "YES " : "NO  ",
                    olsr_lookup_mprs_set(&neigh->neighbor_main_addr) == NULL ? "NO  " : "YES ",
                    neigh->willingness);
      }
    }
  }
}
示例#13
0
/**
 * Delete a prefix from the prefix tree hanging off a lsdb (tc) entry.
 */
void
olsr_delete_routing_table(union olsr_ip_addr *dst, int plen,
                          union olsr_ip_addr *originator)
{
#ifdef DEBUG
  struct ipaddr_str dstbuf, origbuf;
#endif

  struct tc_entry *tc;
  struct rt_path *rtp;
  struct avl_node *node;
  struct olsr_ip_prefix prefix;

  /*
   * No bogus prefix lengths.
   */
  if (plen > olsr_cnf->maxplen) {
    return;
  }

  tc = olsr_lookup_tc_entry(originator);
  if (!tc) {
    return;
  }

  /*
   * Grab the rt_path for the prefix.
   */
  prefix.prefix = *dst;
  prefix.prefix_len = plen;

  node = avl_find(&tc->prefix_tree, &prefix);

  if (node) {
    rtp = rtp_prefix_tree2rtp(node);
    olsr_delete_rt_path(rtp);

#ifdef DEBUG
    OLSR_PRINTF(1, "RIB: del prefix %s/%u from %s\n",
                olsr_ip_to_string(&dstbuf, dst), plen,
                olsr_ip_to_string(&origbuf, originator));
#endif

    /* overload the hna change bit for flagging a prefix change */
    changes_hna = OLSR_TRUE;
  }
}
示例#14
0
/*
 * olsr_spf_add_path_list
 *
 * Insert an SPF result at the end of the path list.
 */
static void
olsr_spf_add_path_list(struct list_node *head, int *path_count, struct tc_entry *tc)
{
#if !defined(NODEBUG) && defined(DEBUG)
  struct ipaddr_str pathbuf, nbuf;
  struct lqtextbuffer lqbuffer;
#endif /* !defined(NODEBUG) && defined(DEBUG) */

#ifdef DEBUG
  OLSR_PRINTF(2, "SPF: append path %s, cost %s, via %s\n", olsr_ip_to_string(&pathbuf, &tc->addr),
              get_linkcost_text(tc->path_cost, false, &lqbuffer), tc->next_hop ? olsr_ip_to_string(&nbuf,
                                                                                                   &tc->next_hop->
                                                                                                   neighbor_iface_addr) : "-");
#endif /* DEBUG */

  list_add_before(head, &tc->path_list_node);
  *path_count = *path_count + 1;
}
示例#15
0
/**
 *This function processes the chosen MPRs and updates the counters
 *used in calculations
 */
static int
olsr_chosen_mpr(struct neighbor_entry *one_hop_neighbor, uint16_t * two_hop_covered_count)
{
  struct neighbor_list_entry *the_one_hop_list;
  struct neighbor_2_list_entry *second_hop_entries;
  struct neighbor_entry *dup_neighbor;
  uint16_t count;
  struct ipaddr_str buf;
  count = *two_hop_covered_count;

  OLSR_PRINTF(1, "Setting %s as MPR\n", olsr_ip_to_string(&buf, &one_hop_neighbor->neighbor_main_addr));

  //printf("PRE COUNT: %d\n\n", count);

  one_hop_neighbor->is_mpr = true;      //NBS_MPR;

  for (second_hop_entries = one_hop_neighbor->neighbor_2_list.next; second_hop_entries != &one_hop_neighbor->neighbor_2_list;
       second_hop_entries = second_hop_entries->next) {
    dup_neighbor = olsr_lookup_neighbor_table(&second_hop_entries->neighbor_2->neighbor_2_addr);

    if ((dup_neighbor != NULL) && (dup_neighbor->status == SYM)) {
      //OLSR_PRINTF(7, "(2)Skipping 2h neighbor %s - already 1hop\n", olsr_ip_to_string(&buf, &second_hop_entries->neighbor_2->neighbor_2_addr));
      continue;
    }
    //      if(!second_hop_entries->neighbor_2->neighbor_2_state)
    //if(second_hop_entries->neighbor_2->mpr_covered_count < olsr_cnf->mpr_coverage)
    //{
    /*
       Now the neighbor is covered by this mpr
     */
    second_hop_entries->neighbor_2->mpr_covered_count++;
    the_one_hop_list = second_hop_entries->neighbor_2->neighbor_2_nblist.next;

    //OLSR_PRINTF(1, "[%s](%x) has coverage %d\n", olsr_ip_to_string(&buf, &second_hop_entries->neighbor_2->neighbor_2_addr), second_hop_entries->neighbor_2, second_hop_entries->neighbor_2->mpr_covered_count);

    if (second_hop_entries->neighbor_2->mpr_covered_count >= olsr_cnf->mpr_coverage)
      count++;

    while (the_one_hop_list != &second_hop_entries->neighbor_2->neighbor_2_nblist) {

      if ((the_one_hop_list->neighbor->status == SYM)) {
        if (second_hop_entries->neighbor_2->mpr_covered_count >= olsr_cnf->mpr_coverage) {
          the_one_hop_list->neighbor->neighbor_2_nocov--;
        }
      }
      the_one_hop_list = the_one_hop_list->next;
    }

    //}
  }

  //printf("POST COUNT %d\n\n", count);

  *two_hop_covered_count = count;
  return count;

}
示例#16
0
static
int olsrd_sanity_check_interface_cnf(struct if_config_options * io, struct olsrd_config * cnf, char* name) {
    struct olsr_lq_mult *mult;

    /* HELLO interval */

    if (io->hello_params.validity_time < 0.0) {
        if (cnf->lq_level == 0)
            io->hello_params.validity_time = NEIGHB_HOLD_TIME;

        else
            io->hello_params.validity_time = (int)(REFRESH_INTERVAL / cnf->lq_aging);
    }

    if (io->hello_params.emission_interval < cnf->pollrate || io->hello_params.emission_interval > io->hello_params.validity_time) {
        fprintf(stderr, "Bad HELLO parameters! (em: %0.2f, vt: %0.2f) for dev %s\n", io->hello_params.emission_interval,
                io->hello_params.validity_time, name);
        return -1;
    }

    /* TC interval */
    if (io->tc_params.emission_interval < cnf->pollrate || io->tc_params.emission_interval > io->tc_params.validity_time) {
        fprintf(stderr, "Bad TC parameters! (em: %0.2f, vt: %0.2f) for dev %s\n", io->tc_params.emission_interval,
                io->tc_params.validity_time, name);
        return -1;
    }

    if (cnf->min_tc_vtime > 0.0 && (io->tc_params.validity_time / io->tc_params.emission_interval) < 128) {
        fprintf(stderr, "Please use a tc vtime at least 128 times the emission interval while using the min_tc_vtime hack.\n");
        return -1;
    }
    /* MID interval */
    if (io->mid_params.emission_interval < cnf->pollrate || io->mid_params.emission_interval > io->mid_params.validity_time) {
        fprintf(stderr, "Bad MID parameters! (em: %0.2f, vt: %0.2f) for dev %s\n", io->mid_params.emission_interval,
                io->mid_params.validity_time, name);
        return -1;
    }

    /* HNA interval */
    if (io->hna_params.emission_interval < cnf->pollrate || io->hna_params.emission_interval > io->hna_params.validity_time) {
        fprintf(stderr, "Bad HNA parameters! (em: %0.2f, vt: %0.2f) for dev %s\n", io->hna_params.emission_interval,
                io->hna_params.validity_time, name);
        return -1;
    }

    for (mult = io->lq_mult; mult; mult=mult->next) {
        if (mult->value > LINK_LOSS_MULTIPLIER) {
            struct ipaddr_str buf;

            fprintf(stderr, "Bad Linkquality multiplier ('%s' on IP %s: %0.2f)\n",
                    name, olsr_ip_to_string(&buf, &mult->addr), (float)mult->value / (float)LINK_LOSS_MULTIPLIER);
            return -1;
        }
    }
    return 0;
}
示例#17
0
/**
 *Print the current MPR selector set to STDOUT
 */
void
olsr_print_mprs_set(void)
{
  struct mpr_selector *mprs;
  OLSR_PRINTF(1, "MPR SELECTORS: ");
  for (mprs = mprs_list.next; mprs != &mprs_list; mprs = mprs->next) {
    struct ipaddr_str buf;
    OLSR_PRINTF(1, "%s ", olsr_ip_to_string(&buf, &mprs->MS_main_addr));
  }
  OLSR_PRINTF(1, "\n");
}
示例#18
0
/**
 *Update the hello timeout of a hysteresis link
 *entry
 *
 *@param entry the link entry to update
 *@param htime the hello interval to use
 *
 *@return nada
 */
void
olsr_update_hysteresis_hello(struct link_entry *entry, olsr_reltime htime)
{
  struct ipaddr_str buf;
  OLSR_PRINTF(3, "HYST[%s]: HELLO update vtime %u ms\n", olsr_ip_to_string(&buf, &entry->neighbor_iface_addr), htime + htime / 2);

  olsr_set_timer(&entry->link_hello_timer, htime + htime / 2, OLSR_LINK_HELLO_JITTER, OLSR_TIMER_PERIODIC,
                 &olsr_expire_link_hello_timer, entry, 0);

  return;
}
示例#19
0
文件: net_olsr.c 项目: OLSR/olsrd
/*
 * Adds the given IP-address to the invalid list.
 */
void
olsr_add_invalid_address(const union olsr_ip_addr *adr)
{
  struct ipaddr_str buf;
  struct deny_address_entry *new_entry = olsr_malloc(sizeof(struct deny_address_entry), "Add deny address");

  new_entry->addr = *adr;
  new_entry->next = deny_entries;
  deny_entries = new_entry;
  OLSR_PRINTF(1, "Added %s to IP deny set\n", olsr_ip_to_string(&buf, &new_entry->addr));
}
示例#20
0
/**
 * Print all HNA entries.
 *
 *@return nada
 */
void
olsr_print_hna_set(void)
{
#ifdef NODEBUG
    /* The whole function doesn't do anything else. */
    int idx;

    OLSR_PRINTF(1, "\n--- %02d:%02d:%02d.%02d ------------------------------------------------- HNA SET\n\n", nowtm->tm_hour,
                nowtm->tm_min, nowtm->tm_sec, (int)now.tv_usec / 10000);

    if (olsr_cnf->ip_version == AF_INET)
        OLSR_PRINTF(1, "IP net          netmask         GW IP\n");
    else
        OLSR_PRINTF(1, "IP net/prefixlen               GW IP\n");

    for (idx = 0; idx < HASHSIZE; idx++) {
        struct hna_entry *tmp_hna = hna_set[idx].next;
        /* Check all entrys */
        while (tmp_hna != &hna_set[idx]) {
            /* Check all networks */
            struct hna_net *tmp_net = tmp_hna->networks.next;

            while (tmp_net != &tmp_hna->networks) {
                if (olsr_cnf->ip_version == AF_INET) {
                    struct ipaddr_str buf;
                    OLSR_PRINTF(1, "%-15s ", olsr_ip_to_string(&buf, &tmp_net->A_network_addr));
                    OLSR_PRINTF(1, "%-15d ", tmp_net->prefix_len);
                    OLSR_PRINTF(1, "%-15s\n", olsr_ip_to_string(&buf, &tmp_hna->A_gateway_addr));
                } else {
                    struct ipaddr_str buf;
                    OLSR_PRINTF(1, "%-27s/%d", olsr_ip_to_string(&buf, &tmp_net->A_network_addr), tmp_net->A_netmask.v6);
                    OLSR_PRINTF(1, "%s\n", olsr_ip_to_string(&buf, &tmp_hna->A_gateway_addr));
                }

                tmp_net = tmp_net->next;
            }
            tmp_hna = tmp_hna->next;
        }
    }
#endif /* NODEBUG */
}
示例#21
0
void
update_hysteresis_incoming(union olsr_ip_addr *remote, struct interface *local, uint16_t seqno)
{
  struct link_entry *lnk = lookup_link_entry(remote, NULL, local);

  /* Calculate new quality */
  if (lnk != NULL) {
#ifdef DEBUG
    struct ipaddr_str buf;
#endif
    lnk->L_link_quality = olsr_hyst_calc_stability(lnk->L_link_quality);
#ifdef DEBUG
    OLSR_PRINTF(3, "HYST[%s]: %f\n", olsr_ip_to_string(&buf, remote), lnk->L_link_quality);
#endif

    /*
     * see how many packets we have missed and update the link quality
     * for each missed packet; HELLOs have already been accounted for by
     * the timeout function and the number of missed HELLOs has already
     * been added to olsr_seqno there
     */

    if (lnk->olsr_seqno_valid && (unsigned short)(seqno - lnk->olsr_seqno) < 100)
      while (lnk->olsr_seqno != seqno) {
        lnk->L_link_quality = olsr_hyst_calc_instability(lnk->L_link_quality);
#ifdef DEBUG
        OLSR_PRINTF(5, "HYST[%s] PACKET LOSS! %f\n", olsr_ip_to_string(&buf, remote), lnk->L_link_quality);
#endif
        if (lnk->L_link_quality < olsr_cnf->hysteresis_param.thr_low)
          break;

        lnk->olsr_seqno++;
      }

    lnk->olsr_seqno = seqno + 1;
    lnk->olsr_seqno_valid = true;

    //printf("Updating seqno to: %d\n", lnk->olsr_seqno);
  }
  return;
}
示例#22
0
文件: Bmf.c 项目: Dany3R9/Proj
void
BMF_handle_encapsulatingFd(int skfd, void *data, unsigned int flags __attribute__ ((unused))) {
  unsigned char rxBuffer[BMF_BUFFER_SIZE];
  struct TBmfInterface* walker = data;
  struct sockaddr_in from;
  socklen_t fromLen = sizeof(from);
  int nBytes;
  int minimumLength;
  union olsr_ip_addr forwardedBy;

  /* An encapsulated packet was received */
  nBytes = recvfrom(
    skfd,
    rxBuffer,
    BMF_BUFFER_SIZE,
    0,
    (struct sockaddr*)&from,
    &fromLen);
  if (nBytes < 0)
  {
    BmfPError("recvfrom() error on \"%s\"", walker->ifName);

    return;
  } /* if (nBytes < 0) */

  forwardedBy.v4 = from.sin_addr;

  /* Check if the number of received bytes is large enough for a minimal BMF
   * encapsulation packet, at least:
   * - the encapsulation header
   * - a minimum IP header inside the encapsulated packet */
  minimumLength =
    ENCAP_HDR_LEN +
    sizeof(struct ip);
  if (nBytes < minimumLength)
  {
    struct ipaddr_str buf;
    olsr_printf(
      1,
      "%s: received a too short encapsulation packet (%d bytes) from %s on \"%s\"\n",
      PLUGIN_NAME,
      nBytes,
      olsr_ip_to_string(&buf, &forwardedBy),
      walker->ifName);
    return;
  }

  /* Unfortunately, the recvfrom call does not return the destination
   * of the encapsulation packet (the destination may be either the
   * my unicast or my local broadcast address). Therefore we fill in 'NULL'
   * for the 'forwardedTo' parameter. */
  BmfEncapsulationPacketReceived(walker, &forwardedBy, NULL, rxBuffer);
}
示例#23
0
文件: tc_set.c 项目: brabander/olsr
/**
 * Add a new tc_entry to the tc tree
 *
 * @param (last)adr address of the entry
 * @return a pointer to the created entry
 */
static struct tc_entry *
olsr_add_tc_entry(const union olsr_ip_addr *adr)
{
#if !defined REMOVE_LOG_DEBUG
  struct ipaddr_str buf;
#endif
  struct tc_entry *tc;

  /*
   * Safety net against loss of the last main IP address.
   */
  if (olsr_ipcmp(&olsr_cnf->router_id, &all_zero) == 0) {
    return NULL;
  }

  OLSR_DEBUG(LOG_TC, "TC: add entry %s\n", olsr_ip_to_string(&buf, adr));

  tc = olsr_memcookie_malloc(tc_mem_cookie);
  if (!tc) {
    return NULL;
  }

  /* Fill entry */
  tc->addr = *adr;
  tc->vertex_node.key = &tc->addr;

  tc->mid_seq = -1;
  tc->hna_seq = -1;
  tc->tc_seq = -1;
  /*
   * Insert into the global tc tree.
   */
  avl_insert(&tc_tree, &tc->vertex_node);

  /*
   * Initialize subtrees for edges, prefixes, HNAs and MIDs.
   */
  avl_init(&tc->edge_tree, avl_comp_default, true, NULL);
  avl_init(&tc->prefix_tree, avl_comp_prefix_origin_default, false, NULL);
  avl_init(&tc->mid_tree, avl_comp_default, false, NULL);
  avl_init(&tc->hna_tree, avl_comp_prefix_default, false, NULL);

  /*
   * Add a rt_path for ourselves.
   */
  olsr_insert_routing_table(adr, 8 * olsr_cnf->ipsize, adr, OLSR_RT_ORIGIN_TC);

  return tc;
}
示例#24
0
文件: tc_set.c 项目: brabander/olsr
/**
 * Attempts to delete a tc entry. This will work unless there are virtual edges left
 * that cannot be removed
 *
 * @param entry the TC entry to delete
 *
 */
void
olsr_delete_tc_entry(struct tc_entry *tc)
{
  struct tc_edge_entry *tc_edge, *edge_iterator;
  struct rt_path *rtp, *rtp_iterator;

#if !defined REMOVE_LOG_DEBUG
  struct ipaddr_str buf;
#endif
  OLSR_DEBUG(LOG_TC, "TC: del entry %s\n", olsr_ip_to_string(&buf, &tc->addr));

  /* The delete all non-virtual edges */
  OLSR_FOR_ALL_TC_EDGE_ENTRIES(tc, tc_edge, edge_iterator) {
    olsr_delete_tc_edge_entry(tc_edge);
  }
示例#25
0
/*
 * olsr_spf_del_cand_tree
 *
 * Unkey an existing vertex from a candidate tree.
 */
static void
olsr_spf_del_cand_tree(struct avl_tree *tree, struct tc_entry *tc)
{

#ifdef DEBUG
#ifndef NODEBUG
  struct ipaddr_str buf;
  struct lqtextbuffer lqbuffer;
#endif /* NODEBUG */
  OLSR_PRINTF(2, "SPF: delete candidate %s, cost %s\n", olsr_ip_to_string(&buf, &tc->addr),
              get_linkcost_text(tc->path_cost, false, &lqbuffer));
#endif /* DEBUG */

  avl_delete(tree, &tc->cand_tree_node);
}
示例#26
0
文件: net_olsr.c 项目: OLSR/olsrd
bool
olsr_validate_address(const union olsr_ip_addr *adr)
{
  const struct deny_address_entry *deny_entry;

  for (deny_entry = deny_entries; deny_entry != NULL; deny_entry = deny_entry->next) {
    if (ipequal(adr, &deny_entry->addr)) {
      struct ipaddr_str buf;
      OLSR_PRINTF(1, "Validation of address %s failed!\n", olsr_ip_to_string(&buf, adr));
      return false;
    }
    if (&deny_entry->addr == &olsr_cnf->main_addr)
      break;
  }
  return true;
}
示例#27
0
/**
 *Update a MPR selector entry or create an new
 *one if it does not exist
 *
 *@param addr the address of the MPR selector
 *@param vtime tha validity time of the entry
 *
 *@return 1 if a new entry was added 0 if not
 */
int
olsr_update_mprs_set(const union olsr_ip_addr *addr, olsr_reltime vtime)
{
  struct ipaddr_str buf;
  struct mpr_selector *mprs = olsr_lookup_mprs_set(addr);

  OLSR_PRINTF(5, "MPRS: Update %s\n", olsr_ip_to_string(&buf, addr));

  if (mprs == NULL) {
    olsr_add_mpr_selector(addr, vtime);
    signal_link_changes(true);
    return 1;
  }
  olsr_set_mpr_sel_timer(mprs, vtime);
  return 0;
}
示例#28
0
/*
 * olsr_spf_add_cand_tree
 *
 * Key an existing vertex to a candidate tree.
 */
static void
olsr_spf_add_cand_tree(struct avl_tree *tree, struct tc_entry *tc)
{
#if !defined(NODEBUG) && defined(DEBUG)
  struct ipaddr_str buf;
  struct lqtextbuffer lqbuffer;
#endif /* !defined(NODEBUG) && defined(DEBUG) */
  tc->cand_tree_node.key = &tc->path_cost;

#ifdef DEBUG
  OLSR_PRINTF(2, "SPF: insert candidate %s, cost %s\n", olsr_ip_to_string(&buf, &tc->addr),
              get_linkcost_text(tc->path_cost, false, &lqbuffer));
#endif /* DEBUG */

  avl_insert(tree, &tc->cand_tree_node, AVL_DUP);
}
示例#29
0
/**
 * Add a new tc_entry to the tc tree
 *
 * @param adr (last)adr address of the entry
 * @return a pointer to the created entry
 */
static struct tc_entry *
olsr_add_tc_entry(union olsr_ip_addr *adr)
{
#ifdef DEBUG
  struct ipaddr_str buf;
#endif /* DEBUG */
  struct tc_entry *tc;

  /*
   * Safety net against loss of the last main IP address.
   */
  if (ipequal(&olsr_cnf->main_addr, &all_zero)) {
    return NULL;
  }
#ifdef DEBUG
  OLSR_PRINTF(1, "TC: add entry %s\n", olsr_ip_to_string(&buf, adr));
#endif /* DEBUG */

  tc = olsr_cookie_malloc(tc_mem_cookie);
  if (!tc) {
    return NULL;
  }

  /* Fill entry */
  tc->addr = *adr;
  tc->vertex_node.key = &tc->addr;

  /*
   * Insert into the global tc tree.
   */
  avl_insert(&tc_tree, &tc->vertex_node, AVL_DUP_NO);
  olsr_lock_tc_entry(tc);

  /*
   * Initialize subtrees for edges and prefixes.
   */
  avl_init(&tc->edge_tree, avl_comp_default);
  avl_init(&tc->prefix_tree, avl_comp_prefix_default);

  /*
   * Add a rt_path for ourselves.
   */
  olsr_insert_routing_table(adr, olsr_cnf->maxplen, adr, OLSR_RT_ORIGIN_INT);

  return tc;
}
示例#30
0
/**
 *Optimize MPR set by removing all entries
 *where all 2 hop neighbors actually is
 *covered by enough MPRs already
 *Described in RFC3626 section 8.3.1
 *point 5
 *
 *@return nada
 */
static void
olsr_optimize_mpr_set(void)
{
  struct neighbor_entry *a_neighbor, *dup_neighbor;
  struct neighbor_2_list_entry *two_hop_list;
  int i, removeit;

#if 0
  printf("\n**MPR OPTIMIZING**\n\n");
#endif

  for (i = WILL_NEVER + 1; i < WILL_ALWAYS; i++) {

    OLSR_FOR_ALL_NBR_ENTRIES(a_neighbor) {

      if (a_neighbor->willingness != i) {
        continue;
      }

      if (a_neighbor->is_mpr) {
        removeit = 1;

        for (two_hop_list = a_neighbor->neighbor_2_list.next; two_hop_list != &a_neighbor->neighbor_2_list;
             two_hop_list = two_hop_list->next) {

          dup_neighbor = olsr_lookup_neighbor_table(&two_hop_list->neighbor_2->neighbor_2_addr);

          if ((dup_neighbor != NULL) && (dup_neighbor->status != NOT_SYM)) {
            continue;
          }
          //printf("\t[%s] coverage %d\n", olsr_ip_to_string(&buf, &two_hop_list->neighbor_2->neighbor_2_addr), two_hop_list->neighbor_2->mpr_covered_count);
          /* Do not remove if we find a entry which need this MPR */
          if (two_hop_list->neighbor_2->mpr_covered_count <= olsr_cnf->mpr_coverage) {
            removeit = 0;
          }
        }

        if (removeit) {
          struct ipaddr_str buf;
          OLSR_PRINTF(3, "MPR OPTIMIZE: removiong mpr %s\n\n", olsr_ip_to_string(&buf, &a_neighbor->neighbor_main_addr));
          a_neighbor->is_mpr = false;
        }
      }
    } OLSR_FOR_ALL_NBR_ENTRIES_END(a_neighbor);
  }
}