Exemple #1
0
static void ospf_dump_dbdes(struct ospf_proto *p, struct ospf_packet *pkt)
{
    struct ospf_lsa_header *lsas;
    uint i, lsa_count;
    u32 pkt_ddseq;
    u16 pkt_iface_mtu;
    u8 pkt_imms;

    ASSERT(pkt->type == DBDES_P);
    ospf_dump_common(p, pkt);

    if (ospf_is_v2(p)) {
        struct ospf_dbdes2_packet *ps = (void *)pkt;
        pkt_iface_mtu = ntohs(ps->iface_mtu);
        pkt_imms = ps->imms;
        pkt_ddseq = ntohl(ps->ddseq);
    } else {		/* OSPFv3 */

        struct ospf_dbdes3_packet *ps = (void *)pkt;
        pkt_iface_mtu = ntohs(ps->iface_mtu);
        pkt_imms = ps->imms;
        pkt_ddseq = ntohl(ps->ddseq);
    }

    log(L_TRACE "%s:     mtu      %u", p->p.name, pkt_iface_mtu);
    log(L_TRACE "%s:     imms     %s%s%s", p->p.name,
        (pkt_imms & DBDES_I) ? "I " : "",
        (pkt_imms & DBDES_M) ? "M " : "",
        (pkt_imms & DBDES_MS) ? "MS" : "");
    log(L_TRACE "%s:     ddseq    %u", p->p.name, pkt_ddseq);

    ospf_dbdes_body(p, pkt, &lsas, &lsa_count);
    for (i = 0; i < lsa_count; i++)
        ospf_dump_lsahdr(p, lsas + i);
}
Exemple #2
0
static void
ospf_prepare_dbdes(struct ospf_proto *p, struct ospf_neighbor *n)
{
  struct ospf_iface *ifa = n->ifa;
  struct ospf_packet *pkt;
  uint length;

  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);
    n->ldd_buffer = mb_allocz(n->pool, ifa->tx_length);
    n->ldd_bsize = ifa->tx_length;
  }

  pkt = n->ldd_buffer;
  ospf_pkt_fill_hdr(ifa, pkt, DBDES_P);

  if (ospf_is_v2(p))
  {
    struct ospf_dbdes2_packet *ps = (void *) pkt;
    ps->iface_mtu = htons(iface_mtu);
    ps->options = ifa->oa->options;
    ps->imms = 0;	/* Will be set later */
    ps->ddseq = htonl(n->dds);
    length = sizeof(struct ospf_dbdes2_packet);
  }
  else /* OSPFv3 */
  {
    struct ospf_dbdes3_packet *ps = (void *) pkt;
    ps->options = htonl(ifa->oa->options);
    ps->iface_mtu = htons(iface_mtu);
    ps->padding = 0;
    ps->imms = 0;	/* Will be set later */
    ps->ddseq = htonl(n->dds);
    length = sizeof(struct ospf_dbdes3_packet);
  }

  /* Prepare DBDES body */
  if (!(n->myimms & DBDES_I) && (n->myimms & DBDES_M))
  {
    struct ospf_lsa_header *lsas;
    struct top_hash_entry *en;
    uint i = 0, lsa_max;

    ospf_dbdes_body(p, pkt, &lsas, &lsa_max);
    en = (void *) s_get(&(n->dbsi));

    while (i < lsa_max)
    {
      if (!SNODE_VALID(en))
      {
	n->myimms &= ~DBDES_M;	/* Unset More bit */
	break;
      }

      if ((en->lsa.age < LSA_MAXAGE) &&
	  lsa_flooding_allowed(en->lsa_type, en->domain, ifa))
      {
	lsa_hton_hdr(&(en->lsa), lsas + i);
	i++;
      }

      en = SNODE_NEXT(en);
    }

    s_put(&(n->dbsi), SNODE en);

    length += i * sizeof(struct ospf_lsa_header);
  }

  if (ospf_is_v2(p))
    ((struct ospf_dbdes2_packet *) pkt)->imms = n->myimms;
  else
    ((struct ospf_dbdes3_packet *) pkt)->imms = n->myimms;

  pkt->length = htons(length);
}
Exemple #3
0
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, 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++)
  {
    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)
      DROP1("LSA of unknown type");

    if (!oa_is_ext(ifa->oa) && (LSA_SCOPE(lsa_type) == LSA_SCOPE_AS))
      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))
      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)
      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))
    {
      /* This should be splitted to ospf_lsa_lsrq_up() */
      req = ospf_hash_get(n->lsrqh, lsa_domain, lsa.id, lsa.rt, lsa_type);

      if (!SNODE_VALID(req))
	s_add_tail(&n->lsrql, SNODE req);

      if (!SNODE_VALID(n->lsrqi))
	n->lsrqi = req;

      req->lsa = lsa;
      req->lsa_body = LSA_BODY_DUMMY;

      if (!tm_active(n->lsrq_timer))
	tm_start(n->lsrq_timer, 0);
    }
  }

  return 0;

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;
}