From 456a3197757c5e21f57a44192a0dab163b69b6fd Mon Sep 17 00:00:00 2001 From: Dominik DL6ER Date: Sun, 20 Oct 2019 18:51:52 +0200 Subject: [PATCH] DHCPv6 IAID should be of unsigned type. It is derived from strtoul() in lease.c:read_leases() and already now interpreted as unsigned in helper.c:276 and outpacket.c:put_opt6_long(). RFC3315 (section 22.4) shows that the IAID is 4 bytes long so we do not need to go up to unsigned long. Signed-off-by: Dominik DL6ER --- src/dhcp6.c | 2 +- src/dnsmasq.h | 11 ++++++----- src/helper.c | 3 ++- src/lease.c | 9 ++++++--- src/rfc3315.c | 4 ++-- 5 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/dhcp6.c b/src/dhcp6.c index 5badc46..ce682db 100644 --- a/src/dhcp6.c +++ b/src/dhcp6.c @@ -423,7 +423,7 @@ struct dhcp_config *config_find_by_address6(struct dhcp_config *configs, struct } struct dhcp_context *address6_allocate(struct dhcp_context *context, unsigned char *clid, int clid_len, int temp_addr, - int iaid, int serial, struct dhcp_netid *netids, int plain_range, struct in6_addr *ans) + unsigned int iaid, int serial, struct dhcp_netid *netids, int plain_range, struct in6_addr *ans) { /* Find a free address: exclude anything in use and anything allocated to a particular hwaddr/clientid/hostname in our configuration. diff --git a/src/dnsmasq.h b/src/dnsmasq.h index e78afd3..b7c9490 100644 --- a/src/dnsmasq.h +++ b/src/dnsmasq.h @@ -723,7 +723,7 @@ struct dhcp_lease { int new_prefixlen; /* and its prefix length */ #ifdef HAVE_DHCP6 struct in6_addr addr6; - int iaid; + unsigned int iaid; struct slaac_address { struct in6_addr addr; time_t ping_time; @@ -1395,14 +1395,15 @@ struct dhcp_lease *lease4_allocate(struct in_addr addr); #ifdef HAVE_DHCP6 struct dhcp_lease *lease6_allocate(struct in6_addr *addrp, int lease_type); struct dhcp_lease *lease6_find(unsigned char *clid, int clid_len, - int lease_type, int iaid, struct in6_addr *addr); + int lease_type, unsigned int iaid, struct in6_addr *addr); void lease6_reset(void); -struct dhcp_lease *lease6_find_by_client(struct dhcp_lease *first, int lease_type, unsigned char *clid, int clid_len, int iaid); +struct dhcp_lease *lease6_find_by_client(struct dhcp_lease *first, int lease_type, + unsigned char *clid, int clid_len, unsigned int iaid); struct dhcp_lease *lease6_find_by_addr(struct in6_addr *net, int prefix, u64 addr); u64 lease_find_max_addr6(struct dhcp_context *context); void lease_ping_reply(struct in6_addr *sender, unsigned char *packet, char *interface); void lease_update_slaac(time_t now); -void lease_set_iaid(struct dhcp_lease *lease, int iaid); +void lease_set_iaid(struct dhcp_lease *lease, unsigned int iaid); void lease_make_duid(time_t now); #endif void lease_set_hwaddr(struct dhcp_lease *lease, const unsigned char *hwaddr, @@ -1520,7 +1521,7 @@ int get_incoming_mark(union mysockaddr *peer_addr, union all_addr *local_addr, void dhcp6_init(void); void dhcp6_packet(time_t now); struct dhcp_context *address6_allocate(struct dhcp_context *context, unsigned char *clid, int clid_len, int temp_addr, - int iaid, int serial, struct dhcp_netid *netids, int plain_range, struct in6_addr *ans); + unsigned int iaid, int serial, struct dhcp_netid *netids, int plain_range, struct in6_addr *ans); int config_valid(struct dhcp_config *config, struct dhcp_context *context, struct in6_addr *addr); struct dhcp_context *address6_available(struct dhcp_context *context, struct in6_addr *taddr, diff --git a/src/helper.c b/src/helper.c index c392eec..62ac9cf 100644 --- a/src/helper.c +++ b/src/helper.c @@ -66,7 +66,8 @@ struct script_data #endif struct in6_addr addr6; #ifdef HAVE_DHCP6 - int iaid, vendorclass_count; + int vendorclass_count; + unsigned int iaid; #endif unsigned char hwaddr[DHCP_CHADDR_MAX]; char interface[IF_NAMESIZE]; diff --git a/src/lease.c b/src/lease.c index f14d128..081d90e 100644 --- a/src/lease.c +++ b/src/lease.c @@ -635,7 +635,8 @@ struct dhcp_lease *lease_find_by_addr(struct in_addr addr) #ifdef HAVE_DHCP6 /* find address for {CLID, IAID, address} */ struct dhcp_lease *lease6_find(unsigned char *clid, int clid_len, - int lease_type, int iaid, struct in6_addr *addr) + int lease_type, unsigned int iaid, + struct in6_addr *addr) { struct dhcp_lease *lease; @@ -667,7 +668,9 @@ void lease6_reset(void) } /* enumerate all leases belonging to {CLID, IAID} */ -struct dhcp_lease *lease6_find_by_client(struct dhcp_lease *first, int lease_type, unsigned char *clid, int clid_len, int iaid) +struct dhcp_lease *lease6_find_by_client(struct dhcp_lease *first, int lease_type, + unsigned char *clid, int clid_len, + unsigned int iaid) { struct dhcp_lease *lease; @@ -849,7 +852,7 @@ void lease_set_expires(struct dhcp_lease *lease, unsigned int len, time_t now) } #ifdef HAVE_DHCP6 -void lease_set_iaid(struct dhcp_lease *lease, int iaid) +void lease_set_iaid(struct dhcp_lease *lease, unsigned int iaid) { if (lease->iaid != iaid) { diff --git a/src/rfc3315.c b/src/rfc3315.c index 44a09bb..6d8df35 100644 --- a/src/rfc3315.c +++ b/src/rfc3315.c @@ -21,11 +21,11 @@ struct state { unsigned char *clid; - int clid_len, iaid, ia_type, interface, hostname_auth, lease_allocate; + int clid_len, ia_type, interface, hostname_auth, lease_allocate; char *client_hostname, *hostname, *domain, *send_domain; struct dhcp_context *context; struct in6_addr *link_address, *fallback, *ll_addr, *ula_addr; - unsigned int xid, fqdn_flags; + unsigned int xid, fqdn_flags, iaid; char *iface_name; void *packet_options, *end; struct dhcp_netid *tags, *context_tags;