svn commit: r368769 - head/sys/net

2020-12-18 Thread Alexander V. Chernikov
Author: melifaro
Date: Fri Dec 18 22:00:57 2020
New Revision: 368769
URL: https://svnweb.freebsd.org/changeset/base/368769

Log:
  Switch direct rt fields access in rtsock.c to newly-create field acessors.
  
  rtsock code was build around the assumption that each rtentry record
   in the system radix tree is a ready-to-use sockaddr. This assumptions
   turned out to be not quite true:
  * masks have their length tweaked, so we have rtsock_fix_netmask() hack
  * IPv6 addresses have their scope embedded, so we have another explicit
   deembedding hack.
  
  Change the code to decouple rtentry internals from rtsock code using
   newly-created rtentry accessors. This will allow to eventually eliminate
   both of the hacks and change rtentry dst/mask format.
  
  Differential Revision:https://reviews.freebsd.org/D27451

Modified:
  head/sys/net/rtsock.c

Modified: head/sys/net/rtsock.c
==
--- head/sys/net/rtsock.c   Fri Dec 18 20:41:23 2020(r368768)
+++ head/sys/net/rtsock.c   Fri Dec 18 22:00:57 2020(r368769)
@@ -158,10 +158,13 @@ MTX_SYSINIT(rtsock, _mtx, "rtsock route_cb lock
 SYSCTL_NODE(_net, OID_AUTO, route, CTLFLAG_RD | CTLFLAG_MPSAFE, 0, "");
 
 struct walkarg {
+   int family;
int w_tmemsize;
int w_op, w_arg;
caddr_t w_tmem;
struct sysctl_req *w_req;
+   struct sockaddr *dst;
+   struct sockaddr *mask;
 };
 
 static voidrts_input(struct mbuf *m);
@@ -170,7 +173,7 @@ static int  rtsock_msg_buffer(int type, struct rt_addri
struct walkarg *w, int *plen);
 static int rt_xaddrs(caddr_t cp, caddr_t cplim,
struct rt_addrinfo *rtinfo);
-static int sysctl_dumpentry(struct radix_node *rn, void *vw);
+static int sysctl_dumpentry(struct rtentry *rt, void *vw);
 static int sysctl_dumpnhop(struct rtentry *rt, struct nhop_object *nh,
uint32_t weight, struct walkarg *w);
 static int sysctl_iflist(int af, struct walkarg *w);
@@ -187,7 +190,8 @@ static int  update_rtm_from_rc(struct rt_addrinfo *info
 static voidsend_rtm_reply(struct socket *so, struct rt_msghdr *rtm,
struct mbuf *m, sa_family_t saf, u_int fibnum,
int rtm_errno);
-static int can_export_rte(struct ucred *td_ucred, const struct rtentry 
*rt);
+static boolcan_export_rte(struct ucred *td_ucred, bool rt_is_host,
+   const struct sockaddr *rt_dst);
 
 static struct netisr_handler rtsock_nh = {
.nh_name = "rtsock",
@@ -707,7 +711,7 @@ handle_rtm_get(struct rt_addrinfo *info, u_int fibnum,
return (ESRCH);
}
 
-   nh = select_nhop(rc->rc_rt->rt_nhop, info->rti_info[RTAX_GATEWAY]);
+   nh = select_nhop(rt_get_raw_nhop(rc->rc_rt), 
info->rti_info[RTAX_GATEWAY]);
if (nh == NULL) {
RIB_RUNLOCK(rnh);
return (ESRCH);
@@ -721,9 +725,7 @@ handle_rtm_get(struct rt_addrinfo *info, u_int fibnum,
 */
if (rtm->rtm_flags & RTF_ANNOUNCE) {
struct sockaddr laddr;
-   struct nhop_object *nh;
 
-   nh = rc->rc_rt->rt_nhop;
if (nh->nh_ifp != NULL &&
nh->nh_ifp->if_type == IFT_PROPVIRTUAL) {
struct ifaddr *ifa;
@@ -747,7 +749,7 @@ handle_rtm_get(struct rt_addrinfo *info, u_int fibnum,
RIB_RUNLOCK(rnh);
return (ESRCH);
}
-   nh = select_nhop(rc->rc_rt->rt_nhop, 
info->rti_info[RTAX_GATEWAY]);
+   nh = select_nhop(rt_get_raw_nhop(rc->rc_rt), 
info->rti_info[RTAX_GATEWAY]);
if (nh == NULL) {
RIB_RUNLOCK(rnh);
return (ESRCH);
@@ -760,6 +762,66 @@ handle_rtm_get(struct rt_addrinfo *info, u_int fibnum,
return (0);
 }
 
+static void
+init_sockaddrs_family(int family, struct sockaddr *dst, struct sockaddr *mask)
+{
+#ifdef INET
+   if (family == AF_INET) {
+   struct sockaddr_in *dst4 = (struct sockaddr_in *)dst;
+   struct sockaddr_in *mask4 = (struct sockaddr_in *)mask;
+
+   bzero(dst4, sizeof(struct sockaddr_in));
+   bzero(mask4, sizeof(struct sockaddr_in));
+
+   dst4->sin_family = AF_INET;
+   dst4->sin_len = sizeof(struct sockaddr_in);
+   mask4->sin_family = AF_INET;
+   mask4->sin_len = sizeof(struct sockaddr_in);
+   }
+#endif
+#ifdef INET6
+   if (family == AF_INET6) {
+   struct sockaddr_in6 *dst6 = (struct sockaddr_in6 *)dst;
+   struct sockaddr_in6 *mask6 = (struct sockaddr_in6 *)mask;
+
+   bzero(dst6, sizeof(struct sockaddr_in6));
+   bzero(mask6, sizeof(struct sockaddr_in6));
+
+   dst6->sin6_family = AF_INET6;
+   

svn commit: r368651 - head/sys/netpfil/ipfw

2020-12-14 Thread Alexander V. Chernikov
Author: melifaro
Date: Mon Dec 14 22:54:32 2020
New Revision: 368651
URL: https://svnweb.freebsd.org/changeset/base/368651

Log:
  Fix LINT-NOINET6 build after r368571.
  
  Reported by:  mjg

Modified:
  head/sys/netpfil/ipfw/ip_fw_table_algo.c

Modified: head/sys/netpfil/ipfw/ip_fw_table_algo.c
==
--- head/sys/netpfil/ipfw/ip_fw_table_algo.cMon Dec 14 22:53:19 2020
(r368650)
+++ head/sys/netpfil/ipfw/ip_fw_table_algo.cMon Dec 14 22:54:32 2020
(r368651)
@@ -3935,16 +3935,24 @@ static int
 ta_find_kfib_tentry(void *ta_state, struct table_info *ti,
 ipfw_obj_tentry *tent)
 {
-   struct rtentry *rt;
+   struct rtentry *rt = NULL;
struct route_nhop_data rnd;
struct epoch_tracker et;
int error;
 
NET_EPOCH_ENTER(et);
-   if (tent->subtype == AF_INET) {
+
+   switch (tent->subtype) {
+#ifdef INET
+   case AF_INET:
rt = fib4_lookup_rt(ti->data, tent->k.addr, 0, 0, );
-   } else {
+   break;
+#endif
+#ifdef INET6
+   case AF_INET6:
rt = fib6_lookup_rt(ti->data, >k.addr6, 0, 0, );
+   break;
+#endif
}
if (rt != NULL)
error = ta_dump_kfib_tentry_int(tent->subtype, rt, tent);
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r368648 - in head/sys: amd64/conf arm64/conf i386/conf powerpc/conf riscv/conf

2020-12-14 Thread Alexander V. Chernikov
Author: melifaro
Date: Mon Dec 14 22:23:08 2020
New Revision: 368648
URL: https://svnweb.freebsd.org/changeset/base/368648

Log:
  Enable ROUTE_MPATH support in GENERIC kernels.
  
  Ability to load-balance traffic over multiple path is a must-have thing for 
routers.
  It may be used by the servers to balance outgoing traffic over multiple 
default gateways.
  
  The previous implementation, RADIX_MPATH stayed in the shadow for too long.
  It was not well maintained, which lead us to a vicious circle - people were 
using
   non-contiguous mask or firewalls to achieve similar goals. As a result, some 
routing
   daemons implementation still don't have multipath support enabled for 
FreeBSD.
  
  Turning on ROUTE_MPATH by default would fix it. It will allow to reduce 
networking
   feature gap to other operating systems. Linux and OpenBSD enabled similar 
support
   at least 5 years ago.
  
  ROUTE_MPATH does not consume memory unless actually used. It enables around 
~1k LOC.
  
  It does not bring any behaviour changes for userland.
  Additionally, feature is (temporarily) turned off by the net.route.multipath 
sysctl
   defaulting to 0.
  
  Differential Revision:https://reviews.freebsd.org/D27428

Modified:
  head/sys/amd64/conf/GENERIC
  head/sys/arm64/conf/GENERIC
  head/sys/i386/conf/GENERIC
  head/sys/powerpc/conf/GENERIC64
  head/sys/riscv/conf/GENERIC

Modified: head/sys/amd64/conf/GENERIC
==
--- head/sys/amd64/conf/GENERIC Mon Dec 14 22:13:58 2020(r368647)
+++ head/sys/amd64/conf/GENERIC Mon Dec 14 22:23:08 2020(r368648)
@@ -31,6 +31,7 @@ options   VIMAGE  # Subsystem 
virtualization, e.g. VNE
 optionsINET# InterNETworking
 optionsINET6   # IPv6 communications protocols
 optionsIPSEC_SUPPORT   # Allow kldload of ipsec and tcpmd5
+optionsROUTE_MPATH # Multipath routing support
 optionsTCP_OFFLOAD # TCP offload
 optionsTCP_BLACKBOX# Enhanced TCP event logging
 optionsTCP_HHOOK   # hhook(9) framework for TCP

Modified: head/sys/arm64/conf/GENERIC
==
--- head/sys/arm64/conf/GENERIC Mon Dec 14 22:13:58 2020(r368647)
+++ head/sys/arm64/conf/GENERIC Mon Dec 14 22:23:08 2020(r368648)
@@ -30,6 +30,7 @@ options   PREEMPTION  # Enable kernel thread 
preemption
 optionsVIMAGE  # Subsystem virtualization, e.g. VNET
 optionsINET# InterNETworking
 optionsINET6   # IPv6 communications protocols
+optionsROUTE_MPATH # Multipath routing support
 optionsIPSEC_SUPPORT   # Allow kldload of ipsec and tcpmd5
 optionsTCP_HHOOK   # hhook(9) framework for TCP
 optionsTCP_OFFLOAD # TCP offload

Modified: head/sys/i386/conf/GENERIC
==
--- head/sys/i386/conf/GENERIC  Mon Dec 14 22:13:58 2020(r368647)
+++ head/sys/i386/conf/GENERIC  Mon Dec 14 22:23:08 2020(r368648)
@@ -32,6 +32,7 @@ options   VIMAGE  # Subsystem 
virtualization, e.g. VNE
 optionsINET# InterNETworking
 optionsINET6   # IPv6 communications protocols
 optionsIPSEC_SUPPORT   # Allow kldload of ipsec and tcpmd5
+optionsROUTE_MPATH # Multipath routing support
 optionsTCP_HHOOK   # hhook(9) framework for TCP
 optionsTCP_OFFLOAD # TCP offload
 optionsSCTP_SUPPORT# Allow kldload of SCTP

Modified: head/sys/powerpc/conf/GENERIC64
==
--- head/sys/powerpc/conf/GENERIC64 Mon Dec 14 22:13:58 2020
(r368647)
+++ head/sys/powerpc/conf/GENERIC64 Mon Dec 14 22:23:08 2020
(r368648)
@@ -42,6 +42,7 @@ options   VIMAGE  # Subsystem 
virtualization, e.g. VNE
 optionsINET#InterNETworking
 optionsINET6   #IPv6 communications protocols
 optionsIPSEC_SUPPORT   # Allow kldload of ipsec and tcpmd5
+optionsROUTE_MPATH # Multipath routing support
 optionsTCP_OFFLOAD # TCP offload
 optionsTCP_BLACKBOX# Enhanced TCP event logging
 optionsTCP_HHOOK   # hhook(9) framework for TCP

Modified: head/sys/riscv/conf/GENERIC
==
--- head/sys/riscv/conf/GENERIC Mon Dec 14 22:13:58 2020(r368647)
+++ head/sys/riscv/conf/GENERIC Mon Dec 14 22:23:08 2020

svn commit: r368572 - head/sys/netpfil/ipfw

2020-12-11 Thread Alexander V. Chernikov
Author: melifaro
Date: Sat Dec 12 01:05:31 2020
New Revision: 368572
URL: https://svnweb.freebsd.org/changeset/base/368572

Log:
  Fix NOINET6 build broken by r368571.

Modified:
  head/sys/netpfil/ipfw/ip_fw_table_algo.c

Modified: head/sys/netpfil/ipfw/ip_fw_table_algo.c
==
--- head/sys/netpfil/ipfw/ip_fw_table_algo.cFri Dec 11 23:57:30 2020
(r368571)
+++ head/sys/netpfil/ipfw/ip_fw_table_algo.cSat Dec 12 01:05:31 2020
(r368572)
@@ -3920,7 +3920,7 @@ ta_dump_kfib_tentry_int(int family, const struct rtent
tent->v.kidx = 0;
}
 #endif
-#ifdef INET
+#ifdef INET6
if (family == AF_INET6) {
rt_get_inet6_prefix_plen(rt, >k.addr6, , );
tent->masklen = plen;
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r368571 - head/sys/netpfil/ipfw

2020-12-11 Thread Alexander V. Chernikov
Author: melifaro
Date: Fri Dec 11 23:57:30 2020
New Revision: 368571
URL: https://svnweb.freebsd.org/changeset/base/368571

Log:
  ipfw kfib algo: Use rt accessors instead of accessing rib/rtentry directly.
  
  This removes assumptions on prefix storage and rtentry layout
   from an external code.
  
  Differential Revision:https://reviews.freebsd.org/D27450

Modified:
  head/sys/netpfil/ipfw/ip_fw_table_algo.c

Modified: head/sys/netpfil/ipfw/ip_fw_table_algo.c
==
--- head/sys/netpfil/ipfw/ip_fw_table_algo.cFri Dec 11 22:52:20 2020
(r368570)
+++ head/sys/netpfil/ipfw/ip_fw_table_algo.cFri Dec 11 23:57:30 2020
(r368571)
@@ -52,7 +52,7 @@ __FBSDID("$FreeBSD$");
 #include 
 #include 
 #include 
-#include 
+#include 
 
 #include 
 #include 
@@ -3781,11 +3781,10 @@ static int ta_init_kfib(struct ip_fw_chain *ch, void *
 static void ta_destroy_kfib(void *ta_state, struct table_info *ti);
 static void ta_dump_kfib_tinfo(void *ta_state, struct table_info *ti,
 ipfw_ta_tinfo *tinfo);
-static int contigmask(uint8_t *p, int len);
 static int ta_dump_kfib_tentry(void *ta_state, struct table_info *ti, void *e,
 ipfw_obj_tentry *tent);
-static int ta_dump_kfib_tentry_int(struct sockaddr *paddr,
-struct sockaddr *pmask, ipfw_obj_tentry *tent);
+static int ta_dump_kfib_tentry_int(int familt, const struct rtentry *rt,
+ipfw_obj_tentry *tent);
 static int ta_find_kfib_tentry(void *ta_state, struct table_info *ti,
 ipfw_obj_tentry *tent);
 static void ta_foreach_kfib(void *ta_state, struct table_info *ti,
@@ -3900,84 +3899,35 @@ ta_dump_kfib_tinfo(void *ta_state, struct table_info *
tinfo->flags = IPFW_TATFLAGS_AFDATA;
tinfo->taclass4 = IPFW_TACLASS_RADIX;
tinfo->count4 = 0;
-   tinfo->itemsize4 = sizeof(struct rtentry);
+   tinfo->itemsize4 = 128; /* table is readonly, value does not matter */
tinfo->taclass6 = IPFW_TACLASS_RADIX;
tinfo->count6 = 0;
-   tinfo->itemsize6 = sizeof(struct rtentry);
+   tinfo->itemsize6 = 128;
 }
 
 static int
-contigmask(uint8_t *p, int len)
-{
-   int i, n;
-
-   for (i = 0; i < len ; i++)
-   if ( (p[i/8] & (1 << (7 - (i%8 == 0) /* first bit unset */
-   break;
-   for (n= i + 1; n < len; n++)
-   if ( (p[n/8] & (1 << (7 - (n % 8 != 0)
-   return (-1); /* mask not contiguous */
-   return (i);
-}
-
-static int
-ta_dump_kfib_tentry(void *ta_state, struct table_info *ti, void *e,
+ta_dump_kfib_tentry_int(int family, const struct rtentry *rt,
 ipfw_obj_tentry *tent)
 {
-   struct rtentry *rte;
+   uint32_t scopeid;
+   int plen;
 
-   rte = (struct rtentry *)e;
-
-   return ta_dump_kfib_tentry_int(rt_key(rte), rt_mask(rte), tent);
-}
-
-static int
-ta_dump_kfib_tentry_int(struct sockaddr *paddr, struct sockaddr *pmask,
-ipfw_obj_tentry *tent)
-{
 #ifdef INET
-   struct sockaddr_in *addr, *mask;
-#endif
-#ifdef INET6
-   struct sockaddr_in6 *addr6, *mask6;
-#endif
-   int len;
-
-   len = 0;
-
-   /* Guess IPv4/IPv6 radix by sockaddr family */
-#ifdef INET
-   if (paddr->sa_family == AF_INET) {
-   addr = (struct sockaddr_in *)paddr;
-   mask = (struct sockaddr_in *)pmask;
-   tent->k.addr.s_addr = addr->sin_addr.s_addr;
-   len = 32;
-   if (mask != NULL)
-   len = contigmask((uint8_t *)>sin_addr, 32);
-   if (len == -1)
-   len = 0;
-   tent->masklen = len;
+   if (family == AF_INET) {
+   rt_get_inet_prefix_plen(rt, >k.addr, , );
+   tent->masklen = plen;
tent->subtype = AF_INET;
-   tent->v.kidx = 0; /* Do we need to put GW here? */
+   tent->v.kidx = 0;
}
 #endif
-#ifdef INET6
-   if (paddr->sa_family == AF_INET6) {
-   addr6 = (struct sockaddr_in6 *)paddr;
-   mask6 = (struct sockaddr_in6 *)pmask;
-   memcpy(>k.addr6, >sin6_addr,
-   sizeof(struct in6_addr));
-   len = 128;
-   if (mask6 != NULL)
-   len = contigmask((uint8_t *)>sin6_addr, 128);
-   if (len == -1)
-   len = 0;
-   tent->masklen = len;
+#ifdef INET
+   if (family == AF_INET6) {
+   rt_get_inet6_prefix_plen(rt, >k.addr6, , );
+   tent->masklen = plen;
tent->subtype = AF_INET6;
tent->v.kidx = 0;
}
 #endif
-
return (0);
 }
 
@@ -3985,66 +3935,61 @@ static int
 ta_find_kfib_tentry(void *ta_state, struct table_info *ti,
 ipfw_obj_tentry *tent)
 {
-   struct rt_addrinfo info;
-   struct sockaddr_in6 key6, dst6, mask6;
-   struct sockaddr *dst, *key, *mask;
+   struct rtentry 

svn commit: r368317 - head/sys/net/route

2020-12-03 Thread Alexander V. Chernikov
Author: melifaro
Date: Thu Dec  3 22:23:57 2020
New Revision: 368317
URL: https://svnweb.freebsd.org/changeset/base/368317

Log:
  Add IPv4/IPv6 rtentry prefix accessors.
  
  Multiple consumers like ipfw, netflow or new route lookup algorithms
   need to get the prefix data out of struct rtentry.
  Instead of providing direct access to the rtentry, create IPv4/IPv6
   accessors to abstract struct rtentry internals and avoid including
   internal routing headers for external consumers.
  
  While here, move struct route_nhop_data to the public header, so external
   customers can actually use lookup functions returning rt data.
  
  Differential Revision:https://reviews.freebsd.org/D27416

Modified:
  head/sys/net/route/route_ctl.c
  head/sys/net/route/route_ctl.h
  head/sys/net/route/route_var.h

Modified: head/sys/net/route/route_ctl.c
==
--- head/sys/net/route/route_ctl.c  Thu Dec  3 22:06:08 2020
(r368316)
+++ head/sys/net/route/route_ctl.c  Thu Dec  3 22:23:57 2020
(r368317)
@@ -53,6 +53,7 @@ __FBSDID("$FreeBSD$");
 #include 
 #include 
 #include 
+#include 
 
 #include 
 
@@ -235,6 +236,132 @@ get_info_weight(const struct rt_addrinfo *info, uint32
 
return (weight);
 }
+
+bool
+rt_is_host(const struct rtentry *rt)
+{
+
+   return (rt->rte_flags & RTF_HOST);
+}
+
+/*
+ * Returns pointer to nexthop or nexthop group
+ * associated with @rt
+ */
+struct nhop_object *
+rt_get_raw_nhop(const struct rtentry *rt)
+{
+
+   return (rt->rt_nhop);
+}
+
+#ifdef INET
+/*
+ * Stores IPv4 address and prefix length of @rt inside
+ *  @paddr and @plen.
+ * @pscopeid is currently always set to 0.
+ */
+void
+rt_get_inet_prefix_plen(const struct rtentry *rt, struct in_addr *paddr,
+int *plen, uint32_t *pscopeid)
+{
+   const struct sockaddr_in *dst;
+
+   dst = (const struct sockaddr_in *)rt_key_const(rt);
+   KASSERT((dst->sin_family == AF_INET),
+   ("rt family is %d, not inet", dst->sin_family));
+   *paddr = dst->sin_addr;
+   dst = (const struct sockaddr_in *)rt_mask_const(rt);
+   if (dst == NULL)
+   *plen = 32;
+   else
+   *plen = bitcount32(dst->sin_addr.s_addr);
+   *pscopeid = 0;
+}
+
+/*
+ * Stores IPv4 address and prefix mask of @rt inside
+ *  @paddr and @pmask. Sets mask to INADDR_ANY for host routes.
+ * @pscopeid is currently always set to 0.
+ */
+void
+rt_get_inet_prefix_pmask(const struct rtentry *rt, struct in_addr *paddr,
+struct in_addr *pmask, uint32_t *pscopeid)
+{
+   const struct sockaddr_in *dst;
+
+   dst = (const struct sockaddr_in *)rt_key_const(rt);
+   KASSERT((dst->sin_family == AF_INET),
+   ("rt family is %d, not inet", dst->sin_family));
+   *paddr = dst->sin_addr;
+   dst = (const struct sockaddr_in *)rt_mask_const(rt);
+   if (dst == NULL)
+   pmask->s_addr = INADDR_BROADCAST;
+   else
+   *pmask = dst->sin_addr;
+   *pscopeid = 0;
+}
+#endif
+
+#ifdef INET6
+static int
+inet6_get_plen(const struct in6_addr *addr)
+{
+
+   return (bitcount32(addr->s6_addr32[0]) + bitcount32(addr->s6_addr32[1]) 
+
+   bitcount32(addr->s6_addr32[2]) + bitcount32(addr->s6_addr32[3]));
+}
+
+/*
+ * Stores IPv6 address and prefix length of @rt inside
+ *  @paddr and @plen. Addresses are returned in de-embedded form.
+ * Scopeid is set to 0 for non-LL addresses.
+ */
+void
+rt_get_inet6_prefix_plen(const struct rtentry *rt, struct in6_addr *paddr,
+int *plen, uint32_t *pscopeid)
+{
+   const struct sockaddr_in6 *dst;
+
+   dst = (const struct sockaddr_in6 *)rt_key_const(rt);
+   KASSERT((dst->sin6_family == AF_INET6),
+   ("rt family is %d, not inet6", dst->sin6_family));
+   if (IN6_IS_SCOPE_LINKLOCAL(>sin6_addr))
+   in6_splitscope(>sin6_addr, paddr, pscopeid);
+   else
+   *paddr = dst->sin6_addr;
+   dst = (const struct sockaddr_in6 *)rt_mask_const(rt);
+   if (dst == NULL)
+   *plen = 128;
+   else
+   *plen = inet6_get_plen(>sin6_addr);
+}
+
+/*
+ * Stores IPv6 address and prefix mask of @rt inside
+ *  @paddr and @pmask. Addresses are returned in de-embedded form.
+ * Scopeid is set to 0 for non-LL addresses.
+ */
+void
+rt_get_inet6_prefix_pmask(const struct rtentry *rt, struct in6_addr *paddr,
+struct in6_addr *pmask, uint32_t *pscopeid)
+{
+   const struct sockaddr_in6 *dst;
+
+   dst = (const struct sockaddr_in6 *)rt_key_const(rt);
+   KASSERT((dst->sin6_family == AF_INET6),
+   ("rt family is %d, not inet", dst->sin6_family));
+   if (IN6_IS_SCOPE_LINKLOCAL(>sin6_addr))
+   in6_splitscope(>sin6_addr, paddr, pscopeid);
+   else
+   *paddr = dst->sin6_addr;
+   dst = (const struct sockaddr_in6 *)rt_mask_const(rt);
+   if (dst == NULL)
+   memset(pmask, 0xFF, 

svn commit: r368199 - head/sys/kern

2020-11-30 Thread Alexander V. Chernikov
Author: melifaro
Date: Mon Nov 30 21:59:52 2020
New Revision: 368199
URL: https://svnweb.freebsd.org/changeset/base/368199

Log:
  Move inner loop logic out of sysctl_sysctl_next_ls().
  
  Refactor sysctl_sysctl_next_ls():
  * Move huge inner loop out of sysctl_sysctl_next_ls() into a separate
   non-recursive function, returning the next step to be taken.
  * Update resulting node oid parts only on successful lookup
  * Make sysctl_sysctl_next_ls() return boolean success/failure instead of 
errno,
   slightly simplifying logic
  
  Reviewed by:  freqlabs
  Differential Revision:https://reviews.freebsd.org/D27029

Modified:
  head/sys/kern/kern_sysctl.c

Modified: head/sys/kern/kern_sysctl.c
==
--- head/sys/kern/kern_sysctl.c Mon Nov 30 21:42:55 2020(r368198)
+++ head/sys/kern/kern_sysctl.c Mon Nov 30 21:59:52 2020(r368199)
@@ -1100,109 +1100,148 @@ sysctl_sysctl_name(SYSCTL_HANDLER_ARGS)
 static SYSCTL_NODE(_sysctl, CTL_SYSCTL_NAME, name, CTLFLAG_RD |
 CTLFLAG_MPSAFE | CTLFLAG_CAPRD, sysctl_sysctl_name, "");
 
+enum sysctl_iter_action {
+   ITER_SIBLINGS,  /* Not matched, continue iterating siblings */
+   ITER_CHILDREN,  /* Node has children we need to iterate over them */
+   ITER_FOUND, /* Matching node was found */
+};
+
 /*
- * Walk the sysctl subtree at lsp until we find the given name,
- * and return the next name in order by oid_number.
+ * Tries to find the next node for @name and @namelen.
+ *
+ * Returns next action to take. 
  */
-static int
-sysctl_sysctl_next_ls(struct sysctl_oid_list *lsp, int *name, u_int namelen, 
-int *next, int *len, int level, bool honor_skip)
+static enum sysctl_iter_action
+sysctl_sysctl_next_node(struct sysctl_oid *oidp, int *name, unsigned int 
namelen,
+bool honor_skip)
 {
-   struct sysctl_oid *oidp;
 
-   SYSCTL_ASSERT_LOCKED();
-   *len = level;
-   SLIST_FOREACH(oidp, lsp, oid_link) {
-   *next = oidp->oid_number;
+   if ((oidp->oid_kind & CTLFLAG_DORMANT) != 0)
+   return (ITER_SIBLINGS);
 
-   if ((oidp->oid_kind & CTLFLAG_DORMANT) != 0)
-   continue;
+   if (honor_skip && (oidp->oid_kind & CTLFLAG_SKIP) != 0)
+   return (ITER_SIBLINGS);
 
-   if (honor_skip && (oidp->oid_kind & CTLFLAG_SKIP) != 0)
-   continue;
+   if (namelen == 0) {
+   /*
+* We have reached a node with a full name match and are
+* looking for the next oid in its children.
+*
+* For CTL_SYSCTL_NEXTNOSKIP we are done.
+*
+* For CTL_SYSCTL_NEXT we skip CTLTYPE_NODE (unless it
+* has a handler) and move on to the children.
+*/
+   if (!honor_skip)
+   return (ITER_FOUND);
+   if ((oidp->oid_kind & CTLTYPE) != CTLTYPE_NODE) 
+   return (ITER_FOUND);
+   /* If node does not have an iterator, treat it as leaf */
+   if (oidp->oid_handler) 
+   return (ITER_FOUND);
 
-   if (namelen == 0) {
-   /*
-* We have reached a node with a full name match and are
-* looking for the next oid in its children.
-*
-* For CTL_SYSCTL_NEXTNOSKIP we are done.
-*
-* For CTL_SYSCTL_NEXT we skip CTLTYPE_NODE (unless it
-* has a handler) and move on to the children.
-*/
-   if (!honor_skip)
-   return (0);
-   if ((oidp->oid_kind & CTLTYPE) != CTLTYPE_NODE) 
-   return (0);
-   if (oidp->oid_handler) 
-   return (0);
-   lsp = SYSCTL_CHILDREN(oidp);
-   if (!sysctl_sysctl_next_ls(lsp, NULL, 0, next + 1, len,
-   level + 1, honor_skip))
-   return (0);
-   /*
-* There were no useable children in this node.
-* Continue searching for the next oid at this level.
-*/
-   goto emptynode;
-   }
+   /* Report oid as a node to iterate */
+   return (ITER_CHILDREN);
+   }
 
+   /*
+* No match yet. Continue seeking the given name.
+*
+* We are iterating in order by oid_number, so skip oids lower
+* than the one we are looking for.
+*
+* When the current oid_number is higher than the one we seek,
+* that means we have reached the next oid in the sequence and
+* 

svn commit: r368198 - head/sys/net

2020-11-30 Thread Alexander V. Chernikov
Author: melifaro
Date: Mon Nov 30 21:42:55 2020
New Revision: 368198
URL: https://svnweb.freebsd.org/changeset/base/368198

Log:
  Renumber NHR_* flags after NHR_IFAIF removal in r368127.
  
  Suggested by: rpokala

Modified:
  head/sys/net/route.h

Modified: head/sys/net/route.h
==
--- head/sys/net/route.hMon Nov 30 21:05:31 2020(r368197)
+++ head/sys/net/route.hMon Nov 30 21:42:55 2020(r368198)
@@ -223,10 +223,8 @@ VNET_DECLARE(u_int, fib_hash_outbound);
 
 /* Nexthop request flags */
 #defineNHR_NONE0x00/* empty flags field */
-#defineNHR_REF 0x02/* reference nexhop */
-
-/* uRPF */
-#defineNHR_NODEFAULT   0x04/* do not consider default 
route */
+#defineNHR_REF 0x01/* reference nexhop */
+#defineNHR_NODEFAULT   0x02/* uRPF: do not consider 
default route */
 
 /* Control plane route request flags */
 #defineNHR_COPY0x100   /* Copy rte data */
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r368164 - in head/sys: conf net net/route netinet netinet6

2020-11-29 Thread Alexander V. Chernikov
Author: melifaro
Date: Sun Nov 29 19:43:33 2020
New Revision: 368164
URL: https://svnweb.freebsd.org/changeset/base/368164

Log:
  Remove RADIX_MPATH config option.
  
  ROUTE_MPATH is the new config option controlling new multipath routing
   implementation. Remove the last pieces of RADIX_MPATH-related code and
   the config option.
  
  Reviewed by:  glebius
  Differential Revision:https://reviews.freebsd.org/D27244

Deleted:
  head/sys/net/radix_mpath.c
  head/sys/net/radix_mpath.h
Modified:
  head/sys/conf/options
  head/sys/net/route.c
  head/sys/net/route/route_ctl.c
  head/sys/net/route/route_ifaddrs.c
  head/sys/net/rtsock.c
  head/sys/netinet/ip_input.c
  head/sys/netinet6/nd6.c

Modified: head/sys/conf/options
==
--- head/sys/conf/options   Sun Nov 29 19:38:03 2020(r368163)
+++ head/sys/conf/options   Sun Nov 29 19:43:33 2020(r368164)
@@ -452,7 +452,6 @@ MROUTINGopt_mrouting.h
 NFSLOCKD
 PCBGROUP   opt_pcbgroup.h
 PF_DEFAULT_TO_DROP opt_pf.h
-RADIX_MPATHopt_mpath.h
 ROUTE_MPATHopt_route.h
 ROUTETABLESopt_route.h
 RSSopt_rss.h

Modified: head/sys/net/route.c
==
--- head/sys/net/route.cSun Nov 29 19:38:03 2020(r368163)
+++ head/sys/net/route.cSun Nov 29 19:43:33 2020(r368164)
@@ -65,10 +65,6 @@
 #include 
 #include 
 
-#ifdef RADIX_MPATH
-#include 
-#endif
-
 #include 
 #include 
 
@@ -674,87 +670,6 @@ rt_print(char *buf, int buflen, struct rtentry *rt)
}
 
return (i);
-}
-#endif
-
-#ifdef RADIX_MPATH
-/*
- * Deletes key for single-path routes, unlinks rtentry with
- * gateway specified in @info from multi-path routes.
- *
- * Returnes unlinked entry. In case of failure, returns NULL
- * and sets @perror to ESRCH.
- */
-struct radix_node *
-rt_mpath_unlink(struct rib_head *rnh, struct rt_addrinfo *info,
-struct rtentry *rto, int *perror)
-{
-   /*
-* if we got multipath routes, we require users to specify
-* a matching RTAX_GATEWAY.
-*/
-   struct rtentry *rt; // *rto = NULL;
-   struct radix_node *rn;
-   struct sockaddr *gw;
-
-   gw = info->rti_info[RTAX_GATEWAY];
-   rt = rt_mpath_matchgate(rto, gw);
-   if (rt == NULL) {
-   *perror = ESRCH;
-   return (NULL);
-   }
-
-   /*
-* this is the first entry in the chain
-*/
-   if (rto == rt) {
-   rn = rn_mpath_next((struct radix_node *)rt);
-   /*
-* there is another entry, now it's active
-*/
-   if (rn) {
-   rto = RNTORT(rn);
-   rto->rte_flags |= RTF_UP;
-   } else if (rt->rte_flags & RTF_GATEWAY) {
-   /*
-* For gateway routes, we need to 
-* make sure that we we are deleting
-* the correct gateway. 
-* rt_mpath_matchgate() does not 
-* check the case when there is only
-* one route in the chain.  
-*/
-   if (gw &&
-   (rt->rt_nhop->gw_sa.sa_len != gw->sa_len ||
-   memcmp(>rt_nhop->gw_sa, gw, gw->sa_len))) {
-   *perror = ESRCH;
-   return (NULL);
-   }
-   }
-
-   /*
-* use the normal delete code to remove
-* the first entry
-*/
-   rn = rnh->rnh_deladdr(info->rti_info[RTAX_DST],
-   info->rti_info[RTAX_NETMASK],
-   >head);
-   if (rn != NULL) {
-   *perror = 0;
-   } else {
-   *perror = ESRCH;
-   }
-   return (rn);
-   }
-   
-   /*
-* if the entry is 2nd and on up
-*/
-   if (rt_mpath_deldup(rto, rt) == 0)
-   panic ("rtrequest1: rt_mpath_deldup");
-   *perror = 0;
-   rn = (struct radix_node *)rt;
-   return (rn);
 }
 #endif
 

Modified: head/sys/net/route/route_ctl.c
==
--- head/sys/net/route/route_ctl.c  Sun Nov 29 19:38:03 2020
(r368163)
+++ head/sys/net/route/route_ctl.c  Sun Nov 29 19:43:33 2020
(r368164)
@@ -54,10 +54,6 @@ __FBSDID("$FreeBSD$");
 #include 
 #include 
 
-#ifdef RADIX_MPATH
-#include 
-#endif
-
 #include 
 
 /*

Modified: head/sys/net/route/route_ifaddrs.c
==
--- 

svn commit: r368150 - head/sys/net/route

2020-11-29 Thread Alexander V. Chernikov
Author: melifaro
Date: Sun Nov 29 13:54:49 2020
New Revision: 368150
URL: https://svnweb.freebsd.org/changeset/base/368150

Log:
  Introduce rib_walk_ext_internal() to allow iteration with rnh pointer.
  
  This solves the case when rib is not yet attached/detached to/from the
   system rib array.
  
  Differential Revision:https://reviews.freebsd.org/D27406

Modified:
  head/sys/net/route/route_ctl.h
  head/sys/net/route/route_helpers.c

Modified: head/sys/net/route/route_ctl.h
==
--- head/sys/net/route/route_ctl.h  Sun Nov 29 13:52:06 2020
(r368149)
+++ head/sys/net/route/route_ctl.h  Sun Nov 29 13:54:49 2020
(r368150)
@@ -67,17 +67,19 @@ enum rib_walk_hook {
 };
 typedef int rib_walktree_f_t(struct rtentry *, void *);
 typedef void rib_walk_hook_f_t(struct rib_head *rnh, enum rib_walk_hook stage,
-  void *arg);
+void *arg);
 void rib_walk(uint32_t fibnum, int af, bool wlock, rib_walktree_f_t *wa_f,
-  void *arg);
+void *arg);
 void rib_walk_ext(uint32_t fibnum, int af, bool wlock, rib_walktree_f_t *wa_f,
-  rib_walk_hook_f_t *hook_f, void *arg);
+rib_walk_hook_f_t *hook_f, void *arg);
+void rib_walk_ext_internal(struct rib_head *rnh, bool wlock,
+rib_walktree_f_t *wa_f, rib_walk_hook_f_t *hook_f, void *arg);
 
 void rib_walk_del(u_int fibnum, int family, rib_filter_f_t *filter_f,
-  void *arg, bool report);
+void *arg, bool report);
 
 void rib_foreach_table_walk(int family, bool wlock, rib_walktree_f_t *wa_f,
-  rib_walk_hook_f_t *hook_f, void *arg);
+rib_walk_hook_f_t *hook_f, void *arg);
 void rib_foreach_table_walk_del(int family, rib_filter_f_t *filter_f, void 
*arg);
 
 struct route_nhop_data;

Modified: head/sys/net/route/route_helpers.c
==
--- head/sys/net/route/route_helpers.c  Sun Nov 29 13:52:06 2020
(r368149)
+++ head/sys/net/route/route_helpers.c  Sun Nov 29 13:54:49 2020
(r368150)
@@ -77,15 +77,11 @@ __FBSDID("$FreeBSD$");
  * Table is traversed under read lock unless @wlock is set.
  */
 void
-rib_walk_ext(uint32_t fibnum, int family, bool wlock, rib_walktree_f_t *wa_f,
+rib_walk_ext_internal(struct rib_head *rnh, bool wlock, rib_walktree_f_t *wa_f,
 rib_walk_hook_f_t *hook_f, void *arg)
 {
RIB_RLOCK_TRACKER;
-   struct rib_head *rnh;
 
-   if ((rnh = rt_tables_get_rnh(fibnum, family)) == NULL)
-   return;
-
if (wlock)
RIB_WLOCK(rnh);
else
@@ -99,6 +95,16 @@ rib_walk_ext(uint32_t fibnum, int family, bool wlock, 
RIB_WUNLOCK(rnh);
else
RIB_RUNLOCK(rnh);
+}
+
+void
+rib_walk_ext(uint32_t fibnum, int family, bool wlock, rib_walktree_f_t *wa_f,
+rib_walk_hook_f_t *hook_f, void *arg)
+{
+   struct rib_head *rnh;
+
+   if ((rnh = rt_tables_get_rnh(fibnum, family)) != NULL)
+   rib_walk_ext_internal(rnh, wlock, wa_f, hook_f, arg);
 }
 
 /*
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r368149 - head/sys/net/route

2020-11-29 Thread Alexander V. Chernikov
Author: melifaro
Date: Sun Nov 29 13:52:06 2020
New Revision: 368149
URL: https://svnweb.freebsd.org/changeset/base/368149

Log:
  Add nhop_ref_any() to unify referencing nhop or nexthop group.
  
  It allows code within routing subsystem to transparently reference nexthops
   and nexthop groups, similar to nhop_free_any(), abstracting ROUTE_MPATH
   details.
  
  Differential Revision:https://reviews.freebsd.org/D27410

Modified:
  head/sys/net/route/nhgrp_ctl.c
  head/sys/net/route/nhop_ctl.c
  head/sys/net/route/route_var.h

Modified: head/sys/net/route/nhgrp_ctl.c
==
--- head/sys/net/route/nhgrp_ctl.c  Sun Nov 29 13:45:53 2020
(r368148)
+++ head/sys/net/route/nhgrp_ctl.c  Sun Nov 29 13:52:06 2020
(r368149)
@@ -294,6 +294,17 @@ alloc_nhgrp(struct weightened_nhop *wn, int num_nhops)
 }
 
 void
+nhgrp_ref_object(struct nhgrp_object *nhg)
+{
+   struct nhgrp_priv *nhg_priv;
+   u_int old;
+
+   nhg_priv = NHGRP_PRIV(nhg);
+   old = refcount_acquire(_priv->nhg_refcount);
+   KASSERT(old > 0, ("%s: nhgrp object %p has 0 refs", __func__, nhg));
+}
+
+void
 nhgrp_free(struct nhgrp_object *nhg)
 {
struct nhgrp_priv *nhg_priv;

Modified: head/sys/net/route/nhop_ctl.c
==
--- head/sys/net/route/nhop_ctl.c   Sun Nov 29 13:45:53 2020
(r368148)
+++ head/sys/net/route/nhop_ctl.c   Sun Nov 29 13:52:06 2020
(r368149)
@@ -691,6 +691,19 @@ nhop_free(struct nhop_object *nh)
 }
 
 void
+nhop_ref_any(struct nhop_object *nh)
+{
+#ifdef ROUTE_MPATH
+   if (!NH_IS_NHGRP(nh))
+   nhop_ref_object(nh);
+   else
+   nhgrp_ref_object((struct nhgrp_object *)nh);
+#else
+   nhop_ref_object(nh);
+#endif
+}
+
+void
 nhop_free_any(struct nhop_object *nh)
 {
 

Modified: head/sys/net/route/route_var.h
==
--- head/sys/net/route/route_var.h  Sun Nov 29 13:45:53 2020
(r368148)
+++ head/sys/net/route/route_var.h  Sun Nov 29 13:52:06 2020
(r368149)
@@ -242,6 +242,7 @@ int nhops_init_rib(struct rib_head *rh);
 void nhops_destroy_rib(struct rib_head *rh);
 void nhop_ref_object(struct nhop_object *nh);
 int nhop_try_ref_object(struct nhop_object *nh);
+void nhop_ref_any(struct nhop_object *nh);
 void nhop_free_any(struct nhop_object *nh);
 
 void nhop_set_type(struct nhop_object *nh, enum nhop_type nh_type);
@@ -306,6 +307,7 @@ int nhgrp_get_addition_group(struct rib_head *rnh,
 struct route_nhop_data *rnd_orig, struct route_nhop_data *rnd_add,
 struct route_nhop_data *rnd_new);
 
+void nhgrp_ref_object(struct nhgrp_object *nhg);
 uint32_t nhgrp_get_idx(const struct nhgrp_object *nhg);
 void nhgrp_free(struct nhgrp_object *nhg);
 
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r368147 - in head/sys: net netinet netinet6

2020-11-29 Thread Alexander V. Chernikov
Author: melifaro
Date: Sun Nov 29 13:41:49 2020
New Revision: 368147
URL: https://svnweb.freebsd.org/changeset/base/368147

Log:
  Refactor fib4/fib6 functions.
  
  No functional changes.
  
  * Make lookup path of fib<4|6>_lookup_debugnet() separate functions
   (fib<46>_lookup_rt()). These will be used in the control plane code
   requiring unlocked radix operations and actual prefix pointer.
  * Make lookup part of fib<4|6>_check_urpf() separate functions.
   This change simplifies the switch to alternative lookup implementations,
   which helps algorithmic lookups introduction.
  * While here, use static initializers for IPv4/IPv6 keys
  
  Differential Revision:https://reviews.freebsd.org/D27405

Modified:
  head/sys/net/route.h
  head/sys/netinet/in_fib.c
  head/sys/netinet/in_fib.h
  head/sys/netinet6/in6_fib.c
  head/sys/netinet6/in6_fib.h

Modified: head/sys/net/route.h
==
--- head/sys/net/route.hSun Nov 29 13:27:24 2020(r368146)
+++ head/sys/net/route.hSun Nov 29 13:41:49 2020(r368147)
@@ -230,6 +230,7 @@ VNET_DECLARE(u_int, fib_hash_outbound);
 
 /* Control plane route request flags */
 #defineNHR_COPY0x100   /* Copy rte data */
+#defineNHR_UNLOCKED0x200   /* Do not lock table */
 
 /*
  * Routing statistics.

Modified: head/sys/netinet/in_fib.c
==
--- head/sys/netinet/in_fib.c   Sun Nov 29 13:27:24 2020(r368146)
+++ head/sys/netinet/in_fib.c   Sun Nov 29 13:41:49 2020(r368147)
@@ -75,7 +75,6 @@ struct _hash_5tuple_ipv4 {
 _Static_assert(sizeof(struct _hash_5tuple_ipv4) == 16,
 "_hash_5tuple_ipv4 size is wrong");
 
-
 uint32_t
 fib4_calc_software_hash(struct in_addr src, struct in_addr dst,
 unsigned short src_port, unsigned short dst_port, char proto,
@@ -119,11 +118,11 @@ fib4_lookup(uint32_t fibnum, struct in_addr dst, uint3
return (NULL);
 
/* Prepare lookup key */
-   struct sockaddr_in sin4;
-   memset(, 0, sizeof(sin4));
-   sin4.sin_family = AF_INET;
-   sin4.sin_len = sizeof(struct sockaddr_in);
-   sin4.sin_addr = dst;
+   struct sockaddr_in sin4 = {
+   .sin_family = AF_INET,
+   .sin_len = sizeof(struct sockaddr_in),
+   .sin_addr = dst,
+   };
 
nh = NULL;
RIB_RLOCK(rh);
@@ -181,28 +180,18 @@ check_urpf(struct nhop_object *nh, uint32_t flags,
return (check_urpf_nhop(nh, flags, src_if));
 }
 
-/*
- * Performs reverse path forwarding lookup.
- * If @src_if is non-zero, verifies that at least 1 path goes via
- *   this interface.
- * If @src_if is zero, verifies that route exist.
- * if @flags contains NHR_NOTDEFAULT, do not consider default route.
- *
- * Returns 1 if route matching conditions is found, 0 otherwise.
- */
-int
-fib4_check_urpf(uint32_t fibnum, struct in_addr dst, uint32_t scopeid,
-  uint32_t flags, const struct ifnet *src_if)
+static struct nhop_object *
+lookup_nhop(uint32_t fibnum, struct in_addr dst, uint32_t scopeid)
 {
RIB_RLOCK_TRACKER;
struct rib_head *rh;
struct radix_node *rn;
-   int ret;
+   struct nhop_object *nh;
 
KASSERT((fibnum < rt_numfibs), ("fib4_check_urpf: bad fibnum"));
rh = rt_tables_get_rnh(fibnum, AF_INET);
if (rh == NULL)
-   return (0);
+   return (NULL);
 
/* Prepare lookup key */
struct sockaddr_in sin4;
@@ -210,49 +199,96 @@ fib4_check_urpf(uint32_t fibnum, struct in_addr dst, u
sin4.sin_len = sizeof(struct sockaddr_in);
sin4.sin_addr = dst;
 
+   nh = NULL;
RIB_RLOCK(rh);
rn = rh->rnh_matchaddr((void *), >head);
-   if (rn != NULL && ((rn->rn_flags & RNF_ROOT) == 0)) {
-   ret = check_urpf(RNTORT(rn)->rt_nhop, flags, src_if);
-   RIB_RUNLOCK(rh);
-   return (ret);
-   }
+   if (rn != NULL && ((rn->rn_flags & RNF_ROOT) == 0))
+   nh = RNTORT(rn)->rt_nhop;
RIB_RUNLOCK(rh);
 
+   return (nh);
+}
+
+/*
+ * Performs reverse path forwarding lookup.
+ * If @src_if is non-zero, verifies that at least 1 path goes via
+ *   this interface.
+ * If @src_if is zero, verifies that route exist.
+ * if @flags contains NHR_NOTDEFAULT, do not consider default route.
+ *
+ * Returns 1 if route matching conditions is found, 0 otherwise.
+ */
+int
+fib4_check_urpf(uint32_t fibnum, struct in_addr dst, uint32_t scopeid,
+  uint32_t flags, const struct ifnet *src_if)
+{
+   struct nhop_object *nh;
+
+   nh = lookup_nhop(fibnum, dst, scopeid);
+   if (nh != NULL)
+   return (check_urpf(nh, flags, src_if));
+
return (0);
 }
 
-struct nhop_object *
-fib4_lookup_debugnet(uint32_t fibnum, struct in_addr dst, uint32_t scopeid,
-uint32_t flags)
+/*
+ * 

svn commit: r368146 - head/sys/net/route

2020-11-29 Thread Alexander V. Chernikov
Author: melifaro
Date: Sun Nov 29 13:27:24 2020
New Revision: 368146
URL: https://svnweb.freebsd.org/changeset/base/368146

Log:
  Add tracking for rib/nhops/nhgrp objects and provide cumulative number 
accessors.
  
  The resulting KPI can be used by routing table consumers to estimate the 
required
   scale for route table export.
  
  * Add tracking for rib routes
  * Add accessors for number of nexthops/nexthop objects
  * Simplify rib_unsubscribe: store rnh we're attached to instead of requiring 
it up
   again on destruction. This helps in the cases when rnh is not linked 
yet/already unlinked.
  
  Differential Revision:https://reviews.freebsd.org/D27404

Modified:
  head/sys/net/route/nhgrp_ctl.c
  head/sys/net/route/nhop_ctl.c
  head/sys/net/route/route_ctl.c
  head/sys/net/route/route_ctl.h
  head/sys/net/route/route_var.h

Modified: head/sys/net/route/nhgrp_ctl.c
==
--- head/sys/net/route/nhgrp_ctl.c  Sun Nov 29 10:36:56 2020
(r368145)
+++ head/sys/net/route/nhgrp_ctl.c  Sun Nov 29 13:27:24 2020
(r368146)
@@ -762,6 +762,21 @@ nhgrp_get_idx(const struct nhgrp_object *nhg)
return (nhg_priv->nhg_idx);
 }
 
+uint32_t
+nhgrp_get_count(struct rib_head *rh)
+{
+   struct nh_control *ctl;
+   uint32_t count;
+
+   ctl = rh->nh_control;
+
+   NHOPS_RLOCK(ctl);
+   count = ctl->gr_head.items_count;
+   NHOPS_RUNLOCK(ctl);
+
+   return (count);
+}
+
 int
 nhgrp_dump_sysctl(struct rib_head *rh, struct sysctl_req *w)
 {

Modified: head/sys/net/route/nhop_ctl.c
==
--- head/sys/net/route/nhop_ctl.c   Sun Nov 29 10:36:56 2020
(r368145)
+++ head/sys/net/route/nhop_ctl.c   Sun Nov 29 13:27:24 2020
(r368146)
@@ -852,6 +852,21 @@ dump_nhop_entry(struct rib_head *rh, struct nhop_objec
return (error);
 }
 
+uint32_t
+nhops_get_count(struct rib_head *rh)
+{
+   struct nh_control *ctl;
+   uint32_t count;
+
+   ctl = rh->nh_control;
+
+   NHOPS_RLOCK(ctl);
+   count = ctl->nh_head.items_count;
+   NHOPS_RUNLOCK(ctl);
+
+   return (count);
+}
+
 int
 nhops_dump_sysctl(struct rib_head *rh, struct sysctl_req *w)
 {

Modified: head/sys/net/route/route_ctl.c
==
--- head/sys/net/route/route_ctl.c  Sun Nov 29 10:36:56 2020
(r368145)
+++ head/sys/net/route/route_ctl.c  Sun Nov 29 13:27:24 2020
(r368146)
@@ -70,6 +70,7 @@ struct rib_subscription {
CK_STAILQ_ENTRY(rib_subscription)   next;
rib_subscription_cb_t   *func;
void*arg;
+   struct rib_head *rnh;
enum rib_subscription_type  type;
struct epoch_contextepoch_ctx;
 };
@@ -669,6 +670,8 @@ rt_unlinkrte(struct rib_head *rnh, struct rt_addrinfo 
 
/* Finalize notification */
rnh->rnh_gen++;
+   rnh->rnh_prefixes--;
+
rc->rc_cmd = RTM_DELETE;
rc->rc_rt = rt;
rc->rc_nh_old = rt->rt_nhop;
@@ -929,6 +932,7 @@ add_route_nhop(struct rib_head *rnh, struct rtentry *r
 
/* Finalize notification */
rnh->rnh_gen++;
+   rnh->rnh_prefixes++;
 
rc->rc_cmd = RTM_ADD;
rc->rc_rt = rt;
@@ -984,6 +988,8 @@ change_route_nhop(struct rib_head *rnh, struct rtentry
 
/* Finalize notification */
rnh->rnh_gen++;
+   if (rnd->rnd_nhop == NULL)
+   rnh->rnh_prefixes--;
 
rc->rc_cmd = (rnd->rnd_nhop != NULL) ? RTM_CHANGE : RTM_DELETE;
rc->rc_rt = rt;
@@ -1222,7 +1228,7 @@ allocate_subscription(rib_subscription_cb_t *f, void *
 enum rib_subscription_type type, bool waitok)
 {
struct rib_subscription *rs;
-   int flags = M_ZERO | (waitok ? M_WAITOK : 0);
+   int flags = M_ZERO | (waitok ? M_WAITOK : M_NOWAIT);
 
rs = malloc(sizeof(struct rib_subscription), M_RTABLE, flags);
if (rs == NULL)
@@ -1246,22 +1252,14 @@ rib_subscribe(uint32_t fibnum, int family, rib_subscri
 enum rib_subscription_type type, bool waitok)
 {
struct rib_head *rnh;
-   struct rib_subscription *rs;
struct epoch_tracker et;
 
-   if ((rs = allocate_subscription(f, arg, type, waitok)) == NULL)
-   return (NULL);
-
NET_EPOCH_ENTER(et);
KASSERT((fibnum < rt_numfibs), ("%s: bad fibnum", __func__));
rnh = rt_tables_get_rnh(fibnum, family);
-
-   RIB_WLOCK(rnh);
-   CK_STAILQ_INSERT_TAIL(>rnh_subscribers, rs, next);
-   RIB_WUNLOCK(rnh);
NET_EPOCH_EXIT(et);
 
-   return (rs);
+   return (rib_subscribe_internal(rnh, f, arg, type, waitok));
 }
 
 struct rib_subscription *
@@ -1273,6 +1271,7 @@ rib_subscribe_internal(struct 

svn commit: r368128 - head/sys/net/route

2020-11-28 Thread Alexander V. Chernikov
Author: melifaro
Date: Sat Nov 28 15:46:40 2020
New Revision: 368128
URL: https://svnweb.freebsd.org/changeset/base/368128

Log:
  Add nhgrp_get_idx() as a counterpart for nhop_get_idx().
  
  It allows the routing-related code to reference nexthop groups by index
   instead of storing a pointer.

Modified:
  head/sys/net/route/nhgrp_ctl.c
  head/sys/net/route/route_var.h

Modified: head/sys/net/route/nhgrp_ctl.c
==
--- head/sys/net/route/nhgrp_ctl.c  Sat Nov 28 15:11:59 2020
(r368127)
+++ head/sys/net/route/nhgrp_ctl.c  Sat Nov 28 15:46:40 2020
(r368128)
@@ -753,6 +753,15 @@ dump_nhgrp_entry(struct rib_head *rh, const struct nhg
return (error);
 }
 
+uint32_t
+nhgrp_get_idx(const struct nhgrp_object *nhg)
+{
+   const struct nhgrp_priv *nhg_priv;
+
+   nhg_priv = NHGRP_PRIV_CONST(nhg);
+   return (nhg_priv->nhg_idx);
+}
+
 int
 nhgrp_dump_sysctl(struct rib_head *rh, struct sysctl_req *w)
 {

Modified: head/sys/net/route/route_var.h
==
--- head/sys/net/route/route_var.h  Sat Nov 28 15:11:59 2020
(r368127)
+++ head/sys/net/route/route_var.h  Sat Nov 28 15:46:40 2020
(r368128)
@@ -305,6 +305,7 @@ int nhgrp_get_addition_group(struct rib_head *rnh,
 struct route_nhop_data *rnd_orig, struct route_nhop_data *rnd_add,
 struct route_nhop_data *rnd_new);
 
+uint32_t nhgrp_get_idx(const struct nhgrp_object *nhg);
 void nhgrp_free(struct nhgrp_object *nhg);
 
 /* Entropy data used for outbound hashing */
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r368127 - head/sys/net

2020-11-28 Thread Alexander V. Chernikov
Author: melifaro
Date: Sat Nov 28 15:11:59 2020
New Revision: 368127
URL: https://svnweb.freebsd.org/changeset/base/368127

Log:
  Cleanup nexthops request flags:
  * remove NHR_IFAIF as it was used by previous version of nexthop KPI
  * update NHR_REF description

Modified:
  head/sys/net/route.h

Modified: head/sys/net/route.h
==
--- head/sys/net/route.hSat Nov 28 15:00:08 2020(r368126)
+++ head/sys/net/route.hSat Nov 28 15:11:59 2020(r368127)
@@ -223,8 +223,7 @@ VNET_DECLARE(u_int, fib_hash_outbound);
 
 /* Nexthop request flags */
 #defineNHR_NONE0x00/* empty flags field */
-#defineNHR_IFAIF   0x01/* Return ifa_ifp interface */
-#defineNHR_REF 0x02/* For future use */
+#defineNHR_REF 0x02/* reference nexhop */
 
 /* uRPF */
 #defineNHR_NODEFAULT   0x04/* do not consider default 
route */
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r367941 - in head/sys: net net/route netinet netinet6

2020-11-22 Thread Alexander V. Chernikov
Author: melifaro
Date: Sun Nov 22 20:21:10 2020
New Revision: 367941
URL: https://svnweb.freebsd.org/changeset/base/367941

Log:
  Refactor rib iterator functions.
  
  * Make rib_walk() order of arguments consistent with the rest of RIB api
  * Add rib_walk_ext() allowing to exec callback before/after iteration.
  * Rename rt_foreach_fib_walk_del -> rib_foreach_table_walk_del
  * Rename rt_forach_fib_walk -> rib_foreach_table_walk
  * Move rib_foreach_table_walk{_del} to route/route_helpers.c
  * Slightly refactor rib_foreach_table_walk{_del} to make the implementation
   consistent and prepare for upcoming iterator optimizations.
  
  Differential Revision:https://reviews.freebsd.org/D27219

Modified:
  head/sys/net/route.c
  head/sys/net/route.h
  head/sys/net/route/route_ctl.c
  head/sys/net/route/route_ctl.h
  head/sys/net/route/route_helpers.c
  head/sys/netinet/in_rmx.c
  head/sys/netinet6/nd6_rtr.c

Modified: head/sys/net/route.c
==
--- head/sys/net/route.cSun Nov 22 20:16:46 2020(r367940)
+++ head/sys/net/route.cSun Nov 22 20:21:10 2020(r367941)
@@ -458,81 +458,6 @@ rib_free_info(struct rt_addrinfo *info)
 }
 
 /*
- * Iterates over all existing fibs in system calling
- *  @setwa_f function prior to traversing each fib.
- *  Calls @wa_f function for each element in current fib.
- * If af is not AF_UNSPEC, iterates over fibs in particular
- * address family.
- */
-void
-rt_foreach_fib_walk(int af, rt_setwarg_t *setwa_f, rt_walktree_f_t *wa_f,
-void *arg)
-{
-   struct rib_head *rnh;
-   uint32_t fibnum;
-   int i;
-
-   for (fibnum = 0; fibnum < rt_numfibs; fibnum++) {
-   /* Do we want some specific family? */
-   if (af != AF_UNSPEC) {
-   rnh = rt_tables_get_rnh(fibnum, af);
-   if (rnh == NULL)
-   continue;
-   if (setwa_f != NULL)
-   setwa_f(rnh, fibnum, af, arg);
-
-   RIB_WLOCK(rnh);
-   rnh->rnh_walktree(>head, (walktree_f_t *)wa_f,arg);
-   RIB_WUNLOCK(rnh);
-   continue;
-   }
-
-   for (i = 1; i <= AF_MAX; i++) {
-   rnh = rt_tables_get_rnh(fibnum, i);
-   if (rnh == NULL)
-   continue;
-   if (setwa_f != NULL)
-   setwa_f(rnh, fibnum, i, arg);
-
-   RIB_WLOCK(rnh);
-   rnh->rnh_walktree(>head, (walktree_f_t *)wa_f,arg);
-   RIB_WUNLOCK(rnh);
-   }
-   }
-}
-
-/*
- * Iterates over all existing fibs in system and deletes each element
- *  for which @filter_f function returns non-zero value.
- * If @family is not AF_UNSPEC, iterates over fibs in particular
- * address family.
- */
-void
-rt_foreach_fib_walk_del(int family, rt_filter_f_t *filter_f, void *arg)
-{
-   u_int fibnum;
-   int i, start, end;
-
-   for (fibnum = 0; fibnum < rt_numfibs; fibnum++) {
-   /* Do we want some specific family? */
-   if (family != AF_UNSPEC) {
-   start = family;
-   end = family;
-   } else {
-   start = 1;
-   end = AF_MAX;
-   }
-
-   for (i = start; i <= end; i++) {
-   if (rt_tables_get_rnh(fibnum, i) == NULL)
-   continue;
-
-   rib_walk_del(fibnum, i, filter_f, arg, 0);
-   }
-   }
-}
-
-/*
  * Delete Routes for a Network Interface
  *
  * Called for each routing entry via the rnh->rnh_walktree() call above
@@ -577,14 +502,14 @@ rt_flushifroutes_af(struct ifnet *ifp, int af)
KASSERT((af >= 1 && af <= AF_MAX), ("%s: af %d not >= 1 and <= %d",
__func__, af, AF_MAX));
 
-   rt_foreach_fib_walk_del(af, rt_ifdelroute, ifp);
+   rib_foreach_table_walk_del(af, rt_ifdelroute, ifp);
 }
 
 void
 rt_flushifroutes(struct ifnet *ifp)
 {
 
-   rt_foreach_fib_walk_del(AF_UNSPEC, rt_ifdelroute, ifp);
+   rib_foreach_table_walk_del(AF_UNSPEC, rt_ifdelroute, ifp);
 }
 
 /*

Modified: head/sys/net/route.h
==
--- head/sys/net/route.hSun Nov 22 20:16:46 2020(r367940)
+++ head/sys/net/route.hSun Nov 22 20:21:10 2020(r367941)
@@ -342,7 +342,7 @@ struct rt_msghdr {
 
 struct rtentry;
 struct nhop_object;
-typedef int rt_filter_f_t(const struct rtentry *, const struct nhop_object *,
+typedef int rib_filter_f_t(const struct rtentry *, const struct nhop_object *,
 void *);
 
 struct rt_addrinfo {
@@ -351,7 +351,7 @@ struct rt_addrinfo {
struct  sockaddr *rti_info[RTAX_MAX];   

svn commit: r367491 - in head: . sys/net/route

2020-11-08 Thread Alexander V. Chernikov
Author: melifaro
Date: Sun Nov  8 18:27:49 2020
New Revision: 367491
URL: https://svnweb.freebsd.org/changeset/base/367491

Log:
  Switch net.add_addr_allfibs default to 0.
  
  The goal of the fib support is to provide multiple independent
   routing tables, isolated from each other.
  net.add_addr_allfibs default tries to shift gears in the opposite
   direction, unconditionally inserting all addresses to all of the fibs.
  
  There are use cases when this is necessary, however this is not a
   default expected behaviour, especially compared to other implementations.
  
  Provide WARNING message for the setups with multiple fibs to notify
   potential users of the feature.
  
  Differential Revision:https://reviews.freebsd.org/D26076

Modified:
  head/UPDATING
  head/sys/net/route/route_ifaddrs.c
  head/sys/net/route/route_tables.c

Modified: head/UPDATING
==
--- head/UPDATING   Sun Nov  8 18:11:12 2020(r367490)
+++ head/UPDATING   Sun Nov  8 18:27:49 2020(r367491)
@@ -26,6 +26,10 @@ NOTE TO PEOPLE WHO THINK THAT FreeBSD 13.x IS SLOW:
world, or to merely disable the most expensive debugging functionality
at runtime, run "ln -s 'abort:false,junk:false' /etc/malloc.conf".)
 
+20201108:
+   Default value of net.add_addr_allfibs has been changed to 0.
+   If you have multi-fib configuration and rely on existence of all
+   interface routes in every fib, you need to set the above sysctl to 1.
 20201030:
The internal pre-processor in the calendar(1) program has been
extended to support more C pre-processor commands (e.g. #ifdef, #else,

Modified: head/sys/net/route/route_ifaddrs.c
==
--- head/sys/net/route/route_ifaddrs.c  Sun Nov  8 18:11:12 2020
(r367490)
+++ head/sys/net/route/route_ifaddrs.c  Sun Nov  8 18:27:49 2020
(r367491)
@@ -61,7 +61,7 @@
  * By default, interface address routes are added to the fib of the interface.
  * Once set to non-zero, adds interface address route to all fibs.
  */
-VNET_DEFINE(u_int, rt_add_addr_allfibs) = 1;
+VNET_DEFINE(u_int, rt_add_addr_allfibs) = 0;
 SYSCTL_UINT(_net, OID_AUTO, add_addr_allfibs, CTLFLAG_RWTUN | CTLFLAG_VNET,
 _NAME(rt_add_addr_allfibs), 0, "");
 

Modified: head/sys/net/route/route_tables.c
==
--- head/sys/net/route/route_tables.c   Sun Nov  8 18:11:12 2020
(r367490)
+++ head/sys/net/route/route_tables.c   Sun Nov  8 18:27:49 2020
(r367491)
@@ -183,6 +183,11 @@ grow_rtables(uint32_t num_tables)
new_rt_tables = mallocarray(num_tables * (AF_MAX + 1), sizeof(void *),
M_RTABLE, M_WAITOK | M_ZERO);
 
+   if ((num_tables > 1) && (V_rt_add_addr_allfibs == 0))
+   printf("WARNING: Adding ifaddrs to all fibs has been turned off 
"
+   "by default. Consider tuning %s if needed\n",
+   "net.add_addr_allfibs");
+
/*
 * Current rt_tables layout:
 * fib0[af0, af1, af2, .., AF_MAX]fib1[af0, af1, af2, .., Af_MAX]..
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r367490 - head/sys/net/route

2020-11-08 Thread Alexander V. Chernikov
Author: melifaro
Date: Sun Nov  8 18:11:12 2020
New Revision: 367490
URL: https://svnweb.freebsd.org/changeset/base/367490

Log:
  Temporarily revert setting net.add_addr_allfibs to 0.
  It accidentally sweeped in r367486.
  Revert to allow for proper commit message & warning.

Modified:
  head/sys/net/route/route_ifaddrs.c

Modified: head/sys/net/route/route_ifaddrs.c
==
--- head/sys/net/route/route_ifaddrs.c  Sun Nov  8 17:10:12 2020
(r367489)
+++ head/sys/net/route/route_ifaddrs.c  Sun Nov  8 18:11:12 2020
(r367490)
@@ -61,7 +61,7 @@
  * By default, interface address routes are added to the fib of the interface.
  * Once set to non-zero, adds interface address route to all fibs.
  */
-VNET_DEFINE(u_int, rt_add_addr_allfibs) = 0;
+VNET_DEFINE(u_int, rt_add_addr_allfibs) = 1;
 SYSCTL_UINT(_net, OID_AUTO, add_addr_allfibs, CTLFLAG_RWTUN | CTLFLAG_VNET,
 _NAME(rt_add_addr_allfibs), 0, "");
 
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r367486 - head/sys/net/route

2020-11-08 Thread Alexander V. Chernikov
Author: melifaro
Date: Sun Nov  8 13:30:44 2020
New Revision: 367486
URL: https://svnweb.freebsd.org/changeset/base/367486

Log:
  Fix build broken by r367484: add route_ifaddrs.c.
  
  Pointy hat to: melifaro
  Reported by:  jenkins

Added:
  head/sys/net/route/route_ifaddrs.c   (contents, props changed)

Added: head/sys/net/route/route_ifaddrs.c
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/sys/net/route/route_ifaddrs.c  Sun Nov  8 13:30:44 2020
(r367486)
@@ -0,0 +1,309 @@
+/*-
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ * Copyright (c) 1980, 1986, 1991, 1993
+ * The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *may be used to endorse or promote products derived from this software
+ *without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)route.c 8.3.1.1 (Berkeley) 2/23/95
+ * $FreeBSD$
+ */
+
+#include "opt_mpath.h"
+#include "opt_route.h"
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+/*
+ * Control interface address fib propagation.
+ * By default, interface address routes are added to the fib of the interface.
+ * Once set to non-zero, adds interface address route to all fibs.
+ */
+VNET_DEFINE(u_int, rt_add_addr_allfibs) = 0;
+SYSCTL_UINT(_net, OID_AUTO, add_addr_allfibs, CTLFLAG_RWTUN | CTLFLAG_VNET,
+_NAME(rt_add_addr_allfibs), 0, "");
+
+/*
+ * Set up a routing table entry, normally
+ * for an interface.
+ */
+static inline  int
+rtinit1(struct ifaddr *ifa, int cmd, int flags, int fibnum)
+{
+   RIB_RLOCK_TRACKER;
+   struct epoch_tracker et;
+   struct sockaddr *dst;
+   struct sockaddr *netmask;
+   struct rib_cmd_info rc;
+   struct rt_addrinfo info;
+   int error = 0;
+   int startfib, endfib;
+   struct sockaddr_storage ss;
+   int didwork = 0;
+   int a_failure = 0;
+   struct sockaddr_dl_short sdl;
+   struct rib_head *rnh;
+
+   if (flags & RTF_HOST) {
+   dst = ifa->ifa_dstaddr;
+   netmask = NULL;
+   } else {
+   dst = ifa->ifa_addr;
+   netmask = ifa->ifa_netmask;
+   }
+   if (dst->sa_len == 0)
+   return(EINVAL);
+   switch (dst->sa_family) {
+   case AF_INET6:
+   case AF_INET:
+   /* We support multiple FIBs. */
+   break;
+   default:
+   fibnum = RT_DEFAULT_FIB;
+   break;
+   }
+   if (fibnum == RT_ALL_FIBS) {
+   if (V_rt_add_addr_allfibs == 0 && cmd == (int)RTM_ADD)
+   startfib = endfib = ifa->ifa_ifp->if_fib;
+   else {
+   startfib = 0;
+   endfib = rt_numfibs - 1;
+   }
+   } else {
+   KASSERT((fibnum < rt_numfibs), ("rtinit1: bad fibnum"));
+   startfib = fibnum;
+   endfib = fibnum;
+   }
+
+   /*
+* If it's a delete, check that if it exists,
+* it's on the correct interface or we might scrub
+* a route to another ifa which would
+* be confusing at best and possibly worse.
+*/
+   if (cmd == RTM_DELETE) {
+   /*
+* It's a delete, so it should already exist..
+* If it's a net, mask off the host bits
+* (Assuming we have a mask)
+* XXX 

svn commit: r367484 - in head/sys: conf net

2020-11-08 Thread Alexander V. Chernikov
Author: melifaro
Date: Sun Nov  8 11:12:00 2020
New Revision: 367484
URL: https://svnweb.freebsd.org/changeset/base/367484

Log:
  Move all ifaddr route creation business logic to net/route/route_ifaddr.c
  
  Differential Revision:https://reviews.freebsd.org/D26318

Modified:
  head/sys/conf/files
  head/sys/net/if.c
  head/sys/net/route.c

Modified: head/sys/conf/files
==
--- head/sys/conf/files Sun Nov  8 10:13:06 2020(r367483)
+++ head/sys/conf/files Sun Nov  8 11:12:00 2020(r367484)
@@ -4174,6 +4174,7 @@ net/route/nhop_utils.cstandard
 net/route/route_ctl.c  standard
 net/route/route_ddb.c  optional ddb
 net/route/route_helpers.c  standard
+net/route/route_ifaddrs.c  standard
 net/route/route_tables.c   standard
 net/route/route_temporal.c standard
 net/rss_config.c   optional inet rss | inet6 rss

Modified: head/sys/net/if.c
==
--- head/sys/net/if.c   Sun Nov  8 10:13:06 2020(r367483)
+++ head/sys/net/if.c   Sun Nov  8 11:12:00 2020(r367484)
@@ -1842,76 +1842,6 @@ ifa_free(struct ifaddr *ifa)
NET_EPOCH_CALL(ifa_destroy, >ifa_epoch_ctx);
 }
 
-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;
-   struct sockaddr_dl null_sdl;
-   struct ifnet *ifp;
-   struct ifaddr *rti_ifa = NULL;
-
-   ifp = ifa->ifa_ifp;
-
-   NET_EPOCH_ENTER(et);
-   bzero(, sizeof(info));
-   if (cmd != RTM_DELETE)
-   info.rti_ifp = V_loif;
-   if (cmd == RTM_ADD) {
-   /* explicitly specify (loopback) ifa */
-   if (info.rti_ifp != NULL) {
-   rti_ifa = ifaof_ifpforaddr(ifa->ifa_addr, info.rti_ifp);
-   if (rti_ifa != NULL)
-   ifa_ref(rti_ifa);
-   info.rti_ifa = rti_ifa;
-   }
-   }
-   info.rti_flags = ifa->ifa_flags | RTF_HOST | RTF_STATIC | RTF_PINNED;
-   info.rti_info[RTAX_DST] = ia;
-   info.rti_info[RTAX_GATEWAY] = (struct sockaddr *)_sdl;
-   link_init_sdl(ifp, (struct sockaddr *)_sdl, ifp->if_type);
-
-   error = rib_action(ifp->if_fib, cmd, , );
-   NET_EPOCH_EXIT(et);
-
-   if (rti_ifa != NULL)
-   ifa_free(rti_ifa);
-
-   if (error == 0 ||
-   (cmd == RTM_ADD && error == EEXIST) ||
-   (cmd == RTM_DELETE && (error == ENOENT || error == ESRCH)))
-   return (error);
-
-   log(LOG_DEBUG, "%s: %s failed for interface %s: %u\n",
-   __func__, otype, if_name(ifp), error);
-
-   return (error);
-}
-
-int
-ifa_add_loopback_route(struct ifaddr *ifa, struct sockaddr *ia)
-{
-
-   return (ifa_maintain_loopback_route(RTM_ADD, "insertion", ifa, ia));
-}
-
-int
-ifa_del_loopback_route(struct ifaddr *ifa, struct sockaddr *ia)
-{
-
-   return (ifa_maintain_loopback_route(RTM_DELETE, "deletion", ifa, ia));
-}
-
-int
-ifa_switch_loopback_route(struct ifaddr *ifa, struct sockaddr *ia)
-{
-
-   return (ifa_maintain_loopback_route(RTM_CHANGE, "switch", ifa, ia));
-}
-
 /*
  * XXX: Because sockaddr_dl has deeper structure than the sockaddr
  * structs used to represent other address families, it is necessary

Modified: head/sys/net/route.c
==
--- head/sys/net/route.cSun Nov  8 10:13:06 2020(r367483)
+++ head/sys/net/route.cSun Nov  8 11:12:00 2020(r367484)
@@ -72,20 +72,6 @@
 #include 
 #include 
 
-/*
- * By default add routes to all fibs for new interfaces.
- * Once this is set to 0 then only allocate routes on interface
- * changes for the FIB of the caller when adding a new set of addresses
- * to an interface.  XXX this is a shotgun aproach to a problem that needs
- * a more fine grained solution.. that will come.
- * XXX also has the problems getting the FIB from curthread which will not
- * always work given the fib can be overridden and prefixes can be added
- * from the network stack context.
- */
-VNET_DEFINE(u_int, rt_add_addr_allfibs) = 1;
-SYSCTL_UINT(_net, OID_AUTO, add_addr_allfibs, CTLFLAG_RWTUN | CTLFLAG_VNET,
-_NAME(rt_add_addr_allfibs), 0, "");
-
 VNET_PCPUSTAT_DEFINE(struct rtstat, rtstat);
 
 VNET_PCPUSTAT_SYSINIT(rtstat);
@@ -864,196 +850,6 @@ rt_maskedcopy(struct sockaddr *src, struct sockaddr *d
*cp2++ = *cp1++ & *cp3++;
if (cp2 < cplim2)
bzero((caddr_t)cp2, (unsigned)(cplim2 - cp2));
-}
-
-/*
- * Set up a routing table entry, normally
- * for an interface.
- */
-static inline  int
-rtinit1(struct ifaddr *ifa, int cmd, int flags, int fibnum)
-{
-   

svn commit: r367114 - head/sys/netinet6

2020-10-28 Thread Alexander V. Chernikov
Author: melifaro
Date: Wed Oct 28 20:22:20 2020
New Revision: 367114
URL: https://svnweb.freebsd.org/changeset/base/367114

Log:
  Fix use-after-free in icmp6_notify_error().
  
  Reported by:  Maxime Villard 
  Reviewed by:  markj
  MFC after:3 days

Modified:
  head/sys/netinet6/icmp6.c

Modified: head/sys/netinet6/icmp6.c
==
--- head/sys/netinet6/icmp6.c   Wed Oct 28 18:22:25 2020(r367113)
+++ head/sys/netinet6/icmp6.c   Wed Oct 28 20:22:20 2020(r367114)
@@ -917,6 +917,7 @@ icmp6_notify_error(struct mbuf **mp, int off, int icmp
}
icmp6 = (struct icmp6_hdr *)(mtod(m, caddr_t) + off);
eip6 = (struct ip6_hdr *)(icmp6 + 1);
+   bzero(, sizeof(icmp6dst));
 
/* Detect the upper level protocol */
{
@@ -925,7 +926,6 @@ icmp6_notify_error(struct mbuf **mp, int off, int icmp
int eoff = off + sizeof(struct icmp6_hdr) +
sizeof(struct ip6_hdr);
struct ip6ctlparam ip6cp;
-   struct in6_addr *finaldst = NULL;
int icmp6type = icmp6->icmp6_type;
struct ip6_frag *fh;
struct ip6_rthdr *rth;
@@ -999,10 +999,11 @@ icmp6_notify_error(struct mbuf **mp, int off, int icmp
}
rth0 = (struct ip6_rthdr0 *)
(mtod(m, caddr_t) + eoff);
+
/* just ignore a bogus header */
if ((rth0->ip6r0_len % 2) == 0 &&
(hops = rth0->ip6r0_len/2))
-   finaldst = (struct in6_addr 
*)(rth0 + 1) + (hops - 1);
+   icmp6dst.sin6_addr = *((struct 
in6_addr *)(rth0 + 1) + (hops - 1));
}
eoff += rthlen;
nxt = rth->ip6r_nxt;
@@ -1056,13 +1057,10 @@ icmp6_notify_error(struct mbuf **mp, int off, int icmp
 */
eip6 = (struct ip6_hdr *)(icmp6 + 1);
 
-   bzero(, sizeof(icmp6dst));
icmp6dst.sin6_len = sizeof(struct sockaddr_in6);
icmp6dst.sin6_family = AF_INET6;
-   if (finaldst == NULL)
+   if (IN6_IS_ADDR_UNSPECIFIED(_addr))
icmp6dst.sin6_addr = eip6->ip6_dst;
-   else
-   icmp6dst.sin6_addr = *finaldst;
if (in6_setscope(_addr, m->m_pkthdr.rcvif, NULL))
goto freeit;
bzero(, sizeof(icmp6src));
@@ -1074,13 +1072,11 @@ icmp6_notify_error(struct mbuf **mp, int off, int icmp
icmp6src.sin6_flowinfo =
(eip6->ip6_flow & IPV6_FLOWLABEL_MASK);
 
-   if (finaldst == NULL)
-   finaldst = >ip6_dst;
ip6cp.ip6c_m = m;
ip6cp.ip6c_icmp6 = icmp6;
ip6cp.ip6c_ip6 = (struct ip6_hdr *)(icmp6 + 1);
ip6cp.ip6c_off = eoff;
-   ip6cp.ip6c_finaldst = finaldst;
+   ip6cp.ip6c_finaldst = _addr;
ip6cp.ip6c_src = 
ip6cp.ip6c_nxt = nxt;
 
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r366993 - head/sys/net

2020-10-24 Thread Alexander V . Chernikov
24.10.2020, 14:08, "Hans Petter Selasky" :
> On 2020-10-24 14:52, Alexey Dokuchaev wrote:
>>  On Sat, Oct 24, 2020 at 10:23:22AM +, Hans Petter Selasky wrote:
>>>  New Revision: 366993
>>>  URL: https://svnweb.freebsd.org/changeset/base/366993
>>>
>>>  Log:
>>> Run code through "clang-format -style=file" with some additional fixes.
>>> No functional change.
>>>
>>>  ...
>>>  @@ -99,8 +97,8 @@ infiniband_ipv4_multicast_map(uint32_t addr,
>>>
>>>    #ifdef INET6
>>>    static inline void
>>>  -infiniband_ipv6_multicast_map(const struct in6_addr *addr,
>>>  - const uint8_t *broadcast, uint8_t *buf)
>>>  +infiniband_ipv6_multicast_map(
>>>  + const struct in6_addr *addr, const uint8_t *broadcast, uint8_t *buf)
>>>    {
>>
>>  This is not how we format these in FreeBSD, please revert. It was correct
>>  before and no "fix" is need here.
Given we already have nice .clang-format, that does most of the job, maybe it's 
worth considering looking into tweaking it further to fix this part?
It would be nice if we could finally offload all formatting issues to the tool 
and focus on the actual code :-)
> Done.
>
> --HPS
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r366917 - in head: sbin/ifconfig sys/net tests/sys/net

2020-10-21 Thread Alexander V. Chernikov
Author: melifaro
Date: Wed Oct 21 21:28:20 2020
New Revision: 366917
URL: https://svnweb.freebsd.org/changeset/base/366917

Log:
  Add support for stacked VLANs (IEEE 802.1ad, AKA Q-in-Q).
  
  802.1ad interfaces are created with ifconfig using the "vlanproto" parameter.
  Eg., the following creates a 802.1Q VLAN (id #42) over a 802.1ad S-VLAN
  (id #5) over a physical Ethernet interface (em0).
  
  ifconfig vlan5 create vlandev em0 vlan 5 vlanproto 802.1ad up
  ifconfig vlan42 create vlandev vlan5 vlan 42 inet 10.5.42.1/24
  
  VLAN_MTU, VLAN_HWCSUM and VLAN_TSO capabilities should be properly
  supported. VLAN_HWTAGGING is only partially supported, as there is
  currently no IFCAP_VLAN_* denoting the possibility to set the VLAN
  EtherType to anything else than 0x8100 (802.1ad uses 0x88A8).
  
  Submitted by: Olivier Piras
  Sponsored by: RG Nets
  Differential Revision:https://reviews.freebsd.org/D26436

Modified:
  head/sbin/ifconfig/ifclone.c
  head/sbin/ifconfig/ifconfig.8
  head/sbin/ifconfig/ifconfig.h
  head/sbin/ifconfig/ifieee80211.c
  head/sbin/ifconfig/ifvlan.c
  head/sbin/ifconfig/ifvxlan.c
  head/sys/net/ethernet.h
  head/sys/net/if_clone.c
  head/sys/net/if_ethersubr.c
  head/sys/net/if_vlan.c
  head/sys/net/if_vlan_var.h
  head/tests/sys/net/if_vlan.sh

Modified: head/sbin/ifconfig/ifclone.c
==
--- head/sbin/ifconfig/ifclone.cWed Oct 21 20:42:29 2020
(r366916)
+++ head/sbin/ifconfig/ifclone.cWed Oct 21 21:28:20 2020
(r366917)
@@ -49,6 +49,11 @@ static const char rcsid[] =
 
 #include "ifconfig.h"
 
+typedef enum {
+   MT_PREFIX,
+   MT_FILTER,
+} clone_match_type;
+
 static void
 list_cloners(void)
 {
@@ -76,7 +81,11 @@ list_cloners(void)
 }
 
 struct clone_defcb {
-   char ifprefix[IFNAMSIZ];
+   union {
+   char ifprefix[IFNAMSIZ];
+   clone_match_func *ifmatch;
+   };
+   clone_match_type clone_mt;
clone_callback_func *clone_cb;
SLIST_ENTRY(clone_defcb) next;
 };
@@ -85,16 +94,29 @@ static SLIST_HEAD(, clone_defcb) clone_defcbh =
SLIST_HEAD_INITIALIZER(clone_defcbh);
 
 void
-clone_setdefcallback(const char *ifprefix, clone_callback_func *p)
+clone_setdefcallback_prefix(const char *ifprefix, clone_callback_func *p)
 {
struct clone_defcb *dcp;
 
dcp = malloc(sizeof(*dcp));
strlcpy(dcp->ifprefix, ifprefix, IFNAMSIZ-1);
+   dcp->clone_mt = MT_PREFIX;
dcp->clone_cb = p;
SLIST_INSERT_HEAD(_defcbh, dcp, next);
 }
 
+void
+clone_setdefcallback_filter(clone_match_func *filter, clone_callback_func *p)
+{
+   struct clone_defcb *dcp;
+
+   dcp = malloc(sizeof(*dcp));
+   dcp->ifmatch  = filter;
+   dcp->clone_mt = MT_FILTER;
+   dcp->clone_cb = p;
+   SLIST_INSERT_HEAD(_defcbh, dcp, next);
+}
+
 /*
  * Do the actual clone operation.  Any parameters must have been
  * setup by now.  If a callback has been setup to do the work
@@ -114,8 +136,14 @@ ifclonecreate(int s, void *arg)
if (clone_cb == NULL) {
/* Try to find a default callback */
SLIST_FOREACH(dcp, _defcbh, next) {
-   if (strncmp(dcp->ifprefix, ifr.ifr_name,
-   strlen(dcp->ifprefix)) == 0) {
+   if ((dcp->clone_mt == MT_PREFIX) &&
+   (strncmp(dcp->ifprefix, ifr.ifr_name,
+strlen(dcp->ifprefix)) == 0)) {
+   clone_cb = dcp->clone_cb;
+   break;
+   }
+   if ((dcp->clone_mt == MT_FILTER) &&
+ dcp->ifmatch(ifr.ifr_name)) {
clone_cb = dcp->clone_cb;
break;
}

Modified: head/sbin/ifconfig/ifconfig.8
==
--- head/sbin/ifconfig/ifconfig.8   Wed Oct 21 20:42:29 2020
(r366916)
+++ head/sbin/ifconfig/ifconfig.8   Wed Oct 21 21:28:20 2020
(r366917)
@@ -582,7 +582,7 @@ they support in their capabilities.
 is a synonym for enabling all available WOL mechanisms.
 To disable WOL use
 .Fl wol .
-.It Cm vlanmtu , vlanhwtag, vlanhwfilter, vlanhwcsum, vlanhwtso
+.It Cm vlanmtu , vlanhwtag , vlanhwfilter , vlanhwcsum , vlanhwtso
 If the driver offers user-configurable VLAN support, enable
 reception of extended frames, tag processing in hardware,
 frame filtering in hardware, checksum offloading, or TSO on VLAN,
@@ -592,7 +592,7 @@ Note that this must be configured on a physical interf
 not on a
 .Xr vlan 4
 interface itself.
-.It Fl vlanmtu , vlanhwtag , vlanhwfilter , vlanhwtso
+.It Fl vlanmtu , vlanhwtag, vlanhwfilter, vlanhwtso
 If the driver offers user-configurable VLAN support, disable
 reception of extended frames, tag processing 

svn commit: r366813 - in head/sys: conf net net/route netinet netinet6

2020-10-18 Thread Alexander V. Chernikov
Author: melifaro
Date: Sun Oct 18 17:15:47 2020
New Revision: 366813
URL: https://svnweb.freebsd.org/changeset/base/366813

Log:
  Implement flowid calculation for outbound connections to balance
   connections over multiple paths.
  
  Multipath routing relies on mbuf flowid data for both transit
   and outbound traffic. Current code fills mbuf flowid from inp_flowid
   for connection-oriented sockets. However, inp_flowid is currently
   not calculated for outbound connections.
  
  This change creates simple hashing functions and starts calculating hashes
   for TCP,UDP/UDP-Lite and raw IP if multipath routes are present in the
   system.
  
  Reviewed by:  glebius (previous version),ae
  Differential Revision:https://reviews.freebsd.org/D26523

Modified:
  head/sys/conf/files
  head/sys/net/radix.c
  head/sys/net/route.h
  head/sys/net/route/mpath_ctl.c
  head/sys/net/route/route_var.h
  head/sys/netinet/in_fib.c
  head/sys/netinet/in_fib.h
  head/sys/netinet/in_pcb.c
  head/sys/netinet/in_rss.c
  head/sys/netinet/in_rss.h
  head/sys/netinet/raw_ip.c
  head/sys/netinet/udp_usrreq.c
  head/sys/netinet6/in6_fib.c
  head/sys/netinet6/in6_fib.h
  head/sys/netinet6/in6_pcb.c
  head/sys/netinet6/in6_rss.c
  head/sys/netinet6/in6_rss.h
  head/sys/netinet6/ip6_output.c
  head/sys/netinet6/raw_ip6.c
  head/sys/netinet6/udp6_usrreq.c

Modified: head/sys/conf/files
==
--- head/sys/conf/files Sun Oct 18 16:30:49 2020(r366812)
+++ head/sys/conf/files Sun Oct 18 17:15:47 2020(r366813)
@@ -4180,7 +4180,7 @@ net/rss_config.c  optional inet rss | inet6 rss
 net/rtsock.c   standard
 net/slcompress.c   optional netgraph_vjc | sppp | \
 netgraph_sppp
-net/toeplitz.c optional inet rss | inet6 rss
+net/toeplitz.c optional inet rss | inet6 rss | route_mpath
 net/vnet.c optional vimage
 net80211/ieee80211.c   optional wlan
 net80211/ieee80211_acl.c   optional wlan wlan_acl

Modified: head/sys/net/radix.c
==
--- head/sys/net/radix.cSun Oct 18 16:30:49 2020(r366812)
+++ head/sys/net/radix.cSun Oct 18 17:15:47 2020(r366813)
@@ -624,21 +624,6 @@ rn_addroute(void *v_arg, void *n_arg, struct radix_hea
saved_tt = tt = rn_insert(v, head, , treenodes);
if (keyduplicated) {
for (t = tt; tt; t = tt, tt = tt->rn_dupedkey) {
-#ifdef RADIX_MPATH
-   /* permit multipath, if enabled for the family */
-   if (rn_mpath_capable(head) && netmask == tt->rn_mask) {
-   /*
-* go down to the end of multipaths, so that
-* new entry goes into the end of rn_dupedkey
-* chain.
-*/
-   do {
-   t = tt;
-   tt = tt->rn_dupedkey;
-   } while (tt && t->rn_mask == tt->rn_mask);
-   break;
-   }
-#endif
if (tt->rn_mask == netmask)
return (0);
if (netmask == 0 ||
@@ -744,10 +729,8 @@ on2:
if (m->rm_flags & RNF_NORMAL) {
mmask = m->rm_leaf->rn_mask;
if (tt->rn_flags & RNF_NORMAL) {
-#if !defined(RADIX_MPATH)
log(LOG_ERR,
"Non-unique normal route, mask not entered\n");
-#endif
return (tt);
}
} else

Modified: head/sys/net/route.h
==
--- head/sys/net/route.hSun Oct 18 16:30:49 2020(r366812)
+++ head/sys/net/route.hSun Oct 18 17:15:47 2020(r366813)
@@ -125,7 +125,41 @@ VNET_DECLARE(uint32_t, _rt_numfibs);   /* number of 
exis
 #definert_numfibs  V_rt_numfibs
 VNET_DECLARE(u_int, rt_add_addr_allfibs); /* Announce interfaces to all fibs */
 #defineV_rt_add_addr_allfibs   VNET(rt_add_addr_allfibs)
+
+/* Calculate flowid for locally-originated packets */
+#defineV_fib_hash_outbound VNET(fib_hash_outbound)
+VNET_DECLARE(u_int, fib_hash_outbound);
+
+/* Outbound flowid generation rules */
+#ifdef RSS
+
+#define fib4_calc_packet_hash  xps_proto_software_hash_v4
+#define fib6_calc_packet_hash  xps_proto_software_hash_v6
+#defineCALC_FLOWID_OUTBOUND_SENDTO true
+
+#ifdef ROUTE_MPATH
+#defineCALC_FLOWID_OUTBOUNDV_fib_hash_outbound
+#else
+#define

svn commit: r366807 - head/sys/netinet

2020-10-18 Thread Alexander V. Chernikov
Author: melifaro
Date: Sun Oct 18 12:03:36 2020
New Revision: 366807
URL: https://svnweb.freebsd.org/changeset/base/366807

Log:
  Simplify NET_EPOCH_EXIT in inp_join_group().
  
  Suggested by: kib

Modified:
  head/sys/netinet/in_mcast.c

Modified: head/sys/netinet/in_mcast.c
==
--- head/sys/netinet/in_mcast.c Sun Oct 18 08:58:14 2020(r366806)
+++ head/sys/netinet/in_mcast.c Sun Oct 18 12:03:36 2020(r366807)
@@ -2009,6 +2009,7 @@ inp_join_group(struct inpcb *inp, struct sockopt *sopt
else
ifp = inp_lookup_mcast_ifp(inp, >sin,
mreqn.imr_address);
+   NET_EPOCH_EXIT(et);
break;
}
case IP_ADD_SOURCE_MEMBERSHIP: {
@@ -2032,6 +2033,7 @@ inp_join_group(struct inpcb *inp, struct sockopt *sopt
NET_EPOCH_ENTER(et);
ifp = inp_lookup_mcast_ifp(inp, >sin,
mreqs.imr_interface);
+   NET_EPOCH_EXIT(et);
CTR3(KTR_IGMPV3, "%s: imr_interface = 0x%08x, ifp = %p",
__func__, ntohl(mreqs.imr_interface.s_addr), ifp);
break;
@@ -2074,6 +2076,7 @@ inp_join_group(struct inpcb *inp, struct sockopt *sopt
return (EADDRNOTAVAIL);
NET_EPOCH_ENTER(et);
ifp = ifnet_byindex_ref(gsr.gsr_interface);
+   NET_EPOCH_EXIT(et);
break;
 
default:
@@ -2082,7 +2085,6 @@ inp_join_group(struct inpcb *inp, struct sockopt *sopt
return (EOPNOTSUPP);
break;
}
-   NET_EPOCH_EXIT(et);
 
if (ifp == NULL || (ifp->if_flags & IFF_MULTICAST) == 0) {
if (ifp != NULL)
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r366795 - head/sys/netinet

2020-10-17 Thread Alexander V. Chernikov
Author: melifaro
Date: Sat Oct 17 20:33:09 2020
New Revision: 366795
URL: https://svnweb.freebsd.org/changeset/base/366795

Log:
  Fix sleepq_add panic happening with too wide net epoch in mcast control.
  
  PR:   250413
  Reported by:  Christopher Hall 
  Reviewed by:  ae
  Differential Revision:https://reviews.freebsd.org/D26827

Modified:
  head/sys/netinet/in_mcast.c

Modified: head/sys/netinet/in_mcast.c
==
--- head/sys/netinet/in_mcast.c Sat Oct 17 17:31:06 2020(r366794)
+++ head/sys/netinet/in_mcast.c Sat Oct 17 20:33:09 2020(r366795)
@@ -1905,7 +1905,7 @@ inp_getmoptions(struct inpcb *inp, struct sockopt *sop
  * this in order to allow groups to be joined when the routing
  * table has not yet been populated during boot.
  *
- * Returns NULL if no ifp could be found.
+ * Returns NULL if no ifp could be found, otherwise return referenced ifp.
  *
  * FUTURE: Implement IPv4 source-address selection.
  */
@@ -1926,13 +1926,16 @@ inp_lookup_mcast_ifp(const struct inpcb *inp,
if (!in_nullhost(ina)) {
IN_IFADDR_RLOCK(_ifa_tracker);
INADDR_TO_IFP(ina, ifp);
+   if (ifp != NULL)
+   if_ref(ifp);
IN_IFADDR_RUNLOCK(_ifa_tracker);
} else {
-   fibnum = inp ? inp->inp_inc.inc_fibnum : 0;
-   nh = fib4_lookup(fibnum, gsin->sin_addr, 0, 0, 0);
-   if (nh != NULL)
+   fibnum = inp ? inp->inp_inc.inc_fibnum : RT_DEFAULT_FIB;
+   nh = fib4_lookup(fibnum, gsin->sin_addr, 0, NHR_NONE, 0);
+   if (nh != NULL) {
ifp = nh->nh_ifp;
-   else {
+   if_ref(ifp);
+   } else {
struct in_ifaddr *ia;
struct ifnet *mifp;
 
@@ -1943,6 +1946,7 @@ inp_lookup_mcast_ifp(const struct inpcb *inp,
if (!(mifp->if_flags & IFF_LOOPBACK) &&
 (mifp->if_flags & IFF_MULTICAST)) {
ifp = mifp;
+   if_ref(ifp);
break;
}
}
@@ -1966,6 +1970,7 @@ inp_join_group(struct inpcb *inp, struct sockopt *sopt
struct ip_moptions  *imo;
struct in_multi *inm;
struct in_msource   *lims;
+   struct epoch_tracker et;
int  error, is_new;
 
ifp = NULL;
@@ -1997,9 +2002,10 @@ inp_join_group(struct inpcb *inp, struct sockopt *sopt
if (!IN_MULTICAST(ntohl(gsa->sin.sin_addr.s_addr)))
return (EINVAL);
 
+   NET_EPOCH_ENTER(et);
if (sopt->sopt_valsize == sizeof(struct ip_mreqn) &&
mreqn.imr_ifindex != 0)
-   ifp = ifnet_byindex(mreqn.imr_ifindex);
+   ifp = ifnet_byindex_ref(mreqn.imr_ifindex);
else
ifp = inp_lookup_mcast_ifp(inp, >sin,
mreqn.imr_address);
@@ -2023,6 +2029,7 @@ inp_join_group(struct inpcb *inp, struct sockopt *sopt
 
ssa->sin.sin_addr = mreqs.imr_sourceaddr;
 
+   NET_EPOCH_ENTER(et);
ifp = inp_lookup_mcast_ifp(inp, >sin,
mreqs.imr_interface);
CTR3(KTR_IGMPV3, "%s: imr_interface = 0x%08x, ifp = %p",
@@ -2065,7 +2072,8 @@ inp_join_group(struct inpcb *inp, struct sockopt *sopt
 
if (gsr.gsr_interface == 0 || V_if_index < gsr.gsr_interface)
return (EADDRNOTAVAIL);
-   ifp = ifnet_byindex(gsr.gsr_interface);
+   NET_EPOCH_ENTER(et);
+   ifp = ifnet_byindex_ref(gsr.gsr_interface);
break;
 
default:
@@ -2074,9 +2082,13 @@ inp_join_group(struct inpcb *inp, struct sockopt *sopt
return (EOPNOTSUPP);
break;
}
+   NET_EPOCH_EXIT(et);
 
-   if (ifp == NULL || (ifp->if_flags & IFF_MULTICAST) == 0)
+   if (ifp == NULL || (ifp->if_flags & IFF_MULTICAST) == 0) {
+   if (ifp != NULL)
+   if_rele(ifp);
return (EADDRNOTAVAIL);
+   }
 
IN_MULTI_LOCK();
 
@@ -2265,6 +2277,7 @@ out_inp_unlocked:
}
ip_mfilter_free(imf);
}
+   if_rele(ifp);
return (error);
 }
 
@@ -2740,7 +2753,6 @@ inp_setmoptions(struct inpcb *inp, struct sockopt *sop
 {
struct ip_moptions  *imo;
int  error;
-   struct epoch_trackeret;
 
error = 0;
 
@@ -2847,9 +2859,7 @@ inp_setmoptions(struct inpcb *inp, struct sockopt *sop
case IP_ADD_SOURCE_MEMBERSHIP:
case 

Re: svn commit: r366372 - in head/sys: compat/linuxkpi/common/include/linux compat/linuxkpi/common/src conf

2020-10-17 Thread Alexander V . Chernikov


___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r366372 - in head/sys: compat/linuxkpi/common/include/linux compat/linuxkpi/common/src conf

2020-10-17 Thread Alexander V . Chernikov


___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r366372 - in head/sys: compat/linuxkpi/common/include/linux compat/linuxkpi/common/src conf

2020-10-17 Thread Alexander V . Chernikov


___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r366773 - in head/tests/sys: netinet netinet6

2020-10-16 Thread Alexander V. Chernikov
Author: melifaro
Date: Fri Oct 16 21:51:17 2020
New Revision: 366773
URL: https://svnweb.freebsd.org/changeset/base/366773

Log:
  Try to enable multipath routing in flowid tests.

Modified:
  head/tests/sys/netinet/output.sh
  head/tests/sys/netinet6/output6.sh

Modified: head/tests/sys/netinet/output.sh
==
--- head/tests/sys/netinet/output.shFri Oct 16 20:57:41 2020
(r366772)
+++ head/tests/sys/netinet/output.shFri Oct 16 21:51:17 2020
(r366773)
@@ -223,11 +223,19 @@ output_raw_success_cleanup()
 
 mpath_check()
 {
-   if [ "`sysctl -i -n net.route.multipath`" != 1 ]; then
+   if [ `sysctl -iW net.route.multipath | wc -l` != "1" ]; then
atf_skip "This test requires ROUTE_MPATH enabled"
fi
 }
 
+mpath_enable()
+{
+   jexec $1 sysctl net.route.multipath=1
+   if [ $? != 0 ]; then
+   atf_fail "Setting multipath in jail $1 failed".
+   fi
+}
+
 atf_test_case "output_tcp_flowid_mpath_success" "cleanup"
 output_tcp_flowid_mpath_success_head()
 {
@@ -258,6 +266,7 @@ output_tcp_flowid_mpath_success_body()
lo_dst=$(vnet_mkloopback)
 
vnet_mkjail ${jname}a ${epair0}a ${epair1}a ${lo_src}
+   mpath_enable ${jname}a
# Setup transit IPv4 networks
jexec ${jname}a ifconfig ${epair0}a up
jexec ${jname}a ifconfig ${epair0}a inet 203.0.113.1/30
@@ -386,6 +395,7 @@ output_udp_flowid_mpath_success_body()
lo_dst=$(vnet_mkloopback)
 
vnet_mkjail ${jname}a ${epair0}a ${epair1}a ${lo_src}
+   mpath_enable ${jname}a
# Setup transit IPv4 networks
jexec ${jname}a ifconfig ${epair0}a up
jexec ${jname}a ifconfig ${epair0}a inet 203.0.113.1/30
@@ -509,6 +519,7 @@ output_raw_flowid_mpath_success_body()
lo_dst=$(vnet_mkloopback)
 
vnet_mkjail ${jname}a ${epair0}a ${epair1}a ${lo_src}
+   mpath_enable ${jname}a
# Setup transit IPv4 networks
jexec ${jname}a ifconfig ${epair0}a up
jexec ${jname}a ifconfig ${epair0}a inet 203.0.113.1/30

Modified: head/tests/sys/netinet6/output6.sh
==
--- head/tests/sys/netinet6/output6.sh  Fri Oct 16 20:57:41 2020
(r366772)
+++ head/tests/sys/netinet6/output6.sh  Fri Oct 16 21:51:17 2020
(r366773)
@@ -247,11 +247,20 @@ output6_raw_success_cleanup()
 
 mpath_check()
 {
-   if [ "`sysctl -i -n net.route.multipath`" != 1 ]; then
+   if [ `sysctl -iW net.route.multipath | wc -l` != "1" ]; then
atf_skip "This test requires ROUTE_MPATH enabled"
fi
 }
 
+mpath_enable()
+{
+   jexec $1 sysctl net.route.multipath=1
+   if [ $? != 0 ]; then
+   atf_fail "Setting multipath in jail $1 failed".
+   fi
+}
+
+
 atf_test_case "output6_tcp_flowid_mpath_success" "cleanup"
 output6_tcp_flowid_mpath_success_head()
 {
@@ -282,6 +291,7 @@ output6_tcp_flowid_mpath_success_body()
lo_dst=$(vnet_mkloopback)
 
vnet_mkjail ${jname}a ${epair0}a ${epair1}a ${lo_src}
+   mpath_enable ${jname}a
jls -N
# enable link-local IPv6
jexec ${jname}a ndp -i ${epair0}a -- -disabled
@@ -422,6 +432,7 @@ output6_udp_flowid_mpath_success_body()
lo_dst=$(vnet_mkloopback)
 
vnet_mkjail ${jname}a ${epair0}a ${epair1}a ${lo_src}
+   mpath_enable ${jname}a
jls -N
# enable link-local IPv6
jexec ${jname}a ndp -i ${epair0}a -- -disabled
@@ -559,6 +570,7 @@ output6_raw_flowid_mpath_success_body()
lo_dst=$(vnet_mkloopback)
 
vnet_mkjail ${jname}a ${epair0}a ${epair1}a ${lo_src}
+   mpath_enable ${jname}a
jls -N
# enable link-local IPv6
jexec ${jname}a ndp -i ${epair0}a -- -disabled
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r366424 - in head: sys/net sys/net/route tests/sys/net/routing

2020-10-04 Thread Alexander V. Chernikov
Author: melifaro
Date: Sun Oct  4 13:24:58 2020
New Revision: 366424
URL: https://svnweb.freebsd.org/changeset/base/366424

Log:
  Fix route flags update during RTM_CHANGE.
  Nexthop lookup was not consireding rt_flags when doing
   structure comparison, which lead to an original nexthop
   selection when changing flags. Fix the case by adding
   rt_flags field into comparison and rearranging nhop_priv
   fields to allow for efficient matching.
  Fix `route change X/Y flags` case - recent changes
   disallowed specifying RTF_GATEWAY flag without actual gateway.
   It turns out, route(8) fills in RTF_GATEWAY by default, unless
   -interface flag is specified. Fix regression by clearing
   RTF_GATEWAY flag instead of failing.
  Fix route flag reporting in RTM_CHANGE messages by explicitly
   updating rtm_flags after operation competion.
  Add IPv4/IPv6 tests for flag-only route changes.

Modified:
  head/sys/net/route/nhop_ctl.c
  head/sys/net/route/nhop_var.h
  head/sys/net/route/route_ctl.c
  head/sys/net/rtsock.c
  head/tests/sys/net/routing/test_rtsock_l3.c

Modified: head/sys/net/route/nhop_ctl.c
==
--- head/sys/net/route/nhop_ctl.c   Sun Oct  4 06:14:51 2020
(r366423)
+++ head/sys/net/route/nhop_ctl.c   Sun Oct  4 13:24:58 2020
(r366424)
@@ -164,8 +164,7 @@ cmp_priv(const struct nhop_priv *_one, const struct nh
if (memcmp(_one->nh, _two->nh, NHOP_END_CMP) != 0)
return (0);
 
-   if ((_one->nh_type != _two->nh_type) ||
-   (_one->nh_family != _two->nh_family))
+   if (memcmp(_one, _two, NH_PRIV_END_CMP) != 0)
return (0);
 
return (1);

Modified: head/sys/net/route/nhop_var.h
==
--- head/sys/net/route/nhop_var.h   Sun Oct  4 06:14:51 2020
(r366423)
+++ head/sys/net/route/nhop_var.h   Sun Oct  4 13:24:58 2020
(r366424)
@@ -74,19 +74,24 @@ struct nh_control {
 /* Control plane-only nhop data */
 struct nhop_object;
 struct nhop_priv {
-   uint32_tnh_idx; /* nexthop index */
+   /* nhop lookup comparison start */
uint8_t nh_family;  /* address family of the lookup 
*/
+   uint8_t spare;
uint16_tnh_type;/* nexthop type */
+   uint32_trt_flags;   /* routing flags for the 
control plane */
+   /* nhop lookup comparison end */
+   uint32_tnh_idx; /* nexthop index */
void*cb_func;   /* function handling additional 
rewrite caps */
u_int   nh_refcnt;  /* number of references, 
refcount(9)  */
u_int   nh_linked;  /* refcount(9), == 2 if linked 
to the list */
-   int rt_flags;   /* routing flags for the 
control plane */
struct nhop_object  *nh;/* backreference to the 
dataplane nhop */
struct nh_control   *nh_control;/* backreference to the rnh */
struct nhop_priv*nh_next;   /* hash table membership */
struct vnet *nh_vnet;   /* vnet nhop belongs to */
struct epoch_contextnh_epoch_ctx;   /* epoch data for nhop */
 };
+
+#defineNH_PRIV_END_CMP (__offsetof(struct nhop_priv, nh_idx))
 
 #defineNH_IS_PINNED(_nh)   ((!NH_IS_NHGRP(_nh)) && \
((_nh)->nh_priv->rt_flags & RTF_PINNED))

Modified: head/sys/net/route/route_ctl.c
==
--- head/sys/net/route/route_ctl.c  Sun Oct  4 06:14:51 2020
(r366423)
+++ head/sys/net/route/route_ctl.c  Sun Oct  4 13:24:58 2020
(r366424)
@@ -733,8 +733,15 @@ rib_change_route(uint32_t fibnum, struct rt_addrinfo *
 
/* Check if updated gateway exists */
if ((info->rti_flags & RTF_GATEWAY) &&
-   (info->rti_info[RTAX_GATEWAY] == NULL))
-   return (EINVAL);
+   (info->rti_info[RTAX_GATEWAY] == NULL)) {
+
+   /*
+* route(8) adds RTF_GATEWAY flag if -interface is not set.
+* Remove RTF_GATEWAY to enforce consistency and maintain
+* compatibility..
+*/
+   info->rti_flags &= ~RTF_GATEWAY;
+   }
 
/*
 * route change is done in multiple steps, with dropping and

Modified: head/sys/net/rtsock.c
==
--- head/sys/net/rtsock.c   Sun Oct  4 06:14:51 2020(r366423)
+++ head/sys/net/rtsock.c   Sun Oct  4 13:24:58 2020(r366424)
@@ -965,6 +965,7 @@ route_output(struct mbuf *m, struct socket *so, ...)
 #endif
nh = rc.rc_nh_new;

svn commit: r366398 - in head/sys/net: . route

2020-10-03 Thread Alexander V. Chernikov
Author: melifaro
Date: Sat Oct  3 14:37:54 2020
New Revision: 366398
URL: https://svnweb.freebsd.org/changeset/base/366398

Log:
  Remove ROUTE_MPATH-related warnings introduced in r366390.
  
  Reported by:  mjg

Modified:
  head/sys/net/route/route_ctl.c
  head/sys/net/rtsock.c

Modified: head/sys/net/route/route_ctl.c
==
--- head/sys/net/route/route_ctl.c  Sat Oct  3 14:01:20 2020
(r366397)
+++ head/sys/net/route/route_ctl.c  Sat Oct  3 14:37:54 2020
(r366398)
@@ -91,7 +91,9 @@ static void rib_notify(struct rib_head *rnh, enum rib_
 struct rib_cmd_info *rc);
 
 static void destroy_subscription_epoch(epoch_context_t ctx);
+#ifdef ROUTE_MPATH
 static bool rib_can_multipath(struct rib_head *rh);
+#endif
 
 /* Per-vnet multipath routing configuration */
 SYSCTL_DECL(_net_route);

Modified: head/sys/net/rtsock.c
==
--- head/sys/net/rtsock.c   Sat Oct  3 14:01:20 2020(r366397)
+++ head/sys/net/rtsock.c   Sat Oct  3 14:37:54 2020(r366398)
@@ -847,6 +847,7 @@ update_rtm_from_rc(struct rt_addrinfo *info, struct rt
return (0);
 }
 
+#ifdef ROUTE_MPATH
 static void
 save_del_notification(struct rib_cmd_info *rc, void *_cbdata)
 {
@@ -864,6 +865,7 @@ save_add_notification(struct rib_cmd_info *rc, void *_
if (rc->rc_cmd == RTM_ADD)
*rc_new = *rc;
 }
+#endif
 
 /*ARGSUSED*/
 static int
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r366390 - in head: sys/conf sys/net sys/net/route sys/netinet sys/netinet6 sys/sys usr.bin/netstat

2020-10-03 Thread Alexander V. Chernikov
+net/route/nhgrp.c  optional route_mpath
+net/route/nhgrp_ctl.c  optional route_mpath
 net/route/nhop.c   standard
 net/route/nhop_ctl.c   standard
 net/route/nhop_utils.c standard

Modified: head/sys/conf/options
==
--- head/sys/conf/options   Sat Oct  3 09:36:33 2020(r366389)
+++ head/sys/conf/options   Sat Oct  3 10:47:17 2020(r366390)
@@ -454,6 +454,7 @@ NFSLOCKD
 PCBGROUP   opt_pcbgroup.h
 PF_DEFAULT_TO_DROP opt_pf.h
 RADIX_MPATHopt_mpath.h
+ROUTE_MPATHopt_route.h
 ROUTETABLESopt_route.h
 RSSopt_rss.h
 SLIP_IFF_OPTS  opt_slip.h

Modified: head/sys/net/radix.c
==
--- head/sys/net/radix.cSat Oct  3 09:36:33 2020(r366389)
+++ head/sys/net/radix.cSat Oct  3 10:47:17 2020(r366390)
@@ -44,10 +44,6 @@
 #include 
 #include 
 #include 
-#include "opt_mpath.h"
-#ifdef RADIX_MPATH
-#include 
-#endif
 #else /* !_KERNEL */
 #include 
 #include 

Modified: head/sys/net/route.c
==
--- head/sys/net/route.cSat Oct  3 09:36:33 2020(r366389)
+++ head/sys/net/route.cSat Oct  3 10:47:17 2020(r366390)
@@ -39,7 +39,6 @@
 #include "opt_inet.h"
 #include "opt_inet6.h"
 #include "opt_mrouting.h"
-#include "opt_mpath.h"
 #include "opt_route.h"
 
 #include 

Modified: head/sys/net/route.h
==
--- head/sys/net/route.hSat Oct  3 09:36:33 2020(r366389)
+++ head/sys/net/route.hSat Oct  3 10:47:17 2020(r366390)
@@ -178,6 +178,7 @@ VNET_DECLARE(u_int, rt_add_addr_allfibs); /* Announce 
  */
 
 /* Consumer-visible nexthop info flags */
+#defineNHF_MULTIPATH   0x0008  /* Nexhop is a nexthop group */
 #defineNHF_REJECT  0x0010  /* RTF_REJECT */
 #defineNHF_BLACKHOLE   0x0020  /* RTF_BLACKHOLE */
 #defineNHF_REDIRECT0x0040  /* RTF_DYNAMIC|RTF_MODIFIED */
@@ -208,6 +209,10 @@ struct rtstat {
uint64_t rts_wildcard;  /* lookups satisfied by a wildcard */
uint64_t rts_nh_idx_alloc_failure;  /* nexthop index alloc failure*/
uint64_t rts_nh_alloc_failure;  /* nexthop allocation failure*/
+   uint64_t rts_add_failure;   /* # of route addition failures */
+   uint64_t rts_add_retry; /* # of route addition retries */
+   uint64_t rts_del_failure;   /* # of route deletion failure */
+   uint64_t rts_del_retry; /* # of route deletion retries */
 };
 
 /*

Added: head/sys/net/route/mpath_ctl.c
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/sys/net/route/mpath_ctl.c  Sat Oct  3 10:47:17 2020
(r366390)
@@ -0,0 +1,165 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
+ * Copyright (c) 2020 Alexander V. Chernikov
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#include "opt_inet.h"
+#include "opt_route.h"
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+
+/*
+ * This file cont

svn commit: r365973 - in head/sys: net net/route netinet netinet6

2020-09-21 Thread Alexander V. Chernikov
Author: melifaro
Date: Mon Sep 21 20:02:26 2020
New Revision: 365973
URL: https://svnweb.freebsd.org/changeset/base/365973

Log:
  Rework part of routing code to reduce difference to D26449.
  
  * Split rt_setmetrics into get_info_weight() and rt_set_expire_info(),
   as these two can be applied at different entities and at different times.
  * Start filling route weight in route change notifications
  * Pass flowid to UDP/raw IP route lookups
  * Rework nd6_subscription_cb() and sysctl_dumpentry() to prepare for the fact
   that rtentry can contain multiple nexthops.
  
  Differential Revision:https://reviews.freebsd.org/D26497

Modified:
  head/sys/net/route.c
  head/sys/net/route.h
  head/sys/net/route/route_ctl.c
  head/sys/net/route/route_var.h
  head/sys/net/rtsock.c
  head/sys/netinet/ip_output.c
  head/sys/netinet6/nd6.c

Modified: head/sys/net/route.c
==
--- head/sys/net/route.cMon Sep 21 19:50:39 2020(r365972)
+++ head/sys/net/route.cMon Sep 21 20:02:26 2020(r365973)
@@ -849,18 +849,6 @@ rt_mpath_unlink(struct rib_head *rnh, struct rt_addrin
 #endif
 
 void
-rt_setmetrics(const struct rt_addrinfo *info, struct rtentry *rt)
-{
-
-   if (info->rti_mflags & RTV_WEIGHT)
-   rt->rt_weight = info->rti_rmx->rmx_weight;
-   /* Kernel -> userland timebase conversion. */
-   if (info->rti_mflags & RTV_EXPIRE)
-   rt->rt_expire = info->rti_rmx->rmx_expire ?
-   info->rti_rmx->rmx_expire - time_second + time_uptime : 0;
-}
-
-void
 rt_maskedcopy(struct sockaddr *src, struct sockaddr *dst, struct sockaddr 
*netmask)
 {
u_char *cp1 = (u_char *)src;

Modified: head/sys/net/route.h
==
--- head/sys/net/route.hMon Sep 21 19:50:39 2020(r365972)
+++ head/sys/net/route.hMon Sep 21 20:02:26 2020(r365973)
@@ -104,6 +104,10 @@ struct rt_metrics {
 /* lle state is exported in rmx_state rt_metrics field */
 #definermx_state   rmx_weight
 
+/* default route weight */
+#defineRT_DEFAULT_WEIGHT   1
+#defineRT_MAX_WEIGHT   16777215/* 3 bytes */
+
 /*
  * Keep a generation count of routing table, incremented on route addition,
  * so we can invalidate caches.  This is accessed without a lock, as precision

Modified: head/sys/net/route/route_ctl.c
==
--- head/sys/net/route/route_ctl.c  Mon Sep 21 19:50:39 2020
(r365972)
+++ head/sys/net/route/route_ctl.c  Mon Sep 21 20:02:26 2020
(r365973)
@@ -175,6 +175,32 @@ get_rnh(uint32_t fibnum, const struct rt_addrinfo *inf
return (rnh);
 }
 
+static int
+get_info_weight(const struct rt_addrinfo *info, uint32_t default_weight)
+{
+   uint32_t weight;
+
+   if (info->rti_mflags & RTV_WEIGHT)
+   weight = info->rti_rmx->rmx_weight;
+   else
+   weight = default_weight;
+   /* Keep upper 1 byte for adm distance purposes */
+   if (weight > RT_MAX_WEIGHT)
+   weight = RT_MAX_WEIGHT;
+
+   return (weight);
+}
+
+static void
+rt_set_expire_info(struct rtentry *rt, const struct rt_addrinfo *info)
+{
+
+   /* Kernel -> userland timebase conversion. */
+   if (info->rti_mflags & RTV_EXPIRE)
+   rt->rt_expire = info->rti_rmx->rmx_expire ?
+   info->rti_rmx->rmx_expire - time_second + time_uptime : 0;
+}
+
 /*
  * Check if specified @gw matches gw data in the nexthop @nh.
  *
@@ -423,10 +449,9 @@ create_rtentry(struct rib_head *rnh, struct rt_addrinf
 * examine the ifa and  ifa->ifa_ifp if it so desires.
 */
ifa = info->rti_ifa;
-   rt->rt_weight = 1;
+   rt->rt_weight = get_info_weight(info, RT_DEFAULT_WEIGHT);
+   rt_set_expire_info(rt, info);
 
-   rt_setmetrics(info, rt);
-
*prt = rt;
return (0);
 }
@@ -815,7 +840,7 @@ change_route_nhop(struct rib_head *rnh, struct rtentry
 
if (rnd->rnd_nhop != NULL) {
/* Changing expiration & nexthop & weight to a new one */
-   rt_setmetrics(info, rt);
+   rt_set_expire_info(rt, info);
rt->rt_nhop = rnd->rnd_nhop;
rt->rt_weight = rnd->rnd_weight;
if (rt->rt_expire > 0)

Modified: head/sys/net/route/route_var.h
==
--- head/sys/net/route/route_var.h  Mon Sep 21 19:50:39 2020
(r365972)
+++ head/sys/net/route/route_var.h  Mon Sep 21 20:02:26 2020
(r365973)
@@ -115,7 +115,6 @@ _Static_assert(__offsetof(struct route, ro_dst) == __o
 struct rib_head *rt_tables_get_rnh(uint32_t table, sa_family_t family);
 void rt_mpath_init_rnh(struct rib_head *rnh);
 int rt_getifa_fib(struct rt_addrinfo 

svn commit: r365930 - in head/sys: net/route netinet netinet6

2020-09-20 Thread Alexander V. Chernikov
Author: melifaro
Date: Sun Sep 20 21:32:52 2020
New Revision: 365930
URL: https://svnweb.freebsd.org/changeset/base/365930

Log:
  Remove unused nhop_ref_any() function.
  Remove "opt_mpath.h" header where not needed.
  
  No functional changes.

Modified:
  head/sys/net/route/nhop_ctl.c
  head/sys/net/route/nhop_utils.c
  head/sys/net/route/route_var.h
  head/sys/netinet/in_proto.c
  head/sys/netinet6/in6_proto.c
  head/sys/netinet6/in6_src.c

Modified: head/sys/net/route/nhop_ctl.c
==
--- head/sys/net/route/nhop_ctl.c   Sun Sep 20 17:28:24 2020
(r365929)
+++ head/sys/net/route/nhop_ctl.c   Sun Sep 20 21:32:52 2020
(r365930)
@@ -691,13 +691,6 @@ nhop_free(struct nhop_object *nh)
_priv->nh_epoch_ctx);
 }
 
-int
-nhop_ref_any(struct nhop_object *nh)
-{
-
-   return (nhop_try_ref_object(nh));
-}
-
 void
 nhop_free_any(struct nhop_object *nh)
 {

Modified: head/sys/net/route/nhop_utils.c
==
--- head/sys/net/route/nhop_utils.c Sun Sep 20 17:28:24 2020
(r365929)
+++ head/sys/net/route/nhop_utils.c Sun Sep 20 21:32:52 2020
(r365930)
@@ -29,7 +29,6 @@
 __FBSDID("$FreeBSD$");
 #include "opt_inet.h"
 #include "opt_route.h"
-#include "opt_mpath.h"
 
 #include 
 #include 

Modified: head/sys/net/route/route_var.h
==
--- head/sys/net/route/route_var.h  Sun Sep 20 17:28:24 2020
(r365929)
+++ head/sys/net/route/route_var.h  Sun Sep 20 21:32:52 2020
(r365930)
@@ -244,7 +244,6 @@ int nhops_init_rib(struct rib_head *rh);
 void nhops_destroy_rib(struct rib_head *rh);
 void nhop_ref_object(struct nhop_object *nh);
 int nhop_try_ref_object(struct nhop_object *nh);
-int nhop_ref_any(struct nhop_object *nh);
 void nhop_free_any(struct nhop_object *nh);
 
 void nhop_set_type(struct nhop_object *nh, enum nhop_type nh_type);

Modified: head/sys/netinet/in_proto.c
==
--- head/sys/netinet/in_proto.c Sun Sep 20 17:28:24 2020(r365929)
+++ head/sys/netinet/in_proto.c Sun Sep 20 21:32:52 2020(r365930)
@@ -39,7 +39,6 @@ __FBSDID("$FreeBSD$");
 #include "opt_inet.h"
 #include "opt_inet6.h"
 #include "opt_sctp.h"
-#include "opt_mpath.h"
 
 #include 
 #include 

Modified: head/sys/netinet6/in6_proto.c
==
--- head/sys/netinet6/in6_proto.c   Sun Sep 20 17:28:24 2020
(r365929)
+++ head/sys/netinet6/in6_proto.c   Sun Sep 20 21:32:52 2020
(r365930)
@@ -70,7 +70,6 @@ __FBSDID("$FreeBSD$");
 #include "opt_ipsec.h"
 #include "opt_ipstealth.h"
 #include "opt_sctp.h"
-#include "opt_mpath.h"
 #include "opt_route.h"
 
 #include 

Modified: head/sys/netinet6/in6_src.c
==
--- head/sys/netinet6/in6_src.c Sun Sep 20 17:28:24 2020(r365929)
+++ head/sys/netinet6/in6_src.c Sun Sep 20 21:32:52 2020(r365930)
@@ -67,8 +67,6 @@ __FBSDID("$FreeBSD$");
 
 #include "opt_inet.h"
 #include "opt_inet6.h"
-#include "opt_mpath.h"
-
 #include 
 #include 
 #include 
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r365925 - head/sys/net/route

2020-09-20 Thread Alexander V. Chernikov
Author: melifaro
Date: Sun Sep 20 12:31:48 2020
New Revision: 365925
URL: https://svnweb.freebsd.org/changeset/base/365925

Log:
  Fix gw updates / flag updates during route changes.
  
  * Zero gw_sdl if switching to interface route - the assumption
   that underlying storage is zeroed is incorrect with route changes.
  * Apply proper flag mask to rte.
  
  Reported by:  vangyzen

Modified:
  head/sys/net/route/nhop_ctl.c
  head/sys/net/route/route_ctl.c

Modified: head/sys/net/route/nhop_ctl.c
==
--- head/sys/net/route/nhop_ctl.c   Sun Sep 20 09:47:28 2020
(r365924)
+++ head/sys/net/route/nhop_ctl.c   Sun Sep 20 12:31:48 2020
(r365925)
@@ -205,6 +205,7 @@ static void
 fill_sdl_from_ifp(struct sockaddr_dl_short *sdl, const struct ifnet *ifp)
 {
 
+   bzero(sdl, sizeof(struct sockaddr_dl_short));
sdl->sdl_family = AF_LINK;
sdl->sdl_len = sizeof(struct sockaddr_dl_short);
sdl->sdl_index = ifp->if_index;
@@ -217,6 +218,8 @@ set_nhop_gw_from_info(struct nhop_object *nh, struct r
struct sockaddr *gw;
 
gw = info->rti_info[RTAX_GATEWAY];
+   KASSERT(gw != NULL, ("gw is NULL"));
+
if (info->rti_flags & RTF_GATEWAY) {
if (gw->sa_len > sizeof(struct sockaddr_in6)) {
DPRINTF("nhop SA size too big: AF %d len %u",
@@ -318,6 +321,9 @@ nhop_create_from_info(struct rib_head *rnh, struct rt_
int error;
 
NET_EPOCH_ASSERT();
+
+   if (info->rti_info[RTAX_GATEWAY] == NULL)
+   return (EINVAL);
 
nh_priv = alloc_nhop_structure();
 

Modified: head/sys/net/route/route_ctl.c
==
--- head/sys/net/route/route_ctl.c  Sun Sep 20 09:47:28 2020
(r365924)
+++ head/sys/net/route/route_ctl.c  Sun Sep 20 12:31:48 2020
(r365925)
@@ -397,7 +397,7 @@ create_rtentry(struct rib_head *rnh, struct rt_addrinf
nhop_free(nh);
return (ENOBUFS);
}
-   rt->rte_flags = RTF_UP | flags;
+   rt->rte_flags = (RTF_UP | flags) & RTE_RT_FLAG_MASK;
rt->rt_nhop = nh;
 
/* Fill in dst */
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r365874 - in head/tests/sys: netinet netinet6

2020-09-18 Thread Alexander V. Chernikov
Author: melifaro
Date: Fri Sep 18 07:27:01 2020
New Revision: 365874
URL: https://svnweb.freebsd.org/changeset/base/365874

Log:
  Use atf_fail instead of exit 1 to indicate mpath tests failure.

Modified:
  head/tests/sys/netinet/output.sh
  head/tests/sys/netinet6/output6.sh

Modified: head/tests/sys/netinet/output.sh
==
--- head/tests/sys/netinet/output.shFri Sep 18 05:54:59 2020
(r365873)
+++ head/tests/sys/netinet/output.shFri Sep 18 07:27:01 2020
(r365874)
@@ -339,11 +339,10 @@ output_tcp_flowid_mpath_success_body()
pkt_0=`jexec ${jname}a netstat -Wf link -I ${epair0}a | head | awk 
'$1!~/^Name/{print$8}'`
pkt_1=`jexec ${jname}a netstat -Wf link -I ${epair1}a | head | awk 
'$1!~/^Name/{print$8}'`
if [ ${pkt_0} -le 10 ]; then
-   echo "Balancing failure: 1: ${pkt_0} 2: ${pkt_1}"
-   exit 1
+   atf_fail "Balancing failure: 1: ${pkt_0} 2: ${pkt_1}"
fi
if [ ${pkt_1} -le 10 ]; then
-   echo "Balancing failure: 1: ${pkt_0} 2: ${pkt_1}"
+   atf_fail "Balancing failure: 1: ${pkt_0} 2: ${pkt_1}"
exit 1
fi
echo "TCP Balancing: 1: ${pkt_0} 2: ${pkt_1}"
@@ -468,12 +467,10 @@ output_udp_flowid_mpath_success_body()
pkt_0=`jexec ${jname}a netstat -Wf link -I ${epair0}a | head | awk 
'$1!~/^Name/{print$8}'`
pkt_1=`jexec ${jname}a netstat -Wf link -I ${epair1}a | head | awk 
'$1!~/^Name/{print$8}'`
if [ ${pkt_0} -le 10 ]; then
-   echo "Balancing failure: 1: ${pkt_0} 2: ${pkt_1}"
-   exit 1
+   atf_fail "Balancing failure: 1: ${pkt_0} 2: ${pkt_1}"
fi
if [ ${pkt_1} -le 10 ]; then
-   echo "Balancing failure: 1: ${pkt_0} 2: ${pkt_1}"
-   exit 1
+   atf_fail "Balancing failure: 1: ${pkt_0} 2: ${pkt_1}"
fi
echo "UDP BALANCING: 1: ${pkt_0} 2: ${pkt_1}"
 }
@@ -561,12 +558,10 @@ output_raw_flowid_mpath_success_body()
jexec ${jname}a netstat -bWf link -I ${epair0}a
jexec ${jname}a netstat -bWf link -I ${epair1}a
if [ ${pkt_0} -le 10 ]; then
-   echo "Balancing failure: 1: ${pkt_0} 2: ${pkt_1}"
-   exit 1
+   atf_fail "Balancing failure: 1: ${pkt_0} 2: ${pkt_1}"
fi
if [ ${pkt_1} -le 10 ]; then
-   echo "Balancing failure: 1: ${pkt_0} 2: ${pkt_1}"
-   exit 1
+   atf_fail "Balancing failure: 1: ${pkt_0} 2: ${pkt_1}"
fi
echo "RAW BALANCING: 1: ${pkt_0} 2: ${pkt_1}"
 }

Modified: head/tests/sys/netinet6/output6.sh
==
--- head/tests/sys/netinet6/output6.sh  Fri Sep 18 05:54:59 2020
(r365873)
+++ head/tests/sys/netinet6/output6.sh  Fri Sep 18 07:27:01 2020
(r365874)
@@ -376,12 +376,10 @@ output6_tcp_flowid_mpath_success_body()
pkt_0=`jexec ${jname}a netstat -Wf link -I ${epair0}a | head | awk 
'$1!~/^Name/{print$8}'`
pkt_1=`jexec ${jname}a netstat -Wf link -I ${epair1}a | head | awk 
'$1!~/^Name/{print$8}'`
if [ ${pkt_0} -le 10 ]; then
-   echo "Balancing failure: 1: ${pkt_0} 2: ${pkt_1}"
-   exit 1
+   atf_fail "Balancing failure: 1: ${pkt_0} 2: ${pkt_1}"
fi
if [ ${pkt_1} -le 10 ]; then
-   echo "Balancing failure: 1: ${pkt_0} 2: ${pkt_1}"
-   exit 1
+   atf_fail "Balancing failure: 1: ${pkt_0} 2: ${pkt_1}"
fi
echo "TCP Balancing: 1: ${pkt_0} 2: ${pkt_1}"
 }
@@ -519,12 +517,10 @@ output6_udp_flowid_mpath_success_body()
pkt_0=`jexec ${jname}a netstat -Wf link -I ${epair0}a | head | awk 
'$1!~/^Name/{print$8}'`
pkt_1=`jexec ${jname}a netstat -Wf link -I ${epair1}a | head | awk 
'$1!~/^Name/{print$8}'`
if [ ${pkt_0} -le 10 ]; then
-   echo "Balancing failure: 1: ${pkt_0} 2: ${pkt_1}"
-   exit 1
+   atf_fail "Balancing failure: 1: ${pkt_0} 2: ${pkt_1}"
fi
if [ ${pkt_1} -le 10 ]; then
-   echo "Balancing failure: 1: ${pkt_0} 2: ${pkt_1}"
-   exit 1
+   atf_fail "Balancing failure: 1: ${pkt_0} 2: ${pkt_1}"
fi
echo "UDP BALANCING: 1: ${pkt_0} 2: ${pkt_1}"
 }
@@ -628,12 +624,10 @@ output6_raw_flowid_mpath_success_body()
jexec ${jname}a netstat -bWf link -I ${epair0}a
jexec ${jname}a netstat -bWf link -I ${epair1}a
if [ ${pkt_0} -le 10 ]; then
-   echo "Balancing failure: 1: ${pkt_0} 2: ${pkt_1}"
-   exit 1
+   atf_fail "Balancing failure: 1: ${pkt_0} 2: ${pkt_1}"
fi
if [ ${pkt_1} -le 10 ]; then
-   echo "Balancing failure: 1: ${pkt_0} 2: ${pkt_1}"
-   exit 1
+   atf_fail "Balancing failure: 1: ${pkt_0} 2: 

svn commit: r365609 - in head/tests/sys: netinet netinet6

2020-09-10 Thread Alexander V. Chernikov
Author: melifaro
Date: Thu Sep 10 19:25:51 2020
New Revision: 365609
URL: https://svnweb.freebsd.org/changeset/base/365609

Log:
  Add basic test for net.fibs dynamic growth.
  
  Reviewed by:  kp
  Differential Revision:https://reviews.freebsd.org/D26382

Added:
  head/tests/sys/netinet/fibs.sh   (contents, props changed)
  head/tests/sys/netinet6/fibs6.sh   (contents, props changed)
Modified:
  head/tests/sys/netinet/Makefile
  head/tests/sys/netinet6/Makefile

Modified: head/tests/sys/netinet/Makefile
==
--- head/tests/sys/netinet/Makefile Thu Sep 10 19:00:17 2020
(r365608)
+++ head/tests/sys/netinet/Makefile Thu Sep 10 19:25:51 2020
(r365609)
@@ -9,7 +9,7 @@ ATF_TESTS_C=ip_reass_test \
so_reuseport_lb_test \
socket_afinet
 
-ATF_TESTS_SH=  carp fibs_test redirect divert forward output lpm
+ATF_TESTS_SH=  carp fibs fibs_test redirect divert forward output lpm
 TEST_METADATA.output+= required_programs="python"
 
 PROGS= udp_dontroute tcp_user_cookie

Added: head/tests/sys/netinet/fibs.sh
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/tests/sys/netinet/fibs.sh  Thu Sep 10 19:25:51 2020
(r365609)
@@ -0,0 +1,73 @@
+#!/usr/bin/env atf-sh
+#-
+# SPDX-License-Identifier: BSD-2-Clause
+#
+# Copyright (c) 2020 Alexander V. Chernikov
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#notice, this list of conditions and the following disclaimer in the
+#documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+# SUCH DAMAGE.
+#
+# $FreeBSD$
+#
+
+. $(atf_get_srcdir)/../common/vnet.subr
+
+atf_test_case "fibs_ifroutes1_success" "cleanup"
+fibs_ifroutes1_success_head()
+{
+
+   atf_set descr 'Test IPv4 routes gets populated in the correct fib'
+   atf_set require.user root
+}
+
+fibs_ifroutes1_success_body()
+{
+
+   vnet_init
+
+   net_dst="192.168.0."
+   jname="v6t-fibs_ifroutes1_success"
+
+   epair=$(vnet_mkepair)
+   vnet_mkjail ${jname}a ${epair}a
+
+   jexec ${jname}a sysctl net.fibs=2
+   
+   jexec ${jname}a ifconfig ${epair}a fib 1
+   jexec ${jname}a ifconfig ${epair}a inet ${net_dst}1/24
+   jexec ${jname}a ifconfig ${epair}a up
+
+   atf_check -s exit:0 -o ignore jexec ${jname}a setfib 1 route -4n get 
${net_dst}0/24
+   atf_check -o match:"interface: lo0" jexec ${jname}a setfib 1 route -4n 
get ${net_dst}1
+   atf_check -o match:"destination: ${net_dst}1" jexec ${jname}a setfib 1 
route -4n get ${net_dst}1
+}
+
+fibs_ifroutes1_success_cleanup()
+{
+   vnet_cleanup
+}
+
+atf_init_test_cases()
+{
+   atf_add_test_case "fibs_ifroutes1_success"
+}
+
+

Modified: head/tests/sys/netinet6/Makefile
==
--- head/tests/sys/netinet6/MakefileThu Sep 10 19:00:17 2020
(r365608)
+++ head/tests/sys/netinet6/MakefileThu Sep 10 19:25:51 2020
(r365609)
@@ -13,7 +13,8 @@ ATF_TESTS_SH= \
divert \
forward6 \
output6 \
-   lpm6
+   lpm6 \
+   fibs6
 TEST_METADATA.output6+=required_programs="python"
 
 ${PACKAGE}FILES+=  exthdr.py

Added: head/tests/sys/netinet6/fibs6.sh
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/tests/sys/netinet6/fibs6.shThu Sep 10 19:25:51 2020
(r365609)
@@ -0,0 +1,92 @@
+#!/usr/bin/

svn commit: r365554 - head/sys/net/route

2020-09-10 Thread Alexander V. Chernikov
Author: melifaro
Date: Thu Sep 10 07:05:31 2020
New Revision: 365554
URL: https://svnweb.freebsd.org/changeset/base/365554

Log:
  Fix RADIX_MPATH build broken by r365521.
  
  Reported by:  jenkins, Hartmann, O. 

Modified:
  head/sys/net/route/route_ctl.c

Modified: head/sys/net/route/route_ctl.c
==
--- head/sys/net/route/route_ctl.c  Thu Sep 10 06:32:25 2020
(r365553)
+++ head/sys/net/route/route_ctl.c  Thu Sep 10 07:05:31 2020
(r365554)
@@ -577,9 +577,11 @@ rt_unlinkrte(struct rib_head *rnh, struct rt_addrinfo 
 */
 #ifdef RADIX_MPATH
info->rti_info[RTAX_GATEWAY] = >gw_sa;
-   if (rt_mpath_capable(rnh))
-   rn = rt_mpath_unlink(rnh, info, rt, perror);
-   else
+   if (rt_mpath_capable(rnh)) {
+   rn = rt_mpath_unlink(rnh, info, rt, );
+   if (error != 0)
+   return (error);
+   } else
 #endif
rn = rnh->rnh_deladdr(info->rti_info[RTAX_DST],
info->rti_info[RTAX_NETMASK], >head);
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r365521 - head/sys/net/route

2020-09-09 Thread Alexander V. Chernikov
Author: melifaro
Date: Wed Sep  9 22:07:54 2020
New Revision: 365521
URL: https://svnweb.freebsd.org/changeset/base/365521

Log:
  Update nexthop handling for route addition/deletion in preparation for mpath.
  
  Currently kernel requests deletion for the certain routes with specified 
gateway,
   but this gateway is not actually checked. With multipath routes, internal 
gateway
   checking becomes mandatory. Add the logic performing this check.
  
  Generalise RTF_PINNED routes to the generic route priorities, simplifying the 
logic.
  
  Add lookup_prefix() function to perform exact match search based on data in 
@info.
  
  Differential Revision:https://reviews.freebsd.org/D26356

Modified:
  head/sys/net/route/route_ctl.c
  head/sys/net/route/route_var.h

Modified: head/sys/net/route/route_ctl.c
==
--- head/sys/net/route/route_ctl.c  Wed Sep  9 22:02:30 2020
(r365520)
+++ head/sys/net/route/route_ctl.c  Wed Sep  9 22:07:54 2020
(r365521)
@@ -86,6 +86,10 @@ static int change_route(struct rib_head *rnh, struct r
 static int change_route_nhop(struct rib_head *rnh, struct rtentry *rt,
 struct rt_addrinfo *info, struct route_nhop_data *rnd,
 struct rib_cmd_info *rc);
+
+static int rt_unlinkrte(struct rib_head *rnh, struct rt_addrinfo *info,
+struct rib_cmd_info *rc);
+
 static void rib_notify(struct rib_head *rnh, enum rib_subscription_type type,
 struct rib_cmd_info *rc);
 
@@ -172,6 +176,141 @@ get_rnh(uint32_t fibnum, const struct rt_addrinfo *inf
 }
 
 /*
+ * Check if specified @gw matches gw data in the nexthop @nh.
+ *
+ * Returns true if matches, false otherwise.
+ */
+static bool
+match_nhop_gw(const struct nhop_object *nh, const struct sockaddr *gw)
+{
+
+   if (nh->gw_sa.sa_family != gw->sa_family)
+   return (false);
+
+   switch (gw->sa_family) {
+   case AF_INET:
+   return (nh->gw4_sa.sin_addr.s_addr ==
+   ((const struct sockaddr_in *)gw)->sin_addr.s_addr);
+   case AF_INET6:
+   {
+   const struct sockaddr_in6 *gw6;
+   gw6 = (const struct sockaddr_in6 *)gw;
+
+   /*
+* Currently (2020-09) IPv6 gws in kernel have their
+* scope embedded. Once this becomes false, this code
+* has to be revisited.
+*/
+   if (IN6_ARE_ADDR_EQUAL(>gw6_sa.sin6_addr,
+   >sin6_addr))
+   return (true);
+   return (false);
+   }
+   case AF_LINK:
+   {
+   const struct sockaddr_dl *sdl;
+   sdl = (const struct sockaddr_dl *)gw;
+   return (nh->gwl_sa.sdl_index == sdl->sdl_index);
+   }
+   default:
+   return (memcmp(>gw_sa, gw, nh->gw_sa.sa_len) == 0);
+   }
+
+   /* NOTREACHED */
+   return (false);
+}
+
+/*
+ * Checks if data in @info matches nexhop @nh.
+ *
+ * Returns 0 on success,
+ * ESRCH if not matched,
+ * ENOENT if filter function returned false
+ */
+int
+check_info_match_nhop(const struct rt_addrinfo *info, const struct rtentry *rt,
+const struct nhop_object *nh)
+{
+   const struct sockaddr *gw = info->rti_info[RTAX_GATEWAY];
+
+   if (info->rti_filter != NULL) {
+   if (info->rti_filter(rt, nh, info->rti_filterdata) == 0)
+   return (ENOENT);
+   else
+   return (0);
+   }
+   if ((gw != NULL) && !match_nhop_gw(nh, gw))
+   return (ESRCH);
+
+   return (0);
+}
+
+/*
+ * Checks if nexhop @nh can be rewritten by data in @info because
+ *  of higher "priority". Currently the only case for such scenario
+ *  is kernel installing interface routes, marked by RTF_PINNED flag.
+ *
+ * Returns:
+ * 1 if @info data has higher priority
+ * 0 if priority is the same
+ * -1 if priority is lower
+ */
+int
+can_override_nhop(const struct rt_addrinfo *info, const struct nhop_object *nh)
+{
+
+   if (info->rti_flags & RTF_PINNED) {
+   return (NH_IS_PINNED(nh)) ? 0 : 1;
+   } else {
+   return (NH_IS_PINNED(nh)) ? -1 : 0;
+   }
+}
+
+/*
+ * Runs exact prefix match based on @dst and @netmask.
+ * Returns matched @rtentry if found or NULL.
+ * If rtentry was found, saves nexthop / weight value into @rnd.
+ */
+static struct rtentry *
+lookup_prefix_bysa(struct rib_head *rnh, const struct sockaddr *dst,
+const struct sockaddr *netmask, struct route_nhop_data *rnd)
+{
+   struct rtentry *rt;
+
+   RIB_LOCK_ASSERT(rnh);
+
+   rt = (struct rtentry *)rnh->rnh_lookup(__DECONST(void *, dst),
+   __DECONST(void *, netmask), >head);
+   if (rt != NULL) {
+   rnd->rnd_nhop = rt->rt_nhop;
+   

Re: svn commit: r364465 - in head/sys: conf net net/route

2020-09-09 Thread Alexander V . Chernikov
09.09.2020, 07:13, "Andriy Gapon" :
> On 09/09/2020 00:50, Alexander V. Chernikov wrote:
>>  08.09.2020, 21:03, "Andriy Gapon" :
>>>  On 22/08/2020 00:34, Alexander V. Chernikov wrote:
>>>>   Author: melifaro
>>>>   Date: Fri Aug 21 21:34:52 2020
>>>>   New Revision: 364465
>>>>   URL: https://svnweb.freebsd.org/changeset/base/364465
>>>>
>>>>   Log:
>>>> Make net.fibs growable.
>>>>
>>>> Allow to dynamically grow the amount of fibs in each vnet.
>>>>
>>>> This change alters current behavior. Currently, if one defines
>>>>  ROUTETABLES > 1 in the kernel config, each vnet will be created
>>>>  with the number of fibs defined in the kernel config.
>>>>  After this commit vnets will be created with fibs=1.
>>>>
>>>> Dynamic net.fibs is not compatible with net.add_addr_allfibs.
>>>>  The plan is to deprecate the latter and make
>>>>  net.add_addr_allfibs=0 default behaviour.
>>>>
>>>> Reviewed by: glebius
>>>> Relnotes: yes
>>>> Differential Revision: https://reviews.freebsd.org/D26062
>>>
>>>  I wonder why no one reported a problem that I am seeing after upgrading 
>>> past
>>>  this revision. Maybe because I do have net.fibs=2 in my loader.conf?
>>  Hi Andriy,
>>
>>  Does r365475 fix the problem for you?
>>  CTLFLAG_RWTUN flag got slipped through the cracks somewhere :-(
>
> I am not sure that it does, I haven't tried it, but I agree with Ryan's 
> comment.
It should.
> In general, I would keep CTLFLAG_RWTUN as the knob is a tunable indeed and 
> some
> tools query that flag.
Thanks for the suggestion, I've updated the params to include CTLFLAG_NOFETCH 
in r365517.
> So, I would like to re-iterate my earlier suggestion to use CTLFLAG_NOFETCH
> paired with explicit TUNABLE_INT_FETCH (which seems to be there already).
>
>>>  The problem -- unfortunately I only have a screenshot -- but it's a page 
>>> fault
>>>  trap in this call chain:
>>>  sysctl_register_all -> sysctl_load_tunable_by_oid_locked -> sysctl_fibs ->
>>>  _sx_xlock.
>>>
>>>  The crash is on the RTABLES_LOCK() line.
>>>  And it's kind of obvious why.
>>>
>>>  The tunables, including net.fibs which is declared as RWTUN, are set at
>>>  SI_SUB_TUNABLES stage, but RTABLES_LOCK_INIT() is not called until
>>>  SI_SUB_PROTO_DOMAIN much later. In other words, sysctal_fibs can be called
>>>  earlier than vnet_rtables_init.
>>>
>>>  I think that the best way to handle the problem would be to add 
>>> CTLFLAG_NOFETCH
>>>  to the sysctl declaration and then to add -- if necessary at all -- an 
>>> explicit
>>>  query of the kenv.
>>>
>>>  --
>>>  Andriy Gapon
>
> --
> Andriy Gapon
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r365517 - head/sys/net/route

2020-09-09 Thread Alexander V. Chernikov
Author: melifaro
Date: Wed Sep  9 21:45:18 2020
New Revision: 365517
URL: https://svnweb.freebsd.org/changeset/base/365517

Log:
  Retain marking net.fibs sysctl as a tunable.
  
  Suggested by: avg

Modified:
  head/sys/net/route/route_tables.c

Modified: head/sys/net/route/route_tables.c
==
--- head/sys/net/route/route_tables.c   Wed Sep  9 21:44:59 2020
(r365516)
+++ head/sys/net/route/route_tables.c   Wed Sep  9 21:45:18 2020
(r365517)
@@ -140,8 +140,8 @@ sysctl_fibs(SYSCTL_HANDLER_ARGS)
return (error);
 }
 SYSCTL_PROC(_net, OID_AUTO, fibs,
-CTLFLAG_VNET | CTLTYPE_U32 | CTLFLAG_MPSAFE, NULL, 0,
-_fibs, "IU",
+CTLFLAG_VNET | CTLTYPE_U32 | CTLFLAG_RWTUN | CTLFLAG_NOFETCH | 
CTLFLAG_MPSAFE,
+NULL, 0, _fibs, "IU",
 "set number of fibs");
 
 /*
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r364465 - in head/sys: conf net net/route

2020-09-08 Thread Alexander V . Chernikov
08.09.2020, 21:03, "Andriy Gapon" :
> On 22/08/2020 00:34, Alexander V. Chernikov wrote:
>>  Author: melifaro
>>  Date: Fri Aug 21 21:34:52 2020
>>  New Revision: 364465
>>  URL: https://svnweb.freebsd.org/changeset/base/364465
>>
>>  Log:
>>    Make net.fibs growable.
>>
>>    Allow to dynamically grow the amount of fibs in each vnet.
>>
>>    This change alters current behavior. Currently, if one defines
>> ROUTETABLES > 1 in the kernel config, each vnet will be created
>> with the number of fibs defined in the kernel config.
>> After this commit vnets will be created with fibs=1.
>>
>>    Dynamic net.fibs is not compatible with net.add_addr_allfibs.
>> The plan is to deprecate the latter and make
>> net.add_addr_allfibs=0 default behaviour.
>>
>>    Reviewed by: glebius
>>    Relnotes: yes
>>    Differential Revision: https://reviews.freebsd.org/D26062
>
> I wonder why no one reported a problem that I am seeing after upgrading past
> this revision. Maybe because I do have net.fibs=2 in my loader.conf?
Hi Andriy,

Does r365475 fix the problem for you?
CTLFLAG_RWTUN flag got slipped through the cracks somewhere :-(

> The problem -- unfortunately I only have a screenshot -- but it's a page fault
> trap in this call chain:
> sysctl_register_all -> sysctl_load_tunable_by_oid_locked -> sysctl_fibs ->
> _sx_xlock.
>
> The crash is on the RTABLES_LOCK() line.
> And it's kind of obvious why.
>
> The tunables, including net.fibs which is declared as RWTUN, are set at
> SI_SUB_TUNABLES stage, but RTABLES_LOCK_INIT() is not called until
> SI_SUB_PROTO_DOMAIN much later. In other words, sysctal_fibs can be called
> earlier than vnet_rtables_init.
>
> I think that the best way to handle the problem would be to add 
> CTLFLAG_NOFETCH
> to the sysctl declaration and then to add -- if necessary at all -- an 
> explicit
> query of the kenv.
>
> --
> Andriy Gapon
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r365475 - head/sys/net/route

2020-09-08 Thread Alexander V . Chernikov
08.09.2020, 22:39, "Alexander V. Chernikov" :
> Author: melifaro
> Date: Tue Sep 8 21:39:34 2020
> New Revision: 365475
> URL: https://svnweb.freebsd.org/changeset/base/365475
>
> Log:
>   Fix panic with net.fibs tunable set in loader.conf.
>
>   Fix by removing forgotten CTLFLAG_RWTUN flag from the sysctl,
>    loader variable will be read later in vnet_rtables_init().
>
>   Reported by: mav
^^ meant to be avg
>
> Modified:
>   head/sys/net/route/route_tables.c
>
> Modified: head/sys/net/route/route_tables.c
> ==
> --- head/sys/net/route/route_tables.c Tue Sep 8 20:53:44 2020 (r365474)
> +++ head/sys/net/route/route_tables.c Tue Sep 8 21:39:34 2020 (r365475)
> @@ -140,7 +140,7 @@ sysctl_fibs(SYSCTL_HANDLER_ARGS)
>  return (error);
>  }
>  SYSCTL_PROC(_net, OID_AUTO, fibs,
> - CTLFLAG_VNET | CTLTYPE_U32 | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, NULL, 0,
> + CTLFLAG_VNET | CTLTYPE_U32 | CTLFLAG_MPSAFE, NULL, 0,
>  _fibs, "IU",
>  "set number of fibs");
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r365475 - head/sys/net/route

2020-09-08 Thread Alexander V. Chernikov
Author: melifaro
Date: Tue Sep  8 21:39:34 2020
New Revision: 365475
URL: https://svnweb.freebsd.org/changeset/base/365475

Log:
  Fix panic with net.fibs tunable set in loader.conf.
  
  Fix by removing forgotten CTLFLAG_RWTUN flag from the sysctl,
   loader variable will be read later in vnet_rtables_init().
  
  Reported by:  mav

Modified:
  head/sys/net/route/route_tables.c

Modified: head/sys/net/route/route_tables.c
==
--- head/sys/net/route/route_tables.c   Tue Sep  8 20:53:44 2020
(r365474)
+++ head/sys/net/route/route_tables.c   Tue Sep  8 21:39:34 2020
(r365475)
@@ -140,7 +140,7 @@ sysctl_fibs(SYSCTL_HANDLER_ARGS)
return (error);
 }
 SYSCTL_PROC(_net, OID_AUTO, fibs,
-CTLFLAG_VNET | CTLTYPE_U32 | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, NULL, 0,
+CTLFLAG_VNET | CTLTYPE_U32 | CTLFLAG_MPSAFE, NULL, 0,
 _fibs, "IU",
 "set number of fibs");
 
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r365404 - head/sys/net

2020-09-07 Thread Alexander V. Chernikov
Author: melifaro
Date: Mon Sep  7 10:13:54 2020
New Revision: 365404
URL: https://svnweb.freebsd.org/changeset/base/365404

Log:
  Consistently use the same gateway when adding/deleting interface routes.
  
  Use the same link-level gateway when adding or deleting interface routes.
  This helps nexthop checking in the upcoming multipath changes.
  
  Differential Revision:https://reviews.freebsd.org/D26317

Modified:
  head/sys/net/route.c

Modified: head/sys/net/route.c
==
--- head/sys/net/route.cMon Sep  7 07:44:14 2020(r365403)
+++ head/sys/net/route.cMon Sep  7 10:13:54 2020(r365404)
@@ -883,7 +883,6 @@ rt_maskedcopy(struct sockaddr *src, struct sockaddr *d
  * Set up a routing table entry, normally
  * for an interface.
  */
-#define _SOCKADDR_TMPSIZE 128 /* Not too big.. kernel stack size is limited */
 static inline  int
 rtinit1(struct ifaddr *ifa, int cmd, int flags, int fibnum)
 {
@@ -895,10 +894,10 @@ rtinit1(struct ifaddr *ifa, int cmd, int flags, int fi
struct rt_addrinfo info;
int error = 0;
int startfib, endfib;
-   char tempbuf[_SOCKADDR_TMPSIZE];
+   struct sockaddr_storage ss;
int didwork = 0;
int a_failure = 0;
-   struct sockaddr_dl_short *sdl = NULL;
+   struct sockaddr_dl_short sdl;
struct rib_head *rnh;
 
if (flags & RTF_HOST) {
@@ -946,17 +945,15 @@ rtinit1(struct ifaddr *ifa, int cmd, int flags, int fi
 * XXX this is kinda inet specific..
 */
if (netmask != NULL) {
-   rt_maskedcopy(dst, (struct sockaddr *)tempbuf, netmask);
-   dst = (struct sockaddr *)tempbuf;
+   rt_maskedcopy(dst, (struct sockaddr *), netmask);
+   dst = (struct sockaddr *)
}
-   } else if (cmd == RTM_ADD) {
-   sdl = (struct sockaddr_dl_short *)tempbuf;
-   bzero(sdl, sizeof(struct sockaddr_dl_short));
-   sdl->sdl_family = AF_LINK;
-   sdl->sdl_len = sizeof(struct sockaddr_dl_short);
-   sdl->sdl_type = ifa->ifa_ifp->if_type;
-   sdl->sdl_index = ifa->ifa_ifp->if_index;
-}
+   }
+   bzero(, sizeof(struct sockaddr_dl_short));
+   sdl.sdl_family = AF_LINK;
+   sdl.sdl_len = sizeof(struct sockaddr_dl_short);
+   sdl.sdl_type = ifa->ifa_ifp->if_type;
+   sdl.sdl_index = ifa->ifa_ifp->if_index;
/*
 * Now go through all the requested tables (fibs) and do the
 * requested action. Realistically, this will either be fib 0
@@ -1012,13 +1009,7 @@ rtinit1(struct ifaddr *ifa, int cmd, int flags, int fi
info.rti_flags = flags |
(ifa->ifa_flags & ~IFA_RTSELF) | RTF_PINNED;
info.rti_info[RTAX_DST] = dst;
-   /* 
-* doing this for compatibility reasons
-*/
-   if (cmd == RTM_ADD)
-   info.rti_info[RTAX_GATEWAY] = (struct sockaddr *)sdl;
-   else
-   info.rti_info[RTAX_GATEWAY] = ifa->ifa_addr;
+   info.rti_info[RTAX_GATEWAY] = (struct sockaddr *)
info.rti_info[RTAX_NETMASK] = netmask;
NET_EPOCH_ENTER(et);
error = rib_action(fibnum, cmd, , );
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r365315 - head/sys/net/route

2020-09-03 Thread Alexander V. Chernikov
Author: melifaro
Date: Thu Sep  3 22:24:52 2020
New Revision: 365315
URL: https://svnweb.freebsd.org/changeset/base/365315

Log:
  Fix regression for IPv6 loopback routes.
  
  After nexthop introduction, loopback routes for the interface addresses
   were created without embedding actual interface index in the gateway.
   The latter is needed to pass the IPv6 scope during transmission via 
loopback..
  
  Fix the regression by actually using passed gateway data with interface index.
  
  Differential Revision:https://reviews.freebsd.org/D26306

Modified:
  head/sys/net/route/nhop_ctl.c

Modified: head/sys/net/route/nhop_ctl.c
==
--- head/sys/net/route/nhop_ctl.c   Thu Sep  3 22:20:27 2020
(r365314)
+++ head/sys/net/route/nhop_ctl.c   Thu Sep  3 22:24:52 2020
(r365315)
@@ -225,6 +225,7 @@ set_nhop_gw_from_info(struct nhop_object *nh, struct r
}
memcpy(>gw_sa, gw, gw->sa_len);
} else {
+
/*
 * Interface route. Currently the route.c code adds
 * sa of type AF_LINK, which is 56 bytes long. The only
@@ -235,7 +236,21 @@ set_nhop_gw_from_info(struct nhop_object *nh, struct r
 * in the separate field (nh_aifp, see below), write AF_LINK
 * compatible sa with shorter total length.
 */
-   fill_sdl_from_ifp(>gwl_sa, nh->nh_ifp);
+   struct sockaddr_dl *sdl;
+   struct ifnet *ifp;
+
+   /* Fetch and validate interface index */
+   sdl = (struct sockaddr_dl *)gw;
+   if (sdl->sdl_family != AF_LINK) {
+   DPRINTF("unsupported AF: %d", sdl->sdl_family);
+   return (ENOTSUP);
+   }
+   ifp = ifnet_byindex(sdl->sdl_index);
+   if (ifp == NULL) {
+   DPRINTF("invalid ifindex %d", sdl->sdl_index);
+   return (EINVAL);
+   }
+   fill_sdl_from_ifp(>gwl_sa, ifp);
}
 
return (0);
@@ -272,12 +287,13 @@ fill_nhop_from_info(struct nhop_priv *nh_priv, struct 
 
nh->nh_flags = convert_rt_to_nh_flags(rt_flags);
set_nhop_mtu_from_info(nh, info);
+   if ((error = set_nhop_gw_from_info(nh, info)) != 0)
+   return (error);
+
nh->nh_ifp = info->rti_ifa->ifa_ifp;
nh->nh_ifa = info->rti_ifa;
+   /* depends on the gateway */
nh->nh_aifp = get_aifp(nh, 0);
-
-   if ((error = set_nhop_gw_from_info(nh, info)) != 0)
-   return (error);
 
/*
 * Note some of the remaining data is set by the
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r364954 - head/sys/net/route

2020-08-29 Thread Alexander V. Chernikov
Author: melifaro
Date: Sat Aug 29 12:04:13 2020
New Revision: 364954
URL: https://svnweb.freebsd.org/changeset/base/364954

Log:
  Revert uma zone alignemnt cache unadvertenly committed in r364950.

Modified:
  head/sys/net/route/route_ctl.c

Modified: head/sys/net/route/route_ctl.c
==
--- head/sys/net/route/route_ctl.c  Sat Aug 29 11:46:50 2020
(r364953)
+++ head/sys/net/route/route_ctl.c  Sat Aug 29 12:04:13 2020
(r364954)
@@ -101,7 +101,7 @@ vnet_rtzone_init()
 {

V_rtzone = uma_zcreate("rtentry", sizeof(struct rtentry),
-   NULL, NULL, NULL, NULL, UMA_ALIGN_CACHE, 0);
+   NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, 0);
 }
 
 #ifdef VIMAGE
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r364950 - head/sys/net/route

2020-08-29 Thread Alexander V. Chernikov
Author: melifaro
Date: Sat Aug 29 11:04:24 2020
New Revision: 364950
URL: https://svnweb.freebsd.org/changeset/base/364950

Log:
  Fix build with RADIX_MPATH.
  
  Reported by:  Hartmann, O 

Modified:
  head/sys/net/route/route_ctl.c

Modified: head/sys/net/route/route_ctl.c
==
--- head/sys/net/route/route_ctl.c  Sat Aug 29 09:59:52 2020
(r364949)
+++ head/sys/net/route/route_ctl.c  Sat Aug 29 11:04:24 2020
(r364950)
@@ -101,7 +101,7 @@ vnet_rtzone_init()
 {

V_rtzone = uma_zcreate("rtentry", sizeof(struct rtentry),
-   NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, 0);
+   NULL, NULL, NULL, NULL, UMA_ALIGN_CACHE, 0);
 }
 
 #ifdef VIMAGE
@@ -310,6 +310,7 @@ add_route(struct rib_head *rnh, struct rt_addrinfo *in
 
RIB_WLOCK(rnh);
 #ifdef RADIX_MPATH
+   netmask = info->rti_info[RTAX_NETMASK];
/* do not permit exactly the same dst/mask/gw pair */
if (rt_mpath_capable(rnh) &&
rt_mpath_conflict(rnh, rt, netmask)) {
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r364942 - head/sys/net/route

2020-08-28 Thread Alexander V. Chernikov
Author: melifaro
Date: Fri Aug 28 23:01:56 2020
New Revision: 364942
URL: https://svnweb.freebsd.org/changeset/base/364942

Log:
  Move fib_rte_to_nh_flags() from net/route_var.h to net/route/nhop_ctl.c.
  
  No functional changes.
  Initially this function was created to perform runtime flag conversions
   for the previous incarnation of fib lookup functions. As these functions
   got deprecated, move the function to the file with the only remaining
   caller. Lastly, rename it to convert_rt_to_nh_flags() to follow the
   naming notation.

Modified:
  head/sys/net/route/nhop_ctl.c
  head/sys/net/route/route_var.h

Modified: head/sys/net/route/nhop_ctl.c
==
--- head/sys/net/route/nhop_ctl.c   Fri Aug 28 22:50:20 2020
(r364941)
+++ head/sys/net/route/nhop_ctl.c   Fri Aug 28 23:01:56 2020
(r364942)
@@ -244,6 +244,21 @@ set_nhop_gw_from_info(struct nhop_object *nh, struct r
return (0);
 }
 
+static uint16_t
+convert_rt_to_nh_flags(int rt_flags)
+{
+   uint16_t res;
+
+   res = (rt_flags & RTF_REJECT) ? NHF_REJECT : 0;
+   res |= (rt_flags & RTF_HOST) ? NHF_HOST : 0;
+   res |= (rt_flags & RTF_BLACKHOLE) ? NHF_BLACKHOLE : 0;
+   res |= (rt_flags & (RTF_DYNAMIC|RTF_MODIFIED)) ? NHF_REDIRECT : 0;
+   res |= (rt_flags & RTF_BROADCAST) ? NHF_BROADCAST : 0;
+   res |= (rt_flags & RTF_GATEWAY) ? NHF_GATEWAY : 0;
+
+   return (res);
+}
+
 static int
 fill_nhop_from_info(struct nhop_priv *nh_priv, struct rt_addrinfo *info)
 {
@@ -258,7 +273,7 @@ fill_nhop_from_info(struct nhop_priv *nh_priv, struct 
nh_priv->nh_family = info->rti_info[RTAX_DST]->sa_family;
nh_priv->nh_type = 0; // hook responsibility to set nhop type
 
-   nh->nh_flags = fib_rte_to_nh_flags(rt_flags);
+   nh->nh_flags = convert_rt_to_nh_flags(rt_flags);
set_nhop_mtu_from_info(nh, info);
nh->nh_ifp = info->rti_ifa->ifa_ifp;
nh->nh_ifa = info->rti_ifa;
@@ -397,7 +412,7 @@ alter_nhop_from_info(struct nhop_object *nh, struct rt
nh->nh_priv->rt_flags |= (RTF_GATEWAY & info->rti_flags);
}
/* Update datapath flags */
-   nh->nh_flags = fib_rte_to_nh_flags(nh->nh_priv->rt_flags);
+   nh->nh_flags = convert_rt_to_nh_flags(nh->nh_priv->rt_flags);
 
if (info->rti_ifa != NULL)
nh->nh_ifa = info->rti_ifa;

Modified: head/sys/net/route/route_var.h
==
--- head/sys/net/route/route_var.h  Fri Aug 28 22:50:20 2020
(r364941)
+++ head/sys/net/route/route_var.h  Fri Aug 28 23:01:56 2020
(r364942)
@@ -212,22 +212,6 @@ struct rtentry {
((!NH_IS_MULTIPATH(_nh)) ? (_nh) : _SELECT_NHOP(_nh, _flowid))
 #defineRT_SELECT_NHOP(_rt, _flowid)_RT_SELECT_NHOP((_rt)->rt_nhop, 
_flowid)
  
-/* rte<>nhop translation */
-static inline uint16_t
-fib_rte_to_nh_flags(int rt_flags)
-{
-   uint16_t res;
-
-   res = (rt_flags & RTF_REJECT) ? NHF_REJECT : 0;
-   res |= (rt_flags & RTF_HOST) ? NHF_HOST : 0;
-   res |= (rt_flags & RTF_BLACKHOLE) ? NHF_BLACKHOLE : 0;
-   res |= (rt_flags & (RTF_DYNAMIC|RTF_MODIFIED)) ? NHF_REDIRECT : 0;
-   res |= (rt_flags & RTF_BROADCAST) ? NHF_BROADCAST : 0;
-   res |= (rt_flags & RTF_GATEWAY) ? NHF_GATEWAY : 0;
-
-   return (res);
-}
-
 /* route_temporal.c */
 void tmproutes_update(struct rib_head *rnh, struct rtentry *rt);
 void tmproutes_init(struct rib_head *rh);
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r364941 - in head/sys: net net/route netinet netinet6

2020-08-28 Thread Alexander V. Chernikov
Author: melifaro
Date: Fri Aug 28 22:50:20 2020
New Revision: 364941
URL: https://svnweb.freebsd.org/changeset/base/364941

Log:
  Move net/route/shared.h definitions to net/route/route_var.h.
  
  No functional changes.
  
  net/route/shared.h was created in the inital phases of nexthop conversion.
  It was intended to serve the same purpose as route_var.h - share definitions
   of functions and structures between the routing subsystem components. At
   that time route_var.h was included by many files external to the routing
   subsystem, which largerly defeats its purpose.
  
  As currently this is not the case anymore and amount of route_var.h includes
   is roughly the same as shared.h, retire the latter in favour of the former.

Deleted:
  head/sys/net/route/shared.h
Modified:
  head/sys/net/radix_mpath.c
  head/sys/net/route.c
  head/sys/net/route/nhop.c
  head/sys/net/route/nhop_ctl.c
  head/sys/net/route/route_ctl.c
  head/sys/net/route/route_helpers.c
  head/sys/net/route/route_var.h
  head/sys/net/rtsock.c
  head/sys/netinet/in_fib.c
  head/sys/netinet/in_rmx.c
  head/sys/netinet6/in6_fib.c
  head/sys/netinet6/in6_rmx.c

Modified: head/sys/net/radix_mpath.c
==
--- head/sys/net/radix_mpath.c  Fri Aug 28 21:59:10 2020(r364940)
+++ head/sys/net/radix_mpath.c  Fri Aug 28 22:50:20 2020(r364941)
@@ -56,7 +56,6 @@ __FBSDID("$FreeBSD$");
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 

Modified: head/sys/net/route.c
==
--- head/sys/net/route.cFri Aug 28 21:59:10 2020(r364940)
+++ head/sys/net/route.cFri Aug 28 22:50:20 2020(r364941)
@@ -64,7 +64,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 
 #ifdef RADIX_MPATH

Modified: head/sys/net/route/nhop.c
==
--- head/sys/net/route/nhop.c   Fri Aug 28 21:59:10 2020(r364940)
+++ head/sys/net/route/nhop.c   Fri Aug 28 22:50:20 2020(r364941)
@@ -46,7 +46,6 @@ __FBSDID("$FreeBSD$");
 #include 
 #include 
 #include 
-#include 
 #include 
 
 /*

Modified: head/sys/net/route/nhop_ctl.c
==
--- head/sys/net/route/nhop_ctl.c   Fri Aug 28 21:59:10 2020
(r364940)
+++ head/sys/net/route/nhop_ctl.c   Fri Aug 28 22:50:20 2020
(r364941)
@@ -49,7 +49,6 @@ __FBSDID("$FreeBSD$");
 #include 
 #include 
 #include 
-#include 
 #include 
 
 /*

Modified: head/sys/net/route/route_ctl.c
==
--- head/sys/net/route/route_ctl.c  Fri Aug 28 21:59:10 2020
(r364940)
+++ head/sys/net/route/route_ctl.c  Fri Aug 28 22:50:20 2020
(r364941)
@@ -52,7 +52,6 @@ __FBSDID("$FreeBSD$");
 #include 
 #include 
 #include 
-#include 
 #include 
 
 #ifdef RADIX_MPATH

Modified: head/sys/net/route/route_helpers.c
==
--- head/sys/net/route/route_helpers.c  Fri Aug 28 21:59:10 2020
(r364940)
+++ head/sys/net/route/route_helpers.c  Fri Aug 28 22:50:20 2020
(r364941)
@@ -55,7 +55,6 @@ __FBSDID("$FreeBSD$");
 #include 
 #include 
 #include 
-#include 
 #ifdef INET
 #include 
 #endif

Modified: head/sys/net/route/route_var.h
==
--- head/sys/net/route/route_var.h  Fri Aug 28 21:59:10 2020
(r364940)
+++ head/sys/net/route/route_var.h  Fri Aug 28 22:50:20 2020
(r364941)
@@ -39,7 +39,14 @@
 #include 
 #include /* struct sockaddr_in */
 #include 
+#include 
 
+#ifdef RTDEBUG
+#defineDPRINTF(_fmt, ...)  printf("%s: " _fmt "\n", __func__ , ## 
__VA_ARGS__)
+#else
+#defineDPRINTF(_fmt, ...)
+#endif
+
 struct nh_control;
 typedef int rnh_preadd_entry_f_t(u_int fibnum, const struct sockaddr *addr,
const struct sockaddr *mask, struct nhop_object *nh);
@@ -221,6 +228,7 @@ fib_rte_to_nh_flags(int rt_flags)
return (res);
 }
 
+/* route_temporal.c */
 void tmproutes_update(struct rib_head *rnh, struct rtentry *rt);
 void tmproutes_init(struct rib_head *rh);
 void tmproutes_destroy(struct rib_head *rh);
@@ -236,5 +244,33 @@ int change_route_conditional(struct rib_head *rnh, str
 
 void vnet_rtzone_init(void);
 void vnet_rtzone_destroy(void);
+
+/* subscriptions */
+void rib_init_subscriptions(struct rib_head *rnh);
+void rib_destroy_subscriptions(struct rib_head *rnh);
+
+/* Nexhops */
+void nhops_init(void);
+int nhops_init_rib(struct rib_head *rh);
+void nhops_destroy_rib(struct rib_head *rh);
+void nhop_ref_object(struct nhop_object *nh);
+int nhop_try_ref_object(struct nhop_object *nh);
+int nhop_ref_any(struct nhop_object *nh);
+void nhop_free_any(struct 

svn commit: r364940 - head/sys/net/route

2020-08-28 Thread Alexander V. Chernikov
Author: melifaro
Date: Fri Aug 28 21:59:10 2020
New Revision: 364940
URL: https://svnweb.freebsd.org/changeset/base/364940

Log:
  Further split nhop creation and rtable operations.
  
  As nexthops are immutable, some operations such as route attribute changes
   require nexthop fetching, forking, modification and route switching.
  These operations are not atomic, so they may need to be retried multiple
   times in presence of multiple speakers changing the same route.
  
  This change introduces "synchronisation" primitive: 
route_update_conditional(),
   simplifying logic for route changes and upcoming multipath operations.
  
  Differential Revision:https://reviews.freebsd.org/D26216

Modified:
  head/sys/net/route/route_ctl.c
  head/sys/net/route/route_var.h

Modified: head/sys/net/route/route_ctl.c
==
--- head/sys/net/route/route_ctl.c  Fri Aug 28 20:37:57 2020
(r364939)
+++ head/sys/net/route/route_ctl.c  Fri Aug 28 21:59:10 2020
(r364940)
@@ -78,9 +78,15 @@ struct rib_subscription {
 
 static int add_route(struct rib_head *rnh, struct rt_addrinfo *info,
 struct rib_cmd_info *rc);
+static int add_route_nhop(struct rib_head *rnh, struct rtentry *rt,
+struct rt_addrinfo *info, struct route_nhop_data *rnd,
+struct rib_cmd_info *rc);
 static int del_route(struct rib_head *rnh, struct rt_addrinfo *info,
 struct rib_cmd_info *rc);
-static int change_route(struct rib_head *, struct rt_addrinfo *,
+static int change_route(struct rib_head *rnh, struct rt_addrinfo *info,
+struct route_nhop_data *nhd_orig, struct rib_cmd_info *rc);
+static int change_route_nhop(struct rib_head *rnh, struct rtentry *rt,
+struct rt_addrinfo *info, struct route_nhop_data *rnd,
 struct rib_cmd_info *rc);
 static void rib_notify(struct rib_head *rnh, enum rib_subscription_type type,
 struct rib_cmd_info *rc);
@@ -202,14 +208,18 @@ rib_add_route(uint32_t fibnum, struct rt_addrinfo *inf
return (add_route(rnh, info, rc));
 }
 
+/*
+ * Creates rtentry and nexthop based on @info data.
+ * Return 0 and fills in rtentry into @prt on success,
+ * return errno otherwise.
+ */
 static int
-add_route(struct rib_head *rnh, struct rt_addrinfo *info,
-struct rib_cmd_info *rc)
+create_rtentry(struct rib_head *rnh, struct rt_addrinfo *info,
+struct rtentry **prt)
 {
struct sockaddr *dst, *ndst, *gateway, *netmask;
-   struct rtentry *rt, *rt_old;
+   struct rtentry *rt;
struct nhop_object *nh;
-   struct radix_node *rn;
struct ifaddr *ifa;
int error, flags;
 
@@ -276,8 +286,29 @@ add_route(struct rib_head *rnh, struct rt_addrinfo *in
rt->rt_weight = 1;
 
rt_setmetrics(info, rt);
-   rt_old = NULL;
 
+   *prt = rt;
+   return (0);
+}
+
+static int
+add_route(struct rib_head *rnh, struct rt_addrinfo *info,
+struct rib_cmd_info *rc)
+{
+   struct sockaddr *ndst, *netmask;
+   struct route_nhop_data rnd;
+   struct nhop_object *nh;
+   struct rtentry *rt;
+   int error;
+
+   error = create_rtentry(rnh, info, );
+   if (error != 0)
+   return (error);
+
+   rnd.rnd_nhop = rt->rt_nhop;
+   rnd.rnd_weight = rt->rt_weight;
+   nh = rt->rt_nhop;
+
RIB_WLOCK(rnh);
 #ifdef RADIX_MPATH
/* do not permit exactly the same dst/mask/gw pair */
@@ -290,76 +321,42 @@ add_route(struct rib_head *rnh, struct rt_addrinfo *in
return (EEXIST);
}
 #endif
+   error = add_route_nhop(rnh, rt, info, , rc);
+   if (error == 0) {
+   rt = NULL;
+   nh = NULL;
+   } else if ((error == EEXIST) && ((info->rti_flags & RTF_PINNED) != 0)) {
+   struct rtentry *rt_orig;
+   struct nhop_object *nh_orig;
+   struct radix_node *rn;
 
-   rn = rnh->rnh_addaddr(ndst, netmask, >head, rt->rt_nodes);
-
-   if (rn != NULL) {
-   /* Most common usecase */
-   if (rt->rt_expire > 0)
-   tmproutes_update(rnh, rt);
-
-   /* Finalize notification */
-   rnh->rnh_gen++;
-
-   rc->rc_rt = rt;
-   rc->rc_nh_new = nh;
-   rc->rc_nh_weight = rt->rt_weight;
-
-   rib_notify(rnh, RIB_NOTIFY_IMMEDIATE, rc);
-   } else if ((info->rti_flags & RTF_PINNED) != 0) {
-
-   /*
-* Force removal and re-try addition
-* TODO: better multipath support
-*/
-   struct sockaddr *info_dst = info->rti_info[RTAX_DST];
-   info->rti_info[RTAX_DST] = ndst;
-   /* Do not delete existing PINNED(interface) routes */
-   info->rti_flags &= ~RTF_PINNED;
-   rt_old = rt_unlinkrte(rnh, info, );
-   info->rti_flags |= RTF_PINNED;
-   info->rti_info[RTAX_DST] = info_dst;
-   

svn commit: r364730 - in head/sys: kern net net/route

2020-08-24 Thread Alexander V. Chernikov
Author: melifaro
Date: Mon Aug 24 20:23:34 2020
New Revision: 364730
URL: https://svnweb.freebsd.org/changeset/base/364730

Log:
  Remove RT_LOCK mutex from rte.
  
  rtentry lock traditionally served 2 purposed: first was protecting refcounts,
   the second was assuring consistent field access/changes.
  Since route nexthop introduction, the need for the former disappeared and
   the need for the latter reduced.
  To be more precise, the following rte field are mutable:
  
  rt_nhop (nexthop pointer, updated with RIB_WLOCK, passed in rib_cmd_info)
  rte_flags (only RTF_HOST and RTF_UP, where RTF_UP gets changed at rte removal)
  rt_weight (relative weight, updated with RIB_WLOCK, passed in rib_cmd_info)
  rt_expire (time when rte deletion is scheduled, updated with RIB_WLOCK)
  rt_chain (deletion chain pointer, updated with RIB_WLOCK)
  All of them are updated under RIB_WLOCK, so the only remaining concern is the 
reading.
  
  rt_nhop and rt_weight (addressed in this review) are read under rib lock and
   stored in the rib_cmd_info, so the caller has no problem with consitency.
  rte_flags is currently read unlocked in rtsock reporting (however the scope
   is only RTF_UP flag, which is pretty static).
  rt_expire is currently read unlocked in rtsock reporting.
  rt_chain accesses are safe, as this is only used at route deletion.
  
  rt_expire and rte_flags reads will be dealt in a separate reviews soon.
  
  Differential Revision:https://reviews.freebsd.org/D26162

Modified:
  head/sys/kern/subr_witness.c
  head/sys/net/route.c
  head/sys/net/route/route_ctl.c
  head/sys/net/route/route_var.h
  head/sys/net/rtsock.c

Modified: head/sys/kern/subr_witness.c
==
--- head/sys/kern/subr_witness.cMon Aug 24 20:02:36 2020
(r364729)
+++ head/sys/kern/subr_witness.cMon Aug 24 20:23:34 2020
(r364730)
@@ -531,7 +531,6 @@ static struct witness_order_list_entry order_lists[] =
 */
{ "so_rcv", _class_mtx_sleep },
{ "radix node head", _class_rm },
-   { "rtentry", _class_mtx_sleep },
{ "ifaddr", _class_mtx_sleep },
{ NULL, NULL },
/*

Modified: head/sys/net/route.c
==
--- head/sys/net/route.cMon Aug 24 20:02:36 2020(r364729)
+++ head/sys/net/route.cMon Aug 24 20:23:34 2020(r364730)
@@ -214,18 +214,19 @@ rib_add_redirect(u_int fibnum, struct sockaddr *dst, s
/* Verify the allowed flag mask. */
KASSERT(((flags & ~(RTF_GATEWAY)) == 0),
("invalid redirect flags: %x", flags));
+   flags |= RTF_HOST | RTF_DYNAMIC;
 
/* Get the best ifa for the given interface and gateway. */
if ((ifa = ifaof_ifpforaddr(gateway, ifp)) == NULL)
return (ENETUNREACH);
ifa_ref(ifa);
-   
+
bzero(, 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 | RTF_HOST | RTF_DYNAMIC;
+   info.rti_flags = flags;
 
/* Setup route metrics to define expire time. */
bzero(_rmx, sizeof(rti_rmx));
@@ -242,10 +243,6 @@ rib_add_redirect(u_int fibnum, struct sockaddr *dst, s
return (error);
}
 
-   RT_LOCK(rc.rc_rt);
-   flags = rc.rc_rt->rte_flags;
-   RT_UNLOCK(rc.rc_rt);
-
RTSTAT_INC(rts_dynamic);
 
/* Send notification of a route addition to userland. */
@@ -253,7 +250,7 @@ rib_add_redirect(u_int fibnum, struct sockaddr *dst, s
info.rti_info[RTAX_DST] = dst;
info.rti_info[RTAX_GATEWAY] = gateway;
info.rti_info[RTAX_AUTHOR] = author;
-   rt_missmsg_fib(RTM_REDIRECT, , flags, error, fibnum);
+   rt_missmsg_fib(RTM_REDIRECT, , flags | RTF_UP, error, fibnum);
 
return (0);
 }
@@ -811,9 +808,7 @@ rt_mpath_unlink(struct rib_head *rnh, struct rt_addrin
 */
if (rn) {
rto = RNTORT(rn);
-   RT_LOCK(rto);
rto->rte_flags |= RTF_UP;
-   RT_UNLOCK(rto);
} else if (rt->rte_flags & RTF_GATEWAY) {
/*
 * For gateway routes, we need to 

Modified: head/sys/net/route/route_ctl.c
==
--- head/sys/net/route/route_ctl.c  Mon Aug 24 20:02:36 2020
(r364729)
+++ head/sys/net/route/route_ctl.c  Mon Aug 24 20:23:34 2020
(r364730)
@@ -149,9 +149,6 @@ rtfree(struct rtentry *rt)
 
KASSERT(rt != NULL, ("%s: NULL rt", __func__));
 
-   RT_LOCK_ASSERT(rt);
-
-   RT_UNLOCK(rt);
epoch_call(net_epoch_preempt, destroy_rtentry_epoch,
>rt_epoch_ctx);
 }
@@ -250,7 +247,6 @@ add_route(struct 

svn commit: r364493 - head/sys/net

2020-08-22 Thread Alexander V. Chernikov
Author: melifaro
Date: Sat Aug 22 20:02:40 2020
New Revision: 364493
URL: https://svnweb.freebsd.org/changeset/base/364493

Log:
  Finish r364492 by renaming rt_flags to rte_flags for multipath code.

Modified:
  head/sys/net/route.c

Modified: head/sys/net/route.c
==
--- head/sys/net/route.cSat Aug 22 19:30:56 2020(r364492)
+++ head/sys/net/route.cSat Aug 22 20:02:40 2020(r364493)
@@ -812,9 +812,9 @@ rt_mpath_unlink(struct rib_head *rnh, struct rt_addrin
if (rn) {
rto = RNTORT(rn);
RT_LOCK(rto);
-   rto->rt_flags |= RTF_UP;
+   rto->rte_flags |= RTF_UP;
RT_UNLOCK(rto);
-   } else if (rt->rt_flags & RTF_GATEWAY) {
+   } else if (rt->rte_flags & RTF_GATEWAY) {
/*
 * For gateway routes, we need to 
 * make sure that we we are deleting
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r364492 - in head/sys/net: . route

2020-08-22 Thread Alexander V. Chernikov
Author: melifaro
Date: Sat Aug 22 19:30:56 2020
New Revision: 364492
URL: https://svnweb.freebsd.org/changeset/base/364492

Log:
  Rename rt_flags to rte_flags && reduce number of rt_nhop accesses.
  
  No functional changes.
  
  Most of the routing flags are stored in the netxtop instead of rtentry.
  Rename rt->rt_flags to rt->rte_flags to simplify reading/modifying code
   checking routing flags.
  
  In the new multipath code, rt->rt_nhop may actually point to nexthop group
   instead of nhop. To ease transition, reduce the amount of rt->rt_nhop->...
   accesses.
  
  Differential Revision:https://reviews.freebsd.org/D26156

Modified:
  head/sys/net/route.c
  head/sys/net/route/route_ctl.c
  head/sys/net/route/route_ddb.c
  head/sys/net/route/route_var.h
  head/sys/net/rtsock.c

Modified: head/sys/net/route.c
==
--- head/sys/net/route.cSat Aug 22 19:18:31 2020(r364491)
+++ head/sys/net/route.cSat Aug 22 19:30:56 2020(r364492)
@@ -243,7 +243,7 @@ rib_add_redirect(u_int fibnum, struct sockaddr *dst, s
}
 
RT_LOCK(rc.rc_rt);
-   flags = rc.rc_rt->rt_flags;
+   flags = rc.rc_rt->rte_flags;
RT_UNLOCK(rc.rc_rt);
 
RTSTAT_INC(rts_dynamic);
@@ -354,6 +354,7 @@ rt_exportinfo(struct rtentry *rt, struct rt_addrinfo *
struct nhop_object *nh;
int sa_len;
 
+   nh = rt->rt_nhop;
if (flags & NHR_COPY) {
/* Copy destination if dst is non-zero */
src = rt_key(rt);
@@ -383,9 +384,10 @@ rt_exportinfo(struct rtentry *rt, struct rt_addrinfo *
}
 
/* Copy gateway is set && dst is non-zero */
-   src = >rt_nhop->gw_sa;
+   src = >gw_sa;
dst = info->rti_info[RTAX_GATEWAY];
-   if ((rt->rt_flags & RTF_GATEWAY) && src != NULL && dst != NULL){
+   if ((nhop_get_rtflags(nh) & RTF_GATEWAY) &&
+   src != NULL && dst != NULL) {
if (src->sa_len > dst->sa_len)
return (ENOMEM);
memcpy(dst, src, src->sa_len);
@@ -398,20 +400,19 @@ rt_exportinfo(struct rtentry *rt, struct rt_addrinfo *
info->rti_info[RTAX_NETMASK] = rt_mask(rt);
info->rti_addrs |= RTA_NETMASK;
}
-   if (rt->rt_flags & RTF_GATEWAY) {
-   info->rti_info[RTAX_GATEWAY] = >rt_nhop->gw_sa;
+   if (nhop_get_rtflags(nh) & RTF_GATEWAY) {
+   info->rti_info[RTAX_GATEWAY] = >gw_sa;
info->rti_addrs |= RTA_GATEWAY;
}
}
 
-   nh = rt->rt_nhop;
rmx = info->rti_rmx;
if (rmx != NULL) {
info->rti_mflags |= RTV_MTU;
rmx->rmx_mtu = nh->nh_mtu;
}
 
-   info->rti_flags = rt->rt_flags | nhop_get_rtflags(nh);
+   info->rti_flags = rt->rte_flags | nhop_get_rtflags(nh);
info->rti_ifp = nh->nh_ifp;
info->rti_ifa = nh->nh_ifa;
if (flags & NHR_REF) {
@@ -579,7 +580,7 @@ rt_ifdelroute(const struct rtentry *rt, const struct n
 * Protect (sorta) against walktree recursion problems
 * with cloned routes
 */
-   if ((rt->rt_flags & RTF_UP) == 0)
+   if ((rt->rte_flags & RTF_UP) == 0)
return (0);
 
return (1);

Modified: head/sys/net/route/route_ctl.c
==
--- head/sys/net/route/route_ctl.c  Sat Aug 22 19:18:31 2020
(r364491)
+++ head/sys/net/route/route_ctl.c  Sat Aug 22 19:30:56 2020
(r364492)
@@ -251,7 +251,7 @@ add_route(struct rib_head *rnh, struct rt_addrinfo *in
return (ENOBUFS);
}
RT_LOCK_INIT(rt);
-   rt->rt_flags = RTF_UP | flags;
+   rt->rte_flags = RTF_UP | flags;
rt->rt_nhop = nh;
 
/* Fill in dst */
@@ -406,6 +406,7 @@ rt_unlinkrte(struct rib_head *rnh, struct rt_addrinfo 
 {
struct sockaddr *dst, *netmask;
struct rtentry *rt;
+   struct nhop_object *nh;
struct radix_node *rn;
 
dst = info->rti_info[RTAX_DST];
@@ -417,16 +418,18 @@ rt_unlinkrte(struct rib_head *rnh, struct rt_addrinfo 
return (NULL);
}
 
+   nh = rt->rt_nhop;
+
if ((info->rti_flags & RTF_PINNED) == 0) {
/* Check if target route can be deleted */
-   if (rt->rt_flags & RTF_PINNED) {
+   if (NH_IS_PINNED(nh)) {
*perror = EADDRINUSE;
return (NULL);
}
}
 
if (info->rti_filter != NULL) {
-   if (info->rti_filter(rt, rt->rt_nhop, info->rti_filterdata)==0){
+   if (info->rti_filter(rt, nh, info->rti_filterdata)==0){
/* Not 

svn commit: r364489 - head/tests/sys/net/routing

2020-08-22 Thread Alexander V. Chernikov
Author: melifaro
Date: Sat Aug 22 18:14:05 2020
New Revision: 364489
URL: https://svnweb.freebsd.org/changeset/base/364489

Log:
  Add test for checking RTF_HOST and RTAX_NETMASK inconsistency.
  
  RTF_HOST indicates whether route is a host route
   (netmask is empty or /{32,128}).
  Check that if netmask is empty and host route is not specified, kernel
   returns an error.
  
  Differential Revision:https://reviews.freebsd.org/D26155

Modified:
  head/tests/sys/net/routing/test_rtsock_l3.c

Modified: head/tests/sys/net/routing/test_rtsock_l3.c
==
--- head/tests/sys/net/routing/test_rtsock_l3.c Sat Aug 22 16:58:59 2020
(r364488)
+++ head/tests/sys/net/routing/test_rtsock_l3.c Sat Aug 22 18:14:05 2020
(r364489)
@@ -365,7 +365,6 @@ ATF_TC_BODY(rtm_get_v4_empty_dst_failure, tc)
(struct sockaddr *)>mask4, NULL);
rtsock_update_rtm_len(rtm);
 
-   write(c->rtsock_fd, rtm, rtm->rtm_msglen);
ATF_CHECK_ERRNO(EINVAL, write(c->rtsock_fd, rtm, rtm->rtm_msglen));
 }
 
@@ -441,6 +440,30 @@ ATF_TC_CLEANUP(rtm_add_v4_gw_direct_success, tc)
CLEANUP_AFTER_TEST;
 }
 
+RTM_DECLARE_ROOT_TEST(rtm_add_v4_no_rtf_host_failure,
+"Tests failure with netmask sa and RTF_HOST inconsistency");
+
+ATF_TC_BODY(rtm_add_v4_no_rtf_host_failure, tc)
+{
+   DECLARE_TEST_VARS;
+
+   c = presetup_ipv4(tc);
+
+   /* Create IPv4 subnetwork with smaller prefix */
+   struct sockaddr_in mask4;
+   struct sockaddr_in net4;
+   struct sockaddr_in gw4;
+   prepare_v4_network(c, , , );
+
+   prepare_route_message(rtm, RTM_ADD, (struct sockaddr *),
+   NULL, (struct sockaddr *));
+   rtsock_update_rtm_len(rtm);
+
+   /* RTF_HOST is NOT specified, while netmask is empty */
+
+   ATF_CHECK_ERRNO(EINVAL, write(c->rtsock_fd, rtm, rtm->rtm_msglen));
+}
+
 ATF_TC_WITH_CLEANUP(rtm_del_v4_prefix_nogw_success);
 ATF_TC_HEAD(rtm_del_v4_prefix_nogw_success, tc)
 {
@@ -1269,6 +1292,7 @@ ATF_TP_ADD_TCS(tp)
ATF_TP_ADD_TC(tp, rtm_get_v4_lpm_success);
ATF_TP_ADD_TC(tp, rtm_get_v4_hostbits_failure);
ATF_TP_ADD_TC(tp, rtm_get_v4_empty_dst_failure);
+   ATF_TP_ADD_TC(tp, rtm_add_v4_no_rtf_host_failure);
ATF_TP_ADD_TC(tp, rtm_add_v4_gw_direct_success);
ATF_TP_ADD_TC(tp, rtm_del_v4_prefix_nogw_success);
ATF_TP_ADD_TC(tp, rtm_add_v6_gu_gw_gu_direct_success);
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r364465 - in head/sys: conf net net/route

2020-08-21 Thread Alexander V . Chernikov
22.08.2020, 00:31, "Jung-uk Kim" :
> On 20. 8. 21., Alexander V. Chernikov wrote:
>>  Author: melifaro
>>  Date: Fri Aug 21 21:34:52 2020
>>  New Revision: 364465
>>  URL: https://svnweb.freebsd.org/changeset/base/364465
>>
>>  Log:
>>    Make net.fibs growable.
>>
>>    Allow to dynamically grow the amount of fibs in each vnet.
>>
>>    This change alters current behavior. Currently, if one defines
>> ROUTETABLES > 1 in the kernel config, each vnet will be created
>> with the number of fibs defined in the kernel config.
>> After this commit vnets will be created with fibs=1.
>>
>>    Dynamic net.fibs is not compatible with net.add_addr_allfibs.
>> The plan is to deprecate the latter and make
>> net.add_addr_allfibs=0 default behaviour.
>>
>>    Reviewed by: glebius
>>    Relnotes: yes
>>    Differential Revision: https://reviews.freebsd.org/D26062
>>
>>  Added:
>>    head/sys/net/route/route_tables.c (contents, props changed)
>>  Modified:
>>    head/sys/conf/files
>>    head/sys/net/route.c
>>    head/sys/net/route.h
>>    head/sys/net/route/route_var.h
>
> ...
>
> This commit broke the kernel build and the following patch fixed it for me.
Could you please name the architecture? ci.freebsd.org looks pretty green so 
far. 
>
> Index: sys/net/route/route_tables.c
> ===
> --- sys/net/route/route_tables.c (revision 364466)
> +++ sys/net/route/route_tables.c (working copy)
> @@ -44,6 +44,7 @@ __FBSDID("$FreeBSD$");
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
>
> Jung-uk Kim
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r364465 - in head/sys: conf net net/route

2020-08-21 Thread Alexander V . Chernikov
21.08.2020, 23:21, "Julian Elischer" :
> On 8/21/20 2:34 PM, Alexander V. Chernikov wrote:
>>  Author: melifaro
>>  Date: Fri Aug 21 21:34:52 2020
>>  New Revision: 364465
>>  URL: https://svnweb.freebsd.org/changeset/base/364465
>>
>>  Log:
>> Make net.fibs growable.
>>
>> Allow to dynamically grow the amount of fibs in each vnet.
>>
>> This change alters current behavior. Currently, if one defines
>>  ROUTETABLES > 1 in the kernel config, each vnet will be created
>>  with the number of fibs defined in the kernel config.
>>  After this commit vnets will be created with fibs=1.
>>
>> Dynamic net.fibs is not compatible with net.add_addr_allfibs.
>>  The plan is to deprecate the latter and make
>>  net.add_addr_allfibs=0 default behaviour.
>
> For a while, setting it to 1 should be very noisy.
You mean that kernel should print warning when creating VNET && original 
net.fibs value is > 1 ?
>
>>
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r364465 - in head/sys: conf net net/route

2020-08-21 Thread Alexander V. Chernikov
Author: melifaro
Date: Fri Aug 21 21:34:52 2020
New Revision: 364465
URL: https://svnweb.freebsd.org/changeset/base/364465

Log:
  Make net.fibs growable.
  
  Allow to dynamically grow the amount of fibs in each vnet.
  
  This change alters current behavior. Currently, if one defines
   ROUTETABLES > 1 in the kernel config, each vnet will be created
   with the number of fibs defined in the kernel config.
   After this commit vnets will be created with fibs=1.
  
  Dynamic net.fibs is not compatible with net.add_addr_allfibs.
   The plan is to deprecate the latter and make
   net.add_addr_allfibs=0 default behaviour.
  
  Reviewed by:  glebius
  Relnotes: yes
  Differential Revision:https://reviews.freebsd.org/D26062

Added:
  head/sys/net/route/route_tables.c   (contents, props changed)
Modified:
  head/sys/conf/files
  head/sys/net/route.c
  head/sys/net/route.h
  head/sys/net/route/route_var.h

Modified: head/sys/conf/files
==
--- head/sys/conf/files Fri Aug 21 21:24:14 2020(r364464)
+++ head/sys/conf/files Fri Aug 21 21:34:52 2020(r364465)
@@ -4102,6 +4102,7 @@ net/route/nhop_utils.cstandard
 net/route/route_ctl.c  standard
 net/route/route_ddb.c  optional ddb
 net/route/route_helpers.c  standard
+net/route/route_tables.c   standard
 net/route/route_temporal.c standard
 net/rss_config.c   optional inet rss | inet6 rss
 net/rtsock.c   standard

Modified: head/sys/net/route.c
==
--- head/sys/net/route.cFri Aug 21 21:24:14 2020(r364464)
+++ head/sys/net/route.cFri Aug 21 21:34:52 2020(r364465)
@@ -74,29 +74,6 @@
 #include 
 #include 
 
-#include 
-
-#defineRT_MAXFIBS  UINT16_MAX
-
-/* Kernel config default option. */
-#ifdef ROUTETABLES
-#if ROUTETABLES <= 0
-#error "ROUTETABLES defined too low"
-#endif
-#if ROUTETABLES > RT_MAXFIBS
-#error "ROUTETABLES defined too big"
-#endif
-#defineRT_NUMFIBS  ROUTETABLES
-#endif /* ROUTETABLES */
-/* Initialize to default if not otherwise set. */
-#ifndefRT_NUMFIBS
-#defineRT_NUMFIBS  1
-#endif
-
-/* This is read-only.. */
-u_int rt_numfibs = RT_NUMFIBS;
-SYSCTL_UINT(_net, OID_AUTO, fibs, CTLFLAG_RDTUN, _numfibs, 0, "");
-
 /*
  * By default add routes to all fibs for new interfaces.
  * Once this is set to 0 then only allocate routes on interface
@@ -118,10 +95,6 @@ VNET_PCPUSTAT_SYSINIT(rtstat);
 VNET_PCPUSTAT_SYSUNINIT(rtstat);
 #endif
 
-VNET_DEFINE(struct rib_head *, rt_tables);
-#defineV_rt_tables VNET(rt_tables)
-
-
 EVENTHANDLER_LIST_DEFINE(rt_addrmsg);
 
 static int rt_ifdelroute(const struct rtentry *rt, const struct nhop_object *,
@@ -130,63 +103,6 @@ static int rt_exportinfo(struct rtentry *rt, struct rt
 int flags);
 
 /*
- * handler for net.my_fibnum
- */
-static int
-sysctl_my_fibnum(SYSCTL_HANDLER_ARGS)
-{
-int fibnum;
-int error;
- 
-fibnum = curthread->td_proc->p_fibnum;
-error = sysctl_handle_int(oidp, , 0, req);
-return (error);
-}
-
-SYSCTL_PROC(_net, OID_AUTO, my_fibnum,
-CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, 0,
-_my_fibnum, "I",
-"default FIB of caller");
-
-static __inline struct rib_head **
-rt_tables_get_rnh_ptr(int table, int fam)
-{
-   struct rib_head **rnh;
-
-   KASSERT(table >= 0 && table < rt_numfibs,
-   ("%s: table out of bounds (0 <= %d < %d)", __func__, table,
-rt_numfibs));
-   KASSERT(fam >= 0 && fam < (AF_MAX + 1),
-   ("%s: fam out of bounds (0 <= %d < %d)", __func__, fam, AF_MAX+1));
-
-   /* rnh is [fib=0][af=0]. */
-   rnh = (struct rib_head **)V_rt_tables;
-   /* Get the offset to the requested table and fam. */
-   rnh += table * (AF_MAX+1) + fam;
-
-   return (rnh);
-}
-
-struct rib_head *
-rt_tables_get_rnh(int table, int fam)
-{
-
-   return (*rt_tables_get_rnh_ptr(table, fam));
-}
-
-u_int
-rt_tables_get_gen(int table, int fam)
-{
-   struct rib_head *rnh;
-
-   rnh = *rt_tables_get_rnh_ptr(table, fam);
-   KASSERT(rnh != NULL, ("%s: NULL rib_head pointer table %d fam %d",
-   __func__, table, fam));
-   return (rnh->rnh_gen);
-}
-
-
-/*
  * route initialization must occur before ip6_init2(), which happenas at
  * SI_ORDER_MIDDLE.
  */
@@ -194,89 +110,10 @@ static void
 route_init(void)
 {
 
-   /* whack the tunable ints into  line. */
-   if (rt_numfibs > RT_MAXFIBS)
-   rt_numfibs = RT_MAXFIBS;
-   if (rt_numfibs == 0)
-   rt_numfibs = 1;
nhops_init();
 }
 SYSINIT(route_init, SI_SUB_PROTO_DOMAIN, SI_ORDER_THIRD, route_init, NULL);
 
-static void
-vnet_route_init(const void *unused __unused)
-{
-   struct domain *dom;
-   struct rib_head **rnh;
-   int table;
-   int fam;
-

svn commit: r364250 - in head/sys: net netinet6

2020-08-15 Thread Alexander V. Chernikov
Author: melifaro
Date: Sat Aug 15 11:37:44 2020
New Revision: 364250
URL: https://svnweb.freebsd.org/changeset/base/364250

Log:
  Make net.inet6.ip6.deembed_scopeid behaviour default & remove sysctl.
  
  Submitted by: Neel Chauhan 
  Differential Revision:https://reviews.freebsd.org/D25637

Modified:
  head/sys/net/rtsock.c
  head/sys/netinet6/in6.c
  head/sys/netinet6/scope6.c
  head/sys/netinet6/scope6_var.h

Modified: head/sys/net/rtsock.c
==
--- head/sys/net/rtsock.c   Sat Aug 15 11:28:01 2020(r364249)
+++ head/sys/net/rtsock.c   Sat Aug 15 11:37:44 2020(r364250)
@@ -900,7 +900,7 @@ route_output(struct mbuf *m, struct socket *so, ...)
error = lla_rt_output(rtm, );
 #ifdef INET6
if (error == 0)
-   rti_need_deembed = (V_deembed_scopeid) ? 1 : 0;
+   rti_need_deembed = 1;
 #endif
goto flush;
}
@@ -915,7 +915,7 @@ route_output(struct mbuf *m, struct socket *so, ...)
error = rib_action(fibnum, rtm->rtm_type, , );
if (error == 0) {
 #ifdef INET6
-   rti_need_deembed = (V_deembed_scopeid) ? 1 : 0;
+   rti_need_deembed = 1;
 #endif
rtm->rtm_index = rc.rc_nh_new->nh_ifp->if_index;
nh = rc.rc_nh_new;
@@ -930,7 +930,7 @@ route_output(struct mbuf *m, struct socket *so, ...)
}
 #ifdef INET6
/* rt_msg2() will not be used when RTM_DELETE fails. */
-   rti_need_deembed = (V_deembed_scopeid) ? 1 : 0;
+   rti_need_deembed = 1;
 #endif
break;
 
@@ -1192,7 +1192,7 @@ rtsock_msg_mbuf(int type, struct rt_addrinfo *rtinfo)
rtinfo->rti_addrs |= (1 << i);
dlen = SA_SIZE(sa);
 #ifdef INET6
-   if (V_deembed_scopeid && sa->sa_family == AF_INET6) {
+   if (sa->sa_family == AF_INET6) {
sin6 = (struct sockaddr_in6 *)
bcopy(sa, sin6, sizeof(*sin6));
if (sa6_recoverscope(sin6) == 0)
@@ -1298,7 +1298,7 @@ rtsock_msg_buffer(int type, struct rt_addrinfo *rtinfo
dlen = SA_SIZE(sa);
if (cp != NULL && buflen >= dlen) {
 #ifdef INET6
-   if (V_deembed_scopeid && sa->sa_family == AF_INET6) {
+   if (sa->sa_family == AF_INET6) {
sin6 = (struct sockaddr_in6 *)
bcopy(sa, sin6, sizeof(*sin6));
if (sa6_recoverscope(sin6) == 0)

Modified: head/sys/netinet6/in6.c
==
--- head/sys/netinet6/in6.c Sat Aug 15 11:28:01 2020(r364249)
+++ head/sys/netinet6/in6.c Sat Aug 15 11:37:44 2020(r364250)
@@ -2374,8 +2374,7 @@ in6_lltable_dump_entry(struct lltable *llt, struct lle
ndpc.rtm.rtm_type = RTM_GET;
ndpc.rtm.rtm_flags = RTF_UP;
ndpc.rtm.rtm_addrs = RTA_DST | RTA_GATEWAY;
-   if (V_deembed_scopeid)
-   sa6_recoverscope();
+   sa6_recoverscope();
 
/* publish */
if (lle->la_flags & LLE_PUB)

Modified: head/sys/netinet6/scope6.c
==
--- head/sys/netinet6/scope6.c  Sat Aug 15 11:28:01 2020(r364249)
+++ head/sys/netinet6/scope6.c  Sat Aug 15 11:37:44 2020(r364250)
@@ -60,11 +60,7 @@ VNET_DEFINE(int, ip6_use_defzone) = 1;
 #else
 VNET_DEFINE(int, ip6_use_defzone) = 0;
 #endif
-VNET_DEFINE(int, deembed_scopeid) = 1;
 SYSCTL_DECL(_net_inet6_ip6);
-SYSCTL_INT(_net_inet6_ip6, OID_AUTO, deembed_scopeid, CTLFLAG_VNET | 
CTLFLAG_RW,
-_NAME(deembed_scopeid), 0,
-"Extract embedded zone ID and set it to sin6_scope_id in sockaddr_in6.");
 
 /*
  * The scope6_lock protects the global sid default stored in

Modified: head/sys/netinet6/scope6_var.h
==
--- head/sys/netinet6/scope6_var.h  Sat Aug 15 11:28:01 2020
(r364249)
+++ head/sys/netinet6/scope6_var.h  Sat Aug 15 11:37:44 2020
(r364250)
@@ -47,9 +47,6 @@ struct scope6_id {
uint32_t s6id_list[IPV6_ADDR_SCOPES_COUNT];
 };
 
-VNET_DECLARE(int, deembed_scopeid);
-#define V_deembed_scopeid   VNET(deembed_scopeid)
-
 void   scope6_init(void);
 struct scope6_id *scope6_ifattach(struct ifnet *);
 void   scope6_ifdetach(struct scope6_id *);
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r364238 - in head/sys: net net/route netinet netinet6 sys

2020-08-14 Thread Alexander V. Chernikov
Author: melifaro
Date: Fri Aug 14 21:29:56 2020
New Revision: 364238
URL: https://svnweb.freebsd.org/changeset/base/364238

Log:
  Simplify dom_.
  
  Remove unused arguments from dom_rtattach/dom_rtdetach functions and make
them return/accept 'struct rib_head' instead of 'void **'.
  Declare inet/inet6 implementations in the relevant _var.h headers similar
to domifattach / domifdetach.
  Add rib_subscribe_internal() function to accept subscriptions to the rnh
directly.
  
  Differential Revision:https://reviews.freebsd.org/D26053

Modified:
  head/sys/net/route.c
  head/sys/net/route/route_ctl.c
  head/sys/net/route/route_ctl.h
  head/sys/netinet/in_proto.c
  head/sys/netinet/in_rmx.c
  head/sys/netinet/in_var.h
  head/sys/netinet6/in6_proto.c
  head/sys/netinet6/in6_rmx.c
  head/sys/netinet6/in6_var.h
  head/sys/sys/domain.h

Modified: head/sys/net/route.c
==
--- head/sys/net/route.cFri Aug 14 18:48:48 2020(r364237)
+++ head/sys/net/route.cFri Aug 14 21:29:56 2020(r364238)
@@ -227,7 +227,7 @@ vnet_route_init(const void *unused __unused)
rnh = rt_tables_get_rnh_ptr(table, fam);
if (rnh == NULL)
panic("%s: rnh NULL", __func__);
-   dom->dom_rtattach((void **)rnh, 0, table);
+   *rnh = dom->dom_rtattach(table);
}
}
 }
@@ -256,7 +256,7 @@ vnet_route_uninit(const void *unused __unused)
rnh = rt_tables_get_rnh_ptr(table, fam);
if (rnh == NULL)
panic("%s: rnh NULL", __func__);
-   dom->dom_rtdetach((void **)rnh, 0);
+   dom->dom_rtdetach(*rnh);
}
}
 

Modified: head/sys/net/route/route_ctl.c
==
--- head/sys/net/route/route_ctl.c  Fri Aug 14 18:48:48 2020
(r364237)
+++ head/sys/net/route/route_ctl.c  Fri Aug 14 21:29:56 2020
(r364238)
@@ -817,6 +817,25 @@ rib_notify(struct rib_head *rnh, enum rib_subscription
}
 }
 
+static struct rib_subscription *
+allocate_subscription(rib_subscription_cb_t *f, void *arg,
+enum rib_subscription_type type, bool waitok)
+{
+   struct rib_subscription *rs;
+   int flags = M_ZERO | (waitok ? M_WAITOK : 0);
+
+   rs = malloc(sizeof(struct rib_subscription), M_RTABLE, flags);
+   if (rs == NULL)
+   return (NULL);
+
+   rs->func = f;
+   rs->arg = arg;
+   rs->type = type;
+
+   return (rs);
+}
+
+
 /*
  * Subscribe for the changes in the routing table specified by @fibnum and
  *  @family.
@@ -830,20 +849,33 @@ rib_subscribe(uint32_t fibnum, int family, rib_subscri
struct rib_head *rnh;
struct rib_subscription *rs;
struct epoch_tracker et;
-   int flags = M_ZERO | (waitok ? M_WAITOK : 0);
 
-   rs = malloc(sizeof(struct rib_subscription), M_RTABLE, flags);
-   if (rs == NULL)
+   if ((rs = allocate_subscription(f, arg, type, waitok)) == NULL)
return (NULL);
 
NET_EPOCH_ENTER(et);
KASSERT((fibnum < rt_numfibs), ("%s: bad fibnum", __func__));
rnh = rt_tables_get_rnh(fibnum, family);
 
-   rs->func = f;
-   rs->arg = arg;
-   rs->type = type;
+   RIB_WLOCK(rnh);
+   CK_STAILQ_INSERT_TAIL(>rnh_subscribers, rs, next);
+   RIB_WUNLOCK(rnh);
+   NET_EPOCH_EXIT(et);
 
+   return (rs);
+}
+
+struct rib_subscription *
+rib_subscribe_internal(struct rib_head *rnh, rib_subscription_cb_t *f, void 
*arg,
+enum rib_subscription_type type, bool waitok)
+{
+   struct rib_subscription *rs;
+   struct epoch_tracker et;
+
+   if ((rs = allocate_subscription(f, arg, type, waitok)) == NULL)
+   return (NULL);
+
+   NET_EPOCH_ENTER(et);
RIB_WLOCK(rnh);
CK_STAILQ_INSERT_TAIL(>rnh_subscribers, rs, next);
RIB_WUNLOCK(rnh);

Modified: head/sys/net/route/route_ctl.h
==
--- head/sys/net/route/route_ctl.h  Fri Aug 14 18:48:48 2020
(r364237)
+++ head/sys/net/route/route_ctl.h  Fri Aug 14 21:29:56 2020
(r364238)
@@ -79,6 +79,9 @@ typedef void rib_subscription_cb_t(struct rib_head *rn
 struct rib_subscription *rib_subscribe(uint32_t fibnum, int family,
 rib_subscription_cb_t *f, void *arg, enum rib_subscription_type type,
 bool waitok);
+struct rib_subscription *rib_subscribe_internal(struct rib_head *rnh,
+rib_subscription_cb_t *f, void *arg, enum rib_subscription_type type,
+bool waitok);
 int rib_unsibscribe(uint32_t fibnum, int family, struct rib_subscription *rs);
 
 #endif

Modified: head/sys/netinet/in_proto.c

svn commit: r364202 - in head/sys/net: . route

2020-08-13 Thread Alexander V. Chernikov
Author: melifaro
Date: Thu Aug 13 18:35:29 2020
New Revision: 364202
URL: https://svnweb.freebsd.org/changeset/base/364202

Log:
  Move rtzone handling code to net/route_ctl.c
  
  After moving the route control plane code from net/route.c,
   all rtzone users ended up being in net/route_ctl.c.
  Move uma(9) rtzone setup/teardown code to net/route_ctl.c as well
   to have everything in a single place.
  
  While here, remove custom initializers from the zone.
  It was added originally to avoid setup/teardown of costy per-cpu couters.
  With these counters removed, the only remaining job was avoiding rte mutex
   setup/teardown. Mutex setup is relatively cheap. Additionally, this mutex
   will soon be removed. With that in mind, there is no sense in keeping
   custom zone callbacks.
  
  Differential Revision:https://reviews.freebsd.org/D26051

Modified:
  head/sys/net/route.c
  head/sys/net/route.h
  head/sys/net/route/route_ctl.c
  head/sys/net/route/route_var.h
  head/sys/net/route/shared.h

Modified: head/sys/net/route.c
==
--- head/sys/net/route.cThu Aug 13 17:42:50 2020(r364201)
+++ head/sys/net/route.cThu Aug 13 18:35:29 2020(r364202)
@@ -122,14 +122,10 @@ VNET_DEFINE(struct rib_head *, rt_tables);
 #defineV_rt_tables VNET(rt_tables)
 
 
-VNET_DEFINE(uma_zone_t, rtzone);   /* Routing table UMA zone. */
-#defineV_rtzoneVNET(rtzone)
-
 EVENTHANDLER_LIST_DEFINE(rt_addrmsg);
 
 static int rt_ifdelroute(const struct rtentry *rt, const struct nhop_object *,
 void *arg);
-static void destroy_rtentry_epoch(epoch_context_t ctx);
 static int rt_exportinfo(struct rtentry *rt, struct rt_addrinfo *info,
 int flags);
 
@@ -207,44 +203,7 @@ route_init(void)
 }
 SYSINIT(route_init, SI_SUB_PROTO_DOMAIN, SI_ORDER_THIRD, route_init, NULL);
 
-static int
-rtentry_zinit(void *mem, int size, int how)
-{
-   struct rtentry *rt = mem;
-
-   RT_LOCK_INIT(rt);
-
-   return (0);
-}
-
 static void
-rtentry_zfini(void *mem, int size)
-{
-   struct rtentry *rt = mem;
-
-   RT_LOCK_DESTROY(rt);
-}
-
-static int
-rtentry_ctor(void *mem, int size, void *arg, int how)
-{
-   struct rtentry *rt = mem;
-
-   bzero(rt, offsetof(struct rtentry, rt_endzero));
-   rt->rt_chain = NULL;
-
-   return (0);
-}
-
-static void
-rtentry_dtor(void *mem, int size, void *arg)
-{
-   struct rtentry *rt = mem;
-
-   RT_UNLOCK_COND(rt);
-}
-
-static void
 vnet_route_init(const void *unused __unused)
 {
struct domain *dom;
@@ -255,9 +214,7 @@ vnet_route_init(const void *unused __unused)
V_rt_tables = malloc(rt_numfibs * (AF_MAX+1) *
sizeof(struct rib_head *), M_RTABLE, M_WAITOK|M_ZERO);
 
-   V_rtzone = uma_zcreate("rtentry", sizeof(struct rtentry),
-   rtentry_ctor, rtentry_dtor,
-   rtentry_zinit, rtentry_zfini, UMA_ALIGN_PTR, 0);
+   vnet_rtzone_init();
for (dom = domains; dom; dom = dom->dom_next) {
if (dom->dom_rtattach == NULL)
continue;
@@ -314,7 +271,7 @@ vnet_route_uninit(const void *unused __unused)
epoch_drain_callbacks(net_epoch_preempt);
 
free(V_rt_tables, M_RTABLE);
-   uma_zdestroy(V_rtzone);
+   vnet_rtzone_destroy();
 }
 VNET_SYSUNINIT(vnet_route_uninit, SI_SUB_PROTO_DOMAIN, SI_ORDER_FIRST,
 vnet_route_uninit, 0);
@@ -403,55 +360,6 @@ sys_setfib(struct thread *td, struct setfib_args *uap)
return EINVAL;
td->td_proc->p_fibnum = uap->fibnum;
return (0);
-}
-
-/*
- * Remove a reference count from an rtentry.
- * If the count gets low enough, take it out of the routing table
- */
-void
-rtfree(struct rtentry *rt)
-{
-
-   KASSERT(rt != NULL,("%s: NULL rt", __func__));
-
-   RT_LOCK_ASSERT(rt);
-
-   RT_UNLOCK(rt);
-   epoch_call(net_epoch_preempt, destroy_rtentry_epoch,
-   >rt_epoch_ctx);
-}
-
-static void
-destroy_rtentry(struct rtentry *rt)
-{
-
-   /*
-* At this moment rnh, nh_control may be already freed.
-* nhop interface may have been migrated to a different vnet.
-* Use vnet stored in the nexthop to delete the entry.
-*/
-   CURVNET_SET(nhop_get_vnet(rt->rt_nhop));
-
-   /* Unreference nexthop */
-   nhop_free(rt->rt_nhop);
-
-   uma_zfree(V_rtzone, rt);
-
-   CURVNET_RESTORE();
-}
-
-/*
- * Epoch callback indicating rtentry is safe to destroy
- */
-static void
-destroy_rtentry_epoch(epoch_context_t ctx)
-{
-   struct rtentry *rt;
-
-   rt = __containerof(ctx, struct rtentry, rt_epoch_ctx);
-
-   destroy_rtentry(rt);
 }
 
 /*

Modified: head/sys/net/route.h
==
--- head/sys/net/route.hThu Aug 13 17:42:50 2020(r364201)
+++ head/sys/net/route.hThu Aug 13 18:35:29 2020(r364202)

svn commit: r364101 - head/sys/net/route

2020-08-11 Thread Alexander V. Chernikov
Author: melifaro
Date: Tue Aug 11 07:23:07 2020
New Revision: 364101
URL: https://svnweb.freebsd.org/changeset/base/364101

Log:
  Do not enter epoch in add_route(), as it is already called in epoch.
  
  Reviewed by:  glebius

Modified:
  head/sys/net/route/route_ctl.c

Modified: head/sys/net/route/route_ctl.c
==
--- head/sys/net/route/route_ctl.c  Tue Aug 11 07:21:32 2020
(r364100)
+++ head/sys/net/route/route_ctl.c  Tue Aug 11 07:23:07 2020
(r364101)
@@ -144,7 +144,6 @@ add_route(struct rib_head *rnh, struct rt_addrinfo *in
struct radix_node *rn;
struct ifaddr *ifa;
int error, flags;
-   struct epoch_tracker et;
 
dst = info->rti_info[RTAX_DST];
gateway = info->rti_info[RTAX_GATEWAY];
@@ -168,9 +167,7 @@ add_route(struct rib_head *rnh, struct rt_addrinfo *in
ifa_ref(info->rti_ifa);
}
 
-   NET_EPOCH_ENTER(et);
error = nhop_create_from_info(rnh, info, );
-   NET_EPOCH_EXIT(et);
if (error != 0) {
ifa_free(info->rti_ifa);
return (error);
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r364100 - head/sys/net/route

2020-08-11 Thread Alexander V. Chernikov
Author: melifaro
Date: Tue Aug 11 07:21:32 2020
New Revision: 364100
URL: https://svnweb.freebsd.org/changeset/base/364100

Log:
  Make _route() static to finish the transition to the new kpi.
  
  Discussed with:   glebius

Modified:
  head/sys/net/route/route_ctl.c
  head/sys/net/route/route_var.h

Modified: head/sys/net/route/route_ctl.c
==
--- head/sys/net/route/route_ctl.c  Tue Aug 11 07:05:30 2020
(r364099)
+++ head/sys/net/route/route_ctl.c  Tue Aug 11 07:21:32 2020
(r364100)
@@ -76,6 +76,12 @@ struct rib_subscription {
struct epoch_contextepoch_ctx;
 };
 
+static int add_route(struct rib_head *rnh, struct rt_addrinfo *info,
+struct rib_cmd_info *rc);
+static int del_route(struct rib_head *rnh, struct rt_addrinfo *info,
+struct rib_cmd_info *rc);
+static int change_route(struct rib_head *, struct rt_addrinfo *,
+struct rib_cmd_info *rc);
 static void rib_notify(struct rib_head *rnh, enum rib_subscription_type type,
 struct rib_cmd_info *rc);
 
@@ -128,7 +134,7 @@ rib_add_route(uint32_t fibnum, struct rt_addrinfo *inf
return (add_route(rnh, info, rc));
 }
 
-int
+static int
 add_route(struct rib_head *rnh, struct rt_addrinfo *info,
 struct rib_cmd_info *rc)
 {
@@ -389,7 +395,7 @@ rt_unlinkrte(struct rib_head *rnh, struct rt_addrinfo 
return (rt);
 }
 
-int
+static int
 del_route(struct rib_head *rnh, struct rt_addrinfo *info,
 struct rib_cmd_info *rc)
 {
@@ -566,7 +572,7 @@ change_route_one(struct rib_head *rnh, struct rt_addri
return (0);
 }
 
-int
+static int
 change_route(struct rib_head *rnh, struct rt_addrinfo *info,
 struct rib_cmd_info *rc)
 {

Modified: head/sys/net/route/route_var.h
==
--- head/sys/net/route/route_var.h  Tue Aug 11 07:05:30 2020
(r364099)
+++ head/sys/net/route/route_var.h  Tue Aug 11 07:21:32 2020
(r364100)
@@ -113,12 +113,6 @@ struct radix_node *rt_mpath_unlink(struct rib_head *rn
 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);
-int del_route(struct rib_head *rnh, struct rt_addrinfo *info,
-struct rib_cmd_info *rc);
-int change_route(struct rib_head *, struct rt_addrinfo *,
-struct rib_cmd_info *rc);
 
 VNET_PCPUSTAT_DECLARE(struct rtstat, rtstat);
 #defineRTSTAT_ADD(name, val)   \
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r364099 - in head/sys: net/route netinet6

2020-08-11 Thread Alexander V. Chernikov
Author: melifaro
Date: Tue Aug 11 07:05:30 2020
New Revision: 364099
URL: https://svnweb.freebsd.org/changeset/base/364099

Log:
  Fix rib_subscribe() waitok flag by performing allocation outside epoch.
  Make in6_inithead() use rib_subscribe with waitok to achieve reliable
   subscription allocation.
  
  Reviewed by:  glebius

Modified:
  head/sys/net/route/route_ctl.c
  head/sys/net/route/route_ctl.h
  head/sys/netinet6/in6_rmx.c

Modified: head/sys/net/route/route_ctl.c
==
--- head/sys/net/route/route_ctl.c  Tue Aug 11 05:17:10 2020
(r364098)
+++ head/sys/net/route/route_ctl.c  Tue Aug 11 07:05:30 2020
(r364099)
@@ -743,26 +743,26 @@ rib_notify(struct rib_head *rnh, enum rib_subscription
 /*
  * Subscribe for the changes in the routing table specified by @fibnum and
  *  @family.
- * Needs to be run in network epoch.
  *
  * Returns pointer to the subscription structure on success.
  */
 struct rib_subscription *
 rib_subscribe(uint32_t fibnum, int family, rib_subscription_cb_t *f, void *arg,
-enum rib_subscription_type type, int waitok)
+enum rib_subscription_type type, bool waitok)
 {
struct rib_head *rnh;
struct rib_subscription *rs;
+   struct epoch_tracker et;
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);
 
+   NET_EPOCH_ENTER(et);
+   KASSERT((fibnum < rt_numfibs), ("%s: bad fibnum", __func__));
+   rnh = rt_tables_get_rnh(fibnum, family);
+
rs->func = f;
rs->arg = arg;
rs->type = type;
@@ -770,6 +770,7 @@ rib_subscribe(uint32_t fibnum, int family, rib_subscri
RIB_WLOCK(rnh);
CK_STAILQ_INSERT_TAIL(>rnh_subscribers, rs, next);
RIB_WUNLOCK(rnh);
+   NET_EPOCH_EXIT(et);
 
return (rs);
 }

Modified: head/sys/net/route/route_ctl.h
==
--- head/sys/net/route/route_ctl.h  Tue Aug 11 05:17:10 2020
(r364098)
+++ head/sys/net/route/route_ctl.h  Tue Aug 11 07:05:30 2020
(r364099)
@@ -78,7 +78,7 @@ typedef void rib_subscription_cb_t(struct rib_head *rn
 
 struct rib_subscription *rib_subscribe(uint32_t fibnum, int family,
 rib_subscription_cb_t *f, void *arg, enum rib_subscription_type type,
-int waitok);
+bool waitok);
 int rib_unsibscribe(uint32_t fibnum, int family, struct rib_subscription *rs);
 
 #endif

Modified: head/sys/netinet6/in6_rmx.c
==
--- head/sys/netinet6/in6_rmx.c Tue Aug 11 05:17:10 2020(r364098)
+++ head/sys/netinet6/in6_rmx.c Tue Aug 11 07:05:30 2020(r364099)
@@ -150,8 +150,8 @@ rib6_preadd(u_int fibnum, const struct sockaddr *addr,
 int
 in6_inithead(void **head, int off, u_int fibnum)
 {
-   struct epoch_tracker et;
struct rib_head *rh;
+   struct rib_subscription *rs;
 
rh = rt_table_init(offsetof(struct sockaddr_in6, sin6_addr) << 3,
AF_INET6, fibnum);
@@ -164,12 +164,9 @@ in6_inithead(void **head, int off, u_int fibnum)
 #endif
*head = (void *)rh;
 
-   NET_EPOCH_ENTER(et);
-   if (rib_subscribe(fibnum, AF_INET6, nd6_subscription_cb, NULL,
-   RIB_NOTIFY_IMMEDIATE, M_NOWAIT) == NULL)
-   log(LOG_ERR, "in6_inithead(): unable to subscribe to fib %u\n",
-   fibnum);
-   NET_EPOCH_EXIT(et);
+   rs = rib_subscribe(fibnum, AF_INET6, nd6_subscription_cb, NULL,
+   RIB_NOTIFY_IMMEDIATE, true);
+   KASSERT(rs != NULL, ("Unable to subscribe to fib %u\n", fibnum));
 
return (1);
 }
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r363403 - in head/sys: fs/nfsclient net netinet6 nfs

2020-07-21 Thread Alexander V. Chernikov
Author: melifaro
Date: Tue Jul 21 19:56:13 2020
New Revision: 363403
URL: https://svnweb.freebsd.org/changeset/base/363403

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
  head/sys/nfs/bootp_subr.c

Modified: head/sys/fs/nfsclient/nfs_clvfsops.c
==
--- head/sys/fs/nfsclient/nfs_clvfsops.cTue Jul 21 19:18:29 2020
(r363402)
+++ head/sys/fs/nfsclient/nfs_clvfsops.cTue Jul 21 19:56:13 2020
(r363403)
@@ -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), 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 *),
-   (struct sockaddr *)>mygateway,
-   (struct sockaddr *),
-   RTF_UP | RTF_GATEWAY, NULL, RT_DEFAULT_FIB);
+
+   bzero((caddr_t), sizeof(info));
+   info.rti_flags = RTF_UP | RTF_GATEWAY;
+   info.rti_info[RTAX_DST] = (struct sockaddr *)
+   info.rti_info[RTAX_GATEWAY] = (struct sockaddr *)>mygateway;
+   info.rti_info[RTAX_NETMASK] = (struct sockaddr *)
+
+   error = rib_action(RT_DEFAULT_FIB, RTM_ADD, , );
CURVNET_RESTORE();
NET_EPOCH_EXIT(et);
if (error)

Modified: head/sys/net/if.c
==
--- head/sys/net/if.c   Tue Jul 21 19:18:29 2020(r363402)
+++ head/sys/net/if.c   Tue Jul 21 19:56:13 2020(r363403)
@@ -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 *)_sdl;
link_init_sdl(ifp, (struct sockaddr *)_sdl, ifp->if_type);
 
-   error = rtrequest1_fib(cmd, , NULL, ifp->if_fib);
+   error = rib_action(ifp->if_fib, cmd, , );
NET_EPOCH_EXIT(et);
 
if (rti_ifa != NULL)

Modified: head/sys/net/route.c
==
--- head/sys/net/route.cTue Jul 21 19:18:29 2020(r363402)
+++ head/sys/net/route.cTue Jul 21 19:56:13 2020(r363403)
@@ -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 = _rmx;
 
-   error = rtrequest1_fib(RTM_ADD, , , fibnum);
+   error = rib_action(fibnum, RTM_ADD, , );
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)
-

svn commit: r363320 - in head/sys: fs/nfsclient net netinet6

2020-07-19 Thread Alexander V. Chernikov
Author: melifaro
Date: Sun Jul 19 10:53:15 2020
New Revision: 363320
URL: https://svnweb.freebsd.org/changeset/base/363320

Log:
  Temporarly revert r363319 to unbreak the build.
  
  Reported by:  CI
  Pointy hat to: melifaro

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.cSun Jul 19 09:29:27 2020
(r363319)
+++ head/sys/fs/nfsclient/nfs_clvfsops.cSun Jul 19 10:53:15 2020
(r363320)
@@ -68,7 +68,6 @@ __FBSDID("$FreeBSD$");
 
 #include 
 #include 
-#include 
 #include 
 
 #include 
@@ -467,8 +466,6 @@ 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), sizeof(mask));
sin = mask;
@@ -477,14 +474,10 @@ 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));
-
-   bzero((caddr_t), sizeof(info));
-   info.rti_flags = RTF_UP | RTF_GATEWAY;
-   info.rti_info[RTAX_DST] = (struct sockaddr *)
-   info.rti_info[RTAX_GATEWAY] = (struct sockaddr *)>mygateway;
-   info.rti_info[RTAX_NETMASK] = (struct sockaddr *)
-
-   error = rib_action(RT_DEFAULT_FIB, RTM_ADD, , );
+   error = rtrequest_fib(RTM_ADD, (struct sockaddr *),
+   (struct sockaddr *)>mygateway,
+   (struct sockaddr *),
+   RTF_UP | RTF_GATEWAY, NULL, RT_DEFAULT_FIB);
CURVNET_RESTORE();
NET_EPOCH_EXIT(et);
if (error)

Modified: head/sys/net/if.c
==
--- head/sys/net/if.c   Sun Jul 19 09:29:27 2020(r363319)
+++ head/sys/net/if.c   Sun Jul 19 10:53:15 2020(r363320)
@@ -80,7 +80,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 
 #if defined(INET) || defined(INET6)
@@ -1846,7 +1845,6 @@ 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;
@@ -1874,7 +1872,7 @@ ifa_maintain_loopback_route(int cmd, const char *otype
info.rti_info[RTAX_GATEWAY] = (struct sockaddr *)_sdl;
link_init_sdl(ifp, (struct sockaddr *)_sdl, ifp->if_type);
 
-   error = rib_action(ifp->if_fib, cmd, , );
+   error = rtrequest1_fib(cmd, , NULL, ifp->if_fib);
NET_EPOCH_EXIT(et);
 
if (rti_ifa != NULL)

Modified: head/sys/net/route.c
==
--- head/sys/net/route.cSun Jul 19 09:29:27 2020(r363319)
+++ head/sys/net/route.cSun Jul 19 10:53:15 2020(r363320)
@@ -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 rib_cmd_info rc;
+   struct rtentry *rt;
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 = _rmx;
 
-   error = rib_action(fibnum, RTM_ADD, , );
+   error = rtrequest1_fib(RTM_ADD, , , fibnum);
ifa_free(ifa);
 
if (error != 0) {
@@ -512,9 +512,9 @@ rib_add_redirect(u_int fibnum, struct sockaddr *dst, s
return (error);
}
 
-   RT_LOCK(rc.rc_rt);
-   flags = rc.rc_rt->rt_flags;
-   RT_UNLOCK(rc.rc_rt);
+   RT_LOCK(rt);
+   flags = rt->rt_flags;
+   RT_UNLOCK(rt);
 
RTSTAT_INC(rts_dynamic);
 
@@ -602,7 +602,33 @@ 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), sizeof(info));
+   info.rti_flags = flags;
+   info.rti_info[RTAX_DST] = dst;
+   info.rti_info[RTAX_GATEWAY] = gateway;
+   

svn commit: r363319 - in head/sys: fs/nfsclient net netinet6

2020-07-19 Thread Alexander V. Chernikov
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.cSun Jul 19 06:59:09 2020
(r363318)
+++ head/sys/fs/nfsclient/nfs_clvfsops.cSun 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), 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 *),
-   (struct sockaddr *)>mygateway,
-   (struct sockaddr *),
-   RTF_UP | RTF_GATEWAY, NULL, RT_DEFAULT_FIB);
+
+   bzero((caddr_t), sizeof(info));
+   info.rti_flags = RTF_UP | RTF_GATEWAY;
+   info.rti_info[RTAX_DST] = (struct sockaddr *)
+   info.rti_info[RTAX_GATEWAY] = (struct sockaddr *)>mygateway;
+   info.rti_info[RTAX_NETMASK] = (struct sockaddr *)
+
+   error = rib_action(RT_DEFAULT_FIB, RTM_ADD, , );
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 *)_sdl;
link_init_sdl(ifp, (struct sockaddr *)_sdl, ifp->if_type);
 
-   error = rtrequest1_fib(cmd, , NULL, ifp->if_fib);
+   error = rib_action(ifp->if_fib, cmd, , );
NET_EPOCH_EXIT(et);
 
if (rti_ifa != NULL)

Modified: head/sys/net/route.c
==
--- head/sys/net/route.cSun Jul 19 06:59:09 2020(r363318)
+++ head/sys/net/route.cSun 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 = _rmx;
 
-   error = rtrequest1_fib(RTM_ADD, , , fibnum);
+   error = rib_action(fibnum, RTM_ADD, , );
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);
-

svn commit: r363128 - in head/sys: net net/route netinet6

2020-07-12 Thread Alexander V. Chernikov
Author: melifaro
Date: Sun Jul 12 11:24:23 2020
New Revision: 363128
URL: https://svnweb.freebsd.org/changeset/base/363128

Log:
  Switch inet6 default route subscription to the new rib subscription api.
  
  Old subscription model allowed only single customer.
  
  Switch inet6 to the new subscription api and eliminate the old model.
  
  Differential Revision:https://reviews.freebsd.org/D25615

Modified:
  head/sys/net/if_var.h
  head/sys/net/route/route_ctl.c
  head/sys/netinet6/in6_rmx.c
  head/sys/netinet6/nd6.c
  head/sys/netinet6/nd6.h
  head/sys/netinet6/nd6_rtr.c

Modified: head/sys/net/if_var.h
==
--- head/sys/net/if_var.h   Sun Jul 12 11:18:09 2020(r363127)
+++ head/sys/net/if_var.h   Sun Jul 12 11:24:23 2020(r363128)
@@ -61,8 +61,6 @@
  */
 
 struct rtentry;/* ifa_rtrequest */
-struct nhop_object;/* ifa_rtrequest */
-struct rt_addrinfo;/* ifa_rtrequest */
 struct socket;
 struct carp_if;
 struct carp_softc;
@@ -551,9 +549,6 @@ struct ifaddr {
struct  ifnet *ifa_ifp; /* back-pointer to interface */
struct  carp_softc *ifa_carp;   /* pointer to CARP data */
CK_STAILQ_ENTRY(ifaddr) ifa_link;   /* queue macro glue */
-   void(*ifa_rtrequest)/* check or clean routes (+ or -)'d */
-   (int, struct rtentry *, struct nhop_object *,
-struct rt_addrinfo *);
u_short ifa_flags;  /* mostly rt_flags for cloning */
 #defineIFA_ROUTE   RTF_UP  /* route installed */
 #defineIFA_RTSELF  RTF_HOST/* loopback route to self 
installed */

Modified: head/sys/net/route/route_ctl.c
==
--- head/sys/net/route/route_ctl.c  Sun Jul 12 11:18:09 2020
(r363127)
+++ head/sys/net/route/route_ctl.c  Sun Jul 12 11:24:23 2020
(r363128)
@@ -79,7 +79,6 @@ struct rib_subscription {
 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 void destroy_subscription_epoch(epoch_context_t ctx);
 
 static struct rib_head *
@@ -275,10 +274,8 @@ add_route(struct rib_head *rnh, struct rt_addrinfo *in
if ((rn != NULL) || (rt_old != NULL))
rib_notify(rnh, RIB_NOTIFY_DELAYED, rc);
 
-   if (rt_old != NULL) {
-   rt_notifydelete(rt_old, info);
+   if (rt_old != NULL)
rtfree(rt_old);
-   }
 
/*
 * If it still failed to go into the tree,
@@ -290,13 +287,6 @@ add_route(struct rib_head *rnh, struct rt_addrinfo *in
return (EEXIST);
}
 
-   /*
-* If this protocol has something to add to this then
-* allow it to do that as well.
-*/
-   if (ifa->ifa_rtrequest)
-   ifa->ifa_rtrequest(RTM_ADD, rt, rt->rt_nhop, info);
-
RT_UNLOCK(rt);
 
return (0);
@@ -432,7 +422,6 @@ del_route(struct rib_head *rnh, struct rt_addrinfo *in
return (error);
 
rib_notify(rnh, RIB_NOTIFY_DELAYED, rc);
-   rt_notifydelete(rt, info);
 
/*
 * If the caller wants it, then it can have it,
@@ -554,15 +543,9 @@ change_route_one(struct rib_head *rnh, struct rt_addri
RT_LOCK(rt);
 
/* Provide notification to the protocols.*/
-   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);
-
rt->rt_nhop = nh;
rt_setmetrics(info, rt);
 
-   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;
@@ -641,19 +624,6 @@ rib_action(uint32_t fibnum, int action, struct rt_addr
 }
 
 
-static void
-rt_notifydelete(struct rtentry *rt, struct rt_addrinfo *info)
-{
-   struct ifaddr *ifa;
-
-   /*
-* give the protocol a chance to keep things in sync.
-*/
-   ifa = rt->rt_nhop->nh_ifa;
-   if (ifa != NULL && ifa->ifa_rtrequest != NULL)
-   ifa->ifa_rtrequest(RTM_DELETE, rt, rt->rt_nhop, info);
-}
-
 struct rt_delinfo
 {
struct rt_addrinfo info;
@@ -748,8 +718,6 @@ rib_walk_del(u_int fibnum, int family, rt_filter_f_t *
/* TODO std rt -> rt_addrinfo export */
di.info.rti_info[RTAX_DST] = rt_key(rt);
di.info.rti_info[RTAX_NETMASK] = rt_mask(rt);
-
-   rt_notifydelete(rt, );
 
if (report)
rt_routemsg(RTM_DELETE, rt, rt->rt_nhop->nh_ifp, 0,

Modified: head/sys/netinet6/in6_rmx.c

svn commit: r363127 - in head/sys/net: . route

2020-07-12 Thread Alexander V. Chernikov
Author: melifaro
Date: Sun Jul 12 11:18:09 2020
New Revision: 363127
URL: https://svnweb.freebsd.org/changeset/base/363127

Log:
  Add destructor for the rib subscription system to simplify users code.
  
  Subscriptions are planned to be used by modules such as route lookup engines.
  In that case that's the module task to properly unsibscribe before detach.
  However, the in-kernel customer - inet6 wants to track default route changes.
  To avoid having inet6 store per-fib subscriptions, handle automatic
   destruction internally.
  
  Differential Revision:https://reviews.freebsd.org/D25614

Modified:
  head/sys/net/route.c
  head/sys/net/route/route_ctl.c
  head/sys/net/route/shared.h

Modified: head/sys/net/route.c
==
--- head/sys/net/route.cSun Jul 12 10:07:01 2020(r363126)
+++ head/sys/net/route.cSun Jul 12 11:18:09 2020(r363127)
@@ -348,7 +348,7 @@ rt_table_init(int offset, int family, u_int fibnum)
nhops_init_rib(rh);
 
/* Init subscription system */
-   CK_STAILQ_INIT(>rnh_subscribers);
+   rib_init_subscriptions(rh);
 
/* Finally, set base callbacks */
rh->rnh_addaddr = rn_addroute;
@@ -382,6 +382,8 @@ rt_table_destroy(struct rib_head *rh)
rn_walktree(>rmhead.head, rt_freeentry, >rmhead.head);
 
nhops_destroy_rib(rh);
+
+   rib_destroy_subscriptions(rh);
 
/* Assume table is already empty */
RIB_LOCK_DESTROY(rh);

Modified: head/sys/net/route/route_ctl.c
==
--- head/sys/net/route/route_ctl.c  Sun Jul 12 10:07:01 2020
(r363126)
+++ head/sys/net/route/route_ctl.c  Sun Jul 12 11:18:09 2020
(r363127)
@@ -847,3 +847,28 @@ destroy_subscription_epoch(epoch_context_t ctx)
 
free(rs, M_RTABLE);
 }
+
+void
+rib_init_subscriptions(struct rib_head *rnh)
+{
+
+   CK_STAILQ_INIT(>rnh_subscribers);
+}
+
+void
+rib_destroy_subscriptions(struct rib_head *rnh)
+{
+   struct rib_subscription *rs;
+   struct epoch_tracker et;
+
+   NET_EPOCH_ENTER(et);
+   RIB_WLOCK(rnh);
+   while ((rs = CK_STAILQ_FIRST(>rnh_subscribers)) != NULL) {
+   CK_STAILQ_REMOVE_HEAD(>rnh_subscribers, next);
+   epoch_call(net_epoch_preempt, destroy_subscription_epoch,
+   >epoch_ctx);
+   }
+   RIB_WUNLOCK(rnh);
+   NET_EPOCH_EXIT(et);
+}
+

Modified: head/sys/net/route/shared.h
==
--- head/sys/net/route/shared.h Sun Jul 12 10:07:01 2020(r363126)
+++ head/sys/net/route/shared.h Sun Jul 12 11:18:09 2020(r363127)
@@ -67,6 +67,10 @@ int nhop_create_from_nhop(struct rib_head *rnh, const 
 void nhops_update_ifmtu(struct rib_head *rh, struct ifnet *ifp, uint32_t mtu);
 int nhops_dump_sysctl(struct rib_head *rh, struct sysctl_req *w);
 
+/* subscriptions */
+void rib_init_subscriptions(struct rib_head *rnh);
+void rib_destroy_subscriptions(struct rib_head *rnh);
+
 /* route */
 VNET_DECLARE(uma_zone_t, rtzone);  /* Routing table UMA zone. */
 #defineV_rtzoneVNET(rtzone)
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r362909 - in head: sys/netinet6 tests/sys/netinet6

2020-07-03 Thread Alexander V. Chernikov
Author: melifaro
Date: Fri Jul  3 08:06:26 2020
New Revision: 362909
URL: https://svnweb.freebsd.org/changeset/base/362909

Log:
  Fix IPv6 regression introduced by r362900.
  
  PR:   kern/247729

Modified:
  head/sys/netinet6/icmp6.c
  head/tests/sys/netinet6/redirect.sh

Modified: head/sys/netinet6/icmp6.c
==
--- head/sys/netinet6/icmp6.c   Fri Jul  3 07:25:26 2020(r362908)
+++ head/sys/netinet6/icmp6.c   Fri Jul  3 08:06:26 2020(r362909)
@@ -2277,7 +2277,7 @@ icmp6_redirect_input(struct mbuf *m, int off)
in6_splitscope(, , );
NET_EPOCH_ASSERT();
nh = fib6_lookup(ifp->if_fib, , scopeid, 0, 0);
-   if (nh == NULL) {
+   if (nh != NULL) {
struct in6_addr nh_addr;
nh_addr = ifatoia6(nh->nh_ifa)->ia_addr.sin6_addr;
if ((nh->nh_flags & NHF_GATEWAY) == 0) {

Modified: head/tests/sys/netinet6/redirect.sh
==
--- head/tests/sys/netinet6/redirect.sh Fri Jul  3 07:25:26 2020
(r362908)
+++ head/tests/sys/netinet6/redirect.sh Fri Jul  3 08:06:26 2020
(r362909)
@@ -87,7 +87,15 @@ valid_redirect_body() {
local_ll_mac=`jexec ${jname} ifconfig ${epair}b ether | awk 
'$1~/ether/{print$2}'`
 
# wait for DAD to complete
-   sleep 2
+   while [ `ifconfig ${epair}a inet6 | grep -c tentative` != "0" ]; do
+   sleep 0.1
+   done
+   while [ `jexec ${jname}b ifconfig ${epair}b inet6 | grep -c tentative` 
!= "0" ]; do
+   sleep 0.1
+   done
+
+   # enable ND debugging in the target jail to ease catching errors
+   jexec ${jname} sysctl net.inet6.icmp6.nd6_debug=1
 
# echo "LOCAL: ${local_ll_ip} ${local_ll_mac}"
# echo "REMOTE: ${remote_rtr_ll_ip} ${remote_rtr_mac}"
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r362900 - in head/sys: net netinet netinet6 netpfil/ipfw netpfil/ipfw/nat64

2020-07-02 Thread Alexander V. Chernikov
Author: melifaro
Date: Thu Jul  2 21:04:08 2020
New Revision: 362900
URL: https://svnweb.freebsd.org/changeset/base/362900

Log:
  Complete conversions from fib<4|6>_lookup_nh_ to fib<4|6>_lookup().
  
  fib[46]_lookup_nh_ represents pre-epoch generation of fib api, providing less 
guarantees
   over pointer validness and requiring on-stack data copying.
  
  With no callers remaining, remove fib[46]_lookup_nh_ functions.
  
  Submitted by: Neel Chauhan 
  Differential Revision:https://reviews.freebsd.org/D25445

Modified:
  head/sys/net/if_stf.c
  head/sys/netinet/if_ether.c
  head/sys/netinet/in_fib.c
  head/sys/netinet/in_fib.h
  head/sys/netinet/in_mcast.c
  head/sys/netinet/ip_options.c
  head/sys/netinet6/icmp6.c
  head/sys/netinet6/in6.c
  head/sys/netinet6/in6_fib.c
  head/sys/netinet6/in6_fib.h
  head/sys/netinet6/in6_mcast.c
  head/sys/netinet6/in6_src.c
  head/sys/netpfil/ipfw/ip_fw2.c
  head/sys/netpfil/ipfw/ip_fw_table_algo.c
  head/sys/netpfil/ipfw/nat64/nat64_translate.c

Modified: head/sys/net/if_stf.c
==
--- head/sys/net/if_stf.c   Thu Jul  2 18:42:43 2020(r362899)
+++ head/sys/net/if_stf.c   Thu Jul  2 21:04:08 2020(r362900)
@@ -97,6 +97,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -568,12 +569,14 @@ stf_checkaddr4(struct stf_softc *sc, struct in_addr *i
 * perform ingress filter
 */
if (sc && (STF2IFP(sc)->if_flags & IFF_LINK2) == 0 && inifp) {
-   struct nhop4_basic nh4;
+   struct nhop_object *nh;
 
-   if (fib4_lookup_nh_basic(sc->sc_fibnum, *in, 0, 0, ) != 0)
+   NET_EPOCH_ASSERT();
+   nh = fib4_lookup(sc->sc_fibnum, *in, 0, 0, 0);
+   if (nh == NULL)
return (-1);
 
-   if (nh4.nh_ifp != inifp)
+   if (nh->nh_ifp != inifp)
return (-1);
}
 

Modified: head/sys/netinet/if_ether.c
==
--- head/sys/netinet/if_ether.c Thu Jul  2 18:42:43 2020(r362899)
+++ head/sys/netinet/if_ether.c Thu Jul  2 21:04:08 2020(r362900)
@@ -63,6 +63,7 @@ __FBSDID("$FreeBSD$");
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #include 
@@ -804,7 +805,7 @@ in_arpinput(struct mbuf *m)
int carped;
struct sockaddr_in sin;
struct sockaddr *dst;
-   struct nhop4_basic nh4;
+   struct nhop_object *nh;
uint8_t linkhdr[LLE_MAX_LINKHDR];
struct route ro;
size_t linkhdrsize;
@@ -1065,8 +1066,9 @@ reply:
if (!V_arp_proxyall)
goto drop;
 
-   if (fib4_lookup_nh_basic(ifp->if_fib, itaddr, 0, 0,
-   ) != 0)
+   NET_EPOCH_ASSERT();
+   nh = fib4_lookup(ifp->if_fib, itaddr, 0, 0, 0);
+   if (nh == NULL)
goto drop;
 
/*
@@ -1074,7 +1076,7 @@ reply:
 * as this one came out of, or we'll get into a fight
 * over who claims what Ether address.
 */
-   if (nh4.nh_ifp == ifp)
+   if (nh->nh_ifp == ifp)
goto drop;
 
(void)memcpy(ar_tha(ah), ar_sha(ah), ah->ar_hln);
@@ -1087,10 +1089,10 @@ reply:
 * wrong network.
 */
 
-   if (fib4_lookup_nh_basic(ifp->if_fib, isaddr, 0, 0,
-   ) != 0)
+   nh = fib4_lookup(ifp->if_fib, isaddr, 0, 0, 0);
+   if (nh == NULL)
goto drop;
-   if (nh4.nh_ifp != ifp) {
+   if (nh->nh_ifp != ifp) {
ARP_LOG(LOG_INFO, "proxy: ignoring request"
" from %s via %s\n",
inet_ntoa_r(isaddr, addrbuf),

Modified: head/sys/netinet/in_fib.c
==
--- head/sys/netinet/in_fib.c   Thu Jul  2 18:42:43 2020(r362899)
+++ head/sys/netinet/in_fib.c   Thu Jul  2 21:04:08 2020(r362900)
@@ -66,165 +66,6 @@ __FBSDID("$FreeBSD$");
 /* Verify struct route compatiblity */
 /* Assert 'struct route_in' is compatible with 'struct route' */
 CHK_STRUCT_ROUTE_COMPAT(struct route_in, ro_dst4);
-static void fib4_rte_to_nh_basic(struct nhop_object *nh, struct in_addr dst,
-uint32_t flags, struct nhop4_basic *pnh4);
-static void fib4_rte_to_nh_extended(struct nhop_object *nh, struct in_addr dst,
-uint32_t flags, struct nhop4_extended *pnh4);
-
-
-static void
-fib4_rte_to_nh_basic(struct nhop_object 

svn commit: r362487 - in head/sys/dev/cxgbe: iw_cxgbe tom

2020-06-22 Thread Alexander V. Chernikov
Author: melifaro
Date: Mon Jun 22 07:35:23 2020
New Revision: 362487
URL: https://svnweb.freebsd.org/changeset/base/362487

Log:
  Switch cxgbe interface lookup to use fibX_lookup() from older
   fibX_lookup_nh_ext().
  
  fibX_lookup_nh_ represents pre-epoch generation of fib kpi,
  providing less guarantees over pointer validness and requiring
  on-stack data copying.
  
  Reviewed by:  np
  Differential Revision:https://reviews.freebsd.org/D24975

Modified:
  head/sys/dev/cxgbe/iw_cxgbe/cm.c
  head/sys/dev/cxgbe/tom/t4_listen.c

Modified: head/sys/dev/cxgbe/iw_cxgbe/cm.c
==
--- head/sys/dev/cxgbe/iw_cxgbe/cm.cMon Jun 22 07:00:26 2020
(r362486)
+++ head/sys/dev/cxgbe/iw_cxgbe/cm.cMon Jun 22 07:35:23 2020
(r362487)
@@ -45,6 +45,7 @@ __FBSDID("$FreeBSD$");
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -537,32 +538,29 @@ static int
 get_ifnet_from_raddr(struct sockaddr_storage *raddr, struct ifnet **ifp)
 {
int err = 0;
+   struct nhop_object *nh;
 
if (raddr->ss_family == AF_INET) {
struct sockaddr_in *raddr4 = (struct sockaddr_in *)raddr;
-   struct nhop4_extended nh4 = {0};
 
-   err = fib4_lookup_nh_ext(RT_DEFAULT_FIB, raddr4->sin_addr,
-   NHR_REF, 0, );
-   *ifp = nh4.nh_ifp;
-   if (err)
-   fib4_free_nh_ext(RT_DEFAULT_FIB, );
+   nh = fib4_lookup(RT_DEFAULT_FIB, raddr4->sin_addr, 0,
+   NHR_NONE, 0);
} else {
struct sockaddr_in6 *raddr6 = (struct sockaddr_in6 *)raddr;
-   struct nhop6_extended nh6 = {0};
struct in6_addr addr6;
uint32_t scopeid;
 
memset(, 0, sizeof(addr6));
in6_splitscope((struct in6_addr *)>sin6_addr,
, );
-   err = fib6_lookup_nh_ext(RT_DEFAULT_FIB, , scopeid,
-   NHR_REF, 0, );
-   *ifp = nh6.nh_ifp;
-   if (err)
-   fib6_free_nh_ext(RT_DEFAULT_FIB, );
+   nh = fib6_lookup(RT_DEFAULT_FIB, , scopeid,
+   NHR_NONE, 0);
}
 
+   if (nh == NULL)
+   err = EHOSTUNREACH;
+   else
+   *ifp = nh->nh_ifp;
CTR2(KTR_IW_CXGBE, "%s: return: %d", __func__, err);
return err;
 }
@@ -2589,6 +2587,7 @@ int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_
struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
struct c4iw_ep *ep = NULL;
struct ifnet*nh_ifp;/* Logical egress interface */
+   struct epoch_tracker et;
 #ifdef VIMAGE
struct rdma_cm_id *rdma_id = (struct rdma_cm_id*)cm_id->context;
struct vnet *vnet = rdma_id->route.addr.dev_addr.net;
@@ -2639,9 +2638,11 @@ int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_
ref_qp(ep);
ep->com.thread = curthread;
 
+   NET_EPOCH_ENTER(et);
CURVNET_SET(vnet);
err = get_ifnet_from_raddr(_id->remote_addr, _ifp);
CURVNET_RESTORE();
+   NET_EPOCH_EXIT(et);
 
if (err) {
 

Modified: head/sys/dev/cxgbe/tom/t4_listen.c
==
--- head/sys/dev/cxgbe/tom/t4_listen.c  Mon Jun 22 07:00:26 2020
(r362486)
+++ head/sys/dev/cxgbe/tom/t4_listen.c  Mon Jun 22 07:35:23 2020
(r362487)
@@ -51,6 +51,7 @@ __FBSDID("$FreeBSD$");
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -1052,10 +1053,9 @@ get_l2te_for_nexthop(struct port_info *pi, struct ifne
struct l2t_entry *e;
struct sockaddr_in6 sin6;
struct sockaddr *dst = (void *)
+   struct nhop_object *nh;
 
if (inc->inc_flags & INC_ISIPV6) {
-   struct nhop6_basic nh6;
-
bzero(dst, sizeof(struct sockaddr_in6));
dst->sa_len = sizeof(struct sockaddr_in6);
dst->sa_family = AF_INET6;
@@ -1066,24 +1066,28 @@ get_l2te_for_nexthop(struct port_info *pi, struct ifne
return (e);
}
 
-   if (fib6_lookup_nh_basic(RT_DEFAULT_FIB, >inc6_faddr,
-   0, 0, 0, ) != 0)
+   nh = fib6_lookup(RT_DEFAULT_FIB, >inc6_faddr, 0, NHR_NONE, 
0);
+   if (nh == NULL)
return (NULL);
-   if (nh6.nh_ifp != ifp)
+   if (nh->nh_ifp != ifp)
return (NULL);
-   ((struct sockaddr_in6 *)dst)->sin6_addr = nh6.nh_addr;
+   if (nh->nh_flags & NHF_GATEWAY)
+   ((struct sockaddr_in6 *)dst)->sin6_addr = 
nh->gw6_sa.sin6_addr;
+   else
+   ((struct sockaddr_in6 *)dst)->sin6_addr = 
inc->inc6_faddr;
  

svn commit: r362007 - in head/sys/net: . route

2020-06-10 Thread Alexander V. Chernikov
Author: melifaro
Date: Wed Jun 10 07:46:22 2020
New Revision: 362007
URL: https://svnweb.freebsd.org/changeset/base/362007

Log:
  Switch rtsock code to using newly-create rib_action() KPI call.
  
  This simplifies the code and allows to further split rtentry and nexthop,
   removing one of the blockers for multipath code introduction, described in
   D24141.
  
  Reviewed by:  ae
  Differential Revision:https://reviews.freebsd.org/D25192

Modified:
  head/sys/net/route/route_ctl.c
  head/sys/net/route/route_ctl.h
  head/sys/net/rtsock.c

Modified: head/sys/net/route/route_ctl.c
==
--- head/sys/net/route/route_ctl.c  Wed Jun 10 07:32:02 2020
(r362006)
+++ head/sys/net/route/route_ctl.c  Wed Jun 10 07:46:22 2020
(r362007)
@@ -610,6 +610,37 @@ change_route(struct rib_head *rnh, struct rt_addrinfo 
return (error);
 }
 
+/*
+ * Performs modification of routing table specificed by @action.
+ * Table is specified by @fibnum and sa_family in @info->rti_info[RTAX_DST].
+ * Needs to be run in network epoch.
+ *
+ * Returns 0 on success and fills in @rc with action result.
+ */
+int
+rib_action(uint32_t fibnum, int action, struct rt_addrinfo *info,
+struct rib_cmd_info *rc)
+{
+   int error;
+
+   switch (action) {
+   case RTM_ADD:
+   error = rib_add_route(fibnum, info, rc);
+   break;
+   case RTM_DELETE:
+   error = rib_del_route(fibnum, info, rc);
+   break;
+   case RTM_CHANGE:
+   error = rib_change_route(fibnum, info, rc);
+   break;
+   default:
+   error = ENOTSUP;
+   }
+
+   return (error);
+}
+
+
 static void
 rt_notifydelete(struct rtentry *rt, struct rt_addrinfo *info)
 {

Modified: head/sys/net/route/route_ctl.h
==
--- head/sys/net/route/route_ctl.h  Wed Jun 10 07:32:02 2020
(r362006)
+++ head/sys/net/route/route_ctl.h  Wed Jun 10 07:46:22 2020
(r362007)
@@ -51,6 +51,8 @@ int rib_del_route(uint32_t fibnum, struct rt_addrinfo 
   struct rib_cmd_info *rc);
 int rib_change_route(uint32_t fibnum, struct rt_addrinfo *info,
   struct rib_cmd_info *rc);
+int rib_action(uint32_t fibnum, int action, struct rt_addrinfo *info,
+  struct rib_cmd_info *rc);
 
 int rib_add_redirect(u_int fibnum, struct sockaddr *dst,
   struct sockaddr *gateway, struct sockaddr *author, struct ifnet *ifp,

Modified: head/sys/net/rtsock.c
==
--- head/sys/net/rtsock.c   Wed Jun 10 07:32:02 2020(r362006)
+++ head/sys/net/rtsock.c   Wed Jun 10 07:46:22 2020(r362007)
@@ -62,6 +62,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #ifdef RADIX_MPATH
 #include 
@@ -181,10 +182,10 @@ static introute_output(struct mbuf *m, struct 
socket 
 static voidrt_getmetrics(const struct rtentry *rt, struct rt_metrics *out);
 static voidrt_dispatch(struct mbuf *, sa_family_t);
 static int handle_rtm_get(struct rt_addrinfo *info, u_int fibnum,
-   struct rt_msghdr *rtm, struct rtentry **ret_nrt);
+   struct rt_msghdr *rtm, struct rib_cmd_info *rc);
 static int update_rtm_from_rte(struct rt_addrinfo *info,
struct rt_msghdr **prtm, int alloc_len,
-   struct rtentry *rt);
+   struct rtentry *rt, struct nhop_object *nh);
 static voidsend_rtm_reply(struct socket *so, struct rt_msghdr *rtm,
struct mbuf *m, sa_family_t saf, u_int fibnum,
int rtm_errno);
@@ -656,10 +657,9 @@ fill_addrinfo(struct rt_msghdr *rtm, int len, u_int fi
  */
 static int
 handle_rtm_get(struct rt_addrinfo *info, u_int fibnum,
-struct rt_msghdr *rtm, struct rtentry **ret_nrt)
+struct rt_msghdr *rtm, struct rib_cmd_info *rc)
 {
RIB_RLOCK_TRACKER;
-   struct rtentry *rt;
struct rib_head *rnh;
sa_family_t saf;
 
@@ -677,14 +677,14 @@ handle_rtm_get(struct rt_addrinfo *info, u_int fibnum,
 * address lookup (no mask).
 * 'route -n get addr'
 */
-   rt = (struct rtentry *) rnh->rnh_matchaddr(
+   rc->rc_rt = (struct rtentry *) rnh->rnh_matchaddr(
info->rti_info[RTAX_DST], >head);
} else
-   rt = (struct rtentry *) rnh->rnh_lookup(
+   rc->rc_rt = (struct rtentry *) rnh->rnh_lookup(
info->rti_info[RTAX_DST],
info->rti_info[RTAX_NETMASK], >head);
 
-   if (rt == NULL) {
+   if (rc->rc_rt == NULL) {
RIB_RUNLOCK(rnh);
return (ESRCH);
}
@@ -695,8 +695,9 @@ handle_rtm_get(struct rt_addrinfo *info, u_int fibnum,
 * (no need to call 

Re: svn commit: r361706 - in head/sys: net net/route netinet netinet6

2020-06-01 Thread Alexander V . Chernikov
01.06.2020, 22:43, "Cy Schubert" :
> In message <6fe2c649-2d81-4c9c-b821-d8226b6bb...@fh-muenster.de>, Michael
> Tuexe
> n writes:
>>  --Apple-Mail=_30A6D176-B5FA-4F13-A949-3CE33C73C3B8
>>  Content-Transfer-Encoding: quoted-printable
>>  Content-Type: text/plain;
>>  charset=us-ascii
>>
>>  > On 1. Jun 2020, at 22:49, Alexander V. Chernikov =
>>   wrote:
>>  >=20
>>  > Author: melifaro
>>  > Date: Mon Jun 1 20:49:42 2020
>>  > New Revision: 361706
>>  > URL: https://svnweb.freebsd.org/changeset/base/361706
>>  >=20
>>  > Log:
>>  > * Add rib__route() functions to manipulate the =
>>  routing table.
>>  >=20
>>  > The main driver for the change is the need to improve notification =
>>  mechanism.
>>  > Currently callers guess the operation data based on the rtentry =
>>  structure
>>  > returned in case of successful operation result. There are two =
>>  problems with
>>  > this appoach. First is that it doesn't provide enough information =
>>  for the
>>  > upcoming multipath changes, where rtentry refers to a new nexthop =
>>  group,
>>  > and there is no way of guessing which paths were added during the =
>>  change.
>>  > Second is that some rtentry fields can change during notification =
>>  and
>>  > protecting from it by requiring customers to unlock rtentry is not =
>>  desired.
>>  >=20
>>  > Additionally, as the consumers such as rtsock do know which operation =
>>  they
>>  > request in advance, making explicit add/change/del versions of the =
>>  functions
>>  > makes sense, especially given the functions don't share a lot of =
>>  code.
>>  >=20
>>  > With that in mind, introduce rib_cmd_info notification structure and
>>  > rib__route() functions, with mandatory rib_cmd_info =
>>  pointer.
>>  > It will be used in upcoming generalized notifications.
>>  >=20
>>  > * Move definitions of the new functions and some other =
>>  functions/structures
>>  > used for the routing table manipulation to a separate header file,
>>  > net/route/route_ctl.h. net/route.h is a frequently used file =
>>  included in
>>  > ~140 places in kernel, and 90% of the users don't need these =
>>  definitions.
>>  >=20
>>  > Reviewed by: ae
>>  > Differential Revision: https://reviews.freebsd.org/D25067
>>  >=20
>>  > 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
>>  >=20
>>  > Modified: head/sys/net/if_llatbl.c
>>  > =
>>  =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
>>  =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
>>  =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
>>  =3D=3D=3D
>>  > --- head/sys/net/if_llatbl.c Mon Jun 1 20:40:40 2020 =
>>  (r361705)
>>  > +++ head/sys/net/if_llatbl.c Mon Jun 1 20:49:42 2020 =
>>  (r361706)
>>  > @@ -58,6 +58,7 @@ __FBSDID("$FreeBSD$");
>>  > #include 
>>  > #include 
>>  > #include 
>>  > +#include 
>>  Where is this file coming from?
>
> That was in r361704 and reverted in r361705, but should have been in this
> commit too.
Thanks for the notification and sorry for the breakage.
Didn't realise it was not added and was testin another change.
Commited back in r361707.
>
>>  Best regards
>>  Michael
>
> --
> Cheers,
> Cy Schubert 
> FreeBSD UNIX:  Web: https://FreeBSD.org
> NTP:  Web: https://nwtime.org
>
> The need of the many outweighs the greed of the few.
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r361708 - head/sys/net/route

2020-06-01 Thread Alexander V. Chernikov
Author: melifaro
Date: Mon Jun  1 21:52:24 2020
New Revision: 361708
URL: https://svnweb.freebsd.org/changeset/base/361708

Log:
  Add rib subscription API.
  
  Currently there is no easy way of subscribing for the routing table changes.
  The only existing way is to set ifa_rtrequest callback in the each protocol
   ifaddr, which is not convenient or extandable.
  
  This change provides generic notification subscription mechanism, that will
   replace current ifa_rtrequest one and allow other applications such as
   accelerated routing lookup modules subscribe for the changes.
  
  In particular, this change provides 2 hooks: 1) synchronous one
   (RIB_NOTIFY_IMMEDIATE), called under RIB_WLOCK, which ensures exact
   ordering of the changes and 2) async one, (RIB_NOTIFY_DELAYED)
   that is called after the change w/o holding locks. The latter one does not
   provide any notification ordering guarantee.
  
  Differential Revision:  https://reviews.freebsd.org/D25070

Modified:
  head/sys/net/route/route_ctl.c
  head/sys/net/route/route_ctl.h

Modified: head/sys/net/route/route_ctl.c
==
--- head/sys/net/route/route_ctl.c  Mon Jun  1 21:51:20 2020
(r361707)
+++ head/sys/net/route/route_ctl.c  Mon Jun  1 21:52:24 2020
(r361708)
@@ -68,10 +68,19 @@ __FBSDID("$FreeBSD$");
  * All functions assumes they are called in net epoch.
  */
 
+struct rib_subscription {
+   CK_STAILQ_ENTRY(rib_subscription)   next;
+   rib_subscription_cb_t   *func;
+   void*arg;
+   enum rib_subscription_type  type;
+   struct epoch_contextepoch_ctx;
+};
+
 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 void destroy_subscription_epoch(epoch_context_t ctx);
 
 static struct rib_head *
 get_rnh(uint32_t fibnum, const struct rt_addrinfo *info)
@@ -263,6 +272,9 @@ add_route(struct rib_head *rnh, struct rt_addrinfo *in
}
RIB_WUNLOCK(rnh);
 
+   if ((rn != NULL) || (rt_old != NULL))
+   rib_notify(rnh, RIB_NOTIFY_DELAYED, rc);
+
if (rt_old != NULL) {
rt_notifydelete(rt_old, info);
rtfree(rt_old);
@@ -419,6 +431,7 @@ del_route(struct rib_head *rnh, struct rt_addrinfo *in
if (error != 0)
return (error);
 
+   rib_notify(rnh, RIB_NOTIFY_DELAYED, rc);
rt_notifydelete(rt, info);
 
/*
@@ -559,11 +572,12 @@ change_route_one(struct rib_head *rnh, struct rt_addri
 
/* Update generation id to reflect rtable change */
rnh->rnh_gen++;
-
rib_notify(rnh, RIB_NOTIFY_IMMEDIATE, rc);
 
RIB_WUNLOCK(rnh);
 
+   rib_notify(rnh, RIB_NOTIFY_DELAYED, rc);
+
nhop_free(nh_orig);
 
return (0);
@@ -614,6 +628,7 @@ struct rt_delinfo
struct rt_addrinfo info;
struct rib_head *rnh;
struct rtentry *head;
+   struct rib_cmd_info rc;
 };
 
 /*
@@ -643,7 +658,13 @@ rt_checkdelroute(struct radix_node *rn, void *arg)
return (0);
}
 
-   /* Entry was unlinked. Add to the list and return */
+   /* Entry was unlinked. Notify subscribers */
+   di->rnh->rnh_gen++;
+   di->rc.rc_rt = rt;
+   di->rc.rc_nh_old = rt->rt_nhop;
+   rib_notify(di->rnh, RIB_NOTIFY_IMMEDIATE, >rc);
+
+   /* Add to the list and return */
rt->rt_chain = di->head;
di->head = rt;
 
@@ -665,6 +686,7 @@ rib_walk_del(u_int fibnum, int family, rt_filter_f_t *
struct rib_head *rnh;
struct rt_delinfo di;
struct rtentry *rt;
+   struct epoch_tracker et;
 
rnh = rt_tables_get_rnh(fibnum, family);
if (rnh == NULL)
@@ -674,20 +696,24 @@ rib_walk_del(u_int fibnum, int family, rt_filter_f_t *
di.info.rti_filter = filter_f;
di.info.rti_filterdata = arg;
di.rnh = rnh;
+   di.rc.rc_cmd = RTM_DELETE;
 
+   NET_EPOCH_ENTER(et);
+
RIB_WLOCK(rnh);
rnh->rnh_walktree(>head, rt_checkdelroute, );
RIB_WUNLOCK(rnh);
 
-   if (di.head == NULL)
-   return;
-
/* We might have something to reclaim. */
while (di.head != NULL) {
rt = di.head;
di.head = rt->rt_chain;
rt->rt_chain = NULL;
 
+   di.rc.rc_rt = rt;
+   di.rc.rc_nh_old = rt->rt_nhop;
+   rib_notify(rnh, RIB_NOTIFY_DELAYED, );
+
/* TODO std rt -> rt_addrinfo export */
di.info.rti_info[RTAX_DST] = rt_key(rt);
di.info.rti_info[RTAX_NETMASK] = rt_mask(rt);
@@ -699,6 +725,8 @@ rib_walk_del(u_int fibnum, int family, rt_filter_f_t *
fibnum);
rtfree(rt);
}
+
+   

svn commit: r361707 - head/sys/net/route

2020-06-01 Thread Alexander V. Chernikov
Author: melifaro
Date: Mon Jun  1 21:51:20 2020
New Revision: 361707
URL: https://svnweb.freebsd.org/changeset/base/361707

Log:
  Finish r361706: add sys/net/route/route_ctl.h, missed in previous commit.

Added:
  head/sys/net/route/route_ctl.h   (contents, props changed)

Added: head/sys/net/route/route_ctl.h
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/sys/net/route/route_ctl.h  Mon Jun  1 21:51:20 2020
(r361707)
@@ -0,0 +1,68 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
+ * Copyright (c) 2020 Alexander V. Chernikov
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+/*
+ * This header file contains public functions and structures used for
+ * routing table manipulations.
+ */
+
+#ifndef_NET_ROUTE_ROUTE_CTL_H_
+#define_NET_ROUTE_ROUTE_CTL_H_
+
+struct rib_cmd_info {
+   uint8_t rc_cmd; /* RTM_ADD|RTM_DEL|RTM_CHANGE */
+   uint8_t spare[3];
+   uint32_trc_nh_weight;   /* new nhop weight */
+   struct rtentry  *rc_rt; /* Target entry */
+   struct nhop_object  *rc_nh_old; /* Target nhop OR mpath */
+   struct nhop_object  *rc_nh_new; /* Target nhop OR mpath */
+};
+
+
+int rib_add_route(uint32_t fibnum, struct rt_addrinfo *info,
+  struct rib_cmd_info *rc);
+int rib_del_route(uint32_t fibnum, struct rt_addrinfo *info,
+  struct rib_cmd_info *rc);
+int rib_change_route(uint32_t fibnum, struct rt_addrinfo *info,
+  struct rib_cmd_info *rc);
+
+int rib_add_redirect(u_int fibnum, struct sockaddr *dst,
+  struct sockaddr *gateway, struct sockaddr *author, struct ifnet *ifp,
+  int flags, int expire_sec);
+
+typedef int rt_walktree_f_t(struct rtentry *, void *);
+void rib_walk(int af, u_int fibnum, rt_walktree_f_t *wa_f, void *arg);
+void rib_walk_del(u_int fibnum, int family, rt_filter_f_t *filter_f,
+  void *arg, bool report);
+
+typedef void rt_setwarg_t(struct rib_head *, uint32_t, int, void *);
+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);
+#endif
+
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r361706 - in head/sys: net net/route netinet netinet6

2020-06-01 Thread Alexander V. Chernikov
Author: melifaro
Date: Mon Jun  1 20:49:42 2020
New Revision: 361706
URL: https://svnweb.freebsd.org/changeset/base/361706

Log:
  * Add rib__route() functions to manipulate the routing table.
  
  The main driver for the change is the need to improve notification mechanism.
  Currently callers guess the operation data based on the rtentry structure
   returned in case of successful operation result. There are two problems with
   this appoach. First is that it doesn't provide enough information for the
   upcoming multipath changes, where rtentry refers to a new nexthop group,
   and there is no way of guessing which paths were added during the change.
   Second is that some rtentry fields can change during notification and
   protecting from it by requiring customers to unlock rtentry is not desired.
  
  Additionally, as the consumers such as rtsock do know which operation they
   request in advance, making explicit add/change/del versions of the functions
   makes sense, especially given the functions don't share a lot of code.
  
  With that in mind, introduce rib_cmd_info notification structure and
   rib__route() functions, with mandatory rib_cmd_info pointer.
   It will be used in upcoming generalized notifications.
  
  * Move definitions of the new functions and some other functions/structures
   used for the routing table manipulation to a separate header file,
   net/route/route_ctl.h. net/route.h is a frequently used file included in
   ~140 places in kernel, and 90% of the users don't need these definitions.
  
  Reviewed by:  ae
  Differential Revision:https://reviews.freebsd.org/D25067

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.cMon Jun  1 20:40:40 2020(r361705)
+++ head/sys/net/if_llatbl.cMon Jun  1 20:49:42 2020(r361706)
@@ -58,6 +58,7 @@ __FBSDID("$FreeBSD$");
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 

Modified: head/sys/net/route.c
==
--- head/sys/net/route.cMon Jun  1 20:40:40 2020(r361705)
+++ head/sys/net/route.cMon Jun  1 20:49:42 2020(r361706)
@@ -61,6 +61,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -346,6 +347,9 @@ rt_table_init(int offset, int family, u_int fibnum)
 
nhops_init_rib(rh);
 
+   /* Init subscription system */
+   CK_STAILQ_INIT(>rnh_subscribers);
+
/* Finally, set base callbacks */
rh->rnh_addaddr = rn_addroute;
rh->rnh_deladdr = rn_delete;
@@ -1148,6 +1152,7 @@ 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"));
@@ -1180,10 +1185,11 @@ rtrequest1_fib(int req, struct rt_addrinfo *info, stru
if (info->rti_flags & RTF_HOST)
info->rti_info[RTAX_NETMASK] = NULL;
 
+   bzero(, sizeof(struct rib_cmd_info));
error = 0;
switch (req) {
case RTM_DELETE:
-   error = del_route(rnh, info, ret_nrt);
+   error = del_route(rnh, info, );
break;
case RTM_RESOLVE:
/*
@@ -1192,14 +1198,17 @@ rtrequest1_fib(int req, struct rt_addrinfo *info, stru
 */
break;
case RTM_ADD:
-   error = add_route(rnh, info, ret_nrt);
+   error = add_route(rnh, info, );
break;
case RTM_CHANGE:
-   error = change_route(rnh, info, ret_nrt);
+   error = change_route(rnh, info, );
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.hMon Jun  1 20:40:40 2020(r361705)
+++ head/sys/net/route.hMon Jun  1 20:49:42 2020(r361706)
@@ -399,12 +399,6 @@ voidrtfree(struct rtentry *);
 voidrtfree_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 

svn commit: r361705 - in head/sys: net net/route netinet netinet6

2020-06-01 Thread Alexander V. Chernikov
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.cMon Jun  1 20:32:02 2020(r361704)
+++ head/sys/net/if_llatbl.cMon 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.cMon Jun  1 20:32:02 2020(r361704)
+++ head/sys/net/route.cMon 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(>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(, sizeof(struct rib_cmd_info));
error = 0;
switch (req) {
case RTM_DELETE:
-   error = del_route(rnh, info, );
+   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, );
+   error = add_route(rnh, info, ret_nrt);
break;
case RTM_CHANGE:
-   error = change_route(rnh, info, );
+   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.hMon Jun  1 20:32:02 2020(r361704)
+++ head/sys/net/route.hMon Jun  1 20:40:40 2020(r361705)
@@ -399,6 +399,12 @@ voidrtfree(struct rtentry *);
 voidrtfree_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 
 intrib_lookup_info(uint32_t, const struct sockaddr *, uint32_t, uint32_t,
struct rt_addrinfo *);
 void   rib_free_info(struct rt_addrinfo *info);
+intrib_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: 

svn commit: r361704 - in head/sys: net net/route netinet netinet6

2020-06-01 Thread Alexander V. Chernikov
 -468,7 +588,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, ret_nrt);
+   error = change_route_one(rnh, info, rc);
if (error != EAGAIN)
break;
}
@@ -581,4 +701,62 @@ 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_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_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_subscribers, rs, rib_subscription, next);
+   RIB_WUNLOCK(rnh);
+
+   free(rs, M_RTABLE);
+   return (0);
+}
 

Added: head/sys/net/route/route_ctl.h
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/sys/net/route/route_ctl.h  Mon Jun  1 20:32:02 2020
(r361704)
@@ -0,0 +1,90 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
+ * Copyright (c) 2020 Alexander V. Chernikov
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+/*
+ * This header file contains public functions and structures used for
+ * routing table manipulations.
+ */
+
+#ifndef_NET_ROUTE_ROUTE_CTL_H_
+#define_NET_ROUTE_ROUTE_CTL_H_
+
+struct rib_cmd_info {
+   uint8_t rc_cmd; /* RTM_ADD|RTM_DEL|RTM_CHANGE */
+   uint8_t spare[3];
+   uint32_trc_nh_weight;   /* new nhop weight */
+   struct rtentry  *rc_rt; /* Target entry */
+   struct nhop_object  *rc_nh_old; /* Target nhop OR mpath */
+   struct nhop_object  *rc_nh_new; /* Target nhop OR mpath */
+};
+
+
+int rib_add_route(uint32_t fibnum, struct rt_addrinfo *info,
+  struct rib_cmd_info *rc);
+int rib_del_route(uint32_t fibnum, struct rt_addrinfo *info,
+  struct rib_cmd_info *rc);
+int rib_change_route(uint32_t fibnum, struct rt_addrinfo *info,
+  struct rib_cmd_info *rc);
+
+int rib_add_redirect(u_int fibnum, struct sockaddr *dst,
+  struct sockaddr *gateway, struct sockaddr *author, struct ifnet *ifp,
+  int flags, int expire_sec);
+
+typedef int rt_walktree_f_t(struct rtentry *, void *);
+void rib_walk(int af, u_int fibnum, rt_walktree_f_

svn commit: r361584 - head/sys/fs/nfsclient

2020-05-28 Thread Alexander V. Chernikov
Author: melifaro
Date: Thu May 28 09:52:28 2020
New Revision: 361584
URL: https://svnweb.freebsd.org/changeset/base/361584

Log:
  Fix NOINET6 build broken by r361575.
  
  Reported by:  ci, hps

Modified:
  head/sys/fs/nfsclient/nfs_clport.c

Modified: head/sys/fs/nfsclient/nfs_clport.c
==
--- head/sys/fs/nfsclient/nfs_clport.c  Thu May 28 09:13:20 2020
(r361583)
+++ head/sys/fs/nfsclient/nfs_clport.c  Thu May 28 09:52:28 2020
(r361584)
@@ -971,7 +971,7 @@ u_int8_t *
 nfscl_getmyip(struct nfsmount *nmp, struct in6_addr *paddr, int *isinet6p)
 {
 #if defined(INET6) || defined(INET)
-   int error, fibnum;
+   int fibnum;
 
fibnum = curthread->td_proc->p_fibnum;
 #endif
@@ -1007,6 +1007,7 @@ nfscl_getmyip(struct nfsmount *nmp, struct in6_addr *p
 #ifdef INET6
if (nmp->nm_nam->sa_family == AF_INET6) {
struct sockaddr_in6 *sin6;
+   int error;
 
sin6 = (struct sockaddr_in6 *)nmp->nm_nam;
 
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r361576 - in head/sys: netinet netinet6

2020-05-28 Thread Alexander V. Chernikov
Author: melifaro
Date: Thu May 28 08:00:08 2020
New Revision: 361576
URL: https://svnweb.freebsd.org/changeset/base/361576

Log:
  Use fib[46]_lookup() in mtu calculations.
  
  fib[46]_lookup_nh_ represents pre-epoch generation of fib api,
  providing less guarantees over pointer validness and requiring
  on-stack data copying.
  
  Conversion is straight-forwarded, as the only 2 differences are
  requirement of running in network epoch and the need to handle
  RTF_GATEWAY case in the caller code.
  
  Differential Revision:https://reviews.freebsd.org/D24974

Modified:
  head/sys/netinet/tcp_subr.c
  head/sys/netinet6/icmp6.c

Modified: head/sys/netinet/tcp_subr.c
==
--- head/sys/netinet/tcp_subr.c Thu May 28 07:35:07 2020(r361575)
+++ head/sys/netinet/tcp_subr.c Thu May 28 08:00:08 2020(r361576)
@@ -2920,7 +2920,7 @@ tcp_mtudisc(struct inpcb *inp, int mtuoffer)
 uint32_t
 tcp_maxmtu(struct in_conninfo *inc, struct tcp_ifcap *cap)
 {
-   struct nhop4_extended nh4;
+   struct nhop_object *nh;
struct ifnet *ifp;
uint32_t maxmtu = 0;
 
@@ -2928,12 +2928,12 @@ tcp_maxmtu(struct in_conninfo *inc, struct tcp_ifcap *
 
if (inc->inc_faddr.s_addr != INADDR_ANY) {
 
-   if (fib4_lookup_nh_ext(inc->inc_fibnum, inc->inc_faddr,
-   NHR_REF, 0, ) != 0)
+   nh = fib4_lookup(inc->inc_fibnum, inc->inc_faddr, 0, NHR_NONE, 
0);
+   if (nh == NULL)
return (0);
 
-   ifp = nh4.nh_ifp;
-   maxmtu = nh4.nh_mtu;
+   ifp = nh->nh_ifp;
+   maxmtu = nh->nh_mtu;
 
/* Report additional interface capabilities. */
if (cap != NULL) {
@@ -2945,7 +2945,6 @@ tcp_maxmtu(struct in_conninfo *inc, struct tcp_ifcap *
cap->tsomaxsegsize = ifp->if_hw_tsomaxsegsize;
}
}
-   fib4_free_nh_ext(inc->inc_fibnum, );
}
return (maxmtu);
 }
@@ -2955,7 +2954,7 @@ tcp_maxmtu(struct in_conninfo *inc, struct tcp_ifcap *
 uint32_t
 tcp_maxmtu6(struct in_conninfo *inc, struct tcp_ifcap *cap)
 {
-   struct nhop6_extended nh6;
+   struct nhop_object *nh;
struct in6_addr dst6;
uint32_t scopeid;
struct ifnet *ifp;
@@ -2968,12 +2967,12 @@ tcp_maxmtu6(struct in_conninfo *inc, struct tcp_ifcap 
 
if (!IN6_IS_ADDR_UNSPECIFIED(>inc6_faddr)) {
in6_splitscope(>inc6_faddr, , );
-   if (fib6_lookup_nh_ext(inc->inc_fibnum, , scopeid, 0,
-   0, ) != 0)
+   nh = fib6_lookup(inc->inc_fibnum, , scopeid, NHR_NONE, 0);
+   if (nh == NULL)
return (0);
 
-   ifp = nh6.nh_ifp;
-   maxmtu = nh6.nh_mtu;
+   ifp = nh->nh_ifp;
+   maxmtu = nh->nh_mtu;
 
/* Report additional interface capabilities. */
if (cap != NULL) {
@@ -2985,7 +2984,6 @@ tcp_maxmtu6(struct in_conninfo *inc, struct tcp_ifcap 
cap->tsomaxsegsize = ifp->if_hw_tsomaxsegsize;
}
}
-   fib6_free_nh_ext(inc->inc_fibnum, );
}
 
return (maxmtu);

Modified: head/sys/netinet6/icmp6.c
==
--- head/sys/netinet6/icmp6.c   Thu May 28 07:35:07 2020(r361575)
+++ head/sys/netinet6/icmp6.c   Thu May 28 08:00:08 2020(r361576)
@@ -402,6 +402,8 @@ icmp6_input(struct mbuf **mp, int *offp, int proto)
char ip6bufs[INET6_ADDRSTRLEN], ip6bufd[INET6_ADDRSTRLEN];
int code, error, icmp6len, ip6len, noff, off, sum;
 
+   NET_EPOCH_ASSERT();
+
m = *mp;
off = *offp;
 
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r361575 - head/sys/fs/nfsclient

2020-05-28 Thread Alexander V. Chernikov
Author: melifaro
Date: Thu May 28 07:35:07 2020
New Revision: 361575
URL: https://svnweb.freebsd.org/changeset/base/361575

Log:
  Make NFS address selection use fib4_lookup().
  
  fib4_lookup_nh_ represents pre-epoch generation of fib api,
  providing less guarantees over pointer validness and requiring
  on-stack data copying.
  Switch call to use new fib4_lookup(), allowing to eventually
  deprecate old api.
  
  Differential Revision:https://reviews.freebsd.org/D24977

Modified:
  head/sys/fs/nfsclient/nfs_clport.c

Modified: head/sys/fs/nfsclient/nfs_clport.c
==
--- head/sys/fs/nfsclient/nfs_clport.c  Thu May 28 07:31:53 2020
(r361574)
+++ head/sys/fs/nfsclient/nfs_clport.c  Thu May 28 07:35:07 2020
(r361575)
@@ -53,6 +53,7 @@ __FBSDID("$FreeBSD$");
 #include 
 #include 
 #include 
+#include 
 
 #include 
 
@@ -976,24 +977,29 @@ nfscl_getmyip(struct nfsmount *nmp, struct in6_addr *p
 #endif
 #ifdef INET
if (nmp->nm_nam->sa_family == AF_INET) {
+   struct epoch_tracker et;
+   struct nhop_object *nh;
struct sockaddr_in *sin;
-   struct nhop4_extended nh_ext;
+   struct in_addr addr = {};
 
sin = (struct sockaddr_in *)nmp->nm_nam;
+   NET_EPOCH_ENTER(et);
CURVNET_SET(CRED_TO_VNET(nmp->nm_sockreq.nr_cred));
-   error = fib4_lookup_nh_ext(fibnum, sin->sin_addr, 0, 0,
-   _ext);
+   nh = fib4_lookup(fibnum, sin->sin_addr, 0, NHR_NONE, 0);
CURVNET_RESTORE();
-   if (error != 0)
+   if (nh != NULL)
+   addr = IA_SIN(ifatoia(nh->nh_ifa))->sin_addr;
+   NET_EPOCH_EXIT(et);
+   if (nh == NULL)
return (NULL);
 
-   if (IN_LOOPBACK(ntohl(nh_ext.nh_src.s_addr))) {
+   if (IN_LOOPBACK(ntohl(addr.s_addr))) {
/* Ignore loopback addresses */
return (NULL);
}
 
*isinet6p = 0;
-   *((struct in_addr *)paddr) = nh_ext.nh_src;
+   *((struct in_addr *)paddr) = addr;
 
return (u_int8_t *)paddr;
}
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r361574 - head/sys/netinet

2020-05-28 Thread Alexander V. Chernikov
Author: melifaro
Date: Thu May 28 07:31:53 2020
New Revision: 361574
URL: https://svnweb.freebsd.org/changeset/base/361574

Log:
  Switch ip_output/icmp_reflect rt lookup calls with fib4_lookup.
  
  fib4_lookup_nh_ represents pre-epoch generation of fib api,
  providing less guarantees over pointer validness and requiring
  on-stack data copying.
  
  Conversion is straight-forwarded, as the only 2 differences are
  requirement of running in network epoch and the need to handle
  RTF_GATEWAY case in the caller code.
  
  Reviewed by:  ae
  Differential Revision:https://reviews.freebsd.org/D24976

Modified:
  head/sys/netinet/ip_icmp.c
  head/sys/netinet/ip_output.c

Modified: head/sys/netinet/ip_icmp.c
==
--- head/sys/netinet/ip_icmp.c  Thu May 28 07:29:44 2020(r361573)
+++ head/sys/netinet/ip_icmp.c  Thu May 28 07:31:53 2020(r361574)
@@ -764,7 +764,7 @@ icmp_reflect(struct mbuf *m)
struct ifnet *ifp;
struct in_ifaddr *ia;
struct in_addr t;
-   struct nhop4_extended nh_ext;
+   struct nhop_object *nh;
struct mbuf *opts = NULL;
int optlen = (ip->ip_hl << 2) - sizeof(struct ip);
 
@@ -851,12 +851,13 @@ icmp_reflect(struct mbuf *m)
 * When we don't have a route back to the packet source, stop here
 * and drop the packet.
 */
-   if (fib4_lookup_nh_ext(M_GETFIB(m), ip->ip_dst, 0, 0, _ext) != 0) {
+   nh = fib4_lookup(M_GETFIB(m), ip->ip_dst, 0, NHR_NONE, 0);
+   if (nh == NULL) {
m_freem(m);
ICMPSTAT_INC(icps_noroute);
goto done;
}
-   t = nh_ext.nh_src;
+   t = IA_SIN(ifatoia(nh->nh_ifa))->sin_addr;
 match:
 #ifdef MAC
mac_netinet_icmp_replyinplace(m);

Modified: head/sys/netinet/ip_output.c
==
--- head/sys/netinet/ip_output.cThu May 28 07:29:44 2020
(r361573)
+++ head/sys/netinet/ip_output.cThu May 28 07:31:53 2020
(r361574)
@@ -512,11 +512,10 @@ again:
mtu = ifp->if_mtu;
src = IA_SIN(ia)->sin_addr;
} else {
-   struct nhop4_extended nh;
+   struct nhop_object *nh;
 
-   bzero(, sizeof(nh));
-   if (fib4_lookup_nh_ext(M_GETFIB(m), ip->ip_dst, 0, 0, ) !=
-   0) {
+   nh = fib4_lookup(M_GETFIB(m), ip->ip_dst, 0, NHR_NONE, 0);
+   if (nh == NULL) {
 #if defined(IPSEC) || defined(IPSEC_SUPPORT)
/*
 * There is no route for this packet, but it is
@@ -530,8 +529,8 @@ again:
error = EHOSTUNREACH;
goto bad;
}
-   ifp = nh.nh_ifp;
-   mtu = nh.nh_mtu;
+   ifp = nh->nh_ifp;
+   mtu = nh->nh_mtu;
/*
 * We are rewriting here dst to be gw actually, contradicting
 * comment at the beginning of the function. However, in this
@@ -540,10 +539,11 @@ again:
 * function, the dst would be rewritten by ip_output_pfil().
 */
MPASS(dst == );
-   dst->sin_addr = nh.nh_addr;
-   ia = nh.nh_ia;
-   src = nh.nh_src;
-   isbroadcast = (((nh.nh_flags & (NHF_HOST | NHF_BROADCAST)) ==
+   if (nh->nh_flags & NHF_GATEWAY)
+   dst->sin_addr = nh->gw4_sa.sin_addr;
+   ia = ifatoia(nh->nh_ifa);
+   src = IA_SIN(ia)->sin_addr;
+   isbroadcast = (((nh->nh_flags & (NHF_HOST | NHF_BROADCAST)) ==
(NHF_HOST | NHF_BROADCAST)) ||
((ifp->if_flags & IFF_BROADCAST) &&
in_ifaddr_broadcast(dst->sin_addr, ia)));
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r361573 - head/sys/netinet6

2020-05-28 Thread Alexander V. Chernikov
Author: melifaro
Date: Thu May 28 07:29:44 2020
New Revision: 361573
URL: https://svnweb.freebsd.org/changeset/base/361573

Log:
  Replace ip6_ouput fib6_lookup_nh_ calls with fib6_lookup().
  
  fib6_lookup_nh_ represents pre-epoch generation of fib api,
  providing less guarantees over pointer validness and requiring
  on-stack data copying.
  
  Conversion is straight-forwarded, as the only 2 differences are
  requirement of running in network epoch and the need to handle
  RTF_GATEWAY case in the caller code.
  
  Reviewed by:  ae
  Differential Revision:https://reviews.freebsd.org/D24973

Modified:
  head/sys/netinet6/ip6_output.c

Modified: head/sys/netinet6/ip6_output.c
==
--- head/sys/netinet6/ip6_output.c  Thu May 28 07:26:18 2020
(r361572)
+++ head/sys/netinet6/ip6_output.c  Thu May 28 07:29:44 2020
(r361573)
@@ -736,7 +736,7 @@ again:
counter_u64_add(nh->nh_pksent, 1);
}
} else {
-   struct nhop6_extended nh6;
+   struct nhop_object *nh;
struct in6_addr kdst;
uint32_t scopeid;
 
@@ -766,20 +766,19 @@ again:
}
}
 
-   error = fib6_lookup_nh_ext(fibnum, , scopeid, NHR_REF, 0,
-   );
-   if (error != 0) {
+   nh = fib6_lookup(fibnum, , scopeid, NHR_NONE, 0);
+   if (nh == NULL) {
IP6STAT_INC(ip6s_noroute);
/* No ifp in6_ifstat_inc(ifp, ifs6_out_discard); */
error = EHOSTUNREACH;;
goto bad;
}
 
-   ifp = nh6.nh_ifp;
-   mtu = nh6.nh_mtu;
-   dst->sin6_addr = nh6.nh_addr;
-   ia = nh6.nh_ia;
-   fib6_free_nh_ext(fibnum, );
+   ifp = nh->nh_ifp;
+   mtu = nh->nh_mtu;
+   ia = ifatoia6(nh->nh_ifa);
+   if (nh->nh_flags & NHF_GATEWAY)
+   dst->sin6_addr = nh->gw6_sa.sin6_addr;
 nonh6lookup:
;
}
@@ -1449,23 +1448,22 @@ ip6_insertfraghdr(struct mbuf *m0, struct mbuf *m, int
 static int
 ip6_getpmtu_ctl(u_int fibnum, const struct in6_addr *dst, u_long *mtup)
 {
-   struct nhop6_extended nh6;
+   struct epoch_tracker et;
+   struct nhop_object *nh;
struct in6_addr kdst;
uint32_t scopeid;
-   struct ifnet *ifp;
-   u_long mtu;
int error;
 
in6_splitscope(dst, , );
-   if (fib6_lookup_nh_ext(fibnum, , scopeid, NHR_REF, 0, ) != 0)
-   return (EHOSTUNREACH);
 
-   ifp = nh6.nh_ifp;
-   mtu = nh6.nh_mtu;
+   NET_EPOCH_ENTER(et);
+   nh = fib6_lookup(fibnum, , scopeid, NHR_NONE, 0);
+   if (nh != NULL)
+   error = ip6_calcmtu(nh->nh_ifp, dst, nh->nh_mtu, mtup, NULL, 0);
+   else
+   error = EHOSTUNREACH;
+   NET_EPOCH_EXIT(et);
 
-   error = ip6_calcmtu(ifp, dst, mtu, mtup, NULL, 0);
-   fib6_free_nh_ext(fibnum, );
-
return (error);
 }
 
@@ -1484,12 +1482,14 @@ ip6_getpmtu(struct route_in6 *ro_pmtu, int do_lookup,
 struct ifnet *ifp, const struct in6_addr *dst, u_long *mtup,
 int *alwaysfragp, u_int fibnum, u_int proto)
 {
-   struct nhop6_basic nh6;
+   struct nhop_object *nh;
struct in6_addr kdst;
uint32_t scopeid;
struct sockaddr_in6 *sa6_dst, sin6;
u_long mtu;
 
+   NET_EPOCH_ASSERT();
+
mtu = 0;
if (ro_pmtu == NULL || do_lookup) {
 
@@ -1512,9 +1512,9 @@ ip6_getpmtu(struct route_in6 *ro_pmtu, int do_lookup,
sa6_dst->sin6_addr = *dst;
 
in6_splitscope(dst, , );
-   if (fib6_lookup_nh_basic(fibnum, , scopeid, 0, 0,
-   ) == 0) {
-   mtu = nh6.nh_mtu;
+   nh = fib6_lookup(fibnum, , scopeid, NHR_NONE, 0);
+   if (nh != NULL) {
+   mtu = nh->nh_mtu;
if (ro_pmtu != NULL)
ro_pmtu->ro_mtu = mtu;
}
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r361572 - in head/sys: netinet netinet6

2020-05-28 Thread Alexander V. Chernikov
Author: melifaro
Date: Thu May 28 07:26:18 2020
New Revision: 361572
URL: https://svnweb.freebsd.org/changeset/base/361572

Log:
  Switch gif(4) path verification to fib[46]_check_urfp().
  
  fibX_lookup_nh_ represents pre-epoch generation of fib api,
  providing less guarantees over pointer validness and requiring
  on-stack data copying.
  Use specialized fib[46]_check_urpf() from newer KPI instead,
  to allow removal of older KPI.
  
  Reviewed by:  ae
  Differential Revision:https://reviews.freebsd.org/D24978

Modified:
  head/sys/netinet/in_gif.c
  head/sys/netinet6/in6_gif.c

Modified: head/sys/netinet/in_gif.c
==
--- head/sys/netinet/in_gif.c   Thu May 28 07:23:27 2020(r361571)
+++ head/sys/netinet/in_gif.c   Thu May 28 07:26:18 2020(r361572)
@@ -379,13 +379,8 @@ done:
return (0);
/* ingress filters on outer source */
if ((GIF2IFP(sc)->if_flags & IFF_LINK2) == 0) {
-   struct nhop4_basic nh4;
-   struct in_addr dst;
-
-   dst = ip->ip_src;
-   if (fib4_lookup_nh_basic(sc->gif_fibnum, dst, 0, 0, ) != 0)
-   return (0);
-   if (nh4.nh_ifp != m->m_pkthdr.rcvif)
+   if (fib4_check_urpf(sc->gif_fibnum, ip->ip_src, 0, NHR_NONE,
+   m->m_pkthdr.rcvif) == 0)
return (0);
}
*arg = sc;

Modified: head/sys/netinet6/in6_gif.c
==
--- head/sys/netinet6/in6_gif.c Thu May 28 07:23:27 2020(r361571)
+++ head/sys/netinet6/in6_gif.c Thu May 28 07:26:18 2020(r361572)
@@ -402,13 +402,9 @@ done:
return (0);
/* ingress filters on outer source */
if ((GIF2IFP(sc)->if_flags & IFF_LINK2) == 0) {
-   struct nhop6_basic nh6;
-
-   if (fib6_lookup_nh_basic(sc->gif_fibnum, >ip6_src,
-   ntohs(in6_getscope(>ip6_src)), 0, 0, ) != 0)
-   return (0);
-
-   if (nh6.nh_ifp != m->m_pkthdr.rcvif)
+   if (fib6_check_urpf(sc->gif_fibnum, >ip6_src,
+   ntohs(in6_getscope(>ip6_src)), NHR_NONE,
+   m->m_pkthdr.rcvif) == 0)
return (0);
}
*arg = sc;
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r361571 - head/sys/net

2020-05-28 Thread Alexander V. Chernikov
Author: melifaro
Date: Thu May 28 07:23:27 2020
New Revision: 361571
URL: https://svnweb.freebsd.org/changeset/base/361571

Log:
  Unlock rtentry before calling for epoch(9) destruction as the destruction
may happen immediately, leading to panic.
  
  Reported by:  bdragon

Modified:
  head/sys/net/route.c

Modified: head/sys/net/route.c
==
--- head/sys/net/route.cThu May 28 03:08:50 2020(r361570)
+++ head/sys/net/route.cThu May 28 07:23:27 2020(r361571)
@@ -411,9 +411,9 @@ rtfree(struct rtentry *rt)
 
RT_LOCK_ASSERT(rt);
 
+   RT_UNLOCK(rt);
epoch_call(net_epoch_preempt, destroy_rtentry_epoch,
>rt_epoch_ctx);
-   RT_UNLOCK(rt);
 }
 
 static void
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r361421 - in head/sys: net net/route netinet netinet6

2020-05-23 Thread Alexander V. Chernikov
Author: melifaro
Date: Sat May 23 19:06:57 2020
New Revision: 361421
URL: https://svnweb.freebsd.org/changeset/base/361421

Log:
  Move _route() functions to route_ctl.c in preparation of
   multipath control plane changed described in D24141.
  
  Currently route.c contains core routing init/teardown functions, route table
   manipulation functions and various helper functions, resulting in >2KLOC
   file in total. This change moves most of the route table manipulation parts
   to a dedicated file, simplifying planned multipath changes and making
   route.c more manageable.
  
  Differential Revision:https://reviews.freebsd.org/D24870

Modified:
  head/sys/net/if_var.h
  head/sys/net/route.c
  head/sys/net/route/route_ctl.c
  head/sys/net/route/route_var.h
  head/sys/net/route/shared.h
  head/sys/netinet/in_fib.c
  head/sys/netinet6/in6_fib.c

Modified: head/sys/net/if_var.h
==
--- head/sys/net/if_var.h   Sat May 23 18:03:19 2020(r361420)
+++ head/sys/net/if_var.h   Sat May 23 19:06:57 2020(r361421)
@@ -686,8 +686,8 @@ int ifa_ifwithaddr_check(const struct sockaddr *);
 struct ifaddr *ifa_ifwithbroadaddr(const struct sockaddr *, int);
 struct ifaddr *ifa_ifwithdstaddr(const struct sockaddr *, int);
 struct ifaddr *ifa_ifwithnet(const struct sockaddr *, int, int);
-struct ifaddr *ifa_ifwithroute(int, const struct sockaddr *, struct sockaddr *,
-u_int);
+struct ifaddr *ifa_ifwithroute(int, const struct sockaddr *,
+const struct sockaddr *, u_int);
 struct ifaddr *ifaof_ifpforaddr(const struct sockaddr *, struct ifnet *);
 intifa_preferred(struct ifaddr *, struct ifaddr *);
 

Modified: head/sys/net/route.c
==
--- head/sys/net/route.cSat May 23 18:03:19 2020(r361420)
+++ head/sys/net/route.cSat May 23 19:06:57 2020(r361421)
@@ -121,45 +121,17 @@ VNET_DEFINE(struct rib_head *, rt_tables);
 #defineV_rt_tables VNET(rt_tables)
 
 
-/*
- * Convert a 'struct radix_node *' to a 'struct rtentry *'.
- * The operation can be done safely (in this code) because a
- * 'struct rtentry' starts with two 'struct radix_node''s, the first
- * one representing leaf nodes in the routing tree, which is
- * what the code in radix.c passes us as a 'struct radix_node'.
- *
- * But because there are a lot of assumptions in this conversion,
- * do not cast explicitly, but always use the macro below.
- */
-#define RNTORT(p)  ((struct rtentry *)(p))
-
-VNET_DEFINE_STATIC(uma_zone_t, rtzone);/* Routing table UMA 
zone. */
+VNET_DEFINE(uma_zone_t, rtzone);   /* Routing table UMA zone. */
 #defineV_rtzoneVNET(rtzone)
 
 EVENTHANDLER_LIST_DEFINE(rt_addrmsg);
 
-static int rt_getifa_fib(struct rt_addrinfo *, u_int);
-static void rt_setmetrics(const struct rt_addrinfo *, struct rtentry *);
 static int rt_ifdelroute(const struct rtentry *rt, const struct nhop_object *,
 void *arg);
-static struct rtentry *rt_unlinkrte(struct rib_head *rnh,
-struct rt_addrinfo *info, int *perror);
-static void rt_notifydelete(struct rtentry *rt, struct rt_addrinfo *info);
 static void destroy_rtentry_epoch(epoch_context_t ctx);
-#ifdef RADIX_MPATH
-static struct radix_node *rt_mpath_unlink(struct rib_head *rnh,
-struct rt_addrinfo *info, struct rtentry *rto, int *perror);
-#endif
 static int rt_exportinfo(struct rtentry *rt, struct rt_addrinfo *info,
 int flags);
 
-static int add_route(struct rib_head *rnh, struct rt_addrinfo *info,
-struct rtentry **ret_nrt);
-static int del_route(struct rib_head *rnh, struct rt_addrinfo *info,
-struct rtentry **ret_nrt);
-static int change_route(struct rib_head *, struct rt_addrinfo *,
-struct rtentry **);
-
 /*
  * handler for net.my_fibnum
  */
@@ -572,8 +544,8 @@ rtioctl_fib(u_long req, caddr_t data, u_int fibnum)
 }
 
 struct ifaddr *
-ifa_ifwithroute(int flags, const struct sockaddr *dst, struct sockaddr 
*gateway,
-   u_int fibnum)
+ifa_ifwithroute(int flags, const struct sockaddr *dst,
+const struct sockaddr *gateway, u_int fibnum)
 {
struct ifaddr *ifa;
 
@@ -839,99 +811,7 @@ rt_foreach_fib_walk(int af, rt_setwarg_t *setwa_f, rt_
}
 }
 
-struct rt_delinfo
-{
-   struct rt_addrinfo info;
-   struct rib_head *rnh;
-   struct rtentry *head;
-};
-
 /*
- * Conditionally unlinks @rn from radix tree based
- * on info data passed in @arg.
- */
-static int
-rt_checkdelroute(struct radix_node *rn, void *arg)
-{
-   struct rt_delinfo *di;
-   struct rt_addrinfo *info;
-   struct rtentry *rt;
-   int error;
-
-   di = (struct rt_delinfo *)arg;
-   rt = (struct rtentry *)rn;
-   info = >info;
-   error = 0;
-
-   info->rti_info[RTAX_DST] = rt_key(rt);
-   info->rti_info[RTAX_NETMASK] = rt_mask(rt);
-   

svn commit: r361415 - in head/sys/net: . route

2020-05-23 Thread Alexander V. Chernikov
Author: melifaro
Date: Sat May 23 12:15:47 2020
New Revision: 361415
URL: https://svnweb.freebsd.org/changeset/base/361415

Log:
  Remove refcounting from rtentry.
  
  After making rtentry reclamation backed by epoch(9) in r361409, there is
   no reason in keeping reference counting code.
  
  Differential Revision:https://reviews.freebsd.org/D24867

Modified:
  head/sys/net/route.c
  head/sys/net/route/route_var.h

Modified: head/sys/net/route.c
==
--- head/sys/net/route.cSat May 23 12:00:46 2020(r361414)
+++ head/sys/net/route.cSat May 23 12:15:47 2020(r361415)
@@ -439,39 +439,8 @@ rtfree(struct rtentry *rt)
 
RT_LOCK_ASSERT(rt);
 
-   /*
-* The callers should use RTFREE_LOCKED() or RTFREE(), so
-* we should come here exactly with the last reference.
-*/
-   RT_REMREF(rt);
-   if (rt->rt_refcnt > 0) {
-   log(LOG_DEBUG, "%s: %p has %d refs\n", __func__, rt, 
rt->rt_refcnt);
-   goto done;
-   }
-
-   /*
-* If we are no longer "up" (and ref == 0)
-* then we can free the resources associated
-* with the route.
-*/
-   if ((rt->rt_flags & RTF_UP) == 0) {
-   if (rt->rt_nodes->rn_flags & (RNF_ACTIVE | RNF_ROOT))
-   panic("rtfree 2");
-#ifdef DIAGNOSTIC
-   if (rt->rt_refcnt < 0) {
-   printf("rtfree: %p not freed (neg refs)\n", rt);
-   goto done;
-   }
-#endif
-   epoch_call(net_epoch_preempt, destroy_rtentry_epoch,
-   >rt_epoch_ctx);
-
-   /*
-* FALLTHROUGH to RT_UNLOCK() so the reporting functions
-* have consistent behaviour of operating on unlocked entry.
-*/
-   }
-done:
+   epoch_call(net_epoch_preempt, destroy_rtentry_epoch,
+   >rt_epoch_ctx);
RT_UNLOCK(rt);
 }
 
@@ -958,7 +927,7 @@ rib_walk_del(u_int fibnum, int family, rt_filter_f_t *
if (report)
rt_routemsg(RTM_DELETE, rt, rt->rt_nhop->nh_ifp, 0,
fibnum);
-   RTFREE_LOCKED(rt);
+   rtfree(rt);
}
 }
 
@@ -1114,7 +1083,6 @@ rt_unlinkrte(struct rib_head *rnh, struct rt_addrinfo 
 
rt = RNTORT(rn);
RT_LOCK(rt);
-   RT_ADDREF(rt);
rt->rt_flags &= ~RTF_UP;
 
*perror = 0;
@@ -1569,8 +1537,10 @@ add_route(struct rib_head *rnh, struct rt_addrinfo *in
}
RIB_WUNLOCK(rnh);
 
-   if (rt_old != NULL)
-   RT_UNLOCK(rt_old);
+   if (rt_old != NULL) {
+   rt_notifydelete(rt_old, info);
+   rtfree(rt_old);
+   }
 
/*
 * If it still failed to go into the tree,
@@ -1582,11 +1552,6 @@ add_route(struct rib_head *rnh, struct rt_addrinfo *in
return (EEXIST);
} 
 
-   if (rt_old != NULL) {
-   rt_notifydelete(rt_old, info);
-   RTFREE(rt_old);
-   }
-
/*
 * If this protocol has something to add to this then
 * allow it to do that as well.
@@ -1639,7 +1604,7 @@ del_route(struct rib_head *rnh, struct rt_addrinfo *in
if (ret_nrt)
*ret_nrt = rt;
 
-   RTFREE_LOCKED(rt);
+   rtfree(rt);
 
return (0);
 }

Modified: head/sys/net/route/route_var.h
==
--- head/sys/net/route/route_var.h  Sat May 23 12:00:46 2020
(r361414)
+++ head/sys/net/route/route_var.h  Sat May 23 12:15:47 2020
(r361415)
@@ -143,7 +143,6 @@ struct rtentry {
};
 
int rt_flags;   /* up/down?, host/net */
-   int rt_refcnt;  /* # held references */
u_long  rt_weight;  /* absolute weight */ 
u_long  rt_expire;  /* lifetime for route, e.g. redirect */
 #definert_endzero  rt_mtx
@@ -161,36 +160,6 @@ struct rtentry {
 #defineRT_UNLOCK_COND(_rt) do {\
if (mtx_owned(&(_rt)->rt_mtx))  \
mtx_unlock(&(_rt)->rt_mtx); \
-} while (0)
-
-#defineRT_ADDREF(_rt)  do {\
-   RT_LOCK_ASSERT(_rt);\
-   KASSERT((_rt)->rt_refcnt >= 0,  \
-   ("negative refcnt %d", (_rt)->rt_refcnt));  \
-   (_rt)->rt_refcnt++; \
-} while (0)
-
-#defineRT_REMREF(_rt)  do {\
-   RT_LOCK_ASSERT(_rt);\
-   KASSERT((_rt)->rt_refcnt > 0,   \
-   ("bogus refcnt %d", (_rt)->rt_refcnt)); \
-   

svn commit: r361409 - in head/sys: fs/nfsclient net net/route netinet6 nfs

2020-05-23 Thread Alexander V. Chernikov
Author: melifaro
Date: Sat May 23 10:21:02 2020
New Revision: 361409
URL: https://svnweb.freebsd.org/changeset/base/361409

Log:
  Use epoch(9) for rtentries to simplify control plane operations.
  
  Currently the only reason of refcounting rtentries is the need to report
   the rtable operation details immediately after the execution.
  Delaying rtentry reclamation allows to stop refcounting and simplify the code.
  Additionally, this change allows to reimplement rib_lookup_info(), which
   is used by some of the customers to get the matching prefix along
   with nexthops, in more efficient way.
  
  The change keeps per-vnet rtzone uma zone. It adds nh_vnet field to
   nhop_priv to be able to reliably set curvnet even during vnet teardown.
  Rest of the reference counting code will be removed in the D24867 .
  
  Differential Revision:https://reviews.freebsd.org/D24866

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/net/route/nhop.h
  head/sys/net/route/nhop_ctl.c
  head/sys/net/route/nhop_var.h
  head/sys/net/route/route_var.h
  head/sys/net/rtsock.c
  head/sys/netinet6/nd6.c
  head/sys/netinet6/nd6_rtr.c
  head/sys/nfs/bootp_subr.c

Modified: head/sys/fs/nfsclient/nfs_clvfsops.c
==
--- head/sys/fs/nfsclient/nfs_clvfsops.cSat May 23 03:32:08 2020
(r361408)
+++ head/sys/fs/nfsclient/nfs_clvfsops.cSat May 23 10:21:02 2020
(r361409)
@@ -465,18 +465,21 @@ nfs_mountroot(struct mount *mp)
if (nd->mygateway.sin_len != 0 &&
nd->mygateway.sin_addr.s_addr != 0) {
struct sockaddr_in mask, sin;
+   struct epoch_tracker et;
 
bzero((caddr_t), sizeof(mask));
sin = mask;
sin.sin_family = AF_INET;
sin.sin_len = sizeof(sin);
 /* 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 *),
(struct sockaddr *)>mygateway,
(struct sockaddr *),
RTF_UP | RTF_GATEWAY, NULL, RT_DEFAULT_FIB);
CURVNET_RESTORE();
+   NET_EPOCH_EXIT(et);
if (error)
panic("nfs_mountroot: RTM_ADD: %d", error);
}

Modified: head/sys/net/if.c
==
--- head/sys/net/if.c   Sat May 23 03:32:08 2020(r361408)
+++ head/sys/net/if.c   Sat May 23 10:21:02 2020(r361409)
@@ -1854,18 +1854,17 @@ ifa_maintain_loopback_route(int cmd, const char *otype
 
ifp = ifa->ifa_ifp;
 
+   NET_EPOCH_ENTER(et);
bzero(, sizeof(info));
if (cmd != RTM_DELETE)
info.rti_ifp = V_loif;
if (cmd == RTM_ADD) {
/* explicitly specify (loopback) ifa */
if (info.rti_ifp != NULL) {
-   NET_EPOCH_ENTER(et);
rti_ifa = ifaof_ifpforaddr(ifa->ifa_addr, info.rti_ifp);
if (rti_ifa != NULL)
ifa_ref(rti_ifa);
info.rti_ifa = rti_ifa;
-   NET_EPOCH_EXIT(et);
}
}
info.rti_flags = ifa->ifa_flags | RTF_HOST | RTF_STATIC | RTF_PINNED;
@@ -1874,6 +1873,7 @@ ifa_maintain_loopback_route(int cmd, const char *otype
link_init_sdl(ifp, (struct sockaddr *)_sdl, ifp->if_type);
 
error = rtrequest1_fib(cmd, , NULL, ifp->if_fib);
+   NET_EPOCH_EXIT(et);
 
if (rti_ifa != NULL)
ifa_free(rti_ifa);

Modified: head/sys/net/route.c
==
--- head/sys/net/route.cSat May 23 03:32:08 2020(r361408)
+++ head/sys/net/route.cSat May 23 10:21:02 2020(r361409)
@@ -120,10 +120,7 @@ VNET_PCPUSTAT_SYSUNINIT(rtstat);
 VNET_DEFINE(struct rib_head *, rt_tables);
 #defineV_rt_tables VNET(rt_tables)
 
-VNET_DEFINE(int, rttrash); /* routes not in table but not freed */
-#defineV_rttrash   VNET(rttrash)
 
-
 /*
  * Convert a 'struct radix_node *' to a 'struct rtentry *'.
  * The operation can be done safely (in this code) because a
@@ -148,6 +145,7 @@ static int rt_ifdelroute(const struct rtentry *rt, con
 static struct rtentry *rt_unlinkrte(struct rib_head *rnh,
 struct rt_addrinfo *info, int *perror);
 static void rt_notifydelete(struct rtentry *rt, struct rt_addrinfo *info);
+static void destroy_rtentry_epoch(epoch_context_t ctx);
 #ifdef RADIX_MPATH
 static struct radix_node *rt_mpath_unlink(struct rib_head *rnh,
 struct rt_addrinfo *info, struct rtentry *rto, int *perror);
@@ -332,6 +330,16 @@ vnet_route_uninit(const 

svn commit: r361137 - head/sys/netinet

2020-05-17 Thread Alexander V. Chernikov
Author: melifaro
Date: Sun May 17 15:32:36 2020
New Revision: 361137
URL: https://svnweb.freebsd.org/changeset/base/361137

Log:
  Remove redundant checks for nhop validity.
   Currently NH_IS_VALID() simly aliases to RT_LINK_IS_UP(), so we're
   checking the same thing twice.
  
  In the near future the implementation of this check will be simpler,
   as there are plans to introduce control-plane interface status monitoring
   similar to ipfw interface tracker.

Modified:
  head/sys/netinet/ip_output.c

Modified: head/sys/netinet/ip_output.c
==
--- head/sys/netinet/ip_output.cSun May 17 14:52:54 2020
(r361136)
+++ head/sys/netinet/ip_output.cSun May 17 15:32:36 2020
(r361137)
@@ -407,8 +407,7 @@ again:
 * Also check whether routing cache needs invalidation.
 */
if (ro != NULL && ro->ro_nh != NULL &&
-   ((!NH_IS_VALID(ro->ro_nh)) || !RT_LINK_IS_UP(ro->ro_nh->nh_ifp) ||
-   dst->sin_family != AF_INET ||
+   ((!NH_IS_VALID(ro->ro_nh)) || dst->sin_family != AF_INET ||
dst->sin_addr.s_addr != ip->ip_dst.s_addr))
RO_INVALIDATE_CACHE(ro);
ia = NULL;
@@ -480,8 +479,7 @@ again:
ro->ro_nh = fib4_lookup(fibnum, dst->sin_addr, 0,
NHR_REF, flowid);
 
-   if (ro->ro_nh == NULL || (!NH_IS_VALID(ro->ro_nh)) ||
-   !RT_LINK_IS_UP(ro->ro_nh->nh_ifp)) {
+   if (ro->ro_nh == NULL || (!NH_IS_VALID(ro->ro_nh))) {
 #if defined(IPSEC) || defined(IPSEC_SUPPORT)
/*
 * There is no route for this packet, but it is
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r360921 - head/sys/netinet

2020-05-11 Thread Alexander V. Chernikov
Author: melifaro
Date: Mon May 11 20:41:03 2020
New Revision: 360921
URL: https://svnweb.freebsd.org/changeset/base/360921

Log:
  Fix NOINET[6] build by using af-independent route lookup function.
  
  Reported by:  rpokala

Modified:
  head/sys/netinet/sctp_os_bsd.h

Modified: head/sys/netinet/sctp_os_bsd.h
==
--- head/sys/netinet/sctp_os_bsd.h  Mon May 11 20:40:30 2020
(r360920)
+++ head/sys/netinet/sctp_os_bsd.h  Mon May 11 20:41:03 2020
(r360921)
@@ -402,10 +402,7 @@ typedef struct route sctp_route_t;
 #define SCTP_RTALLOC(ro, vrf_id, fibnum) \
 { \
if ((ro)->ro_nh == NULL) { \
-   if ((ro)->ro_dst.sa_family == AF_INET) \
-   (ro)->ro_nh = fib4_lookup(fibnum, ((struct sockaddr_in 
*)&(ro)->ro_dst)->sin_addr, 0, NHR_REF, 0); \
-   if ((ro)->ro_dst.sa_family == AF_INET6) \
-   (ro)->ro_nh = fib6_lookup(fibnum, &((struct sockaddr_in6 
*)&(ro)->ro_dst)->sin6_addr, 0, NHR_REF, 0); \
+   (ro)->ro_nh = rib_lookup(fibnum, &(ro)->ro_dst, NHR_REF, 0); \
} \
 }
 
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r360889 - in head/sys/net: . route

2020-05-11 Thread Alexander V. Chernikov
Author: melifaro
Date: Mon May 11 06:09:18 2020
New Revision: 360889
URL: https://svnweb.freebsd.org/changeset/base/360889

Log:
  Remove unused rnh_close callback from rtable & cleanup depends.
  
  rnh_close callbackes was used by the in[6]_clsroute() handlers,
   doing cleanup in the route cloning code. Route cloning was eliminated
   somewhere around r186119. Last callback user was eliminated in r186215,
   11 years ago.
  
  Differential Revision:https://reviews.freebsd.org/D24793

Modified:
  head/sys/net/route.c
  head/sys/net/route/route_var.h

Modified: head/sys/net/route.c
==
--- head/sys/net/route.cMon May 11 05:53:12 2020(r360888)
+++ head/sys/net/route.cMon May 11 06:09:18 2020(r360889)
@@ -426,11 +426,8 @@ sys_setfib(struct thread *td, struct setfib_args *uap)
 void
 rtfree(struct rtentry *rt)
 {
-   struct rib_head *rnh;
 
KASSERT(rt != NULL,("%s: NULL rt", __func__));
-   rnh = rt_tables_get_rnh(rt->rt_fibnum, rt_key(rt)->sa_family);
-   KASSERT(rnh != NULL,("%s: NULL rnh", __func__));
 
RT_LOCK_ASSERT(rt);
 
@@ -445,18 +442,6 @@ rtfree(struct rtentry *rt)
}
 
/*
-* On last reference give the "close method" a chance
-* to cleanup private state.  This also permits (for
-* IPv4 and IPv6) a chance to decide if the routing table
-* entry should be purged immediately or at a later time.
-* When an immediate purge is to happen the close routine
-* typically calls rtexpunge which clears the RTF_UP flag
-* on the entry so that the code below reclaims the storage.
-*/
-   if (rt->rt_refcnt == 0 && rnh->rnh_close)
-   rnh->rnh_close((struct radix_node *)rt, >head);
-
-   /*
 * If we are no longer "up" (and ref == 0)
 * then we can free the resources associated
 * with the route.
@@ -1501,7 +1486,6 @@ add_route(struct rib_head *rnh, struct rt_addrinfo *in
return (ENOBUFS);
}
rt->rt_flags = RTF_UP | flags;
-   rt->rt_fibnum = rnh->rib_fibnum;
rt->rt_nhop = nh;
 
/* Fill in dst */

Modified: head/sys/net/route/route_var.h
==
--- head/sys/net/route/route_var.h  Mon May 11 05:53:12 2020
(r360888)
+++ head/sys/net/route/route_var.h  Mon May 11 06:09:18 2020
(r360889)
@@ -50,7 +50,6 @@ struct rib_head {
rn_lookup_f_t   *rnh_lookup;/* exact match for sockaddr */
rn_walktree_t   *rnh_walktree;  /* traverse tree */
rn_walktree_from_t  *rnh_walktree_from; /* traverse tree below a */
-   rn_close_t  *rnh_close; /*do something when the last 
ref drops*/
rnh_preadd_entry_f_t*rnh_preadd;/* hook to alter record prior 
to insertion */
rt_gen_trnh_gen;/* generation counter */
int rnh_multipath;  /* multipath capable ? */
@@ -144,7 +143,6 @@ struct rtentry {
 
int rt_flags;   /* up/down?, host/net */
int rt_refcnt;  /* # held references */
-   u_int   rt_fibnum;  /* which FIB */
u_long  rt_weight;  /* absolute weight */ 
u_long  rt_expire;  /* lifetime for route, e.g. redirect */
 #definert_endzero  rt_mtx
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r360866 - head/sys/net

2020-05-10 Thread Alexander V. Chernikov
Author: melifaro
Date: Sun May 10 09:34:48 2020
New Revision: 360866
URL: https://svnweb.freebsd.org/changeset/base/360866

Log:
  Remove rtalloc1(_fib) KPI.
  
  Last user of rtalloc1() KPI has been eliminated in rS360631.
  As kernel is now fully switched to use new routing KPI defined in
  rS359823, remove old lookup functions.
  
  Differential Revision:https://reviews.freebsd.org/D24776

Modified:
  head/sys/net/route.c
  head/sys/net/route.h

Modified: head/sys/net/route.c
==
--- head/sys/net/route.cSun May 10 03:36:11 2020(r360865)
+++ head/sys/net/route.cSun May 10 09:34:48 2020(r360866)
@@ -420,76 +420,6 @@ sys_setfib(struct thread *td, struct setfib_args *uap)
 }
 
 /*
- * Look up the route that matches the address given
- * Or, at least try.. Create a cloned route if needed.
- *
- * The returned route, if any, is locked.
- */
-struct rtentry *
-rtalloc1(struct sockaddr *dst, int report, u_long ignflags)
-{
-
-   return (rtalloc1_fib(dst, report, ignflags, RT_DEFAULT_FIB));
-}
-
-struct rtentry *
-rtalloc1_fib(struct sockaddr *dst, int report, u_long ignflags,
-   u_int fibnum)
-{
-   RIB_RLOCK_TRACKER;
-   struct rib_head *rh;
-   struct radix_node *rn;
-   struct rtentry *newrt;
-   struct rt_addrinfo info;
-   int err = 0, msgtype = RTM_MISS;
-
-   KASSERT((fibnum < rt_numfibs), ("rtalloc1_fib: bad fibnum"));
-   rh = rt_tables_get_rnh(fibnum, dst->sa_family);
-   newrt = NULL;
-   if (rh == NULL)
-   goto miss;
-
-   /*
-* Look up the address in the table for that Address Family
-*/
-   if ((ignflags & RTF_RNH_LOCKED) == 0)
-   RIB_RLOCK(rh);
-#ifdef INVARIANTS
-   else
-   RIB_LOCK_ASSERT(rh);
-#endif
-   rn = rh->rnh_matchaddr(dst, >head);
-   if (rn && ((rn->rn_flags & RNF_ROOT) == 0)) {
-   newrt = RNTORT(rn);
-   RT_LOCK(newrt);
-   RT_ADDREF(newrt);
-   if ((ignflags & RTF_RNH_LOCKED) == 0)
-   RIB_RUNLOCK(rh);
-   return (newrt);
-
-   } else if ((ignflags & RTF_RNH_LOCKED) == 0)
-   RIB_RUNLOCK(rh);
-   /*
-* Either we hit the root or could not find any match,
-* which basically means: "cannot get there from here".
-*/
-miss:
-   RTSTAT_INC(rts_unreach);
-
-   if (report) {
-   /*
-* If required, report the failure to the supervising
-* Authorities.
-* For a delete, this is not an error. (report == 0)
-*/
-   bzero(, sizeof(info));
-   info.rti_info[RTAX_DST] = dst;
-   rt_missmsg_fib(msgtype, , 0, err, fibnum);
-   }
-   return (newrt);
-}
-
-/*
  * Remove a reference count from an rtentry.
  * If the count gets low enough, take it out of the routing table
  */

Modified: head/sys/net/route.h
==
--- head/sys/net/route.hSun May 10 03:36:11 2020(r360865)
+++ head/sys/net/route.hSun May 10 09:34:48 2020(r360866)
@@ -392,8 +392,6 @@ struct sockaddr *rtsock_fix_netmask(const struct socka
 /*
  * Note the following locking behavior:
  *
- *rtalloc1() returns a locked rtentry
- *
  *rtfree() and RTFREE_LOCKED() require a locked rtentry
  *
  *RTFREE() uses an unlocked entry.
@@ -414,14 +412,12 @@ void  rt_flushifroutes(struct ifnet *ifp);
 
 /* XXX MRT COMPAT VERSIONS THAT SET UNIVERSE to 0 */
 /* Thes are used by old code not yet converted to use multiple FIBS */
-struct rtentry *rtalloc1(struct sockaddr *, int, u_long);
 int rtinit(struct ifaddr *, int, int);
 
 /* XXX MRT NEW VERSIONS THAT USE FIBs
  * For now the protocol indepedent versions are the same as the AF_INET ones
  * but this will change.. 
  */
-struct rtentry *rtalloc1_fib(struct sockaddr *, int, u_long, u_int);
 int rtioctl_fib(u_long, caddr_t, u_int);
 int rtrequest_fib(int, struct sockaddr *,
struct sockaddr *, struct sockaddr *, int, struct rtentry **, 
u_int);
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r360824 - in head/sys/net: . route

2020-05-08 Thread Alexander V. Chernikov
Author: melifaro
Date: Fri May  8 21:06:10 2020
New Revision: 360824
URL: https://svnweb.freebsd.org/changeset/base/360824

Log:
  Embed dst sockaddr into rtentry and remove rte packet counter
  
  Currently each rtentry has dst allocated separately from another zone,
   bloating cache accesses.
  
  Current 'struct rtentry' has 12 "mandatory" radix pointers in the beginning,
   leaving 4 usable pointers/32 bytes in the first 2 cache lines (amd64).
  Fields needed for the datapath are destination sockaddr and rt_nhop.
  
  So far it doesn't look like there is other routable addressing protocol other
   than IPv4/IPv6/MPLS, which uses keys longer than 20 bytes.
  With that in mind, embed dst into struct rtentry, making the first 24 bytes
   of rtentry within 128 bytes. That is enough to make IPv6 address within first
   128 bytes.
  
  It is still pretty easy to add code for supporting separately-allocated dst,
   however it doesn't make a lot of sense in having such code without a use 
case.
  
  As rS359823 moved the gateway to the nexthop structure, the dst embedding 
change
   removes the need for any additional allocations done by rt_setgate().
  
  Lastly, as a part of cleanup, remove counter(9) allocation code, as this field
   is not used in packet processing anymore.
  
  Reviewed by:  ae
  Differential Revision:https://reviews.freebsd.org/D24669

Modified:
  head/sys/net/route.c
  head/sys/net/route.h
  head/sys/net/route/route_ddb.c
  head/sys/net/route/route_var.h
  head/sys/net/rtsock.c

Modified: head/sys/net/route.c
==
--- head/sys/net/route.cFri May  8 20:15:18 2020(r360823)
+++ head/sys/net/route.cFri May  8 21:06:10 2020(r360824)
@@ -241,10 +241,6 @@ rtentry_zinit(void *mem, int size, int how)
 {
struct rtentry *rt = mem;
 
-   rt->rt_pksent = counter_u64_alloc(how);
-   if (rt->rt_pksent == NULL)
-   return (ENOMEM);
-
RT_LOCK_INIT(rt);
 
return (0);
@@ -256,7 +252,6 @@ rtentry_zfini(void *mem, int size)
struct rtentry *rt = mem;
 
RT_LOCK_DESTROY(rt);
-   counter_u64_free(rt->rt_pksent);
 }
 
 static int
@@ -265,7 +260,6 @@ rtentry_ctor(void *mem, int size, void *arg, int how)
struct rtentry *rt = mem;
 
bzero(rt, offsetof(struct rtentry, rt_endzero));
-   counter_u64_zero(rt->rt_pksent);
rt->rt_chain = NULL;
 
return (0);
@@ -551,12 +545,6 @@ rtfree(struct rtentry *rt)
goto done;
}
 #endif
-   /*
-* The key is separatly alloc'd so free it (see rt_setgate()).
-* This also frees the gateway, as they are always malloc'd
-* together.
-*/
-   R_Free(rt_key(rt));
 
/* Unreference nexthop */
nhop_free(rt->rt_nhop);
@@ -1557,6 +1545,9 @@ add_route(struct rib_head *rnh, struct rt_addrinfo *in
(gateway->sa_family != AF_UNSPEC) && (gateway->sa_family != 
AF_LINK))
return (EINVAL);
 
+   if (dst->sa_len > sizeof(((struct rtentry *)NULL)->rt_dstb))
+   return (EINVAL);
+
if (info->rti_ifa == NULL) {
error = rt_getifa_fib(info, rnh->rib_fibnum);
if (error)
@@ -1582,16 +1573,11 @@ add_route(struct rib_head *rnh, struct rt_addrinfo *in
rt->rt_flags = RTF_UP | flags;
rt->rt_fibnum = rnh->rib_fibnum;
rt->rt_nhop = nh;
-   /*
-* Add the gateway. Possibly re-malloc-ing the storage for it.
-*/
-   if ((error = rt_setgate(rt, dst, gateway)) != 0) {
-   ifa_free(info->rti_ifa);
-   nhop_free(nh);
-   uma_zfree(V_rtzone, rt);
-   return (error);
-   }
 
+   /* Fill in dst */
+   memcpy(>rt_dst, dst, dst->sa_len);
+   rt_key(rt) = >rt_dst;
+
/*
 * point to the (possibly newly malloc'd) dest address.
 */
@@ -1623,7 +1609,6 @@ add_route(struct rib_head *rnh, struct rt_addrinfo *in
rt_mpath_conflict(rnh, rt, netmask)) {
RIB_WUNLOCK(rnh);
 
-   R_Free(rt_key(rt));
nhop_free(nh);
uma_zfree(V_rtzone, rt);
return (EEXIST);
@@ -1663,7 +1648,6 @@ add_route(struct rib_head *rnh, struct rt_addrinfo *in
 * then un-make it (this should be a function)
 */
if (rn == NULL) {
-   R_Free(rt_key(rt));
nhop_free(nh);
uma_zfree(V_rtzone, rt);
return (EEXIST);
@@ -1897,40 +1881,6 @@ rt_setmetrics(const struct rt_addrinfo *info, struct r
if (info->rti_mflags & RTV_EXPIRE)
rt->rt_expire = info->rti_rmx->rmx_expire ?
info->rti_rmx->rmx_expire - time_second + time_uptime : 0;
-}
-
-int
-rt_setgate(struct rtentry *rt, struct sockaddr 

svn commit: r360773 - in head/sys/net: . route

2020-05-07 Thread Alexander V. Chernikov
Author: melifaro
Date: Thu May  7 08:11:36 2020
New Revision: 360773
URL: https://svnweb.freebsd.org/changeset/base/360773

Log:
  Add rib_lookup() sockaddr lookup wrapper and make ifa_ifwithroute use it.
  
  Create rib_lookup() wrapper around per-af dataplane lookup functions.
  This will help in the cases of having control plane af-agnostic code.
  
  Switch ifa_ifwithroute() to use this function instead of rtalloc1().
  
  Reviewed by:  ae
  Differential Revision:https://reviews.freebsd.org/D24731

Modified:
  head/sys/net/route.c
  head/sys/net/route.h
  head/sys/net/route/route_helpers.c

Modified: head/sys/net/route.c
==
--- head/sys/net/route.cThu May  7 03:50:34 2020(r360772)
+++ head/sys/net/route.cThu May  7 08:11:36 2020(r360773)
@@ -683,7 +683,6 @@ ifa_ifwithroute(int flags, const struct sockaddr *dst,
u_int fibnum)
 {
struct ifaddr *ifa;
-   int not_found = 0;
 
NET_EPOCH_ASSERT();
if ((flags & RTF_GATEWAY) == 0) {
@@ -710,34 +709,17 @@ ifa_ifwithroute(int flags, const struct sockaddr *dst,
if (ifa == NULL)
ifa = ifa_ifwithnet(gateway, 0, fibnum);
if (ifa == NULL) {
-   struct rtentry *rt;
+   struct nhop_object *nh;
 
-   rt = rtalloc1_fib(gateway, 0, flags, fibnum);
-   if (rt == NULL)
-   goto out;
+   nh = rib_lookup(fibnum, gateway, NHR_NONE, 0);
+
/*
 * dismiss a gateway that is reachable only
 * through the default router
 */
-   switch (gateway->sa_family) {
-   case AF_INET:
-   if (satosin(rt_key(rt))->sin_addr.s_addr == INADDR_ANY)
-   not_found = 1;
-   break;
-   case AF_INET6:
-   if 
(IN6_IS_ADDR_UNSPECIFIED((rt_key(rt))->sin6_addr))
-   not_found = 1;
-   break;
-   default:
-   break;
-   }
-   if (!not_found && rt->rt_nhop->nh_ifa != NULL) {
-   ifa = rt->rt_nhop->nh_ifa;
-   }
-   RT_REMREF(rt);
-   RT_UNLOCK(rt);
-   if (not_found || ifa == NULL)
-   goto out;
+   if ((nh == NULL) || (nh->nh_flags & NHF_DEFAULT))
+   return (NULL);
+   ifa = nh->nh_ifa;
}
if (ifa->ifa_addr->sa_family != dst->sa_family) {
struct ifaddr *oifa = ifa;
@@ -745,7 +727,7 @@ ifa_ifwithroute(int flags, const struct sockaddr *dst,
if (ifa == NULL)
ifa = oifa;
}
- out:
+
return (ifa);
 }
 

Modified: head/sys/net/route.h
==
--- head/sys/net/route.hThu May  7 03:50:34 2020(r360772)
+++ head/sys/net/route.hThu May  7 08:11:36 2020(r360773)
@@ -436,6 +436,8 @@ int rib_add_redirect(u_int fibnum, struct sockaddr *ds
 
 /* 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
 
 #endif

Modified: head/sys/net/route/route_helpers.c
==
--- head/sys/net/route/route_helpers.c  Thu May  7 03:50:34 2020
(r360772)
+++ head/sys/net/route/route_helpers.c  Thu May  7 08:11:36 2020
(r360773)
@@ -55,6 +55,12 @@ __FBSDID("$FreeBSD$");
 #include 
 #include 
 #include 
+#ifdef INET
+#include 
+#endif
+#ifdef INET6
+#include 
+#endif
 #include 
 
 /*
@@ -79,5 +85,50 @@ rib_walk(int af, u_int fibnum, rt_walktree_f_t *wa_f, 
RIB_RLOCK(rnh);
rnh->rnh_walktree(>head, (walktree_f_t *)wa_f, arg);
RIB_RUNLOCK(rnh);
+}
+
+/*
+ * Wrapper for the control plane functions for performing af-agnostic
+ *  lookups.
+ * @fibnum: fib to perform the lookup.
+ * @dst: sockaddr with family and addr filled in. IPv6 addresses needs to be in
+ *  deembedded from.
+ * @flags: fib(9) flags.
+ * @flowid: flow id for path selection in multipath use case.
+ *
+ * Returns nhop_object or NULL.
+ *
+ * Requires NET_EPOCH.
+ *
+ */
+struct nhop_object *
+rib_lookup(uint32_t fibnum, const struct sockaddr *dst, uint32_t flags,
+uint32_t flowid)
+{
+   struct nhop_object *nh;
+
+   nh = NULL;
+
+   switch (dst->sa_family) {
+#ifdef INET
+   case AF_INET:
+   {
+   const struct sockaddr_in *a = (const struct sockaddr_in *)dst;
+   nh = fib4_lookup(fibnum, a->sin_addr, 0, flags, flowid);
+   break;
+   }
+#endif
+#ifdef INET6
+ 

svn commit: r360685 - in head/tests/sys: netinet netinet6

2020-05-06 Thread Alexander V. Chernikov
Author: melifaro
Date: Wed May  6 07:48:37 2020
New Revision: 360685
URL: https://svnweb.freebsd.org/changeset/base/360685

Log:
  Add basic routing LPM tests.
  
  Differential Revision:https://reviews.freebsd.org/D24684

Added:
  head/tests/sys/netinet/lpm.sh   (contents, props changed)
  head/tests/sys/netinet6/lpm6.sh   (contents, props changed)
Modified:
  head/tests/sys/netinet/Makefile
  head/tests/sys/netinet6/Makefile

Modified: head/tests/sys/netinet/Makefile
==
--- head/tests/sys/netinet/Makefile Wed May  6 05:41:02 2020
(r360684)
+++ head/tests/sys/netinet/Makefile Wed May  6 07:48:37 2020
(r360685)
@@ -9,7 +9,7 @@ ATF_TESTS_C=ip_reass_test \
so_reuseport_lb_test \
socket_afinet
 
-ATF_TESTS_SH=  carp fibs_test redirect divert forward output
+ATF_TESTS_SH=  carp fibs_test redirect divert forward output lpm
 
 PROGS= udp_dontroute tcp_user_cookie
 

Added: head/tests/sys/netinet/lpm.sh
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/tests/sys/netinet/lpm.sh   Wed May  6 07:48:37 2020
(r360685)
@@ -0,0 +1,179 @@
+#!/usr/bin/env atf-sh
+#-
+# SPDX-License-Identifier: BSD-2-Clause
+#
+# Copyright (c) 2020 Alexander V. Chernikov
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#notice, this list of conditions and the following disclaimer in the
+#documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+# SUCH DAMAGE.
+#
+# $FreeBSD$
+#
+
+. $(atf_get_srcdir)/../common/vnet.subr
+
+setup_networking()
+{
+   jname="$1"
+   lo_dst="$2"
+   epair0="$3"
+   epair1="$4"
+
+   vnet_mkjail ${jname}a ${epair0}a ${epair1}a
+   # Setup transit IPv4 networks
+   jexec ${jname}a ifconfig ${epair0}a up
+   jexec ${jname}a ifconfig ${epair0}a inet 203.0.113.1/30
+   jexec ${jname}a ifconfig ${epair1}a up
+   jexec ${jname}a ifconfig ${epair1}a inet 203.0.113.5/30
+
+   vnet_mkjail ${jname}b ${epair0}b ${epair1}b ${lo_dst}
+   jexec ${jname}b ifconfig ${epair0}b up
+   jexec ${jname}b ifconfig ${epair0}b inet 203.0.113.2/30
+   jexec ${jname}b ifconfig ${epair1}b up
+   jexec ${jname}b ifconfig ${epair1}b inet 203.0.113.6/30
+   jexec ${jname}b ifconfig ${lo_dst} up
+
+}
+
+atf_test_case "lpm_test1_success" "cleanup"
+lpm_test1_success_head()
+{
+
+   atf_set descr 'Test IPv4 LPM for /30 and /31'
+   atf_set require.user root
+}
+
+lpm_test1_success_body()
+{
+
+   vnet_init
+
+   jname="v4t-lpm_test1_success"
+
+   lo_dst=$(vnet_mkloopback)
+   epair0=$(vnet_mkepair)
+   epair1=$(vnet_mkepair)
+
+   setup_networking ${jname} ${lo_dst} ${epair0} ${epair1}
+
+   jexec ${jname}b ifconfig ${lo_dst} inet 198.51.100.0/32
+   jexec ${jname}b ifconfig ${lo_dst} alias 198.51.100.2/32
+
+   # Add routes
+   # A -> towards B via epair0a 
+   jexec ${jname}a route add -4 -net 198.51.100.0/30 203.0.113.2
+   # A -> towards B via epair1a
+   jexec ${jname}a route add -4 -net 198.51.100.0/31 203.0.113.6
+
+   count=20
+   valid_message="${count} packets transmitted, ${count} packets received"
+   
+   # Check that 198.51.100.0 goes via epair1
+   atf_check -o match:"${valid_message}" jexec ${jname}a ping -f 
-nc${count} 198.51.100.0
+   pkt_0=`jexec ${jname}a netstat -Wf link -I ${epair0}a | head | awk 
'$1!~/^Name/{print$8}'`
+   pkt_1=`jexec ${jname}a netstat -Wf link -I ${epair1}a | head | awk 
'$1!~/^Name/{print$8}'`
+   if [ ${pkt_1} -le ${count} ]; then
+   echo "LPM failure: 1: ${pkt_0} 2: ${pkt_1} (should be ${count})&quo

svn commit: r360631 - head/sys/net/route

2020-05-04 Thread Alexander V. Chernikov
Author: melifaro
Date: Mon May  4 15:07:57 2020
New Revision: 360631
URL: https://svnweb.freebsd.org/changeset/base/360631

Log:
  Switch DDB show route to direct rnh_matchaddr() call instead of rtalloc1().
  
  Eliminate the last rtalloc1() call to finish transition to the new routing
  KPI defined in r359823.
  
  Differential Revision:https://reviews.freebsd.org/D24663

Modified:
  head/sys/net/route/route_ddb.c

Modified: head/sys/net/route/route_ddb.c
==
--- head/sys/net/route/route_ddb.c  Mon May  4 15:00:19 2020
(r360630)
+++ head/sys/net/route/route_ddb.c  Mon May  4 15:07:57 2020
(r360631)
@@ -208,6 +208,8 @@ DB_SHOW_COMMAND(routetable, db_show_routetable_cmd)
 _DB_FUNC(_show, route, db_show_route_cmd, db_show_table, CS_OWN, NULL)
 {
char abuf[INET6_ADDRSTRLEN], *buf, *end;
+   struct rib_head *rh;
+   struct radix_node *rn;
void *dst_addrp;
struct rtentry *rt;
union {
@@ -244,8 +246,15 @@ _DB_FUNC(_show, route, db_show_route_cmd, db_show_tabl
if (inet_ntop(af, dst_addrp, abuf, sizeof(abuf)) != NULL)
db_printf("Looking up route to destination '%s'\n", abuf);
 
+   rt = NULL;
CURVNET_SET(vnet0);
-   rt = rtalloc1((struct sockaddr *), 0, RTF_RNH_LOCKED);
+
+   rh = rt_tables_get_rnh(RT_DEFAULT_FIB, af);
+
+   rn = rh->rnh_matchaddr(, >head);
+   if (rn && ((rn->rn_flags & RNF_ROOT) == 0))
+   rt = (struct rtentry *)rn;
+
CURVNET_RESTORE();
 
if (rt == NULL) {
@@ -254,7 +263,6 @@ _DB_FUNC(_show, route, db_show_route_cmd, db_show_tabl
}
 
rt_dumpentry_ddb((void *)rt, NULL);
-   RTFREE_LOCKED(rt);
 
return;
 usage:
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r360630 - head/sys/net/route

2020-05-04 Thread Alexander V. Chernikov
Author: melifaro
Date: Mon May  4 15:00:19 2020
New Revision: 360630
URL: https://svnweb.freebsd.org/changeset/base/360630

Log:
  Simplify address parsing in DDB show route command.
  
  Use db_get_line() to overcome parser limitation.
  
  Differential Revision:https://reviews.freebsd.org/D24662

Modified:
  head/sys/net/route/route_ddb.c

Modified: head/sys/net/route/route_ddb.c
==
--- head/sys/net/route/route_ddb.c  Mon May  4 14:31:45 2020
(r360629)
+++ head/sys/net/route/route_ddb.c  Mon May  4 15:00:19 2020
(r360630)
@@ -30,6 +30,7 @@ __FBSDID("$FreeBSD$");
 #include "opt_inet.h"
 #include "opt_inet6.h"
 
+#include 
 #include 
 #include 
 #include 
@@ -206,239 +207,45 @@ DB_SHOW_COMMAND(routetable, db_show_routetable_cmd)
 
 _DB_FUNC(_show, route, db_show_route_cmd, db_show_table, CS_OWN, NULL)
 {
-   char buf[INET6_ADDRSTRLEN], *bp;
-   const void *dst_addrp;
-   struct sockaddr *dstp;
+   char abuf[INET6_ADDRSTRLEN], *buf, *end;
+   void *dst_addrp;
struct rtentry *rt;
union {
struct sockaddr_in dest_sin;
struct sockaddr_in6 dest_sin6;
} u;
-   uint16_t hextets[8];
-   unsigned i, tets;
-   int t, af, exp, tokflags;
+   int af;
 
-   /*
-* Undecoded address family.  No double-colon expansion seen yet.
-*/
-   af = -1;
-   exp = -1;
-   /* Assume INET6 to start; we can work back if guess was wrong. */
-   tokflags = DRT_WSPACE | DRT_HEX | DRT_HEXADECIMAL;
+   buf = db_get_line();
 
-   /*
-* db_command has lexed 'show route' for us.
-*/
-   t = db_read_token_flags(tokflags);
-   if (t == tWSPACE)
-   t = db_read_token_flags(tokflags);
+   /* Remove whitespaces from both ends */
+   end = buf + strlen(buf) - 1;
+   for (; (end >= buf) && (*end=='\n' || isspace(*end)); end--)
+   *end = '\0';
+   while (isspace(*buf))
+   buf++;
 
-   /*
-* tEOL: Just 'show route' isn't a valid mode.
-* tMINUS: It's either '-h' or some invalid option.  Regardless, usage.
-*/
-   if (t == tEOL || t == tMINUS)
-   goto usage;
-
-   db_unread_token(t);
-
-   tets = nitems(hextets);
-
-   /*
-* Each loop iteration, we expect to read one octet (v4) or hextet
-* (v6), followed by an appropriate field separator ('.' or ':' or
-* '::').
-*
-* At the start of each loop, we're looking for a number (octet or
-* hextet).
-*
-* INET6 addresses have a special case where they may begin with '::'.
-*/
-   for (i = 0; i < tets; i++) {
-   t = db_read_token_flags(tokflags);
-
-   if (t == tCOLONCOLON) {
-   /* INET6 with leading '::' or invalid. */
-   if (i != 0) {
-   db_printf("Parse error: unexpected extra "
-   "colons.\n");
-   goto exit;
-   }
-
-   af = AF_INET6;
-   exp = i;
-   hextets[i] = 0;
-   continue;
-   } else if (t == tNUMBER) {
-   /*
-* Lexer separates out '-' as tMINUS, but make the
-* assumption explicit here.
-*/
-   MPASS(db_tok_number >= 0);
-
-   if (af == AF_INET && db_tok_number > UINT8_MAX) {
-   db_printf("Not a valid v4 octet: %ld\n",
-   (long)db_tok_number);
-   goto exit;
-   }
-   hextets[i] = db_tok_number;
-   } else if (t == tEOL) {
-   /*
-* We can only detect the end of an IPv6 address in
-* compact representation with EOL.
-*/
-   if (af != AF_INET6 || exp < 0) {
-   db_printf("Parse failed.  Got unexpected EOF "
-   "when the address is not a compact-"
-   "representation IPv6 address.\n");
-   goto exit;
-   }
-   break;
-   } else {
-   db_printf("Parse failed.  Unexpected token %d.\n", t);
-   goto exit;
-   }
-
-   /* Next, look for a separator, if appropriate. */
-   if (i == tets - 1)
-   continue;
-
-   t = db_read_token_flags(tokflags);
-   if (af < 0) {
-   if (t == tCOLON) {
-  

svn commit: r360629 - in head/sys: net net/route netinet netinet6

2020-05-04 Thread Alexander V. Chernikov
Author: melifaro
Date: Mon May  4 14:31:45 2020
New Revision: 360629
URL: https://svnweb.freebsd.org/changeset/base/360629

Log:
  Remove now-unused rt_ifp,rt_ifa,rt_gateway,rt_mtu rte fields.
  
  After converting routing subsystem customers to use nexthop objects
   defined in r359823, some fields in struct rtentry became unused.
  
  This commit removes rt_ifp, rt_ifa, rt_gateway and rt_mtu from struct rtentry
   along with the code initializing and updating these fields.
  
  Cleanup of the remaining fields will be addressed by D24669.
  
  This commit also changes the implementation of the RTM_CHANGE handling.
  Old implementation tried to perform the whole operation under radix WLOCK,
   resulting in slow performance and hacks like using RTF_RNH_LOCKED flag.
  New implementation looks up the route nexthop under radix RLOCK, creates new
   nexthop and tries to update rte nhop pointer. Only last part is done under
   WLOCK.
  In the hypothetical scenarious where multiple rtsock clients
   repeatedly issue RTM_CHANGE requests for the same route, route may get
   updated between read and update operation. This is addressed by retrying
   the operation multiple (3) times before returning failure back to the
   caller.
  
  Differential Revision:https://reviews.freebsd.org/D24666

Modified:
  head/sys/net/route.c
  head/sys/net/route/route_var.h
  head/sys/netinet/in_rmx.c
  head/sys/netinet6/in6_rmx.c

Modified: head/sys/net/route.c
==
--- head/sys/net/route.cMon May  4 12:28:44 2020(r360628)
+++ head/sys/net/route.cMon May  4 14:31:45 2020(r360629)
@@ -162,14 +162,6 @@ static int del_route(struct rib_head *rnh, struct rt_a
 static int change_route(struct rib_head *, struct rt_addrinfo *,
 struct rtentry **);
 
-struct if_mtuinfo
-{
-   struct ifnet*ifp;
-   int mtu;
-};
-
-static int if_updatemtu_cb(struct radix_node *, void *);
-
 /*
  * handler for net.my_fibnum
  */
@@ -560,12 +552,6 @@ rtfree(struct rtentry *rt)
}
 #endif
/*
-* release references on items we hold them on..
-* e.g other routes and ifaddrs.
-*/
-   if (rt->rt_ifa)
-   ifa_free(rt->rt_ifa);
-   /*
 * The key is separatly alloc'd so free it (see rt_setgate()).
 * This also frees the gateway, as they are always malloc'd
 * together.
@@ -1346,66 +1332,25 @@ rt_getifa_fib(struct rt_addrinfo *info, u_int fibnum)
return (error);
 }
 
-static int
-if_updatemtu_cb(struct radix_node *rn, void *arg)
-{
-   struct rtentry *rt;
-   struct if_mtuinfo *ifmtu;
-
-   rt = (struct rtentry *)rn;
-   ifmtu = (struct if_mtuinfo *)arg;
-
-   if (rt->rt_ifp != ifmtu->ifp)
-   return (0);
-
-   if (rt->rt_mtu >= ifmtu->mtu) {
-   /* We have to decrease mtu regardless of flags */
-   rt->rt_mtu = ifmtu->mtu;
-   return (0);
-   }
-
-   /*
-* New MTU is bigger. Check if are allowed to alter it
-*/
-   if ((rt->rt_flags & (RTF_FIXEDMTU | RTF_GATEWAY | RTF_HOST)) != 0) {
-
-   /*
-* Skip routes with user-supplied MTU and
-* non-interface routes
-*/
-   return (0);
-   }
-
-   /* We are safe to update route MTU */
-   rt->rt_mtu = ifmtu->mtu;
-
-   return (0);
-}
-
 void
 rt_updatemtu(struct ifnet *ifp)
 {
-   struct if_mtuinfo ifmtu;
struct rib_head *rnh;
+   int mtu;
int i, j;
 
-   ifmtu.ifp = ifp;
-
/*
 * Try to update rt_mtu for all routes using this interface
 * Unfortunately the only way to do this is to traverse all
 * routing tables in all fibs/domains.
 */
for (i = 1; i <= AF_MAX; i++) {
-   ifmtu.mtu = if_getmtu_family(ifp, i);
+   mtu = if_getmtu_family(ifp, i);
for (j = 0; j < rt_numfibs; j++) {
rnh = rt_tables_get_rnh(j, i);
if (rnh == NULL)
continue;
-   RIB_WLOCK(rnh);
-   rnh->rnh_walktree(>head, if_updatemtu_cb, );
-   RIB_WUNLOCK(rnh);
-   nhops_update_ifmtu(rnh, ifp, ifmtu.mtu);
+   nhops_update_ifmtu(rnh, ifp, mtu);
}
}
 }
@@ -1550,7 +1495,6 @@ int
 rtrequest1_fib(int req, struct rt_addrinfo *info, struct rtentry **ret_nrt,
u_int fibnum)
 {
-   struct epoch_tracker et;
const struct sockaddr *dst;
struct rib_head *rnh;
int error;
@@ -1599,11 +1543,7 @@ rtrequest1_fib(int req, struct rt_addrinfo *info, stru
error = add_route(rnh, info, ret_nrt);
 

  1   2   3   4   5   6   >