Beispiel #1
0
static bool
olsr_delete_hna_net_entry(struct hna_net *net_to_delete) {
#ifdef DEBUG
    struct ipaddr_str buf1, buf2;
#endif /* DEBUG */
    struct hna_entry *hna_gw;
    bool removed_entry = false;

#ifdef __linux__
    if (is_prefix_inetgw(&net_to_delete->hna_prefix)) {
        /* modify smart gateway entry if necessary */
        olsr_delete_gateway_entry(&net_to_delete->hna_gw->A_gateway_addr, net_to_delete->hna_prefix.prefix_len, false);
    }
#endif /* __linux__ */

    olsr_stop_timer(net_to_delete->hna_net_timer);
    net_to_delete->hna_net_timer = NULL;  /* be pedandic */
    hna_gw = net_to_delete->hna_gw;

#ifdef DEBUG
    OLSR_PRINTF(5, "HNA: timeout %s via hna-gw %s\n",
                olsr_ip_prefix_to_string(&net_to_delete->hna_prefix),
                olsr_ip_to_string(&buf2, &hna_gw->A_gateway_addr));
#endif /* DEBUG */

    /*
     * Delete the rt_path for the entry.
     */
    olsr_delete_routing_table(&net_to_delete->hna_prefix.prefix,
                              net_to_delete->hna_prefix.prefix_len, &hna_gw->A_gateway_addr);

    DEQUEUE_ELEM(net_to_delete);

    /* Delete hna_gw if empty */
    if (hna_gw->networks.next == &hna_gw->networks) {
        DEQUEUE_ELEM(hna_gw);
        olsr_cookie_free(hna_entry_mem_cookie, hna_gw);
        removed_entry = true;
    }

    olsr_cookie_free(hna_net_mem_cookie, net_to_delete);
    return removed_entry;
}
Beispiel #2
0
/**
 *IP version 4
 *
 *@param ifp the interface to send on
 *@return nada
 */
static bool
serialize_hna4(struct interface *ifp)
{
  uint16_t remainsize, curr_size, needsize;
  /* preserve existing data in output buffer */
  union olsr_message *m;
  struct hnapair *pair;
  struct ip_prefix_list *h;

  /* No hna nets */
  if (ifp == NULL) {
    return false;
  }
  if (olsr_cnf->ip_version != AF_INET) {
    return false;
  }
  h = olsr_cnf->hna_entries;
  if (h == NULL) {
    return false;
  }

  remainsize = net_outbuffer_bytes_left(ifp);

  curr_size = OLSR_HNA_IPV4_HDRSIZE;

  /* calculate size needed for HNA */
  needsize = curr_size;
  while (h) {
    needsize += olsr_cnf->ipsize*2;
    h = h->next;
  }

  h = olsr_cnf->hna_entries;

  /* Send pending packet if not room in buffer */
  if (needsize > remainsize) {
    net_output(ifp);
    remainsize = net_outbuffer_bytes_left(ifp);
  }
  check_buffspace(curr_size, remainsize, "HNA");

  m = (union olsr_message *)msg_buffer;

  /* Fill header */
  m->v4.originator = olsr_cnf->main_addr.v4.s_addr;
  m->v4.hopcnt = 0;
  m->v4.ttl = MAX_TTL;
  m->v4.olsr_msgtype = HNA_MESSAGE;
  m->v4.olsr_vtime = ifp->valtimes.hna;

  pair = m->v4.message.hna.hna_net;

  for (; h != NULL; h = h->next) {
    union olsr_ip_addr ip_addr;
    if ((curr_size + (2 * olsr_cnf->ipsize)) > remainsize) {
      /* Only add HNA message if it contains data */
      if (curr_size > OLSR_HNA_IPV4_HDRSIZE) {
#ifdef DEBUG
        OLSR_PRINTF(BMSG_DBGLVL, "Sending partial(size: %d, buff left:%d)\n", curr_size, remainsize);
#endif
        m->v4.seqno = htons(get_msg_seqno());
        m->v4.olsr_msgsize = htons(curr_size);
        net_outbuffer_push(ifp, msg_buffer, curr_size);
        curr_size = OLSR_HNA_IPV4_HDRSIZE;
        pair = m->v4.message.hna.hna_net;
      }
      net_output(ifp);
      remainsize = net_outbuffer_bytes_left(ifp);
      check_buffspace(curr_size + (2 * olsr_cnf->ipsize), remainsize, "HNA2");
    }
#ifdef DEBUG
    OLSR_PRINTF(BMSG_DBGLVL, "\tNet: %s\n", olsr_ip_prefix_to_string(&h->net));
#endif

    olsr_prefix_to_netmask(&ip_addr, h->net.prefix_len);
#ifdef linux
    if (olsr_cnf->smart_gw_active && is_prefix_inetgw(&h->net)) {
      /* this is the default route, overwrite it with the smart gateway */
      olsr_modifiy_inetgw_netmask(&ip_addr, h->net.prefix_len);
    }
#endif
    pair->addr = h->net.prefix.v4.s_addr;
    pair->netmask = ip_addr.v4.s_addr;
    pair++;
    curr_size += (2 * olsr_cnf->ipsize);
  }

  m->v4.seqno = htons(get_msg_seqno());
  m->v4.olsr_msgsize = htons(curr_size);

  net_outbuffer_push(ifp, msg_buffer, curr_size);

  //printf("Sending HNA (%d bytes)...\n", outputsize);
  return false;
}
Beispiel #3
0
  return true;
}

static void appendHNAEntry(struct interface_olsr *ifp, struct ip_prefix_list *h, uint16_t * remainsize, uint16_t * curr_size,
    union olsr_message *m, struct hnapair **pair, bool zero
#ifndef __linux__
__attribute__((unused))
#endif
  , bool * sgw_set
#ifndef __linux__
__attribute__((unused))
#endif
  ) {
  union olsr_ip_addr ip_addr;
#ifdef __linux__
  bool is_def_route = is_prefix_inetgw(&h->net);
#endif

#ifdef __linux__
  if (!zero && olsr_cnf->smart_gw_active && is_def_route && smartgw_is_zero_bandwidth(olsr_cnf)) {
    /* this is the default route, with zero bandwidth, do not append it */
    return;
  }
#endif /* __linux__ */

  if ((*curr_size + (2 * olsr_cnf->ipsize)) > *remainsize) {
    /* Only add HNA message if it contains data */
    if (*curr_size > OLSR_HNA_IPV4_HDRSIZE) {
#ifdef DEBUG
      OLSR_PRINTF(BMSG_DBGLVL, "Sending partial(size: %d, buff left:%d)\n", *curr_size, *remainsize);
#endif /* DEBUG */