From owner-svn-src-all@freebsd.org Sun Jul 19 09:29:29 2020 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id BE18F359959; Sun, 19 Jul 2020 09:29:29 +0000 (UTC) (envelope-from melifaro@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4B8fh952yVz4Lwn; Sun, 19 Jul 2020 09:29:29 +0000 (UTC) (envelope-from melifaro@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 913821989C; Sun, 19 Jul 2020 09:29:29 +0000 (UTC) (envelope-from melifaro@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 06J9TTMj038968; Sun, 19 Jul 2020 09:29:29 GMT (envelope-from melifaro@FreeBSD.org) Received: (from melifaro@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 06J9TS30038961; Sun, 19 Jul 2020 09:29:28 GMT (envelope-from melifaro@FreeBSD.org) Message-Id: <202007190929.06J9TS30038961@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: melifaro set sender to melifaro@FreeBSD.org using -f From: "Alexander V. Chernikov" Date: Sun, 19 Jul 2020 09:29:28 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r363319 - in head/sys: fs/nfsclient net netinet6 X-SVN-Group: head X-SVN-Commit-Author: melifaro X-SVN-Commit-Paths: in head/sys: fs/nfsclient net netinet6 X-SVN-Commit-Revision: 363319 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 19 Jul 2020 09:29:29 -0000 Author: melifaro Date: Sun Jul 19 09:29:27 2020 New Revision: 363319 URL: https://svnweb.freebsd.org/changeset/base/363319 Log: Transition from rtrequest1_fib() to rib_action(). Remove all variations of rtrequest and their uses and switch to to rib_action(). This is part of the new routing KPI. Submitted by: Neel Chauhan Differential Revision: https://reviews.freebsd.org/D25546 Modified: head/sys/fs/nfsclient/nfs_clvfsops.c head/sys/net/if.c head/sys/net/route.c head/sys/net/route.h head/sys/netinet6/in6_rmx.c head/sys/netinet6/in6_var.h head/sys/netinet6/nd6.c head/sys/netinet6/nd6_rtr.c Modified: head/sys/fs/nfsclient/nfs_clvfsops.c ============================================================================== --- head/sys/fs/nfsclient/nfs_clvfsops.c Sun Jul 19 06:59:09 2020 (r363318) +++ head/sys/fs/nfsclient/nfs_clvfsops.c Sun Jul 19 09:29:27 2020 (r363319) @@ -68,6 +68,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include @@ -466,6 +467,8 @@ nfs_mountroot(struct mount *mp) nd->mygateway.sin_addr.s_addr != 0) { struct sockaddr_in mask, sin; struct epoch_tracker et; + struct rt_addrinfo info; + struct rib_cmd_info rc; bzero((caddr_t)&mask, sizeof(mask)); sin = mask; @@ -474,10 +477,14 @@ nfs_mountroot(struct mount *mp) /* XXX MRT use table 0 for this sort of thing */ NET_EPOCH_ENTER(et); CURVNET_SET(TD_TO_VNET(td)); - error = rtrequest_fib(RTM_ADD, (struct sockaddr *)&sin, - (struct sockaddr *)&nd->mygateway, - (struct sockaddr *)&mask, - RTF_UP | RTF_GATEWAY, NULL, RT_DEFAULT_FIB); + + bzero((caddr_t)&info, sizeof(info)); + info.rti_flags = RTF_UP | RTF_GATEWAY; + info.rti_info[RTAX_DST] = (struct sockaddr *)&sin; + info.rti_info[RTAX_GATEWAY] = (struct sockaddr *)&nd->mygateway; + info.rti_info[RTAX_NETMASK] = (struct sockaddr *)&mask; + + error = rib_action(RT_DEFAULT_FIB, RTM_ADD, &info, &rc); CURVNET_RESTORE(); NET_EPOCH_EXIT(et); if (error) Modified: head/sys/net/if.c ============================================================================== --- head/sys/net/if.c Sun Jul 19 06:59:09 2020 (r363318) +++ head/sys/net/if.c Sun Jul 19 09:29:27 2020 (r363319) @@ -80,6 +80,7 @@ #include #include #include +#include #include #if defined(INET) || defined(INET6) @@ -1845,6 +1846,7 @@ static int ifa_maintain_loopback_route(int cmd, const char *otype, struct ifaddr *ifa, struct sockaddr *ia) { + struct rib_cmd_info rc; struct epoch_tracker et; int error; struct rt_addrinfo info; @@ -1872,7 +1874,7 @@ ifa_maintain_loopback_route(int cmd, const char *otype info.rti_info[RTAX_GATEWAY] = (struct sockaddr *)&null_sdl; link_init_sdl(ifp, (struct sockaddr *)&null_sdl, ifp->if_type); - error = rtrequest1_fib(cmd, &info, NULL, ifp->if_fib); + error = rib_action(ifp->if_fib, cmd, &info, &rc); NET_EPOCH_EXIT(et); if (rti_ifa != NULL) Modified: head/sys/net/route.c ============================================================================== --- head/sys/net/route.c Sun Jul 19 06:59:09 2020 (r363318) +++ head/sys/net/route.c Sun Jul 19 09:29:27 2020 (r363319) @@ -470,7 +470,7 @@ 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 rtentry *rt; + struct rib_cmd_info rc; int error; struct rt_addrinfo info; struct rt_metrics rti_rmx; @@ -504,7 +504,7 @@ rib_add_redirect(u_int fibnum, struct sockaddr *dst, s info.rti_mflags |= RTV_EXPIRE; info.rti_rmx = &rti_rmx; - error = rtrequest1_fib(RTM_ADD, &info, &rt, fibnum); + error = rib_action(fibnum, RTM_ADD, &info, &rc); ifa_free(ifa); if (error != 0) { @@ -512,9 +512,9 @@ rib_add_redirect(u_int fibnum, struct sockaddr *dst, s return (error); } - RT_LOCK(rt); - flags = rt->rt_flags; - RT_UNLOCK(rt); + RT_LOCK(rc.rc_rt); + flags = rc.rc_rt->rt_flags; + RT_UNLOCK(rc.rc_rt); RTSTAT_INC(rts_dynamic); @@ -602,33 +602,7 @@ ifa_ifwithroute(int flags, const struct sockaddr *dst, return (ifa); } -/* - * Do appropriate manipulations of a routing tree given - * all the bits of info needed - */ -int -rtrequest_fib(int req, - struct sockaddr *dst, - struct sockaddr *gateway, - struct sockaddr *netmask, - int flags, - struct rtentry **ret_nrt, - u_int fibnum) -{ - struct rt_addrinfo info; - if (dst->sa_len == 0) - return(EINVAL); - - bzero((caddr_t)&info, sizeof(info)); - info.rti_flags = flags; - info.rti_info[RTAX_DST] = dst; - info.rti_info[RTAX_GATEWAY] = gateway; - info.rti_info[RTAX_NETMASK] = netmask; - return rtrequest1_fib(req, &info, ret_nrt, fibnum); -} - - /* * Copy most of @rt data into @info. * @@ -1148,73 +1122,6 @@ rt_mpath_unlink(struct rib_head *rnh, struct rt_addrin } #endif -int -rtrequest1_fib(int req, struct rt_addrinfo *info, struct rtentry **ret_nrt, - u_int fibnum) -{ - const struct sockaddr *dst; - struct rib_head *rnh; - struct rib_cmd_info rc; - int error; - - KASSERT((fibnum < rt_numfibs), ("rtrequest1_fib: bad fibnum")); - KASSERT((info->rti_flags & RTF_RNH_LOCKED) == 0, ("rtrequest1_fib: locked")); - NET_EPOCH_ASSERT(); - - dst = info->rti_info[RTAX_DST]; - - switch (dst->sa_family) { - case AF_INET6: - case AF_INET: - /* We support multiple FIBs. */ - break; - default: - fibnum = RT_DEFAULT_FIB; - break; - } - - /* - * Find the correct routing tree to use for this Address Family - */ - rnh = rt_tables_get_rnh(fibnum, dst->sa_family); - if (rnh == NULL) - return (EAFNOSUPPORT); - - /* - * If we are adding a host route then we don't want to put - * a netmask in the tree, nor do we want to clone it. - */ - if (info->rti_flags & RTF_HOST) - info->rti_info[RTAX_NETMASK] = NULL; - - bzero(&rc, sizeof(struct rib_cmd_info)); - error = 0; - switch (req) { - case RTM_DELETE: - error = del_route(rnh, info, &rc); - break; - case RTM_RESOLVE: - /* - * resolve was only used for route cloning - * here for compat - */ - break; - case RTM_ADD: - error = add_route(rnh, info, &rc); - break; - case RTM_CHANGE: - error = change_route(rnh, info, &rc); - break; - default: - error = EOPNOTSUPP; - } - - if (ret_nrt != NULL) - *ret_nrt = rc.rc_rt; - - return (error); -} - void rt_setmetrics(const struct rt_addrinfo *info, struct rtentry *rt) { @@ -1258,7 +1165,7 @@ rtinit1(struct ifaddr *ifa, int cmd, int flags, int fi struct epoch_tracker et; struct sockaddr *dst; struct sockaddr *netmask; - struct rtentry *rt = NULL; + struct rib_cmd_info rc; struct rt_addrinfo info; int error = 0; int startfib, endfib; @@ -1349,7 +1256,7 @@ rtinit1(struct ifaddr *ifa, int cmd, int flags, int fi if (rn == NULL) error = ESRCH; else { - rt = RNTORT(rn); + struct rtentry *rt = RNTORT(rn); /* * for interface route the gateway * gateway is sockaddr_dl, so @@ -1389,14 +1296,14 @@ rtinit1(struct ifaddr *ifa, int cmd, int flags, int fi info.rti_info[RTAX_GATEWAY] = ifa->ifa_addr; info.rti_info[RTAX_NETMASK] = netmask; NET_EPOCH_ENTER(et); - error = rtrequest1_fib(cmd, &info, &rt, fibnum); - if (error == 0 && rt != NULL) { + error = rib_action(fibnum, cmd, &info, &rc); + if (error == 0 && rc.rc_rt != NULL) { /* * notify any listening routing agents of the change */ /* TODO: interface routes/aliases */ - rt_newaddrmsg_fib(cmd, ifa, rt, fibnum); + rt_newaddrmsg_fib(cmd, ifa, rc.rc_rt, fibnum); didwork = 1; } NET_EPOCH_EXIT(et); Modified: head/sys/net/route.h ============================================================================== --- head/sys/net/route.h Sun Jul 19 06:59:09 2020 (r363318) +++ head/sys/net/route.h Sun Jul 19 09:29:27 2020 (r363319) @@ -411,9 +411,6 @@ int rtinit(struct ifaddr *, int, int); * but this will change.. */ int rtioctl_fib(u_long, caddr_t, u_int); -int rtrequest_fib(int, struct sockaddr *, - struct sockaddr *, struct sockaddr *, int, struct rtentry **, u_int); -int rtrequest1_fib(int, struct rt_addrinfo *, struct rtentry **, u_int); int rib_lookup_info(uint32_t, const struct sockaddr *, uint32_t, uint32_t, struct rt_addrinfo *); void rib_free_info(struct rt_addrinfo *info); Modified: head/sys/netinet6/in6_rmx.c ============================================================================== --- head/sys/netinet6/in6_rmx.c Sun Jul 19 06:59:09 2020 (r363318) +++ head/sys/netinet6/in6_rmx.c Sun Jul 19 09:29:27 2020 (r363319) @@ -185,14 +185,3 @@ in6_detachhead(void **head, int off) } #endif -/* - * Extended API for IPv6 FIB support. - */ -int -in6_rtrequest(int req, struct sockaddr *dst, struct sockaddr *gw, - struct sockaddr *mask, int flags, struct rtentry **ret_nrt, u_int fibnum) -{ - - return (rtrequest_fib(req, dst, gw, mask, flags, ret_nrt, fibnum)); -} - Modified: head/sys/netinet6/in6_var.h ============================================================================== --- head/sys/netinet6/in6_var.h Sun Jul 19 06:59:09 2020 (r363318) +++ head/sys/netinet6/in6_var.h Sun Jul 19 09:29:27 2020 (r363319) @@ -915,8 +915,6 @@ void in6_newaddrmsg(struct in6_ifaddr *, int); * Extended API for IPv6 FIB support. */ struct mbuf *ip6_tryforward(struct mbuf *); -int in6_rtrequest(int, struct sockaddr *, struct sockaddr *, - struct sockaddr *, int, struct rtentry **, u_int); #endif /* _KERNEL */ #endif /* _NETINET6_IN6_VAR_H_ */ Modified: head/sys/netinet6/nd6.c ============================================================================== --- head/sys/netinet6/nd6.c Sun Jul 19 06:59:09 2020 (r363318) +++ head/sys/netinet6/nd6.c Sun Jul 19 09:29:27 2020 (r363319) @@ -1564,6 +1564,7 @@ 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); @@ -1573,7 +1574,7 @@ nd6_free_redirect(const struct llentry *ln) NET_EPOCH_ENTER(et); for (fibnum = 0; fibnum < rt_numfibs; fibnum++) - rtrequest1_fib(RTM_DELETE, &info, NULL, fibnum); + rib_action(fibnum, RTM_DELETE, &info, &rc); NET_EPOCH_EXIT(et); } Modified: head/sys/netinet6/nd6_rtr.c ============================================================================== --- head/sys/netinet6/nd6_rtr.c Sun Jul 19 06:59:09 2020 (r363318) +++ head/sys/netinet6/nd6_rtr.c Sun Jul 19 09:29:27 2020 (r363319) @@ -674,7 +674,8 @@ static void defrouter_addreq(struct nd_defrouter *new) { struct sockaddr_in6 def, mask, gate; - struct rtentry *newrt = NULL; + struct rt_addrinfo info; + struct rib_cmd_info rc; unsigned int fibnum; int error; @@ -688,11 +689,16 @@ defrouter_addreq(struct nd_defrouter *new) gate.sin6_addr = new->rtaddr; fibnum = new->ifp->if_fib; - error = in6_rtrequest(RTM_ADD, (struct sockaddr *)&def, - (struct sockaddr *)&gate, (struct sockaddr *)&mask, - RTF_GATEWAY, &newrt, fibnum); - if (newrt != NULL) - rt_routemsg(RTM_ADD, newrt, new->ifp, 0, fibnum); + bzero((caddr_t)&info, sizeof(info)); + info.rti_flags = RTF_GATEWAY; + info.rti_info[RTAX_DST] = (struct sockaddr *)&def; + info.rti_info[RTAX_GATEWAY] = (struct sockaddr *)&gate; + info.rti_info[RTAX_NETMASK] = (struct sockaddr *)&mask; + + NET_EPOCH_ASSERT(); + error = rib_action(fibnum, RTM_ADD, &info, &rc); + if (rc.rc_rt != NULL) + rt_routemsg(RTM_ADD, rc.rc_rt, new->ifp, 0, fibnum); if (error == 0) new->installed = 1; } @@ -706,7 +712,8 @@ static void defrouter_delreq(struct nd_defrouter *dr) { struct sockaddr_in6 def, mask, gate; - struct rtentry *oldrt = NULL; + struct rt_addrinfo info; + struct rib_cmd_info rc; struct epoch_tracker et; unsigned int fibnum; @@ -720,12 +727,16 @@ defrouter_delreq(struct nd_defrouter *dr) gate.sin6_addr = dr->rtaddr; fibnum = dr->ifp->if_fib; + bzero((caddr_t)&info, sizeof(info)); + info.rti_flags = RTF_GATEWAY; + info.rti_info[RTAX_DST] = (struct sockaddr *)&def; + info.rti_info[RTAX_GATEWAY] = (struct sockaddr *)&gate; + info.rti_info[RTAX_NETMASK] = (struct sockaddr *)&mask; + NET_EPOCH_ENTER(et); - in6_rtrequest(RTM_DELETE, (struct sockaddr *)&def, - (struct sockaddr *)&gate, - (struct sockaddr *)&mask, RTF_GATEWAY, &oldrt, fibnum); - if (oldrt != NULL) - rt_routemsg(RTM_DELETE, oldrt, dr->ifp, 0, fibnum); + rib_action(fibnum, RTM_DELETE, &info, &rc); + if (rc.rc_rt != NULL) + rt_routemsg(RTM_DELETE, rc.rc_rt, dr->ifp, 0, fibnum); NET_EPOCH_EXIT(et); dr->installed = 0; @@ -2009,7 +2020,6 @@ static int nd6_prefix_onlink_rtrequest(struct nd_prefix *pr, struct ifaddr *ifa) { struct sockaddr_dl_short sdl; - struct rtentry *rt; struct sockaddr_in6 mask6; u_long rtflags; int error, a_failure, fibnum, maxfib; @@ -2034,11 +2044,17 @@ nd6_prefix_onlink_rtrequest(struct nd_prefix *pr, stru } a_failure = 0; for (; fibnum < maxfib; fibnum++) { + struct rt_addrinfo info; + struct rib_cmd_info rc; - rt = NULL; - error = in6_rtrequest(RTM_ADD, - (struct sockaddr *)&pr->ndpr_prefix, (struct sockaddr *)&sdl, - (struct sockaddr *)&mask6, rtflags, &rt, fibnum); + bzero((caddr_t)&info, sizeof(info)); + info.rti_flags = rtflags; + info.rti_info[RTAX_DST] = (struct sockaddr *)&pr->ndpr_prefix; + info.rti_info[RTAX_GATEWAY] = (struct sockaddr *)&sdl; + info.rti_info[RTAX_NETMASK] = (struct sockaddr *)&mask6; + + NET_EPOCH_ASSERT(); + error = rib_action(fibnum, RTM_ADD, &info, &rc); if (error != 0) { char ip6buf[INET6_ADDRSTRLEN]; char ip6bufg[INET6_ADDRSTRLEN]; @@ -2061,7 +2077,7 @@ nd6_prefix_onlink_rtrequest(struct nd_prefix *pr, stru } pr->ndpr_stateflags |= NDPRF_ONLINK; - rt_routemsg(RTM_ADD, rt, pr->ndpr_ifp, 0, fibnum); + rt_routemsg(RTM_ADD, rc.rc_rt, pr->ndpr_ifp, 0, fibnum); } /* Return the last error we got. */ @@ -2158,7 +2174,6 @@ nd6_prefix_offlink(struct nd_prefix *pr) struct ifnet *ifp = pr->ndpr_ifp; struct nd_prefix *opr; struct sockaddr_in6 sa6, mask6; - struct rtentry *rt; char ip6buf[INET6_ADDRSTRLEN]; uint64_t genid; int fibnum, maxfib, a_failure; @@ -2191,9 +2206,17 @@ nd6_prefix_offlink(struct nd_prefix *pr) a_failure = 0; NET_EPOCH_ENTER(et); for (; fibnum < maxfib; fibnum++) { - rt = NULL; - error = in6_rtrequest(RTM_DELETE, (struct sockaddr *)&sa6, NULL, - (struct sockaddr *)&mask6, 0, &rt, fibnum); + struct rt_addrinfo info; + struct rib_cmd_info rc; + + bzero((caddr_t)&info, sizeof(info)); + info.rti_flags = RTF_GATEWAY; + info.rti_info[RTAX_DST] = (struct sockaddr *)&sa6; + info.rti_info[RTAX_GATEWAY] = NULL; + info.rti_info[RTAX_NETMASK] = (struct sockaddr *)&mask6; + + NET_EPOCH_ASSERT(); + error = rib_action(fibnum, RTM_DELETE, &info, &rc); if (error != 0) { /* Save last error to return, see rtinit(). */ a_failure = error; @@ -2201,7 +2224,7 @@ nd6_prefix_offlink(struct nd_prefix *pr) } /* report route deletion to the routing socket. */ - rt_routemsg(RTM_DELETE, rt, ifp, 0, fibnum); + rt_routemsg(RTM_DELETE, rc.rc_rt, ifp, 0, fibnum); } NET_EPOCH_EXIT(et); error = a_failure;