]> git.proxmox.com Git - mirror_frr.git/blob - ldpd/keepalive.c
*: auto-convert to SPDX License IDs
[mirror_frr.git] / ldpd / keepalive.c
1 // SPDX-License-Identifier: ISC
2 /* $OpenBSD$ */
3
4 /*
5 * Copyright (c) 2009 Michele Marchetto <michele@openbsd.org>
6 */
7
8 #include <zebra.h>
9
10 #include "ldpd.h"
11 #include "ldpe.h"
12 #include "log.h"
13 #include "ldp_debug.h"
14
15 void
16 send_keepalive(struct nbr *nbr)
17 {
18 struct ibuf *buf;
19 uint16_t size;
20
21 size = LDP_HDR_SIZE + LDP_MSG_SIZE;
22 if ((buf = ibuf_open(size)) == NULL)
23 fatal(__func__);
24
25 gen_ldp_hdr(buf, size);
26 size -= LDP_HDR_SIZE;
27 gen_msg_hdr(buf, MSG_TYPE_KEEPALIVE, size);
28
29 debug_kalive_send("keepalive: lsr-id %pI4", &nbr->id);
30
31 evbuf_enqueue(&nbr->tcp->wbuf, buf);
32 nbr->stats.kalive_sent++;
33 }
34
35 int
36 recv_keepalive(struct nbr *nbr, char *buf, uint16_t len)
37 {
38 struct ldp_msg msg;
39
40 memcpy(&msg, buf, sizeof(msg));
41 if (len != LDP_MSG_SIZE) {
42 session_shutdown(nbr, S_BAD_MSG_LEN, msg.id, msg.type);
43 return (-1);
44 }
45
46 debug_kalive_recv("keepalive: lsr-id %pI4", &nbr->id);
47
48 if (nbr->state != NBR_STA_OPER)
49 nbr_fsm(nbr, NBR_EVT_KEEPALIVE_RCVD);
50
51 return (0);
52 }