The branch main has been updated by pouria:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=ff6d1faa65a1a77d04746b43023feb457cfa27b8

commit ff6d1faa65a1a77d04746b43023feb457cfa27b8
Author:     Pouria Mousavizadeh Tehrani <[email protected]>
AuthorDate: 2026-02-22 17:46:12 +0000
Commit:     Pouria Mousavizadeh Tehrani <[email protected]>
CommitDate: 2026-02-26 09:37:14 +0000

    rtnetlink: Add support for nexthop expiration in new/get route
    
    Before this change, netlink only shows nexthop
    expire value if route is not multipath.
    Now it can set expire time during route creation.
    Also, show expire time of multipath nexthops.
    
    Reviewed by: glebius
    MFC after: 3 weeks
    Differential Revision: https://reviews.freebsd.org/D55442
---
 sys/netlink/netlink_snl_route_parsers.h |  2 ++
 sys/netlink/route/rt.c                  | 12 +++++++++++-
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/sys/netlink/netlink_snl_route_parsers.h 
b/sys/netlink/netlink_snl_route_parsers.h
index 6b7a8188180d..70a12ad3ad74 100644
--- a/sys/netlink/netlink_snl_route_parsers.h
+++ b/sys/netlink/netlink_snl_route_parsers.h
@@ -53,6 +53,7 @@ struct rta_mpath_nh {
        uint8_t         rtnh_weight;
        uint32_t        rtax_mtu;
        uint32_t        rta_rtflags;
+       uint32_t        rta_expire;
 };
 
 #define        _IN(_field)     offsetof(struct rtnexthop, _field)
@@ -67,6 +68,7 @@ static const struct snl_attr_parser _nla_p_mp_nh[] = {
        { .type = NL_RTA_METRICS, .arg = &_metrics_mp_nh_parser, .cb = 
snl_attr_get_nested },
        { .type = NL_RTA_RTFLAGS, .off = _OUT(rta_rtflags), .cb = 
snl_attr_get_uint32 },
        { .type = NL_RTA_VIA, .off = _OUT(gw), .cb = snl_attr_get_ipvia },
+       { .type = NL_RTA_EXPIRES, .off = _OUT(rta_expire), .cb = 
snl_attr_get_uint32 },
 };
 
 static const struct snl_field_parser _fp_p_mp_nh[] = {
diff --git a/sys/netlink/route/rt.c b/sys/netlink/route/rt.c
index dcd19b43105c..4d7f676d2aec 100644
--- a/sys/netlink/route/rt.c
+++ b/sys/netlink/route/rt.c
@@ -179,7 +179,7 @@ static void
 dump_rc_nhg(struct nl_writer *nw, const struct nhgrp_object *nhg, struct rtmsg 
*rtm)
 {
        uint32_t uidx = nhgrp_get_uidx(nhg);
-       uint32_t num_nhops;
+       uint32_t num_nhops, nh_expire;
        const struct weightened_nhop *wn = nhgrp_get_nhops(nhg, &num_nhops);
        uint32_t base_rtflags = nhop_get_rtflags(wn[0].nh);
 
@@ -206,6 +206,9 @@ dump_rc_nhg(struct nl_writer *nw, const struct nhgrp_object 
*nhg, struct rtmsg *
                        nlattr_add_u32(nw, NL_RTA_RTFLAGS, rtflags);
                if (rtflags & RTF_FIXEDMTU)
                        dump_rc_nhop_mtu(nw, wn[i].nh);
+               nh_expire = nhop_get_expire(wn[i].nh);
+               if (nh_expire > 0)
+                       nlattr_add_u32(nw, NL_RTA_EXPIRES, nh_expire - 
time_uptime);
                rtnh = nlattr_restore_offset(nw, nh_off, struct rtnexthop);
                /*
                 * nlattr_add() allocates 4-byte aligned storage, no need to 
aligh
@@ -487,6 +490,7 @@ struct nl_parsed_route {
        uint32_t                rta_rtflags;
        uint32_t                rta_nh_id;
        uint32_t                rta_weight;
+       uint32_t                rta_expire;
        uint32_t                rtax_mtu;
        uint8_t                 rtm_table;
        uint8_t                 rtm_family;
@@ -513,6 +517,7 @@ static const struct nlattr_parser nla_p_rtmsg[] = {
        { .type = NL_RTA_RTFLAGS, .off = _OUT(rta_rtflags), .cb = 
nlattr_get_uint32 },
        { .type = NL_RTA_TABLE, .off = _OUT(rta_table), .cb = nlattr_get_uint32 
},
        { .type = NL_RTA_VIA, .off = _OUT(rta_gw), .cb = nlattr_get_ipvia },
+       { .type = NL_RTA_EXPIRES, .off = _OUT(rta_expire), .cb = 
nlattr_get_uint32 },
        { .type = NL_RTA_NH_ID, .off = _OUT(rta_nh_id), .cb = nlattr_get_uint32 
},
 };
 
@@ -851,6 +856,7 @@ create_nexthop_from_attrs(struct nl_parsed_route *attrs,
 {
        struct nhop_object *nh = NULL;
        int error = 0;
+       uint32_t nh_expire = 0;
 
        if (attrs->rta_multipath != NULL) {
 #ifdef ROUTE_MPATH
@@ -907,6 +913,10 @@ create_nexthop_from_attrs(struct nl_parsed_route *attrs,
                        nhop_set_transmit_ifp(nh, attrs->rta_oif);
                if (attrs->rtax_mtu != 0)
                        nhop_set_mtu(nh, attrs->rtax_mtu, true);
+               if (attrs->rta_expire > 0) {
+                       nh_expire = attrs->rta_expire - time_second + 
time_uptime;
+                       nhop_set_expire(nh, nh_expire);
+               }
                if (attrs->rta_rtflags & RTF_BROADCAST)
                        nhop_set_broadcast(nh, true);
                if (attrs->rtm_protocol > RTPROT_STATIC)

Reply via email to