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>
|
2000-03-30 08:18:59 +08:00
|
|
|
*
|
|
|
|
* Can be freely distributed and used under the terms of the GNU GPL.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ospf.h"
|
|
|
|
|
|
|
|
void
|
2004-06-05 01:28:41 +08:00
|
|
|
ospf_lsreq_send(struct ospf_neighbor *n)
|
2000-03-30 08:18:59 +08: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-05 01:28:41 +08:00
|
|
|
int i, j;
|
2004-07-16 00:37:52 +08:00
|
|
|
struct proto *p = &n->ifa->oa->po->proto;
|
2000-03-30 08:18:59 +08:00
|
|
|
|
2004-06-05 01:28:41 +08:00
|
|
|
pk = (struct ospf_lsreq_packet *) n->ifa->ip_sk->tbuf;
|
|
|
|
op = (struct ospf_packet *) n->ifa->ip_sk->tbuf;
|
2000-03-30 08:18:59 +08:00
|
|
|
|
2004-06-27 04:15:34 +08:00
|
|
|
ospf_pkt_fill_hdr(n->ifa, pk, LSREQ_P);
|
2000-03-30 08:18:59 +08:00
|
|
|
|
2004-06-05 01:28:41 +08:00
|
|
|
sn = SHEAD(n->lsrql);
|
|
|
|
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
|
|
|
|
2004-06-27 04:15:34 +08:00
|
|
|
i = j = (ospf_pkt_maxsize(n->ifa) - sizeof(struct ospf_lsreq_packet)) /
|
2000-03-31 00:22:58 +08:00
|
|
|
sizeof(struct ospf_lsreq_header);
|
2004-06-05 01:28:41 +08:00
|
|
|
lsh = (struct ospf_lsreq_header *) (pk + 1);
|
|
|
|
|
|
|
|
for (; i > 0; i--)
|
2000-03-30 08:18:59 +08:00
|
|
|
{
|
2004-06-05 01:28:41 +08:00
|
|
|
en = (struct top_hash_entry *) sn;
|
|
|
|
lsh->padd1 = 0;
|
|
|
|
lsh->padd2 = 0;
|
|
|
|
lsh->type = en->lsa.type;
|
|
|
|
lsh->rt = htonl(en->lsa.rt);
|
|
|
|
lsh->id = htonl(en->lsa.id);
|
2009-01-11 19:14:27 +08:00
|
|
|
DBG("Requesting %uth LSA: Type: %u, ID: %I, RT: %I, 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 08:21:41 +08:00
|
|
|
lsh++;
|
2004-06-05 01:28:41 +08:00
|
|
|
if (sn == STAIL(n->lsrql))
|
|
|
|
break;
|
|
|
|
sn = sn->next;
|
2000-03-30 08:18:59 +08:00
|
|
|
}
|
2004-06-05 01:28:41 +08:00
|
|
|
if (i != 0)
|
|
|
|
i--;
|
2000-03-30 08:18:59 +08:00
|
|
|
|
2004-06-05 01:28:41 +08:00
|
|
|
length =
|
|
|
|
sizeof(struct ospf_lsreq_packet) + (j -
|
|
|
|
i) * sizeof(struct ospf_lsreq_header);
|
|
|
|
op->length = htons(length);
|
2004-06-27 04:15:34 +08:00
|
|
|
ospf_send_to(n->ifa->ip_sk, n->ip, n->ifa);
|
2000-06-06 10:50:49 +08:00
|
|
|
OSPF_TRACE(D_PACKETS, "LS request sent to: %I", n->rid);
|
2000-03-30 08:18:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-06-05 01:28:41 +08:00
|
|
|
ospf_lsreq_receive(struct ospf_lsreq_packet *ps,
|
2004-06-07 03:53:52 +08:00
|
|
|
struct ospf_iface *ifa, struct ospf_neighbor *n)
|
2000-03-30 08:18:59 +08:00
|
|
|
{
|
|
|
|
struct ospf_lsreq_header *lsh;
|
2000-03-31 08:21:41 +08:00
|
|
|
struct l_lsr_head *llsh;
|
|
|
|
list uplist;
|
|
|
|
slab *upslab;
|
2004-06-07 03:53:52 +08:00
|
|
|
unsigned int size = ntohs(ps->ospf_packet.length);
|
|
|
|
int i, lsano;
|
2004-07-16 00:37:52 +08:00
|
|
|
struct ospf_area *oa = ifa->oa;
|
|
|
|
struct proto_ospf *po = oa->po;
|
|
|
|
struct proto *p = &po->proto;
|
2000-03-30 08:18:59 +08:00
|
|
|
|
2004-06-05 01:28:41 +08:00
|
|
|
if (n->state < NEIGHBOR_EXCHANGE)
|
|
|
|
return;
|
2000-05-10 02:17:34 +08:00
|
|
|
|
2000-06-06 10:50:49 +08:00
|
|
|
OSPF_TRACE(D_EVENTS, "Received LS req from neighbor: %I", n->ip);
|
2000-06-06 03:45:06 +08:00
|
|
|
ospf_neigh_sm(n, INM_HELLOREC);
|
2000-03-30 08:18:59 +08:00
|
|
|
|
2004-06-05 01:28:41 +08:00
|
|
|
lsh = (void *) (ps + 1);
|
2000-03-31 08:21:41 +08:00
|
|
|
init_list(&uplist);
|
2004-06-05 01:28:41 +08:00
|
|
|
upslab = sl_new(n->pool, sizeof(struct l_lsr_head));
|
2000-03-31 08:21:41 +08:00
|
|
|
|
2004-06-07 03:53:52 +08:00
|
|
|
lsano = (size - sizeof(struct ospf_lsreq_packet)) /
|
2000-06-02 17:42:24 +08:00
|
|
|
sizeof(struct ospf_lsreq_header);
|
2004-06-05 01:28:41 +08:00
|
|
|
for (i = 0; i < lsano; lsh++, i++)
|
2000-03-30 08:18:59 +08:00
|
|
|
{
|
2008-08-25 20:00:55 +08:00
|
|
|
u32 hid = ntohl(lsh->id);
|
|
|
|
u32 hrt = ntohl(lsh->rt);
|
2009-01-11 19:14:27 +08:00
|
|
|
DBG("Processing requested LSA: Type: %u, ID: %I, RT: %I\n", lsh->type, hid, hrt);
|
2004-06-05 01:28:41 +08:00
|
|
|
llsh = sl_alloc(upslab);
|
2008-08-25 20:00:55 +08:00
|
|
|
llsh->lsh.id = hid;
|
|
|
|
llsh->lsh.rt = hrt;
|
2004-06-05 01:28:41 +08:00
|
|
|
llsh->lsh.type = lsh->type;
|
2000-03-31 08:21:41 +08:00
|
|
|
add_tail(&uplist, NODE llsh);
|
2004-07-16 00:37:52 +08:00
|
|
|
if (ospf_hash_find(po->gr, oa->areaid, llsh->lsh.id, llsh->lsh.rt,
|
2004-06-05 01:28:41 +08:00
|
|
|
llsh->lsh.type) == NULL)
|
2000-03-31 04:00:42 +08:00
|
|
|
{
|
2004-06-06 17:37:54 +08:00
|
|
|
log(L_WARN
|
2009-01-11 19:14:27 +08:00
|
|
|
"Received bad LS req from: %I looking: Type: %u, ID: %I, RT: %I",
|
|
|
|
n->ip, lsh->type, hid, hrt);
|
2004-06-05 01:28:41 +08:00
|
|
|
ospf_neigh_sm(n, INM_BADLSREQ);
|
2000-03-31 08:21:41 +08:00
|
|
|
rfree(upslab);
|
2000-03-31 04:00:42 +08:00
|
|
|
return;
|
|
|
|
}
|
2000-03-30 08:18:59 +08:00
|
|
|
}
|
2004-06-05 05:05:43 +08:00
|
|
|
ospf_lsupd_send_list(n, &uplist);
|
2000-03-31 08:21:41 +08:00
|
|
|
rfree(upslab);
|
2000-03-30 08:18:59 +08:00
|
|
|
}
|