X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fodhcpd.git;a=blobdiff_plain;f=src%2Fconfig.c;h=df0cbc4cb11f3c907540cb425c713f6c89783ee2;hp=5174f2c7dde12c38c00938c7f7a7568a42dbb9b5;hb=e437ce9422c2f92752be5b6b3fd453e099a98a7e;hpb=0129f7926b9a0f993058dca9775e64021527eb32;ds=sidebyside diff --git a/src/config.c b/src/config.c index 5174f2c..df0cbc4 100644 --- a/src/config.c +++ b/src/config.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include @@ -16,7 +17,8 @@ static struct blob_buf b; static int reload_pipe[2]; struct list_head leases = LIST_HEAD_INIT(leases); struct list_head interfaces = LIST_HEAD_INIT(interfaces); -struct config config = {false, NULL, NULL}; +struct config config = {.legacy = false, .dhcp_cb = NULL, + .dhcp_statefile = NULL, .log_level = LOG_INFO}; enum { IFACE_ATTR_INTERFACE, @@ -43,7 +45,9 @@ enum { IFACE_ATTR_RA_OFFLINK, IFACE_ATTR_RA_PREFERENCE, IFACE_ATTR_RA_ADVROUTER, + IFACE_ATTR_RA_MININTERVAL, IFACE_ATTR_RA_MAXINTERVAL, + IFACE_ATTR_RA_LIFETIME, IFACE_ATTR_PD_MANAGER, IFACE_ATTR_PD_CER, IFACE_ATTR_NDPROXY_ROUTING, @@ -78,7 +82,9 @@ static const struct blobmsg_policy iface_attrs[IFACE_ATTR_MAX] = { [IFACE_ATTR_RA_OFFLINK] = { .name = "ra_offlink", .type = BLOBMSG_TYPE_BOOL }, [IFACE_ATTR_RA_PREFERENCE] = { .name = "ra_preference", .type = BLOBMSG_TYPE_STRING }, [IFACE_ATTR_RA_ADVROUTER] = { .name = "ra_advrouter", .type = BLOBMSG_TYPE_BOOL }, + [IFACE_ATTR_RA_MININTERVAL] = { .name = "ra_mininterval", .type = BLOBMSG_TYPE_INT32 }, [IFACE_ATTR_RA_MAXINTERVAL] = { .name = "ra_maxinterval", .type = BLOBMSG_TYPE_INT32 }, + [IFACE_ATTR_RA_LIFETIME] = { .name = "ra_lifetime", .type = BLOBMSG_TYPE_INT32 }, [IFACE_ATTR_NDPROXY_ROUTING] = { .name = "ndproxy_routing", .type = BLOBMSG_TYPE_BOOL }, [IFACE_ATTR_NDPROXY_SLAVE] = { .name = "ndproxy_slave", .type = BLOBMSG_TYPE_BOOL }, }; @@ -123,6 +129,7 @@ enum { ODHCPD_ATTR_MAINDHCP, ODHCPD_ATTR_LEASEFILE, ODHCPD_ATTR_LEASETRIGGER, + ODHCPD_ATTR_LOGLEVEL, ODHCPD_ATTR_MAX }; @@ -130,6 +137,7 @@ static const struct blobmsg_policy odhcpd_attrs[LEASE_ATTR_MAX] = { [ODHCPD_ATTR_MAINDHCP] = { .name = "maindhcp", .type = BLOBMSG_TYPE_BOOL }, [ODHCPD_ATTR_LEASEFILE] = { .name = "leasefile", .type = BLOBMSG_TYPE_STRING }, [ODHCPD_ATTR_LEASETRIGGER] = { .name = "leasetrigger", .type = BLOBMSG_TYPE_STRING }, + [ODHCPD_ATTR_LOGLEVEL] = { .name = "loglevel", .type = BLOBMSG_TYPE_INT32 }, }; const struct uci_blob_param_list odhcpd_attr_list = { @@ -184,6 +192,10 @@ static void set_interface_defaults(struct interface *iface) { iface->managed = 1; iface->learn_routes = 1; + iface->dhcpv4_leasetime = 43200; + iface->ra_maxinterval = 600; + iface->ra_mininterval = iface->ra_maxinterval/3; + iface->ra_lifetime = -1; } static void clean_interface(struct interface *iface) @@ -247,6 +259,15 @@ static void set_config(struct uci_section *s) free(config.dhcp_cb); config.dhcp_cb = strdup(blobmsg_get_string(c)); } + + if ((c = tb[ODHCPD_ATTR_LOGLEVEL])) { + int log_level = (blobmsg_get_u32(c) & LOG_PRIMASK); + + if (config.log_level != log_level) { + config.log_level = log_level; + setlogmask(LOG_UPTO(config.log_level)); + } + } } static double parse_leasetime(struct blob_attr *c) { @@ -268,10 +289,10 @@ static double parse_leasetime(struct blob_attr *c) { goto err; } - if (time >= 60) - return time; + if (time < 60) + time = 60; - return 0; + return time; err: return -1; @@ -331,8 +352,7 @@ static int set_lease(struct uci_section *s) if (time < 0) goto err; - if (time >= 60) - lease->dhcpv4_leasetime = time; + lease->dhcpv4_leasetime = time; } list_add(&lease->head, &leases); @@ -405,8 +425,7 @@ int config_parse_interface(void *data, size_t len, const char *name, bool overwr if (time < 0) goto err; - if (time >= 60) - iface->dhcpv4_leasetime = time; + iface->dhcpv4_leasetime = time; } if ((c = tb[IFACE_ATTR_START])) { @@ -571,9 +590,15 @@ int config_parse_interface(void *data, size_t len, const char *name, bool overwr if ((c = tb[IFACE_ATTR_RA_ADVROUTER])) iface->ra_advrouter = blobmsg_get_bool(c); + if ((c = tb[IFACE_ATTR_RA_MININTERVAL])) + iface->ra_mininterval = blobmsg_get_u32(c); + if ((c = tb[IFACE_ATTR_RA_MAXINTERVAL])) iface->ra_maxinterval = blobmsg_get_u32(c); + if ((c = tb[IFACE_ATTR_RA_LIFETIME])) + iface->ra_lifetime = blobmsg_get_u32(c); + if ((c = tb[IFACE_ATTR_RA_PREFERENCE])) { const char *prio = blobmsg_get_string(c);