summaryrefslogtreecommitdiff
path: root/ubus.c
Commit message (Collapse)AuthorAgeFilesLines
* netifd: Fix multiple -Wsign-compare warningsHauke Mehrtens2023-02-191-2/+2
| | | | | | | | | | | | | | | | | | This fixes warnings like this: warning: comparison of integer expressions of different signedness: 'int' and 'long unsigned int' [-Wsign-compare] Mostly this was an int compared to a size_t returned by ARRAY_SIZE(). The easiest fix is to count on the size_t type. The ifindex is sometimes an unsigned int and sometimes a signed int in the kernel interfaces. I think it normally fits into an unsigned 16 bit value, so this should be fine. Do the one comparison where the compiler complains as a long. Casting the result of sizeof() to int should be safe. These values are never out of range of int. Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
* interface: support "zone" config optionRafał Miłecki2022-08-111-0/+3
| | | | | | | | | | | Many protocol handlers support "zone" option independently and they pass it in the "data". Then it's read e.g. by a firewall[34]. Add support for "zone" directly to the netifd so: 1. It works for all protocols 2. Handlers don't have to duplicate code Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
* interface-ip: add support for excluding interfaces in host route lookupFelix Fietkau2022-05-191-2/+7
| | | | | | | | When adding host routes needed for an interface to communicate, it may be necessary to skip the interface itself, in case it provides a default route. This helps with avoiding accidental loops Signed-off-by: Felix Fietkau <nbd@nbd.name>
* interface, ubus: rework netns up/downDaniel Golle2021-10-131-14/+15
| | | | | | | | 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>
* netifd: rework/fix device free handlingFelix Fietkau2021-09-271-1/+1
| | | | | | | | | 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>
* bridge: add support for an external STP daemonFelix Fietkau2021-08-241-0/+16
| | | | | | | | 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>
* ubus: add a dummy mode ubus call to simulate hotplug eventsFelix Fietkau2021-06-191-0/+36
| | | | | | Can be used to test the device hotplug handling Signed-off-by: Felix Fietkau <nbd@nbd.name>
* device: add support for configuring devices with external auth handlerFelix Fietkau2021-05-171-0/+6
| | | | | | | | | | | 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>
* extdev: add support for external device handlersArne Kappen2021-03-311-0/+7
| | | | | | | | | | 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>
* wireless: fix passing bridge name for vlan hotplug pass-throughFelix Fietkau2020-11-181-4/+12
| | | | | | | 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>
* bridge: add support for defining port member vlans via hotplug opsFelix Fietkau2020-10-281-1/+4
| | | | Signed-off-by: Felix Fietkau <nbd@nbd.name>
* interface: allow renaming interface when moving to jail netnsDaniel Golle2020-04-141-0/+3
| | | | | | | | | | Introduce jail_ifname option to define the name of a Linux network interface when moved into a jail's network namespace. This is useful for containers which expect the network interface to have a specific name (eg. 'host0' in case of systemd). While at it, clean-up and fix bugs in jail interface up/down routines. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* add basic support for jail network namespacesDaniel Golle2020-01-181-0/+43
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Prepare netifd for handling procd service jails having their own network namespace. Intefaces having the jail attribute will only be brought inside the jail's network namespace by procd calling the newly introduced ubus method 'netns_updown'. Currently proto 'static' is supported and configuration changes are not yet being handled (ie. you'll have to restart the jailed service for changes to take effect). Example /etc/config/network snippet: config device 'veth0' option type 'veth' option name 'vhost0' option peer_name 'virt0' config interface 'virt' option type 'bridge' list ifname 'vhost0' option proto 'static' option ipaddr '10.0.0.1' option netmask '255.255.255.0' config interface 'virt0' option ifname 'virt0' option proto 'static' option ipaddr '10.0.0.2' option netmask '255.255.255.0' option gateway '10.0.0.1' option dns '10.0.0.1' option jail 'transmission' Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* wireless: add ubus method for reloading configurationJohn Crispin2019-10-251-0/+23
| | | | Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* treewide: pass bool as second argument of blobmsg_check_attrHans Dedecker2019-05-161-1/+1
| | | | | | blobmsg_check_attr() takes as second argument a bool; fix it where needed Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
* interface: add neighbor config supportmeurisa2019-04-151-0/+45
| | | | | | | | | | | | | | | | | | The neighbor or neighbor6 network section makes neighbours configurable via UCI or proto shell handlers. It allows to install neighbor proxy entries or static neighbor entries The neighbor or neighbor6 section has the following types: interface : declares the logical OpenWrt interface ipaddr : the ip address of the neighbor mac : the mac address of the neighbor proxy : specifies whether the neighbor ia a proxy entry (can be 1 or 0) router : specifies whether the neighbor is a router (can be 1 or 0) Signed-off-by: Alexander Meuris <meurisalexander@gmail.com> Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
* netifd: fix resource leak on error in netifd_add_dynamic()Hans Dedecker2018-11-261-4/+5
| | | | Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
* interface: rework code to get rid of interface_set_dynamicHans Dedecker2018-11-131-13/+6
| | | | | | | Integrate dynamic interface creation code into interface_alloc and __interface_add so we can get rid of interface_set_dynamic Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
* ubus: display correct prefix size for IPv6 prefix addressHans Dedecker2018-07-161-1/+1
| | | | | | | Make sure the displayed prefix size is identical to the kernel installed prefix size for local IPv6 prefix addresses Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
* ubus: display the point-to-point IPv4 addressHans Dedecker2017-10-181-0/+6
| | | | | | | 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>
* ubus: fix ubus error code on reload failureHans Dedecker2017-10-071-1/+1
| | | | | | | Return the more approriate error code UBUS_STATUS_NOT_FOUND in case network reload fails Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
* ubus: remove superfluous error check in netifd_add_dynamicHans Dedecker2017-06-171-5/+0
| | | | | | | | | | | | | | | | 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>
* ubus: add interface method to trigger renew eventMatthias Schiffer2017-04-221-0/+14
| | | | | | | | | 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>
* netifd: propagate error code on netifd_reload()Alexandru Ardelean2017-04-051-2/+4
| | | | | | | | | | | | | | | 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>
* interface: add prefix assignment priority supportHans Dedecker2017-02-111-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | 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]
* treewide: fix white space errorsHans Dedecker2017-01-311-6/+3
| | | | Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
* interface-ip: route proto config support (FS#170)Hans Dedecker2017-01-251-0/+3
| | | | | | | | | | | 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>
* ubus: Display the IPv6 prefix assigned addressHans Dedecker2016-12-121-1/+10
| | | | | | | | | 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>
* ubus: Use device_find to find a device when displaying device infoHans Dedecker2016-11-221-1/+1
| | | | | | | | | | | | 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>
* interface-ip: DNS name server sorting support in resolv.conf.autoHans Dedecker2016-09-141-0/+1
| | | | | | | | | | | | | | | | | | 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>
* device: prepare for adding device handlers dynamicallyArne Kappen2016-08-261-1/+1
| | | | | | | | - 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]
* system-linux: Replace device_get by device_find where appropriateHans Dedecker2016-06-061-1/+1
| | | | | | | 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>
* ubus: Fix possible segfaultHans Dedecker2016-02-011-0/+3
| | | | Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
* interface: Trigger interface update event when interface data is updated via ↵Hans Dedecker2015-12-191-9/+1
| | | | | | | | | ubus Interface update event will trigger an interface hotplug event and an ubus notify event which will inform subscribers about the updated interface data field Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
* ubus: export dynamic-flag for interfacesSteven Barth2015-11-191-0/+1
| | | | Signed-off-by: Steven Barth <steven@midlink.org>
* Changes for more readability.Yousong Zhou2015-08-251-1/+1
| | | | Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
* Fix removal of dynamic interfacesSteven Barth2015-06-081-26/+0
| | | | | | Also remove obsolete "del_dynamic" call (use "down" instead) Signed-off-by: Steven Barth <steven@midlink.org>
* Cleanup issues reported by scan-buildSteven Barth2015-04-141-1/+1
| | | | Signed-off-by: Steven Barth <steven@midlink.org>
* netifd: Allow to add link devices which can be marked as non externalHans Dedecker2014-07-301-6/+23
| | | | Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
* add_dynamic: remove redundant codeSteven Barth2014-07-291-7/+0
| | | | | | | device_config is unneeded since add_dynamic is used to create aliases checking of setup state is unneeded because of race condition fixes Signed-off-by: Steven Barth <steven@midlink.org>
* ubus: add del_dynamic as complement to add_dynamicSteven Barth2014-07-281-0/+26
| | | | Signed-off-by: Steven Barth <steven@midlink.org>
* Only add dynamic interfaces if the underlying interface is readySteven Barth2014-07-251-0/+4
| | | | Signed-off-by: Steven Barth <steven@midlink.org>
* netifd: Route type supportHans Dedecker2014-06-181-0/+3
| | | | | | | | Patch adds route type support in netifd by means of the route parameter type. By default the route type was unicast; the parameter adss support for local/broadcast/multicast/unicast routes which will be put into the appropriate routing table. If route type parameter is unset the route type will be unicast as before. Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
* add a interface. prefix to ubus_notify callsJohn Crispin2014-06-051-1/+1
| | | | Signed-off-by: John Crispin <blogic@openwrt.org>
* netifd: Mark interface as dynamic after it has been added in the interface listHans Dedecker2014-04-241-2/+5
| | | | | | | Adding an interface in the interface list in case of a config update will override the node version of the old interface and thus overriding the dynamic interface marker. In case of config update interface_set_dynamic is done on an invalid interface pointer as the new interface pointer has been freed. Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
* ubus: check the l3_dev pointer before dereferencing itFelix Fietkau2014-04-191-1/+2
| | | | Signed-off-by: Felix Fietkau <nbd@openwrt.org>
* ubus: use list_empty() instead of the compat wrapperFelix Fietkau2014-03-211-1/+1
| | | | Signed-off-by: Felix Fietkau <nbd@openwrt.org>
* ubus: fix displaying interface data itemsFelix Fietkau2014-03-201-1/+1
| | | | Signed-off-by: Felix Fietkau <nbd@openwrt.org>
* Revert "ubus events: don't incorrectly announce an interface as being up"Felix Fietkau2014-03-111-5/+5
| | | | | | Made obsolete by b114b86c70766f67f503077ad1de013c17fbf366 This reverts commit 4d1a597f65bbb49aa843112812d5ca929478c706.
* ubus events: don't incorrectly announce an interface as being upSteven Barth2014-03-051-5/+5
| | | | Signed-off-by: Steven Barth <steven@midlink.org>