2000-03-31 04:00:42 +08:00
|
|
|
/*
|
|
|
|
* BIRD -- OSPF
|
|
|
|
*
|
2004-06-05 00:30:04 +08:00
|
|
|
* (c) 2000-2004 Ondrej Filip <feela@network.cz>
|
2000-03-31 04:00:42 +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
|
|
|
|
|
|
|
struct ospf_lsack_packet
|
|
|
|
{
|
|
|
|
struct ospf_packet ospf_packet;
|
|
|
|
struct ospf_lsa_header lsh[];
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2004-06-05 00:55:53 +08:00
|
|
|
char *s_queue[] = { "direct", "delayed" };
|
2000-04-18 09:06:16 +08:00
|
|
|
|
2009-04-06 22:17:47 +08:00
|
|
|
|
|
|
|
static void ospf_dump_lsack(struct proto *p, struct ospf_lsack_packet *pkt)
|
|
|
|
{
|
|
|
|
struct ospf_packet *op = &pkt->ospf_packet;
|
|
|
|
|
|
|
|
ASSERT(op->type == LSACK_P);
|
|
|
|
ospf_dump_common(p, op);
|
|
|
|
|
2009-10-30 06:57:42 +08:00
|
|
|
unsigned int i, j;
|
2009-04-06 22:17:47 +08:00
|
|
|
j = (ntohs(op->length) - sizeof(struct ospf_lsack_packet)) /
|
|
|
|
sizeof(struct ospf_lsa_header);
|
|
|
|
|
|
|
|
for (i = 0; i < j; i++)
|
2009-08-21 15:27:52 +08:00
|
|
|
ospf_dump_lsahdr(p, pkt->lsh + i);
|
2009-04-06 22:17:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-06-05 00:30:04 +08:00
|
|
|
/*
|
|
|
|
* =====================================
|
|
|
|
* Note, that h is in network endianity!
|
|
|
|
* =====================================
|
|
|
|
*/
|
2004-06-05 00:55:53 +08:00
|
|
|
|
2000-04-18 09:06:16 +08:00
|
|
|
void
|
2004-06-05 00:55:53 +08:00
|
|
|
ospf_lsack_enqueue(struct ospf_neighbor *n, struct ospf_lsa_header *h,
|
2004-06-05 01:05:24 +08:00
|
|
|
int queue)
|
2000-04-18 09:06:16 +08:00
|
|
|
{
|
2004-06-05 01:05:24 +08:00
|
|
|
struct lsah_n *no = mb_alloc(n->pool, sizeof(struct lsah_n));
|
2004-06-05 00:55:53 +08:00
|
|
|
memcpy(&no->lsa, h, sizeof(struct ospf_lsa_header));
|
2004-06-05 00:30:04 +08:00
|
|
|
add_tail(&n->ackl[queue], NODE no);
|
2009-07-23 22:51:28 +08:00
|
|
|
DBG("Adding (%s) ack for %R, ID: %R, RT: %R, Type: %u\n", s_queue[queue],
|
|
|
|
n->rid, ntohl(h->id), ntohl(h->rt), h->type);
|
2000-04-18 09:06:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-06-05 00:30:04 +08:00
|
|
|
ospf_lsack_send(struct ospf_neighbor *n, int queue)
|
2000-04-18 09:06:16 +08:00
|
|
|
{
|
|
|
|
struct ospf_packet *op;
|
|
|
|
struct ospf_lsack_packet *pk;
|
2004-06-05 00:55:53 +08:00
|
|
|
u16 len, i = 0;
|
2000-04-18 09:06:16 +08:00
|
|
|
struct ospf_lsa_header *h;
|
|
|
|
struct lsah_n *no;
|
2004-06-05 00:55:53 +08:00
|
|
|
struct ospf_iface *ifa = n->ifa;
|
2004-07-16 00:37:52 +08:00
|
|
|
struct proto *p = &n->ifa->oa->po->proto;
|
2000-04-18 09:06:16 +08:00
|
|
|
|
2004-06-05 00:55:53 +08:00
|
|
|
if (EMPTY_LIST(n->ackl[queue]))
|
|
|
|
return;
|
2004-06-05 00:30:04 +08:00
|
|
|
|
2009-09-04 17:06:51 +08:00
|
|
|
pk = (struct ospf_lsack_packet *) ifa->sk->tbuf;
|
|
|
|
op = (struct ospf_packet *) ifa->sk->tbuf;
|
2000-04-18 09:06:16 +08:00
|
|
|
|
2004-06-27 04:15:34 +08:00
|
|
|
ospf_pkt_fill_hdr(n->ifa, pk, LSACK_P);
|
2009-08-21 15:27:52 +08:00
|
|
|
h = pk->lsh;
|
2000-04-18 09:06:16 +08:00
|
|
|
|
2004-06-05 00:55:53 +08:00
|
|
|
while (!EMPTY_LIST(n->ackl[queue]))
|
2000-04-18 09:06:16 +08:00
|
|
|
{
|
2004-06-05 00:55:53 +08:00
|
|
|
no = (struct lsah_n *) HEAD(n->ackl[queue]);
|
|
|
|
memcpy(h + i, &no->lsa, sizeof(struct ospf_lsa_header));
|
2009-12-04 01:25:14 +08:00
|
|
|
DBG("Iter %u ID: %R, RT: %R, Type: %04x\n", i, ntohl((h + i)->id),
|
2009-07-23 22:51:28 +08:00
|
|
|
ntohl((h + i)->rt), (h + i)->type);
|
2009-12-04 01:25:14 +08:00
|
|
|
i++;
|
2000-04-19 01:00:56 +08:00
|
|
|
rem_node(NODE no);
|
2000-04-19 01:36:46 +08:00
|
|
|
mb_free(no);
|
2004-06-05 00:55:53 +08:00
|
|
|
if ((i * sizeof(struct ospf_lsa_header) +
|
2004-06-27 04:15:34 +08:00
|
|
|
sizeof(struct ospf_lsack_packet)) > ospf_pkt_maxsize(n->ifa))
|
2000-04-18 09:06:16 +08:00
|
|
|
{
|
2004-06-05 00:55:53 +08:00
|
|
|
if (!EMPTY_LIST(n->ackl[queue]))
|
2000-04-18 09:06:16 +08:00
|
|
|
{
|
2004-06-05 00:55:53 +08:00
|
|
|
len =
|
|
|
|
sizeof(struct ospf_lsack_packet) +
|
|
|
|
i * sizeof(struct ospf_lsa_header);
|
|
|
|
op->length = htons(len);
|
|
|
|
DBG("Sending and continuing! Len=%u\n", len);
|
2009-04-06 22:17:47 +08:00
|
|
|
|
2009-09-04 17:06:51 +08:00
|
|
|
OSPF_PACKET(ospf_dump_lsack, (struct ospf_lsack_packet *) ifa->sk->tbuf,
|
2009-04-06 22:17:47 +08:00
|
|
|
"LSACK packet sent via %s", ifa->iface->name);
|
|
|
|
|
2004-06-05 00:55:53 +08:00
|
|
|
if (ifa->type == OSPF_IT_BCAST)
|
2000-04-18 09:06:16 +08:00
|
|
|
{
|
2004-06-05 00:55:53 +08:00
|
|
|
if ((ifa->state == OSPF_IS_DR) || (ifa->state == OSPF_IS_BACKUP))
|
2009-09-04 17:06:51 +08:00
|
|
|
ospf_send_to(ifa, AllSPFRouters);
|
2000-04-18 09:06:16 +08:00
|
|
|
else
|
2009-09-04 17:06:51 +08:00
|
|
|
ospf_send_to(ifa, AllDRouters);
|
2000-04-18 09:06:16 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-06-05 00:55:53 +08:00
|
|
|
if ((ifa->state == OSPF_IS_DR) || (ifa->state == OSPF_IS_BACKUP))
|
2009-09-04 17:06:51 +08:00
|
|
|
ospf_send_to_agt(ifa, NEIGHBOR_EXCHANGE);
|
2000-06-06 08:08:27 +08:00
|
|
|
else
|
2009-09-04 17:06:51 +08:00
|
|
|
ospf_send_to_bdr(ifa);
|
2000-04-18 09:06:16 +08:00
|
|
|
}
|
2000-04-19 01:36:46 +08:00
|
|
|
|
2004-06-27 04:15:34 +08:00
|
|
|
ospf_pkt_fill_hdr(n->ifa, pk, LSACK_P);
|
2004-06-05 00:55:53 +08:00
|
|
|
i = 0;
|
2000-04-18 09:06:16 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-06-05 00:55:53 +08:00
|
|
|
len = sizeof(struct ospf_lsack_packet) + i * sizeof(struct ospf_lsa_header);
|
|
|
|
op->length = htons(len);
|
|
|
|
DBG("Sending! Len=%u\n", len);
|
2009-04-06 22:17:47 +08:00
|
|
|
|
2009-09-04 17:06:51 +08:00
|
|
|
OSPF_PACKET(ospf_dump_lsack, (struct ospf_lsack_packet *) ifa->sk->tbuf,
|
2009-04-06 22:17:47 +08:00
|
|
|
"LSACK packet sent via %s", ifa->iface->name);
|
|
|
|
|
2004-06-05 00:55:53 +08:00
|
|
|
if (ifa->type == OSPF_IT_BCAST)
|
2000-04-18 09:06:16 +08:00
|
|
|
{
|
2004-06-05 00:55:53 +08:00
|
|
|
if ((ifa->state == OSPF_IS_DR) || (ifa->state == OSPF_IS_BACKUP))
|
2009-09-04 17:06:51 +08:00
|
|
|
ospf_send_to(ifa, AllSPFRouters);
|
2000-04-18 09:06:16 +08:00
|
|
|
else
|
2009-09-04 17:06:51 +08:00
|
|
|
ospf_send_to(ifa, AllDRouters);
|
2000-04-18 09:06:16 +08:00
|
|
|
}
|
|
|
|
else
|
2009-09-04 17:06:51 +08:00
|
|
|
ospf_send_to_agt(ifa, NEIGHBOR_EXCHANGE);
|
2000-03-31 04:00:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-08-21 15:27:52 +08:00
|
|
|
ospf_lsack_receive(struct ospf_packet *ps_i, struct ospf_iface *ifa,
|
|
|
|
struct ospf_neighbor *n)
|
2000-03-31 04:00:42 +08:00
|
|
|
{
|
2009-10-30 06:57:42 +08:00
|
|
|
struct proto *p = &ifa->oa->po->proto;
|
2009-08-21 15:27:52 +08:00
|
|
|
struct ospf_lsa_header lsa;
|
2000-04-12 23:20:13 +08:00
|
|
|
struct top_hash_entry *en;
|
2009-10-30 06:57:42 +08:00
|
|
|
unsigned int i, lsano;
|
|
|
|
|
|
|
|
unsigned int size = ntohs(ps_i->length);
|
|
|
|
if (size < sizeof(struct ospf_lsack_packet))
|
|
|
|
{
|
|
|
|
log(L_ERR "Bad OSPF LSACK packet from %I - too short (%u B)", n->ip, size);
|
|
|
|
return;
|
|
|
|
}
|
2000-04-12 23:37:52 +08:00
|
|
|
|
2009-10-30 06:57:42 +08:00
|
|
|
struct ospf_lsack_packet *ps = (void *) ps_i;
|
2009-04-06 22:17:47 +08:00
|
|
|
OSPF_PACKET(ospf_dump_lsack, ps, "LSACK packet received from %I via %s", n->ip, ifa->iface->name);
|
|
|
|
|
2000-06-06 03:45:06 +08:00
|
|
|
ospf_neigh_sm(n, INM_HELLOREC);
|
2000-05-10 02:17:34 +08:00
|
|
|
|
2004-06-05 00:55:53 +08:00
|
|
|
if (n->state < NEIGHBOR_EXCHANGE)
|
|
|
|
return;
|
2000-05-10 02:17:34 +08:00
|
|
|
|
2009-10-30 06:57:42 +08:00
|
|
|
lsano = (size - sizeof(struct ospf_lsack_packet)) /
|
2000-04-12 23:20:13 +08:00
|
|
|
sizeof(struct ospf_lsa_header);
|
2009-10-30 06:57:42 +08:00
|
|
|
for (i = 0; i < lsano; i++)
|
2000-04-12 23:20:13 +08:00
|
|
|
{
|
2009-08-21 15:27:52 +08:00
|
|
|
ntohlsah(ps->lsh + i, &lsa);
|
2009-08-25 22:42:14 +08:00
|
|
|
u32 dom = ospf_lsa_domain(lsa.type, n->ifa);
|
|
|
|
if ((en = ospf_hash_find_header(n->lsrth, dom, &lsa)) == NULL)
|
2004-06-06 17:37:54 +08:00
|
|
|
continue; /* pg 155 */
|
2000-04-12 23:20:13 +08:00
|
|
|
|
2004-06-05 04:41:02 +08:00
|
|
|
if (lsa_comp(&lsa, &en->lsa) != CMP_SAME) /* pg 156 */
|
2000-04-12 23:20:13 +08:00
|
|
|
{
|
2004-06-05 00:55:53 +08:00
|
|
|
if ((lsa.sn == LSA_MAXSEQNO) && (lsa.age == LSA_MAXAGE))
|
|
|
|
continue;
|
2000-06-01 02:21:42 +08:00
|
|
|
|
2004-06-05 00:55:53 +08:00
|
|
|
OSPF_TRACE(D_PACKETS, "Strange LS acknoledgement from %I", n->ip);
|
2009-12-04 01:56:39 +08:00
|
|
|
OSPF_TRACE(D_PACKETS, "Id: %R, Rt: %R, Type: 0x%04x",
|
2009-07-23 22:51:28 +08:00
|
|
|
lsa.id, lsa.rt, lsa.type);
|
2009-12-04 01:56:39 +08:00
|
|
|
OSPF_TRACE(D_PACKETS, "I have: Age: %4u, Seqno: 0x%08x, Sum: 0x%04x",
|
2004-06-05 00:55:53 +08:00
|
|
|
en->lsa.age, en->lsa.sn, en->lsa.checksum);
|
2009-12-04 01:56:39 +08:00
|
|
|
OSPF_TRACE(D_PACKETS, "He has: Age: %4u, Seqno: 0x%08x, Sum: 0x%04x",
|
2004-06-05 00:55:53 +08:00
|
|
|
lsa.age, lsa.sn, lsa.checksum);
|
2000-04-12 23:20:13 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2009-07-23 22:51:28 +08:00
|
|
|
DBG("Deleting LS Id: %R RT: %R Type: %u from LS Retl for neighbor %R\n",
|
|
|
|
lsa.id, lsa.rt, lsa.type, n->rid);
|
2000-04-12 23:20:13 +08:00
|
|
|
s_rem_node(SNODE en);
|
2004-06-05 00:55:53 +08:00
|
|
|
if (en->lsa_body != NULL)
|
|
|
|
mb_free(en->lsa_body);
|
|
|
|
en->lsa_body = NULL;
|
|
|
|
ospf_hash_delete(n->lsrth, en);
|
|
|
|
}
|
2000-03-31 04:00:42 +08:00
|
|
|
}
|