Commit f8fefde3 authored by Ondrej Zajicek's avatar Ondrej Zajicek
Browse files

Refactoring of OSPF messages.

parent 78342404
Loading
Loading
Loading
Loading
+12 −3
Original line number Diff line number Diff line
@@ -36,9 +36,18 @@ password_find(list *l, int first_fit)
  return pf;
}

void password_cpy(char *dst, char *src, int size)
struct password_item *
password_find_by_id(list *l, int id)
{
  bzero(dst, size);
  memcpy(dst, src, (strlen(src) < (unsigned) size ? strlen(src) : (unsigned) size));
  struct password_item *pi;

  if (!l)
    return NULL;

  WALK_LIST(pi, *l)
    if ((pi->id == id) && (pi->accfrom <= now_real) && (now_real < pi->accto))
      return pi;

  return NULL;
}
+8 −1
Original line number Diff line number Diff line
@@ -23,6 +23,13 @@ struct password_item {
extern struct password_item *last_password_item;

struct password_item *password_find(list *l, int first_fit);
void password_cpy(char *dst, char *src, int size);
struct password_item *password_find_by_id(list *l, int id);

static inline int password_verify(struct password_item *p1, char *p2, uint size)
{
  char buf[size];
  strncpy(buf, p1->password, size);
  return !memcmp(buf, p2, size);
}

#endif
+94 −136
Original line number Diff line number Diff line
@@ -98,7 +98,7 @@ ospf_dump_dbdes(struct ospf_proto *p, struct ospf_packet *pkt)


static void
ospf_prepare_dbdes(struct ospf_proto *p, struct ospf_neighbor *n, int body)
ospf_prepare_dbdes(struct ospf_proto *p, struct ospf_neighbor *n)
{
  struct ospf_iface *ifa = n->ifa;
  struct ospf_packet *pkt;
@@ -106,6 +106,7 @@ ospf_prepare_dbdes(struct ospf_proto *p, struct ospf_neighbor *n, int body)

  u16 iface_mtu = (ifa->type == OSPF_IT_VLINK) ? 0 : ifa->iface->mtu;

  /* Update DBDES buffer */
  if (n->ldd_bsize != ifa->tx_length)
  {
    mb_free(n->ldd_buffer);
@@ -136,7 +137,8 @@ ospf_prepare_dbdes(struct ospf_proto *p, struct ospf_neighbor *n, int body)
    length = sizeof(struct ospf_dbdes3_packet);
  }

  if (body && (n->myimms & DBDES_M))
  /* Prepare DBDES body */
  if (!(n->myimms & DBDES_I) && (n->myimms & DBDES_M))
  {
    struct ospf_lsa_header *lsas;
    struct top_hash_entry *en;
@@ -182,7 +184,7 @@ ospf_do_send_dbdes(struct ospf_proto *p, struct ospf_neighbor *n)
  struct ospf_iface *ifa = n->ifa;

  OSPF_PACKET(ospf_dump_dbdes, n->ldd_buffer,
	      "DBDES packet sent to %I via %s", n->ip, ifa->ifname);
	      "DBDES packet sent to nbr %R on %s", n->rid, ifa->ifname);
  sk_set_tbuf(ifa->sk, n->ldd_buffer);
  ospf_send_to(ifa, n->ip);
  sk_set_tbuf(ifa->sk, NULL);
@@ -191,7 +193,6 @@ ospf_do_send_dbdes(struct ospf_proto *p, struct ospf_neighbor *n)
/**
 * ospf_send_dbdes - transmit database description packet
 * @n: neighbor
 * @next: whether to send a next packet in a sequence (1) or to retransmit the old one (0)
 *
 * Sending of a database description packet is described in 10.8 of RFC 2328.
 * Reception of each packet is acknowledged in the sequence number of another.
@@ -200,104 +201,78 @@ ospf_do_send_dbdes(struct ospf_proto *p, struct ospf_neighbor *n)
 * of the buffer.
 */
void
ospf_send_dbdes(struct ospf_proto *p, struct ospf_neighbor *n, int next)
ospf_send_dbdes(struct ospf_proto *p, struct ospf_neighbor *n)
{
  /* RFC 2328 10.8 */

  ASSERT((n->state == NEIGHBOR_EXSTART) || (n->state == NEIGHBOR_EXCHANGE));

  if (n->ifa->oa->rt == NULL)
    return;

  switch (n->state)
  {
  case NEIGHBOR_EXSTART:
    n->myimms |= DBDES_I;

    /* Send empty packets */
    ospf_prepare_dbdes(p, n, 0);
  ospf_prepare_dbdes(p, n);
  ospf_do_send_dbdes(p, n);
    break;

  case NEIGHBOR_EXCHANGE:
    n->myimms &= ~DBDES_I;

    if (next)
      ospf_prepare_dbdes(p, n, 1);

    /* Send prepared packet */
    ospf_do_send_dbdes(p, n);
  if (n->state == NEIGHBOR_EXSTART)
    return;

  /* Master should restart RXMT timer for each DBDES exchange */
  if (n->myimms & DBDES_MS)
    tm_start(n->rxmt_timer, n->ifa->rxmtint);

  if (!(n->myimms & DBDES_MS))
      if (!(n->myimms & DBDES_M) &&
	  !(n->imms & DBDES_M))
    if (!(n->myimms & DBDES_M) && !(n->imms & DBDES_M))
      ospf_neigh_sm(n, INM_EXDONE);
    break;
}

  case NEIGHBOR_LOADING:
  case NEIGHBOR_FULL:
void
ospf_rxmt_dbdes(struct ospf_proto *p, struct ospf_neighbor *n)
{
  ASSERT(n->state > NEIGHBOR_EXSTART);

  if (!n->ldd_buffer)
  {
      OSPF_TRACE(D_PACKETS, "No DBDES packet for repeating");
      ospf_neigh_sm(n, INM_KILLNBR);
    log(L_WARN "%s: No DBDES packet for retransmit", p->p.name);
    ospf_neigh_sm(n, INM_SEQMIS);
    return;
  }

  /* Send last packet */
  ospf_do_send_dbdes(p, n);
    break;
  }
}


static int
ospf_process_dbdes(struct ospf_proto *p, struct ospf_packet *pkt, struct ospf_neighbor *n)
{
  struct ospf_iface *ifa = n->ifa;
  struct ospf_lsa_header *lsas;
  struct ospf_lsa_header *lsas, lsa;
  struct top_hash_entry *en, *req;
  const char *err_dsc = NULL;
  u32 lsa_type, lsa_domain;
  uint i, lsa_count;

  ospf_dbdes_body(p, pkt, &lsas, &lsa_count);

  for (i = 0; i < lsa_count; i++)
  {
    struct top_hash_entry *en, *req;
    struct ospf_lsa_header lsa;
    u32 lsa_type, lsa_domain;

    lsa_ntoh_hdr(lsas + i, &lsa);
    lsa_get_type_domain(&lsa, ifa, &lsa_type, &lsa_domain);

    /* RFC 2328 10.6 and RFC 5340 4.2.2 */

    if (!lsa_type)
    {
      log(L_WARN "%s: Bad DBDES from %I - LSA of unknown type", p->p.name, n->ip);
      goto err;
    }
      DROP1("LSA of unknown type");

    if (!oa_is_ext(ifa->oa) && (LSA_SCOPE(lsa_type) == LSA_SCOPE_AS))
    {
      log(L_WARN "%s: Bad DBDES from %I - LSA with AS scope in stub area", p->p.name, n->ip);
      goto err;
    }
      DROP1("LSA with AS scope in stub area");

    /* Errata 3746 to RFC 2328 - rt-summary-LSAs forbidden in stub areas */
    if (!oa_is_ext(ifa->oa) && (lsa_type == LSA_T_SUM_RT))
    {
      log(L_WARN "%s: Bad DBDES from %I - rt-summary-LSA in stub area", p->p.name, n->ip);
      goto err;
    }
      DROP1("rt-summary-LSA in stub area");

    /* Not explicitly mentioned in RFC 5340 4.2.2 but makes sense */
    if (LSA_SCOPE(lsa_type) == LSA_SCOPE_RES)
    {
      log(L_WARN "%s: Bad DBDES from %I - LSA with invalid scope", p->p.name, n->ip);
      goto err;
    }
      DROP1("LSA with invalid scope");

    en = ospf_hash_find(p->gr, lsa_domain, lsa.id, lsa.rt, lsa_type);
    if (!en || (lsa_comp(&lsa, &(en->lsa)) == CMP_NEWER))
@@ -314,7 +289,10 @@ ospf_process_dbdes(struct ospf_proto *p, struct ospf_packet *pkt, struct ospf_ne

  return 0;

 err:
drop:
  LOG_LSA1("Bad LSA (Type: %04x, Id: %R, Rt: %R) in DBDES", lsa_type, lsa.id, lsa.rt);
  LOG_LSA2("  received from nbr %R on %s - %s", n->rid, ifa->ifname, err_dsc);

  ospf_neigh_sm(n, INM_SEQMIS);
  return -1;
}
@@ -324,21 +302,19 @@ ospf_receive_dbdes(struct ospf_packet *pkt, struct ospf_iface *ifa,
		   struct ospf_neighbor *n)
{
  struct ospf_proto *p = ifa->oa->po;
  const char *err_dsc = NULL;
  u32 rcv_ddseq, rcv_options;
  u16 rcv_iface_mtu;
  u8 rcv_imms;
  uint plen;
  uint plen, err_val = 0, err_seqmis = 0;

  /* RFC 2328 10.6 */

  plen = ntohs(pkt->length);
  if (plen < ospf_dbdes_hdrlen(p))
  {
    log(L_ERR "OSPF: Bad DBDES packet from %I - too short (%u B)", n->ip, plen);
    return;
  }
    DROP("too short", plen);

  OSPF_PACKET(ospf_dump_dbdes, pkt, "DBDES packet received from %I via %s", n->ip, ifa->ifname);
  OSPF_PACKET(ospf_dump_dbdes, pkt, "DBDES packet received from nbr %R on %s", n->rid, ifa->ifname);

  ospf_neigh_sm(n, INM_HELLOREC);

@@ -364,6 +340,7 @@ ospf_receive_dbdes(struct ospf_packet *pkt, struct ospf_iface *ifa,
  case NEIGHBOR_DOWN:
  case NEIGHBOR_ATTEMPT:
  case NEIGHBOR_2WAY:
    OSPF_TRACE(D_PACKETS, "DBDES packet ignored - lesser state than ExStart");
    return;

  case NEIGHBOR_INIT:
@@ -376,8 +353,8 @@ ospf_receive_dbdes(struct ospf_packet *pkt, struct ospf_iface *ifa,
	(rcv_iface_mtu != ifa->iface->mtu) &&
	(rcv_iface_mtu != 0) &&
	(ifa->iface->mtu != 0))
      log(L_WARN "OSPF: MTU mismatch with neighbor %I on interface %s (remote %d, local %d)",
	  n->ip, ifa->ifname, rcv_iface_mtu, ifa->iface->mtu);
      LOG_PKT_WARN("MTU mismatch with nbr %R on %s (remote %d, local %d)",
		   n->rid, ifa->ifname, rcv_iface_mtu, ifa->iface->mtu);

    if ((rcv_imms == DBDES_IMMS) &&
	(n->rid > p->router_id) &&
@@ -389,9 +366,8 @@ ospf_receive_dbdes(struct ospf_packet *pkt, struct ospf_iface *ifa,
      n->options = rcv_options;
      n->myimms &= ~DBDES_MS;
      n->imms = rcv_imms;
      OSPF_TRACE(D_PACKETS, "I'm slave to %I", n->ip);
      ospf_neigh_sm(n, INM_NEGDONE);
      ospf_send_dbdes(p, n, 1);
      ospf_send_dbdes(p, n);
      break;
    }

@@ -404,7 +380,6 @@ ospf_receive_dbdes(struct ospf_packet *pkt, struct ospf_iface *ifa,
      n->options = rcv_options;
      n->ddr = rcv_ddseq - 1;	/* It will be set corectly a few lines down */
      n->imms = rcv_imms;
      OSPF_TRACE(D_PACKETS, "I'm master to %I", n->ip);
      ospf_neigh_sm(n, INM_NEGDONE);
    }
    else
@@ -417,49 +392,29 @@ ospf_receive_dbdes(struct ospf_packet *pkt, struct ospf_iface *ifa,
    if ((rcv_imms == n->imms) &&
	(rcv_options == n->options) &&
	(rcv_ddseq == n->ddr))
    {
      /* Duplicate packet */
      OSPF_TRACE(D_PACKETS, "Received duplicate dbdes from %I", n->ip);
      if (!(n->myimms & DBDES_MS))
      {
	/* Slave should retransmit dbdes packet */
	ospf_send_dbdes(p, n, 0);
      }
      return;
    }
      goto duplicate;

    if ((rcv_imms & DBDES_MS) != (n->imms & DBDES_MS))	/* M/S bit differs */
    {
      OSPF_TRACE(D_PACKETS, "dbdes - sequence mismatch neighbor %I (bit MS)", n->ip);
      ospf_neigh_sm(n, INM_SEQMIS);
      break;
    }
    /* Do INM_SEQMIS during packet error */
    err_seqmis = 1;

    if (rcv_imms & DBDES_I)		/* I bit is set */
    {
      OSPF_TRACE(D_PACKETS, "dbdes - sequence mismatch neighbor %I (bit I)", n->ip);
      ospf_neigh_sm(n, INM_SEQMIS);
      break;
    }
    if ((rcv_imms & DBDES_MS) != (n->imms & DBDES_MS))
      DROP("MS-bit mismatch", rcv_imms);

    if (rcv_options != n->options)	/* Options differs */
    {
      OSPF_TRACE(D_PACKETS, "dbdes - sequence mismatch neighbor %I (options)", n->ip);
      ospf_neigh_sm(n, INM_SEQMIS);
      break;
    }
    if (rcv_imms & DBDES_I)
      DROP("I-bit mismatch", rcv_imms);

    if (rcv_options != n->options)
      DROP("options mismatch", rcv_options);

    n->ddr = rcv_ddseq;
    n->imms = rcv_imms;

    if (n->myimms & DBDES_MS)
    {
      if (rcv_ddseq != n->dds)	/* MASTER */
      {
	OSPF_TRACE(D_PACKETS, "dbdes - sequence mismatch neighbor %I (master)", n->ip);
	ospf_neigh_sm(n, INM_SEQMIS);
	break;
      }
      /* MASTER */

      if (rcv_ddseq != n->dds)
	DROP("DD sequence number mismatch", rcv_ddseq);

      n->dds++;

@@ -469,16 +424,14 @@ ospf_receive_dbdes(struct ospf_packet *pkt, struct ospf_iface *ifa,
      if (!(n->myimms & DBDES_M) && !(n->imms & DBDES_M))
	ospf_neigh_sm(n, INM_EXDONE);
      else
	ospf_send_dbdes(p, n, 1);
	ospf_send_dbdes(p, n);
    }
    else
    {
      if (rcv_ddseq != (n->dds + 1))	/* SLAVE */
      {
	OSPF_TRACE(D_PACKETS, "dbdes - sequence mismatch neighbor %I (slave)", n->ip);
	ospf_neigh_sm(n, INM_SEQMIS);
	break;
      }
      /* SLAVE */

      if (rcv_ddseq != (n->dds + 1))
	DROP("DD sequence number mismatch", rcv_ddseq);

      n->ddr = rcv_ddseq;
      n->dds = rcv_ddseq;
@@ -486,7 +439,7 @@ ospf_receive_dbdes(struct ospf_packet *pkt, struct ospf_iface *ifa,
      if (ospf_process_dbdes(p, pkt, n) < 0)
	return;

      ospf_send_dbdes(p, n, 1);
      ospf_send_dbdes(p, n);
    }
    break;

@@ -495,25 +448,30 @@ ospf_receive_dbdes(struct ospf_packet *pkt, struct ospf_iface *ifa,
    if ((rcv_imms == n->imms) &&
	(rcv_options == n->options) &&
	(rcv_ddseq == n->ddr))
    {
      /* Duplicate packet */
      OSPF_TRACE(D_PACKETS, "Received duplicate dbdes from %I", n->ip);
      if (!(n->myimms & DBDES_MS))
      {
	/* Slave should retransmit dbdes packet */
	ospf_send_dbdes(p, n, 0);
      }
      return;
    }
    else
    {
      OSPF_TRACE(D_PACKETS, "dbdes - sequence mismatch neighbor %I (full)", n->ip);
      DBG("PS=%u, DDR=%u, DDS=%u\n", rcv_ddseq, n->ddr, n->dds);
      ospf_neigh_sm(n, INM_SEQMIS);
    }
    break;
      goto duplicate;

    err_seqmis = 1;

    DROP("too late for DD exchange", n->state);

  default:
    bug("Received dbdes from %I in undefined state.", n->ip);
    bug("Undefined interface state");
  }
  return;

duplicate:
  OSPF_TRACE(D_PACKETS, "DBDES packet is duplicate");

  /* Slave should retransmit DBDES packet */
  if (!(n->myimms & DBDES_MS))
    ospf_rxmt_dbdes(p, n);
  return;

drop:
  LOG_PKT("Bad DBDES packet from nbr %R on %s - %s (%u)",
	  n->rid, ifa->ifname, err_dsc, err_val);

  if (err_seqmis)
    ospf_neigh_sm(n, INM_SEQMIS);
  return;
}
+35 −43
Original line number Diff line number Diff line
@@ -114,7 +114,7 @@ ospf_send_hello(struct ospf_iface *ifa, int kind, struct ospf_neighbor *dirn)
    {
      if (i == max)
      {
	log(L_WARN "%s: Too many neighbors on interface %s", p->p.name, ifa->ifname);
	log(L_WARN "%s: Too many neighbors on %s", p->p.name, ifa->ifname);
	break;
      }
      neighbors[i] = htonl(neigh->rid);
@@ -188,16 +188,21 @@ ospf_receive_hello(struct ospf_packet *pkt, struct ospf_iface *ifa,
		   struct ospf_neighbor *n, ip_addr faddr)
{
  struct ospf_proto *p = ifa->oa->po;
  char *beg = "OSPF: Bad HELLO packet from ";
  const char *err_dsc = NULL;
  u32 rcv_iface_id, rcv_helloint, rcv_deadint, rcv_dr, rcv_bdr;
  u8 rcv_options, rcv_priority;
  u32 *neighbors;
  u32 neigh_count;
  uint plen, i;
  uint plen, i, err_val = 0;

  /* RFC 2328 10.5 */

  OSPF_TRACE(D_PACKETS, "HELLO packet received from %I via %s", faddr, ifa->ifname);
  /*
   * We may not yet havethe associate neighbor, so we use Router ID from the
   * packet instead of one from the neighbor structure for log messages.
   */
  u32 rcv_rid = ntohl(pkt->routerid);
  OSPF_TRACE(D_PACKETS, "HELLO packet received from nbr %R on %s", rcv_rid, ifa->ifname);

  plen = ntohs(pkt->length);

@@ -206,10 +211,7 @@ ospf_receive_hello(struct ospf_packet *pkt, struct ospf_iface *ifa,
    struct ospf_hello2_packet *ps = (void *) pkt;

    if (plen < sizeof(struct ospf_hello2_packet))
    {
      log(L_ERR "%s%I - too short (%u B)", beg, faddr, plen);
      return;
    }
      DROP("too short", plen);

    rcv_iface_id = 0;
    rcv_helloint = ntohs(ps->helloint);
@@ -223,10 +225,7 @@ ospf_receive_hello(struct ospf_packet *pkt, struct ospf_iface *ifa,
    if ((ifa->type != OSPF_IT_VLINK) &&
	(ifa->type != OSPF_IT_PTP) &&
	(pxlen != ifa->addr->pxlen))
    {
      log(L_ERR "%s%I - prefix length mismatch (%d)", beg, faddr, pxlen);
      return;
    }
      DROP("prefix length mismatch", pxlen);

    neighbors = ps->neighbors;
    neigh_count = (plen - sizeof(struct ospf_hello2_packet)) / sizeof(u32);
@@ -236,10 +235,7 @@ ospf_receive_hello(struct ospf_packet *pkt, struct ospf_iface *ifa,
    struct ospf_hello3_packet *ps = (void *) pkt;

    if (plen < sizeof(struct ospf_hello3_packet))
    {
      log(L_ERR "%s%I - too short (%u B)", beg, faddr, plen);
      return;
    }
      DROP("too short", plen);

    rcv_iface_id = ntohl(ps->iface_id);
    rcv_helloint = ntohs(ps->helloint);
@@ -254,23 +250,14 @@ ospf_receive_hello(struct ospf_packet *pkt, struct ospf_iface *ifa,
  }

  if (rcv_helloint != ifa->helloint)
  {
    log(L_ERR "%s%I - hello interval mismatch (%d)", beg, faddr, rcv_helloint);
    return;
  }
    DROP("hello interval mismatch", rcv_helloint);

  if (rcv_deadint != ifa->deadint)
  {
    log(L_ERR "%s%I - dead interval mismatch (%d)", beg, faddr, rcv_deadint);
    return;
  }
    DROP("dead interval mismatch", rcv_deadint);

  /* Check whether bits E, N match */
  if ((rcv_options ^ ifa->oa->options) & (OPT_E | OPT_N))
  {
    log(L_ERR "%s%I - area type mismatch (%x)", beg, faddr, rcv_options);
    return;
  }
    DROP("area type mismatch", rcv_options);

  /* Check consistency of existing neighbor entry */
  if (n)
@@ -279,11 +266,11 @@ ospf_receive_hello(struct ospf_packet *pkt, struct ospf_iface *ifa,
    if (ospf_is_v2(p) && ((t == OSPF_IT_BCAST) || (t == OSPF_IT_NBMA) || (t == OSPF_IT_PTMP)))
    {
      /* Neighbor identified by IP address; Router ID may change */
      if (n->rid != ntohl(pkt->routerid))
      if (n->rid != rcv_rid)
      {
	OSPF_TRACE(D_EVENTS, "Neighbor %I has changed Router ID from %R to %R",
		   n->ip, n->rid, ntohl(pkt->routerid));
	ospf_neigh_remove(n);
	OSPF_TRACE(D_EVENTS, "Neighbor %R on %s changed Router ID to %R",
		   n->rid, ifa->ifname, rcv_rid);
	ospf_neigh_sm(n, INM_KILLNBR);
	n = NULL;
      }
    }
@@ -292,7 +279,8 @@ ospf_receive_hello(struct ospf_packet *pkt, struct ospf_iface *ifa,
      /* Neighbor identified by Router ID; IP address may change */
      if (!ipa_equal(faddr, n->ip))
      {
	OSPF_TRACE(D_EVENTS, "Neighbor address changed from %I to %I", n->ip, faddr);
	OSPF_TRACE(D_EVENTS, "Neighbor %R on %s changed IP address to %I",
		   n->rid, ifa->ifname, n->ip, faddr);
	n->ip = faddr;
      }
    }
@@ -305,28 +293,26 @@ ospf_receive_hello(struct ospf_packet *pkt, struct ospf_iface *ifa,
      struct nbma_node *nn = find_nbma_node(ifa, faddr);

      if (!nn && ifa->strictnbma)
      {
	log(L_WARN "Ignoring new neighbor: %I on %s", faddr, ifa->ifname);
	return;
      }
	DROP1("new neighbor denied");

      if (nn && (ifa->type == OSPF_IT_NBMA) &&
	  (((rcv_priority == 0) && nn->eligible) ||
	   ((rcv_priority > 0) && !nn->eligible)))
      {
	log(L_ERR "Eligibility mismatch for neighbor: %I on %s", faddr, ifa->ifname);
	return;
      }
	DROP("eligibility mismatch", rcv_priority);

      if (nn)
	nn->found = 1;
    }

    // XXXX format
    // "ospf1: New neighbor found: 192.168.1.1/fe80:1234:1234:1234:1234 on eth0";
    // "ospf1: New neighbor found: 192.168.1.1 on eth0 at fe80:1234:1234:1234:1234";
    // "ospf1: Neighbor 192.168.1.1 on eth0 found, IP adress fe80:1234:1234:1234:1234";
    OSPF_TRACE(D_EVENTS, "New neighbor found: %I on %s", faddr, ifa->ifname);

    n = ospf_neighbor_new(ifa);

    n->rid = ntohl(pkt->routerid);
    n->rid = rcv_rid;
    n->ip = faddr;
    n->dr = rcv_dr;
    n->bdr = rcv_bdr;
@@ -400,4 +386,10 @@ ospf_receive_hello(struct ospf_packet *pkt, struct ospf_iface *ifa,
	((n->bdr != n_id) && (old_bdr == n_id)))
      ospf_iface_sm(ifa, ISM_NEICH);
  }

  return;

drop:
  LOG_PKT("Bad HELLO packet from nbr %R on %s - %s (%u)",
	  rcv_rid, ifa->ifname, err_dsc, err_val);
}
+36 −35
Original line number Diff line number Diff line
@@ -11,15 +11,16 @@
#include "ospf.h"


char *ospf_is[] = { "down", "loop", "waiting", "ptp", "drother",
  "backup", "dr"
const char *ospf_is_names[] = {
  "Down", "Loopback", "Waiting", "PtP", "DROther", "Backup", "DR"
};

char *ospf_ism[] = { "interface up", "wait timer fired", "backup seen",
  "neighbor change", "loop indicated", "unloop indicated", "interface down"
const char *ospf_ism_names[] = {
  "InterfaceUp", "WaitTimer", "BackupSeen", "NeighborChange",
  "LoopInd", "UnloopInd", "InterfaceDown"
};

char *ospf_it[] = { "broadcast", "nbma", "ptp", "ptmp", "virtual link" };
const char *ospf_it[] = { "broadcast", "nbma", "ptp", "ptmp", "virtual link" };


static void
@@ -40,7 +41,7 @@ wait_timer_hook(timer * timer)
  struct ospf_iface *ifa = (struct ospf_iface *) timer->data;
  struct ospf_proto *p = ifa->oa->po;

  OSPF_TRACE(D_EVENTS, "Wait timer fired on interface %s", ifa->ifname);
  OSPF_TRACE(D_EVENTS, "Wait timer fired on %s", ifa->ifname);
  ospf_iface_sm(ifa, ISM_WAITF);
}

@@ -240,10 +241,7 @@ ospf_iface_down(struct ospf_iface *ifa)
  }

  WALK_LIST_DELSAFE(n, nx, ifa->neigh_list)
  {
    OSPF_TRACE(D_EVENTS, "Removing neighbor %I", n->ip);
    ospf_neigh_remove(n);
  }
    ospf_neigh_sm(n, INM_KILLNBR);

  if (ifa->hello_timer)
    tm_stop(ifa->hello_timer);
@@ -311,8 +309,8 @@ ospf_iface_chstate(struct ospf_iface *ifa, u8 state)
  if (state == oldstate)
    return;

  OSPF_TRACE(D_EVENTS, "Changing state of iface %s from %s to %s",
	     ifa->ifname, ospf_is[oldstate], ospf_is[state]);
  OSPF_TRACE(D_EVENTS, "Interface %s changed state from %s to %s",
	     ifa->ifname, ospf_is_names[oldstate], ospf_is_names[state]);

  ifa->state = state;

@@ -351,7 +349,7 @@ ospf_iface_chstate(struct ospf_iface *ifa, u8 state)
void
ospf_iface_sm(struct ospf_iface *ifa, int event)
{
  DBG("SM on %s. Event is '%s'\n", ifa->ifname, ospf_ism[event]);
  DBG("SM on %s. Event is '%s'\n", ifa->ifname, ospf_ism_names[event]);

  switch (event)
  {
@@ -613,7 +611,8 @@ ospf_iface_new(struct ospf_area *oa, struct ifa *addr, struct ospf_iface_patt *i
      continue;

    if (ospf_is_v3(p) && !ipa_is_link_local(nb->ip))
      log(L_WARN "In OSPFv3, configured neighbor address (%I) should be link-local", nb->ip);
      log(L_WARN "%s: Configured neighbor address (%I) should be link-local",
	  p->p.name, nb->ip);

    add_nbma_node(ifa, nb, 0);
  }
@@ -726,7 +725,7 @@ ospf_iface_reconfigure(struct ospf_iface *ifa, struct ospf_iface_patt *new)
  /* HELLO TIMER */
  if (ifa->helloint != new->helloint)
  {
    OSPF_TRACE(D_EVENTS, "Changing hello interval on interface %s from %d to %d",
    OSPF_TRACE(D_EVENTS, "Changing hello interval of %s from %d to %d",
	       ifname, ifa->helloint, new->helloint);

    ifa->helloint = new->helloint;
@@ -736,7 +735,7 @@ ospf_iface_reconfigure(struct ospf_iface *ifa, struct ospf_iface_patt *new)
  /* RXMT TIMER */
  if (ifa->rxmtint != new->rxmtint)
  {
    OSPF_TRACE(D_EVENTS, "Changing retransmit interval on interface %s from %d to %d",
    OSPF_TRACE(D_EVENTS, "Changing retransmit interval of %s from %d to %d",
	       ifname, ifa->rxmtint, new->rxmtint);

    ifa->rxmtint = new->rxmtint;
@@ -745,7 +744,7 @@ ospf_iface_reconfigure(struct ospf_iface *ifa, struct ospf_iface_patt *new)
  /* POLL TIMER */
  if (ifa->pollint != new->pollint)
  {
    OSPF_TRACE(D_EVENTS, "Changing poll interval on interface %s from %d to %d",
    OSPF_TRACE(D_EVENTS, "Changing poll interval of %s from %d to %d",
	       ifname, ifa->pollint, new->pollint);

    ifa->pollint = new->pollint;
@@ -755,7 +754,7 @@ ospf_iface_reconfigure(struct ospf_iface *ifa, struct ospf_iface_patt *new)
  /* WAIT TIMER */
  if (ifa->waitint != new->waitint)
  {
    OSPF_TRACE(D_EVENTS, "Changing wait interval on interface %s from %d to %d",
    OSPF_TRACE(D_EVENTS, "Changing wait interval of %s from %d to %d",
	       ifname, ifa->waitint, new->waitint);

    ifa->waitint = new->waitint;
@@ -766,7 +765,7 @@ ospf_iface_reconfigure(struct ospf_iface *ifa, struct ospf_iface_patt *new)
  /* DEAD TIMER */
  if (ifa->deadint != new->deadint)
  {
    OSPF_TRACE(D_EVENTS, "Changing dead interval on interface %s from %d to %d",
    OSPF_TRACE(D_EVENTS, "Changing dead interval of %s from %d to %d",
	       ifname, ifa->deadint, new->deadint);
    ifa->deadint = new->deadint;
  }
@@ -774,7 +773,7 @@ ospf_iface_reconfigure(struct ospf_iface *ifa, struct ospf_iface_patt *new)
  /* INFTRANS */
  if (ifa->inftransdelay != new->inftransdelay)
  {
    OSPF_TRACE(D_EVENTS, "Changing transmit delay on interface %s from %d to %d",
    OSPF_TRACE(D_EVENTS, "Changing transmit delay of %s from %d to %d",
		     ifname, ifa->inftransdelay, new->inftransdelay);
    ifa->inftransdelay = new->inftransdelay;
  }
@@ -782,7 +781,7 @@ ospf_iface_reconfigure(struct ospf_iface *ifa, struct ospf_iface_patt *new)
  /* AUTHENTICATION */
  if (ifa->autype != new->autype)
  {
    OSPF_TRACE(D_EVENTS, "Changing authentication type on interface %s", ifname);
    OSPF_TRACE(D_EVENTS, "Changing authentication type of %s", ifname);
    ifa->autype = new->autype;
  }

@@ -797,7 +796,7 @@ ospf_iface_reconfigure(struct ospf_iface *ifa, struct ospf_iface_patt *new)
  /* COST */
  if (ifa->cost != new->cost)
  {
    OSPF_TRACE(D_EVENTS, "Changing cost on interface %s from %d to %d",
    OSPF_TRACE(D_EVENTS, "Changing cost of %s from %d to %d",
	       ifname, ifa->cost, new->cost);

    ifa->cost = new->cost;
@@ -806,7 +805,7 @@ ospf_iface_reconfigure(struct ospf_iface *ifa, struct ospf_iface_patt *new)
  /* PRIORITY */
  if (ifa->priority != new->priority)
  {
    OSPF_TRACE(D_EVENTS, "Changing priority on interface %s from %d to %d",
    OSPF_TRACE(D_EVENTS, "Changing priority of %s from %d to %d",
	       ifname, ifa->priority, new->priority);

    ifa->priority = new->priority;
@@ -816,7 +815,8 @@ ospf_iface_reconfigure(struct ospf_iface *ifa, struct ospf_iface_patt *new)
  /* STRICT NBMA */
  if (ifa->strictnbma != new->strictnbma)
  {
    OSPF_TRACE(D_EVENTS, "Changing NBMA strictness on interface %s", ifname);
    OSPF_TRACE(D_EVENTS, "Changing NBMA strictness of %s from %d to %d",
	       ifname, ifa->strictnbma, new->strictnbma);
    ifa->strictnbma = new->strictnbma;
  }

@@ -830,14 +830,14 @@ ospf_iface_reconfigure(struct ospf_iface *ifa, struct ospf_iface_patt *new)
    {
      if (nb->eligible != nb2->eligible)
      {
	OSPF_TRACE(D_EVENTS, "Changing eligibility of neighbor %I on interface %s",
	OSPF_TRACE(D_EVENTS, "Changing eligibility of NBMA neighbor %I on %s",
		   nb->ip, ifname);
	nb->eligible = nb2->eligible;
      }
    }
    else
    {
      OSPF_TRACE(D_EVENTS, "Removing NBMA neighbor %I on interface %s",
      OSPF_TRACE(D_EVENTS, "Removing NBMA neighbor %I on %s",
		       nb->ip, ifname);
      rem_node(NODE nb);
      mb_free(nb);
@@ -852,11 +852,12 @@ ospf_iface_reconfigure(struct ospf_iface *ifa, struct ospf_iface_patt *new)
      continue;

    if (ospf_is_v3(p) && !ipa_is_link_local(nb->ip))
      log(L_WARN "In OSPFv3, configured neighbor address (%I) should be link-local", nb->ip);
      log(L_WARN "%s: Configured neighbor address (%I) should be link-local",
	  p->p.name, nb->ip);

    if (! find_nbma_node(ifa, nb->ip))
    {
      OSPF_TRACE(D_EVENTS, "Adding NBMA neighbor %I on interface %s",
      OSPF_TRACE(D_EVENTS, "Adding NBMA neighbor %I on %s",
		 nb->ip, ifname);
      add_nbma_node(ifa, nb, !!find_neigh_by_ip(ifa, nb->ip));
    }
@@ -867,7 +868,7 @@ ospf_iface_reconfigure(struct ospf_iface *ifa, struct ospf_iface_patt *new)
  /* TX LENGTH */
  if (old->tx_length != new->tx_length)
  {
    OSPF_TRACE(D_EVENTS, "Changing TX length on interface %s from %d to %d",
    OSPF_TRACE(D_EVENTS, "Changing TX length of %s from %d to %d",
	       ifname, old->tx_length, new->tx_length);

    /* ifa cannot be vlink */
@@ -878,7 +879,7 @@ ospf_iface_reconfigure(struct ospf_iface *ifa, struct ospf_iface_patt *new)
  /* RX BUFFER */
  if (old->rx_buffer != new->rx_buffer)
  {
    OSPF_TRACE(D_EVENTS, "Changing buffer size on interface %s from %d to %d",
    OSPF_TRACE(D_EVENTS, "Changing buffer size of %s from %d to %d",
	       ifname, old->rx_buffer, new->rx_buffer);

    /* ifa cannot be vlink */
@@ -896,7 +897,7 @@ ospf_iface_reconfigure(struct ospf_iface *ifa, struct ospf_iface_patt *new)
  /* LINK */
  if (ifa->check_link != new->check_link)
  {
    OSPF_TRACE(D_EVENTS, "%s link check on interface %s",
    OSPF_TRACE(D_EVENTS, "%s link check for %s",
	       new->check_link ? "Enabling" : "Disabling", ifname);
    ifa->check_link = new->check_link;

@@ -908,7 +909,7 @@ ospf_iface_reconfigure(struct ospf_iface *ifa, struct ospf_iface_patt *new)
  /* ECMP weight */
  if (ifa->ecmp_weight != new->ecmp_weight)
  {
    OSPF_TRACE(D_EVENTS, "Changing ECMP weight of interface %s from %d to %d",
    OSPF_TRACE(D_EVENTS, "Changing ECMP weight of %s from %d to %d",
	       ifname, (int)ifa->ecmp_weight + 1, (int)new->ecmp_weight + 1);
    ifa->ecmp_weight = new->ecmp_weight;
  }
@@ -927,7 +928,7 @@ ospf_iface_reconfigure(struct ospf_iface *ifa, struct ospf_iface_patt *new)
  /* BFD */
  if (ifa->bfd != new->bfd)
  {
    OSPF_TRACE(D_EVENTS, "%s BFD on interface %s",
    OSPF_TRACE(D_EVENTS, "%s BFD for %s",
	       new->bfd ? "Enabling" : "Disabling", ifname);
    ifa->bfd = new->bfd;

@@ -1197,7 +1198,7 @@ ospf_iface_change_mtu(struct ospf_proto *p, struct ospf_iface *ifa)
{
  /* ifa is not vlink */

  OSPF_TRACE(D_EVENTS, "Changing MTU on interface %s", ifa->ifname);
  OSPF_TRACE(D_EVENTS, "Interface %s changed MTU to %d", ifa->iface->mtu);

  ifa->tx_length = ifa_tx_length(ifa);

@@ -1285,7 +1286,7 @@ ospf_iface_info(struct ospf_iface *ifa)
    cli_msg(-1015, "\tType: %s%s", ospf_it[ifa->type], more);
    cli_msg(-1015, "\tArea: %R (%u)", ifa->oa->areaid, ifa->oa->areaid);
  }
  cli_msg(-1015, "\tState: %s%s", ospf_is[ifa->state], ifa->stub ? " (stub)" : "");
  cli_msg(-1015, "\tState: %s%s", ospf_is_names[ifa->state], ifa->stub ? " (stub)" : "");
  cli_msg(-1015, "\tPriority: %u", ifa->priority);
  cli_msg(-1015, "\tCost: %u", ifa->cost);
  if (ifa->oa->po->ecmp)
Loading