diff options
author | Steven Barth <steven@midlink.org> | 2013-10-14 13:12:28 +0200 |
---|---|---|
committer | Steven Barth <steven@midlink.org> | 2013-10-14 13:12:28 +0200 |
commit | 78c5e4b032c420852abc2a9e1e6f429a4d803c21 (patch) | |
tree | 76c0f1f4c08571516b70d7f5575f7cec7cf02adf /src | |
parent | 2a80a389e1df5341ada9a9f66ce0ad9844ef65f7 (diff) |
Various fixes
Diffstat (limited to 'src')
-rw-r--r-- | src/config.c | 19 | ||||
-rw-r--r-- | src/dhcpv4.c | 6 | ||||
-rw-r--r-- | src/odhcpd.h | 1 | ||||
-rw-r--r-- | src/ubus.c | 37 |
4 files changed, 56 insertions, 7 deletions
diff --git a/src/config.c b/src/config.c index 6ae219a..ebc6642 100644 --- a/src/config.c +++ b/src/config.c @@ -15,6 +15,7 @@ struct config config = {false, NULL, NULL}; enum { IFACE_ATTR_INTERFACE, IFACE_ATTR_IFNAME, + IFACE_ATTR_NETWORKID, IFACE_ATTR_DYNAMICDHCP, IFACE_ATTR_IGNORE, IFACE_ATTR_LEASETIME, @@ -25,7 +26,7 @@ enum { IFACE_ATTR_RA, IFACE_ATTR_DHCPV4, IFACE_ATTR_DHCPV6, - IFACE_ATTR_NDPROXY, + IFACE_ATTR_NDP, IFACE_ATTR_DNS, IFACE_ATTR_DOMAIN, IFACE_ATTR_ULA_COMPAT, @@ -42,6 +43,7 @@ enum { static const struct blobmsg_policy iface_attrs[IFACE_ATTR_MAX] = { [IFACE_ATTR_INTERFACE] = { .name = "interface", .type = BLOBMSG_TYPE_STRING }, [IFACE_ATTR_IFNAME] = { .name = "ifname", .type = BLOBMSG_TYPE_STRING }, + [IFACE_ATTR_NETWORKID] = { .name = "networkid", .type = BLOBMSG_TYPE_STRING }, [IFACE_ATTR_DYNAMICDHCP] = { .name = "dynamicdhcp", .type = BLOBMSG_TYPE_BOOL }, [IFACE_ATTR_IGNORE] = { .name = "ignore", .type = BLOBMSG_TYPE_BOOL }, [IFACE_ATTR_LEASETIME] = { .name = "leasetime", .type = BLOBMSG_TYPE_STRING }, @@ -52,7 +54,7 @@ static const struct blobmsg_policy iface_attrs[IFACE_ATTR_MAX] = { [IFACE_ATTR_RA] = { .name = "ra", .type = BLOBMSG_TYPE_STRING }, [IFACE_ATTR_DHCPV4] = { .name = "dhcpv4", .type = BLOBMSG_TYPE_STRING }, [IFACE_ATTR_DHCPV6] = { .name = "dhcpv6", .type = BLOBMSG_TYPE_STRING }, - [IFACE_ATTR_NDPROXY] = { .name = "ndproxy", .type = BLOBMSG_TYPE_BOOL }, + [IFACE_ATTR_NDP] = { .name = "ndp", .type = BLOBMSG_TYPE_STRING }, [IFACE_ATTR_DNS] = { .name = "dns", .type = BLOBMSG_TYPE_ARRAY }, [IFACE_ATTR_DOMAIN] = { .name = "domain", .type = BLOBMSG_TYPE_ARRAY }, [IFACE_ATTR_ULA_COMPAT] = { .name = "ula_compat", .type = BLOBMSG_TYPE_BOOL }, @@ -276,6 +278,8 @@ int config_parse_interface(struct blob_attr *b, const char *name, bool overwrite #endif if ((c = tb[IFACE_ATTR_IFNAME])) ifname = blobmsg_get_string(c); + else if ((c = tb[IFACE_ATTR_NETWORKID])) + ifname = blobmsg_get_string(c); strncpy(iface->ifname, ifname, sizeof(iface->ifname) - 1); iface->inuse = true; @@ -352,13 +356,15 @@ int config_parse_interface(struct blob_attr *b, const char *name, bool overwrite if ((iface->dhcpv6 = parse_mode(blobmsg_get_string(c))) < 0) goto err; - if ((c = tb[IFACE_ATTR_NDPROXY])) - iface->ndp = blobmsg_get_bool(c) ? RELAYD_RELAY : RELAYD_DISABLED; + if ((c = tb[IFACE_ATTR_NDP])) + if ((iface->ndp = parse_mode(blobmsg_get_string(c))) < 0) + goto err; if ((c = tb[IFACE_ATTR_DNS])) { struct blob_attr *cur; int rem; + iface->always_rewrite_dns = true; blobmsg_for_each_attr(cur, c, rem) { if (blobmsg_type(cur) != BLOBMSG_TYPE_STRING || !blobmsg_check_attr(cur, NULL)) continue; @@ -513,6 +519,11 @@ void odhcpd_run(void) continue; enum odhcpd_mode hybrid_mode = RELAYD_DISABLED; +#ifdef WITH_UBUS + if (ubus_has_prefix(i->name, i->ifname)) + hybrid_mode = RELAYD_RELAY; +#endif + if (i->dhcpv6 == RELAYD_HYBRID) i->dhcpv6 = hybrid_mode; diff --git a/src/dhcpv4.c b/src/dhcpv4.c index 38b4f9b..7a68f66 100644 --- a/src/dhcpv4.c +++ b/src/dhcpv4.c @@ -119,8 +119,8 @@ int setup_dhcpv4_interface(struct interface *iface, bool enable) end = addr.s_addr & mask.s_addr; if (ntohl(mask.s_addr) <= 0xffffff00) { - iface->dhcpv4_start.s_addr = start | htonl(20); - iface->dhcpv4_end.s_addr = end | htonl(199); + iface->dhcpv4_start.s_addr = start | htonl(100); + iface->dhcpv4_end.s_addr = end | htonl(250); } else { iface->dhcpv4_start.s_addr = start | htonl(10); iface->dhcpv4_end.s_addr = end | htonl(59); @@ -168,7 +168,7 @@ int setup_dhcpv4_interface(struct interface *iface, bool enable) if (iface->dhcpv4_leasetime < 60) - iface->dhcpv4_leasetime = 1800; + iface->dhcpv4_leasetime = 43200; iface->dhcpv4_event.uloop.fd = sock; iface->dhcpv4_event.handle_dgram = handle_dhcpv4; diff --git a/src/odhcpd.h b/src/odhcpd.h index be8baeb..fb3db37 100644 --- a/src/odhcpd.h +++ b/src/odhcpd.h @@ -190,6 +190,7 @@ int config_parse_interface(struct blob_attr *b, const char *iname, bool overwrit const char* ubus_get_ifname(const char *name); void ubus_apply_network(void); +bool ubus_has_prefix(const char *name, const char *ifname); // Exported module initializers @@ -160,6 +160,7 @@ enum { IFACE_ATTR_IFNAME, IFACE_ATTR_UP, IFACE_ATTR_DATA, + IFACE_ATTR_PREFIX, IFACE_ATTR_MAX, }; @@ -168,6 +169,7 @@ static const struct blobmsg_policy iface_attrs[IFACE_ATTR_MAX] = { [IFACE_ATTR_IFNAME] = { .name = "ifname", .type = BLOBMSG_TYPE_STRING }, [IFACE_ATTR_UP] = { .name = "up", .type = BLOBMSG_TYPE_BOOL }, [IFACE_ATTR_DATA] = { .name = "data", .type = BLOBMSG_TYPE_TABLE }, + [IFACE_ATTR_PREFIX] = { .name = "ipv6-prefix", .type = BLOBMSG_TYPE_ARRAY }, }; static void handle_dump(_unused struct ubus_request *req, _unused int type, struct blob_attr *msg) @@ -308,6 +310,41 @@ const char* ubus_get_ifname(const char *name) } +bool ubus_has_prefix(const char *name, const char *ifname) +{ + struct blob_attr *c, *cur; + int rem; + + if (!dump) + return NULL; + + blobmsg_for_each_attr(c, dump, rem) { + struct blob_attr *tb[IFACE_ATTR_MAX]; + blobmsg_parse(iface_attrs, IFACE_ATTR_MAX, tb, blob_data(c), blob_len(c)); + + if (!tb[IFACE_ATTR_INTERFACE] || !tb[IFACE_ATTR_IFNAME]) + continue; + + if (!strcmp(name, blobmsg_get_string(tb[IFACE_ATTR_INTERFACE])) || + !strcmp(ifname, blobmsg_get_string(tb[IFACE_ATTR_IFNAME]))) + continue; + + if ((cur = tb[IFACE_ATTR_PREFIX])) { + if (blobmsg_type(cur) != BLOBMSG_TYPE_ARRAY || !blobmsg_check_attr(cur, NULL)) + continue; + + struct blob_attr *d; + int drem; + blobmsg_for_each_attr(d, cur, drem) { + return true; + } + } + } + + return false; +} + + int init_ubus(void) { if (!(ubus = ubus_connect(NULL))) { |