2 * services/listen_dnsport.c - listen on port 53 for incoming DNS queries.
4 * Copyright (c) 2007, NLnet Labs. All rights reserved.
6 * This software is open source.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
15 * Redistributions in binary form must reproduce the above copyright notice,
16 * this list of conditions and the following disclaimer in the documentation
17 * and/or other materials provided with the distribution.
19 * Neither the name of the NLNET LABS nor the names of its contributors may
20 * be used to endorse or promote products derived from this software without
21 * specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
39 * This file has functions to get queries from clients.
42 #ifdef HAVE_SYS_TYPES_H
43 # include <sys/types.h>
46 #include "services/listen_dnsport.h"
47 #include "services/outside_network.h"
48 #include "util/netevent.h"
50 #include "util/config_file.h"
51 #include "util/net_help.h"
58 /** number of queued TCP connections for listen() */
62 * Debug print of the getaddrinfo returned address.
63 * @param addr: the address returned.
66 verbose_print_addr(struct addrinfo *addr)
68 if(verbosity >= VERB_ALGO) {
70 void* sinaddr = &((struct sockaddr_in*)addr->ai_addr)->sin_addr;
72 if(addr->ai_family == AF_INET6)
73 sinaddr = &((struct sockaddr_in6*)addr->ai_addr)->
76 if(inet_ntop(addr->ai_family, sinaddr, buf,
77 (socklen_t)sizeof(buf)) == 0) {
78 strncpy(buf, "(null)", sizeof(buf));
80 buf[sizeof(buf)-1] = 0;
81 verbose(VERB_ALGO, "creating %s%s socket %s %d",
82 addr->ai_socktype==SOCK_DGRAM?"udp":
83 addr->ai_socktype==SOCK_STREAM?"tcp":"otherproto",
84 addr->ai_family==AF_INET?"4":
85 addr->ai_family==AF_INET6?"6":
87 ntohs(((struct sockaddr_in*)addr->ai_addr)->sin_port));
92 create_udp_sock(int family, int socktype, struct sockaddr* addr,
93 socklen_t addrlen, int v6only, int* inuse, int* noproto,
97 #if defined(IPV6_USE_MIN_MTU)
101 int mtu = IPV6_MIN_MTU;
103 #if !defined(SO_RCVBUFFORCE) && !defined(SO_RCVBUF)
106 #if !defined(SO_SNDBUFFORCE) && !defined(SO_SNDBUF)
112 if((s = socket(family, socktype, 0)) == -1) {
115 if(errno == EAFNOSUPPORT || errno == EPROTONOSUPPORT) {
119 log_err("can't create socket: %s", strerror(errno));
121 if(WSAGetLastError() == WSAEAFNOSUPPORT ||
122 WSAGetLastError() == WSAEPROTONOSUPPORT) {
126 log_err("can't create socket: %s",
127 wsa_strerror(WSAGetLastError()));
135 socklen_t slen = (socklen_t)sizeof(got);
136 # ifdef SO_RCVBUFFORCE
137 /* Linux specific: try to use root permission to override
138 * system limits on rcvbuf. The limit is stored in
139 * /proc/sys/net/core/rmem_max or sysctl net.core.rmem_max */
140 if(setsockopt(s, SOL_SOCKET, SO_RCVBUFFORCE, (void*)&rcv,
141 (socklen_t)sizeof(rcv)) < 0) {
144 log_err("setsockopt(..., SO_RCVBUFFORCE, "
145 "...) failed: %s", strerror(errno));
148 log_err("setsockopt(..., SO_RCVBUFFORCE, "
150 wsa_strerror(WSAGetLastError()));
157 # endif /* SO_RCVBUFFORCE */
158 if(setsockopt(s, SOL_SOCKET, SO_RCVBUF, (void*)&rcv,
159 (socklen_t)sizeof(rcv)) < 0) {
161 log_err("setsockopt(..., SO_RCVBUF, "
162 "...) failed: %s", strerror(errno));
165 log_err("setsockopt(..., SO_RCVBUF, "
167 wsa_strerror(WSAGetLastError()));
174 /* check if we got the right thing or if system
175 * reduced to some system max. Warn if so */
176 if(getsockopt(s, SOL_SOCKET, SO_RCVBUF, (void*)&got,
177 &slen) >= 0 && got < rcv/2) {
178 log_warn("so-rcvbuf %u was not granted. "
179 "Got %u. To fix: start with "
180 "root permissions(linux) or sysctl "
181 "bigger net.core.rmem_max(linux) or "
182 "kern.ipc.maxsockbuf(bsd) values.",
183 (unsigned)rcv, (unsigned)got);
185 # ifdef SO_RCVBUFFORCE
188 #endif /* SO_RCVBUF */
190 /* first do RCVBUF as the receive buffer is more important */
194 socklen_t slen = (socklen_t)sizeof(got);
195 # ifdef SO_SNDBUFFORCE
196 /* Linux specific: try to use root permission to override
197 * system limits on sndbuf. The limit is stored in
198 * /proc/sys/net/core/wmem_max or sysctl net.core.wmem_max */
199 if(setsockopt(s, SOL_SOCKET, SO_SNDBUFFORCE, (void*)&snd,
200 (socklen_t)sizeof(snd)) < 0) {
203 log_err("setsockopt(..., SO_SNDBUFFORCE, "
204 "...) failed: %s", strerror(errno));
207 log_err("setsockopt(..., SO_SNDBUFFORCE, "
209 wsa_strerror(WSAGetLastError()));
216 # endif /* SO_SNDBUFFORCE */
217 if(setsockopt(s, SOL_SOCKET, SO_SNDBUF, (void*)&snd,
218 (socklen_t)sizeof(snd)) < 0) {
220 log_err("setsockopt(..., SO_SNDBUF, "
221 "...) failed: %s", strerror(errno));
224 log_err("setsockopt(..., SO_SNDBUF, "
226 wsa_strerror(WSAGetLastError()));
233 /* check if we got the right thing or if system
234 * reduced to some system max. Warn if so */
235 if(getsockopt(s, SOL_SOCKET, SO_SNDBUF, (void*)&got,
236 &slen) >= 0 && got < snd/2) {
237 log_warn("so-sndbuf %u was not granted. "
238 "Got %u. To fix: start with "
239 "root permissions(linux) or sysctl "
240 "bigger net.core.wmem_max(linux) or "
241 "kern.ipc.maxsockbuf(bsd) values.",
242 (unsigned)snd, (unsigned)got);
244 # ifdef SO_SNDBUFFORCE
247 #endif /* SO_SNDBUF */
249 if(family == AF_INET6) {
250 # if defined(IPV6_V6ONLY)
252 int val=(v6only==2)?0:1;
253 if (setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY,
254 (void*)&val, (socklen_t)sizeof(val)) < 0) {
256 log_err("setsockopt(..., IPV6_V6ONLY"
257 ", ...) failed: %s", strerror(errno));
260 log_err("setsockopt(..., IPV6_V6ONLY"
262 wsa_strerror(WSAGetLastError()));
271 # if defined(IPV6_USE_MIN_MTU)
273 * There is no fragmentation of IPv6 datagrams
274 * during forwarding in the network. Therefore
275 * we do not send UDP datagrams larger than
276 * the minimum IPv6 MTU of 1280 octets. The
277 * EDNS0 message length can be larger if the
278 * network stack supports IPV6_USE_MIN_MTU.
280 if (setsockopt(s, IPPROTO_IPV6, IPV6_USE_MIN_MTU,
281 (void*)&on, (socklen_t)sizeof(on)) < 0) {
283 log_err("setsockopt(..., IPV6_USE_MIN_MTU, "
284 "...) failed: %s", strerror(errno));
287 log_err("setsockopt(..., IPV6_USE_MIN_MTU, "
289 wsa_strerror(WSAGetLastError()));
296 # elif defined(IPV6_MTU)
298 * On Linux, to send no larger than 1280, the PMTUD is
299 * disabled by default for datagrams anyway, so we set
302 if (setsockopt(s, IPPROTO_IPV6, IPV6_MTU,
303 (void*)&mtu, (socklen_t)sizeof(mtu)) < 0) {
305 log_err("setsockopt(..., IPV6_MTU, ...) failed: %s",
309 log_err("setsockopt(..., IPV6_MTU, ...) failed: %s",
310 wsa_strerror(WSAGetLastError()));
317 # endif /* IPv6 MTU */
318 } else if(family == AF_INET) {
319 # if defined(IP_MTU_DISCOVER) && defined(IP_PMTUDISC_DONT)
320 int action = IP_PMTUDISC_DONT;
321 if (setsockopt(s, IPPROTO_IP, IP_MTU_DISCOVER,
322 &action, (socklen_t)sizeof(action)) < 0) {
323 log_err("setsockopt(..., IP_MTU_DISCOVER, "
324 "IP_PMTUDISC_DONT...) failed: %s",
328 # elif defined(IP_DONTFRAG)
330 if (setsockopt(s, IPPROTO_IP, IP_DONTFRAG,
331 &off, (socklen_t)sizeof(off)) < 0) {
332 log_err("setsockopt(..., IP_DONTFRAG, ...) failed: %s",
336 # endif /* IPv4 MTU */
338 if(bind(s, (struct sockaddr*)addr, addrlen) != 0) {
342 *inuse = (errno == EADDRINUSE);
343 /* detect freebsd jail with no ipv6 permission */
344 if(family==AF_INET6 && errno==EINVAL)
346 else if(errno != EADDRINUSE) {
347 log_err("can't bind socket: %s", strerror(errno));
348 log_addr(0, "failed address",
349 (struct sockaddr_storage*)addr, addrlen);
351 #endif /* EADDRINUSE */
353 #else /* USE_WINSOCK */
354 if(WSAGetLastError() != WSAEADDRINUSE &&
355 WSAGetLastError() != WSAEADDRNOTAVAIL) {
356 log_err("can't bind socket: %s",
357 wsa_strerror(WSAGetLastError()));
358 log_addr(0, "failed address",
359 (struct sockaddr_storage*)addr, addrlen);
365 if(!fd_set_nonblock(s)) {
379 create_tcp_accept_sock(struct addrinfo *addr, int v6only, int* noproto)
382 #if defined(SO_REUSEADDR) || defined(IPV6_V6ONLY)
384 #endif /* SO_REUSEADDR || IPV6_V6ONLY */
385 verbose_print_addr(addr);
387 if((s = socket(addr->ai_family, addr->ai_socktype, 0)) == -1) {
389 if(errno == EAFNOSUPPORT || errno == EPROTONOSUPPORT) {
393 log_err("can't create socket: %s", strerror(errno));
395 if(WSAGetLastError() == WSAEAFNOSUPPORT ||
396 WSAGetLastError() == WSAEPROTONOSUPPORT) {
400 log_err("can't create socket: %s",
401 wsa_strerror(WSAGetLastError()));
406 if(setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (void*)&on,
407 (socklen_t)sizeof(on)) < 0) {
409 log_err("setsockopt(.. SO_REUSEADDR ..) failed: %s",
412 log_err("setsockopt(.. SO_REUSEADDR ..) failed: %s",
413 wsa_strerror(WSAGetLastError()));
417 #endif /* SO_REUSEADDR */
418 #if defined(IPV6_V6ONLY)
419 if(addr->ai_family == AF_INET6 && v6only) {
420 if(setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY,
421 (void*)&on, (socklen_t)sizeof(on)) < 0) {
423 log_err("setsockopt(..., IPV6_V6ONLY, ...) failed: %s",
426 log_err("setsockopt(..., IPV6_V6ONLY, ...) failed: %s",
427 wsa_strerror(WSAGetLastError()));
434 #endif /* IPV6_V6ONLY */
435 if(bind(s, addr->ai_addr, addr->ai_addrlen) != 0) {
437 /* detect freebsd jail with no ipv6 permission */
438 if(addr->ai_family==AF_INET6 && errno==EINVAL)
441 log_err("can't bind socket: %s", strerror(errno));
442 log_addr(0, "failed address",
443 (struct sockaddr_storage*)addr->ai_addr,
447 log_err("can't bind socket: %s",
448 wsa_strerror(WSAGetLastError()));
449 log_addr(0, "failed address",
450 (struct sockaddr_storage*)addr->ai_addr,
455 if(!fd_set_nonblock(s)) {
458 if(listen(s, TCP_BACKLOG) == -1) {
460 log_err("can't listen: %s", strerror(errno));
462 log_err("can't listen: %s", wsa_strerror(WSAGetLastError()));
470 * Create socket from getaddrinfo results
473 make_sock(int stype, const char* ifname, const char* port,
474 struct addrinfo *hints, int v6only, int* noip6, size_t rcv, size_t snd)
476 struct addrinfo *res = NULL;
477 int r, s, inuse, noproto;
478 hints->ai_socktype = stype;
480 if((r=getaddrinfo(ifname, port, hints, &res)) != 0 || !res) {
482 if(r == EAI_NONAME && hints->ai_family == AF_INET6){
483 *noip6 = 1; /* 'Host not found' for IP6 on winXP */
487 log_err("node %s:%s getaddrinfo: %s %s",
488 ifname?ifname:"default", port, gai_strerror(r),
490 r==EAI_SYSTEM?(char*)strerror(errno):""
497 if(stype == SOCK_DGRAM) {
498 verbose_print_addr(res);
499 s = create_udp_sock(res->ai_family, res->ai_socktype,
500 (struct sockaddr*)res->ai_addr, res->ai_addrlen,
501 v6only, &inuse, &noproto, (int)rcv, (int)snd);
502 if(s == -1 && inuse) {
503 log_err("bind: address already in use");
504 } else if(s == -1 && noproto && hints->ai_family == AF_INET6){
508 s = create_tcp_accept_sock(res, v6only, &noproto);
509 if(s == -1 && noproto && hints->ai_family == AF_INET6){
517 /** make socket and first see if ifname contains port override info */
519 make_sock_port(int stype, const char* ifname, const char* port,
520 struct addrinfo *hints, int v6only, int* noip6, size_t rcv, size_t snd)
522 char* s = strchr(ifname, '@');
524 /* override port with ifspec@port */
527 if((size_t)(s-ifname) >= sizeof(newif)) {
528 log_err("ifname too long: %s", ifname);
532 if(strlen(s+1) >= sizeof(p)) {
533 log_err("portnumber too long: %s", ifname);
537 strncpy(newif, ifname, sizeof(newif));
539 strncpy(p, s+1, sizeof(p));
541 return make_sock(stype, newif, p, hints, v6only, noip6,
544 return make_sock(stype, ifname, port, hints, v6only, noip6, rcv, snd);
548 * Add port to open ports list.
549 * @param list: list head. changed.
551 * @param ftype: if fd is UDP.
552 * @return false on failure. list in unchanged then.
555 port_insert(struct listen_port** list, int s, enum listen_type ftype)
557 struct listen_port* item = (struct listen_port*)malloc(
558 sizeof(struct listen_port));
568 /** set fd to receive source address packet info */
570 set_recvpktinfo(int s, int family)
572 #if defined(IPV6_RECVPKTINFO) || defined(IPV6_PKTINFO) || (defined(IP_RECVDSTADDR) && defined(IP_SENDSRCADDR)) || defined(IP_PKTINFO)
577 if(family == AF_INET6) {
578 # ifdef IPV6_RECVPKTINFO
579 if(setsockopt(s, IPPROTO_IPV6, IPV6_RECVPKTINFO,
580 (void*)&on, (socklen_t)sizeof(on)) < 0) {
581 log_err("setsockopt(..., IPV6_RECVPKTINFO, ...) failed: %s",
585 # elif defined(IPV6_PKTINFO)
586 if(setsockopt(s, IPPROTO_IPV6, IPV6_PKTINFO,
587 (void*)&on, (socklen_t)sizeof(on)) < 0) {
588 log_err("setsockopt(..., IPV6_PKTINFO, ...) failed: %s",
593 log_err("no IPV6_RECVPKTINFO and no IPV6_PKTINFO option, please "
594 "disable interface-automatic in config");
596 # endif /* defined IPV6_RECVPKTINFO */
598 } else if(family == AF_INET) {
600 if(setsockopt(s, IPPROTO_IP, IP_PKTINFO,
601 (void*)&on, (socklen_t)sizeof(on)) < 0) {
602 log_err("setsockopt(..., IP_PKTINFO, ...) failed: %s",
606 # elif defined(IP_RECVDSTADDR) && defined(IP_SENDSRCADDR)
607 if(setsockopt(s, IPPROTO_IP, IP_RECVDSTADDR,
608 (void*)&on, (socklen_t)sizeof(on)) < 0) {
609 log_err("setsockopt(..., IP_RECVDSTADDR, ...) failed: %s",
614 log_err("no IP_SENDSRCADDR or IP_PKTINFO option, please disable "
615 "interface-automatic in config");
617 # endif /* IP_PKTINFO */
624 * Helper for ports_open. Creates one interface (or NULL for default).
625 * @param ifname: The interface ip address.
626 * @param do_auto: use automatic interface detection.
627 * If enabled, then ifname must be the wildcard name.
628 * @param do_udp: if udp should be used.
629 * @param do_tcp: if udp should be used.
630 * @param hints: for getaddrinfo. family and flags have to be set by caller.
631 * @param port: Port number to use (as string).
632 * @param list: list of open ports, appended to, changed to point to list head.
633 * @param rcv: receive buffer size for UDP
634 * @param snd: send buffer size for UDP
635 * @param ssl_port: ssl service port number
636 * @return: returns false on error.
639 ports_create_if(const char* ifname, int do_auto, int do_udp, int do_tcp,
640 struct addrinfo *hints, const char* port, struct listen_port** list,
641 size_t rcv, size_t snd, int ssl_port)
644 if(!do_udp && !do_tcp)
647 if((s = make_sock_port(SOCK_DGRAM, ifname, port, hints, 1,
648 &noip6, rcv, snd)) == -1) {
650 log_warn("IPv6 protocol not available");
655 /* getting source addr packet info is highly non-portable */
656 if(!set_recvpktinfo(s, hints->ai_family))
658 if(!port_insert(list, s, listen_type_udpancil)) {
667 /* regular udp socket */
668 if((s = make_sock_port(SOCK_DGRAM, ifname, port, hints, 1,
669 &noip6, rcv, snd)) == -1) {
671 log_warn("IPv6 protocol not available");
676 if(!port_insert(list, s, listen_type_udp)) {
686 int is_ssl = ((strchr(ifname, '@') &&
687 atoi(strchr(ifname, '@')+1) == ssl_port) ||
688 (!strchr(ifname, '@') && atoi(port) == ssl_port));
689 if((s = make_sock_port(SOCK_STREAM, ifname, port, hints, 1,
690 &noip6, 0, 0)) == -1) {
692 /*log_warn("IPv6 protocol not available");*/
698 verbose(VERB_ALGO, "setup TCP for SSL service");
699 if(!port_insert(list, s, is_ssl?listen_type_ssl:
713 * Add items to commpoint list in front.
714 * @param c: commpoint to add.
715 * @param front: listen struct.
716 * @return: false on failure.
719 listen_cp_insert(struct comm_point* c, struct listen_dnsport* front)
721 struct listen_list* item = (struct listen_list*)malloc(
722 sizeof(struct listen_list));
726 item->next = front->cps;
731 struct listen_dnsport*
732 listen_create(struct comm_base* base, struct listen_port* ports,
733 size_t bufsize, int tcp_accept_count, void* sslctx,
734 comm_point_callback_t* cb, void *cb_arg)
736 struct listen_dnsport* front = (struct listen_dnsport*)
737 malloc(sizeof(struct listen_dnsport));
741 front->udp_buff = ldns_buffer_new(bufsize);
742 if(!front->udp_buff) {
747 /* create comm points as needed */
749 struct comm_point* cp = NULL;
750 if(ports->ftype == listen_type_udp)
751 cp = comm_point_create_udp(base, ports->fd,
752 front->udp_buff, cb, cb_arg);
753 else if(ports->ftype == listen_type_tcp)
754 cp = comm_point_create_tcp(base, ports->fd,
755 tcp_accept_count, bufsize, cb, cb_arg);
756 else if(ports->ftype == listen_type_ssl) {
757 cp = comm_point_create_tcp(base, ports->fd,
758 tcp_accept_count, bufsize, cb, cb_arg);
760 } else if(ports->ftype == listen_type_udpancil)
761 cp = comm_point_create_udp_ancil(base, ports->fd,
762 front->udp_buff, cb, cb_arg);
764 log_err("can't create commpoint");
765 listen_delete(front);
768 cp->do_not_close = 1;
769 if(!listen_cp_insert(cp, front)) {
770 log_err("malloc failed");
771 comm_point_delete(cp);
772 listen_delete(front);
778 log_err("Could not open sockets to accept queries.");
779 listen_delete(front);
787 listen_list_delete(struct listen_list* list)
789 struct listen_list *p = list, *pn;
792 comm_point_delete(p->com);
799 listen_delete(struct listen_dnsport* front)
803 listen_list_delete(front->cps);
804 ldns_buffer_free(front->udp_buff);
809 listening_ports_open(struct config_file* cfg)
811 struct listen_port* list = NULL;
812 struct addrinfo hints;
813 int i, do_ip4, do_ip6;
816 snprintf(portbuf, sizeof(portbuf), "%d", cfg->port);
817 do_ip4 = cfg->do_ip4;
818 do_ip6 = cfg->do_ip6;
819 do_tcp = cfg->do_tcp;
820 do_auto = cfg->if_automatic && cfg->do_udp;
821 if(cfg->incoming_num_tcp == 0)
825 memset(&hints, 0, sizeof(hints));
826 hints.ai_flags = AI_PASSIVE;
827 /* no name lookups on our listening ports */
829 hints.ai_flags |= AI_NUMERICHOST;
830 hints.ai_family = AF_UNSPEC;
834 if(!do_ip4 && !do_ip6) {
837 /* create ip4 and ip6 ports so that return addresses are nice. */
838 if(do_auto || cfg->num_ifs == 0) {
840 hints.ai_family = AF_INET6;
841 if(!ports_create_if(do_auto?"::0":"::1",
842 do_auto, cfg->do_udp, do_tcp,
843 &hints, portbuf, &list,
844 cfg->so_rcvbuf, cfg->so_sndbuf,
846 listening_ports_free(list);
851 hints.ai_family = AF_INET;
852 if(!ports_create_if(do_auto?"0.0.0.0":"127.0.0.1",
853 do_auto, cfg->do_udp, do_tcp,
854 &hints, portbuf, &list,
855 cfg->so_rcvbuf, cfg->so_sndbuf,
857 listening_ports_free(list);
861 } else for(i = 0; i<cfg->num_ifs; i++) {
862 if(str_is_ip6(cfg->ifs[i])) {
865 hints.ai_family = AF_INET6;
866 if(!ports_create_if(cfg->ifs[i], 0, cfg->do_udp,
867 do_tcp, &hints, portbuf, &list,
868 cfg->so_rcvbuf, cfg->so_sndbuf,
870 listening_ports_free(list);
876 hints.ai_family = AF_INET;
877 if(!ports_create_if(cfg->ifs[i], 0, cfg->do_udp,
878 do_tcp, &hints, portbuf, &list,
879 cfg->so_rcvbuf, cfg->so_sndbuf,
881 listening_ports_free(list);
889 void listening_ports_free(struct listen_port* list)
891 struct listen_port* nx;
898 closesocket(list->fd);
906 size_t listen_get_mem(struct listen_dnsport* listen)
908 size_t s = sizeof(*listen) + sizeof(*listen->base) +
909 sizeof(*listen->udp_buff) +
910 ldns_buffer_capacity(listen->udp_buff);
911 struct listen_list* p;
912 for(p = listen->cps; p; p = p->next) {
914 s += comm_point_get_mem(p->com);
919 void listen_stop_accept(struct listen_dnsport* listen)
921 /* do not stop the ones that have no tcp_free list
922 * (they have already stopped listening) */
923 struct listen_list* p;
924 for(p=listen->cps; p; p=p->next) {
925 if(p->com->type == comm_tcp_accept &&
926 p->com->tcp_free != NULL) {
927 comm_point_stop_listening(p->com);
932 void listen_start_accept(struct listen_dnsport* listen)
934 /* do not start the ones that have no tcp_free list, it is no
935 * use to listen to them because they have no free tcp handlers */
936 struct listen_list* p;
937 for(p=listen->cps; p; p=p->next) {
938 if(p->com->type == comm_tcp_accept &&
939 p->com->tcp_free != NULL) {
940 comm_point_start_listening(p->com, -1, -1);