]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
mingw port continues.
authorWouter Wijngaards <wouter@nlnetlabs.nl>
Wed, 25 Jun 2008 14:36:10 +0000 (14:36 +0000)
committerWouter Wijngaards <wouter@nlnetlabs.nl>
Wed, 25 Jun 2008 14:36:10 +0000 (14:36 +0000)
git-svn-id: file:///svn/unbound/trunk@1139 be551aaa-1e26-0410-a405-d3ace91eadb9

doc/Changelog
doc/TODO
libunbound/libunbound.c
services/listen_dnsport.c
testcode/delayer.c
testdata/05-asynclook.tpkg
testdata/hostsfileosx.tpkg
util/config_file.c
util/netevent.c
util/winsock_event.h

index cd14132c105be4b0d087cb393ade4166f46a20ef..096ad37bf9fb4a09aadd53422917821c259d34fd 100644 (file)
@@ -2,6 +2,8 @@
        - fixup fwd_ancil test typos.
        - Fix for newegg lameness : ok for qtype=A, but lame for others.
        - fixup unit test for infra cache, test lame merging.
+       - porting to mingw, bind, listen, getsockopt and setsockopt error
+         handling.
 
 24 June 2008: Wouter
        - removed testcode/checklocks from production code compilation path.
index 9e04a77a33ad9eb1b3626da83df931e1fbbdfd09..a2aa108e4116d0c4dab4930c89be297f11df61fa 100644 (file)
--- a/doc/TODO
+++ b/doc/TODO
@@ -69,3 +69,8 @@ o command channel for couple of tasks. Like rndc.
   o add/del static preload data to change the domain redirections.
   o and maybe also start, stop, reload.
 
+
+o on windows version, libunbound uses a NamedPipe, examine security status
+  make sure the OS makes it safe like on unix.
+o on windows version, implement that OS ancillary data capabilities for
+  interface-automatic. IPPKTINFO, IP6PKTINFO for WSARecvMsg, WSASendMsg.
index 8cb146304e3d305d8ce83177270b235b59f2b8bf..4b7a6d5e3a9f1fb4c68e2fa130f52a41a259dcbf 100644 (file)
@@ -109,6 +109,7 @@ ub_ctx_create()
                errno = e;
                return NULL;
        }
+#ifndef USE_WINSOCK
        if(!fd_set_nonblock(ctx->rrpipe[0]) ||
           !fd_set_nonblock(ctx->rrpipe[1]) ||
           !fd_set_nonblock(ctx->qqpipe[0]) ||
@@ -123,6 +124,7 @@ ub_ctx_create()
                errno = e;
                return NULL;
        }
+#endif /* !USE_WINSOCK - it is a pipe(nonsocket) on windows) */
        lock_basic_init(&ctx->qqpipe_lock);
        lock_basic_init(&ctx->rrpipe_lock);
        lock_basic_init(&ctx->cfglock);
index c054c268cb2a3248504e215decce8fae59b15887..2e8c46eaf35080e0a4fea1560aded2a12b995e74 100644 (file)
@@ -123,8 +123,14 @@ create_udp_sock(int family, int socktype, struct sockaddr* addr,
                        int val=(v6only==2)?0:1;
                        if (setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY, 
                                (void*)&val, (socklen_t)sizeof(val)) < 0) {
+#ifndef USE_WINSOCK
                                log_err("setsockopt(..., IPV6_V6ONLY"
                                        ", ...) failed: %s", strerror(errno));
+#else
+                               log_err("setsockopt(..., IPV6_V6ONLY"
+                                       ", ...) failed: %s", 
+                                       wsa_strerror(WSAGetLastError()));
+#endif
                                close(s);
                                *noproto = 0;
                                *inuse = 0;
@@ -143,8 +149,14 @@ create_udp_sock(int family, int socktype, struct sockaddr* addr,
                 */
                if (setsockopt(s, IPPROTO_IPV6, IPV6_USE_MIN_MTU,
                        (void*)&on, (socklen_t)sizeof(on)) < 0) {
+#ifndef USE_WINSOCK
                        log_err("setsockopt(..., IPV6_USE_MIN_MTU, "
                                "...) failed: %s", strerror(errno));
+#else
+                       log_err("setsockopt(..., IPV6_USE_MIN_MTU, "
+                               "...) failed: %s", 
+                               wsa_strerror(WSAGetLastError()));
+#endif
                        close(s);
                        *noproto = 0;
                        *inuse = 0;
@@ -154,11 +166,18 @@ create_udp_sock(int family, int socktype, struct sockaddr* addr,
        }
        if(bind(s, (struct sockaddr*)addr, addrlen) != 0) {
                *noproto = 0;
+#ifndef USE_WINSOCK
 #ifdef EADDRINUSE
                *inuse = (errno == EADDRINUSE);
                if(errno != EADDRINUSE)
-#endif
                        log_err("can't bind socket: %s", strerror(errno));
+#endif
+#else /* USE_WINSOCK */
+               if(WSAGetLastError() != WSAEADDRINUSE &&
+                       WSAGetLastError() != WSAEADDRNOTAVAIL)
+#endif
+                       log_err("can't bind socket: %s", 
+                               wsa_strerror(WSAGetLastError()));
                close(s);
                return -1;
        }
@@ -208,8 +227,13 @@ create_tcp_accept_sock(struct addrinfo *addr, int v6only, int* noproto)
 #ifdef SO_REUSEADDR
        if(setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (void*)&on, 
                (socklen_t)sizeof(on)) < 0) {
+#ifndef USE_WINSOCK
                log_err("setsockopt(.. SO_REUSEADDR ..) failed: %s",
                        strerror(errno));
+#else
+               log_err("setsockopt(.. SO_REUSEADDR ..) failed: %s",
+                       wsa_strerror(WSAGetLastError()));
+#endif
                return -1;
        }
 #endif /* SO_REUSEADDR */
@@ -217,8 +241,13 @@ create_tcp_accept_sock(struct addrinfo *addr, int v6only, int* noproto)
        if(addr->ai_family == AF_INET6 && v6only) {
                if(setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY, 
                        (void*)&on, (socklen_t)sizeof(on)) < 0) {
+#ifndef USE_WINSOCK
                        log_err("setsockopt(..., IPV6_V6ONLY, ...) failed: %s",
                                strerror(errno));
+#else
+                       log_err("setsockopt(..., IPV6_V6ONLY, ...) failed: %s",
+                               wsa_strerror(WSAGetLastError()));
+#endif
                        return -1;
                }
        }
@@ -226,14 +255,23 @@ create_tcp_accept_sock(struct addrinfo *addr, int v6only, int* noproto)
        (void)v6only;
 #endif /* IPV6_V6ONLY */
        if(bind(s, addr->ai_addr, addr->ai_addrlen) != 0) {
+#ifndef USE_WINSOCK
                log_err("can't bind socket: %s", strerror(errno));
+#else
+               log_err("can't bind socket: %s", 
+                       wsa_strerror(WSAGetLastError()));
+#endif
                return -1;
        }
        if(!fd_set_nonblock(s)) {
                return -1;
        }
        if(listen(s, TCP_BACKLOG) == -1) {
+#ifndef USE_WINSOCK
                log_err("can't listen: %s", strerror(errno));
+#else
+               log_err("can't listen: %s", wsa_strerror(WSAGetLastError()));
+#endif
                return -1;
        }
        return s;
index f6e089571123ed566e83dc18b60f644cc27dfd96..4bf8d98e73665e55bb228471c7147be366e26b00 100644 (file)
@@ -1025,7 +1025,11 @@ service(char* bind_str, int bindport, char* serv_str, size_t memsize,
                        exit(1);
                }
                if(bind(s, (struct sockaddr*)&bind_addr, bind_len) == -1) {
+#ifndef USE_WINSOCK
                        log_err("bind: %s", strerror(errno));
+#else
+                       log_err("bind: %s", wsa_strerror(WSAGetLastError()));
+#endif
                        if(i--==0)
                                fatal_exit("cannot bind any port");
                        bindport = 1024 + random()%64000;
@@ -1046,14 +1050,29 @@ service(char* bind_str, int bindport, char* serv_str, size_t memsize,
                int on = 1;
                if(setsockopt(listen_s, SOL_SOCKET, SO_REUSEADDR, (void*)&on,
                        (socklen_t)sizeof(on)) < 0)
+#ifndef USE_WINSOCK
                        fatal_exit("setsockopt(.. SO_REUSEADDR ..) failed: %s",
                                strerror(errno));
+#else
+                       fatal_exit("setsockopt(.. SO_REUSEADDR ..) failed: %s",
+                               wsa_strerror(WSAGetLastError()));
+#endif
        }
 #endif
-       if(bind(listen_s, (struct sockaddr*)&bind_addr, bind_len) == -1)
+       if(bind(listen_s, (struct sockaddr*)&bind_addr, bind_len) == -1) {
+#ifndef USE_WINSOCK
                fatal_exit("tcp bind: %s", strerror(errno));
-       if(listen(listen_s, 5) == -1)
+#else
+               fatal_exit("tcp bind: %s", wsa_strerror(WSAGetLastError()));
+#endif
+       }
+       if(listen(listen_s, 5) == -1) {
+#ifndef USE_WINSOCK
                fatal_exit("tcp listen: %s", strerror(errno));
+#else
+               fatal_exit("tcp listen: %s", wsa_strerror(WSAGetLastError()));
+#endif
+       }
        fd_set_nonblock(listen_s);
        printf("listening on port: %d\n", bindport);
 
index 128328d657f4a945bcdce7aa26b11e4f75a39561..941a46aae5afe971bbcc22a409958748f0b4af4a 100644 (file)
Binary files a/testdata/05-asynclook.tpkg and b/testdata/05-asynclook.tpkg differ
index e12de40bba9a78b1f2ac5aa0c4f437eb9c4c0b4c..1e0ead059882c3d1af786190100806413d6a6cd0 100644 (file)
Binary files a/testdata/hostsfileosx.tpkg and b/testdata/hostsfileosx.tpkg differ
index 5f806c3c56bae30376baf92a7a8d865ba0e17cd0..a4cb912763fc28ec91932618f78f6de109a1ec0d 100644 (file)
@@ -85,7 +85,7 @@ config_create()
 #ifndef USE_WINSOCK
        cfg->outgoing_num_ports = 256;
 #else
-       cfg->outgoing_num_ports = 32; /* windows is limited in num fds */
+       cfg->outgoing_num_ports = 16; /* windows is limited in num fds */
 #endif
        cfg->outgoing_num_tcp = 10;
        cfg->incoming_num_tcp = 10;
index 3e5e1c99102db3f484a4747e1ac9220aec7171e9..47bec1863a69e4d456975ad13f954b6200ac909d 100644 (file)
@@ -762,8 +762,13 @@ comm_point_tcp_handle_write(int fd, struct comm_point* c)
                socklen_t len = (socklen_t)sizeof(error);
                if(getsockopt(fd, SOL_SOCKET, SO_ERROR, (void*)&error, 
                        &len) < 0){
+#ifndef USE_WINSOCK
                        error = errno; /* on solaris errno is error */
+#else /* USE_WINSOCK */
+                       error = WSAGetLastError();
+#endif
                }
+#ifndef USE_WINSOCK
 #if defined(EINPROGRESS) && defined(EWOULDBLOCK)
                if(error == EINPROGRESS || error == EWOULDBLOCK)
                        return 1; /* try again later */
@@ -778,6 +783,18 @@ comm_point_tcp_handle_write(int fd, struct comm_point* c)
 #endif
                 else if(error != 0) {
                        log_err("tcp connect: %s", strerror(error));
+#else /* USE_WINSOCK */
+               /* examine error */
+               if(error == WSAEINPROGRESS)
+                       return 1;
+               else if(error == WSAEWOULDBLOCK) {
+                       winsock_tcp_wouldblock(&c->ev->ev, EV_WRITE);
+                       return 1;
+               } else if(error == WSAECONNREFUSED || error == WSAEHOSTUNREACH)
+                       return 0;
+               else if(error != 0) {
+                       log_err("tcp connect: %s", wsa_strerror(error));
+#endif /* USE_WINSOCK */
                        log_addr(0, "remote address is", &c->repinfo.addr, 
                                c->repinfo.addrlen);
                        return 0;
index 2851b0eeb99e204a527fe9b6aae3d36e6e0d862e..86ea9c8d0101dab9ab094d7aa235059ebdfc19c4 100644 (file)
  * not read() and write(), those work only on files.
  *
  * Also fseek and fseeko do not work if a FILE is not fopen-ed in binary mode.
+ *
+ * When under a high load windows gives out lots of errors, from recvfrom
+ * on udp sockets for example (WSAECONNRESET). Even though the udp socket
+ * has no connection per se.
  */
 
 #ifndef UTIL_WINSOCK_EVENT_H