summaryrefslogtreecommitdiffhomepage
path: root/lib/rtnl.c
AgeCommit message (Collapse)Author
2024-01-10rtnl: increase event socket rx buffer size limit to 1 MiBJo-Philipp Wich
Use the same RX buffer size which iproute2 uses as default, in order to avoid (or rather, delay as much as possible) ENOBUFS conditions when receiving a large burst of netlink notifications. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-01-10rtnl: optimize reception of rtnl eventsJo-Philipp Wich
Once we're notified about pending data on the netlink event socket, try to receive as much messages as possible in order to empty the socket buffer. In contrast to the previous implementation which received one message per epoll read notification, this avoids some premature ENOBUFS situations when a huge burst of messages arrives, e.g. due to kernel side GC runs on the neighbor table. Since libnl's nl_recvmsgs*() functions do not expose the underlying -1 error returned by the recvmsg() calls, we need to indirectly check for errors through errno variable, so clear it out both before the recvmsgs() call and after successfully completing a message reception callback invocation. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-01-10rtnl: store callback in listener registry only on successJo-Philipp Wich
Only store the callback reference in the registry once the listener context was successfully initialized, to avoid keeping a lingering entry when invalid parameters are passed. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2023-09-22rtnl: update the link attr TODOsPacket Please
Signed-off-by: Packet Please <pktpls@systemli.org>
2023-09-22rtnl: add IFLA_TARGET_NETNSID for operating in other namespacesPacket Please
Signed-off-by: Packet Please <pktpls@systemli.org>
2023-08-09treewide: consolidate platform specific code in platform.cJo-Philipp Wich
Get rid of most __APPLE__ guards by introducing a central platform.c unit providing drop-in replacements for missing APIs. Also move system signal definitions into the new platform file to be able to share them with the upcoming debug library. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2023-02-13rtnl: add missing uc_vm_registry_set callFelix Fietkau
Fixes maintaining the listener array Signed-off-by: Felix Fietkau <nbd@nbd.name>
2023-02-13rtnl: add missing ucv_get() callsFelix Fietkau
Arguments stored in the registry need an extra reference Signed-off-by: Felix Fietkau <nbd@nbd.name>
2023-01-31rtnl: add support for registering an uloop based listenerFelix Fietkau
Similar to nl80211 uloop listener Signed-off-by: Felix Fietkau <nbd@nbd.name>
2022-07-03rtnl: fix parsing/creation of IFLA_AF_SPEC RTA for the AF_BRIDGE familyJo-Philipp Wich
Some pecularities in the encoding of the IFLA_AF_SPEC attribute make it unsuitable for table driven parsing/generation. To solve this issue, introduce specific datatype handling for IFLA_AF_SPEC and parse/generate the RTA depending on the address family of the containing netlink message. Also add some missing constants while we're at it. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-06-28rtnl: expose IFLA_STATS64 contentsJo-Philipp Wich
Decode IFLA_STATS64 attribute and make contained counters available to ucode. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-06-28rtnl: expose ifinfomsg.ifi_change memberJo-Philipp Wich
For certain operations, such as bringing up interfaces, it is required to initialize the ifi_change mask in the ifinfomsg struct. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-06-27rtnl: update NETLINK_GET_STRICT_CHK socket flag with every requestJo-Philipp Wich
So far the NETLINK_GET_STRICT_CHK socket flag was only set on the implicit socket creation performed during the first request and ignored for subsequent ones which made it impossible to perform only some requests with enabled strict checking. Modify the logic to check the flag state for every request and change it if needed. This allows performing both strict and non-strict requests over the same connection. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-06-08Merge pull request #83 from jow-/rtnl-fix-linkinfo-segfaultJo-Philipp Wich
rtnl: fix segmentation fault on parsing linkinfo RTA without data
2022-06-08Merge pull request #82 from jow-/rtnl-zero-msghdrJo-Philipp Wich
rtnl: zero request message headers
2022-06-08Merge pull request #81 from jow-/rtnl-fix-ack-handlingJo-Philipp Wich
rtnl: fix premature netlink reply receive abort
2022-06-08rtnl: fix segmentation fault on parsing linkinfo RTA without dataJo-Philipp Wich
Some link types, such as veth, yield an IFLA_LINKINFO nla without an embedded IFLA_INFO_DATA / INFLA_INFO_SLAVE_DATA nla which causes the nla converter to dereference a NULL nla pointer. Properly deal with such cases and check for the existence of the child nla before attempting to parse it. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-06-08rtnl: zero request message headersJo-Philipp Wich
For route netlink request messages having a header struct, uc_nl_request() invokes nlmsg_reserve() to reserve room for the struct data but the nlmsg_reserve() function only zeroes additional alignment bytes, not the actual reserved buffer space. Extend the existing logic to explicitly zero out the reserved header space in order to avoid sending uninitialized struct member values to the kernel. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-06-08rtnl: fix premature netlink reply receive abortJo-Philipp Wich
The nl_recvmsgs() logic in uc_nl_request() incorrectly stopped reading the socket before the netlink ACK message was handled for non-multipart replies. This caused subsequent requests to incorrectly receive the ACK of the previous request, leading to a failure to receive the actual reply. Fix this issue by continue reading the socket until either the finish callback for multipart (dump) messages or the ack callback for non- multipart messages was received. This fix is basically the same as the one applied to the nl80211 module in 54ef6c0 ("nl80211: fix premature netlink reply receive abort"). Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-06-04rtnl: avoid stray "netlink: %d bytes leftover after parsing attributes."Jo-Philipp Wich
Some nested RTAs such as IFLA_INET_CONF do not contain actual sub-RTAs but just an array of integers. Avoid calling a no-op `nla_parse()` for such attributes to suppress the non-harmful leftover bytes warning emitted by libnl. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-01-18lib: replace usages of vasprintf() with xvasprintf()Jo-Philipp Wich
This avoid triggering -Werror=unused-result compilation failures with certain toolchains. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-01-04treewide: rework numeric value handlingJo-Philipp Wich
- Parse integer literals as unsigned numeric values in order to be able to represent the entire unsigned 64bit value range - Stop parsing minus-prefixed integer literals as negative numbers but treat them as separate minus operator followed by a positive integer instead - Only store unsigned numeric constants in bytecode - Rework numeric comparison logic to be able to handle full 64bit unsigned integers - If possible, yield unsigned 64 bit results for additions - Simplify numeric value conversion API - Compile code with -fwrapv for defined signed overflow semantics Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-09-15rtnl: automatically derive message family from certain address attrsJo-Philipp Wich
# ucode -mrtnl -Rs 'printf("%.J", rtnl.request(rtnl.const.RTM_GETROUTE, 0, { dst: "8.8.8.8" }))' { "family": 2, "tos": 0, "protocol": 0, "scope": 0, "type": 1, "flags": 512, "dst": "8.8.8.8/32", "oif": "onboard", "gateway": "10.11.12.13", "prefsrc": "10.11.12.7", "cacheinfo": { "clntref": 2, "lastuse": 0, "expires": 0, "error": 0, "used": 0, "id": 0, "ts": 0, "tsage": 0 }, "table": 254, "uid": 0 } Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-09-15rtnl: expose IPv4 and IPv6 devconfig informationJo-Philipp Wich
# ucode -mrtnl -Rs 'printf("%.J", rtnl.request(rtnl.const.RTM_GETLINK, 0, { dev: "lo" }))' { "family": 0, "type": 772, "dev": "lo", "flags": 65609, "address": "00:00:00:00:00:00", "broadcast": "00:00:00:00:00:00", "txqlen": 1000, "mtu": 65536, "carrier": true, "linkmode": 0, "operstate": 0, "num_tx_queues": 1, "num_rx_queues": 1, "af_spec": { "inet": { "conf": { "forwarding": 1, "mc_forwarding": 0, "proxy_arp": 0, "accept_redirects": 1, "secure_redirects": 1, "send_redirects": 1, "shared_media": 1, "rp_filter": 0, "accept_source_route": 1, "bootp_relay": 0, "log_martians": 0, "tag": 0, "arpfilter": 0, "medium_id": 0, "noxfrm": 1, "nopolicy": 1, "force_igmp_version": 0, "arp_announce": 0, "arp_ignore": 0, "promote_secondaries": 0, "arp_accept": 0, "arp_notify": 0, "accept_local": 0, "src_vmark": 0, "proxy_arp_pvlan": 0, "route_localnet": 0, "igmpv2_unsolicited_report_interval": 10000, "igmpv3_unsolicited_report_interval": 1000, "ignore_routes_with_linkdown": 0, "drop_unicast_in_l2_multicast": 0, "drop_gratuitous_arp": 0, "bc_forwarding": 0 } }, "inet6": { "mode": 0, "flags": 2147483648, "conf": { "forwarding": 0, "hoplimit": 64, "mtu6": 65536, "accept_ra": 1, "accept_redirects": 1, "autoconf": 1, "dad_transmits": 1, "rtr_solicits": -1, "rtr_solicit_interval": 4000, "rtr_solicit_delay": 1000, "use_tempaddr": -1, "temp_valid_lft": 604800, "temp_prefered_lft": 86400, "regen_max_retry": 3, "max_desync_factor": 600, "max_addresses": 16, "force_mld_version": 0, "accept_ra_defrtr": 1, "accept_ra_pinfo": 1, "accept_ra_rtr_pref": 1, "rtr_probe_interval": 60000, "accept_ra_rt_info_max_plen": 0, "proxy_ndp": 0, "optimistic_dad": 0, "accept_source_route": 0, "mc_forwarding": 0, "disable_ipv6": 0, "accept_dad": -1, "force_tllao": 0, "ndisc_notify": 0, "mldv1_unsolicited_report_interval": 10000, "mldv2_unsolicited_report_interval": 1000, "suppress_frag_ndisc": 1, "accept_ra_from_local": 0, "use_optimistic": 0, "accept_ra_mtu": 1, "stable_secret": 0, "use_oif_addrs_only": 0, "accept_ra_min_hop_limit": 1, "ignore_routes_with_linkdown": 0, "drop_unicast_in_l2_multicast": 0, "drop_unsolicited_na": 0, "keep_addr_on_down": 0, "rtr_solicit_max_interval": 3600000, "seg6_enabled": 0, "seg6_require_hmac": 0, "enhanced_dad": 1, "addr_gen_mode": 0, "disable_policy": 0, "accept_ra_rt_info_min_plen": 0, "ndisc_tclass": 0, "rpl_seg_enabled": 0 } } }, "proto_down": false, "group": 0, "ifname": "lo" } Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-09-15rtnl: allow reply nla payloads to be smaller than headsizeJo-Philipp Wich
Some netlink replies contain attributes with embeded payloads whose length depends on the kernel version, e.g. IFLA_INET_CONF and IFLA_INET6_CONF. Deal with such cases by allowing the payloads to be shorter than the expected size and by skipping struct members which would lead to out-of-bounds accesses. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-09-15lib: introduce Linux route netlink bindingJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>