git: netinet: Auto add loopback routes to interface addresses

Aaron LI aly at
Wed Mar 20 08:33:50 PDT 2024

commit 951ecd7f55e2edd33258ad6d9593c9f81c92b42e
Author: Aaron LI <aly at>
Date:   Mon Mar 18 11:43:41 2024 +0800

    netinet: Auto add loopback routes to interface addresses
    When adding an address to an interface, a loopback route will be created
    to route the traffic targeting it through the lo0 interface.  The
    loopback route will also be removed when the corresponding interface
    address is deleted.
    In principle, this can help simplify the network input and output paths
    by avoiding special handling of local addresses.  That deserves some
    further efforts.
    Nonetheless, an immediate benefit goes to wg(4).  Now we can access
    (e.g., ping) from localhost a wg(4) interface's IPv4 addresses.
    Previously it was broken because wg(4) is a virtual device and doesn't
    have/use ARP.  For Ethernet devices, the ether_output() function will
    redirect the traffic targeting its own address to the loopback interface
    by calling if_simloop().
    Derived from FreeBSD; the major commits are:
    - This patch adds a host route to an interface address ...
    - Self pointing routes are installed for configured interface addr ...
    - Unify loopback route switching
    - Fix rt_ifa selection during loopback route insertion process
    Discussed-with: dillon

Summary of changes:
 sys/net/if.c         | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 sys/net/if_var.h     |  3 +++
 sys/netinet/in.c     | 18 +++++++++++++
 sys/netinet/in_rmx.c | 27 ++++++++++++--------
 4 files changed, 109 insertions(+), 11 deletions(-)

DragonFly BSD source repository

More information about the Commits mailing list