Odhcpd and odhcp6c

Hello everyone, I am still new to openwrt routers. And currently, I am trying to map the whole process of dhcpv6. Now, I have several questions,

the first one is the connection between odhcp6c and odhcpd, how does the 2 connect if the mode of addressing is DHCPv6 with ia_na and ia_pd enabled in the dhcpv6 server? How does the prefix delegation works?

The 2nd one is, how does the /lib/netifd/proto/dhcpv6.sh and /lib/netifd/dhcpv6.script being started? Because I don't see any init.d scripts for odhcp6c.

The 3rd one is, is it possible in openwrt router to receive only stateful address from the upstream? Because even though I allow the '-D' option in odhcp6c, there are always 2 ipv6 addresses, one is from IA_NA, and one is configured using the prefix from the RA server.

Thank you in advance for response.

Here's the best of my sleuthing:

It looks like the netifd process does the equivalent of uci get network.wan6.proto to figure out how to handle the upstream IPv6 connection. It then looks in its table of handlers (ubus call network get_proto_handlers) and determines how ppp or dhcpv6 or static or whatever is to be dealt with. If the handler is in the proto directory, /lib/netifd/proto/, it fires that off and in your case that's how odhcp6c is started. If you had a ppp connection, then pppd would appear instead of odhcp6c when you look in ps www | grep netifd.

I think the proto handler registration happens in proto.c here https://git.openwrt.org/?p=project/netifd.git;a=tree

Regarding how odhcpd and odhcp6c interact, well, they don't even know that the other exists, so it's through ubus calls that the PD information is passed (do ubus call network.interface dump). This isolates the interfaces, so that you can have ppp or static or dhcpv6 upstream, and the downstream dhcp demon doesn't have to care where the data came from, it just looks there, if it sees a PD, then it can dole out prefixes to your clients.

But how is it that the router still gets 2 IPv6 addresses? One from SLAAC and one from stateful DHCPv6 address. Even though the router is already configured to receive only stateful address? Is it possible to get only 1 ipv6 address with stateful while the A-flag in DHCPv6 server is enabled?

I think there's a misunderstanding as to what the -D option does:

root@OpenWrt:~# odhcp6c
Usage: odhcp6c [options] <interface>

Feature options:
        -S <time>       Wait at least <time> sec for a DHCP-server (0)
        -D              Discard advertisements without any address or prefix proposed
        -N <mode>       Mode for requesting addresses [try|force|none]
        -P <length>     Request IPv6-Prefix (0 = auto)
        -F              Force IPv6-Prefix

-D doesn't mean "discard all advertisements", it means "discard advertisements without prefixes". If odhcp6c receives an advertisement with prefixes, it will use it to assign one or more SLAAC addresses to the <interface>.

And besides, who cares that some interface has 2 IPv6 addresses? IPv6 was designed specifically to allow this. My computer's NIC has 7 IPv6 addresses right now (DHCPv6, SLAAC with privacy extensions, link-local) and it works just fine, and all 7 can be used for sending and receiving packets.

Because I am trying to learn every possible way of configuring the dhcpv6 protocol in the router. I was trying to figure out if it can only receive the stateful address. Since I already know that SLAAC address will always be configured if the A-flag is enabled in the DHCPv6 server. Just want to gain some more knowledge with regards to IPv6.

I mean, what is/are the particular file that these 2 scripts being called? Since there is no init.d for the odhcp6c.

/etc/init.d/network runs netifd which then listens on ubus for ubus call network.interface.wan6 up which then looks at the network config and uses proto to launch /lib/netifd/<proto>.sh which, since proto in this case is dhcpv6 == /lib/netifd/dhcpv6.sh, runs odhcp6c.


1 Like

One more thing, what does this /usr/lib/lua/luci/model/network/proto_dhcpv6.lua registers /lib/netifd/proto/dhcpv6.sh work if the netifd is the one starting the daemon? According to this thread: How is odhcp6c daemon started Sorry, I am really confused right now.