keep tcp address around for acl.

git-svn-id: file:///svn/unbound/trunk@770 be551aaa-1e26-0410-a405-d3ace91eadb9
This commit is contained in:
Wouter Wijngaards 2007-11-19 16:31:22 +00:00
parent eda6528c14
commit b9c417481b
5 changed files with 33 additions and 29 deletions

View file

@ -9,6 +9,7 @@
and unit test for addr_in_common(). and unit test for addr_in_common().
- 0.8: access-control config file element. - 0.8: access-control config file element.
and unit test rpl replay file. and unit test rpl replay file.
- 0.8: fixup address reporting from netevent.
16 November 2007: Wouter 16 November 2007: Wouter
- privilege separation is not needed in unbound at this time. - privilege separation is not needed in unbound at this time.

View 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; w->outnet->tcp_free = pend->next_free;
pend->next_free = NULL; pend->next_free = NULL;
pend->query = w; 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_clear(pend->c->buffer);
ldns_buffer_write(pend->c->buffer, pkt, pkt_len); ldns_buffer_write(pend->c->buffer, pkt, pkt_len);
ldns_buffer_flip(pend->c->buffer); ldns_buffer_flip(pend->c->buffer);

View file

@ -208,6 +208,8 @@ replay_moment_read(char* remain, FILE* in, const char* name, int* lineno,
} else if(parse_keyword(&remain, "QUERY")) { } else if(parse_keyword(&remain, "QUERY")) {
mom->evt_type = repevt_front_query; mom->evt_type = repevt_front_query;
readentry = 1; readentry = 1;
if(!extstrtoaddr("127.0.0.1", &mom->addr, &mom->addrlen))
fatal_exit("internal error");
} else if(parse_keyword(&remain, "CHECK_ANSWER")) { } else if(parse_keyword(&remain, "CHECK_ANSWER")) {
mom->evt_type = repevt_front_reply; mom->evt_type = repevt_front_reply;
readentry = 1; readentry = 1;

View file

@ -229,18 +229,23 @@ void
comm_point_tcp_accept_callback(int fd, short event, void* arg) comm_point_tcp_accept_callback(int fd, short event, void* arg)
{ {
struct comm_point* c = (struct comm_point*)arg, *c_hdl; struct comm_point* c = (struct comm_point*)arg, *c_hdl;
struct comm_reply rep;
int new_fd; int new_fd;
log_assert(c->type == comm_tcp_accept); log_assert(c->type == comm_tcp_accept);
if(!(event & EV_READ)) { if(!(event & EV_READ)) {
log_info("ignoring tcp accept event %d", (int)event); log_info("ignoring tcp accept event %d", (int)event);
return; return;
} }
/* find free tcp handler. */
if(!c->tcp_free) {
log_warn("accepted too many tcp, connections full");
return;
}
/* accept incoming connection. */ /* accept incoming connection. */
rep.c = NULL; c_hdl = c->tcp_free;
rep.addrlen = (socklen_t)sizeof(rep.addr); c_hdl->repinfo.addrlen = (socklen_t)sizeof(c_hdl->repinfo.addr);
log_assert(fd != -1); 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) { if(new_fd == -1) {
/* EINTR is signal interrupt. others are closed connection. */ /* EINTR is signal interrupt. others are closed connection. */
if( errno != EINTR 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)); log_err("accept failed: %s", strerror(errno));
return; return;
} }
/* find free tcp handler. */ /* grab the tcp handler buffers */
if(!c->tcp_free) {
log_err("accepted too many tcp, connections full");
close(new_fd);
return;
}
/* grab it */
c_hdl = c->tcp_free;
c->tcp_free = c_hdl->tcp_free; c->tcp_free = c_hdl->tcp_free;
if(!c->tcp_free) { if(!c->tcp_free) {
/* stop accepting incoming queries for now. */ /* stop accepting incoming queries for now. */
@ -307,7 +305,6 @@ tcp_callback_writer(struct comm_point* c)
static void static void
tcp_callback_reader(struct comm_point* c) tcp_callback_reader(struct comm_point* c)
{ {
struct comm_reply rep;
log_assert(c->type == comm_tcp || c->type == comm_local); log_assert(c->type == comm_tcp || c->type == comm_local);
ldns_buffer_flip(c->buffer); ldns_buffer_flip(c->buffer);
if(c->tcp_do_toggle_rw) if(c->tcp_do_toggle_rw)
@ -315,10 +312,8 @@ tcp_callback_reader(struct comm_point* c)
c->tcp_byte_count = 0; c->tcp_byte_count = 0;
if(c->type == comm_tcp) if(c->type == comm_tcp)
comm_point_stop_listening(c); comm_point_stop_listening(c);
rep.c = c;
rep.addrlen = 0;
log_assert(fptr_whitelist_comm_point(c->callback)); 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); 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->do_not_close = 0;
c->tcp_do_toggle_rw = 1; c->tcp_do_toggle_rw = 1;
c->tcp_check_nb_connect = 0; c->tcp_check_nb_connect = 0;
c->repinfo.c = c;
c->callback = callback; c->callback = callback;
c->cb_arg = callback_arg; c->cb_arg = callback_arg;
/* add to parent free list */ /* 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->do_not_close = 0;
c->tcp_do_toggle_rw = 1; c->tcp_do_toggle_rw = 1;
c->tcp_check_nb_connect = 1; c->tcp_check_nb_connect = 1;
c->repinfo.c = c;
c->callback = callback; c->callback = callback;
c->cb_arg = callback_arg; c->cb_arg = callback_arg;
evbits = EV_PERSIST | EV_WRITE; evbits = EV_PERSIST | EV_WRITE;

View file

@ -88,6 +88,18 @@ struct comm_base {
struct internal_base* eb; 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 * Communication point to the network
* These behaviours can be accomplished by setting the flags * These behaviours can be accomplished by setting the flags
@ -117,6 +129,8 @@ struct comm_point {
size_t tcp_byte_count; size_t tcp_byte_count;
/** parent communication point (for TCP sockets) */ /** parent communication point (for TCP sockets) */
struct comm_point* tcp_parent; struct comm_point* tcp_parent;
/** sockaddr from peer, for TCP handlers */
struct comm_reply repinfo;
/* -------- TCP Accept -------- */ /* -------- TCP Accept -------- */
/** the number of TCP handlers for this tcp-accept socket */ /** the number of TCP handlers for this tcp-accept socket */
@ -187,18 +201,6 @@ struct comm_point {
void *cb_arg; 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. * Structure only for making timeout events.
*/ */