Ejemplo n.º 1
0
Archivo: if.c Proyecto: AmVPN/badvpn
static void new_templ (NCDModuleInst *i, const struct NCDModuleInst_new_params *params, int is_not)
{
    // check arguments
    NCDValRef arg;
    if (!NCDVal_ListRead(params->args, 1, &arg)) {
        ModuleLog(i, BLOG_ERROR, "wrong arity");
        goto fail0;
    }
    int arg_val;
    if (!ncd_read_boolean(arg, &arg_val)) {
        ModuleLog(i, BLOG_ERROR, "bad argument");
        goto fail0;
    }
    
    // compute logical value of argument
    int c = arg_val;
    
    // signal up if needed
    if ((is_not && !c) || (!is_not && c)) {
        NCDModuleInst_Backend_Up(i);
    }
    
    return;
    
fail0:
    NCDModuleInst_Backend_DeadError(i);
}
Ejemplo n.º 2
0
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);
}
Ejemplo n.º 3
0
static void func_new_from_value (void *vo, NCDModuleInst *i, const struct NCDModuleInst_new_params *params)
{
    // read arguments
    NCDValRef arg_value;
    if (!NCDVal_ListRead(params->args, 1, &arg_value)) {
        ModuleLog(i, BLOG_ERROR, "wrong arity");
        goto fail0;
    }
    if (!NCDVal_IsString(arg_value)) {
        ModuleLog(i, BLOG_ERROR, "wrong type");
        goto fail0;
    }

    // parse value
    uintmax_t value;
    if (!ncd_read_uintmax(arg_value, &value)) {
        ModuleLog(i, BLOG_ERROR, "wrong value");
        goto fail0;
    }

    // check overflow
    if (value > SIZE_MAX) {
        ModuleLog(i, BLOG_ERROR, "value too large");
        goto fail0;
    }

    func_new_templ(vo, i, value);
    return;

fail0:
    NCDModuleInst_Backend_DeadError(i);
}
Ejemplo n.º 4
0
static void func_new (void *vo, NCDModuleInst *i, const struct NCDModuleInst_new_params *params)
{
    struct instance *o = vo;
    o->i = i;
    
    // read arguments
    NCDValRef arg_choices;
    NCDValRef arg_default_result;
    if (!NCDVal_ListRead(params->args, 2, &arg_choices, &arg_default_result)) {
        ModuleLog(i, BLOG_ERROR, "wrong arity");
        goto fail0;
    }
    if (!NCDVal_IsList(arg_choices)) {
        ModuleLog(i, BLOG_ERROR, "wrong type");
        goto fail0;
    }
    
    // iterate choices
    int have_result = 0;
    size_t count = NCDVal_ListCount(arg_choices);
    for (size_t j = 0; j < count; j++) {
        NCDValRef c = NCDVal_ListGet(arg_choices, j);
        
        // check choice type
        if (!NCDVal_IsList(c)) {
            ModuleLog(i, BLOG_ERROR, "wrong choice type");
            goto fail0;
        }
        
        // read choice
        NCDValRef c_cond;
        NCDValRef c_result;
        if (!NCDVal_ListRead(c, 2, &c_cond, &c_result)) {
            ModuleLog(i, BLOG_ERROR, "wrong choice contents arity");
            goto fail0;
        }
        if (!NCDVal_IsString(c_cond)) {
            ModuleLog(i, BLOG_ERROR, "wrong choice condition type");
            goto fail0;
        }
        
        // update result
        if (!have_result && ncd_read_boolean(c_cond)) {
            o->result = c_result;
            have_result = 1;
        }
    }
    
    // default?
    if (!have_result) {
        o->result = arg_default_result;
    }
    
    // signal up
    NCDModuleInst_Backend_Up(o->i);
    return;
    
fail0:
    NCDModuleInst_Backend_DeadError(i);
}
Ejemplo n.º 5
0
static void prefix_to_mask_func_init (void *vo, NCDModuleInst *i, const struct NCDModuleInst_new_params *params)
{
    // read arguments
    NCDValRef prefix_arg;
    if (!NCDVal_ListRead(params->args, 1, &prefix_arg)) {
        ModuleLog(i, BLOG_ERROR, "wrong arity");
        goto fail0;
    }
    if (!NCDVal_IsString(prefix_arg)) {
        ModuleLog(i, BLOG_ERROR, "wrong type");
        goto fail0;
    }
    
    // parse prefix
    int prefix;
    if (!ipaddr_parse_ipv4_prefix(NCDVal_StringMemRef(prefix_arg), &prefix)) {
        ModuleLog(i, BLOG_ERROR, "bad prefix");
        goto fail0;
    }
    
    // make mask
    uint32_t mask = ipaddr_ipv4_mask_from_prefix(prefix);
    
    addr_func_init_templ(vo, i, mask);
    return;
    
fail0:
    NCDModuleInst_Backend_DeadError(i);
}
Ejemplo n.º 6
0
static void func_new (void *vo, NCDModuleInst *i, const struct NCDModuleInst_new_params *params)
{
    struct instance *o = vo;
    o->i = i;
    
    // check arguments
    NCDValRef str1_arg;
    NCDValRef str2_arg;
    if (!NCDVal_ListRead(params->args, 2, &str1_arg, &str2_arg)) {
        ModuleLog(i, BLOG_ERROR, "wrong arity");
        goto fail0;
    }
    if (!NCDVal_IsString(str1_arg) || !NCDVal_IsString(str2_arg)) {
        ModuleLog(i, BLOG_ERROR, "wrong type");
        goto fail0;
    }
    
    // compare
    o->result = (NCDVal_Compare(str1_arg, str2_arg) == 0);
    
    // signal up
    NCDModuleInst_Backend_Up(i);
    return;
    
fail0:
    NCDModuleInst_Backend_DeadError(i);
}
Ejemplo n.º 7
0
static void new_number_templ (void *vo, NCDModuleInst *i, const struct NCDModuleInst_new_params *params, number_compute_func cfunc)
{
    struct number_instance *o = vo;
    o->i = i;
    
    NCDValRef n1_arg;
    NCDValRef n2_arg;
    if (!NCDVal_ListRead(params->args, 2, &n1_arg, &n2_arg)) {
        ModuleLog(i, BLOG_ERROR, "wrong arity");
        goto fail0;
    }
    
    uintmax_t n1;
    if (!ncd_read_uintmax(n1_arg, &n1)) {
        ModuleLog(o->i, BLOG_ERROR, "wrong first argument");
        goto fail0;
    }
    
    uintmax_t n2;
    if (!ncd_read_uintmax(n2_arg, &n2)) {
        ModuleLog(o->i, BLOG_ERROR, "wrong second argument");
        goto fail0;
    }
    
    o->error = cfunc(i, n1, n2, &o->value);
    
    NCDModuleInst_Backend_Up(i);
    return;
    
fail0:
    NCDModuleInst_Backend_DeadError(i);
}
Ejemplo n.º 8
0
static void func_new (void *vo, NCDModuleInst *i, const struct NCDModuleInst_new_params *params)
{
    struct instance *o = vo;
    o->i = i;
    
    // read arguments
    NCDValRef ifname_arg;
    NCDValRef addr_arg;
    NCDValRef prefix_arg = NCDVal_NewInvalid();
    if (!NCDVal_ListRead(params->args, 2, &ifname_arg, &addr_arg) &&
        !NCDVal_ListRead(params->args, 3, &ifname_arg, &addr_arg, &prefix_arg)
    ) {
        ModuleLog(o->i, BLOG_ERROR, "wrong arity");
        goto fail0;
    }
    if (!NCDVal_IsStringNoNulls(ifname_arg) || !NCDVal_IsString(addr_arg) ||
        (!NCDVal_IsInvalid(prefix_arg) && !NCDVal_IsString(prefix_arg))
    ) {
        ModuleLog(o->i, BLOG_ERROR, "wrong type");
        goto fail0;
    }
    
    // null terminate ifname
    if (!NCDVal_StringNullTerminate(ifname_arg, &o->ifname_nts)) {
        ModuleLog(i, BLOG_ERROR, "NCDVal_StringNullTerminate failed");
        goto fail0;
    }
    
    if (NCDVal_IsInvalid(prefix_arg)) {
        if (!ipaddr_parse_ipv4_ifaddr(NCDVal_StringMemRef(addr_arg), &o->ifaddr)) {
            ModuleLog(o->i, BLOG_ERROR, "wrong CIDR notation address");
            goto fail1;
        }
    } else {
        if (!ipaddr_parse_ipv4_addr(NCDVal_StringMemRef(addr_arg), &o->ifaddr.addr)) {
            ModuleLog(o->i, BLOG_ERROR, "wrong address");
            goto fail1;
        }
        
        if (!ipaddr_parse_ipv4_prefix(NCDVal_StringMemRef(prefix_arg), &o->ifaddr.prefix)) {
            ModuleLog(o->i, BLOG_ERROR, "wrong prefix");
            goto fail1;
        }
    }
    
    // add address
    if (!NCDIfConfig_add_ipv4_addr(o->ifname_nts.data, o->ifaddr)) {
        ModuleLog(o->i, BLOG_ERROR, "failed to add IP address");
        goto fail1;
    }
    
    // signal up
    NCDModuleInst_Backend_Up(o->i);
    return;
    
fail1:
    NCDValNullTermString_Free(&o->ifname_nts);
fail0:
    NCDModuleInst_Backend_DeadError(i);
}
Ejemplo n.º 9
0
Archivo: exit.c Proyecto: 2722/lantern
static void func_new (void *unused, NCDModuleInst *i, const struct NCDModuleInst_new_params *params)
{
    // check arguments
    NCDValRef exit_code_arg;
    if (!NCDVal_ListRead(params->args, 1, &exit_code_arg)) {
        ModuleLog(i, BLOG_ERROR, "wrong arity");
        goto fail0;
    }
    if (!NCDVal_IsString(exit_code_arg)) {
        ModuleLog(i, BLOG_ERROR, "wrong type");
        goto fail0;
    }

    // parse exit code
    uintmax_t exit_code;
    if (!ncd_read_uintmax(exit_code_arg, &exit_code) || exit_code >= INT_MAX) {
        ModuleLog(i, BLOG_ERROR, "wrong exit code value");
        goto fail0;
    }

    // signal up
    NCDModuleInst_Backend_Up(i);

    // initiate exit (before up!)
    NCDModuleInst_Backend_InterpExit(i, exit_code);
    return;

fail0:
    NCDModuleInst_Backend_DeadError(i);
}
Ejemplo n.º 10
0
static void func_new (void *vo, NCDModuleInst *i, const struct NCDModuleInst_new_params *params)
{
    struct instance *o = vo;
    o->i = i;
    
    // read arguments
    NCDValRef target_arg;
    if (!NCDVal_ListRead(params->args, 1, &target_arg)) {
        ModuleLog(i, BLOG_ERROR, "wrong arity");
        goto fail0;
    }
    if (!NCDVal_IsString(target_arg)) {
        ModuleLog(i, BLOG_ERROR, "wrong type");
        goto fail0;
    }
    
    // parse name string
    if (!AliasNames_InitNames(o, i->params->iparams->string_index, NCDVal_StringData(target_arg), NCDVal_StringLength(target_arg))) {
        ModuleLog(i, BLOG_ERROR, "make_names failed");
        goto fail0;
    }
    
    // signal up
    NCDModuleInst_Backend_Up(o->i);
    return;
    
fail0:
    NCDModuleInst_Backend_DeadError(i);
}
Ejemplo n.º 11
0
static void func_new (void *vo, NCDModuleInst *i, const struct NCDModuleInst_new_params *params)
{
    struct instance *o = vo;
    o->i = i;
    
    // check arguments
    NCDValRef arg;
    if (!NCDVal_ListRead(params->args, 1, &arg)) {
        ModuleLog(o->i, BLOG_ERROR, "wrong arity");
        goto fail0;
    }
    if (!NCDVal_IsStringNoNulls(arg)) {
        ModuleLog(o->i, BLOG_ERROR, "wrong type");
        goto fail0;
    }
    o->ifname = NCDVal_StringMemRef(arg);
    
    // init client
    NCDUdevClient_Init(&o->client, o->i->params->iparams->umanager, o, (NCDUdevClient_handler)client_handler);
    
    // compile regex
    if (regcomp(&o->reg, DEVPATH_REGEX, REG_EXTENDED)) {
        ModuleLog(o->i, BLOG_ERROR, "regcomp failed");
        goto fail1;
    }
    
    // set no devpath
    o->devpath = NULL;
    return;
    
fail1:
    NCDUdevClient_Free(&o->client);
fail0:
    NCDModuleInst_Backend_DeadError(i);
}
Ejemplo n.º 12
0
static void new_templ (void *vo, NCDModuleInst *i, const struct NCDModuleInst_new_params *params, parse_func pfunc)
{
    struct instance *o = vo;
    o->i = i;
    
    // read arguments
    NCDValRef str_arg;
    if (!NCDVal_ListRead(params->args, 1, &str_arg)) {
        ModuleLog(i, BLOG_ERROR, "wrong arity");
        goto fail0;
    }
    if (!NCDVal_IsString(str_arg)) {
        ModuleLog(o->i, BLOG_ERROR, "wrong type");
        goto fail0;
    }
    
    // init mem
    NCDValMem_Init(&o->mem);
    
    // parse
    o->succeeded = pfunc(i, NCDVal_StringMemRef(str_arg), &o->mem, &o->value);
    
    // signal up
    NCDModuleInst_Backend_Up(i);
    return;
    
fail0:
    NCDModuleInst_Backend_DeadError(i);
}
Ejemplo n.º 13
0
static void func_new (void *vo, NCDModuleInst *i, const struct NCDModuleInst_new_params *params)
{
    struct instance *o = vo;
    o->i = i;
    
    // check arguments
    NCDValRef type_arg;
    NCDValRef name_arg;
    if (!NCDVal_ListRead(params->args, 2, &type_arg, &name_arg)) {
        ModuleLog(o->i, BLOG_ERROR, "wrong arity");
        goto fail0;
    }
    if (!NCDVal_IsString(type_arg) || !NCDVal_IsStringNoNulls(name_arg)) {
        ModuleLog(o->i, BLOG_ERROR, "wrong type");
        goto fail0;
    }
    
    // null terminate name
    NCDValNullTermString name_nts;
    if (!NCDVal_StringNullTerminate(name_arg, &name_nts)) {
        ModuleLog(o->i, BLOG_ERROR, "NCDVal_StringNullTerminate failed");
        goto fail0;
    }
    
    if (NCDVal_StringEquals(type_arg, "index")) {
        if (sscanf(name_nts.data, "%"SCNu32, &o->index) != 1) {
            ModuleLog(o->i, BLOG_ERROR, "wrong index argument");
            goto fail1;
        }
    }
    else if (NCDVal_StringEquals(type_arg, "wlan")) {
        if (!find_wlan_rfill(name_nts.data, &o->index)) {
            ModuleLog(o->i, BLOG_ERROR, "failed to find rfkill for wlan interface");
            goto fail1;
        }
    }
    else {
        ModuleLog(o->i, BLOG_ERROR, "unknown type argument");
        goto fail1;
    }
    
    // init monitor
    if (!NCDRfkillMonitor_Init(&o->monitor, o->i->params->iparams->reactor, (NCDRfkillMonitor_handler)monitor_handler, o)) {
        ModuleLog(o->i, BLOG_ERROR, "monitor failed");
        goto fail1;
    }
    
    // set not up
    o->up = 0;
    
    // free name nts
    NCDValNullTermString_Free(&name_nts);
    return;
    
fail1:
    NCDValNullTermString_Free(&name_nts);
fail0:
    NCDModuleInst_Backend_DeadError(i);
}
Ejemplo n.º 14
0
Archivo: sleep.c Proyecto: AmVPN/badvpn
static void func_new (void *vo, NCDModuleInst *i, const struct NCDModuleInst_new_params *params)
{
    struct instance *o = vo;
    o->i = i;
    
    // check arguments
    NCDValRef ms_start_arg;
    NCDValRef ms_stop_arg = NCDVal_NewInvalid();
    if (!NCDVal_ListRead(params->args, 1, &ms_start_arg) &&
        !NCDVal_ListRead(params->args, 2, &ms_start_arg, &ms_stop_arg)) {
        ModuleLog(o->i, BLOG_ERROR, "wrong arity");
        goto fail0;
    }
    
    uintmax_t ms;
    btime_t ms_start;
    
    if (NCDVal_IsString(ms_start_arg) && NCDVal_StringEqualsId(ms_start_arg, NCD_STRING_EMPTY)) {
        ms_start = -1;
    } else {
        if (!ncd_read_uintmax(ms_start_arg, &ms) || ms > INT64_MAX) {
            ModuleLog(o->i, BLOG_ERROR, "wrong start time");
            goto fail0;
        }
        ms_start = ms;
    }
    
    if (NCDVal_IsInvalid(ms_stop_arg) || (NCDVal_IsString(ms_stop_arg) && NCDVal_StringEqualsId(ms_stop_arg, NCD_STRING_EMPTY))) {
        o->ms_stop = -1;
    } else {
        if (!ncd_read_uintmax(ms_stop_arg, &ms) || ms > INT64_MAX) {
            ModuleLog(o->i, BLOG_ERROR, "wrong stop time");
            goto fail0;
        }
        o->ms_stop = ms;
    }
    
    // init timer
    BTimer_Init(&o->timer, 0, timer_handler, o);
    
    // set not dying
    o->dying = 0;
    
    if (ms_start < 0) {
        // go up
        NCDModuleInst_Backend_Up(i);
    } else {
        // set timer
        BReactor_SetTimerAfter(o->i->params->iparams->reactor, &o->timer, ms_start);
    }
    
    return;
    
fail0:
    NCDModuleInst_Backend_DeadError(i);
}
Ejemplo n.º 15
0
static void func_new (void *vo, NCDModuleInst *i, const struct NCDModuleInst_new_params *params)
{
    struct instance *o = vo;
    o->i = i;
    
    // read arguments
    NCDValRef input_arg;
    NCDValRef regex_arg;
    if (!NCDVal_ListRead(params->args, 2, &input_arg, &regex_arg)) {
        ModuleLog(o->i, BLOG_ERROR, "wrong arity");
        goto fail0;
    }
    if (!NCDVal_IsString(input_arg) || !NCDVal_IsStringNoNulls(regex_arg)) {
        ModuleLog(o->i, BLOG_ERROR, "wrong type");
        goto fail0;
    }
    o->input = NCDVal_StringMemRef(input_arg);
    
    // make sure we don't overflow regoff_t
    if (o->input.len > INT_MAX) {
        ModuleLog(o->i, BLOG_ERROR, "input string too long");
        goto fail0;
    }
    
    // null terminate regex
    NCDValNullTermString regex_nts;
    if (!NCDVal_StringNullTerminate(regex_arg, &regex_nts)) {
        ModuleLog(i, BLOG_ERROR, "NCDVal_StringNullTerminate failed");
        goto fail0;
    }
    
    // compile regex
    regex_t preg;
    int ret = regcomp(&preg, regex_nts.data, REG_EXTENDED);
    NCDValNullTermString_Free(&regex_nts);
    if (ret != 0) {
        ModuleLog(o->i, BLOG_ERROR, "regcomp failed (error=%d)", ret);
        goto fail0;
    }
    
    // execute match
    o->matches[0].rm_so = 0;
    o->matches[0].rm_eo = o->input.len;
    o->succeeded = (regexec(&preg, o->input.ptr, MAX_MATCHES, o->matches, REG_STARTEND) == 0);
    
    // free regex
    regfree(&preg);
    
    // signal up
    NCDModuleInst_Backend_Up(o->i);
    return;
    
fail0:
    NCDModuleInst_Backend_DeadError(i);
}
Ejemplo n.º 16
0
static void instance_free (struct instance *o, int is_error)
{
    // free DHCP
    BDHCPClient_Free(&o->dhcp);
    
    if (is_error) {
        NCDModuleInst_Backend_DeadError(o->i);
    } else {
        NCDModuleInst_Backend_Dead(o->i);
    }
}
Ejemplo n.º 17
0
static void instance_free (struct instance *o, int is_error)
{
    // free arpprobe
    BArpProbe_Free(&o->arpprobe);
    
    if (is_error) {
        NCDModuleInst_Backend_DeadError(o->i);
    } else {
        NCDModuleInst_Backend_Dead(o->i);
    }
}
Ejemplo n.º 18
0
Archivo: print.c Proyecto: AmVPN/badvpn
static void println_func_new (void *unused, NCDModuleInst *i, const struct NCDModuleInst_new_params *params)
{
    if (!check_args(i, params)) {
        goto fail0;
    }
    
    do_print(i, params->args, 1);
    
    NCDModuleInst_Backend_Up(i);
    return;
    
fail0:
    NCDModuleInst_Backend_DeadError(i);
}
Ejemplo n.º 19
0
static void stat_func_new_common (void *vo, NCDModuleInst *i, const struct NCDModuleInst_new_params *params, int is_lstat)
{
    struct stat_instance *o = vo;
    o->i = i;
    
    NCDValRef filename_arg;
    if (!NCDVal_ListRead(params->args, 1, &filename_arg)) {
        ModuleLog(i, BLOG_ERROR, "wrong arity");
        goto fail0;
    }
    if (!NCDVal_IsString(filename_arg)) {
        ModuleLog(i, BLOG_ERROR, "wrong type");
        goto fail0;
    }
    
    o->succeeded = 0;
    
    if (!NCDVal_IsStringNoNulls(filename_arg)) {
        goto out;
    }
    
    // null terminate filename
    NCDValNullTermString filename_nts;
    if (!NCDVal_StringNullTerminate(filename_arg, &filename_nts)) {
        ModuleLog(i, BLOG_ERROR, "NCDVal_StringNullTerminate failed");
        goto fail0;
    }
    
    int res;
    if (is_lstat) {
        res = lstat(filename_nts.data, &o->result);
    } else {
        res = stat(filename_nts.data, &o->result);
    }
    NCDValNullTermString_Free(&filename_nts);
    
    if (res < 0) {
        goto out;
    }
    
    o->succeeded = 1;
    
out:
    NCDModuleInst_Backend_Up(i);
    return;
    
fail0:
    NCDModuleInst_Backend_DeadError(i);
}
Ejemplo n.º 20
0
static void func_new (void *unused, NCDModuleInst *i, const struct NCDModuleInst_new_params *params)
{
    // check arguments
    if (!NCDVal_ListRead(params->args, 0)) {
        ModuleLog(i, BLOG_ERROR, "wrong arity");
        goto fail0;
    }
    
    // go up
    NCDModuleInst_Backend_Up(i);
    return;
    
fail0:
    NCDModuleInst_Backend_DeadError(i);
}
Ejemplo n.º 21
0
static void func_new (void *vo, NCDModuleInst *i, const struct NCDModuleInst_new_params *params, int is_not, int is_or)
{
    struct instance *o = vo;
    o->i = i;
    
    // compute value from arguments
    if (is_not) {
        NCDValRef arg;
        if (!NCDVal_ListRead(params->args, 1, &arg)) {
            ModuleLog(o->i, BLOG_ERROR, "wrong arity");
            goto fail0;
        }
        int arg_val;
        if (!ncd_read_boolean(arg, &arg_val)) {
            ModuleLog(o->i, BLOG_ERROR, "bad argument");
            goto fail0;
        }
        
        o->value = !arg_val;
    } else {
        o->value = (is_or ? 0 : 1);
        
        size_t count = NCDVal_ListCount(params->args);
        
        for (size_t j = 0; j < count; j++) {
            NCDValRef arg = NCDVal_ListGet(params->args, j);
            
            int this_value;
            if (!ncd_read_boolean(arg, &this_value)) {
                ModuleLog(o->i, BLOG_ERROR, "bad argument");
                goto fail0;
            }
            
            if (is_or) {
                o->value = o->value || this_value;
            } else {
                o->value = o->value && this_value;
            }
        }
    }
    
    // signal up
    NCDModuleInst_Backend_Up(o->i);
    return;
    
fail0:
    NCDModuleInst_Backend_DeadError(i);
}
Ejemplo n.º 22
0
static void func_new_from_index (void *vo, NCDModuleInst *i, const struct NCDModuleInst_new_params *params)
{
    struct instance *index = NCDModuleInst_Backend_GetUser((NCDModuleInst *)params->method_user);

    // check overflow
    if (index->value == SIZE_MAX) {
        ModuleLog(i, BLOG_ERROR, "overflow");
        goto fail0;
    }

    func_new_templ(vo, i, index->value + 1);
    return;

fail0:
    NCDModuleInst_Backend_DeadError(i);
}
Ejemplo n.º 23
0
static void func_new (void *vo, NCDModuleInst *i, const struct NCDModuleInst_new_params *params)
{
    struct instance *o = vo;
    o->i = i;
    
    // read arguments
    NCDValRef arg_ifname;
    NCDValRef arg_addr;
    if (!NCDVal_ListRead(params->args, 2, &arg_ifname, &arg_addr)) {
        ModuleLog(o->i, BLOG_ERROR, "wrong arity");
        goto fail0;
    }
    if (!NCDVal_IsStringNoNulls(arg_ifname) || !NCDVal_IsString(arg_addr)) {
        ModuleLog(o->i, BLOG_ERROR, "wrong type");
        goto fail0;
    }
    
    // parse address
    uint32_t addr;
    if (!ipaddr_parse_ipv4_addr_bin(NCDVal_StringData(arg_addr), NCDVal_StringLength(arg_addr), &addr)) {
        ModuleLog(o->i, BLOG_ERROR, "wrong address");
        goto fail0;
    }
    
    // null terminate ifname
    NCDValNullTermString ifname_nts;
    if (!NCDVal_StringNullTerminate(arg_ifname, &ifname_nts)) {
        ModuleLog(i, BLOG_ERROR, "NCDVal_StringNullTerminate failed");
        goto fail0;
    }
    
    // init arpprobe
    int res = BArpProbe_Init(&o->arpprobe, ifname_nts.data, addr, i->params->iparams->reactor, o, (BArpProbe_handler)arpprobe_handler);
    NCDValNullTermString_Free(&ifname_nts);
    if (!res) {
        ModuleLog(o->i, BLOG_ERROR, "BArpProbe_Init failed");
        goto fail0;
    }
    
    // set state unknown
    o->state = STATE_UNKNOWN;
    return;
    
fail0:
    NCDModuleInst_Backend_DeadError(i);
}
Ejemplo n.º 24
0
Archivo: print.c Proyecto: AmVPN/badvpn
static void rprint_func_new_common (void *vo, NCDModuleInst *i, const struct NCDModuleInst_new_params *params, int ln)
{
    struct rprint_instance *o = vo;
    o->i = i;
    o->args = params->args;
    o->ln = ln;
    
    if (!check_args(i, params)) {
        goto fail0;
    }
    
    NCDModuleInst_Backend_Up(i);
    return;
    
fail0:
    NCDModuleInst_Backend_DeadError(i);
}
Ejemplo n.º 25
0
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(i, BLOG_ERROR, "wrong arity");
        goto fail0;
    }
    
    // signal up
    NCDModuleInst_Backend_Up(i);
    return;
    
fail0:
    NCDModuleInst_Backend_DeadError(i);
}
Ejemplo n.º 26
0
static void new_templ (void *vo, NCDModuleInst *i, const struct NCDModuleInst_new_params *params, compute_func cfunc)
{
    struct instance *o = vo;
    o->i = i;
    
    NCDValRef v1_arg;
    NCDValRef v2_arg;
    if (!NCDVal_ListRead(params->args, 2, &v1_arg, &v2_arg)) {
        ModuleLog(i, BLOG_ERROR, "wrong arity");
        goto fail0;
    }
    
    o->result = cfunc(v1_arg, v2_arg);
    
    NCDModuleInst_Backend_Up(i);
    return;
    
fail0:
    NCDModuleInst_Backend_DeadError(i);
}
Ejemplo n.º 27
0
static void go_func_new (void *unused, NCDModuleInst *i, const struct NCDModuleInst_new_params *params)
{
    // check arguments
    if (!NCDVal_ListRead(params->args, 0)) {
        ModuleLog(i, BLOG_ERROR, "wrong arity");
        goto fail0;
    }
    
    // get backtrack point
    NCDModuleInst *backtrack_point_inst = params->method_user;
    
    // go up (after toggling)
    NCDModuleInst_Backend_Up(i);
    
    // toggle backtrack point
    NCDModuleInst_Backend_DownUp(backtrack_point_inst);
    return;
    
fail0:
    NCDModuleInst_Backend_DeadError(i);
}
Ejemplo n.º 28
0
static void read_func_new (void *vo, NCDModuleInst *i, const struct NCDModuleInst_new_params *params)
{
    struct read_instance *o = vo;
    o->i = i;
    
    // read arguments
    NCDValRef filename_arg;
    if (!NCDVal_ListRead(params->args, 1, &filename_arg)) {
        ModuleLog(i, BLOG_ERROR, "wrong arity");
        goto fail0;
    }
    if (!NCDVal_IsStringNoNulls(filename_arg)) {
        ModuleLog(i, BLOG_ERROR, "wrong type");
        goto fail0;
    }
    
    // get null terminated name
    NCDValNullTermString filename_nts;
    if (!NCDVal_StringNullTerminate(filename_arg, &filename_nts)) {
        ModuleLog(i, BLOG_ERROR, "NCDVal_StringNullTerminate failed");
        goto fail0;
    }
    
    // read file
    int res = read_file(filename_nts.data, &o->file_data, &o->file_len);
    NCDValNullTermString_Free(&filename_nts);
    if (!res) {
        ModuleLog(i, BLOG_ERROR, "failed to read file");
        goto fail0;
    }
    
    // signal up
    NCDModuleInst_Backend_Up(i);
    return;
    
fail0:
    NCDModuleInst_Backend_DeadError(i);
}
Ejemplo n.º 29
0
static void ipv6_cidr_addr_func_new (void *vo, NCDModuleInst *i, const struct NCDModuleInst_new_params *params)
{
    struct ipv6_cidr_instance *o = vo;
    o->i = i;
    
    NCDValRef str_arg;
    if (!NCDVal_ListRead(params->args, 1, &str_arg)) {
        ModuleLog(i, BLOG_ERROR, "wrong arity");
        goto fail0;
    }
    if (!NCDVal_IsString(str_arg)) {
        ModuleLog(o->i, BLOG_ERROR, "wrong type");
        goto fail0;
    }
    
    o->succeeded = ipaddr6_parse_ipv6_ifaddr(NCDVal_StringMemRef(str_arg), &o->ifaddr);
    
    NCDModuleInst_Backend_Up(i);
    return;
    
fail0:
    NCDModuleInst_Backend_DeadError(i);
}
Ejemplo n.º 30
0
static void ipv4_net_from_addr_and_prefix_func_init (void *vo, NCDModuleInst *i, const struct NCDModuleInst_new_params *params)
{
    // read arguments
    NCDValRef addr_arg;
    NCDValRef prefix_arg;
    if (!NCDVal_ListRead(params->args, 2, &addr_arg, &prefix_arg)) {
        ModuleLog(i, BLOG_ERROR, "wrong arity");
        goto fail0;
    }
    if (!NCDVal_IsString(addr_arg) || !NCDVal_IsString(prefix_arg)) {
        ModuleLog(i, BLOG_ERROR, "wrong type");
        goto fail0;
    }
    
    // parse addr
    uint32_t addr;
    if (!ipaddr_parse_ipv4_addr(NCDVal_StringMemRef(addr_arg), &addr)) {
        ModuleLog(i, BLOG_ERROR, "bad addr");
        goto fail0;
    }
    
    // parse prefix
    int prefix;
    if (!ipaddr_parse_ipv4_prefix(NCDVal_StringMemRef(prefix_arg), &prefix)) {
        ModuleLog(i, BLOG_ERROR, "bad prefix");
        goto fail0;
    }
    
    // make network
    uint32_t network = (addr & ipaddr_ipv4_mask_from_prefix(prefix));
    
    addr_func_init_templ(vo, i, network);
    return;
    
fail0:
    NCDModuleInst_Backend_DeadError(i);
}