Skip to content
openwrtPublic

About

This repository is a mirror of https://git.openwrt.org/?p=project/odhcpd.git. Pull requests will be accepted which will be merged in odhcpd.git

Resources

Stars

205 stars

Watchers

14 watching

Forks

Latest commit

 

History

953 Commits

Folders and files

Repository files navigation

odhcpd - Embedded DHCP/DHCPv6/RA Server & Relay

Abstract

odhcpd is a daemon for serving and relaying IP management protocols to configure clients and downstream routers. It tries to follow the RFC 6204 requirements for IPv6 home routers.

odhcpd provides server services for DHCP, RA, stateless and stateful DHCPv6, prefix delegation and can be used to relay RA, DHCPv6 and NDP between routed (non-bridged) interfaces in case no delegated prefixes are available.

Features

  1. Router Discovery support (solicitations and advertisements) with 2 modes:

    • server: RD server for slave interfaces

      • automatic detection of prefixes, delegated prefix and default routes, MTU
      • automatic reannouncement when changes to prefixes or routes occur
    • relay: RD relay between master and slave interfaces

      • support for rewriting announced DNS-server addresses in relay mode
  2. DHCPv6-support with 2 modes of operation

    • server: stateless, stateful and PD-server mode

      • stateless and stateful address assignment
      • prefix delegation support
      • dynamic reconfiguration in case prefixes change
      • hostname detection and hosts-files creation
      • registration of self-generated (e.g. SLAAC; RFC 9686) addresses
    • relay: mostly standards-compliant DHCPv6-relay

      • support for rewriting announced DNS-server addresses
  3. DHCPv4-support

    • server: stateless and stateful mode
  4. Proxy for Neighbor Discovery messages (solicitations and advertisements)

    • support for auto-learning routes to the local routing table
    • support for marking interfaces "external" not proxying NDP for them and only serving NDP for DAD and for traffic to the router itself [Warning: you should provide additional firewall rules for security]
  5. IPv6 PxE Support

Compiling

odhcpd uses cmake:

  • To prepare a Makefile use: cmake .
  • To build / install use: make / make install afterwards.
  • To build DEB or RPM packages use: make package afterwards.

Configuration

odhcpd uses a UCI configuration file in /etc/config/dhcp for configuration and may also receive information from ubus

Section of type odhcpd

Option Type Default Description
maindhcp bool 0 Use odhcpd as the main DHCPv4 service
hostsdir string DHCPv4/v6 hostfile directory (one file per interface will be created, see also hostsdir in sections of type dhcp)
leasedir string Directory for the DHCPv4/v6 lease files (one file per interface; their contents are internal to odhcpd and may change)
loglevel integer 4 Syslog level priority (0-7)
piodir string Directory to store IPv6 prefix information (to detect stale prefixes, see RFC9096, §3.5)

Sections of type dhcp (configure DHCP / DHCPv6 / RA / NDP service)

Option Type Default Description
interface string <name of UCI section> logical OpenWrt interface
ifname string <resolved from logical> network device
networkid string same as ifname compat. alias for ifname
master bool 0 is a master interface for relaying
ra string disabled Router Advert service [disabled|server|relay|hybrid]
dhcpv6 string disabled DHCPv6 service [disabled|server|relay|hybrid]
dhcpv4 string disabled DHCPv4 service [disabled|server]
ndp string disabled Neighbor Discovery Proxy [disabled|relay|hybrid]
dynamicdhcp bool 1 Dynamically create leases for DHCPv4 and DHCPv6
dhcpv6_assignall bool 1 Assign all viable DHCPv6 addresses in statefull mode; if disabled only the DHCPv6 address having the longest preferred lifetime is assigned
dhcpv6_hostidlength integer 12 Host ID length of dynamically created leases, allowed values: 12 - 64 (bits).
dhcpv6_na bool 1 DHCPv6 stateful addressing hands out IA_NA - Internet Address - Network Address
dhcpv6_pd bool 1 DHCPv6 stateful addressing hands out IA_PD - Internet Address - Prefix Delegation (PD)
dhcpv6_pd_preferred bool 0 Set the DHCPv6-PD Preferred (P) flag in outgoing ICMPv6 RA message PIOs (RFC9762); requires dhcpv6 and dhcpv6_pd.
dhcpv6_pd_min_len integer 62 Minimum prefix length to delegate with IA_PD (adjusted, if necessary, to be longer than the interface prefix length). Range [1,64]
dhcpv6_relay_servers list - IPv6 addresses of DHCPv6 servers to relay the DHCPv6 Messages to
router list <local address> IPv4 addresses of routers on a given subnet (provided via DHCPv4, should be in order of preference)
dns list <local address> DNS servers to announce, accepts IPv4 and IPv6
dnr list disabled Encrypted DNS servers to announce, <priority> <domain name> [<comma separated IP addresses> <SvcParams (key=value)>...]
dns_service bool 1 Announce the address of interface as DNS service if the list of dns is empty
domain list <local search domain> Search domains to announce
leasetime string 12h DHCPv4 address leasetime
start integer auto First pool address, as an offset from the network address. Default: 100 (less on /25 to /28)
limit integer auto Number of addresses in the pool, cut off at the end of the subnet. Default: 150 (less on /25 to /28 if start isn't set)
max_preferred_lifetime string 45m Upper limit for the preferred lifetime for a prefix
max_valid_lifetime string 90m Upper limit for the valid lifetime for a prefix
ra_default integer 0 Override default route - 0: default, 1: ignore no public address, 2: ignore all
ra_flags list other-config List of RA flags to be advertised in RA messages [managed-config|other-config|home-agent|none]
ra_slaac bool 1 Advertise that prefixes (which are <= 64 bits long) on this interface can be used for SLAAC (the "A" flag in the PIO, RFC4861, §4.6.2)
ra_advrouter bool 0 Advertise the IPv6 address of this router in RA messages (the "R" flag in the PIO, RFC6275, §7.2)
ra_offlink bool 0 Announce prefixes off-link
ra_preference string medium Route(r) preference [medium|high|low]
ra_maxinterval integer 600 Maximum time allowed between sending unsolicited RA
ra_mininterval integer 200 Minimum time allowed between sending unsolicited RA
ra_lifetime integer 2700 Value to be placed in Router Lifetime field of RA (0: not a default router, otherwise ra_maxinterval-65535). Not recommended to be more than 2700 (RFC9096); some old hosts might not accept more than 9000 (RFC8319)
ra_reachabletime integer 0 Reachable Time in milliseconds to be advertised in RA messages
ra_retranstime integer 0 Retransmit Time in milliseconds to be advertised in RA messages
ra_hoplimit integer 0 Current hoplimit to be advertised in RA messages
ra_mtu integer - MTU to be advertised in RA messages
ra_dns bool 1 Announce DNS configuration in RA messages (RFC8106)
ra_pref64 string - Announce PREF64 option for NAT64 prefix (RFC8781) [IPv6 prefix]
ndproxy_routing bool 1 Learn routes from NDP
ndproxy_slave bool 0 NDProxy external slave
ndp_from_link_local bool 1 Use link-local source addresses for NDP operations (RFC 4861, §4.2 compliance) and macOS compatibility
prefix_filter string ::/0 Only advertise on-link prefixes within the provided IPv6 prefix; others are filtered out. [IPv6 prefix]
ntp list <local address> NTP servers to announce accepts IPv4 and IPv6
upstream list - A list of interfaces which can be used as a source of configuration information (e.g. for NTP servers, if not set explicitly).
captive_portal_uri string no The API URI to be sent in RFC8910 captive portal options, via DHCPv4, DHCPv6, and ICMPv6 RA.
ipv6_only_preferred integer 0 Indicate that IPv6-only mode is preferred (RFC8925) [V6ONLY_WAIT time in seconds]
hostsdir string <hostsdir of the odhcpd section> Directory for this interface's hostfile (odhcpd.hosts.<interface>), e.g. to give it to a separate DNS server instance

Sections of type host (static leases)

Option Type Default Description
interface list (none) Logical OpenWrt interface(s) this static lease applies to; all interfaces if not set
ip string (none) IPv4 host address or ignore to ignore any DHCPv4 request from this host
mac list (none) Hexadecimal MAC address(es)
duid list (none) Hexadecimal DUID(s), or DUID%IAID(s)
hostid string (none) IPv6 tokenised IID or ignore to ignore any DHCPv6 request from this host
name string (none) Hostname
leasetime string (none) DHCPv4/v6 lease time

A host can have several sections with the same mac/duid, e.g. one per VLAN with a different ip on each. If you do that, give each of them an interface list.

Sections of type boot6

Option Type Required Description
url string yes e.g. tftp://[fd11::1]/pxe.efi
arch integer no the arch code. 07 is EFI. If not present, this boot6 will be the default.

odhcpd also uses the UCI configuration file /etc/config/network for configuration of the following options:

Section of type globals

Option Type Required Description
dhcp_default_duid string no The DUID to use to identify the DHCPv6 server to clients.

System variables for Timezone options (uci system.system)

Option Type Required Description
timezone string no e.g. EST5EDT4,M3.2.0/02:00,M11.1.0/02:00
zonename string no e.g. Europe/Zurich

ubus Interface

odhcpd currently exposes the following methods under the dhcp object path:

Method Arguments Description
ipv4leases none Lists all currently active DHCPv4 leases per interface
ipv6leases none Lists all currently active DHCPv6 leases per interface
ipv6ra none Lists announced IPv6 prefixes per interface
add_lease options as in the cfg host section Creates a new static lease, the arguments need to be formatted as a valid JSON string

These can be called by running e.g. ubus call dhcp ipv6leases on your OpenWrt device.

The replies of ipv4leases, ipv6leases and ipv6ra contain an interface table with an entry per logical interface (e.g. lan), which has the interface's device (e.g. br-lan) and its leases (or, for ipv6ra, prefixes).

odhcpd sends the following notifications to the subscribers of the dhcp object:

Name Parameters Description
dhcp.lease4 interface,device,ipv4,mac,hostname,duid,iaid A DHCPv4 lease has been assigned, renewed or changed (e.g. its hostname)
dhcp.release4 interface,device,ipv4,mac,hostname,duid,iaid A DHCPv4 lease has been released or declined by a client
dhcp.expire4 interface,device,ipv4,mac,hostname,duid,iaid A DHCPv4 lease has expired or has been removed
dhcp.lease6 interface,device,duid,hostname,ias,updated DHCPv6 leases of a client have been assigned, renewed or changed (e.g. their hostname)
dhcp.release6 interface,device,duid,hostname,ias,released DHCPv6 leases of a client have been released or declined by the client
dhcp.expire6 interface,device,duid,hostname,ias,expired DHCPv6 leases of a client have expired or have been removed

interface is the logical interface name (e.g. lan) and device the name of the network device (e.g. br-lan). hostname is only included if known, duid and iaid of DHCPv4 leases only if the client used a DUID-based client identifier.

The DHCPv6 notifications are sent once per client (duid) and interface, e.g. once per handled message. ias lists all current leases (IA_NA/IA_PD) of the client on that interface (empty if it has none left), updated, released or expired the leases the notification is about. Each lease is a table with iaid and ipv6-addr (IA_NA) or ipv6-prefix (IA_PD), the list of the addresses/prefixes (address, and prefix-length for prefixes) last sent to the client. Leases which are removed before they expire (e.g. because a static lease has been changed) are announced via dhcp.expire6 as well.

{ "dhcp.lease6": { "interface": "lan", "device": "br-lan",
                   "duid": "00030001020000000042", "hostname": "foo",
                   "ias": [ { "iaid": 1, "ipv6-addr": [ { "address": "fd00::abc" } ] },
                            { "iaid": 1, "ipv6-prefix": [ { "address": "fd00:0:0:10::",
                                                            "prefix-length": 62 } ] } ],
                   "updated": [ { "iaid": 1, "ipv6-prefix": [ { "address": "fd00:0:0:10::",
                                                                "prefix-length": 62 } ] } ] } }

These can be observed by running e.g. ubus subscribe dhcp on your OpenWrt device.

Whenever the hostnames/addresses of the leases change (i.e. when the hosts files are rewritten), odhcpd also sends a dhcp.hosts.update event without parameters. It is sent as a regular ubus event (observable with ubus listen dhcp.hosts.update) and also submitted to procd (via service event), so it can be used as a procd service trigger, e.g.:

procd_add_raw_trigger "dhcp.hosts.update" 1000 /etc/init.d/foo reload

About

This repository is a mirror of https://git.openwrt.org/?p=project/odhcpd.git. Pull requests will be accepted which will be merged in odhcpd.git

Resources

Stars

205 stars

Watchers

14 watching

Forks

Releases

Packages

Used by

Contributors

Languages