+// SPDX-License-Identifier: ISC
/* $OpenBSD$ */
/*
* Copyright (c) 2013, 2016 Renato Westphal <renato@openbsd.org>
* Copyright (c) 2009 Michele Marchetto <michele@openbsd.org>
* Copyright (c) 2004, 2005, 2008 Esben Norby <norby@openbsd.org>
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <zebra.h>
static struct iface *disc_find_iface(unsigned int, int,
union ldpd_addr *);
-static int session_read(struct thread *);
-static int session_write(struct thread *);
+static void session_read(struct thread *thread);
+static void session_write(struct thread *thread);
static ssize_t session_get_pdu(struct ibuf_read *, char **);
static void tcp_close(struct tcp_conn *);
static struct pending_conn *pending_conn_new(int, int, union ldpd_addr *);
-static int pending_conn_timeout(struct thread *);
+static void pending_conn_timeout(struct thread *thread);
int
gen_ldp_hdr(struct ibuf *buf, uint16_t size)
}
/* Discovery functions */
-int
-disc_recv_packet(struct thread *thread)
+void disc_recv_packet(struct thread *thread)
{
int fd = THREAD_FD(thread);
struct thread **threadp = THREAD_ARG(thread);
if (errno != EAGAIN && errno != EINTR)
log_debug("%s: read error: %s", __func__,
strerror(errno));
- return (0);
+ return;
}
sa2addr((struct sockaddr *)&from, &af, &src, NULL);
if (bad_addr(af, &src)) {
log_debug("%s: invalid source address: %s", __func__,
log_addr(af, &src));
- return (0);
+ return;
}
ifindex = getsockopt_ifindex(af, &m);
if (multicast) {
iface = disc_find_iface(ifindex, af, &src);
if (iface == NULL)
- return (0);
+ return;
}
/* check packet size */
if (len < (LDP_HDR_SIZE + LDP_MSG_SIZE) || len > LDP_MAX_LEN) {
log_debug("%s: bad packet size, source %s", __func__,
log_addr(af, &src));
- return (0);
+ return;
}
/* LDP header sanity checks */
if (ntohs(ldp_hdr.version) != LDP_VERSION) {
log_debug("%s: invalid LDP version %d, source %s", __func__,
ntohs(ldp_hdr.version), log_addr(af, &src));
- return (0);
+ return;
}
if (ntohs(ldp_hdr.lspace_id) != 0) {
log_debug("%s: invalid label space %u, source %s", __func__,
ntohs(ldp_hdr.lspace_id), log_addr(af, &src));
- return (0);
+ return;
}
/* check "PDU Length" field */
pdu_len = ntohs(ldp_hdr.length);
(pdu_len > (len - LDP_HDR_DEAD_LEN))) {
log_debug("%s: invalid LDP packet length %u, source %s",
__func__, ntohs(ldp_hdr.length), log_addr(af, &src));
- return (0);
+ return;
}
buf += LDP_HDR_SIZE;
len -= LDP_HDR_SIZE;
if (msg_len < LDP_MSG_LEN || ((msg_len + LDP_MSG_DEAD_LEN) > pdu_len)) {
log_debug("%s: invalid LDP message length %u, source %s",
__func__, ntohs(msg.length), log_addr(af, &src));
- return (0);
+ return;
}
buf += LDP_MSG_SIZE;
len -= LDP_MSG_SIZE;
log_debug("%s: unknown LDP packet type, source %s", __func__,
log_addr(af, &src));
}
-
- return (0);
}
static struct iface *
return (iface);
}
-int
-session_accept(struct thread *thread)
+void session_accept(struct thread *thread)
{
int fd = THREAD_FD(thread);
struct sockaddr_storage src;
errno != ECONNABORTED)
log_debug("%s: accept error: %s", __func__,
strerror(errno));
- return (0);
+ return;
}
sock_set_nonblock(newfd);
close(newfd);
else
pending_conn_new(newfd, af, &addr);
- return (0);
+ return;
}
/* protection against buggy implementations */
if (nbr_session_active_role(nbr)) {
close(newfd);
- return (0);
+ return;
}
if (nbr->state != NBR_STA_PRESENT) {
log_debug("%s: lsr-id %pI4: rejecting additional transport connection", __func__, &nbr->id);
close(newfd);
- return (0);
+ return;
}
session_accept_nbr(nbr, newfd);
-
- return (0);
}
void
nbr_fsm(nbr, NBR_EVT_MATCH_ADJ);
}
-static int
-session_read(struct thread *thread)
+static void session_read(struct thread *thread)
{
int fd = THREAD_FD(thread);
struct nbr *nbr = THREAD_ARG(thread);
if (errno != EINTR && errno != EAGAIN) {
log_warn("%s: read error", __func__);
nbr_fsm(nbr, NBR_EVT_CLOSE_SESSION);
- return (0);
+ return;
}
/* retry read */
- return (0);
+ return;
}
if (n == 0) {
/* connection closed */
log_debug("%s: connection closed by remote end", __func__);
nbr_fsm(nbr, NBR_EVT_CLOSE_SESSION);
- return (0);
+ return;
}
tcp->rbuf->wpos += n;
if (ntohs(ldp_hdr->version) != LDP_VERSION) {
session_shutdown(nbr, S_BAD_PROTO_VER, 0, 0);
free(buf);
- return (0);
+ return;
}
pdu_len = ntohs(ldp_hdr->length);
pdu_len > max_pdu_len) {
session_shutdown(nbr, S_BAD_PDU_LEN, 0, 0);
free(buf);
- return (0);
+ return;
}
pdu_len -= LDP_HDR_PDU_LEN;
if (ldp_hdr->lsr_id != nbr->id.s_addr ||
ldp_hdr->lspace_id != 0) {
session_shutdown(nbr, S_BAD_LDP_ID, 0, 0);
free(buf);
- return (0);
+ return;
}
pdu += LDP_HDR_SIZE;
len -= LDP_HDR_SIZE;
session_shutdown(nbr, S_BAD_MSG_LEN, msg->id,
msg->type);
free(buf);
- return (0);
+ return;
}
msg_size = msg_len + LDP_MSG_DEAD_LEN;
pdu_len -= msg_size;
session_shutdown(nbr, S_SHUTDOWN,
msg->id, msg->type);
free(buf);
- return (0);
+ return;
}
break;
case MSG_TYPE_KEEPALIVE:
session_shutdown(nbr, S_SHUTDOWN,
msg->id, msg->type);
free(buf);
- return (0);
+ return;
}
break;
case MSG_TYPE_NOTIFICATION:
session_shutdown(nbr, S_SHUTDOWN,
msg->id, msg->type);
free(buf);
- return (0);
+ return;
}
break;
}
if (ret == -1) {
/* parser failed, giving up */
free(buf);
- return (0);
+ return;
}
/* no errors - update per neighbor message counters */
buf = NULL;
if (len != 0) {
session_shutdown(nbr, S_BAD_PDU_LEN, 0, 0);
- return (0);
+ return;
}
}
* allocated - but let's get rid of the SA warning.
*/
free(buf);
- return (0);
}
-static int
-session_write(struct thread *thread)
+static void session_write(struct thread *thread)
{
struct tcp_conn *tcp = THREAD_ARG(thread);
struct nbr *nbr = tcp->nbr;
* close the socket.
*/
tcp_close(tcp);
- return (0);
+ return;
}
evbuf_event_add(&tcp->wbuf);
-
- return (0);
}
void
switch (nbr->state) {
case NBR_STA_PRESENT:
if (nbr_pending_connect(nbr))
- thread_cancel(&nbr->ev_connect);
+ THREAD_OFF(nbr->ev_connect);
break;
case NBR_STA_INITIAL:
case NBR_STA_OPENREC:
evbuf_clear(&tcp->wbuf);
if (tcp->nbr) {
- thread_cancel(&tcp->rev);
+ THREAD_OFF(tcp->rev);
free(tcp->rbuf);
tcp->nbr->tcp = NULL;
}
void
pending_conn_del(struct pending_conn *pconn)
{
- thread_cancel(&pconn->ev_timeout);
+ THREAD_OFF(pconn->ev_timeout);
TAILQ_REMOVE(&global.pending_conns, pconn, entry);
free(pconn);
}
return (NULL);
}
-static int
-pending_conn_timeout(struct thread *thread)
+static void pending_conn_timeout(struct thread *thread)
{
struct pending_conn *pconn = THREAD_ARG(thread);
struct tcp_conn *tcp;
msgbuf_write(&tcp->wbuf.wbuf);
pending_conn_del(pconn);
-
- return (0);
}