// ubus call test_ubus helloworld '{"id":1,"msg":"hello","array":["a","b"]}' static int test_hello(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, struct blob_attr *msg) { struct blob_attr *tb[__HELLO_MAX]; int tmp_id; char *tmp_msg = NULL; int len; struct blob_attr *attr; void *arr; blobmsg_parse(hello_policy, __HELLO_MAX, tb, blob_data(msg), blob_len(msg)); blob_buf_init(&b, 0); if(tb[HELLO_ID]) { tmp_id = blobmsg_get_u32(tb[HELLO_ID]); blobmsg_add_u32(&b, "id", tmp_id); } if(tb[HELLO_MSG]) { tmp_msg = blobmsg_get_string(tb[HELLO_MSG]); blobmsg_add_string(&b, "msg", tmp_msg); } if(tb[HELLO_ARRAY] && blobmsg_type(tb[HELLO_ARRAY]) == BLOBMSG_TYPE_ARRAY) { arr = blobmsg_open_array(&b, "array"); len = blobmsg_data_len(tb[HELLO_ARRAY]); __blob_for_each_attr(attr, blobmsg_data(tb[HELLO_ARRAY]), len) { if (blobmsg_type(attr) == BLOBMSG_TYPE_STRING) { char *tmp = blobmsg_get_string(attr); blobmsg_add_blob(&b, attr); printf("array=%s\n", tmp); } } blobmsg_close_array(&b, arr); }
static bool menu_access(struct blob_attr *sid, struct blob_attr *acls, struct blob_buf *e) { int rem; struct blob_attr *acl; bool rv = true; void *c; c = blobmsg_open_table(e, "write"); blobmsg_for_each_attr(acl, acls, rem) { if (!ops->session_access(blobmsg_data(sid), "access-group", blobmsg_data(acl), "read")) { rv = false; break; } blobmsg_add_u8(e, blobmsg_data(acl), ops->session_access(blobmsg_data(sid), "access-group", blobmsg_data(acl), "write")); } blobmsg_close_table(e, c); return rv; }
struct env_var *uh_get_process_vars(struct client *cl, struct path_info *pi) { struct http_request *req = &cl->request; struct blob_attr *data = cl->hdr.head; struct env_var *vars = (void *) uh_buf; struct blob_attr *tb[__HDR_MAX]; const char *url; int len; int i; url = blobmsg_data(blob_data(cl->hdr.head)); len = ARRAY_SIZE(proc_header_env); len += ARRAY_SIZE(extra_vars); len *= sizeof(struct env_var); BUILD_BUG_ON(sizeof(uh_buf) < len); extra_vars[VAR_SCRIPT_NAME].value = pi->name; extra_vars[VAR_SCRIPT_FILE].value = pi->phys; extra_vars[VAR_DOCROOT].value = pi->root; extra_vars[VAR_QUERY].value = pi->query ? pi->query : ""; extra_vars[VAR_REQUEST].value = url; extra_vars[VAR_PROTO].value = http_versions[req->version]; extra_vars[VAR_METHOD].value = http_methods[req->method]; extra_vars[VAR_PATH_INFO].value = pi->info; extra_vars[VAR_USER].value = req->realm ? req->realm->user : NULL; extra_vars[VAR_HTTPS].value = cl->tls ? "on" : NULL; snprintf(redirect_status, sizeof(redirect_status), "%d", req->redirect_status); inet_ntop(cl->srv_addr.family, &cl->srv_addr.in, local_addr, sizeof(local_addr)); snprintf(local_port, sizeof(local_port), "%d", cl->srv_addr.port); inet_ntop(cl->peer_addr.family, &cl->peer_addr.in, remote_addr, sizeof(remote_addr)); snprintf(remote_port, sizeof(remote_port), "%d", cl->peer_addr.port); blobmsg_parse(hdr_policy, __HDR_MAX, tb, blob_data(data), blob_len(data)); for (i = 0; i < ARRAY_SIZE(proc_header_env); i++) { struct blob_attr *cur; cur = tb[proc_header_env[i].idx]; vars[i].name = proc_header_env[i].name; vars[i].value = cur ? blobmsg_data(cur) : ""; } memcpy(&vars[i], extra_vars, sizeof(extra_vars)); i += ARRAY_SIZE(extra_vars); vars[i].name = NULL; vars[i].value = NULL; return vars; }
static char *uh_file_header(struct client *cl, int idx) { if (!cl->dispatch.file.hdr[idx]) return NULL; return (char *) blobmsg_data(cl->dispatch.file.hdr[idx]); }
static int rpc_juci_backup_config_set(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, struct blob_attr *msg) { FILE *f; struct blob_attr *tb[__RPC_D_MAX]; blobmsg_parse(rpc_data_policy, __RPC_D_MAX, tb, blob_data(msg), blob_len(msg)); if (!tb[RPC_D_DATA]) return UBUS_STATUS_INVALID_ARGUMENT; if (blobmsg_data_len(tb[RPC_D_DATA]) >= 2048) return UBUS_STATUS_NOT_SUPPORTED; if (!(f = fopen("/etc/sysupgrade.conf", "w"))) return rpc_errno_status(); fwrite(blobmsg_data(tb[RPC_D_DATA]), blobmsg_data_len(tb[RPC_D_DATA]) - 1, 1, f); fclose(f); return 0; }
static void vif_config_add_bridge(struct blob_buf *buf, struct blob_attr *networks, bool prepare) { struct interface *iface; struct device *dev = NULL; struct blob_attr *cur; const char *network; int rem; if (!networks) return; blobmsg_for_each_attr(cur, networks, rem) { network = blobmsg_data(cur); iface = vlist_find(&interfaces, network, iface, node); if (!iface) continue; dev = iface->main_dev.dev; if (!dev) return; if (dev->type != &bridge_device_type) return; }
bool blobmsg_check_attr(const struct blob_attr *attr, bool name) { const struct blobmsg_hdr *hdr; const char *data; int id, len; if (blob_len(attr) < sizeof(struct blobmsg_hdr)) return false; hdr = (void *) attr->data; if (!hdr->namelen && name) return false; if (blobmsg_namelen(hdr) > blob_len(attr) - sizeof(struct blobmsg_hdr)) return false; if (hdr->name[blobmsg_namelen(hdr)] != 0) return false; id = blob_id(attr); len = blobmsg_data_len(attr); data = blobmsg_data(attr); if (!id || id > BLOBMSG_TYPE_LAST) return false; if (!blob_type[id]) return true; return blob_check_type(data, len, blob_type[id]); }
void blobmsg_format_std_indent(const struct blob_attr *data, int indent) { struct blob_attr *attr; const struct blob_attr *head = blobmsg_data(data); int len = blobmsg_data_len(data); __blob_for_each_attr(attr, head, len) { int type = blobmsg_type(attr); if (blobmsg_type(data) != BLOBMSG_TYPE_ARRAY && blobmsg_name(attr)[0]) indent_printf(indent, "%s: ", blobmsg_name(attr)); else indent_printf(indent, "%s", ""); if (type == BLOBMSG_TYPE_TABLE) printf("{\n"); else if (type == BLOBMSG_TYPE_ARRAY) printf("[\n"); blobmsg_format_element(attr, indent + 1); if (type == BLOBMSG_TYPE_TABLE) indent_printf(indent, "}\n"); else if (type == BLOBMSG_TYPE_ARRAY) indent_printf(indent, "]\n"); }
void get_port_attr(struct portAttr *port, struct blob_attr *msg) { struct blob_attr *tb[__PORT_MAX]; int portNum; blobmsg_parse(port_policy, ARRAY_SIZE(port_policy), tb, blobmsg_data(msg), blobmsg_len(msg)); if(tb[AGG_PORT_NUMBER]) port->number = blobmsg_get_u32(tb[AGG_PORT_NUMBER]); if(tb[AGG_PORT_ALIAS]) port->alias = blobmsg_get_string(tb[AGG_PORT_ALIAS]); return; }
static void parse_subnets(struct list_head *head, enum fw3_family family, struct blob_attr *list) { struct blob_attr *cur; struct fw3_address *addr; int rem; if (!list) return; rem = blobmsg_data_len(list); __blob_for_each_attr(cur, blobmsg_data(list), rem) { addr = parse_subnet(family, blobmsg_data(cur), blobmsg_data_len(cur)); if (addr) list_add_tail(&addr->list, head); }
static void handle_command(struct json_script_ctx *ctx, const char *name, struct blob_attr *data, struct blob_attr *vars) { struct blob_attr *cur; int rem; fprintf(stderr, "Command: %s", name); blobmsg_for_each_attr(cur, data, rem) fprintf(stderr, " %s", (char *) blobmsg_data(cur)); fprintf(stderr, "\n"); }
static int easycwmpd_handle_inform(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, struct blob_attr *msg) { int tmp; struct blob_attr *tb[__INFORM_MAX]; blobmsg_parse(inform_policy, ARRAY_SIZE(inform_policy), tb, blob_data(msg), blob_len(msg)); if (!tb[INFORM_EVENT]) return UBUS_STATUS_INVALID_ARGUMENT; log_message(NAME, L_NOTICE, "triggered ubus inform %s\n", blobmsg_data(tb[INFORM_EVENT])); tmp = cwmp_get_int_event_code(blobmsg_data(tb[INFORM_EVENT])); cwmp_connection_request(tmp); return 0; }
static void dump_table(struct blob_attr *head, int len, int indent, bool array) { struct blob_attr *attr; struct blobmsg_hdr *hdr; indent_printf(indent, "{\n"); __blob_for_each_attr(attr, head, len) { hdr = blob_data(attr); if (!array) indent_printf(indent + 1, "%s : ", hdr->name); dump_attr_data(blobmsg_data(attr), blobmsg_data_len(attr), blob_id(attr), 0, indent + 1); }
static int easycwmpd_handle_command(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, struct blob_attr *msg) { struct blob_attr *tb[__COMMAND_MAX]; blobmsg_parse(command_policy, ARRAY_SIZE(command_policy), tb, blob_data(msg), blob_len(msg)); if (!tb[COMMAND_NAME]) return UBUS_STATUS_INVALID_ARGUMENT; blob_buf_init(&b, 0); char *cmd = blobmsg_data(tb[COMMAND_NAME]); char *info; if (!strcmp("reload", cmd)) { log_message(NAME, L_NOTICE, "triggered ubus reload\n"); easycwmp_reload(); blobmsg_add_u32(&b, "status", 0); if (asprintf(&info, "easycwmpd reloaded") == -1) goto error; } else if (!strcmp("stop", cmd)) { log_message(NAME, L_NOTICE, "triggered ubus stop\n"); ubus_timer.cb = ubus_easycwmpd_stop_callback; uloop_timeout_set(&ubus_timer, 1000); blobmsg_add_u32(&b, "status", 0); if (asprintf(&info, "easycwmpd stopped") == -1) goto error; } else { blobmsg_add_u32(&b, "status", -1); if (asprintf(&info, "%s command is not supported", cmd) == -1) goto error; } blobmsg_add_string(&b, "info", info); free(info); ubus_send_reply(ctx, req, b.head); blob_buf_free(&b); return 0; error: blob_buf_free(&b); return -1; }
static int freecwmpd_handle_notify(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, struct blob_attr *msg) { struct blob_attr *tb[__NOTIFY_MAX]; blobmsg_parse(notify_policy, ARRAY_SIZE(notify_policy), tb, blob_data(msg), blob_len(msg)); if (!tb[NOTIFY_PARAM]) return UBUS_STATUS_INVALID_ARGUMENT; if (!tb[NOTIFY_VALUE]) return UBUS_STATUS_INVALID_ARGUMENT; freecwmp_log_message(NAME, L_NOTICE, "triggered ubus notification parameter %s\n", blobmsg_data(tb[NOTIFY_PARAM])); cwmp_add_notification(blobmsg_data(tb[NOTIFY_PARAM]), blobmsg_data(tb[NOTIFY_VALUE])); return 0; }
static int rpc_juci_backup_restore(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, struct blob_attr *msg) { struct blob_attr *tb[__RPC_BACKUP_MAX]; blobmsg_parse(rpc_backup_policy, __RPC_BACKUP_MAX, tb, blob_data(msg), blob_len(msg)); struct blob_attr *pass = tb[RPC_BACKUP_PASSWORD]; if (pass && blobmsg_data_len(pass) > 0 && blobmsg_data(pass) && strlen(blobmsg_data(pass)) > 0){ const char *cmd[] = { "sysupgrade", "--restore-backup", "/tmp/backup.tar.gz", "--password", blobmsg_data(pass), NULL }; return ops->exec(cmd, NULL, NULL, NULL, NULL, NULL, ctx, req); } const char *cmd[] = { "sysupgrade", "--restore-backup", "/tmp/backup.tar.gz", NULL }; return ops->exec(cmd, NULL, NULL, NULL, NULL, NULL, ctx, req); }
static void proc_handle_header_end(struct relay *r) { struct client *cl = r->cl; struct dispatch_proc *p = &cl->dispatch.proc; struct blob_attr *cur; int rem; uloop_timeout_cancel(&p->timeout); uh_http_header(cl, cl->dispatch.proc.status_code, cl->dispatch.proc.status_msg); blob_for_each_attr(cur, cl->dispatch.proc.hdr.head, rem) ustream_printf(cl->us, "%s: %s\r\n", blobmsg_name(cur), blobmsg_data(cur)); ustream_printf(cl->us, "\r\n"); if (cl->request.method == UH_HTTP_MSG_HEAD) r->skip_data = true; }
static int handle_loglevel_update(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, struct blob_attr *msg) { struct blob_attr *tb[__LOGLEVEL_MAX]; char *log_buf = NULL; char cmd[128] = {0}; cloudc_debug("%s[%d]: Enter ", __func__, __LINE__); blobmsg_parse(handle_loglevel_policy, ARRAY_SIZE(handle_loglevel_policy), tb, blob_data(msg), blob_len(msg)); if (tb[LOGLEVEL]) { log_buf = blobmsg_data(tb[LOGLEVEL]); if ( NULL != strcasestr(log_buf, "debug")) { cloudc_log_level_int = LOG_LEVEL_DEBUG; } else if ( NULL != strcasestr(log_buf, "error")) { cloudc_log_level_int = LOG_LEVEL_ERR; } else { cloudc_error("%s[%d]: parameter should only be debug or error, please double check", __func__, __LINE__); } snprintf(cmd, sizeof(cmd), "uci set cloudc.global.loglevel=\"%s\"",log_buf); system(cmd); system("uci commit"); cloudc_debug("%s[%d]: cmd = %s\n", __func__, __LINE__, cmd); cloudc_debug("%s[%d]: cloudc_log_level_int = %d", __func__, __LINE__, cloudc_log_level_int); } else { cloudc_debug("%s[%d]: wrong parameter,please double check", __func__, __LINE__); } cloudc_debug("%s[%d]: Exit ", __func__, __LINE__); return 0; }
static void uqmi_print_result(struct blob_attr *data) { struct blob_attr *cur; int rem; blob_for_each_attr(cur, data, rem) { switch (blobmsg_type(cur)) { case BLOBMSG_TYPE_STRING: printf("%s=%s\n", blobmsg_name(cur), (char *) blobmsg_data(cur)); break; case BLOBMSG_TYPE_INT32: printf("%s=%d\n", blobmsg_name(cur), (int32_t) blobmsg_get_u32(cur)); break; case BLOBMSG_TYPE_INT8: printf("%s=%s\n", blobmsg_name(cur), blobmsg_get_u8(cur) ? "true" : "false"); break; } } }
static int parse_static_address_option(struct interface *iface, struct blob_attr *attr, bool v6, int netmask, bool ext, uint32_t broadcast) { struct blob_attr *cur; int n_addr = 0; int rem; blobmsg_for_each_attr(cur, attr, rem) { if (blobmsg_type(cur) != BLOBMSG_TYPE_STRING) return -1; n_addr++; if (!parse_addr(iface, blobmsg_data(cur), v6, netmask, ext, broadcast)) return -1; } return n_addr; }
static int apClient_connect(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, struct blob_attr *msg) { struct blob_attr *tb[__CONFIG_MAX]; int try_count = 0; int wait_count = 3; const char *apname; const char *staname; const char *ssid; const char *passwd; const char *channel; const char *security; const char *bssid; char *crypto; char cmd[100]; blobmsg_parse(connect_policy, __CONFIG_MAX, tb, blob_data(msg), blob_len(msg)); if (!tb[CONFIG_APNAME]) return UBUS_STATUS_INVALID_ARGUMENT; blob_buf_init(&buf, 0); apname = blobmsg_data(tb[CONFIG_APNAME]); staname = blobmsg_data(tb[CONFIG_STANAME]); ssid = blobmsg_data(tb[CONFIG_SSID]); passwd = blobmsg_data(tb[CONFIG_PASSWD]); channel = blobmsg_data(tb[CONFIG_CHANNEL]); security = blobmsg_data(tb[CONFIG_SECURITY]); crypto = strstr(security, "/"); if (crypto) { *crypto = '\0'; crypto++; } wifi_site_survey(apname,NULL,0); wifi_repeater_start(apname, staname, channel, ssid, passwd, security, crypto); /*ifconfig staname down*/ snprintf(cmd, lengthof(cmd) - 1, "ifconfig %s down", staname); system(cmd); /*ifconfig staname down*/ snprintf(cmd, lengthof(cmd) - 1, "ifconfig %s up", staname); system(cmd); /*use uci set ssid*/ snprintf(cmd, lengthof(cmd) - 1, "uci set wireless.sta.ApCliSsid=%s", ssid); system(cmd); /*use uci set key*/ snprintf(cmd, lengthof(cmd) - 1, "uci set wireless.sta.ApCliWPAPSK=%s", passwd); system(cmd); /*uci commit*/ snprintf(cmd, lengthof(cmd) - 1, "uci commit"); system(cmd); /*udhcpc -i apcli0*/ snprintf(cmd, lengthof(cmd) - 1, "udhcpc -n -q -i apcli0"); system(cmd); while (wait_count--) { if (isStaGetIP(staname)) { blobmsg_add_string(&buf, "result", "success"); break; } sleep(1); } if (wait_count == -1) { blobmsg_add_string(&buf, "result", "failed"); } ubus_send_reply(ctx, req, buf.head); return UBUS_STATUS_OK; }
static int rpc_rrdns_lookup(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, struct blob_attr *msg) { int port = 53, limit = RRDNS_DEF_LIMIT, timeout = RRDNS_DEF_TIMEOUT; struct blob_attr *tb[__RPC_L_MAX]; struct rrdns_context *rctx; const char *server = NULL; blobmsg_parse(rpc_lookup_policy, __RPC_L_MAX, tb, blob_data(msg), blob_len(msg)); if (tb[RPC_L_PORT]) port = blobmsg_get_u16(tb[RPC_L_PORT]); if (tb[RPC_L_LIMIT]) limit = blobmsg_get_u32(tb[RPC_L_LIMIT]); if (tb[RPC_L_TIMEOUT]) timeout = blobmsg_get_u32(tb[RPC_L_TIMEOUT]); if (tb[RPC_L_SERVER]) server = blobmsg_get_string(tb[RPC_L_SERVER]); if (!tb[RPC_L_ADDRS]) return UBUS_STATUS_INVALID_ARGUMENT; if (port <= 0) return UBUS_STATUS_INVALID_ARGUMENT; if (limit <= 0 || limit > RRDNS_MAX_LIMIT) return UBUS_STATUS_INVALID_ARGUMENT; if (timeout <= 0 || timeout > RRDNS_MAX_TIMEOUT) return UBUS_STATUS_INVALID_ARGUMENT; if (!server || !*server) server = rrdns_find_nameserver(); if (!server) return UBUS_STATUS_NOT_FOUND; rctx = calloc(1, sizeof(*rctx)); if (!rctx) return UBUS_STATUS_UNKNOWN_ERROR; rctx->socket.fd = usock(USOCK_UDP, server, usock_port(port)); if (rctx->socket.fd < 0) { free(rctx); return UBUS_STATUS_UNKNOWN_ERROR; } rctx->context = ctx; rctx->addr_cur = blobmsg_data(tb[RPC_L_ADDRS]); rctx->addr_rem = blobmsg_data_len(tb[RPC_L_ADDRS]); avl_init(&rctx->request_ids, rrdns_cmp_id, false, NULL); avl_init(&rctx->request_addrs, rrdns_cmp_addr, false, NULL); rctx->timeout.cb = rrdns_handle_timeout; uloop_timeout_set(&rctx->timeout, timeout); rctx->socket.cb = rrdns_handle_response; uloop_fd_add(&rctx->socket, ULOOP_READ); blob_buf_init(&rctx->blob, 0); while (limit--) rrdns_next_query(rctx); ubus_defer_request(ctx, req, &rctx->request); return UBUS_STATUS_OK; }
static void receive_call_result_data(struct ubus_request *req, int type, struct blob_attr *msg) { struct blob_attr *tb[__INIT_MAX]; char *token, *ssid, *ssid_pwd; int len, ret; if (!msg) return; ret = 0; blobmsg_parse(init_policy, __INIT_MAX, tb, blob_data(msg), blob_len(msg)); if(tb[INIT_TOKEN] && tb[INIT_SSID] && tb[INIT_SSID_PWD]){ token = blobmsg_data(tb[INIT_TOKEN]); ssid = blobmsg_data(tb[INIT_SSID]); ssid_pwd = blobmsg_data(tb[INIT_SSID_PWD]); // todo dlog("recv token[%s], ssid[%s] ssid_pwd[%s]\n", token, ssid, ssid_pwd); // printf("recv token[%s], ssid[%s] ssid_pwd[%s]\n", token, ssid, ssid_pwd); char *base64 = malloc(MAX_ALLOC_LEN); char *router_key_iv = malloc(MAX_ALLOC_LEN); char *r_ssid = malloc(MAX_ALLOC_LEN); char *r_pwd = malloc(MAX_ALLOC_LEN); char base64_ssid[MAX_ALLOC_LEN] = {0}; char base64_pwd[MAX_ALLOC_LEN] = {0}; // get router key, iv memset(base64, 0, MAX_ALLOC_LEN); int base64_length = base64Decode(base64, token, strlen(token)); // printf("json base64 len: %d\n", base64_length); AES128_CBC_decrypt_buffer(router_key_iv, base64, base64_length, repeater_key, repeater_iv); memcpy(router_key, router_key_iv, 16); memcpy(router_iv, router_key_iv+16, 16); // ssid memset(base64_ssid, 0, MAX_ALLOC_LEN); memset(r_ssid, 0, MAX_ALLOC_LEN); memset(rr_ssid, 0, MAX_ALLOC_LEN); base64_length = base64Decode(base64_ssid, ssid, strlen(ssid)); AES128_CBC_decrypt_buffer(r_ssid, base64_ssid, base64_length, router_key, router_iv); memcpy(rr_ssid, r_ssid, strlen(r_ssid)); // printf("rr_ssid:%s\n", rr_ssid); // ssid pwd memset(base64_pwd, 0, MAX_ALLOC_LEN); memset(r_pwd, 0, MAX_ALLOC_LEN); memset(rr_pwd, 0, MAX_ALLOC_LEN); base64_length = base64Decode(base64_pwd, ssid_pwd, strlen(ssid_pwd)); AES128_CBC_decrypt_buffer(r_pwd, base64_pwd, base64_length, router_key, router_iv); memcpy(rr_pwd, r_pwd, strlen(r_pwd)); // printf("rr_pwd:%s\n", rr_pwd); flag_ssid_pwd = 1; /* Succeed to get password and ssid, so clear hide_mode flag */ set_hide_mode(0); if (router_key_iv) free(router_key_iv); if (base64) free(base64); if (r_ssid) free(r_ssid); if (r_pwd) free(r_pwd); }else{ dlog("recv DATA INVALID\n"); ret = 1; } if (ret){ printf("ecos pair verify failed!\n"); dlog("ret:%d wait %d try again\n", ret, TRAFFICD_INIT_LOOP_TIME / 1000); uloop_timeout_set(&sd->timeout_init, TRAFFICD_INIT_LOOP_TIME); }else{ printf("ssid:%s\n", rr_ssid); printf("ecos pair verify ok!\n"); #ifdef __ECOS #if 0 CFG_set(CFG_TRAFFIC_INIT, 0); sys->init_mode = 0; uloop_timeout_set(&sd->timeout_mat, TRAFFICD_WIFIAP_LOOP_TIME); #endif #endif } }
void iprule_add(struct blob_attr *attr, bool v6) { struct interface *iif = NULL, *oif = NULL; struct blob_attr *tb[__RULE_MAX], *cur; struct interface *iface; struct iprule *rule; int af = v6 ? AF_INET6 : AF_INET; blobmsg_parse(rule_attr, __RULE_MAX, tb, blobmsg_data(attr), blobmsg_data_len(attr)); rule = calloc(1, sizeof(*rule)); if (!rule) return; rule->flags = v6 ? IPRULE_INET6 : IPRULE_INET4; rule->order = iprules_counter[rule->flags]++; if ((cur = tb[RULE_INVERT]) != NULL) rule->invert = blobmsg_get_bool(cur); if ((cur = tb[RULE_INTERFACE_IN]) != NULL) { iif = vlist_find(&interfaces, blobmsg_data(cur), iface, node); if (!iif || !iif->l3_dev.dev) { DPRINTF("Failed to resolve device of network: %s\n", (char *) blobmsg_data(cur)); goto error; } memcpy(rule->in_dev, iif->l3_dev.dev->ifname, sizeof(rule->in_dev)); rule->flags |= IPRULE_IN; } if ((cur = tb[RULE_INTERFACE_OUT]) != NULL) { oif = vlist_find(&interfaces, blobmsg_data(cur), iface, node); if (!oif || !oif->l3_dev.dev) { DPRINTF("Failed to resolve device of network: %s\n", (char *) blobmsg_data(cur)); goto error; } memcpy(rule->out_dev, oif->l3_dev.dev->ifname, sizeof(rule->out_dev)); rule->flags |= IPRULE_OUT; } if ((cur = tb[RULE_SRC]) != NULL) { if (!parse_ip_and_netmask(af, blobmsg_data(cur), &rule->src_addr, &rule->src_mask)) { DPRINTF("Failed to parse rule source: %s\n", (char *) blobmsg_data(cur)); goto error; } rule->flags |= IPRULE_SRC; } if ((cur = tb[RULE_DEST]) != NULL) { if (!parse_ip_and_netmask(af, blobmsg_data(cur), &rule->dest_addr, &rule->dest_mask)) { DPRINTF("Failed to parse rule destination: %s\n", (char *) blobmsg_data(cur)); goto error; } rule->flags |= IPRULE_DEST; } if ((cur = tb[RULE_PRIORITY]) != NULL) { rule->priority = blobmsg_get_u32(cur); rule->flags |= IPRULE_PRIORITY; } if ((cur = tb[RULE_TOS]) != NULL) { if ((rule->tos = blobmsg_get_u32(cur)) > 255) { DPRINTF("Invalid TOS value: %u\n", blobmsg_get_u32(cur)); goto error; } rule->flags |= IPRULE_TOS; } if ((cur = tb[RULE_FWMARK]) != NULL) { if (!iprule_parse_mark(blobmsg_data(cur), rule)) { DPRINTF("Failed to parse rule fwmark: %s\n", (char *) blobmsg_data(cur)); goto error; } /* flags set by iprule_parse_mark() */ } if ((cur = tb[RULE_LOOKUP]) != NULL) { if (!system_resolve_rt_table(blobmsg_data(cur), &rule->lookup)) { DPRINTF("Failed to parse rule lookup table: %s\n", (char *) blobmsg_data(cur)); goto error; } rule->flags |= IPRULE_LOOKUP; } if ((cur = tb[RULE_ACTION]) != NULL) { if (!system_resolve_iprule_action(blobmsg_data(cur), &rule->action)) { DPRINTF("Failed to parse rule action: %s\n", (char *) blobmsg_data(cur)); goto error; } rule->flags |= IPRULE_ACTION; } if ((cur = tb[RULE_GOTO]) != NULL) { rule->gotoid = blobmsg_get_u32(cur); rule->flags |= IPRULE_GOTO; } vlist_add(&iprules, &rule->node, &rule->flags); return; error: free(rule); }
static struct device_addr * parse_address_item(struct blob_attr *attr, bool v6, bool ext) { struct device_addr *addr; struct blob_attr *tb[__ADDR_MAX]; struct blob_attr *cur; if (blobmsg_type(attr) != BLOBMSG_TYPE_TABLE) return NULL; addr = alloc_device_addr(v6, ext); if (!addr) return NULL; blobmsg_parse(proto_ip_addr, __ADDR_MAX, tb, blobmsg_data(attr), blobmsg_data_len(attr)); addr->mask = v6 ? 128 : 32; if ((cur = tb[ADDR_MASK])) { unsigned int new_mask; new_mask = parse_netmask_string(blobmsg_data(cur), v6); if (new_mask > addr->mask) goto error; addr->mask = new_mask; } cur = tb[ADDR_IPADDR]; if (!cur) goto error; if (!inet_pton(v6 ? AF_INET6 : AF_INET, blobmsg_data(cur), &addr->addr)) goto error; if ((cur = tb[ADDR_OFFLINK]) && blobmsg_get_bool(cur)) addr->flags |= DEVADDR_OFFLINK; if (!v6) { if ((cur = tb[ADDR_BROADCAST]) && !inet_pton(AF_INET, blobmsg_data(cur), &addr->broadcast)) goto error; if ((cur = tb[ADDR_PTP]) && !inet_pton(AF_INET, blobmsg_data(cur), &addr->point_to_point)) goto error; } else { time_t now = system_get_rtime(); if ((cur = tb[ADDR_PREFERRED])) { int64_t preferred = blobmsg_get_u32(cur); int64_t preferred_until = preferred + (int64_t)now; if (preferred_until <= LONG_MAX && preferred != 0xffffffffLL) addr->preferred_until = preferred_until; } if ((cur = tb[ADDR_VALID])) { int64_t valid = blobmsg_get_u32(cur); int64_t valid_until = valid + (int64_t)now; if (valid_until <= LONG_MAX && valid != 0xffffffffLL) addr->valid_until = valid_until; } if (addr->valid_until) { if (!addr->preferred_until) addr->preferred_until = addr->valid_until; else if (addr->preferred_until > addr->valid_until) goto error; } if ((cur = tb[ADDR_CLASS])) addr->pclass = strdup(blobmsg_get_string(cur)); } return addr; error: free(addr); return NULL; }