From 9245d7c2e1d160e23f88b46706e2a2cca7160634 Mon Sep 17 00:00:00 2001 From: Willem Toorop Date: Thu, 17 Oct 2024 13:15:58 +0200 Subject: [PATCH] Remove NSD_PASS_TO_XFRD passing --- ipc.c | 177 ------------------------------------------------------- ipc.h | 10 ---- nsd.h | 7 --- server.c | 13 +--- xfrd.c | 5 -- xfrd.h | 2 - 6 files changed, 1 insertion(+), 213 deletions(-) diff --git a/ipc.c b/ipc.c index 1a975f3e..557f8cd9 100644 --- a/ipc.c +++ b/ipc.c @@ -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) { @@ -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", @@ -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); @@ -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", @@ -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 */ @@ -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 diff --git a/ipc.h b/ipc.h index 333ac090..c92bea5c 100644 --- a/ipc.h +++ b/ipc.h @@ -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; }; /* diff --git a/nsd.h b/nsd.h index 5cda7ff8..cd247950 100644 --- a/nsd.h +++ b/nsd.h @@ -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). diff --git a/server.c b/server.c index be52a745..ac7b5580 100644 --- a/server.c +++ b/server.c @@ -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]; @@ -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; @@ -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; diff --git a/xfrd.c b/xfrd.c index dd4a1737..ff8b5b0d 100644 --- a/xfrd.c +++ b/xfrd.c @@ -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); @@ -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; diff --git a/xfrd.h b/xfrd.h index 7c18cfa6..5701a564 100644 --- a/xfrd.h +++ b/xfrd.h @@ -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;