2021-05-08 14:07:45 +08:00
From 53e1a09a06e11317bbde0e236837e5daa8d40593 Mon Sep 17 00:00:00 2001
From: liaichun <liaichun@huawei.com>
Date: Mon, 20 Apr 2020 16:06:51 +0800
Reference: NA
2023-02-02 20:08:26 +08:00
Conflict: NA
2019-12-25 15:44:46 +08:00
---
2022-03-22 11:42:25 +08:00
src/dnsmasq.c | 1 +
src/dnsmasq.h | 4 +++-
src/option.c | 3 +++
src/rfc3315.c | 35 ++++++++++++++++++++++++++++++++++-
4 files changed, 41 insertions(+), 2 deletions(-)
2019-12-25 15:44:46 +08:00
diff --git a/src/dnsmasq.c b/src/dnsmasq.c
2023-02-02 20:08:26 +08:00
index 9f326ed..70ea6fa 100644
2019-12-25 15:44:46 +08:00
--- a/src/dnsmasq.c
+++ b/src/dnsmasq.c
2023-02-02 20:08:26 +08:00
@@ -292,6 +292,7 @@ int main (int argc, char **argv)
2019-12-25 15:44:46 +08:00
{
daemon->doing_ra = option_bool(OPT_RA);
2022-03-22 11:42:25 +08:00
+ daemon->bind_mac_with_ip6 = option_bool(OPT_BIND_MAC_IP6);
2019-12-25 15:44:46 +08:00
for (context = daemon->dhcp6; context; context = context->next)
{
2021-05-08 14:07:45 +08:00
if (context->flags & CONTEXT_DHCP)
2019-12-25 15:44:46 +08:00
diff --git a/src/dnsmasq.h b/src/dnsmasq.h
2023-02-02 20:08:26 +08:00
index aaa6d62..c843238 100644
2019-12-25 15:44:46 +08:00
--- a/src/dnsmasq.h
+++ b/src/dnsmasq.h
2023-02-02 20:08:26 +08:00
@@ -281,7 +281,8 @@ struct event_desc {
#define OPT_STRIP_ECS 69
#define OPT_STRIP_MAC 70
#define OPT_NORR 71
-#define OPT_LAST 72
+#define OPT_BIND_MAC_IP6 72
+#define OPT_LAST 73
2019-12-25 15:44:46 +08:00
2020-07-28 16:39:08 +08:00
#define OPTION_BITS (sizeof(unsigned int)*8)
#define OPTION_SIZE ( (OPT_LAST/OPTION_BITS)+((OPT_LAST%OPTION_BITS)!=0) )
2023-02-02 20:08:26 +08:00
@@ -1179,6 +1180,7 @@ extern struct daemon {
2019-12-25 15:44:46 +08:00
int override;
int enable_pxe;
int doing_ra, doing_dhcp6;
+ int bind_mac_with_ip6;
struct dhcp_netid_list *dhcp_ignore, *dhcp_ignore_names, *dhcp_gen_names;
struct dhcp_netid_list *force_broadcast, *bootp_dynamic;
2023-02-02 20:08:26 +08:00
struct hostsfile *dhcp_hosts_file, *dhcp_opts_file;
2019-12-25 15:44:46 +08:00
diff --git a/src/option.c b/src/option.c
2023-02-02 20:08:26 +08:00
index 8e61a6b..9d4db5a 100644
2019-12-25 15:44:46 +08:00
--- a/src/option.c
+++ b/src/option.c
2023-02-02 20:08:26 +08:00
@@ -185,6 +185,7 @@ struct myoption {
#define LOPT_FAST_RETRY 376
#define LOPT_STALE_CACHE 377
#define LOPT_NORR 378
+#define LOPT_BIND_MAC_IP6 379
2019-12-25 15:44:46 +08:00
#ifdef HAVE_GETOPT_LONG
static const struct option opts[] =
2023-02-02 20:08:26 +08:00
@@ -374,6 +375,7 @@ static const struct myoption opts[] =
{ "port-limit", 1, 0, LOPT_RANDPORT_LIM },
{ "fast-dns-retry", 2, 0, LOPT_FAST_RETRY },
{ "use-stale-cache", 2, 0 , LOPT_STALE_CACHE },
2021-05-08 14:07:45 +08:00
+ { "bind-mac-with-ip6", 0, 0 , LOPT_BIND_MAC_IP6 },
2019-12-25 15:44:46 +08:00
{ NULL, 0, 0, 0 }
};
2023-02-02 20:08:26 +08:00
@@ -570,6 +572,7 @@ static struct {
2022-03-22 11:42:25 +08:00
{ LOPT_UMBRELLA, ARG_ONE, "[=<optspec>]", gettext_noop("Send Cisco Umbrella identifiers including remote IP."), NULL },
{ LOPT_QUIET_TFTP, OPT_QUIET_TFTP, NULL, gettext_noop("Do not log routine TFTP."), NULL },
2023-02-02 20:08:26 +08:00
{ LOPT_NORR, OPT_NORR, NULL, gettext_noop("Suppress round-robin ordering of DNS records."), NULL },
2019-12-25 15:44:46 +08:00
+ { LOPT_BIND_MAC_IP6, OPT_BIND_MAC_IP6, NULL, gettext_noop("Bind mac with ipv6 address. This is an experimental feature and it conflicts with rfc3315."), NULL },
{ 0, 0, NULL, NULL, NULL }
};
diff --git a/src/rfc3315.c b/src/rfc3315.c
2023-02-02 20:08:26 +08:00
index 8754481..f093a5c 100644
2019-12-25 15:44:46 +08:00
--- a/src/rfc3315.c
+++ b/src/rfc3315.c
2020-07-28 16:39:08 +08:00
@@ -49,6 +49,7 @@ static void end_ia(int t1cntr, unsigned int min_time, int do_fuzz);
2019-12-25 15:44:46 +08:00
static void mark_context_used(struct state *state, struct in6_addr *addr);
static void mark_config_used(struct dhcp_context *context, struct in6_addr *addr);
static int check_address(struct state *state, struct in6_addr *addr);
+static int check_and_try_preempte_address(struct state *state, struct in6_addr *addr, time_t now, struct dhcp_config *config);
2020-07-28 16:39:08 +08:00
static int config_valid(struct dhcp_config *config, struct dhcp_context *context, struct in6_addr *addr, struct state *state, time_t now);
static struct addrlist *config_implies(struct dhcp_config *config, struct dhcp_context *context, struct in6_addr *addr);
2019-12-25 15:44:46 +08:00
static void add_address(struct state *state, struct dhcp_context *context, unsigned int lease_time, void *ia_option,
2023-02-02 20:08:26 +08:00
@@ -704,7 +705,8 @@ static int dhcp6_no_relay(struct state *state, int msg_type, unsigned char *inbu
2020-07-28 16:39:08 +08:00
for (c = state->context; c; c = c->current)
2019-12-25 15:44:46 +08:00
if (!(c->flags & CONTEXT_CONF_USED) &&
match_netid(c->filter, solicit_tags, plain_range) &&
2020-07-28 16:39:08 +08:00
- config_valid(config, c, &addr, state, now))
+ config_valid(config, c, &addr, state, now) &&
2022-03-22 11:42:25 +08:00
+ check_and_try_preempte_address(state, &addr, now, config))
2019-12-25 15:44:46 +08:00
{
mark_config_used(state->context, &addr);
if (have_config(config, CONFIG_TIME))
2023-02-02 20:08:26 +08:00
@@ -1289,6 +1291,37 @@ static int dhcp6_no_relay(struct state *state, int msg_type, unsigned char *inbu
2021-05-08 14:07:45 +08:00
2019-12-25 15:44:46 +08:00
}
2021-05-08 14:07:45 +08:00
+static int check_and_try_preempte_address(struct state *state, struct in6_addr *addr, time_t now, struct dhcp_config *config)
+{
2019-12-25 15:44:46 +08:00
+ struct dhcp_lease *lease;
+
+ if (!(lease = lease6_find_by_addr(addr, 128, 0)))
+ {
+ return 1;
+ }
+
2021-05-08 14:07:45 +08:00
+
+ if(daemon->bind_mac_with_ip6) {
2019-12-25 15:44:46 +08:00
+ // break rfc3315 here
+ // bind mac address with a lease
+ if ((state->mac) && !(config->flags & CONFIG_CLID) &&
+ config_has_mac(config, state->mac, state->mac_len, state->mac_type)) {
+ lease_prune(lease, now);
+ return 1;
+ }
+ }
+
+ // what rfc3315 do
+ if (lease->clid_len != state->clid_len ||
+ memcmp(lease->clid, state->clid, state->clid_len) != 0 ||
+ lease->iaid != state->iaid)
2021-05-08 14:07:45 +08:00
+ {
+ return 0;
+ }
2019-12-25 15:44:46 +08:00
+
+ return 1;
+}
2021-05-08 14:07:45 +08:00
+
static struct dhcp_netid *add_options(struct state *state, int do_refresh)
{
void *oro;
2019-12-25 15:44:46 +08:00
--
2021-05-08 14:07:45 +08:00
2.23.0
2022-03-22 11:42:25 +08:00