project/odhcpd.git
5 months agoconfig: set RFC defaults for preferred lifetime master
Paul Donald [Tue, 9 Apr 2024 03:04:10 +0000 (05:04 +0200)]
config: set RFC defaults for preferred lifetime

Update preferred lifetime default value in accordance with RFC4861.

Signed-off-by: Paul Donald <newtwen@gmail.com>
[ fix comment style ]
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
5 months agorouter: disambiguate and clarify 'no route' messages
Paul Donald [Tue, 9 Apr 2024 03:04:09 +0000 (05:04 +0200)]
router: disambiguate and clarify 'no route' messages

Better describe "no route" messages.

Signed-off-by: Paul Donald <newtwen@gmail.com>
[ improve commit title ]
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
5 months agorouter: rename minvalid to lowest_found_lifetime
Paul Donald [Tue, 9 Apr 2024 03:04:08 +0000 (05:04 +0200)]
router: rename minvalid to lowest_found_lifetime

The variable is used across all prefix lifetimes, serving as a low-tide
mark. It stores the lowest lifetime among all prefixes.

Signed-off-by: Paul Donald <newtwen@gmail.com>
[ fix comment format ]
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
5 months agotreewide: normalize spaces to tabs
Paul Donald [Tue, 9 Apr 2024 03:04:07 +0000 (05:04 +0200)]
treewide: normalize spaces to tabs

Normalize space to tabs.

Signed-off-by: Paul Donald <newtwen@gmail.com>
[ improve commit title and description ]
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
5 months agotreewide: spell-fixes and new comments for extra clarification
Paul Donald [Tue, 9 Apr 2024 03:04:06 +0000 (05:04 +0200)]
treewide: spell-fixes and new comments for extra clarification

Fix some spell mistake and add new comments for extra clatification.

Signed-off-by: Paul Donald <newtwen@gmail.com>
Reviewed-by: Daniel Golle <daniel@makrotopia.org>
[ improve commit title ]
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
5 months agorouter: limit prefix preferred_lt to valid_lt in accordance with RFC4861
Paul Donald [Tue, 9 Apr 2024 03:04:05 +0000 (05:04 +0200)]
router: limit prefix preferred_lt to valid_lt in accordance with RFC4861

Follow-up fix for bc9d317f2921 ("dhcpv6-ia: fix invalid preferred
lifetime").

https://www.rfc-editor.org/rfc/rfc4861#page-44

Fixes: bc9d317f2921 ("dhcpv6-ia: fix invalid preferred lifetime")
Signed-off-by: Paul Donald <newtwen@gmail.com>
Reviewed-by: Daniel Golle <daniel@makrotopia.org>
[ fix comment format and improve commit title ]
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
5 months agorouter: inherit user-assigned preferred_lifetime
Paul Donald [Tue, 9 Apr 2024 03:04:04 +0000 (05:04 +0200)]
router: inherit user-assigned preferred_lifetime

Inherit preferred_lifetime value irrespective of whether ra_useleasetime
is set or not.

User-provided values for preferred_lifetime are now assigned, instead of
ignored.

Before:
==
ICMPv6 Option (Prefix information : fd51:1c2a:8909::/64)
    Type: Prefix information (3)
    Length: 4 (32 bytes)
    Prefix Length: 64
    Flag: 0xc0, On-link flag(L), Autonomous address-configuration flag(A)
    Valid Lifetime: Infinity (4294967295)
    Preferred Lifetime: Infinity (4294967295)
    Reserved
    Prefix: fd51:1c2a:8909::
==

After (preferred_lifetime set to 7 minutes):
==
ICMPv6 Option (Prefix information : fd51:1c2a:8909::/64)
    Type: Prefix information (3)
    Length: 4 (32 bytes)
    Prefix Length: 64
    Flag: 0xc0, On-link flag(L), Autonomous address-configuration flag(A)
    Valid Lifetime: Infinity (4294967295)
    Preferred Lifetime: 420
    Reserved
    Prefix: fd51:1c2a:8909::
==

Signed-off-by: Paul Donald <newtwen@gmail.com>
Reviewed-by: Daniel Golle <daniel@makrotopia.org>
[ fix comment format and improve commit description ]
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
5 months agotreewide: refactor valid to valid_lt (lifetime)
Paul Donald [Tue, 9 Apr 2024 03:04:03 +0000 (05:04 +0200)]
treewide: refactor valid to valid_lt (lifetime)

Refactor "valid" (valid what?) to "valid_lt".

Signed-off-by: Paul Donald <newtwen@gmail.com>
Reviewed-by: Daniel Golle <daniel@makrotopia.org>
[ improve commit title ]
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
5 months agotreewide: refactor pref(erred) to preferred_lt (lifetime)
Paul Donald [Tue, 9 Apr 2024 03:04:02 +0000 (05:04 +0200)]
treewide: refactor pref(erred) to preferred_lt (lifetime)

Refactor "preferred" (preferred what?) and "pref" (obscure) to
"preferred_lt".

It is now more difficult to conflate prefix, preference and other "pref"
related terminology with preferred_lifetime.

Signed-off-by: Paul Donald <newtwen@gmail.com>
Reviewed-by: Daniel Golle <daniel@makrotopia.org>
[ improve commit title ]
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
12 months agoconfig: make sure timer is not on the timeouts list before freeing
Colin Whittaker [Sat, 24 Jun 2023 20:33:12 +0000 (13:33 -0700)]
config: make sure timer is not on the timeouts list before freeing

Signed-off-by: Colin Whittaker <colin.whittaker@adtran.com>
Signed-off-by: Chad Monroe <chad@monroe.io>
12 months agoadd hostsfile output in addition to statefile
Kevin Darbyshire-Bryant [Sat, 21 Oct 2023 18:50:25 +0000 (19:50 +0100)]
add hostsfile output in addition to statefile

a92c0a7 made the temporary state/leasefile hidden so that an atomic
change was made and dnsmasq only saw the new file on rename.  A
misguided optimisation was made to only rename the temporary file if
something had changed.  Unfortunately only address and hostnames were
considered in the change, lease durations were not.

As a result it was possible for LUCI which consumes the state/leasefile
to report DHCPv6 leases had expired when they had not.

Revert the optimisation so that the file rename occurs irrespective of
content change, this keeps LUCI reporting of state/lease expiry correct.

This leaves us back with hosts file/dnsmasq update problem. Solve this
by writing out a separate hosts file.  Update this file using the
original IP/Hostname change logic that prompts calling the 'lease'
script.

odhcpd config now supports a string 'hostsfile' which defines the path
and name of the hosts file in an identical manner to 'leasefile'.  A
state 'leasefile' must be defined IF a 'hostsfile' is also required.

eg.

leasefile '/tmp/odhcpdstate'
hostsfile '/tmp/hosts/odhcpdhosts'

Signed-off-by: Kevin Darbyshire-Bryant <ldir@darbyshire-bryant.me.uk>
16 months agodhcpv4: improve error when a prefix is too long
Ross Vandegrift [Mon, 16 Jan 2023 21:35:46 +0000 (13:35 -0800)]
dhcpv4: improve error when a prefix is too long

If a user tries to enable dhcpv4 on an interface with a /29, odhcp won't work.
The logs will only contain a message that doesn't help identify the problem.
It'd be idea to support any prefix with a valid pool, but at least this would
point a confused user in the right direction.

Signed-off-by: Ross Vandegrift <ross@kallisti.us>
16 months agoodhcpd: add support for dhcpv6_pd_min_len parameter
John Kohl [Sat, 24 Jun 2023 14:18:03 +0000 (10:18 -0400)]
odhcpd: add support for dhcpv6_pd_min_len parameter

The dhcpv6_pd_min_len configuration clamps the requested prefix
delegation to be at least as big as the option.  This allows a
router to manage the size of each downstream router's prefix
delegation length independently from the delegating interface's
prefix length.

This behavior is an implementation choice permitted by the RFCs.
The delegating router (us) is not required to honor the hint
(RFC3633, section 11.2, we MAY choose to use the information in the
option; RFC8168, section 3.2 has several SHOULDs about desired
choices for selecting a prefix to delegate).

This configuration allows us to conserve prefix space so that any
single router can't grab too much of it.  Consider if we have an
interface with a /56 prefix.  A requesting router could ask for a
/58 and take 1/4 of our total address space.  But if we set a
minimum of /60, we can limit each requesting router to get only 1/16
of our total address space.

sample config:

config dhcp 'pd'
    ...
    option dhcpv6_pd_min_len '60'

Signed-off-by: John Kohl <jtk.git@bostonpog.org>
[ use different comment style and fix commit description ]
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
16 months agorouter: Add PREF64 (RFC 8781) support
Ondřej Caletka [Sat, 4 Jun 2022 21:42:59 +0000 (23:42 +0200)]
router: Add PREF64 (RFC 8781) support

This option of IPv6 Router Advertisements allows devices connected to
a IPv6-only network to discover IPv6 prefix of the NAT64 gateway.
Devices can use this information for instance to setup client translator
(CLAT) from IPv4 to IPv6 in 464XLAT (RFC 6877) scenario or to handle
IPv4 address literal on application level.

To enable PREF64 option, a new uci parameter ra_pref64 has to contain
the NAT64 prefix, including prefix length. Only lengths of 96, 64, 56,
48, 40 and 32 bits are supported. For example, to annonce the Well-Known
Prefix:

config dhcp 'lan'
        …
        option ra_pref64 '64:ff9b::/96'

Fixes: #182
Signed-off-by: Ondřej Caletka <ondrej@caletka.cz>
[ remove extra space for Fixes tag ]
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
19 months agoconfig: use dedicated link local function to check interface
Christian Marangi [Mon, 3 Apr 2023 18:12:13 +0000 (20:12 +0200)]
config: use dedicated link local function to check interface

Use netlink_get_interface_addrs is wrong and doesn't actually work. The
function checks only for UNIVERSE address and is not suitable for
dumping linklocal address of an interface. Use the new and dedicated
function to get interface linklocal address to correctly check if the
interface can receive message.

Fixes: #197
Fixes: 7c0f603abc14 ("router: skip RA and wait for LINK-LOCAL to be assigned")
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
19 months agonetlink: add support for getting interface linklocal
Christian Marangi [Mon, 3 Apr 2023 18:04:01 +0000 (20:04 +0200)]
netlink: add support for getting interface linklocal

Add support for getting interface linklocal address. This is needed to
make sure an interface have a valid link local address and such address
is not TENTATIVE. With these info we can check if an interface is ready
to accept packets.

Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
19 months agoRevert "config: recheck have_link_local on interface reload if already init"
Christian Marangi [Mon, 3 Apr 2023 17:42:43 +0000 (19:42 +0200)]
Revert "config: recheck have_link_local on interface reload if already init"

This reverts commit 29c934d7ab98ca0b5da0e3757b885a1d3c19a2f4.

Replace with a better more safe implementation.

Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
19 months agoconfig: fix feature for enabling service only when interface RUNNING
Christian Marangi [Tue, 28 Mar 2023 22:16:46 +0000 (00:16 +0200)]
config: fix feature for enabling service only when interface RUNNING

With ba30afcfec0a26ce4bcd96ea4d687c498b0ba4df it was found that odhcpd
service are setup even if an interface had no connection and was not
running. The commit introduced the change but required more fixup for
the feature to work correctly.

The close_interface() remove the interface from the avl list and this
cause the interface to be missing later in the code flow.
The intention of the commit was to just disable the service and enable
them later when the interface is correctly set to running with the flag
IFF_RUNNING.

Change the logic and introduce a new function reload_servies() that will
check IFF_RUNNING and enable or disable odhcp services.

This function is called on odhcpd_reload() for each interface. In
odhcpd_reload() also restore the original pattern with calling
close_interface() only when the interface is not inuse for odhcp.

Also call reload_services() on the single interface when a RTM_NEWLINK
event is fired reacting to a link change of an odhcp interface and
enabling the services if IFF_RUNNING is set.

Fixes ba30afcfec0a ("config: skip interface setup if interface not IFF_RUNNING")
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
19 months agoconfig: recheck have_link_local on interface reload if already init
Christian Marangi [Thu, 23 Mar 2023 23:29:15 +0000 (00:29 +0100)]
config: recheck have_link_local on interface reload if already init

If an interface is already init in the odhcpd avl tables, have_link_local
is not set to true with a link local addr set as get ipv6 addr is skipped.

Move checking for have_link_local outside get_addr to better track when
an interface is ready and have a link local addr for interface already
init in odhcpd avl tables.

Fixes: #197
Fixes: 7c0f603abc14 ("router: skip RA and wait for LINK-LOCAL to be assigned")
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
19 months agorouter: skip RA and wait for LINK-LOCAL to be assigned
Christian Marangi [Thu, 16 Mar 2023 23:56:25 +0000 (00:56 +0100)]
router: skip RA and wait for LINK-LOCAL to be assigned

This fix a specific and corner case when the following error and similar
is printed in the log:

Failed to send to ff02::1%br-lan (Address not available)

The cause for this was tracked down to the lack of the interface of a
configured LINK-LOCAL IPV6 address resulting in odhcpd_send() always
failing.

A LINK-LOCAL IPV6 address is assigned only after the interface has
carrier and is set to IFF_RUNNING and require some time for the address
to be assigned due to DAD logic.

In the case where an interface was just UP, odhcpd RA may fail since the
LINK-LOCAL IPV6 address still needs to be assigned as it still need to
be "trained". From the kernel view this is flagged in the IPV6 interface
address with the flag IFA_F_TENTATIVE, that means the address still
needs to be checked and follow DAD process.

This is only a transient problem and the DAD process is required only
once till the interface is not set DOWN.

To handle this, add some check to verify if the address has to be
checked and add an additional bool to flag if the interface have a
LINK-LOCAL assigned.

Skip sending RA if the interface still doesn't have finished the DAD
process and retry at the next RA.
A notice log is added to track this special case to track problematic
case and even more corner case.

Logic to check if interface have LINK-LOCAL are:
- When interface is setup, on scanning for the interface ipv6 address
  check if at least one address is NOT in IFA_F_TENTATIVE state.
- With interface already up but with still no LINK-LOCAL react on the
  RTM_NEWADDR event and set LINK-LOCAL if the addrs added by the event
  is a LINK-LOCAL reflecting that the interface finally ended the DAD
  process and have a correct address.

Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
Acked-by: Hans Dedecker <dedeckeh@gmail.com>
19 months agoconfig: skip interface setup if interface not IFF_RUNNING
Christian Marangi [Thu, 16 Mar 2023 22:44:43 +0000 (23:44 +0100)]
config: skip interface setup if interface not IFF_RUNNING

We currently setup odhcp service even if the interface is not running.
This is the case for bridge or specific interface that are flagged as UP
but have no carrier as nothing is connected to it.
This cause a similar error like:

Failed to send to ff02::1%br-lan (Address not available)

This is caused by the kernel assigning IPV6 address only when the
interface is set to IFF_RUNNING.
A LINK-LOCAL IPV6 address is required for odhcpd_send() to work or every
request will be rejected.

To fix this setup services only when interface is in IFF_RUNNING state.
When an interface change state, odhcpd is reloaded and the services are
correctly setup again.

Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
Acked-by: Hans Dedecker <dedeckeh@gmail.com>
19 months agoRevert "odhcpd: Reduce error messages"
Stijn Tintel [Tue, 14 Mar 2023 23:37:44 +0000 (01:37 +0200)]
Revert "odhcpd: Reduce error messages"

Silencing an error message without properly understanding why it occurs
is terrible practice. "I think this would be better served as debug."
doesn't inspire confidence the author actually understood what was going
on, so revert this commit.

This reverts commit 90d6cc9cd48a333b95604ff90f7ffe67fe14efe3.

Signed-off-by: Stijn Tintel <stijn@linux-ipv6.be>
19 months agoodhcpd: Reduce error messages
Peter Naulls [Tue, 24 Jan 2023 19:35:02 +0000 (14:35 -0500)]
odhcpd: Reduce error messages

When there's no network cable connected to LAN, then odhcpd does this:

Tue Jan 24 18:32:04 2023 daemon.err odhcpd[2017]: Failed to send to
ff02::1%lan@br-lan (Address not available)
Tue Jan 24 18:32:20 2023 daemon.err odhcpd[2017]: Failed to send to
ff02::1%lan@br-lan (Address not available)
Tue Jan 24 18:32:36 2023 daemon.err odhcpd[2017]: Failed to send to
ff02::1%lan@br-lan (Address not available)
Tue Jan 24 18:32:52 2023 daemon.err odhcpd[2017]: Failed to send to
ff02::1%lan@br-lan (Address not available)

Accurate, but not very interesting. I think this would be better served
as debug.

Signed-off-by: Peter Naulls <peter@chocky.org>
20 months agorouter: always check ra_default
stijn@linux-ipv6.be [Thu, 16 Feb 2023 20:30:41 +0000 (22:30 +0200)]
router: always check ra_default

We currently only check ra_default when an interface has valid
addresses. This results in ra_default being ignored in case we have an
interface with only link-local addresses. This effectively breaks the
use of value 2 for the ra_default parameter.

Fix this by always checking ra_lifetime, regardless of the interface
having public addresses or not.

Fixes: #11930
Fixes: 83e14f455817 ("router: advertise removed addresses as invalid in 3 consecutive RAs")
Signed-off-by: Stijn Tintel <stijn@linux-ipv6.be>
Acked-by:Hans Dedecker <dedeckeh@gmail.com>

20 months agorouter: improve RA logging
stijn@linux-ipv6.be [Thu, 16 Feb 2023 20:30:40 +0000 (22:30 +0200)]
router: improve RA logging

We only set the RA lifetime to what is configured in UCI when there is a
default route and valid prefix. In any other case, we set it to 0. This
leads to confusion where people believe ra_lifetime is completely
ignored. In case there is a default route, but no valid prefix, a debug
message explains this, but if there is no default route, we silently
override ra_lifetime.

Add a debug message for the latter case, and explicitly mention
overriding ra_lifetime in both cases.

Signed-off-by: Stijn Tintel <stijn@linux-ipv6.be>
Acked-by: Hans Dedecker <dedeckeh@gmail.com>
20 months agodhcpv4: detect noarp interfaces
Mikael Magnusson [Tue, 7 Feb 2023 16:53:00 +0000 (16:53 +0000)]
dhcpv4: detect noarp interfaces

Don't add ARP entries to interfaces with IFF_NOARP, it causes
problems with for example WireGuard interfaces (which requires
this change to be usable with DHCPv4-over-DHCPv6).

Signed-off-by: Mikael Magnusson <mikma@users.sourceforge.net>
2 years agodhcpv6-ia: make tmp lease file hidden
Kevin Darbyshire-Bryant [Fri, 21 Oct 2022 13:28:59 +0000 (14:28 +0100)]
dhcpv6-ia: make tmp lease file hidden

Use a hidden . prefixed temporary lease file instead of appending
'.tmp'.  Dnsmasq is capable of scanning files/directories using inotify
to receive file change notifications and updating its view of hostname
ip address mapping without being SIGHUPped.  Until dnsmasq v2.88 this
mechanism allows additions to hostnames, no deletions.  dnsmasq v2.88
when released will understand how to remove mappings.

Unfortunately without this change dnsmasq sees odhcpd's temporary lease
file via inotify and it also sees the change when odhcpd atomically
renames the file from '.tmp' to the correct name.

dnsmasq excludes hidden '.' files from it's inotify scans, thus changing
odhcpd to use a hidden temporary lease file reduces load and makes
sense.

Also, while here, only rename the temporary file if it actually contains
different content.

Signed-off-by: Kevin Darbyshire-Bryant <ldir@darbyshire-bryant.me.uk>
2 years agofix null pointer dereference for INFORM messages
Rob Ekl [Fri, 14 Oct 2022 16:50:43 +0000 (11:50 -0500)]
fix null pointer dereference for INFORM messages

2 years agoodhcpd: Support for Option NTP and SNTP
Avinash Tekumalla [Wed, 8 Dec 2021 13:14:36 +0000 (18:44 +0530)]
odhcpd: Support for Option NTP and SNTP

Support for DHCPv6 Option NTP (Option-56) and SNTP (Option-31),
DHCP Option NTP(Option-42) is implemented.
ntp list is supported for IPv4, IPv6 and FQDN.

Signed-off-by: Avinash Tekumalla <avinash.tekumalla@technicolor.com>
Signed-off-by: Alin Nastac <alin.nastac@technicolor.com>
Signed-off-by: Ashutosh Shandilya <ashutosh.shandilya@technicolor.com>
Signed-off-by: Vidya Rajagopal <vidya.rajagopal@technicolor.com>
2 years agorouter: advertise removed addresses as invalid in 3 consecutive RAs
Alin Nastac [Wed, 15 Dec 2021 12:47:04 +0000 (13:47 +0100)]
router: advertise removed addresses as invalid in 3 consecutive RAs

On prefix removal, router advertisement daemon is supposed to send
advertise with an invalid PI entry (see RFC 7084 L-13).

Signed-off-by: Alin Nastac <alin.nastac@gmail.com>
Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
3 years agodhcpv4: fix uninitialized hostname in some ubus events
Mikael Magnusson [Wed, 11 Aug 2021 15:04:54 +0000 (17:04 +0200)]
dhcpv4: fix uninitialized hostname in some ubus events

The hostname buffer is uninitialized if the client doesn't provide
DHCPV4_OPT_HOSTNAME. Use hostname from the assignment which is present if
a static lease contains the hostname or if the client provides one, and
the hostname is valid. It's also used in the ubus ipv4leases method.

Signed-off-by: Mikael Magnusson <mikma@users.sourceforge.net>
3 years agodhcpv6-ia: allow up to 64 bit wide hostid
Mikael Magnusson [Wed, 14 Jul 2021 20:46:55 +0000 (22:46 +0200)]
dhcpv6-ia: allow up to 64 bit wide hostid

Add dhcpv6_hostid_len config option which controls the number
of bits in the host identifier of dynamically assigned IPv6
addresses. The default is 12 bits which is also the minimum.
The maximum is the whole interface identifier, i.e. 64 bits.

Allow up to 64 bit wide hostid in static leases.

Fixes #84 and #27.

Signed-off-by: Mikael Magnusson <mikma@users.sourceforge.net>
Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
3 years agodhcpv6-ia: fix invalid preferred lifetime
Hans Dedecker [Sun, 18 Jul 2021 16:43:26 +0000 (18:43 +0200)]
dhcpv6-ia: fix invalid preferred lifetime

Preferred lifetime cannot be greater than the valid lifetime of an IA;
fix this by checking if the preferred lifetime does not exceed the
valid lifetime of an IA

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
3 years agoconfig: fix ra_flags none setting
Hans Dedecker [Sun, 13 Jun 2021 20:09:54 +0000 (22:09 +0200)]
config: fix ra_flags none setting

Fixes commit a12fcb3cee2d489b8648a2398812d7bed2f25faa which wrongly
removed setting ra_flags to 0

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
3 years agoconfig: log config parse failures to syslog
Hans Dedecker [Sat, 15 May 2021 18:52:41 +0000 (20:52 +0200)]
config: log config parse failures to syslog

An invalid config setting for an interface lead to a flush of all config
settings of the related interface and thus made the interface unusable.
Change the behavior by logging config parse failures to syslog and
not flushing all config settings

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
3 years agocmake: enforce additonal compiler checks
Hans Dedecker [Sat, 3 Apr 2021 18:54:57 +0000 (20:54 +0200)]
cmake: enforce additonal compiler checks

Let's catch compile errors by enabling extra compiler checks

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
3 years agoodhcpd: fix extra compiler warning
Hans Dedecker [Sat, 3 Apr 2021 19:11:16 +0000 (21:11 +0200)]
odhcpd: fix extra compiler warning

src/odhcpd.c:143:2: error: format not a string literal, argument types not checked [-Werror=format-nonliteral]
  snprintf(buf, sizeof(buf), sysctl_pattern, ifname, what);
  ^~~~~~~~
cc1: all warnings being treated as errors

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
3 years agodhcpv6-ia: apply prefix_filter on dhcpv6
Nick Hainke [Wed, 6 Jan 2021 12:04:02 +0000 (13:04 +0100)]
dhcpv6-ia: apply prefix_filter on dhcpv6

The prefix_filter allows to select which prefix should be assigned
to clients if you have multiple prefixes on an interface.
Currently, the filter only applies to RAs and does work with
a dhcpv6 server.

This commit enables the filter also on dhcpv6.

Signed-off-by: Nick Hainke <vincent@systemli.org>
Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
3 years agoodhcpd: add option for setting preferred lifetime
Nick Hainke [Sat, 2 Jan 2021 22:27:03 +0000 (23:27 +0100)]
odhcpd: add option for setting preferred lifetime

"valid_lft" and "preferred_lft" are different. If the "preferred_lft"
is expired the prefix should be avoided in source prefix selection.
However, the interface is allowed to still receive downstream traffic.

preferred_lfetime:
  Limit for preferred lifetime of a prefix

If you want the old behavior, you have to set preferred_lifetime to
the same value as leasetime.

Signed-off-by: Nick Hainke <vincent@systemli.org>
Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
3 years agodhcpv6-ia: remove assignment equal to 0 checks
Hans Dedecker [Thu, 24 Dec 2020 15:28:43 +0000 (16:28 +0100)]
dhcpv6-ia: remove assignment equal to 0 checks

Remove the checks as they're leftovers of the old static lease
implementation which created assigments with assigned equal to 0
whihc is not the case anymore in the reworked static lease
implementation

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
3 years agodhcpv6-ia: fix logic to include IA_PD prefix with lifetimes set to 0
Hans Dedecker [Thu, 24 Dec 2020 15:08:58 +0000 (16:08 +0100)]
dhcpv6-ia: fix logic to include IA_PD prefix with lifetimes set to 0

Make sure IA_PD prefixes for which no preferred and valid lifetimes
can be returned are included in the reply with a preferred and valid
lifetime to 0.
Therefore exclude IPv6 prefixes with an invalid prefix length as
well so IA_PD prefixes for which not a preferred/valid lifetime is
returned are included with a preferred and valid lifetime set to 0

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
3 years agodhcpv6-ia: fix prefix delegation behavior
Hans Dedecker [Thu, 24 Dec 2020 14:41:37 +0000 (15:41 +0100)]
dhcpv6-ia: fix prefix delegation behavior

When an IPv6 address change is triggered each PD assignment is checked
if it is still consistent with the updated IPv6 prefix list.
If not consistent anymore a reconfigure is triggered for the assignment
and a best effort is made to assign a new IA_PD prefix.
If it not possible anymore to assign an IA_PD prefix delete the PD
assignment now so it will result into a NO BINDING status code for the
given IA_PD in the DHCPv6 reply when the client tries to renew the IA_PD prefix.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
3 years agoconfig: remove local mkdir_p implementation
Daniel Golle [Sun, 13 Dec 2020 00:08:23 +0000 (00:08 +0000)]
config: remove local mkdir_p implementation

Replace local mkdir_p implementation in favour of using mkdir_p now
added to libubox.

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
3 years agoubus: add add_lease method
Santiago Piccinini [Wed, 2 Dec 2020 22:07:05 +0000 (19:07 -0300)]
ubus: add add_lease method

Allows sharing leases between odhcpd instances running
in multiple hosts.

Signed-off-by: Santiago Piccinini <spiccinini@altermundi.net>
Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
3 years agoconfig: add option to indicate dns service presence
icpz [Fri, 20 Nov 2020 16:55:25 +0000 (00:55 +0800)]
config: add option to indicate dns service presence

Adds the config option to set if ipv6 dns service is availiable on the
interface. In some cases the dns service may not be listening on the
ipv6 address of the interface, and thus should not be announced to clients.

Signed-off-by: Paizhuo Chen <cc@icpz.dev>
3 years agodhcpv6-ia : write statefile atomically
Hans Dedecker [Sat, 8 Aug 2020 23:08:23 +0000 (19:08 -0400)]
dhcpv6-ia : write statefile atomically

Applications (e.g. unbound) need a consistent view of the statefile;
therefore write all the lease info to a temporary file which is later
renamed to the configured statefile name

Suggested-by : John Fremlin <john@fremlin.org>
Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
4 years agodhcpv6: fix size_t fields in syslog format
Mikael Magnusson [Sun, 1 Nov 2020 13:52:39 +0000 (14:52 +0100)]
dhcpv6: fix size_t fields in syslog format

Signed-off-by: Mikael Magnusson <mikma@users.sourceforge.net>
4 years agodhcpv6: add explicit dhcpv4o6 server address
Mikael Magnusson [Mon, 26 Oct 2020 21:52:27 +0000 (22:52 +0100)]
dhcpv6: add explicit dhcpv4o6 server address

Include the All_DHCP_Relay_Agents_and_Servers multicast address
in the option explicitly. It shouldn't be needed according
to RFC 7341 section 7.2 but ISC dhclient logs an error otherwise:

dhcp4-o-dhcp6-server: expecting at least 16 bytes; got 0

Signed-off-by: Mikael Magnusson <mikma@users.sourceforge.net>
4 years agodhcpv6: add DHCPv4-over-DHCPv6 support
Mikael Magnusson [Mon, 26 Oct 2020 21:52:17 +0000 (22:52 +0100)]
dhcpv6: add DHCPv4-over-DHCPv6 support

Add support for DHCPv4-over-DHCPv6 (DHCP 4o6) Transport (RFC 7341).

Signed-off-by: Mikael Magnusson <mikma@users.sourceforge.net>
Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
4 years agodhcpv6: check message type
Mikael Magnusson [Wed, 4 Mar 2020 00:25:50 +0000 (01:25 +0100)]
dhcpv6: check message type

Signed-off-by: Mikael Magnusson <mikma@users.sourceforge.net>
4 years agorouter: fix advertisement interval option
Hans Dedecker [Mon, 7 Sep 2020 19:35:42 +0000 (21:35 +0200)]
router: fix advertisement interval option

The variable maxival contains the maximum time in seconds between
successive unsolicited Router Advertisement messages; RFC6275 defines
the Advertisement Interval option as the time in milliseconds.
Therefore convert maxival to milliseconds when populating the
Advertisement Interval option.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
4 years agoodhcpd: fix compilation with GCC10
Rosen Penev [Mon, 22 Jun 2020 04:37:36 +0000 (21:37 -0700)]
odhcpd: fix compilation with GCC10

GCC10 mandates the C++ one definition rule, which breaks on multiple
definitions of config. Add the appropriate extern declaration.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
4 years agorouter: fix Lan host reachibility due to identical RIO and PIO prefixes (FS#3056)
Hans Dedecker [Sun, 3 May 2020 19:17:53 +0000 (21:17 +0200)]
router: fix Lan host reachibility due to identical RIO and PIO prefixes (FS#3056)

odhcpd includes RIO RA options according to requirement L3 in RFC7084.
However if the delegated prefix length received on the wan is equal to the
downstream delegated prefix length on the Lan this may pollute the
routing table of type C hosts as the RIO routing entry can take
precedence of the PIO routing entry meaning all traffic for the on link
hosts will go via the router iso direct on link communication.
If the traffic is dropped in the router hosts are unreachable; therefore
don't include RIO options with prefixes and prefix length identical to
those in a PIO RA option

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
4 years agodhcpv6-ia: fix preferred and valid lifetimes in ubus ipv6leases
Hans Dedecker [Thu, 2 Apr 2020 19:26:57 +0000 (21:26 +0200)]
dhcpv6-ia: fix preferred and valid lifetimes in ubus ipv6leases

Since commit 6db312a698e920ff61505ef1f42469880829774d the preferred and
valid lifetimes of the addresses/prefixes is based on the configured leasetime;
as a result the displayed preferred and valid lifetimes need to be
calculated based on the assignment lifetime as this is set to the lowest
valid lifetime of the addresses/prefixes.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
4 years agoodhcpd: fix compilation with musl 1.2.0
Rosen Penev [Thu, 26 Mar 2020 23:07:12 +0000 (16:07 -0700)]
odhcpd: fix compilation with musl 1.2.0

SYS_clock_gettime is gone with musl 1.2.0. Switched to the function.

Also fixed two format strings that fail as time_t is 64-bit with 1.2.0.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
4 years agoubus: use dhcpv6 ia assignment flag
Hans Dedecker [Sat, 14 Mar 2020 20:03:11 +0000 (21:03 +0100)]
ubus: use dhcpv6 ia assignment flag

Further align the code to use DHCPv6 assignment flags to distinguish
between prefix delegation and non temporary address assignments

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
4 years agodhcpv6-ia: avoid setting lifetime to infinite for static assignments
Hans Dedecker [Sun, 16 Feb 2020 20:27:42 +0000 (21:27 +0100)]
dhcpv6-ia: avoid setting lifetime to infinite for static assignments

Don't set the valid lifetime to infinite for static assignments
but rather set it to the IA lifetime given to the client.
This makes it possible to display the leasetime for static assigments
and simplifies the code in several places

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
4 years agodhcpv4: avoid setting lifetime to infinite for static assignments
Hans Dedecker [Sun, 16 Feb 2020 20:15:28 +0000 (21:15 +0100)]
dhcpv4: avoid setting lifetime to infinite for static assignments

Don't set the valid lifetime to infinite for static assignments
but rather set it to the leasetime given to the client.
This makes it possible to display the leasetime for static assigments
and simplifies the code in several places

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
4 years agodhcpv6-ia: use dhcp leasetime to set preferred/valid statefull lifetimes
Hans Dedecker [Tue, 14 Jan 2020 20:16:48 +0000 (21:16 +0100)]
dhcpv6-ia: use dhcp leasetime to set preferred/valid statefull lifetimes

Allow to set the preferred/valid lifetimes of IA_NA/IA_PD options based
on the configured dhcp leasetime.
DHCP leqasetime will be used to set the preferred/valid lifetimes in the
IA_NA/IA_PD options unless the preferred/valid lifetimes of the IPv6
address are smaller then the DHCP leasetime.
This will avoid IA_NA/IA_PD options being sent with infinite lifetimes
due to the IPv6 address having infinite preferred/valid lifetimes
like IPv6 ULA addresses.
While at it rename dhcpv4_leasetime into dhcp_leasetime as the leasetime
is used both for DHCPv4 and DHCPv6

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
4 years agodhcpv6-ia: introduce DHCPv6 pd and ia assignments flags
Hans Dedecker [Thu, 2 Jan 2020 17:26:51 +0000 (18:26 +0100)]
dhcpv6-ia: introduce DHCPv6 pd and ia assignments flags

Simplify the code by using specific flags which identify the assignment
either as a DHCPv6 PD or NA assignment. This allows to remove implicit
checks for PD and NA assignments based on the value of the assignment
length parameter.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
4 years agodhcpv6-ia: cleanup prefix delegation routes
Hans Dedecker [Tue, 31 Dec 2019 15:30:34 +0000 (16:30 +0100)]
dhcpv6-ia: cleanup prefix delegation routes

Remove prefix delegation routes as well in free_dhcpv6_assignment when
cleaning up the assignment resources

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
4 years agodhcpv6-ia: remove passing interface as parameter to apply_lease
Hans Dedecker [Tue, 31 Dec 2019 15:13:08 +0000 (16:13 +0100)]
dhcpv6-ia: remove passing interface as parameter to apply_lease

As the assignment struct holds a pointer to the interface struct
use this one in apply_lease iso passing interface as a parameter

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
4 years agotreewide: optimize syslog priority values
Hans Dedecker [Sun, 15 Dec 2019 19:17:32 +0000 (20:17 +0100)]
treewide: optimize syslog priority values

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
5 years agondp: fix endian issue
Hans Dedecker [Sun, 13 Oct 2019 18:37:14 +0000 (20:37 +0200)]
ndp: fix endian issue

Fix endian issue introduced in commit 91a28e4 by using
ND_NA_FLAG_SOLICITED defined in netinet/icmp6.h

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
5 years agonetlink: fix potential infinite loops
Hans Dedecker [Mon, 23 Sep 2019 20:06:00 +0000 (22:06 +0200)]
netlink: fix potential infinite loops

Fix potential infinite loops by checking the return code of
nl_send_auto_complete; if nl_send_auto_complete fails pending
will always have the value 1 as the finish callback will not
be called resulting into an infinite loop

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
5 years agonetlink: rename netlink callback handlers
Hans Dedecker [Sun, 15 Sep 2019 17:26:37 +0000 (19:26 +0200)]
netlink: rename netlink callback handlers

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
5 years agondp: answer global-addressed NS manually
sfan5 [Sat, 2 Feb 2019 21:48:18 +0000 (22:48 +0100)]
ndp: answer global-addressed NS manually

An upstream router may address solicits to the global address of the target,
these will not be answered by the kernel and not routed either due to link-local
source. The NS will eventually be retried as multicast, but we want to avoid this.

see also https://forum.archive.openwrt.org/viewtopic.php?id=40871

Signed-off-by: Stefan Alfers <sfan5@live.de>
5 years agodhcpv6: retry failed PD assignments on addrlist change
Tian Hao [Thu, 29 Aug 2019 17:08:17 +0000 (01:08 +0800)]
dhcpv6: retry failed PD assignments on addrlist change

Currently only assignments with prefixes larger than the largest
available one will be re-assigned on addrlist change events.
Previously failed PD assignments are not taken into account, and these
assignments will never have a chance to recover even if the address just
added to the interface could satisfy them.

Failed PD assignments could be very common when upstream prefix is obtained
from a PPPoE WAN, as ISPs tend to terminate the PPPoE session after a fixed
time period. Addresses on LAN could disappear and re-appear during WAN redial,
and all existing PD assignments to clients in LAN will become failed when the
addresses disappear. These assignments will not be recovered after WAN has been
brought back up, and clients in LAN could no longer receive any PD prefix.

This commit fixes the issue by including failed PD assignments in the
re-assign list on addrlist change event, so that newly added prefixes can be
put into use right after they are added to the interface.

Signed-off-by: Tian Hao <haotia@gmail.com>
5 years agoconfig: ra_management compatibility support
Hans Dedecker [Mon, 9 Sep 2019 20:12:51 +0000 (22:12 +0200)]
config: ra_management compatibility support

Keep supporting ra_management for backwards compatibility support;
ra_management will only be processed if neither ra_slaac and ra_flags
are set.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
5 years agoodhcpd: router: Fix out of scope memory access
Hauke Mehrtens [Mon, 2 Sep 2019 20:29:49 +0000 (22:29 +0200)]
odhcpd: router: Fix out of scope memory access

A pointer to search_buf is accessed by search_domain outside of the
if branch which defines search_buf. The compiler could already reuse
this memory.

Coverity: #1445747
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
5 years agodhcpv6-ia: free assignment when validity timer expires
Hans Dedecker [Tue, 27 Aug 2019 20:00:26 +0000 (22:00 +0200)]
dhcpv6-ia: free assignment when validity timer expires

In case clid_len is set free assignment when validity timer expires

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
5 years agorouter: speed up initial router advertisements
Hans Dedecker [Fri, 16 Aug 2019 19:22:11 +0000 (21:22 +0200)]
router: speed up initial router advertisements

Speed up sending initial router advertisement messages as documented in
RFC2461 point 6.2.4

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
5 years agorouter: close socket upon NETEV_IFINDEX_CHANGE fixed
Koen Aerts [Mon, 19 Aug 2019 11:18:04 +0000 (13:18 +0200)]
router: close socket upon NETEV_IFINDEX_CHANGE fixed

Make sure the raw socket is removed from the uloop file descriptor
list before the socket is closed as introduced in
https://github.com/openwrt/odhcpd/commit/000182fe4f94a5a6ec139456a2b74f0cdea13b9c

Related to  https://github.com/openwrt/odhcpd/issues/135

Signed-off-by: Koen Aerts <aertskoen5@gmail.com>
5 years agorouter: fix previous commit
Hans Dedecker [Fri, 16 Aug 2019 19:14:07 +0000 (21:14 +0200)]
router: fix previous commit

After closing the router socket the value needs to be set to -1

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
5 years agorouter: close socket upon NETEV_IFINDEX_CHANGE
Koen Aerts [Tue, 13 Aug 2019 13:02:19 +0000 (15:02 +0200)]
router: close socket upon NETEV_IFINDEX_CHANGE

Make sure the socket is closed in a case where the bridge goes down
as a result of NO-CARRIER on the bridge.
If not present Router Discovery and Router Advertisement will break
permanently after the bridge went down.

Related to  https://github.com/openwrt/odhcpd/issues/135

Signed-off-by: Koen Aerts <aertskoen5@gmail.com>
5 years agorouter: fix lingering uloop socket descriptor
Hans Dedecker [Thu, 8 Aug 2019 19:42:15 +0000 (21:42 +0200)]
router: fix lingering uloop socket descriptor

In case setting one of the socket options fails; make sure the raw
socket is removed from the uloop file descriptor list before the
socket is closed.
In case this is not done and a new raw socket is created with the
same fd value odhcpd will not be triggered by uloop in case RS messages
are received on the socket as reported in https://github.com/openwrt/odhcpd/issues/135

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
5 years agorouter: support ra_lifetime being 0
Jan-Philipp Litza [Thu, 4 Jul 2019 11:31:25 +0000 (13:31 +0200)]
router: support ra_lifetime being 0

The value 0 has the special meaning of not being a default router. This
is useful to only advertise prefixes or DNS settings without being a
real router.

Signed-off-by: Jan-Philipp Litza <janphilipp@litza.de>
5 years agorouter: make RA flags configurable (FS#2019)
Hans Dedecker [Fri, 17 May 2019 19:29:25 +0000 (21:29 +0200)]
router: make RA flags configurable (FS#2019)

Replace the config option ra_management by the config options ra_flags
and ra_slaac. The latter allows to configure the autonomous-address
config flag used for stateless address configuration while the former
allows to configure the RA flags in the form of a list.
The list can hold the following values :
managed-config
other-config
home-agent
none

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
5 years agoconfig: remove 'ignore' config option
Dainis Jonitis [Fri, 12 Apr 2019 10:46:43 +0000 (13:46 +0300)]
config: remove 'ignore' config option

1. Remove 'ignore' config option for interface. Interface is still used if
   any of 'ra', 'ndp', 'dhcpv4' or 'dhcpv6' options are different from
   default 'disabled' mode. In config_parse_interface() update runtime
   ignore value according to all mode values.
2. Reset ignore, ra, ndp, dhcpv4 and dhcpv6 values in set_interface_defaults().
   Otherwise if option is deleted from config file and config is reloaded,
   it will use the value from old config, potentiallly not turning services off.
3. Do not use implicit checks that 0 server mode means MODE_DISABLED.
4. Simplify code of all service setup functions if passed enabled = true
   argument, but service mode is disabled.

Signed-off-by: Dainis Jonitis <dainis.jonitis@ubnt.com>
Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
5 years agotreewide: init assignment lists head
Hans Dedecker [Tue, 14 May 2019 14:18:51 +0000 (16:18 +0200)]
treewide: init assignment lists head

When allocating an assignment in alloc_assignment; init the circular head
and lease_list circular lists. Avoids checking NULL pointer when freeing
the assignment in free_assignment.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
5 years agoconfig: use list safe iterator in lease_delete
Hans Dedecker [Tue, 14 May 2019 13:18:08 +0000 (15:18 +0200)]
config: use list safe iterator in lease_delete

As the current assignment is freed in lease_delete use list_for_each_entry_safe

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
5 years agodhcpv4: fix lease ordering by ip address
Dainis Jonitis [Mon, 29 Apr 2019 11:57:13 +0000 (14:57 +0300)]
dhcpv4: fix lease ordering by ip address

1. Maintaining of sorted list was wrong for static lease case.
   Add dhcpv4_insert_assignment() helper function and use it from all places.
2. Add ip4toa() helper function to print ipv4 address that is stored as
   network byte-order uint32_t.

Signed-off-by: Dainis Jonitis <dainis.jonitis@ubnt.com>
Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
5 years agoconfig: use multi-stage parsing of uci sections
Dainis Jonitis [Mon, 29 Apr 2019 11:47:13 +0000 (14:47 +0300)]
config: use multi-stage parsing of uci sections

When loading uci sections from config file, in one pass do not
mix sections from different types. First load odhcpd global
settings, then all interface sections and finally static leases.
It ensures that section order in file can't affect what information
is already parsed. For example static lease section may need
information about all interfaces, to decide whether ip address
belongs to any of currently defined interfaces/address pools.

Signed-off-by: Dainis Jonitis <dainis.jonitis@ubnt.com>
5 years agotreewide: always init interface list heads during initialization
Dainis Jonitis [Mon, 29 Apr 2019 11:40:14 +0000 (14:40 +0300)]
treewide: always init interface list heads during initialization

When allocating interface, init dhcpv4_assignments, dhcpv4_fr_ips
and ia_assignments circular list heads to point to self. Avoids
checking whether next pointer is not null all over the place.

Signed-off-by: Dainis Jonitis <dainis.jonitis@ubnt.com>
5 years agodhcpv4: do not allow pool end address to overlap with broadcast address
Dainis Jonitis [Mon, 26 Nov 2018 12:53:51 +0000 (14:53 +0200)]
dhcpv4: do not allow pool end address to overlap with broadcast address

Signed-off-by: Dainis Jonitis <dainis.jonitis@ubnt.com>
5 years agotreewide: give file descriptors safe initial value
Dainis Jonitis [Mon, 26 Nov 2018 12:45:53 +0000 (14:45 +0200)]
treewide: give file descriptors safe initial value

Since main problem of assuming that fd==0 is invalid value
was fixed in upstream odhcpd by e7b1d4bf3a2297192638b9c84208b3dcb306ecd8
then what is left are minor problems of static initialization
of some global fd variables.

Signed-off-by: Dainis Jonitis <dainis.jonitis@ubnt.com>
5 years agodhcpv4: DHCP pool size is off-by-one
Dainis Jonitis [Mon, 26 Nov 2018 12:43:45 +0000 (14:43 +0200)]
dhcpv4: DHCP pool size is off-by-one

1. "limit" option should specify the size of dynamic pool. The dhcpv4_end
   includes the last valid pool address.
2. Also handle 7 bit host addresses when not directly specified in config file.
3. Make sure code does what documentation says and default 'start'/'limit'
   pool options to 100 and 150 respectively.

Signed-off-by: Dainis Jonitis <dainis.jonitis@ubnt.com>
Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
5 years agodhcpv4: add support for Parameter Request List option 55
Dainis Jonitis [Mon, 26 Nov 2018 12:36:28 +0000 (14:36 +0200)]
dhcpv4: add support for Parameter Request List option 55

Add client "reqopts" in ubus "ipv4leases" output.

Signed-off-by: Roman Yeryomin <roman.yeryomin@ubnt.com>
Signed-off-by: Dainis Jonitis <dainis.jonitis@ubnt.com>
5 years agodhcpv4: fix DHCP packet size
Hans Dedecker [Fri, 26 Apr 2019 12:15:55 +0000 (14:15 +0200)]
dhcpv4: fix DHCP packet size

Calculate the DHCP packet size based on the number of DHCP options in the
message. Make sure the DHCP packet size does not go lower than 300 bytes
as some clients ignore DHCP messages smaller than 300 bytes.

Based on a patch by Dainis Jonitis <dainis.jonitis@ubnt.com>

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
5 years agondp: fix syslog flooding (FS#2242)
Hans Dedecker [Tue, 23 Apr 2019 13:07:52 +0000 (15:07 +0200)]
ndp: fix syslog flooding (FS#2242)

Only log a syslog error in case adding of a proxy neighbor fails as a delete
failure cannot be considered as a syslog error for all cases.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
5 years agoconfig: set default loglevel to LOG_WARNING
Hans Dedecker [Tue, 23 Apr 2019 11:45:28 +0000 (13:45 +0200)]
config: set default loglevel to LOG_WARNING

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
5 years agorouter: fix dns search list option
Hans Dedecker [Fri, 19 Apr 2019 11:16:58 +0000 (13:16 +0200)]
router: fix dns search list option

Fix regression issue introduced in commit 0523bdd as empty DNS search
list option was sent making the RA message invalid

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
5 years agorouter: use ra_lifetime as lifetime for RA options (FS#2206)
Hans Dedecker [Wed, 17 Apr 2019 09:22:43 +0000 (11:22 +0200)]
router: use ra_lifetime as lifetime for RA options (FS#2206)

Use the RA lifetime as lifetime for the recursive DNS and DNS search options
For the route options use as lifetime the smallest value of either the valid
lifetime of the address associated with the route or the RA lifetime.
This avoids routes having infinite lifetime being installed in downstream
clients which can results into routes pointing to a removed router.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
5 years agorouter: improve code readibility
Hans Dedecker [Thu, 11 Apr 2019 20:48:28 +0000 (22:48 +0200)]
router: improve code readibility

No functional changes; just improve code readibilty in send_router_advert()

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
5 years agoRevert "router:"
Hans Dedecker [Tue, 16 Apr 2019 20:46:26 +0000 (22:46 +0200)]
Revert "router:"

This reverts commit f1d7da9801adc0a77c1a35363e4242544c4915e7.

5 years agotreewide: align syslog loglevels
Hans Dedecker [Tue, 16 Apr 2019 13:27:42 +0000 (15:27 +0200)]
treewide: align syslog loglevels

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
5 years agorouter:
Hans Dedecker [Fri, 12 Apr 2019 13:47:29 +0000 (15:47 +0200)]
router:

5 years agotreewide: fix compiler warnings
Hans Dedecker [Thu, 11 Apr 2019 20:00:15 +0000 (22:00 +0200)]
treewide: fix compiler warnings

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
5 years agoCMakeList.txt: enable extra compiler checks
Hans Dedecker [Thu, 11 Apr 2019 19:50:12 +0000 (21:50 +0200)]
CMakeList.txt: enable extra compiler checks

Enforce additional compiler checks in order to catch
possible errors during compilation

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
5 years agondp: create ICMPv6 socket per interface
Hans Dedecker [Thu, 4 Apr 2019 14:57:47 +0000 (16:57 +0200)]
ndp: create ICMPv6 socket per interface

Get rid of the global raw ICMPv6 socket by creating a raw ICMPv6 ping socket
per interface. This fixes an open raw ICMPv6 socket in case all ndp interfaces
are configured as disabled.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>