aboutsummaryrefslogtreecommitdiff
path: root/usr.bin/netstat/route.c
Commit message (Collapse)AuthorAgeFilesLines
* netstat(1): Show metric value for routesPouria Mousavizadeh Tehrani2026-05-201-4/+8
| | | | | | | | | | | Add metric support and show its value in wide flag and libxo output. Also, add metric to the description of wide flag (`-w`) in routing display (`-r`) section of manual page. Reviewed by: markj (manpage) Discussed with: markj Differential Revision: https://reviews.freebsd.org/D57011
* netstat: restore printing the "default" keyword, provide -nn optionGleb Smirnoff2025-02-031-2/+2
| | | | | | | | | | | | | | | Avoid POLA breakage and preserve output standard that really predates the FreeBSD project itself. There are scripts in the wild that rely on the behavior. Provide option to specify -nn twice to have a completely numeric output of the routing tables. Fixes: 9206c79961986c2114a9a2cfccf009ac010ad259 This reverts commit e090646d6f5a4a6848ecd4bcb1f2db498ea3b3e2. Reviewed by: zlei, gallatin, melifaro, allanjude, markj, emaste Differential Revision: https://reviews.freebsd.org/D48729
* usr.bin/netstat: -n should not print symbolic namesAllan Jude2024-11-261-2/+3
| | | | | | | | | | | | | | | | | | | | In numeric mode, the default route is printed as "default" rather than 0.0.0.0/0 or ::/0 From the man page: "-n: Show network addresses and ports as numbers. Normally netstat attempts to resolve addresses and ports, and display them symbolically. If the -n option is specified, the address is printed numerically, according to the address family. For more information regarding the Internet IPv4 ``dot format'', refer to inet(3). Unspecified, or `wildcard'', addresses and ports appear as `*''." Reported By: rgrimes Reviewed by: emaste, ngie, eadler, seanc Relnotes: yes Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D10320
* netstat: switch to using the sysctl-exported stats for live statsKyle Evans2024-10-241-5/+3
| | | | | | | | | | | | | | | | | Now that we export the relevant stats via the net.route.stats sysctl, switch to using that to avoid having to dig around in mem(4) for live kernel statistics. Based on callers of kresolve_list(), this is the last live path using mem(4) that could be functional today. Tested both with `netstat -rs` and `netstat -rs -M`. Note that this will not be able to extract stats from a running kernel that predates 3360a15898 / 1500026, but this can be worked around by specifying `-M /dev/mem` explicitly in the interim to fallback to libkvm against /dev/mem. Reviewed by: glebius, markj, zlei Differential Revision: https://reviews.freebsd.org/D47231
* netstat(1): Complete libxo transitionYan-Hao Wang2024-10-121-6/+5
| | | | | | Reviewed by: des MFC after: 3 days Differential Revision: https://reviews.freebsd.org/D41427
* netstat(8): for -W, use IFNAMSIZLexi Winter2024-05-161-1/+1
| | | | | | | | If -W is specified, use IFNAMSIZ as the width of the Netif column, instead of the default 12. Reviewed by: imp,zlei,Mina Galić Pull Request: https://github.com/freebsd/freebsd-src/pull/1223
* netstat(1): increase width of Netif columnLexi Winter2024-05-161-3/+2
| | | | | | | | | | | | | | | | | The previous width of Netif (10 or 8) was too short for modern interface names; make it 12, which is long enough to display "epair0a.1000". This came up in practice with genet(4) interfaces, since the base interface name is long enough that with the previous limit, VLAN identifiers would be truncated at 1 character in the IPv6 output: "genet0.100" becomes "genet0.1". The width is now fixed, and doesn't depend on the address family, because there's no reason that length of the interface name would vary based on the AF. Reviewed by: imp,zlei,Mina Galić Pull Request: https://github.com/freebsd/freebsd-src/pull/1223
* usr.bin: Automated cleanup of cdefs and other formattingWarner Losh2023-11-271-4/+0
| | | | | | | | | | | | | | | | Apply the following automated changes to try to eliminate no-longer-needed sys/cdefs.h includes as well as now-empty blank lines in a row. Remove /^#if.*\n#endif.*\n#include\s+<sys/cdefs.h>.*\n/ Remove /\n+#include\s+<sys/cdefs.h>.*\n+#if.*\n#endif.*\n+/ Remove /\n+#if.*\n#endif.*\n+/ Remove /^#if.*\n#endif.*\n/ Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/types.h>/ Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/param.h>/ Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/capsicum.h>/ Sponsored by: Netflix
* usr.bin: Remove ancient SCCS tags.Warner Losh2023-11-271-3/+0
| | | | | | | | Remove ancient SCCS tags from the tree, automated scripting, with two minor fixup to keep things compiling. All the common forms in the tree were removed with a perl script. Sponsored by: Netflix
* Remove $FreeBSD$: one-line .c patternWarner Losh2023-08-161-2/+0
| | | | Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
* netlink: add NETLINK/NETLINK_SUPPORT userland options.Alexander V. Chernikov2023-03-261-2/+11
| | | | | | | | | | Make userland tools such as netstat, route, arp and ndp use either netlink or rtsock interfaces based on the NETLINK_SUPPORT options. Both NETLINK and NETLINK_SUPPORT options are turned on by default. Reviewed By: eugen Differential Revision: https://reviews.freebsd.org/D39148
* netstat: export weight for single-path routes.Alexander V. Chernikov2023-01-291-0/+1
| | | | | | | | | | | | | | | * Parse and export newly-added NL_RTA_WEIGHT attribute, providing path weight for a non-multipath route. This fixes a number of tests in sys/net/routing which rely on this data. * Remove handling of NL_RTA_KNH_ID in multipath routes, as it is not provided. * Improve kernel/user nexthop index export. As a result, for multipath routes: * nhg-kidx attribute represents kernel nhg index (always provided) * nhg-uidx attribute represents user-provided nhg index (if set) for non-multipath routes: * nhop-kidx attribute represents kernel nhop index (always provided) * nhop-udx attribute represents user-provided nexthop index (if set)
* netstat: make netstat -rn use netlink instead of rtsockAlexander V. Chernikov2023-01-271-40/+39
| | | | | | | | This change 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. Differential Revision: https://reviews.freebsd.org/D36529
* netstat: print path weight when showing routes in structured output.Alexander V. Chernikov2022-06-221-0/+2
| | | | | Differential Revision: https://reviews.freebsd.org/D35530 MFC after: 2 weeks
* Fix `netstat -rs` reporting.Alexander V. Chernikov2021-03-311-12/+1
| | | | | | | | | rttrash (unused but not yet delete entries) were eliminated during routing rework. Remove reading these symbols from the kernel. PR: 254681 Reported by: rashey@superbox.pl MFC after: immediately
* Introduce nexthop objects and new routing KPI.Alexander V. Chernikov2020-04-121-77/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is the foundational change for the routing subsytem rearchitecture. More details and goals are available in https://reviews.freebsd.org/D24141 . This patch introduces concept of nexthop objects and new nexthop-based routing KPI. Nexthops are objects, containing all necessary information for performing the packet output decision. Output interface, mtu, flags, gw address goes there. For most of the cases, these objects will serve the same role as the struct rtentry is currently serving. Typically there will be low tens of such objects for the router even with multiple BGP full-views, as these objects will be shared between routing entries. This allows to store more information in the nexthop. New KPI: struct nhop_object *fib4_lookup(uint32_t fibnum, struct in_addr dst, uint32_t scopeid, uint32_t flags, uint32_t flowid); struct nhop_object *fib6_lookup(uint32_t fibnum, const struct in6_addr *dst6, uint32_t scopeid, uint32_t flags, uint32_t flowid); These 2 function are intended to replace all all flavours of <in_|in6_>rtalloc[1]<_ign><_fib>, mpath functions and the previous fib[46]-generation functions. Upon successful lookup, they return nexthop object which is guaranteed to exist within current NET_EPOCH. If longer lifetime is desired, one can specify NHR_REF as a flag and get a referenced version of the nexthop. Reference semantic closely resembles rtentry one, allowing sed-style conversion. Additionally, another 2 functions are introduced to support uRPF functionality inside variety of our firewalls. Their primary goal is to hide the multipath implementation details inside the routing subsystem, greatly simplifying firewalls implementation: int fib4_lookup_urpf(uint32_t fibnum, struct in_addr dst, uint32_t scopeid, uint32_t flags, const struct ifnet *src_if); int fib6_lookup_urpf(uint32_t fibnum, const struct in6_addr *dst6, uint32_t scopeid, uint32_t flags, const struct ifnet *src_if); All functions have a separate scopeid argument, paving way to eliminating IPv6 scope embedding and allowing to support IPv4 link-locals in the future. Structure changes: * rtentry gets new 'rt_nhop' pointer, slightly growing the overall size. * rib_head gets new 'rnh_preadd' callback pointer, slightly growing overall sz. Old KPI: During the transition state old and new KPI will coexists. As there are another 4-5 decent-sized conversion patches, it will probably take a couple of weeks. To support both KPIs, fields not required by the new KPI (most of rtentry) has to be kept, resulting in the temporary size increase. Once conversion is finished, rtentry will notably shrink. More details: * architectural overview: https://reviews.freebsd.org/D24141 * list of the next changes: https://reviews.freebsd.org/D24232 Reviewed by: ae,glebius(initial version) Differential Revision: https://reviews.freebsd.org/D24232 Notes: svn path=/head/; revision=359823
* Convert routing statistics to VNET_PCPUSTAT.Gleb Smirnoff2019-12-171-6/+6
| | | | | | | | | Submitted by: ocochard Reviewed by: melifaro, glebius Differential Revision: https://reviews.freebsd.org/D22834 Notes: svn path=/head/; revision=355840
* General further adoption of SPDX licensing ID tags.Pedro F. Giffuni2017-11-201-0/+2
| | | | | | | | | | | | | | | | | Mainly focus on files that use BSD 3-Clause license. The Software Package Data Exchange (SPDX) group provides a specification to make it easier for automated tools to detect and summarize well known opensource licenses. We are gradually adopting the specification, noting that the tags are considered only advisory and do not, in any way, superceed or replace the license texts. Special thanks to Wind River for providing access to "The Duke of Highlander" tool: an older (2014) run over FreeBSD tree was useful as a starting point. Notes: svn path=/head/; revision=326025
* Fix userland tools that don't check the format of routing socketPatrick Kelsey2017-04-161-2/+3
| | | | | | | | | | | | | | | | | | | messages before accessing message fields that may not be present, removing dead/duplicate/misleading code along the way. Document the message format for each routing socket message in route.h. Fix a bug in usr.bin/netstat introduced in r287351 that resulted in pointer computation with essentially random 16-bit offsets and dereferencing of the results. Reviewed by: ae MFC after: 1 month Differential Revision: https://reviews.freebsd.org/D10330 Notes: svn path=/head/; revision=317035
* Renumber copyright clause 4Warner Losh2017-02-281-1/+1
| | | | | | | | | | | | Renumber cluase 4 to 3, per what everybody else did when BSD granted them permission to remove clause 3. My insistance on keeping the same numbering for legal reasons is too pedantic, so give up on that point. Submitted by: Jan Schaumann <jschauma@stevens.edu> Pull Request: https://github.com/freebsd/freebsd/pull/96 Notes: svn path=/head/; revision=314436
* Fix typo.Xin LI2017-01-091-1/+1
| | | | | | | MFC after: 3 days Notes: svn path=/head/; revision=311762
* Use strlcpy and snprintf in netstat(1).Xin LI2017-01-051-19/+29
| | | | | | | | | | | | Expand inet6name() line buffer to NI_MAXHOST and use strlcpy/snprintf in various places. Reported by: Anton Yuzhaninov <citrin citrin ru> MFC after: 3 days Differential Revision: https://reviews.freebsd.org/D8916 Notes: svn path=/head/; revision=311392
* Fix build without INET6 and with gcc. A function definition was ifdefedBruce Evans2016-08-271-0/+2
| | | | | | | for INET6, but its protototype was not, and gcc detects the error. Notes: svn path=/head/; revision=304895
* netstat: avoid returning uninitialized value in p_sockaddr().Pedro F. Giffuni2016-03-271-0/+1
| | | | | | | | | | | In the case the width is less than 0, we are returning an uninitialized value. For practical purposes the return value is ignored but initialize it to avoid trouble. CID: 1341619 Notes: svn path=/head/; revision=297321
* At the time a destination or a gateway of `netstat -r'Hajimu UMEMOTO2015-12-011-6/+14
| | | | | | | | protrudes its field, narrow the next field to raise readability bit. Notes: svn path=/head/; revision=291592
* Don't truncate an interface name when -W option is specified.Hajimu UMEMOTO2015-11-201-1/+5
| | | | | | | | Spotted by: Jim Thompson <jim__at__netgate.com> MFC after: 1 week Notes: svn path=/head/; revision=291097
* Use returned network name from getnetbyaddr() correctly.Hajimu UMEMOTO2015-11-051-6/+5
| | | | Notes: svn path=/head/; revision=290389
* Revert previous workaround. This problem was fixedHajimu UMEMOTO2015-11-051-4/+0
| | | | | | | by r290318. Notes: svn path=/head/; revision=290388
* Since sa->sa_len doesn't match sizeof(struct sockaddr_dl),Hajimu UMEMOTO2015-11-041-0/+4
| | | | | | | | getnameinfo() fails against sockaddr_dl. This commit is workaround for this problem. Notes: svn path=/head/; revision=290372
* Mask an IPv6 network address.Hajimu UMEMOTO2015-11-041-1/+8
| | | | Notes: svn path=/head/; revision=290366
* Simplify kvm symbol resolution and error handling. The symbol tableHiroki Sato2015-09-021-16/+3
| | | | | | | | nl_symbols will eventually be organized into several modules depending on MK_* variables. Notes: svn path=/head/; revision=287407
* - Add -W flag support for network column in intpr() (-i flag) andHiroki Sato2015-09-011-184/+136
| | | | | | | | | | | | | | | | | | | | | | | | | | | | routepr() (-r flag). It is too narrow to show an IPv6 prefix in most cases. - Accept "local" as a synonym of "unix" in protocol family name. - Show a prefix length in CIDR notation when name resolution failed in netname(). - Make routename() and netname() AF-independent and remove unnecessary typecasting from struct sockaddr. - Use getnameinfo(3) to format L2 addr in intpr(). - Fix a bug which showed "Address" when -A flag is specfied in pr_rthdr(). - Replace cryptic GETSA() macro with SA_SIZE(). - Fix declarations shadowing local variables with the same names. - Add more static, remove unused header files and variables. MFC after: 1 week Notes: svn path=/head/; revision=287351
* Properly align the header and the data columns for netstat -r with andLuiz Otavio O Souza2015-05-181-2/+2
| | | | | | | without the -W flag. Notes: svn path=/head/; revision=283071
* Adjust the string format to match the actual number of arguments.Luiz Otavio O Souza2015-05-171-1/+1
| | | | | | | | | | This fix a segmentation fault on ARM when netstat -r is used together with -W. This issue was introduced in r279122. Notes: svn path=/head/; revision=283028
* Like it was already done for 'netstat -i', drop the kvm(3) supportGleb Smirnoff2015-04-071-388/+13
| | | | | | | | | | | | | | | | | in 'netstat -r'. The netstat/route.c was the last abuser of struct ifnet and struct rtentry in the tree. With this change if_var.h can become kernel only include, _WANT_RTENTRY can go away and projects/ifnet and projects/routing can go forward. Differential Revision: https://reviews.freebsd.org/D2242 Reviewed by: melifaro, gnn Sponsored by: Nginx, Inc. Sponsored by: Netflix Notes: svn path=/head/; revision=281188
* Convert netstat to use libxo.Marcel Moolenaar2015-02-211-109/+209
| | | | | | | | | | Obtained from: Phil Shafer <phil@juniper.net> Ported to -current by: alfred@ (mostly), Kim Shrier Formatting: marcel@ Sponsored by: Juniper Networks, Inc. Notes: svn path=/head/; revision=279122
* - Fix a bug which can make sysctl() fail when -F is specified.Hiroki Sato2014-05-211-9/+5
| | | | | | | | | - Increase WID_IF_DEFAULT() from 6 to 8 (the default for AF_INET6) because we have interfaces with longer names than 6 chars like epairN{a,b}. - Style fixes. Notes: svn path=/head/; revision=266494
* - Do not override sin6_scope_id in LLA when it is already set to non-zero.Hiroki Sato2014-05-151-5/+9
| | | | | | | | | | This fixes destination list in output of netstat -r. - Plug a memory leak. - Add RTM_VERSION check. - Minor style fixes. Notes: svn path=/head/; revision=266177
* Garbage collect long time obsoleted (or never used) stuff from routing API.Gleb Smirnoff2014-03-151-7/+0
| | | | Notes: svn path=/head/; revision=263203
* Remove AppleTalk support.Gleb Smirnoff2014-03-141-12/+0
| | | | | | | | | | | | | AppleTalk was a network transport protocol for Apple Macintosh devices in 80s and then 90s. Starting with Mac OS X in 2000 the AppleTalk was a legacy protocol and primary networking protocol is TCP/IP. The last Mac OS X release to support AppleTalk happened in 2009. The same year routing equipment vendors (namely Cisco) end their support. Thus, AppleTalk won't be supported in FreeBSD 11.0-RELEASE. Notes: svn path=/head/; revision=263152
* Remove IPX support.Gleb Smirnoff2014-03-141-119/+0
| | | | | | | | | | | | | | IPX was a network transport protocol in Novell's NetWare network operating system from late 80s and then 90s. The NetWare itself switched to TCP/IP as default transport in 1998. Later, in this century the Novell Open Enterprise Server became successor of Novell NetWare. The last release that claimed to still support IPX was OES 2 in 2007. Routing equipment vendors (e.g. Cisco) discontinued support for IPX in 2011. Thus, IPX won't be supported in FreeBSD 11.0-RELEASE. Notes: svn path=/head/; revision=263140
* Fix compilation for 32-bit machines.Gleb Smirnoff2014-03-061-4/+4
| | | | Notes: svn path=/head/; revision=262819
* Hide struct rtentry from userland.Gleb Smirnoff2014-03-051-0/+1
| | | | Notes: svn path=/head/; revision=262767
* - Remove rt_metrics_lite and simply put its members into rtentry.Gleb Smirnoff2014-03-051-31/+23
| | | | | | | | | | | | | | | | | | | - Use counter(9) for rt_pksent (former rt_rmx.rmx_pksent). This removes another cache trashing ++ from packet forwarding path. - Create zini/fini methods for the rtentry UMA zone. Via initialize mutex and counter in them. - Fix reporting of rmx_pksent to routing socket. - Fix netstat(1) to report "Use" both in kvm(3) and sysctl(3) mode. The change is mostly targeted for stable/10 merge. For head, rt_pksent is expected to just disappear. Discussed with: melifaro Sponsored by: Netflix Sponsored by: Nginx, Inc. Notes: svn path=/head/; revision=262763
* Explicitly free rt_tables to please Coverity.Alexander V. Chernikov2013-12-311-1/+3
| | | | | | | | | Reported by: Coverity Coverity CID: 1147174 MFC after: 2 weeks Notes: svn path=/head/; revision=260124
* Further split kvm(3) and sysctl interfaces for route table printing.Alexander V. Chernikov2013-12-201-72/+89
| | | | | | | | MFC after: 4 weeks Sponsored by: Yandex LLC Notes: svn path=/head/; revision=259645
* Use more fine-grained kvm(3) symbol lookup: routing code retrieves onlyAlexander V. Chernikov2013-12-201-12/+32
| | | | | | | | | | | | | | necessary symbols needed per subsystem. Main kvm(3) init is now delayed as much as possbile. This finally fixes performance issues reported in kern/167204. Some non-working code (ng_socket.ko symbol addresses calculation) removed. Some global variables eliminated. PR: kern/167204 MFC after: 4 weeks Notes: svn path=/head/; revision=259638
* Restore corefiles handling via kvm(3).Alexander V. Chernikov2013-12-181-1/+1
| | | | | | | | Found by: John-Mark Gurney <jmg at funkthat.com> MFC after: 4 weeks Notes: svn path=/head/; revision=259566
* Switch netstat -rn to use standard API for retrieving list of routesAlexander V. Chernikov2013-12-181-58/+120
| | | | | | | | | | | | | | | | | | | | | | | instead of peeking inside in-kernel radix via kget. This permits us to change kernel structures without breaking userland. Additionally, this change provide more reliable and faster output. `Refs` and `Use` fields available in IPv4 by default (and via -W for other families) were removed. `Refs` is radix-specific thing which is not informative for users. `Use` field value is handy sometimes, but a) current API does not support it and b) I'm not sure we will support per-rte pcpu counters in near future. Old method of retrieving data is still supported (either by defining NewTree=0 or running netstat with -A). However, Refs/Use fields are hidden. Sponsored by: Yandex LLC MFC after: 4 weeks PR: kern/167204 Notes: svn path=/head/; revision=259562
* Rewrite netstat/if.c to use getifaddrs(3) and getifmaddrs(3) instead ofGleb Smirnoff2013-10-151-7/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | libkvm digging in kernel memory. This is possible since r231506 made getifaddrs(3) to supply if_data for each ifaddr. The pros of this change is that now netstat(1) doesn't know about kernel struct ifnet and struct ifaddr. And these structs are about to change significantly in head soon. New netstat binary will work well with 10.0 and any future kernel. The cons is that now it isn't possible to obtain interface statistics from a vmcore. Functions intpr() and sidewaysintpr() were rewritten from scratch. The output of netstat(1) has underwent the following changes: 1) The MTU is not printed for protocol addresses, since it has no notion. Dash is printed instead. If there would be a strong desire to return previous output, it is doable. 2) Output interface queue drops are not printed. Currently this data isn't available to userland via any API. We plan to drop 'struct ifqueue' from 'struct ifnet' very soon, so old kvm(3) access to queue drops is soon to be broken, too. The plan is that drivers would handle their queues theirselves and a new field in if_data would be updated in case of drops. 3) In-kernel reference count for multicast addresses isn't printed. I doubt that anyone used it. Anyway, netstat(1) is sysadmin tool, not kernel debugger. Sponsored by: Netflix Sponsored by: Nginx, Inc. Notes: svn path=/head/; revision=256512