]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
keep tcp address around for acl.
authorWouter Wijngaards <wouter@nlnetlabs.nl>
Mon, 19 Nov 2007 16:31:22 +0000 (16:31 +0000)
committerWouter Wijngaards <wouter@nlnetlabs.nl>
Mon, 19 Nov 2007 16:31:22 +0000 (16:31 +0000)
git-svn-id: file:///svn/unbound/trunk@770 be551aaa-1e26-0410-a405-d3ace91eadb9

doc/Changelog
services/outside_network.c
testcode/replay.c
util/netevent.c
util/netevent.h

index 5a306672684611b0e8439125fe1d72dd30250ede..94b644832c4c4ab17d54764b7161b340b634714a 100644 (file)
@@ -9,6 +9,7 @@
          and unit test for addr_in_common().
        - 0.8: access-control config file element.
          and unit test rpl replay file.
+       - 0.8: fixup address reporting from netevent.
 
 16 November 2007: Wouter
        - privilege separation is not needed in unbound at this time.
index 4ccce3cde7c3a4ff3a11b96bff53e3b59fe1a085..a46ba49d270838d6bcacfac9751dec13eaed9869 100644 (file)
@@ -150,6 +150,8 @@ outnet_tcp_take_into_use(struct waiting_tcp* w, uint8_t* pkt, size_t pkt_len)
        w->outnet->tcp_free = pend->next_free;
        pend->next_free = NULL;
        pend->query = w;
+       pend->c->repinfo.addrlen = w->addrlen;
+       memcpy(&pend->c->repinfo.addr, &w->addr, w->addrlen);
        ldns_buffer_clear(pend->c->buffer);
        ldns_buffer_write(pend->c->buffer, pkt, pkt_len);
        ldns_buffer_flip(pend->c->buffer);
index 512c7579521ef60052b068468fc7cfc79ae3eca1..4d5da932cf051c68631e693f4ec51553f3324f51 100644 (file)
@@ -208,6 +208,8 @@ replay_moment_read(char* remain, FILE* in, const char* name, int* lineno,
        } else if(parse_keyword(&remain, "QUERY")) {
                mom->evt_type = repevt_front_query;
                readentry = 1;
+               if(!extstrtoaddr("127.0.0.1", &mom->addr, &mom->addrlen))
+                       fatal_exit("internal error");
        } else if(parse_keyword(&remain, "CHECK_ANSWER")) {
                mom->evt_type = repevt_front_reply;
                readentry = 1;
@@ -240,7 +242,7 @@ replay_moment_read(char* remain, FILE* in, const char* name, int* lineno,
                        free(mom);
                        return NULL;
                }
-       }
+       } 
 
        if(readentry) {
                mom->match = read_entry(in, name, lineno, ttl, or, prev);
index 64cc5ee73228bb5ab0050362b6b799dea6a858b1..6b41cd411317c0fe4f589619c1b8890468219388 100644 (file)
@@ -229,18 +229,23 @@ void
 comm_point_tcp_accept_callback(int fd, short event, void* arg)
 {
        struct comm_point* c = (struct comm_point*)arg, *c_hdl;
-       struct comm_reply rep;
        int new_fd;
        log_assert(c->type == comm_tcp_accept);
        if(!(event & EV_READ)) {
                log_info("ignoring tcp accept event %d", (int)event);
                return;
        }
+       /* find free tcp handler. */
+       if(!c->tcp_free) {
+               log_warn("accepted too many tcp, connections full");
+               return;
+       }
        /* accept incoming connection. */
-       rep.c = NULL;
-       rep.addrlen = (socklen_t)sizeof(rep.addr);
+       c_hdl = c->tcp_free;
+       c_hdl->repinfo.addrlen = (socklen_t)sizeof(c_hdl->repinfo.addr);
        log_assert(fd != -1);
-       new_fd = accept(fd, (struct sockaddr*)&rep.addr, &rep.addrlen);
+       new_fd = accept(fd, (struct sockaddr*)&c_hdl->repinfo.addr, 
+               &c_hdl->repinfo.addrlen);
        if(new_fd == -1) {
                /* EINTR is signal interrupt. others are closed connection. */
                if(     errno != EINTR 
@@ -254,14 +259,7 @@ comm_point_tcp_accept_callback(int fd, short event, void* arg)
                log_err("accept failed: %s", strerror(errno));
                return;
        }
-       /* find free tcp handler. */
-       if(!c->tcp_free) {
-               log_err("accepted too many tcp, connections full");
-               close(new_fd);
-               return;
-       }
-       /* grab it */
-       c_hdl = c->tcp_free;
+       /* grab the tcp handler buffers */
        c->tcp_free = c_hdl->tcp_free;
        if(!c->tcp_free) {
                /* stop accepting incoming queries for now. */
@@ -307,7 +305,6 @@ tcp_callback_writer(struct comm_point* c)
 static void
 tcp_callback_reader(struct comm_point* c)
 {
-       struct comm_reply rep;
        log_assert(c->type == comm_tcp || c->type == comm_local);
        ldns_buffer_flip(c->buffer);
        if(c->tcp_do_toggle_rw)
@@ -315,10 +312,8 @@ tcp_callback_reader(struct comm_point* c)
        c->tcp_byte_count = 0;
        if(c->type == comm_tcp)
                comm_point_stop_listening(c);
-       rep.c = c;
-       rep.addrlen = 0;
        log_assert(fptr_whitelist_comm_point(c->callback));
-       if( (*c->callback)(c, c->cb_arg, NETEVENT_NOERROR, &rep) ) {
+       if( (*c->callback)(c, c->cb_arg, NETEVENT_NOERROR, &c->repinfo) ) {
                comm_point_start_listening(c, -1, TCP_QUERY_TIMEOUT);
        }
 }
@@ -608,6 +603,7 @@ comm_point_create_tcp_handler(struct comm_base *base,
        c->do_not_close = 0;
        c->tcp_do_toggle_rw = 1;
        c->tcp_check_nb_connect = 0;
+       c->repinfo.c = c;
        c->callback = callback;
        c->cb_arg = callback_arg;
        /* add to parent free list */
@@ -724,6 +720,7 @@ comm_point_create_tcp_out(struct comm_base *base, size_t bufsize,
        c->do_not_close = 0;
        c->tcp_do_toggle_rw = 1;
        c->tcp_check_nb_connect = 1;
+       c->repinfo.c = c;
        c->callback = callback;
        c->cb_arg = callback_arg;
        evbits = EV_PERSIST | EV_WRITE;
index c63944e39671e140bab6e49fd2420e5f9ef5d699..cae79e5a77804e7af0e5b983fe978945237bbaf6 100644 (file)
@@ -88,6 +88,18 @@ struct comm_base {
        struct internal_base* eb;
 };
 
+/**
+ * Reply information for a communication point.
+ */
+struct comm_reply {
+       /** the comm_point with fd to send reply on to. */
+       struct comm_point* c;
+       /** the address (for UDP based communication) */
+       struct sockaddr_storage addr;
+       /** length of address */
+       socklen_t addrlen;
+};
+
 /** 
  * Communication point to the network 
  * These behaviours can be accomplished by setting the flags
@@ -117,6 +129,8 @@ struct comm_point {
        size_t tcp_byte_count;
        /** parent communication point (for TCP sockets) */
        struct comm_point* tcp_parent;
+       /** sockaddr from peer, for TCP handlers */
+       struct comm_reply repinfo;
 
        /* -------- TCP Accept -------- */
        /** the number of TCP handlers for this tcp-accept socket */
@@ -187,18 +201,6 @@ struct comm_point {
        void *cb_arg;
 };
 
-/**
- * Reply information for a communication point.
- */
-struct comm_reply {
-       /** the comm_point with fd to send reply on to. */
-       struct comm_point* c;
-       /** the address (for UDP based communication) */
-       struct sockaddr_storage addr;
-       /** length of address */
-       socklen_t addrlen;
-};
-
 /**
  * Structure only for making timeout events.
  */