0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2024-12-23 02:01:55 +00:00
bird/proto/ospf/lsack.c

182 lines
4.5 KiB
C
Raw Normal View History

2000-03-30 20:00:42 +00:00
/*
* BIRD -- OSPF
*
2014-06-26 09:58:57 +00: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-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
2014-06-26 09:58:57 +00:00
/*
2009-08-21 07:27:52 +00:00
struct ospf_lsack_packet
{
2014-06-26 09:58:57 +00:00
struct ospf_packet hdr;
// union ospf_auth auth;
2009-08-21 07:27:52 +00:00
2014-06-26 09:58:57 +00:00
struct ospf_lsa_header lsas[];
};
*/
2009-08-21 07:27:52 +00:00
2014-06-26 09:58:57 +00:00
struct lsa_node
{
node n;
struct ospf_lsa_header lsa;
};
2014-06-26 09:58:57 +00:00
static inline void
ospf_lsack_body(struct ospf_proto *p, struct ospf_packet *pkt,
struct ospf_lsa_header **body, uint *count)
{
2014-06-26 09:58:57 +00:00
uint plen = ntohs(pkt->length);
uint hlen = ospf_pkt_hdrlen(p);
2014-06-26 09:58:57 +00:00
*body = ((void *) pkt) + hlen;
*count = (plen - hlen) / sizeof(struct ospf_lsa_header);
}
2014-06-26 09:58:57 +00:00
static void
ospf_dump_lsack(struct ospf_proto *p, struct ospf_packet *pkt)
{
struct ospf_lsa_header *lsas;
uint i, lsa_count;
2014-06-26 09:58:57 +00:00
ASSERT(pkt->type == LSACK_P);
ospf_dump_common(p, pkt);
2014-06-26 09:58:57 +00:00
ospf_lsack_body(p, pkt, &lsas, &lsa_count);
for (i = 0; i < lsa_count; i++)
ospf_dump_lsahdr(p, lsas + i);
}
2004-06-04 16:55:53 +00:00
void
2014-06-26 09:58:57 +00:00
ospf_enqueue_lsack(struct ospf_neighbor *n, struct ospf_lsa_header *h_n, int queue)
{
2014-06-26 09:58:57 +00:00
/* Note that h_n is in network endianity */
struct lsa_node *no = mb_alloc(n->pool, sizeof(struct lsa_node));
no->n = (node) {};
2014-06-26 09:58:57 +00:00
memcpy(&no->lsa, h_n, sizeof(struct ospf_lsa_header));
add_tail(&n->ackl[queue], NODE no);
2014-06-26 09:58:57 +00: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);
}
void
2014-06-26 09:58:57 +00:00
ospf_reset_lsack_queue(struct ospf_neighbor *n)
{
2014-06-26 09:58:57 +00:00
struct lsa_node *no;
2014-06-26 09:58:57 +00:00
WALK_LIST_FIRST(no, n->ackl[ACKL_DELAY])
{
rem_node(NODE no);
mb_free(no);
}
}
2014-06-26 09:58:57 +00:00
static inline void
2014-07-18 16:24:12 +00:00
ospf_send_lsack_(struct ospf_proto *p, struct ospf_neighbor *n, int queue)
2014-06-26 09:58:57 +00:00
{
struct ospf_iface *ifa = n->ifa;
struct ospf_lsa_header *lsas;
struct ospf_packet *pkt;
struct lsa_node *no;
uint i, lsa_max, length;
2014-06-26 09:58:57 +00:00
/* RFC 2328 13.5 */
2014-06-26 09:58:57 +00: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++)
{
2014-06-26 09:58:57 +00: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);
rem_node(NODE no);
mb_free(no);
}
2014-06-26 09:58:57 +00:00
length = ospf_pkt_hdrlen(p) + i * sizeof(struct ospf_lsa_header);
pkt->length = htons(length);
if (queue == ACKL_DIRECT)
{
OSPF_PACKET(ospf_dump_lsack, pkt, "LSACK packet sent to nbr %R on %s", n->rid, ifa->ifname);
ospf_send_to_nbr(ifa, n);
}
else
{
OSPF_PACKET(ospf_dump_lsack, pkt, "LSACK packet sent via %s", ifa->ifname);
ospf_send_to_iface(ifa);
}
2000-03-30 20:00:42 +00:00
}
void
2014-07-18 16:24:12 +00:00
ospf_send_lsack(struct ospf_proto *p, struct ospf_neighbor *n, int queue)
2014-06-26 09:58:57 +00:00
{
while (!EMPTY_LIST(n->ackl[queue]))
2014-07-18 16:24:12 +00:00
ospf_send_lsack_(p, n, queue);
2014-06-26 09:58:57 +00:00
}
void
ospf_receive_lsack(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
{
2014-06-26 09:58:57 +00: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;
2014-06-26 09:58:57 +00:00
/* RFC 2328 13.7 */
2000-04-12 15:37:52 +00:00
2014-06-26 09:58:57 +00:00
/* No need to check length, lsack has only basic header */
2014-10-24 08:27:21 +00:00
OSPF_PACKET(ospf_dump_lsack, pkt, "LSACK packet received from nbr %R on %s", n->rid, ifa->ifname);
2004-06-04 16:55:53 +00:00
if (n->state < NEIGHBOR_EXCHANGE)
2014-10-24 08:27:21 +00:00
{
OSPF_TRACE(D_PACKETS, "LSACK packet ignored - lesser state than Exchange");
2004-06-04 16:55:53 +00:00
return;
2014-10-24 08:27:21 +00:00
}
2014-06-26 09:58:57 +00: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 15:20:13 +00:00
{
2014-06-26 09:58:57 +00:00
lsa_ntoh_hdr(&lsas[i], &lsa);
lsa_get_type_domain(&lsa, n->ifa, &lsa_type, &lsa_domain);
2000-04-12 15:20:13 +00:00
2014-06-26 09:58:57 +00: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 15:20:13 +00:00
{
2014-11-03 09:42:55 +00:00
OSPF_TRACE(D_PACKETS, "Strange LSACK from nbr %R on %s", n->rid, ifa->ifname);
OSPF_TRACE(D_PACKETS, " Type: %04x, Id: %R, Rt: %R",
2014-06-26 09:58:57 +00:00
lsa_type, lsa.id, lsa.rt);
2014-11-03 09:42:55 +00:00
OSPF_TRACE(D_PACKETS, " I have: Seq: %08x, Age: %4u, Sum: %04x",
ret->lsa.sn, ret->lsa.age, ret->lsa.checksum);
OSPF_TRACE(D_PACKETS, " It has: Seq: %08x, Age: %4u, Sum: %04x",
lsa.sn, lsa.age, lsa.checksum);
2000-04-12 15:20:13 +00:00
continue;
}
2014-06-26 09:58:57 +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);
2014-11-03 09:42:55 +00:00
en = ospf_hash_find_entry(p->gr, ret);
ospf_lsa_lsrt_down_(en, n, ret);
2004-06-04 16:55:53 +00:00
}
2000-03-30 20:00:42 +00:00
}