struct interface_proto_state proto;
struct blob_attr *config;
- struct interface *iface;
};
static bool
}
static bool
-parse_addr(struct static_proto_state *state, const char *str, bool v6, int mask)
+parse_addr(struct interface_proto_state *state, const char *str, bool v6, int mask)
{
struct device_addr *addr;
int af = v6 ? AF_INET6 : AF_INET;
}
static int
-parse_address_option(struct static_proto_state *state, struct blob_attr *attr, bool v6, int netmask)
+parse_address_option(struct interface_proto_state *state, struct blob_attr *attr, bool v6, int netmask)
{
struct blob_attr *cur;
int n_addr = 0;
}
static bool
-parse_gateway_option(struct static_proto_state *state, struct blob_attr *attr, bool v6)
+parse_gateway_option(struct interface_proto_state *state, struct blob_attr *attr, bool v6)
{
struct device_route *route;
const char *str = blobmsg_data(attr);
return true;
}
-static bool
-static_proto_setup(struct static_proto_state *state)
+int
+proto_apply_static_settings(struct interface_proto_state *state, struct blob_attr *attr)
{
struct blob_attr *tb[__OPT_MAX];
struct in_addr ina;
int netmask = 32;
int n_v4 = 0, n_v6 = 0;
- blobmsg_parse(static_attrs, __OPT_MAX, tb, blob_data(state->config),
- blob_len(state->config));
+ blobmsg_parse(static_attrs, __OPT_MAX, tb, blob_data(attr), blob_len(attr));
if (tb[OPT_NETMASK]) {
if (!inet_aton(blobmsg_data(tb[OPT_NETMASK]), &ina)) {
goto out;
}
- return true;
+ return 0;
error:
interface_add_error(state->iface, "proto-static", error, NULL, 0);
out:
- return false;
+ return -1;
+}
+
+static bool
+static_proto_setup(struct static_proto_state *state)
+{
+ return proto_apply_static_settings(&state->proto, state->config) == 0;
}
static int
/* fall through */
case PROTO_CMD_TEARDOWN:
- interface_del_ctx_addr(state->iface, state);
+ interface_del_ctx_addr(state->proto.iface, proto);
break;
}
return ret;
if (!state)
return NULL;
- state->iface = iface;
state->config = malloc(blob_pad_len(attr));
if (!state->config)
goto error;
void proto_attach_interface(struct interface *iface, const char *proto_name);
int interface_proto_event(struct interface_proto_state *proto,
enum interface_proto_cmd cmd, bool force);
+int proto_apply_static_settings(struct interface_proto_state *state,
+ struct blob_attr *attr);
#endif