{
struct interface_ip_settings *ip;
struct blob_attr *cur;
+ int dev_create = 1;
bool addr_ext = false;
bool up;
return 0;
}
+ if ((cur = tb[NOTIFY_ADDR_EXT]) != NULL) {
+ addr_ext = blobmsg_get_bool(cur);
+ if (addr_ext)
+ dev_create = 2;
+ }
+
if (!tb[NOTIFY_IFNAME]) {
if (!state->proto.iface->main_dev.dev)
return UBUS_STATUS_INVALID_ARGUMENT;
device_remove_user(&state->l3_dev);
device_add_user(&state->l3_dev,
- device_get(blobmsg_data(tb[NOTIFY_IFNAME]), true));
+ device_get(blobmsg_data(tb[NOTIFY_IFNAME]), dev_create));
state->proto.iface->l3_dev = &state->l3_dev;
device_claim(&state->l3_dev);
}
ip = &state->proto.iface->proto_ip;
interface_update_start(state->proto.iface);
- if ((cur = tb[NOTIFY_ADDR_EXT]) != NULL)
- addr_ext = blobmsg_get_bool(cur);
-
if ((cur = tb[NOTIFY_IPADDR]) != NULL)
proto_shell_parse_addr_list(ip, cur, false, addr_ext);
}
}
-struct interface_proto_state *
+static struct interface_proto_state *
proto_shell_attach(const struct proto_handler *h, struct interface *iface,
struct blob_attr *attr)
{
struct json_tokener *tok = NULL;
json_object *obj;
static char buf[512];
- char *start, *end, *cmd;
+ char *start, *cmd;
FILE *f;
- int buflen, len;
+ int len;
#define DUMP_SUFFIX " '' dump"
return;
do {
- buflen = fread(buf, 1, sizeof(buf) - 1, f);
- if (buflen <= 0)
+ start = fgets(buf, sizeof(buf), f);
+ if (!start)
continue;
- start = buf;
- len = buflen;
- do {
- end = memchr(start, '\n', len);
- if (end)
- len = end - start;
-
- if (!tok)
- tok = json_tokener_new();
-
- obj = json_tokener_parse_ex(tok, start, len);
- if (!is_error(obj)) {
- proto_shell_add_handler(name, obj);
- json_object_put(obj);
- json_tokener_free(tok);
- tok = NULL;
- }
-
- if (end) {
- start = end + 1;
- len = buflen - (start - buf);
- }
- } while (len > 0);
+ len = strlen(start);
+
+ if (!tok)
+ tok = json_tokener_new();
+
+ obj = json_tokener_parse_ex(tok, start, len);
+ if (!is_error(obj)) {
+ proto_shell_add_handler(name, obj);
+ json_object_put(obj);
+ json_tokener_free(tok);
+ tok = NULL;
+ } else if (start[len - 1] == '\n') {
+ json_tokener_free(tok);
+ tok = NULL;
+ }
} while (!feof(f) && !ferror(f));
if (tok)
pclose(f);
}
-void __init proto_shell_init(void)
+static void __init proto_shell_init(void)
{
glob_t g;
int main_fd;