2000-03-30 00:18:59 +00:00
|
|
|
/*
|
|
|
|
* BIRD -- OSPF
|
|
|
|
*
|
2004-06-04 17:28:41 +00:00
|
|
|
* (c) 2000--2004 Ondrej Filip <feela@network.cz>
|
2000-03-30 00:18:59 +00:00
|
|
|
*
|
|
|
|
* Can be freely distributed and used under the terms of the GNU GPL.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ospf.h"
|
|
|
|
|
2009-08-21 07:27:52 +00:00
|
|
|
|
2012-08-05 20:32:06 +00:00
|
|
|
/*
|
2009-08-21 07:27:52 +00:00
|
|
|
struct ospf_lsreq_packet
|
|
|
|
{
|
2012-08-05 20:32:06 +00:00
|
|
|
struct ospf_packet hdr;
|
|
|
|
// union ospf_auth auth;
|
2009-08-21 07:27:52 +00:00
|
|
|
|
2012-08-05 20:32:06 +00:00
|
|
|
struct ospf_lsreq_header lsrs[];
|
|
|
|
};
|
|
|
|
*/
|
2009-08-21 07:27:52 +00:00
|
|
|
|
2012-10-02 09:44:05 +00:00
|
|
|
static inline void
|
2012-08-05 20:32:06 +00:00
|
|
|
ospf_lsreq_body(struct proto_ospf *po, struct ospf_packet *pkt, unsigned plen,
|
|
|
|
struct ospf_lsreq_header **body, unsigned *count)
|
2009-04-06 14:17:47 +00:00
|
|
|
{
|
2012-08-05 20:32:06 +00:00
|
|
|
unsigned hdrlen = ospf_pkt_hdrlen(po);
|
|
|
|
*body = ((void *) pkt) + hdrlen;
|
|
|
|
*count = (plen - hdrlen) / sizeof(struct ospf_lsreq_header);
|
|
|
|
}
|
2009-04-06 14:17:47 +00:00
|
|
|
|
2012-08-05 20:32:06 +00:00
|
|
|
static void
|
|
|
|
ospf_lsreq_dump(struct proto_ospf *po, struct ospf_packet *pkt)
|
|
|
|
{
|
|
|
|
struct ospf_lsreq_header *lsrs;
|
|
|
|
unsigned i, lsr_count;
|
2009-04-06 14:17:47 +00:00
|
|
|
|
2012-08-05 20:32:06 +00:00
|
|
|
ASSERT(pkt->type == LSREQ_P);
|
|
|
|
ospf_dump_common(po, pkt);
|
2009-04-06 14:17:47 +00:00
|
|
|
|
2012-08-05 20:32:06 +00:00
|
|
|
ospf_lsreq_body(po, pkt, ntohs(pkt->length), &lsrs, &lsr_count);
|
|
|
|
for (i = 0; i < lsr_count; i++)
|
|
|
|
log(L_TRACE "%s: LSR Type: %04x, Id: %R, Rt: %R", po->proto.name,
|
|
|
|
ntohl(lsrs[i].type), ntohl(lsrs[i].id), ntohl(lsrs[i].rt));
|
2009-04-06 14:17:47 +00:00
|
|
|
}
|
|
|
|
|
2000-03-30 00:18:59 +00:00
|
|
|
void
|
2004-06-04 17:28:41 +00:00
|
|
|
ospf_lsreq_send(struct ospf_neighbor *n)
|
2000-03-30 00:18:59 +00:00
|
|
|
{
|
2012-08-05 20:32:06 +00:00
|
|
|
struct ospf_iface *ifa = n->ifa;
|
|
|
|
struct proto_ospf *po = ifa->oa->po;
|
|
|
|
struct ospf_lsreq_header *lsrs;
|
2000-03-30 00:18:59 +00:00
|
|
|
struct top_hash_entry *en;
|
2012-08-05 20:32:06 +00:00
|
|
|
struct ospf_packet *pkt;
|
|
|
|
unsigned i, lsh_max, length;
|
|
|
|
snode *sn;
|
2000-03-30 00:18:59 +00:00
|
|
|
|
|
|
|
|
2004-06-04 17:28:41 +00:00
|
|
|
if (EMPTY_SLIST(n->lsrql))
|
2000-03-30 19:21:17 +00:00
|
|
|
{
|
2004-06-04 17:28:41 +00:00
|
|
|
if (n->state == NEIGHBOR_LOADING)
|
|
|
|
ospf_neigh_sm(n, INM_LOADDONE);
|
2000-03-30 19:21:17 +00:00
|
|
|
return;
|
|
|
|
}
|
2004-06-04 17:28:41 +00:00
|
|
|
|
2012-08-05 20:32:06 +00:00
|
|
|
pkt = ospf_tx_buffer(ifa);
|
|
|
|
ospf_pkt_fill_hdr(ifa, pkt, LSREQ_P);
|
|
|
|
ospf_lsreq_body(po, pkt, ospf_pkt_maxsize(ifa), &lsrs, &lsh_max);
|
2004-06-04 17:28:41 +00:00
|
|
|
|
2012-08-05 20:32:06 +00:00
|
|
|
sn = SHEAD(n->lsrql);
|
|
|
|
for (i = 0; i < lsh_max; i++)
|
2000-03-30 00:18:59 +00:00
|
|
|
{
|
2004-06-04 17:28:41 +00:00
|
|
|
en = (struct top_hash_entry *) sn;
|
2009-07-23 14:51:28 +00:00
|
|
|
DBG("Requesting %uth LSA: Type: %u, ID: %R, RT: %R, SN: 0x%x, Age %u\n",
|
2012-10-02 09:44:05 +00:00
|
|
|
i, en->lsa_type, en->lsa.id, en->lsa.rt, en->lsa.sn, en->lsa.age);
|
2012-08-05 20:32:06 +00:00
|
|
|
|
2012-10-02 09:44:05 +00:00
|
|
|
u32 rtype = lsa_get_type(po, en->lsa.type_raw);
|
|
|
|
lsrs[i].type = htonl(rtype);
|
2012-08-05 20:32:06 +00:00
|
|
|
lsrs[i].rt = htonl(en->lsa.rt);
|
|
|
|
lsrs[i].id = htonl(en->lsa.id);
|
|
|
|
|
2004-06-04 17:28:41 +00:00
|
|
|
if (sn == STAIL(n->lsrql))
|
|
|
|
break;
|
|
|
|
sn = sn->next;
|
2000-03-30 00:18:59 +00:00
|
|
|
}
|
|
|
|
|
2012-08-05 20:32:06 +00:00
|
|
|
length = ospf_pkt_hdrlen(po) + i * sizeof(struct ospf_lsreq_header);
|
|
|
|
pkt->length = htons(length);
|
2009-04-06 14:17:47 +00:00
|
|
|
|
2012-08-05 20:32:06 +00:00
|
|
|
OSPF_PACKET(ospf_lsreq_dump, pkt, "LSREQ packet sent to %I via %s",
|
|
|
|
n->ip, ifa->iface->name);
|
|
|
|
ospf_send_to(ifa, n->ip);
|
2000-03-30 00:18:59 +00:00
|
|
|
}
|
|
|
|
|
2013-04-15 23:14:57 +00:00
|
|
|
|
2000-03-30 00:18:59 +00:00
|
|
|
void
|
2012-08-05 20:32:06 +00:00
|
|
|
ospf_lsreq_receive(struct ospf_packet *pkt, struct ospf_iface *ifa,
|
2009-08-21 07:27:52 +00:00
|
|
|
struct ospf_neighbor *n)
|
2000-03-30 00:18:59 +00:00
|
|
|
{
|
2012-08-05 20:32:06 +00:00
|
|
|
struct proto_ospf *po = ifa->oa->po;
|
|
|
|
struct ospf_lsreq_header *lsrs;
|
|
|
|
unsigned i, lsr_count;
|
2012-10-02 09:44:05 +00:00
|
|
|
|
2012-08-05 20:32:06 +00:00
|
|
|
/* No need to check length, lsreq has only basic header */
|
|
|
|
|
|
|
|
OSPF_PACKET(ospf_lsreq_dump, pkt, "LSREQ packet received from %I via %s",
|
|
|
|
n->ip, ifa->iface->name);
|
2009-04-06 14:17:47 +00:00
|
|
|
|
2004-06-04 17:28:41 +00:00
|
|
|
if (n->state < NEIGHBOR_EXCHANGE)
|
|
|
|
return;
|
2000-05-09 18:17:34 +00:00
|
|
|
|
2012-08-05 20:32:06 +00:00
|
|
|
ospf_neigh_sm(n, INM_HELLOREC); /* Not in RFC */
|
2000-03-30 00:18:59 +00:00
|
|
|
|
2012-08-05 20:32:06 +00:00
|
|
|
ospf_lsreq_body(po, pkt, ntohs(pkt->length), &lsrs, &lsr_count);
|
2013-04-15 23:14:57 +00:00
|
|
|
|
|
|
|
struct top_hash_entry *en, *entries[lsr_count];
|
|
|
|
|
2012-08-05 20:32:06 +00:00
|
|
|
for (i = 0; i < lsr_count; i++)
|
2000-03-30 00:18:59 +00:00
|
|
|
{
|
2012-10-02 09:44:05 +00:00
|
|
|
u32 id, rt, type, dom;
|
|
|
|
|
|
|
|
id = ntohl(lsrs[i].id);
|
|
|
|
rt = ntohl(lsrs[i].rt);
|
|
|
|
lsa_xxxxtype(ntohl(lsrs[i].type), ifa, &type, &dom);
|
|
|
|
|
|
|
|
DBG("Processing requested LSA: Type: %04x, Id: %R, Rt: %R\n", type, id, rt);
|
|
|
|
|
2013-04-15 23:14:57 +00:00
|
|
|
en = ospf_hash_find(po->gr, dom, id, rt, type);
|
|
|
|
if (!en)
|
2000-03-30 20:00:42 +00:00
|
|
|
{
|
2013-04-15 23:14:57 +00:00
|
|
|
log(L_WARN "%s: Received LSREQ from %I for missing LSA (Type: %04x, Id: %R, Rt: %R)",
|
|
|
|
po->proto.name, n->ip, type, id, rt);
|
2004-06-04 17:28:41 +00:00
|
|
|
ospf_neigh_sm(n, INM_BADLSREQ);
|
2000-03-30 20:00:42 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-08-05 20:32:06 +00:00
|
|
|
|
2013-04-15 23:14:57 +00:00
|
|
|
entries[i] = en;
|
2000-03-30 00:18:59 +00:00
|
|
|
}
|
2012-08-05 20:32:06 +00:00
|
|
|
|
2013-04-15 23:14:57 +00:00
|
|
|
ospf_lsupd_send(n, entries, lsr_count);
|
2000-03-30 00:18:59 +00:00
|
|
|
}
|