oweals/odhcpd.git
3 years agoodhcpd: fix compilation with GCC10 master
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>
3 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>
4 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>
4 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>
4 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>
4 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>
4 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>
4 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>
4 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>
4 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>
4 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>
4 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>
4 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>
4 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>
4 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>
4 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>
4 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>
4 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>
4 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>
4 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>
4 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>
4 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>
4 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>
4 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>
4 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>
4 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>
4 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>
4 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>
4 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>
4 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>
5 years agorouter: create ICMPv6 socket per interface
Hans Dedecker [Wed, 3 Apr 2019 14:29:19 +0000 (16:29 +0200)]
router: create ICMPv6 socket per interface

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

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
5 years agotreewide: initialize properly file descriptors
Hans Dedecker [Thu, 4 Apr 2019 10:01:46 +0000 (12:01 +0200)]
treewide: initialize properly file descriptors

Initialzie properly the dhcpv6, dhcpv4 and ndp ffile descriptors
when creating an interface.
As such the check for a valid descriptor can be done correct now
in the different modules

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
5 years agonetlink: rework IPv4 address refresh logic
Hans Dedecker [Fri, 29 Mar 2019 14:10:29 +0000 (15:10 +0100)]
netlink: rework IPv4 address refresh logic

Rework logic to refresh IPv4 addresses so we can get rid of the
second for loop

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
5 years agonetlink: rework IPv6 address refresh logic
Hans Dedecker [Fri, 29 Mar 2019 11:01:19 +0000 (12:01 +0100)]
netlink: rework IPv6 address refresh logic

Rework logic to refresh IPv6 addresses so we can get rid of the
second for loop

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
5 years agonetlink: fix IPv6 address updates (FS#2204)
Hans Dedecker [Wed, 27 Mar 2019 15:55:19 +0000 (16:55 +0100)]
netlink: fix IPv6 address updates (FS#2204)

Keep the valid and preferred lifetimes in sync with the kernel by always
updating the cached IPv6 addresses in refesh_iface_addr6().
This fixes invalid preferred and valid IA lifetimes in DHCPv6 reply
messages due to the cached preferred and valid lifetimes not being in
sync with the preferred and valid kernel lifetimes

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
5 years agodhcpv6: extra syslog tracing
Hans Dedecker [Thu, 21 Mar 2019 14:37:56 +0000 (15:37 +0100)]
dhcpv6: extra syslog tracing

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
5 years agodhcpv6/router: add support for mutiple master interfaces
Hans Dedecker [Thu, 21 Mar 2019 13:43:52 +0000 (14:43 +0100)]
dhcpv6/router: add support for mutiple master interfaces

Support multiple master interfaces for dhcpv6 and ra; it allows
to forward dhcpv6 mesaages and RS on multiple upstream links

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
5 years agondp: fix adding proxy neighbor entries
Hans Dedecker [Thu, 21 Mar 2019 13:17:50 +0000 (14:17 +0100)]
ndp: fix adding proxy neighbor entries

In case multiple logical OpenWrt interfaces are stacked on the same device
and one of the interfaces is configured in relay and the other not; adding
a proxy neighbor entry will result into it immediately being deleted if
the interface in non relay mode comes last.
Fix this by not doing a delete on the interface which is not configured in
relay mode.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
5 years agorouter: add extra syslog tracing
Hans Dedecker [Thu, 21 Mar 2019 08:19:00 +0000 (09:19 +0100)]
router: add extra syslog tracing

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
5 years agonetlink: fix neighbor event handling (FS#2160)
Hans Dedecker [Wed, 20 Mar 2019 15:33:19 +0000 (16:33 +0100)]
netlink: fix neighbor event handling (FS#2160)

Commit a54cee0 introduced a regression in the handling of netlink neighbor
events as it did not set the interface pointer in the netevent_handler_info
struct resulting into a breakage of ndp relay mode

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
5 years agoubus: always trigger an update if interface is not found
Hans Dedecker [Wed, 27 Feb 2019 10:10:29 +0000 (11:10 +0100)]
ubus: always trigger an update if interface is not found

Commit 9f25dd8af76dc30e54ddcbb4a284058e598951d5 changed the logic of
handle_update by only triggering an update if the interface is
found in the interface list and is not set as to be ignored.
However this breaks the behavior of loading the dhcp config for
interfaces which were previously not yet known by netifd and as
result were not yet created in the interface list.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
5 years agodhcpv4: fix adding assignment in list (FS#2142)
Hans Dedecker [Mon, 25 Feb 2019 09:48:44 +0000 (10:48 +0100)]
dhcpv4: fix adding assignment in list (FS#2142)

Add assignment to the tail of the list in case the last element
is not bigger

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
5 years agodhcpv4: fix static lease lookup
Hans Dedecker [Mon, 25 Feb 2019 09:46:18 +0000 (10:46 +0100)]
dhcpv4: fix static lease lookup

Function config_find_lease_by_ip_addr expects IP address in network
byte order

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
5 years agodhcp: rework assignment free logic
Hans Dedecker [Mon, 18 Feb 2019 17:22:24 +0000 (18:22 +0100)]
dhcp: rework assignment free logic

Replace the separate dhcpv4/dhcpv6 assignment free functions by
the function free_assignment which calls the dhcp specific
free function via a callback

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
5 years agoconfig: fix build failure in case DHCPv4 support is disabled
Hans Dedecker [Mon, 18 Feb 2019 14:35:04 +0000 (15:35 +0100)]
config: fix build failure in case DHCPv4 support is disabled

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
5 years agodhcpv4: fix assignment of requested IP address
Hans Dedecker [Mon, 18 Feb 2019 13:11:12 +0000 (14:11 +0100)]
dhcpv4: fix assignment of requested IP address

Fix assignment of requested IP address by a client in case the
assignment list is empty.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
5 years agodhcp: rework static lease logic
Hans Dedecker [Tue, 12 Feb 2019 15:07:24 +0000 (16:07 +0100)]
dhcp: rework static lease logic

Rework the static lease logic as the existing logic had different issues.
Static leases are now added in a vlist tree which makes it easier to handle
static lease config changes.
For both DHCPv4 and DHCPv6 static assignments are now created upon the
receival of DHCPv4/DHCPv6 messages as before the static assignment was
created even if the client was not physically present.
In case a hostname is specified in a static lease it won't be overriden
anymore by the hostname received from the client.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
5 years agodhcpv6: rapid commit support
Hans Dedecker [Wed, 13 Feb 2019 11:07:49 +0000 (12:07 +0100)]
dhcpv6: rapid commit support

Add support for rapid commit according to RFC8415 18.3.1

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
5 years agodhcpv6: fix parsing of DHCPv6 relay messages
Hans Dedecker [Wed, 13 Feb 2019 10:07:38 +0000 (11:07 +0100)]
dhcpv6: fix parsing of DHCPv6 relay messages

Commit 0db69b0b85c83fedd74ac77e850669a17c4e6617 broke parsing of DHCPv6
relay messages as the DHCPv6 client header pointer was not updated
after parsing the nested relay forward message(s).

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
5 years agodhcpv4: fix compile issue
Hans Dedecker [Tue, 12 Feb 2019 13:14:50 +0000 (14:14 +0100)]
dhcpv4: fix compile issue

Fix compile issue introduced in commit 671ccaabc893b53be8a1891aaf2236b657d6ce06

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
5 years agodhcpv6-ia: move function definitions to odhcpd.h
Hans Dedecker [Mon, 11 Feb 2019 14:46:29 +0000 (15:46 +0100)]
dhcpv6-ia: move function definitions to odhcpd.h

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
5 years agodhcpv6: improve code readibility
Hans Dedecker [Sun, 10 Feb 2019 20:21:51 +0000 (21:21 +0100)]
dhcpv6: improve code readibility

Use struct dhcpv6_client_header hdr to access fixed DHCPv6 header fields

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
5 years agotreewide: unify dhcpv6 and dhcpv4 assignments
Hans Dedecker [Tue, 11 Dec 2018 13:13:30 +0000 (14:13 +0100)]
treewide: unify dhcpv6 and dhcpv4 assignments

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
5 years agonetlink: rework handling of netlink messages
Hans Dedecker [Thu, 7 Feb 2019 12:18:40 +0000 (13:18 +0100)]
netlink: rework handling of netlink messages

Multiple logical OpenWrt interfaces can be stacked on top of the same
Linux device. As such netlink events for addresses/routes/ifindex changes
need to be propagated to the different logical OpenWrt interfaces
which use the Linux device as reported in the netlink message.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
5 years agotreewide: use avl tree to store interfaces
Hans Dedecker [Tue, 5 Feb 2019 11:09:44 +0000 (12:09 +0100)]
treewide: use avl tree to store interfaces

Store the interfaces in an avl tree iso a linear linked list

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
5 years agotreewide: align syslog tracing
Hans Dedecker [Sun, 3 Feb 2019 17:03:42 +0000 (18:03 +0100)]
treewide: align syslog tracing

Use the logical OpenWrt interface name in syslog printing as multiple
logical interfaces can be defined on top of the same device

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
5 years agodhcpv6-ia: add full CONFIRM support
Hans Dedecker [Wed, 30 Jan 2019 17:19:49 +0000 (18:19 +0100)]
dhcpv6-ia: add full CONFIRM support

Add CONFIRM support as specified in RFC8415 paragraph 18.3.3

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
5 years agodhcpv6-ia: rework append_reply()
Hans Dedecker [Tue, 29 Jan 2019 14:38:36 +0000 (15:38 +0100)]
dhcpv6-ia: rework append_reply()

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
5 years agodhcpv6-ia: fix compiler warning
Hans Dedecker [Wed, 16 Jan 2019 21:40:46 +0000 (22:40 +0100)]
dhcpv6-ia: fix compiler warning

Fixes :

src/dhcpv6-ia.c:1117:22: warning: variable 'onlink' set but not used [-Wunused-but-set-variable]
   for (size_t i = 0, onlink = false; i < addrlen; ++i) {

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
5 years agodhcpv6-ia: fix onlink IA check (FS#2060)
Hans Dedecker [Wed, 16 Jan 2019 10:03:14 +0000 (11:03 +0100)]
dhcpv6-ia: fix onlink IA check (FS#2060)

Some DHCPv6 clients start sending SOLICIT messages without including either
an IA_NA or IA_PD and only start including an IA_NA or IA_PD in the REQUEST
message without including an IA_PREFIX or IA_ADDR as suboption. As a result
the check to verify if an IA_ADDR and/or IA_PREFIX is onlink fails.
Fix this by returning notonlink if an IA_PREFIX or IA_ADDR suboption is
present having an address/prefix not matching any of the addresses

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
5 years agodhcpv6: add setting to choose IA_NA, IA_PD or both
Matija Amidzic [Fri, 21 Dec 2018 14:58:47 +0000 (15:58 +0100)]
dhcpv6: add setting to choose IA_NA, IA_PD or both

Adds the config options to set if DHCPv6 'stateful addresing' hands out
IA_NA (Internet Address - Network Address), IA_PD (Internet Address -
Prefix Delegation), both or none.

Signed-off-by: Matija Amidzic <matija.amidzic@sartura.hr>
5 years agorouter: add syslog tracing for skipped routes
Hans Dedecker [Wed, 2 Jan 2019 20:36:27 +0000 (21:36 +0100)]
router: add syslog tracing for skipped routes

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
5 years agorouter: filter route information option
Hans Dedecker [Wed, 2 Jan 2019 18:23:11 +0000 (19:23 +0100)]
router: filter route information option

Commit 750e457e3000187b85906814a2529ede24775325 added the capability
to filter out prefixes in RAs; however routes were not filtered out
based on the prefixes. This commit fixes this by taking into account
the prefix_filter when constructing the RA route info option

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
5 years agorouter: make announcing DNS info configurable (FS#2020)
Hans Dedecker [Mon, 31 Dec 2018 16:06:40 +0000 (17:06 +0100)]
router: make announcing DNS info configurable (FS#2020)

Make announcing options Recursive DNS server and DNS search list
configurable via the ra_dns config option.
This allows to disable sending RA based DNS info if such info is
already provided by DHCPv6.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
5 years agorouter: check return code of odhcpd_get_interface_dns_addr()
Hans Dedecker [Mon, 31 Dec 2018 15:00:12 +0000 (16:00 +0100)]
router: check return code of odhcpd_get_interface_dns_addr()

Check if odhcpd_get_interface_dns_addr() returns a valid DNS address.
While at it restructure the DNS RA code to make it more readable

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
5 years agoconfig: check for invalid DNS addresses
Hans Dedecker [Mon, 31 Dec 2018 14:41:25 +0000 (15:41 +0100)]
config: check for invalid DNS addresses

Don't accept 0.0.0.0 and :: as DNS addresses.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
5 years agoodhcpd: switch to libubox container_of implementation
Hans Dedecker [Wed, 12 Dec 2018 17:48:30 +0000 (18:48 +0100)]
odhcpd: switch to libubox container_of implementation

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
5 years agotreewide: switch to libubox ARRAY_SIZE immplementation
Hans Dedecker [Wed, 12 Dec 2018 16:58:18 +0000 (17:58 +0100)]
treewide: switch to libubox ARRAY_SIZE immplementation

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
5 years agonetlink: fix triggering of NETEV_ADDR6LIST_CHANGE event
Hans Dedecker [Mon, 26 Nov 2018 13:58:08 +0000 (14:58 +0100)]
netlink: fix triggering of NETEV_ADDR6LIST_CHANGE event

Generate a NETEV_ADDR6LIST_CHANGE event in case the preferred lifetime
makes a transition from deprecated (preferred lifetime not greater than
current timestamp) to not deprecated (preferred lifetime greater than
current timestamp)

Reported-by: Tian Hao <haotia@gmail.com>
Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
5 years agoconfig: correctly break string for prefix filter
Hamster Tian [Thu, 22 Nov 2018 15:36:14 +0000 (23:36 +0800)]
config: correctly break string for prefix filter

This if statement does the following:

1. Copy the value of "config prefix_filter"
2. Break the string at "/"
3. Save the number after / as prefix length
4. Convert the address before / into in6_addr

However the extraneous "=" broke the second step and inet_pton
failed with addresses with mask. This commit removes the = thus
fixes the feature.

Signed-off-by: Tian Hao <haotia@gmail.com>
5 years agoodhcpd: make DHCPv6/RA/NDP support optional
Hans Dedecker [Sun, 30 Sep 2018 19:54:33 +0000 (21:54 +0200)]
odhcpd: make DHCPv6/RA/NDP support optional

In case IPv6 is not enabled don't try to init DHCPv6/RA and NDP but only
init DHCPv4. This allows odhcpd to start up in absence of IPv6 support.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
5 years agodhcpv6: check return code of dhcpv6_ia_init()
Hans Dedecker [Sun, 23 Sep 2018 18:21:54 +0000 (20:21 +0200)]
dhcpv6: check return code of dhcpv6_ia_init()

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
5 years agorouter: don't leak RA message in relay mode (FS#1853)
Hans Dedecker [Sun, 23 Sep 2018 17:06:08 +0000 (19:06 +0200)]
router: don't leak RA message in relay mode (FS#1853)

In relay mode don't send RA message with router lifetime equal to 0 when
interface gets disabled as router

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
5 years agoodhcpd: detect broken hostnames
Hans Dedecker [Wed, 22 Aug 2018 09:45:53 +0000 (11:45 +0200)]
odhcpd: detect broken hostnames

Check hostnames contain valid characters as defined in RFC 952 and RFC 1123.
Invalid hostnames in uci configured host entries will result into a refusal
to create the static lease.
In case a client received hostname contains an invalid character no
<hostname> <IP address> entry will be added to the lease file.
In such case the leaseinfo description in the lease file will still contain
the hostname but preceded by the string broken\x20

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
5 years agoconfig: fix odhcpd_attrs array size
Hans Dedecker [Mon, 3 Sep 2018 11:46:28 +0000 (13:46 +0200)]
config: fix odhcpd_attrs array size

Use ODHCPD_ATTR_MAX as array size of odhcpd_attrs

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
5 years agoubus: avoid dumping interface state with NULL message
Jo-Philipp Wich [Thu, 26 Jul 2018 12:26:37 +0000 (14:26 +0200)]
ubus: avoid dumping interface state with NULL message

Invoking ubus methods with NULL message is not supported anymore, so
make sure that network.interface/dump is called with an empty blob buffer
argument.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
5 years agodhcpv4: improve error checking in handle_dhcpv4()
Hans Dedecker [Mon, 9 Jul 2018 06:58:00 +0000 (08:58 +0200)]
dhcpv4: improve error checking in handle_dhcpv4()

Check ioctl return value as reported by Coverity in CID1437659

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
5 years agoodhcpd: Check if open the ioctl socket failed
Hyeonsik Song [Thu, 5 Jul 2018 01:45:37 +0000 (10:45 +0900)]
odhcpd: Check if open the ioctl socket failed

Signed-off-by: Hyeonsik Song <blogcin@naver.com>
5 years agodhcpv6-ia: fix border assignment size setting
Hans Dedecker [Tue, 26 Jun 2018 10:17:11 +0000 (12:17 +0200)]
dhcpv6-ia: fix border assignment size setting

The border assignment size is not updated by address list change events if
the interface is not configured as DHCPv6 server; therefore set the border
assignment size when an interface is enabled and configured as a DHCPv6
server in order to keep the assignment size in sync with the available
prefix sizes

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
5 years agodhcpv6-ia: fix status code for not on link IAs
Hans Dedecker [Mon, 25 Jun 2018 14:51:42 +0000 (16:51 +0200)]
dhcpv6-ia: fix status code for not on link IAs

Set status code not on link for IAs in DHCPv6 request messages carrying
prefixes/addresses not matching the link prefix(es) to which the client
is connected

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
5 years agodhcpv6-ia: improve error checking in assign_pd()
Hans Dedecker [Fri, 22 Jun 2018 14:32:31 +0000 (16:32 +0200)]
dhcpv6-ia: improve error checking in assign_pd()

Detected by Coverity in CID1412267

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