From owner-svn-src-head@freebsd.org Mon Jun 1 20:40:43 2020 Return-Path: Delivered-To: svn-src-head@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 31D142F1BBD; Mon, 1 Jun 2020 20:40:43 +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 49bRrq0y66z3SJR; Mon, 1 Jun 2020 20:40:43 +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 1BCF01159F; Mon, 1 Jun 2020 20:40:43 +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 051Keh6q055660; Mon, 1 Jun 2020 20:40:43 GMT (envelope-from melifaro@FreeBSD.org) Received: (from melifaro@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 051Kee9m055647; Mon, 1 Jun 2020 20:40:40 GMT (envelope-from melifaro@FreeBSD.org) Message-Id: <202006012040.051Kee9m055647@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: melifaro set sender to melifaro@FreeBSD.org using -f From: "Alexander V. Chernikov" Date: Mon, 1 Jun 2020 20:40:40 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r361705 - in head/sys: net net/route netinet netinet6 X-SVN-Group: head X-SVN-Commit-Author: melifaro X-SVN-Commit-Paths: in head/sys: net net/route netinet netinet6 X-SVN-Commit-Revision: 361705 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 01 Jun 2020 20:40:43 -0000 Author: melifaro Date: Mon Jun 1 20:40:40 2020 New Revision: 361705 URL: https://svnweb.freebsd.org/changeset/base/361705 Log: Revert r361704, it accidentally committed merged D25067 and D25070. Deleted: head/sys/net/route/route_ctl.h Modified: head/sys/net/if_llatbl.c head/sys/net/route.c head/sys/net/route.h head/sys/net/route/nhop_ctl.c head/sys/net/route/route_ctl.c head/sys/net/route/route_ddb.c head/sys/net/route/route_helpers.c head/sys/net/route/route_temporal.c head/sys/net/route/route_var.h head/sys/netinet/in_rmx.c head/sys/netinet/ip_icmp.c head/sys/netinet6/icmp6.c head/sys/netinet6/in6_rmx.c head/sys/netinet6/nd6_rtr.c Modified: head/sys/net/if_llatbl.c ============================================================================== --- head/sys/net/if_llatbl.c Mon Jun 1 20:32:02 2020 (r361704) +++ head/sys/net/if_llatbl.c Mon Jun 1 20:40:40 2020 (r361705) @@ -58,7 +58,6 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include #include #include #include Modified: head/sys/net/route.c ============================================================================== --- head/sys/net/route.c Mon Jun 1 20:32:02 2020 (r361704) +++ head/sys/net/route.c Mon Jun 1 20:40:40 2020 (r361705) @@ -61,7 +61,6 @@ #include #include #include -#include #include #include #include @@ -347,9 +346,6 @@ rt_table_init(int offset, int family, u_int fibnum) nhops_init_rib(rh); - /* Init subscription system */ - CK_STAILQ_INIT(&rh->rnh_subscribers); - /* Finally, set base callbacks */ rh->rnh_addaddr = rn_addroute; rh->rnh_deladdr = rn_delete; @@ -1152,7 +1148,6 @@ rtrequest1_fib(int req, struct rt_addrinfo *info, stru { const struct sockaddr *dst; struct rib_head *rnh; - struct rib_cmd_info rc; int error; KASSERT((fibnum < rt_numfibs), ("rtrequest1_fib: bad fibnum")); @@ -1185,11 +1180,10 @@ rtrequest1_fib(int req, struct rt_addrinfo *info, stru 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); + error = del_route(rnh, info, ret_nrt); break; case RTM_RESOLVE: /* @@ -1198,17 +1192,14 @@ rtrequest1_fib(int req, struct rt_addrinfo *info, stru */ break; case RTM_ADD: - error = add_route(rnh, info, &rc); + error = add_route(rnh, info, ret_nrt); break; case RTM_CHANGE: - error = change_route(rnh, info, &rc); + error = change_route(rnh, info, ret_nrt); break; default: error = EOPNOTSUPP; } - - if (ret_nrt != NULL) - *ret_nrt = rc.rc_rt; return (error); } Modified: head/sys/net/route.h ============================================================================== --- head/sys/net/route.h Mon Jun 1 20:32:02 2020 (r361704) +++ head/sys/net/route.h Mon Jun 1 20:40:40 2020 (r361705) @@ -399,6 +399,12 @@ void rtfree(struct rtentry *); void rtfree_func(struct rtentry *); void rt_updatemtu(struct ifnet *); +typedef int rt_walktree_f_t(struct rtentry *, void *); +typedef void rt_setwarg_t(struct rib_head *, uint32_t, int, void *); +void rib_walk_del(u_int fibnum, int family, rt_filter_f_t *filter_f, + void *arg, bool report); +void rt_foreach_fib_walk(int af, rt_setwarg_t *, rt_walktree_f_t *, void *); +void rt_foreach_fib_walk_del(int af, rt_filter_f_t *filter_f, void *arg); void rt_flushifroutes_af(struct ifnet *, int); void rt_flushifroutes(struct ifnet *ifp); @@ -417,8 +423,12 @@ int rtrequest1_fib(int, struct rt_addrinfo *, struct int rib_lookup_info(uint32_t, const struct sockaddr *, uint32_t, uint32_t, struct rt_addrinfo *); void rib_free_info(struct rt_addrinfo *info); +int rib_add_redirect(u_int fibnum, struct sockaddr *dst, + struct sockaddr *gateway, struct sockaddr *author, struct ifnet *ifp, + int flags, int expire_sec); /* New API */ +void rib_walk(int af, u_int fibnum, rt_walktree_f_t *wa_f, void *arg); struct nhop_object *rib_lookup(uint32_t fibnum, const struct sockaddr *dst, uint32_t flags, uint32_t flowid); #endif Modified: head/sys/net/route/nhop_ctl.c ============================================================================== --- head/sys/net/route/nhop_ctl.c Mon Jun 1 20:32:02 2020 (r361704) +++ head/sys/net/route/nhop_ctl.c Mon Jun 1 20:40:40 2020 (r361705) @@ -44,7 +44,6 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include #include #include #include Modified: head/sys/net/route/route_ctl.c ============================================================================== --- head/sys/net/route/route_ctl.c Mon Jun 1 20:32:02 2020 (r361704) +++ head/sys/net/route/route_ctl.c Mon Jun 1 20:40:40 2020 (r361705) @@ -47,7 +47,6 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include #include #include #include @@ -68,61 +67,11 @@ __FBSDID("$FreeBSD$"); * All functions assumes they are called in net epoch. */ -static void rib_notify(struct rib_head *rnh, enum rib_subscription_type type, - struct rib_cmd_info *rc); - static void rt_notifydelete(struct rtentry *rt, struct rt_addrinfo *info); -static struct rib_head * -get_rnh(uint32_t fibnum, const struct rt_addrinfo *info) -{ - struct rib_head *rnh; - struct sockaddr *dst; - - KASSERT((fibnum < rt_numfibs), ("rib_add_route: bad fibnum")); - - dst = info->rti_info[RTAX_DST]; - rnh = rt_tables_get_rnh(fibnum, dst->sa_family); - - return (rnh); -} - -/* - * Adds route defined by @info into the kernel table specified by @fibnum and - * sa_family in @info->rti_info[RTAX_DST]. - * - * Returns 0 on success and fills in operation metadata into @rc. - */ int -rib_add_route(uint32_t fibnum, struct rt_addrinfo *info, - struct rib_cmd_info *rc) -{ - struct rib_head *rnh; - - NET_EPOCH_ASSERT(); - - rnh = get_rnh(fibnum, info); - if (rnh == NULL) - return (EAFNOSUPPORT); - - /* - * Check consistency between RTF_HOST flag and netmask - * existence. - */ - if (info->rti_flags & RTF_HOST) - info->rti_info[RTAX_NETMASK] = NULL; - else if (info->rti_info[RTAX_NETMASK] == NULL) - return (EINVAL); - - bzero(rc, sizeof(struct rib_cmd_info)); - rc->rc_cmd = RTM_ADD; - - return (add_route(rnh, info, rc)); -} - -int add_route(struct rib_head *rnh, struct rt_addrinfo *info, - struct rib_cmd_info *rc) + struct rtentry **ret_nrt) { struct sockaddr *dst, *ndst, *gateway, *netmask; struct rtentry *rt, *rt_old; @@ -197,7 +146,6 @@ add_route(struct rib_head *rnh, struct rt_addrinfo *in rt->rt_weight = 1; rt_setmetrics(info, rt); - rt_old = NULL; RIB_WLOCK(rnh); RT_LOCK(rt); @@ -215,20 +163,12 @@ add_route(struct rib_head *rnh, struct rt_addrinfo *in rn = rnh->rnh_addaddr(ndst, netmask, &rnh->head, rt->rt_nodes); - if (rn != NULL) { - /* Most common usecase */ - if (rt->rt_expire > 0) - tmproutes_update(rnh, rt); + if (rn != NULL && rt->rt_expire > 0) + tmproutes_update(rnh, rt); - /* Finalize notification */ - rnh->rnh_gen++; + rt_old = NULL; + if (rn == NULL && (info->rti_flags & RTF_PINNED) != 0) { - rc->rc_rt = RNTORT(rn); - rc->rc_nh_new = nh; - - rib_notify(rnh, RIB_NOTIFY_IMMEDIATE, rc); - } else if ((info->rti_flags & RTF_PINNED) != 0) { - /* * Force removal and re-try addition * TODO: better multipath&pinned support @@ -240,26 +180,9 @@ add_route(struct rib_head *rnh, struct rt_addrinfo *in rt_old = rt_unlinkrte(rnh, info, &error); info->rti_flags |= RTF_PINNED; info->rti_info[RTAX_DST] = info_dst; - if (rt_old != NULL) { + if (rt_old != NULL) rn = rnh->rnh_addaddr(ndst, netmask, &rnh->head, rt->rt_nodes); - - /* Finalize notification */ - rnh->rnh_gen++; - - if (rn != NULL) { - rc->rc_cmd = RTM_CHANGE; - rc->rc_rt = RNTORT(rn); - rc->rc_nh_old = rt_old->rt_nhop; - rc->rc_nh_new = nh; - } else { - rc->rc_cmd = RTM_DELETE; - rc->rc_rt = RNTORT(rn); - rc->rc_nh_old = rt_old->rt_nhop; - rc->rc_nh_new = nh; - } - rib_notify(rnh, RIB_NOTIFY_IMMEDIATE, rc); - } } RIB_WUNLOCK(rnh); @@ -285,6 +208,12 @@ add_route(struct rib_head *rnh, struct rt_addrinfo *in if (ifa->ifa_rtrequest) ifa->ifa_rtrequest(RTM_ADD, rt, rt->rt_nhop, info); + /* + * actually return a resultant rtentry + */ + if (ret_nrt) + *ret_nrt = rt; + rnh->rnh_gen++; /* Routing table updated */ RT_UNLOCK(rt); return (0); @@ -292,29 +221,6 @@ add_route(struct rib_head *rnh, struct rt_addrinfo *in /* - * Removes route defined by @info from the kernel table specified by @fibnum and - * sa_family in @info->rti_info[RTAX_DST]. - * - * Returns 0 on success and fills in operation metadata into @rc. - */ -int -rib_del_route(uint32_t fibnum, struct rt_addrinfo *info, struct rib_cmd_info *rc) -{ - struct rib_head *rnh; - - NET_EPOCH_ASSERT(); - - rnh = get_rnh(fibnum, info); - if (rnh == NULL) - return (EAFNOSUPPORT); - - bzero(rc, sizeof(struct rib_cmd_info)); - rc->rc_cmd = RTM_DELETE; - - return (del_route(rnh, info, rc)); -} - -/* * Conditionally unlinks rtentry matching data inside @info from @rnh. * Returns unlinked, locked and referenced @rtentry on success, * Returns NULL and sets @perror to: @@ -389,7 +295,7 @@ rt_unlinkrte(struct rib_head *rnh, struct rt_addrinfo int del_route(struct rib_head *rnh, struct rt_addrinfo *info, - struct rib_cmd_info *rc) + struct rtentry **ret_nrt) { struct sockaddr *dst, *netmask; struct sockaddr_storage mdst; @@ -408,13 +314,6 @@ del_route(struct rib_head *rnh, struct rt_addrinfo *in RIB_WLOCK(rnh); rt = rt_unlinkrte(rnh, info, &error); - if (rt != NULL) { - /* Finalize notification */ - rnh->rnh_gen++; - rc->rc_rt = rt; - rc->rc_nh_old = rt->rt_nhop; - rib_notify(rnh, RIB_NOTIFY_IMMEDIATE, rc); - } RIB_WUNLOCK(rnh); if (error != 0) return (error); @@ -425,32 +324,17 @@ del_route(struct rib_head *rnh, struct rt_addrinfo *in * If the caller wants it, then it can have it, * the entry will be deleted after the end of the current epoch. */ + if (ret_nrt) + *ret_nrt = rt; + rtfree(rt); return (0); } -int -rib_change_route(uint32_t fibnum, struct rt_addrinfo *info, - struct rib_cmd_info *rc) -{ - struct rib_head *rnh; - - NET_EPOCH_ASSERT(); - - rnh = get_rnh(fibnum, info); - if (rnh == NULL) - return (EAFNOSUPPORT); - - bzero(rc, sizeof(struct rib_cmd_info)); - rc->rc_cmd = RTM_CHANGE; - - return (change_route(rnh, info, rc)); -} - static int change_route_one(struct rib_head *rnh, struct rt_addrinfo *info, - struct rib_cmd_info *rc) + struct rtentry **ret_nrt) { RIB_RLOCK_TRACKER; struct rtentry *rt = NULL; @@ -550,18 +434,14 @@ change_route_one(struct rib_head *rnh, struct rt_addri if ((nh_orig->nh_ifa != nh->nh_ifa) && nh_orig->nh_ifa->ifa_rtrequest) nh_orig->nh_ifa->ifa_rtrequest(RTM_DELETE, rt, nh_orig, info); - /* Finalize notification */ - rc->rc_rt = rt; - rc->rc_nh_old = nh_orig; - rc->rc_nh_new = rt->rt_nhop; + if (ret_nrt != NULL) + *ret_nrt = rt; RT_UNLOCK(rt); /* Update generation id to reflect rtable change */ rnh->rnh_gen++; - rib_notify(rnh, RIB_NOTIFY_IMMEDIATE, rc); - RIB_WUNLOCK(rnh); nhop_free(nh_orig); @@ -571,7 +451,7 @@ change_route_one(struct rib_head *rnh, struct rt_addri int change_route(struct rib_head *rnh, struct rt_addrinfo *info, - struct rib_cmd_info *rc) + struct rtentry **ret_nrt) { int error; @@ -588,7 +468,7 @@ change_route(struct rib_head *rnh, struct rt_addrinfo * multiple times before failing. */ for (int i = 0; i < RIB_MAX_RETRIES; i++) { - error = change_route_one(rnh, info, rc); + error = change_route_one(rnh, info, ret_nrt); if (error != EAGAIN) break; } @@ -701,62 +581,4 @@ rib_walk_del(u_int fibnum, int family, rt_filter_f_t * } } -static void -rib_notify(struct rib_head *rnh, enum rib_subscription_type type, - struct rib_cmd_info *rc) -{ - struct rib_subscription *rs; - - CK_STAILQ_FOREACH(rs, &rnh->rnh_subscribers, next) { - if (rs->type == type) - rs->func(rnh, rc, rs->arg); - } -} - -struct rib_subscription * -rib_subscribe(uint32_t fibnum, int family, rib_subscription_cb_t *f, void *arg, - enum rib_subscription_type type, int waitok) -{ - struct rib_head *rnh; - struct rib_subscription *rs; - int flags = M_ZERO | (waitok ? M_WAITOK : 0); - - NET_EPOCH_ASSERT(); - KASSERT((fibnum < rt_numfibs), ("%s: bad fibnum", __func__)); - rnh = rt_tables_get_rnh(fibnum, family); - - rs = malloc(sizeof(struct rib_subscription), M_RTABLE, flags); - if (rs == NULL) - return (NULL); - - rs->func = f; - rs->arg = arg; - rs->type = type; - - RIB_WLOCK(rnh); - CK_STAILQ_INSERT_TAIL(&rnh->rnh_subscribers, rs, next); - RIB_WUNLOCK(rnh); - - return (rs); -} - -int -rib_unsibscribe(uint32_t fibnum, int family, struct rib_subscription *rs) -{ - struct rib_head *rnh; - - NET_EPOCH_ASSERT(); - KASSERT((fibnum < rt_numfibs), ("%s: bad fibnum", __func__)); - rnh = rt_tables_get_rnh(fibnum, family); - - if (rnh == NULL) - return (ENOENT); - - RIB_WLOCK(rnh); - CK_STAILQ_REMOVE(&rnh->rnh_subscribers, rs, rib_subscription, next); - RIB_WUNLOCK(rnh); - - free(rs, M_RTABLE); - return (0); -} Modified: head/sys/net/route/route_ddb.c ============================================================================== --- head/sys/net/route/route_ddb.c Mon Jun 1 20:32:02 2020 (r361704) +++ head/sys/net/route/route_ddb.c Mon Jun 1 20:40:40 2020 (r361705) @@ -50,7 +50,6 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include #include /* Modified: head/sys/net/route/route_helpers.c ============================================================================== --- head/sys/net/route/route_helpers.c Mon Jun 1 20:32:02 2020 (r361704) +++ head/sys/net/route/route_helpers.c Mon Jun 1 20:40:40 2020 (r361705) @@ -50,7 +50,6 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include #include #include #include Modified: head/sys/net/route/route_temporal.c ============================================================================== --- head/sys/net/route/route_temporal.c Mon Jun 1 20:32:02 2020 (r361704) +++ head/sys/net/route/route_temporal.c Mon Jun 1 20:40:40 2020 (r361705) @@ -38,13 +38,11 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include #include #include #include #include -#include #include #include Modified: head/sys/net/route/route_var.h ============================================================================== --- head/sys/net/route/route_var.h Mon Jun 1 20:32:02 2020 (r361704) +++ head/sys/net/route/route_var.h Mon Jun 1 20:40:40 2020 (r361705) @@ -35,7 +35,6 @@ #ifndef RNF_NORMAL #include #endif -#include #include #include /* struct sockaddr_in */ #include @@ -64,7 +63,6 @@ struct rib_head { struct callout expire_callout; /* Callout for expiring dynamic routes */ time_t next_expire; /* Next expire run ts */ struct nh_control *nh_control; /* nexthop subsystem data */ - CK_STAILQ_HEAD(, rib_subscription) rnh_subscribers;/* notification subscribers */ }; #define RIB_RLOCK_TRACKER struct rm_priotracker _rib_tracker @@ -112,13 +110,12 @@ void rt_setmetrics(const struct rt_addrinfo *info, str struct radix_node *rt_mpath_unlink(struct rib_head *rnh, struct rt_addrinfo *info, struct rtentry *rto, int *perror); #endif -struct rib_cmd_info; int add_route(struct rib_head *rnh, struct rt_addrinfo *info, - struct rib_cmd_info *rc); + struct rtentry **ret_nrt); int del_route(struct rib_head *rnh, struct rt_addrinfo *info, - struct rib_cmd_info *rc); + struct rtentry **ret_nrt); int change_route(struct rib_head *, struct rt_addrinfo *, - struct rib_cmd_info *rc); + struct rtentry **); VNET_PCPUSTAT_DECLARE(struct rtstat, rtstat); #define RTSTAT_ADD(name, val) \ Modified: head/sys/netinet/in_rmx.c ============================================================================== --- head/sys/netinet/in_rmx.c Mon Jun 1 20:32:02 2020 (r361704) +++ head/sys/netinet/in_rmx.c Mon Jun 1 20:40:40 2020 (r361705) @@ -42,7 +42,6 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include #include #include #include Modified: head/sys/netinet/ip_icmp.c ============================================================================== --- head/sys/netinet/ip_icmp.c Mon Jun 1 20:32:02 2020 (r361704) +++ head/sys/netinet/ip_icmp.c Mon Jun 1 20:40:40 2020 (r361705) @@ -52,7 +52,6 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include #include #include Modified: head/sys/netinet6/icmp6.c ============================================================================== --- head/sys/netinet6/icmp6.c Mon Jun 1 20:32:02 2020 (r361704) +++ head/sys/netinet6/icmp6.c Mon Jun 1 20:40:40 2020 (r361705) @@ -93,7 +93,6 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include #include #include Modified: head/sys/netinet6/in6_rmx.c ============================================================================== --- head/sys/netinet6/in6_rmx.c Mon Jun 1 20:32:02 2020 (r361704) +++ head/sys/netinet6/in6_rmx.c Mon Jun 1 20:40:40 2020 (r361705) @@ -81,7 +81,6 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include #include #include #include Modified: head/sys/netinet6/nd6_rtr.c ============================================================================== --- head/sys/netinet6/nd6_rtr.c Mon Jun 1 20:32:02 2020 (r361704) +++ head/sys/netinet6/nd6_rtr.c Mon Jun 1 20:40:40 2020 (r361705) @@ -60,7 +60,6 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include #include #include #include