2000-03-30 20:00:42 +00:00
|
|
|
/*
|
|
|
|
* BIRD -- OSPF
|
|
|
|
*
|
2004-06-04 16:30:04 +00:00
|
|
|
* (c) 2000-2004 Ondrej Filip <feela@network.cz>
|
2000-03-30 20:00:42 +00:00
|
|
|
*
|
|
|
|
* Can be freely distributed and used under the terms of the GNU GPL.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ospf.h"
|
|
|
|
|
2004-06-04 16:55:53 +00:00
|
|
|
char *s_queue[] = { "direct", "delayed" };
|
2000-04-18 01:06:16 +00:00
|
|
|
|
2004-06-04 16:30:04 +00:00
|
|
|
/*
|
|
|
|
* =====================================
|
|
|
|
* Note, that h is in network endianity!
|
|
|
|
* =====================================
|
|
|
|
*/
|
2004-06-04 16:55:53 +00:00
|
|
|
|
2000-04-18 01:06:16 +00:00
|
|
|
void
|
2004-06-04 16:55:53 +00:00
|
|
|
ospf_lsack_enqueue(struct ospf_neighbor *n, struct ospf_lsa_header *h,
|
2004-06-04 17:05:24 +00:00
|
|
|
int queue)
|
2000-04-18 01:06:16 +00:00
|
|
|
{
|
2004-06-04 17:05:24 +00:00
|
|
|
struct lsah_n *no = mb_alloc(n->pool, sizeof(struct lsah_n));
|
2004-06-04 16:55:53 +00:00
|
|
|
memcpy(&no->lsa, h, sizeof(struct ospf_lsa_header));
|
2004-06-04 16:30:04 +00:00
|
|
|
add_tail(&n->ackl[queue], NODE no);
|
2004-06-04 16:55:53 +00:00
|
|
|
DBG("Adding (%s) ack for %I, ID: %I, RT: %I, Type: %u\n", s_queue[queue],
|
|
|
|
n->rid, ntohl(h->id), ntohl(h->rt), h->type);
|
2000-04-18 01:06:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-06-04 16:30:04 +00:00
|
|
|
ospf_lsack_send(struct ospf_neighbor *n, int queue)
|
2000-04-18 01:06:16 +00:00
|
|
|
{
|
|
|
|
struct ospf_packet *op;
|
|
|
|
struct ospf_lsack_packet *pk;
|
|
|
|
sock *sk;
|
2004-06-04 16:55:53 +00:00
|
|
|
u16 len, i = 0;
|
2000-04-18 01:06:16 +00:00
|
|
|
struct ospf_lsa_header *h;
|
|
|
|
struct lsah_n *no;
|
2004-06-04 16:55:53 +00:00
|
|
|
struct ospf_iface *ifa = n->ifa;
|
|
|
|
struct proto *p = &n->ifa->proto->proto;
|
2000-04-18 01:06:16 +00:00
|
|
|
|
2004-06-04 16:55:53 +00:00
|
|
|
if (EMPTY_LIST(n->ackl[queue]))
|
|
|
|
return;
|
2004-06-04 16:30:04 +00:00
|
|
|
|
|
|
|
OSPF_TRACE(D_PACKETS, "LS ack sent to %I (%s)", n->ip, s_queue[queue]);
|
2000-04-18 17:00:56 +00:00
|
|
|
|
2004-06-04 16:55:53 +00:00
|
|
|
if (ifa->type == OSPF_IT_BCAST)
|
|
|
|
sk = ifa->hello_sk;
|
2000-04-18 01:06:16 +00:00
|
|
|
else
|
2004-06-04 16:55:53 +00:00
|
|
|
sk = ifa->ip_sk;
|
2000-04-18 01:06:16 +00:00
|
|
|
|
2004-06-04 16:55:53 +00:00
|
|
|
pk = (struct ospf_lsack_packet *) sk->tbuf;
|
|
|
|
op = (struct ospf_packet *) sk->tbuf;
|
2000-04-18 01:06:16 +00:00
|
|
|
|
2000-06-03 01:29:00 +00:00
|
|
|
fill_ospf_pkt_hdr(n->ifa, pk, LSACK_P);
|
2004-06-04 16:55:53 +00:00
|
|
|
h = (struct ospf_lsa_header *) (pk + 1);
|
2000-04-18 01:06:16 +00:00
|
|
|
|
2004-06-04 16:55:53 +00:00
|
|
|
while (!EMPTY_LIST(n->ackl[queue]))
|
2000-04-18 01:06:16 +00:00
|
|
|
{
|
2004-06-04 16:55:53 +00:00
|
|
|
no = (struct lsah_n *) HEAD(n->ackl[queue]);
|
|
|
|
memcpy(h + i, &no->lsa, sizeof(struct ospf_lsa_header));
|
2000-04-18 01:06:16 +00:00
|
|
|
i++;
|
2004-06-04 16:55:53 +00:00
|
|
|
DBG("Iter %u ID: %I, RT: %I, Type: %u\n", i, ntohl((h + i)->id),
|
|
|
|
ntohl((h + i)->rt), (h + i)->type);
|
2000-04-18 17:00:56 +00:00
|
|
|
rem_node(NODE no);
|
2000-04-18 17:36:46 +00:00
|
|
|
mb_free(no);
|
2004-06-04 16:55:53 +00:00
|
|
|
if ((i * sizeof(struct ospf_lsa_header) +
|
|
|
|
sizeof(struct ospf_lsack_packet) + SIPH) > n->ifa->iface->mtu)
|
2000-04-18 01:06:16 +00:00
|
|
|
{
|
2004-06-04 16:55:53 +00:00
|
|
|
if (!EMPTY_LIST(n->ackl[queue]))
|
2000-04-18 01:06:16 +00:00
|
|
|
{
|
2004-06-04 16:55:53 +00:00
|
|
|
len =
|
|
|
|
sizeof(struct ospf_lsack_packet) +
|
|
|
|
i * sizeof(struct ospf_lsa_header);
|
|
|
|
op->length = htons(len);
|
2000-04-18 01:06:16 +00:00
|
|
|
ospf_pkt_finalize(n->ifa, op);
|
2004-06-04 16:55:53 +00:00
|
|
|
DBG("Sending and continuing! Len=%u\n", len);
|
|
|
|
if (ifa->type == OSPF_IT_BCAST)
|
2000-04-18 01:06:16 +00:00
|
|
|
{
|
2004-06-04 16:55:53 +00:00
|
|
|
if ((ifa->state == OSPF_IS_DR) || (ifa->state == OSPF_IS_BACKUP))
|
|
|
|
sk_send_to(sk, len, AllSPFRouters, OSPF_PROTO);
|
2000-04-18 01:06:16 +00:00
|
|
|
else
|
2004-06-04 16:55:53 +00:00
|
|
|
sk_send_to(sk, len, AllDRouters, OSPF_PROTO);
|
2000-04-18 01:06:16 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-06-04 16:55:53 +00:00
|
|
|
if ((ifa->state == OSPF_IS_DR) || (ifa->state == OSPF_IS_BACKUP))
|
|
|
|
sk_send_to_agt(sk, len, ifa, NEIGHBOR_EXCHANGE);
|
2000-06-06 00:08:27 +00:00
|
|
|
else
|
2004-06-04 16:55:53 +00:00
|
|
|
sk_send_to_bdr(sk, len, ifa);
|
2000-04-18 01:06:16 +00:00
|
|
|
}
|
2000-04-18 17:36:46 +00:00
|
|
|
|
2000-06-03 01:29:00 +00:00
|
|
|
fill_ospf_pkt_hdr(n->ifa, pk, LSACK_P);
|
2004-06-04 16:55:53 +00:00
|
|
|
i = 0;
|
2000-04-18 01:06:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-06-04 16:55:53 +00:00
|
|
|
len = sizeof(struct ospf_lsack_packet) + i * sizeof(struct ospf_lsa_header);
|
|
|
|
op->length = htons(len);
|
2000-04-18 01:06:16 +00:00
|
|
|
ospf_pkt_finalize(n->ifa, op);
|
2004-06-04 16:55:53 +00:00
|
|
|
DBG("Sending! Len=%u\n", len);
|
|
|
|
if (ifa->type == OSPF_IT_BCAST)
|
2000-04-18 01:06:16 +00:00
|
|
|
{
|
2004-06-04 16:55:53 +00:00
|
|
|
if ((ifa->state == OSPF_IS_DR) || (ifa->state == OSPF_IS_BACKUP))
|
2000-04-18 01:06:16 +00:00
|
|
|
{
|
2004-06-04 16:30:04 +00:00
|
|
|
sk_send_to(sk, len, AllSPFRouters, OSPF_PROTO);
|
2000-04-18 01:06:16 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-06-04 16:30:04 +00:00
|
|
|
sk_send_to(sk, len, AllDRouters, OSPF_PROTO);
|
2000-04-18 01:06:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sk_send_to_agt(sk, len, ifa, NEIGHBOR_EXCHANGE);
|
|
|
|
}
|
2000-03-30 20:00:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-06-04 17:05:24 +00:00
|
|
|
ospf_lsack_receive(struct ospf_lsack_packet *ps,
|
2004-06-04 16:55:53 +00:00
|
|
|
struct ospf_iface *ifa, u16 size)
|
2000-03-30 20:00:42 +00:00
|
|
|
{
|
|
|
|
u32 nrid, myrid;
|
|
|
|
struct ospf_neighbor *n;
|
2004-06-04 16:55:53 +00:00
|
|
|
struct ospf_lsa_header lsa, *plsa;
|
2000-03-30 20:00:42 +00:00
|
|
|
int length;
|
2004-06-04 16:55:53 +00:00
|
|
|
u16 nolsa, i;
|
2000-04-12 15:20:13 +00:00
|
|
|
struct top_hash_entry *en;
|
2004-06-04 16:55:53 +00:00
|
|
|
u16 lenn = ntohs(ps->ospf_packet.length);
|
2004-06-04 17:05:24 +00:00
|
|
|
struct proto *p = (struct proto *) ifa->proto;
|
2000-03-30 20:00:42 +00:00
|
|
|
|
2004-06-04 16:55:53 +00:00
|
|
|
nrid = ntohl(ps->ospf_packet.routerid);
|
2000-03-30 20:00:42 +00:00
|
|
|
|
2004-06-04 16:55:53 +00:00
|
|
|
myrid = p->cf->global->router_id;
|
2000-03-30 20:00:42 +00:00
|
|
|
|
2004-06-04 16:55:53 +00:00
|
|
|
if ((n = find_neigh(ifa, nrid)) == NULL)
|
2000-03-30 20:00:42 +00:00
|
|
|
{
|
2004-06-04 16:55:53 +00:00
|
|
|
OSPF_TRACE(D_PACKETS, "Received LS ack from unknown neigbor! (%I)", nrid);
|
|
|
|
return;
|
2000-03-30 20:00:42 +00:00
|
|
|
}
|
2000-04-12 15:37:52 +00:00
|
|
|
|
2000-06-06 02:32:14 +00:00
|
|
|
OSPF_TRACE(D_PACKETS, "Received LS ack from %I", n->ip);
|
2000-06-05 19:45:06 +00:00
|
|
|
ospf_neigh_sm(n, INM_HELLOREC);
|
2000-05-09 18:17:34 +00:00
|
|
|
|
2004-06-04 16:55:53 +00:00
|
|
|
if (n->state < NEIGHBOR_EXCHANGE)
|
|
|
|
return;
|
2000-05-09 18:17:34 +00:00
|
|
|
|
2004-06-04 16:55:53 +00:00
|
|
|
nolsa = (lenn - sizeof(struct ospf_lsack_packet)) /
|
2000-04-12 15:20:13 +00:00
|
|
|
sizeof(struct ospf_lsa_header);
|
2000-05-11 22:00:16 +00:00
|
|
|
|
2004-06-04 16:55:53 +00:00
|
|
|
if ((nolsa < 1) || ((lenn - sizeof(struct ospf_lsack_packet)) !=
|
|
|
|
(nolsa * sizeof(struct ospf_lsa_header))))
|
2000-05-11 22:00:16 +00:00
|
|
|
{
|
2004-06-04 16:56:54 +00:00
|
|
|
log(L_ERR "Received corrupted LS ack from %I", n->ip);
|
2000-05-11 22:00:16 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-06-04 16:55:53 +00:00
|
|
|
plsa = (struct ospf_lsa_header *) (ps + 1);
|
2000-04-12 15:20:13 +00:00
|
|
|
|
2004-06-04 16:55:53 +00:00
|
|
|
for (i = 0; i < nolsa; i++)
|
2000-04-12 15:20:13 +00:00
|
|
|
{
|
2004-06-04 16:55:53 +00:00
|
|
|
ntohlsah(plsa + i, &lsa);
|
|
|
|
if ((en = ospf_hash_find_header(n->lsrth, &lsa)) == NULL)
|
|
|
|
continue;
|
2000-04-12 15:20:13 +00:00
|
|
|
|
2004-06-04 16:55:53 +00:00
|
|
|
if (lsa_comp(&lsa, &en->lsa) != CMP_SAME)
|
2000-04-12 15:20:13 +00:00
|
|
|
{
|
2004-06-04 16:55:53 +00:00
|
|
|
if ((lsa.sn == LSA_MAXSEQNO) && (lsa.age == LSA_MAXAGE))
|
|
|
|
continue;
|
2000-05-31 18:21:42 +00:00
|
|
|
|
2004-06-04 16:55:53 +00:00
|
|
|
OSPF_TRACE(D_PACKETS, "Strange LS acknoledgement from %I", n->ip);
|
2000-06-06 02:32:14 +00:00
|
|
|
OSPF_TRACE(D_PACKETS, "Id: %I, Rt: %I, Type: %u",
|
2004-06-04 16:55:53 +00:00
|
|
|
lsa.id, lsa.rt, lsa.type);
|
2000-06-06 02:32:14 +00:00
|
|
|
OSPF_TRACE(D_PACKETS, "I have: Age: %4u, Seqno: 0x%08x, Sum: %u",
|
2004-06-04 16:55:53 +00:00
|
|
|
en->lsa.age, en->lsa.sn, en->lsa.checksum);
|
2000-06-06 02:32:14 +00:00
|
|
|
OSPF_TRACE(D_PACKETS, "He has: Age: %4u, Seqno: 0x%08x, Sum: %u",
|
2004-06-04 16:55:53 +00:00
|
|
|
lsa.age, lsa.sn, lsa.checksum);
|
2000-04-12 15:20:13 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2000-04-12 15:37:52 +00:00
|
|
|
DBG("Deleting LS Id: %I RT: %I Type: %u from LS Retl for neighbor %I\n",
|
2004-06-04 16:55:53 +00:00
|
|
|
lsa.id, lsa.rt, lsa.type, n->rid);
|
2000-04-12 15:20:13 +00:00
|
|
|
s_rem_node(SNODE en);
|
2004-06-04 16:55:53 +00:00
|
|
|
if (en->lsa_body != NULL)
|
|
|
|
mb_free(en->lsa_body);
|
|
|
|
en->lsa_body = NULL;
|
|
|
|
ospf_hash_delete(n->lsrth, en);
|
|
|
|
}
|
2000-03-30 20:00:42 +00:00
|
|
|
}
|