/** * Get the config from the jool kernel app, then serialized a local config copy, * then deserialize the buffer and finally compare the configs. * */ static bool basic_test(void) { int error; unsigned char *buffer; size_t buffer_len; bool success = true; struct global_config config = { .mtu_plateaus = NULL }; struct global_config response = { .mtu_plateaus = NULL }; error = config_clone(&config); if (error) return false; error = serialize_global_config(&config, true, &buffer, &buffer_len); if (error) return false; error = deserialize_global_config(buffer, buffer_len, &response); if (error) return false; success &= compare_global_configs(&config, &response); kfree(buffer); return success; }
static int handle_global_config(struct nlmsghdr *nl_hdr, struct request_hdr *jool_hdr, union request_global *request) { struct global_config response = { .mtu_plateaus = NULL }; unsigned char *buffer; size_t buffer_len; bool disabled; int error; switch (jool_hdr->operation) { case OP_DISPLAY: log_debug("Returning 'Global' options."); error = config_clone(&response); if (error) goto end; disabled = xlat_is_nat64() ? pool6_is_empty() : (pool6_is_empty() && eamt_is_empty()); error = serialize_global_config(&response, disabled, &buffer, &buffer_len); if (error) goto end; error = respond_setcfg(nl_hdr, buffer, buffer_len); kfree(buffer); break; case OP_UPDATE: if (verify_superpriv()) return respond_error(nl_hdr, -EPERM); log_debug("Updating 'Global' options."); buffer = (unsigned char *) (request + 1); buffer_len = jool_hdr->length - sizeof(*jool_hdr) - sizeof(*request); error = handle_global_update(request->update.type, buffer_len, buffer); break; default: log_err("Unknown operation: %d", jool_hdr->operation); error = -EINVAL; } end: return respond_error(nl_hdr, error); }
static void init_Configure(GtkWidget * dialog) { guint i; GtkWidget *cbTypes; cbTypes = ui_lookup_widget(dialog, "comboboxType"); g_object_set(cbTypes, "wrap-width", 3, NULL); for (i = 0; i < geany->filetypes_array->len; i++) { gtk_combo_box_append_text(GTK_COMBO_BOX(cbTypes), ((struct GeanyFiletype *) (filetypes[i]))-> name); } g_object_set_data(G_OBJECT(cbTypes), "config", config_clone()); g_object_set_data(G_OBJECT(cbTypes), "current", NULL); gtk_combo_box_set_active(GTK_COMBO_BOX(cbTypes), 0); }
/** * Same as above, the only difference is that we set NULL the mtu_plateaus from * the local translate config. */ static bool translate_nulls_mtu(void) { int error; unsigned char *buffer; size_t buffer_len; bool success = true; struct global_config config = { .mtu_plateaus = NULL }; struct global_config response = { .mtu_plateaus = NULL }; error = config_clone(&config); if (error) return false; /* * lets modify our local config manually, jool's update functions wont * update to null */ config.mtu_plateaus = NULL; config.mtu_plateau_count = 0; error = serialize_global_config(&config, true, &buffer, &buffer_len); if (error) return false; error = deserialize_global_config(buffer, buffer_len, &response); if (error) return false; success &= compare_global_configs(&config, &response); /* the "compare_global_configs" will not evaluate the mtu_plateaus * because of the plateau_count = 0 */ success &= ASSERT_PTR(NULL, config.mtu_plateaus, "local config mtu_plateaus"); success &= ASSERT_PTR(NULL, response.mtu_plateaus, "deserialized config mtu_plateaus"); kfree(buffer); return success; }
static int handle_global_update(enum global_type type, size_t size, unsigned char *value) { struct global_config *config; bool timer_needs_update = false; enum session_timer_type timer_type; int error; config = kmalloc(sizeof(*config), GFP_KERNEL); if (!config) return -ENOMEM; config->mtu_plateaus = NULL; error = config_clone(config); if (error) goto fail; switch (type) { #ifdef STATEFUL case MAX_PKTS: if (!ensure_bytes(size, 8)) goto einval; config->max_stored_pkts = *((__u64 *) value); break; case SRC_ICMP6ERRS_BETTER: if (!ensure_bytes(size, 1)) goto einval; config->src_icmp6errs_better = *((__u8 *) value); break; case BIB_LOGGING: if (!ensure_bytes(size, 1)) goto einval; config->bib_logging = *((__u8 *) value); break; case SESSION_LOGGING: if (!ensure_bytes(size, 1)) goto einval; config->session_logging = *((__u8 *) value); break; case UDP_TIMEOUT: if (!ensure_bytes(size, 8)) goto einval; if (!assign_timeout(value, UDP_MIN, &config->ttl.udp)) goto einval; timer_needs_update = true; timer_type = SESSIONTIMER_UDP; break; case ICMP_TIMEOUT: if (!ensure_bytes(size, 8)) goto einval; if (!assign_timeout(value, 0, &config->ttl.icmp)) goto einval; timer_needs_update = true; timer_type = SESSIONTIMER_ICMP; break; case TCP_EST_TIMEOUT: if (!ensure_bytes(size, 8)) goto einval; if (!assign_timeout(value, TCP_EST, &config->ttl.tcp_est)) goto einval; timer_needs_update = true; timer_type = SESSIONTIMER_EST; break; case TCP_TRANS_TIMEOUT: if (!ensure_bytes(size, 8)) goto einval; if (!assign_timeout(value, TCP_TRANS, &config->ttl.tcp_trans)) goto einval; timer_needs_update = true; timer_type = SESSIONTIMER_TRANS; break; case FRAGMENT_TIMEOUT: if (!ensure_bytes(size, 8)) goto einval; if (!assign_timeout(value, FRAGMENT_MIN, &config->ttl.frag)) goto einval; break; case DROP_BY_ADDR: if (!ensure_bytes(size, 1)) goto einval; config->drop_by_addr = *((__u8 *) value); break; case DROP_ICMP6_INFO: if (!ensure_bytes(size, 1)) goto einval; config->drop_icmp6_info = *((__u8 *) value); break; case DROP_EXTERNAL_TCP: if (!ensure_bytes(size, 1)) goto einval; config->drop_external_tcp = *((__u8 *) value); break; #else case COMPUTE_UDP_CSUM_ZERO: if (!ensure_bytes(size, 1)) goto einval; config->compute_udp_csum_zero = *((__u8 *) value); break; case RANDOMIZE_RFC6791: if (!ensure_bytes(size, 1)) goto einval; config->randomize_error_addresses = *((__u8 *) value); break; #endif case RESET_TCLASS: if (!ensure_bytes(size, 1)) goto einval; config->reset_traffic_class = *((__u8 *) value); break; case RESET_TOS: if (!ensure_bytes(size, 1)) goto einval; config->reset_tos = *((__u8 *) value); break; case NEW_TOS: if (!ensure_bytes(size, 1)) goto einval; config->new_tos = *((__u8 *) value); break; case DF_ALWAYS_ON: if (!ensure_bytes(size, 1)) goto einval; config->atomic_frags.df_always_on = *((__u8 *) value); break; case BUILD_IPV6_FH: if (!ensure_bytes(size, 1)) goto einval; config->atomic_frags.build_ipv6_fh = *((__u8 *) value); break; case BUILD_IPV4_ID: if (!ensure_bytes(size, 1)) goto einval; config->atomic_frags.build_ipv4_id = *((__u8 *) value); break; case LOWER_MTU_FAIL: if (!ensure_bytes(size, 1)) goto einval; config->atomic_frags.lower_mtu_fail = *((__u8 *) value); break; case MTU_PLATEAUS: if (is_error(update_plateaus(config, size, value))) goto einval; break; case DISABLE: config->is_disable = (__u8) true; break; case ENABLE: config->is_disable = (__u8) false; break; case ATOMIC_FRAGMENTS: if (!ensure_bytes(size, 1)) goto einval; config->atomic_frags.df_always_on = *((__u8 *) value); config->atomic_frags.build_ipv6_fh = *((__u8 *) value); config->atomic_frags.build_ipv4_id = !(*((__u8 *) value)); config->atomic_frags.lower_mtu_fail = !(*((__u8 *) value)); break; default: log_err("Unknown config type: %u", type); goto einval; } error = config_set(config); if (error) goto fail; if (timer_needs_update) error = sessiondb_update_timer(timer_type); return error; einval: error = -EINVAL; /* Fall through. */ fail: kfree(config->mtu_plateaus); kfree(config); return error; }