[Dnsmasq-discuss] Why dhcp6 still returns DHCPADVERSISE after allocate lease failed?

胡义臻 huyizhen2024 at 163.com
Thu Dec 19 08:28:02 UTC 2024


Dear all, I start dnsmasq(version 2.86) with --dhcp-lease-max=1, only one DHCP lease can be allocated. I find that the behavior of IPv4 and IPv6 is inconsistent. IPv4 returns a DHCPNAK packet with log  "no leases left". Although IPv6 does not allocate a lease in function lease_allocate, it still returns a DHCPADVERSISE packet and allocates an IPv6 address.

Is IPv6 behavior normal? According to my understanding, if lease_allocate returns NULL, then the IPv6 address should not be allocated and the DHCPADVERTISE message should not be returned.

Looking forward to your reply, thank you!



cmd:

dnsmasq --dhcp-range=set:subnet,46:41::1:1,46:41::ffff:1,infinite --dhcp-lease-max=1

 

gdb trace:

Breakpoint 1, lease6_allocate (addrp=addrp at entry=0x7fff0ecc0090, lease_type=32) at lease.c:804

804 struct dhcp_lease *lease = lease_allocate();

(gdb) s

lease_allocate () at lease.c:770

770 if (!leases_left || !(lease = whine_malloc(sizeof(struct dhcp_lease))))

(gdb) p leases_left

$2 = 0

(gdb) n

lease6_allocate (addrp=addrp at entry=0x7fff0ecc0090, lease_type=32) at lease.c:806

806 if (lease)

(gdb)

815 return lease;

(gdb) p lease

$3 = (struct dhcp_lease *) 0x0

(gdb) n

update_leases (now=1734576779, lease_time=7500, addr=0x7fff0ecc0090, context=0x564b4c6cbaf0, state=0x7fff0ecc0100) at rfc3315.c:1929

1929 if (lease)

(gdb) n

1723 if ((lease = lease6_find_by_addr(addr, 128, 0)))

(gdb)

1727 if (context->netid.next == &context->netid && context->netid.net)

(gdb) p lease

$4 = (struct dhcp_lease *) 0x0

(gdb) n

1729 context->netid.next = state->context_tags;

(gdb)

1730 state->context_tags = &context->netid;

(gdb)

1732 if (!state->hostname_auth)

(gdb)

1736 for (id_list = daemon->dhcp_ignore_names; id_list; id_list = id_list->next)

(gdb)

1744 log6_quiet(state, state->lease_allocate ? "DHCPREPLY" : "DHCPADVERTISE", addr, state->hostname);

(gdb)

dhcp6_no_relay (state=state at entry=0x7fff0ecc0100, msg_type=<optimized out>, inbuff=<optimized out>, sz=sz at entry=102, is_unicast=<optimized out>, now=now at entry=1734576779) at rfc3315.c:886

886 get_context_tag(state, dynamic);

(gdb)

887 address_assigned = 1;

(gdb)

844 for (; ia_option; ia_option = opt6_find(opt6_next(ia_option, ia_end), ia_end, OPTION6_IAADDR, 24))

(gdb)

900 end_ia(t1cntr, min_time, 0);

(gdb)

901 end_opt6(o);

(gdb)

825 for (opt = state->packet_options; opt; opt = opt6_next(opt, state->end))

(gdb)

904 if (address_assigned)

(gdb)

906 o1 = new_opt6(OPTION6_STATUS_CODE);

(gdb)

907 put_opt6_short(DHCP6SUCCESS);

(gdb)

908 put_opt6_string(_("success"));

(gdb)

909 end_opt6(o1);

(gdb)

1056 tagif = add_options(state, 0);

(gdb)

1057 break;

(gdb)

1311 log_tags(tagif, state->xid);

(gdb)

1317 ((unsigned char *)(daemon->outpacket.iov_base))[start_msg] = outmsgtype;

(gdb)

1319 log6_opts(0, state->xid, daemon->outpacket.iov_base + start_opts, daemon->outpacket.iov_base + save_counter(-1));

(gdb)

1321 return 1;

(gdb)

dhcp6_reply (context=0x564b4c6cbaf0, interface=interface at entry=132, iface_name=iface_name at entry=0x7fff0ecc02e0 "veth0", fallback=fallback at entry=0x7fff0ecc0320, ll_addr=ll_addr at entry=0x7fff0ecc0340, ula_addr=ula_addr at entry=0x7fff0ecc0350, sz=102, client_addr=0x7fff0ecc0298, now=1734576779) at rfc3315.c:102

102 return msg_type == DHCP6RELAYFORW ? DHCPV6_SERVER_PORT : DHCPV6_CLIENT_PORT;

(gdb)

dhcp6_packet (now=1734576779) at dhcp6.c:270

270 if (port != 0)

(gdb)

272 from.sin6_port = htons(port);

(gdb)

273 while (retry_send(sendto(daemon->dhcp6fd, daemon->outpacket.iov_base,

(gdb)

280 lease_update_file(now);

(gdb)

281 lease_update_dns(0);

(gdb)

 

tcpdump:

[root at localhost.localdomain /]$ip netns exec ns0 tcpdump -i veth0 -vvv port 546 or port 547

dropped privs to tcpdump

tcpdump: listening on veth0, link-type EN10MB (Ethernet), snapshot length 262144 bytes

15:55:18.192825 IP6 (flowlabel 0xffe1d, hlim 1, next-header UDP (17) payload length: 92) fe80::f03a:70ff:feb0:6dfe.dhcpv6-client > ff02::1:2.dhcpv6-server: [bad udp cksum 0xcbdd -> 0x890a!] dhcp6 solicit (xid=3e98e (client-ID type 4) (option-request DNS-server DNS-search-list) (elapsed-time 0) (IA_NA IAID:1890610686 T1:3600 T2:5400 (IA_ADDR 46:41::165a:c84d pltime:7200 vltime:10800)))

15:55:18.194264 IP6 (class 0xc0, flowlabel 0x91e38, hlim 64, next-header UDP (17) payload length: 134) localhost.localdomain.dhcpv6-server > fe80::f03a:70ff:feb0:6dfe.dhcpv6-client: [bad udp cksum 0x1a8f -> 0xb1bb!] dhcp6 advertise (xid=3e98e (client-ID type 4) (server-ID hwaddr/time type 1 time 787889844 e6ad77d9f384) (IA_NA IAID:1890610686 T1:3600 T2:6300 (IA_ADDR 46:41::165a:c84d pltime:7200 vltime:10800)) (status-code Success) (preference 0) (DNS-server localhost.localdomain))

15:55:19.224489 IP6 (flowlabel 0xffe1d, hlim 1, next-header UDP (17) payload length: 110) fe80::f03a:70ff:feb0:6dfe.dhcpv6-client > ff02::1:2.dhcpv6-server: [bad udp cksum 0xcbef -> 0x6fae!] dhcp6 request (xid=584d8d (client-ID type 4) (server-ID hwaddr/time type 1 time 787889844 e6ad77d9f384) (option-request DNS-server DNS-search-list) (elapsed-time 0) (IA_NA IAID:1890610686 T1:3600 T2:5400 (IA_ADDR 46:41::165a:c84d pltime:7200 vltime:7500)))

15:55:19.224885 IP6 (class 0xc0, flowlabel 0x91e38, hlim 64, next-header UDP (17) payload length: 129) localhost.localdomain.dhcpv6-server > fe80::f03a:70ff:feb0:6dfe.dhcpv6-client: [bad udp cksum 0x1a8a -> 0x6350!] dhcp6 reply (xid=584d8d (client-ID type 4) (server-ID hwaddr/time type 1 time 787889844 e6ad77d9f384) (IA_NA IAID:1890610686 T1:3600 T2:6300 (IA_ADDR 46:41::165a:c84d pltime:7200 vltime:7500)) (status-code Success) (DNS-server localhost.localdomain))


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.thekelleys.org.uk/pipermail/dnsmasq-discuss/attachments/20241219/2155e09a/attachment-0001.htm>


More information about the Dnsmasq-discuss mailing list