static bool
parse_addr(struct static_proto_state *state, const char *str, bool v6, int mask)
{
- struct interface_addr *addr;
+ struct device_addr *addr;
int af = v6 ? AF_INET6 : AF_INET;
addr = calloc(1, sizeof(*addr));
- addr->flags = v6 ? IFADDR_INET6 : IFADDR_INET4;
+ addr->flags = v6 ? DEVADDR_INET6 : DEVADDR_INET4;
addr->ctx = state;
addr->mask = mask;
if (!parse_ip_and_netmask(af, str, &addr->addr, &addr->mask)) {
return n_addr;
}
+static bool
+parse_gateway_option(struct static_proto_state *state, struct uci_option *o, bool v6)
+{
+ struct device_route *route;
+ const char *str = o->v.string;
+ int af = v6 ? AF_INET6 : AF_INET;
+
+ route = calloc(1, sizeof(*route));
+ if (!inet_pton(af, str, &route->nexthop)) {
+ interface_add_error(state->iface, "proto-static",
+ "INVALID_GATEWAY", &str, 1);
+ free(route);
+ return false;
+ }
+ route->mask = 0;
+ route->flags = DEVADDR_DEVICE | (v6 ? DEVADDR_INET6 : DEVADDR_INET4);
+ interface_add_route(state->iface, route);
+
+ return true;
+}
+
enum {
OPT_IPADDR,
OPT_IP6ADDR,
if (n_v4 < 0 || n_v6 < 0)
goto out;
-#if 0
- if (ps.n_v4 && tb[OPT_GATEWAY]) {
- if (!inet_pton(AF_INET, tb[OPT_GATEWAY]->v.string, &ps.ipv4gw)) {
- error = "INVALID_GATEWAY";
- goto error;
- }
- ps.flags |= STATIC_F_IPV4GW;
+ if (n_v4 && tb[OPT_GATEWAY]) {
+ if (!parse_gateway_option(state, tb[OPT_GATEWAY], false))
+ goto out;
}
- if (ps.n_v6 && tb[OPT_IP6GW]) {
- if (!inet_pton(AF_INET6, tb[OPT_IP6GW]->v.string, &ps.ipv6gw)) {
- error = "INVALID_GATEWAY";
- goto error;
- }
- ps.flags |= STATIC_F_IPV6GW;
+ if (n_v6 && tb[OPT_IP6GW]) {
+ if (!parse_gateway_option(state, tb[OPT_IP6GW], true))
+ goto out;
}
-#endif
return true;
}
struct interface_proto_state *
-static_attach(struct proto_handler *h, struct interface *iface,
+static_attach(const struct proto_handler *h, struct interface *iface,
struct uci_section *s)
{
struct static_proto_state *state;