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"
|
|
|
|
|
2009-08-21 07:27:52 +00:00
|
|
|
|
2012-08-05 20:32:06 +00:00
|
|
|
/*
|
2009-08-21 07:27:52 +00:00
|
|
|
struct ospf_lsack_packet
|
|
|
|
{
|
2012-08-05 20:32:06 +00:00
|
|
|
struct ospf_packet hdr;
|
|
|
|
// union ospf_auth auth;
|
2009-08-21 07:27:52 +00:00
|
|
|
|
2012-08-05 20:32:06 +00:00
|
|
|
struct ospf_lsa_header lsas[];
|
|
|
|
};
|
|
|
|
*/
|
2000-04-18 01:06:16 +00:00
|
|
|
|
2009-04-06 14:17:47 +00:00
|
|
|
|
2012-08-05 20:32:06 +00:00
|
|
|
static void
|
|
|
|
ospf_lsack_body(struct proto_ospf *po, struct ospf_packet *pkt, unsigned plen,
|
|
|
|
struct ospf_lsa_header **body, unsigned *count)
|
2009-04-06 14:17:47 +00:00
|
|
|
{
|
2012-08-05 20:32:06 +00:00
|
|
|
unsigned hdrlen = ospf_pkt_hdrlen(po);
|
|
|
|
*body = ((void *) pkt) + hdrlen;
|
|
|
|
*count = (plen - hdrlen) / sizeof(struct ospf_lsa_header);
|
|
|
|
}
|
2009-04-06 14:17:47 +00:00
|
|
|
|
2012-08-05 20:32:06 +00:00
|
|
|
static void
|
|
|
|
ospf_lsack_dump(struct proto_ospf *po, struct ospf_packet *pkt)
|
|
|
|
{
|
|
|
|
struct ospf_lsa_header *lsas;
|
|
|
|
unsigned i, lsa_count;
|
2009-04-06 14:17:47 +00:00
|
|
|
|
2012-08-05 20:32:06 +00:00
|
|
|
ASSERT(pkt->type == LSACK_P);
|
|
|
|
ospf_dump_common(po, pkt);
|
2009-04-06 14:17:47 +00:00
|
|
|
|
2012-08-05 20:32:06 +00:00
|
|
|
ospf_lsack_body(po, pkt, ntohs(pkt->length), &lsas, &lsa_count);
|
|
|
|
for (i = 0; i < lsa_count; i++)
|
|
|
|
ospf_dump_lsahdr(po, lsas + i);
|
2009-04-06 14:17:47 +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
|
2012-08-05 20:32:06 +00:00
|
|
|
ospf_lsack_enqueue(struct ospf_neighbor *n, struct ospf_lsa_header *h, 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);
|
2012-08-05 20:32:06 +00:00
|
|
|
DBG("Adding (%s) ack for %R, ID: %R, RT: %R, Type: %u\n",
|
|
|
|
(queue == ACKL_DIRECT) ? "direct" : "delayed",
|
2009-07-23 14:51:28 +00:00
|
|
|
n->rid, ntohl(h->id), ntohl(h->rt), h->type);
|
2000-04-18 01:06:16 +00:00
|
|
|
}
|
|
|
|
|
2012-08-05 20:32:06 +00:00
|
|
|
static inline void
|
|
|
|
ospf_lsack_send_one(struct ospf_neighbor *n, int queue)
|
2000-04-18 01:06:16 +00:00
|
|
|
{
|
2004-06-04 16:55:53 +00:00
|
|
|
struct ospf_iface *ifa = n->ifa;
|
2012-08-05 20:32:06 +00:00
|
|
|
struct proto_ospf *po = ifa->oa->po;
|
|
|
|
struct ospf_lsa_header *lsas;
|
|
|
|
struct ospf_packet *pkt;
|
|
|
|
struct lsah_n *no;
|
|
|
|
unsigned i, lsa_max, length;
|
2004-06-04 16:30:04 +00:00
|
|
|
|
2000-04-18 01:06:16 +00:00
|
|
|
|
2012-08-05 20:32:06 +00:00
|
|
|
pkt = ospf_tx_buffer(ifa);
|
|
|
|
ospf_pkt_fill_hdr(ifa, pkt, LSACK_P);
|
|
|
|
ospf_lsack_body(po, pkt, ospf_pkt_maxsize(ifa), &lsas, &lsa_max);
|
2000-04-18 01:06:16 +00:00
|
|
|
|
2012-08-05 20:32:06 +00:00
|
|
|
for (i = 0; i < lsa_max && !EMPTY_LIST(n->ackl[queue]); i++)
|
2000-04-18 01:06:16 +00:00
|
|
|
{
|
2004-06-04 16:55:53 +00:00
|
|
|
no = (struct lsah_n *) HEAD(n->ackl[queue]);
|
2012-08-05 20:32:06 +00:00
|
|
|
memcpy(&lsas[i], &no->lsa, sizeof(struct ospf_lsa_header));
|
|
|
|
DBG("Iter %u ID: %R, RT: %R, Type: %04x\n",
|
|
|
|
i, ntohl(lsas[i].id), ntohl(lsas[i].rt), lsas[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);
|
2000-04-18 01:06:16 +00:00
|
|
|
}
|
|
|
|
|
2012-08-05 20:32:06 +00:00
|
|
|
length = ospf_pkt_hdrlen(po) + i * sizeof(struct ospf_lsa_header);
|
|
|
|
pkt->length = htons(length);
|
2009-04-06 14:17:47 +00:00
|
|
|
|
2012-08-05 20:32:06 +00:00
|
|
|
OSPF_PACKET(ospf_lsack_dump, pkt, "LSACK packet sent via %s", ifa->iface->name);
|
2009-04-06 14:17:47 +00:00
|
|
|
|
2012-08-05 20:32:06 +00:00
|
|
|
/* XXXX this is very strange */
|
2004-06-04 16:55:53 +00:00
|
|
|
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))
|
2012-05-14 09:47:41 +00:00
|
|
|
ospf_send_to_all(ifa);
|
2000-04-18 01:06:16 +00:00
|
|
|
else
|
2012-10-02 09:44:05 +00:00
|
|
|
ospf_send_to_des(ifa);
|
2000-04-18 01:06:16 +00:00
|
|
|
}
|
|
|
|
else
|
2009-09-04 09:06:51 +00:00
|
|
|
ospf_send_to_agt(ifa, NEIGHBOR_EXCHANGE);
|
2012-08-05 20:32:06 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
if ((ifa->state == OSPF_IS_DR) || (ifa->state == OSPF_IS_BACKUP))
|
|
|
|
ospf_send_to_agt(ifa, NEIGHBOR_EXCHANGE);
|
|
|
|
else
|
|
|
|
ospf_send_to_bdr(ifa);
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ospf_lsack_send(struct ospf_neighbor *n, int queue)
|
|
|
|
{
|
|
|
|
while (!EMPTY_LIST(n->ackl[queue]))
|
|
|
|
ospf_lsack_send_one(n, queue);
|
2000-03-30 20:00:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-05 20:32:06 +00:00
|
|
|
ospf_lsack_receive(struct ospf_packet *pkt, struct ospf_iface *ifa,
|
2009-08-21 07:27:52 +00:00
|
|
|
struct ospf_neighbor *n)
|
2000-03-30 20:00:42 +00:00
|
|
|
{
|
2012-08-05 20:32:06 +00:00
|
|
|
struct proto_ospf *po = ifa->oa->po;
|
|
|
|
struct ospf_lsa_header lsa, *lsas;
|
2000-04-12 15:20:13 +00:00
|
|
|
struct top_hash_entry *en;
|
2012-08-05 20:32:06 +00:00
|
|
|
unsigned i, lsa_count;
|
2012-10-02 09:44:05 +00:00
|
|
|
u32 lsa_dom, lsa_type;
|
2009-10-29 22:57:42 +00:00
|
|
|
|
2000-04-12 15:37:52 +00:00
|
|
|
|
2012-08-05 20:32:06 +00:00
|
|
|
/* No need to check length, lsack has only basic header */
|
2009-04-06 14:17:47 +00:00
|
|
|
|
2012-08-05 20:32:06 +00:00
|
|
|
OSPF_PACKET(ospf_lsack_dump, pkt, "LSACK packet received from %I via %s",
|
|
|
|
n->ip, ifa->iface->name);
|
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
|
|
|
|
2012-08-05 20:32:06 +00:00
|
|
|
ospf_neigh_sm(n, INM_HELLOREC); /* Not in RFC */
|
|
|
|
|
|
|
|
ospf_lsack_body(po, pkt, ntohs(pkt->length), &lsas, &lsa_count);
|
|
|
|
for (i = 0; i < lsa_count; i++)
|
2000-04-12 15:20:13 +00:00
|
|
|
{
|
2012-10-02 09:44:05 +00:00
|
|
|
lsa_ntoh_hdr(&lsas[i], &lsa);
|
|
|
|
lsa_xxxxtype(lsa.type_raw, n->ifa, &lsa_type, &lsa_dom);
|
|
|
|
|
|
|
|
en = ospf_hash_find(n->lsrth, lsa_dom, lsa.id, lsa.rt, lsa_type);
|
|
|
|
if (!en)
|
2004-06-06 09:37:54 +00:00
|
|
|
continue; /* pg 155 */
|
2000-04-12 15:20:13 +00:00
|
|
|
|
2004-06-04 20:41:02 +00:00
|
|
|
if (lsa_comp(&lsa, &en->lsa) != CMP_SAME) /* pg 156 */
|
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
|
|
|
|
2009-12-14 16:29:33 +00:00
|
|
|
OSPF_TRACE(D_PACKETS, "Strange LSACK from %I", n->ip);
|
|
|
|
OSPF_TRACE(D_PACKETS, "Type: %04x, Id: %R, Rt: %R",
|
2012-10-02 09:44:05 +00:00
|
|
|
lsa_type, lsa.id, lsa.rt);
|
2009-12-14 16:29:33 +00:00
|
|
|
OSPF_TRACE(D_PACKETS, "I have: Age: %4u, Seq: %08x, Sum: %04x",
|
2004-06-04 16:55:53 +00:00
|
|
|
en->lsa.age, en->lsa.sn, en->lsa.checksum);
|
2009-12-14 16:29:33 +00:00
|
|
|
OSPF_TRACE(D_PACKETS, "He has: Age: %4u, Seq: %08x, Sum: %04x",
|
2004-06-04 16:55:53 +00:00
|
|
|
lsa.age, lsa.sn, lsa.checksum);
|
2000-04-12 15:20:13 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-10-02 09:44:05 +00:00
|
|
|
DBG("Deleting LSA (Type: %04x Id: %R Rt: %R) from lsrtl for neighbor %R\n",
|
|
|
|
lsa_type, lsa.id, lsa.rt, n->rid);
|
2000-04-12 15:20:13 +00:00
|
|
|
s_rem_node(SNODE en);
|
2004-06-04 16:55:53 +00:00
|
|
|
ospf_hash_delete(n->lsrth, en);
|
|
|
|
}
|
2000-03-30 20:00:42 +00:00
|
|
|
}
|