static void func_new (void *vo, NCDModuleInst *i, const struct NCDModuleInst_new_params *params) { struct instance *o = vo; o->i = i; // check arguments if (!NCDVal_ListRead(params->args, 0)) { ModuleLog(o->i, BLOG_ERROR, "wrong arity"); goto fail0; } // init users list LinkedList1_Init(&o->users); // init rdownups list LinkedList0_Init(&o->rdownups_list); // set not up o->up = 0; // set not dying o->dying = 0; // signal up NCDModuleInst_Backend_Up(o->i); return; fail0: NCDModuleInst_Backend_DeadError(i); }
void BPendingGroup_Init (BPendingGroup *g) { // init jobs list LinkedList1_Init(&g->jobs); // init pending counter DebugCounter_Init(&g->pending_ctr); // init debug object DebugObject_Init(&g->d_obj); }
static int func_globalinit (struct NCDInterpModuleGroup *group, const struct NCDModuleInst_iparams *params) { // allocate global state structure struct global *g = BAlloc(sizeof(*g)); if (!g) { BLog(BLOG_ERROR, "BAlloc failed"); return 0; } // set group state pointer group->group_state = g; // init instances list LinkedList1_Init(&g->instances); return 1; }
int DPReceiveDevice_Init (DPReceiveDevice *o, int device_mtu, DPReceiveDevice_output_func output_func, void *output_func_user, BReactor *reactor, int relay_flow_buffer_size, int relay_flow_inactivity_time) { ASSERT(device_mtu >= 0) ASSERT(device_mtu <= INT_MAX - DATAPROTO_MAX_OVERHEAD) ASSERT(output_func) ASSERT(relay_flow_buffer_size > 0) // init arguments o->device_mtu = device_mtu; o->output_func = output_func; o->output_func_user = output_func_user; o->reactor = reactor; o->relay_flow_buffer_size = relay_flow_buffer_size; o->relay_flow_inactivity_time = relay_flow_inactivity_time; // remember packet MTU o->packet_mtu = DATAPROTO_MAX_OVERHEAD + o->device_mtu; // init relay router if (!DPRelayRouter_Init(&o->relay_router, o->device_mtu, o->reactor)) { BLog(BLOG_ERROR, "DPRelayRouter_Init failed"); goto fail0; } // have no peer ID o->have_peer_id = 0; // init peers list LinkedList1_Init(&o->peers_list); DebugObject_Init(&o->d_obj); return 1; fail0: return 0; }
void PacketPassFifoQueue_Init (PacketPassFifoQueue *o, PacketPassInterface *output, BPendingGroup *pg) { // init arguments o->output = output; o->pg = pg; // init output PacketPassInterface_Sender_Init(output, (PacketPassInterface_handler_done)output_handler_done, o); // init waiting flows list LinkedList1_Init(&o->waiting_flows_list); // set no sending flow o->sending_flow = NULL; // init schedule job BPending_Init(&o->schedule_job, pg, (BPending_handler)schedule_job_handler, o); // set not freeing o->freeing = 0; DebugCounter_Init(&o->d_flows_ctr); DebugObject_Init(&o->d_obj); }
static void func_new_resolvconf (void *vo, NCDModuleInst *i, const struct NCDModuleInst_new_params *params) { struct global *g = ModuleGlobal(i); struct instance *o = vo; o->i = i; // init servers list LinkedList1_Init(&o->entries); // get arguments NCDValRef lines_arg; NCDValRef priority_arg; if (!NCDVal_ListRead(params->args, 2, &lines_arg, &priority_arg)) { ModuleLog(o->i, BLOG_ERROR, "wrong arity"); goto fail1; } if (!NCDVal_IsList(lines_arg) || !NCDVal_IsString(priority_arg)) { ModuleLog(o->i, BLOG_ERROR, "wrong type"); goto fail1; } uintmax_t priority; if (!ncd_read_uintmax(priority_arg, &priority) || priority > INT_MAX) { ModuleLog(o->i, BLOG_ERROR, "wrong priority"); goto fail1; } // read lines size_t count = NCDVal_ListCount(lines_arg); for (size_t j = 0; j < count; j++) { int loop_failed = 1; NCDValRef line = NCDVal_ListGet(lines_arg, j); if (!NCDVal_IsList(line) || NCDVal_ListCount(line) != 2) { ModuleLog(o->i, BLOG_ERROR, "lines element is not a list with two elements"); goto loop_fail0; } NCDValRef type = NCDVal_ListGet(line, 0); NCDValRef value = NCDVal_ListGet(line, 1); if (!NCDVal_IsStringNoNulls(type) || !NCDVal_IsStringNoNulls(value)) { ModuleLog(o->i, BLOG_ERROR, "wrong type of type or value"); goto loop_fail0; } NCDValNullTermString type_nts; if (!NCDVal_StringNullTerminate(type, &type_nts)) { ModuleLog(o->i, BLOG_ERROR, "NCDVal_StringNullTerminate failed"); goto loop_fail0; } NCDValNullTermString value_nts; if (!NCDVal_StringNullTerminate(value, &value_nts)) { ModuleLog(o->i, BLOG_ERROR, "NCDVal_StringNullTerminate failed"); goto loop_fail1; } if (!add_dns_entry(o, type_nts.data, value_nts.data, priority)) { ModuleLog(o->i, BLOG_ERROR, "failed to add dns entry"); goto loop_fail2; } loop_failed = 0; loop_fail2: NCDValNullTermString_Free(&value_nts); loop_fail1: NCDValNullTermString_Free(&type_nts); loop_fail0: if (loop_failed) { goto fail1; } } // add to instances LinkedList1_Append(&g->instances, &o->instances_node); // set servers if (!set_servers(g)) { ModuleLog(o->i, BLOG_ERROR, "failed to set DNS servers"); goto fail2; } // signal up NCDModuleInst_Backend_Up(o->i); return; fail2: LinkedList1_Remove(&g->instances, &o->instances_node); fail1: remove_entries(o); NCDModuleInst_Backend_DeadError(i); }
static void func_new (void *vo, NCDModuleInst *i, const struct NCDModuleInst_new_params *params) { struct global *g = ModuleGlobal(i); struct instance *o = vo; o->i = i; // init servers list LinkedList1_Init(&o->entries); // get arguments NCDValRef servers_arg; NCDValRef priority_arg; if (!NCDVal_ListRead(params->args, 2, &servers_arg, &priority_arg)) { ModuleLog(o->i, BLOG_ERROR, "wrong arity"); goto fail1; } if (!NCDVal_IsList(servers_arg) || !NCDVal_IsString(priority_arg)) { ModuleLog(o->i, BLOG_ERROR, "wrong type"); goto fail1; } uintmax_t priority; if (!ncd_read_uintmax(priority_arg, &priority) || priority > INT_MAX) { ModuleLog(o->i, BLOG_ERROR, "wrong priority"); goto fail1; } // read servers size_t count = NCDVal_ListCount(servers_arg); for (size_t j = 0; j < count; j++) { NCDValRef server_arg = NCDVal_ListGet(servers_arg, j); if (!NCDVal_IsString(server_arg)) { ModuleLog(o->i, BLOG_ERROR, "wrong type"); goto fail1; } uint32_t addr; if (!ipaddr_parse_ipv4_addr_bin((char *)NCDVal_StringData(server_arg), NCDVal_StringLength(server_arg), &addr)) { ModuleLog(o->i, BLOG_ERROR, "wrong addr"); goto fail1; } char addr_str[IPADDR_PRINT_MAX]; ipaddr_print_addr(addr, addr_str); if (!add_dns_entry(o, "nameserver", addr_str, priority)) { ModuleLog(o->i, BLOG_ERROR, "failed to add dns entry"); goto fail1; } } // add to instances LinkedList1_Append(&g->instances, &o->instances_node); // set servers if (!set_servers(g)) { ModuleLog(o->i, BLOG_ERROR, "failed to set DNS servers"); goto fail2; } // signal up NCDModuleInst_Backend_Up(o->i); return; fail2: LinkedList1_Remove(&g->instances, &o->instances_node); fail1: remove_entries(o); NCDModuleInst_Backend_DeadError(i); }