interface string <name of UCI section> logical OpenWrt interface
ifname string <resolved from logical> physical network interface
networkid string same as ifname compat. alias for ifname
-ignore bool 0 do not serve this interface
- unless overridden by ra, ndp,
- dhcpv4 or dhcpv6 options
master bool 0 is a master interface
for relaying
IFACE_ATTR_IFNAME,
IFACE_ATTR_NETWORKID,
IFACE_ATTR_DYNAMICDHCP,
- IFACE_ATTR_IGNORE,
IFACE_ATTR_LEASETIME,
IFACE_ATTR_LIMIT,
IFACE_ATTR_START,
[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 },
[IFACE_ATTR_START] = { .name = "start", .type = BLOBMSG_TYPE_INT32 },
[IFACE_ATTR_LIMIT] = { .name = "limit", .type = BLOBMSG_TYPE_INT32 },
static void set_interface_defaults(struct interface *iface)
{
+ iface->ignore = true;
+ iface->dhcpv4 = MODE_DISABLED;
+ iface->dhcpv6 = MODE_DISABLED;
+ iface->ra = MODE_DISABLED;
+ iface->ndp = MODE_DISABLED;
iface->learn_routes = 1;
iface->dhcpv4_leasetime = 43200;
iface->dhcpv4_start.s_addr = htonl(START_DEFAULT);
if ((c = tb[IFACE_ATTR_DYNAMICDHCP]))
iface->no_dynamic_dhcp = !blobmsg_get_bool(c);
- if (overwrite && (c = tb[IFACE_ATTR_IGNORE]))
- iface->ignore = blobmsg_get_bool(c);
-
if ((c = tb[IFACE_ATTR_LEASETIME])) {
double time = parse_leasetime(c);
if (time < 0)
int mode;
if ((c = tb[IFACE_ATTR_RA])) {
- if ((mode = parse_mode(blobmsg_get_string(c))) >= 0)
+ if ((mode = parse_mode(blobmsg_get_string(c))) >= 0) {
iface->ra = mode;
- else
+
+ if (iface->ra != MODE_DISABLED)
+ iface->ignore = false;
+ } else
goto err;
}
if ((c = tb[IFACE_ATTR_DHCPV4])) {
if ((mode = parse_mode(blobmsg_get_string(c))) >= 0) {
- if (config.main_dhcpv4)
+ if (config.main_dhcpv4) {
iface->dhcpv4 = mode;
+
+ if (iface->dhcpv4 != MODE_DISABLED)
+ iface->ignore = false;
+ }
}
else
goto err;
}
if ((c = tb[IFACE_ATTR_DHCPV6])) {
- if ((mode = parse_mode(blobmsg_get_string(c))) >= 0)
+ if ((mode = parse_mode(blobmsg_get_string(c))) >= 0) {
iface->dhcpv6 = mode;
- else
+
+ if (iface->dhcpv6 != MODE_DISABLED)
+ iface->ignore = false;
+ } else
goto err;
}
if ((c = tb[IFACE_ATTR_NDP])) {
- if ((mode = parse_mode(blobmsg_get_string(c))) >= 0)
+ if ((mode = parse_mode(blobmsg_get_string(c))) >= 0) {
iface->ndp = mode;
- else
+
+ if (iface->ndp != MODE_DISABLED)
+ iface->ignore = false;
+ } else
goto err;
}
i->ndp = (master && master->ndp == MODE_RELAY) ?
MODE_RELAY : MODE_DISABLED;
- router_setup_interface(i, !i->ignore || i->ra != MODE_DISABLED);
- dhcpv6_setup_interface(i, !i->ignore || i->dhcpv6 != MODE_DISABLED);
- ndp_setup_interface(i, !i->ignore || i->ndp != MODE_DISABLED);
+ router_setup_interface(i, i->ra != MODE_DISABLED);
+ dhcpv6_setup_interface(i, i->dhcpv6 != MODE_DISABLED);
+ ndp_setup_interface(i, i->ndp != MODE_DISABLED);
#ifdef DHCPV4_SUPPORT
- dhcpv4_setup_interface(i, !i->ignore || i->dhcpv4 != MODE_DISABLED);
+ dhcpv4_setup_interface(i, i->dhcpv4 != MODE_DISABLED);
#endif
} else
close_interface(i);
{
int ret = 0;
+ enable = enable && (iface->dhcpv4 != MODE_DISABLED);
+
if (iface->dhcpv4_event.uloop.fd >= 0) {
uloop_fd_delete(&iface->dhcpv4_event.uloop);
close(iface->dhcpv4_event.uloop.fd);
iface->dhcpv4_event.uloop.fd = -1;
}
- if (iface->dhcpv4 && enable) {
+ if (enable) {
struct sockaddr_in bind_addr = {AF_INET, htons(DHCPV4_SERVER_PORT),
{INADDR_ANY}, {0}};
int val = 1;
{
struct dhcpv4_message *req = data;
- if (!iface->dhcpv4)
+ if (iface->dhcpv4 == MODE_DISABLED)
return;
if (len < offsetof(struct dhcpv4_message, options) + 4 ||
int dhcpv6_ia_setup_interface(struct interface *iface, bool enable)
{
- if (!enable) {
- struct dhcp_assignment *c;
-
- while (!list_empty(&iface->ia_assignments)) {
- c = list_first_entry(&iface->ia_assignments, struct dhcp_assignment, head);
- free_assignment(c);
- }
- }
+ enable = enable && (iface->dhcpv6 == MODE_SERVER);
- if (enable && iface->dhcpv6 == MODE_SERVER) {
+ if (enable) {
struct dhcp_assignment *border;
if (list_empty(&iface->ia_assignments)) {
border = list_last_entry(&iface->ia_assignments, struct dhcp_assignment, head);
set_border_assignment_size(iface, border);
+ } else {
+ struct dhcp_assignment *c;
+
+ while (!list_empty(&iface->ia_assignments)) {
+ c = list_first_entry(&iface->ia_assignments, struct dhcp_assignment, head);
+ free_assignment(c);
+ }
}
+
return 0;
}
{
int ret = 0;
+ enable = enable && (iface->dhcpv6 != MODE_DISABLED);
+
if (iface->dhcpv6_event.uloop.fd >= 0) {
uloop_fd_delete(&iface->dhcpv6_event.uloop);
close(iface->dhcpv6_event.uloop.fd);
}
/* Configure multicast settings */
- if (enable && iface->dhcpv6) {
+ if (enable) {
struct sockaddr_in6 bind_addr = {AF_INET6, htons(DHCPV6_SERVER_PORT),
0, IN6ADDR_ANY_INIT, 0};
struct ipv6_mreq mreq;
bool dump_neigh = false;
char procbuf[64];
+ enable = enable && (iface->ndp == MODE_RELAY);
+
snprintf(procbuf, sizeof(procbuf), "/proc/sys/net/ipv6/conf/%s/proxy_ndp", iface->ifname);
procfd = open(procbuf, O_WRONLY);
close(iface->ndp_event.uloop.fd);
iface->ndp_event.uloop.fd = -1;
- if (!enable || iface->ndp != MODE_RELAY)
+ if (!enable)
if (write(procfd, "0\n", 2) < 0) {}
dump_neigh = true;
}
- if (enable && iface->ndp == MODE_RELAY) {
+ if (enable) {
struct sockaddr_ll ll;
struct packet_mreq mreq;
struct icmp6_filter filt;
{
int ret = 0;
+ enable = enable && (iface->ra != MODE_DISABLED);
+
if (!fp_route) {
ret = -1;
goto out;
}
- if ((!enable || iface->ra == MODE_DISABLED) && iface->router_event.uloop.fd >= 0) {
+ if (!enable && iface->router_event.uloop.fd >= 0) {
if (!iface->master) {
uloop_timeout_cancel(&iface->timer_rs);
iface->timer_rs.cb = NULL;
uloop_fd_delete(&iface->router_event.uloop);
close(iface->router_event.uloop.fd);
iface->router_event.uloop.fd = -1;
- } else if (enable && iface->ra != MODE_DISABLED) {
+ } else if (enable) {
struct icmp6_filter filt;
struct ipv6_mreq mreq;
int val = 2;
if (hlim > 0)
adv.h.nd_ra_curhoplimit = hlim;
- if (iface->dhcpv6) {
+ if (iface->dhcpv6 != MODE_DISABLED) {
adv.h.nd_ra_flags_reserved = ND_RA_FLAG_OTHER;
if (iface->ra_managed >= RA_MANAGED_MFLAG)