0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2024-10-19 10:28:42 +00:00
bird/proto/ospf/lsreq.c

139 lines
3.4 KiB
C
Raw Normal View History

2000-03-30 00:18:59 +00:00
/*
* BIRD -- OSPF
*
* (c) 2000--2004 Ondrej Filip <feela@network.cz>
2000-03-30 00:18:59 +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
/*
2009-08-21 07:27:52 +00:00
struct ospf_lsreq_packet
{
struct ospf_packet hdr;
// union ospf_auth auth;
2009-08-21 07:27:52 +00:00
struct ospf_lsreq_header lsrs[];
};
*/
2009-08-21 07:27:52 +00:00
static inline void
ospf_lsreq_body(struct proto_ospf *po, struct ospf_packet *pkt, unsigned plen,
struct ospf_lsreq_header **body, unsigned *count)
{
unsigned hdrlen = ospf_pkt_hdrlen(po);
*body = ((void *) pkt) + hdrlen;
*count = (plen - hdrlen) / sizeof(struct ospf_lsreq_header);
}
static void
ospf_lsreq_dump(struct proto_ospf *po, struct ospf_packet *pkt)
{
struct ospf_lsreq_header *lsrs;
unsigned i, lsr_count;
ASSERT(pkt->type == LSREQ_P);
ospf_dump_common(po, pkt);
ospf_lsreq_body(po, pkt, ntohs(pkt->length), &lsrs, &lsr_count);
for (i = 0; i < lsr_count; i++)
log(L_TRACE "%s: LSR Type: %04x, Id: %R, Rt: %R", po->proto.name,
ntohl(lsrs[i].type), ntohl(lsrs[i].id), ntohl(lsrs[i].rt));
}
2000-03-30 00:18:59 +00:00
void
ospf_lsreq_send(struct ospf_neighbor *n)
2000-03-30 00:18:59 +00:00
{
struct ospf_iface *ifa = n->ifa;
struct proto_ospf *po = ifa->oa->po;
struct ospf_lsreq_header *lsrs;
2000-03-30 00:18:59 +00:00
struct top_hash_entry *en;
struct ospf_packet *pkt;
unsigned i, lsh_max, length;
snode *sn;
2000-03-30 00:18:59 +00:00
if (EMPTY_SLIST(n->lsrql))
2000-03-30 19:21:17 +00:00
{
if (n->state == NEIGHBOR_LOADING)
ospf_neigh_sm(n, INM_LOADDONE);
2000-03-30 19:21:17 +00:00
return;
}
pkt = ospf_tx_buffer(ifa);
ospf_pkt_fill_hdr(ifa, pkt, LSREQ_P);
ospf_lsreq_body(po, pkt, ospf_pkt_maxsize(ifa), &lsrs, &lsh_max);
sn = SHEAD(n->lsrql);
for (i = 0; i < lsh_max; i++)
2000-03-30 00:18:59 +00:00
{
en = (struct top_hash_entry *) sn;
2009-07-23 14:51:28 +00:00
DBG("Requesting %uth LSA: Type: %u, ID: %R, RT: %R, SN: 0x%x, Age %u\n",
i, en->lsa_type, en->lsa.id, en->lsa.rt, en->lsa.sn, en->lsa.age);
u32 rtype = lsa_get_type(po, en->lsa.type_raw);
lsrs[i].type = htonl(rtype);
lsrs[i].rt = htonl(en->lsa.rt);
lsrs[i].id = htonl(en->lsa.id);
if (sn == STAIL(n->lsrql))
break;
sn = sn->next;
2000-03-30 00:18:59 +00:00
}
length = ospf_pkt_hdrlen(po) + i * sizeof(struct ospf_lsreq_header);
pkt->length = htons(length);
OSPF_PACKET(ospf_lsreq_dump, pkt, "LSREQ packet sent to %I via %s", n->ip, ifa->ifname);
ospf_send_to(ifa, n->ip);
2000-03-30 00:18:59 +00:00
}
2013-04-15 23:14:57 +00:00
2000-03-30 00:18:59 +00:00
void
ospf_lsreq_receive(struct ospf_packet *pkt, struct ospf_iface *ifa,
2009-08-21 07:27:52 +00:00
struct ospf_neighbor *n)
2000-03-30 00:18:59 +00:00
{
struct proto_ospf *po = ifa->oa->po;
struct ospf_lsreq_header *lsrs;
unsigned i, lsr_count;
/* No need to check length, lsreq has only basic header */
OSPF_PACKET(ospf_lsreq_dump, pkt, "LSREQ packet received from %I via %s", n->ip, ifa->ifname);
if (n->state < NEIGHBOR_EXCHANGE)
return;
ospf_neigh_sm(n, INM_HELLOREC); /* Not in RFC */
2000-03-30 00:18:59 +00:00
ospf_lsreq_body(po, pkt, ntohs(pkt->length), &lsrs, &lsr_count);
2013-04-15 23:14:57 +00:00
struct top_hash_entry *en, *entries[lsr_count];
for (i = 0; i < lsr_count; i++)
2000-03-30 00:18:59 +00:00
{
u32 id, rt, type, dom;
id = ntohl(lsrs[i].id);
rt = ntohl(lsrs[i].rt);
lsa_xxxxtype(ntohl(lsrs[i].type), ifa, &type, &dom);
DBG("Processing requested LSA: Type: %04x, Id: %R, Rt: %R\n", type, id, rt);
2013-04-15 23:14:57 +00:00
en = ospf_hash_find(po->gr, dom, id, rt, type);
if (!en)
2000-03-30 20:00:42 +00:00
{
2013-04-15 23:14:57 +00:00
log(L_WARN "%s: Received LSREQ from %I for missing LSA (Type: %04x, Id: %R, Rt: %R)",
po->proto.name, n->ip, type, id, rt);
ospf_neigh_sm(n, INM_BADLSREQ);
2000-03-30 20:00:42 +00:00
return;
}
2013-04-15 23:14:57 +00:00
entries[i] = en;
2000-03-30 00:18:59 +00:00
}
2013-04-15 23:14:57 +00:00
ospf_lsupd_send(n, entries, lsr_count);
2000-03-30 00:18:59 +00:00
}