2000-03-30 08:18:59 +08:00
|
|
|
/*
|
|
|
|
* BIRD -- OSPF
|
|
|
|
*
|
2004-06-05 01:28:41 +08:00
|
|
|
* (c) 2000--2004 Ondrej Filip <feela@network.cz>
|
2014-06-26 17:58:57 +08:00
|
|
|
* (c) 2009--2014 Ondrej Zajicek <santiago@crfreenet.org>
|
|
|
|
* (c) 2009--2014 CZ.NIC z.s.p.o.
|
2000-03-30 08:18:59 +08:00
|
|
|
*
|
|
|
|
* Can be freely distributed and used under the terms of the GNU GPL.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ospf.h"
|
|
|
|
|
2009-08-21 15:27:52 +08:00
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
/*
|
2009-08-21 15:27:52 +08:00
|
|
|
struct ospf_lsreq_packet
|
|
|
|
{
|
2014-06-26 17:58:57 +08:00
|
|
|
struct ospf_packet hdr;
|
|
|
|
// union ospf_auth auth;
|
|
|
|
|
|
|
|
struct ospf_lsreq_header lsrs[];
|
2009-08-21 15:27:52 +08:00
|
|
|
};
|
2014-06-26 17:58:57 +08:00
|
|
|
*/
|
2009-08-21 15:27:52 +08:00
|
|
|
|
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
static inline void
|
|
|
|
ospf_lsreq_body(struct ospf_proto *p, struct ospf_packet *pkt,
|
|
|
|
struct ospf_lsreq_header **body, uint *count)
|
2009-04-06 22:17:47 +08:00
|
|
|
{
|
2014-06-26 17:58:57 +08:00
|
|
|
uint plen = ntohs(pkt->length);
|
|
|
|
uint hlen = ospf_pkt_hdrlen(p);
|
|
|
|
|
|
|
|
*body = ((void *) pkt) + hlen;
|
|
|
|
*count = (plen - hlen) / sizeof(struct ospf_lsreq_header);
|
|
|
|
}
|
2009-04-06 22:17:47 +08:00
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
static void
|
|
|
|
ospf_dump_lsreq(struct ospf_proto *p, struct ospf_packet *pkt)
|
|
|
|
{
|
|
|
|
struct ospf_lsreq_header *lsrs;
|
|
|
|
uint i, lsr_count;
|
2009-04-06 22:17:47 +08:00
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
ASSERT(pkt->type == LSREQ_P);
|
|
|
|
ospf_dump_common(p, pkt);
|
2009-04-06 22:17:47 +08:00
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
ospf_lsreq_body(p, pkt, &lsrs, &lsr_count);
|
|
|
|
for (i = 0; i < lsr_count; i++)
|
|
|
|
log(L_TRACE "%s: LSR Type: %04x, Id: %R, Rt: %R", p->p.name,
|
|
|
|
ntohl(lsrs[i].type), ntohl(lsrs[i].id), ntohl(lsrs[i].rt));
|
2009-04-06 22:17:47 +08:00
|
|
|
}
|
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
|
2000-03-30 08:18:59 +08:00
|
|
|
void
|
2014-06-26 17:58:57 +08:00
|
|
|
ospf_send_lsreq(struct ospf_proto *p, struct ospf_neighbor *n)
|
2000-03-30 08:18:59 +08:00
|
|
|
{
|
2014-06-26 17:58:57 +08:00
|
|
|
struct ospf_iface *ifa = n->ifa;
|
|
|
|
struct ospf_lsreq_header *lsrs;
|
2000-03-30 08:18:59 +08:00
|
|
|
struct top_hash_entry *en;
|
2014-06-26 17:58:57 +08:00
|
|
|
struct ospf_packet *pkt;
|
|
|
|
uint i, lsr_max, length;
|
2000-03-30 08:18:59 +08:00
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
/* RFC 2328 10.9 */
|
2000-03-30 08:18:59 +08:00
|
|
|
|
2004-06-05 01:28:41 +08:00
|
|
|
if (EMPTY_SLIST(n->lsrql))
|
2000-03-31 03:21:17 +08:00
|
|
|
{
|
2004-06-05 01:28:41 +08:00
|
|
|
if (n->state == NEIGHBOR_LOADING)
|
|
|
|
ospf_neigh_sm(n, INM_LOADDONE);
|
2000-03-31 03:21:17 +08:00
|
|
|
return;
|
|
|
|
}
|
2004-06-05 01:28:41 +08:00
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
pkt = ospf_tx_buffer(ifa);
|
|
|
|
ospf_pkt_fill_hdr(ifa, pkt, LSREQ_P);
|
|
|
|
ospf_lsreq_body(p, pkt, &lsrs, &lsr_max);
|
|
|
|
|
2014-07-19 00:24:12 +08:00
|
|
|
/* We send smaller LSREQ to prevent multiple LSACKs as answer */
|
|
|
|
lsr_max = lsr_max / 4;
|
2004-06-05 01:28:41 +08:00
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
i = 0;
|
|
|
|
WALK_SLIST(en, n->lsrql)
|
2000-03-30 08:18:59 +08:00
|
|
|
{
|
2014-06-26 17:58:57 +08:00
|
|
|
if (i == lsr_max)
|
2004-06-05 01:28:41 +08:00
|
|
|
break;
|
2014-06-26 17:58:57 +08:00
|
|
|
|
|
|
|
DBG("Requesting %uth LSA: Type: %04u, ID: %R, RT: %R, SN: 0x%x, Age %u\n",
|
|
|
|
i, en->lsa_type, en->lsa.id, en->lsa.rt, en->lsa.sn, en->lsa.age);
|
|
|
|
|
|
|
|
u32 etype = lsa_get_etype(&en->lsa, p);
|
|
|
|
lsrs[i].type = htonl(etype);
|
|
|
|
lsrs[i].rt = htonl(en->lsa.rt);
|
|
|
|
lsrs[i].id = htonl(en->lsa.id);
|
|
|
|
i++;
|
2000-03-30 08:18:59 +08:00
|
|
|
}
|
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
length = ospf_pkt_hdrlen(p) + i * sizeof(struct ospf_lsreq_header);
|
|
|
|
pkt->length = htons(length);
|
2009-04-06 22:17:47 +08:00
|
|
|
|
2014-10-24 16:27:21 +08:00
|
|
|
OSPF_PACKET(ospf_dump_lsreq, pkt, "LSREQ packet sent to nbr %R on %s", n->rid, ifa->ifname);
|
2014-06-26 17:58:57 +08:00
|
|
|
ospf_send_to(ifa, n->ip);
|
2000-03-30 08:18:59 +08:00
|
|
|
}
|
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
|
2000-03-30 08:18:59 +08:00
|
|
|
void
|
2014-06-26 17:58:57 +08:00
|
|
|
ospf_receive_lsreq(struct ospf_packet *pkt, struct ospf_iface *ifa,
|
2009-08-21 15:27:52 +08:00
|
|
|
struct ospf_neighbor *n)
|
2000-03-30 08:18:59 +08:00
|
|
|
{
|
2014-06-26 17:58:57 +08:00
|
|
|
struct ospf_proto *p = ifa->oa->po;
|
|
|
|
struct ospf_lsreq_header *lsrs;
|
|
|
|
uint i, lsr_count;
|
2009-10-30 06:57:42 +08:00
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
/* RFC 2328 10.7 */
|
|
|
|
|
|
|
|
/* No need to check length, lsreq has only basic header */
|
|
|
|
|
2014-10-24 16:27:21 +08:00
|
|
|
OSPF_PACKET(ospf_dump_lsreq, pkt, "LSREQ packet received from nbr %R on %s", n->rid, ifa->ifname);
|
2009-04-06 22:17:47 +08:00
|
|
|
|
2004-06-05 01:28:41 +08:00
|
|
|
if (n->state < NEIGHBOR_EXCHANGE)
|
2014-10-24 16:27:21 +08:00
|
|
|
{
|
|
|
|
OSPF_TRACE(D_PACKETS, "LSREQ packet ignored - lesser state than Exchange");
|
2004-06-05 01:28:41 +08:00
|
|
|
return;
|
2014-10-24 16:27:21 +08:00
|
|
|
}
|
2000-05-10 02:17:34 +08:00
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
ospf_neigh_sm(n, INM_HELLOREC); /* Not in RFC */
|
|
|
|
|
|
|
|
ospf_lsreq_body(p, pkt, &lsrs, &lsr_count);
|
2000-03-30 08:18:59 +08:00
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
struct top_hash_entry *en, *entries[lsr_count];
|
2000-03-31 08:21:41 +08:00
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
for (i = 0; i < lsr_count; i++)
|
2000-03-30 08:18:59 +08:00
|
|
|
{
|
2014-06-26 17:58:57 +08:00
|
|
|
u32 id, rt, type, domain;
|
|
|
|
|
|
|
|
id = ntohl(lsrs[i].id);
|
|
|
|
rt = ntohl(lsrs[i].rt);
|
|
|
|
lsa_get_type_domain_(ntohl(lsrs[i].type), ifa, &type, &domain);
|
|
|
|
|
|
|
|
DBG("Processing requested LSA: Type: %04x, Id: %R, Rt: %R\n", type, id, rt);
|
|
|
|
|
2014-07-19 23:28:38 +08:00
|
|
|
en = ospf_hash_find(p->gr, domain, id, rt, type);
|
2014-06-26 17:58:57 +08:00
|
|
|
if (!en)
|
2000-03-31 04:00:42 +08:00
|
|
|
{
|
2014-10-24 16:27:21 +08:00
|
|
|
LOG_LSA1("Bad LSR (Type: %04x, Id: %R, Rt: %R) in LSREQ", type, id, rt);
|
|
|
|
LOG_LSA2(" received from nbr %R on %s - LSA is missing", n->rid, ifa->ifname);
|
|
|
|
|
2004-06-05 01:28:41 +08:00
|
|
|
ospf_neigh_sm(n, INM_BADLSREQ);
|
2000-03-31 04:00:42 +08:00
|
|
|
return;
|
|
|
|
}
|
2014-06-26 17:58:57 +08:00
|
|
|
|
|
|
|
entries[i] = en;
|
2000-03-30 08:18:59 +08:00
|
|
|
}
|
2014-06-26 17:58:57 +08:00
|
|
|
|
|
|
|
ospf_send_lsupd(p, entries, lsr_count, n);
|
2000-03-30 08:18:59 +08:00
|
|
|
}
|