Address allocation tweaking - lease outside dhcp-range but in subnet.

This commit is contained in:
Simon Kelley
2012-09-16 22:15:56 +01:00
parent 8b46061e73
commit b269221c00
4 changed files with 14 additions and 7 deletions

View File

@@ -323,14 +323,21 @@ struct dhcp_context *narrow_context6(struct dhcp_context *context,
return tmp;
}
static int is_addr_in_context6(struct dhcp_context *context, struct dhcp_config *config)
static int is_config_in_context6(struct dhcp_context *context, struct dhcp_config *config)
{
if (!context) /* called via find_config() from lease_update_from_configs() */
return 1;
if (!(config->flags & CONFIG_ADDR6))
if (!(config->flags & CONFIG_ADDR6) || is_addr_in_context6(context, &config->addr6))
return 1;
return 0;
}
int is_addr_in_context6(struct dhcp_context *context, struct in6_addr *addr)
{
for (; context; context = context->current)
if (is_same_net6(&config->addr6, &context->start6, context->prefix))
if (is_same_net6(addr, &context->start6, context->prefix))
return 1;
return 0;
@@ -350,7 +357,7 @@ struct dhcp_config *find_config6(struct dhcp_config *configs,
{
if (config->clid_len == duid_len &&
memcmp(config->clid, duid, duid_len) == 0 &&
is_addr_in_context6(context, config))
is_config_in_context6(context, config))
return config;
}
@@ -358,7 +365,7 @@ struct dhcp_config *find_config6(struct dhcp_config *configs,
for (config = configs; config; config = config->next)
if ((config->flags & CONFIG_NAME) &&
hostname_isequal(config->hostname, hostname) &&
is_addr_in_context6(context, config))
is_config_in_context6(context, config))
return config;
return NULL;

View File

@@ -1092,6 +1092,7 @@ void dhcp6_init(void);
void dhcp6_packet(time_t now);
int address6_allocate(struct dhcp_context *context, unsigned char *clid, int clid_len,
int serial, struct dhcp_netid *netids, struct in6_addr *ans);
int is_addr_in_context6(struct dhcp_context *context, struct in6_addr *addr);
struct dhcp_context *address6_available(struct dhcp_context *context,
struct in6_addr *taddr,
struct dhcp_netid *netids);

View File

@@ -582,7 +582,7 @@ void lease6_filter(int lease_type, int iaid, struct dhcp_context *context)
continue;
/* leases on the wrong interface get filtered out here */
if (!address6_available(context, (struct in6_addr *)&lease->hwaddr, NULL))
if (!is_addr_in_context6(context, (struct in6_addr *)&lease->hwaddr))
lease->flags |= LEASE_USED;
}
}

View File

@@ -582,7 +582,6 @@ static int dhcp6_no_relay(int msg_type, struct in6_addr *link_address, struct dh
if (!addrp &&
(lease = lease6_find(clid, clid_len,
ia_type == OPTION6_IA_NA ? LEASE_NA : LEASE_TA, iaid, NULL)) &&
address6_available(context, (struct in6_addr *)&lease->hwaddr, tags) &&
!config_find_by_address6(daemon->dhcp_conf, (struct in6_addr *)&lease->hwaddr, 128, 0))
addrp = (struct in6_addr *)&lease->hwaddr;