summaryrefslogtreecommitdiffhomepage
path: root/src/config.c
diff options
context:
space:
mode:
authorChristian Mehlis <christian@m3hlis.de>2014-08-12 14:58:06 +0200
committerChristian Mehlis <christian@m3hlis.de>2014-08-12 14:58:06 +0200
commitf2cda6c15b55c80be8739f492a8ee7b4dbd1cf52 (patch)
treea2095d9dec4fb67c6de995e47c9664013bbd2aec /src/config.c
parent634d9fe9142f62b7b2e7647ef88d6606e54ab155 (diff)
dhcpv4: implement router configuration option
RFC 2132 defines: 3.5. Router Option The router option specifies a list of IP addresses for routers on the client's subnet. Routers SHOULD be listed in order of preference. The code for the router option is 3. The minimum length for the router option is 4 octets, and the length MUST always be a multiple of 4. Code Len Address 1 Address 2 +-----+-----+-----+-----+-----+-----+-----+-----+-- | 3 | n | a1 | a2 | a3 | a4 | a1 | a2 | ... +-----+-----+-----+-----+-----+-----+-----+-----+--
Diffstat (limited to 'src/config.c')
-rw-r--r--src/config.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/config.c b/src/config.c
index 068d1a7..835db13 100644
--- a/src/config.c
+++ b/src/config.c
@@ -30,6 +30,7 @@ enum {
IFACE_ATTR_DHCPV4,
IFACE_ATTR_DHCPV6,
IFACE_ATTR_NDP,
+ IFACE_ATTR_ROUTER,
IFACE_ATTR_DNS,
IFACE_ATTR_DOMAIN,
IFACE_ATTR_FILTER_CLASS,
@@ -61,6 +62,7 @@ static const struct blobmsg_policy iface_attrs[IFACE_ATTR_MAX] = {
[IFACE_ATTR_DHCPV4] = { .name = "dhcpv4", .type = BLOBMSG_TYPE_STRING },
[IFACE_ATTR_DHCPV6] = { .name = "dhcpv6", .type = BLOBMSG_TYPE_STRING },
[IFACE_ATTR_NDP] = { .name = "ndp", .type = BLOBMSG_TYPE_STRING },
+ [IFACE_ATTR_ROUTER] = { .name = "router", .type = BLOBMSG_TYPE_ARRAY },
[IFACE_ATTR_DNS] = { .name = "dns", .type = BLOBMSG_TYPE_ARRAY },
[IFACE_ATTR_DOMAIN] = { .name = "domain", .type = BLOBMSG_TYPE_ARRAY },
[IFACE_ATTR_FILTER_CLASS] = { .name = "filter_class", .type = BLOBMSG_TYPE_STRING },
@@ -152,6 +154,7 @@ static void clean_interface(struct interface *iface)
free(iface->search);
free(iface->upstream);
free(iface->static_ndp);
+ free(iface->dhcpv4_router);
free(iface->dhcpv4_dns);
free(iface->dhcpv6_raw);
free(iface->filter_class);
@@ -409,6 +412,28 @@ int config_parse_interface(void *data, size_t len, const char *name, bool overwr
goto err;
}
+ if ((c = tb[IFACE_ATTR_ROUTER])) {
+ struct blob_attr *cur;
+ unsigned rem;
+
+ blobmsg_for_each_attr(cur, c, rem) {
+ if (blobmsg_type(cur) != BLOBMSG_TYPE_STRING || !blobmsg_check_attr(cur, NULL))
+ continue;
+
+ struct in_addr addr4;
+ if (inet_pton(AF_INET, blobmsg_get_string(cur), &addr4) == 1) {
+ iface->dhcpv4_router = realloc(iface->dhcpv4_router,
+ (++iface->dhcpv4_router_cnt) * sizeof(*iface->dhcpv4_router));
+ if (!iface->dhcpv4_router)
+ goto err;
+
+ iface->dhcpv4_router[iface->dhcpv4_router_cnt - 1] = addr4;
+ } else {
+ goto err;
+ }
+ }
+ }
+
if ((c = tb[IFACE_ATTR_DNS])) {
struct blob_attr *cur;
unsigned rem;