interface: add support for disabling renew on topology change
authorFelix Fietkau <nbd@nbd.name>
Wed, 17 Jul 2024 17:56:50 +0000 (19:56 +0200)
committerFelix Fietkau <nbd@nbd.name>
Mon, 2 Sep 2024 15:33:59 +0000 (17:33 +0200)
In some cases this may trigger too many dhcp requests, tripping up upstream
servers, so there needs to be an option to disable this behavior.

Signed-off-by: Felix Fietkau <nbd@nbd.name>
interface.c
interface.h
scripts/netifd-proto.sh

index 641bcddcf031f4ae472fb45eb5c9261d58fc9eb4..eb3bece1f7a576d892012658e54ed696810b1186 100644 (file)
@@ -45,6 +45,7 @@ enum {
        IFACE_ATTR_DNS,
        IFACE_ATTR_DNS_SEARCH,
        IFACE_ATTR_DNS_METRIC,
+       IFACE_ATTR_RENEW,
        IFACE_ATTR_METRIC,
        IFACE_ATTR_INTERFACE,
        IFACE_ATTR_IP6ASSIGN,
@@ -73,6 +74,7 @@ static const struct blobmsg_policy iface_attrs[IFACE_ATTR_MAX] = {
        [IFACE_ATTR_PEERDNS] = { .name = "peerdns", .type = BLOBMSG_TYPE_BOOL },
        [IFACE_ATTR_METRIC] = { .name = "metric", .type = BLOBMSG_TYPE_INT32 },
        [IFACE_ATTR_DNS] = { .name = "dns", .type = BLOBMSG_TYPE_ARRAY },
+       [IFACE_ATTR_RENEW] = { .name = "renew", .type = BLOBMSG_TYPE_BOOL },
        [IFACE_ATTR_DNS_SEARCH] = { .name = "dns_search", .type = BLOBMSG_TYPE_ARRAY },
        [IFACE_ATTR_DNS_METRIC] = { .name = "dns_metric", .type = BLOBMSG_TYPE_INT32 },
        [IFACE_ATTR_INTERFACE] = { .name = "interface", .type = BLOBMSG_TYPE_STRING },
@@ -452,7 +454,8 @@ interface_main_dev_cb(struct device_user *dep, enum device_event ev)
                interface_set_link_state(iface, device_link_active(dep->dev));
                break;
        case DEV_EVENT_TOPO_CHANGE:
-               interface_proto_event(iface->proto, PROTO_CMD_RENEW, false);
+               if (iface->renew)
+                       interface_proto_event(iface->proto, PROTO_CMD_RENEW, false);
                return;
        default:
                break;
@@ -850,6 +853,7 @@ interface_alloc(const char *name, struct blob_attr *config, bool dynamic)
                force_link = true;
 
        iface->autostart = blobmsg_get_bool_default(tb[IFACE_ATTR_AUTO], true);
+       iface->renew = blobmsg_get_bool_default(tb[IFACE_ATTR_RENEW], true);
        iface->force_link = blobmsg_get_bool_default(tb[IFACE_ATTR_FORCE_LINK], force_link);
        iface->dynamic = dynamic;
        iface->proto_ip.no_defaultroute =
index 9343ade2327bfe12b9b8fdc281daa20bebf31fc6..122864f9f08b04d53c4bcd7f14f8e2a929f23571 100644 (file)
@@ -124,6 +124,7 @@ struct interface {
        bool dynamic;
        bool policy_rules_set;
        bool link_up_event;
+       bool renew;
 
        time_t start_time;
        enum interface_state state;
index 0785b9c1fce24c8aca4320b995cd6bd6fb9d42a7..c25aa9f627ed4a0a16c19140d78b97e464b79ad4 100644 (file)
@@ -23,6 +23,7 @@ proto_config_add_array() {
 proto_config_add_defaults() {
        proto_config_add_boolean "defaultroute"
        proto_config_add_boolean "peerdns"
+       proto_config_add_boolean "renew"
        proto_config_add_int "metric"
 }