return 0;
}
+int worker_handle_reply(struct comm_point* ATTR_UNUSED(c),
+ void* ATTR_UNUSED(arg), int ATTR_UNUSED(error),
+ struct comm_reply* ATTR_UNUSED(reply_info))
+{
+ log_assert(0);
+ return 0;
+}
+
+int worker_handle_service_reply(struct comm_point* ATTR_UNUSED(c),
+ void* ATTR_UNUSED(arg), int ATTR_UNUSED(error),
+ struct comm_reply* ATTR_UNUSED(reply_info))
+{
+ log_assert(0);
+ return 0;
+}
+
void worker_sighandler(int ATTR_UNUSED(sig), void* ATTR_UNUSED(arg))
{
log_assert(0);
log_err("write socket: %s", strerror(errno));
}
-/** process incoming replies from the network */
-static int
+int
worker_handle_reply(struct comm_point* c, void* arg, int error,
struct comm_reply* reply_info)
{
return 0;
}
-/** process incoming serviced query replies from the network */
-static int
+int
worker_handle_service_reply(struct comm_point* c, void* arg, int error,
struct comm_reply* reply_info)
{
int worker_handle_request(struct comm_point* c, void* arg, int error,
struct comm_reply* repinfo);
+/** process incoming replies from the network */
+int worker_handle_reply(struct comm_point* c, void* arg, int error,
+ struct comm_reply* reply_info);
+
+/** process incoming serviced query replies from the network */
+int worker_handle_service_reply(struct comm_point* c, void* arg, int error,
+ struct comm_reply* reply_info);
+
#endif /* DAEMON_WORKER_H */
+5 October 2007: Wouter
+ - function pointer whitelist.
+
4 October 2007: Wouter
- overwrite sensitive random seed value after use.
- switch to logfile very soon if not -d (console attached).
#include "util/log.h"
#include "util/net_help.h"
#include "util/random.h"
+#include "util/fptr_wlist.h"
#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
/** number of retries on outgoing UDP queries */
#define OUTBOUND_UDP_RETRY 4
-/** callback for serviced query UDP answers */
-static int serviced_udp_callback(struct comm_point* c, void* arg, int error,
- struct comm_reply* rep);
/** initiate TCP transaction for serviced query */
static void serviced_tcp_initiate(struct outside_network* outnet,
struct serviced_query* sq, ldns_buffer* buff);
comm_point_callback_t* cb = w->cb;
void* cb_arg = w->cb_arg;
waiting_tcp_delete(w);
+ log_assert(fptr_whitelist_pending_tcp(cb));
(void)(*cb)(NULL, cb_arg, NETEVENT_CLOSED, NULL);
}
}
use_free_buffer(outnet);
}
-/** callback for pending tcp connections */
-static int
+int
outnet_tcp_cb(struct comm_point* c, void* arg, int error,
struct comm_reply *reply_info)
{
error = NETEVENT_CLOSED;
}
}
+ log_assert(fptr_whitelist_pending_tcp(pend->query->cb));
(void)(*pend->query->cb)(c, pend->query->cb_arg, error, reply_info);
decomission_pending_tcp(outnet, pend);
return 0;
verbose(VERB_ALGO, "outnet handle udp reply");
/* delete from tree first in case callback creates a retry */
(void)rbtree_delete(outnet->pending, p->node.key);
+ log_assert(fptr_whitelist_pending_udp(p->cb));
(void)(*p->cb)(p->c, p->cb_arg, NETEVENT_NOERROR, reply_info);
pending_delete(NULL, p);
return 0;
struct pending* p = (struct pending*)arg;
/* it timed out */
verbose(VERB_ALGO, "timeout udp");
+ log_assert(fptr_whitelist_pending_udp(p->cb));
(void)(*p->cb)(p->c, p->cb_arg, NETEVENT_TIMEOUT, NULL);
pending_delete(p->outnet, p);
}
cb = w->cb;
cb_arg = w->cb_arg;
waiting_tcp_delete(w);
+ log_assert(fptr_whitelist_pending_tcp(cb));
(void)(*cb)(NULL, cb_arg, NETEVENT_TIMEOUT, NULL);
use_free_buffer(outnet);
}
ldns_buffer_write(c->buffer, backup_p, backlen);
ldns_buffer_flip(c->buffer);
}
+ log_assert(fptr_whitelist_serviced_query(p->cb));
(void)(*p->cb)(c, p->cb_arg, error, rep);
p = n;
}
serviced_delete(sq);
}
-/** TCP reply or error callback for serviced queries */
-static int
+int
serviced_tcp_callback(struct comm_point* c, void* arg, int error,
struct comm_reply* rep)
{
}
}
-static int
+int
serviced_udp_callback(struct comm_point* c, void* arg, int error,
struct comm_reply* rep)
{
int outnet_udp_cb(struct comm_point* c, void* arg, int error,
struct comm_reply *reply_info);
+/** callback for pending tcp connections */
+int outnet_tcp_cb(struct comm_point* c, void* arg, int error,
+ struct comm_reply *reply_info);
+
/** callback for udp timeout */
void pending_udp_timer_cb(void *arg);
/** callback for outgoing TCP timer event */
void outnet_tcptimer(void* arg);
+/** callback for serviced query UDP answers */
+int serviced_udp_callback(struct comm_point* c, void* arg, int error,
+ struct comm_reply* rep);
+
+/** TCP reply or error callback for serviced queries */
+int serviced_tcp_callback(struct comm_point* c, void* arg, int error,
+ struct comm_reply* rep);
+
#endif /* OUTSIDE_NETWORK_H */
return 0;
}
+int outnet_tcp_cb(struct comm_point* ATTR_UNUSED(c),
+ void* ATTR_UNUSED(arg), int ATTR_UNUSED(error),
+ struct comm_reply *ATTR_UNUSED(reply_info))
+{
+ log_assert(0);
+ return 0;
+}
+
void pending_udp_timer_cb(void *ATTR_UNUSED(arg))
{
log_assert(0);
log_assert(0);
}
+void comm_point_udp_callback(int ATTR_UNUSED(fd), short ATTR_UNUSED(event),
+ void* ATTR_UNUSED(arg))
+{
+ log_assert(0);
+}
+
+void comm_point_tcp_accept_callback(int ATTR_UNUSED(fd),
+ short ATTR_UNUSED(event), void* ATTR_UNUSED(arg))
+{
+ log_assert(0);
+}
+
+void comm_point_tcp_handle_callback(int ATTR_UNUSED(fd),
+ short ATTR_UNUSED(event), void* ATTR_UNUSED(arg))
+{
+ log_assert(0);
+}
+
+void comm_timer_callback(int ATTR_UNUSED(fd),
+ short ATTR_UNUSED(event), void* ATTR_UNUSED(arg))
+{
+ log_assert(0);
+}
+
+void comm_signal_callback(int ATTR_UNUSED(fd),
+ short ATTR_UNUSED(event), void* ATTR_UNUSED(arg))
+{
+ log_assert(0);
+}
+
+void comm_point_local_handle_callback(int ATTR_UNUSED(fd),
+ short ATTR_UNUSED(event), void* ATTR_UNUSED(arg))
+{
+ log_assert(0);
+}
+
+int serviced_udp_callback(struct comm_point* ATTR_UNUSED(c),
+ void* ATTR_UNUSED(arg), int ATTR_UNUSED(error),
+ struct comm_reply* ATTR_UNUSED(reply_info))
+{
+ log_assert(0);
+ return 0;
+}
+
+int serviced_tcp_callback(struct comm_point* ATTR_UNUSED(c),
+ void* ATTR_UNUSED(arg), int ATTR_UNUSED(error),
+ struct comm_reply* ATTR_UNUSED(reply_info))
+{
+ log_assert(0);
+ return 0;
+}
+
/*********** End of Dummy routines ***********/
int
fptr_whitelist_comm_point(comm_point_callback_t *fptr)
{
- return 1;
- if(fptr == &worker_handle_control_cmd) return 1;
- else if(fptr == &worker_handle_request) return 1;
+ if(fptr == &worker_handle_request) return 1;
else if(fptr == &outnet_udp_cb) return 1;
+ else if(fptr == &outnet_tcp_cb) return 1;
+ else if(fptr == &worker_handle_control_cmd) return 1;
return 0;
}
int
fptr_whitelist_comm_timer(void (*fptr)(void*))
{
- return 1;
if(fptr == &pending_udp_timer_cb) return 1;
else if(fptr == &outnet_tcptimer) return 1;
return 0;
int
fptr_whitelist_comm_signal(void (*fptr)(int, void*))
{
- return 1;
if(fptr == &worker_sighandler) return 1;
return 0;
}
int
fptr_whitelist_event(void (*fptr)(int, short, void *))
{
+ if(fptr == &comm_point_udp_callback) return 1;
+ else if(fptr == &comm_point_tcp_accept_callback) return 1;
+ else if(fptr == &comm_point_tcp_handle_callback) return 1;
+ else if(fptr == &comm_timer_callback) return 1;
+ else if(fptr == &comm_signal_callback) return 1;
+ else if(fptr == &comm_point_local_handle_callback) return 1;
+ return 0;
+}
+
+int
+fptr_whitelist_pending_udp(comm_point_callback_t *fptr)
+{
+ if(fptr == &serviced_udp_callback) return 1;
+ else if(fptr == &worker_handle_reply) return 1;
+ return 0;
+}
+
+int
+fptr_whitelist_pending_tcp(comm_point_callback_t *fptr)
+{
+ if(fptr == &serviced_tcp_callback) return 1;
+ else if(fptr == &worker_handle_reply) return 1;
+ return 0;
+}
+
+int
+fptr_whitelist_serviced_query(comm_point_callback_t *fptr)
+{
+ if(fptr == &worker_handle_service_reply) return 1;
return 0;
}
*/
int fptr_whitelist_event(void (*fptr)(int, short, void *));
+/**
+ * Check function pointer whitelist for pending udp callback values.
+ * This is not called by libevent itself, but checked by netevent.
+ *
+ * @param fptr: function pointer to check.
+ * @return false if not in whitelist.
+ */
+int fptr_whitelist_pending_udp(comm_point_callback_t *fptr);
+
+/**
+ * Check function pointer whitelist for pending tcp callback values.
+ * This is not called by libevent itself, but checked by netevent.
+ *
+ * @param fptr: function pointer to check.
+ * @return false if not in whitelist.
+ */
+int fptr_whitelist_pending_tcp(comm_point_callback_t *fptr);
+
+/**
+ * Check function pointer whitelist for serviced query callback values.
+ * This is not called by libevent itself, but checked by netevent.
+ *
+ * @param fptr: function pointer to check.
+ * @return false if not in whitelist.
+ */
+int fptr_whitelist_serviced_query(comm_point_callback_t *fptr);
+
+
#endif /* UTIL_FPTR_WLIST_H */
struct internal_signal* next;
};
-/**
- * handle libevent callback for udp comm point.
- * @param fd: file descriptor.
- * @param event: event bits from libevent:
- * EV_READ, EV_WRITE, EV_SIGNAL, EV_TIMEOUT.
- * @param arg: the comm_point structure.
- */
-static void comm_point_udp_callback(int fd, short event, void* arg);
-
-/**
- * handle libevent callback for tcp accept comm point
- * @param fd: file descriptor.
- * @param event: event bits from libevent:
- * EV_READ, EV_WRITE, EV_SIGNAL, EV_TIMEOUT.
- * @param arg: the comm_point structure.
- */
-static void comm_point_tcp_accept_callback(int fd, short event, void* arg);
-
-/**
- * handle libevent callback for tcp data comm point
- * @param fd: file descriptor.
- * @param event: event bits from libevent:
- * EV_READ, EV_WRITE, EV_SIGNAL, EV_TIMEOUT.
- * @param arg: the comm_point structure.
- */
-static void comm_point_tcp_handle_callback(int fd, short event, void* arg);
-
-/**
- * handle libevent callback for timer comm.
- * @param fd: file descriptor (always -1).
- * @param event: event bits from libevent:
- * EV_READ, EV_WRITE, EV_SIGNAL, EV_TIMEOUT.
- * @param arg: the comm_timer structure.
- */
-static void comm_timer_callback(int fd, short event, void* arg);
-
-/**
- * handle libevent callback for signal comm.
- * @param fd: file descriptor (used for the signal number).
- * @param event: event bits from libevent:
- * EV_READ, EV_WRITE, EV_SIGNAL, EV_TIMEOUT.
- * @param arg: the internal commsignal structure.
- */
-static void comm_signal_callback(int fd, short event, void* arg);
-
-/** libevent callback for AF_UNIX fds */
-static void comm_point_local_handle_callback(int fd, short event, void* arg);
-
/** create a tcp handler with a parent */
static struct comm_point* comm_point_create_tcp_handler(
struct comm_base *base, struct comm_point* parent, size_t bufsize,
return 1;
}
-static void
+void
comm_point_udp_callback(int fd, short event, void* arg)
{
struct comm_reply rep;
(void)comm_point_send_udp_msg(rep.c, rep.c->buffer,
(struct sockaddr*)&rep.addr, rep.addrlen);
}
+ log_assert(fptr_whitelist_event(rep.c->ev->ev.ev_callback));
}
/** Use a new tcp handler for new query fd, set to read query */
comm_point_start_listening(c, fd, TCP_QUERY_TIMEOUT);
}
-static void
+void
comm_point_tcp_accept_callback(int fd, short event, void* arg)
{
struct comm_point* c = (struct comm_point*)arg, *c_hdl;
}
/* addr is dropped. Not needed for tcp reply. */
setup_tcp_handler(c_hdl, new_fd);
+ log_assert(fptr_whitelist_event(c->ev->ev.ev_callback));
}
/** Make tcp handler free for next assignment */
return 1;
}
-static void
+void
comm_point_tcp_handle_callback(int fd, short event, void* arg)
{
struct comm_point* c = (struct comm_point*)arg;
NETEVENT_CLOSED, NULL);
}
}
+ log_assert(fptr_whitelist_event(c->ev->ev.ev_callback));
return;
}
if(event&EV_WRITE) {
NETEVENT_CLOSED, NULL);
}
}
+ log_assert(fptr_whitelist_event(c->ev->ev.ev_callback));
return;
}
if(event&EV_TIMEOUT) {
(void)(*c->callback)(c, c->cb_arg,
NETEVENT_TIMEOUT, NULL);
}
+ log_assert(fptr_whitelist_event(c->ev->ev.ev_callback));
return;
}
log_err("Ignored event %d for tcphdl.", event);
+ log_assert(fptr_whitelist_event(c->ev->ev.ev_callback));
}
-static void comm_point_local_handle_callback(int fd, short event, void* arg)
+void comm_point_local_handle_callback(int fd, short event, void* arg)
{
struct comm_point* c = (struct comm_point*)arg;
log_assert(c->type == comm_local);
(void)(*c->callback)(c, c->cb_arg, NETEVENT_CLOSED,
NULL);
}
+ log_assert(fptr_whitelist_event(c->ev->ev.ev_callback));
return;
}
log_err("Ignored event %d for localhdl.", event);
+ log_assert(fptr_whitelist_event(c->ev->ev.ev_callback));
}
struct comm_point*
free(timer);
}
-static void
+void
comm_timer_callback(int ATTR_UNUSED(fd), short event, void* arg)
{
struct comm_timer* tm = (struct comm_timer*)arg;
tm->ev_timer->enabled = 0;
log_assert(fptr_whitelist_comm_timer(tm->callback));
(*tm->callback)(tm->cb_arg);
+ log_assert(fptr_whitelist_event(tm->ev_timer->ev.ev_callback));
}
int
return com;
}
-static void
+void
comm_signal_callback(int sig, short event, void* arg)
{
struct comm_signal* comsig = (struct comm_signal*)arg;
return;
log_assert(fptr_whitelist_comm_signal(comsig->callback));
(*comsig->callback)(sig, comsig->cb_arg);
+ log_assert(fptr_whitelist_event(comsig->ev_signal->ev.ev_callback));
}
int
*/
void comm_signal_delete(struct comm_signal* comsig);
+
+/**** internal routines ****/
+
+/**
+ * This routine is published for checks and tests, and is only used internally.
+ * handle libevent callback for udp comm point.
+ * @param fd: file descriptor.
+ * @param event: event bits from libevent:
+ * EV_READ, EV_WRITE, EV_SIGNAL, EV_TIMEOUT.
+ * @param arg: the comm_point structure.
+ */
+void comm_point_udp_callback(int fd, short event, void* arg);
+
+/**
+ * This routine is published for checks and tests, and is only used internally.
+ * handle libevent callback for tcp accept comm point
+ * @param fd: file descriptor.
+ * @param event: event bits from libevent:
+ * EV_READ, EV_WRITE, EV_SIGNAL, EV_TIMEOUT.
+ * @param arg: the comm_point structure.
+ */
+void comm_point_tcp_accept_callback(int fd, short event, void* arg);
+
+/**
+ * This routine is published for checks and tests, and is only used internally.
+ * handle libevent callback for tcp data comm point
+ * @param fd: file descriptor.
+ * @param event: event bits from libevent:
+ * EV_READ, EV_WRITE, EV_SIGNAL, EV_TIMEOUT.
+ * @param arg: the comm_point structure.
+ */
+void comm_point_tcp_handle_callback(int fd, short event, void* arg);
+
+/**
+ * This routine is published for checks and tests, and is only used internally.
+ * handle libevent callback for timer comm.
+ * @param fd: file descriptor (always -1).
+ * @param event: event bits from libevent:
+ * EV_READ, EV_WRITE, EV_SIGNAL, EV_TIMEOUT.
+ * @param arg: the comm_timer structure.
+ */
+void comm_timer_callback(int fd, short event, void* arg);
+
+/**
+ * This routine is published for checks and tests, and is only used internally.
+ * handle libevent callback for signal comm.
+ * @param fd: file descriptor (used for the signal number).
+ * @param event: event bits from libevent:
+ * EV_READ, EV_WRITE, EV_SIGNAL, EV_TIMEOUT.
+ * @param arg: the internal commsignal structure.
+ */
+void comm_signal_callback(int fd, short event, void* arg);
+
+/**
+ * This routine is published for checks and tests, and is only used internally.
+ * libevent callback for AF_UNIX fds
+ * @param fd: file descriptor.
+ * @param event: event bits from libevent:
+ * EV_READ, EV_WRITE, EV_SIGNAL, EV_TIMEOUT.
+ * @param arg: the comm_point structure.
+ */
+void comm_point_local_handle_callback(int fd, short event, void* arg);
+
+
#endif /* NET_EVENT_H */