From fdab32a92f9dfb35cd708c9842e96ae1b1a4efa8 Mon Sep 17 00:00:00 2001 From: Hazael Sanchez Date: Fri, 15 Aug 2025 10:26:15 -0700 Subject: [PATCH] Introduce socket tagging capabilities to the DNS resolver Internal bug: b/419200756 --- resolv/res_send.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/resolv/res_send.c b/resolv/res_send.c index 9e9541789b2..ce63ea8a91e 100644 --- a/resolv/res_send.c +++ b/resolv/res_send.c @@ -117,6 +117,13 @@ #define MAXPACKET 65536 #endif +static inline void tag_socket(int fd) { +#if defined(SO_NET_PROTOCOL_ID) && defined(PROTOCOL_ID_DNS) + int id = PROTOCOL_ID_DNS; + setsockopt(fd, SOL_SOCKET, SO_NET_PROTOCOL_ID, &id, sizeof(id)); +#endif +} + /* From ev_streams.c. */ static inline void @@ -743,6 +750,7 @@ send_vc(res_state statp, return (-1); } __set_errno (0); + tag_socket(statp->_vcsock); if (connect(statp->_vcsock, nsap, nsap->sa_family == AF_INET ? sizeof (struct sockaddr_in) @@ -945,6 +953,7 @@ reopen (res_state statp, int *terrno, int ns) *terrno = errno; return (-1); } + tag_socket(EXT(statp).nssocks[ns]); /* * On a 4.3BSD+ machine (client and server, -- 2.47.2