static svmdb_client_t * svmdb_map_internal (char *root_path, uword size) { svmdb_client_t *client = 0; svm_map_region_args_t *a = 0; svm_region_t *db_rp; void *oldheap; svmdb_shm_hdr_t *hp = 0; vec_validate (client, 0); vec_validate (a, 0); svm_region_init_chroot (root_path); a->root_path = root_path; a->name = "/db"; a->size = size ? size : SVMDB_DEFAULT_SIZE; a->flags = SVM_FLAGS_MHEAP; db_rp = client->db_rp = svm_region_find_or_create (a); ASSERT (db_rp); vec_free (a); region_lock (client->db_rp, 10); /* Has someone else set up the shared-memory variable table? */ if (db_rp->user_ctx) { client->shm = (void *) db_rp->user_ctx; client->pid = getpid (); region_unlock (client->db_rp); ASSERT (client->shm->version == SVMDB_SHM_VERSION); return (client); } /* Nope, it's our problem... */ /* Add a bogus client (pid=0) so the svm won't be deallocated */ oldheap = svm_push_pvt_heap (db_rp); vec_add1 (client->db_rp->client_pids, 0); svm_pop_heap (oldheap); oldheap = svm_push_data_heap (db_rp); vec_validate (hp, 0); hp->version = SVMDB_SHM_VERSION; hp->namespaces[SVMDB_NAMESPACE_STRING] = hash_create_string (0, sizeof (uword)); hp->namespaces[SVMDB_NAMESPACE_VEC] = hash_create_string (0, sizeof (uword)); db_rp->user_ctx = hp; client->shm = hp; svm_pop_heap (oldheap); region_unlock (client->db_rp); client->pid = getpid (); return (client); }
int vat_plugin_init (vat_main_t * vam) { plugin_main_t *pm = &vat_plugin_main; u8 *vlib_get_vat_plugin_path (void); u8 *vlib_get_vat_plugin_name_filter (void); u8 *plugin_path; u8 *plugin_name_filter; plugin_path = vlib_get_vat_plugin_path (); plugin_name_filter = vlib_get_vat_plugin_name_filter (); if (plugin_path) vat_plugin_path = (char *) plugin_path; if (plugin_name_filter) vat_plugin_name_filter = (char *) plugin_name_filter; pm->plugin_path = format (0, "%s%c", vat_plugin_path, 0); if (vat_plugin_name_filter) pm->plugin_name_filter = format (0, "%s%c", vat_plugin_name_filter, 0); pm->plugin_by_name_hash = hash_create_string (0, sizeof (uword)); pm->vat_main = vam; return vat_load_new_plugins (pm); }
static clib_error_t * ethernet_init (vlib_main_t * vm) { ethernet_main_t *em = ðernet_main; clib_error_t *error; /* * Set up the L2 path now, or we'll wipe out the L2 ARP * registration set up by ethernet_arp_init. */ if ((error = vlib_call_init_function (vm, l2_init))) return error; em->vlib_main = vm; em->type_info_by_name = hash_create_string (0, sizeof (uword)); em->type_info_by_type = hash_create (0, sizeof (uword)); #define ethernet_type(n,s) add_type (em, ETHERNET_TYPE_##s, #s); #include "types.def" #undef ethernet_type if ((error = vlib_call_init_function (vm, llc_init))) return error; if ((error = vlib_call_init_function (vm, ethernet_input_init))) return error; if ((error = vlib_call_init_function (vm, vnet_feature_init))) return error; return 0; }
/* * read_cpel_file */ int read_cpel_file(char *cpel_file) { int verbose = 0; int rv; static u8 *cpel; static unsigned long size; static FILE *ofp; if (cpel) { unmapfile((char *)cpel, size); hash_free(the_strtab_hash); the_strtab_hash = 0; hash_free(the_evtdef_hash); the_evtdef_hash = 0; hash_free(the_trackdef_hash); the_trackdef_hash = 0; } cpel = (u8 *)mapfile((char *)cpel_file, &size); if (cpel == 0) { fprintf(stderr, "Couldn't map %s...\n", cpel_file); exit(1); } if (ofp == NULL) { ofp = fdopen(2, "w"); if (ofp == NULL) { fprintf(stderr, "Couldn't fdopen(2)?\n"); exit(1); } } the_strtab_hash = hash_create_string (0, sizeof (uword)); the_evtdef_hash = hash_create (0, sizeof (uword)); the_trackdef_hash = hash_create (0, sizeof (uword)); rv = cpel_process(cpel, verbose, ofp); set_pid_ax_width(8*widest_track_format); return(rv); }
static u32 elog_id_for_msg_name (vlib_main_t * vm, char *msg_name) { uword * p, r; static uword * h; u8 *name_copy; if (! h) h = hash_create_string (0, sizeof (uword)); p = hash_get_mem (h, msg_name); if (p) return p[0]; r = elog_string (&vm->elog_main, "%s", msg_name); name_copy = format (0, "%s%c", msg_name, 0); hash_set_mem (h, name_copy, r); return r; }
static clib_error_t * ethernet_init (vlib_main_t * vm) { ethernet_main_t * em = ðernet_main; clib_error_t * error; em->vlib_main = vm; em->type_info_by_name = hash_create_string (0, sizeof (uword)); em->type_info_by_type = hash_create (0, sizeof (uword)); #define ethernet_type(n,s) add_type (em, ETHERNET_TYPE_##s, #s); #include "types.def" #undef ethernet_type if ((error = vlib_call_init_function (vm, llc_init))) return error; if ((error = vlib_call_init_function (vm, ethernet_input_init))) return error; if ((error = vlib_call_init_function (vm, ethernet_cli_init))) return error; return error; }
clib_error_t * ip_main_init (vlib_main_t * vm) { ip_main_t * im = &ip_main; clib_error_t * error = 0; memset (im, 0, sizeof (im[0])); { ip_protocol_info_t * pi; u32 i; #define ip_protocol(n,s) \ do { \ vec_add2 (im->protocol_infos, pi, 1); \ pi->protocol = n; \ pi->name = (u8 *) #s; \ } while (0); #include "protocols.def" #undef ip_protocol im->protocol_info_by_name = hash_create_string (0, sizeof (uword)); for (i = 0; i < vec_len (im->protocol_infos); i++) { pi = im->protocol_infos + i; hash_set_mem (im->protocol_info_by_name, pi->name, i); hash_set (im->protocol_info_by_protocol, pi->protocol, i); } } { tcp_udp_port_info_t * pi; u32 i; static char * port_names[] = { #define ip_port(s,n) #s, #include "ports.def" #undef ip_port }; static u16 ports[] = { #define ip_port(s,n) n, #include "ports.def" #undef ip_port }; vec_resize (im->port_infos, ARRAY_LEN (port_names)); im->port_info_by_name = hash_create_string (0, sizeof (uword)); for (i = 0; i < vec_len (im->port_infos); i++) { pi = im->port_infos + i; pi->port = clib_host_to_net_u16 (ports[i]); pi->name = (u8 *) port_names[i]; hash_set_mem (im->port_info_by_name, pi->name, i); hash_set (im->port_info_by_port, pi->port, i); } } if ((error = vlib_call_init_function (vm, vnet_main_init))) return error; if ((error = vlib_call_init_function (vm, ip4_init))) return error; if ((error = vlib_call_init_function (vm, ip6_init))) return error; if ((error = vlib_call_init_function (vm, icmp4_init))) return error; if ((error = vlib_call_init_function (vm, icmp6_init))) return error; if ((error = vlib_call_init_function (vm, ip6_hop_by_hop_init))) return error; if ((error = vlib_call_init_function (vm, udp_local_init))) return error; if ((error = vlib_call_init_function (vm, udp_init))) return error; if ((error = vlib_call_init_function (vm, ip_classify_init))) return error; if ((error = vlib_call_init_function (vm, input_acl_init))) return error; return error; }
/* Entry point for the assembler. code_ref is assumed to be attached to the gc. */ size_t asm_string(gc_type *gc, char *str, uint8_t **code_ref) { yyscan_t scanner = 0; op_type token = 0; buffer_type *buf = 0; hashtable_type *labels = 0; jump_type *jump_list = 0; size_t length = 0; gc_register_root(gc, &buf); gc_register_root(gc, &labels); gc_register_root(gc, (void **)&jump_list); /* create an output buffer */ buffer_create(gc, &buf); hash_create_string(gc, &labels); yylex_init(&scanner); /* yyset_debug(1, scanner); */ /* set the scanners input */ yy_scan_string(str, scanner); /* match until there is nothing left to match */ while((token = yylex(scanner)) != END_OF_FILE) { /* Handle individual tokens */ switch((int)token) { case OP_LIT_FIXNUM: asm_lit_fixnum(buf, scanner); break; case OP_LIT_CHAR: asm_lit_char(buf, scanner); break; case STRING_START_TOKEN: EMIT(buf, OP_LIT_STRING, 1); asm_lit_string(buf, scanner); break; case SYMBOL_START_TOKEN: EMIT(buf, OP_LIT_SYMBOL, 1); asm_lit_string(buf, scanner); break; case OP_JMP: case OP_JNF: case OP_CALL: case OP_PROC: case OP_CONTINUE: EMIT(buf, token, 1); /* emit the jump operation */ asm_jump(gc, buf, scanner, &jump_list); break; case LABEL_TOKEN: asm_label(gc, buf, labels, get_text(scanner)); break; /* All otherwise not defined tokens are their opcode */ default: EMIT(buf, token, 1); break; } } yylex_destroy(scanner); /* build a code_ref */ length = buffer_size(buf); /* *code_ref = gc_alloc(gc, 0, length); */ gc_alloc(gc, 0, length, (void **)code_ref); length = buffer_read(buf, *code_ref, length); /* replace jump address fields */ rewrite_jumps(*code_ref, jump_list, labels); gc_unregister_root(gc, &buf); gc_unregister_root(gc, &labels); gc_unregister_root(gc, (void **)&jump_list); return length; }
clib_error_t * vlib_call_all_config_functions (vlib_main_t * vm, unformat_input_t * input, int is_early) { clib_error_t *error = 0; vlib_config_function_runtime_t *c, **all; uword *hash = 0, *p; uword i; hash = hash_create_string (0, sizeof (uword)); all = 0; c = vm->config_function_registrations; while (c) { hash_set_mem (hash, c->name, vec_len (all)); vec_add1 (all, c); unformat_init (&c->input, 0, 0); c = c->next_registration; } while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) { u8 *s, *v; if (!unformat (input, "%s %v", &s, &v) || !(p = hash_get_mem (hash, s))) { error = clib_error_create ("unknown input `%s %v'", s, v); goto done; } c = all[p[0]]; if (vec_len (c->input.buffer) > 0) vec_add1 (c->input.buffer, ' '); vec_add (c->input.buffer, v, vec_len (v)); vec_free (v); vec_free (s); } for (i = 0; i < vec_len (all); i++) { c = all[i]; /* Is this an early config? Are we doing early configs? */ if (is_early ^ c->is_early) continue; /* Already called? */ if (hash_get (vm->init_functions_called, c->function)) continue; hash_set1 (vm->init_functions_called, c->function); error = c->function (vm, &c->input); if (error) goto done; } done: for (i = 0; i < vec_len (all); i++) { c = all[i]; unformat_free (&c->input); } vec_free (all); hash_free (hash); return error; }
int test_ptclosure_main (unformat_input_t * input) { test_main_t *tm = &test_main; u8 *item_name; int i, j; u8 **orig; u8 **closure; u8 *a_name, *b_name; int a_index, b_index; uword *p; u8 *this_constraint; int n; u32 *result = 0; tm->index_by_name = hash_create_string (0, sizeof (uword)); n = ARRAY_LEN (items); for (i = 0; i < n; i++) { item_name = (u8 *) items[i]; hash_set_mem (tm->index_by_name, item_name, i); } orig = clib_ptclosure_alloc (n); for (i = 0; i < ARRAY_LEN (constraints); i++) { this_constraint = format (0, "%s%c", constraints[i], 0); if (comma_split (this_constraint, &a_name, &b_name)) { clib_warning ("couldn't split '%s'", constraints[i]); return 1; } p = hash_get_mem (tm->index_by_name, a_name); if (p == 0) { clib_warning ("couldn't find '%s'", a_name); return 1; } a_index = p[0]; p = hash_get_mem (tm->index_by_name, b_name); if (p == 0) { clib_warning ("couldn't find '%s'", b_name); return 1; } b_index = p[0]; orig[a_index][b_index] = 1; vec_free (this_constraint); } dump_closure (tm, "original relation", orig); closure = clib_ptclosure (orig); dump_closure (tm, "closure", closure); /* * Output partial order */ again: for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { if (closure[i][j]) goto item_constrained; } /* Item i can be output */ vec_add1 (result, i); { int k; for (k = 0; k < n; k++) closure[k][i] = 0; /* "Magic" a before a, to keep from ever outputting it again */ closure[i][i] = 1; goto again; } item_constrained: ; } if (vec_len (result) != n) { clib_warning ("no partial order exists"); exit (1); } fformat (stdout, "Partial order:\n"); for (i = vec_len (result) - 1; i >= 0; i--) { fformat (stdout, "%s\n", items[result[i]]); } vec_free (result); clib_ptclosure_free (orig); clib_ptclosure_free (closure); return 0; }