@@ -941,29 +941,91 @@ LocalManager::listenForProxy()
941941 // We are not already bound, bind the port
942942 for (auto &p : lmgmt->m_proxy_ports ) {
943943 if (ts::NO_FD == p.m_fd ) {
944- this ->bindProxyPort (p);
944+ // Check the protocol (TCP or UDP) and create an appropriate socket
945+ if (p.isQUIC ()) {
946+ this ->bindUdpProxyPort (p);
947+ } else {
948+ this ->bindTcpProxyPort (p);
949+ }
945950 }
946951
947- // read backlog configuration value and overwrite the default value if found
948- bool found;
949952 std::string_view fam{ats_ip_family_name (p.m_family )};
950- RecInt backlog = REC_readInteger (" proxy.config.net.listen_backlog" , &found);
951- backlog = (found && backlog >= 0 ) ? backlog : ats_tcp_somaxconn ();
953+ if (p.isQUIC ()) {
954+ // Can we do something like listen backlog for QUIC(UDP) ??
955+ // Do nothing for now
956+ } else {
957+ // read backlog configuration value and overwrite the default value if found
958+ bool found;
959+ RecInt backlog = REC_readInteger (" proxy.config.net.listen_backlog" , &found);
960+ backlog = (found && backlog >= 0 ) ? backlog : ats_tcp_somaxconn ();
952961
953- if ((listen (p.m_fd , backlog)) < 0 ) {
954- mgmt_fatal (errno, " [LocalManager::listenForProxy] Unable to listen on port: %d (%.*s)\n " , p.m_port , fam.size (), fam.data ());
962+ if ((listen (p.m_fd , backlog)) < 0 ) {
963+ mgmt_fatal (errno, " [LocalManager::listenForProxy] Unable to listen on port: %d (%.*s)\n " , p.m_port , fam.size (), fam.data ());
964+ }
955965 }
966+
956967 mgmt_log (" [LocalManager::listenForProxy] Listening on port: %d (%.*s)\n " , p.m_port , fam.size (), fam.data ());
957968 }
958969 return ;
959970}
960971
961972/*
962- * bindProxyPort()
973+ * bindUdpProxyPort()
974+ * Function binds the accept port of the proxy
975+ */
976+ void
977+ LocalManager::bindUdpProxyPort (HttpProxyPort &port)
978+ {
979+ int one = 1 ;
980+ int priv = (port.m_port < 1024 && 0 != geteuid ()) ? ElevateAccess::LOW_PORT_PRIVILEGE : 0 ;
981+
982+ ElevateAccess access (priv);
983+
984+ if ((port.m_fd = socket (port.m_family , SOCK_DGRAM, 0 )) < 0 ) {
985+ mgmt_fatal (0 , " [bindProxyPort] Unable to create socket : %s\n " , strerror (errno));
986+ }
987+
988+ if (port.m_family == AF_INET6) {
989+ if (setsockopt (port.m_fd , IPPROTO_IPV6, IPV6_V6ONLY, SOCKOPT_ON, sizeof (int )) < 0 ) {
990+ mgmt_log (" [bindProxyPort] Unable to set socket options: %d : %s\n " , port.m_port , strerror (errno));
991+ }
992+ }
993+ if (setsockopt (port.m_fd , SOL_SOCKET, SO_REUSEADDR, reinterpret_cast <char *>(&one), sizeof (int )) < 0 ) {
994+ mgmt_fatal (0 , " [bindProxyPort] Unable to set socket options: %d : %s\n " , port.m_port , strerror (errno));
995+ }
996+
997+ IpEndpoint ip;
998+ if (port.m_inbound_ip .isValid ()) {
999+ ip.assign (port.m_inbound_ip );
1000+ } else if (AF_INET6 == port.m_family ) {
1001+ if (m_inbound_ip6.isValid ()) {
1002+ ip.assign (m_inbound_ip6);
1003+ } else {
1004+ ip.setToAnyAddr (AF_INET6);
1005+ }
1006+ } else if (AF_INET == port.m_family ) {
1007+ if (m_inbound_ip4.isValid ()) {
1008+ ip.assign (m_inbound_ip4);
1009+ } else {
1010+ ip.setToAnyAddr (AF_INET);
1011+ }
1012+ } else {
1013+ mgmt_fatal (0 , " [bindProxyPort] Proxy port with invalid address type %d\n " , port.m_family );
1014+ }
1015+ ip.port () = htons (port.m_port );
1016+ if (bind (port.m_fd , &ip.sa , ats_ip_size (&ip)) < 0 ) {
1017+ mgmt_fatal (0 , " [bindProxyPort] Unable to bind socket: %d : %s\n " , port.m_port , strerror (errno));
1018+ }
1019+
1020+ Debug (" lm" , " [bindProxyPort] Successfully bound proxy port %d" , port.m_port );
1021+ }
1022+
1023+ /*
1024+ * bindTcpProxyPort()
9631025 * Function binds the accept port of the proxy
9641026 */
9651027void
966- LocalManager::bindProxyPort (HttpProxyPort &port)
1028+ LocalManager::bindTcpProxyPort (HttpProxyPort &port)
9671029{
9681030 int one = 1 ;
9691031 int priv = (port.m_port < 1024 && 0 != geteuid ()) ? ElevateAccess::LOW_PORT_PRIVILEGE : 0 ;
0 commit comments