Skip to content

Commit

Permalink
Remove NSD_PASS_TO_XFRD passing
Browse files Browse the repository at this point in the history
  • Loading branch information
wtoorop committed Oct 17, 2024
1 parent 7090635 commit 9245d7c
Show file tree
Hide file tree
Showing 6 changed files with 1 addition and 213 deletions.
177 changes: 0 additions & 177 deletions ipc.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,31 +166,6 @@ send_stat_to_child(struct main_ipc_handler_data* data, int fd)
data->child->need_to_send_STATS = 0;
}

#ifndef NDEBUG
int packet_read_query_section(buffer_type *packet, uint8_t* dest, uint16_t* qtype, uint16_t* qclass);
static void
debug_print_fwd_name(int ATTR_UNUSED(len), buffer_type* packet, int acl_num)
{
uint8_t qnamebuf[MAXDOMAINLEN];
uint16_t qtype, qclass;
const dname_type* dname;
region_type* tempregion = region_create(xalloc, free);

size_t bufpos = buffer_position(packet);
buffer_rewind(packet);
buffer_skip(packet, 12);
if(packet_read_query_section(packet, qnamebuf, &qtype, &qclass)) {
dname = dname_make(tempregion, qnamebuf, 1);
log_msg(LOG_INFO, "main: fwd packet for %s, acl %d",
dname_to_string(dname,0), acl_num);
} else {
log_msg(LOG_INFO, "main: fwd packet badqname, acl %d", acl_num);
}
buffer_set_position(packet, bufpos);
region_destroy(tempregion);
}
#endif

static void
send_quit_to_child(struct main_ipc_handler_data* data, int fd)
{
Expand Down Expand Up @@ -332,95 +307,6 @@ parent_handle_child_command(netio_type *ATTR_UNUSED(netio),
return;
}

if (data->forward_mode) {
int got_acl;
/* forward the data to xfrd */
DEBUG(DEBUG_IPC,2, (LOG_INFO,
"main passed packet readup %d", (int)data->got_bytes));
if(data->got_bytes < sizeof(data->total_bytes))
{
if ((len = read(handler->fd,
(char*)&data->total_bytes+data->got_bytes,
sizeof(data->total_bytes)-data->got_bytes)) == -1) {
log_msg(LOG_ERR, "handle_child_command: read: %s",
strerror(errno));
return;
}
if(len == 0) {
/* EOF */
data->forward_mode = 0;
return;
}
data->got_bytes += len;
if(data->got_bytes < sizeof(data->total_bytes))
return;
data->total_bytes = ntohs(data->total_bytes);
buffer_clear(data->packet);
if(data->total_bytes > buffer_capacity(data->packet)) {
log_msg(LOG_ERR, "internal error: ipc too large");
exit(1);
}
return;
}
/* read the packet */
if(data->got_bytes-sizeof(data->total_bytes) < data->total_bytes) {
if((len = read(handler->fd, buffer_current(data->packet),
data->total_bytes - (data->got_bytes-sizeof(data->total_bytes))
)) == -1 ) {
log_msg(LOG_ERR, "handle_child_command: read: %s",
strerror(errno));
return;
}
if(len == 0) {
/* EOF */
data->forward_mode = 0;
return;
}
data->got_bytes += len;
buffer_skip(data->packet, len);
/* read rest later */
return;
}
/* read the acl numbers */
got_acl = data->got_bytes - sizeof(data->total_bytes) - data->total_bytes;
if((len = read(handler->fd, (char*)&data->acl_num+got_acl,
sizeof(data->acl_num)+sizeof(data->acl_xfr)-got_acl)) == -1 ) {
log_msg(LOG_ERR, "handle_child_command: read: %s",
strerror(errno));
return;
}
if(len == 0) {
/* EOF */
data->forward_mode = 0;
return;
}
got_acl += len;
data->got_bytes += len;
if(got_acl >= (int)(sizeof(data->acl_num)+sizeof(data->acl_xfr))) {
uint16_t len = htons(data->total_bytes);
DEBUG(DEBUG_IPC,2, (LOG_INFO,
"main fwd passed packet write %d", (int)data->got_bytes));
#ifndef NDEBUG
if(nsd_debug_level >= 2)
debug_print_fwd_name(len, data->packet, data->acl_num);
#endif
data->forward_mode = 0;
mode = NSD_PASS_TO_XFRD;
if(!write_socket(*data->xfrd_sock, &mode, sizeof(mode)) ||
!write_socket(*data->xfrd_sock, &len, sizeof(len)) ||
!write_socket(*data->xfrd_sock, buffer_begin(data->packet),
data->total_bytes) ||
!write_socket(*data->xfrd_sock, &data->acl_num,
sizeof(data->acl_num)) ||
!write_socket(*data->xfrd_sock, &data->acl_xfr,
sizeof(data->acl_xfr))) {
log_msg(LOG_ERR, "error in ipc fwd main2xfrd: %s",
strerror(errno));
}
}
return;
}

/* read command from ipc */
if ((len = read(handler->fd, &mode, sizeof(mode))) == -1) {
log_msg(LOG_ERR, "handle_child_command: read: %s",
Expand All @@ -443,12 +329,6 @@ parent_handle_child_command(netio_type *ATTR_UNUSED(netio),
case NSD_REAP_CHILDREN:
data->nsd->signal_hint_child = 1;
break;
case NSD_PASS_TO_XFRD:
/* set mode for handle_child_command; echo to xfrd. */
data->forward_mode = 1;
data->got_bytes = 0;
data->total_bytes = 0;
break;
default:
log_msg(LOG_ERR, "handle_child_command: bad mode %d",
(int) mode);
Expand Down Expand Up @@ -651,52 +531,6 @@ xfrd_handle_ipc_read(struct event* handler, xfrd_state_type* xfrd)
sig_atomic_t cmd;
int len;

if(xfrd->ipc_conn->is_reading==2) {
buffer_type* tmp = xfrd->ipc_pass;
uint32_t acl_num;
int32_t acl_xfr;
/* read acl_num */
int ret = conn_read(xfrd->ipc_conn);
if(ret == -1) {
log_msg(LOG_ERR, "xfrd: error in read ipc: %s", strerror(errno));
xfrd->ipc_conn->is_reading = 0;
return;
}
if(ret == 0)
return;
buffer_flip(xfrd->ipc_conn->packet);
xfrd->ipc_pass = xfrd->ipc_conn->packet;
xfrd->ipc_conn->packet = tmp;
xfrd->ipc_conn->is_reading = 0;
acl_num = buffer_read_u32(xfrd->ipc_pass);
acl_xfr = (int32_t)buffer_read_u32(xfrd->ipc_pass);
xfrd_handle_passed_packet(xfrd->ipc_conn->packet, acl_num, acl_xfr);
return;
}
if(xfrd->ipc_conn->is_reading) {
/* reading an IPC message */
buffer_type* tmp;
int ret = conn_read(xfrd->ipc_conn);
if(ret == -1) {
log_msg(LOG_ERR, "xfrd: error in read ipc: %s", strerror(errno));
xfrd->ipc_conn->is_reading = 0;
return;
}
if(ret == 0)
return;
buffer_flip(xfrd->ipc_conn->packet);
/* use ipc_conn to read remaining data as well */
tmp = xfrd->ipc_pass;
xfrd->ipc_conn->is_reading=2;
xfrd->ipc_pass = xfrd->ipc_conn->packet;
xfrd->ipc_conn->packet = tmp;
xfrd->ipc_conn->total_bytes = sizeof(xfrd->ipc_conn->msglen);
xfrd->ipc_conn->msglen = 2*sizeof(uint32_t);
buffer_clear(xfrd->ipc_conn->packet);
buffer_set_limit(xfrd->ipc_conn->packet, xfrd->ipc_conn->msglen);
return;
}

if((len = read(handler->ev_fd, &cmd, sizeof(cmd))) == -1) {
if(errno != EINTR && errno != EAGAIN)
log_msg(LOG_ERR, "xfrd_handle_ipc: read: %s",
Expand Down Expand Up @@ -747,10 +581,6 @@ xfrd_handle_ipc_read(struct event* handler, xfrd_state_type* xfrd)
xfrd_prepare_zones_for_reload();
xfrd->reload_failed = 0;
break;
case NSD_PASS_TO_XFRD:
DEBUG(DEBUG_IPC,1, (LOG_INFO, "xfrd: ipc recv PASS_TO_XFRD"));
xfrd->ipc_conn->is_reading = 1;
break;
case NSD_RELOAD_REQ:
DEBUG(DEBUG_IPC,1, (LOG_INFO, "xfrd: ipc recv RELOAD_REQ"));
/* make reload happen, right away, and schedule file check */
Expand All @@ -769,13 +599,6 @@ xfrd_handle_ipc_read(struct event* handler, xfrd_state_type* xfrd)
(int)ntohl(cmd));
break;
}

if(xfrd->ipc_conn->is_reading) {
/* setup read of info */
xfrd->ipc_conn->total_bytes = 0;
xfrd->ipc_conn->msglen = 0;
buffer_clear(xfrd->ipc_conn->packet);
}
}

void
Expand Down
10 changes: 0 additions & 10 deletions ipc.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,6 @@ struct main_ipc_handler_data
{
struct nsd *nsd;
struct nsd_child *child;
int child_num;

/* pointer to the socket, as it may change if it is restarted */
int *xfrd_sock;
struct buffer *packet;
int forward_mode;
size_t got_bytes;
uint16_t total_bytes;
uint32_t acl_num;
int32_t acl_xfr;
};

/*
Expand Down
7 changes: 0 additions & 7 deletions nsd.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,6 @@ struct dt_collector;
#define NSD_STATS 3
#define NSD_REAP_CHILDREN 4
#define NSD_QUIT 5
/*
* PASS_TO_XFRD is followed by the u16(len in network order) and
* then network packet contents. packet is a notify(acl checked), or
* xfr reply from a master(acl checked).
* followed by u32(acl number that matched from notify/xfr acl).
*/
#define NSD_PASS_TO_XFRD 6
/*
* RELOAD_REQ is sent when parent receives a SIGHUP and tells
* xfrd that it wants to initiate a reload (and thus task swap).
Expand Down
13 changes: 1 addition & 12 deletions server.c
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,6 @@ static int
restart_child_servers(struct nsd *nsd, region_type* region, netio_type* netio,
int* xfrd_sock_p)
{
struct main_ipc_handler_data *ipc_data;
size_t i;
int sv[2];

Expand All @@ -463,17 +462,11 @@ restart_child_servers(struct nsd *nsd, region_type* region, netio_type* netio,
}
if(!nsd->children[i].handler)
{
struct main_ipc_handler_data *ipc_data;
ipc_data = (struct main_ipc_handler_data*) region_alloc(
region, sizeof(struct main_ipc_handler_data));
ipc_data->nsd = nsd;
ipc_data->child = &nsd->children[i];
ipc_data->child_num = i;
ipc_data->xfrd_sock = xfrd_sock_p;
ipc_data->packet = buffer_create(region, QIOBUFSZ);
ipc_data->forward_mode = 0;
ipc_data->got_bytes = 0;
ipc_data->total_bytes = 0;
ipc_data->acl_num = 0;
nsd->children[i].handler = (struct netio_handler*) region_alloc(
region, sizeof(struct netio_handler));
nsd->children[i].handler->fd = nsd->children[i].child_fd;
Expand All @@ -483,10 +476,6 @@ restart_child_servers(struct nsd *nsd, region_type* region, netio_type* netio,
nsd->children[i].handler->event_handler = parent_handle_child_command;
netio_add_handler(netio, nsd->children[i].handler);
}
/* clear any ongoing ipc */
ipc_data = (struct main_ipc_handler_data*)
nsd->children[i].handler->user_data;
ipc_data->forward_mode = 0;
/* restart - update fd */
nsd->children[i].handler->fd = nsd->children[i].child_fd;
break;
Expand Down
5 changes: 0 additions & 5 deletions xfrd.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ xfrd_init(int socket, struct nsd* nsd, int shortsoa, int reload_active,
xfrd->zonestat_safe = nsd->zonestatdesired;
#endif
xfrd->activated_first = NULL;
xfrd->ipc_pass = buffer_create(xfrd->region, QIOBUFSZ);
xfrd->last_task = region_alloc(xfrd->region, sizeof(*xfrd->last_task));
udb_ptr_init(xfrd->last_task, xfrd->nsd->task[xfrd->nsd->mytask]);
assert(shortsoa || udb_base_get_userdata(xfrd->nsd->task[xfrd->nsd->mytask])->data == 0);
Expand All @@ -183,10 +182,6 @@ xfrd_init(int socket, struct nsd* nsd, int shortsoa, int reload_active,
if(event_add(&xfrd->ipc_handler, NULL) != 0)
log_msg(LOG_ERR, "xfrd ipc handler: event_add failed");
xfrd->ipc_handler_flags = EV_PERSIST|EV_READ;
xfrd->ipc_conn = xfrd_tcp_create(xfrd->region, QIOBUFSZ);
/* not reading using ipc_conn yet */
xfrd->ipc_conn->is_reading = 0;
xfrd->ipc_conn->fd = socket;
xfrd->need_to_send_reload = 0;
xfrd->need_to_send_shutdown = 0;
xfrd->need_to_send_stats = 0;
Expand Down
2 changes: 0 additions & 2 deletions xfrd.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,6 @@ struct xfrd_state {
/* communication channel with server_main */
struct event ipc_handler;
int ipc_handler_flags;
struct xfrd_tcp *ipc_conn;
struct buffer* ipc_pass;

/* 2 * nsd->child_count communication channels with the serve childs */
struct event* serve2xfrd;
Expand Down

0 comments on commit 9245d7c

Please sign in to comment.