Commit Graph

92 Commits

Author SHA1 Message Date
Alexander V. Chernikov
28abf63277 netlink: sync interface IFLA attributes
MFC after:	2 weeks
2023-04-18 12:34:05 +00:00
Alexander V. Chernikov
9742519b22 netlink: fix operations with link-local routes/gateways.
MFC after:	3 days
2023-04-17 12:04:43 +00:00
Alexander V. Chernikov
9f324d8ac2 netlink: make netlink work correctly on CHERI.
Current Netlink message writer code relies on executing callbacks
 with arbitrary data (pointer or integer) to flush the completed
 messages.
This arbitrary data is stored as a union of { void *, uint64_t }.
At some stage, the message flushing code copied this data, using
 direct uint64_t assignment instead of copying the union. It lead
 to failure on CHERI, as sizeof(pointer) == 16 there.

Fix the code by making union non-anonymous and copying it entirely.

Reviewed by:	br, jhb, jrtc27
Differential Revision: https://reviews.freebsd.org/D39557
MFC after:	2 weeks
2023-04-14 16:33:43 +00:00
Alexander V. Chernikov
cc3793b1c5 netlink: improve source ifa selection algorithm when adding routes.
Use route destination sockaddr when the gateway is eiter AF_LINK or
 has the different family (IPv4 over IPv6). This change ensures
 the nexthop IFA has the same family as the destination.

Reported by:	Dmitriy Smirnov <fox@sage.su>
Tested by:	Dmitriy Smirnov <fox@sage.su>
MFC after:	3 days
2023-04-09 13:33:22 +00:00
Alexander V. Chernikov
0d4038e301 netlink: set prefix-related flags to the created nexthop.
This fixes incorrect flag combinations when adding IPv4/IPv6 host
routes.

MFC after:	3 days
2023-04-09 09:26:12 +00:00
Alexander V. Chernikov
75379ea2e4 netlink: do not print "unknown sa family" warnings at the default debug
level.

MFC after:	2 weeks
2023-04-08 19:40:32 +00:00
Alexander V. Chernikov
39c0036d88 netlink: fix !INET6 warning
Reported by:	Gary Jennejohn <garyj@gmx.de>
MFC after:	2 weeks
2023-04-08 19:39:37 +00:00
Alexander V. Chernikov
c35a43b261 netlink: allow exact-match route lookups via RTM_GETROUTE.
Use already-existing RTM_F_PREFIX rtm_flag to indicate that the
 request assumes exact-prefix lookup instead of the
 longest-prefix-match.

MFC after:	2 weeks
2023-04-02 13:47:10 +00:00
Alexander V. Chernikov
4aeb939ecf netlink: fix NULL check in the default route snl(3) parser.
CID:		1506959
MFC after:	2 weeks
2023-04-02 12:44:20 +00:00
Alexander V. Chernikov
27cbc1a7fe netlink: fix snl_read_reply_multi().
CID:		1506956
MFC after:	2 weeks
2023-04-02 12:41:53 +00:00
Alexander V. Chernikov
b755f1a009 netlink: Fix adding routes with nexthops on p2p interfaces.
Use full-featured ifa_ifwithroute() to guess route ifa/ifp
 instead of ifa_ifwithnet(). This change makes the route addition
 logic closer to the rt_getifa_fib() used by rtsock.

Reported by:	glebius
Tested by:	glebius
Differential Revision: https://reviews.freebsd.org/D39335
MFC after:	2 weeks
2023-03-30 09:53:50 +00:00
Alexander V. Chernikov
d3a49f62a2 netlink: fix 19e43c163c by adding miseed netlinkg_glue.c 2023-03-27 16:09:02 +00:00
Alexander V. Chernikov
19e43c163c netlink: add netlink KPI to the kernel by default
This change does the following:

Base Netlink KPIs (ability to register the family, parse and/or
 write a Netlink message) are always present in the kernel. Specifically,
* Implementation of genetlink family/group registration/removal,
  some base accessors (netlink_generic_kpi.c, 260 LoC) are compiled in
  unconditionally.
* Basic TLV parser functions (netlink_message_parser.c, 507 LoC) are
  compiled in unconditionally.
* Glue functions (netlink<>rtsock), malloc/core sysctl definitions
 (netlink_glue.c, 259 LoC) are compiled in unconditionally.
* The rest of the KPI _functions_ are defined in the netlink_glue.c,
 but their implementation calls a pointer to either the stub function
 or the actual function, depending on whether the module is loaded or not.

This approach allows to have only 1k LoC out of ~3.7k LoC (current
 sys/netlink implementation) in the kernel, which will not grow further.
It also allows for the generic netlink kernel customers to load
 successfully without requiring Netlink module and operate correctly
 once Netlink module is loaded.

Reviewed by:	imp
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D39269
2023-03-27 13:55:44 +00:00
Alexander V. Chernikov
eccccd657f netlink: make nlattr_add_in[6]_addr inline
MFC after:	2 weeks
2023-03-27 11:53:34 +00:00
Alexander V. Chernikov
6dc858d84c netlink: remove forgotten debug message in handle_rtm_getroute().
MFC after:	2 weeks
2023-03-27 10:49:40 +00:00
Alexander V. Chernikov
544f1492c0 netlink: ensure genetlink control family always registers under the same ID.
MFC after:	2 weeks
2023-03-27 10:48:24 +00:00
Alexander V. Chernikov
9a11f3dff9 netlink: add standrard ifaddr/neigh parsers to snl(3).
MFC after:	2 weeks
2023-03-26 09:04:41 +00:00
Alexander V. Chernikov
04f75b9802 netlink: allow netlink sockets in non-vnet jails.
This change allow to open Netlink sockets in the non-vnet jails, even for
 unpriviledged processes.
The security model largely follows the existing one. To be more specific:
* by default, every `NETLINK_ROUTE` command is **NOT** allowed in non-VNET
 jail UNLESS `RTNL_F_ALLOW_NONVNET_JAIL` flag is specified in the command
 handler.
* All notifications are **disabled** for non-vnet jails (requests to
 subscribe for the notifications are ignored). This will change to be more
 fine-grained model once the first netlink provider requiring this gets
 committed.
* Listing interfaces (RTM_GETLINK) is **allowed** w/o limits (**including**
 interfaces w/o any addresses attached to the jail). The value of this is
 questionable, but it follows the existing approach.
* Listing ARP/NDP neighbours is **forbidden**. This is a **change** from the
 current approach - currently we list static ARP/ND entries belonging to the
 addresses attached to the jail.
* Listing interface addresses is **allowed**, but the addresses are filtered
 to match only ones attached to the jail.
* Listing routes is **allowed**, but the routes are filtered to provide only
 host routes matching the addresses attached to the jail.
* By default, every `NETLINK_GENERIC` command is **allowed** in non-VNET jail
 (as sub-families may be unrelated to network at all).
 It is the goal of the family author to implement the restriction if
 necessary.

Differential Revision: https://reviews.freebsd.org/D39206
MFC after:	1 month
2023-03-26 08:44:09 +00:00
Alexander V. Chernikov
a74998f38a netlink: reduce the default debugging levels
Reported by:	kp
MFC after:	2 weeks
2023-03-21 18:55:00 +00:00
Kristof Provost
137818006d carp: support unicast
Allow users to configure the address to send carp messages to. This
allows carp to be used in unicast mode, which is useful in certain
virtual configurations (e.g. AWS, VMWare ESXi, ...)

Reviewed by:	melifaro
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D38940
2023-03-20 14:37:09 +01:00
Alexander V. Chernikov
046acc2bfd netlink: add public ucred accessor for nlp.
MFC after:	2 weeks
2023-03-18 11:44:29 +00:00
Alexander V. Chernikov
568a645ba5 netlink: fix capped uncapped ack handling in snl(3).
Reviewed by:	kp
Differential Revision: https://reviews.freebsd.org/D39144
MFC after:	2 weeks
2023-03-18 11:35:56 +00:00
Alexander V. Chernikov
73ae25c174 netlink: improve snl(3)
Summary:
* add snl_send_message() as a convenient send wrapper
* add signed integer parsers
* add snl_read_reply_code() to simplify operation result checks
* add snl_read_reply_multi() to simplify reading multipart messages
* add snl_create_genl_msg_request()
* add snl_get_genl_family() to simplify family name->id resolution
* add tests for some of the functionality

Reviewed by:	kp
Differential Revision: https://reviews.freebsd.org/D39092
MFC after:	2 weeks
2023-03-15 20:53:20 +00:00
Alexander V. Chernikov
da4047d3ba fix buildworld after 595d23f777.
Reported by:	se
2023-03-09 15:45:57 +00:00
Alexander V. Chernikov
595d23f777 netlink: add snl(3) default parsers for routes and links.
This change adds the "default" parsers of _all_ route/link attributes
 exported by the kernel.
It removes the need to declare similar parsers in the userland applications,
 simplifying their logic.

Differential Revision: https://reviews.freebsd.org/D38979
MFC after:	2 weeks
2023-03-09 14:46:27 +00:00
Alexander V. Chernikov
90d6251228 netlink: add rtsock-compatible header to use with netlink snl(3).
Some routing socket defines (`RTM_` and `RTA_` ones) clash with the ones
 used by the the Netlink.
As some rtsock definitions like interface flags or route flags are used in
 both netlink and rtsock, provide a convenient way to include those without
 running into the define collision.

Differential Revision: https://reviews.freebsd.org/D38982
MFC after:	2 weeks
2023-03-09 14:37:42 +00:00
Alexander V. Chernikov
76f6d39150 netlink: add basic message writing support to snl(3).
Differential Revision:	https://reviews.freebsd.org/D38947
MFC after:	2 weeks
2023-03-09 14:33:26 +00:00
Alexander V. Chernikov
0679eb1f39 netlink: make snl(3) scratch buffer growable
Differential Revision: https://reviews.freebsd.org/D38946
MFC after:	2 weeks
2023-03-08 12:28:55 +00:00
Alexander V. Chernikov
5c8277ec25 netlink: cleanup netlink_writer code
* Remove unused nlattr_add_nla() - that's a duplicate of nlattr_add_raw().
* Calculate alignment only once in nlmsg_reserve_data_raw()

MFC after:	2 weeks
2023-03-07 17:45:31 +00:00
Alexander V. Chernikov
055776c84a netlink: use newly-added if_foreach_sleep() to iterate over the interface list.
Summary: MFC after:	2 weeks

Subscribers: imp, glebius

Differential Revision: https://reviews.freebsd.org/D38907
2023-03-06 15:08:08 +00:00
Alexander V. Chernikov
ce9f95bd83 netlink: fix vlan interface creation
MFC after:	2 weeks
2023-03-03 16:02:05 +00:00
Alexander V. Chernikov
61507ae30b netlink: add u8/u64 attribute fetcher accessors to snl(3).
MFC after:	2 weeks
2023-03-03 14:05:40 +00:00
Alexander V. Chernikov
e6b4177c47 netlink: add userland name mappings to all NETLINK_ROUTE messages.
MFC after:	1 day
2023-03-01 15:24:45 +00:00
Alexander V. Chernikov
28a5d88f70 netlink: make the maximum allowed netlink socket buffer runtime tunable.
Dumping large routng tables (>1M paths with multipath) require the socket
 buffer which is larger than the currently defined limit.
Allow the limit to be set in runtime, similar to kern.ipc.maxsockbuf.

Reported by:	Marek Zarychta <zarychtam@plan-b.pwste.edu.pl>
MFC after:	1 day
2023-02-27 10:48:31 +00:00
Alexander V. Chernikov
d2deebe21b netlink: fix addition of blackhole/reject routes.
* Make nhop_set_blackhole() set all necessary properties for the
 nexthop
* Make nexthops blackhole/reject based on the rtm_type netlink
 property instead of using rtflags.

Reported by:	Marek Zarychta <zarychtam@plan-b.pwste.edu.pl>
MFC after:	3 days
2023-02-23 17:43:18 +00:00
Alexander V. Chernikov
b9b2184322 netlink: clear IPv6 embedded scope when dumping route gateways.
Reported by:	zarychtam@plan-b.pwste.edu.pl
MFC after:	3 days
2023-02-21 12:27:26 +00:00
Alexander V. Chernikov
c7c3481621 netlink: fix IPv6 route addition with link-local gateway
Currently kernel assumes that IPv6 gateway address is in "embedded"
 form - that is, for the link-local IPv6 addresses, interface index
 is embedded in bytes 2 and 3 of the address.
Fix address embedding in netlink by wrapping nhop_set_gw() in the
 netlink-specific nl_set_nexthop_gw(), which does such embedding
 automatically.

Reported by:	Marek Zarychta <zarychtam@plan-b.pwste.edu.pl>
MFC after:	3 days
2023-02-20 14:29:48 +00:00
Alexander V. Chernikov
453c7d6803 netlink: do not crash when linux message translation fails.
CID:		1498889
MFC after:	2 weeks
2023-02-18 17:53:06 +00:00
Alexander V. Chernikov
8f7455a926 netlink: fix OOB read in genetlink
CID:		1498863
MFC after:	1 day
2023-02-18 17:53:06 +00:00
Alexander V. Chernikov
4404e840cf netlink: initialise error in nl_autobind_port().
CID:		1498877
MFC after:	2 weeks
2023-02-18 17:53:05 +00:00
Alexander V. Chernikov
3f70fca90f netlink: check result of sooptcopyin().
CID:		1498866
MFC after:	2 weeks
2023-02-18 17:53:05 +00:00
Alexander V. Chernikov
1ea58b4135 netlink: remove redundant check.
MFC after:	2 weeks
CID:		1498867
2023-02-18 17:53:05 +00:00
Alexander V. Chernikov
7cbe771f01 netlink: call genetlink notification handler upon successful family
search.

MFC after:	3 days
2023-02-17 18:16:07 +00:00
Alexander V. Chernikov
45356a1864 netlink: simplify temporary address allocation in rtnl_handle_getlink().
MFC after:	3 days
2023-02-17 18:16:07 +00:00
Alexander V. Chernikov
6694cb1f57 netlink: fix if_allocdescr() malloc options argument.
The current value was based on the initial revision of D37566 and
 was not updated afterwards.

MFC after:	1 day
2023-02-17 18:00:37 +00:00
Alexander V. Chernikov
f2f7911c55 netlink: validate rtable value in RTM_<NEW|DEL|GET>ROUTE.
Reported by:	Stefan Grundmann <sg2342@googlemail.com>
MFC after:	1 day
2023-02-17 18:00:37 +00:00
Alexander V. Chernikov
86fd0bdba5 netlink: fix interface dump.
The current code missed interface addition when reallocating
 temporary buffer.
Tweak the code to perform the reallocation first and add
 interface afterwards unconditionally.

Reported by:	Marek Zarychta <zarychtam@plan-b.pwste.edu.pl>
MFC after:	3 days
2023-02-16 13:20:45 +00:00
Alexander V. Chernikov
5dd48f7184 netlink: use ifmedia to provide vlan interface operstate.
Netlink customers rely on admin and operational state when
 working with interfaces. The current implementation retuns
 "unknown" operstate for all interface types except IFT_ETHER
 and IFT_LOOP.

This change updates the code to fetch vlan operstate in the same way
 as for the ether interfaces. For the rest of the interface types,
 operstate is now mapped to the admin state.

Reported by:	Marek Zarychta <zarychtam@plan-b.pwste.edu.pl>
MFC after:	3 days
2023-02-15 20:22:47 +00:00
Alexander V. Chernikov
6d7da7c849 Revert "netlink: make netlink_snl(3) c++ friendly."
Was pushed accidentally.

This reverts commit 629d9219d9.
2023-02-12 12:17:05 +00:00
Alexander V. Chernikov
629d9219d9 netlink: make netlink_snl(3) c++ friendly. 2023-02-12 11:46:38 +00:00