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
|
|
|
|
|
|
|
struct ospf_lsreq_packet
|
|
|
|
{
|
|
|
|
struct ospf_packet ospf_packet;
|
|
|
|
struct ospf_lsreq_header lsh[];
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-04-06 14:17:47 +00:00
|
|
|
static void ospf_dump_lsreq(struct proto *p, struct ospf_lsreq_packet *pkt)
|
|
|
|
{
|
|
|
|
struct ospf_packet *op = &pkt->ospf_packet;
|
|
|
|
|
|
|
|
ASSERT(op->type == LSREQ_P);
|
|
|
|
ospf_dump_common(p, op);
|
|
|
|
|
2009-10-29 22:57:42 +00:00
|
|
|
unsigned int i, j;
|
2009-08-21 07:27:52 +00:00
|
|
|
j = (ntohs(op->length) - sizeof(struct ospf_lsreq_packet)) /
|
2009-04-06 14:17:47 +00:00
|
|
|
sizeof(struct ospf_lsreq_header);
|
|
|
|
|
|
|
|
for (i = 0; i < j; i++)
|
2009-12-14 16:29:33 +00:00
|
|
|
log(L_TRACE "%s: LSR Type: %04x, Id: %R, Rt: %R", p->name,
|
|
|
|
htonl(pkt->lsh[i].type), htonl(pkt->lsh[i].id), htonl(pkt->lsh[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
|
|
|
{
|
|
|
|
snode *sn;
|
|
|
|
struct top_hash_entry *en;
|
|
|
|
struct ospf_lsreq_packet *pk;
|
|
|
|
struct ospf_packet *op;
|
|
|
|
struct ospf_lsreq_header *lsh;
|
|
|
|
u16 length;
|
2004-06-04 17:28:41 +00:00
|
|
|
int i, j;
|
2004-07-15 16:37:52 +00:00
|
|
|
struct proto *p = &n->ifa->oa->po->proto;
|
2000-03-30 00:18:59 +00:00
|
|
|
|
2010-03-11 17:07:24 +00:00
|
|
|
pk = ospf_tx_buffer(n->ifa);
|
2010-02-11 09:23:35 +00:00
|
|
|
op = &pk->ospf_packet;
|
2000-03-30 00:18:59 +00:00
|
|
|
|
2004-06-26 20:15:34 +00:00
|
|
|
ospf_pkt_fill_hdr(n->ifa, pk, LSREQ_P);
|
2000-03-30 00:18:59 +00:00
|
|
|
|
2004-06-04 17:28:41 +00:00
|
|
|
sn = SHEAD(n->lsrql);
|
|
|
|
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
|
|
|
|
2004-06-26 20:15:34 +00:00
|
|
|
i = j = (ospf_pkt_maxsize(n->ifa) - sizeof(struct ospf_lsreq_packet)) /
|
2000-03-30 16:22:58 +00:00
|
|
|
sizeof(struct ospf_lsreq_header);
|
2009-08-21 07:27:52 +00:00
|
|
|
lsh = pk->lsh;
|
2004-06-04 17:28:41 +00:00
|
|
|
|
|
|
|
for (; i > 0; i--)
|
2000-03-30 00:18:59 +00:00
|
|
|
{
|
2004-06-04 17:28:41 +00:00
|
|
|
en = (struct top_hash_entry *) sn;
|
2009-08-21 07:27:52 +00:00
|
|
|
lsh->type = htonl(en->lsa.type);
|
2004-06-04 17:28:41 +00:00
|
|
|
lsh->rt = htonl(en->lsa.rt);
|
|
|
|
lsh->id = htonl(en->lsa.id);
|
2009-07-23 14:51:28 +00:00
|
|
|
DBG("Requesting %uth LSA: Type: %u, 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);
|
2000-03-31 00:21:41 +00:00
|
|
|
lsh++;
|
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
|
|
|
}
|
2004-06-04 17:28:41 +00:00
|
|
|
if (i != 0)
|
|
|
|
i--;
|
2000-03-30 00:18:59 +00:00
|
|
|
|
2004-06-04 17:28:41 +00:00
|
|
|
length =
|
|
|
|
sizeof(struct ospf_lsreq_packet) + (j -
|
|
|
|
i) * sizeof(struct ospf_lsreq_header);
|
|
|
|
op->length = htons(length);
|
2009-04-06 14:17:47 +00:00
|
|
|
|
2010-02-11 09:23:35 +00:00
|
|
|
OSPF_PACKET(ospf_dump_lsreq, pk, "LSREQ packet sent to %I via %s", n->ip, n->ifa->iface->name);
|
2009-09-04 09:06:51 +00:00
|
|
|
ospf_send_to(n->ifa, n->ip);
|
2000-03-30 00:18:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-08-21 07:27:52 +00:00
|
|
|
ospf_lsreq_receive(struct ospf_packet *ps_i, struct ospf_iface *ifa,
|
|
|
|
struct ospf_neighbor *n)
|
2000-03-30 00:18:59 +00:00
|
|
|
{
|
2009-10-29 22:57:42 +00:00
|
|
|
struct ospf_area *oa = ifa->oa;
|
|
|
|
struct proto_ospf *po = oa->po;
|
|
|
|
struct proto *p = &po->proto;
|
2000-03-30 00:18:59 +00:00
|
|
|
struct ospf_lsreq_header *lsh;
|
2000-03-31 00:21:41 +00:00
|
|
|
struct l_lsr_head *llsh;
|
|
|
|
list uplist;
|
|
|
|
slab *upslab;
|
2004-06-06 19:53:52 +00:00
|
|
|
int i, lsano;
|
2000-03-30 00:18:59 +00:00
|
|
|
|
2009-10-29 22:57:42 +00:00
|
|
|
unsigned int size = ntohs(ps_i->length);
|
|
|
|
if (size < sizeof(struct ospf_lsreq_packet))
|
|
|
|
{
|
|
|
|
log(L_ERR "Bad OSPF LSREQ packet from %I - too short (%u B)", n->ip, size);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct ospf_lsreq_packet *ps = (void *) ps_i;
|
2009-04-06 14:17:47 +00:00
|
|
|
OSPF_PACKET(ospf_dump_lsreq, ps, "LSREQ packet received from %I via %s", n->ip, ifa->iface->name);
|
|
|
|
|
2004-06-04 17:28:41 +00:00
|
|
|
if (n->state < NEIGHBOR_EXCHANGE)
|
|
|
|
return;
|
2000-05-09 18:17:34 +00:00
|
|
|
|
2000-06-05 19:45:06 +00:00
|
|
|
ospf_neigh_sm(n, INM_HELLOREC);
|
2000-03-30 00:18:59 +00:00
|
|
|
|
2009-08-21 07:27:52 +00:00
|
|
|
lsh = ps->lsh;
|
2000-03-31 00:21:41 +00:00
|
|
|
init_list(&uplist);
|
2004-06-04 17:28:41 +00:00
|
|
|
upslab = sl_new(n->pool, sizeof(struct l_lsr_head));
|
2000-03-31 00:21:41 +00:00
|
|
|
|
2004-06-06 19:53:52 +00:00
|
|
|
lsano = (size - sizeof(struct ospf_lsreq_packet)) /
|
2000-06-02 09:42:24 +00:00
|
|
|
sizeof(struct ospf_lsreq_header);
|
2004-06-04 17:28:41 +00:00
|
|
|
for (i = 0; i < lsano; lsh++, i++)
|
2000-03-30 00:18:59 +00:00
|
|
|
{
|
2008-08-25 12:00:55 +00:00
|
|
|
u32 hid = ntohl(lsh->id);
|
|
|
|
u32 hrt = ntohl(lsh->rt);
|
2009-08-21 07:27:52 +00:00
|
|
|
u32 htype = ntohl(lsh->type);
|
|
|
|
u32 dom = ospf_lsa_domain(htype, ifa);
|
2009-07-23 14:51:28 +00:00
|
|
|
DBG("Processing requested LSA: Type: %u, ID: %R, RT: %R\n", lsh->type, hid, hrt);
|
2004-06-04 17:28:41 +00:00
|
|
|
llsh = sl_alloc(upslab);
|
2008-08-25 12:00:55 +00:00
|
|
|
llsh->lsh.id = hid;
|
|
|
|
llsh->lsh.rt = hrt;
|
2009-08-21 07:27:52 +00:00
|
|
|
llsh->lsh.type = htype;
|
2000-03-31 00:21:41 +00:00
|
|
|
add_tail(&uplist, NODE llsh);
|
2009-08-25 14:42:14 +00:00
|
|
|
if (ospf_hash_find(po->gr, dom, hid, hrt, htype) == NULL)
|
2000-03-30 20:00:42 +00:00
|
|
|
{
|
2009-12-14 16:29:33 +00:00
|
|
|
log(L_WARN "Received bad LSREQ from %I: Type: %04x, Id: %R, Rt: %R",
|
2009-08-21 07:27:52 +00:00
|
|
|
n->ip, htype, hid, hrt);
|
2004-06-04 17:28:41 +00:00
|
|
|
ospf_neigh_sm(n, INM_BADLSREQ);
|
2000-03-31 00:21:41 +00:00
|
|
|
rfree(upslab);
|
2000-03-30 20:00:42 +00:00
|
|
|
return;
|
|
|
|
}
|
2000-03-30 00:18:59 +00:00
|
|
|
}
|
2004-06-04 21:05:43 +00:00
|
|
|
ospf_lsupd_send_list(n, &uplist);
|
2000-03-31 00:21:41 +00:00
|
|
|
rfree(upslab);
|
2000-03-30 00:18:59 +00:00
|
|
|
}
|