1437 Commits

Author SHA1 Message Date
Felix Fietkau
777f5942fa system-linux: only parse device status for AF_UNSPEC link messages
In bridge messages (family = AF_BRIDGE), the commands are the same, but the
contents are different, and this can confuse netifd into thinking that devices
are down, while they are actually up.

Signed-off-by: Felix Fietkau <nbd@nbd.name>
2025-10-20 23:37:36 +02:00
Felix Fietkau
b6d371f307 system-linux: handle RTM_DELLINK events for device state tracking
Add RTM_DELLINK handling to properly track device lifecycle. When a
device is deleted, update its state with flags=0 to mark it as not
present. This improves synchronization compared to only relying on
the hotplug handler.

Signed-off-by: Felix Fietkau <nbd@nbd.name>
2025-10-20 19:46:54 +02:00
Felix Fietkau
df2f5c9a30 veth: delete device before creation to handle stale state
When a veth device already exists in the kernel (from a previous failed
cleanup or external creation), attempting to create it again with
NLM_F_EXCL fails with -EEXIST. This leaves the device in a broken state
where netifd marks it as present but cannot bring it up.

Signed-off-by: Felix Fietkau <nbd@nbd.name>
2025-10-20 19:44:20 +02:00
Felix Fietkau
649028013a config: fix overriding bridge-vlan sections via procd data
Allow procd data with the same object name as an existing config section to
override the data from the config section.

Signed-off-by: Felix Fietkau <nbd@nbd.name>
2025-10-06 09:14:14 +02:00
Felix Fietkau
ecca21ca07 system: add logging wrappers for basic system functions
Helps with debugging by providing context for the calls

Signed-off-by: Felix Fietkau <nbd@nbd.name>
2025-09-30 14:06:30 +02:00
Felix Fietkau
22216cac7c bridge: fix reload when ports refer to aliased vlans on another bridge
When aliases are derived from bridge-vlan section, the device lookup needs
to be repeated on reload.

Signed-off-by: Felix Fietkau <nbd@nbd.name>
2025-09-30 11:30:47 +02:00
Felix Fietkau
c3bf8fd913 interface: fix reload for devices that point to vlan aliases
When aliases are derived from bridge-vlan section, the device lookup needs
to be repeated on reload.

Signed-off-by: Felix Fietkau <nbd@nbd.name>
2025-09-30 11:01:06 +02:00
Felix Fietkau
2a85440bcd netifd: fix misplaced ")"
Fixes memory corruption issue

Fixes: https://github.com/openwrt/netifd/issues/54
Signed-off-by: Felix Fietkau <nbd@nbd.name>
2025-09-12 11:26:52 +02:00
Felix Fietkau
8c139e183e bridge: fix changing the vlan local flag at runtime
Signed-off-by: Felix Fietkau <nbd@nbd.name>
2025-08-14 18:57:22 +02:00
Felix Fietkau
a0be934399 examples: sync wireless.uc
Signed-off-by: Felix Fietkau <nbd@nbd.name>
2025-08-12 20:18:52 +02:00
Felix Fietkau
575b04326e config: add support for defining interfaces via procd data
Uses the data type 'network-interface'

Signed-off-by: Felix Fietkau <nbd@nbd.name>
2025-08-12 20:14:05 +02:00
Felix Fietkau
813b9882db config: add support for defining devices via procd data
Uses the data type 'network-device'

Signed-off-by: Felix Fietkau <nbd@nbd.name>
2025-08-12 20:14:05 +02:00
Felix Fietkau
6ead304877 global: use blobmsg_parse_attr
Avoids mismatch in blob vs blobmsg parsing, simplifies code.

Signed-off-by: Felix Fietkau <nbd@nbd.name>
2025-08-12 20:14:05 +02:00
Felix Fietkau
94c3869941 interface: avoid memleaks on invalid interfaces
Free strings that were allocated with strdup in interface_alloc

Signed-off-by: Felix Fietkau <nbd@nbd.name>
2025-08-12 19:53:06 +02:00
Felix Fietkau
843a736a4e ubus: fix type check in procd ubus data callback
Use the correct iterator variable

Signed-off-by: Felix Fietkau <nbd@nbd.name>
2025-08-12 19:43:07 +02:00
Felix Fietkau
3d140ec0b8 examples: sync scripts with openwrt
Signed-off-by: Felix Fietkau <nbd@nbd.name>
2025-08-06 12:28:45 +02:00
Felix Fietkau
964c9aa3ec ucode: fix passing network vlan on handle_link
Use an extra container element to ensure that the type matches

Signed-off-by: Felix Fietkau <nbd@nbd.name>
2025-08-06 12:03:59 +02:00
Felix Fietkau
c3cfd8df02 system-linux: add variable initialization to avoid compiler warnings on older gcc
Signed-off-by: Felix Fietkau <nbd@nbd.name>
2025-08-03 06:19:32 +02:00
Felix Fietkau
b563d7b2e6 ucode: add missing return code checks for fchdir/chdir
Fixes build issue on glibc

Signed-off-by: Felix Fietkau <nbd@nbd.name>
2025-08-03 06:16:44 +02:00
Felix Fietkau
74c22601ba wireless: add MLO support to example scripts
Signed-off-by: Felix Fietkau <nbd@nbd.name>
2025-08-02 16:44:19 +02:00
Felix Fietkau
d9f2dd2614 wireless: replace with ucode scripts
Wireless configuration is a lot easier to deal with in a high level language
like ucode. Replace lots of C code with vastly simpler scripts.

Signed-off-by: Felix Fietkau <nbd@nbd.name>
2025-08-02 16:44:04 +02:00
Felix Fietkau
7a3b281230 update example mac80211 script and wireless config
Signed-off-by: Felix Fietkau <nbd@nbd.name>
2025-06-11 10:29:41 +02:00
Felix Fietkau
c3a0255e21 scripts: fix dummy mode on systems where libubox is in /usr/local
Signed-off-by: Felix Fietkau <nbd@nbd.name>
2025-06-11 10:29:41 +02:00
Felix Fietkau
471d9d6abb CMakeLists.txt: bump minimum required version
Signed-off-by: Felix Fietkau <nbd@nbd.name>
2025-06-11 10:29:41 +02:00
Felix Fietkau
3a78780658 system-dummy: add missing vrf functions
Signed-off-by: Felix Fietkau <nbd@nbd.name>
2025-06-11 10:29:18 +02:00
egc112
7901e66c5f netifd: iprule add sport and dport
Maintainer: @nbd, @robimarko

I was missing the ip rules for `sport` and `dport` in netifd and although I have a working C knowledge, I have little netlink knowledge and it is the first time I looked into netifd but after some research I could come up with a working patch to implement `option sport` and `option dport`.

I hope you can have a look and implement these useful options.

Run tested: Dynalink DL-WRX36 (ipq8074) running Main Snapshot r29276-963d320086 20-apr-2025

Example 1 sport:
```
config rule
	option src '192.168.9.23/32'
	option sport '1194'
	option lookup 'main'
```
Result:
```
root@DL-WRX36:~# ip ru
0:      from all lookup local
1:      from 192.168.9.23 sport 1194 lookup main
```

Example 2  sport range:
```
config rule
	option src '192.168.9.23/32'
	option sport '1194-1195'
	option lookup 'main'
```
Result:
```
root@DL-WRX36:~# ip ru
0:      from all lookup local
1:      from 192.168.9.23 sport 1194-1195 lookup main
```

Example 3 dport:
```
config rule
	option src '192.168.9.23/32'
	option dport '1294'
	option lookup 'main'
```
Result:
```
root@DL-WRX36:~# ip ru
0:      from all lookup local
1:      from 192.168.9.23 dport 1294 lookup main
```

Example 4  dport range:
```
config rule
	option src '192.168.9.23/32'
	option dport '1294-1295'
	option lookup 'main'
```
Result:
```
root@DL-WRX36:~# ip ru
0:      from all lookup local
1:      from 192.168.9.23 dport 1294-1295 lookup main
```
Example 5 sport dport:
```
config rule
	option src '192.168.9.23/32'
	option sport '1194-1195'
	option dport '1294-1295'
	option lookup 'main'
```
Result:
```
root@DL-WRX36:~# ip ru
0:      from all lookup local
1:      from 192.168.9.23 sport 1194-1195 dport 1294-1295 lookup main
```

Signed-off-by: Erik Conijn <egc112@msn.com>
Link: https://github.com/openwrt/netifd/pull/47
Signed-off-by: Robert Marko <robimarko@gmail.com>
2025-05-23 13:18:40 +02:00
Ivan Mosin
d476e18e8d iprule: resolve ipproto by name
Handle ipproto as an string. Set protocol in lowercase for musl libc compatibility.

Signed-off-by: Ivan Mosin <astrcomp@gmail.com>
Link: https://github.com/openwrt/netifd/pull/43
Signed-off-by: Robert Marko <robimarko@gmail.com>
2025-05-18 18:22:22 +02:00
Fabian Bläse
723c699e84 Restore disable_ipv6 sysctl after removing a device from bridge or bond
If a device is added to a bond or bridge, the disable_ipv6 sysctl is
set, so that no link local addresses are present on the slave devices.

However, the disable_ipv6 sysctl is not restored after removing the
device from the bridge or bond. Therefore, no IPv6 link local addresses
are added and autoconfiguration does not work.

Set the disable_ipv6 to '0' on device removal from bridge or bond.

Signed-off-by: Fabian Bläse <fabian@blaese.de>
Link: https://github.com/openwrt/netifd/pull/40
Signed-off-by: Robert Marko <robimarko@gmail.com>
2025-05-17 11:35:54 +02:00
Nicolò
e8bbf246ce system-linux: fix sysfs name for all_ports_active flag
Right now system-linux writes to the wrong file (not existing)
 to configure the "all_ports_active" flag for bonding devices.
Write to the correct "bonding/all_slaves_active" path.

Signed-off-by: Nicolò Veronese <nicveronese@gmail.com>
Link: https://github.com/openwrt/netifd/pull/49
Signed-off-by: Robert Marko <robimarko@gmail.com>
2025-05-17 11:33:16 +02:00
Nicolò
a1b6386a20 device: fix bonding primary port selection
The confuguration of the primary port was read
 but never used to properly configure the right port.

This patch fix this, and another small fix suggested
 by nbd to properly handle the "reload" of the
 primary interface when is changed.

Co-developed-by: Felix Fietkau <nbd@nbd.name>
Signed-off-by: Nicolò Veronese <nicveronese@gmail.com>
Link: https://github.com/openwrt/netifd/pull/49
Signed-off-by: Robert Marko <robimarko@gmail.com>
2025-05-17 11:33:16 +02:00
Maxim Anisimov
d610d68c71 device: add support for configuring vrf
Config example:
...
config device
	option type 'vrf'
	option name 'dcn'
	option table '20'
	option mtu '1500'
	option ipv6 '0'
	list ports 'l2tp-wanvpn'
	list ports 'lan3'

config interface 'dcn'
	option proto 'none'
	option device 'dcn'
...

Note: using "ports" in config simplifies luci integration

Tested-by: Paul Donald <newtwen+github@gmail.com>
Signed-off-by: Maxim Anisimov <maxim.anisimov.ua@gmail.com>
Link: https://github.com/openwrt/netifd/pull/38
Signed-off-by: Robert Marko <robimarko@gmail.com>
2025-05-17 11:32:17 +02:00
Paul Donald
61ae5732ad iprule: amend ipproto netlink nla_put_u32 to nla_put_u8
FRA_IP_PROTO expects an 8 bit value.

Follow-up fix for d29cf70747.

uint8 prevents the kernel log message:
netlink: 'netifd': attribute type 22 has an invalid length.

The message is otherwise harmless; ip rules using ipproto are created
successfully.

Tested on 24.10-snapshot

Signed-off-by: Paul Donald <newtwen+github@gmail.com>
Link: https://github.com/openwrt/netifd/pull/42
Signed-off-by: Robert Marko <robimarko@gmail.com>
2025-04-02 10:58:38 +02:00
Felix Fietkau
ea01ed41f3 interface: remove unnecessary NULL checks before free()
Calling free(NULL) is always valid

Signed-off-by: Felix Fietkau <nbd@nbd.name>
2024-12-17 14:25:21 +01:00
Felix Fietkau
058a099f5b interface: fix memleak and reload issue for the zone attribute
- consider the field in the reload codepath
- free the attribute on interface free

Signed-off-by: Felix Fietkau <nbd@nbd.name>
2024-12-17 14:23:06 +01:00
Felix Fietkau
768027c5a7 system-linux: restore reading flags from netlink messages
The SIOCGIFFLAGS ioctl truncates returned flags to u16, and the IFF_LOWER_UP
flag exceeds that size. Because of that, the carrier status needs to be pulled
from the netlink message.

Signed-off-by: Felix Fietkau <nbd@nbd.name>
2024-11-27 21:02:06 +01:00
Paul Donald
d29cf70747 iprule: add ipproto property
```
config rule
	option ...
	option ipproto '17'
```

This allows handling rules which anchor to protocol number like:

`ip ru add from all ipproto udp table udp_table prior 10`

Handle ipproto as an unsigned integer.

https://www.iana.org/assignments/protocol-numbers/protocol-numbers.xhtml

Example:

config rule
	option in 'lan'
	option src '10.48.0.0/16'
	option out 'lan'
	option dest '192.168.1.144/32'
	option lookup 'main'
	option ipproto '17'

Results in

~# ip rule
0:	from all lookup local
1:	from 10.48.0.0/16 to 192.168.1.144 iif br-lan oif br-lan ipproto udp lookup main

Tested on 23.05.5 x86_64

Signed-off-by: Paul Donald <newtwen+github@gmail.com>
2024-11-25 10:41:57 +01:00
Felix Fietkau
a39fe3a8b1 wireless: add support for adding a list of devices for a wifi-iface
Simplifies handling of a single SSID on multiple radios.

Signed-off-by: Felix Fietkau <nbd@nbd.name>
2024-11-19 13:56:24 +01:00
Felix Fietkau
cd96f61ba6 proto-shell: fix spurious interface teardowns with host deps
Only treat IFEV_UP_FAILED, IFEV_DOWN and IFEV_FREE as down indicators

Signed-off-by: Felix Fietkau <nbd@nbd.name>
2024-11-18 21:00:10 +01:00
Felix Fietkau
86da5cbcdb system-linux: do not pull ifindex/flags from netlink messages on rtnl events
rtnl event processing might be delayed due to other calls / state changes.
That can lead to devices toggled up/down unnecessarily.

Signed-off-by: Felix Fietkau <nbd@nbd.name>
2024-11-18 14:17:47 +01:00
Felix Fietkau
34eb11eb6f device/interface: add "tags" attribute from config to status dump
This allows annotating interfaces/devices in the config in a way that can be
queried through status. One example use case is to mark wifi interfaces for
use with specific services without having to explicitly reference sections
from elsewhere.

Signed-off-by: Felix Fietkau <nbd@nbd.name>
2024-11-08 10:33:45 +01:00
Felix Fietkau
992d33cb42 ubus: add notifications on wireless device state changes
Provide notifications similar to interface state changes

Signed-off-by: Felix Fietkau <nbd@nbd.name>
2024-11-08 10:07:33 +01:00
Felix Fietkau
4fe997b61d system-dummy: add system_if_apply_settings_after_up
Signed-off-by: Felix Fietkau <nbd@nbd.name>
2024-10-21 17:41:56 +02:00
Felix Fietkau
6ab44a2413 fix signed/unsigned comparison warnings
Signed-off-by: Felix Fietkau <nbd@nbd.name>
2024-10-21 17:41:19 +02:00
Felix Fietkau
e93f6c3fc7 main: fix format string related warnings for log/debug printf functions
Signed-off-by: Felix Fietkau <nbd@nbd.name>
2024-10-20 21:07:11 +02:00
Felix Fietkau
3c6265fdbd wireless: reload wireless device if any vif network bridge changes ifindex
This fixes an issue where wireless vifs were not added back after the bridge
was recreated due to config changes (e.g. after switching to vlan filtering).

Signed-off-by: Felix Fietkau <nbd@nbd.name>
2024-10-06 19:40:58 +02:00
Felix Fietkau
24f9a93a95 interface: fix regression on adding hotplug devices to interfaces
Adding the same device to an interface again led to a call chain that ended
up removing the device again through device callbacks.
Fix this by only toggling the interface available status when the device is
still the same.

Signed-off-by: Felix Fietkau <nbd@nbd.name>
2024-09-21 18:26:51 +02:00
Daniel Golle
02aa43d82d Revert "system-linux: re-apply ethtool on phy attachment"
This reverts commit 68c8a4f94c.

Matching on flags IFF_UP AND NOT IFF_LOWER_UP and then reapply ethtool
settings freaks out some PHY drivers. While a better method is being
worked on, revert the problematic solution.

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
2024-09-12 15:33:26 +02:00
Felix Fietkau
61c606d6e6 device: simplify external device settings handling
Use the normal set_state function, but leave out the system_if_up/down part.
Fixes a race condition that prevented properly applying device settings

Signed-off-by: Felix Fietkau <nbd@nbd.name>
2024-09-05 10:12:07 +02:00
Felix Fietkau
cd2a7964f2 device: revert to explicit device_set_present calls
Works around unknown hangs exposed by the recent changes

Signed-off-by: Felix Fietkau <nbd@nbd.name>
2024-09-03 15:13:49 +02:00
Felix Fietkau
cdb41673ce device: remove redundant newlines from debug messages
Signed-off-by: Felix Fietkau <nbd@nbd.name>
2024-09-03 12:06:39 +02:00