void test_send (l2net_154 *l2, l2addr_154 *dest) { Msg *m1 = initMsg(l2) ; Msg *m2 = initMsg(l2) ; bool ok ; option *up1 = initOptionOpaque(MO_Uri_Path, PATH1, sizeof PATH1 - 1) ; option *up2 = initOptionOpaque(MO_Uri_Path, PATH2, sizeof PATH2 - 1) ; option *up3 = initOptionOpaque(MO_Uri_Path, PATH3, sizeof PATH3 - 1) ; option *ocf = initOptionOpaque(MO_Content_Format, "abc", sizeof "abc" - 1) ; set_id (m1, 258) ; set_type (m1, COAP_TYPE_NON) ; push_option (m1, ocf) ; push_option (m1, up1) ; push_option (m1, up2) ; push_option (m1, up3) ; ok = sendMsg (m1, dest) ; res_send (1, ok) ; set_id (m2, 33) ; set_type (m2, COAP_TYPE_CON) ; push_option (m2, ocf) ; ok = sendMsg (m2, dest) ; res_send (2, ok) ; }
static int sync_kloop_eventfds(struct TestContext *ctx) { struct nmreq_opt_sync_kloop_eventfds *evopt = NULL; struct nmreq_opt_sync_kloop_mode modeopt; struct nmreq_option evsave; int num_entries; size_t opt_size; int ret, i; memset(&modeopt, 0, sizeof(modeopt)); modeopt.nro_opt.nro_reqtype = NETMAP_REQ_OPT_SYNC_KLOOP_MODE; modeopt.mode = ctx->sync_kloop_mode; push_option(&modeopt.nro_opt, ctx); num_entries = num_registered_rings(ctx); opt_size = sizeof(*evopt) + num_entries * sizeof(evopt->eventfds[0]); evopt = calloc(1, opt_size); evopt->nro_opt.nro_next = 0; evopt->nro_opt.nro_reqtype = NETMAP_REQ_OPT_SYNC_KLOOP_EVENTFDS; evopt->nro_opt.nro_status = 0; evopt->nro_opt.nro_size = opt_size; for (i = 0; i < num_entries; i++) { int efd = eventfd(0, 0); evopt->eventfds[i].ioeventfd = efd; efd = eventfd(0, 0); evopt->eventfds[i].irqfd = efd; } push_option(&evopt->nro_opt, ctx); evsave = evopt->nro_opt; ret = sync_kloop_start_stop(ctx); if (ret != 0) { free(evopt); clear_options(ctx); return ret; } #ifdef __linux__ evsave.nro_status = 0; #else /* !__linux__ */ evsave.nro_status = EOPNOTSUPP; #endif /* !__linux__ */ ret = checkoption(&evopt->nro_opt, &evsave); free(evopt); clear_options(ctx); return ret; }
/* * * HELPER DIRECTIVE: * * keepalive 10 60 * * EXPANDS TO: * * if mode server: * ping 10 * ping-restart 120 * push "ping 10" * push "ping-restart 60" * else * ping 10 * ping-restart 60 */ void helper_keepalive(struct options *o) { if (o->keepalive_ping || o->keepalive_timeout) { /* * Sanity checks. */ if (o->keepalive_ping <= 0 || o->keepalive_timeout <= 0) { msg(M_USAGE, "--keepalive parameters must be > 0"); } if (o->keepalive_ping * 2 > o->keepalive_timeout) { msg(M_USAGE, "the second parameter to --keepalive (restart timeout=%d) must be at least twice the value of the first parameter (ping interval=%d). A ratio of 1:5 or 1:6 would be even better. Recommended setting is --keepalive 10 60.", o->keepalive_timeout, o->keepalive_ping); } if (o->ping_send_timeout || o->ping_rec_timeout) { msg(M_USAGE, "--keepalive conflicts with --ping, --ping-exit, or --ping-restart. If you use --keepalive, you don't need any of the other --ping directives."); } /* * Expand. */ if (o->mode == MODE_POINT_TO_POINT) { o->ping_rec_timeout_action = PING_RESTART; o->ping_send_timeout = o->keepalive_ping; o->ping_rec_timeout = o->keepalive_timeout; } #if P2MP_SERVER else if (o->mode == MODE_SERVER) { o->ping_rec_timeout_action = PING_RESTART; o->ping_send_timeout = o->keepalive_ping; o->ping_rec_timeout = o->keepalive_timeout * 2; push_option(o, print_str_int("ping", o->keepalive_ping, &o->gc), M_USAGE); push_option(o, print_str_int("ping-restart", o->keepalive_timeout, &o->gc), M_USAGE); } #endif else { ASSERT(0); } } }
void push_options(struct options *o, char **p, int msglevel, struct gc_arena *gc) { const char **argv = make_extended_arg_array(p, gc); char *opt = print_argv(argv, gc, 0); push_option(o, opt, msglevel); }
void test_resource (Casan *ca, l2net_154 *l2, const char *name) { Msg *in = initMsg(l2) ; Msg *out = initMsg(l2) ; printf("Resource: '%s'\n", name); option *up = initOptionOpaque(MO_Uri_Path, (void *) name, strlen (name)) ; option *ocf = initOptionOpaque(MO_Content_Format, (void *) "abc", sizeof "abc" - 1) ; set_id(in, 100); set_type(in, COAP_TYPE_ACK); push_option(in, up); push_option(in, ocf); printf("Simulated message IN: \n"); printMsg(in); process_request(ca, in ,out); printf("Simulated message OUT: \n"); printMsg(out); printf("Done\n"); }
void test_msg (void) { l2net_154 *l2 ; printf ("STEP 1: create 2 empty messages\n") ; Msg *m1 = initMsg(l2) ; printMsg (m1) ; Msg *m2 = initMsg(l2) ; printMsg (m2) ; printf ("STEP 2: create options\n") ; option *oup1 = initOptionOpaque(MO_Uri_Path, (void *) PATH1, sizeof PATH1-1) ; option *oup2 = initOptionOpaque(MO_Uri_Path, (void *) PATH2, sizeof PATH2-1) ; option *ouq1 = initOptionOpaque(MO_Uri_Query, (void *) URIQUERY1, sizeof URIQUERY1-1) ; option *ouq2 = initOptionOpaque(MO_Uri_Query, (void *) URIQUERY2, sizeof URIQUERY2-1) ; option *ouq3 = initOptionOpaque(MO_Uri_Query, (void *) URIQUERY3, sizeof URIQUERY3-1) ; // REGISTER message set_type (m1, COAP_TYPE_CON) ; set_code (m1, COAP_CODE_GET) ; set_id (m1, 10) ; printf ("STEP 3a: M1 add uriquery2\n") ; push_option (m1, ouq2) ; printMsg (m1) ; printf("\n") ; printf ("STEP 3b: M1 add uripath1\n") ; push_option (m1, oup1) ; printMsg (m1) ; printf("\n") ; printf ("STEP 3c: M1 add uripath2\n") ; push_option (m1, oup2) ; printMsg (m1) ; printf("\n") ; printf ("STEP 3d: M1 add uriquery1\n") ; push_option (m1, ouq1) ; printMsg (m1) ; printf("\n") ; printf("STEP 3e: M1 add uriquery3\n") ; push_option (m1, ouq3) ; printMsg (m1) ; printf("\n") ; set_type (m2, COAP_TYPE_NON) ; set_code (m2, COAP_CODE_POST) ; set_id (m2, 11) ; printf ("STEP 3f: M2 add oriquery2\n") ; push_option (m2, ouq2) ; printMsg (m2) ; printf("\n") ; if (get_errno () != 0) { printf ("ERROR : ERRNO => ") ; printf ("%d\n",get_errno ()) ; reset_errno () ; } clock_delay (1000) ; }
static bool push_option_fmt(struct options *o, int msglevel, const char *format, ...) { va_list arglist; char tmp[256] = {0}; int len = -1; va_start (arglist, format); len = vsnprintf (tmp, sizeof(tmp), format, arglist); va_end (arglist); if (len > sizeof(tmp)-1) return false; push_option (o, string_alloc (tmp, &o->gc), msglevel); return true; }
static int infinite_options(struct TestContext *ctx) { struct nmreq_option opt; printf("Testing infinite list of options on %s\n", ctx->ifname_ext); opt.nro_reqtype = 1234; push_option(&opt, ctx); opt.nro_next = (uintptr_t)&opt; if (port_register_hwall(ctx) >= 0) return -1; clear_options(ctx); return (errno == EMSGSIZE ? 0 : -1); }
/* * * HELPER DIRECTIVE: * * tcp-nodelay * * EXPANDS TO: * * if mode server: * socket-flags TCP_NODELAY * push "socket-flags TCP_NODELAY" */ void helper_tcp_nodelay (struct options *o) { #if P2MP_SERVER if (o->server_flags & SF_TCP_NODELAY_HELPER) { if (o->mode == MODE_SERVER) { o->sockflags |= SF_TCP_NODELAY; push_option (o, print_str ("socket-flags TCP_NODELAY", &o->gc), M_USAGE); } else { ASSERT (0); } } #endif }
static int csb_mode_invalid_memory(struct TestContext *ctx) { struct nmreq_opt_csb opt; int ret; memset(&opt, 0, sizeof(opt)); opt.nro_opt.nro_reqtype = NETMAP_REQ_OPT_CSB; opt.csb_atok = (uintptr_t)0x10; opt.csb_ktoa = (uintptr_t)0x800; push_option(&opt.nro_opt, ctx); ctx->nr_flags = NR_EXCLUSIVE; ret = port_register_hwall(ctx); clear_options(ctx); return (ret < 0) ? 0 : -1; }
static int unsupported_option(struct TestContext *ctx) { struct nmreq_option opt, save; printf("Testing unsupported option on %s\n", ctx->ifname_ext); memset(&opt, 0, sizeof(opt)); opt.nro_reqtype = 1234; push_option(&opt, ctx); save = opt; if (port_register_hwall(ctx) >= 0) return -1; clear_options(ctx); save.nro_status = EOPNOTSUPP; return checkoption(&opt, &save); }
static int push_csb_option(struct TestContext *ctx, struct nmreq_opt_csb *opt) { size_t csb_size; int num_entries; int ret; ctx->nr_flags |= NR_EXCLUSIVE; /* Get port info in order to use num_registered_rings(). */ ret = port_info_get(ctx); if (ret != 0) { return ret; } num_entries = num_registered_rings(ctx); csb_size = (sizeof(struct nm_csb_atok) + sizeof(struct nm_csb_ktoa)) * num_entries; assert(csb_size > 0); if (ctx->csb) { free(ctx->csb); } ret = posix_memalign(&ctx->csb, sizeof(struct nm_csb_atok), csb_size); if (ret != 0) { printf("Failed to allocate CSB memory\n"); exit(EXIT_FAILURE); } memset(opt, 0, sizeof(*opt)); opt->nro_opt.nro_reqtype = NETMAP_REQ_OPT_CSB; opt->csb_atok = (uintptr_t)ctx->csb; opt->csb_ktoa = (uintptr_t)(((uint8_t *)ctx->csb) + sizeof(struct nm_csb_atok) * num_entries); printf("Pushing option NETMAP_REQ_OPT_CSB\n"); push_option(&opt->nro_opt, ctx); return 0; }
static int push_extmem_option(struct TestContext *ctx, const struct nmreq_pools_info *pi, struct nmreq_opt_extmem *e) { void *addr; addr = mmap(NULL, pi->nr_memsize, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_SHARED, -1, 0); if (addr == MAP_FAILED) { perror("mmap"); return -1; } memset(e, 0, sizeof(*e)); e->nro_opt.nro_reqtype = NETMAP_REQ_OPT_EXTMEM; e->nro_info = *pi; e->nro_usrptr = (uintptr_t)addr; push_option(&e->nro_opt, ctx); return 0; }
/* * Process server, server-bridge, and client helper * directives after the parameters themselves have been * parsed and placed in struct options. */ void helper_client_server (struct options *o) { struct gc_arena gc = gc_new (); #if P2MP #if P2MP_SERVER /* * Get tun/tap/null device type */ const int dev = dev_type_enum (o->dev, o->dev_type); const int topology = o->topology; /* * * HELPER DIRECTIVE for IPv6 * * server-ipv6 2001:db8::/64 * * EXPANDS TO: * * tun-ipv6 * push "tun-ipv6" * ifconfig-ipv6 2001:db8::1 2001:db8::2 * if !nopool: * ifconfig-ipv6-pool 2001:db8::1:0/64 * */ if ( o->server_ipv6_defined ) { if ( ! o->server_defined ) { msg (M_USAGE, "--server-ipv6 must be used together with --server"); } if ( o->server_flags & SF_NOPOOL ) { msg( M_USAGE, "--server-ipv6 is incompatible with 'nopool' option" ); } if ( o->ifconfig_ipv6_pool_defined ) { msg( M_USAGE, "--server-ipv6 already defines an ifconfig-ipv6-pool, so you can't also specify --ifconfig-pool explicitly"); } /* local ifconfig is "base address + 1" and "+2" */ o->ifconfig_ipv6_local = print_in6_addr( add_in6_addr( o->server_network_ipv6, 1), 0, &o->gc ); o->ifconfig_ipv6_remote = print_in6_addr( add_in6_addr( o->server_network_ipv6, 2), 0, &o->gc ); o->ifconfig_ipv6_netbits = o->server_netbits_ipv6; /* pool starts at "base address + 0x1000" - leave enough room */ ASSERT( o->server_netbits_ipv6 <= 112 ); /* want 16 bits */ o->ifconfig_ipv6_pool_defined = true; o->ifconfig_ipv6_pool_base = add_in6_addr( o->server_network_ipv6, 0x1000 ); o->ifconfig_ipv6_pool_netbits = o->server_netbits_ipv6; o->tun_ipv6 = true; push_option( o, "tun-ipv6", M_USAGE ); } /* * * HELPER DIRECTIVE: * * server 10.8.0.0 255.255.255.0 * * EXPANDS TO: * * mode server * tls-server * push "topology [topology]" * * if tun AND (topology == net30 OR topology == p2p): * ifconfig 10.8.0.1 10.8.0.2 * if !nopool: * ifconfig-pool 10.8.0.4 10.8.0.251 * route 10.8.0.0 255.255.255.0 * if client-to-client: * push "route 10.8.0.0 255.255.255.0" * else if topology == net30: * push "route 10.8.0.1" * * if tap OR (tun AND topology == subnet): * ifconfig 10.8.0.1 255.255.255.0 * if !nopool: * ifconfig-pool 10.8.0.2 10.8.0.254 255.255.255.0 * push "route-gateway 10.8.0.1" * if route-gateway unset: * route-gateway 10.8.0.2 */ if (o->server_defined) { int netbits = -2; bool status = false; if (o->client) msg (M_USAGE, "--server and --client cannot be used together"); if (o->server_bridge_defined || o->server_bridge_proxy_dhcp) msg (M_USAGE, "--server and --server-bridge cannot be used together"); if (o->shared_secret_file) msg (M_USAGE, "--server and --secret cannot be used together (you must use SSL/TLS keys)"); if (!(o->server_flags & SF_NOPOOL) && o->ifconfig_pool_defined) msg (M_USAGE, "--server already defines an ifconfig-pool, so you can't also specify --ifconfig-pool explicitly"); if (!(dev == DEV_TYPE_TAP || dev == DEV_TYPE_TUN)) msg (M_USAGE, "--server directive only makes sense with --dev tun or --dev tap"); status = netmask_to_netbits (o->server_network, o->server_netmask, &netbits); if (!status) msg (M_USAGE, "--server directive network/netmask combination is invalid"); if (netbits < 0) msg (M_USAGE, "--server directive netmask is invalid"); if (netbits < IFCONFIG_POOL_MIN_NETBITS) msg (M_USAGE, "--server directive netmask allows for too many host addresses (subnet must be %s or higher)", print_netmask (IFCONFIG_POOL_MIN_NETBITS, &gc)); if (dev == DEV_TYPE_TUN) { int pool_end_reserve = 4; if (netbits > 29) msg (M_USAGE, "--server directive when used with --dev tun must define a subnet of %s or lower", print_netmask (29, &gc)); if (netbits == 29) pool_end_reserve = 0; o->mode = MODE_SERVER; o->tls_server = true; if (topology == TOP_NET30 || topology == TOP_P2P) { o->ifconfig_local = print_in_addr_t (o->server_network + 1, 0, &o->gc); o->ifconfig_remote_netmask = print_in_addr_t (o->server_network + 2, 0, &o->gc); if (!(o->server_flags & SF_NOPOOL)) { o->ifconfig_pool_defined = true; o->ifconfig_pool_start = o->server_network + 4; o->ifconfig_pool_end = (o->server_network | ~o->server_netmask) - pool_end_reserve; ifconfig_pool_verify_range (M_USAGE, o->ifconfig_pool_start, o->ifconfig_pool_end); } helper_add_route (o->server_network, o->server_netmask, o); if (o->enable_c2c) push_option (o, print_opt_route (o->server_network, o->server_netmask, &o->gc), M_USAGE); else if (topology == TOP_NET30) push_option (o, print_opt_route (o->server_network + 1, 0, &o->gc), M_USAGE); } else if (topology == TOP_SUBNET) { o->ifconfig_local = print_in_addr_t (o->server_network + 1, 0, &o->gc); o->ifconfig_remote_netmask = print_in_addr_t (o->server_netmask, 0, &o->gc); if (!(o->server_flags & SF_NOPOOL)) { o->ifconfig_pool_defined = true; o->ifconfig_pool_start = o->server_network + 2; o->ifconfig_pool_end = (o->server_network | ~o->server_netmask) - 2; ifconfig_pool_verify_range (M_USAGE, o->ifconfig_pool_start, o->ifconfig_pool_end); } o->ifconfig_pool_netmask = o->server_netmask; push_option (o, print_opt_route_gateway (o->server_network + 1, &o->gc), M_USAGE); if (!o->route_default_gateway) o->route_default_gateway = print_in_addr_t (o->server_network + 2, 0, &o->gc); } else ASSERT (0); push_option (o, print_opt_topology (topology, &o->gc), M_USAGE); } else if (dev == DEV_TYPE_TAP) { if (netbits > 30) msg (M_USAGE, "--server directive when used with --dev tap must define a subnet of %s or lower", print_netmask (30, &gc)); o->mode = MODE_SERVER; o->tls_server = true; o->ifconfig_local = print_in_addr_t (o->server_network + 1, 0, &o->gc); o->ifconfig_remote_netmask = print_in_addr_t (o->server_netmask, 0, &o->gc); if (!(o->server_flags & SF_NOPOOL)) { o->ifconfig_pool_defined = true; o->ifconfig_pool_start = o->server_network + 2; o->ifconfig_pool_end = (o->server_network | ~o->server_netmask) - 1; ifconfig_pool_verify_range (M_USAGE, o->ifconfig_pool_start, o->ifconfig_pool_end); } o->ifconfig_pool_netmask = o->server_netmask; push_option (o, print_opt_route_gateway (o->server_network + 1, &o->gc), M_USAGE); } else { ASSERT (0); } /* set push-ifconfig-constraint directive */ if ((dev == DEV_TYPE_TAP || topology == TOP_SUBNET)) { o->push_ifconfig_constraint_defined = true; o->push_ifconfig_constraint_network = o->server_network; o->push_ifconfig_constraint_netmask = o->server_netmask; } } /* * HELPER DIRECTIVE: * * server-bridge 10.8.0.4 255.255.255.0 10.8.0.128 10.8.0.254 * * EXPANDS TO: * * mode server * tls-server * * ifconfig-pool 10.8.0.128 10.8.0.254 255.255.255.0 * push "route-gateway 10.8.0.4" * * OR * * server-bridge * * EXPANDS TO: * * mode server * tls-server * * if !nogw: * push "route-gateway dhcp" */ else if (o->server_bridge_defined | o->server_bridge_proxy_dhcp) { if (o->client) msg (M_USAGE, "--server-bridge and --client cannot be used together"); if (!(o->server_flags & SF_NOPOOL) && o->ifconfig_pool_defined) msg (M_USAGE, "--server-bridge already defines an ifconfig-pool, so you can't also specify --ifconfig-pool explicitly"); if (o->shared_secret_file) msg (M_USAGE, "--server-bridge and --secret cannot be used together (you must use SSL/TLS keys)"); if (dev != DEV_TYPE_TAP) msg (M_USAGE, "--server-bridge directive only makes sense with --dev tap"); if (o->server_bridge_defined) { verify_common_subnet ("--server-bridge", o->server_bridge_ip, o->server_bridge_pool_start, o->server_bridge_netmask); verify_common_subnet ("--server-bridge", o->server_bridge_pool_start, o->server_bridge_pool_end, o->server_bridge_netmask); verify_common_subnet ("--server-bridge", o->server_bridge_ip, o->server_bridge_pool_end, o->server_bridge_netmask); } o->mode = MODE_SERVER; o->tls_server = true; if (o->server_bridge_defined) { o->ifconfig_pool_defined = true; o->ifconfig_pool_start = o->server_bridge_pool_start; o->ifconfig_pool_end = o->server_bridge_pool_end; ifconfig_pool_verify_range (M_USAGE, o->ifconfig_pool_start, o->ifconfig_pool_end); o->ifconfig_pool_netmask = o->server_bridge_netmask; push_option (o, print_opt_route_gateway (o->server_bridge_ip, &o->gc), M_USAGE); } else if (o->server_bridge_proxy_dhcp && !(o->server_flags & SF_NO_PUSH_ROUTE_GATEWAY)) { push_option (o, print_opt_route_gateway_dhcp (&o->gc), M_USAGE); } } else #endif /* P2MP_SERVER */ /* * HELPER DIRECTIVE: * * client * * EXPANDS TO: * * pull * tls-client */ if (o->client) { if (o->key_method != 2) msg (M_USAGE, "--client requires --key-method 2"); o->pull = true; o->tls_client = true; } #endif /* P2MP */ gc_free (&gc); }
//+++++++++++++++++++++++++ void interrogation_factory::load_file( QString path ){ // csv_reader reader( path ); // create_interrogation(); // QString path_info=""; // Parse our file content. // while( reader.goto_next_line() ){ // QStringList tokens = reader.line_tokens(); // Comments. // if( tokens.at(0).compare("--") == 0 ) return; // Info. // if( tokens.at(0).compare("#i") == 0 ){ path_info = tokens.at(1); } // Datasets. // if( tokens.at(0).compare("#d") == 0 ){ // submit_question(); // QString path_data = tokens.at(1); // push_dataset( path_data, path_info ); } // Questions. // else if( tokens.at(0).compare("#q") == 0 ){ submit_question(); start_question(); push_question( tokens.at(1) ); } // Question options. // else if( tokens.at(0).compare("#qo") == 0 ) push_option( tokens.at(1) ); } // Submit any outstanding questions. // submit_question(); // Let's see what we loaded. // QString("Interrgation..."); for( int ii=0; ii<_cached_interrogation->_pairs.size(); ii++ ){ // dataset_questions_pair* pair = &_cached_interrogation->_pairs.at(ii); // QString dataset = pair->_dataset->name(); std::vector< question > *questions = &pair->_questions; // The dataset. // helpers::debug_out( QString("dataset [%1]").arg(dataset) ); // Questions / Options. // for( int ii=0; ii<questions->size(); ii++ ){ // The question. // question* tmp = &questions->at(ii); helpers::debug_out( QString("Q: %1").arg(tmp->get_question()) ); // The options. // for( int jj=0; jj<tmp->get_options().size(); jj++ ) helpers::debug_out( QString("\t%1").arg( tmp->get_options().at(jj) ) ); } } }