2000-03-31 04:00:42 +08:00
|
|
|
/*
|
|
|
|
* BIRD -- OSPF
|
|
|
|
*
|
2014-06-26 17:58:57 +08:00
|
|
|
* (c) 2000--2004 Ondrej Filip <feela@network.cz>
|
|
|
|
* (c) 2009--2014 Ondrej Zajicek <santiago@crfreenet.org>
|
|
|
|
* (c) 2009--2014 CZ.NIC z.s.p.o.
|
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
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
/*
|
2009-08-21 15:27:52 +08:00
|
|
|
struct ospf_lsack_packet
|
|
|
|
{
|
2014-06-26 17:58:57 +08:00
|
|
|
struct ospf_packet hdr;
|
|
|
|
// union ospf_auth auth;
|
2009-08-21 15:27:52 +08:00
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
struct ospf_lsa_header lsas[];
|
|
|
|
};
|
|
|
|
*/
|
2009-08-21 15:27:52 +08:00
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
struct lsa_node
|
|
|
|
{
|
|
|
|
node n;
|
|
|
|
struct ospf_lsa_header lsa;
|
|
|
|
};
|
2000-04-18 09:06:16 +08:00
|
|
|
|
2009-04-06 22:17:47 +08:00
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
static inline void
|
|
|
|
ospf_lsack_body(struct ospf_proto *p, struct ospf_packet *pkt,
|
|
|
|
struct ospf_lsa_header **body, uint *count)
|
2009-04-06 22:17:47 +08:00
|
|
|
{
|
2014-06-26 17:58:57 +08:00
|
|
|
uint plen = ntohs(pkt->length);
|
|
|
|
uint hlen = ospf_pkt_hdrlen(p);
|
2009-04-06 22:17:47 +08:00
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
*body = ((void *) pkt) + hlen;
|
|
|
|
*count = (plen - hlen) / sizeof(struct ospf_lsa_header);
|
|
|
|
}
|
2009-04-06 22:17:47 +08:00
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
static void
|
|
|
|
ospf_dump_lsack(struct ospf_proto *p, struct ospf_packet *pkt)
|
|
|
|
{
|
|
|
|
struct ospf_lsa_header *lsas;
|
|
|
|
uint i, lsa_count;
|
2009-04-06 22:17:47 +08:00
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
ASSERT(pkt->type == LSACK_P);
|
|
|
|
ospf_dump_common(p, pkt);
|
2009-04-06 22:17:47 +08:00
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
ospf_lsack_body(p, pkt, &lsas, &lsa_count);
|
|
|
|
for (i = 0; i < lsa_count; i++)
|
|
|
|
ospf_dump_lsahdr(p, lsas + i);
|
|
|
|
}
|
2009-04-06 22:17:47 +08:00
|
|
|
|
2004-06-05 00:55:53 +08:00
|
|
|
|
2000-04-18 09:06:16 +08:00
|
|
|
void
|
2014-06-26 17:58:57 +08:00
|
|
|
ospf_enqueue_lsack(struct ospf_neighbor *n, struct ospf_lsa_header *h_n, int queue)
|
2000-04-18 09:06:16 +08:00
|
|
|
{
|
2014-06-26 17:58:57 +08:00
|
|
|
/* Note that h_n is in network endianity */
|
|
|
|
struct lsa_node *no = mb_alloc(n->pool, sizeof(struct lsa_node));
|
|
|
|
memcpy(&no->lsa, h_n, sizeof(struct ospf_lsa_header));
|
2004-06-05 00:30:04 +08:00
|
|
|
add_tail(&n->ackl[queue], NODE no);
|
2014-06-26 17:58:57 +08:00
|
|
|
DBG("Adding %s ack for %R, ID: %R, RT: %R, Type: %u\n",
|
|
|
|
(queue == ACKL_DIRECT) ? "direct" : "delayed",
|
|
|
|
n->rid, ntohl(h_n->id), ntohl(h_n->rt), h_n->type);
|
2000-04-18 09:06:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-06-26 17:58:57 +08:00
|
|
|
ospf_reset_lsack_queue(struct ospf_neighbor *n)
|
2000-04-18 09:06:16 +08:00
|
|
|
{
|
2014-06-26 17:58:57 +08:00
|
|
|
struct lsa_node *no;
|
2000-04-18 09:06:16 +08:00
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
WALK_LIST_FIRST(no, n->ackl[ACKL_DELAY])
|
|
|
|
{
|
|
|
|
rem_node(NODE no);
|
|
|
|
mb_free(no);
|
|
|
|
}
|
|
|
|
}
|
2004-06-05 00:30:04 +08:00
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
static inline void
|
|
|
|
ospf_send_lsack(struct ospf_neighbor *n, int queue)
|
|
|
|
{
|
|
|
|
struct ospf_iface *ifa = n->ifa;
|
|
|
|
struct ospf_proto *p = ifa->oa->po;
|
|
|
|
struct ospf_lsa_header *lsas;
|
|
|
|
struct ospf_packet *pkt;
|
|
|
|
struct lsa_node *no;
|
|
|
|
uint i, lsa_max, length;
|
2000-04-18 09:06:16 +08:00
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
/* RFC 2328 13.5 */
|
2000-04-18 09:06:16 +08:00
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
pkt = ospf_tx_buffer(ifa);
|
|
|
|
ospf_pkt_fill_hdr(ifa, pkt, LSACK_P);
|
|
|
|
ospf_lsack_body(p, pkt, &lsas, &lsa_max);
|
|
|
|
|
|
|
|
for (i = 0; i < lsa_max && !EMPTY_LIST(n->ackl[queue]); i++)
|
2000-04-18 09:06:16 +08:00
|
|
|
{
|
2014-06-26 17:58:57 +08:00
|
|
|
no = (struct lsa_node *) HEAD(n->ackl[queue]);
|
|
|
|
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-19 01:00:56 +08:00
|
|
|
rem_node(NODE no);
|
2000-04-19 01:36:46 +08:00
|
|
|
mb_free(no);
|
2000-04-18 09:06:16 +08:00
|
|
|
}
|
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
length = ospf_pkt_hdrlen(p) + i * sizeof(struct ospf_lsa_header);
|
|
|
|
pkt->length = htons(length);
|
2009-04-06 22:17:47 +08:00
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
OSPF_PACKET(ospf_dump_lsack, pkt, "LSACK packet sent via %s", ifa->ifname);
|
2009-04-06 22:17:47 +08:00
|
|
|
|
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))
|
2012-05-14 17:47:41 +08:00
|
|
|
ospf_send_to_all(ifa);
|
2000-04-18 09:06:16 +08:00
|
|
|
else
|
2014-06-26 17:58:57 +08:00
|
|
|
ospf_send_to_des(ifa);
|
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
|
2014-06-26 17:58:57 +08:00
|
|
|
ospf_lsack_send(struct ospf_neighbor *n, int queue)
|
|
|
|
{
|
|
|
|
while (!EMPTY_LIST(n->ackl[queue]))
|
|
|
|
ospf_send_lsack(n, queue);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ospf_receive_lsack(struct ospf_packet *pkt, struct ospf_iface *ifa,
|
2009-08-21 15:27:52 +08:00
|
|
|
struct ospf_neighbor *n)
|
2000-03-31 04:00:42 +08:00
|
|
|
{
|
2014-06-26 17:58:57 +08:00
|
|
|
struct ospf_proto *p = ifa->oa->po;
|
|
|
|
struct ospf_lsa_header lsa, *lsas;
|
|
|
|
struct top_hash_entry *ret, *en;
|
|
|
|
uint i, lsa_count;
|
|
|
|
u32 lsa_type, lsa_domain;
|
2009-10-30 06:57:42 +08:00
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
/* RFC 2328 13.7 */
|
2000-04-12 23:37:52 +08:00
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
/* No need to check length, lsack has only basic header */
|
2009-04-06 22:17:47 +08:00
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
OSPF_PACKET(ospf_dump_lsack, pkt, "LSACK packet received from %I via %s", n->ip, ifa->ifname);
|
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
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
ospf_neigh_sm(n, INM_HELLOREC); /* Not in RFC */
|
|
|
|
|
|
|
|
ospf_lsack_body(p, pkt, &lsas, &lsa_count);
|
|
|
|
for (i = 0; i < lsa_count; i++)
|
2000-04-12 23:20:13 +08:00
|
|
|
{
|
2014-06-26 17:58:57 +08:00
|
|
|
lsa_ntoh_hdr(&lsas[i], &lsa);
|
|
|
|
lsa_get_type_domain(&lsa, n->ifa, &lsa_type, &lsa_domain);
|
2000-04-12 23:20:13 +08:00
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
ret = ospf_hash_find(n->lsrth, lsa_domain, lsa.id, lsa.rt, lsa_type);
|
|
|
|
if (!ret)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (lsa_comp(&lsa, &ret->lsa) != CMP_SAME)
|
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
|
|
|
|
2009-12-15 00:29:33 +08:00
|
|
|
OSPF_TRACE(D_PACKETS, "Strange LSACK from %I", n->ip);
|
|
|
|
OSPF_TRACE(D_PACKETS, "Type: %04x, Id: %R, Rt: %R",
|
2014-06-26 17:58:57 +08:00
|
|
|
lsa_type, lsa.id, lsa.rt);
|
2009-12-15 00:29:33 +08:00
|
|
|
OSPF_TRACE(D_PACKETS, "I have: Age: %4u, Seq: %08x, Sum: %04x",
|
2014-06-26 17:58:57 +08:00
|
|
|
ret->lsa.age, ret->lsa.sn, ret->lsa.checksum);
|
2009-12-15 00:29:33 +08:00
|
|
|
OSPF_TRACE(D_PACKETS, "He has: Age: %4u, Seq: %08x, Sum: %04x",
|
2004-06-05 00:55:53 +08:00
|
|
|
lsa.age, lsa.sn, lsa.checksum);
|
2000-04-12 23:20:13 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-06-26 17:58:57 +08:00
|
|
|
en = ospf_hash_find_entry(p->gr, ret);
|
|
|
|
if (en)
|
|
|
|
en->ret_count--;
|
|
|
|
|
|
|
|
DBG("Deleting LSA (Type: %04x Id: %R Rt: %R) from lsrtl for neighbor %R\n",
|
|
|
|
lsa_type, lsa.id, lsa.rt, n->rid);
|
|
|
|
s_rem_node(SNODE ret);
|
|
|
|
ospf_hash_delete(n->lsrth, ret);
|
2004-06-05 00:55:53 +08:00
|
|
|
}
|
2000-03-31 04:00:42 +08:00
|
|
|
}
|