git: 1350c3f17100 - stable/13 - routing: make rib_add_redirect() use new nhop-based KPI
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Fri, 13 Jan 2023 21:25:46 UTC
The branch stable/13 has been updated by melifaro: URL: https://cgit.FreeBSD.org/src/commit/?id=1350c3f17100b73c02babd92878e4e2ae68f22f9 commit 1350c3f17100b73c02babd92878e4e2ae68f22f9 Author: Alexander V. Chernikov <melifaro@FreeBSD.org> AuthorDate: 2022-08-09 11:45:59 +0000 Commit: Alexander V. Chernikov <melifaro@FreeBSD.org> CommitDate: 2023-01-13 21:24:11 +0000 routing: make rib_add_redirect() use new nhop-based KPI MFC after: 1 month Differential Revision: https://reviews.freebsd.org/D36169 (cherry picked from commit 6d4f6e4c704d17084144ac3fe0c8507015f1357f) --- sys/net/route.c | 44 ++++++++++++++++++++++---------------------- sys/netinet6/nd6.c | 7 ++----- 2 files changed, 24 insertions(+), 27 deletions(-) diff --git a/sys/net/route.c b/sys/net/route.c index 7a18acc0c281..7190d93d787d 100644 --- a/sys/net/route.c +++ b/sys/net/route.c @@ -188,11 +188,10 @@ int rib_add_redirect(u_int fibnum, struct sockaddr *dst, struct sockaddr *gateway, struct sockaddr *author, struct ifnet *ifp, int flags, int lifetime_sec) { + struct route_nhop_data rnd = { .rnd_weight = RT_DEFAULT_WEIGHT }; struct rib_cmd_info rc; - int error; - struct rt_addrinfo info; - struct rt_metrics rti_rmx; struct ifaddr *ifa; + int error; NET_EPOCH_ASSERT(); @@ -208,21 +207,21 @@ rib_add_redirect(u_int fibnum, struct sockaddr *dst, struct sockaddr *gateway, if ((ifa = ifaof_ifpforaddr(gateway, ifp)) == NULL) return (ENETUNREACH); - bzero(&info, sizeof(info)); - info.rti_info[RTAX_DST] = dst; - info.rti_info[RTAX_GATEWAY] = gateway; - info.rti_ifa = ifa; - info.rti_ifp = ifp; - info.rti_flags = flags; - - /* Setup route metrics to define expire time. */ - bzero(&rti_rmx, sizeof(rti_rmx)); - /* Set expire time as absolute. */ - rti_rmx.rmx_expire = lifetime_sec + time_second; - info.rti_mflags |= RTV_EXPIRE; - info.rti_rmx = &rti_rmx; - - error = rib_action(fibnum, RTM_ADD, &info, &rc); + struct nhop_object *nh = nhop_alloc(fibnum, dst->sa_family); + if (nh == NULL) + return (ENOMEM); + + nhop_set_gw(nh, gateway, flags & RTF_GATEWAY); + nhop_set_transmit_ifp(nh, ifp); + nhop_set_src(nh, ifa); + nhop_set_pxtype_flag(nh, NHF_HOST); + nhop_set_expire(nh, lifetime_sec + time_uptime); + nhop_set_redirect(nh, true); + rnd.rnd_nhop = nhop_get_nhop(nh, &error); + if (error == 0) { + error = rib_add_route_px(fibnum, dst, -1, + &rnd, RTM_F_CREATE, &rc); + } if (error != 0) { /* TODO: add per-fib redirect stats. */ @@ -232,10 +231,11 @@ rib_add_redirect(u_int fibnum, struct sockaddr *dst, struct sockaddr *gateway, RTSTAT_INC(rts_dynamic); /* Send notification of a route addition to userland. */ - bzero(&info, sizeof(info)); - info.rti_info[RTAX_DST] = dst; - info.rti_info[RTAX_GATEWAY] = gateway; - info.rti_info[RTAX_AUTHOR] = author; + struct rt_addrinfo info = { + .rti_info[RTAX_DST] = dst, + .rti_info[RTAX_GATEWAY] = gateway, + .rti_info[RTAX_AUTHOR] = author, + }; rt_missmsg_fib(RTM_REDIRECT, &info, flags | RTF_UP, error, fibnum); return (0); diff --git a/sys/netinet6/nd6.c b/sys/netinet6/nd6.c index e4d657feed98..751511170439 100644 --- a/sys/netinet6/nd6.c +++ b/sys/netinet6/nd6.c @@ -1575,18 +1575,15 @@ nd6_free_redirect(const struct llentry *ln) { int fibnum; struct sockaddr_in6 sin6; - struct rt_addrinfo info; struct rib_cmd_info rc; struct epoch_tracker et; lltable_fill_sa_entry(ln, (struct sockaddr *)&sin6); - memset(&info, 0, sizeof(info)); - info.rti_info[RTAX_DST] = (struct sockaddr *)&sin6; - info.rti_filter = nd6_isdynrte; NET_EPOCH_ENTER(et); for (fibnum = 0; fibnum < rt_numfibs; fibnum++) - rib_action(fibnum, RTM_DELETE, &info, &rc); + rib_del_route_px(fibnum, (struct sockaddr *)&sin6, 128, + nd6_isdynrte, NULL, 0, &rc); NET_EPOCH_EXIT(et); }