]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: quic: remove sendto() usage variant
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Mon, 19 Feb 2024 14:29:48 +0000 (15:29 +0100)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Tue, 20 Feb 2024 15:42:05 +0000 (16:42 +0100)
qc_snd_buf() is a wrapper around emission syscalls. Given QUIC
configuration, a different variant is used. When using connection
socket, send() is the only used. For listener sockets, sendmsg() and
sendto() are possible. The first one is used only if local address has
been retrieved prior. This allows to fix it on sending to guarantee the
source address selection. Finally, sendto() is used for systems which do
not support local address retrieval.

All of these variants render the code too complex. As such, this patch
simplifies this by removing sendto() alternative. Now, sendmsg() is
always used for listener sockets. Source address is then specified only
if supported by the system.

This patch should not exhibit functional behavior changes. It will be
useful when implementing GSO as the code is now simpler.

src/quic_sock.c

index 14db339f5b0968c2073549d6c74fa13c94a09ef4..45f6bb85c67932823685fbf294931e71bf194e9f 100644 (file)
@@ -670,11 +670,11 @@ int qc_snd_buf(struct quic_conn *qc, const struct buffer *buf, size_t sz,
                        ret = send(qc->fd, b_peek(buf, b_head_ofs(buf)), sz,
                                   MSG_DONTWAIT | MSG_NOSIGNAL);
                }
-#if defined(IP_PKTINFO) || defined(IP_RECVDSTADDR) || defined(IPV6_RECVPKTINFO)
-               else if (is_addr(&qc->local_addr)) {
+               else {
                        struct msghdr msg;
                        struct iovec vec;
-                       struct cmsghdr *cmsg = NULL;
+                       struct cmsghdr *cmsg __maybe_unused = NULL;
+
                        union {
 #ifdef IP_PKTINFO
                                char buf[CMSG_SPACE(sizeof(struct in_pktinfo))];
@@ -684,27 +684,25 @@ int qc_snd_buf(struct quic_conn *qc, const struct buffer *buf, size_t sz,
 #endif /* IPV6_RECVPKTINFO */
                                char bufaddr[CMSG_SPACE(sizeof(struct in_addr))];
                                struct cmsghdr align;
-                       } u;
+                       } ancillary_data;
 
                        vec.iov_base = b_peek(buf, b_head_ofs(buf));
                        vec.iov_len = sz;
+
                        msg.msg_name = &qc->peer_addr;
                        msg.msg_namelen = get_addr_len(&qc->peer_addr);
                        msg.msg_iov = &vec;
                        msg.msg_iovlen = 1;
+                       msg.msg_control = NULL;
+                       msg.msg_controllen = 0;
 
-                       msg.msg_control = u.bufaddr;
-                       cmsg_set_saddr(&msg, &cmsg, &qc->local_addr);
+                       /* Set source address for listener socket if known. */
+                       if (is_addr(&qc->local_addr)) {
+                               msg.msg_control = ancillary_data.bufaddr;
+                               cmsg_set_saddr(&msg, &cmsg, &qc->local_addr);
+                       }
 
-                       ret = sendmsg(qc->li->rx.fd, &msg,
-                                     MSG_DONTWAIT|MSG_NOSIGNAL);
-               }
-#endif /* IP_PKTINFO || IP_RECVDSTADDR || IPV6_RECVPKTINFO */
-               else {
-                       ret = sendto(qc->li->rx.fd, b_peek(buf, b_head_ofs(buf)), sz,
-                                    MSG_DONTWAIT|MSG_NOSIGNAL,
-                                    (struct sockaddr *)&qc->peer_addr,
-                                    get_addr_len(&qc->peer_addr));
+                       ret = sendmsg(qc->li->rx.fd, &msg, MSG_DONTWAIT|MSG_NOSIGNAL);
                }
        } while (ret < 0 && errno == EINTR);