diff src/event/ngx_event_udp.h @ 8810:2dfd313f22f2 quic

Core: made the ngx_sendmsg() function non-static. Additionally, the ngx_init_srcaddr_cmsg() function is introduced which initializes control message with connection local address. The NGX_HAVE_ADDRINFO_CMSG macro is defined when at least one of methods to deal with corresponding control message is available.
author Vladimir Homutov <vl@nginx.com>
date Thu, 15 Jul 2021 14:21:39 +0300
parents 6f434af59257
children e7a2d3914877
line wrap: on
line diff
--- a/src/event/ngx_event_udp.h
+++ b/src/event/ngx_event_udp.h
@@ -14,6 +14,14 @@
 
 #if !(NGX_WIN32)
 
+#if ((NGX_HAVE_MSGHDR_MSG_CONTROL)                                            \
+     && (NGX_HAVE_IP_SENDSRCADDR || NGX_HAVE_IP_RECVDSTADDR                   \
+         || NGX_HAVE_IP_PKTINFO                                               \
+         || (NGX_HAVE_INET6 && NGX_HAVE_IPV6_RECVPKTINFO)))
+#define NGX_HAVE_ADDRINFO_CMSG  1
+#endif
+
+
 typedef struct {
     ngx_buf_t                 *buffer;
     struct sockaddr           *sockaddr;
@@ -29,7 +37,30 @@ struct ngx_udp_connection_s {
 };
 
 
+#if (NGX_HAVE_ADDRINFO_CMSG)
+
+typedef union {
+#if (NGX_HAVE_IP_SENDSRCADDR || NGX_HAVE_IP_RECVDSTADDR)
+    struct in_addr        addr;
+#endif
+
+#if (NGX_HAVE_IP_PKTINFO)
+    struct in_pktinfo     pkt;
+#endif
+
+#if (NGX_HAVE_INET6 && NGX_HAVE_IPV6_RECVPKTINFO)
+    struct in6_pktinfo    pkt6;
+#endif
+} ngx_addrinfo_t;
+
+size_t ngx_set_srcaddr_cmsg(struct cmsghdr *cmsg,
+    struct sockaddr *local_sockaddr);
+
+#endif
+
+
 void ngx_event_recvmsg(ngx_event_t *ev);
+ssize_t ngx_sendmsg(ngx_connection_t *c, struct msghdr *msg, int flags);
 void ngx_udp_rbtree_insert_value(ngx_rbtree_node_t *temp,
     ngx_rbtree_node_t *node, ngx_rbtree_node_t *sentinel);
 void ngx_insert_udp_connection(ngx_connection_t *c, ngx_udp_connection_t *udp,