#include "sockopt.h"
static struct iface *disc_find_iface(unsigned int, int,
- union ldpd_addr *, int);
+ union ldpd_addr *);
static int session_read(struct thread *);
static int session_write(struct thread *);
static ssize_t session_get_pdu(struct ibuf_read *, char **);
send_packet(int fd, int af, union ldpd_addr *dst, struct iface_af *ia,
void *pkt, size_t len)
{
- struct sockaddr *sa;
+ union sockunion su;
switch (af) {
case AF_INET:
fatalx("send_packet: unknown af");
}
- sa = addr2sa(af, dst, LDP_PORT);
- if (sendto(fd, pkt, len, 0, sa, sockaddr_len(sa)) == -1) {
+ addr2sa(af, dst, LDP_PORT, &su);
+ if (sendto(fd, pkt, len, 0, &su.sa, sockaddr_len(&su.sa)) == -1) {
log_warn("%s: error sending packet to %s", __func__,
- log_sockaddr(sa));
+ log_sockaddr(&su.sa));
return (-1);
}
int af;
union ldpd_addr src;
unsigned int ifindex = 0;
- struct iface *iface;
+ struct iface *iface = NULL;
uint16_t len;
struct ldp_hdr ldp_hdr;
uint16_t pdu_len;
struct in_addr lsr_id;
/* reschedule read */
- *threadp = thread_add_read(master, disc_recv_packet, threadp, fd);
+ *threadp = NULL;
+ thread_add_read(master, disc_recv_packet, threadp, fd, threadp);
/* setup buffer */
memset(&m, 0, sizeof(m));
ifindex = getsockopt_ifindex(af, &m);
/* find a matching interface */
- iface = disc_find_iface(ifindex, af, &src, multicast);
- if (iface == NULL)
- return (0);
+ if (multicast) {
+ iface = disc_find_iface(ifindex, af, &src);
+ if (iface == NULL)
+ return (0);
+ }
/* check packet size */
len = (uint16_t)r;
}
static struct iface *
-disc_find_iface(unsigned int ifindex, int af, union ldpd_addr *src,
- int multicast)
+disc_find_iface(unsigned int ifindex, int af, union ldpd_addr *src)
{
struct iface *iface;
struct iface_af *ia;
* "Link-local IPv6 address MUST be used as the source IP address in
* IPv6 LDP Link Hellos".
*/
- if (multicast && af == AF_INET6 && !IN6_IS_ADDR_LINKLOCAL(&src->v6))
+ if (af == AF_INET6 && !IN6_IS_ADDR_LINKLOCAL(&src->v6))
return (NULL);
return (iface);
uint16_t pdu_len, msg_len, msg_size, max_pdu_len;
int ret;
- tcp->rev = thread_add_read(master, session_read, nbr, fd);
+ tcp->rev = NULL;
+ thread_add_read(master, session_read, nbr, fd, &tcp->rev);
if ((n = read(fd, tcp->rbuf->buf + tcp->rbuf->wpos,
sizeof(tcp->rbuf->buf) - tcp->rbuf->wpos)) == -1) {
msg_len = ntohs(msg->length);
if (msg_len < LDP_MSG_LEN ||
(msg_len + LDP_MSG_DEAD_LEN) > pdu_len) {
- session_shutdown(nbr, S_BAD_TLV_LEN, msg->id,
+ session_shutdown(nbr, S_BAD_MSG_LEN, msg->id,
msg->type);
free(buf);
return (0);
return (0);
}
break;
+ case MSG_TYPE_NOTIFICATION:
+ break;
default:
if (nbr->state != NBR_STA_OPER) {
session_shutdown(nbr, S_SHUTDOWN,
len -= msg_size;
}
free(buf);
+ buf = NULL;
if (len != 0) {
session_shutdown(nbr, S_BAD_PDU_LEN, 0, 0);
return (0);
}
}
+ /* shouldn't happen, session_get_pdu should be > 0 if buf was
+ * allocated - but let's get rid of the SA warning.
+ */
+ free(buf);
return (0);
}
case NBR_STA_OPENREC:
case NBR_STA_OPENSENT:
case NBR_STA_OPER:
- log_debug("%s: lsr-id %s", __func__, inet_ntoa(nbr->id));
-
send_notification(nbr->tcp, status, msg_id, msg_type);
nbr_fsm(nbr, NBR_EVT_CLOSE_SESSION);
if ((tcp->rbuf = calloc(1, sizeof(struct ibuf_read))) == NULL)
fatal(__func__);
- tcp->rev = thread_add_read(master, session_read, nbr, tcp->fd);
+ tcp->rev = NULL;
+ thread_add_read(master, session_read, nbr, tcp->fd, &tcp->rev);
tcp->nbr = nbr;
}
pconn->af = af;
pconn->addr = *addr;
TAILQ_INSERT_TAIL(&global.pending_conns, pconn, entry);
- pconn->ev_timeout = thread_add_timer(master, pending_conn_timeout,
- pconn, PENDING_CONN_TIMEOUT);
+ pconn->ev_timeout = NULL;
+ thread_add_timer(master, pending_conn_timeout, pconn, PENDING_CONN_TIMEOUT,
+ &pconn->ev_timeout);
return (pconn);
}