Page MenuHomeFreeBSD

netstat: make netstat -rn use netlink instead of rtsock
ClosedPublic

Authored by melifaro on Sep 11 2022, 7:12 PM.
Tags
None
Referenced Files
Unknown Object (File)
Thu, Oct 17, 12:45 AM
Unknown Object (File)
Thu, Oct 17, 12:45 AM
Unknown Object (File)
Thu, Oct 17, 12:45 AM
Unknown Object (File)
Oct 4 2024, 9:58 PM
Unknown Object (File)
Oct 4 2024, 10:01 AM
Unknown Object (File)
Oct 3 2024, 6:20 PM
Unknown Object (File)
Oct 3 2024, 5:27 AM
Unknown Object (File)
Oct 2 2024, 8:41 PM

Details

Summary

This review switches route listing in netstat to netlink, with fallback to rtsock.

The outputs are mostly identical, with an exception of not showing kernel nexthop indexes for multipath routes.

Test Plan
# netlink:
Internet:
Destination        Gateway            Flags   Nhop#    Mtu      Netif Expire
default            10.0.0.1           UGS          4   1500     vtnet0
10.0.0.0/24        link#1           U              2   1500     vtnet0
10.0.0.4           link#2             UHS          3  16384        lo0
127.0.0.1          link#2             UH           1  16384        lo0

#rtsock
Internet:
Destination        Gateway            Flags   Nhop#    Mtu      Netif Expire
default            10.0.0.1           UGS         4   1500     vtnet0
10.0.0.0/24        link#1             U           2   1500     vtnet0
10.0.0.4           link#1             UHS         3  16384        lo0
127.0.0.1          link#2             UH          1  16384        lo0


#netlink
Internet6:
Destination                       Gateway                       Flags   Nhop#    Mtu    Netif Expire
::/96                             ::1                           UGRS         7  16384      lo0
default                           fe80::5054:ff:fe8c:63e9%vtnet0 G          6   1500   vtnet0
::1                               link#2                        UHS          1  16384      lo0
::ffff:0.0.0.0/96                 ::1                           UGRS         7  16384      lo0
2a01:4f9:3a:fa00::/64             link#1                U                    5   1500   vtnet0
2a01:4f9:3a:fa00:5054:ff:fe14:e319 link#2                       UHS          4  16384      lo0
fe80::/10                         ::1                           UGRS         7  16384      lo0
fe80::/64                         link#1                      U              5   1500   vtnet0
fe80::5054:ff:fe14:e319           link#2                        UHS          4  16384      lo0
fe80::/64                         link#2                        U            3  16384      lo0
fe80::1                           link#2                        UHS          2  16384      lo0
ff02::/16                         ::1                           UGRS         7  16384      lo0

#rtsock
Internet6:
Destination                       Gateway                       Flags   Nhop#    Mtu    Netif Expire
::/96                             ::1                           UGRS        7  16384      lo0
default                           fe80::5054:ff:fe8c:63e9%vtnet0 UG         6   1500   vtnet0
::1                               link#2                        UHS         1  16384      lo0
::ffff:0.0.0.0/96                 ::1                           UGRS        7  16384      lo0
2a01:4f9:3a:fa00::/64             link#1                        U           5   1500   vtnet0
2a01:4f9:3a:fa00:5054:ff:fe14:e319 link#1                       UHS         4  16384      lo0
fe80::/10                         ::1                           UGRS        7  16384      lo0
fe80::%vtnet0/64                  link#1                        U           5   1500   vtnet0
fe80::5054:ff:fe14:e319%vtnet0    link#1                        UHS         4  16384      lo0
fe80::%lo0/64                     link#2                        U           3  16384      lo0
fe80::1%lo0                       link#2                        UHS         2  16384      lo0
ff02::/16                         ::1                           UGRS        7  16384      lo0

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

melifaro retitled this revision from netstat: make netstat -rn use netlink instead of rtsock to [WIP] netstat: make netstat -rn use netlink instead of rtsock.Sep 11 2022, 7:20 PM
melifaro edited the summary of this revision. (Show Details)
melifaro edited the test plan for this revision. (Show Details)
melifaro added a reviewer: network.
bapt added inline comments.
usr.bin/netstat/netlink_snl.h
123 ↗(On Diff #110449)

would be nice if snl_init could have the protol in argument, for example I want to use this with NETLINK_GENERIC

melifaro edited the summary of this revision. (Show Details)

Update to use the snl(3) api.

melifaro retitled this revision from [WIP] netstat: make netstat -rn use netlink instead of rtsock to netstat: make netstat -rn use netlink instead of rtsock.Dec 20 2022, 10:49 AM
melifaro edited the summary of this revision. (Show Details)
melifaro edited the test plan for this revision. (Show Details)

@melifaro thanks for the differential. I remember darkly, that there was PR a few month ago, that FreeBSD doesn't support "route print" like most operating systems do. Would it be possible to integrate that feature of that differential and netlink?

usr.bin/netstat/route_netlink.c
5

I think that this should be updated to mention @melifaro as author.

In D36529#858749, @gbe wrote:

@melifaro thanks for the differential. I remember darkly, that there was PR a few month ago, that FreeBSD doesn't support "route print" like most operating systems do. Would it be possible to integrate that feature of that differential and netlink?

Generally I'm not opposed to the idea. There are a number of things to be sorted out, though. For example, what should be the column format, should it be machine-readable (as currently /sbin/route does not have any lib depenencies) and so on.
I guess the easiest would be to do execve /usr/sbin/netstat -[46]rn on route print inside route(8) if so desired. That should be pretty straight-forwarded to implement. I'm not sure I'll have cycles to do this ATM, as I'm full-hands in Netlink conversion. I'm happy to review such change if somebody else comes up with the patch.

This revision was not accepted when it landed; it landed in state Needs Review.Jan 27 2023, 3:36 PM
This revision was automatically updated to reflect the committed changes.
freebsd_igalic.co added inline comments.
usr.bin/netstat/route_netlink.c
33

I thought we got rid of this