diff options
author | Mikael Magnusson <mikma@users.sourceforge.net> | 2020-11-08 22:24:11 +0100 |
---|---|---|
committer | Mikael Magnusson <mikma@users.sourceforge.net> | 2020-11-08 22:24:11 +0100 |
commit | 3e37ffd2597846830836bfa1159ee7e615ea6f0f (patch) | |
tree | b0d7df263e59ccdef0ce2f0329761bac70d97c7a | |
parent | 5e02f94411b06f192fb2a7d9be9abde3549153a8 (diff) |
WIP: add ip rules priority options
-rw-r--r-- | config.c | 19 | ||||
-rw-r--r-- | interface-ip.c | 22 | ||||
-rw-r--r-- | interface-ip.h | 2 |
3 files changed, 39 insertions, 4 deletions
@@ -306,6 +306,17 @@ config_init_rules(void) iprule_update_complete(); } +static unsigned int +lookup_global_integer(const char *name, unsigned int default_value) +{ + const char *value = uci_lookup_option_string( + uci_ctx, globals, name); + if (!value) + return default_value; + + return atoi(value); +} + static void config_init_globals(void) { @@ -317,6 +328,14 @@ config_init_globals(void) const char *ula_prefix = uci_lookup_option_string( uci_ctx, globals, "ula_prefix"); interface_ip_set_ula_prefix(ula_prefix); + + unsigned int priority_addr = lookup_global_integer( + "priority_addr", IPRULE_PRIORITY_ADDR); + interface_ip_set_addr_priority(priority_addr); + + unsigned int priority_addr_mask = lookup_global_integer( + "priority_addr_mask", IPRULE_PRIORITY_ADDR_MASK); + interface_ip_set_addr_priority_mask(priority_addr_mask); } static void diff --git a/interface-ip.c b/interface-ip.c index c159e09..b5029c5 100644 --- a/interface-ip.c +++ b/interface-ip.c @@ -94,6 +94,8 @@ const struct uci_blob_param_list neighbor_attr_list = { struct list_head prefixes = LIST_HEAD_INIT(prefixes); static struct device_prefix *ula_prefix = NULL; static struct uloop_timeout valid_until_timeout; +static unsigned int priority_addr = IPRULE_PRIORITY_ADDR; +static unsigned int priority_addr_mask = IPRULE_PRIORITY_ADDR_MASK; static void @@ -599,10 +601,10 @@ interface_add_addr_rules(struct device_addr *addr, bool enabled) { bool v6 = (addr->flags & DEVADDR_FAMILY) == DEVADDR_INET6; - set_ip_source_policy(enabled, v6, IPRULE_PRIORITY_ADDR, &addr->addr, + set_ip_source_policy(enabled, v6, priority_addr, &addr->addr, (v6) ? 128 : 32, addr->policy_table, NULL, NULL, true); - set_ip_source_policy(enabled, v6, IPRULE_PRIORITY_ADDR_MASK, + set_ip_source_policy(enabled, v6, priority_addr_mask, &addr->addr, addr->mask, addr->policy_table, NULL, NULL, false); } @@ -927,7 +929,7 @@ interface_set_prefix_address(struct device_prefix_assignment *assignment, addr.valid_until = now + 7200; if (iface->ip6table) - set_ip_source_policy(false, true, IPRULE_PRIORITY_ADDR_MASK, &addr.addr, + set_ip_source_policy(false, true, priority_addr_mask, &addr.addr, addr.mask < 64 ? 64 : addr.mask, iface->ip6table, NULL, NULL, false); if (prefix->iface) { @@ -963,7 +965,7 @@ interface_set_prefix_address(struct device_prefix_assignment *assignment, if (!assignment->enabled) { if (iface->ip6table) - set_ip_source_policy(true, true, IPRULE_PRIORITY_ADDR_MASK, &addr.addr, + set_ip_source_policy(true, true, priority_addr_mask, &addr.addr, addr.mask < 64 ? 64 : addr.mask, iface->ip6table, NULL, NULL, false); if (prefix->iface) { @@ -1326,6 +1328,18 @@ interface_ip_set_ula_prefix(const char *prefix) } } +void +interface_ip_set_addr_priority(unsigned int priority) +{ + priority_addr = priority; +} + +void +interface_ip_set_addr_mask_priority(unsigned int priority) +{ + priority_addr_mask = priority; +} + static void interface_add_dns_server(struct interface_ip_settings *ip, const char *str) { diff --git a/interface-ip.h b/interface-ip.h index 3f99eb9..e5a7663 100644 --- a/interface-ip.h +++ b/interface-ip.h @@ -189,6 +189,8 @@ struct device_prefix* interface_ip_add_device_prefix(struct interface *iface, struct in6_addr *addr, uint8_t length, time_t valid_until, time_t preferred_until, struct in6_addr *excl_addr, uint8_t excl_length, const char *pclass); void interface_ip_set_ula_prefix(const char *prefix); +void interface_ip_set_addr_priority(); +void interface_ip_set_addr_mask_priority(); void interface_refresh_assignments(bool hint); void interface_update_prefix_delegation(struct interface_ip_settings *ip); |