ospf6d: add lsreq messages to tx fifo

queue outgoing lsreq messages to the interface tx FIFO and schedule
the ospf_write task to deal with them.

Signed-off-by: Pat Ruddy <pat@voltanet.io>
This commit is contained in:
Pat Ruddy 2021-03-15 18:17:02 +00:00
parent d6a39b53f5
commit 571eed235d

View File

@ -2279,13 +2279,43 @@ int ospf6_dbdesc_send_newone(struct thread *thread)
return 0; return 0;
} }
static uint16_t ospf6_make_lsreq(struct ospf6_neighbor *on, struct stream *s)
{
uint16_t length = 0;
struct ospf6_lsa *lsa, *lsanext, *last_req = NULL;
for (ALL_LSDB(on->request_list, lsa, lsanext)) {
if ((length + OSPF6_HEADER_SIZE)
> ospf6_packet_max(on->ospf6_if)) {
ospf6_lsa_unlock(lsa);
if (lsanext)
ospf6_lsa_unlock(lsanext);
break;
}
stream_putw(s, 0); /* reserved */
stream_putw(s, ntohs(lsa->header->type));
stream_putl(s, ntohl(lsa->header->id));
stream_putl(s, ntohl(lsa->header->adv_router));
length += sizeof(struct ospf6_lsreq_entry);
last_req = lsa;
}
if (last_req != NULL) {
if (on->last_ls_req != NULL)
on->last_ls_req = ospf6_lsa_unlock(on->last_ls_req);
ospf6_lsa_lock(last_req);
on->last_ls_req = last_req;
}
return length;
}
int ospf6_lsreq_send(struct thread *thread) int ospf6_lsreq_send(struct thread *thread)
{ {
struct ospf6_neighbor *on; struct ospf6_neighbor *on;
struct ospf6_header *oh; struct ospf6_packet *op;
struct ospf6_lsreq_entry *e; uint16_t length = OSPF6_HEADER_SIZE;
uint8_t *p;
struct ospf6_lsa *lsa, *lsanext, *last_req;
on = (struct ospf6_neighbor *)THREAD_ARG(thread); on = (struct ospf6_neighbor *)THREAD_ARG(thread);
on->thread_send_lsreq = (struct thread *)NULL; on->thread_send_lsreq = (struct thread *)NULL;
@ -2306,49 +2336,31 @@ int ospf6_lsreq_send(struct thread *thread)
return 0; return 0;
} }
memset(sendbuf, 0, iobuflen); op = ospf6_packet_new(on->ospf6_if->ifmtu);
oh = (struct ospf6_header *)sendbuf; ospf6_make_header(OSPF6_MESSAGE_TYPE_LSREQ, on->ospf6_if, op->s);
last_req = NULL;
/* set Request entries in lsreq */ length += ospf6_make_lsreq(on, op->s);
p = (uint8_t *)((caddr_t)oh + sizeof(struct ospf6_header));
for (ALL_LSDB(on->request_list, lsa, lsanext)) {
/* MTU check */
if (p - sendbuf + sizeof(struct ospf6_lsreq_entry)
> ospf6_packet_max(on->ospf6_if)) {
ospf6_lsa_unlock(lsa);
if (lsanext)
ospf6_lsa_unlock(lsanext);
break;
}
e = (struct ospf6_lsreq_entry *)p; if (length == OSPF6_HEADER_SIZE) {
e->type = lsa->header->type; /* Hello overshooting MTU */
e->id = lsa->header->id; ospf6_packet_free(op);
e->adv_router = lsa->header->adv_router; return 0;
p += sizeof(struct ospf6_lsreq_entry);
last_req = lsa;
} }
if (last_req != NULL) { /* Fill OSPF header. */
if (on->last_ls_req != NULL) ospf6_fill_header(on->ospf6_if, op->s, length);
on->last_ls_req = ospf6_lsa_unlock(on->last_ls_req);
ospf6_lsa_lock(last_req); /* Set packet length. */
on->last_ls_req = last_req; op->length = length;
}
oh->type = OSPF6_MESSAGE_TYPE_LSREQ;
oh->length = htons(p - sendbuf);
on->ospf6_if->ls_req_out++;
if (on->ospf6_if->state == OSPF6_INTERFACE_POINTTOPOINT) if (on->ospf6_if->state == OSPF6_INTERFACE_POINTTOPOINT)
ospf6_send(on->ospf6_if->linklocal_addr, &allspfrouters6, op->dst = allspfrouters6;
on->ospf6_if, oh);
else else
ospf6_send(on->ospf6_if->linklocal_addr, &on->linklocal_addr, op->dst = on->linklocal_addr;
on->ospf6_if, oh);
ospf6_packet_add(on->ospf6_if, op);
OSPF6_MESSAGE_WRITE_ON(on->ospf6_if);
/* set next thread */ /* set next thread */
if (on->request_list->count != 0) { if (on->request_list->count != 0) {