oweals/netifd.git
6 years agosystem-linux: fix segfault on error in system_add_ip6_tunnel()
Hans Dedecker [Sat, 14 Apr 2018 18:58:42 +0000 (20:58 +0200)]
system-linux: fix segfault on error in system_add_ip6_tunnel()

Detected by Coverity in CID 1430884

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
6 years agohandler: fix resource leak on error in netifd_init_script_handlers()
Hans Dedecker [Thu, 12 Apr 2018 20:46:35 +0000 (22:46 +0200)]
handler: fix resource leak on error in netifd_init_script_handlers()

Detected by Coverity in CID 1412486

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
6 years agosystem-linux: remove unnecessary open call in system_if_dump_info()
Hans Dedecker [Thu, 12 Apr 2018 20:36:38 +0000 (22:36 +0200)]
system-linux: remove unnecessary open call in system_if_dump_info()

Detected by coverity in CID 1329735

6 years agosystem-linux: fix memory leak on error in system_add_vxlan()
Hans Dedecker [Thu, 12 Apr 2018 20:14:52 +0000 (22:14 +0200)]
system-linux: fix memory leak on error in system_add_vxlan()

Detected by coverity in CID 1412449

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
6 years agointerface-ip: fix memory leak on error in interface_update_prefix_assignments()
Hans Dedecker [Thu, 12 Apr 2018 20:08:18 +0000 (22:08 +0200)]
interface-ip: fix memory leak on error in interface_update_prefix_assignments()

Detected by coverity in CID 141267

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
6 years agointerface: fix "ifup-failed" hotplug event handling
Martin Schiller [Tue, 10 Apr 2018 04:21:39 +0000 (06:21 +0200)]
interface: fix "ifup-failed" hotplug event handling

The ifup-failed event should only be triggered when the former
interface state is IFS_SETUP.

Otherwise, there will also be an ifup-failed event in the
IFS_TEARDOWN stateif you do an manual ifdown <IFC>.

Signed-off-by: Martin Schiller <ms@dev.tdt.de>
6 years agointerface-ip: fix memory leak in interface_ip_add_target_route()
Hans Dedecker [Sun, 1 Apr 2018 10:21:38 +0000 (12:21 +0200)]
interface-ip: fix memory leak in interface_ip_add_target_route()

Commit 9c8d781 introduced a memory leak in interface_ip_add_target_route
in case interface_ip_find_addr_target returns true for a given address
by not freeing the previously allocated route.
While at it rework the logic so a host route is only allocated when it's
really required.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
6 years agonetifd: return the interface for locally addressable host dependencies (FS#1452)
Felix Fietkau [Tue, 27 Mar 2018 09:28:54 +0000 (11:28 +0200)]
netifd: return the interface for locally addressable host dependencies (FS#1452)

Fixes an issue where interfaces with host dependencies that resolve to a
local subnet stay down.

Fixes: 1f5a29c3de6e ("ip: do not add local routes for host dependencies")
Signed-off-by: Felix Fietkau <nbd@nbd.name>
6 years agointerface-ip: fix route selection for host dependencies
Felix Fietkau [Tue, 13 Mar 2018 12:05:28 +0000 (13:05 +0100)]
interface-ip: fix route selection for host dependencies

In order to find the best match, allow overriding the last found entry
if route->mask for the new entry is bigger than the one from the previous
entry.

Patch submitted by 'Mikael' in FS#1358

Signed-off-by: Felix Fietkau <nbd@nbd.name>
6 years agodevice: add support for setting the isolate options for bridge ports
Felix Fietkau [Tue, 13 Mar 2018 11:52:43 +0000 (12:52 +0100)]
device: add support for setting the isolate options for bridge ports

Signed-off-by: Felix Fietkau <nbd@nbd.name>
6 years agoip: do not add local routes for host dependencies
Felix Fietkau [Wed, 7 Mar 2018 22:14:57 +0000 (23:14 +0100)]
ip: do not add local routes for host dependencies

This avoids creating invalid routes in cases where another daemon is
handling local routes for an interface, e.g. on mesh interfaces

Signed-off-by: Felix Fietkau <nbd@nbd.name>
6 years agoremove rps/xps configuration support
Felix Fietkau [Mon, 26 Feb 2018 11:21:00 +0000 (12:21 +0100)]
remove rps/xps configuration support

It is overly complex, yet does not cover common scenarios very well.
It will be replaced with a simpler shell script that provides a better
default policy

Signed-off-by: Felix Fietkau <nbd@nbd.name>
6 years agonetifd-proto: add proto_config_add_array wrapper
Hans Dedecker [Mon, 5 Feb 2018 08:57:47 +0000 (09:57 +0100)]
netifd-proto: add proto_config_add_array wrapper

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
6 years agosystem-linux: VXLAN: add options to enable and disable UDP checksums
Matthias Schiffer [Wed, 24 Jan 2018 12:21:44 +0000 (13:21 +0100)]
system-linux: VXLAN: add options to enable and disable UDP checksums

Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net>
6 years agoproto: allow dumping protocol handlers without config_params
Olof Sivertsson [Wed, 3 Jan 2018 09:35:13 +0000 (10:35 +0100)]
proto: allow dumping protocol handlers without config_params

When ubus invokes proto_dump_handlers, and a struct proto_handler has
been added with a NULL config_params, a segmentation fault occurs.

Avoid this segmentation fault by checking for a NULL config_params
before further access.

Signed-off-by: Olof Sivertsson <olof.sivertsson@zenterio.com>
6 years agointerface-ip: harden eui64 IPv6 prefix address generation
Hans Dedecker [Thu, 14 Dec 2017 13:13:35 +0000 (14:13 +0100)]
interface-ip: harden eui64 IPv6 prefix address generation

Check if a mac address is actually present when generating an eui64 based
IPv6 address; in case of failure bail out.
At the same time make sure the active mac address is used as input for the
eui64 based IPv6 address and guarantee IPv6 prefix address generation is
based on the actual config by resetting the IPv6 prefix address in the
assignment structure when it gets deleted.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
6 years agointerface-ip: fix race condition in IPv6 prefix address generation
Hans Dedecker [Thu, 14 Dec 2017 13:13:34 +0000 (14:13 +0100)]
interface-ip: fix race condition in IPv6 prefix address generation

Don't generate an IPv6 prefix address without taking into account the
interface state. In case eui64 is configured to generate the ifaceid this
could fail as the layer3 device mac address could not yet be available if
the interface is not yet in setup or up state.
While at it remove the interface metric assignment as this is already done
by the function interface_set_route_info.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
6 years agohandler: replace is_error() helper with NULL check
Alexandru Ardelean [Fri, 8 Dec 2017 14:22:13 +0000 (16:22 +0200)]
handler: replace is_error() helper with NULL check

The `is_error()` is just a macro that checks
that object is NULL (which is considered an error
in libjson-c terminology).

Newer libjson-c versions have deprecated this.

Signed-off-by: Alexandru Ardelean <ardeleanalex@gmail.com>
7 years agointerface-ip: add missing IPv6 policy rule
Hans Dedecker [Thu, 16 Nov 2017 14:42:41 +0000 (15:42 +0100)]
interface-ip: add missing IPv6 policy rule

Commit 2f31bff38d4dc2f36006ded6b8a7d039cb569eaa added interface routing
table support; as a result for IPv6 the prefix route linked to the IPv6
address is added to the specified IPv6 interface routing table.
In order to route traffic having as destination the IPv6 prefix a policy
rule is required using the prefix destination as policy so the traffic is
passed to the correct routing table.
The IPv6 prefix address logic was not installing this policy rule effectively
breaking routing when trying to reach a global or ULA IPv6 address in the
lan from either the device or another wan device.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agoproto: add point-to-point IPv4 address config support (FS#1037)
Hans Dedecker [Tue, 17 Oct 2017 20:16:43 +0000 (22:16 +0200)]
proto: add point-to-point IPv4 address config support (FS#1037)

Add config support support for point-to-point IPv4 addresses by providing
the uci parameter ptpaddr. This allows to support a gateway being in a
different subnet than the assigned IP by modeling the local IP having a
point-to-point address.
This is similar to the point-to-point IPv4 address support already present
for the protocol handlers.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
Tested-by: Stijn Tintel <stijn@linux-ipv6.be>
7 years agoubus: display the point-to-point IPv4 address
Hans Dedecker [Tue, 17 Oct 2017 20:16:44 +0000 (22:16 +0200)]
ubus: display the point-to-point IPv4 address

Display the point-to-point IPv4 address as well when dumping
the IP address list in ubus.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agoubus: fix ubus error code on reload failure
Hans Dedecker [Sat, 7 Oct 2017 17:46:44 +0000 (19:46 +0200)]
ubus: fix ubus error code on reload failure

Return the more approriate error code UBUS_STATUS_NOT_FOUND in case
network reload fails

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agoconfig: suppress error if no wireless config present (FS#1030)
Hans Dedecker [Fri, 6 Oct 2017 14:56:42 +0000 (16:56 +0200)]
config: suppress error if no wireless config present (FS#1030)

Wireless config is optional as not all targets have a wireless interface;
therefore don't report an error if the wireless config is missing so
network reload is not reporting an error to the user.
While at it use netifd_log_message to print an error if the config cannot
be loaded.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agosystem-linux: add support for hotplug event 'move'
Martin Schiller [Thu, 28 Sep 2017 08:32:28 +0000 (10:32 +0200)]
system-linux: add support for hotplug event 'move'

If you rename a network interface, there is a move uevent
invoked instead of remove/add.

This patch adds support for this kind of event.

Signed-off-by: Martin Schiller <ms@dev.tdt.de>
Acked-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agosystem-linux: parse map-e fmrs parameters as nested data json object
Hans Dedecker [Sun, 27 Aug 2017 19:48:28 +0000 (21:48 +0200)]
system-linux: parse map-e fmrs parameters as nested data json object

Parse map-e fmrs parameters IPv6 prefix, IPv4 prefix, ealen and offset
as array elements nested in a data json object.
At the same time remove the now obsolete TUNNEL_ATTR_FMRS tunnel attribute.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agoallow setting rps/xps defualt values via uci
John Crispin [Tue, 22 Aug 2017 07:10:58 +0000 (09:10 +0200)]
allow setting rps/xps defualt values via uci

Signed-off-by: John Crispin <john@phrozen.org>
7 years agosystem: remove unused 6rd tunnel attributes
Hans Dedecker [Mon, 21 Aug 2017 17:32:25 +0000 (19:32 +0200)]
system: remove unused 6rd tunnel attributes

Commit 7573880ac042c6e5c8d48b1ad83d357b5e02743b added support for 6rd
attributes as a nested json data object which makes the attributes
TUNNEL_ATTR_6RD_PREFIX and TUNNEL_ATTR_6RD_RELAY_PREFIX unused

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agonetifd: allow negative neighlocktime values
Alin Năstac [Thu, 17 Aug 2017 12:12:05 +0000 (14:12 +0200)]
netifd: allow negative neighlocktime values

When -1 is written in /proc/sys/net/ipv4/neigh/<iface>/locktime,
kernel disables ARP trashing protection. A value of 0 does not completely
disable this protection, a second ARP update being discarded if it
is processed during the same jiffie as the first update.

Signed-off-by: Alin Nastac <alin.nastac@gmail.com>
7 years agosystem-linux: parse ipv6 specific tunnel settings as nested data json
Hans Dedecker [Tue, 15 Aug 2017 20:00:14 +0000 (22:00 +0200)]
system-linux: parse ipv6 specific tunnel settings as nested data json
object

7 years agosystem-linux: fix GRE ikey/okey endianness
Stijn Tintel [Fri, 21 Jul 2017 18:57:47 +0000 (20:57 +0200)]
system-linux: fix GRE ikey/okey endianness

The kernel expects IFLA_GRE_IKEY and IFLA_GRE_OKEY to be in network byte
order, so convert the values from host byte order.

Fixes ikey/okey on little endian systems.

Signed-off-by: Stijn Tintel <stijn@linux-ipv6.be>
7 years agonetifd: Fix printf calls + function declarations.
Rosen Penev [Mon, 26 Jun 2017 00:18:06 +0000 (17:18 -0700)]
netifd: Fix printf calls + function declarations.

cppcheck found printf functions with signed instead of unsigned
formats. Fix those as well as some non-matching function
declarations.

Signed-off by: Rosen Penev <rosenp@gmail.com>

7 years agoubus: remove superfluous error check in netifd_add_dynamic
Hans Dedecker [Tue, 13 Jun 2017 11:33:56 +0000 (13:33 +0200)]
ubus: remove superfluous error check in netifd_add_dynamic

Check for main device and main device having default config for a dynamic
interface was orginally added in commit 266d92dd83bd5bfe520f3e2838794bf9bb827c07
with as purpose to set the device config. The latter was later removed in
commit 4bf89afc22b43d5bd155d32d3998348a77179c1a which makes the device checks
superfluous.

Also not all interfaces have a main device (eg tunnel interfaces) resulting
into netifd_add_dynamic returning an error code when such interfaces are added.
As an example 6rd interfaces dynamically added by the DHCP script the log
messages are cluttered with the trace 'wan (7803): Command failed: Unknown error'
after each DHCP renew.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agoiprule: coding style line up
Hans Dedecker [Sun, 11 Jun 2017 13:08:19 +0000 (15:08 +0200)]
iprule: coding style line up

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agoiprule: Add option to suppress unspecific routing lookups
Stefan Tomanek [Wed, 7 Jun 2017 10:47:04 +0000 (12:47 +0200)]
iprule: Add option to suppress unspecific routing lookups

After applying this patch, policy routing rules can be employed that ignore
parts of a routing table. The following config snippet ignores routing lookups
from the specified main routing table yielding the default route, passing the
lookup process on to the next rule (that might provide a special default route
for marked packets):

config rule
option priority 10
# check main routing table first, but ignore default route result
option lookup main
option suppress_prefixlength 0

config rule
option priority 11
# use special routing table for marked packets
# (unless already consumed by previous rule)
option mark 0xFF
option lookup 100

The result is a ruleset like this (only visible using the full 'ip' binary):

 # ip rule
 0: from all lookup local
 10: from all lookup main suppress_prefixlength 0
 11: from all fwmark 0xff lookup 100
 32766: from all lookup main
 32767: from all lookup default
 #

Signed-off-by: Stefan Tomanek <stefan.tomanek@wertarbyte.de>
7 years agosystem-linux: fix 6rd regression
Hans Dedecker [Sat, 27 May 2017 11:07:33 +0000 (13:07 +0200)]
system-linux: fix 6rd regression

Fix 6rd regression introduced in commit 7573880ac042c6e5c8d48b1ad83d357b5e02743b

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agosystem-linux: parse 6rd specific settings as nested json data object
Hans Dedecker [Fri, 19 May 2017 10:05:55 +0000 (12:05 +0200)]
system-linux: parse 6rd specific settings as nested json data object

Parse 6rd specific settings prefix, relay-prefix as nested json data objects.
At the same time improve 6rd error handling.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agosystem-linux: remove redundant check for strtoul() return value
Khem Raj [Fri, 19 May 2017 00:02:14 +0000 (17:02 -0700)]
system-linux: remove redundant check for strtoul() return value

Fixes
system-linux.c:1998:33: error: comparison of unsigned expression >= 0 is always true [-Werror,-Wtautological-compare]

Signed-off-by: Khem Raj <raj.khem@gmail.com>
7 years agobuild: disable unknown warning option error in clang
Felix Fietkau [Tue, 9 May 2017 10:56:07 +0000 (12:56 +0200)]
build: disable unknown warning option error in clang

Signed-off-by: Felix Fietkau <nbd@nbd.name>
7 years agointerface: add new "ifup-failed" hotplug event
Martin Schiller [Fri, 31 Mar 2017 06:31:39 +0000 (08:31 +0200)]
interface: add new "ifup-failed" hotplug event

This hook makes it possible to do some helper work in hotplug scripts
when a connection is not established successfully.

example: try several username/passwords from a pool to establish a
pppoe or wwan connection by replacing the configured values of the
connection in a hotplug script.

Signed-off-by: Martin Schiller <ms@dev.tdt.de>
7 years agobridge: reset primary only after marking the member not present
Alex Oprea [Mon, 8 May 2017 14:30:13 +0000 (16:30 +0200)]
bridge: reset primary only after marking the member not present

Run the bridge_reset_primary function only after the member being removed
has been marked as not present.
This change prevents the bridge_reset_primary function from choosing the
member being removed as the new primary member.

Signed-off-by: Alex Oprea <alex.oprea@inteno.se>
7 years agobuild: suppress format truncation warnings to avoid errors with gcc7
Felix Fietkau [Thu, 4 May 2017 13:49:53 +0000 (15:49 +0200)]
build: suppress format truncation warnings to avoid errors with gcc7

Signed-off-by: Felix Fietkau <nbd@nbd.name>
7 years agoubus: add interface method to trigger renew event
Matthias Schiffer [Wed, 12 Apr 2017 17:53:20 +0000 (19:53 +0200)]
ubus: add interface method to trigger renew event

Not all topology or connectivity changes may be detected by netifd,
depending on the underlying technology (e.g. VPN software); this adds a way
to explicitly trigger a renew.

Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net>
Acked-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agosystem-linux: allow "throw" route type
Matthias Schiffer [Fri, 14 Apr 2017 00:24:08 +0000 (02:24 +0200)]
system-linux: allow "throw" route type

system_rtn_aton() was already parsing "throw" correctly, but system_rt()
did now allow it.

Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net>
7 years agonetifd: propagate error code on netifd_reload()
Alexandru Ardelean [Mon, 27 Mar 2017 06:35:04 +0000 (09:35 +0300)]
netifd: propagate error code on netifd_reload()

The context is that we generate some of the UCI config
for netifd via scripts/programs.

Every once in a while, there's a goof when doing that
UCI generation, and netifd prints out the error at
stderr, but returns 0 (success) err-code.

This change will fail the ubus call if UCI config
is invalid or missing for /etc/config/network.

Signed-off-by: Alexandru Ardelean <ardeleanalex@gmail.com>
Acked-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agointerface-ip: fix device name for IPv6 link-local DNS server
Hans Dedecker [Mon, 3 Apr 2017 07:47:08 +0000 (09:47 +0200)]
interface-ip: fix device name for IPv6 link-local DNS server

Commit 235a02424c3ab1b59308895c4f00395dacf2557c adds support for IPv6 link-local
DNS server by appending the device name; however the interface ifname parameter
does not always contain the layer 3 device name (e.g it can hold the aliased
interface name)
Fix this by passing the device name of the referenced layer 3 device.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agointerface-ip: set prefix indicator flag when IPv6 prefix lifetime changes
Hans Dedecker [Thu, 9 Mar 2017 16:33:00 +0000 (17:33 +0100)]
interface-ip: set prefix indicator flag when IPv6 prefix lifetime changes

Trigger interface update event when IPv6 prefix lifetime changes by setting
the prefix indicator flag to inform external subsystems (eg hnetd) about IPv6
prefix lifetime changes.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agosystem-linux: parse vti specific settings as nested json data object
Hans Dedecker [Tue, 14 Mar 2017 20:36:39 +0000 (21:36 +0100)]
system-linux: parse vti specific settings as nested json data object

Parse vti specific settings ikey and okey as nested json data object.
At the same time remove the now obsolete TUNNEL_ATTR_INFO attribute.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agosystem-linux: parse gre specific settings as nested json data object
Hans Dedecker [Tue, 14 Mar 2017 20:36:38 +0000 (21:36 +0100)]
system-linux: parse gre specific settings as nested json data object

Parse gre specific settings ikey, okey, icsum, ocsum, iseqno and oseqno
as nested json data object

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agosystem-linux: add VXLAN support
Matthias Schiffer [Tue, 28 Feb 2017 09:57:05 +0000 (10:57 +0100)]
system-linux: add VXLAN support

VXLAN shares many attributes with the tunnel devices, so it is implemented
as a new tunnel type. The 'remote' attribute can be used for an unicast
peer or a multicast group.

The IANA-assigned port 4789 is used by default, instead of the non-standard
port Linux defaults to.

Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net>
Acked-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agonetifd: Add option to configure locktime for each device
Alin Năstac [Tue, 17 Jan 2017 15:16:04 +0000 (16:16 +0100)]
netifd: Add option to configure locktime for each device

The UCI parameter neighlocktime allows to control the hardware
address to IP mapping lock time in the IPv4 neighbour table.

The IPv6 lock time was not set because it is not used at all in any
kernel versions, hardware address override being controlled in this case
by the override flag present in the NA packet.

Signed-off-by: Alin Nastac <alin.nastac@gmail.com>
7 years agointerface: add prefix assignment priority support
Hans Dedecker [Tue, 31 Jan 2017 15:46:15 +0000 (16:46 +0100)]
interface: add prefix assignment priority support

In case of prefix delegation prefixes are assigned to one or more
configured downstream interfaces. The delegated prefix length in
combination with the assignment length of the downstream interfaces
determines the number of subnets which can be allocated from the
delegated prefix.
The interface ip6weight parameter allows to prioritize the allocation
of subnets to interfaces in case of multiple configured downstream
interfaces.

The order of interface prefix assignment from a delegated prefix is
based on the following parameters:
- Primary key is prefix assignment based on the configured interface ip6hint
- Secondary key is the requested downstream interface prefix length,
  interfaces configured with the smallest ip6hint will be assigned first
- Third key is the assigned interface ip6weight in case of equal prefix
  assignment length; interfaces having the highest ip6weight will be
  assigned first
- Finally the alphabetical order of the interfaces in case of equal
  ip6weight

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name> [cleanup]
7 years agodevice: add veth support
Matthias Schiffer [Fri, 10 Feb 2017 05:30:17 +0000 (06:30 +0100)]
device: add veth support

The veth config code mostly handles the primary interface of a veth pair,
the secondary interface is not explicitly referenced and will be found as
an unrelated interface after the pair has been created.

This doesn't only allow us to keep the veth code simple (and similar to
existing device handlers), but will also avoid complicating handling
unnecessarily in case the secondary interface is moved into another network
namespace.

Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net>
7 years agowireless: fix _wireless_add_process
Günther Kelleter [Wed, 8 Feb 2017 15:47:22 +0000 (16:47 +0100)]
wireless: fix _wireless_add_process

The pid is in $1, not $pid.
Use proper test condition for nonmatching exe warning.

Signed-off-by: Günther Kelleter <guenther.kelleter@devolo.de>
7 years agotreewide: fix white space errors
Hans Dedecker [Tue, 31 Jan 2017 08:30:27 +0000 (09:30 +0100)]
treewide: fix white space errors

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agointerface-ip: route proto config support (FS#170)
Hans Dedecker [Thu, 19 Jan 2017 14:59:54 +0000 (15:59 +0100)]
interface-ip: route proto config support (FS#170)

Route proto support is usefull when using route distribution
via a routing daemon.
The route proto parameter can be specified via the route proto
uci config parameter, it can hold a numerical value or the string
values unspec, kernel, boot, static or a string present in
/etc/iproute2/rt_protos.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agodevice: fix DEV_OPT_SENDREDIRECTS definition
Hans Dedecker [Tue, 17 Jan 2017 09:10:50 +0000 (10:10 +0100)]
device: fix DEV_OPT_SENDREDIRECTS definition

Commit abf52371db75eb449f12209ca1b7ffaa9d2baa22 adds sendredirects
device config support by defining DEV_OPT_SENDREDIRECTS. Fix definition
overlap of DEV_OPT_SENREDIRECTS with DEV_OPT_LEARNING.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agobridge: disable IGMP snooping by default
Felix Fietkau [Fri, 13 Jan 2017 12:03:18 +0000 (13:03 +0100)]
bridge: disable IGMP snooping by default

Lots of configurations have triggered various issues in this feature,
any many people don't even need this.

Let's disable it by default until it has become more stable

Signed-off-by: Felix Fietkau <nbd@nbd.name>
7 years agonetifd: Add sendredirects config support
Daniel Golle [Fri, 12 Feb 2016 20:04:00 +0000 (22:04 +0200)]
netifd: Add sendredirects config support

Setting /proc/sys/net/ipv4/conf/*/send_redirects is useful if a single
layer-2 domain is shared among routed subnets.
Sending redirects will prevents traffic from taking unnessesary detours
through a gateway in cases where direct connectivity on layer 2 exists.
This is commonly the case if an existing LAN infratructure with dump
switches is used to additionally carry routing protocols like OLSR
which are supported only by some nodes on the network.
It's important to note that the default value for send_redirects
differs for interface types (it's enabled on physical ethernet
interfaces, but disabled e.g. on VLANs) due to olsrd changing
/proc/sys/net/ipv4/conf/default/send_redirects during boot, thus the
default differs also depending e.g. on the way an on-board switch is
integrated on specific boards (as eth0 exists before olsrd is started,
eth0.1 gets created by netifd later on...)
Having a way to explicitely enable or disable send_redirects is
thus desireable also to unify the default behaviour among different,
but seemingly similar devices supported.

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
7 years agoproto: allow configuring deprecated static IPv6 addresses
Matthias Schiffer [Fri, 23 Dec 2016 15:55:20 +0000 (16:55 +0100)]
proto: allow configuring deprecated static IPv6 addresses

Add a new boolean attribute ip6deprecated to the static protocol which can
be used to mark IPv6 addresses as deprecated (i.e., set the preferred
lifetime to 0). This is useful to configure addresses that may be used for
incoming, but not for outgoing connections unless bound explicitly.

Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net>
7 years agoremove obsolete /opt/local prefix on Mac OS X
Felix Fietkau [Sat, 24 Dec 2016 09:52:18 +0000 (10:52 +0100)]
remove obsolete /opt/local prefix on Mac OS X

Signed-off-by: Felix Fietkau <nbd@nbd.name>
7 years agosystem-linux: Don't set gre tunnel ttl by default to 64 (#FS312)
Hans Dedecker [Fri, 23 Dec 2016 14:52:32 +0000 (15:52 +0100)]
system-linux: Don't set gre tunnel ttl by default to 64 (#FS312)

As the ttl of a gre tunnel was set by default to 64 the gre tunnel
failed to get active if don't fragment was disabled as setting
nopmtudisc and ttl is incompatible.
Fix this by setting the default ttl value after don't fragment
and ttl config values have been parsed.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
7 years agoubus: Display the IPv6 prefix assigned address
Hans Dedecker [Fri, 9 Dec 2016 07:47:39 +0000 (08:47 +0100)]
ubus: Display the IPv6 prefix assigned address

Display the IPv6 address obtained from a prefix assignment
as local-address element in the ubus ipv6-prefix-assignment
list so it's explicitly clear which IPv6 address from the
delegated prefix is assigned to interface.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
8 years agodevice: Use device_find for better readibility in device_create
Hans Dedecker [Mon, 21 Nov 2016 14:05:08 +0000 (15:05 +0100)]
device: Use device_find for better readibility in device_create

Use device_find in device_create so it's clear a device lookup
is being done in the device list.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
8 years agoubus: Use device_find to find a device when displaying device info
Hans Dedecker [Mon, 21 Nov 2016 14:05:07 +0000 (15:05 +0100)]
ubus: Use device_find to find a device when displaying device info

Replace device_get by device_find in netifd_dev_status as device_get
will fail to find the device if it's created via config as an aliased
vlan device in dotted notation (eg @iface.200).
In such case get_vlan_device_chain will figure out the layer3 device
but get_vlan_device will not find the vlan device in the dependency
list of the layer 3 device as it has been created as a dependency of
the aliased device.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
8 years agobridge: fix MAC address override on config reload
Felix Fietkau [Tue, 22 Nov 2016 09:43:25 +0000 (10:43 +0100)]
bridge: fix MAC address override on config reload

When no MAC address option is given, the MAC address of
bst->primary_port is used to override the bridge device address.
When the config changes and a new MAC address is provided in the config,
bridge_reset_primary needs to stop overriding it

Signed-off-by: Felix Fietkau <nbd@nbd.name>
8 years agosystem-linux: cosmetic cleanup
Felix Fietkau [Fri, 4 Nov 2016 12:20:46 +0000 (13:20 +0100)]
system-linux: cosmetic cleanup

Signed-off-by: Felix Fietkau <nbd@nbd.name>
8 years agosystem-linux: check for open failure
Günther Kelleter [Thu, 3 Nov 2016 12:40:53 +0000 (13:40 +0100)]
system-linux: check for open failure

Signed-off-by: Günther Kelleter <guenther.kelleter@devolo.de>
8 years agointerface: Fix triggering of interface update event
Hans Dedecker [Wed, 2 Nov 2016 08:22:10 +0000 (09:22 +0100)]
interface: Fix triggering of interface update event

In case the keep flag is set in proto_shell_update_link no interface
update event is triggered when IPv4/6 addresses/routes/... are updated
as the proto_event callback is not called due to keep being set.

Unconditionally call the proto_event callback handler in proto_shell_update_link
but let the proto_event callback handler; in this case interface_proto_event_cb,
decide which actions need to be taken dependant on the interface state.

In case the interface is already in the up state trigger an update event
only if the interface updated flag actually indicates either an IP address/
route/data change; before interface update events were actually sent wihtout
any parameter change.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
8 years agowireless: Call wireless_interface_handle_link before deleting the vif
Hans Dedecker [Tue, 25 Oct 2016 09:08:34 +0000 (11:08 +0200)]
wireless: Call wireless_interface_handle_link before deleting the vif

Similar as when updating a vif; call wireless_interface_handle_link removing the vif from
the network when deleting a vif

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
8 years agobridge: Don't use device name as bridge member name
Hans Dedecker [Tue, 25 Oct 2016 09:08:33 +0000 (11:08 +0200)]
bridge: Don't use device name as bridge member name

The bridge name is a copy of the device name; but the device name can
change which is the case when an aliased interface is used as bridge member.
This will result into unwanted side effects like bridge reload triggering
a topology change effect after doing network reload; therefore use the
configured ifname as fixed bridge member name.
Also don't display bridge member devices which are hidden

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
8 years agoproto-shell: add helpers for generic options in proto handlers
Marcin Jurkowski [Wed, 26 Oct 2016 01:04:01 +0000 (03:04 +0200)]
proto-shell: add helpers for generic options in proto handlers

Adding helpers for virtual interfaces generic options in ncm, qmi, mbim
and directip protocols as suggested by Felix in
https://lists.openwrt.org/pipermail/openwrt-devel/2016-February/039794.html

Signed-off-by: Marcin Jurkowski <marcin1j@gmail.com>
8 years agodevice: ignore MTU values below minimum
Felix Fietkau [Wed, 28 Sep 2016 07:55:07 +0000 (09:55 +0200)]
device: ignore MTU values below minimum

Signed-off-by: Felix Fietkau <nbd@nbd.name>
8 years agodevice: Drop device down event during device release if device gets active again
Hans Dedecker [Fri, 23 Sep 2016 13:08:23 +0000 (15:08 +0200)]
device: Drop device down event during device release if device gets active again

Fixes a race condition as the device can be active again; due to a device_claim; by the logic
behind the set_state device type function. In this case the down event cannot be sent anymore
as it would bring down the interface(s) referencing the device.
This can be the case for an aliased device when the underlying device is switched during a reload;
the alias_set_device function can add a new dependency on the new active device which will put the
aliased device in active mode again as the aliased device is already claimed by the interface
using it.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
8 years agovlandev: Rework 8021ad/8021q detection based on vlandevice type
Hans Dedecker [Fri, 23 Sep 2016 13:08:22 +0000 (15:08 +0200)]
vlandev: Rework 8021ad/8021q detection based on vlandevice type

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
8 years agovlandev: Register 8021ad and 8021q s device types
Hans Dedecker [Fri, 23 Sep 2016 13:08:21 +0000 (15:08 +0200)]
vlandev: Register 8021ad and 8021q s device types

Fixes creation of vlan 8021ad/8021q devices by UCI due to device handlers rework

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
8 years agotunnel: Use tunnel as device type name
Hans Dedecker [Fri, 23 Sep 2016 13:08:20 +0000 (15:08 +0200)]
tunnel: Use tunnel as device type name

Fixes creation of tunnel devices by UCI due to device handlers rework

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
8 years agomacvlan: Use macvlan as device type name
Hans Dedecker [Fri, 23 Sep 2016 13:08:19 +0000 (15:08 +0200)]
macvlan: Use macvlan as device type name

Fixes creation of macvlan devices by UCI due to device handlers rework

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
8 years agobridge: Make bridge_device_type static
Hans Dedecker [Fri, 23 Sep 2016 13:08:18 +0000 (15:08 +0200)]
bridge: Make bridge_device_type static

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
8 years agodevice: Move the different device type registrations to the device type file
Hans Dedecker [Fri, 23 Sep 2016 13:08:17 +0000 (15:08 +0200)]
device: Move the different device type registrations to the device type file

While at it; make device_types static if only used in the device type file

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
8 years agointerface-event: Don't dequeue hotplug event in case of interface reload event
Hans Dedecker [Tue, 13 Sep 2016 12:33:40 +0000 (14:33 +0200)]
interface-event: Don't dequeue hotplug event in case of interface reload event

Dropping hotplug event in case of interface reload results into hotplug scripts
not being being run for the interface and thus external actors not being informed
about the actual state of the interface.

This is clearly visible if the interface auto parameter is set to disabled for
multiple interfaces resulting into no hotplug down event for all interfaces.

Therefore don't flush the interface hotplug queue in case an interface reload
event is observed.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
8 years agointerface-ip: DNS name server sorting support in resolv.conf.auto
Hans Dedecker [Tue, 13 Sep 2016 12:33:39 +0000 (14:33 +0200)]
interface-ip: DNS name server sorting support in resolv.conf.auto

Interface name servers when being written to resolv.conf.auto are sorted
based on the following parameters:
-Primary sorting key is interface dns_metric; name servers having lowest
interface dns_metric are listed first
-Secondary sorting key is interface metric; in case of equal interface
dns_metric name servers having lowest interface metric are listed first
-Finally alphabetical order of the interface names in case of equal
interface dns_metric and metric

In case the resolver queries the multiple servers in the order
listed; sorting is usefull in the following scenarios :
-Name resolving over a main and backup interface
-Assign priority to IPv6 name servers over IPv4 or vice versa

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
8 years agobridge: Allow setting multicast_fast_leave_option
Hans Dedecker [Tue, 13 Sep 2016 12:33:38 +0000 (14:33 +0200)]
bridge: Allow setting multicast_fast_leave_option

Setting the multicast_fast_leave option of a bridge allows to control
the forwarding of multicast traffic when an IGMP/MLD leave is received.
In case multicast_leave_option is enabled and a leave is received the
multicast membership will immediately be dropped on the bridge port while
in the other case the multicast membership will time out in the bridge.

This could be usefull in scenarios where explicit multicast membership
host tracking is not supported in the upstream network. In this case the
multicast stream is still flowing after a leave is received resulting into
possible bandwidth saturation on the lan if a new stream is joined as
multiple multicast streams are received.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
8 years agodevice: add device handler list
Arne Kappen [Thu, 18 Aug 2016 09:35:29 +0000 (11:35 +0200)]
device: add device handler list

Device handlers now also declare if they have bridge capabilities and include
a string to prefix device names for their types.

Signed-off-by: Arne Kappen <akappen@inet.tu-berlin.de>
Signed-off-by: Felix Fietkau <nbd@nbd.name> [cleanup/fixes]
8 years agodevice: prepare for adding device handlers dynamically
Arne Kappen [Thu, 18 Aug 2016 09:35:28 +0000 (11:35 +0200)]
device: prepare for adding device handlers dynamically

- remove const from device handler struct
- pass device handler type to create function

Signed-off-by: Arne Kappen <akappen@inet.tu-berlin.de>
Signed-off-by: Felix Fietkau <nbd@nbd.name> [cleanup]
8 years agowireless: remove config_autostart
Eduardo Abinader [Thu, 25 Aug 2016 09:13:13 +0000 (11:13 +0200)]
wireless: remove config_autostart

just a cleanup for an unused member.

Signed-off-by: Eduardo Abinader <eduardoabinader@gmail.com>
8 years agowireless: add retry_setup_failed to status notification
Eduardo Abinader [Wed, 24 Aug 2016 10:15:21 +0000 (12:15 +0200)]
wireless: add retry_setup_failed to status notification

As autostart is now more aligned to user intention of automatic
starting the wdev, to add retry_setup_failed to status msg may be of a help
for current stating how setup is proceeding.

Signed-off-by: Eduardo Abinader <eduardoabinader@gmail.com>
8 years agonetifd: track when wdev setup fails
Eduardo Abinader [Fri, 12 Aug 2016 06:51:58 +0000 (08:51 +0200)]
netifd: track when wdev setup fails

When netifd failed to load a valid configuration, after an invalid one,
it was not possible to setup the wireless device. This patch
aims to track this situation and behave acordingly, by keeping
track of failed setup without affecting autostart behavior. Also
block the restart of the wdev, when not applied.

Signed-off-by: Eduardo Abinader <eduardoabinader@gmail.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
8 years agoPrevent premature device free in interface_claim_device
Felix Fietkau [Thu, 11 Aug 2016 17:36:09 +0000 (19:36 +0200)]
Prevent premature device free in interface_claim_device

interface_set_device_config can trigger a device free (for example
if the device is here only present in a bridge), which renders dev
invalid and leads to segfault. Add a lock to prevent this and
clean-up the code for readability.

Signed-off-by: Gino Peeters <peeters.gino@gmail.com>
Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
8 years agoutils: Move IP address validation to parse_addr function
Hans Dedecker [Thu, 11 Aug 2016 13:53:29 +0000 (15:53 +0200)]
utils: Move IP address validation to parse_addr function

Commit 7a51f23e adds IP address validation in the function parse_ip_and_netmask;
however the added check is too restrictive as the function is used on several places
resulting into the problem multicast routes cannot be added anymore via UCI.
Therefore move the IP host address validation to the function parse_addr so
experimantal/multicast addresses cannot be added as a host IP address while
multicast routes can be added again.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
8 years agoproto: Display proto flags when dumping the protocol handlers in ubus
Hans Dedecker [Thu, 11 Aug 2016 13:53:27 +0000 (15:53 +0200)]
proto: Display proto flags when dumping the protocol handlers in ubus

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
8 years agoproto-shell: Model config parameter "no-proto-task" as a proto flag
Hans Dedecker [Thu, 11 Aug 2016 13:53:26 +0000 (15:53 +0200)]
proto-shell: Model config parameter "no-proto-task" as a proto flag

Export the config parameter "no-proto-task" as a proto flag so it's available for other
other netifd modules

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
8 years agoproto-shell: Support teardown on layer 3 link loss
Hans Dedecker [Thu, 11 Aug 2016 13:53:25 +0000 (15:53 +0200)]
proto-shell: Support teardown on layer 3 link loss

Commit c6858766 added interface teardown support on layer 3 device link loss
mainly for shell protocols who have no proto task like xl2tp. However for
shell protocols having a proto task it is not always the correct action to
teardown the interface; as an example the PPP daemon can be put into
persist state trying to re-establish the link via a hold-off mechanism
if layer 3 link loss is detected.
Therefore shell handlers can enable via TEARDOWN_ON_L3_LINK_DOWN a proto
flag which will teardown the interface when layer 3 link loss is detected

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
8 years agointerface: do not process hotplug events for link up event
Felix Fietkau [Fri, 29 Jul 2016 17:47:32 +0000 (19:47 +0200)]
interface: do not process hotplug events for link up event

Signed-off-by: Felix Fietkau <nbd@nbd.name>
8 years agointerface: report link up events for force_link interfaces
Felix Fietkau [Fri, 29 Jul 2016 14:12:17 +0000 (16:12 +0200)]
interface: report link up events for force_link interfaces

Signed-off-by: Felix Fietkau <nbd@nbd.name>
8 years agoalias: Set alias link device status to disabled when device is removed
Hans Dedecker [Wed, 29 Jun 2016 12:02:18 +0000 (14:02 +0200)]
alias: Set alias link device status to disabled when device is removed

Fixes missing link state event propagation for an aliased device in case a new device is added
as the link state has the last known status of the old device possible resulting into
no link state change detection.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
Acked-by: Felix Fietkau <nbd@nbd.name>
8 years agosystem-linux: Replace device_get by device_find where appropriate
Hans Dedecker [Mon, 6 Jun 2016 12:58:33 +0000 (14:58 +0200)]
system-linux: Replace device_get by device_find where appropriate

Replace device_get by device_find so it's clear a device needs to be found present
in the device list.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
8 years agodevice: Fix dotted vlan interface staying down
Hans Dedecker [Mon, 6 Jun 2016 12:58:32 +0000 (14:58 +0200)]
device: Fix dotted vlan interface staying down

Using the config below a dotted vlan interface stays down as get_vlan_device
does not find the device due to the aliased device stacked on top of the base
device.
As all devices; aliased devices being the exception; are in the device list
use device_find to find the device when setting the link state

config interface 'test'
    option proto 'static'
    option ipaddr '192.168.2.1'
    option netmask '255.255.255.0'

config interface 'test2'
    option ifname '@test.1'
    option proto 'dhcp'

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
8 years agodevice: Fix device find failure in avl list due to device name change
Hans Dedecker [Mon, 6 Jun 2016 12:58:31 +0000 (14:58 +0200)]
device: Fix device find failure in avl list due to device name change

As device name is used as key in avl list a device name change will break the avl find logic.
Function device_set_ifname offers api to set the device name and re-inserts the avl node in the list
when the avl key value is changed.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
8 years agonetifd: Add option to configure gc_stale_time for each device
Alin Năstac [Tue, 24 May 2016 15:02:20 +0000 (17:02 +0200)]
netifd: Add option to configure gc_stale_time for each device

The UCI parameter neighgcstaletime allows to control how much time will
STALE entries be kept in the neighbour table for both IPv4 and IPv6.

Signed-off-by: Alin Nastac <alin.nastac@gmail.com>
8 years agobridge: make learning and unicast-flood configurable per bridge port
Linus Lüssing [Sun, 22 May 2016 20:33:48 +0000 (22:33 +0200)]
bridge: make learning and unicast-flood configurable per bridge port

Tuning these two options allows a more fine grained configuration of the
forwarding database (fdb) of a bridge.

The former allows to enable or disable the learning of the presence of
MAC addresses behind a bridge port. (default: enabled on all ports)

The latter allows to tune the behaviour in case a destination MAC address
of a frame is unknown to the fdb, like only flooding on specific ports or
not flooding on any port. (default: flood on all ports, except incoming)

This can be useful to create a dumb hub, for instance for monitoring
purposes. Or in larger layer 2 mesh networks to avoid keeping redundant
databases (e.g. with the batman-adv translation table).

Signed-off-by: Linus Lüssing <linus.luessing@c0d3.blue>