[osv-dev] [PATCH 10/10] netlink: enable it and add unit test

2022-06-03 Thread Waldemar Kozaczuk
This changes bsd/net.cc to enables netlink by registering netlink domain and calling netlink_init(). It also adds a unit test to verify the netlink implementation. Signed-off-by: Waldemar Kozaczuk --- bsd/net.cc | 5 + modules/tests/Makefile | 3 +- tests/tst-netlink.c| 441

[osv-dev] [PATCH 09/10] netlink: set negative errno in error responses

2022-06-03 Thread Waldemar Kozaczuk
The netlink specfication requires that error field contains a negative value of errno. Signed-off-by: Waldemar Kozaczuk --- bsd/sys/compat/linux/linux_netlink.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bsd/sys/compat/linux/linux_netlink.cc b/bsd/sys/compat/linux/linu

[osv-dev] [PATCH 08/10] netlink: made some functions static

2022-06-03 Thread Waldemar Kozaczuk
Signed-off-by: Waldemar Kozaczuk --- bsd/sys/compat/linux/linux_netlink.cc | 9 - 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/bsd/sys/compat/linux/linux_netlink.cc b/bsd/sys/compat/linux/linux_netlink.cc index 180d81b5..be9ea1b8 100644 --- a/bsd/sys/compat/linux/linux_ne

[osv-dev] [PATCH 06/10] netlink: return stashed pid

2022-06-03 Thread Waldemar Kozaczuk
There are three types of pid used in netlink interface: - the nl_pid on the source (app) side (part of sockaddr_nl) set before bind(); could be 0 to request kernel generating new one - the nl_pid on the destination (kernel) size set into dst_addr that always needs to be 0 if we communicate with

[osv-dev] [PATCH 07/10] netlink: fix error handling

2022-06-03 Thread Waldemar Kozaczuk
Fix netlink_process_msg() to propagate potential error from netlink_senderr(). Normally netlink_senderr() should return 0 indicating that the error response was built successfully. This patch tweaks the logic to make sure the error response in such case is sent back as a NLMSG_ERROR reply according

[osv-dev] [PATCH 05/10] netlink: stash nl_pid into netlinkcb

2022-06-03 Thread Waldemar Kozaczuk
This enhances the netlink_attach() to capture or generate the source nl_pid (if 0) and save it in the control back that could be fetched later when necessary. This will be useful in the next patch. Signed-off-by: Waldemar Kozaczuk --- bsd/sys/compat/linux/linux_netlink.cc | 25 ++

[osv-dev] [PATCH 04/10] netlink: do not put IFA_BROADCAST for loopback address

2022-06-03 Thread Waldemar Kozaczuk
This is a minor adjustment to make OSv implementation match what Linux does - skip IFA_BROADCAST attributes for loopback address in NEWADDR response. Signed-off-by: Waldemar Kozaczuk --- bsd/sys/compat/linux/linux_netlink.cc | 14 ++ 1 file changed, 10 insertions(+), 4 deletions(-)

[osv-dev] [PATCH 03/10] netlink: IFA_ADDRESS needs to go first

2022-06-03 Thread Waldemar Kozaczuk
Golang uses the netlink interface RTM_GETADDR to query the network interfaces and IPs. It assumes that the 1st attribute in the RTM_NEWADDR response is IFA_ADDRESS. This patch changes the order in which RTM_NEWADDR attributes are sent to make sure the IFA_ADDRESS goes first and IFA_LABEL last. T

[osv-dev] [PATCH 02/10] netlink: set LINUX_RTM_NEWADDR and LINUX_RTM_NEWNEIGH on responses

2022-06-03 Thread Waldemar Kozaczuk
This patch fixes a minor bug in handling RTM_GETADDR and RTM_GETNEIGH requests. It tweaks the relevant code to set the RTM_NEWADDR and RTM_NEWNEIGH type for the responses respectively. This is important as for example Golang runtime tests the nlmsg_type of the netlink response and breaks if it is

[osv-dev] [PATCH 01/10] netlink: minimal Linux rtnetlink support

2022-06-03 Thread Waldemar Kozaczuk
This 1st of the 10 patches brings support of the minimal subset of the rtnetlink (Linux routing socket) interface as described here - https://man7.org/linux/man-pages/man7/rtnetlink.7.html. The rtnetlink is actually a subset of even richer netlink interface described here - https://man7.org/linux/m