oweals/odhcpd.git
7 years agotreewide: use angle-brackets to include libubox header files
Hans Dedecker [Tue, 27 Jun 2017 09:20:20 +0000 (11:20 +0200)]
treewide: use angle-brackets to include libubox header files

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agoconfig: fix invalid hoplimit in RA message
Hans Dedecker [Mon, 15 May 2017 18:02:40 +0000 (20:02 +0200)]
config: fix invalid hoplimit in RA message

Don't send an invalid hoplimit in RA message when
the interface is shutdown due to a invalid configured
ra_hoplimit.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agoconfig: fix invalid retranstime in RA message
Hans Dedecker [Mon, 15 May 2017 17:59:03 +0000 (19:59 +0200)]
config: fix invalid retranstime in RA message

Don't send an invalid retranstime in RA message when
the interface is shutdown due to a invalid configured
ra_retranstime.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agoconfig: fix invalid reachabletime in RA message
Hans Dedecker [Mon, 15 May 2017 17:54:20 +0000 (19:54 +0200)]
config: fix invalid reachabletime in RA message

Don't send an invalid reachabletime in RA message when
the interface is shutdown due to a invalid configured
ra_reachabletime.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agoconfig: limit ra_mtu to 65535
Hans Dedecker [Mon, 15 May 2017 15:42:52 +0000 (17:42 +0200)]
config: limit ra_mtu to 65535

Limit the maximum ra_mtu to 65535

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agorouter: fix interface mtu read error
Hans Dedecker [Mon, 15 May 2017 15:40:37 +0000 (17:40 +0200)]
router: fix interface mtu read error

Use integer type for mtu variable as odhcpd_get_interface_config returns
-1 when it fails to read the interface mtu. This allows to set the mtu
to a meaningfull value of 1280 in case of interface mtu read failure.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agoconfig: limit ra_retranstime to 60000
Hans Dedecker [Mon, 15 May 2017 13:58:46 +0000 (15:58 +0200)]
config: limit ra_retranstime to 60000

Limit the maximum ra_retranstime value to 60000 milliseconds as
described in RFC7048.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agodhcpv4: display two hex digits per octet in syslog
Leon M. George [Fri, 12 May 2017 12:12:34 +0000 (14:12 +0200)]
dhcpv4: display two hex digits per octet in syslog

Signed-off-by: Leon M. George <leon@georgemail.eu>
7 years agoconfig: make RA retransTime configurable via uci
Hans Dedecker [Fri, 12 May 2017 08:53:25 +0000 (10:53 +0200)]
config: make RA retransTime configurable via uci

Allow to specify the router advertisement retrans time via the uci
parameter ra_retranstime. If retransmit time is not configured the
value is set to 0 in RA message meaning undefined.

7 years agoconfig: make RA reachableTime configurable via uci
Hans Dedecker [Thu, 11 May 2017 16:44:17 +0000 (18:44 +0200)]
config: make RA reachableTime configurable via uci

Allow to specify the router advertisement reachable time via the uci
parameter ra_reachabletime. If reachable time is not configured the
value is set to 0 in RA message meaning undefined.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agoconfig: make RA curHopLimit configurable via uci
Hans Dedecker [Thu, 11 May 2017 14:50:14 +0000 (16:50 +0200)]
config: make RA curHopLimit configurable via uci

Allow to specify the router advertisement current hop limit via the uci
parameter ra_hoplimit. If hoplimit is not configured the hoplimit is
taken from the interface as before.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agoconfig: make RA mtu configurable via UCI
Hans Dedecker [Thu, 11 May 2017 13:34:27 +0000 (15:34 +0200)]
config: make RA mtu configurable via UCI

Allow to specify the router advertisement mtu via the uci parameter
ra_mtu. In case the config parameter is not set the MTU is taken from
the interface as before.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agoconfig: fix dhcpv4 server being started
Hans Dedecker [Thu, 11 May 2017 09:08:48 +0000 (11:08 +0200)]
config: fix dhcpv4 server being started

In case maindhcp is set to disabled in global config one expect the DHCPv4
server not being started irrespective if the dhcpv4 interface config is set
to server.
Fix this by keeping maindhcp config apart from the legacy config parameter
as already documented in the README.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agondp.c: add switch/case fallthrough comments
Felix Fietkau [Thu, 4 May 2017 13:51:53 +0000 (15:51 +0200)]
ndp.c: add switch/case fallthrough comments

Fixes gcc 7 build errors

Signed-off-by: Felix Fietkau <nbd@nbd.name>
7 years agondp: don't trigger IPv6 ping when neighbor entry is invalid
Hans Dedecker [Fri, 28 Apr 2017 08:20:13 +0000 (10:20 +0200)]
ndp: don't trigger IPv6 ping when neighbor entry is invalid

A ping for an IPv6 address not present on an interface will generate a
netlink neighbor message with as status fail; launching again an IPv6
ping on other proxy enabled interfaces will create a cascade effect of
netlink neighbor messages with as status fail which in its turn will
again trigger an IPv6 ping on proxy enabled interfaces ...

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agondp: fix adding proxy neighbor entries
Hans Dedecker [Fri, 28 Apr 2017 07:58:54 +0000 (09:58 +0200)]
ndp: fix adding proxy neighbor entries

Proxy neighbor entries were not created for proxy enabled interfaces
if the first interface was not enabled

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agondp: fix wrong interface name in syslog message
Hans Dedecker [Thu, 27 Apr 2017 16:16:11 +0000 (18:16 +0200)]
ndp: fix wrong interface name in syslog message

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agodhcpv6-ia: Fix segfault when writing DHCPv4 leases in state file
Hans Dedecker [Wed, 26 Apr 2017 07:56:06 +0000 (09:56 +0200)]
dhcpv6-ia: Fix segfault when writing DHCPv4 leases in state file

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agoubus: don't segfault when there're no leases
Hans Dedecker [Tue, 25 Apr 2017 12:50:18 +0000 (14:50 +0200)]
ubus: don't segfault when there're no leases

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agoubus: rework dumping IPv6 and IPv4 leases
Hans Dedecker [Fri, 21 Apr 2017 14:23:04 +0000 (16:23 +0200)]
ubus: rework dumping IPv6 and IPv4 leases

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agodhcpv6-ia: simplify logic to write statefile and dhcpv6 logging
Hans Dedecker [Thu, 13 Apr 2017 20:24:20 +0000 (22:24 +0200)]
dhcpv6-ia: simplify logic to write statefile and dhcpv6 logging

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agodhcpv6-ia: create assignment for unknown IA in rebind messages
Hans Dedecker [Wed, 12 Apr 2017 14:35:21 +0000 (16:35 +0200)]
dhcpv6-ia: create assignment for unknown IA in rebind messages

Create assignment for unknown identity association in rebind messages which is
equivalent to the handling of identity association for solicit/request messages.
However don't consider identity associations in rebind messages as a request so
that addresses/prefixes which are not apropriate for the link are returned with
lifetimes of 0.
This aligns with the behavior of the ISC DHCPv6 server.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agorework IPv6 dns address selection (FS#635)
Hans Dedecker [Wed, 29 Mar 2017 15:03:29 +0000 (17:03 +0200)]
rework IPv6 dns address selection (FS#635)

Don't return anymore the link local IPv6 address as DNS IPv6 address
since different OS implementations (e.g. android, ...) cannot handle
a link local IPv6 address as DNS address.

IPv6 DNS address selection is reworked as follows :
-Consider all global/ULA IPv6 address having a valid lifetime
-Give preference to global/ULA IPv6 addresses being not deprecated
-Give preference to ULA IPv6 addresses over IPv6 global addresses
-Give preference to the IPv6 address with the longest preferred lifetime in
its selected category (ULA or global)
-If no global/ULA IPv6 address is present use the IPv6 link local address

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agondp: keep an exact copy of IPv6 interface addresses
Hans Dedecker [Wed, 29 Mar 2017 14:47:52 +0000 (16:47 +0200)]
ndp: keep an exact copy of IPv6 interface addresses

Don't reset the final 32 bit IPv6 host suffix when storing the IPv6 addresses
in the interface structure. This will allow exact lookup aand return of IPv6
addresses stored in the interface structure when needed.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agondp: code cleanup
Hans Dedecker [Tue, 28 Mar 2017 14:44:50 +0000 (16:44 +0200)]
ndp: code cleanup

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agorework IPv6 address dump logic
Hans Dedecker [Mon, 27 Mar 2017 20:01:13 +0000 (22:01 +0200)]
rework IPv6 address dump logic

Make the code more logical by moving the IPv6 address dump logic into the
different protocol interface enable handlers so it's clear which protocols
require interface IPv6 address tracking.
At the same time restructure the IPv6 address dump logic so less IPv6 address
netlink dumps are created.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agondp: add syslog debug tracing
Hans Dedecker [Thu, 9 Mar 2017 14:49:03 +0000 (15:49 +0100)]
ndp: add syslog debug tracing

Add extra LOG_DEBUG syslog tracing for trouble shooting

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agodhcpv6-ia: Check lockf return value
Florian Fainelli [Wed, 1 Mar 2017 05:48:29 +0000 (21:48 -0800)]
dhcpv6-ia: Check lockf return value

Check the lockf return value to fix the following warning/error:

/home/fainelli/dev/openwrt/trunk/build_dir/target-mipsel-linux-gnu_glibc/odhcpd-2017-02-21-1b630f8b/src/dhcpv6-ia.c: In function 'dhcpv6_write_statefile':
/home/fainelli/dev/openwrt/trunk/build_dir/target-mipsel-linux-gnu_glibc/odhcpd-2017-02-21-1b630f8b/src/dhcpv6-ia.c:246:8: error: ignoring return value of 'lockf', declared with attribute warn_unused_result [-Werror=unused-result]
   lockf(fd, F_LOCK, 0);
        ^
cc1: all warnings being treated as errors

Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
7 years agorouter: don't announce prefixes with valid lifetime equal to 0
Hans Dedecker [Tue, 21 Feb 2017 08:54:36 +0000 (09:54 +0100)]
router: don't announce prefixes with valid lifetime equal to 0

Don't set prefix valid lifetime to 0 in case the preferred lifetime
equals 0 and valid lifetime gets smaller than 7200.
In corner cases it leads to router lifetime being set although no
prefixes are announced with a valid lifetime different from 0.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agorouter: fix arithmetic exception fault
Hans Dedecker [Mon, 20 Feb 2017 16:19:06 +0000 (17:19 +0100)]
router: fix arithmetic exception fault

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agorouter: allow RA prefix lifetime being set to leasetime value (FS#397)
Hans Dedecker [Mon, 20 Feb 2017 14:31:48 +0000 (15:31 +0100)]
router: allow RA prefix lifetime being set to leasetime value (FS#397)

Add config option ra_useleasetime which allows the RA prefix lifetime
being set to the leasetime in case the valid and/or preferred prefix
lifetime is bigger than the configured leasetime.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agotreewide: simplify dhcp leasetime checking
Hans Dedecker [Sun, 19 Feb 2017 21:00:38 +0000 (22:00 +0100)]
treewide: simplify dhcp leasetime checking

Set dhcp leasetim to 43200 seconds for all interfaces independant
if dhcpv4 is enabled for an interface. Minimum allowed leasetime
is 60 seconds when parsing leastime configuration; this allows to
clean up the awkward leasetime checks on different places in the code

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agorouter: support ra_mininterval and ra_lifetime uci parameters (FS#397)
Hans Dedecker [Thu, 16 Feb 2017 11:20:08 +0000 (12:20 +0100)]
router: support ra_mininterval and ra_lifetime uci parameters (FS#397)

Add support for uci parameters ra_mininterval and ra_lifetime as described
in RFC4861 paragraph 6.2.1.

Variable ra_mininterval allows to configure the minimum interval time
between unsolicited router advertisement messages; default value is
200 seconds. The minimum allowed value is 4 seconds while the maximum
value is limited to 0.75 of the maximum interval time.

The calculation of the maximum interval time between unsolicited
router advertisement messages has been reworked. The default value is 600
seconds as specified in RFC4861; if the maximum interval time exceeds
0.33 * the minimal valid lifetime of all IPv6 prefixes it will be limited
to 0.33 * the minimal valid lifetime of all IPv6 prefixes

Variable ra_lifetime allows to configure the Router Lifetime field
in the router advertisement messages; the value is either 0 or a value
between the maximum interval time and 9000 seconds. If the router lifetime
is smaller than the RA maximum interval it will be set equal to the RA
maximum interval time.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agorouter.h: fix alignment style
Hans Dedecker [Wed, 15 Feb 2017 13:12:55 +0000 (14:12 +0100)]
router.h: fix alignment style

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agoRevert "odhcpd.h: fix alignment style"
Hans Dedecker [Wed, 15 Feb 2017 13:11:35 +0000 (14:11 +0100)]
Revert "odhcpd.h: fix alignment style"

This reverts commit 62ea54f5db4c636710781056541c4b85d043bef8.

7 years agoodhcpd.h: fix alignment style
Hans Dedecker [Wed, 15 Feb 2017 12:51:56 +0000 (13:51 +0100)]
odhcpd.h: fix alignment style

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agoconfig: make loglevel configurable via uci (FS#481)
Hans Dedecker [Tue, 14 Feb 2017 10:59:14 +0000 (11:59 +0100)]
config: make loglevel configurable via uci (FS#481)

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agoodhcpd: display correct default log level in usage text
Hans Dedecker [Mon, 13 Feb 2017 08:29:12 +0000 (09:29 +0100)]
odhcpd: display correct default log level in usage text

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agotreewide: define and use macro IN6_IS_ADDR_ULA
Hans Dedecker [Fri, 10 Feb 2017 16:03:49 +0000 (17:03 +0100)]
treewide: define and use macro IN6_IS_ADDR_ULA

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agondp: deregister netlink event socket for non recoverable errors
Hans Dedecker [Fri, 10 Feb 2017 09:57:34 +0000 (10:57 +0100)]
ndp: deregister netlink event socket for non recoverable errors

Deregister netlink event socket in case of error different
from ENOBUFS or failure to set netlink rx buffer size

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agoodhcpd: fix white space errors
Hans Dedecker [Fri, 10 Feb 2017 09:24:20 +0000 (10:24 +0100)]
odhcpd: fix white space errors

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agondp: harden netlink event socket error handling
Hans Dedecker [Thu, 9 Feb 2017 15:52:50 +0000 (16:52 +0100)]
ndp: harden netlink event socket error handling

Start with a netlink receive buffersize of 130k for the netlink event socket;
double the netlink receive buffer size in case an ENOBUFS is reported.
Also align function naming and its parameters.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agondp: close proc file descriptor also during error handling
Hans Dedecker [Thu, 9 Feb 2017 14:25:35 +0000 (15:25 +0100)]
ndp: close proc file descriptor also during error handling

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agonpd: rework IPv6 relay logic (FS#396)
Hans Dedecker [Wed, 1 Feb 2017 09:44:51 +0000 (10:44 +0100)]
npd: rework IPv6 relay logic (FS#396)

Rework the IPv6 relay logic to make it more robust by making
use of libnltiny to process netlink messages.
At the same time reimplement the IPv6 relay finite state machine
to make the relay logic less error prone

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agoconfig: restore interface defaults when cleaning interface
Hans Dedecker [Wed, 8 Feb 2017 15:36:02 +0000 (16:36 +0100)]
config: restore interface defaults when cleaning interface

Interface defaults are whiped when clean interface is executed
resulting into loss of default behavior for the ndproxy_routing
and ra_management uci parameters

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agodhcpv6-ia: apply lease delete based on assignment bound state
Hans Dedecker [Wed, 1 Feb 2017 09:44:51 +0000 (10:44 +0100)]
dhcpv6-ia: apply lease delete based on assignment bound state

Make adding and removing of routes via apply_lease dependant
on the assignment bound state as it makes no sense to delete
routes for an assignment which is not bound.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agoodhcpd: properly handle netlink messages (FS#388)
Hans Dedecker [Tue, 31 Jan 2017 21:11:20 +0000 (22:11 +0100)]
odhcpd: properly handle netlink messages (FS#388)

Use libnl-tiny to construct and process netlink messages when
manipulating IPv6 routes and fetching IPv6 addresses.
This fixes lingering netlink error messages on the netlink socket
in case route deletion failed causing fetching of IPv6 addresses
to be aborted and odhcpd faultly assuming no IPv6 addresses being
present on the interface.

7 years agoodhcpd: fix coding style
Hans Dedecker [Tue, 31 Jan 2017 21:07:08 +0000 (22:07 +0100)]
odhcpd: fix coding style

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agoodhcpd: decrease default log level to LOG_INFO
Hans Dedecker [Thu, 26 Jan 2017 17:32:14 +0000 (18:32 +0100)]
odhcpd: decrease default log level to LOG_INFO

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agoodhcpd: rework IPv6 interface address dump
Hans Dedecker [Thu, 26 Jan 2017 17:29:09 +0000 (18:29 +0100)]
odhcpd: rework IPv6 interface address dump

Rework the IPv6 address dump logic to make it more robust
and generate syslog traces in case of error situations

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agoodhcpd: extra syslog tracing
Hans Dedecker [Thu, 26 Jan 2017 14:23:36 +0000 (15:23 +0100)]
odhcpd: extra syslog tracing

Add extra syslog tracing for trouble shooting
and make some syslog traces more self explaining

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agorouter: fix compile issue on 64 bit systems
Hans Dedecker [Tue, 24 Jan 2017 08:31:24 +0000 (09:31 +0100)]
router: fix compile issue on 64 bit systems

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agoRevert "router: fix compile issue on 64 targets"
Hans Dedecker [Tue, 24 Jan 2017 08:22:55 +0000 (09:22 +0100)]
Revert "router: fix compile issue on 64 targets"

This reverts commit 70fbf936839e02d526929be06ecba3059f78be3c.

7 years agorouter: fix compile issue on 64 targets
Hans Dedecker [Tue, 24 Jan 2017 08:06:22 +0000 (09:06 +0100)]
router: fix compile issue on 64 targets

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agorouter: convert syslog lifetime traces into LOG_INFO prio
Hans Dedecker [Mon, 23 Jan 2017 16:54:42 +0000 (17:54 +0100)]
router: convert syslog lifetime traces into LOG_INFO prio

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agotreewide: rework prio of syslog messages
Hans Dedecker [Mon, 23 Jan 2017 16:29:43 +0000 (17:29 +0100)]
treewide: rework prio of syslog messages

Rework prio of syslog messages allowing to filter out the relevant messages
by setting the correct log level

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agondp: code cleanup
Hans Dedecker [Mon, 23 Jan 2017 15:49:15 +0000 (16:49 +0100)]
ndp: code cleanup

ia_reconf is only set but nowhere used; so let's remove it ...

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agorouter: add syslog debug tracing for trouble shooting
Hans Dedecker [Sat, 21 Jan 2017 16:07:54 +0000 (17:07 +0100)]
router: add syslog debug tracing for trouble shooting

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agotreewide: use RELAYD_MAX_ADDRS as address array size
Hans Dedecker [Sat, 21 Jan 2017 15:27:17 +0000 (16:27 +0100)]
treewide: use RELAYD_MAX_ADDRS as address array size

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agondp: don't scan netlink attributes in case of netlink route event
Hans Dedecker [Sat, 21 Jan 2017 14:40:13 +0000 (15:40 +0100)]
ndp: don't scan netlink attributes in case of netlink route event

In case a netlink route event is received for a default route
netlink data attributes were faulty processed as neigbor netlink
data. Fix this by not processing any netlink attribute for
any route event.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agodhcpv6-ia: filter out prefixes having invalid length
Hans Dedecker [Fri, 6 Jan 2017 14:26:17 +0000 (15:26 +0100)]
dhcpv6-ia: filter out prefixes having invalid length

Function append_reply filters out addresses having invalid prefix length
when constructing prefixes being delegated to a client.
Now also filter out addresses with an invalid prefix length when writing
the delegated prefixes in the statefile and during logging of the delegated
prefixes.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agodhcpv6-ia: fix dereference after freeing assignment
Hans Dedecker [Thu, 5 Jan 2017 15:03:35 +0000 (16:03 +0100)]
dhcpv6-ia: fix dereference after freeing assignment

Fix assignment dereference by dhcpv6_log in case
the assignment is freed when nothing has been
assigned.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agodhcpv6-ia: log only IPv6 addresses which are effectively assigned to a DHCPv6 client
Hans Dedecker [Thu, 5 Jan 2017 14:06:07 +0000 (15:06 +0100)]
dhcpv6-ia: log only IPv6 addresses which are effectively assigned to a DHCPv6 client

Fix displaying IPv6 addresses which were not assigned to a DHCPv6 client
Clean up the code by using macro ADDR_ENTRY_VALID_IA_ADDR on different
places to align the checks.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agoconfig: respect ignore uci option
Jo-Philipp Wich [Tue, 3 Jan 2017 13:09:08 +0000 (14:09 +0100)]
config: respect ignore uci option

The odhcpd documentation currently implies that "option ignore 1" in a section
of type "dhcp" will disable any services on the referenced interface while the
code actually ignores the setting when initializing referenced interfaces.

This commonly leads to situations where users think that "option disabled"
will prevent any server activity on a given interface while in reality odhcpd
effectively acts as rogue DHCPv6 server in its default configuration.

To fully inhibit any activity, one has to specify both "option ignore 1" as
well as "option ra disabled", "option ndp disabled" and
"option dhcpv6 disabled" which is highly counter intuitive at best.

A previous commit (5f425ed Respect interface "ignore" settings as documented.)
attempted to address the problem by observing the value of i->ignore instead
of unconditionally enabling all protocols but broke the ability to use DHCPv6
relay mode while having DHCPv4 disabled.

This patch changes ...

 - the enabling of services on an interface to use the value of the ignore
   option as default choice instead of hardcoding "true"

 - the options "ra", "ndp", "dhcpv4" and "dhcpv6" to take precedence over the
   default "ignore" state to allow selectively enabling services on ignored
   interfaces

 - the README to clarify the fact that "ra", "ndp", "dhcpv4" and "dhcpv6" can
   now override "option ignore"

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Acked-by: Karl Palsson <karlp@etactica.com>
Tested-by: Stijn Tintel <stijn@linux-ipv6.be>
Tested-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agodhcpv6-ia: fix static assignment check
Hans Dedecker [Tue, 3 Jan 2017 09:42:19 +0000 (10:42 +0100)]
dhcpv6-ia: fix static assignment check

Fix static assignment check failure which was
introduced in commit 561890e

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agodhcpv6-ia: coding style fixes
Hans Dedecker [Mon, 2 Jan 2017 16:13:09 +0000 (17:13 +0100)]
dhcpv6-ia: coding style fixes

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agodhcpv6-ia: update valid_until only for non static DHCPv6 leases
Hans Dedecker [Mon, 2 Jan 2017 16:10:14 +0000 (17:10 +0100)]
dhcpv6-ia: update valid_until only for non static DHCPv6 leases

Update valid_until lifetime only for non static DHCPv6 leases otherwise
the lifetime of a static lease is not infinite anymore

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agodhcpv4: coding style fixes
Hans Dedecker [Mon, 2 Jan 2017 15:29:14 +0000 (16:29 +0100)]
dhcpv4: coding style fixes

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agoREADME: Add host leasetime uci parameter
Hans Dedecker [Sat, 31 Dec 2016 09:26:49 +0000 (10:26 +0100)]
README: Add host leasetime uci parameter

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agodhcpv6-ia: fix invalid IPv6/hostname entries in statefile
Hans Dedecker [Fri, 30 Dec 2016 19:52:05 +0000 (20:52 +0100)]
dhcpv6-ia: fix invalid IPv6/hostname entries in statefile

Statefull IPv6 addresses are assigned to DHCPv6 clients from a
local prefix based on criteria which need to be fulfilled.
One of those criteria requires the IPv6 address still having
preferred lifetime which was not checked when constructing
the contents of the statefile.
Another criteria requires the prefix length not being smaller
than or equal to 64 when ra_management equals 0 or 1 which was
neither correctly checked when constructing the statefile.
This can lead to invalid hostname/IPv6 entries in the statefile
and thus possible connectivity issues when using DNS resolving.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agodhcpv6-ia: fix delete logic of an assignment in reconf_timer
Hans Dedecker [Fri, 30 Dec 2016 16:44:44 +0000 (17:44 +0100)]
dhcpv6-ia: fix delete logic of an assignment in reconf_timer

Function free_dhcpv6_assignment already removes the assignment in
the list so there's no need to call list_del in reconf_timer

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agodhcpv6-ia : code style fixes
Hans Dedecker [Fri, 30 Dec 2016 16:34:01 +0000 (17:34 +0100)]
dhcpv6-ia : code style fixes

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agoconfig: use free_lease to delete a lease
Hans Dedecker [Thu, 29 Dec 2016 14:17:13 +0000 (15:17 +0100)]
config: use free_lease to delete a lease

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agoconfig: coding style fixes
Hans Dedecker [Thu, 29 Dec 2016 13:12:08 +0000 (14:12 +0100)]
config: coding style fixes

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agoconfig: Create statefile dir
Hans Dedecker [Thu, 29 Dec 2016 11:33:39 +0000 (12:33 +0100)]
config: Create statefile dir

Create statefile dir if the specified dir does not yet exist

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agodhcpv6-ia: use free_dhcpv6_assignment where needed
Hans Dedecker [Wed, 28 Dec 2016 22:23:55 +0000 (23:23 +0100)]
dhcpv6-ia: use free_dhcpv6_assignment where needed

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agodhcpv6-ia: make free_dhcpv6_assignment static
Hans Dedecker [Wed, 28 Dec 2016 22:18:54 +0000 (23:18 +0100)]
dhcpv6-ia: make free_dhcpv6_assignment static

Further align coding style

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agodhcpv4: make dhcpv4_msg_to_string static
Hans Dedecker [Wed, 28 Dec 2016 22:07:47 +0000 (23:07 +0100)]
dhcpv4: make dhcpv4_msg_to_string static

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agodhcpv4: fix DHCPv4 hostname handling
Hans Dedecker [Wed, 28 Dec 2016 09:57:30 +0000 (10:57 +0100)]
dhcpv4: fix DHCPv4 hostname handling

Fix hostname not being reported as "-" in the DHCP statefile in case
no hostname is reported by the DHCPv4 client
(https://:wqgithub.com/openwrt/odhcpd/issues/94)

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agoLimit lifetime of non-static leases in case of release and decline
Hans Dedecker [Thu, 15 Dec 2016 21:37:47 +0000 (22:37 +0100)]
Limit lifetime of non-static leases in case of release and decline

In case infinite leasetime is assigned to a non static DHCPv4/v6 lease
override the infinite lifetime of the lease when either a DHCPv4/v6
decline or release is received.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agoRevert "Respect interface "ignore" settings as documented."
Stijn Tintel [Tue, 27 Dec 2016 08:40:21 +0000 (09:40 +0100)]
Revert "Respect interface "ignore" settings as documented."

This reverts commit 5f425ed1e5f92397e27ec4f44820b6ef677b8134.

Both dnsmasq and odhcpd use the ignore option. This is fine for normal
operation, but it breaks DHCPv6 relay when dnsmasq is disabled on the
wan interface.

Signed-off-by: Stijn Tintel <stijn@linux-ipv6.be>
7 years agorouter: skip parse_routes when ra_default > 1
Stijn Tintel [Sun, 14 Aug 2016 17:22:57 +0000 (20:22 +0300)]
router: skip parse_routes when ra_default > 1

It does not make sense to scan the entire routing table if the decision
will be overridden afterwards.

This makes it possible to use odhcpd on a router with full IPv6 BGP
table, by setting ra_default to 2. Without this change, odhcpd is
constantly busy reading /proc/net/ipv6_route, and doesn't respond to
router solicitations in time.

Signed-off-by: Stijn Tintel <stijn@linux-ipv6.be>
7 years agoDon't print non bound assignments in the state file
Hans Dedecker [Wed, 14 Dec 2016 21:22:22 +0000 (22:22 +0100)]
Don't print non bound assignments in the state file

Set bound flag for DHCPv4 and DHCPv6 assignments when the IPv6/IPv4 address
is leased to a client.
This will prevent the printing of leases and hostname/IPv4/IPv6 address
combinations in the state file for for which the IPv4/6 address has not
been assigned.
Also this will fix the printing of assignments which have been declined
by the clients

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agoconfig: Fix RA interface config being overwritten
Hans Dedecker [Mon, 5 Dec 2016 08:57:12 +0000 (09:57 +0100)]
config: Fix RA interface config being overwritten

In case multiple dhcp uci sections are configured and one section contains
RA config while the other section does not; the RA interface config of the
first section will be overwritten by the second section.
Fix this by setting the default values for ra_management and ndp_proxy_routing
uci parameters when the interface is created and by removing the overwrite check

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agodhcpv6-ia : Fix static DHCPv6 assignments becoming non static
Hans Dedecker [Thu, 1 Dec 2016 13:24:24 +0000 (14:24 +0100)]
dhcpv6-ia : Fix static DHCPv6 assignments becoming non static

The valid_until parameter which is set to 0 for static DHCPv6
assignments was overwritten depending on the received DHCPv6 message
which turned the assignment into having a finite lifetime and thus not
static anymore.
Fix this by checking if the valid_until parameter holds infinite
lifetime before updating it.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agodhcpv6-ia: Fix assignment of static DHCPv6 leases
Hans Dedecker [Thu, 1 Dec 2016 13:24:23 +0000 (14:24 +0100)]
dhcpv6-ia: Fix assignment of static DHCPv6 leases

Fix assignment of static DHCPv6 leases which was broken
by commit 6c3bc0141dacc88992583d6f2cdc8a360df7422d.
At the same time fix lifetime check of existing assignments
having a finite lifetime

Fixes FS#309

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agocmake: Find libubox/uloop.h
Florian Fainelli [Sat, 2 Jul 2016 00:05:17 +0000 (17:05 -0700)]
cmake: Find libubox/uloop.h

Add a CMake FIND_PATH and INCLUDE_DIRECTORIES searching for
libubox/uloop.h. Some external toolchains which do not include standard
locations would fail to find the header otherwise.

Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
7 years agoodhcpd: Display infinite valid lifetime as -1
Hans Dedecker [Mon, 21 Nov 2016 13:42:16 +0000 (14:42 +0100)]
odhcpd: Display infinite valid lifetime as -1

Display infinite valid lifetime as -1 both in ubus
and statefile

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
8 years agoRespect interface "ignore" settings as documented.
Karl Palsson [Wed, 28 Sep 2016 16:32:41 +0000 (16:32 +0000)]
Respect interface "ignore" settings as documented.

The "ignore" option is correctly loaded.  Actually observe it as
documented.

Signed-off-by: Karl Palsson <karlp@etactica.com>
8 years agoenable loglevel setting via command line
Karl Palsson [Wed, 28 Sep 2016 16:32:39 +0000 (16:32 +0000)]
enable loglevel setting via command line

Currently the loglevel is hardcoded to LOG_WARNING, even though there is
debug log messages.  Allow setting the loglevel via cli option.
Include basic help text because we're adding command line options.

Signed-off-by: Karl Palsson <karlp@etactica.com>
8 years agodhcpv4: Adding DHCP client leasetime request support
Hans Dedecker [Thu, 17 Nov 2016 15:12:00 +0000 (16:12 +0100)]
dhcpv4: Adding DHCP client leasetime request support

Add support for DHCPv4 clients proposing a leasetime;
proposed leasetime will be accepted if it does not
exceed either the pool or configured lease leastime.
Further rework the duplicated leasetime logic which
was in place.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
8 years agodhcpv6-ia: Display infinite lifetime as INT32_MAX in state file
Hans Dedecker [Thu, 17 Nov 2016 15:11:59 +0000 (16:11 +0100)]
dhcpv6-ia: Display infinite lifetime as INT32_MAX in state file

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
8 years agoubus: Fix displayed valid paramater for both DHCPv4 and DHCPv6 lease
Hans Dedecker [Thu, 17 Nov 2016 15:11:58 +0000 (16:11 +0100)]
ubus: Fix displayed valid paramater for both DHCPv4 and DHCPv6 lease

Fix ubus valid parameter being displayed as a negative number;
also display infinite lifetime as INT32_MAX

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
8 years agodhcpv4: Keep DHCPv4 assignment lifetime value in sync with assigned leasetime
Hans Dedecker [Thu, 17 Nov 2016 15:11:57 +0000 (16:11 +0100)]
dhcpv4: Keep DHCPv4 assignment lifetime value in sync with assigned leasetime

Keep the valid_until assignment parameter in sync with the
leasetime assigned to the DHCP client when handling DHCP
request message.
This guarantees the contents of the ubus dhcp ipv4leases valid
parameter is in sync with the client leasetime

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
8 years agoconfig: Support infinite as DHCP pool leasetime value
Hans Dedecker [Thu, 17 Nov 2016 15:11:56 +0000 (16:11 +0100)]
config: Support infinite as DHCP pool leasetime value

Add support for infinite leasetime value; this can be done by
specifying "infinite" as leasetime value which is similar to
dnsmasq infinite leasetime support.
Specifying "infinite" as leasetime is valid for both the host
and dhcp uci sections.
A DHCPv4/DHCPv6 assignment is now considered infinite if valid_unil
holds the value 0.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
8 years agoCorrect a typo
Massimiliano Stucchi [Wed, 22 Jun 2016 08:22:41 +0000 (10:22 +0200)]
Correct a typo

8 years agoodhcpd: remove superfluous log output.
Karl Palsson [Thu, 22 Sep 2016 17:32:18 +0000 (17:32 +0000)]
odhcpd: remove superfluous log output.

Drop pointless syslog.  The single line just doubles the amount of lines
logged to syslog without adding any value.

Signed-off-by: Karl Palsson <karlp@etactica.com>
8 years agoAdd per-host leasetime support
Steven Barth [Thu, 19 May 2016 06:54:24 +0000 (08:54 +0200)]
Add per-host leasetime support

Patch by Daniel Dickinson

Signed-off-by: Steven Barth <steven@midlink.org>
8 years agoMerge pull request #68 from dedeckeh/bugfixes
Steven Barth [Sun, 31 Jan 2016 15:19:05 +0000 (16:19 +0100)]
Merge pull request #68 from dedeckeh/bugfixes

config: blobmsg_check_attr expects bool type as last argument

8 years agoconfig: blobmsg_check_attr expects bool type as last argument
Hans Dedecker [Tue, 15 Dec 2015 14:32:33 +0000 (15:32 +0100)]
config: blobmsg_check_attr expects bool type as last argument

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