project/odhcpd.git
5 years agodhcpv6-ia: fix compiler warning openwrt-18.06
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 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 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>
6 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>
6 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>
6 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>
6 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>
6 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>
6 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>
6 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>
6 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>
6 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>
6 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>
6 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>
6 years agoconfig: fix wrong assignment
Hans Dedecker [Fri, 22 Jun 2018 14:16:30 +0000 (16:16 +0200)]
config: fix wrong assignment

Detected by Coverity in CID1430899

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
6 years agodhcpv4: delay forced renew transaction start
Hans Dedecker [Thu, 21 Jun 2018 08:25:53 +0000 (10:25 +0200)]
dhcpv4: delay forced renew transaction start

Delay the start of the forced renew transaction start with a random delay
between 500 and 1000 ms. This avoids sending DHCP forced renew messages
in case the DHCP client starts sending discover messages triggered by
link state flap.
Also it distributes sending of DHCP forced renew messages to different clients
over an interval instead of sending DHCP forced renew messages in a burst mode.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
6 years agodhcpv4: fix DHCP address space logic
Hans Dedecker [Thu, 21 Jun 2018 14:36:29 +0000 (16:36 +0200)]
dhcpv4: fix DHCP address space logic

Don't use an IPv4 address which belongs to the force renew IP address
list as candidate for the DHCP address space calculation logic as
such addresses are installed by the forced renew logic to safeguard
IP connectivity during the forced renew message exchanges and thus
cannot be used to calculate the DHCP address space

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
6 years agodhcpv4: improve logging when sending DHCP messages
Hans Dedecker [Fri, 15 Jun 2018 12:30:18 +0000 (14:30 +0200)]
dhcpv4: improve logging when sending DHCP messages

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
6 years agoodhcpd: call handle_error when socket error can be retrieved
Hans Dedecker [Wed, 13 Jun 2018 20:15:51 +0000 (22:15 +0200)]
odhcpd: call handle_error when socket error can be retrieved

Detected by Coverity in CID1412300

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
6 years agodhcpv6: fix out of bounds write in handle_nested_message()
Hans Dedecker [Thu, 7 Jun 2018 20:36:29 +0000 (22:36 +0200)]
dhcpv6: fix out of bounds write in handle_nested_message()

Detected by Coverity in CID1412413

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
6 years agodhcpv6-ia: log renew messages as well
Hans Dedecker [Thu, 7 Jun 2018 15:33:27 +0000 (17:33 +0200)]
dhcpv6-ia: log renew messages as well

As the odhcpd log verbosity is configurable log renew messages as well.
Fixes logically dead code reported by Coverity in CID1412318

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
6 years agorouter: fix possible segfault in send_router_advert()
Hans Dedecker [Mon, 4 Jun 2018 20:07:13 +0000 (22:07 +0200)]
router: fix possible segfault in send_router_advert()

Detected by Coverity in CID1412349

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
6 years agoodhcpd: fix passing possible negative parameter
Hans Dedecker [Mon, 4 Jun 2018 19:49:52 +0000 (21:49 +0200)]
odhcpd: fix passing possible negative parameter

Prevent passing negative argument to read; detected by Coverity in CID1412381

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
6 years agotreewide: switch to C-code style comments
Hans Dedecker [Mon, 28 May 2018 10:26:19 +0000 (12:26 +0200)]
treewide: switch to C-code style comments

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
6 years agorouter: improve error checking
Hans Dedecker [Sun, 27 May 2018 20:18:25 +0000 (22:18 +0200)]
router: improve error checking

Improve error checking fixing resource leak detected by Coverity in CID
1430880.
Further fix unchecked return value reported by Coverity in CIDs 1430872,
14308391430831 and 1412382

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
6 years agonetlink: fix incorrect sizeof argument
Hans Dedecker [Sat, 26 May 2018 11:30:47 +0000 (13:30 +0200)]
netlink: fix incorrect sizeof argument

Fix incorrect sizeof arguments detetced by Coverity in CID 1430866 and
CID 1430893

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
6 years agodhcpv6: improve error checking in dhcpv6_setup_interface()
Hans Dedecker [Sat, 19 May 2018 20:37:27 +0000 (22:37 +0200)]
dhcpv6: improve error checking in dhcpv6_setup_interface()

Improve error checking fixing resource leakage detected by Coverity in
CID 1430880

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
6 years agoubus: fix invalid ipv6-prefix json
Mislav Novakovic [Mon, 21 May 2018 16:07:38 +0000 (18:07 +0200)]
ubus: fix invalid ipv6-prefix json

"ipv6-prefix": [
{
"<some ipv6 address>",
"preferred-lifetime": 37979,
"valid-lifetime": 48779,
"prefix-length": 63
}
],

json object is missing key, set address as key name.

Line up DHCPv4 lease json info by using key name "address"

Signed-off-by: Mislav Novakovic <mislav.novakovic@sartura.hr>
Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
6 years agondp: improve error checking
Hans Dedecker [Wed, 16 May 2018 19:57:31 +0000 (21:57 +0200)]
ndp: improve error checking

Improve error checking; fixes resource leak detected by Coverity
in CID 1430925

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
6 years agodhcpv4: fix error checking in dhcpv4_setup_interface()
Hans Dedecker [Wed, 16 May 2018 19:36:16 +0000 (21:36 +0200)]
dhcpv4: fix error checking in dhcpv4_setup_interface()

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
6 years agodhcpv4: fix out of bound access in dhcpv4_put
Hans Dedecker [Tue, 15 May 2018 20:22:30 +0000 (22:22 +0200)]
dhcpv4: fix out of bound access in dhcpv4_put

Detected by Coverity in CID 1433363 and 1432121

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
6 years agodhcpv4: improve error checking in dhcpv4_setup_interface()
Hans Dedecker [Mon, 7 May 2018 13:49:13 +0000 (15:49 +0200)]
dhcpv4: improve error checking in dhcpv4_setup_interface()

Improve error checking fixing resource leakage detected by Coverity in
CID 1433402

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
6 years agoodhcpd: fix strncpy bounds
Hans Dedecker [Thu, 3 May 2018 15:21:15 +0000 (17:21 +0200)]
odhcpd: fix strncpy bounds

Fix strncpy bounds as reported by Coverity in CID 1412278 and 1412293

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
6 years agodhcpv6-ia: keep tentative assignments alive for a short time
Hans Dedecker [Mon, 23 Apr 2018 11:32:19 +0000 (13:32 +0200)]
dhcpv6-ia: keep tentative assignments alive for a short time

Assign tentative assignments a lifetime of 60 seconds; this will assure
the assignment is seen as valid during lookup when receiving a later
REQUEST from the DHCPv6 client.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
6 years agodhcpv6-ia: make assignment lookup more strict
Hans Dedecker [Mon, 23 Apr 2018 09:56:27 +0000 (11:56 +0200)]
dhcpv6-ia: make assignment lookup more strict

Whe doing an assignment lookup do a strict match between the assignment
IAID and the IAID received form the client in case the BOUND or TENTATIVE
assignment flags are set.
This fixes a wrong assignment being returned for a client which uses a
different IAID than the IAID used in a previous DHCPv6 exchange.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
6 years agorouter: fix managed address configuration setting
Hans Dedecker [Wed, 18 Apr 2018 12:09:47 +0000 (14:09 +0200)]
router: fix managed address configuration setting

Don't announce managed address configuration in case DHCPv6 is disabled

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
6 years agorouter: improve RFC7084 compliancy
Hans Dedecker [Mon, 9 Apr 2018 15:01:45 +0000 (17:01 +0200)]
router: improve RFC7084 compliancy

Send Router Information Option as well for prefixes with length 64 in order
to be compliant with L-3 in RFC7084: An IPv6 CE router must advertise
itself as a router for the delegated prefixes using the "Route Information
Option".

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
6 years agodhcpv6-ia: don't always send reconf accept option (FS#1377)
Hans Dedecker [Tue, 20 Feb 2018 10:23:25 +0000 (11:23 +0100)]
dhcpv6-ia: don't always send reconf accept option (FS#1377)

Send reconfigure accept and reconfigure key authentication protocol options
only if the client indicates it supports reconfigure accept as descibed
in RFC3315 paragraph 21.5.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
6 years agoodhcpd: Replace strerror(errno) with %m format
Rosen Penev [Sun, 17 Dec 2017 03:55:04 +0000 (19:55 -0800)]
odhcpd: Replace strerror(errno) with %m format

Saves a few bytes.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
6 years agoSupport muliple RAs on single interface
Pierre Pfister [Fri, 8 Dec 2017 14:15:02 +0000 (15:15 +0100)]
Support muliple RAs on single interface

IETF is moving toward implementing IPv6 multihoming by sending
multiple RAs on a single interface:
- draft-ietf-intarea-provisioning-domains-00
- draft-ietf-rtgwg-enterprise-pa-multihoming-02

odhcpd supports configuration of multiple software interfaces
on the same physical interface, which already advertises
multiple RAs, but had two issues:
- Each RA includes all the prefixes available on the interface.
- Replies to sollicits with a single RA.

This patch introduces the prefix_filter configuration parameter
which allows filtering prefixes that are sent in a given RA,
and fixes the sollicit code in order to reply with all the RAs
that are configured on a given interface.

Signed-off-by: Pierre Pfister <ppfister@cisco.com>
6 years agodhcpv4: notify DHCP ACK and RELEASE via ubus
Hans Dedecker [Tue, 28 Nov 2017 14:08:27 +0000 (15:08 +0100)]
dhcpv4: notify DHCP ACK and RELEASE via ubus

If the ubus object has any subscription notify DHCP ACK and DHCP RELEASE
events using ubus notifications.

Signed-off-by: Borja Salazar <borja.salazar@fon.com>
Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
6 years agodhcpv6: fix compile issues when CER-ID extension is enabled
Hans Dedecker [Sat, 25 Nov 2017 16:42:00 +0000 (17:42 +0100)]
dhcpv6: fix compile issues when CER-ID extension is enabled

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
6 years agondp: add switch/case fallthrough comments
Hans Dedecker [Tue, 21 Nov 2017 13:48:14 +0000 (14:48 +0100)]
ndp: add switch/case fallthrough comments

Fixes gcc 7 build errors

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
6 years agodhcpv4: make DHCPv4 support compiletime configurable
Hans Dedecker [Thu, 9 Nov 2017 15:09:51 +0000 (16:09 +0100)]
dhcpv4: make DHCPv4 support compiletime configurable

Make DHCPv4 support compile time configurable; avoids DHCPv4 functionality
overlap with other packages.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
6 years agotreewide: rework handling of netlink events
Hans Dedecker [Tue, 17 Oct 2017 14:23:35 +0000 (16:23 +0200)]
treewide: rework handling of netlink events

Rework the handling of netlink events by letting the different
modules ndp, ra, dhcpv6 and dhcpv4 install netevent handlers.
The installed netevent handlers are called by the netlink logic
passing an event indication together with event data.
Each netevent handler implements its own event logic; this
makes the code more modular and less complex by moving all
netlink code to netlink.c
While at it rename ia_addr and ia_addr_len into addr6 and
addr6_len respectively

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agotreewide: add netlink file
Hans Dedecker [Fri, 13 Oct 2017 13:35:29 +0000 (15:35 +0200)]
treewide: add netlink file

First step in moving netlink code to netlink.c by
moving netlink code from odhcpd.c to netlink.c

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agotreewide: align function naming
Hans Dedecker [Fri, 13 Oct 2017 10:09:28 +0000 (12:09 +0200)]
treewide: align function naming

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agodhcpv4: fix memset compile issue
Hans Dedecker [Wed, 13 Sep 2017 13:56:42 +0000 (15:56 +0200)]
dhcpv4: fix memset compile issue

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agodhcpv4: rework assignment lookup
Hans Dedecker [Tue, 12 Sep 2017 09:03:37 +0000 (11:03 +0200)]
dhcpv4: rework assignment lookup

When receiving a DHCPv4 message use find_assignment_by_hwaddr to find
an assignment as only one entry can be present in the assignment table
for a given mac address.
While at it pass requested address by the client as an uint32_t type
to clean up the code.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agodhcpv4: cleanup dhcpv4_test usage
Hans Dedecker [Tue, 12 Sep 2017 08:52:12 +0000 (10:52 +0200)]
dhcpv4: cleanup dhcpv4_test usage

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agodhcpv4: rework lease expire handling logic
Hans Dedecker [Tue, 12 Sep 2017 08:31:13 +0000 (10:31 +0200)]
dhcpv4: rework lease expire handling logic

Don't rely on incoming DHCPv4 messages to trigger the lease expire
detection logic but rather use a periodic timer which checks every
second if a lease is expired

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agodhcpv4: force renew nonce authentication support
Hans Dedecker [Thu, 6 Jul 2017 07:41:10 +0000 (09:41 +0200)]
dhcpv4: force renew nonce authentication support

Support force renew nonce authentication support in the DHCPv4 server as
described in RFC3203 and RFC6704.
The interface uci arameter dhcpv4_forcereconf allows to supports DHCPv4
clients which support force renew without authentication.
While at it align network byte order logic for simplicity.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agodhcpv4: avoid segfault when there's no IPv4 prefix
Hans Dedecker [Mon, 3 Jul 2017 14:39:21 +0000 (16:39 +0200)]
dhcpv4: avoid segfault when there's no IPv4 prefix

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agondp: detect ifindex changes via interface netlink events
Hans Dedecker [Fri, 11 Aug 2017 14:05:01 +0000 (16:05 +0200)]
ndp: detect ifindex changes via interface netlink events

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agoubus: display accept reconf status for DHCPv6 assignments
Hans Dedecker [Mon, 11 Sep 2017 13:01:06 +0000 (15:01 +0200)]
ubus: display accept reconf status for DHCPv6 assignments

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agotreewide: replace RELAYD prefix naming in macros
Hans Dedecker [Wed, 6 Sep 2017 12:51:09 +0000 (14:51 +0200)]
treewide: replace RELAYD prefix naming in macros

Remove the unfortunate RELAYD naming in the different macros

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agodhcpv4: fix possible segfault when lease is not created
Hans Dedecker [Thu, 17 Aug 2017 10:16:07 +0000 (12:16 +0200)]
dhcpv4: fix possible segfault when lease is not created

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agodhcpv4: dhcpv4: move interface lease list insertion out of dhcpv4_assign
Hans Dedecker [Thu, 17 Aug 2017 09:16:00 +0000 (11:16 +0200)]
dhcpv4: dhcpv4: move interface lease list insertion out of dhcpv4_assign

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agondp: use IPv4 address list when comparing IPv4 addresses
Hans Dedecker [Wed, 16 Aug 2017 09:55:39 +0000 (11:55 +0200)]
ndp: use IPv4 address list when comparing IPv4 addresses

Use IPv4 address list in check_addr_updates which fixes possible segfault
as IPv6 address list was used by mistake.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agodhcpv6-ia: rework reconfigure accept logic
Hans Dedecker [Thu, 10 Aug 2017 13:44:09 +0000 (15:44 +0200)]
dhcpv6-ia: rework reconfigure accept logic

Rework reconfigure accept retransmission logic; every DHCPv6 assignment
has its own reconfigure accept timer now making sure the timeout and
retransmission behavior is in line with RFC3315 paragraph 19.1.2.

While at it rename the original reconf_timer into valid_until_timeout as
it will only check now the lifetime of the assignments.

Set reconf_cnt to INT_MAX for every assignment which belongs to the same
client identifier; before the reconf_cnt of the first handled assignment
was set by mistake breaking the retransmission logic.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agotreewide: rework IPv4 address logic
Hans Dedecker [Mon, 3 Jul 2017 14:39:21 +0000 (16:39 +0200)]
treewide: rework IPv4 address logic

Align IPv4 address logic with IPv6 by caching per interface the assigned
IPv4 addresses. This allows to get rid of different ioctl calls in the
DHCPv4 logic to retrieve the IPv4 address and netmask in use by an
interface.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agodhcpv6: assign all viable DHCPv6 addresses by default (FS#402, FS#524)
Hans Dedecker [Wed, 2 Aug 2017 20:32:08 +0000 (22:32 +0200)]
dhcpv6: assign all viable DHCPv6 addresses by default (FS#402, FS#524)

Some client implementations expect DHCPv6 addresses to be assigned for
every prefix present in a RA as reported in FS#524; if not done the
client implementations spam the DHCPv6 server with SOLICIT messages
trying to get an DHCPv6 address for every prefix.
When ra_managed is set to 1 and an ULA prefix is configured; the DHCPv6
server will only assign an ULA DHCPv6 addresses which possibly leads to
DNS issues.

Fix these problems by providing dhcpv6_assignall config option which
assigns all viable DHCPv6 addresses to a client by default.
This is a trade off as it means client implementations will be assigned
more IPv6 addresses and lose the ability to quickly renumber clients
which don't support reconfigure accept in case of wan prefix change

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agotreewide: reflect managed mode is related to RA
Hans Dedecker [Tue, 1 Aug 2017 21:14:33 +0000 (23:14 +0200)]
treewide: reflect managed mode is related to RA

Improve code readability by renaming managed into ra_managed and
define the according ra_managed flags.
This will help to better understand the ra_managed logic as defined
in the README file.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agondp: optimize check_addr6_updates code
Hans Dedecker [Tue, 4 Jul 2017 09:14:54 +0000 (11:14 +0200)]
ndp: optimize check_addr6_updates code

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agondp: fix syslog tracing for netlink neigbor and address events
Hans Dedecker [Tue, 4 Jul 2017 09:10:43 +0000 (11:10 +0200)]
ndp: fix syslog tracing for netlink neigbor and address events

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agotreewide: rework logic to retrieve IPv6 interface addresses
Hans Dedecker [Thu, 29 Jun 2017 13:35:21 +0000 (15:35 +0200)]
treewide: rework logic to retrieve IPv6 interface addresses

Retrieve IPv6 interface addresses when the interface gets created; this
allows to get rid of the IPv6 address dump logic in ndp.c.
Add IPv4 address support in odhcp_ipaddr struct.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agorouter: use enum to specify order and index of iov struct
Hans Dedecker [Thu, 29 Jun 2017 12:02:32 +0000 (14:02 +0200)]
router: use enum to specify order and index of iov struct

Improve code maintainability by using enum to order and index iov struct

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agotreewide: rework code to get rid of fixed IPv6 address arrays
Hans Dedecker [Wed, 28 Jun 2017 13:40:05 +0000 (15:40 +0200)]
treewide: rework code to get rid of fixed IPv6 address arrays

Rework code to get rid of RELAYD_MAX_PREFIXES and RELAYD_MAX_ADDRS
by using dynamic IPv6 address array allocation.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agoconfig: rework code to get rid of IFNAMSIZ usage
Hans Dedecker [Tue, 27 Jun 2017 09:33:08 +0000 (11:33 +0200)]
config: rework code to get rid of IFNAMSIZ usage

Get rid of IFNAMSIZE usage for interface name and ifname variables

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
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>