]> git.proxmox.com Git - mirror_frr.git/blobdiff - ldpd/packet.c
Merge pull request #5288 from SumitAgarwal123/bfd_docs
[mirror_frr.git] / ldpd / packet.c
index 46893b992bd5b2e2d0f193e47dc4c1613c4541f8..dfab30eeb338acd84c5325cac5e42ac40fb48f56 100644 (file)
@@ -27,7 +27,7 @@
 #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 **);
@@ -70,7 +70,7 @@ int
 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:
@@ -97,10 +97,10 @@ send_packet(int fd, int af, union ldpd_addr *dst, struct iface_af *ia,
                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);
        }
 
@@ -134,7 +134,7 @@ disc_recv_packet(struct thread *thread)
        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;
@@ -143,7 +143,8 @@ disc_recv_packet(struct thread *thread)
        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));
@@ -212,9 +213,11 @@ disc_recv_packet(struct thread *thread)
        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;
@@ -280,8 +283,7 @@ disc_recv_packet(struct thread *thread)
 }
 
 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;
@@ -299,7 +301,7 @@ disc_find_iface(unsigned int ifindex, int af, union ldpd_addr *src,
         * "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);
@@ -426,7 +428,8 @@ session_read(struct thread *thread)
        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) {
@@ -491,7 +494,7 @@ session_read(struct thread *thread)
                        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);
@@ -519,6 +522,8 @@ session_read(struct thread *thread)
                                        return (0);
                                }
                                break;
+                       case MSG_TYPE_NOTIFICATION:
+                               break;
                        default:
                                if (nbr->state != NBR_STA_OPER) {
                                        session_shutdown(nbr, S_SHUTDOWN,
@@ -613,12 +618,17 @@ session_read(struct thread *thread)
                        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);
 }
 
@@ -661,8 +671,6 @@ session_shutdown(struct nbr *nbr, uint32_t status, uint32_t msg_id,
        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);
@@ -730,7 +738,8 @@ tcp_new(int fd, struct nbr *nbr)
                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;
        }
 
@@ -776,8 +785,9 @@ pending_conn_new(int fd, int af, union ldpd_addr *addr)
        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);
 }