0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2024-12-22 17:51:53 +00:00
bird/proto/ospf/lsreq.c

137 lines
3.5 KiB
C
Raw Normal View History

2000-03-30 00:18:59 +00:00
/*
* BIRD -- OSPF
*
* (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"
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);
struct ospf_lsreq_header *plsr = (void *) (pkt + 1);
int i, j;
j = (ntohs(op->length) - sizeof(struct ospf_dbdes_packet)) /
sizeof(struct ospf_lsreq_header);
for (i = 0; i < j; i++)
2009-07-23 14:51:28 +00:00
log(L_TRACE "%s: LSR Id: %R, Rt: %R, Type: %u",
p->name, htonl(plsr[i].id), htonl(plsr[i].rt), plsr[i].type);
}
2000-03-30 00:18:59 +00:00
void
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;
int i, j;
struct proto *p = &n->ifa->oa->po->proto;
2000-03-30 00:18:59 +00:00
pk = (struct ospf_lsreq_packet *) n->ifa->ip_sk->tbuf;
op = (struct ospf_packet *) n->ifa->ip_sk->tbuf;
2000-03-30 00:18:59 +00:00
ospf_pkt_fill_hdr(n->ifa, pk, LSREQ_P);
2000-03-30 00:18:59 +00:00
sn = SHEAD(n->lsrql);
if (EMPTY_SLIST(n->lsrql))
2000-03-30 19:21:17 +00:00
{
if (n->state == NEIGHBOR_LOADING)
ospf_neigh_sm(n, INM_LOADDONE);
2000-03-30 19:21:17 +00:00
return;
}
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);
lsh = (struct ospf_lsreq_header *) (pk + 1);
for (; i > 0; i--)
2000-03-30 00:18:59 +00: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-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);
lsh++;
if (sn == STAIL(n->lsrql))
break;
sn = sn->next;
2000-03-30 00:18:59 +00:00
}
if (i != 0)
i--;
2000-03-30 00:18:59 +00:00
length =
sizeof(struct ospf_lsreq_packet) + (j -
i) * sizeof(struct ospf_lsreq_header);
op->length = htons(length);
OSPF_PACKET(ospf_dump_lsreq, (struct ospf_lsreq_packet *) n->ifa->ip_sk->tbuf,
"LSREQ packet sent to %I via %s", n->ip, n->ifa->iface->name);
ospf_send_to(n->ifa->ip_sk, n->ip, n->ifa);
2000-03-30 00:18:59 +00:00
}
void
ospf_lsreq_receive(struct ospf_lsreq_packet *ps,
struct ospf_iface *ifa, struct ospf_neighbor *n)
2000-03-30 00:18:59 +00:00
{
struct ospf_lsreq_header *lsh;
struct l_lsr_head *llsh;
list uplist;
slab *upslab;
unsigned int size = ntohs(ps->ospf_packet.length);
int i, lsano;
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
OSPF_PACKET(ospf_dump_lsreq, ps, "LSREQ packet received from %I via %s", n->ip, ifa->iface->name);
if (n->state < NEIGHBOR_EXCHANGE)
return;
ospf_neigh_sm(n, INM_HELLOREC);
2000-03-30 00:18:59 +00:00
lsh = (void *) (ps + 1);
init_list(&uplist);
upslab = sl_new(n->pool, sizeof(struct l_lsr_head));
lsano = (size - sizeof(struct ospf_lsreq_packet)) /
2000-06-02 09:42:24 +00:00
sizeof(struct ospf_lsreq_header);
for (i = 0; i < lsano; lsh++, i++)
2000-03-30 00:18:59 +00:00
{
u32 hid = ntohl(lsh->id);
u32 hrt = ntohl(lsh->rt);
2009-07-23 14:51:28 +00:00
DBG("Processing requested LSA: Type: %u, ID: %R, RT: %R\n", lsh->type, hid, hrt);
llsh = sl_alloc(upslab);
llsh->lsh.id = hid;
llsh->lsh.rt = hrt;
llsh->lsh.type = lsh->type;
add_tail(&uplist, NODE llsh);
if (ospf_hash_find(po->gr, oa->areaid, llsh->lsh.id, llsh->lsh.rt,
llsh->lsh.type) == NULL)
2000-03-30 20:00:42 +00:00
{
2004-06-06 09:37:54 +00:00
log(L_WARN
2009-07-23 14:51:28 +00:00
"Received bad LS req from: %I looking: Type: %u, ID: %R, RT: %R",
n->ip, lsh->type, hid, hrt);
ospf_neigh_sm(n, INM_BADLSREQ);
rfree(upslab);
2000-03-30 20:00:42 +00:00
return;
}
2000-03-30 00:18:59 +00:00
}
ospf_lsupd_send_list(n, &uplist);
rfree(upslab);
2000-03-30 00:18:59 +00:00
}