]>
Commit | Line | Data |
---|---|---|
8429abe0 RW |
1 | /* $OpenBSD$ */ |
2 | ||
3 | /* | |
4 | * Copyright (c) 2009 Michele Marchetto <michele@openbsd.org> | |
5 | * | |
6 | * Permission to use, copy, modify, and distribute this software for any | |
7 | * purpose with or without fee is hereby granted, provided that the above | |
8 | * copyright notice and this permission notice appear in all copies. | |
9 | * | |
10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | |
16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
17 | */ | |
18 | ||
eac6e3f0 | 19 | #include <zebra.h> |
8429abe0 RW |
20 | |
21 | #include "ldpd.h" | |
22 | #include "ldpe.h" | |
23 | #include "log.h" | |
eac6e3f0 | 24 | #include "ldp_debug.h" |
8429abe0 RW |
25 | |
26 | void | |
27 | send_keepalive(struct nbr *nbr) | |
28 | { | |
29 | struct ibuf *buf; | |
30 | uint16_t size; | |
31 | ||
32 | size = LDP_HDR_SIZE + LDP_MSG_SIZE; | |
33 | if ((buf = ibuf_open(size)) == NULL) | |
34 | fatal(__func__); | |
35 | ||
36 | gen_ldp_hdr(buf, size); | |
37 | size -= LDP_HDR_SIZE; | |
38 | gen_msg_hdr(buf, MSG_TYPE_KEEPALIVE, size); | |
39 | ||
eac6e3f0 RW |
40 | debug_kalive_send("keepalive: lsr-id %s", inet_ntoa(nbr->id)); |
41 | ||
8429abe0 | 42 | evbuf_enqueue(&nbr->tcp->wbuf, buf); |
0f7b5df9 | 43 | nbr->stats.kalive_sent++; |
8429abe0 RW |
44 | } |
45 | ||
46 | int | |
47 | recv_keepalive(struct nbr *nbr, char *buf, uint16_t len) | |
48 | { | |
49 | struct ldp_msg msg; | |
50 | ||
51 | memcpy(&msg, buf, sizeof(msg)); | |
52 | if (len != LDP_MSG_SIZE) { | |
53 | session_shutdown(nbr, S_BAD_MSG_LEN, msg.id, msg.type); | |
54 | return (-1); | |
55 | } | |
56 | ||
eac6e3f0 RW |
57 | debug_kalive_recv("keepalive: lsr-id %s", inet_ntoa(nbr->id)); |
58 | ||
8429abe0 RW |
59 | if (nbr->state != NBR_STA_OPER) |
60 | nbr_fsm(nbr, NBR_EVT_KEEPALIVE_RCVD); | |
61 | ||
62 | return (0); | |
63 | } |