project/netifd.git
2 years agowireless: fix handling vif attributes on reload with mode change
Felix Fietkau [Thu, 21 Oct 2021 09:28:35 +0000 (11:28 +0200)]
wireless: fix handling vif attributes on reload with mode change

When switching from AP to station mode, some AP specific flags such as proxyarp
could become sticky and lead to hairpin being enabled on the sta interface.
Fix this by ensuring that vif fields are always properly rewritten

Signed-off-by: Felix Fietkau <nbd@nbd.name>
2 years agowireless: fix creating AP mode WDS station interfaces
Felix Fietkau [Wed, 20 Oct 2021 19:09:32 +0000 (21:09 +0200)]
wireless: fix creating AP mode WDS station interfaces

Ensure that devices are created without attempting to create a VLAN chain

Signed-off-by: Felix Fietkau <nbd@nbd.name>
2 years agointerface, ubus: rework netns up/down
Daniel Golle [Mon, 11 Oct 2021 23:17:26 +0000 (00:17 +0100)]
interface, ubus: rework netns up/down

Let per-container netifd instance handle the netns bringdown, it makes
everything easier and gets rid of the fork() when bringing down
container network interfaces.

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
2 years agointerface: don't fork() to start jail interface
Daniel Golle [Mon, 11 Oct 2021 22:51:08 +0000 (23:51 +0100)]
interface: don't fork() to start jail interface

As we got a persistent per-netns-jail instance of netifd now which
handles interface configuration we no longer need to fork() the host
netifd to bring up jail interfaces.
The follow-up commit will deal with stopping jail interfaces.

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
2 years agowireless: fix index for stations
Felix Fietkau [Wed, 29 Sep 2021 13:16:33 +0000 (15:16 +0200)]
wireless: fix index for stations

Use wdev->sta_idx instead of the VLAN counter wdev->vlan_idx

Signed-off-by: Felix Fietkau <nbd@nbd.name>
2 years agowireless: reset retry counter when setup succeeds
Felix Fietkau [Wed, 29 Sep 2021 12:59:11 +0000 (14:59 +0200)]
wireless: reset retry counter when setup succeeds

A wireless device restart cycle can be triggered if a tracked process
(e.g. hostapd) dies and is restarted, and this left the retry counter
untouched

Signed-off-by: Felix Fietkau <nbd@nbd.name>
2 years agowireless: reset number of retries on config change
Felix Fietkau [Wed, 29 Sep 2021 11:29:22 +0000 (13:29 +0200)]
wireless: reset number of retries on config change

Ensure that enough retries are performed, just like on a user triggered
down/up cycle.

Signed-off-by: Felix Fietkau <nbd@nbd.name>
2 years agomain: poll process log stream even if processes are killed
Felix Fietkau [Wed, 29 Sep 2021 12:45:16 +0000 (14:45 +0200)]
main: poll process log stream even if processes are killed

Ensures that pending log messages are still received

Signed-off-by: Felix Fietkau <nbd@nbd.name>
2 years agowireless: process and close script file descriptor when rerunning setup
Felix Fietkau [Wed, 29 Sep 2021 12:03:55 +0000 (14:03 +0200)]
wireless: process and close script file descriptor when rerunning setup

On reloading, setup is called without a teardown, so the previous fd might
still be open. Clear it to avoid a leak.

Signed-off-by: Felix Fietkau <nbd@nbd.name>
2 years agowireless: display log messages for setup/teardown/retry
Felix Fietkau [Wed, 29 Sep 2021 12:35:56 +0000 (14:35 +0200)]
wireless: display log messages for setup/teardown/retry

Signed-off-by: Felix Fietkau <nbd@nbd.name>
2 years agowireless: fix applying wireless devices attributes on hotplug events
Andre Heider [Tue, 28 Sep 2021 11:29:27 +0000 (13:29 +0200)]
wireless: fix applying wireless devices attributes on hotplug events

Hotplug events pass their own 'ifname' copy, so we need to compare the
strings, not just the pointers.
Additionally, the check condition was accidentally inverted

Signed-off-by: Andre Heider <a.heider@gmail.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
2 years agonetifd: rework/fix device free handling
Felix Fietkau [Mon, 27 Sep 2021 16:56:21 +0000 (18:56 +0200)]
netifd: rework/fix device free handling

Instead of explicitly preventing free in specific code sections using
device_lock/device_unlock, defer all device free handling via uloop timeout
This avoids an entire class of lurking use-after-free bugs triggered
by device event processing and simplifies the code

Signed-off-by: Felix Fietkau <nbd@nbd.name>
2 years agobonding: claim the port device before creating the bonding device
Felix Fietkau [Tue, 21 Sep 2021 16:04:32 +0000 (18:04 +0200)]
bonding: claim the port device before creating the bonding device

Avoids create/destroy cycles of the bonding device if the port devices are unavailable

Signed-off-by: Felix Fietkau <nbd@nbd.name>
2 years agowireless: only enable proxyarp/isolate for AP vifs
Felix Fietkau [Mon, 20 Sep 2021 16:00:03 +0000 (18:00 +0200)]
wireless: only enable proxyarp/isolate for AP vifs

The settings might be present in the config as leftovers when switching
a vif from AP to sta mode. In that case, they will not be applied by wpad,
so they also must not be used by netifd

Signed-off-by: Felix Fietkau <nbd@nbd.name>
2 years agowireless: only apply wireless device attributes to the base vif interface
Felix Fietkau [Mon, 20 Sep 2021 15:55:39 +0000 (17:55 +0200)]
wireless: only apply wireless device attributes to the base vif interface

Per-station interfaces in 4-addr AP mode must not inherit them, because
this can cause reflected packets by enabling hairpin mode.

Signed-off-by: Felix Fietkau <nbd@nbd.name>
2 years agodevice: add support for configuring bonding devices
Felix Fietkau [Thu, 2 Sep 2021 18:26:33 +0000 (20:26 +0200)]
device: add support for configuring bonding devices

Supported options:

- ports: member devices
- policy: bonding policy
supported values:
- balance-rr
- active-backup
- balance-xor
- broadcast
- 802.3ad
- balance-tlb
- balance-alb
- xmit_hash_policy: slave selection tx hash policy
supported values:
- layer2
- layer2+3
- layer3+4
- encap2+3
- encap3+4
- all_ports_active: allow receiving on inactive ports
- min_links: minimum number of active links
- ad_actor_system: LACPDU exchange MAC address
- ad_actor_sys_prio: LACPDU priority value
- ad_select: 802.3ad aggregation logic
supported values:
- stable
- bandwidth
- count
- lacp_rate: 802.3ad LACPDU packet rate
supported values:
- slow (every 30 seconds)
- fast (every second)
- packets_per_port: number of packets before switching
  ports (balance-rr mode).
- lp_interval: number of seconds between sent learning packets
- dynamic_lb: distribute traffic according to port load
- resend_igmp: number if IGMP membership updates after failover event
- num_peer_notif: number of tx unsolicited ARP/NA after failover event
- primary: name of the primary port
- primary_reselect: primary port reselection policy
supported values:
- always
- better
- failure
- failover_mac: MAC address selection policy
supported values:
- none
- active
- follow
- monitor_mode: select ARP or MII link monitor:
supported values:
- arp
- mii
- monitor_interval: link monitor update interval (msec)
- arp_target: ARP monitor target IP address (list)
- arp_all_targets: all targets must be reachable to consider the link valid
- arp_validate: ARP validation policy
supported values:
- none
- active
- backup
- all
- filter
- filter_active
- filter_backup
- use_carrier: use carrier status instead of MII ioctl result
- updelay: delay before enabling port after MII link up event (msec)
- downdelay: delay before disabling port after MII link down event (msec)

Signed-off-by: Felix Fietkau <nbd@nbd.name>
2 years agowireless: improve reliability of proxyarp support
Felix Fietkau [Wed, 1 Sep 2021 17:00:41 +0000 (19:00 +0200)]
wireless: improve reliability of proxyarp support

instead of relying on hostapd to manipulate bridge attributes (which can race
against netifd adding/removing of member ports), set the proxyarp related
attributes in netifd directly when bringing up the member port

Signed-off-by: Felix Fietkau <nbd@nbd.name>
2 years agosystem-linux: remove copy&paste from /proc and /sys path names
Felix Fietkau [Tue, 31 Aug 2021 19:01:40 +0000 (21:01 +0200)]
system-linux: remove copy&paste from /proc and /sys path names

Preparation for making the /proc and /sys path configurable for configuring
containers

Signed-off-by: Felix Fietkau <nbd@nbd.name>
2 years agowireless: always enable bpdu filter for AP interfaces and VLANs
Felix Fietkau [Fri, 27 Aug 2021 10:15:07 +0000 (12:15 +0200)]
wireless: always enable bpdu filter for AP interfaces and VLANs

Regular AP/VLAN interfaces using 3-address modes should transmit any
STP packets, since devices behind them can not be part of any working bridge
topology. Enable a feature that drops any incoming or outgoing STP packets.
This does not apply to WDS AP VLAN or client mode interfaces, since they
could act as a proper bridge link

Signed-off-by: Felix Fietkau <nbd@nbd.name>
2 years agobridge: tune default stp parameters
Felix Fietkau [Tue, 24 Aug 2021 15:16:05 +0000 (17:16 +0200)]
bridge: tune default stp parameters

The default forwarding delay 2 is broken and makes STP non-functional by
default. The kernel's default of 15 is rather long.
This commit changes makes the timer settings more aggressive than the
kernel's default while still being consistent and allowing proper
convergence for a network diameter up to 4

Signed-off-by: Felix Fietkau <nbd@nbd.name>
2 years agobridge: add support for an external STP daemon
Felix Fietkau [Sun, 22 Aug 2021 06:00:18 +0000 (08:00 +0200)]
bridge: add support for an external STP daemon

netifd notifies the stp daemon through the network.device object and sends
STP related configuration parameters. The daemon can also trigger a STP
restart in order to close the race on init

Signed-off-by: Felix Fietkau <nbd@nbd.name>
2 years agobridge: memset bst->config by default to avoid stale config values
Felix Fietkau [Tue, 24 Aug 2021 10:58:35 +0000 (12:58 +0200)]
bridge: memset bst->config by default to avoid stale config values

Signed-off-by: Felix Fietkau <nbd@nbd.name>
2 years agodevice: add support for configuring device link speed/duplex
Felix Fietkau [Mon, 2 Aug 2021 20:48:44 +0000 (22:48 +0200)]
device: add support for configuring device link speed/duplex

The 'speed' option can be set to the speed in Mbps
The 'duplex' option can be 1 or 0 for full or half duplex

Signed-off-by: Felix Fietkau <nbd@nbd.name>
2 years agodevice: extend device settings flags to 64 bit
Felix Fietkau [Thu, 29 Jul 2021 18:06:14 +0000 (20:06 +0200)]
device: extend device settings flags to 64 bit

The previous 32 bit limit is almost used up

Signed-off-by: Felix Fietkau <nbd@nbd.name>
2 years agobridge: fix regression in bringing up bridge ports
Felix Fietkau [Mon, 26 Jul 2021 18:39:17 +0000 (20:39 +0200)]
bridge: fix regression in bringing up bridge ports

Move the DEV_EVENT_LINK_UP case to avoid messing with a fallthrough
Only restart members if the vlan check returns a positive result

Fixes: 85f01c44a950 ("bridge: check bridge port vlan membership on link-up events")
Signed-off-by: Felix Fietkau <nbd@nbd.name>
2 years agowireless: add back regular virtual interfaces on hotplug-add events as well
Felix Fietkau [Fri, 23 Jul 2021 09:37:57 +0000 (11:37 +0200)]
wireless: add back regular virtual interfaces on hotplug-add events as well

When hostapd does a DFS channel switch, it tears down all vifs except for the
primary one, which causes them got get dropped from the device configuration

Signed-off-by: Felix Fietkau <nbd@nbd.name>
2 years agobridge: check bridge port vlan membership on link-up events
Felix Fietkau [Fri, 23 Jul 2021 09:04:45 +0000 (11:04 +0200)]
bridge: check bridge port vlan membership on link-up events

When changing to a dfs channel, hostapd can bring down wlan interfaces and
reset their bridge membership. If that happens, the port loses its vlan
membership settings and needs to be reconfigured by netifd.

Signed-off-by: Felix Fietkau <nbd@nbd.name>
2 years agovlan: fix device vlan alias handling
Felix Fietkau [Wed, 14 Jul 2021 13:22:09 +0000 (15:22 +0200)]
vlan: fix device vlan alias handling

A recent commit changed the vlan chain handling to not treat devices with
non-digit characters after "." as vlan devices. This broke aliases, which
rely on names after the "." component.
Fix dealing with both cases by first trying to set up a vlan regardless
of the non-digit characters, but for the first component allow falling back
to treating the first two parts as a full device name

Fixes: 013a1171e9b0 ("device: do not treat devices with non-digit characters after . as vlan devices")
Signed-off-by: Felix Fietkau <nbd@nbd.name>
2 years agobridge: fix hotplug vlan overwrite on big-endian systems
Felix Fietkau [Tue, 13 Jul 2021 05:53:40 +0000 (07:53 +0200)]
bridge: fix hotplug vlan overwrite on big-endian systems

The avl key type for bridge vlans is uint16_t, so any lookup with a wider
type is going to fail on big-endian systems
This resulted in hotplug-added devices replacing configured member ports

Signed-off-by: Felix Fietkau <nbd@nbd.name>
2 years agobridge: bring up pre-existing vlans on hotplug as well
Felix Fietkau [Wed, 23 Jun 2021 08:01:41 +0000 (10:01 +0200)]
bridge: bring up pre-existing vlans on hotplug as well

When adding a member to an existing VLAN, it needs to be updated as well

Signed-off-by: Felix Fietkau <nbd@nbd.name>
2 years agobridge: fix enabling hotplug-added VLANs on the bridge port
Felix Fietkau [Tue, 22 Jun 2021 14:56:39 +0000 (16:56 +0200)]
bridge: fix enabling hotplug-added VLANs on the bridge port

Signed-off-by: Felix Fietkau <nbd@nbd.name>
2 years agowireless: handle WDS per-sta devices
Felix Fietkau [Sat, 19 Jun 2021 06:36:06 +0000 (08:36 +0200)]
wireless: handle WDS per-sta devices

Signed-off-by: Felix Fietkau <nbd@nbd.name>
2 years agodevice: do not treat devices with non-digit characters after . as vlan devices
Felix Fietkau [Sat, 19 Jun 2021 06:55:10 +0000 (08:55 +0200)]
device: do not treat devices with non-digit characters after . as vlan devices

Fixes corner cases related to AP WDS station interfaces

Signed-off-by: Felix Fietkau <nbd@nbd.name>
2 years agoexamples: make dummy wireless vif names shorter
Felix Fietkau [Sat, 19 Jun 2021 07:08:17 +0000 (09:08 +0200)]
examples: make dummy wireless vif names shorter

avoids running into ifname size limits

Signed-off-by: Felix Fietkau <nbd@nbd.name>
2 years agoubus: add a dummy mode ubus call to simulate hotplug events
Felix Fietkau [Sat, 19 Jun 2021 06:19:02 +0000 (08:19 +0200)]
ubus: add a dummy mode ubus call to simulate hotplug events

Can be used to test the device hotplug handling

Signed-off-by: Felix Fietkau <nbd@nbd.name>
2 years agodevice: move hotplug handling logic from system-linux.c to device.c
Felix Fietkau [Sat, 19 Jun 2021 06:11:21 +0000 (08:11 +0200)]
device: move hotplug handling logic from system-linux.c to device.c

Preparation for dealing with wifi per-station devices

Signed-off-by: Felix Fietkau <nbd@nbd.name>
2 years agobridge: fix setting pvid for updated vlans
Felix Fietkau [Thu, 17 Jun 2021 08:39:26 +0000 (10:39 +0200)]
bridge: fix setting pvid for updated vlans

defer adding back changed vlans until config processing is done

Signed-off-by: Felix Fietkau <nbd@nbd.name>
2 years agowireless: add some comments to functions
Alexander Couzens [Thu, 7 Jan 2021 01:59:33 +0000 (02:59 +0100)]
wireless: add some comments to functions

Signed-off-by: Alexander Couzens <lynxis@fe80.eu>
2 years agobridge: allow adding/removing VLANs to configured member ports via hotplug
Felix Fietkau [Fri, 4 Jun 2021 07:05:31 +0000 (09:05 +0200)]
bridge: allow adding/removing VLANs to configured member ports via hotplug

This is useful for a dynamic VLAN setup, where extra tags need to be created
on the trunking port on demand

Signed-off-by: Felix Fietkau <nbd@nbd.name>
2 years agowireless: pass the real network ifname to the setup script
Felix Fietkau [Fri, 4 Jun 2021 06:41:34 +0000 (08:41 +0200)]
wireless: pass the real network ifname to the setup script

If the network ifname is a VLAN on top of a VLAN-filtering bridge, hostapd
needs to know the VLAN ifname to communicate with other APs, if 802.11r is enabled.

Signed-off-by: Felix Fietkau <nbd@nbd.name>
2 years agobridge: fix dynamic delete of hotplug vlans
Felix Fietkau [Wed, 2 Jun 2021 16:23:40 +0000 (18:23 +0200)]
bridge: fix dynamic delete of hotplug vlans

Signed-off-by: Felix Fietkau <nbd@nbd.name>
2 years agobridge: dynamically create vlans for hotplug members
Felix Fietkau [Wed, 2 Jun 2021 15:59:03 +0000 (17:59 +0200)]
bridge: dynamically create vlans for hotplug members

This makes it possible to use dynamic tags without changing the configuration

Signed-off-by: Felix Fietkau <nbd@nbd.name>
2 years agointerface: support "device" attribute and deprecate "ifname"
Rafał Miłecki [Tue, 25 May 2021 15:17:26 +0000 (17:17 +0200)]
interface: support "device" attribute and deprecate "ifname"

Interfaces need to be assigned to devices. For that purpose a "device"
option should be more accurate than "ifname" one.

For backward compatibility old option remains supported too.

Config example:

config device
option name 'br-lan'
option type 'bridge'
list ports 'lan1'
list ports 'lan2'

config interface 'lan'
option device 'br-lan'
option proto 'static'

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
2 years agoscripts/netifd-wireless.sh: add support for specifying the operating band
Felix Fietkau [Mon, 24 May 2021 10:37:55 +0000 (12:37 +0200)]
scripts/netifd-wireless.sh: add support for specifying the operating band

Add the new 'band' option, which supports the following values: 2g, 5g, 6g, 60g

Signed-off-by: Felix Fietkau <nbd@nbd.name>
2 years agoconfig: fix ifname->ports compat rename
Felix Fietkau [Thu, 20 May 2021 08:57:52 +0000 (10:57 +0200)]
config: fix ifname->ports compat rename

Instead of looking it up as a string, use uci_rename.
That way it works both on list and string options

Signed-off-by: Felix Fietkau <nbd@nbd.name>
2 years agobridge: rename "ifname" attribute to "ports"
Rafał Miłecki [Fri, 14 May 2021 13:20:28 +0000 (15:20 +0200)]
bridge: rename "ifname" attribute to "ports"

Bridge aggregates multiple ports so use a more accurate name ("ports").
For backward compatibility add a temporary config translation.

Config example:

config interface 'lan'
        option type 'bridge'
        list ports 'lan1'
        list ports 'lan2'

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
2 years agowireless: fix memory corruption bug when using vlans/station entries in the config
Felix Fietkau [Tue, 18 May 2021 04:20:00 +0000 (06:20 +0200)]
wireless: fix memory corruption bug when using vlans/station entries in the config

On config reload, any vif entries in the config added to the vlist will be
matched against existing ones, and the old entries preserved.
This means that the vif pointer is no longer valid after vlist_add.
Look up the vif again before using it for vlan/station entries.

Signed-off-by: Felix Fietkau <nbd@nbd.name>
2 years agodevice: add support for configuring devices with external auth handler
Felix Fietkau [Mon, 17 May 2021 09:20:09 +0000 (11:20 +0200)]
device: add support for configuring devices with external auth handler

This can be used to support 802.1x on wired devices.
In order to use this, the device section for each port needing authentication
needs to contain the option auth 1
When set, this option prevents devices from being added to bridges or configured
with IP settings by default, until the set_state ubus call on network.device
sets "auth_status" to true for the device.

Signed-off-by: Felix Fietkau <nbd@nbd.name>
2 years agoextdev: remove unused function
Felix Fietkau [Sun, 16 May 2021 16:06:48 +0000 (18:06 +0200)]
extdev: remove unused function

Signed-off-by: Felix Fietkau <nbd@nbd.name>
2 years agofix unannotated fall-through warnings
Felix Fietkau [Sun, 16 May 2021 16:04:18 +0000 (18:04 +0200)]
fix unannotated fall-through warnings

Signed-off-by: Felix Fietkau <nbd@nbd.name>
3 years agonetifd: add possibility to switch off route config
Florian Eckert [Tue, 24 Nov 2020 07:18:00 +0000 (08:18 +0100)]
netifd: add possibility to switch off route config

This change adds the new configuration option `disabled` for the route
section, which can be used to temporarily disable the section so that
the route is not set. The advantage is that we do not have to delete
this route configuration section to achieve this.

config route
  option disabled '1

Signed-off-by: Florian Eckert <fe@dev.tdt.de>
3 years agonetifd: bridge: set default value for igmp_snoop
Zheng Qian [Tue, 2 Mar 2021 01:36:51 +0000 (09:36 +0800)]
netifd: bridge: set default value for igmp_snoop

When unchecked the igmp snoop option for a bridge by luci, it
just delete the igmp_snooping key from the config file.
So netifd can't change /sys/devices/virtual/net/br-lan/bridge/multicast_snooping from "1" to "0".

Option multicast_querier seems no input entry in luci, but it's
an related option.

This patch will set a default value to false for the bridge
option to fix this bug.

Signed-off-by: Zheng Qian <sotux82@gmail.com>
3 years agosystem-linux: add device options used by wpad
Daniel Golle [Sat, 12 Dec 2020 21:13:24 +0000 (21:13 +0000)]
system-linux: add device options used by wpad

Add device options used by wpad in preparation of running hostapd and
wpa_supplicant non-root (and hence those options will need to be taken
care of by netifd as sysctl is root-only):
 * drop_v4_unicast_in_l2_multicast
 * drop_v6_unicast_in_l2_multicast
 * drop_gratuitous_arp
 * drop_unsolicited_na
 * arp_accept

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
3 years agosystem-linux: reorder sysctl functions
Daniel Golle [Sat, 12 Dec 2020 17:16:11 +0000 (17:16 +0000)]
system-linux: reorder sysctl functions

Move system_set_sendredirects up to the other non-bridge-related sysctl
functions.

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
3 years agoextdev: add support for external device handlers
Arne Kappen [Wed, 9 Dec 2020 15:01:24 +0000 (16:01 +0100)]
extdev: add support for external device handlers

This allows to integrate external daemons that configure network devices with
netifd. At startup, netifd generates device handler stubs from descriptions in
/lib/netifd/extdev-config via the mechanism in handler.c. These are then added
to the list of device handlers. Device handlers stubs act as relays forwarding
calls against the device handler interface to the external daemon.

Signed-off-by: Arne Kappen <arne.kappen@hhi.fraunhofer.de>
3 years agohandler: add mechanism to generate external device handler stubs
Arne Kappen [Wed, 9 Dec 2020 15:01:23 +0000 (16:01 +0100)]
handler: add mechanism to generate external device handler stubs

Parse JSON files in a given directory and pass the information on to a callback
function for creation of an external device handler stub.
The description contains:
 - 'name': the name of the device type,
 - 'ubus_name': the name of the external device handler daemon on ubus,
 - 'bridge': a flag indicating whether the devices are bridge-like,
 - optionally 'br_prefix': a prefix for created devices
   (only for bridge-like, defaults to type name),
 - 'config': the UCI config options for devices of this type, and
 - optionally 'info' and 'stats': the format of calls to info() and dump().

Signed-off-by: Arne Kappen <arne.kappen@hhi.fraunhofer.de>
3 years agodevice: remove left-over comment
Arne Kappen [Wed, 9 Dec 2020 15:01:22 +0000 (16:01 +0100)]
device: remove left-over comment

Signed-off-by: Arne Kappen <arne.kappen@hhi.fraunhofer.de>
3 years agointerface-ip: add unreachable route if address is offlink
Hans Dedecker [Sat, 9 Jan 2021 20:18:45 +0000 (21:18 +0100)]
interface-ip: add unreachable route if address is offlink

In order to avoid a routing loop add an unreachable route for the
address prefix is the offlink flag is set for an address.
This fixes a routing loop which is currently present on point-to-point
links (e.g PPP) when the wan interface is assigned a globally unique
prefix (e.g. 2001:db8:1:0::/64) from which an IPv6 address is picked
and installed on the wan interface
(e.g. 2001:db8:1:0:5054:ff:feab:d87c/64)

The prefix route 2001:db8:1::/64 would be present in the routing table
which will route any packet with as destination 2001:db8:1::/64 to the wan
interface and would be routed back by the upstream router due to the
wan interface due to the assigned global unique prefix.
Besides not installing the prefix route 2001:db8:1::/64 on point-to-point links
adding an unreachable route is required to avoid the routing loop.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
3 years agointerface-ip: coding style fixes
Hans Dedecker [Sat, 9 Jan 2021 20:12:05 +0000 (21:12 +0100)]
interface-ip: coding style fixes

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
3 years agonetifd: wireless: default to GCMP WPA cipher on 802.11ad
Daniel Golle [Tue, 5 Jan 2021 01:11:21 +0000 (01:11 +0000)]
netifd: wireless: default to GCMP WPA cipher on 802.11ad

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
3 years agowireless: add support for not killing processes on teardown
Felix Fietkau [Mon, 28 Dec 2020 13:42:30 +0000 (14:42 +0100)]
wireless: add support for not killing processes on teardown

When using a global hostapd/wpa_supplicant instance, it should not be killed
if a single radio is torn down

Signed-off-by: Felix Fietkau <nbd@nbd.name>
3 years agonetifd: fix a typo in vlandev hotplug support
Felix Fietkau [Mon, 14 Dec 2020 11:59:32 +0000 (12:59 +0100)]
netifd: fix a typo in vlandev hotplug support

Need to check the type of the vlan device, not the underlying device

Signed-off-by: Felix Fietkau <nbd@nbd.name>
3 years agonetifd: add segment routing support
Nick Hainke [Sat, 12 Dec 2020 20:50:53 +0000 (21:50 +0100)]
netifd: add segment routing support

seg6_enabled - Bool
  Accept or drop SR-enabled IPv6 packets on this interface.

More Information:
https://www.kernel.org/doc/html/latest/networking/seg6-sysctl.html

Now you can set as interface option
  option ip6segmentrouting '1'

It is not enough to turn on "seg6_enabled" on the interface. Further,
we have to enable "/all/seg6_enabled". This means that a working config
is "interface + all".

Signed-off-by: Nick Hainke <vincent@systemli.org>
Signed-off-by: Hans Dedecker <dedeckeh@gmail.com> [style fixes]
3 years agoconfig: parse default mac address from board.json
Felix Fietkau [Mon, 30 Nov 2020 11:34:13 +0000 (12:34 +0100)]
config: parse default mac address from board.json

Example:
{
"network-device": {
"eth0": {
"macaddr": "bc:a5:11:16:76:d7"
}
}
}

Signed-off-by: Felix Fietkau <nbd@nbd.name>
3 years agosystem-linux: move device settings handling to device.c
Felix Fietkau [Mon, 30 Nov 2020 11:08:32 +0000 (12:08 +0100)]
system-linux: move device settings handling to device.c

Signed-off-by: Felix Fietkau <nbd@nbd.name>
3 years agosystem-linux: simplify mask check in system_if_apply_settings
Felix Fietkau [Mon, 30 Nov 2020 10:52:22 +0000 (11:52 +0100)]
system-linux: simplify mask check in system_if_apply_settings

Mask flags against apply_mask only once instead of once per field

Signed-off-by: Felix Fietkau <nbd@nbd.name>
3 years agosystem-dummy: print configured mac address
Felix Fietkau [Mon, 30 Nov 2020 09:55:05 +0000 (10:55 +0100)]
system-dummy: print configured mac address

Signed-off-by: Felix Fietkau <nbd@nbd.name>
3 years agovlandev: support bridge-vlan aliases in the vid config parameter
Felix Fietkau [Thu, 26 Nov 2020 09:23:01 +0000 (10:23 +0100)]
vlandev: support bridge-vlan aliases in the vid config parameter

This can be used to generate default network configurations that define
the lan/wan interfaces as vlandevs with custom names and specify the actual
VLAN ID only in the bridge-vlan section without repeating it elsewhere

Signed-off-by: Felix Fietkau <nbd@nbd.name>
3 years agovlandev: dump vlan id in device status
Felix Fietkau [Thu, 26 Nov 2020 09:20:11 +0000 (10:20 +0100)]
vlandev: dump vlan id in device status

Signed-off-by: Felix Fietkau <nbd@nbd.name>
3 years agosystem-linux: add retry for adding member devices to a bridge
Felix Fietkau [Mon, 23 Nov 2020 11:42:36 +0000 (12:42 +0100)]
system-linux: add retry for adding member devices to a bridge

When netifd tries to add bridge members brought up by hostapd asynchronously
(e.g. after an autochannel run), the first try often fails with EBUSY or
EAGAIN, since it's racing against hostapd's own setup.
Add retry logic, which includes checking if the device was added to the
bridge in the meantime to deal with this issue

Signed-off-by: Felix Fietkau <nbd@nbd.name>
3 years agosystem-linux: implement full device present state management for force-external devices
Felix Fietkau [Mon, 23 Nov 2020 11:11:42 +0000 (12:11 +0100)]
system-linux: implement full device present state management for force-external devices

We need to detect when devices are present, because they can be created
asynchronously by hostapd after they have already been added by the wifi
setup script

Signed-off-by: Felix Fietkau <nbd@nbd.name>
3 years agobridge-vlan: add support for defining aliases for vlan ids
Felix Fietkau [Fri, 20 Nov 2020 17:58:10 +0000 (18:58 +0100)]
bridge-vlan: add support for defining aliases for vlan ids

When defining a bridge-vlan like this:

config bridge-vlan
option device 'switch0'
option vlan '1'
option ports 'lan1 lan2 lan3 lan4'
option alias 'lan'

You can use switch0.lan instead of switch0.1 to refer to the VLAN.
This ensures that the VLAN ID can be kept in a single place in the config

Signed-off-by: Felix Fietkau <nbd@nbd.name>
3 years agointerface: do not force link-ext hotplug interfaces to present by default
Felix Fietkau [Fri, 20 Nov 2020 12:49:00 +0000 (13:49 +0100)]
interface: do not force link-ext hotplug interfaces to present by default

On wireless interfaces, hostapd can sometimes defer the bringup of secondary
virtual interfaces until autochannel or coex scan completes.
Do not force the present state in that case in order to avoid attempting
to bring up the device before it is ready

Signed-off-by: Felix Fietkau <nbd@nbd.name>
3 years agoconfig: initialize bridge and bridge vlans before other devices
Felix Fietkau [Wed, 18 Nov 2020 14:15:01 +0000 (15:15 +0100)]
config: initialize bridge and bridge vlans before other devices

This allows vlan devices to access bridge vlan data safely, regardless
of the order in which sections appear in the config

Signed-off-by: Felix Fietkau <nbd@nbd.name>
3 years agowireless: fix passing bridge name for vlan hotplug pass-through
Felix Fietkau [Wed, 18 Nov 2020 12:38:17 +0000 (13:38 +0100)]
wireless: fix passing bridge name for vlan hotplug pass-through

When preparing the interface for hotplug add, pass the bridge
device back to the caller, since it may not match the original device

Signed-off-by: Felix Fietkau <nbd@nbd.name>
3 years agosystem-linux: only overwrite dev->present state on check_state for simple devices
Felix Fietkau [Fri, 13 Nov 2020 11:44:56 +0000 (12:44 +0100)]
system-linux: only overwrite dev->present state on check_state for simple devices

After settting config_pending for vlan devices, a check_state call from
device_init_pending was leading to the vlan device present state being
overwritten because the linux device didn't exist yet, even though the
vlan code had already indicated its present state based on the lower dev.

Signed-off-by: Felix Fietkau <nbd@nbd.name>
3 years agobridge: only overwrite implicit vlan assignment if vlans are configured
Felix Fietkau [Thu, 5 Nov 2020 11:00:12 +0000 (12:00 +0100)]
bridge: only overwrite implicit vlan assignment if vlans are configured

When VLAN filtering is enabled, but no vlans are defined, the implicit
VLANs should stay, so that forwarding between ports still works.
This is useful for setups where VLANs are assigned by external scripts
instead of being configured via netifd

Signed-off-by: Felix Fietkau <nbd@nbd.name>
3 years agosystem-dummy: set present state only for simple devices
Felix Fietkau [Thu, 5 Nov 2020 10:58:40 +0000 (11:58 +0100)]
system-dummy: set present state only for simple devices

Fixes an issue with bringing up VLANs/bridges too early

Signed-off-by: Felix Fietkau <nbd@nbd.name>
3 years agobridge: fix use-after-free bug on bridge member free
Felix Fietkau [Wed, 4 Nov 2020 15:20:14 +0000 (16:20 +0100)]
bridge: fix use-after-free bug on bridge member free

When removing the device reference, the core might free the device.
Use device_lock/unlock to keep the reference valid until it is no longer needed

Signed-off-by: Felix Fietkau <nbd@nbd.name>
3 years agobridge: preserve hotplug ports on vlan update if config is unchanged
Felix Fietkau [Wed, 4 Nov 2020 11:19:20 +0000 (12:19 +0100)]
bridge: preserve hotplug ports on vlan update if config is unchanged

Fixes cleanup of port state

Signed-off-by: Felix Fietkau <nbd@nbd.name>
3 years agobridge: show vlans in device status
Felix Fietkau [Wed, 28 Oct 2020 17:54:39 +0000 (18:54 +0100)]
bridge: show vlans in device status

List vlans with member ports, VLAN IDs and flags

Signed-off-by: Felix Fietkau <nbd@nbd.name>
3 years agovlandev: add pass-through hotplug ops that pass the VLAN info to the bridge
Felix Fietkau [Fri, 7 Aug 2020 12:33:33 +0000 (14:33 +0200)]
vlandev: add pass-through hotplug ops that pass the VLAN info to the bridge

Only used for 802.1q devices

Signed-off-by: Felix Fietkau <nbd@nbd.name>
3 years agovlan: add pass-through hotplug ops that pass the VLAN info to the bridge
Felix Fietkau [Fri, 7 Aug 2020 12:26:33 +0000 (14:26 +0200)]
vlan: add pass-through hotplug ops that pass the VLAN info to the bridge

Signed-off-by: Felix Fietkau <nbd@nbd.name>
3 years agobridge: add support for defining port member vlans via hotplug ops
Felix Fietkau [Fri, 7 Aug 2020 12:19:06 +0000 (14:19 +0200)]
bridge: add support for defining port member vlans via hotplug ops

Signed-off-by: Felix Fietkau <nbd@nbd.name>
3 years agointerface: proto_ip: order by address index first
Yousong Zhou [Tue, 20 Oct 2020 02:49:18 +0000 (10:49 +0800)]
interface: proto_ip: order by address index first

At the moment, dnsmasq initscript generates dhcp-range for an interface
by inspecting first address of that interface from netifd ubus output.

Order by address index as specified in the uci config makes netifd ubus
output consistent with linux network interfaces' primary/secondary
address settings.  More importantly, the ubus output and dnsmasq config
generation will be more predictable.

Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
Acked-by: Hans Dedecker <dedeckeh@gmail.com>
3 years agodevice_addr: record address index as in the blob
Yousong Zhou [Wed, 21 Oct 2020 02:50:54 +0000 (10:50 +0800)]
device_addr: record address index as in the blob

Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
Acked-by: Hans Dedecker <dedeckeh@gmail.com>
3 years agoproto: rework parse_addr to return struct device_addr
Yousong Zhou [Wed, 14 Oct 2020 06:37:13 +0000 (14:37 +0800)]
proto: rework parse_addr to return struct device_addr

This is a preparation for the next commit to record address index for
the returned device_addr struct

Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
Acked-by: Hans Dedecker <dedeckeh@gmail.com>
3 years agobuild: find and use libnl header dirs
Yousong Zhou [Wed, 14 Oct 2020 08:04:01 +0000 (16:04 +0800)]
build: find and use libnl header dirs

Name of the libnl .pc file is libnl-3.0.pc

This commit is mainly for testing netifd build on usual Linux systems.

netifd Makefile in current OpenWrt build system specifies custom cmake
flags to directly point to libnl-tiny

Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
3 years agosystem-linux: initialize ifreq struct before using it
Alin Nastac [Thu, 8 Oct 2020 11:31:37 +0000 (13:31 +0200)]
system-linux: initialize ifreq struct before using it

Signed-off-by: Alin Nastac <alin.nastac@gmail.com>
3 years agonetifd: vxlan: add aging and maxaddress options
Johannes Kimmel [Fri, 4 Sep 2020 02:59:43 +0000 (04:59 +0200)]
netifd: vxlan: add aging and maxaddress options

For both options the values can just be passed to the kernel. All
unsigned values are accepted, thus no range checking required.

Signed-off-by: Johannes Kimmel <fff@bareminimum.eu>
3 years agonetifd: vxlan: add most missing boolean options
Johannes Kimmel [Fri, 4 Sep 2020 02:59:42 +0000 (04:59 +0200)]
netifd: vxlan: add most missing boolean options

adds the folloing missing options:
  - learning
  - rsc
  - proxy
  - l2miss
  - l3miss
  - gbp

See ip-link(3) for their meaning.

still missing:
  - external
  - gpe

I'm not sure how to handle them at the moment. It's unclear to me what
IFLA_VXLAN_* value corresponds to the 'external' option and according to
the manpage, gpe depends on it.

Signed-off-by: Johannes Kimmel <fff@bareminimum.eu>
3 years agonetifd: vxlan: refactor mapping of boolean attrs
Johannes Kimmel [Fri, 4 Sep 2020 02:59:41 +0000 (04:59 +0200)]
netifd: vxlan: refactor mapping of boolean attrs

Add a small function to handle boolean options and make use of it to handle:
  - rxcsum
  - txcsum

Signed-off-by: Johannes Kimmel <fff@bareminimum.eu>
3 years agonetifd: vxlan: handle srcport range
Johannes Kimmel [Fri, 4 Sep 2020 02:59:40 +0000 (04:59 +0200)]
netifd: vxlan: handle srcport range

This adds adds the ability to set the source port range for vxlan
interfaces.

By default vxlans will use a random port within the ephermal range as
source ports for packets. This is done to aid scaleability within a
datacenter.

But with these defaults it's impossible to punch through NATs or
traverese most stateful firewalls easily. One solution is to fix the
srcport to the same as dstport.

If only srcportmin is specified, then srcportmax is set in a way that
outgoing packets will only use srcportmin.

If a range is to be specified, srcportmin and srcportmax have to be
specified. srcportmax is exclusive.

If only srcportmax is specified, the value is ignored and defaults are
used.

Signed-off-by: Johannes Kimmel <fff@bareminimum.eu>
3 years agonetifd-wireless: parse 'osen' encryption
Daniel Golle [Tue, 8 Sep 2020 16:33:29 +0000 (17:33 +0100)]
netifd-wireless: parse 'osen' encryption

Support Hotspot 2.0 online signup with encryption, either as only
encryption type of a dedicated SSID or together with WPA-EAP for
single SSID setups.

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
3 years agointerface-ip: clear host bits of the device prefix
Hans Dedecker [Sun, 9 Aug 2020 20:46:54 +0000 (22:46 +0200)]
interface-ip: clear host bits of the device prefix

Clear the host bits of the device prefix in
interface_ip_add_device_prefix as interface_set_prefix_address just ORs
the calculated assignment part which would lead to an invalid IPv6
address if the host bits are not masked out

Suggested-by: Daniel Gröber <dxld@darkboxed.org>
Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
3 years agobridge: flush vlan list on bridge free
Felix Fietkau [Fri, 7 Aug 2020 10:07:53 +0000 (12:07 +0200)]
bridge: flush vlan list on bridge free

Fixes a potential memory leak

Signed-off-by: Felix Fietkau <nbd@nbd.name>
3 years agodevice: look up full device name before traversing vlan chain
Felix Fietkau [Mon, 27 Jul 2020 11:27:52 +0000 (13:27 +0200)]
device: look up full device name before traversing vlan chain

The user may have configured a VLAN device with explicit settings and the same
name by adding a config device section

Signed-off-by: Felix Fietkau <nbd@nbd.name>
3 years agoconfig: enable bridge vlan filtering by default for bridges that define VLANs
Felix Fietkau [Sat, 18 Jul 2020 10:01:23 +0000 (12:01 +0200)]
config: enable bridge vlan filtering by default for bridges that define VLANs

Only enables it if the config option is not present. It can still be disabled.

Signed-off-by: Felix Fietkau <nbd@nbd.name>
3 years agobridge: add support for VLAN filtering
Felix Fietkau [Wed, 15 Jul 2020 15:18:20 +0000 (17:18 +0200)]
bridge: add support for VLAN filtering

VLANs can be defined using bridge-vlan sections, like the following example:

config bridge-vlan
option device 'switch0'
option vlan '1'
option ports "lan1 lan2 lan3 lan4:t*"

Each member port can be confgured with optional attributes after ':'
 - t: member port is tagged
 - *: This is the primary VLAN for the port (PVID)

VLAN member interfaces are automatically added as bridge members

Signed-off-by: Felix Fietkau <nbd@nbd.name>
3 years agobridge: add support for adding vlans to a bridge
John Crispin [Sun, 12 Jul 2020 16:50:19 +0000 (18:50 +0200)]
bridge: add support for adding vlans to a bridge

Add a rtnl helper for adding vlans to a bridge interface.

Signed-off-by: John Crispin <john@phrozen.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>