static int handle_logtime_config(struct nlmsghdr *nl_hdr, struct request_hdr *nat64_hdr, struct request_logtime *request) { #ifdef BENCHMARK struct nl_buffer *buffer; int error; switch (nat64_hdr->operation) { case OP_DISPLAY: log_debug("Sending logs time to userspace."); buffer = nlbuffer_create(nl_socket, nl_hdr); if (!buffer) return respond_error(nl_hdr, -ENOMEM); error = logtime_iterate_and_delete(request->l3_proto, request->l4_proto, logtime_entry_to_userspace, buffer); error = (error >= 0) ? nlbuffer_close(buffer, error) : respond_error(nl_hdr, error); kfree(buffer); return error; default: log_err("Unknown operation: %d", nat64_hdr->operation); return respond_error(nl_hdr, -EINVAL); } #else log_err("Benchmark was not enabled during compilation."); return -EINVAL; #endif }
static struct nl_buffer *buffer_create(enum parse_section section) { struct nl_buffer *buffer; buffer = nlbuffer_create(); if (!buffer) { log_err("Out of memory."); return NULL; } if (init_buffer(buffer, section)) { nlbuffer_destroy(buffer); return NULL; } return buffer; }
static int handle_blacklist_display(struct nlmsghdr *nl_hdr, union request_pool *request) { struct nl_buffer *buffer; struct ipv4_prefix *offset; int error; buffer = nlbuffer_create(nl_socket, nl_hdr); if (!buffer) return respond_error(nl_hdr, -ENOMEM); offset = request->display.offset_set ? &request->display.offset : NULL; error = blacklist_for_each(pool_to_usr, buffer, offset); error = (error >= 0) ? nlbuffer_close(buffer, error) : respond_error(nl_hdr, error); kfree(buffer); return error; }
static int handle_pool6791_display(struct nlmsghdr *nl_hdr, union request_pool4 *request) { struct nl_buffer *buffer; struct ipv4_prefix *prefix; int error; log_debug("Sending RFC6791 pool to userspace."); buffer = nlbuffer_create(nl_socket, nl_hdr); if (!buffer) return respond_error(nl_hdr, -ENOMEM); prefix = request->display.prefix_set ? &request->display.prefix : NULL; error = rfc6791_for_each(pool4_to_usr, buffer, prefix); error = (error >= 0) ? nlbuffer_close(buffer, error) : respond_error(nl_hdr, error); kfree(buffer); return error; }
static int handle_eamt_display(struct nlmsghdr *nl_hdr, union request_eamt *request) { struct nl_buffer *buffer; struct ipv4_prefix *prefix4; int error; log_debug("Sending EAMT to userspace."); buffer = nlbuffer_create(nl_socket, nl_hdr); if (!buffer) return respond_error(nl_hdr, -ENOMEM); prefix4 = request->display.prefix4_set ? &request->display.prefix4 : NULL; error = eamt_for_each(eam_entry_to_userspace, buffer, prefix4); error = (error >= 0) ? nlbuffer_close(buffer, error) : respond_error(nl_hdr, error); kfree(buffer); return error; }
static int handle_bib_display(struct nlmsghdr *nl_hdr, struct request_bib *request) { struct nl_buffer *buffer; struct ipv4_transport_addr *addr4; int error; log_debug("Sending BIB to userspace."); buffer = nlbuffer_create(nl_socket, nl_hdr); if (!buffer) return respond_error(nl_hdr, -ENOMEM); addr4 = request->display.addr4_set ? &request->display.addr4 : NULL; error = bibdb_iterate_by_ipv4(request->l4_proto, bib_entry_to_userspace, buffer, addr4); error = (error >= 0) ? nlbuffer_close(buffer, error) : respond_error(nl_hdr, error); kfree(buffer); return error; }
static int handle_pool4_display(struct nlmsghdr *nl_hdr, union request_pool4 *request) { struct nl_buffer *buffer; struct pool4_sample *offset = NULL; int error; log_debug("Sending IPv4 pool to userspace."); buffer = nlbuffer_create(nl_socket, nl_hdr); if (!buffer) return respond_error(nl_hdr, -ENOMEM); if (request->display.offset_set) offset = &request->display.offset; error = pool4db_foreach_sample(pool4_to_usr, buffer, offset); error = (error >= 0) ? nlbuffer_close(buffer, error) : respond_error(nl_hdr, error); kfree(buffer); return error; }
static int handle_session_display(struct nlmsghdr *nl_hdr, struct request_session *request) { struct nl_buffer *buffer; struct ipv4_transport_addr *remote4 = NULL; struct ipv4_transport_addr *local4 = NULL; int error; log_debug("Sending session table to userspace."); buffer = nlbuffer_create(nl_socket, nl_hdr); if (!buffer) return respond_error(nl_hdr, -ENOMEM); if (request->display.connection_set) { remote4 = &request->display.remote4; local4 = &request->display.local4; } error = sessiondb_iterate_by_ipv4(request->l4_proto, session_entry_to_userspace, buffer, remote4, local4); error = (error >= 0) ? nlbuffer_close(buffer, error) : respond_error(nl_hdr, error); kfree(buffer); return error; }