git: 1b8b69508bc5 - main - routing: copy nexthop fib when changing existing nexthop

2022-03-28 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit 1b8b69508bc55a797ba344f95f05978408629e25
Author: Alexander V. Chernikov 
AuthorDate: 2022-03-28 11:31:23 +
Commit: Alexander V. Chernikov 
CommitDate: 2022-03-28 11:32:30 +

routing: copy nexthop fib when changing existing nexthop

MFC after:  1 day
---
 sys/net/route/nhop_ctl.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/sys/net/route/nhop_ctl.c b/sys/net/route/nhop_ctl.c
index 16b8ca46739a..b9b6a6b59139 100644
--- a/sys/net/route/nhop_ctl.c
+++ b/sys/net/route/nhop_ctl.c
@@ -475,6 +475,7 @@ nhop_create_from_nhop(struct rib_head *rnh, const struct 
nhop_object *nh_orig,
nh_priv->nh_neigh_family = nh_orig->nh_priv->nh_neigh_family;
nh_priv->rt_flags = nh_orig->nh_priv->rt_flags;
nh_priv->nh_type = nh_orig->nh_priv->nh_type;
+   nh_priv->nh_fibnum = nh_orig->nh_priv->nh_fibnum;
 
nh->nh_ifp = nh_orig->nh_ifp;
nh->nh_ifa = nh_orig->nh_ifa;



git: 9c0ff6a8bbb5 - main - Remove now-unused RT_GATEWAY* definitions.

2021-01-04 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit 9c0ff6a8bbb5b32db2b8c7afb8bc5212ce717804
Author: Alexander V. Chernikov 
AuthorDate: 2021-01-04 21:45:46 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-01-04 21:45:46 +

Remove now-unused RT_GATEWAY* definitions.

They were used to simplify nexthop transition, hence not needed
 anymore.
---
 sys/net/route/nhop.h | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/sys/net/route/nhop.h b/sys/net/route/nhop.h
index 8b5ac7ada072..ce18cc04e163 100644
--- a/sys/net/route/nhop.h
+++ b/sys/net/route/nhop.h
@@ -157,9 +157,6 @@ struct nhop_object {
 #defineNH_IS_VALID(_nh)RT_LINK_IS_UP((_nh)->nh_ifp)
 #defineNH_IS_NHGRP(_nh)((_nh)->nh_flags & NHF_MULTIPATH)
 
-#defineRT_GATEWAY(_rt) ((struct sockaddr 
*)&(_rt)->rt_nhop->gw4_sa)
-#defineRT_GATEWAY_CONST(_rt)   ((const struct sockaddr 
*)&(_rt)->rt_nhop->gw4_sa)
-
 #defineNH_FREE(_nh) do {   \
nhop_free(_nh); \
/* guard against invalid refs */\
___
dev-commits-src-main@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-main
To unsubscribe, send any mail to "dev-commits-src-main-unsubscr...@freebsd.org"


git: d68cf57b7f22 - main - Refactor rt_addrmsg() and rt_routemsg().

2021-01-07 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit d68cf57b7f22a38a2b276bff039432d1aa2022f8
Author: Alexander V. Chernikov 
AuthorDate: 2021-01-07 19:13:52 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-01-07 19:38:19 +

Refactor rt_addrmsg() and rt_routemsg().

Summary:
* Refactor rt_addrmsg(): make V_rt_add_addr_allfibs decision locally.
* Fix rt_routemsg() and multipath by accepting nexthop instead of interface 
pointer.
* Refactor rtsock_routemsg(): avoid accessing rtentry fields directly.
* Simplify in_addprefix() by moving prefix search to a separate  function.

Reviewers: #network

Subscribers: imp, ae, bz

Differential Revision: https://reviews.freebsd.org/D28011
---
 sys/net/route.c   | 17 ++---
 sys/net/route.h   |  6 +-
 sys/net/route/route_ctl.c | 15 ---
 sys/net/route/route_ctl.h |  1 +
 sys/net/route/route_var.h |  7 +++
 sys/net/rtsock.c  | 16 +---
 sys/netinet/in.c  | 46 +-
 sys/netinet6/in6.c|  2 +-
 sys/netinet6/nd6_rtr.c| 18 --
 9 files changed, 78 insertions(+), 50 deletions(-)

diff --git a/sys/net/route.c b/sys/net/route.c
index 2f4ae40e83aa..b3383f90789b 100644
--- a/sys/net/route.c
+++ b/sys/net/route.c
@@ -710,10 +710,13 @@ rt_addrmsg(int cmd, struct ifaddr *ifa, int fibnum)
 
KASSERT(cmd == RTM_ADD || cmd == RTM_DELETE,
("unexpected cmd %d", cmd));
-   KASSERT(fibnum == RT_ALL_FIBS || (fibnum >= 0 && fibnum < rt_numfibs),
+   KASSERT((fibnum >= 0 && fibnum < rt_numfibs),
("%s: fib out of range 0 <=%d<%d", __func__, fibnum, rt_numfibs));
 
EVENTHANDLER_DIRECT_INVOKE(rt_addrmsg, ifa, cmd);
+
+   if (V_rt_add_addr_allfibs)
+   fibnum = RT_ALL_FIBS;
return (rtsock_addrmsg(cmd, ifa, fibnum));
 }
 
@@ -721,13 +724,13 @@ rt_addrmsg(int cmd, struct ifaddr *ifa, int fibnum)
  * Announce kernel-originated route addition/removal to rtsock based on @rt 
data.
  * cmd: RTM_ cmd
  * @rt: valid rtentry
- * @ifp: target route interface
+ * @nh: nhop object to announce
  * @fibnum: fib id or RT_ALL_FIBS
  *
  * Returns 0 on success.
  */
 int
-rt_routemsg(int cmd, struct rtentry *rt, struct ifnet *ifp, int rti_addrs,
+rt_routemsg(int cmd, struct rtentry *rt, struct nhop_object *nh,
 int fibnum)
 {
 
@@ -739,7 +742,7 @@ rt_routemsg(int cmd, struct rtentry *rt, struct ifnet *ifp, 
int rti_addrs,
 
KASSERT(rt_key(rt) != NULL, (":%s: rt_key must be supplied", __func__));
 
-   return (rtsock_routemsg(cmd, rt, ifp, 0, fibnum));
+   return (rtsock_routemsg(cmd, rt, nh, fibnum));
 }
 
 /*
@@ -775,16 +778,16 @@ rt_newaddrmsg_fib(int cmd, struct ifaddr *ifa, struct 
rtentry *rt, int fibnum)
 
KASSERT(cmd == RTM_ADD || cmd == RTM_DELETE,
("unexpected cmd %u", cmd));
-   KASSERT(fibnum == RT_ALL_FIBS || (fibnum >= 0 && fibnum < rt_numfibs),
+   KASSERT((fibnum >= 0 && fibnum < rt_numfibs),
("%s: fib out of range 0 <=%d<%d", __func__, fibnum, rt_numfibs));
 
if (cmd == RTM_ADD) {
rt_addrmsg(cmd, ifa, fibnum);
if (rt != NULL)
-   rt_routemsg(cmd, rt, ifa->ifa_ifp, 0, fibnum);
+   rt_routemsg(cmd, rt, nhop_select(rt->rt_nhop, 0), 
fibnum);
} else {
if (rt != NULL)
-   rt_routemsg(cmd, rt, ifa->ifa_ifp, 0, fibnum);
+   rt_routemsg(cmd, rt, nhop_select(rt->rt_nhop, 0), 
fibnum);
rt_addrmsg(cmd, ifa, fibnum);
}
 }
diff --git a/sys/net/route.h b/sys/net/route.h
index e9f5b8b9d7f6..96a8e78ecb3a 100644
--- a/sys/net/route.h
+++ b/sys/net/route.h
@@ -417,7 +417,7 @@ void rt_missmsg(int, struct rt_addrinfo *, int, 
int);
 voidrt_missmsg_fib(int, struct rt_addrinfo *, int, int, int);
 voidrt_newaddrmsg_fib(int, struct ifaddr *, struct rtentry *, int);
 int rt_addrmsg(int, struct ifaddr *, int);
-int rt_routemsg(int, struct rtentry *, struct ifnet *ifp, int, int);
+int rt_routemsg(int, struct rtentry *, struct nhop_object *, int);
 int rt_routemsg_info(int, struct rt_addrinfo *, int);
 voidrt_newmaddrmsg(int, struct ifmultiaddr *);
 voidrt_maskedcopy(struct sockaddr *, struct sockaddr *, struct sockaddr *);
@@ -425,10 +425,6 @@ struct rib_head *rt_table_init(int, int, u_int);
 void   rt_table_destroy(struct rib_head *);
 u_int  rt_tables_get_gen(uint32_t table, sa_family_t family);
 
-intrtsock_addrmsg(int, struct ifaddr *, int);
-intrtsock_routemsg(int, struct rtentry *, struct ifnet *ifp, int, int);
-intrtsock_routemsg_info(int, struc

git: 537d13437314 - main - Bring DPDK route lookups to FreeBSD.

2021-01-09 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit 537d134373141c2d25bfb24af6d661d0e6102927
Author: Alexander V. Chernikov 
AuthorDate: 2021-01-09 12:08:00 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-01-09 12:41:04 +

Bring DPDK route lookups to FreeBSD.

This change introduces loadable fib lookup modules based on
 DPDK rte_lpm lib targeted for high-speed lookups in large-scale tables.
It is based on the lookup framework described in D27401.

IPv4 module is called dpdk_lpm4. It wraps around rte_lpm [1] library.
This library implements variation of DIR24-8 [2] lookup algorithm.
Module provide lockless route lookups and in-place incremental updates,
 allowing for good RIB performance.

IPv6 module is called dpdk_lpm6. It wraps around rte_lpm6 [3] library.
Implementation can be seen as multi-bit trie where the stride or number of 
bits
 inspected on each level varies from level to level.
It can vary from 1 to 14 memory accesses, with 5 being the average value
 for the lengths that are most commonly used in IPv6.
Module provide lockless route lookups for global unicast addresses
 and in-place incremental updates, allowing for good RIB performance.

Implementation details:
* wrapper code lives in `sys/contrib/dpdk_rte_lpm/dpdk_lpm[6].c`.
* rte_lpm[6] implementation contains both RIB and FIB code.
 . RIB ("rule_") code, backed by array of hash tables part has been 
commented out,
 as base radix already provides all the necessary primitives.
* link-local lookups are currently implemented as base radix lookup.
 This part should be converted to something like read-only radix trie.

Usage detail:
Compile kernel with option FIB_ALGO and load dpdk_lpm4/dpdk_lpm6
 module at any time. They will be picked up automatically when
 amount of routes raises to several thousand.

[1]: https://doc.dpdk.org/guides/prog_guide/lpm_lib.html
[2]: http://yuba.stanford.edu/~nickm/papers/Infocom98_lookup.pdf
[3]: https://doc.dpdk.org/guides/prog_guide/lpm6_lib.html

Differential Revision: https://reviews.freebsd.org/D27412
---
 sys/contrib/dpdk_rte_lpm/dpdk_lpm.c  |  423 +++
 sys/contrib/dpdk_rte_lpm/dpdk_lpm6.c |  487 
 sys/contrib/dpdk_rte_lpm/dpdk_lpm6.h |   57 +
 sys/contrib/dpdk_rte_lpm/rte_branch_prediction.h |   41 +
 sys/contrib/dpdk_rte_lpm/rte_common.h|  838 +
 sys/contrib/dpdk_rte_lpm/rte_debug.h |   83 ++
 sys/contrib/dpdk_rte_lpm/rte_jhash.h |  379 ++
 sys/contrib/dpdk_rte_lpm/rte_log.h   |  383 ++
 sys/contrib/dpdk_rte_lpm/rte_lpm.c   | 1107 +
 sys/contrib/dpdk_rte_lpm/rte_lpm.h   |  403 ++
 sys/contrib/dpdk_rte_lpm/rte_lpm6.c  | 1415 ++
 sys/contrib/dpdk_rte_lpm/rte_lpm6.h  |  209 
 sys/contrib/dpdk_rte_lpm/rte_shim.h  |   31 +
 sys/contrib/dpdk_rte_lpm/rte_tailq.h |  140 +++
 sys/modules/Makefile |   10 +
 sys/modules/dpdk_lpm4/Makefile   |   12 +
 sys/modules/dpdk_lpm6/Makefile   |   12 +
 17 files changed, 6030 insertions(+)

diff --git a/sys/contrib/dpdk_rte_lpm/dpdk_lpm.c 
b/sys/contrib/dpdk_rte_lpm/dpdk_lpm.c
new file mode 100644
index ..af145997c4d6
--- /dev/null
+++ b/sys/contrib/dpdk_rte_lpm/dpdk_lpm.c
@@ -0,0 +1,423 @@
+/*-
+ * 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

git: 0433870efefc - main - Add fib lookup testing module.

2021-01-09 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit 0433870efefc7875eb3cc4b2896cfc74dffb0eeb
Author: Alexander V. Chernikov 
AuthorDate: 2021-01-09 12:55:04 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-01-09 13:20:30 +

Add fib lookup testing module.

This module intended to measure performance of routing lookups.

Uses a list of IP addresses specified by sysctl one-by-one.
Performance testing is triggered by changing sysctl OID with a number of 
lookups to execute.
Lookups are done by the chunks of 10K routes, entering/exiting epoch on
 chunk granularity to amortise cost.

Example:
make -C sys/modules/test/fib_lookup unload load
for i in `cat ~/ip4.txt`; do sysctl net.route.test.add_inet_addr=$i; done
for i in `cat ~/ip6.txt`; do sysctl net.route.test.add_inet6_addr=$i; done

sysctl net.route.test.run_inet=1000

dmesg | tail

Dec 13 23:24:05 current kernel: 1000 packets in 417240173 nanoseconds, 
23967011 pps
Dec 13 23:24:06 current kernel: run: 1000 packets vnet 
0xf80003073f00
Dec 13 23:24:07 current kernel: 1000 packets in 423086254 nanoseconds, 
23635842 pps

Differential Revision: https://reviews.freebsd.org/D27604
---
 sys/modules/tests/fib_lookup/Makefile |  11 +
 sys/tests/fib_lookup/fib_lookup.c | 537 ++
 2 files changed, 548 insertions(+)

diff --git a/sys/modules/tests/fib_lookup/Makefile 
b/sys/modules/tests/fib_lookup/Makefile
new file mode 100644
index ..06404ff928e6
--- /dev/null
+++ b/sys/modules/tests/fib_lookup/Makefile
@@ -0,0 +1,11 @@
+# $FreeBSD$
+
+SYSDIR?=${SRCTOP}/sys
+.include "${SYSDIR}/conf/kern.opts.mk"
+
+.PATH: ${SYSDIR}/tests/fib_lookup
+
+KMOD=  test_lookup
+SRCS=  opt_inet.h opt_inet6.h fib_lookup.c
+
+.include 
diff --git a/sys/tests/fib_lookup/fib_lookup.c 
b/sys/tests/fib_lookup/fib_lookup.c
new file mode 100644
index ..b48fdfb5630e
--- /dev/null
+++ b/sys/tests/fib_lookup/fib_lookup.c
@@ -0,0 +1,537 @@
+/*-
+ * 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.
+ */
+
+#include 
+__FBSDID("$FreeBSD$");
+#include "opt_inet.h"
+#include "opt_inet6.h"
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+
+#include 
+#include 
+#include 
+
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#defineCHUNK_SIZE  1
+
+VNET_DEFINE_STATIC(struct in_addr *, inet_addr_list);
+#defineV_inet_addr_listVNET(inet_addr_list)
+VNET_DEFINE_STATIC(int, inet_list_size);
+#defineV_inet_list_sizeVNET(inet_list_size)
+
+VNET_DEFINE_STATIC(struct in6_addr *, inet6_addr_list);
+#defineV_inet6_addr_list   VNET(inet6_addr_list)
+VNET_DEFINE_STATIC(int, inet6_list_size);
+#defineV_inet6_list_size   VNET(inet6_list_size)
+
+SYSCTL_DECL(_net_route);
+SYSCTL_NODE(_net_route, OID_AUTO, test, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
+"Route algorithm lookups");
+
+static int
+add_addr(int family, char *addr_str)
+{
+
+   if (family == AF_INET) {
+   struct in_addr *paddr_old = V_inet_addr_list;
+   int size_old = V_inet_list_size;
+   struct in_addr addr;
+
+   if (inet_pton(AF_INET, addr_str, &addr) != 1)
+   return (EINVAL);
+
+   struct in_addr *paddr = mallocarray(size_old

git: 685de460bc91 - main - Use static initializers for fib algo to shift initialization to ealier stage. This allows to register modules loaded at boot time.

2021-01-10 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit 685de460bc91737331eaf475b0f517517b2ddbd0
Author: Alexander V. Chernikov 
AuthorDate: 2021-01-11 00:16:54 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-01-11 00:16:54 +

Use static initializers for fib algo to shift initialization
 to ealier stage. This allows to register modules loaded at
 boot time.

Reported by:olivier
---
 sys/net/route/fib_algo.c | 13 ++---
 1 file changed, 2 insertions(+), 11 deletions(-)

diff --git a/sys/net/route/fib_algo.c b/sys/net/route/fib_algo.c
index 32bafbaca3d1..5e63535f3926 100644
--- a/sys/net/route/fib_algo.c
+++ b/sys/net/route/fib_algo.c
@@ -169,6 +169,7 @@ struct mtx fib_mtx;
 #defineFIB_MOD_UNLOCK()mtx_unlock(&fib_mtx)
 #defineFIB_MOD_LOCK_ASSERT()   mtx_assert(&fib_mtx, MA_OWNED)
 
+MTX_SYSINIT(fib_mtx, &fib_mtx, "algo list mutex", MTX_DEF);
 
 /* Algorithm has to be this percent better than the current to switch */
 #defineBEST_DIFF_PERCENT   (5 * 256 / 100)
@@ -219,7 +220,7 @@ SYSCTL_INT(_net_route_algo, OID_AUTO, debug_level, 
CTLFLAG_RW | CTLFLAG_RWTUN,
 
 
 /* List of all registered lookup algorithms */
-static TAILQ_HEAD(, fib_lookup_module) all_algo_list;
+static TAILQ_HEAD(, fib_lookup_module) all_algo_list = 
TAILQ_HEAD_INITIALIZER(all_algo_list);
 
 /* List of all fib lookup instances in the vnet */
 VNET_DEFINE_STATIC(TAILQ_HEAD(fib_data_head, fib_data), fib_data_list);
@@ -1613,13 +1614,3 @@ vnet_fib_destroy(void)
fib_error_clear();
FIB_MOD_UNLOCK();
 }
-
-static void
-fib_init(void)
-{
-
-   mtx_init(&fib_mtx, "algo list mutex", NULL, MTX_DEF);
-   TAILQ_INIT(&all_algo_list);
-}
-SYSINIT(fib_init, SI_SUB_PROTO_DOMAIN, SI_ORDER_SECOND, fib_init, NULL);
-
___
dev-commits-src-main@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-main
To unsubscribe, send any mail to "dev-commits-src-main-unsubscr...@freebsd.org"


git: 0da3f8c98d17 - main - Bump amount of queued packets in for unresolved ARP/NDP entries to 16.

2021-01-11 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit 0da3f8c98d17d9c6e67d0f6cf45085df6a5ef041
Author: Alexander V. Chernikov 
AuthorDate: 2021-01-11 19:50:21 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-01-11 19:51:11 +

Bump amount of queued packets in for unresolved ARP/NDP entries to 16.

Currently default behaviour is to keep only 1 packet per unresolved entry.
Ability to queue more than one packet was added 10 years ago, in r215207,
 though the default value was kep intact.

Things have changed since that time. Systems tend to initiate multiple
 connections at once for a variety of reasons.
For example, recent kern/252278 bug report describe happy-eyeball DNS
 behaviour sending multiple requests to the DNS server.

The primary driver for upper value for the queue length determination is
 memory consumption. Remote actors should not be able to easily exhaust
 local memory by sending packets to unresolved arp/ND entries.

For now, bump value to 16 packets, to match Darwin implementation.

The proper approach would be to switch the limit to calculate memory
 consumption instead of packet count and limit based on memory.

We should MFC this with a variation of D22447.

Reviewers: #manpages, #network, bz, emaste

Reviewed By: emaste, gbe(doc), jilles(doc)
MFC after: 1 month
Differential Revision: https://reviews.freebsd.org/D28068
---
 sys/netinet/if_ether.c |  2 +-
 sys/netinet6/nd6.c |  2 +-
 usr.sbin/arp/arp.4 | 25 +++--
 3 files changed, 9 insertions(+), 20 deletions(-)

diff --git a/sys/netinet/if_ether.c b/sys/netinet/if_ether.c
index 972701369d13..e09ad3d47382 100644
--- a/sys/netinet/if_ether.c
+++ b/sys/netinet/if_ether.c
@@ -114,7 +114,7 @@ VNET_PCPUSTAT_SYSINIT(arpstat);
 VNET_PCPUSTAT_SYSUNINIT(arpstat);
 #endif /* VIMAGE */
 
-VNET_DEFINE_STATIC(int, arp_maxhold) = 1;
+VNET_DEFINE_STATIC(int, arp_maxhold) = 16;
 
 #defineV_arpt_keep VNET(arpt_keep)
 #defineV_arpt_down VNET(arpt_down)
diff --git a/sys/netinet6/nd6.c b/sys/netinet6/nd6.c
index 5b66375e6613..386eb7cca922 100644
--- a/sys/netinet6/nd6.c
+++ b/sys/netinet6/nd6.c
@@ -106,7 +106,7 @@ VNET_DEFINE_STATIC(int, nd6_maxndopt) = 10; /* max # of ND 
options allowed */
 
 VNET_DEFINE(int, nd6_maxnudhint) = 0;  /* max # of subsequent upper
 * layer hints */
-VNET_DEFINE_STATIC(int, nd6_maxqueuelen) = 1; /* max pkts cached in unresolved
+VNET_DEFINE_STATIC(int, nd6_maxqueuelen) = 16; /* max pkts cached in unresolved
 * ND entries */
 #defineV_nd6_maxndopt  VNET(nd6_maxndopt)
 #defineV_nd6_maxqueuelen   VNET(nd6_maxqueuelen)
diff --git a/usr.sbin/arp/arp.4 b/usr.sbin/arp/arp.4
index f13af95778a8..c9c9002cf908 100644
--- a/usr.sbin/arp/arp.4
+++ b/usr.sbin/arp/arp.4
@@ -40,9 +40,7 @@
 The Address Resolution Protocol (ARP) is used to dynamically
 map between Protocol Addresses (such as IP addresses) and
 Local Network Addresses (such as Ethernet addresses).
-This implementation maps IP addresses to Ethernet,
-ARCnet,
-or Token Ring addresses.
+This implementation maps IP addresses to Ethernet addresses.
 It is used by all the Ethernet interface drivers.
 .Pp
 ARP caches Internet-Ethernet address mappings.
@@ -51,9 +49,10 @@ ARP queues the message which requires the mapping and 
broadcasts
 a message on the associated network requesting the address mapping.
 If a response is provided, the new mapping is cached and any pending
 message is transmitted.
-ARP will queue at most one packet while waiting for a response to a
-mapping request;
-only the most recently ``transmitted'' packet is kept.
+ARP will queue at most
+.Va net.link.ether.inet.maxhold
+packets while waiting for a response to a mapping request;
+only the most recently ``transmitted'' packets are kept.
 If the target host does not respond after several requests,
 the host is considered to be down allowing an error to be returned to
 transmission attempts.
@@ -65,17 +64,7 @@ for a non-responding destination host, and
 .Er EHOSTUNREACH
 for a non-responding router.
 .Pp
-The ARP cache is stored in the system routing table as
-dynamically-created host routes.
-The route to a directly-attached Ethernet network is installed as a
-.Dq cloning
-route (one with the
-.Li RTF_CLONING
-flag set),
-causing routes to individual hosts on that network to be created on
-demand.
-These routes time out periodically (normally 20 minutes after validated;
-entries are not validated when not in use).
+The ARP cache is stored in per-interface link-level table.
 .Pp
 ARP entries may be added, deleted or changed with the
 .Xr arp 8
@@ -173,7 +162,7 @@ Default is 1200 seconds.
 .It 

git: 2defbe9f0e01 - main - Use rn_match instead of doing indirect calls in fib_algo.

2021-01-11 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit 2defbe9f0e01381da0550e7ffbf4e75c723c9331
Author: Alexander V. Chernikov 
AuthorDate: 2021-01-11 23:11:55 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-01-11 23:30:35 +

Use rn_match instead of doing indirect calls in fib_algo.

Relevant inet/inet6 code has the control over deciding what
 the RIB lookup function currently is. With that in mind,
 explicitly set it to the current value (rn_match) in the
 datapath lookups. This avoids cost on indirect call.

Differential Revision: https://reviews.freebsd.org/D28066
---
 sys/netinet/in_fib_algo.c   | 4 ++--
 sys/netinet6/in6_fib_algo.c | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/sys/netinet/in_fib_algo.c b/sys/netinet/in_fib_algo.c
index 92592a6a286f..48e48da395fa 100644
--- a/sys/netinet/in_fib_algo.c
+++ b/sys/netinet/in_fib_algo.c
@@ -521,7 +521,7 @@ lradix4_lookup(void *algo_data, const struct flm_lookup_key 
key, uint32_t scopei
.sin_len = KEY_LEN_INET,
.sin_addr = key.addr4,
};
-   ent = (struct radix4_addr_entry *)(rnh->rnh_matchaddr(&addr4, 
&rnh->rh));
+   ent = (struct radix4_addr_entry *)(rn_match(&addr4, &rnh->rh));
if (ent != NULL)
return (ent->nhop);
return (NULL);
@@ -680,7 +680,7 @@ radix4_lookup(void *algo_data, const struct flm_lookup_key 
key, uint32_t scopeid
 
nh = NULL;
RIB_RLOCK(rh);
-   rn = rh->rnh_matchaddr((void *)&sin4, &rh->head);
+   rn = rn_match((void *)&sin4, &rh->head);
if (rn != NULL && ((rn->rn_flags & RNF_ROOT) == 0))
nh = (RNTORT(rn))->rt_nhop;
RIB_RUNLOCK(rh);
diff --git a/sys/netinet6/in6_fib_algo.c b/sys/netinet6/in6_fib_algo.c
index 4b0409143c95..c9df9387af37 100644
--- a/sys/netinet6/in6_fib_algo.c
+++ b/sys/netinet6/in6_fib_algo.c
@@ -106,7 +106,7 @@ lradix6_lookup(void *algo_data, const struct flm_lookup_key 
key, uint32_t scopei
};
if (IN6_IS_SCOPE_LINKLOCAL(key.addr6))
addr6.sin6_addr.s6_addr16[1] = htons(scopeid & 0x);
-   ent = (struct radix6_addr_entry *)(rnh->rnh_matchaddr(&addr6, 
&rnh->rh));
+   ent = (struct radix6_addr_entry *)(rn_match(&addr6, &rnh->rh));
if (ent != NULL)
return (ent->nhop);
return (NULL);
@@ -264,7 +264,7 @@ radix6_lookup(void *algo_data, const struct flm_lookup_key 
key, uint32_t scopeid
 
nh = NULL;
RIB_RLOCK(rh);
-   rn = rh->rnh_matchaddr((void *)&sin6, &rh->head);
+   rn = rn_match((void *)&sin6, &rh->head);
if (rn != NULL && ((rn->rn_flags & RNF_ROOT) == 0))
nh = (RNTORT(rn))->rt_nhop;
RIB_RUNLOCK(rh);
___
dev-commits-src-main@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-main
To unsubscribe, send any mail to "dev-commits-src-main-unsubscr...@freebsd.org"


git: e58c8da0683d - main - Map IPv6 link-local prefix to the link-local ifa.

2021-01-13 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit e58c8da0683dcff6ce3432bdfa98f7271140cda3
Author: Alexander V. Chernikov 
AuthorDate: 2021-01-12 23:14:03 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-01-13 10:03:15 +

Map IPv6 link-local prefix to the link-local ifa.

Currently we create link-local route by creating an always-on IPv6 prefix
 in the prefix list. This prefix is not tied to the link-local ifa.

This leads to the following problems:

First, when flushing interface addresses we skip on-link route, leaving
 fe80::/64 prefix on the interface without any IPv6 addresses.
Second, when creating and removing link-local alias we lose fe80::/64 prefix
 from the routing table.

Fix this by attaching link-local prefix to the ifa at the initial creation.

Reviewed by:hrs
MFC after:  2 weeks
Differential revision:  https://reviews.freebsd.org/D28129
---
 sys/netinet6/in6_ifattach.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/sys/netinet6/in6_ifattach.c b/sys/netinet6/in6_ifattach.c
index 81cd24823f10..1a07fb13b179 100644
--- a/sys/netinet6/in6_ifattach.c
+++ b/sys/netinet6/in6_ifattach.c
@@ -520,8 +520,11 @@ in6_ifattach_linklocal(struct ifnet *ifp, struct ifnet 
*altifp)
 * valid with referring to the old link-local address.
 */
if ((pr = nd6_prefix_lookup(&pr0)) == NULL) {
-   if ((error = nd6_prelist_add(&pr0, NULL, NULL)) != 0)
+   if ((error = nd6_prelist_add(&pr0, NULL, &pr)) != 0)
return (error);
+   /* Reference prefix */
+   ia->ia6_ndpr = pr;
+   pr->ndpr_addrcnt++;
} else
nd6_prefix_rele(pr);
 
___
dev-commits-src-main@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-main
To unsubscribe, send any mail to "dev-commits-src-main-unsubscr...@freebsd.org"


git: a6b7689718d2 - main - Remove redundant rtinit() calls from tuntap.

2021-01-13 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit a6b7689718d223e5cefc7beb6d8bb317f92ff839
Author: Alexander V. Chernikov 
AuthorDate: 2021-01-11 23:31:37 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-01-13 10:03:15 +

Remove redundant rtinit() calls from tuntap.

Removed code iterates over if_addrhead and tries to remove
 routes for each ifa.
This is exactly the thing that if_purgeaddrs() do, and
 if_purgeaddr() is already called in the end.

Reviewed by:glebius
MFC after:  2 weeks
Differential revision:  https://reviews.freebsd.org/D28106
---
 sys/net/if_tuntap.c | 32 +---
 1 file changed, 1 insertion(+), 31 deletions(-)

diff --git a/sys/net/if_tuntap.c b/sys/net/if_tuntap.c
index 5789fce5407f..0c0a0dd66339 100644
--- a/sys/net/if_tuntap.c
+++ b/sys/net/if_tuntap.c
@@ -123,7 +123,7 @@ struct tuntap_softc {
 #defineTUN_OPEN0x0001
 #defineTUN_INITED  0x0002
 #defineTUN_UNUSED1 0x0008
-#defineTUN_DSTADDR 0x0010
+#defineTUN_UNUSED2 0x0010
 #defineTUN_LMODE   0x0020
 #defineTUN_RWAIT   0x0040
 #defineTUN_ASYNC   0x0080
@@ -1160,19 +1160,8 @@ tundtor(void *data)
 
/* Delete all addresses and routes which reference this interface. */
if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
-   struct ifaddr *ifa;
-
ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
TUN_UNLOCK(tp);
-   CK_STAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) {
-   /* deal w/IPv4 PtP destination; unlocked read */
-   if (!l2tun && ifa->ifa_addr->sa_family == AF_INET) {
-   rtinit(ifa, (int)RTM_DELETE,
-   tp->tun_flags & TUN_DSTADDR ? RTF_HOST : 0);
-   } else {
-   rtinit(ifa, (int)RTM_DELETE, 0);
-   }
-   }
if_purgeaddrs(ifp);
TUN_LOCK(tp);
}
@@ -1197,10 +1186,6 @@ static void
 tuninit(struct ifnet *ifp)
 {
struct tuntap_softc *tp = ifp->if_softc;
-#ifdef INET
-   struct epoch_tracker et;
-   struct ifaddr *ifa;
-#endif
 
TUNDEBUG(ifp, "tuninit\n");
 
@@ -1209,21 +1194,6 @@ tuninit(struct ifnet *ifp)
if ((tp->tun_flags & TUN_L2) == 0) {
ifp->if_flags |= IFF_UP;
getmicrotime(&ifp->if_lastchange);
-#ifdef INET
-   NET_EPOCH_ENTER(et);
-   CK_STAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) {
-   if (ifa->ifa_addr->sa_family == AF_INET) {
-   struct sockaddr_in *si;
-
-   si = (struct sockaddr_in *)ifa->ifa_dstaddr;
-   if (si && si->sin_addr.s_addr) {
-   tp->tun_flags |= TUN_DSTADDR;
-   break;
-   }
-   }
-   }
-   NET_EPOCH_EXIT(et);
-#endif
TUN_UNLOCK(tp);
} else {
ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
___
dev-commits-src-main@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-main
To unsubscribe, send any mail to "dev-commits-src-main-unsubscr...@freebsd.org"


git: 81728a538d24 - main - Split rtinit() into multiple functions.

2021-01-16 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit 81728a538d24f483d0986850fa3f51d5d84d8f26
Author: Alexander V. Chernikov 
AuthorDate: 2021-01-09 00:19:25 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-01-16 22:42:41 +

Split rtinit() into multiple functions.

rtinit[1]() is a function used to add or remove interface address prefix 
routes,
  similar to ifa_maintain_loopback_route().
It was intended to be family-agnostic. There is a problem with this approach
 in reality.

1) IPv6 code does not use it for the ifa routes. There is a separate layer,
  nd6_prelist_(), providing interface for maintaining interface routes. Its 
part,
  responsible for the actual route table interaction, mimics rtenty() code.

2) rtinit tries to combine multiple actions in the same function: 
constructing
  proper route attributes and handling iterations over multiple fibs, for 
the
  non-zero net.add_addr_allfibs use case. It notably increases the code 
complexity.

3) dstaddr handling. flags parameter re-uses RTF_ flags. As there is no 
special flag
 for p2p connections, host routes and p2p routes are handled in the same 
way.
 Additionally, mapping IFA flags to RTF flags makes the interface pretty 
messy.
 It make rtinit() to clash with ifa_mainain_loopback_route() for IPV4 
interface
 aliases.

4) rtinit() is the last customer passing non-masked prefixes to 
rib_action(),
 complicating rib_action() implementation.

5) rtinit() coupled ifa announce/withdrawal notifications, producing "false 
positive"
 ifa messages in certain corner cases.

To address all these points, the following has been done:

* rtinit() has been split into multiple functions:
- Route attribute construction were moved to the per-address-family 
functions,
 dealing with (2), (3) and (4).
- funnction providing net.add_addr_allfibs handling and route rtsock 
notificaions
 is the new routing table inteface.
- rtsock ifa notificaion has been moved out as well. resulting set of 
funcion are only
 responsible for the actual route notifications.

Side effects:
* /32 alias does not result in interface routes (/32 route and "host" route)
* RTF_PINNED is now set for IPv6 prefixes corresponding to the interface 
addresses

Differential revision:  https://reviews.freebsd.org/D28186
---
 sys/net/if_spppsubr.c  |  10 +-
 sys/net/route.c|  24 -
 sys/net/route.h|   5 -
 sys/net/route/route_ctl.h  |   1 +
 sys/net/route/route_ifaddrs.c  | 192 -
 sys/netinet/in.c   | 133 +--
 sys/netinet/in_var.h   |   1 +
 sys/netinet/raw_ip.c   |   4 +-
 sys/netinet6/in6.c |  54 +-
 sys/netinet6/nd6_rtr.c | 165 ++--
 tests/sys/net/routing/test_rtsock_l3.c |   5 +-
 11 files changed, 294 insertions(+), 300 deletions(-)

diff --git a/sys/net/if_spppsubr.c b/sys/net/if_spppsubr.c
index 5a18147f14a7..fbf7b0ea8f4c 100644
--- a/sys/net/if_spppsubr.c
+++ b/sys/net/if_spppsubr.c
@@ -47,6 +47,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -4881,9 +4882,12 @@ sppp_set_ip_addr(struct sppp *sp, u_long src)
 
if (ifa != NULL) {
int error;
+   int fibnum = ifp->if_fib;
 
+   rt_addrmsg(RTM_DELETE, ifa, fibnum);
/* delete old route */
-   error = rtinit(ifa, (int)RTM_DELETE, RTF_HOST);
+   ia = ifatoia(ifa);
+   error = in_handle_ifaddr_route(RTM_DELETE, ia);
if (debug && error) {
log(LOG_DEBUG, SPP_FMT "sppp_set_ip_addr: rtinit DEL 
failed, error=%d\n",
SPP_ARGS(ifp), error);
@@ -4891,14 +4895,14 @@ sppp_set_ip_addr(struct sppp *sp, u_long src)
 
/* set new address */
si->sin_addr.s_addr = htonl(src);
-   ia = ifatoia(ifa);
IN_IFADDR_WLOCK();
LIST_REMOVE(ia, ia_hash);
LIST_INSERT_HEAD(INADDR_HASH(si->sin_addr.s_addr), ia, ia_hash);
IN_IFADDR_WUNLOCK();
 
+   rt_addrmsg(RTM_ADD, ifa, fibnum);
/* add new route */
-   error = rtinit(ifa, (int)RTM_ADD, RTF_HOST);
+   error = in_handle_ifaddr_route(RTM_ADD, ia);
if (debug && error) {
log(LOG_DEBUG, SPP_FMT "sppp_set_ip_addr: rtinit ADD 
failed, error=%d",
SPP_ARGS(ifp), error);
diff --git a/sys/net/route.c b/sys/net/route.c
in

git: d28210b2c2aa - main - Remove remnants of classful behavior in route(8).

2021-01-16 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit d28210b2c2aaf3200907ed30d296b0d4856dd03c
Author: Alexander V. Chernikov 
AuthorDate: 2021-01-16 23:06:32 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-01-16 23:45:30 +

Remove remnants of classful behavior in route(8).

Curently route(8) treats some addresses as network addresses:

 RTA_DST: inet 10.0.0.0; RTA_NETMASK: inet 255.0.0.0; RTA_IFP: link ;
 RTM_GET: Report Metrics: len 240, pid: 0, seq 1, errno 0, 
flags:
 locks:  inits:
 sockaddrs: 
   10.0.0.0 255.0.0.0 link#0

Note added `RTA_NETMASK` in the request.

Host address from the same network is ok:

route -nv get 10.0.0.1
 RTA_DST: inet 10.0.0.1
 RTA_IFP: link
 RTM_GET: Report Metrics: len 224, pid: 0, seq 1, errno 0, 
flags:
...
   route to: 10.0.0.1
destination: 10.0.0.0
   mask: 255.255.255.0

This change eliminates network auto-guessing part AND reading network from 
/etc/networks.

Reviewed By: rgrimes

Differential Revision: https://reviews.freebsd.org/D24401
---
 sbin/route/route.c | 69 +++---
 1 file changed, 14 insertions(+), 55 deletions(-)

diff --git a/sbin/route/route.c b/sbin/route/route.c
index 9c9e4b304848..51a0c68746a6 100644
--- a/sbin/route/route.c
+++ b/sbin/route/route.c
@@ -120,8 +120,7 @@ static int  flushroutes_fib(int);
 static int getaddr(int, char *, struct hostent **, int);
 static int keyword(const char *);
 #ifdef INET
-static voidinet_makenetandmask(u_long, struct sockaddr_in *,
-   struct sockaddr_in *, u_long);
+static voidinet_makemask(struct sockaddr_in *, u_long);
 #endif
 #ifdef INET6
 static int inet6_makenetandmask(struct sockaddr_in6 *, const char *);
@@ -1113,40 +1112,15 @@ newroute_fib(int fib, char *cmd, int flags)
 
 #ifdef INET
 static void
-inet_makenetandmask(u_long net, struct sockaddr_in *sin,
-struct sockaddr_in *sin_mask, u_long bits)
+inet_makemask(struct sockaddr_in *sin_mask, u_long bits)
 {
u_long mask = 0;
 
rtm_addrs |= RTA_NETMASK;
 
-   /*
-* MSB of net should be meaningful. 0/0 is exception.
-*/
-   if (net > 0)
-   while ((net & 0xff00) == 0)
-   net <<= 8;
-
-   /*
-* If no /xx was specified we must calculate the
-* CIDR address.
-*/
-   if ((bits == 0) && (net != 0)) {
-   u_long i, j;
-
-   for(i = 0, j = 0xff; i < 4; i++)  {
-   if (net & j) {
-   break;
-   }
-   j <<= 8;
-   }
-   /* i holds the first non zero bit */
-   bits = 32 - (i*8);
-   }
if (bits != 0)
mask = 0x << (32 - bits);
 
-   sin->sin_addr.s_addr = htonl(net);
sin_mask->sin_addr.s_addr = htonl(mask);
sin_mask->sin_len = sizeof(struct sockaddr_in);
sin_mask->sin_family = AF_INET;
@@ -1186,8 +1160,6 @@ getaddr(int idx, char *str, struct hostent **hpp, int 
nrflags)
 #if defined(INET)
struct sockaddr_in *sin;
struct hostent *hp;
-   struct netent *np;
-   u_long val;
char *q;
 #elif defined(INET6)
char *q;
@@ -1314,34 +1286,21 @@ getaddr(int idx, char *str, struct hostent **hpp, int 
nrflags)
 
q = strchr(str,'/');
if (q != NULL && idx == RTAX_DST) {
+   /* A.B.C.D/NUM */
*q = '\0';
-   if ((val = inet_network(str)) != INADDR_NONE) {
-   inet_makenetandmask(val, sin,
-   (struct sockaddr_in *)&so[RTAX_NETMASK],
-   strtoul(q+1, 0, 0));
-   return (0);
-   }
-   *q = '/';
-   }
-   if ((idx != RTAX_DST || (nrflags & F_FORCENET) == 0) &&
-   inet_aton(str, &sin->sin_addr)) {
-   val = sin->sin_addr.s_addr;
-   if (idx != RTAX_DST || nrflags & F_FORCEHOST ||
-   inet_lnaof(sin->sin_addr) != INADDR_ANY)
-   return (1);
-   else {
-   val = ntohl(val);
-   goto netdone;
-   }
-   }
-   if (idx == RTAX_DST && (nrflags & F_FORCEHOST) == 0 &&
-   ((val = inet_network(str)) != INADDR_NONE ||
-   ((np = getnetbyname(str)) != NULL && (val = np->n_net) != 0))) {
-netdone:
-   inet_makenetandmask(val, sin,
-   (struct sockaddr_in *)&so[RTAX_NETMASK], 0);
+   if (inet_aton(str, &sin->sin_

git: f9e0752e3573 - main - Create new in6_purgeifaddr() which purges bound ifa prefix if it gets unused.

2021-01-17 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit f9e0752e3573e0b60e578e58ee2eac3d42ff533a
Author: Alexander V. Chernikov 
AuthorDate: 2021-01-13 00:18:00 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-01-17 20:32:25 +

Create new in6_purgeifaddr() which purges bound ifa prefix if
 it gets unused.

Currently if_purgeifaddrs() uses in6_purgeaddr() to remove IPv6
 ifaddrs. in6_purgeaddr() does not trrigger prefix removal if
 number of linked ifas goes to 0, as this is a low-level function.
 As a result, if_purgeifaddrs() purges all IPv4/IPv6 addresses but
 keeps corresponding IPv6 prefixes.

Fix this by creating higher-level wrapper which handles unused
 prefix usecase and use it in if_purgeifaddrs().

Differential revision:  https://reviews.freebsd.org/D28128
---
 sys/net/if.c   |  2 +-
 sys/netinet6/in6.c | 53 +-
 sys/netinet6/in6_var.h |  1 +
 3 files changed, 33 insertions(+), 23 deletions(-)

diff --git a/sys/net/if.c b/sys/net/if.c
index 68ed4cf65dc1..74fdd066fd2d 100644
--- a/sys/net/if.c
+++ b/sys/net/if.c
@@ -1077,7 +1077,7 @@ if_purgeaddrs(struct ifnet *ifp)
 #endif /* INET */
 #ifdef INET6
if (ifa->ifa_addr->sa_family == AF_INET6) {
-   in6_purgeaddr(ifa);
+   in6_purgeifaddr((struct in6_ifaddr *)ifa);
/* ifp_addrhead is already updated */
continue;
}
diff --git a/sys/netinet6/in6.c b/sys/netinet6/in6.c
index b42cc16cdb6f..48fa8dd2efc6 100644
--- a/sys/netinet6/in6.c
+++ b/sys/netinet6/in6.c
@@ -696,31 +696,10 @@ aifaddr_out:
}
 
case SIOCDIFADDR_IN6:
-   {
-   struct nd_prefix *pr;
-
-   /*
-* If the address being deleted is the only one that owns
-* the corresponding prefix, expire the prefix as well.
-* XXX: theoretically, we don't have to worry about such
-* relationship, since we separate the address management
-* and the prefix management.  We do this, however, to provide
-* as much backward compatibility as possible in terms of
-* the ioctl operation.
-* Note that in6_purgeaddr() will decrement ndpr_addrcnt.
-*/
-   pr = ia->ia6_ndpr;
-   in6_purgeaddr(&ia->ia_ifa);
-   if (pr != NULL && pr->ndpr_addrcnt == 0) {
-   ND6_WLOCK();
-   nd6_prefix_unlink(pr, NULL);
-   ND6_WUNLOCK();
-   nd6_prefix_del(pr);
-   }
+   in6_purgeifaddr(ia);
EVENTHANDLER_INVOKE(ifaddr_event_ext, ifp, &ia->ia_ifa,
IFADDR_EVENT_DEL);
break;
-   }
 
default:
if (ifp->if_ioctl == NULL) {
@@ -1364,6 +1343,36 @@ in6_purgeaddr(struct ifaddr *ifa)
in6_unlink_ifa(ia, ifp);
 }
 
+/*
+ * Removes @ia from the corresponding interfaces and unlinks corresponding
+ *  prefix if no addresses are using it anymore.
+ */
+void
+in6_purgeifaddr(struct in6_ifaddr *ia)
+{
+   struct nd_prefix *pr;
+
+   /*
+* If the address being deleted is the only one that owns
+* the corresponding prefix, expire the prefix as well.
+* XXX: theoretically, we don't have to worry about such
+* relationship, since we separate the address management
+* and the prefix management.  We do this, however, to provide
+* as much backward compatibility as possible in terms of
+* the ioctl operation.
+* Note that in6_purgeaddr() will decrement ndpr_addrcnt.
+*/
+   pr = ia->ia6_ndpr;
+   in6_purgeaddr(&ia->ia_ifa);
+   if (pr != NULL && pr->ndpr_addrcnt == 0) {
+   ND6_WLOCK();
+   nd6_prefix_unlink(pr, NULL);
+   ND6_WUNLOCK();
+   nd6_prefix_del(pr);
+   }
+}
+
+
 static void
 in6_unlink_ifa(struct in6_ifaddr *ia, struct ifnet *ifp)
 {
diff --git a/sys/netinet6/in6_var.h b/sys/netinet6/in6_var.h
index f5e6a931ae64..5f4364c6fba0 100644
--- a/sys/netinet6/in6_var.h
+++ b/sys/netinet6/in6_var.h
@@ -887,6 +887,7 @@ int in6_update_ifa(struct ifnet *, struct in6_aliasreq *,
 void   in6_prepare_ifra(struct in6_aliasreq *, const struct in6_addr *,
const struct in6_addr *);
 void   in6_purgeaddr(struct ifaddr *);
+void   in6_purgeifaddr(struct in6_ifaddr *);
 intin6if_do_dad(struct ifnet *);
 void   in6_savemkludge(struct in6_ifaddr *);
 void   *in6_domifattach(struct ifnet *);
___
dev-commits-src-main@freebsd.org mailing list
https://lists.freebsd.org/mailman

git: f8798767219d - main - Fix IPv4 fib bsearch4() lookup array construction.

2021-01-17 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit f8798767219ddc5a6dc075b1d2c751ee910e4f10
Author: Alexander V. Chernikov 
AuthorDate: 2021-01-17 19:43:52 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-01-17 20:32:26 +

Fix IPv4 fib bsearch4() lookup array construction.

Current code didn't properly handle the case with nested prefixes
 like 10.0.0.0/24 && 10.0.0.0/25.
---
 sys/netinet/in_fib_algo.c | 12 
 1 file changed, 12 insertions(+)

diff --git a/sys/netinet/in_fib_algo.c b/sys/netinet/in_fib_algo.c
index 48e48da395fa..fd817a3fedf0 100644
--- a/sys/netinet/in_fib_algo.c
+++ b/sys/netinet/in_fib_algo.c
@@ -360,6 +360,18 @@ bsearch4_process_record(struct bsearch4_array *dst_array,
if (!add_array_entry(dst_array, &new_entry))
return (false);
 }
+
+/*
+ * Special case: adding more specific prefix at the start of
+ * the previous interval:
+ * 10.0.0.0(/24,nh=3), 10.0.0.0(/25,nh=4)
+ * Alter the last record, seeting new nexthop and mask.
+ */
+if (br_tmp->addr4 == rib_entry->addr4) {
+   *br_tmp = *rib_entry;
+   add_array_entry(stack, rib_entry);
+   return (true);
+}
 }
 
if (!add_array_entry(dst_array, rib_entry))
___
dev-commits-src-main@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-main
To unsubscribe, send any mail to "dev-commits-src-main-unsubscr...@freebsd.org"


git: 9d6567bc30a0 - main - Fix panic on vnet creation if fib algo has been set to fixed value. Make fixed algo property per-VNET instead of global.

2021-01-17 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit 9d6567bc30a0ae3f6660cc55bc97283ba791b112
Author: Alexander V. Chernikov 
AuthorDate: 2021-01-16 22:55:14 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-01-17 20:32:25 +

Fix panic on vnet creation if fib algo has been set to fixed value.
Make fixed algo property per-VNET instead of global.
---
 sys/net/route/fib_algo.c | 29 ++---
 1 file changed, 14 insertions(+), 15 deletions(-)

diff --git a/sys/net/route/fib_algo.c b/sys/net/route/fib_algo.c
index 5e63535f3926..b84217034e16 100644
--- a/sys/net/route/fib_algo.c
+++ b/sys/net/route/fib_algo.c
@@ -106,12 +106,14 @@ SYSCTL_NODE(_net_route, OID_AUTO, algo, CTLFLAG_RW | 
CTLFLAG_MPSAFE, 0,
 "Fib algorithm lookups");
 
 #ifdef INET6
-bool algo_fixed_inet6 = false;
+VNET_DEFINE_STATIC(bool, algo_fixed_inet6) = false;
+#defineV_algo_fixed_inet6  VNET(algo_fixed_inet6)
 SYSCTL_NODE(_net_route_algo, OID_AUTO, inet6, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
 "IPv6 longest prefix match lookups");
 #endif
 #ifdef INET
-bool algo_fixed_inet = false;
+VNET_DEFINE_STATIC(bool, algo_fixed_inet) = false;
+#defineV_algo_fixed_inet   VNET(algo_fixed_inet)
 SYSCTL_NODE(_net_route_algo, OID_AUTO, inet, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
 "IPv4 longest prefix match lookups");
 #endif
@@ -155,6 +157,7 @@ static void destroy_fd_instance_epoch(epoch_context_t ctx);
 static enum flm_op_result attach_datapath(struct fib_data *fd);
 static bool is_idx_free(struct fib_data *fd, uint32_t index);
 static void set_algo_fixed(struct rib_head *rh);
+static bool is_algo_fixed(struct rib_head *rh);
 
 static uint32_t fib_ref_nhop(struct fib_data *fd, struct nhop_object *nh);
 static void fib_unref_nhop(struct fib_data *fd, struct nhop_object *nh);
@@ -983,7 +986,7 @@ static void
 rebuild_fd_callout(void *_data)
 {
struct fib_data *fd, *fd_new, *fd_tmp;
-   struct fib_lookup_module *flm_new;
+   struct fib_lookup_module *flm_new = NULL;
struct epoch_tracker et;
enum flm_op_result result;
bool need_rebuild = false;
@@ -1000,7 +1003,8 @@ rebuild_fd_callout(void *_data)
CURVNET_SET(fd->fd_vnet);
 
/* First, check if we're still OK to use this algo */
-   flm_new = fib_check_best_algo(fd->fd_rh, fd->fd_flm);
+   if (!is_algo_fixed(fd->fd_rh))
+   flm_new = fib_check_best_algo(fd->fd_rh, fd->fd_flm);
if ((flm_new == NULL) && (!need_rebuild)) {
/* Keep existing algo, no need to rebuild. */
CURVNET_RESTORE();
@@ -1135,7 +1139,7 @@ set_algo_inet_sysctl_handler(SYSCTL_HANDLER_ARGS)
return (set_fib_algo(RT_DEFAULT_FIB, AF_INET, oidp, req));
 }
 SYSCTL_PROC(_net_route_algo_inet, OID_AUTO, algo,
-CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_MPSAFE, NULL, 0,
+CTLFLAG_VNET | CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_MPSAFE, NULL, 0,
 set_algo_inet_sysctl_handler, "A", "Set IPv4 lookup algo");
 #endif
 
@@ -1147,7 +1151,7 @@ set_algo_inet6_sysctl_handler(SYSCTL_HANDLER_ARGS)
return (set_fib_algo(RT_DEFAULT_FIB, AF_INET6, oidp, req));
 }
 SYSCTL_PROC(_net_route_algo_inet6, OID_AUTO, algo,
-CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_MPSAFE, NULL, 0,
+CTLFLAG_VNET | CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_MPSAFE, NULL, 0,
 set_algo_inet6_sysctl_handler, "A", "Set IPv6 lookup algo");
 #endif
 
@@ -1434,12 +1438,12 @@ set_algo_fixed(struct rib_head *rh)
switch (rh->rib_family) {
 #ifdef INET
case AF_INET:
-   algo_fixed_inet = true;
+   V_algo_fixed_inet = true;
break;
 #endif
 #ifdef INET6
case AF_INET6:
-   algo_fixed_inet6 = true;
+   V_algo_fixed_inet6 = true;
break;
 #endif
}
@@ -1452,11 +1456,11 @@ is_algo_fixed(struct rib_head *rh)
switch (rh->rib_family) {
 #ifdef INET
case AF_INET:
-   return (algo_fixed_inet);
+   return (V_algo_fixed_inet);
 #endif
 #ifdef INET6
case AF_INET6:
-   return (algo_fixed_inet6);
+   return (V_algo_fixed_inet6);
 #endif
}
return (false);
@@ -1480,11 +1484,6 @@ fib_check_best_algo(struct rib_head *rh, struct 
fib_lookup_module *orig_flm)
fib_get_rtable_info(rh, &rinfo);
 
FIB_MOD_LOCK();
-   if (is_algo_fixed(rh)) {
-   FIB_MOD_UNLOCK();
-   return (NULL);
-   }
-
TAILQ_FOREACH(flm, &all_algo_list, entries) {
if (flm->flm_family != rh->rib_family)
continue;
___
dev-commits-src-main@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-main
To unsubscribe, send any mail to "dev-commits-src-main-unsubscr...@freebsd.org"


git: 74935ce881ea - main - Enable running fib tests inside vnet jail.

2021-01-17 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit 74935ce881ea7d0abdd59ccae10c6593d4ac14e6
Author: Alexander V. Chernikov 
AuthorDate: 2021-01-17 19:46:56 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-01-17 20:32:26 +

Enable running fib tests inside vnet jail.
---
 sys/tests/fib_lookup/fib_lookup.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/sys/tests/fib_lookup/fib_lookup.c 
b/sys/tests/fib_lookup/fib_lookup.c
index b48fdfb5630e..3dd1bb8d5a50 100644
--- a/sys/tests/fib_lookup/fib_lookup.c
+++ b/sys/tests/fib_lookup/fib_lookup.c
@@ -219,7 +219,7 @@ run_test_inet(SYSCTL_HANDLER_ARGS)
return (0);
 }
 SYSCTL_PROC(_net_route_test, OID_AUTO, run_inet,
-CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE,
+CTLFLAG_VNET | CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE,
 0, 0, run_test_inet, "I", "Execute fib4_lookup test");
 
 static uint64_t
@@ -283,7 +283,7 @@ run_test_inet6(SYSCTL_HANDLER_ARGS)
return (0);
 }
 SYSCTL_PROC(_net_route_test, OID_AUTO, run_inet6,
-CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE,
+CTLFLAG_VNET | CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE,
 0, 0, run_test_inet6, "I", "Execute fib6_lookup test");
 
 static bool
@@ -389,7 +389,7 @@ run_test_inet_random(SYSCTL_HANDLER_ARGS)
return (0);
 }
 SYSCTL_PROC(_net_route_test, OID_AUTO, run_inet_random,
-CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE,
+CTLFLAG_VNET | CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE,
 0, 0, run_test_inet_random, "I", "Execute fib4_lookup random check tests");
 
 
@@ -502,7 +502,7 @@ run_test_inet_scan(SYSCTL_HANDLER_ARGS)
return (0);
 }
 SYSCTL_PROC(_net_route_test, OID_AUTO, run_inet_scan,
-CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE,
+CTLFLAG_VNET | CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE,
 0, 0, run_test_inet_scan, "I", "Execute fib4_lookup scan tests");
 
 
___
dev-commits-src-main@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-main
To unsubscribe, send any mail to "dev-commits-src-main-unsubscr...@freebsd.org"


Re: git: 3b15beb30b3b - main - Implement malloc_domainset_aligned(9).

2021-01-18 Thread Alexander V . Chernikov
17.01.2021, 17:30, "Konstantin Belousov" :
> The branch main has been updated by kib:
>
> URL: 
> https://cgit.FreeBSD.org/src/commit/?id=3b15beb30b3b4ba17bae3d1d43c8c04ff862bb57
>
> commit 3b15beb30b3b4ba17bae3d1d43c8c04ff862bb57
> Author: Konstantin Belousov 
> AuthorDate: 2021-01-14 03:59:34 +
> Commit: Konstantin Belousov 
> CommitDate: 2021-01-17 17:29:05 +
>
> Implement malloc_domainset_aligned(9).
Hi Kostik,

This change makes my vm panic in usb code. No dump, as dumpdev not mounted yet.

Note: the below lines have been OCR'ed, so there may be some errors.

Root mount waiting for: CAM usbus0 usbus1
panic: malloc_domainset_aligned: result not aligned 0xf8000551ca80 size 
0x180 align 0x100
cpuid = 1
time = 2
KDB: stack backtrace:
db_trace_self_urapper() at db_trace_self_wrapper+0x2b/frame 0xfe004d6345c0
vpanic() at vpanic+0x181 /frame 0xfe004d634610
panic() at panic+0x43/frame 0xfe004d634670
malloc_domainset_aligned() at malloc_domainset_aligned+0x8e/frame 
0xfe004d6346a0 bounce_bus_dmamem_alloc() at 
bounce_bus_dmamem_alloc+0xde/frame 0xfe004d6346d0
usb_pc_alloc_mem() at usb_pc_alloc_mem+0x7c/frame 0xfe004d634730
usbd_transfer_setup_sub_malloc() at usbd_transfer_setup_sub_malloc+0x2fc/frame 
0xfe004d6347c0
uhci_xfer_setup() at uhci_xfer_setup+0x1c9/frame 0xfe004d634840
usbd_transfer_setup() at usbd_transfer_setup+0x64a/frame 0xfe004d634910
usbd_ctr l_transfer_setup() at usbd_ctrl_transfer_setup+0xad/frame 
0xfe004d634960
usbd_do_reguest_flags() at usbd_do_reguest_flags+0x220/frame 0xfe004d6349f0
usbd_reg_set_addressO at usbd_reg_set_address+0x9d/frame 0xfe004d634a30
usb_alloc_device() at usb_alloc_device+0x50e/frame 0xfe004d634ae0
uhub_explore() at uhub_explore+0x584/frame 0xfe004d634b60
usb_bus_explore() at usb_bus_explore+0x117/frame 0xfe004d634b80
usb_process() at usb_process+0xf3/frame 0xfe004d634bb0
fork_exit() at fork_exit+0x80/frame 0xfe004d634bf0
fork_trampoline() at fork_trampoline+0xe/frame 0xfe004d634bf0

After converting KASSERT to printf:

malloc_domainset_aligned: result not aligned 0xf80005309a80 size 0x180 
align 0x100
bus_dmamem_alloc failed to align memory properly.
malloc_domainset_aligned: result not aligned 0xf80005309a80 size 0x180 
align 0x100
bus_dmamem_alloc failed to align memory properly.
ugen0.2:  at usbus0
Root mount waiting for: CAM usbus0 usbus1
malloc_domainset_aligned: result not aligned 0xf80005309780 size 0x180 
align 0x100
bus_dmamem_alloc failed to align memory properly.
malloc_domainset_aligned: result not aligned 0xf80005309780 size 0x180 
align 0x100
bus_dmamem_alloc failed to align memory properly.
ugen0.3:  at usbus0
uhub2 on uhub0
uhub2:  on usbus0
malloc_domainset_aligned: result not aligned 0xf80005309480 size 0x180 
align 0x100
bus_dmamem_alloc failed to align memory properly.
malloc_domainset_aligned: result not aligned 0xf80005309180 size 0x180 
align 0x100
bus_dmamem_alloc failed to align memory properly.


>
> Change the power-of-two malloc zones to require alignment equal to the
> size [*]. Current uma allocator already provides such alignment, so in
> fact this change does not change anything except providing future-proof
> setup.
>
> Suggested by: markj [*]
> Reviewed by: andrew, jah, markj
> Tested by: pho
> MFC after: 1 week
> Sponsored by: The FreeBSD Foundation
> Differential Revision: https://reviews.freebsd.org/D28147
> ---
>  sys/kern/kern_malloc.c | 28 +++-
>  sys/sys/malloc.h | 3 +++
>  2 files changed, 30 insertions(+), 1 deletion(-)
>
> diff --git a/sys/kern/kern_malloc.c b/sys/kern/kern_malloc.c
> index f79352f2fbfd..232472708b9b 100644
> --- a/sys/kern/kern_malloc.c
> +++ b/sys/kern/kern_malloc.c
> @@ -763,6 +763,28 @@ malloc_domainset_exec(size_t size, struct malloc_type 
> *mtp, struct domainset *ds
>  return (malloc_large(&size, mtp, ds, flags DEBUG_REDZONE_ARG));
>  }
>
> +void *
> +malloc_domainset_aligned(size_t size, size_t align,
> + struct malloc_type *mtp, struct domainset *ds, int flags)
> +{
> + void *res;
> +
> + KASSERT(align != 0 && powerof2(align),
> + ("malloc_domainset_aligned: wrong align %#zx size %#zx",
> + align, size));
> + KASSERT(align <= kmemzones[nitems(kmemzones) - 2].kz_size,
> + ("malloc_domainset_aligned: align %#zx (size %#zx) too large",
> + align, size));
> +
> + if (size < align)
> + size = align;
> + res = malloc_domainset(size, mtp, ds, flags);
> + KASSERT(res == NULL || ((uintptr_t)res & (align - 1)) == 0,
> + ("malloc_domainset_aligned: result not aligned %p size %#zx "
> + "align %#zx", res, size, align));
> + return (res);
> +}
> +
>  void *
>  mallocarray(size_t nmemb, size_t size, struct malloc_type *type, int flags)
>  {
> @@ -1146,8 +1168,12 @@ mallocinit(void *dummy)
>  for (i = 0, indx = 0; kmemzones[indx].kz_size != 0; indx++) {
>  int size = kmemzones[indx].kz_size;
>    

git: 5bdce6ff546e - main - Remove deadlock in rc caused by pwait waiting for itself.

2021-01-21 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit 5bdce6ff546e00673f9f515d2165d02901e858aa
Author: Alexander V. Chernikov 
AuthorDate: 2021-01-21 21:26:15 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-01-21 21:36:37 +

Remove deadlock in rc caused by pwait waiting for itself.

The following situation can trigger the deadlock:
1) Long time ago a_service was started through rc.d
2) We want to restart a_service and issue service a_service restart
3) rc.subr reads current process PID (via file or process),
   sends TERM signal and runs pwait with PID harvested
4) a_service process dies very quickly so it's PID becomes available.
   It is possible that while original process was running,
   PID counter overflowed and pwait got assigned a_service's PID.

This patch ignores pid(s) to wait that are equal to pwait PID.

Reported by:Dan McGregor, Boris Lytochkin
Submitted by:   Boris Lytochkin 
Reviewed By:0mp
MFC after:  2 weeks
PR: 218598
Differential Revision: https://reviews.freebsd.org/D28240
---
 bin/pwait/pwait.1 | 6 +-
 bin/pwait/pwait.c | 4 
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/bin/pwait/pwait.1 b/bin/pwait/pwait.1
index 0452203eb4a1..b9b651bfc905 100644
--- a/bin/pwait/pwait.1
+++ b/bin/pwait/pwait.1
@@ -32,7 +32,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd October 5, 2020
+.Dd January 21, 2021
 .Dt PWAIT 1
 .Os
 .Sh NAME
@@ -145,6 +145,10 @@ is not a substitute for the
 .Xr wait 1
 builtin
 as it will not clean up any zombies or state in the parent process.
+.Pp
+To avoid deadlock,
+.Nm
+will ignore its own pid, if it is provided as a process id to wait for.
 .Sh HISTORY
 A
 .Nm
diff --git a/bin/pwait/pwait.c b/bin/pwait/pwait.c
index f39922b48eb9..85cc6b994acf 100644
--- a/bin/pwait/pwait.c
+++ b/bin/pwait/pwait.c
@@ -146,6 +146,10 @@ main(int argc, char *argv[])
warnx("%s: bad process id", s);
continue;
}
+   if (pid == getpid()) {
+   warnx("%s: skiping my own pid", s);
+   continue;
+   }
for (i = 0; i < nleft; i++) {
if (e[i].ident == (uintptr_t)pid) {
break;
___
dev-commits-src-main@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-main
To unsubscribe, send any mail to "dev-commits-src-main-unsubscr...@freebsd.org"


git: bbff3a72b23a - main - Fix typo in pwait.c introduced in 5bdce6ff546e

2021-01-21 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit bbff3a72b23a389aebd492ad7c9db9a51166e907
Author: Alexander V. Chernikov 
AuthorDate: 2021-01-21 21:43:27 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-01-21 21:43:27 +

Fix typo in pwait.c introduced in 5bdce6ff546e

Reported by:kevans
---
 bin/pwait/pwait.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/bin/pwait/pwait.c b/bin/pwait/pwait.c
index 85cc6b994acf..66919ffa1c42 100644
--- a/bin/pwait/pwait.c
+++ b/bin/pwait/pwait.c
@@ -147,7 +147,7 @@ main(int argc, char *argv[])
continue;
}
if (pid == getpid()) {
-   warnx("%s: skiping my own pid", s);
+   warnx("%s: skipping my own pid", s);
continue;
}
for (i = 0; i < nleft; i++) {
___
dev-commits-src-main@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-main
To unsubscribe, send any mail to "dev-commits-src-main-unsubscr...@freebsd.org"


git: 130aebbab0d3 - main - Further refactor IPv4 interface route creation.

2021-01-21 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit 130aebbab0d38da85f7d32b6d4227f95a2cd9ec7
Author: Alexander V. Chernikov 
AuthorDate: 2021-01-19 23:50:34 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-01-21 21:48:49 +

Further refactor IPv4 interface route creation.

* Fix bug with /32 aliases introduced in 81728a538d24.
* Explicitly document business logic for IPv4 ifa routes.
* Remove remnants of rtinit()
* Deduplicate ifa->route prefix code by moving it into ia_getrtprefix()
* Deduplicate conditional check for ifa_maintain_loopback_route()  by
 moving into ia_need_loopback_route()
* Remove now-unused flags argument from in_addprefix().

Reviewed by:donner
PR: 252883
Differential Revision:  https://reviews.freebsd.org/D28246
---
 sys/netinet/in.c  | 239 +++---
 sys/netinet/in_var.h  |   2 +-
 sys/netinet/ip_carp.c |   2 +-
 3 files changed, 130 insertions(+), 113 deletions(-)

diff --git a/sys/netinet/in.c b/sys/netinet/in.c
index d6c0c350dec5..eb58c3453cfc 100644
--- a/sys/netinet/in.c
+++ b/sys/netinet/in.c
@@ -79,6 +79,8 @@ static int in_gifaddr_ioctl(u_long, caddr_t, struct ifnet *, 
struct thread *);
 static voidin_socktrim(struct sockaddr_in *);
 static voidin_purgemaddrs(struct ifnet *);
 
+static boolia_need_loopback_route(const struct in_ifaddr *);
+
 VNET_DEFINE_STATIC(int, nosameprefix);
 #defineV_nosameprefix  VNET(nosameprefix)
 SYSCTL_INT(_net_inet_ip, OID_AUTO, no_same_prefix, CTLFLAG_VNET | CTLFLAG_RW,
@@ -445,10 +447,6 @@ in_aifaddr_ioctl(u_long cmd, caddr_t data, struct ifnet 
*ifp, struct thread *td)
if (ifp->if_flags & IFF_POINTOPOINT)
ia->ia_dstaddr = *dstaddr;
 
-   /* XXXGL: rtinit() needs this strange assignment. */
-   if (ifp->if_flags & IFF_LOOPBACK)
-ia->ia_dstaddr = ia->ia_addr;
-
if (vhid != 0) {
error = (*carp_attach_p)(&ia->ia_ifa, vhid);
if (error)
@@ -481,12 +479,7 @@ in_aifaddr_ioctl(u_long cmd, caddr_t data, struct ifnet 
*ifp, struct thread *td)
 * Add route for the network.
 */
if (vhid == 0) {
-   int flags = RTF_UP;
-
-   if (ifp->if_flags & (IFF_LOOPBACK|IFF_POINTOPOINT))
-   flags |= RTF_HOST;
-
-   error = in_addprefix(ia, flags);
+   error = in_addprefix(ia);
if (error)
goto fail1;
}
@@ -494,10 +487,7 @@ in_aifaddr_ioctl(u_long cmd, caddr_t data, struct ifnet 
*ifp, struct thread *td)
/*
 * Add a loopback route to self.
 */
-   if (vhid == 0 && (ifp->if_flags & IFF_LOOPBACK) == 0 &&
-   ia->ia_addr.sin_addr.s_addr != INADDR_ANY &&
-   !((ifp->if_flags & IFF_POINTOPOINT) &&
-ia->ia_dstaddr.sin_addr.s_addr == ia->ia_addr.sin_addr.s_addr)) {
+   if (vhid == 0 && ia_need_loopback_route(ia)) {
struct in_ifaddr *eia;
 
eia = in_localip_more(ia);
@@ -723,7 +713,8 @@ in_match_ifaddr(const struct rtentry *rt, const struct 
nhop_object *nh, void *ar
 
 static int
 in_handle_prefix_route(uint32_t fibnum, int cmd,
-struct sockaddr_in *dst, struct sockaddr_in *netmask, struct ifaddr *ifa)
+struct sockaddr_in *dst, struct sockaddr_in *netmask, struct ifaddr *ifa,
+struct ifnet *ifp)
 {
 
NET_EPOCH_ASSERT();
@@ -738,6 +729,7 @@ in_handle_prefix_route(uint32_t fibnum, int cmd,
 
struct rt_addrinfo info = {
.rti_ifa = ifa,
+   .rti_ifp = ifp,
.rti_flags = RTF_PINNED | ((netmask != NULL) ? 0 : RTF_HOST),
.rti_info = {
[RTAX_DST] = (struct sockaddr *)dst,
@@ -753,29 +745,105 @@ in_handle_prefix_route(uint32_t fibnum, int cmd,
 }
 
 /*
- * Adds or delete interface route corresponding to @ifa.
+ * Routing table interaction with interface addresses.
+ *
+ * In general, two types of routes needs to be installed:
+ * a) "interface" or "prefix" route, telling user that the addresses
+ *   behind the ifa prefix are reached directly.
+ * b) "loopback" route installed for the ifa address, telling user that
+ *   the address belongs to local system.
+ *
+ * Handling for (a) and (b) differs in multi-fib aspects, hence they
+ *  are implemented in different functions below.
+ *
+ * The cases above may intersect - /32 interface aliases results in
+ *  the same prefix produced by (a) and (b). This blurs the definition
+ *  of the "loopback" route and complicate interactions. The interaction
+ *  table is defined below. The case numbers are used in the m

git: 53729367d388 - main - Fix subinterface vlan creation.

2021-01-29 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit 53729367d388e4a6d0ff9be9995bcd4957e9c114
Author: Alexander V. Chernikov 
AuthorDate: 2021-01-26 07:22:23 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-01-29 21:43:20 +

Fix subinterface vlan creation.

D26436 introduced support for stacked vlans that changed the way vlans
 are configured.  In particular, this change broke setups that have
 same-number vlans as subinterfaces.

Vlan support was initially created assuming "vlanX" semantics. In this 
paradigm,
 automatic number assignment supported by cloning (ifconfig vlan create) 
was a
 natural fit.
When "ifaceX.Y" support was added, allowing to have the same vlan number on
 multiple devices, cloning code became more complex, as the is no
unified "vlan" namespace anymore. Such interfaces got the first spare
index from "vlan" cloner. This, in turn, led to the following problem:
 ifconfig ix0.333 create -> index 1
 ifconfig ix0.444 create -> index 2
 ifconfig vlan2 create -> allocation failure

This change fixes such allocations by using cloning indexes only for
 "vlanX" interfaces.

Reviewed by:hselasky
MFC after:  3 days
Differential Revision:  https://reviews.freebsd.org/D27505
---
 sys/net/if_clone.c |  7 +++--
 sys/net/if_vlan.c  | 75 +-
 2 files changed, 54 insertions(+), 28 deletions(-)

diff --git a/sys/net/if_clone.c b/sys/net/if_clone.c
index a55ce9c3005d..a98e43328e0c 100644
--- a/sys/net/if_clone.c
+++ b/sys/net/if_clone.c
@@ -571,7 +571,7 @@ if_clone_addgroup(struct ifnet *ifp, struct if_clone *ifc)
 
 /*
  * A utility function to extract unit numbers from interface names of
- * the form name###[.###].
+ * the form name###.
  *
  * Returns 0 on success and an error on failure.
  */
@@ -582,9 +582,8 @@ ifc_name2unit(const char *name, int *unit)
int cutoff = INT_MAX / 10;
int cutlim = INT_MAX % 10;
 
-   if ((cp = strrchr(name, '.')) == NULL)
-   cp = name;
-   for (; *cp != '\0' && (*cp < '0' || *cp > '9'); cp++);
+   for (cp = name; *cp != '\0' && (*cp < '0' || *cp > '9'); cp++)
+   ;
if (*cp == '\0') {
*unit = -1;
} else if (cp[0] == '0' && cp[1] != '\0') {
diff --git a/sys/net/if_vlan.c b/sys/net/if_vlan.c
index e1c4160495bc..229cd331c7a1 100644
--- a/sys/net/if_vlan.c
+++ b/sys/net/if_vlan.c
@@ -980,63 +980,86 @@ static int
 vlan_clone_create(struct if_clone *ifc, char *name, size_t len, caddr_t params)
 {
char *dp;
-   int wildcard;
+   bool wildcard = false;
+   bool subinterface = false;
int unit;
int error;
-   int vid;
-   uint16_t proto;
+   int vid = 0;
+   uint16_t proto = ETHERTYPE_VLAN;
struct ifvlan *ifv;
struct ifnet *ifp;
-   struct ifnet *p;
+   struct ifnet *p = NULL;
struct ifaddr *ifa;
struct sockaddr_dl *sdl;
struct vlanreq vlr;
static const u_char eaddr[ETHER_ADDR_LEN];  /* 00:00:00:00:00:00 */
 
-   proto = ETHERTYPE_VLAN;
 
/*
-* There are two ways to specify the cloned device:
+* There are three ways to specify the cloned device:
 * o pass a parameter block with the clone request.
+* o specify parameters in the text of the clone device name
 * o specify no parameters and get an unattached device that
 *   must be configured separately.
-* The first technique is preferred; the latter is supported
+* The first technique is preferred; the latter two are supported
 * for backwards compatibility.
 *
 * XXXRW: Note historic use of the word "tag" here.  New ioctls may be
 * called for.
 */
+
if (params) {
error = copyin(params, &vlr, sizeof(vlr));
if (error)
return error;
+   vid = vlr.vlr_tag;
+   proto = vlr.vlr_proto;
+
p = ifunit_ref(vlr.vlr_parent);
if (p == NULL)
return (ENXIO);
-   error = ifc_name2unit(name, &unit);
-   if (error != 0) {
-   if_rele(p);
-   return (error);
-   }
-   vid = vlr.vlr_tag;
-   proto = vlr.vlr_proto;
-   wildcard = (unit < 0);
-   } else {
-   p = NULL;
-   error = ifc_name2unit(name, &unit);
-   if (error != 0)
-

git: cb984c62d705 - main - Fix multipath support for rib_lookup_info().

2021-01-29 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit cb984c62d705e4229998fdb076d012666a2196da
Author: Alexander V. Chernikov 
AuthorDate: 2021-01-29 23:10:52 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-01-29 23:14:24 +

Fix multipath support for rib_lookup_info().

The initial plan was to remove rib_lookup_info() before
 FreeBSD 13. As several customers are still remaining,
 fix rib_lookup_info() for the multipath use case.
---
 sys/net/route.c | 17 +
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/sys/net/route.c b/sys/net/route.c
index 7e087569d45f..a68e46c37861 100644
--- a/sys/net/route.c
+++ b/sys/net/route.c
@@ -79,8 +79,8 @@ EVENTHANDLER_LIST_DEFINE(rt_addrmsg);
 
 static int rt_ifdelroute(const struct rtentry *rt, const struct nhop_object *,
 void *arg);
-static int rt_exportinfo(struct rtentry *rt, struct rt_addrinfo *info,
-int flags);
+static int rt_exportinfo(struct rtentry *rt, struct nhop_object *nh,
+struct rt_addrinfo *info, int flags);
 
 /*
  * route initialization must occur before ip6_init2(), which happenas at
@@ -330,15 +330,14 @@ ifa_ifwithroute(int flags, const struct sockaddr *dst,
  *
  * Returns 0 on success.
  */
-int
-rt_exportinfo(struct rtentry *rt, struct rt_addrinfo *info, int flags)
+static int
+rt_exportinfo(struct rtentry *rt, struct nhop_object *nh,
+struct rt_addrinfo *info, int flags)
 {
struct rt_metrics *rmx;
struct sockaddr *src, *dst;
-   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);
@@ -424,6 +423,7 @@ rib_lookup_info(uint32_t fibnum, const struct sockaddr 
*dst, uint32_t flags,
struct rib_head *rh;
struct radix_node *rn;
struct rtentry *rt;
+   struct nhop_object *nh;
int error;
 
KASSERT((fibnum < rt_numfibs), ("rib_lookup_rte: bad fibnum"));
@@ -435,10 +435,11 @@ rib_lookup_info(uint32_t fibnum, const struct sockaddr 
*dst, uint32_t flags,
rn = rh->rnh_matchaddr(__DECONST(void *, dst), &rh->head);
if (rn != NULL && ((rn->rn_flags & RNF_ROOT) == 0)) {
rt = RNTORT(rn);
+   nh = nhop_select(rt->rt_nhop, flowid);
/* Ensure route & ifp is UP */
-   if (RT_LINK_IS_UP(rt->rt_nhop->nh_ifp)) {
+   if (RT_LINK_IS_UP(nh->nh_ifp)) {
flags = (flags & NHR_REF) | NHR_COPY;
-   error = rt_exportinfo(rt, info, flags);
+   error = rt_exportinfo(rt, nh, info, flags);
RIB_RUNLOCK(rh);
 
return (error);
___
dev-commits-src-main@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-main
To unsubscribe, send any mail to "dev-commits-src-main-unsubscr...@freebsd.org"


git: 91f2c69ec206 - main - Fix unused-function waring when compiling with FIB_ALGO.

2021-01-30 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit 91f2c69ec206c2993722bfd818af8237fa7e
Author: Alexander V. Chernikov 
AuthorDate: 2021-01-30 23:24:26 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-01-30 23:25:56 +

Fix unused-function waring when compiling with FIB_ALGO.

MFC after:  3 days
---
 sys/netinet6/in6_fib.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/sys/netinet6/in6_fib.c b/sys/netinet6/in6_fib.c
index 3fbddbc28e3d..614f8111409a 100644
--- a/sys/netinet6/in6_fib.c
+++ b/sys/netinet6/in6_fib.c
@@ -218,6 +218,7 @@ check_urpf(struct nhop_object *nh, uint32_t flags,
return (check_urpf_nhop(nh, flags, src_if));
 }
 
+#ifndef FIB_ALGO
 static struct nhop_object *
 lookup_nhop(uint32_t fibnum, const struct in6_addr *dst6,
 uint32_t scopeid)
@@ -251,6 +252,7 @@ lookup_nhop(uint32_t fibnum, const struct in6_addr *dst6,
 
return (nh);
 }
+#endif
 
 /*
  * Performs reverse path forwarding lookup.
___
dev-commits-src-main@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-main
To unsubscribe, send any mail to "dev-commits-src-main-unsubscr...@freebsd.org"


git: ab6d9aaed76e - main - Move business logic from rebuild_fd_callout() into rebuild_fd().

2021-01-30 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit ab6d9aaed76ed9f86fd0d938ebb6ea81f5ad6a82
Author: Alexander V. Chernikov 
AuthorDate: 2021-01-30 22:32:42 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-01-30 23:25:57 +

Move business logic from rebuild_fd_callout() into rebuild_fd().

This simplifies code a bit and allows for future non-callout
 callers to request rebuild.

MFC after:  3 days
---
 sys/net/route/fib_algo.c | 40 +---
 1 file changed, 25 insertions(+), 15 deletions(-)

diff --git a/sys/net/route/fib_algo.c b/sys/net/route/fib_algo.c
index 1f040ad259c5..f7a8b3f82431 100644
--- a/sys/net/route/fib_algo.c
+++ b/sys/net/route/fib_algo.c
@@ -155,6 +155,7 @@ struct fib_data {
TAILQ_ENTRY(fib_data)   entries;/* list of all fds in vnet */
 };
 
+static bool rebuild_fd(struct fib_data *fd);
 static void rebuild_fd_callout(void *_data);
 static void destroy_fd_instance_epoch(epoch_context_t ctx);
 static enum flm_op_result attach_datapath(struct fib_data *fd);
@@ -1011,13 +1012,28 @@ setup_fd_instance(struct fib_lookup_module *flm, struct 
rib_head *rh,
 static void
 rebuild_fd_callout(void *_data)
 {
-   struct fib_data *fd, *fd_new, *fd_tmp;
+   struct fib_data *fd = (struct fib_data *)_data;
+
+   FD_PRINTF(LOG_INFO, fd, "running callout rebuild");
+
+   CURVNET_SET(fd->fd_vnet);
+   rebuild_fd(fd);
+   CURVNET_RESTORE();
+}
+
+/*
+ * Tries to create new algo instance based on @fd data.
+ * Returns true on success.
+ */
+static bool
+rebuild_fd(struct fib_data *fd)
+{
+   struct fib_data *fd_new, *fd_tmp;
struct fib_lookup_module *flm_new = NULL;
struct epoch_tracker et;
enum flm_op_result result;
bool need_rebuild = false;
 
-   fd = (struct fib_data *)_data;
 
FIB_MOD_LOCK();
need_rebuild = fd->fd_need_rebuild;
@@ -1026,15 +1042,12 @@ rebuild_fd_callout(void *_data)
fd->fd_num_changes = 0;
FIB_MOD_UNLOCK();
 
-   CURVNET_SET(fd->fd_vnet);
-
/* First, check if we're still OK to use this algo */
if (!is_algo_fixed(fd->fd_rh))
flm_new = fib_check_best_algo(fd->fd_rh, fd->fd_flm);
if ((flm_new == NULL) && (!need_rebuild)) {
/* Keep existing algo, no need to rebuild. */
-   CURVNET_RESTORE();
-   return;
+   return (true);
}
 
if (flm_new == NULL) {
@@ -1051,19 +1064,16 @@ rebuild_fd_callout(void *_data)
}
if (result != FLM_SUCCESS) {
FD_PRINTF(LOG_NOTICE, fd, "table rebuild failed");
-   CURVNET_RESTORE();
-   return;
+   return (false);
}
FD_PRINTF(LOG_INFO, fd_new, "switched to new instance");
 
-   /* Remove old instance removal */
-   if (fd != NULL) {
-   NET_EPOCH_ENTER(et);
-   schedule_destroy_fd_instance(fd, true);
-   NET_EPOCH_EXIT(et);
-   }
+   /* Remove old instance */
+   NET_EPOCH_ENTER(et);
+   schedule_destroy_fd_instance(fd, true);
+   NET_EPOCH_EXIT(et);
 
-   CURVNET_RESTORE();
+   return (true);
 }
 
 /*
___
dev-commits-src-main@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-main
To unsubscribe, send any mail to "dev-commits-src-main-unsubscr...@freebsd.org"


git: dd9163003cb1 - main - Add rib_subscribe_locked() and rib_unsubsribe_locked() to support subscriptions during RIB modifications. Add new subscriptions to the beginning of the lists instead of the

2021-01-30 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit dd9163003cb1be494609d904521e8dae7737caa7
Author: Alexander V. Chernikov 
AuthorDate: 2021-01-30 21:52:44 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-01-30 23:25:57 +

Add rib_subscribe_locked() and rib_unsubsribe_locked() to support
 subscriptions during RIB modifications.
Add new subscriptions to the beginning of the lists instead of
 the end. This fixes the situation when new subscription is created
 int the callback for the existing subscription, leading to the
 subscription notification handler pick it.

MFC after: 3 days
---
 sys/net/route/route_ctl.c | 34 +-
 sys/net/route/route_ctl.h |  3 +++
 2 files changed, 36 insertions(+), 1 deletion(-)

diff --git a/sys/net/route/route_ctl.c b/sys/net/route/route_ctl.c
index 230d23845c64..c46d0430a164 100644
--- a/sys/net/route/route_ctl.c
+++ b/sys/net/route/route_ctl.c
@@ -1407,13 +1407,31 @@ rib_subscribe_internal(struct rib_head *rnh, 
rib_subscription_cb_t *f, void *arg
 
NET_EPOCH_ENTER(et);
RIB_WLOCK(rnh);
-   CK_STAILQ_INSERT_TAIL(&rnh->rnh_subscribers, rs, next);
+   CK_STAILQ_INSERT_HEAD(&rnh->rnh_subscribers, rs, next);
RIB_WUNLOCK(rnh);
NET_EPOCH_EXIT(et);
 
return (rs);
 }
 
+struct rib_subscription *
+rib_subscribe_locked(struct rib_head *rnh, rib_subscription_cb_t *f, void *arg,
+enum rib_subscription_type type)
+{
+   struct rib_subscription *rs;
+
+   NET_EPOCH_ASSERT();
+   RIB_WLOCK_ASSERT(rnh);
+
+   if ((rs = allocate_subscription(f, arg, type, false)) == NULL)
+   return (NULL);
+   rs->rnh = rnh;
+
+   CK_STAILQ_INSERT_HEAD(&rnh->rnh_subscribers, rs, next);
+
+   return (rs);
+}
+
 /*
  * Remove rtable subscription @rs from the routing table.
  * Needs to be run in network epoch.
@@ -1433,6 +1451,20 @@ rib_unsibscribe(struct rib_subscription *rs)
&rs->epoch_ctx);
 }
 
+void
+rib_unsibscribe_locked(struct rib_subscription *rs)
+{
+   struct rib_head *rnh = rs->rnh;
+
+   NET_EPOCH_ASSERT();
+   RIB_WLOCK_ASSERT(rnh);
+
+   CK_STAILQ_REMOVE(&rnh->rnh_subscribers, rs, rib_subscription, next);
+
+   epoch_call(net_epoch_preempt, destroy_subscription_epoch,
+   &rs->epoch_ctx);
+}
+
 /*
  * Epoch callback indicating subscription is safe to destroy
  */
diff --git a/sys/net/route/route_ctl.h b/sys/net/route/route_ctl.h
index ecbc9ee91dc0..bd256e9f0834 100644
--- a/sys/net/route/route_ctl.h
+++ b/sys/net/route/route_ctl.h
@@ -144,6 +144,9 @@ struct rib_subscription *rib_subscribe(uint32_t fibnum, int 
family,
 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 *rib_subscribe_locked(struct rib_head *rnh,
+rib_subscription_cb_t *f, void *arg, enum rib_subscription_type type);
 void rib_unsibscribe(struct rib_subscription *rs);
+void rib_unsibscribe_locked(struct rib_subscription *rs);
 
 #endif
___
dev-commits-src-main@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-main
To unsubscribe, send any mail to "dev-commits-src-main-unsubscr...@freebsd.org"


git: f8b7ebea4905 - main - Improve fib_algo debug messages.

2021-01-30 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit f8b7ebea4905d84032f3195f86f6c27842e7a286
Author: Alexander V. Chernikov 
AuthorDate: 2021-01-30 22:06:40 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-01-30 23:25:56 +

Improve fib_algo debug messages.

* Move per-prefix debug lines under LOG_DEBUG2
* Create fib instance counter to distingush log messages between
 instances
* Add more messages on rebuild reason.

MFC after:  3 days
---
 sys/net/route/fib_algo.c | 62 ++--
 1 file changed, 44 insertions(+), 18 deletions(-)

diff --git a/sys/net/route/fib_algo.c b/sys/net/route/fib_algo.c
index b84217034e16..1f040ad259c5 100644
--- a/sys/net/route/fib_algo.c
+++ b/sys/net/route/fib_algo.c
@@ -118,6 +118,9 @@ SYSCTL_NODE(_net_route_algo, OID_AUTO, inet, CTLFLAG_RW | 
CTLFLAG_MPSAFE, 0,
 "IPv4 longest prefix match lookups");
 #endif
 
+/* Fib instance counter */
+static uint32_t fib_gen = 0;
+
 struct nhop_ref_table {
uint32_tcount;
int32_t refcnt[0];
@@ -137,7 +140,7 @@ struct fib_data {
uint8_t fd_family;  /* family */
uint32_tfd_fibnum;  /* fibnum */
uint32_tfd_failed_rebuilds; /* stat: failed 
rebuilds */
-   uint32_tfd_algo_mask;   /* bitmask for algo data */
+   uint32_tfd_gen; /* instance gen# */
struct callout  fd_callout; /* rebuild callout */
void*fd_algo_data;  /* algorithm data */
struct nhop_object  **nh_idx;   /* nhop idx->ptr array */
@@ -191,12 +194,15 @@ static int flm_debug_level = LOG_NOTICE;
 SYSCTL_INT(_net_route_algo, OID_AUTO, debug_level, CTLFLAG_RW | CTLFLAG_RWTUN,
 &flm_debug_level, 0, "debuglevel");
 #defineFLM_MAX_DEBUG_LEVEL LOG_DEBUG
+#ifndefLOG_DEBUG2
+#defineLOG_DEBUG2  8
+#endif
 
 #define_PASS_MSG(_l)   (flm_debug_level >= (_l))
 #defineALGO_PRINTF(_fmt, ...)  printf("[fib_algo] %s: " _fmt "\n", 
__func__, ##__VA_ARGS__)
-#define_ALGO_PRINTF(_fib, _fam, _aname, _func, _fmt, ...) \
-printf("[fib_algo] %s.%u (%s) %s: " _fmt "\n",\
-print_family(_fam), _fib, _aname, _func, ## __VA_ARGS__)
+#define_ALGO_PRINTF(_fib, _fam, _aname, _gen, _func, _fmt, ...) \
+printf("[fib_algo] %s.%u (%s#%u) %s: " _fmt "\n",\
+print_family(_fam), _fib, _aname, _gen, _func, ## __VA_ARGS__)
 #define_RH_PRINTF(_fib, _fam, _func, _fmt, ...) \
 printf("[fib_algo] %s.%u %s: " _fmt "\n", print_family(_fam), _fib, _func, 
## __VA_ARGS__)
 #defineRH_PRINTF(_l, _rh, _fmt, ...)   if (_PASS_MSG(_l)) {\
@@ -205,8 +211,13 @@ SYSCTL_INT(_net_route_algo, OID_AUTO, debug_level, 
CTLFLAG_RW | CTLFLAG_RWTUN,
 #defineFD_PRINTF(_l, _fd, _fmt, ...)   FD_PRINTF_##_l(_l, _fd, _fmt, 
## __VA_ARGS__)
 #define_FD_PRINTF(_l, _fd, _fmt, ...)  if (_PASS_MSG(_l)) {
\
 _ALGO_PRINTF(_fd->fd_fibnum, _fd->fd_family, _fd->fd_flm->flm_name,
\
-__func__, _fmt, ## __VA_ARGS__);   \
+_fd->fd_gen, __func__, _fmt, ## __VA_ARGS__);  \
 }
+#if FLM_MAX_DEBUG_LEVEL>=LOG_DEBUG2
+#defineFD_PRINTF_LOG_DEBUG2_FD_PRINTF
+#else
+#defineFD_PRINTF_LOG_DEBUG2(_l, _fd, _fmt, ...)
+#endif
 #if FLM_MAX_DEBUG_LEVEL>=LOG_DEBUG
 #defineFD_PRINTF_LOG_DEBUG _FD_PRINTF
 #else
@@ -371,7 +382,7 @@ fib_printf(int level, struct fib_data *fd, const char 
*func, char *fmt, ...)
va_end(ap);
 
_ALGO_PRINTF(fd->fd_fibnum, fd->fd_family, fd->fd_flm->flm_name,
-   func, "%s", buf);
+   fd->fd_gen, func, "%s", buf);
 }
 
 /*
@@ -450,7 +461,7 @@ schedule_callout(struct fib_data *fd, int delay_ms)
 }
 
 static void
-schedule_fd_rebuild(struct fib_data *fd)
+schedule_fd_rebuild(struct fib_data *fd, const char *reason)
 {
 
FIB_MOD_LOCK();
@@ -461,7 +472,8 @@ schedule_fd_rebuild(struct fib_data *fd)
 * Potentially re-schedules pending callout
 *  initiated by schedule_algo_eval.
 */
-   FD_PRINTF(LOG_INFO, fd, "Scheduling rebuilt");
+   FD_PRINTF(LOG_INFO, fd, "Scheduling rebuild: %s (failures=%d)",
+   reason, fd->fd_failed_rebuilds);
schedule_callout(fd, callout_calc_delay_ms(fd));
}
FIB_MOD_UNLOCK();
@@ -527,7 +539,7 @@ handle_rtable_change_cb(struct rib_head *rnh, struct 
rib_cmd_info *rc,
if (rc->rc_nh_new != NULL) {
if (fib_ref_nh

git: 151ec796a230 - main - Fix the design problem with delayed algorithm sync.

2021-01-30 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit 151ec796a23098279531eaebbf30d08a0877ee4e
Author: Alexander V. Chernikov 
AuthorDate: 2021-01-30 22:45:46 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-01-30 23:25:57 +

Fix the design problem with delayed algorithm sync.

Currently, if the immutable algorithm like bsearch or radix_lockless
 receives rtable update notification, it schedules algorithm rebuild.
This rebuild is executed by the callout after ~50 milliseconds.

It is possible that a script adding an interface address and than route
 with the gateway bound to that address will fail. It can happen due
 to the fact that fib is not updated by the time the route addition
 request arrives.

Fix this by allowing synchronous algorithm rebuilds based on certain
 conditions. By default, these conditions assume:
1) less than net.route.algo.fib_sync_limit=100 routes
2) routes without gateway.

* Move algo instance build entirely under rib WLOCK.
 Rib lock is only used for control plane (except radix algo, but there
  are no rebuilds).
* Add rib_walk_ext_locked() function to allow RIB iteration with
 rib lock already held.
* Fix rare potential callout use-after-free for fds by binding fd
 callout to the relevant rib rmlock. In that case, callout_stop()
 under rib WLOCK guarantees no callout will be executed afterwards.

MFC after:  3 days
---
 sys/net/route/fib_algo.c  | 110 --
 sys/net/route/route_ctl.h |   2 +
 sys/net/route/route_helpers.c |  17 +--
 3 files changed, 87 insertions(+), 42 deletions(-)

diff --git a/sys/net/route/fib_algo.c b/sys/net/route/fib_algo.c
index f7a8b3f82431..21b6ba924069 100644
--- a/sys/net/route/fib_algo.c
+++ b/sys/net/route/fib_algo.c
@@ -105,6 +105,11 @@ SYSCTL_DECL(_net_route);
 SYSCTL_NODE(_net_route, OID_AUTO, algo, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
 "Fib algorithm lookups");
 
+VNET_DEFINE(int, fib_sync_limit) = 100;
+#defineV_fib_sync_limitVNET(fib_sync_limit)
+SYSCTL_INT(_net_route_algo, OID_AUTO, fib_sync_limit, CTLFLAG_RW | 
CTLFLAG_VNET,
+&VNET_NAME(fib_sync_limit), 0, "Guarantee synchronous fib till route 
limit");
+
 #ifdef INET6
 VNET_DEFINE_STATIC(bool, algo_fixed_inet6) = false;
 #defineV_algo_fixed_inet6  VNET(algo_fixed_inet6)
@@ -465,7 +470,8 @@ static void
 schedule_fd_rebuild(struct fib_data *fd, const char *reason)
 {
 
-   FIB_MOD_LOCK();
+   RIB_WLOCK_ASSERT(fd->fd_rh);
+
if (!fd->fd_need_rebuild) {
fd->fd_need_rebuild = true;
 
@@ -477,30 +483,52 @@ schedule_fd_rebuild(struct fib_data *fd, const char 
*reason)
reason, fd->fd_failed_rebuilds);
schedule_callout(fd, callout_calc_delay_ms(fd));
}
-   FIB_MOD_UNLOCK();
 }
 
 static void
 schedule_algo_eval(struct fib_data *fd)
 {
 
+   RIB_WLOCK_ASSERT(fd->fd_rh);
+
if (fd->fd_num_changes++ == 0) {
/* Start callout to consider switch */
-   FIB_MOD_LOCK();
if (!callout_pending(&fd->fd_callout))
schedule_callout(fd, ALGO_EVAL_DELAY_MS);
-   FIB_MOD_UNLOCK();
} else if (fd->fd_num_changes > ALGO_EVAL_NUM_ROUTES && 
!fd->fd_force_eval) {
/* Reset callout to exec immediately */
-   FIB_MOD_LOCK();
if (!fd->fd_need_rebuild) {
fd->fd_force_eval = true;
schedule_callout(fd, 1);
}
-   FIB_MOD_UNLOCK();
}
 }
 
+static bool
+need_immediate_rebuild(struct fib_data *fd, struct rib_cmd_info *rc)
+{
+   struct nhop_object *nh;
+
+   if ((V_fib_sync_limit == 0) || (fd->fd_rh->rnh_prefixes <= 
V_fib_sync_limit))
+   return (true);
+
+   /* Sync addition/removal of interface routes */
+   switch (rc->rc_cmd) {
+   case RTM_ADD:
+   nh = rc->rc_nh_new;
+   if (!NH_IS_NHGRP(nh) && (!(nh->nh_flags & NHF_GATEWAY)))
+   return (true);
+   break;
+   case RTM_DELETE:
+   nh = rc->rc_nh_old;
+   if (!NH_IS_NHGRP(nh) && (!(nh->nh_flags & NHF_GATEWAY)))
+   return (true);
+   break;
+   }
+
+   return (false);
+}
+
 /*
  * Rib subscription handler. Checks if the algorithm is ready to
  *  receive updates, handles nexthop refcounting and passes change
@@ -559,7 +587,15 @@ handle_rtable_change_cb(struct rib_head *rnh, struct 
rib_cmd_info *rc,
 * Algo is not able to apply the update.
 * Schedule algo rebuild.
 

git: 78c93a172114 - main - Use process fib for inet/inet6 fib_algo sysctls.

2021-01-31 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit 78c93a1721143db656e277f7827ec4d57826044c
Author: Alexander V. Chernikov 
AuthorDate: 2021-01-31 10:48:47 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-01-31 10:50:08 +

Use process fib for inet/inet6 fib_algo sysctls.

This allows to set/query fib algo for non-default fibs.

MFC after:  3 days
---
 sys/net/route/fib_algo.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/sys/net/route/fib_algo.c b/sys/net/route/fib_algo.c
index 21b6ba924069..b2aa2de087de 100644
--- a/sys/net/route/fib_algo.c
+++ b/sys/net/route/fib_algo.c
@@ -1202,7 +1202,7 @@ static int
 set_algo_inet_sysctl_handler(SYSCTL_HANDLER_ARGS)
 {
 
-   return (set_fib_algo(RT_DEFAULT_FIB, AF_INET, oidp, req));
+   return (set_fib_algo(curthread->td_proc->p_fibnum, AF_INET, oidp, req));
 }
 SYSCTL_PROC(_net_route_algo_inet, OID_AUTO, algo,
 CTLFLAG_VNET | CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_MPSAFE, NULL, 0,
@@ -1214,7 +1214,7 @@ static int
 set_algo_inet6_sysctl_handler(SYSCTL_HANDLER_ARGS)
 {
 
-   return (set_fib_algo(RT_DEFAULT_FIB, AF_INET6, oidp, req));
+   return (set_fib_algo(curthread->td_proc->p_fibnum, AF_INET6, oidp, 
req));
 }
 SYSCTL_PROC(_net_route_algo_inet6, OID_AUTO, algo,
 CTLFLAG_VNET | CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_MPSAFE, NULL, 0,
___
dev-commits-src-main@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-main
To unsubscribe, send any mail to "dev-commits-src-main-unsubscr...@freebsd.org"


git: eb0b1b33d5af - main - Enable multipath routing by default.

2021-02-03 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit eb0b1b33d5af4e81ee77732dffc77634e57a5879
Author: Alexander V. Chernikov 
AuthorDate: 2021-02-03 08:49:46 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-02-03 08:49:58 +

Enable multipath routing by default.

ROUTE_MPATH was added to the GENERIC kernel in r368648.

According to the plan in D27428, it was enabled with `net.route.multipath` 
sysctl set to 0.
Given enough time has passed, this change enables route multipath by 
default.

The goal is to ship FreeBSD 13 with multipath turned on.

Reviewed By: donner, olivier
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D28423
---
 sys/net/route/route_ctl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sys/net/route/route_ctl.c b/sys/net/route/route_ctl.c
index c46d0430a164..6b0869196d12 100644
--- a/sys/net/route/route_ctl.c
+++ b/sys/net/route/route_ctl.c
@@ -101,7 +101,7 @@ SYSCTL_DECL(_net_route);
 #else
 #define _MP_FLAGS  CTLFLAG_RD
 #endif
-VNET_DEFINE(u_int, rib_route_multipath) = 0;
+VNET_DEFINE(u_int, rib_route_multipath) = 1;
 SYSCTL_UINT(_net_route, OID_AUTO, multipath, _MP_FLAGS | CTLFLAG_VNET,
 &VNET_NAME(rib_route_multipath), 0, "Enable route multipath");
 #undef _MP_FLAGS
___
dev-commits-src-main@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-main
To unsubscribe, send any mail to "dev-commits-src-main-unsubscr...@freebsd.org"


git: 4a01b854ca5c - main - SO_RERROR indicates that receive buffer overflows should be handled as errors. Historically receive buffer overflows have been ignored and programs could not tell if they mi

2021-02-08 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit 4a01b854ca5c2e5124958363b3326708b913af71
Author: Alexander V. Chernikov 
AuthorDate: 2021-02-07 17:21:18 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-02-08 21:42:20 +

SO_RERROR indicates that receive buffer overflows should be handled as 
errors.
Historically receive buffer overflows have been ignored and programs
could not tell if they missed messages or messages had been truncated
because of overflows. Since programs historically do not expect to get
receive overflow errors, this behavior is not the default.

This is really really important for programs that use route(4) to keep in 
sync
with the system. If we loose a message then we need to reload the full 
system
state, otherwise the behaviour from that point is undefined and can lead
to chasing bogus bug reports.
---
 lib/libc/sys/getsockopt.2  | 10 +++-
 sbin/route/route.c | 13 +-
 sys/kern/uipc_sockbuf.c| 24 +
 sys/kern/uipc_socket.c | 30 --
 sys/kern/uipc_usrreq.c |  2 +-
 sys/net/raw_usrreq.c   | 11 
 .../bluetooth/socket/ng_btsocket_hci_raw.c |  1 +
 sys/netgraph/ng_socket.c   |  2 +-
 sys/netinet/ip_divert.c|  2 +-
 sys/netinet/ip_mroute.c|  2 +-
 sys/netinet/raw_ip.c   |  3 +--
 sys/netinet/udp_usrreq.c   |  2 +-
 sys/netinet6/icmp6.c   |  6 ++---
 sys/netinet6/ip6_input.c   |  1 +
 sys/netinet6/ip6_mroute.c  |  3 ++-
 sys/netinet6/raw_ip6.c |  2 ++
 sys/netinet6/send.c|  2 +-
 sys/netinet6/udp6_usrreq.c |  2 +-
 sys/netipsec/keysock.c | 10 
 sys/sys/socket.h   |  1 +
 sys/sys/socketvar.h|  6 -
 21 files changed, 100 insertions(+), 35 deletions(-)

diff --git a/lib/libc/sys/getsockopt.2 b/lib/libc/sys/getsockopt.2
index 1e4ed6827170..223eb3e8a28b 100644
--- a/lib/libc/sys/getsockopt.2
+++ b/lib/libc/sys/getsockopt.2
@@ -28,7 +28,7 @@
 .\" @(#)getsockopt.2   8.4 (Berkeley) 5/2/95
 .\" $FreeBSD$
 .\"
-.Dd June 3, 2020
+.Dd Feb 07, 2020
 .Dt GETSOCKOPT 2
 .Os
 .Sh NAME
@@ -177,6 +177,7 @@ for the socket
 .It Dv SO_PROTOCOL Ta "get the protocol number for the socket (get only)"
 .It Dv SO_PROTOTYPE Ta "SunOS alias for the Linux SO_PROTOCOL (get only)"
 .It Dv SO_ERROR Ta "get and clear error on the socket (get only)"
+.It Dv SO_RERROR Ta "enables receive error reporting"
 .It Dv SO_SETFIB Ta "set the associated FIB (routing table) for the socket 
(set only)"
 .El
 .Pp
@@ -514,6 +515,13 @@ returns any pending error on the socket and clears
 the error status.
 It may be used to check for asynchronous errors on connected
 datagram sockets or for other asynchronous errors.
+.Dv SO_RERROR
+indicates that receive buffer overflows should be handled as errors.
+Historically receive buffer overflows have been ignored and programs
+could not tell if they missed messages or messages had been truncated
+because of overflows.
+Since programs historically do not expect to get receive overflow errors,
+this behavior is not the default.
 .Pp
 .Dv SO_LABEL
 returns the MAC label of the socket.
diff --git a/sbin/route/route.c b/sbin/route/route.c
index 51a0c68746a6..b16fb6d17a08 100644
--- a/sbin/route/route.c
+++ b/sbin/route/route.c
@@ -1444,9 +1444,20 @@ monitor(int argc, char *argv[])
interfaces();
exit(0);
}
+
+#ifdef SO_RERROR
+   n = 1;
+   if (setsockopt(s, SOL_SOCKET, SO_RERROR, &n, sizeof(n)) == -1)
+   warn("SO_RERROR");
+#endif
+
for (;;) {
time_t now;
-   n = read(s, msg, 2048);
+   n = read(s, msg, sizeof(msg));
+   if (n == -1) {
+   warn("read");
+   continue;
+   }
now = time(NULL);
(void)printf("\ngot message of size %d on %s", n, ctime(&now));
print_rtmsg((struct rt_msghdr *)(void *)msg, n);
diff --git a/sys/kern/uipc_sockbuf.c b/sys/kern/uipc_sockbuf.c
index cf53f234d8fc..b5ecdb99b59b 100644
--- a/sys/kern/uipc_sockbuf.c
+++ b/sys/kern/uipc_sockbuf.c
@@ -436,6 +436,30 @@ socantrcvmore(struct socket *so)
mtx_assert(SOCKBUF_MTX(&so->so_rcv), MA_NOTOWNED);
 }
 
+void
+soroverflow_loc

git: adc4ea97bd77 - main - Turn off forgotten multipath debug messages

2021-02-08 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit adc4ea97bd775cb49df5dbfd71dd497c834ae150
Author: Alexander V. Chernikov 
AuthorDate: 2021-02-08 20:11:38 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-02-08 21:42:20 +

Turn off forgotten multipath debug messages

Reported by:mike tancsa
MFC after:  3 days
---
 sys/net/route/nhgrp_ctl.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/sys/net/route/nhgrp_ctl.c b/sys/net/route/nhgrp_ctl.c
index c4f86500ca8d..c2119506370f 100644
--- a/sys/net/route/nhgrp_ctl.c
+++ b/sys/net/route/nhgrp_ctl.c
@@ -26,7 +26,6 @@
  *
  * $FreeBSD$
  */
-#define RTDEBUG
 #include "opt_inet.h"
 #include "opt_route.h"
 
___
dev-commits-src-main@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-main
To unsubscribe, send any mail to "dev-commits-src-main-unsubscr...@freebsd.org"


git: 924d1c9a050d - main - Revert "SO_RERROR indicates that receive buffer overflows should be handled as errors." Wrong version of the change was pushed inadvertenly.

2021-02-08 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit 924d1c9a050d7e355d0562fca62bd2bb9b5f53d7
Author: Alexander V. Chernikov 
AuthorDate: 2021-02-08 22:30:39 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-02-08 22:32:32 +

Revert "SO_RERROR indicates that receive buffer overflows should be handled 
as errors."
Wrong version of the change was pushed inadvertenly.

This reverts commit 4a01b854ca5c2e5124958363b3326708b913af71.
---
 lib/libc/sys/getsockopt.2  | 10 +---
 sbin/route/route.c | 13 +-
 sys/kern/uipc_sockbuf.c| 24 -
 sys/kern/uipc_socket.c | 30 ++
 sys/kern/uipc_usrreq.c |  2 +-
 sys/net/raw_usrreq.c   | 11 
 .../bluetooth/socket/ng_btsocket_hci_raw.c |  1 -
 sys/netgraph/ng_socket.c   |  2 +-
 sys/netinet/ip_divert.c|  2 +-
 sys/netinet/ip_mroute.c|  2 +-
 sys/netinet/raw_ip.c   |  3 ++-
 sys/netinet/udp_usrreq.c   |  2 +-
 sys/netinet6/icmp6.c   |  6 +++--
 sys/netinet6/ip6_input.c   |  1 -
 sys/netinet6/ip6_mroute.c  |  3 +--
 sys/netinet6/raw_ip6.c |  2 --
 sys/netinet6/send.c|  2 +-
 sys/netinet6/udp6_usrreq.c |  2 +-
 sys/netipsec/keysock.c | 10 
 sys/sys/socket.h   |  1 -
 sys/sys/socketvar.h|  6 +
 21 files changed, 35 insertions(+), 100 deletions(-)

diff --git a/lib/libc/sys/getsockopt.2 b/lib/libc/sys/getsockopt.2
index 223eb3e8a28b..1e4ed6827170 100644
--- a/lib/libc/sys/getsockopt.2
+++ b/lib/libc/sys/getsockopt.2
@@ -28,7 +28,7 @@
 .\" @(#)getsockopt.2   8.4 (Berkeley) 5/2/95
 .\" $FreeBSD$
 .\"
-.Dd Feb 07, 2020
+.Dd June 3, 2020
 .Dt GETSOCKOPT 2
 .Os
 .Sh NAME
@@ -177,7 +177,6 @@ for the socket
 .It Dv SO_PROTOCOL Ta "get the protocol number for the socket (get only)"
 .It Dv SO_PROTOTYPE Ta "SunOS alias for the Linux SO_PROTOCOL (get only)"
 .It Dv SO_ERROR Ta "get and clear error on the socket (get only)"
-.It Dv SO_RERROR Ta "enables receive error reporting"
 .It Dv SO_SETFIB Ta "set the associated FIB (routing table) for the socket 
(set only)"
 .El
 .Pp
@@ -515,13 +514,6 @@ returns any pending error on the socket and clears
 the error status.
 It may be used to check for asynchronous errors on connected
 datagram sockets or for other asynchronous errors.
-.Dv SO_RERROR
-indicates that receive buffer overflows should be handled as errors.
-Historically receive buffer overflows have been ignored and programs
-could not tell if they missed messages or messages had been truncated
-because of overflows.
-Since programs historically do not expect to get receive overflow errors,
-this behavior is not the default.
 .Pp
 .Dv SO_LABEL
 returns the MAC label of the socket.
diff --git a/sbin/route/route.c b/sbin/route/route.c
index b16fb6d17a08..51a0c68746a6 100644
--- a/sbin/route/route.c
+++ b/sbin/route/route.c
@@ -1444,20 +1444,9 @@ monitor(int argc, char *argv[])
interfaces();
exit(0);
}
-
-#ifdef SO_RERROR
-   n = 1;
-   if (setsockopt(s, SOL_SOCKET, SO_RERROR, &n, sizeof(n)) == -1)
-   warn("SO_RERROR");
-#endif
-
for (;;) {
time_t now;
-   n = read(s, msg, sizeof(msg));
-   if (n == -1) {
-   warn("read");
-   continue;
-   }
+   n = read(s, msg, 2048);
now = time(NULL);
(void)printf("\ngot message of size %d on %s", n, ctime(&now));
print_rtmsg((struct rt_msghdr *)(void *)msg, n);
diff --git a/sys/kern/uipc_sockbuf.c b/sys/kern/uipc_sockbuf.c
index b5ecdb99b59b..cf53f234d8fc 100644
--- a/sys/kern/uipc_sockbuf.c
+++ b/sys/kern/uipc_sockbuf.c
@@ -436,30 +436,6 @@ socantrcvmore(struct socket *so)
mtx_assert(SOCKBUF_MTX(&so->so_rcv), MA_NOTOWNED);
 }
 
-void
-soroverflow_locked(struct socket *so)
-{
-
-   SOCKBUF_LOCK_ASSERT(&so->so_rcv);
-
-   if (so->so_options & SO_RERROR) {
-   so->so_rerror = ENOBUFS;
-   sorwakeup_locked(so);
-   } else
-   SOCKBUF_UNLOCK(&so->so_rcv);
-
-   mtx_assert(SOCKBUF_MTX(&so->so_rcv), MA_NOTOWNED);
-}
-
-void
-soroverflow(struct socket *so)
-{
-
-   SOCKBUF_LOCK(&so->s

git: 145bf6c0af48 - main - Fix blackhole/reject routes.

2021-02-11 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit 145bf6c0af48b89f13465e145f4516de37c31d85
Author: Alexander V. Chernikov 
AuthorDate: 2021-02-08 23:29:05 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-02-11 23:08:55 +

Fix blackhole/reject routes.

Traditionally *BSD routing stack required to supply some
 interface data for blackhole/reject routes. This lead to
 varieties of hacks in routing daemons when inserting such routes.
With the recent routeing stack changes, gateway sockaddr without
 RTF_GATEWAY started to be treated differently, purely as link
 identifier.

This change broke net/bird, which installs blackhole routes with
 127.0.0.1 gateway without RTF_GATEWAY flags.

Fix this by automatically constructing necessary gateway data at
 rtsock level if RTF_REJECT/RTF_BLACKHOLE is set.

Reported by:Marek Zarychta 
Reviewed by:donner
MFC after:  1 week
---
 sys/net/rtsock.c | 58 ++--
 1 file changed, 56 insertions(+), 2 deletions(-)

diff --git a/sys/net/rtsock.c b/sys/net/rtsock.c
index ba1182d55439..f67252f9fd5f 100644
--- a/sys/net/rtsock.c
+++ b/sys/net/rtsock.c
@@ -562,6 +562,50 @@ rtm_get_jailed(struct rt_addrinfo *info, struct ifnet *ifp,
return (0);
 }
 
+static int
+fill_blackholeinfo(struct rt_addrinfo *info, union sockaddr_union *saun)
+{
+   struct ifaddr *ifa;
+   sa_family_t saf;
+
+   if (V_loif == NULL) {
+   printf("Unable to add blackhole/reject nhop without loopback");
+   return (ENOTSUP);
+   }
+   info->rti_ifp = V_loif;
+
+   saf = info->rti_info[RTAX_DST]->sa_family;
+
+   CK_STAILQ_FOREACH(ifa, &info->rti_ifp->if_addrhead, ifa_link) {
+   if (ifa->ifa_addr->sa_family == saf) {
+   info->rti_ifa = ifa;
+   break;
+   }
+   }
+   if (info->rti_ifa == NULL)
+   return (ENOTSUP);
+
+   bzero(saun, sizeof(union sockaddr_union));
+   switch (saf) {
+   case AF_INET:
+   saun->sin.sin_family = AF_INET;
+   saun->sin.sin_len = sizeof(struct sockaddr_in);
+   saun->sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
+   break;
+   case AF_INET6:
+   saun->sin6.sin6_family = AF_INET6;
+   saun->sin6.sin6_len = sizeof(struct sockaddr_in6);
+   saun->sin6.sin6_addr = in6addr_loopback;
+   break;
+   default:
+   return (ENOTSUP);
+   }
+   info->rti_info[RTAX_GATEWAY] = &saun->sa;
+   info->rti_flags |= RTF_GATEWAY;
+
+   return (0);
+}
+
 /*
  * Fills in @info based on userland-provided @rtm message.
  *
@@ -944,7 +988,6 @@ route_output(struct mbuf *m, struct socket *so, ...)
 #endif
int alloc_len = 0, len, error = 0, fibnum;
sa_family_t saf = AF_UNSPEC;
-   struct walkarg w;
struct rib_cmd_info rc;
struct nhop_object *nh;
 
@@ -972,7 +1015,6 @@ route_output(struct mbuf *m, struct socket *so, ...)
 
m_copydata(m, 0, len, (caddr_t)rtm);
bzero(&info, sizeof(info));
-   bzero(&w, sizeof(w));
nh = NULL;
 
if (rtm->rtm_version != RTM_VERSION) {
@@ -1004,6 +1046,18 @@ route_output(struct mbuf *m, struct socket *so, ...)
goto flush;
}
 
+   union sockaddr_union gw_saun;
+   int blackhole_flags = rtm->rtm_flags & (RTF_BLACKHOLE|RTF_REJECT);
+   if (blackhole_flags != 0) {
+   if (blackhole_flags != (RTF_BLACKHOLE | RTF_REJECT))
+   error = fill_blackholeinfo(&info, &gw_saun);
+   else
+   error = EINVAL;
+   if (error != 0)
+   senderr(error);
+   /* TODO: rebuild rtm from scratch */
+   }
+
switch (rtm->rtm_type) {
case RTM_ADD:
case RTM_CHANGE:
___
dev-commits-src-main@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-main
To unsubscribe, send any mail to "dev-commits-src-main-unsubscr...@freebsd.org"


git: 8170a7d43835 - main - Fix interface route addition with net/bird.

2021-02-12 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit 8170a7d43835047f9c1548a081eea45116473995
Author: Alexander V. Chernikov 
AuthorDate: 2021-02-11 23:24:27 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-02-12 19:45:35 +

Fix interface route addition with net/bird.

The case of adding interface route by specifying interface
 address as the gateway was missed during code refactoring.
Re-add it back by copying non-AF_LINK gateway data when RTF_GATEWAY
 is not set.

Reviewed by:donner
MFC after:  3 days
---
 sys/net/route/nhop_ctl.c | 50 +---
 1 file changed, 26 insertions(+), 24 deletions(-)

diff --git a/sys/net/route/nhop_ctl.c b/sys/net/route/nhop_ctl.c
index 542380afd64b..7de553799fab 100644
--- a/sys/net/route/nhop_ctl.c
+++ b/sys/net/route/nhop_ctl.c
@@ -219,42 +219,44 @@ set_nhop_gw_from_info(struct nhop_object *nh, struct 
rt_addrinfo *info)
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",
-   gw->sa_family, gw->sa_len);
-   return (ENOMEM);
-   }
-   memcpy(&nh->gw_sa, gw, gw->sa_len);
-   } else {
+   if ((gw->sa_family == AF_LINK) && !(info->rti_flags & RTF_GATEWAY)) {
 
/*
-* Interface route. Currently the route.c code adds
-* sa of type AF_LINK, which is 56 bytes long. The only
-* meaningful data there is the interface index. It is used
-* used is the IPv6 loopback output, where we need to preserve
-* the original interface to maintain proper scoping.
+* Interface route with interface specified by the interface
+* index in sockadd_dl structure. It is used in the IPv6 
loopback
+* output code, where we need to preserve the original interface
+* to maintain proper scoping.
 * Despite the fact that nexthop code stores original interface
 * in the separate field (nh_aifp, see below), write AF_LINK
 * compatible sa with shorter total length.
 */
-   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);
+   struct sockaddr_dl *sdl = (struct sockaddr_dl *)gw;
+   struct ifnet *ifp = ifnet_byindex(sdl->sdl_index);
if (ifp == NULL) {
DPRINTF("invalid ifindex %d", sdl->sdl_index);
return (EINVAL);
}
fill_sdl_from_ifp(&nh->gwl_sa, ifp);
-   }
+   } else {
 
+   /*
+* Multiple options here:
+*
+* 1) RTF_GATEWAY with IPv4/IPv6 gateway data
+* 2) Interface route with IPv4/IPv6 address of the
+*   matching interface. Some routing daemons do that
+*   instead of specifying ifindex in AF_LINK.
+*
+* In both cases, save the original nexthop to make the callers
+*   happy.
+*/
+   if (gw->sa_len > sizeof(struct sockaddr_in6)) {
+   DPRINTF("nhop SA size too big: AF %d len %u",
+   gw->sa_family, gw->sa_len);
+   return (ENOMEM);
+   }
+   memcpy(&nh->gw_sa, gw, gw->sa_len);
+   }
return (0);
 }
 
___
dev-commits-src-main@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-main
To unsubscribe, send any mail to "dev-commits-src-main-unsubscr...@freebsd.org"


git: 8ca99aecf749 - main - Fix various NOINET* builds broken by 145bf6c0af48.

2021-02-12 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit 8ca99aecf749dd088310f81f3c5364a462f1e332
Author: Alexander V. Chernikov 
AuthorDate: 2021-02-12 20:36:20 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-02-12 20:36:20 +

Fix various NOINET* builds broken by 145bf6c0af48.

Reported by:mjg, bdragon
---
 sys/net/rtsock.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/sys/net/rtsock.c b/sys/net/rtsock.c
index f67252f9fd5f..f8e741d87a10 100644
--- a/sys/net/rtsock.c
+++ b/sys/net/rtsock.c
@@ -587,16 +587,20 @@ fill_blackholeinfo(struct rt_addrinfo *info, union 
sockaddr_union *saun)
 
bzero(saun, sizeof(union sockaddr_union));
switch (saf) {
+#ifdef INET
case AF_INET:
saun->sin.sin_family = AF_INET;
saun->sin.sin_len = sizeof(struct sockaddr_in);
saun->sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
break;
+#endif
+#ifdef INET6
case AF_INET6:
saun->sin6.sin6_family = AF_INET6;
saun->sin6.sin6_len = sizeof(struct sockaddr_in6);
saun->sin6.sin6_addr = in6addr_loopback;
break;
+#endif
default:
return (ENOTSUP);
}
___
dev-commits-src-main@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-main
To unsubscribe, send any mail to "dev-commits-src-main-unsubscr...@freebsd.org"


git: a375ec52a7b4 - main - Fix ifa refcount leak during route addition.

2021-02-12 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit a375ec52a7b423133f66878ecf002efc3b6e9fca
Author: Alexander V. Chernikov 
AuthorDate: 2021-02-12 20:56:52 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-02-13 00:06:14 +

Fix ifa refcount leak during route addition.

Reported by:rstone
Reviewed by:rstone
MFC after:  1 day
---
 sys/net/route/route_ctl.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/sys/net/route/route_ctl.c b/sys/net/route/route_ctl.c
index 6b0869196d12..9aedfb9d5855 100644
--- a/sys/net/route/route_ctl.c
+++ b/sys/net/route/route_ctl.c
@@ -594,14 +594,12 @@ create_rtentry(struct rib_head *rnh, struct rt_addrinfo 
*info,
}
 
error = nhop_create_from_info(rnh, info, &nh);
-   if (error != 0) {
-   ifa_free(info->rti_ifa);
+   ifa_free(info->rti_ifa);
+   if (error != 0)
return (error);
-   }
 
rt = uma_zalloc(V_rtzone, M_NOWAIT | M_ZERO);
if (rt == NULL) {
-   ifa_free(info->rti_ifa);
nhop_free(nh);
return (ENOBUFS);
}
___
dev-commits-src-main@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-main
To unsubscribe, send any mail to "dev-commits-src-main-unsubscr...@freebsd.org"


git: 1bd44b11e59f - main - Do not reference returned ifa in in6_ifawithifp().

2021-02-14 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit 1bd44b11e59f1e9ee7245f8de1f823bc5287b9ef
Author: Alexander V. Chernikov 
AuthorDate: 2021-02-14 10:11:06 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-02-14 10:11:18 +

Do not reference returned ifa in in6_ifawithifp().

The only place where in6_ifawithifp() is used is ip6_output(),
 which uses the returned ifa to bump traffic counters.
Given ifa stability guarantees is provided by epoch, do not refcount ifa.

This eliminates 2 atomic ops from IPv6 fast path.

Reviewed By:rstone
MFC after:  1 week
Differential Revision:  https://reviews.freebsd.org/D28649
---
 sys/netinet6/in6.c| 14 +++---
 sys/netinet6/ip6_output.c |  1 -
 2 files changed, 3 insertions(+), 12 deletions(-)

diff --git a/sys/netinet6/in6.c b/sys/netinet6/in6.c
index 48fa8dd2efc6..057c0ee91e02 100644
--- a/sys/netinet6/in6.c
+++ b/sys/netinet6/in6.c
@@ -1921,10 +1921,8 @@ in6_ifawithifp(struct ifnet *ifp, struct in6_addr *dst)
besta = (struct in6_ifaddr *)ifa;
}
}
-   if (besta) {
-   ifa_ref(&besta->ia_ifa);
+   if (besta)
return (besta);
-   }
 
CK_STAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) {
if (ifa->ifa_addr->sa_family != AF_INET6)
@@ -1941,20 +1939,14 @@ in6_ifawithifp(struct ifnet *ifp, struct in6_addr *dst)
continue;
}
 
-   if (ifa != NULL)
-   ifa_ref(ifa);
return (struct in6_ifaddr *)ifa;
}
 
/* use the last-resort values, that are, deprecated addresses */
-   if (dep[0]) {
-   ifa_ref((struct ifaddr *)dep[0]);
+   if (dep[0])
return dep[0];
-   }
-   if (dep[1]) {
-   ifa_ref((struct ifaddr *)dep[1]);
+   if (dep[1])
return dep[1];
-   }
 
return NULL;
 }
diff --git a/sys/netinet6/ip6_output.c b/sys/netinet6/ip6_output.c
index df1e9e6f2dcd..58334788b05b 100644
--- a/sys/netinet6/ip6_output.c
+++ b/sys/netinet6/ip6_output.c
@@ -1177,7 +1177,6 @@ passout:
counter_u64_add(ia6->ia_ifa.ifa_opackets, 1);
counter_u64_add(ia6->ia_ifa.ifa_obytes,
m->m_pkthdr.len);
-   ifa_free(&ia6->ia_ifa);
}
error = ip6_output_send(inp, ifp, origifp, m, dst, ro,
(flags & IP_NO_SND_TAG_RL) ? false : true);
___
dev-commits-src-main@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-main
To unsubscribe, send any mail to "dev-commits-src-main-unsubscr...@freebsd.org"


git: 64d5c2777731 - main - Remove now-unused RTF_RNH_LOCKED route flag.

2021-02-15 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit 64d5c231c1376dd44b6a5fdb68b168d073dc
Author: Alexander V. Chernikov 
AuthorDate: 2021-02-14 13:45:14 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-02-15 20:49:59 +

Remove now-unused RTF_RNH_LOCKED route flag.

MFC after:  1 week
---
 sys/net/route.h  | 2 +-
 sys/net/rtsock.c | 2 --
 2 files changed, 1 insertion(+), 3 deletions(-)

diff --git a/sys/net/route.h b/sys/net/route.h
index f9928ab6a776..ab6e1aabc5ae 100644
--- a/sys/net/route.h
+++ b/sys/net/route.h
@@ -197,7 +197,7 @@ VNET_DECLARE(u_int, fib_hash_outbound);
/* 0x800 and up unassigned */
 #defineRTF_STICKY   0x1000 /* always route dst->src */
 
-#defineRTF_RNH_LOCKED   0x4000 /* radix node head is locked */
+/* 0x4000 unused, was RTF_RNH_LOCKED */
 
 #defineRTF_GWFLAG_COMPAT 0x8000/* a compatibility bit for 
interacting
   with existing routing apps */
diff --git a/sys/net/rtsock.c b/sys/net/rtsock.c
index f8e741d87a10..3a98b366dfc3 100644
--- a/sys/net/rtsock.c
+++ b/sys/net/rtsock.c
@@ -635,8 +635,6 @@ fill_addrinfo(struct rt_msghdr *rtm, int len, u_int fibnum, 
struct rt_addrinfo *
if (rt_xaddrs((caddr_t)(rtm + 1), len + (caddr_t)rtm, info))
return (EINVAL);
 
-   if (rtm->rtm_flags & RTF_RNH_LOCKED)
-   return (EINVAL);
info->rti_flags = rtm->rtm_flags;
if (info->rti_info[RTAX_DST] == NULL ||
info->rti_info[RTAX_DST]->sa_family >= AF_MAX ||
___
dev-commits-src-main@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-main
To unsubscribe, send any mail to "dev-commits-src-main-unsubscr...@freebsd.org"


git: 605284b89474 - main - Enforce net epoch in in6_selectsrc().

2021-02-15 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit 605284b894748d23136b30a202689493d8f8af52
Author: Alexander V. Chernikov 
AuthorDate: 2021-02-13 14:32:10 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-02-15 22:33:12 +

Enforce net epoch in in6_selectsrc().

in6_selectsrc() may call fib6_lookup() in some cases, which requires
 epoch. Wrap in6_selectsrc* calls into epoch inside its users.
Mark it as requiring epoch by adding NET_EPOCH_ASSERT().

MFC after:  1 weeek
Differential Revision:  https://reviews.freebsd.org/D28647
---
 sys/fs/nfsclient/nfs_clport.c | 3 +++
 sys/netinet6/icmp6.c  | 3 +++
 sys/netinet6/in6_pcb.c| 3 +++
 sys/netinet6/in6_src.c| 1 +
 sys/netinet6/nd6_nbr.c| 4 
 sys/netinet6/raw_ip6.c| 5 +
 sys/netinet6/send.c   | 3 +++
 7 files changed, 22 insertions(+)

diff --git a/sys/fs/nfsclient/nfs_clport.c b/sys/fs/nfsclient/nfs_clport.c
index 9c0ac5c4364e..81a0e05c3234 100644
--- a/sys/fs/nfsclient/nfs_clport.c
+++ b/sys/fs/nfsclient/nfs_clport.c
@@ -1006,15 +1006,18 @@ nfscl_getmyip(struct nfsmount *nmp, struct in6_addr 
*paddr, int *isinet6p)
 #endif
 #ifdef INET6
if (nmp->nm_nam->sa_family == AF_INET6) {
+   struct epoch_tracker et;
struct sockaddr_in6 *sin6;
int error;
 
sin6 = (struct sockaddr_in6 *)nmp->nm_nam;
 
+   NET_EPOCH_ENTER(et);
CURVNET_SET(CRED_TO_VNET(nmp->nm_sockreq.nr_cred));
error = in6_selectsrc_addr(fibnum, &sin6->sin6_addr,
sin6->sin6_scope_id, NULL, paddr, NULL);
CURVNET_RESTORE();
+   NET_EPOCH_EXIT(et);
if (error != 0)
return (NULL);
 
diff --git a/sys/netinet6/icmp6.c b/sys/netinet6/icmp6.c
index 1a08dad7de64..6208b7be78a2 100644
--- a/sys/netinet6/icmp6.c
+++ b/sys/netinet6/icmp6.c
@@ -260,6 +260,7 @@ icmp6_error(struct mbuf *m, int type, int code, int param)
 {
struct ip6_hdr *oip6, *nip6;
struct icmp6_hdr *icmp6;
+   struct epoch_tracker et;
u_int preplen;
int off;
int nxt;
@@ -379,7 +380,9 @@ icmp6_error(struct mbuf *m, int type, int code, int param)
icmp6->icmp6_pptr = htonl((u_int32_t)param);
 
ICMP6STAT_INC(icp6s_outhist[type]);
+   NET_EPOCH_ENTER(et);
icmp6_reflect(m, sizeof(struct ip6_hdr)); /* header order: IPv6 - 
ICMPv6 */
+   NET_EPOCH_EXIT(et);
 
return;
 
diff --git a/sys/netinet6/in6_pcb.c b/sys/netinet6/in6_pcb.c
index 567a7918f159..5fce9fcafa33 100644
--- a/sys/netinet6/in6_pcb.c
+++ b/sys/netinet6/in6_pcb.c
@@ -352,6 +352,7 @@ in6_pcbladdr(struct inpcb *inp, struct sockaddr *nam,
int error = 0;
int scope_ambiguous = 0;
struct in6_addr in6a;
+   struct epoch_tracker et;
 
INP_WLOCK_ASSERT(inp);
INP_HASH_WLOCK_ASSERT(inp->inp_pcbinfo);/* XXXRW: why? */
@@ -379,8 +380,10 @@ in6_pcbladdr(struct inpcb *inp, struct sockaddr *nam,
if ((error = prison_remote_ip6(inp->inp_cred, &sin6->sin6_addr)) != 0)
return (error);
 
+   NET_EPOCH_ENTER(et);
error = in6_selectsrc_socket(sin6, inp->in6p_outputopts,
inp, inp->inp_cred, scope_ambiguous, &in6a, NULL);
+   NET_EPOCH_EXIT(et);
if (error)
return (error);
 
diff --git a/sys/netinet6/in6_src.c b/sys/netinet6/in6_src.c
index 7a756030f01c..2224d568e121 100644
--- a/sys/netinet6/in6_src.c
+++ b/sys/netinet6/in6_src.c
@@ -191,6 +191,7 @@ in6_selectsrc(uint32_t fibnum, struct sockaddr_in6 *dstsock,
int error;
struct ip6_moptions *mopts;
 
+   NET_EPOCH_ASSERT();
KASSERT(srcp != NULL, ("%s: srcp is NULL", __func__));
 
dst = dstsock->sin6_addr; /* make a copy for local operation */
diff --git a/sys/netinet6/nd6_nbr.c b/sys/netinet6/nd6_nbr.c
index ab55c4dfc697..42e901bdd2a4 100644
--- a/sys/netinet6/nd6_nbr.c
+++ b/sys/netinet6/nd6_nbr.c
@@ -413,6 +413,8 @@ nd6_ns_output_fib(struct ifnet *ifp, const struct in6_addr 
*saddr6,
int maxlen;
caddr_t mac;
 
+   NET_EPOCH_ASSERT();
+
if (IN6_IS_ADDR_MULTICAST(taddr6))
return;
 
@@ -947,6 +949,8 @@ nd6_na_output_fib(struct ifnet *ifp, const struct in6_addr 
*daddr6_0,
struct in6_addr daddr6, dst6, src6;
uint32_t scopeid;
 
+   NET_EPOCH_ASSERT();
+
int icmp6len, maxlen, error;
caddr_t mac = NULL;
 
diff --git a/sys/netinet6/raw_ip6.c b/sys/netinet6/raw_ip6.c
index aea99add4391..8d71c40455a1 100644
--- a/sys/netinet6/raw_ip6.c
+++ b/sys/netinet6/raw_ip6.c
@@ -478,8 +478,10 @@ rip6_output(struct mbuf *m, struct socket *so, ...)
/*
 * Source address selection.
 */
+   NET_

git: 8268d82cff1b - main - Remove per-packet ifa refcounting from IPv6 fast path.

2021-02-15 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit 8268d82cff1bcd7969e5b3c676f28684784a7a43
Author: Alexander V. Chernikov 
AuthorDate: 2021-02-15 21:59:21 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-02-15 22:33:12 +

Remove per-packet ifa refcounting from IPv6 fast path.

Currently ip6_input() calls in6ifa_ifwithaddr() for
 every local packet, in order to check if the target ip
 belongs to the local ifa in proper state and increase
 its counters.

in6ifa_ifwithaddr() references found ifa.
With epoch changes, both `ip6_input()` and all other current callers
 of `in6ifa_ifwithaddr()` do not need this reference
 anymore, as epoch provides stability guarantee.

Given that, update `in6ifa_ifwithaddr()` to allow
 it to return ifa without referencing it, while preserving
 option for getting referenced ifa if so desired.

MFC after:  1 week
Differential Revision:  https://reviews.freebsd.org/D28648
---
 sys/netinet/tcp_input.c | 10 ++
 sys/netinet6/frag6.c|  6 ++
 sys/netinet6/icmp6.c|  8 ++--
 sys/netinet6/in6.c  |  7 ---
 sys/netinet6/in6_ifattach.c |  4 +---
 sys/netinet6/in6_src.c  |  8 ++--
 sys/netinet6/in6_var.h  |  2 +-
 sys/netinet6/ip6_input.c|  4 +---
 sys/netinet6/send.c | 12 +++-
 9 files changed, 22 insertions(+), 39 deletions(-)

diff --git a/sys/netinet/tcp_input.c b/sys/netinet/tcp_input.c
index 459b78cd444a..b7baef5bc0d6 100644
--- a/sys/netinet/tcp_input.c
+++ b/sys/netinet/tcp_input.c
@@ -592,16 +592,13 @@ tcp6_input(struct mbuf **mp, int *offp, int proto)
 * better place to put this in?
 */
ip6 = mtod(m, struct ip6_hdr *);
-   ia6 = in6ifa_ifwithaddr(&ip6->ip6_dst, 0 /* XXX */);
+   ia6 = in6ifa_ifwithaddr(&ip6->ip6_dst, 0 /* XXX */, false);
if (ia6 && (ia6->ia6_flags & IN6_IFF_ANYCAST)) {
-   ifa_free(&ia6->ia_ifa);
icmp6_error(m, ICMP6_DST_UNREACH, ICMP6_DST_UNREACH_ADDR,
(caddr_t)&ip6->ip6_dst - (caddr_t)ip6);
*mp = NULL;
return (IPPROTO_DONE);
}
-   if (ia6)
-   ifa_free(&ia6->ia_ifa);
 
*mp = m;
return (tcp_input(mp, offp, proto));
@@ -1249,10 +1246,9 @@ tfo_socket_result:
if (isipv6 && !V_ip6_use_deprecated) {
struct in6_ifaddr *ia6;
 
-   ia6 = in6ifa_ifwithaddr(&ip6->ip6_dst, 0 /* XXX */);
+   ia6 = in6ifa_ifwithaddr(&ip6->ip6_dst, 0 /* XXX */, 
false);
if (ia6 != NULL &&
(ia6->ia6_flags & IN6_IFF_DEPRECATED)) {
-   ifa_free(&ia6->ia_ifa);
if ((s = tcp_log_addrs(&inc, th, NULL, NULL)))
log(LOG_DEBUG, "%s; %s: Listen socket: "
"Connection attempt to deprecated "
@@ -1261,8 +1257,6 @@ tfo_socket_result:
rstreason = BANDLIM_RST_OPENPORT;
goto dropwithreset;
}
-   if (ia6)
-   ifa_free(&ia6->ia_ifa);
}
 #endif /* INET6 */
/*
diff --git a/sys/netinet6/frag6.c b/sys/netinet6/frag6.c
index c22e931dee33..f227930743b7 100644
--- a/sys/netinet6/frag6.c
+++ b/sys/netinet6/frag6.c
@@ -396,11 +396,9 @@ frag6_input(struct mbuf **mp, int *offp, int proto)
 
dstifp = NULL;
/* Find the destination interface of the packet. */
-   ia6 = in6ifa_ifwithaddr(&ip6->ip6_dst, 0 /* XXX */);
-   if (ia6 != NULL) {
+   ia6 = in6ifa_ifwithaddr(&ip6->ip6_dst, 0 /* XXX */, false);
+   if (ia6 != NULL)
dstifp = ia6->ia_ifp;
-   ifa_free(&ia6->ia_ifa);
-   }
 
/* Jumbo payload cannot contain a fragment header. */
if (ip6->ip6_plen == 0) {
diff --git a/sys/netinet6/icmp6.c b/sys/netinet6/icmp6.c
index 6208b7be78a2..e17f82a54951 100644
--- a/sys/netinet6/icmp6.c
+++ b/sys/netinet6/icmp6.c
@@ -1221,19 +1221,17 @@ ni6_input(struct mbuf *m, int off, struct prison *pr)
goto bad;
/* else it's a link-local multicast, fine */
} else {/* unicast or anycast */
-   ia6 = in6ifa_ifwithaddr(&ip6->ip6_dst, 0 /* XXX */);
+   ia6 = in6ifa_ifwithaddr(&ip6->ip6_dst, 0 /* XXX */, false);
if (ia6 == NULL)
goto bad; /* XXX impossible */
 
if ((ia6->ia6_flags & IN6_IFF_TEMPORA

git: 9fdbf7eef5c0 - main - Make in_localip_more() fib-aware.

2021-02-16 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit 9fdbf7eef5c006002769add15b1ebb8fa8d9e220
Author: Alexander V. Chernikov 
AuthorDate: 2021-02-16 20:00:46 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-02-16 20:00:46 +

Make in_localip_more() fib-aware.

It fixes loopback route installation for the interfaces
 in the different fibs using the same prefix.

Reviewed By:donner
PR: 189088
Differential Revision: https://reviews.freebsd.org/D28673
MFC after:  1 week
---
 sys/netinet/in.c | 24 
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/sys/netinet/in.c b/sys/netinet/in.c
index eb58c3453cfc..bcf071a81e0e 100644
--- a/sys/netinet/in.c
+++ b/sys/netinet/in.c
@@ -163,18 +163,23 @@ in_ifhasaddr(struct ifnet *ifp, struct in_addr in)
  * the supplied one but with same IP address value.
  */
 static struct in_ifaddr *
-in_localip_more(struct in_ifaddr *ia)
+in_localip_more(struct in_ifaddr *original_ia)
 {
struct rm_priotracker in_ifa_tracker;
-   in_addr_t in = IA_SIN(ia)->sin_addr.s_addr;
-   struct in_ifaddr *it;
+   in_addr_t original_addr = IA_SIN(original_ia)->sin_addr.s_addr;
+   uint32_t original_fib = original_ia->ia_ifa.ifa_ifp->if_fib;
+   struct in_ifaddr *ia;
 
IN_IFADDR_RLOCK(&in_ifa_tracker);
-   LIST_FOREACH(it, INADDR_HASH(in), ia_hash) {
-   if (it != ia && IA_SIN(it)->sin_addr.s_addr == in) {
-   ifa_ref(&it->ia_ifa);
+   LIST_FOREACH(ia, INADDR_HASH(original_addr), ia_hash) {
+   in_addr_t addr = IA_SIN(ia)->sin_addr.s_addr;
+   uint32_t fib = ia->ia_ifa.ifa_ifp->if_fib;
+   if (!V_rt_add_addr_allfibs && (original_fib != fib))
+   continue;
+   if ((original_ia != ia) && (original_addr == addr)) {
+   ifa_ref(&ia->ia_ifa);
IN_IFADDR_RUNLOCK(&in_ifa_tracker);
-   return (it);
+   return (ia);
}
}
IN_IFADDR_RUNLOCK(&in_ifa_tracker);
@@ -1007,11 +1012,6 @@ in_scrubprefix(struct in_ifaddr *target, u_int flags)
if (ia_need_loopback_route(target) && (flags & LLE_STATIC)) {
struct in_ifaddr *eia;
 
-   /*
-* XXXME: add fib-aware in_localip.
-* We definitely don't want to switch between
-* prefixes in different fibs.
-*/
eia = in_localip_more(target);
 
if (eia != NULL) {
___
dev-commits-src-main@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-main
To unsubscribe, send any mail to "dev-commits-src-main-unsubscr...@freebsd.org"


git: 600eade2fb4f - main - Add ifa_try_ref() to simplify ifa handling inside epoch.

2021-02-16 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit 600eade2fb4faacfcd408a01140ef15f85f0c817
Author: Alexander V. Chernikov 
AuthorDate: 2021-02-16 20:12:58 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-02-16 20:14:50 +

Add ifa_try_ref() to simplify ifa handling inside epoch.

More and more code migrates from lock-based protection to the NET_EPOCH
 umbrella. It requires some logic changes, including, notably, refcount
 handling.

When we have an `ifa` pointer and we're running inside epoch we're
 guaranteed that this pointer will not be freed.
However, the following case can still happen:
 * in thread 1 we drop to 0 refcount for ifa and schedule its deletion.
 * in thread 2 we use this ifa and reference it
 * destroy callout kicks in
 * unhappy user reports bug

To address it, new `ifa_try_ref()` function is added, allowing to return
 failure when we try to reference `ifa` with 0 refcount.
Additionally, existing `ifa_ref()` is enforced with `KASSERT` to provide
 cleaner error in such scenarious.

Reviewed By: rstone, donner
Differential Revision: https://reviews.freebsd.org/D28639
MFC after:  1 week
---
 sys/net/if.c | 12 +++-
 sys/net/if_var.h |  1 +
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/sys/net/if.c b/sys/net/if.c
index c85cfab19bf6..948be6876b65 100644
--- a/sys/net/if.c
+++ b/sys/net/if.c
@@ -1857,8 +1857,18 @@ fail:
 void
 ifa_ref(struct ifaddr *ifa)
 {
+   u_int old;
 
-   refcount_acquire(&ifa->ifa_refcnt);
+   old = refcount_acquire(&ifa->ifa_refcnt);
+   KASSERT(old > 0, ("%s: ifa %p has 0 refs", __func__, ifa));
+}
+
+int
+ifa_try_ref(struct ifaddr *ifa)
+{
+
+   NET_EPOCH_ASSERT();
+   return (refcount_acquire_if_not_zero(&ifa->ifa_refcnt));
 }
 
 static void
diff --git a/sys/net/if_var.h b/sys/net/if_var.h
index 9ecdfb684296..291a7781d73c 100644
--- a/sys/net/if_var.h
+++ b/sys/net/if_var.h
@@ -577,6 +577,7 @@ struct ifaddr {
 struct ifaddr *ifa_alloc(size_t size, int flags);
 void   ifa_free(struct ifaddr *ifa);
 void   ifa_ref(struct ifaddr *ifa);
+intifa_try_ref(struct ifaddr *ifa);
 
 /*
  * Multicast address structure.  This is analogous to the ifaddr
___
dev-commits-src-main@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-main
To unsubscribe, send any mail to "dev-commits-src-main-unsubscr...@freebsd.org"


git: 2fe5a79425c7 - main - Fix dst/netmask handling in routing socket code.

2021-02-16 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit 2fe5a79425c79f7b828acd91da66d97230925fc8
Author: Alexander V. Chernikov 
AuthorDate: 2021-02-16 20:30:04 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-02-16 20:30:04 +

Fix dst/netmask handling in routing socket code.

Traditionally routing socket code did almost zero checks on
 the input message except for the most basic size checks.

This resulted in the unclear KPI boundary for the routing system code
 (`rtrequest*` and now `rib_action()`) w.r.t message validness.

Multiple potential problems and nuances exists:
* Host bits in RTAX_DST sockaddr. Existing applications do send prefixes
 with hostbits uncleared. Even `route(8)` does this, as they hope the kernel
 would do the job of fixing it. Code inside `rib_action()` needs to handle
 it on its own (see `rt_maskedcopy()` ugly hack).
* There are multiple way of adding the host route: it can be DST without
 netmask or DST with /32(/128) netmask. Also, RTF_HOST has to be set 
correspondingly.
 Currently, these 2 options create 2 DIFFERENT routes in the kernel.
* no sockaddr length/content checking for the "secondary" fields exists: 
nothing
 stops rtsock application to send sockaddr_in with length of 25 (instead of 
16).
 Kernel will accept it, install to RIB as is and propagate to all rtsock 
consumers,
 potentially triggering bugs in their code. Same goes for sin_port, 
sin_zero, etc.

The goal of this change is to make rtsock verify all sockaddr and prefix 
consistency.
Said differently, `rib_action()` or internals should NOT require to change 
any of the
 sockaddrs supplied by `rt_addrinfo` structure due to incorrectness.

To be more specific, this change implements the following:
* sockaddr cleanup/validation check is added immediately after getting 
sockaddrs from rtm.
* Per-family dst/netmask checks clears host bits in dst and zeros all 
dst/netmask "secondary" fields.
* The same netmask checking code converts /32(/128) netmasks to "host" 
route case
 (NULL netmask, RTF_HOST), removing the dualism.
* Instead of allowing ANY "known" sockaddr families (0<..
Reviewed By:donner
Differential Revision: https://reviews.freebsd.org/D28668
MFC after:  3 days
---
 sys/net/rtsock.c  | 201 +-
 tests/sys/net/routing/rtsock_common.h |   4 -
 2 files changed, 195 insertions(+), 10 deletions(-)

diff --git a/sys/net/rtsock.c b/sys/net/rtsock.c
index 3a98b366dfc3..40ce62c77c2a 100644
--- a/sys/net/rtsock.c
+++ b/sys/net/rtsock.c
@@ -70,6 +70,7 @@
 #include 
 #include 
 #ifdef INET6
+#include 
 #include 
 #include 
 #endif
@@ -173,6 +174,7 @@ static int  rtsock_msg_buffer(int type, struct rt_addrinfo 
*rtinfo,
struct walkarg *w, int *plen);
 static int rt_xaddrs(caddr_t cp, caddr_t cplim,
struct rt_addrinfo *rtinfo);
+static int cleanup_xaddrs(struct rt_addrinfo *info);
 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);
@@ -636,11 +638,9 @@ fill_addrinfo(struct rt_msghdr *rtm, int len, u_int 
fibnum, struct rt_addrinfo *
return (EINVAL);
 
info->rti_flags = rtm->rtm_flags;
-   if (info->rti_info[RTAX_DST] == NULL ||
-   info->rti_info[RTAX_DST]->sa_family >= AF_MAX ||
-   (info->rti_info[RTAX_GATEWAY] != NULL &&
-info->rti_info[RTAX_GATEWAY]->sa_family >= AF_MAX))
-   return (EINVAL);
+   error = cleanup_xaddrs(info);
+   if (error != 0)
+   return (error);
saf = info->rti_info[RTAX_DST]->sa_family;
/*
 * Verify that the caller has the appropriate privilege; RTM_GET
@@ -739,7 +739,14 @@ handle_rtm_get(struct rt_addrinfo *info, u_int fibnum,
 
RIB_RLOCK(rnh);
 
-   if (info->rti_info[RTAX_NETMASK] == NULL) {
+   /*
+* By (implicit) convention host route (one without netmask)
+* means longest-prefix-match request and the route with netmask
+* means exact-match lookup.
+* As cleanup_xaddrs() cleans up info flags&addrs for the /32,/128
+* prefixes, use original data to check for the netmask presence.
+*/
+   if ((rtm->rtm_addrs & RTA_NETMASK) == 0) {
/*
 * Provide longest prefix match for
 * address lookup (no mask).
@@ -1286,6 +1293,188 @@ rt_xaddrs(caddr_t cp, caddr_t cplim, struct rt_addrinfo 
*rtinfo)
return (0);
 }
 
+static inline void
+fill_sockaddr_inet(struct sockaddr_in 

Re: git: 2fe5a79425c7 - main - Fix dst/netmask handling in routing socket code.

2021-02-16 Thread Alexander V . Chernikov
16.02.2021, 20:43, "Mateusz Guzik" :
> This breaks the built at least without INET6.
It would help if you could share the actual build error.
I see -Wunused for 2 function (which I will fix soon), but I'm not sure if 
that's the error you're running into.
>
> can you please start testing your patches on NOINET kernels
Well, it actually builds for me:
--
>>> Kernel build for LINT-NOINET completed on Tue Feb 16 21:21:39 UTC 2021
--
>>> Kernel(s)  LINT-NOINET built in 28 seconds, ncpu: 2, make -j6
------

>
> On 2/16/21, Alexander V. Chernikov  wrote:
>>  The branch main has been updated by melifaro:
>>
>>  URL:
>>  
>> https://cgit.FreeBSD.org/src/commit/?id=2fe5a79425c79f7b828acd91da66d97230925fc8
>>
>>  commit 2fe5a79425c79f7b828acd91da66d97230925fc8
>>  Author: Alexander V. Chernikov 
>>  AuthorDate: 2021-02-16 20:30:04 +
>>  Commit: Alexander V. Chernikov 
>>  CommitDate: 2021-02-16 20:30:04 +
>>
>>  Fix dst/netmask handling in routing socket code.
>>
>>  Traditionally routing socket code did almost zero checks on
>>   the input message except for the most basic size checks.
>>
>>  This resulted in the unclear KPI boundary for the routing system code
>>   (`rtrequest*` and now `rib_action()`) w.r.t message validness.
>>
>>  Multiple potential problems and nuances exists:
>>  * Host bits in RTAX_DST sockaddr. Existing applications do send
>>  prefixes
>>   with hostbits uncleared. Even `route(8)` does this, as they hope the
>>  kernel
>>   would do the job of fixing it. Code inside `rib_action()` needs to
>>  handle
>>   it on its own (see `rt_maskedcopy()` ugly hack).
>>  * There are multiple way of adding the host route: it can be DST
>>  without
>>   netmask or DST with /32(/128) netmask. Also, RTF_HOST has to be set
>>  correspondingly.
>>   Currently, these 2 options create 2 DIFFERENT routes in the kernel.
>>  * no sockaddr length/content checking for the "secondary" fields exists:
>>  nothing
>>   stops rtsock application to send sockaddr_in with length of 25 (instead
>>  of 16).
>>   Kernel will accept it, install to RIB as is and propagate to all rtsock
>>  consumers,
>>   potentially triggering bugs in their code. Same goes for sin_port,
>>  sin_zero, etc.
>>
>>  The goal of this change is to make rtsock verify all sockaddr and prefix
>>  consistency.
>>  Said differently, `rib_action()` or internals should NOT require to
>>  change any of the
>>   sockaddrs supplied by `rt_addrinfo` structure due to incorrectness.
>>
>>  To be more specific, this change implements the following:
>>  * sockaddr cleanup/validation check is added immediately after getting
>>  sockaddrs from rtm.
>>  * Per-family dst/netmask checks clears host bits in dst and zeros all
>>  dst/netmask "secondary" fields.
>>  * The same netmask checking code converts /32(/128) netmasks to "host"
>>  route case
>>   (NULL netmask, RTF_HOST), removing the dualism.
>>  * Instead of allowing ANY "known" sockaddr families (0<..>  only actually
>>   supported ones (inet, inet6, link).
>>  * Automatically convert `sockaddr_sdl` (AF_LINK) gateways to
>>    `sockaddr_sdl_short`.
>>
>>  Reported by: Guy Yur 
>>  Reviewed By: donner
>>  Differential Revision: https://reviews.freebsd.org/D28668
>>  MFC after: 3 days
>>  ---
>>   sys/net/rtsock.c | 201
>>  +-
>>   tests/sys/net/routing/rtsock_common.h | 4 -
>>   2 files changed, 195 insertions(+), 10 deletions(-)
>>
>>  diff --git a/sys/net/rtsock.c b/sys/net/rtsock.c
>>  index 3a98b366dfc3..40ce62c77c2a 100644
>>  --- a/sys/net/rtsock.c
>>  +++ b/sys/net/rtsock.c
>>  @@ -70,6 +70,7 @@
>>   #include 
>>   #include 
>>   #ifdef INET6
>>  +#include 
>>   #include 
>>   #include 
>>   #endif
>>  @@ -173,6 +174,7 @@ static int rtsock_msg_buffer(int type, struct
>>  rt_addrinfo *rtinfo,
>>   struct walkarg *w, int *plen);
>>   static int rt_xaddrs(caddr_t cp, caddr_t cplim,
>>   struct rt_addrinfo *rtinfo);
>>  +static int cleanup_xaddrs(struct rt_addrinfo *info);
>&g

git: a4513bace0e0 - main - Fix NOINET6 build broken by 2fe5a79425c7.

2021-02-16 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit a4513bace0e0c38d38b0c49c1daea60f2741d781
Author: Alexander V. Chernikov 
AuthorDate: 2021-02-16 21:49:48 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-02-16 21:49:48 +

Fix NOINET6 build broken by 2fe5a79425c7.

Reported by:mjg
---
 sys/net/rtsock.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/sys/net/rtsock.c b/sys/net/rtsock.c
index 40ce62c77c2a..3c1fea497af6 100644
--- a/sys/net/rtsock.c
+++ b/sys/net/rtsock.c
@@ -1293,6 +1293,7 @@ rt_xaddrs(caddr_t cp, caddr_t cplim, struct rt_addrinfo 
*rtinfo)
return (0);
 }
 
+#ifdef INET
 static inline void
 fill_sockaddr_inet(struct sockaddr_in *sin, struct in_addr addr)
 {
@@ -1304,7 +1305,9 @@ fill_sockaddr_inet(struct sockaddr_in *sin, struct 
in_addr addr)
};
*sin = nsin;
 }
+#endif
 
+#ifdef INET6
 static inline void
 fill_sockaddr_inet6(struct sockaddr_in6 *sin6, const struct in6_addr *addr6,
 uint32_t scopeid)
@@ -1318,6 +1321,7 @@ fill_sockaddr_inet6(struct sockaddr_in6 *sin6, const 
struct in6_addr *addr6,
};
*sin6 = nsin6;
 }
+#endif
 
 static int
 cleanup_xaddrs_gateway(struct rt_addrinfo *info)
@@ -1372,6 +1376,7 @@ cleanup_xaddrs_gateway(struct rt_addrinfo *info)
return (0);
 }
 
+#ifdef INET
 static int
 cleanup_xaddrs_inet(struct rt_addrinfo *info)
 {
@@ -1412,7 +1417,9 @@ cleanup_xaddrs_inet(struct rt_addrinfo *info)
 
return (0);
 }
+#endif
 
+#ifdef INET6
 static int
 cleanup_xaddrs_inet6(struct rt_addrinfo *info)
 {
@@ -1450,6 +1457,7 @@ cleanup_xaddrs_inet6(struct rt_addrinfo *info)
 
return (0);
 }
+#endif
 
 static int
 cleanup_xaddrs(struct rt_addrinfo *info)
___
dev-commits-src-main@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-main
To unsubscribe, send any mail to "dev-commits-src-main-unsubscr...@freebsd.org"


Re: git: 2fe5a79425c7 - main - Fix dst/netmask handling in routing socket code.

2021-02-16 Thread Alexander V . Chernikov
16.02.2021, 21:47, "Mateusz Guzik" :
> In this context I meant NOINET and NOINET6
>
> Anyhow I see the following:
> sys/net/rtsock.c:1427:2: error: implicit declaration of function
> 'IN6_MASK_ADDR' is invalid in C99
> [-Werror,-Wimplicit-function-declaration]
> IN6_MASK_ADDR(&dst_sa->sin6_addr, &mask);
Should be fixed by a4513bace0e0.
Sorry for the breakage.

> ^
>
> On 2/16/21, Alexander V. Chernikov  wrote:
>>  16.02.2021, 20:43, "Mateusz Guzik" :
>>>  This breaks the built at least without INET6.
>>  It would help if you could share the actual build error.
>>  I see -Wunused for 2 function (which I will fix soon), but I'm not sure if
>>  that's the error you're running into.
>>>  can you please start testing your patches on NOINET kernels
>>  Well, it actually builds for me:
>>  --
>>>>>  Kernel build for LINT-NOINET completed on Tue Feb 16 21:21:39 UTC 2021
>>  --
>>>>>  Kernel(s) LINT-NOINET built in 28 seconds, ncpu: 2, make -j6
>>  --
>>
>>>  On 2/16/21, Alexander V. Chernikov  wrote:
>>>>   The branch main has been updated by melifaro:
>>>>
>>>>   URL:
>>>>   
>>>> https://cgit.FreeBSD.org/src/commit/?id=2fe5a79425c79f7b828acd91da66d97230925fc8
>>>>
>>>>   commit 2fe5a79425c79f7b828acd91da66d97230925fc8
>>>>   Author: Alexander V. Chernikov 
>>>>   AuthorDate: 2021-02-16 20:30:04 +
>>>>   Commit: Alexander V. Chernikov 
>>>>   CommitDate: 2021-02-16 20:30:04 +
>>>>
>>>>   Fix dst/netmask handling in routing socket code.
>>>>
>>>>   Traditionally routing socket code did almost zero checks on
>>>>    the input message except for the most basic size checks.
>>>>
>>>>   This resulted in the unclear KPI boundary for the routing system
>>>>  code
>>>>    (`rtrequest*` and now `rib_action()`) w.r.t message validness.
>>>>
>>>>   Multiple potential problems and nuances exists:
>>>>   * Host bits in RTAX_DST sockaddr. Existing applications do send
>>>>   prefixes
>>>>    with hostbits uncleared. Even `route(8)` does this, as they hope
>>>>  the
>>>>   kernel
>>>>    would do the job of fixing it. Code inside `rib_action()` needs to
>>>>   handle
>>>>    it on its own (see `rt_maskedcopy()` ugly hack).
>>>>   * There are multiple way of adding the host route: it can be DST
>>>>   without
>>>>    netmask or DST with /32(/128) netmask. Also, RTF_HOST has to be
>>>>  set
>>>>   correspondingly.
>>>>    Currently, these 2 options create 2 DIFFERENT routes in the
>>>>  kernel.
>>>>   * no sockaddr length/content checking for the "secondary" fields
>>>>  exists:
>>>>   nothing
>>>>    stops rtsock application to send sockaddr_in with length of 25
>>>>  (instead
>>>>   of 16).
>>>>    Kernel will accept it, install to RIB as is and propagate to all
>>>>  rtsock
>>>>   consumers,
>>>>    potentially triggering bugs in their code. Same goes for sin_port,
>>>>   sin_zero, etc.
>>>>
>>>>   The goal of this change is to make rtsock verify all sockaddr and
>>>>  prefix
>>>>   consistency.
>>>>   Said differently, `rib_action()` or internals should NOT require to
>>>>   change any of the
>>>>    sockaddrs supplied by `rt_addrinfo` structure due to
>>>>  incorrectness.
>>>>
>>>>   To be more specific, this change implements the following:
>>>>   * sockaddr cleanup/validation check is added immediately after
>>>>  getting
>>>>   sockaddrs from rtm.
>>>>   * Per-family dst/netmask checks clears host bits in dst and zeros
>>>>  all
>>>>   dst/netmask "secondary" fields.
>>>>   * The same netmask checking code converts /32(/128) netmasks to
>>>>  "host"
>>>>   route case
>>>>    (NULL netmask, RTF_HOST), removing the dualism.
>>>>   * Instead of allowing ANY "known" sockaddr 

Re: git: 2fe5a79425c7 - main - Fix dst/netmask handling in routing socket code.

2021-02-19 Thread Alexander V . Chernikov
19.02.2021, 16:11, "Kristof Provost" :
> On 19 Feb 2021, at 16:24, Kristof Provost wrote:
>> On 16 Feb 2021, at 21:31, Alexander V. Chernikov wrote:
>>> The branch main has been updated by melifaro:
>>>
>>> URL: 
>>> https://cgit.FreeBSD.org/src/commit/?id=2fe5a79425c79f7b828acd91da66d97230925fc8
>>>
>>> commit 2fe5a79425c79f7b828acd91da66d97230925fc8
>>> Author: Alexander V. Chernikov 
>>> AuthorDate: 2021-02-16 20:30:04 +
>>> Commit: Alexander V. Chernikov 
>>> CommitDate: 2021-02-16 20:30:04 +
>>>
>>> Fix dst/netmask handling in routing socket code.
>>>
>>> Traditionally routing socket code did almost zero checks on
>>> the input message except for the most basic size checks.
>>>
>>> This resulted in the unclear KPI boundary for the routing system code
>>> (`rtrequest*` and now `rib_action()`) w.r.t message validness.
>>>
>>> Multiple potential problems and nuances exists:
>>> * Host bits in RTAX_DST sockaddr. Existing applications do send prefixes
>>> with hostbits uncleared. Even `route(8)` does this, as they hope the kernel
>>> would do the job of fixing it. Code inside `rib_action()` needs to handle
>>> it on its own (see `rt_maskedcopy()` ugly hack).
>>> * There are multiple way of adding the host route: it can be DST without
>>> netmask or DST with /32(/128) netmask. Also, RTF_HOST has to be set 
>>> correspondingly.
>>> Currently, these 2 options create 2 DIFFERENT routes in the kernel.
>>> * no sockaddr length/content checking for the "secondary" fields exists: 
>>> nothing
>>> stops rtsock application to send sockaddr_in with length of 25 (instead of 
>>> 16).
>>> Kernel will accept it, install to RIB as is and propagate to all rtsock 
>>> consumers,
>>> potentially triggering bugs in their code. Same goes for sin_port, 
>>> sin_zero, etc.
>>>
>>> The goal of this change is to make rtsock verify all sockaddr and prefix 
>>> consistency.
>>> Said differently, `rib_action()` or internals should NOT require to change 
>>> any of the
>>> sockaddrs supplied by `rt_addrinfo` structure due to incorrectness.
>>>
>>> To be more specific, this change implements the following:
>>> * sockaddr cleanup/validation check is added immediately after getting 
>>> sockaddrs from rtm.
>>> * Per-family dst/netmask checks clears host bits in dst and zeros all 
>>> dst/netmask "secondary" fields.
>>> * The same netmask checking code converts /32(/128) netmasks to "host" 
>>> route case
>>> (NULL netmask, RTF_HOST), removing the dualism.
>>> * Instead of allowing ANY "known" sockaddr families (0<..>> only actually
>>> supported ones (inet, inet6, link).
>>> * Automatically convert `sockaddr_sdl` (AF_LINK) gateways to
>>> `sockaddr_sdl_short`.
>>>
>>> Reported by: Guy Yur 
>>> Reviewed By: donner
>>> Differential Revision: https://reviews.freebsd.org/D28668
>>> MFC after: 3 days
>>> ---
>>> sys/net/rtsock.c | 201 +-
>>> tests/sys/net/routing/rtsock_common.h | 4 -
>>> 2 files changed, 195 insertions(+), 10 deletions(-)
>>> +static int
>>> +cleanup_xaddrs_inet(struct rt_addrinfo *info)
>>> +{
>>> + struct sockaddr_in *dst_sa, *mask_sa;
>>> +
>>> + /* Check & fixup dst/netmask combination first */
>>> + dst_sa = (struct sockaddr_in *)info->rti_info[RTAX_DST];
>>> + mask_sa = (struct sockaddr_in *)info->rti_info[RTAX_NETMASK];
>>> +
>>> + struct in_addr mask = {
>>> + .s_addr = mask_sa ? mask_sa->sin_addr.s_addr : INADDR_BROADCAST,
>>> + };
>>> + struct in_addr dst = {
>>> + .s_addr = htonl(ntohl(dst_sa->sin_addr.s_addr) & ntohl(mask.s_addr))
>>> + };
>>> +
>>
>> This breaks things like `arp -d 10.0.2.1`. It always masks off the network 
>> address, which is the right thing to do in the routing table, but not in the 
>> arp table.
Thanks for catching it!
I've raised https://reviews.freebsd.org/D28804 to fix it.
(Also: yes, this should be covered by tests).

>>
>> I’ve worked around it for now with this hack:
>>
>> diff --git a/sys/net/rtsock.c b/sys/net/rtsock.c
>> index 3c1fea497af6..533076db99a5 100644
>> --- a/sys/net/rtsock.c
>> +++ b/sys/net/rtsock.c
>> @@ -638,9 +638,12 @@ fill_addrinfo(struct rt_msghdr *r

git: f9e1cd6c9920 - main - Fix arp/ndp deletion broken by 2fe5a79425c7.

2021-02-19 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit f9e1cd6c99200846b324a8b65f7f31ded74013bd
Author: Alexander V. Chernikov 
AuthorDate: 2021-02-19 21:09:17 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-02-19 21:17:17 +

Fix arp/ndp deletion broken by 2fe5a79425c7.

Changes in the 2fe5a79425c7 moved dst sockaddr masking from the
 routing control plane to the rtsock code.

It broke arp/ndp deletion.
It turns out, arp/ndp perform RTM_GET request first to get an
 interface index necessary for the deletion.
Then they simply stamp the reply with RTF_LLDATA and set the
 command to RTM_DELETE.
As a result, kernel receives request with non-empty RTA_NETMASK
 and clears RTA_DST host bits before passing the message to the
 lla code.

De facto, the only needed bits are RTA_DST, RTA_GATEWAY and the
 subset of rtm_flags.

With that in mind, fix the interace by clearing RTA_NETMASK
 for every messages with RTF_LLDATA.

While here, cleanup arp/ndp code a bit.

MFC after:  1 day
Reviewed by:gnn
Differential Revision:  https://reviews.freebsd.org/D28804
---
 sys/net/rtsock.c   | 31 +--
 usr.sbin/arp/arp.c |  9 -
 usr.sbin/ndp/ndp.c | 10 --
 3 files changed, 21 insertions(+), 29 deletions(-)

diff --git a/sys/net/rtsock.c b/sys/net/rtsock.c
index 3c1fea497af6..221661585bbf 100644
--- a/sys/net/rtsock.c
+++ b/sys/net/rtsock.c
@@ -1376,6 +1376,14 @@ cleanup_xaddrs_gateway(struct rt_addrinfo *info)
return (0);
 }
 
+static void
+remove_netmask(struct rt_addrinfo *info)
+{
+   info->rti_info[RTAX_NETMASK] = NULL;
+   info->rti_flags |= RTF_HOST;
+   info->rti_addrs &= ~RTA_NETMASK;
+}
+
 #ifdef INET
 static int
 cleanup_xaddrs_inet(struct rt_addrinfo *info)
@@ -1405,11 +1413,8 @@ cleanup_xaddrs_inet(struct rt_addrinfo *info)
 
if (mask.s_addr != INADDR_BROADCAST)
fill_sockaddr_inet(mask_sa, mask);
-   else {
-   info->rti_info[RTAX_NETMASK] = NULL;
-   info->rti_flags |= RTF_HOST;
-   info->rti_addrs &= ~RTA_NETMASK;
-   }
+   else
+   remove_netmask(info);
 
/* Check gateway */
if (info->rti_info[RTAX_GATEWAY] != NULL)
@@ -1445,11 +1450,8 @@ cleanup_xaddrs_inet6(struct rt_addrinfo *info)
 
if (!IN6_ARE_ADDR_EQUAL(&mask, &in6mask128))
fill_sockaddr_inet6(mask_sa, &mask, 0);
-   else {
-   info->rti_info[RTAX_NETMASK] = NULL;
-   info->rti_flags |= RTF_HOST;
-   info->rti_addrs &= ~RTA_NETMASK;
-   }
+   else
+   remove_netmask(info);
 
/* Check gateway */
if (info->rti_info[RTAX_GATEWAY] != NULL)
@@ -1467,6 +1469,15 @@ cleanup_xaddrs(struct rt_addrinfo *info)
if (info->rti_info[RTAX_DST] == NULL)
return (EINVAL);
 
+   if (info->rti_flags & RTF_LLDATA) {
+   /*
+* arp(8)/ndp(8) sends RTA_NETMASK for the associated
+* prefix along with the actual address in RTA_DST.
+* Remove netmask to avoid unnecessary address masking.
+*/
+   remove_netmask(info);
+   }
+
switch (info->rti_info[RTAX_DST]->sa_family) {
 #ifdef INET
case AF_INET:
diff --git a/usr.sbin/arp/arp.c b/usr.sbin/arp/arp.c
index 07e07f1f2da9..08698c7bc299 100644
--- a/usr.sbin/arp/arp.c
+++ b/usr.sbin/arp/arp.c
@@ -717,7 +717,6 @@ rtmsg(int cmd, struct sockaddr_in *dst, struct sockaddr_dl 
*sdl)
static int seq;
int rlen;
int l;
-   struct sockaddr_in so_mask, *som = &so_mask;
static int s = -1;
static pid_t pid;
 
@@ -735,9 +734,6 @@ rtmsg(int cmd, struct sockaddr_in *dst, struct sockaddr_dl 
*sdl)
xo_err(1, "socket");
pid = getpid();
}
-   bzero(&so_mask, sizeof(so_mask));
-   so_mask.sin_len = 8;
-   so_mask.sin_addr.s_addr = 0x;
 
errno = 0;
/*
@@ -758,10 +754,6 @@ rtmsg(int cmd, struct sockaddr_in *dst, struct sockaddr_dl 
*sdl)
rtm->rtm_rmx.rmx_expire = expire_time;
rtm->rtm_inits = RTV_EXPIRE;
rtm->rtm_flags |= (RTF_HOST | RTF_STATIC | RTF_LLDATA);
-   if (doing_proxy) {
-   rtm->rtm_addrs |= RTA_NETMASK;
-   rtm->rtm_flags &= ~RTF_HOST;
-   }
/* FALLTHROUGH */
case RTM_GET:
rtm->rtm_addrs |= RTA_DST;
@@ -776,7 +768,6 @@ rtmsg(int cmd, struct sockaddr_in *dst, struct sockaddr_dl 
*sdl)
 
NEXTADDR(RTA_DST, dst);
NEXTADDR(RTA_GATEWAY, sdl);
-   NEXTAD

git: e5b394f2d0d9 - main - Fix setting static entries for arp/ndp.

2021-02-20 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit e5b394f2d0d94f190c9da2346fd22d7c6fb14730
Author: Alexander V. Chernikov 
AuthorDate: 2021-02-20 18:21:52 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-02-20 18:26:35 +

Fix setting static entries for arp/ndp.

rtsock message validation changes committed in 2fe5a79425c7
 did not take llinfo messages into account.

Add a special validation case for RTA_GATEWAY llinfo messages.

MFC after:  2 days
---
 sys/net/if_llatbl.c |  1 +
 sys/net/rtsock.c| 26 ++
 2 files changed, 27 insertions(+)

diff --git a/sys/net/if_llatbl.c b/sys/net/if_llatbl.c
index 97a8e3e9ccc1..7225869a07d0 100644
--- a/sys/net/if_llatbl.c
+++ b/sys/net/if_llatbl.c
@@ -693,6 +693,7 @@ lla_rt_output(struct rt_msghdr *rtm, struct rt_addrinfo 
*info)
if (dl == NULL || dl->sdl_family != AF_LINK)
return (EINVAL);
 
+   /* XXX: should be ntohs() */
ifp = ifnet_byindex(dl->sdl_index);
if (ifp == NULL) {
log(LOG_INFO, "%s: invalid ifp (sdl_index %d)\n",
diff --git a/sys/net/rtsock.c b/sys/net/rtsock.c
index 221661585bbf..12e485f917c8 100644
--- a/sys/net/rtsock.c
+++ b/sys/net/rtsock.c
@@ -1323,11 +1323,37 @@ fill_sockaddr_inet6(struct sockaddr_in6 *sin6, const 
struct in6_addr *addr6,
 }
 #endif
 
+/*
+ * Checks if gateway is suitable for lltable operations.
+ * Lltable code requires AF_LINK gateway with ifindex
+ *  and mac address specified.
+ * Returns 0 on success.
+ */
+static int
+cleanup_xaddrs_lladdr(struct rt_addrinfo *info)
+{
+   struct sockaddr_dl *sdl = (struct sockaddr_dl 
*)info->rti_info[RTAX_GATEWAY];
+
+   if (sdl->sdl_family != AF_LINK)
+   return (EINVAL);
+
+   if (sdl->sdl_index == 0)
+   return (EINVAL);
+
+   if (offsetof(struct sockaddr_dl, sdl_data) + sdl->sdl_nlen + 
sdl->sdl_alen > sdl->sdl_len)
+   return (EINVAL);
+
+   return (0);
+}
+
 static int
 cleanup_xaddrs_gateway(struct rt_addrinfo *info)
 {
struct sockaddr *gw = info->rti_info[RTAX_GATEWAY];
 
+   if (info->rti_flags & RTF_LLDATA)
+   return (cleanup_xaddrs_lladdr(info));
+
switch (gw->sa_family) {
 #ifdef INET
case AF_INET:
___
dev-commits-src-main@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-main
To unsubscribe, send any mail to "dev-commits-src-main-unsubscr...@freebsd.org"


git: f17f94cd1b99 - main - Add arp/ndp tests in addition to rtsock ll tests.

2021-02-20 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit f17f94cd1b99c61faa08aa988b47805c53b78ac7
Author: Alexander V. Chernikov 
AuthorDate: 2021-02-20 18:20:24 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-02-20 18:26:36 +

Add arp/ndp tests in addition to rtsock ll tests.
---
 tests/sys/netinet/Makefile  |   2 +-
 tests/sys/netinet/arp.sh|  97 +
 tests/sys/netinet6/Makefile |   3 +-
 tests/sys/netinet6/ndp.sh   | 115 
 4 files changed, 215 insertions(+), 2 deletions(-)

diff --git a/tests/sys/netinet/Makefile b/tests/sys/netinet/Makefile
index 7dd21c3545b5..56a1cf877135 100644
--- a/tests/sys/netinet/Makefile
+++ b/tests/sys/netinet/Makefile
@@ -10,7 +10,7 @@ ATF_TESTS_C=  ip_reass_test \
socket_afinet \
tcp_connect_port_test
 
-ATF_TESTS_SH=  carp fibs fibs_test redirect divert forward output lpm
+ATF_TESTS_SH=  carp fibs fibs_test redirect divert forward output lpm arp
 TEST_METADATA.output+= required_programs="python"
 
 PROGS= udp_dontroute tcp_user_cookie
diff --git a/tests/sys/netinet/arp.sh b/tests/sys/netinet/arp.sh
new file mode 100755
index ..8b5b30911314
--- /dev/null
+++ b/tests/sys/netinet/arp.sh
@@ -0,0 +1,97 @@
+#!/usr/bin/env atf-sh
+#-
+# SPDX-License-Identifier: BSD-2-Clause
+#
+# Copyright (c) 2021 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 "arp_add_success" "cleanup"
+arp_add_success_head() {
+   atf_set descr 'Test static arp record addition'
+   atf_set require.user root
+}
+
+arp_add_success_body() {
+
+   vnet_init
+
+   jname="v4t-arp_add_success"
+
+   epair0=$(vnet_mkepair)
+
+   vnet_mkjail ${jname} ${epair0}a
+
+   jexec ${jname} ifconfig ${epair0}a inet 198.51.100.1/24
+
+   atf_check jexec ${jname} arp -s 198.51.100.2 90:10:00:01:02:03
+
+   atf_check -o match:"\? \(198.51.100.2\) at 90:10:00:01:02:03 on 
${epair0}a permanent" jexec ${jname} arp -ni ${epair0}a 198.51.100.2
+}
+
+arp_add_success_cleanup() {
+   vnet_cleanup
+}
+
+
+atf_test_case "arp_del_success" "cleanup"
+arp_del_success_head() {
+   atf_set descr 'Test arp record deletion'
+   atf_set require.user root
+}
+
+arp_del_success_body() {
+
+   vnet_init
+
+   jname="v4t-arp_del_success"
+
+   epair0=$(vnet_mkepair)
+
+   vnet_mkjail ${jname} ${epair0}a
+
+   jexec ${jname} ifconfig ${epair0}a inet 198.51.100.1/24
+
+   jexec ${jname} ping -c1 -t1 198.51.100.2
+
+   atf_check -o match:"198.51.100.2 \(198.51.100.2\) deleted" jexec 
${jname} arp -nd 198.51.100.2
+}
+
+arp_del_success_cleanup() {
+   vnet_cleanup
+}
+
+
+atf_init_test_cases()
+{
+
+   atf_add_test_case "arp_add_success"
+   atf_add_test_case "arp_del_success"
+}
+
+# end
+
diff --git a/tests/sys/netinet6/Makefile b/tests/sys/netinet6/Makefile
index 0ad95af97c83..dfae9f698ec4 100644
--- a/tests/sys/netinet6/Makefile
+++ b/tests/sys/netinet6/Makefile
@@ -14,7 +14,8 @@ ATF_TESTS_SH= \
forward6 \
output6 \
lpm6 \
-   fibs6
+   fibs6 \
+   ndp
 TEST_METADATA.output6+=required_programs="python"
 
 ${PACKAGE}FILES+=  exthdr.py
diff --git a/tests/sys/n

git: 7563019bc693 - main - Add if_try_ref() to simplify refcount handling inside epoch.

2021-02-22 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit 7563019bc69301a382abefbac3b0fea1d876410e
Author: Alexander V. Chernikov 
AuthorDate: 2021-02-22 21:37:55 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-02-22 23:37:59 +

Add if_try_ref() to simplify refcount handling inside epoch.

When we have an ifp pointer and the code is running inside epoch,
 epoch guarantees the pointer will not be freed.
However, the following case can still happen:

* in thread 1 we drop to refcount=0 for ifp and schedule its deletion.
* in thread 2 we use this ifp and reference it
* destroy callout kicks in
* unhappy user reports a bug

This can happen with the current implementation of ifnet_byindex_ref(),
 as we're not holding any locks preventing ifnet deletion by a parallel 
thread.

To address it, add if_try_ref(), allowing to return failure when
 referencing ifp with refcount=0.
Additionally, enforce existing if_ref() is with KASSERT to provide a
 cleaner error in such scenarios.

Finally, fix ifnet_byindex_ref() by using if_try_ref() and returning NULL
 if the latter fails.

MFC after:  2 weeks
Differential Revision:  https://reviews.freebsd.org/D28836
---
 sys/net/if.c | 14 --
 sys/net/if_var.h |  1 +
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/sys/net/if.c b/sys/net/if.c
index 948be6876b65..9d5e9e26b4bb 100644
--- a/sys/net/if.c
+++ b/sys/net/if.c
@@ -359,7 +359,8 @@ ifnet_byindex_ref(u_short idx)
ifp = ifnet_byindex(idx);
if (ifp == NULL || (ifp->if_flags & IFF_DYING))
return (NULL);
-   if_ref(ifp);
+   if (!if_try_ref(ifp))
+   return (NULL);
return (ifp);
 }
 
@@ -738,9 +739,18 @@ if_free(struct ifnet *ifp)
 void
 if_ref(struct ifnet *ifp)
 {
+   u_int old;
 
/* We don't assert the ifnet list lock here, but arguably should. */
-   refcount_acquire(&ifp->if_refcount);
+   old = refcount_acquire(&ifp->if_refcount);
+   KASSERT(old > 0, ("%s: ifp %p has 0 refs", __func__, ifp));
+}
+
+bool
+if_try_ref(struct ifnet *ifp)
+{
+   NET_EPOCH_ASSERT();
+   return (refcount_acquire_if_not_zero(&ifp->if_refcount));
 }
 
 void
diff --git a/sys/net/if_var.h b/sys/net/if_var.h
index 291a7781d73c..33a737880a8d 100644
--- a/sys/net/if_var.h
+++ b/sys/net/if_var.h
@@ -661,6 +661,7 @@ voidif_link_state_change(struct ifnet *, int);
 intif_printf(struct ifnet *, const char *, ...) __printflike(2, 3);
 void   if_ref(struct ifnet *);
 void   if_rele(struct ifnet *);
+bool   if_try_ref(struct ifnet *);
 intif_setlladdr(struct ifnet *, const u_char *, int);
 intif_tunnel_check_nesting(struct ifnet *, struct mbuf *, uint32_t, int);
 void   if_up(struct ifnet *);
___
dev-commits-src-main@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-main
To unsubscribe, send any mail to "dev-commits-src-main-unsubscr...@freebsd.org"


git: 596417283722 - main - Simplify ifa/ifp refcounting in the routing stack.

2021-02-22 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit 596417283722ee62ed17aed1c875ad90c01cbb0e
Author: Alexander V. Chernikov 
AuthorDate: 2021-02-22 21:42:27 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-02-22 23:37:59 +

Simplify ifa/ifp refcounting in the routing stack.

The routing stack control depends on quite a tree of functions to
 determine the proper attributes of a route such as a source address (ifa)
 or transmit ifp of a route.

When actually inserting a route, the stack needs to ensure that ifa and ifp
 points to the entities that are still valid.
Validity means slightly more than just pointer validity - stack need 
guarantee
 that the provided objects are not scheduled for deletion.

Currently, callers either ignore it (most ifp parts, historically) or try to
 use refcounting (ifa parts). Even in case of ifa refcounting it's not 
always
 implemented in fully-safe manner. For example, some codepaths inside
 rt_getifa_fib() are referencing ifa while not holding any locks, resulting 
in
 possibility of referencing scheduled-for-deletion ifa.

Instead of trying to fix all of the callers by enforcing proper refcounting,
 switch to a different model.
As the rib_action() already requires epoch, do not require any stability 
guarantees
 other than the epoch-provided one.
Use newly-added conditional versions of the refcounting functions
 (ifa_try_ref(), if_try_ref()) and fail if any of these fails.

Reviewed by:donner
MFC after:  2 weeks
Differential Revision:  https://reviews.freebsd.org/D28837
---
 sys/net/route.c   | 14 +++
 sys/net/route/nhop_ctl.c  | 58 ++-
 sys/net/route/route_ctl.c | 17 ++---
 sys/net/route/route_ifaddrs.c | 12 ++---
 4 files changed, 42 insertions(+), 59 deletions(-)

diff --git a/sys/net/route.c b/sys/net/route.c
index a68e46c37861..d2b405fafcbf 100644
--- a/sys/net/route.c
+++ b/sys/net/route.c
@@ -207,7 +207,6 @@ rib_add_redirect(u_int fibnum, struct sockaddr *dst, struct 
sockaddr *gateway,
/* Get the best ifa for the given interface and gateway. */
if ((ifa = ifaof_ifpforaddr(gateway, ifp)) == NULL)
return (ENETUNREACH);
-   ifa_ref(ifa);
 
bzero(&info, sizeof(info));
info.rti_info[RTAX_DST] = dst;
@@ -224,7 +223,6 @@ rib_add_redirect(u_int fibnum, struct sockaddr *dst, struct 
sockaddr *gateway,
info.rti_rmx = &rti_rmx;
 
error = rib_action(fibnum, RTM_ADD, &info, &rc);
-   ifa_free(ifa);
 
if (error != 0) {
/* TODO: add per-fib redirect stats. */
@@ -518,8 +516,7 @@ rt_flushifroutes(struct ifnet *ifp)
 }
 
 /*
- * Look up rt_addrinfo for a specific fib.  Note that if rti_ifa is defined,
- * it will be referenced so the caller must free it.
+ * Look up rt_addrinfo for a specific fib.
  *
  * Assume basic consistency checks are executed by callers:
  * RTAX_DST exists, if RTF_GATEWAY is set, RTAX_GATEWAY exists as well.
@@ -528,8 +525,7 @@ int
 rt_getifa_fib(struct rt_addrinfo *info, u_int fibnum)
 {
const struct sockaddr *dst, *gateway, *ifpaddr, *ifaaddr;
-   struct epoch_tracker et;
-   int needref, error, flags;
+   int error, flags;
 
dst = info->rti_info[RTAX_DST];
gateway = info->rti_info[RTAX_GATEWAY];
@@ -542,8 +538,6 @@ rt_getifa_fib(struct rt_addrinfo *info, u_int fibnum)
 * when protocol address is ambiguous.
 */
error = 0;
-   needref = (info->rti_ifa == NULL);
-   NET_EPOCH_ENTER(et);
 
/* If we have interface specified by the ifindex in the address, use it 
*/
if (info->rti_ifp == NULL && ifpaddr != NULL &&
@@ -598,13 +592,11 @@ rt_getifa_fib(struct rt_addrinfo *info, u_int fibnum)
info->rti_ifa = ifa_ifwithroute(flags, sa, sa,
fibnum);
}
-   if (needref && info->rti_ifa != NULL) {
+   if (info->rti_ifa != NULL) {
if (info->rti_ifp == NULL)
info->rti_ifp = info->rti_ifa->ifa_ifp;
-   ifa_ref(info->rti_ifa);
} else
error = ENETUNREACH;
-   NET_EPOCH_EXIT(et);
return (error);
 }
 
diff --git a/sys/net/route/nhop_ctl.c b/sys/net/route/nhop_ctl.c
index 7de553799fab..92b43871d604 100644
--- a/sys/net/route/nhop_ctl.c
+++ b/sys/net/route/nhop_ctl.c
@@ -84,7 +84,7 @@ static int get_nhop(struct rib_head *rnh, struct rt_addrinfo 
*info,
 struct nhop_priv **pnh_priv);
 static int finalize_nhop(struct nh_control *ctl, struct rt_addrinfo *info,
 struct nhop_priv *nh_priv);
-static struct ifnet *get_aifp(const struct nhop_ob

git: 9c4a8d24f0ff - main - Fix nd6 rib_action() handling.

2021-02-23 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit 9c4a8d24f0ffd5243fa5c6fe27178f669f16d1f5
Author: Alexander V. Chernikov 
AuthorDate: 2021-02-23 22:31:07 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-02-23 22:40:01 +

Fix nd6 rib_action() handling.

rib_action() guarantees valid rc filling IFF it returns without error.
Check rib_action() return code instead of checking rc fields.

PR: 253800
Reported by:Frederic Denis 
MFC after:  immediately
---
 sys/netinet6/nd6_rtr.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/sys/netinet6/nd6_rtr.c b/sys/netinet6/nd6_rtr.c
index eca704dc2843..51b831a956bc 100644
--- a/sys/netinet6/nd6_rtr.c
+++ b/sys/netinet6/nd6_rtr.c
@@ -698,12 +698,11 @@ defrouter_addreq(struct nd_defrouter *new)
 
NET_EPOCH_ASSERT();
error = rib_action(fibnum, RTM_ADD, &info, &rc);
-   if (rc.rc_rt != NULL) {
+   if (error == 0) {
struct nhop_object *nh = nhop_select(rc.rc_nh_new, 0);
rt_routemsg(RTM_ADD, rc.rc_rt, nh, fibnum);
-   }
-   if (error == 0)
new->installed = 1;
+   }
 }
 
 /*
@@ -719,6 +718,7 @@ defrouter_delreq(struct nd_defrouter *dr)
struct rib_cmd_info rc;
struct epoch_tracker et;
unsigned int fibnum;
+   int error;
 
bzero(&def, sizeof(def));
bzero(&mask, sizeof(mask));
@@ -737,8 +737,8 @@ defrouter_delreq(struct nd_defrouter *dr)
info.rti_info[RTAX_NETMASK] = (struct sockaddr *)&mask;
 
NET_EPOCH_ENTER(et);
-   rib_action(fibnum, RTM_DELETE, &info, &rc);
-   if (rc.rc_rt != NULL) {
+   error = rib_action(fibnum, RTM_DELETE, &info, &rc);
+   if (error == 0) {
struct nhop_object *nh = nhop_select(rc.rc_nh_old, 0);
rt_routemsg(RTM_DELETE, rc.rc_rt, nh, fibnum);
}
___
dev-commits-src-main@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-main
To unsubscribe, send any mail to "dev-commits-src-main-unsubscr...@freebsd.org"


git: cc3fa1e29fda - main - Fix crash with rtadv-originated multipath IPv6 routes.

2021-02-24 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit cc3fa1e29fda2cc761e793a61cef3bd2522b3468
Author: Alexander V. Chernikov 
AuthorDate: 2021-02-24 16:42:48 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-02-24 16:44:10 +

Fix crash with rtadv-originated multipath IPv6 routes.

PR: 253800
Reported by:Frederic Denis 
MFC after:  immediately
---
 sys/netinet6/nd6_rtr.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/sys/netinet6/nd6_rtr.c b/sys/netinet6/nd6_rtr.c
index 51b831a956bc..2f721b4edcc3 100644
--- a/sys/netinet6/nd6_rtr.c
+++ b/sys/netinet6/nd6_rtr.c
@@ -61,7 +61,6 @@ __FBSDID("$FreeBSD$");
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 
@@ -699,7 +698,7 @@ defrouter_addreq(struct nd_defrouter *new)
NET_EPOCH_ASSERT();
error = rib_action(fibnum, RTM_ADD, &info, &rc);
if (error == 0) {
-   struct nhop_object *nh = nhop_select(rc.rc_nh_new, 0);
+   struct nhop_object *nh = nhop_select_func(rc.rc_nh_new, 0);
rt_routemsg(RTM_ADD, rc.rc_rt, nh, fibnum);
new->installed = 1;
}
@@ -739,7 +738,7 @@ defrouter_delreq(struct nd_defrouter *dr)
NET_EPOCH_ENTER(et);
error = rib_action(fibnum, RTM_DELETE, &info, &rc);
if (error == 0) {
-   struct nhop_object *nh = nhop_select(rc.rc_nh_old, 0);
+   struct nhop_object *nh = nhop_select_func(rc.rc_nh_old, 0);
rt_routemsg(RTM_DELETE, rc.rc_rt, nh, fibnum);
}
NET_EPOCH_EXIT(et);
___
dev-commits-src-main@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-main
To unsubscribe, send any mail to "dev-commits-src-main-unsubscr...@freebsd.org"


git: d5be41beb7c4 - main - Fix dpdk/ldradix fib lookup algorithm preference calculation.

2021-03-07 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit d5be41beb7c44119730791d92782d8e77174d312
Author: Alexander V. Chernikov 
AuthorDate: 2021-03-07 22:05:34 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-03-07 22:17:53 +

Fix dpdk/ldradix fib lookup algorithm preference calculation.

The current preference number were copied from IPv4 code,
 assuming 500k routes to be the full-view. Adjust with the current
 reality (100k full-view).

Reported by:Marek Zarychta 
MFC after:  3 days
---
 sys/contrib/dpdk_rte_lpm/dpdk_lpm6.c | 4 ++--
 sys/netinet6/in6_fib_algo.c  | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/sys/contrib/dpdk_rte_lpm/dpdk_lpm6.c 
b/sys/contrib/dpdk_rte_lpm/dpdk_lpm6.c
index 250e3e1bde4a..17d35c16346d 100644
--- a/sys/contrib/dpdk_rte_lpm/dpdk_lpm6.c
+++ b/sys/contrib/dpdk_rte_lpm/dpdk_lpm6.c
@@ -129,8 +129,8 @@ rte6_get_pref(const struct rib_rtable_info *rinfo)
return (1);
else if (rinfo->num_prefixes < 1000)
return (rinfo->num_prefixes / 10);
-   else if (rinfo->num_prefixes < 50)
-   return (100 + rinfo->num_prefixes / 3334);
+   else if (rinfo->num_prefixes < 10)
+   return (100 + rinfo->num_prefixes / 667);
else
return (250);
 }
diff --git a/sys/netinet6/in6_fib_algo.c b/sys/netinet6/in6_fib_algo.c
index c9df9387af37..04d194273168 100644
--- a/sys/netinet6/in6_fib_algo.c
+++ b/sys/netinet6/in6_fib_algo.c
@@ -118,8 +118,8 @@ lradix6_get_pref(const struct rib_rtable_info *rinfo)
 
if (rinfo->num_prefixes < 10)
return (255);
-   else if (rinfo->num_prefixes < 10)
-   return (255 - rinfo->num_prefixes / 394);
+   else if (rinfo->num_prefixes < 1)
+   return (255 - rinfo->num_prefixes / 40);
else
return (1);
 }
___
dev-commits-src-main@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-main
To unsubscribe, send any mail to "dev-commits-src-main-unsubscr...@freebsd.org"


git: 7634919e15f1 - main - Fix 'in6_purgeaddr: err=65, destination address delete failed' message.

2021-03-08 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit 7634919e15f1147b6f26d55354be375bc9b198db
Author: Alexander V. Chernikov 
AuthorDate: 2021-03-08 20:27:29 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-03-08 21:28:35 +

Fix 'in6_purgeaddr: err=65, destination address delete failed' message.

P2P ifa may require 2 routes: one is the loopback route, another is
 the "prefix" route towards its destination.

Current code marks loopback routes existence with IFA_RTSELF and
 "prefix" p2p routes with IFA_ROUTE.

For historic reasons, we fill in ifa_dstaddr for loopback interfaces.
To avoid installing the same route twice, we preemptively set
 IFA_RTSELF when adding "prefix" route for loopback.
However, the teardown part doesn't have this hack, so we try to
 remove the same route twice.

Fix this by checking if ifa_dstaddr is different from the ifa_addr
 and moving this logic into a separate function.

Reviewed By: kp
Differential Revision: https://reviews.freebsd.org/D29121
MFC after:  3 days
---
 sys/netinet6/in6.c | 32 ++--
 1 file changed, 18 insertions(+), 14 deletions(-)

diff --git a/sys/netinet6/in6.c b/sys/netinet6/in6.c
index 4665a21c28fd..02cb9df7da3a 100644
--- a/sys/netinet6/in6.c
+++ b/sys/netinet6/in6.c
@@ -1294,13 +1294,27 @@ in6_handle_dstaddr_rtrequest(int cmd, struct in6_ifaddr 
*ia)
return (error);
 }
 
+static bool
+ifa_is_p2p(struct in6_ifaddr *ia)
+{
+   int plen;
+
+   plen = in6_mask2len(&ia->ia_prefixmask.sin6_addr, NULL); /* XXX */
+
+   if ((plen == 128) && (ia->ia_dstaddr.sin6_family == AF_INET6) &&
+   !IN6_ARE_ADDR_EQUAL(&ia->ia_addr.sin6_addr, 
&ia->ia_dstaddr.sin6_addr))
+   return (true);
+
+   return (false);
+}
+
 void
 in6_purgeaddr(struct ifaddr *ifa)
 {
struct ifnet *ifp = ifa->ifa_ifp;
struct in6_ifaddr *ia = (struct in6_ifaddr *) ifa;
struct in6_multi_mship *imm;
-   int plen, error;
+   int error;
 
if (ifa->ifa_carp)
(*carp_detach_p)(ifa, false);
@@ -1328,10 +1342,7 @@ in6_purgeaddr(struct ifaddr *ifa)
free(imm, M_IP6MADDR);
}
/* Check if we need to remove p2p route */
-   plen = in6_mask2len(&ia->ia_prefixmask.sin6_addr, NULL); /* XXX */
-   if (ia->ia_dstaddr.sin6_family != AF_INET6)
-   plen = 0;
-   if ((ia->ia_flags & IFA_ROUTE) && plen == 128) {
+   if ((ia->ia_flags & IFA_ROUTE) && ifa_is_p2p(ia)) {
error = in6_handle_dstaddr_rtrequest(RTM_DELETE, ia);
if (error != 0)
log(LOG_INFO, "%s: err=%d, destination address delete "
@@ -1434,7 +1445,7 @@ static int
 in6_notify_ifa(struct ifnet *ifp, struct in6_ifaddr *ia,
 struct in6_aliasreq *ifra, int hostIsNew)
 {
-   int error = 0, plen, ifacount = 0;
+   int error = 0, ifacount = 0;
struct ifaddr *ifa;
struct sockaddr_in6 *pdst;
char ip6buf[INET6_ADDRSTRLEN];
@@ -1487,14 +1498,7 @@ in6_notify_ifa(struct ifnet *ifp, struct in6_ifaddr *ia,
 * XXX: the logic below rejects assigning multiple addresses on a p2p
 * interface that share the same destination.
 */
-   plen = in6_mask2len(&ia->ia_prefixmask.sin6_addr, NULL); /* XXX */
-   if (!(ia->ia_flags & IFA_ROUTE) && plen == 128 &&
-   ia->ia_dstaddr.sin6_family == AF_INET6) {
-   /*
-* Handle the case for ::1 .
-*/
-   if (ifp->if_flags & IFF_LOOPBACK)
-   ia->ia_flags |= IFA_RTSELF;
+   if (!(ia->ia_flags & IFA_ROUTE) && ifa_is_p2p(ia)) {
error = in6_handle_dstaddr_rtrequest(RTM_ADD, ia);
if (error)
goto done;
___
dev-commits-src-main@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-main
To unsubscribe, send any mail to "dev-commits-src-main-unsubscr...@freebsd.org"


git: b1d63265ac39 - main - Flush remaining routes from the routing table during VNET shutdown.

2021-03-10 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit b1d63265ac399112b3bca36c3d75df1a3c2c8102
Author: Alexander V. Chernikov 
AuthorDate: 2021-03-08 21:35:41 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-03-10 21:10:14 +

Flush remaining routes from the routing table during VNET shutdown.

Summary:
This fixes rtentry leak for the cloned interfaces created inside the
 VNET.

PR: 253998
Reported by:rashey at superbox.pl
MFC after:  3 days

Loopback teardown order is `SI_SUB_INIT_IF`, which happens after 
`SI_SUB_PROTO_DOMAIN` (route table teardown).
Thus, any route table operations are too late to schedule.
As the intent of the vnet teardown procedures to minimise the amount of 
effort by doing global cleanups instead of per-interface ones, address this by 
adding a relatively light-weight routing table cleanup function, 
`rib_flush_routes()`.
It removes all remaining routes from the routing table and schedules the 
deletion, which will happen later, when `rtables_destroy()` waits for the 
current epoch to finish.

Test Plan:
```
set_skip:set_skip_group_lo  ->  passed  [0.053s]
tail -n 200 /var/log/messages | grep rtentry
```

Reviewers: #network, kp, bz

Reviewed By: kp

Subscribers: imp, ae

Differential Revision: https://reviews.freebsd.org/D29116
---
 sys/net/route.c   | 15 ---
 sys/net/route.h   |  2 +-
 sys/net/route/route_ctl.c | 36 
 sys/netinet/ip_input.c|  6 +-
 sys/netinet6/ip6_input.c  |  5 +++--
 5 files changed, 41 insertions(+), 23 deletions(-)

diff --git a/sys/net/route.c b/sys/net/route.c
index d2b405fafcbf..2416aa9a983f 100644
--- a/sys/net/route.c
+++ b/sys/net/route.c
@@ -493,21 +493,6 @@ rt_ifdelroute(const struct rtentry *rt, const struct 
nhop_object *nh, void *arg)
return (1);
 }
 
-/*
- * Delete all remaining routes using this interface
- * Unfortuneatly the only way to do this is to slog through
- * the entire routing table looking for routes which point
- * to this interface...oh well...
- */
-void
-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));
-
-   rib_foreach_table_walk_del(af, rt_ifdelroute, ifp);
-}
-
 void
 rt_flushifroutes(struct ifnet *ifp)
 {
diff --git a/sys/net/route.h b/sys/net/route.h
index ab6e1aabc5ae..3fdca303596e 100644
--- a/sys/net/route.h
+++ b/sys/net/route.h
@@ -429,7 +429,6 @@ struct sockaddr *rtsock_fix_netmask(const struct sockaddr 
*dst,
 
 void   rt_updatemtu(struct ifnet *);
 
-void   rt_flushifroutes_af(struct ifnet *, int);
 void   rt_flushifroutes(struct ifnet *ifp);
 
 /* XXX MRT NEW VERSIONS THAT USE FIBs
@@ -442,6 +441,7 @@ int rib_lookup_info(uint32_t, const struct sockaddr *, 
uint32_t, uint32_t,
 void   rib_free_info(struct rt_addrinfo *info);
 
 /* New API */
+void rib_flush_routes_family(int family);
 struct nhop_object *rib_lookup(uint32_t fibnum, const struct sockaddr *dst,
uint32_t flags, uint32_t flowid);
 #endif
diff --git a/sys/net/route/route_ctl.c b/sys/net/route/route_ctl.c
index e07a94295b89..d9fd1aa18c92 100644
--- a/sys/net/route/route_ctl.c
+++ b/sys/net/route/route_ctl.c
@@ -1328,6 +1328,42 @@ rib_walk_del(u_int fibnum, int family, rib_filter_f_t 
*filter_f, void *arg, bool
NET_EPOCH_EXIT(et);
 }
 
+static int
+rt_delete_unconditional(struct radix_node *rn, void *arg)
+{
+   struct rtentry *rt = RNTORT(rn);
+   struct rib_head *rnh = (struct rib_head *)arg;
+
+   rn = rnh->rnh_deladdr(rt_key(rt), rt_mask(rt), &rnh->head);
+   if (RNTORT(rn) == rt)
+   rtfree(rt);
+
+   return (0);
+}
+
+/*
+ * Removes all routes from the routing table without executing notifications.
+ * rtentres will be removed after the end of a current epoch.
+ */
+static void
+rib_flush_routes(struct rib_head *rnh)
+{
+   RIB_WLOCK(rnh);
+   rnh->rnh_walktree(&rnh->head, rt_delete_unconditional, rnh);
+   RIB_WUNLOCK(rnh);
+}
+
+void
+rib_flush_routes_family(int family)
+{
+   struct rib_head *rnh;
+
+   for (uint32_t fibnum = 0; fibnum < rt_numfibs; fibnum++) {
+   if ((rnh = rt_tables_get_rnh(fibnum, family)) != NULL)
+   rib_flush_routes(rnh);
+   }
+}
+
 static void
 rib_notify(struct rib_head *rnh, enum rib_subscription_type type,
 struct rib_cmd_info *rc)
diff --git a/sys/netinet/ip_input.c b/sys/netinet/ip_input.c
index be21decff6cb..a85f8ac7b567 100644
--- a/sys/netinet/ip_input.c
+++ b/sys/netinet/ip_input.c
@@ -379,7 +379,6 @@ ip_init(void)
 static void
 ip_destroy(void *unused __unused)
 {
-   struct ifnet *ifp;
int error;
 
 #ifdef R

git: e4ac3f746377 - main - Fix fib algo rebuild delay calculation.

2021-03-15 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit e4ac3f74637778981b2d89745188bb2a39e24e42
Author: Alexander V. Chernikov 
AuthorDate: 2021-03-15 21:09:07 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-03-15 21:09:07 +

Fix fib algo rebuild delay calculation.

Submitted by:   Marco Zec 
MFC after:  3 days
---
 sys/net/route/fib_algo.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sys/net/route/fib_algo.c b/sys/net/route/fib_algo.c
index b2aa2de087de..03c265d28d09 100644
--- a/sys/net/route/fib_algo.c
+++ b/sys/net/route/fib_algo.c
@@ -462,7 +462,7 @@ static void
 schedule_callout(struct fib_data *fd, int delay_ms)
 {
 
-   callout_reset_sbt(&fd->fd_callout, 0, SBT_1MS * delay_ms,
+   callout_reset_sbt(&fd->fd_callout, SBT_1MS * delay_ms, 0,
rebuild_fd_callout, fd, 0);
 }
 
___
dev-commits-src-main@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-main
To unsubscribe, send any mail to "dev-commits-src-main-unsubscr...@freebsd.org"


git: 2476178e6b09 - main - Fix kassert panic when inserting multipath routes from multiple threads.

2021-03-21 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit 2476178e6b09acc8d0fe6b1fb9c1b6f2981f766e
Author: Alexander V. Chernikov 
AuthorDate: 2021-03-21 18:15:29 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-03-21 18:15:29 +

Fix kassert panic when inserting multipath routes from multiple threads.

Reported by:Marco Zec 
MFC after:  immediately
---
 sys/net/route/nhgrp_ctl.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/sys/net/route/nhgrp_ctl.c b/sys/net/route/nhgrp_ctl.c
index c2119506370f..b329b907144f 100644
--- a/sys/net/route/nhgrp_ctl.c
+++ b/sys/net/route/nhgrp_ctl.c
@@ -488,7 +488,9 @@ get_nhgrp(struct nh_control *ctl, struct weightened_nhop 
*wn, int num_nhops,
if (link_nhgrp(ctl, key) == 0) {
/* Unable to allocate index? */
*perror = EAGAIN;
-   destroy_nhgrp(key);
+   free_nhgrp_nhops(key);
+   destroy_nhgrp_int(key);
+   return (NULL);
}
*perror = 0;
return (key);
___
dev-commits-src-main@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-main
To unsubscribe, send any mail to "dev-commits-src-main-unsubscr...@freebsd.org"


git: a0308e48ec12 - main - Fix panic when destroying interface with ECMP routes.

2021-03-23 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit a0308e48ec12ae37f525aa3c6d3c1a236fb55dcd
Author: Alexander V. Chernikov 
AuthorDate: 2021-03-23 22:00:04 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-03-23 22:03:20 +

Fix panic when destroying interface with ECMP routes.

Reported by:Zhenlei Huang 
PR: 254496
MFC after:  immediately
---
 sys/net/route/route_ctl.c | 11 ++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/sys/net/route/route_ctl.c b/sys/net/route/route_ctl.c
index d9fd1aa18c92..d3a35018ae66 100644
--- a/sys/net/route/route_ctl.c
+++ b/sys/net/route/route_ctl.c
@@ -130,13 +130,22 @@ vnet_rtzone_destroy()
 static void
 destroy_rtentry(struct rtentry *rt)
 {
+   struct nhop_object *nh = rt->rt_nhop;
 
/*
 * 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));
+#ifdef ROUTE_MPATH
+   if (NH_IS_NHGRP(nh)) {
+   struct weightened_nhop *wn;
+   uint32_t num_nhops;
+   wn = nhgrp_get_nhops((struct nhgrp_object *)nh, &num_nhops);
+   nh = wn[0].nh;
+   }
+#endif
+   CURVNET_SET(nhop_get_vnet(nh));
 
/* Unreference nexthop */
nhop_free_any(rt->rt_nhop);
___
dev-commits-src-main@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-main
To unsubscribe, send any mail to "dev-commits-src-main-unsubscr...@freebsd.org"


git: c00e2f573b50 - main - Fix build for non-vnet non-multipath kernels broken by a0308e48ec12ae37f525aa3c6d3c1a236fb55dcd.

2021-03-23 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit c00e2f573b50893e7428aee4b928c95ac27b7e5e
Author: Alexander V. Chernikov 
AuthorDate: 2021-03-23 23:35:23 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-03-23 23:35:23 +

Fix build for non-vnet non-multipath kernels broken by
 a0308e48ec12ae37f525aa3c6d3c1a236fb55dcd.
---
 sys/net/route/route_ctl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sys/net/route/route_ctl.c b/sys/net/route/route_ctl.c
index d3a35018ae66..92c7db1d5e29 100644
--- a/sys/net/route/route_ctl.c
+++ b/sys/net/route/route_ctl.c
@@ -148,7 +148,7 @@ destroy_rtentry(struct rtentry *rt)
CURVNET_SET(nhop_get_vnet(nh));
 
/* Unreference nexthop */
-   nhop_free_any(rt->rt_nhop);
+   nhop_free_any(nh);
 
uma_zfree(V_rtzone, rt);
 
___
dev-commits-src-main@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-main
To unsubscribe, send any mail to "dev-commits-src-main-unsubscr...@freebsd.org"


git: 66f138563bec - main - Plug nexthop group refcount leak. In case with batch route delete via rib_walk_del(), when some paths from the multipath route gets deleted, old multipath group were not f

2021-03-24 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit 66f138563becf12d5c21924f816d2a45c3a1ed7a
Author: Alexander V. Chernikov 
AuthorDate: 2021-03-24 23:51:45 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-03-24 23:52:18 +

Plug nexthop group refcount leak.
In case with batch route delete via rib_walk_del(), when
 some paths from the multipath route gets deleted, old
 multipath group were not freed.

PR:254496
Reported by:   Zhenlei Huang 
MFC after: 1 day
---
 sys/net/route/route_ctl.c | 18 ++
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/sys/net/route/route_ctl.c b/sys/net/route/route_ctl.c
index 92c7db1d5e29..36f4afaae648 100644
--- a/sys/net/route/route_ctl.c
+++ b/sys/net/route/route_ctl.c
@@ -130,6 +130,7 @@ vnet_rtzone_destroy()
 static void
 destroy_rtentry(struct rtentry *rt)
 {
+#ifdef VIMAGE
struct nhop_object *nh = rt->rt_nhop;
 
/*
@@ -146,9 +147,10 @@ destroy_rtentry(struct rtentry *rt)
}
 #endif
CURVNET_SET(nhop_get_vnet(nh));
+#endif
 
/* Unreference nexthop */
-   nhop_free_any(nh);
+   nhop_free_any(rt->rt_nhop);
 
uma_zfree(V_rtzone, rt);
 
@@ -1239,7 +1241,6 @@ 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;
@@ -1248,7 +1249,8 @@ rt_checkdelroute(struct radix_node *rn, void *arg)
info->rti_info[RTAX_DST] = rt_key(rt);
info->rti_info[RTAX_NETMASK] = rt_mask(rt);
 
-   error = rt_unlinkrte(di->rnh, info, &di->rc);
+   if (rt_unlinkrte(di->rnh, info, &di->rc) != 0)
+   return (0);
 
/*
 * Add deleted rtentries to the list to GC them
@@ -1257,11 +1259,19 @@ rt_checkdelroute(struct radix_node *rn, void *arg)
 * XXX: Delayed notifications not implemented
 *  for nexthop updates.
 */
-   if ((error == 0) && (di->rc.rc_cmd == RTM_DELETE)) {
+   if (di->rc.rc_cmd == RTM_DELETE) {
/* Add to the list and return */
rt->rt_chain = di->head;
di->head = rt;
+#ifdef ROUTE_MPATH
+   } else {
+   /*
+* RTM_CHANGE to a diferent nexthop or nexthop group.
+* Free old multipath group.
+*/
+   nhop_free_any(di->rc.rc_nh_old);
}
+#endif
 
return (0);
 }
___
dev-commits-src-main@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-main
To unsubscribe, send any mail to "dev-commits-src-main-unsubscr...@freebsd.org"


git: 24cd2796cf10 - main - Fix !VNET build broken by 66f138563becf12d5c21924f816d2a45c3a1ed7a.

2021-03-24 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit 24cd2796cf10211964be8a2cb3ea3e161adea746
Author: Alexander V. Chernikov 
AuthorDate: 2021-03-25 00:30:41 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-03-25 00:31:08 +

Fix !VNET build broken by 66f138563becf12d5c21924f816d2a45c3a1ed7a.
---
 sys/net/route/route_ctl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sys/net/route/route_ctl.c b/sys/net/route/route_ctl.c
index 36f4afaae648..fb3dfff87019 100644
--- a/sys/net/route/route_ctl.c
+++ b/sys/net/route/route_ctl.c
@@ -1270,8 +1270,8 @@ rt_checkdelroute(struct radix_node *rn, void *arg)
 * Free old multipath group.
 */
nhop_free_any(di->rc.rc_nh_old);
-   }
 #endif
+   }
 
return (0);
 }
___
dev-commits-src-main@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-main
To unsubscribe, send any mail to "dev-commits-src-main-unsubscr...@freebsd.org"


git: 6f43c72b472e - main - Zero `struct weightened_nhop` fields in nhgrp_get_addition_group().

2021-03-27 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit 6f43c72b472ee78e04f1ebd347ca0ae7787ee876
Author: Alexander V. Chernikov 
AuthorDate: 2021-03-20 08:26:03 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-03-20 08:26:03 +

Zero `struct weightened_nhop` fields in nhgrp_get_addition_group().

`struct weightened_nhop` has spare 32bit between the fields due to
 the alignment (on amd64).
Not zeroing these spare bits results in duplicating nhop groups
 in the kernel due to the way how comparison works.

MFC after:  1 day
---
 sys/net/route/nhgrp_ctl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sys/net/route/nhgrp_ctl.c b/sys/net/route/nhgrp_ctl.c
index b329b907144f..b228c3bcee37 100644
--- a/sys/net/route/nhgrp_ctl.c
+++ b/sys/net/route/nhgrp_ctl.c
@@ -646,7 +646,7 @@ nhgrp_get_addition_group(struct rib_head *rh, struct 
route_nhop_data *rnd_orig,
 {
struct nh_control *ctl = rh->nh_control;
struct nhgrp_priv *nhg_priv;
-   struct weightened_nhop wn[2];
+   struct weightened_nhop wn[2] = {};
int error;
 
if (rnd_orig->rnd_nhop == NULL) {
___
dev-commits-src-main@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-main
To unsubscribe, send any mail to "dev-commits-src-main-unsubscr...@freebsd.org"


git: 9095dc7da4cf - main - Fix nexhtop group index array scaling.

2021-03-29 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit 9095dc7da4cf0c484fb1160b2180b7329b09b107
Author: Alexander V. Chernikov 
AuthorDate: 2021-03-29 23:00:17 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-03-29 23:00:17 +

Fix nexhtop group index array scaling.

The current code has the limit of 127 nexthop groups due to the
 wrongly-checked bitmask_copy() return value.

PR: 254303
Reported by:Aleks 
MFC after: 1 day
---
 sys/net/route/nhgrp.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/sys/net/route/nhgrp.c b/sys/net/route/nhgrp.c
index c25f4f09865b..f6638b12ebea 100644
--- a/sys/net/route/nhgrp.c
+++ b/sys/net/route/nhgrp.c
@@ -243,8 +243,8 @@ consider_resize(struct nh_control *ctl, uint32_t 
new_nh_buckets, uint32_t new_id
CHT_SLIST_RESIZE(&ctl->gr_head, mpath, nh_ptr, new_nh_buckets);
}
if (nh_idx_ptr != NULL) {
-   if (bitmask_copy(&ctl->gr_idx_head, nh_idx_ptr, new_idx_items))
-   bitmask_swap(&ctl->nh_idx_head, nh_idx_ptr, 
new_idx_items, &old_idx_ptr);
+   if (bitmask_copy(&ctl->gr_idx_head, nh_idx_ptr, new_idx_items) 
== 0)
+   bitmask_swap(&ctl->gr_idx_head, nh_idx_ptr, 
new_idx_items, &old_idx_ptr);
}
NHOPS_WUNLOCK(ctl);
 
___
dev-commits-src-main@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-main
To unsubscribe, send any mail to "dev-commits-src-main-unsubscr...@freebsd.org"


git: 0f30a36dedef - main - Rename variables inside nexhtop group consider_resize() code.

2021-03-29 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit 0f30a36dedef43781f5003bdfcb4254d310f02e4
Author: Alexander V. Chernikov 
AuthorDate: 2021-03-29 23:06:13 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-03-29 23:06:13 +

Rename variables inside nexhtop group consider_resize() code.

No functional changes.

MFC after: 3 days
---
 sys/net/route/nhgrp.c | 40 
 1 file changed, 20 insertions(+), 20 deletions(-)

diff --git a/sys/net/route/nhgrp.c b/sys/net/route/nhgrp.c
index f6638b12ebea..f763cc25fd5c 100644
--- a/sys/net/route/nhgrp.c
+++ b/sys/net/route/nhgrp.c
@@ -82,7 +82,7 @@
  *
  */
 
-static void consider_resize(struct nh_control *ctl, uint32_t new_nh_buckets,
+static void consider_resize(struct nh_control *ctl, uint32_t new_gr_buckets,
 uint32_t new_idx_items);
 
 static int cmp_nhgrp(const struct nhgrp_priv *a, const struct nhgrp_priv *b);
@@ -209,47 +209,47 @@ unlink_nhgrp(struct nh_control *ctl, struct nhgrp_priv 
*key)
  * Checks if hash needs resizing and performs this resize if necessary
  *
  */
-__noinline static void
-consider_resize(struct nh_control *ctl, uint32_t new_nh_buckets, uint32_t 
new_idx_items)
+static void
+consider_resize(struct nh_control *ctl, uint32_t new_gr_bucket, uint32_t 
new_idx_items)
 {
-   void *nh_ptr, *nh_idx_ptr;
+   void *gr_ptr, *gr_idx_ptr;
void *old_idx_ptr;
size_t alloc_size;
 
-   nh_ptr = NULL ;
-   if (new_nh_buckets != 0) {
-   alloc_size = CHT_SLIST_GET_RESIZE_SIZE(new_nh_buckets);
-   nh_ptr = malloc(alloc_size, M_NHOP, M_NOWAIT | M_ZERO);
+   gr_ptr = NULL ;
+   if (new_gr_bucket != 0) {
+   alloc_size = CHT_SLIST_GET_RESIZE_SIZE(new_gr_bucket);
+   gr_ptr = malloc(alloc_size, M_NHOP, M_NOWAIT | M_ZERO);
}
 
-   nh_idx_ptr = NULL;
+   gr_idx_ptr = NULL;
if (new_idx_items != 0) {
alloc_size = bitmask_get_size(new_idx_items);
-   nh_idx_ptr = malloc(alloc_size, M_NHOP, M_NOWAIT | M_ZERO);
+   gr_idx_ptr = malloc(alloc_size, M_NHOP, M_NOWAIT | M_ZERO);
}
 
-   if (nh_ptr == NULL && nh_idx_ptr == NULL) {
+   if (gr_ptr == NULL && gr_idx_ptr == NULL) {
/* Either resize is not required or allocations have failed. */
return;
}
 
-   DPRINTF("mp: going to resize: nh:[ptr:%p sz:%u] idx:[ptr:%p sz:%u]",
-   nh_ptr, new_nh_buckets, nh_idx_ptr, new_idx_items);
+   DPRINTF("mp: going to resize: gr:[ptr:%p sz:%u] idx:[ptr:%p sz:%u]",
+   gr_ptr, new_gr_bucket, gr_idx_ptr, new_idx_items);
 
old_idx_ptr = NULL;
 
NHOPS_WLOCK(ctl);
-   if (nh_ptr != NULL) {
-   CHT_SLIST_RESIZE(&ctl->gr_head, mpath, nh_ptr, new_nh_buckets);
+   if (gr_ptr != NULL) {
+   CHT_SLIST_RESIZE(&ctl->gr_head, mpath, gr_ptr, new_gr_bucket);
}
-   if (nh_idx_ptr != NULL) {
-   if (bitmask_copy(&ctl->gr_idx_head, nh_idx_ptr, new_idx_items) 
== 0)
-   bitmask_swap(&ctl->gr_idx_head, nh_idx_ptr, 
new_idx_items, &old_idx_ptr);
+   if (gr_idx_ptr != NULL) {
+   if (bitmask_copy(&ctl->gr_idx_head, gr_idx_ptr, new_idx_items) 
== 0)
+   bitmask_swap(&ctl->gr_idx_head, gr_idx_ptr, 
new_idx_items, &old_idx_ptr);
}
NHOPS_WUNLOCK(ctl);
 
-   if (nh_ptr != NULL)
-   free(nh_ptr, M_NHOP);
+   if (gr_ptr != NULL)
+   free(gr_ptr, M_NHOP);
if (old_idx_ptr != NULL)
free(old_idx_ptr, M_NHOP);
 }
___
dev-commits-src-main@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-main
To unsubscribe, send any mail to "dev-commits-src-main-unsubscr...@freebsd.org"


git: 9fa8d1582b44 - main - Put bandaid for nhgrp_dump_sysctl() malloc KASSERT().

2021-03-29 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit 9fa8d1582b44b4850d40699c9adb104732328b7d
Author: Alexander V. Chernikov 
AuthorDate: 2021-03-29 23:12:11 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-03-29 23:12:11 +

Put bandaid for nhgrp_dump_sysctl() malloc KASSERT().

Recent rtsock changes widened epoch and covered nhgrp_dump_sysctl(),
  resulting in `netstat -4On` triggering with KASSERT.

MFC after:  1 day
---
 sys/net/route/nhgrp_ctl.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/sys/net/route/nhgrp_ctl.c b/sys/net/route/nhgrp_ctl.c
index b228c3bcee37..2896730458b5 100644
--- a/sys/net/route/nhgrp_ctl.c
+++ b/sys/net/route/nhgrp_ctl.c
@@ -806,7 +806,9 @@ nhgrp_dump_sysctl(struct rib_head *rh, struct sysctl_req *w)
sz = sizeof(struct rt_msghdr) + sizeof(struct nhgrp_external);
sz += 2 * sizeof(struct nhgrp_container);
sz += 2 * sizeof(struct nhgrp_nhop_external) * RIB_MAX_MPATH_WIDTH;
-   buffer = malloc(sz, M_TEMP, M_WAITOK);
+   buffer = malloc(sz, M_TEMP, M_MOWAIT);
+   if (buffer == NULL)
+   return (ENOMEM);
 
NET_EPOCH_ENTER(et);
NHOPS_RLOCK(ctl);
___
dev-commits-src-main@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-main
To unsubscribe, send any mail to "dev-commits-src-main-unsubscr...@freebsd.org"


git: 0c2a0e038002 - main - Fix typo in the 9fa8d1582b44b4850d40699c9adb104732328b7d.

2021-03-29 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit 0c2a0e038002cba423161aeed8f358ffb4fb2836
Author: Alexander V. Chernikov 
AuthorDate: 2021-03-29 23:42:27 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-03-29 23:42:48 +

Fix typo in the 9fa8d1582b44b4850d40699c9adb104732328b7d.

Reported by:cy
---
 sys/net/route/nhgrp_ctl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sys/net/route/nhgrp_ctl.c b/sys/net/route/nhgrp_ctl.c
index 2896730458b5..49866499ac86 100644
--- a/sys/net/route/nhgrp_ctl.c
+++ b/sys/net/route/nhgrp_ctl.c
@@ -806,7 +806,7 @@ nhgrp_dump_sysctl(struct rib_head *rh, struct sysctl_req *w)
sz = sizeof(struct rt_msghdr) + sizeof(struct nhgrp_external);
sz += 2 * sizeof(struct nhgrp_container);
sz += 2 * sizeof(struct nhgrp_nhop_external) * RIB_MAX_MPATH_WIDTH;
-   buffer = malloc(sz, M_TEMP, M_MOWAIT);
+   buffer = malloc(sz, M_TEMP, M_NOWAIT);
if (buffer == NULL)
return (ENOMEM);
 
___
dev-commits-src-main@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-main
To unsubscribe, send any mail to "dev-commits-src-main-unsubscr...@freebsd.org"


Re: git: 9fa8d1582b44 - main - Put bandaid for nhgrp_dump_sysctl() malloc KASSERT().

2021-03-29 Thread Alexander V. Chernikov



> On 30 Mar 2021, at 00:32, Cy Schubert  wrote:
> 
> In message <202103292315.12tnffmz050...@gitrepo.freebsd.org>, "Alexander V. 
> Che
> rnikov" writes:
>> The branch main has been updated by melifaro:
>> 
>> URL: https://cgit.FreeBSD.org/src/commit/?id=9fa8d1582b44b4850d40699c9adb1047
>> 32328b7d
>> 
>> commit 9fa8d1582b44b4850d40699c9adb104732328b7d
>> Author: Alexander V. Chernikov 
>> AuthorDate: 2021-03-29 23:12:11 +
>> Commit: Alexander V. Chernikov 
>> CommitDate: 2021-03-29 23:12:11 +
>> 
>>Put bandaid for nhgrp_dump_sysctl() malloc KASSERT().
>> 
>>Recent rtsock changes widened epoch and covered nhgrp_dump_sysctl(),
>>  resulting in `netstat -4On` triggering with KASSERT.
>> 
>>MFC after:  1 day
>> ---
>> sys/net/route/nhgrp_ctl.c | 4 +++-
>> 1 file changed, 3 insertions(+), 1 deletion(-)
>> 
>> diff --git a/sys/net/route/nhgrp_ctl.c b/sys/net/route/nhgrp_ctl.c
>> index b228c3bcee37..2896730458b5 100644
>> --- a/sys/net/route/nhgrp_ctl.c
>> +++ b/sys/net/route/nhgrp_ctl.c
>> @@ -806,7 +806,9 @@ nhgrp_dump_sysctl(struct rib_head *rh, struct sysctl_req 
>> *w)
>>  sz = sizeof(struct rt_msghdr) + sizeof(struct nhgrp_external);
>>  sz += 2 * sizeof(struct nhgrp_container);
>>  sz += 2 * sizeof(struct nhgrp_nhop_external) * RIB_MAX_MPATH_WIDTH;
>> -buffer = malloc(sz, M_TEMP, M_WAITOK);
>> +buffer = malloc(sz, M_TEMP, M_MOWAIT);
>  ^
> This appears to be a typo.
Fixed typo, build, tested but forgot to amend the commit.
0c2a0e038002cba423161aeed8f358ffb4fb2836 should fix it.
> 
>> +if (buffer == NULL)
>> +return (ENOMEM);
>> 
>>  NET_EPOCH_ENTER(et);
>>  NHOPS_RLOCK(ctl);
>> 
> 
> 
> 
> -- 
> 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.

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


git: b8598e2ff65a - main - Add IPv4 fib lookup performance tests with uniform keys.

2021-03-30 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit b8598e2ff65ab82da0cf6861ee12f078b40bc252
Author: Alexander V. Chernikov 
AuthorDate: 2021-03-30 12:43:55 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-03-30 13:32:28 +

Add IPv4 fib lookup performance tests with uniform keys.

Submitted by:   zec
MFC after:  1 week
---
 sys/tests/fib_lookup/fib_lookup.c | 52 +++
 1 file changed, 52 insertions(+)

diff --git a/sys/tests/fib_lookup/fib_lookup.c 
b/sys/tests/fib_lookup/fib_lookup.c
index 3dd1bb8d5a50..ea07e3d697c6 100644
--- a/sys/tests/fib_lookup/fib_lookup.c
+++ b/sys/tests/fib_lookup/fib_lookup.c
@@ -505,6 +505,58 @@ SYSCTL_PROC(_net_route_test, OID_AUTO, run_inet_scan,
 CTLFLAG_VNET | CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE,
 0, 0, run_test_inet_scan, "I", "Execute fib4_lookup scan tests");
 
+static int
+rnd_lps(SYSCTL_HANDLER_ARGS)
+{
+   struct epoch_tracker et;
+   struct in_addr *keys;
+   struct nhop_object **nhops;
+
+   struct timespec ts_pre, ts_post;
+   uint64_t total_diff, lps;
+   int error;
+   int count = 0;
+
+   error = sysctl_handle_int(oidp, &count, 0, req);
+   if (error != 0)
+   return (error);
+   if (count <= 0)
+   return (0);
+
+   keys = malloc(sizeof(*keys) * count, M_TEMP, M_NOWAIT);
+   nhops = malloc(sizeof(*nhops) * count, M_TEMP, M_NOWAIT);
+   if (keys == NULL || nhops == NULL) {
+   free(keys, M_TEMP);
+   free(nhops, M_TEMP);
+   return (ENOMEM);
+   }
+
+   printf("Preparing %d random keys...\n", count);
+   arc4random_buf(keys, sizeof(*keys) * count);
+   printf("Starting LPS test...\n");
+
+   NET_EPOCH_ENTER(et);
+   nanouptime(&ts_pre);
+   for (int i = 0; i < count; i++)
+   nhops[i] = fib4_lookup(RT_DEFAULT_FIB, keys[i], 0, NHR_NONE, 0);
+   nanouptime(&ts_post);
+   NET_EPOCH_EXIT(et);
+
+   free(keys, M_TEMP);
+   free(nhops, M_TEMP);
+
+   total_diff = (ts_post.tv_sec - ts_pre.tv_sec) * 10 +
+   (ts_post.tv_nsec - ts_pre.tv_nsec);
+   lps = 10ULL * count / total_diff;
+   printf("%d lookups in %zu nanoseconds, %lu.%06lu MLPS\n",
+   count, total_diff, lps / 100, lps % 100);
+
+   return (0);
+}
+SYSCTL_PROC(_net_route_test, OID_AUTO, rnd_lps,
+CTLFLAG_VNET | CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE,
+0, 0, rnd_lps, "I",
+"Measure lookups per second using uniformly random keys");
 
 static int
 test_fib_lookup_modevent(module_t mod, int type, void *unused)
___
dev-commits-src-main@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-main
To unsubscribe, send any mail to "dev-commits-src-main-unsubscr...@freebsd.org"


git: 4084b1ab0413 - main - Fix `netstat -rs` reporting.

2021-03-31 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit 4084b1ab0413d15dab496b1c24c3875601c71438
Author: Alexander V. Chernikov 
AuthorDate: 2021-03-31 20:56:26 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-03-31 20:59:10 +

Fix `netstat -rs` reporting.

rttrash (unused but not yet delete entries) were eliminated
 during routing rework. Remove reading these symbols from the kernel.

PR: 254681
Reported by:ras...@superbox.pl
MFC after:  immediately
---
 usr.bin/netstat/nlist_symbols |  1 -
 usr.bin/netstat/route.c   | 13 +
 2 files changed, 1 insertion(+), 13 deletions(-)

diff --git a/usr.bin/netstat/nlist_symbols b/usr.bin/netstat/nlist_symbols
index afad45d353bd..1c09d81c0b98 100644
--- a/usr.bin/netstat/nlist_symbols
+++ b/usr.bin/netstat/nlist_symbols
@@ -39,7 +39,6 @@ all   _rip6stat
 all_ripcbinfo
 all_rtree
 all_rtstat
-all_rttrash
 all_sctpstat
 all_sfstat
 all_tcbinfo
diff --git a/usr.bin/netstat/route.c b/usr.bin/netstat/route.c
index ba47a4b56ac5..317e3ffb9607 100644
--- a/usr.bin/netstat/route.c
+++ b/usr.bin/netstat/route.c
@@ -699,19 +699,13 @@ void
 rt_stats(void)
 {
struct rtstat rtstat;
-   u_long rtsaddr, rttaddr;
-   int rttrash;
+   u_long rtsaddr;
 
if ((rtsaddr = nl[N_RTSTAT].n_value) == 0) {
xo_emit("{W:rtstat: symbol not in namelist}\n");
return;
}
-   if ((rttaddr = nl[N_RTTRASH].n_value) == 0) {
-   xo_emit("{W:rttrash: symbol not in namelist}\n");
-   return;
-   }
kread_counters(rtsaddr, (char *)&rtstat, sizeof (rtstat));
-   kread(rttaddr, (char *)&rttrash, sizeof (rttrash));
xo_emit("{T:routing}:\n");
 
 #definep(f, m) if (rtstat.f || sflag <= 1) \
@@ -728,9 +722,4 @@ rt_stats(void)
p(rts_wildcard, "\t{:wildcard-uses/%ju} "
"{N:/use%s of a wildcard route}\n");
 #undef p
-
-   if (rttrash || sflag <= 1)
-   xo_emit("\t{:unused-but-not-freed/%u} "
-   "{N:/route%s not in table but not freed}\n",
-   rttrash, plural(rttrash));
 }
___
dev-commits-src-main@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-main
To unsubscribe, send any mail to "dev-commits-src-main-unsubscr...@freebsd.org"


git: 9e5243d7b659 - main - Enforce check for using the return result for ifa?_try_ref().

2021-04-08 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit 9e5243d7b65939c3d3dbf844616084e9580876dd
Author: Alexander V. Chernikov 
AuthorDate: 2021-03-30 14:03:28 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-04-05 02:35:19 +

Enforce check for using the return result for ifa?_try_ref().

Suggested by:   hps
MFC after:  1 week
Differential Revision:  https://reviews.freebsd.org/D29504
---
 sys/net/if_var.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/sys/net/if_var.h b/sys/net/if_var.h
index 1f82dd028379..052ec6b407a0 100644
--- a/sys/net/if_var.h
+++ b/sys/net/if_var.h
@@ -577,7 +577,7 @@ struct ifaddr {
 struct ifaddr *ifa_alloc(size_t size, int flags);
 void   ifa_free(struct ifaddr *ifa);
 void   ifa_ref(struct ifaddr *ifa);
-intifa_try_ref(struct ifaddr *ifa);
+int __result_use_check ifa_try_ref(struct ifaddr *ifa);
 
 /*
  * Multicast address structure.  This is analogous to the ifaddr
@@ -662,7 +662,7 @@ int if_printf(struct ifnet *, const char *, ...) 
__printflike(2, 3);
 intif_log(struct ifnet *, int, const char *, ...) __printflike(3, 4);
 void   if_ref(struct ifnet *);
 void   if_rele(struct ifnet *);
-bool   if_try_ref(struct ifnet *);
+bool   __result_use_check if_try_ref(struct ifnet *);
 intif_setlladdr(struct ifnet *, const u_char *, int);
 intif_tunnel_check_nesting(struct ifnet *, struct mbuf *, uint32_t, int);
 void   if_up(struct ifnet *);
___
dev-commits-src-main@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-main
To unsubscribe, send any mail to "dev-commits-src-main-unsubscr...@freebsd.org"


git: ee2cf2b3609e - main - Implement better rebuild-delay fib algo policy.

2021-04-09 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit ee2cf2b3609ee179f39080e0ebe8bf79dcb13461
Author: Alexander V. Chernikov 
AuthorDate: 2021-04-09 20:25:47 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-04-09 20:33:03 +

Implement better rebuild-delay fib algo policy.

The intent is to better handle time intervals with large amount of RIB
updates (e.g. BGP peer going up or down), while still keeping low sync
delay for the rest scenarios.

The implementation is the following: updates are bucketed into the
buckets of size 50ms. If the number of updates within a current bucket
 exceeds the threshold of 500 routes/sec (e.g. 10 updates per bucket
interval), the update is delayed for another 50ms. This can be repeated
 until the maximum update delay (1 sec) is reached.

All 3 variables are runtime tunables:

* net.route.algo.fib_max_sync_delay_ms: 1000
* net.route.algo.bucket_change_threshold_rate: 500
* net.route.algo.bucket_time_ms: 50

Differential Review:https://reviews.freebsd.org/D29588
MFC after:  2 weeks
---
 sys/net/route/fib_algo.c | 289 +--
 1 file changed, 228 insertions(+), 61 deletions(-)

diff --git a/sys/net/route/fib_algo.c b/sys/net/route/fib_algo.c
index 03c265d28d09..622026668764 100644
--- a/sys/net/route/fib_algo.c
+++ b/sys/net/route/fib_algo.c
@@ -105,10 +105,26 @@ SYSCTL_DECL(_net_route);
 SYSCTL_NODE(_net_route, OID_AUTO, algo, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
 "Fib algorithm lookups");
 
-VNET_DEFINE(int, fib_sync_limit) = 100;
-#defineV_fib_sync_limitVNET(fib_sync_limit)
-SYSCTL_INT(_net_route_algo, OID_AUTO, fib_sync_limit, CTLFLAG_RW | 
CTLFLAG_VNET,
-&VNET_NAME(fib_sync_limit), 0, "Guarantee synchronous fib till route 
limit");
+/* Algorithm sync policy */
+
+/* Time interval to bucket updates */
+VNET_DEFINE(unsigned int, bucket_time_ms) = 50;
+#defineV_bucket_time_msVNET(bucket_time_ms)
+SYSCTL_UINT(_net_route_algo, OID_AUTO, bucket_time_ms, CTLFLAG_RW | 
CTLFLAG_VNET,
+&VNET_NAME(bucket_time_ms), 0, "Time interval to calculate update rate");
+
+/* Minimum update rate to delay sync */
+VNET_DEFINE(unsigned int, bucket_change_threshold_rate) = 500;
+#defineV_bucket_change_threshold_rate  
VNET(bucket_change_threshold_rate)
+SYSCTL_UINT(_net_route_algo, OID_AUTO, bucket_change_threshold_rate, 
CTLFLAG_RW | CTLFLAG_VNET,
+&VNET_NAME(bucket_change_threshold_rate), 0, "Minimum update rate to delay 
sync");
+
+/* Max allowed delay to sync */
+VNET_DEFINE(unsigned int, fib_max_sync_delay_ms) = 1000;
+#defineV_fib_max_sync_delay_ms VNET(fib_max_sync_delay_ms)
+SYSCTL_UINT(_net_route_algo, OID_AUTO, fib_max_sync_delay_ms, CTLFLAG_RW | 
CTLFLAG_VNET,
+&VNET_NAME(fib_max_sync_delay_ms), 0, "Maximum time to delay sync (ms)");
+
 
 #ifdef INET6
 VNET_DEFINE_STATIC(bool, algo_fixed_inet6) = false;
@@ -131,6 +147,19 @@ struct nhop_ref_table {
int32_t refcnt[0];
 };
 
+enum fib_callout_action {
+   FDA_NONE,   /* No callout scheduled */
+   FDA_REBUILD,/* Asks to rebuild algo instance */
+   FDA_EVAL,   /* Asks to evaluate if the current algo is still be 
best */
+};
+
+struct fib_sync_status {
+   struct timeval  diverge_time;   /* ts when diverged */
+   uint32_tnum_changes;/* number of changes since sync 
*/
+   uint32_tbucket_changes; /* num changes within the 
current bucket */
+   uint64_tbucket_id;  /* 50ms bucket # */
+};
+
 /*
  * Data structure for the fib lookup instance tied to the particular rib.
  */
@@ -141,12 +170,12 @@ struct fib_data {
uint32_tfd_dead:1;  /* Scheduled for deletion */
uint32_tfd_linked:1;/* true if linked */
uint32_tfd_need_rebuild:1;  /* true if rebuild 
scheduled */
-   uint32_tfd_force_eval:1;/* true if rebuild scheduled */
uint8_t fd_family;  /* family */
uint32_tfd_fibnum;  /* fibnum */
uint32_tfd_failed_rebuilds; /* stat: failed 
rebuilds */
uint32_tfd_gen; /* instance gen# */
struct callout  fd_callout; /* rebuild callout */
+   enum fib_callout_action fd_callout_action;  /* Callout action to 
take */
void*fd_algo_data;  /* algorithm data */
struct nhop_object  **nh_idx;   /* nhop idx->ptr array */
struct nhop_ref_table   *nh_ref_table;  /* array with # of nhop 
references */
@@ -156,12 +185,14 @@ struct fib_data {
struct vnet *

git: c3a456defaf2 - main - Always use inp fib in the inp_lookup_mcast_ifp().

2021-04-10 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit c3a456defaf28df8d6f47704d606248f6c22146c
Author: Alexander V. Chernikov 
AuthorDate: 2021-04-05 19:58:57 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-04-10 13:47:49 +

Always use inp fib in the inp_lookup_mcast_ifp().

inp_lookup_mcast_ifp() is static and is only used in the inp_join_group().
The latter function is also static, and is only used in the 
inp_setmoptions(),
 which relies on inp being non-NULL.

As a result, in the current code, inp_lookup_mcast_ifp() is always called
 with non-NULL inp. Eliminate unused RT_DEFAULT_FIB condition and always
 use inp fib instead.

Differential Revision:  https://reviews.freebsd.org/D29594
Reviewed by:kp
MFC after:  2 weeks
---
 sys/netinet/in_mcast.c | 8 +++-
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/sys/netinet/in_mcast.c b/sys/netinet/in_mcast.c
index 392856785dd2..f0827fcf3451 100644
--- a/sys/netinet/in_mcast.c
+++ b/sys/netinet/in_mcast.c
@@ -1865,8 +1865,7 @@ inp_getmoptions(struct inpcb *inp, struct sockopt *sopt)
  * specific physical links in the networking stack, or which need
  * to join link-scope groups before IPv4 addresses are configured.
  *
- * If inp is non-NULL, use this socket's current FIB number for any
- * required FIB lookup.
+ * Use this socket's current FIB number for any required FIB lookup.
  * If ina is INADDR_ANY, look up the group address in the unicast FIB,
  * and use its ifp; usually, this points to the default next-hop.
  *
@@ -1887,8 +1886,8 @@ inp_lookup_mcast_ifp(const struct inpcb *inp,
struct rm_priotracker in_ifa_tracker;
struct ifnet *ifp;
struct nhop_object *nh;
-   uint32_t fibnum;
 
+   KASSERT(inp != NULL, ("%s: inp must not be NULL", __func__));
KASSERT(gsin->sin_family == AF_INET, ("%s: not AF_INET", __func__));
KASSERT(IN_MULTICAST(ntohl(gsin->sin_addr.s_addr)),
("%s: not multicast", __func__));
@@ -1901,8 +1900,7 @@ inp_lookup_mcast_ifp(const struct inpcb *inp,
if_ref(ifp);
IN_IFADDR_RUNLOCK(&in_ifa_tracker);
} else {
-   fibnum = inp ? inp->inp_inc.inc_fibnum : RT_DEFAULT_FIB;
-   nh = fib4_lookup(fibnum, gsin->sin_addr, 0, NHR_NONE, 0);
+   nh = fib4_lookup(inp->inp_inc.inc_fibnum, gsin->sin_addr, 0, 
NHR_NONE, 0);
if (nh != NULL) {
ifp = nh->nh_ifp;
if_ref(ifp);
___
dev-commits-src-main@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-main
To unsubscribe, send any mail to "dev-commits-src-main-unsubscr...@freebsd.org"


git: caf2f62765f9 - main - Allow to specify debugnet fib in sysctl/tunable.

2021-04-10 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit caf2f62765f9087a6e0002b1c47c3c6f65a8ae0b
Author: Alexander V. Chernikov 
AuthorDate: 2021-04-05 19:48:07 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-04-10 13:47:49 +

Allow to specify debugnet fib in sysctl/tunable.

Differential Revision:  https://reviews.freebsd.org/D29593
Reviewed by:donner
MFC after:  2 weeks
---
 sys/net/debugnet.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/sys/net/debugnet.c b/sys/net/debugnet.c
index 3930a87d46dc..bb59ff33a93f 100644
--- a/sys/net/debugnet.c
+++ b/sys/net/debugnet.c
@@ -91,6 +91,10 @@ int debugnet_nretries = 10;
 SYSCTL_INT(_net_debugnet, OID_AUTO, nretries, CTLFLAG_RWTUN,
 &debugnet_nretries, 0,
 "Number of retransmit attempts before giving up");
+int debugnet_fib = RT_DEFAULT_FIB;
+SYSCTL_INT(_net_debugnet, OID_AUTO, fib, CTLFLAG_RWTUN,
+&debugnet_fib, 0,
+"Fib to use when sending dump");
 
 static bool g_debugnet_pcb_inuse;
 static struct debugnet_pcb g_dnet_pcb;
@@ -658,7 +662,7 @@ debugnet_connect(const struct debugnet_conn_params *dcp,
};
 
CURVNET_SET(vnet0);
-   nh = fib4_lookup_debugnet(RT_DEFAULT_FIB, dest_sin.sin_addr, 0,
+   nh = fib4_lookup_debugnet(debugnet_fib, dest_sin.sin_addr, 0,
NHR_NONE);
CURVNET_RESTORE();
 
___
dev-commits-src-main@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-main
To unsubscribe, send any mail to "dev-commits-src-main-unsubscr...@freebsd.org"


git: 63dceebe6856 - main - Appease -Wsign-compare in radix.c

2021-04-10 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit 63dceebe68569c3a7ebd07d0a6123264da625149
Author: Alexander V. Chernikov 
AuthorDate: 2021-04-10 13:48:25 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-04-10 13:48:25 +

Appease -Wsign-compare in radix.c

Differential Revision:  https://reviews.freebsd.org/D29661
Submitted by:   zec
MFC after   2 weeks
---
 sys/net/radix.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sys/net/radix.c b/sys/net/radix.c
index 1f58318e52ae..931bf6db871b 100644
--- a/sys/net/radix.c
+++ b/sys/net/radix.c
@@ -428,7 +428,7 @@ rn_insert(void *v_arg, struct radix_head *head, int 
*dupentry,
int head_off = top->rn_offset, vlen = LEN(v);
struct radix_node *t = rn_search(v_arg, top);
caddr_t cp = v + head_off;
-   int b;
+   unsigned b;
struct radix_node *p, *tt, *x;
/*
 * Find first bit at which v and t->rn_key differ
___
dev-commits-src-main@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-main
To unsubscribe, send any mail to "dev-commits-src-main-unsubscr...@freebsd.org"


git: 7f5f3fcc32bf - main - Fix direct route installation with net/bird.

2021-04-10 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit 7f5f3fcc32bfa553faa007579dfcaed84be3b047
Author: Alexander V. Chernikov 
AuthorDate: 2021-04-10 15:25:24 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-04-10 15:31:16 +

Fix direct route installation with net/bird.

Slighly relax the gateway validation rules imposed by the
 2fe5a79425c7, by requiring only first 8 bytes (everyhing
 before sdl_data to be present in the AF_LINK gateway.

Reported by:olivier
---
 sys/net/rtsock.c | 11 ++-
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/sys/net/rtsock.c b/sys/net/rtsock.c
index 12e485f917c8..c0996d318fb2 100644
--- a/sys/net/rtsock.c
+++ b/sys/net/rtsock.c
@@ -1381,20 +1381,21 @@ cleanup_xaddrs_gateway(struct rt_addrinfo *info)
 #endif
case AF_LINK:
{
-   struct sockaddr_dl_short *gw_sdl;
+   struct sockaddr_dl *gw_sdl;
 
-   gw_sdl = (struct sockaddr_dl_short *)gw;
-   if (gw_sdl->sdl_len < sizeof(struct sockaddr_dl_short)) 
{
+   size_t sdl_min_len = offsetof(struct sockaddr_dl, 
sdl_data);
+   gw_sdl = (struct sockaddr_dl *)gw;
+   if (gw_sdl->sdl_len < sdl_min_len) {
printf("gw sdl_len too small\n");
return (EINVAL);
}
 
const struct sockaddr_dl_short sdl = {
.sdl_family = AF_LINK,
-   .sdl_len = sizeof(struct sockaddr_dl_short),
+   .sdl_len = sdl_min_len,
.sdl_index = gw_sdl->sdl_index,
};
-   *gw_sdl = sdl;
+   memcpy(gw_sdl, &sdl, sdl_min_len);
break;
}
}
___
dev-commits-src-main@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-main
To unsubscribe, send any mail to "dev-commits-src-main-unsubscr...@freebsd.org"


git: afbb64f1d85b - main - Fix vlan creation for the older ifconfig(8) binaries.

2021-04-11 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit afbb64f1d85b7d8c2938031c3567946b5d10da4f
Author: Alexander V. Chernikov 
AuthorDate: 2021-04-11 16:47:03 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-04-11 17:13:09 +

Fix vlan creation for the older ifconfig(8) binaries.

Reported by:allanjude
MFC after:  immediately
---
 sys/net/if_vlan.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/sys/net/if_vlan.c b/sys/net/if_vlan.c
index 229cd331c7a1..bd3a5335a97f 100644
--- a/sys/net/if_vlan.c
+++ b/sys/net/if_vlan.c
@@ -1015,6 +1015,10 @@ vlan_clone_create(struct if_clone *ifc, char *name, 
size_t len, caddr_t params)
vid = vlr.vlr_tag;
proto = vlr.vlr_proto;
 
+#ifdef COMPAT_FREEBSD12
+   if (proto == 0)
+   proto = ETHERTYPE_VLAN;
+#endif
p = ifunit_ref(vlr.vlr_parent);
if (p == NULL)
return (ENXIO);
@@ -1947,6 +1951,10 @@ vlan_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
error = ENOENT;
break;
}
+#ifdef COMPAT_FREEBSD12
+   if (vlr.vlr_proto == 0)
+   vlr.vlr_proto = ETHERTYPE_VLAN;
+#endif
oldmtu = ifp->if_mtu;
error = vlan_config(ifv, p, vlr.vlr_tag, vlr.vlr_proto);
if_rele(p);
___
dev-commits-src-main@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-main
To unsubscribe, send any mail to "dev-commits-src-main-unsubscr...@freebsd.org"


git: 936f4a42fa2a - main - lltable: do not require prefix lookup when checking lle allocation rules.

2021-09-06 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit 936f4a42fa2a23d21f8f14a8c33627a8207b4b3b
Author: Alexander V. Chernikov 
AuthorDate: 2021-09-03 11:48:36 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-09-06 21:03:22 +

lltable: do not require prefix lookup when checking lle allocation rules.

With the new FIB_ALGO infrastructure, nearly all subsystems use
 fib[46]_lookup() functions, which provides lockless lookups.
A number of places remains that uses old-style lookup functions, that
 still requires RIB read lock to return the result. One of such places
 is arp processing code.
FIB_ALGO implementation makes some tradeoffs, resulting in (relatively)
 prolonged periods of holding RIB_WLOCK. If the lock is held and datapath
 competes for it, the RX ring may get blocked, ending in traffic delays and 
losses.
As currently arp processing is performed directly in the interrupt handler,
 handling ARP replies triggers the problem descibed above when the amount of
 ARP replies is high.

To be more specific, prior to creating new ARP entry, routing lookup for 
the entry
 address in interface fib is executed. The following conditions are the 
verified:

1. If lookup returns an empty result, or the resulting prefix is 
non-directly-reachable,
 failure is returned. The only exception are host routes w/ 
gateway==address.
2. If the routing lookup returns different interface and non-host route,
 we want to support the use case of having multiple interfaces with the 
same prefix.
 In fact, the current code just checks if the returned prefix covers target 
address
 (always true) and effectively allow allocating ARP entries for any 
directly-reachable prefix,
 regardless of its interface.

Change the code to perform the following:

1) use fib4_lookup() to get the nexthop, instead of requesting exact prefix.
2) Rewrite first condition check using nexthop flags (1:1 match)
3) Rewrite second condition to check for interface addresses matching 
target address on
 the input interface.

Differential Revision: https://reviews.freebsd.org/D31824
Reviewed by:ae
MFC after:  1 week
PR: 257965
---
 sys/netinet/in.c | 73 ++--
 1 file changed, 23 insertions(+), 50 deletions(-)

diff --git a/sys/netinet/in.c b/sys/netinet/in.c
index f9b46b414007..ce03c0b6d4cb 100644
--- a/sys/netinet/in.c
+++ b/sys/netinet/in.c
@@ -64,6 +64,7 @@ __FBSDID("$FreeBSD$");
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -1358,48 +1359,32 @@ in_lltable_free_entry(struct lltable *llt, struct 
llentry *lle)
 static int
 in_lltable_rtcheck(struct ifnet *ifp, u_int flags, const struct sockaddr 
*l3addr)
 {
-   struct rt_addrinfo info;
-   struct sockaddr_in rt_key, rt_mask;
-   struct sockaddr rt_gateway;
-   int rt_flags;
+   struct nhop_object *nh;
+   struct in_addr addr;
 
KASSERT(l3addr->sa_family == AF_INET,
("sin_family %d", l3addr->sa_family));
 
-   bzero(&rt_key, sizeof(rt_key));
-   rt_key.sin_len = sizeof(rt_key);
-   bzero(&rt_mask, sizeof(rt_mask));
-   rt_mask.sin_len = sizeof(rt_mask);
-   bzero(&rt_gateway, sizeof(rt_gateway));
-   rt_gateway.sa_len = sizeof(rt_gateway);
+   addr = ((const struct sockaddr_in *)l3addr)->sin_addr;
 
-   bzero(&info, sizeof(info));
-   info.rti_info[RTAX_DST] = (struct sockaddr *)&rt_key;
-   info.rti_info[RTAX_NETMASK] = (struct sockaddr *)&rt_mask;
-   info.rti_info[RTAX_GATEWAY] = (struct sockaddr *)&rt_gateway;
-
-   if (rib_lookup_info(ifp->if_fib, l3addr, NHR_REF, 0, &info) != 0)
+   nh = fib4_lookup(ifp->if_fib, addr, 0, NHR_NONE, 0);
+   if (nh == NULL)
return (EINVAL);
 
-   rt_flags = info.rti_flags;
-
/*
 * If the gateway for an existing host route matches the target L3
 * address, which is a special route inserted by some implementation
 * such as MANET, and the interface is of the correct type, then
 * allow for ARP to proceed.
 */
-   if (rt_flags & RTF_GATEWAY) {
-   if (!(rt_flags & RTF_HOST) || !info.rti_ifp ||
-   info.rti_ifp->if_type != IFT_ETHER ||
-   (info.rti_ifp->if_flags & (IFF_NOARP | IFF_STATICARP)) != 0 
||
-   memcmp(rt_gateway.sa_data, l3addr->sa_data,
+   if (nh->nh_flags & NHF_GATEWAY) {
+   if (!(nh->nh_flags & NHF_HOST) || nh->nh_ifp->if_type != 
IFT_ETHER ||
+   (nh->nh_ifp->if_flags & (IFF_NOARP | IFF_STATICARP)) != 0 ||
+   memcmp(nh->g

git: 4b631fc832ac - main - routing: fix source address selection rules for IPv4 over IPv6.

2021-09-07 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit 4b631fc832acf1bab24aa88aa06229d368d8e131
Author: Alexander V. Chernikov 
AuthorDate: 2021-09-06 22:08:15 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-09-07 21:41:05 +

routing: fix source address selection rules for IPv4 over IPv6.

Current logic always selects an IFA of the same family from the
 outgoing interfaces. In IPv4 over IPv6 setup there can be just
 single non-127.0.0.1 ifa, attached to the loopback interface.

Create a separate rt_getifa_family() to handle entire ifa selection
 for the IPv4 over IPv6.

Differential Revision: https://reviews.freebsd.org/D31868
MFC after:  1 week
---
 sys/net/route.c  | 38 ++
 sys/netinet/in.c | 34 ++
 sys/netinet/in.h |  1 +
 3 files changed, 73 insertions(+)

diff --git a/sys/net/route.c b/sys/net/route.c
index e4ed7d1a2fd1..b99939179ff2 100644
--- a/sys/net/route.c
+++ b/sys/net/route.c
@@ -534,6 +534,41 @@ info_get_ifp(struct rt_addrinfo *info)
return (NULL);
 }
 
+/*
+ * Calculates proper ifa/ifp for the cases when gateway AF is different
+ * from dst AF.
+ *
+ * Returns 0 on success.
+ */
+__noinline static int
+rt_getifa_family(struct rt_addrinfo *info, uint32_t fibnum)
+{
+   if (info->rti_ifp == NULL) {
+   struct ifaddr *ifa = NULL;
+   /*
+* No transmit interface specified. Guess it by checking gw sa.
+*/
+   const struct sockaddr *gw = info->rti_info[RTAX_GATEWAY];
+   ifa = ifa_ifwithroute(RTF_GATEWAY, gw, gw, fibnum);
+   if (ifa == NULL)
+   return (ENETUNREACH);
+   info->rti_ifp = ifa->ifa_ifp;
+   }
+
+   /* Prefer address from outgoing interface */
+   info->rti_ifa = ifaof_ifpforaddr(info->rti_info[RTAX_DST], 
info->rti_ifp);
+#ifdef INET
+   if (info->rti_ifa == NULL) {
+   /* Use first found IPv4 address */
+   bool loopback_ok = info->rti_ifp->if_flags & IFF_LOOPBACK;
+   info->rti_ifa = (struct ifaddr *)in_findlocal(fibnum, 
loopback_ok);
+   }
+#endif
+   if (info->rti_ifa == NULL)
+   return (ENETUNREACH);
+   return (0);
+}
+
 /*
  * Look up rt_addrinfo for a specific fib.
  *
@@ -566,6 +601,9 @@ rt_getifa_fib(struct rt_addrinfo *info, u_int fibnum)
 */
if (info->rti_ifa == NULL && ifaaddr != NULL)
info->rti_ifa = ifa_ifwithaddr(ifaaddr);
+   if ((info->rti_ifa == NULL) && ((info->rti_flags & RTF_GATEWAY) != 0) &&
+   (gateway->sa_family != dst->sa_family))
+   return (rt_getifa_family(info, fibnum));
if (info->rti_ifa == NULL) {
const struct sockaddr *sa;
 
diff --git a/sys/netinet/in.c b/sys/netinet/in.c
index ce03c0b6d4cb..e968a559a13c 100644
--- a/sys/netinet/in.c
+++ b/sys/netinet/in.c
@@ -188,6 +188,40 @@ in_localip_more(struct in_ifaddr *original_ia)
return (NULL);
 }
 
+/*
+ * Tries to find first IPv4 address in the provided fib.
+ * Prefers non-loopback addresses and return loopback IFF
+ * @loopback_ok is set.
+ *
+ * Returns ifa or NULL.
+ */
+struct in_ifaddr *
+in_findlocal(uint32_t fibnum, bool loopback_ok)
+{
+   struct rm_priotracker in_ifa_tracker;
+   struct in_ifaddr *ia = NULL, *ia_lo = NULL;
+
+   NET_EPOCH_ASSERT();
+
+   IN_IFADDR_RLOCK(&in_ifa_tracker);
+   CK_STAILQ_FOREACH(ia, &V_in_ifaddrhead, ia_link) {
+   uint32_t ia_fib = ia->ia_ifa.ifa_ifp->if_fib;
+   if (!V_rt_add_addr_allfibs && (fibnum != ia_fib))
+   continue;
+
+   if (!IN_LOOPBACK(ntohl(IA_SIN(ia)->sin_addr.s_addr)))
+   break;
+   if (loopback_ok)
+   ia_lo = ia;
+   }
+   IN_IFADDR_RUNLOCK(&in_ifa_tracker);
+
+   if (ia == NULL)
+   ia = ia_lo;
+
+   return (ia);
+}
+
 /*
  * Determine whether an IP address is in a reserved set of addresses
  * that may not be forwarded, or whether datagrams to that destination
diff --git a/sys/netinet/in.h b/sys/netinet/in.h
index 28d6721edc53..0206fd16d2fe 100644
--- a/sys/netinet/in.h
+++ b/sys/netinet/in.h
@@ -651,6 +651,7 @@ int  in_canforward(struct in_addr);
 int in_localaddr(struct in_addr);
 int in_localip(struct in_addr);
 int in_ifhasaddr(struct ifnet *, struct in_addr);
+struct in_ifaddr *in_findlocal(uint32_t, bool);
 int inet_aton(const char *, struct in_addr *); /* in libkern */
 char   *inet_ntoa_r(struct in_addr ina, char *buf); /* in libkern */
 char   *inet_ntop(int, const void *, char *, socklen_t); /* in libkern */
__

git: 7e64580b5f47 - main - routing: Use the same index space for both nexthop and nexthop groups.

2021-10-08 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit 7e64580b5f477ba4523799f26d1178f611f5d6cb
Author: Alexander V. Chernikov 
AuthorDate: 2021-10-06 19:07:54 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-10-08 07:58:55 +

routing: Use the same index space for both nexthop and nexthop groups.

This simplifies userland object handling along with kernel-level
 nexthop handling in fib algo framework.

MFC after:  1 week
Differential Revision: https://reviews.freebsd.org/D32342
---
 sys/net/route/fib_algo.c |  6 ++
 sys/net/route/nhgrp.c| 31 +++
 sys/net/route/nhop_var.h |  1 -
 3 files changed, 9 insertions(+), 29 deletions(-)

diff --git a/sys/net/route/fib_algo.c b/sys/net/route/fib_algo.c
index 4bae9e5edd6c..54b0464711a5 100644
--- a/sys/net/route/fib_algo.c
+++ b/sys/net/route/fib_algo.c
@@ -1764,12 +1764,10 @@ get_nhop_idx(struct nhop_object *nh)
 {
 #ifdef ROUTE_MPATH
if (NH_IS_NHGRP(nh))
-   return (nhgrp_get_idx((struct nhgrp_object *)nh) * 2 - 1);
+   return (nhgrp_get_idx((struct nhgrp_object *)nh));
else
-   return (nhop_get_idx(nh) * 2);
-#else
-   return (nhop_get_idx(nh));
 #endif
+   return (nhop_get_idx(nh));
 }
 
 uint32_t
diff --git a/sys/net/route/nhgrp.c b/sys/net/route/nhgrp.c
index 982ff2a72f15..07abdf480101 100644
--- a/sys/net/route/nhgrp.c
+++ b/sys/net/route/nhgrp.c
@@ -159,9 +159,9 @@ link_nhgrp(struct nh_control *ctl, struct nhgrp_priv 
*grp_priv)
NHOPS_WLOCK(ctl);
/* Check if we need to resize hash and index */
new_num_buckets = CHT_SLIST_GET_RESIZE_BUCKETS(&ctl->gr_head);
-   new_num_items = bitmask_get_resize_items(&ctl->gr_idx_head);
+   new_num_items = bitmask_get_resize_items(&ctl->nh_idx_head);
 
-   if (bitmask_alloc_idx(&ctl->gr_idx_head, &idx) != 0) {
+   if (bitmask_alloc_idx(&ctl->nh_idx_head, &idx) != 0) {
NHOPS_WUNLOCK(ctl);
DPRINTF("Unable to allocate mpath index");
consider_resize(ctl, new_num_buckets, new_num_items);
@@ -196,7 +196,7 @@ unlink_nhgrp(struct nh_control *ctl, struct nhgrp_priv *key)
}
 
idx = nhg_priv_ret->nhg_idx;
-   ret = bitmask_free_idx(&ctl->gr_idx_head, idx);
+   ret = bitmask_free_idx(&ctl->nh_idx_head, idx);
nhg_priv_ret->nhg_idx = 0;
nhg_priv_ret->nh_control = NULL;
 
@@ -243,8 +243,8 @@ consider_resize(struct nh_control *ctl, uint32_t 
new_gr_bucket, uint32_t new_idx
CHT_SLIST_RESIZE(&ctl->gr_head, mpath, gr_ptr, new_gr_bucket);
}
if (gr_idx_ptr != NULL) {
-   if (bitmask_copy(&ctl->gr_idx_head, gr_idx_ptr, new_idx_items) 
== 0)
-   bitmask_swap(&ctl->gr_idx_head, gr_idx_ptr, 
new_idx_items, &old_idx_ptr);
+   if (bitmask_copy(&ctl->nh_idx_head, gr_idx_ptr, new_idx_items) 
== 0)
+   bitmask_swap(&ctl->nh_idx_head, gr_idx_ptr, 
new_idx_items, &old_idx_ptr);
}
NHOPS_WUNLOCK(ctl);
 
@@ -261,8 +261,8 @@ bool
 nhgrp_ctl_alloc_default(struct nh_control *ctl, int malloc_flags)
 {
size_t alloc_size;
-   uint32_t num_buckets, num_items;
-   void *cht_ptr, *mask_ptr;
+   uint32_t num_buckets;
+   void *cht_ptr;
 
malloc_flags = (malloc_flags & (M_NOWAIT | M_WAITOK)) | M_ZERO;
 
@@ -275,29 +275,16 @@ nhgrp_ctl_alloc_default(struct nh_control *ctl, int 
malloc_flags)
return (false);
}
 
-   /*
-* Allocate nexthop index bitmask.
-*/
-   num_items = 128;
-   mask_ptr = malloc(bitmask_get_size(num_items), M_NHOP, malloc_flags);
-   if (mask_ptr == NULL) {
-   DPRINTF("mpath bitmask init failed");
-   free(cht_ptr, M_NHOP);
-   return (false);
-   }
-
NHOPS_WLOCK(ctl);
 
if (ctl->gr_head.hash_size == 0) {
/* Init hash and bitmask */
CHT_SLIST_INIT(&ctl->gr_head, cht_ptr, num_buckets);
-   bitmask_init(&ctl->gr_idx_head, mask_ptr, num_items);
NHOPS_WUNLOCK(ctl);
} else {
/* Other thread has already initiliazed hash/bitmask */
NHOPS_WUNLOCK(ctl);
free(cht_ptr, M_NHOP);
-   free(mask_ptr, M_NHOP);
}
 
DPRINTF("mpath init done for fib/af %d/%d", ctl->rh->rib_fibnum,
@@ -315,18 +302,14 @@ nhgrp_ctl_init(struct nh_control *ctl)
 * routes will not be necessarily used.
 */
CHT_SLIST_INIT(&ctl->gr_head, NULL, 0);
-   bitmask_init(&ctl->gr_idx_head, NULL, 0);
return (0);
 }
 
 void
 nhgrp_ctl_fr

git: 6b8ef0d428c9 - main - Add batched update support for the fib algo.

2021-04-15 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit 6b8ef0d428c93c970c1951a52c72f9e99c9e4279
Author: Alexander V. Chernikov 
AuthorDate: 2021-04-09 21:30:10 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-04-14 22:54:11 +

Add batched update support for the fib algo.

Initial fib algo implementation was build on a very simple set of
 principles w.r.t updates:

1) algorithm is ether able to apply the change synchronously (DIR24-8)
 or requires full rebuild (bsearch, lradix).
2) framework falls back to rebuild on every error (memory allocation,
 nhg limit, other internal algo errors, etc).

This changes brings the new "intermediate" concept - batched updates.
Algotirhm can indicate that the particular update has to be handled in
 batched fashion (FLM_BATCH).
The framework will write this update and other updates to the temporary
 buffer instead of pushing them to the algo callback.
Depending on the update rate, the framework will batch 50..1024 ms of 
updates
 and submit them to a different algo callback.

This functionality is handy for the slow-to-rebuild algorithms like DXR.

Differential Revision:  https://reviews.freebsd.org/D29588
Reviewed by:zec
MFC after:  2 weeks
---
 sys/net/route/fib_algo.c | 135 +--
 sys/net/route/fib_algo.h |  25 -
 2 files changed, 154 insertions(+), 6 deletions(-)

diff --git a/sys/net/route/fib_algo.c b/sys/net/route/fib_algo.c
index 622026668764..4803bafdbae1 100644
--- a/sys/net/route/fib_algo.c
+++ b/sys/net/route/fib_algo.c
@@ -151,6 +151,7 @@ enum fib_callout_action {
FDA_NONE,   /* No callout scheduled */
FDA_REBUILD,/* Asks to rebuild algo instance */
FDA_EVAL,   /* Asks to evaluate if the current algo is still be 
best */
+   FDA_BATCH,  /* Asks to submit batch of updates to the algo */
 };
 
 struct fib_sync_status {
@@ -158,6 +159,7 @@ struct fib_sync_status {
uint32_tnum_changes;/* number of changes since sync 
*/
uint32_tbucket_changes; /* num changes within the 
current bucket */
uint64_tbucket_id;  /* 50ms bucket # */
+   struct fib_change_queue fd_change_queue;/* list of scheduled entries */
 };
 
 /*
@@ -170,6 +172,7 @@ struct fib_data {
uint32_tfd_dead:1;  /* Scheduled for deletion */
uint32_tfd_linked:1;/* true if linked */
uint32_tfd_need_rebuild:1;  /* true if rebuild 
scheduled */
+   uint32_tfd_batch:1; /* true if batched notification 
scheduled */
uint8_t fd_family;  /* family */
uint32_tfd_fibnum;  /* fibnum */
uint32_tfd_failed_rebuilds; /* stat: failed 
rebuilds */
@@ -383,6 +386,8 @@ print_op_result(enum flm_op_result result)
return "success";
case FLM_REBUILD:
return "rebuild";
+   case FLM_BATCH:
+   return "batch";
case FLM_ERROR:
return "error";
}
@@ -508,6 +513,8 @@ schedule_fd_rebuild(struct fib_data *fd, const char *reason)
 
if (!fd->fd_need_rebuild) {
fd->fd_need_rebuild = true;
+   /* Stop batch updates */
+   fd->fd_batch = false;
 
/*
 * Potentially re-schedules pending callout
@@ -568,7 +575,7 @@ mark_diverge_time(struct fib_data *fd)
  *   the update gets delayed, up to maximum delay threshold.
  */
 static void
-update_rebuild_delay(struct fib_data *fd)
+update_rebuild_delay(struct fib_data *fd, enum fib_callout_action action)
 {
uint32_t bucket_id, new_delay = 0;
struct timeval tv;
@@ -616,7 +623,7 @@ update_rebuild_delay(struct fib_data *fd)
add_tv_diff_ms(&new_tv, new_delay);
 
int32_t delay_ms = get_tv_diff_ms(&tv, &new_tv);
-   schedule_callout(fd, FDA_REBUILD, delay_ms);
+   schedule_callout(fd, action, delay_ms);
}
 }
 
@@ -626,8 +633,9 @@ update_algo_state(struct fib_data *fd)
 
RIB_WLOCK_ASSERT(fd->fd_rh);
 
-   if (fd->fd_need_rebuild) {
-   update_rebuild_delay(fd);
+   if (fd->fd_batch || fd->fd_need_rebuild) {
+   enum fib_callout_action action = fd->fd_need_rebuild ? 
FDA_REBUILD : FDA_BATCH;
+   update_rebuild_delay(fd, action);
return;
}
 
@@ -664,6 +672,77 @@ need_immediate_sync(struct fib_data *fd, struct 
rib_cmd_info *rc)
return (false);
 }
 
+static bool
+apply_rtable_changes(struct fib_data *fd)
+{
+   enum flm_op_result res

git: e2f79d9e518f - main - Fib algo: extend KPI by allowing algo to set datapath pointers.

2021-04-18 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit e2f79d9e518f885bf875f6613e70af39b7c397de
Author: Alexander V. Chernikov 
AuthorDate: 2021-04-15 17:44:11 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-04-18 15:12:12 +

Fib algo: extend KPI by allowing algo to set datapath pointers.

Some algorithms may require updating datapath and control plane
 algo pointers after the (batched) updates.

Export fib_set_datapath_ptr() to allow setting the new datapath
 function or data pointer from the algo.
Add fib_set_algo_ptr() to allow updating algo control plane
 pointer from the algo.
Add fib_epoch_call() epoch(9) wrapper to simplify freeing old
 datapath state.

Reviewed by:zec
Differential Revision: https://reviews.freebsd.org/D29799
MFC after:  1 week
---
 sys/net/route/fib_algo.c | 59 
 sys/net/route/fib_algo.h |  4 +++-
 2 files changed, 42 insertions(+), 21 deletions(-)

diff --git a/sys/net/route/fib_algo.c b/sys/net/route/fib_algo.c
index 4803bafdbae1..b0a6c38ff560 100644
--- a/sys/net/route/fib_algo.c
+++ b/sys/net/route/fib_algo.c
@@ -197,7 +197,6 @@ static bool rebuild_fd(struct fib_data *fd, const char 
*reason);
 static bool rebuild_fd_flm(struct fib_data *fd, struct fib_lookup_module 
*flm_new);
 static void handle_fd_callout(void *_data);
 static void destroy_fd_instance_epoch(epoch_context_t ctx);
-static enum flm_op_result attach_datapath(struct fib_data *fd);
 static bool is_idx_free(struct fib_data *fd, uint32_t index);
 static void set_algo_fixed(struct rib_head *rh);
 static bool is_algo_fixed(struct rib_head *rh);
@@ -1014,8 +1013,7 @@ schedule_destroy_fd_instance(struct fib_data *fd, bool 
in_callout)
 */
callout_stop(&fd->fd_callout);
 
-   epoch_call(net_epoch_preempt, destroy_fd_instance_epoch,
-   &fd->fd_epoch_ctx);
+   fib_epoch_call(destroy_fd_instance_epoch, &fd->fd_epoch_ctx);
 
return (0);
 }
@@ -1237,8 +1235,10 @@ setup_fd_instance(struct fib_lookup_module *flm, struct 
rib_head *rh,
for (int i = 0; i < FIB_MAX_TRIES; i++) {
result = try_setup_fd_instance(flm, rh, prev_fd, &new_fd);
 
-   if ((result == FLM_SUCCESS) && attach)
-   result = attach_datapath(new_fd);
+   if ((result == FLM_SUCCESS) && attach) {
+   if (!fib_set_datapath_ptr(new_fd, &new_fd->fd_dp))
+   result = FLM_REBUILD;
+   }
 
if ((prev_fd != NULL) && (prev_fd != orig_fd)) {
schedule_destroy_fd_instance(prev_fd, false);
@@ -1546,32 +1546,33 @@ get_fib_dp_header(struct fib_dp *dp)
 /*
  * Replace per-family index pool @pdp with a new one which
  * contains updated callback/algo data from @fd.
- * Returns 0 on success.
+ * Returns true on success.
  */
-static enum flm_op_result
-replace_rtables_family(struct fib_dp **pdp, struct fib_data *fd)
+static bool
+replace_rtables_family(struct fib_dp **pdp, struct fib_data *fd, struct fib_dp 
*dp)
 {
struct fib_dp_header *new_fdh, *old_fdh;
 
NET_EPOCH_ASSERT();
 
FD_PRINTF(LOG_DEBUG, fd, "[vnet %p] replace with f:%p arg:%p",
-   curvnet, fd->fd_dp.f, fd->fd_dp.arg);
+   curvnet, dp->f, dp->arg);
 
FIB_MOD_LOCK();
old_fdh = get_fib_dp_header(*pdp);
+
new_fdh = alloc_fib_dp_array(old_fdh->fdh_num_tables, false);
FD_PRINTF(LOG_DEBUG, fd, "OLD FDH: %p NEW FDH: %p", old_fdh, new_fdh);
if (new_fdh == NULL) {
FIB_MOD_UNLOCK();
FD_PRINTF(LOG_WARNING, fd, "error attaching datapath");
-   return (FLM_REBUILD);
+   return (false);
}
 
memcpy(&new_fdh->fdh_idx[0], &old_fdh->fdh_idx[0],
old_fdh->fdh_num_tables * sizeof(struct fib_dp));
/* Update relevant data structure for @fd */
-   new_fdh->fdh_idx[fd->fd_fibnum] = fd->fd_dp;
+   new_fdh->fdh_idx[fd->fd_fibnum] = *dp;
 
/* Ensure memcpy() writes have completed */
atomic_thread_fence_rel();
@@ -1580,10 +1581,9 @@ replace_rtables_family(struct fib_dp **pdp, struct 
fib_data *fd)
FIB_MOD_UNLOCK();
FD_PRINTF(LOG_DEBUG, fd, "update %p -> %p", old_fdh, new_fdh);
 
-   epoch_call(net_epoch_preempt, destroy_fdh_epoch,
-   &old_fdh->fdh_epoch_ctx);
+   fib_epoch_call(destroy_fdh_epoch, &old_fdh->fdh_epoch_ctx);
 
-   return (FLM_SUCCESS);
+   return (true);
 }
 
 static struct fib_dp **
@@ -1601,13 +1601,13 @@ get_family_dp_ptr(int family)
 /*
  * Make datapath use fib instance @fd
  */
-static enum fl

git: 0abb6ff59084 - main - fib algo: do not reallocate datapath index for datapath ptr update.

2021-04-18 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit 0abb6ff590842114c74e5d52e1af65605bd9d960
Author: Alexander V. Chernikov 
AuthorDate: 2021-04-18 15:03:58 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-04-18 15:12:13 +

fib algo: do not reallocate datapath index for datapath ptr update.

Fib algo uses a per-family array indexed by the fibnum to store
 lookup function pointers and per-fib data.

Each algorithm rebuild currently requires re-allocating this array
 to support atomic change of two pointers.

As in reality most of the changes actually involve changing only
 data pointer, add a shortcut performing in-flight pointer update.

MFC after:  2 weeks
---
 sys/net/route/fib_algo.c | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/sys/net/route/fib_algo.c b/sys/net/route/fib_algo.c
index b0a6c38ff560..30e715e1e1ef 100644
--- a/sys/net/route/fib_algo.c
+++ b/sys/net/route/fib_algo.c
@@ -1561,6 +1561,17 @@ replace_rtables_family(struct fib_dp **pdp, struct 
fib_data *fd, struct fib_dp *
FIB_MOD_LOCK();
old_fdh = get_fib_dp_header(*pdp);
 
+   if (old_fdh->fdh_idx[fd->fd_fibnum].f == dp->f) {
+   /*
+* Function is the same, data pointer needs update.
+* Perform in-line replace without reallocation.
+*/
+   old_fdh->fdh_idx[fd->fd_fibnum].arg = dp->arg;
+   FD_PRINTF(LOG_DEBUG, fd, "FDH %p inline update", old_fdh);
+   FIB_MOD_UNLOCK();
+   return (true);
+   }
+
new_fdh = alloc_fib_dp_array(old_fdh->fdh_num_tables, false);
FD_PRINTF(LOG_DEBUG, fd, "OLD FDH: %p NEW FDH: %p", old_fdh, new_fdh);
if (new_fdh == NULL) {
___
dev-commits-src-main@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-main
To unsubscribe, send any mail to "dev-commits-src-main-unsubscr...@freebsd.org"


git: 37c0f4a20777 - main - Fix typo in rtsock_common.h

2021-04-19 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit 37c0f4a2077739e735732374d67525cf6de36d21
Author: Alexander V. Chernikov 
AuthorDate: 2021-04-19 20:24:42 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-04-19 20:24:46 +

Fix typo in rtsock_common.h

MFC after:  3 days
---
 tests/sys/net/routing/rtsock_common.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/sys/net/routing/rtsock_common.h 
b/tests/sys/net/routing/rtsock_common.h
index 71476d2b5f3c..ae450ac88ba1 100644
--- a/tests/sys/net/routing/rtsock_common.h
+++ b/tests/sys/net/routing/rtsock_common.h
@@ -454,7 +454,7 @@ sa_equal_msg_flags(const struct sockaddr *a, const struct 
sockaddr *b, char *msg
b6 = (const struct sockaddr_in6 *)b;
if (!IN6_ARE_ADDR_EQUAL(&a6->sin6_addr, &b6->sin6_addr)) {
inet_ntop(AF_INET6, &a6->sin6_addr, a_s, sizeof(a_s));
-   inet_ntop(AF_INET6, &b6->sin6_addr, a_s, sizeof(a_s));
+   inet_ntop(AF_INET6, &b6->sin6_addr, b_s, sizeof(b_s));
snprintf(msg, sz, "addr diff: %s vs %s", a_s, b_s);
return 0;
}
___
dev-commits-src-main@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-main
To unsubscribe, send any mail to "dev-commits-src-main-unsubscr...@freebsd.org"


git: 758c9d54d44f - main - Improve error reporting in rtsock.c

2021-04-19 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit 758c9d54d44f8ce957570b8c2ef6d1b3f28a792d
Author: Alexander V. Chernikov 
AuthorDate: 2021-04-19 20:36:41 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-04-19 20:36:41 +

Improve error reporting in rtsock.c

MFC after:  3 days
---
 sys/net/rtsock.c | 21 -
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/sys/net/rtsock.c b/sys/net/rtsock.c
index c0996d318fb2..5194a2a15c1e 100644
--- a/sys/net/rtsock.c
+++ b/sys/net/rtsock.c
@@ -126,6 +126,9 @@ struct ifa_msghdrl32 {
 
 #endif /* COMPAT_FREEBSD32 */
 
+#defineRTS_PID_PRINTF(_fmt, ...) \
+printf("rtsock:%s(): PID %d: " _fmt "\n", __func__, curproc->p_pid, ## 
__VA_ARGS__)
+
 MALLOC_DEFINE(M_RTABLE, "routetbl", "routing tables");
 
 /* NB: these are not modified */
@@ -571,7 +574,7 @@ fill_blackholeinfo(struct rt_addrinfo *info, union 
sockaddr_union *saun)
sa_family_t saf;
 
if (V_loif == NULL) {
-   printf("Unable to add blackhole/reject nhop without loopback");
+   RTS_PID_PRINTF("Unable to add blackhole/reject nhop without 
loopback");
return (ENOTSUP);
}
info->rti_ifp = V_loif;
@@ -1360,7 +1363,7 @@ cleanup_xaddrs_gateway(struct rt_addrinfo *info)
{
struct sockaddr_in *gw_sin = (struct sockaddr_in *)gw;
if (gw_sin->sin_len < sizeof(struct sockaddr_in)) {
-   printf("gw sin_len too small\n");
+   RTS_PID_PRINTF("gateway sin_len too small: %d", 
gw->sa_len);
return (EINVAL);
}
fill_sockaddr_inet(gw_sin, gw_sin->sin_addr);
@@ -1372,7 +1375,7 @@ cleanup_xaddrs_gateway(struct rt_addrinfo *info)
{
struct sockaddr_in6 *gw_sin6 = (struct sockaddr_in6 
*)gw;
if (gw_sin6->sin6_len < sizeof(struct sockaddr_in6)) {
-   printf("gw sin6_len too small\n");
+   RTS_PID_PRINTF("gateway sin6_len too small: 
%d", gw->sa_len);
return (EINVAL);
}
fill_sockaddr_inet6(gw_sin6, &gw_sin6->sin6_addr, 0);
@@ -1386,7 +1389,7 @@ cleanup_xaddrs_gateway(struct rt_addrinfo *info)
size_t sdl_min_len = offsetof(struct sockaddr_dl, 
sdl_data);
gw_sdl = (struct sockaddr_dl *)gw;
if (gw_sdl->sdl_len < sdl_min_len) {
-   printf("gw sdl_len too small\n");
+   RTS_PID_PRINTF("gateway sdl_len too small: %d", 
gw_sdl->sdl_len);
return (EINVAL);
}
 
@@ -1433,7 +1436,7 @@ cleanup_xaddrs_inet(struct rt_addrinfo *info)
return (EINVAL);
}
if (mask_sa && mask_sa->sin_len < sizeof(struct sockaddr_in)) {
-   printf("mask sin_len too small\n");
+   RTS_PID_PRINTF("prefix mask sin_len too small: %d", 
mask_sa->sin_len);
return (EINVAL);
}
fill_sockaddr_inet(dst_sa, dst);
@@ -1466,11 +1469,11 @@ cleanup_xaddrs_inet6(struct rt_addrinfo *info)
IN6_MASK_ADDR(&dst_sa->sin6_addr, &mask);
 
if (dst_sa->sin6_len < sizeof(struct sockaddr_in6)) {
-   printf("dst sin6_len too small\n");
+   RTS_PID_PRINTF("prefix dst sin6_len too small: %d", 
dst_sa->sin6_len);
return (EINVAL);
}
if (mask_sa && mask_sa->sin6_len < sizeof(struct sockaddr_in6)) {
-   printf("mask sin6_len too small\n");
+   RTS_PID_PRINTF("rtsock: prefix mask sin6_len too small: %d", 
mask_sa->sin6_len);
return (EINVAL);
}
fill_sockaddr_inet6(dst_sa, &dst_sa->sin6_addr, 0);
@@ -2092,9 +2095,9 @@ rt_dispatch(struct mbuf *m, sa_family_t saf)
 }
 
 /*
- * Checks if rte can be exported v.r.t jails/vnets.
+ * Checks if rte can be exported w.r.t jails/vnets.
  *
- * Returns 1 if it can, 0 otherwise.
+ * Returns true if it can, false otherwise.
  */
 static bool
 can_export_rte(struct ucred *td_ucred, bool rt_is_host,
___
dev-commits-src-main@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-main
To unsubscribe, send any mail to "dev-commits-src-main-unsubscr...@freebsd.org"


git: b31fbebeb3d5 - main - Relax rtsock message restrictions.

2021-04-20 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit b31fbebeb3d59af359a3417cddfbcf666b2c56c9
Author: Alexander V. Chernikov 
AuthorDate: 2021-04-19 20:49:18 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-04-20 21:34:19 +

Relax rtsock message restrictions.

Address multiple issues with strict rtsock message validation.

D28668 "normalisation" approach was based on the assumption that
 we always have at least "standard" sockaddr len.
It turned out to be false - certain older applications like quagga
 or routed abuse sin[6]_len field and set it to the offset to the
 first fully-zero bit in the mask. It is impossible to normalise
 such sockaddrs without reallocation.

With that in mind, change the approach to use a distinct memory
 buffer for the altered sockaddrs. This allows supporting the older
 software while maintaining the guarantee on the "standard" sockaddrs.

PR: 255273,255089
Differential Revision:  https://reviews.freebsd.org/D29826
MFC after:  3 days
---
 sys/net/rtsock.c | 271 ---
 1 file changed, 177 insertions(+), 94 deletions(-)

diff --git a/sys/net/rtsock.c b/sys/net/rtsock.c
index 5194a2a15c1e..b7a7e5170c74 100644
--- a/sys/net/rtsock.c
+++ b/sys/net/rtsock.c
@@ -126,6 +126,13 @@ struct ifa_msghdrl32 {
 
 #endif /* COMPAT_FREEBSD32 */
 
+struct linear_buffer {
+   char*base;  /* Base allocated memory pointer */
+   uint32_toffset; /* Currently used offset */
+   uint32_tsize;   /* Total buffer size */
+};
+#defineSCRATCH_BUFFER_SIZE 1024
+
 #defineRTS_PID_PRINTF(_fmt, ...) \
 printf("rtsock:%s(): PID %d: " _fmt "\n", __func__, curproc->p_pid, ## 
__VA_ARGS__)
 
@@ -177,7 +184,7 @@ static int  rtsock_msg_buffer(int type, struct rt_addrinfo 
*rtinfo,
struct walkarg *w, int *plen);
 static int rt_xaddrs(caddr_t cp, caddr_t cplim,
struct rt_addrinfo *rtinfo);
-static int cleanup_xaddrs(struct rt_addrinfo *info);
+static int cleanup_xaddrs(struct rt_addrinfo *info, struct linear_buffer 
*lb);
 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);
@@ -621,7 +628,8 @@ fill_blackholeinfo(struct rt_addrinfo *info, union 
sockaddr_union *saun)
  * Returns 0 on success.
  */
 static int
-fill_addrinfo(struct rt_msghdr *rtm, int len, u_int fibnum, struct rt_addrinfo 
*info)
+fill_addrinfo(struct rt_msghdr *rtm, int len, struct linear_buffer *lb, u_int 
fibnum,
+struct rt_addrinfo *info)
 {
int error;
sa_family_t saf;
@@ -641,7 +649,7 @@ fill_addrinfo(struct rt_msghdr *rtm, int len, u_int fibnum, 
struct rt_addrinfo *
return (EINVAL);
 
info->rti_flags = rtm->rtm_flags;
-   error = cleanup_xaddrs(info);
+   error = cleanup_xaddrs(info, lb);
if (error != 0)
return (error);
saf = info->rti_info[RTAX_DST]->sa_family;
@@ -878,6 +886,45 @@ export_rtaddrs(const struct rtentry *rt, struct sockaddr 
*dst,
 #endif
 }
 
+static int
+update_rtm_from_info(struct rt_addrinfo *info, struct rt_msghdr **prtm,
+int alloc_len)
+{
+   struct rt_msghdr *rtm, *orig_rtm = NULL;
+   struct walkarg w;
+   int len;
+
+   rtm = *prtm;
+   /* Check if we need to realloc storage */
+   rtsock_msg_buffer(rtm->rtm_type, info, NULL, &len);
+   if (len > alloc_len) {
+   struct rt_msghdr *tmp_rtm;
+
+   tmp_rtm = malloc(len, M_TEMP, M_NOWAIT);
+   if (tmp_rtm == NULL)
+   return (ENOBUFS);
+   bcopy(rtm, tmp_rtm, rtm->rtm_msglen);
+   orig_rtm = rtm;
+   rtm = tmp_rtm;
+   alloc_len = len;
+
+   /*
+* Delay freeing original rtm as info contains
+* data referencing it.
+*/
+   }
+
+   w.w_tmem = (caddr_t)rtm;
+   w.w_tmemsize = alloc_len;
+   rtsock_msg_buffer(rtm->rtm_type, info, &w, &len);
+   rtm->rtm_addrs = info->rti_addrs;
+
+   if (orig_rtm != NULL)
+   free(orig_rtm, M_TEMP);
+   *prtm = rtm;
+   return (0);
+}
+
 
 /*
  * Update sockaddrs, flags, etc in @prtm based on @rc data.
@@ -891,11 +938,10 @@ static int
 update_rtm_from_rc(struct rt_addrinfo *info, struct rt_msghdr **prtm,
 int alloc_len, struct rib_cmd_info *rc, struct nhop_object *nh)
 {
-   struct walkarg w;
union sockaddr_union saun;
-   struct rt_msghdr *rtm, *orig_rtm = NULL;
+   struct rt_msghdr *rtm;
str

git: 33cb3cb2e321 - main - Fix rib generation count for fib algo.

2021-04-20 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit 33cb3cb2e3212705b10e7885b37f70a3c2987c9e
Author: Alexander V. Chernikov 
AuthorDate: 2021-04-17 18:58:12 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-04-20 22:02:41 +

Fix rib generation count for fib algo.

Currently, PCB caching mechanism relies on the rib generation
 counter (rnh_gen) to invalidate cached nhops/LLE entries.

With certain fib algorithms, it is now possible that the
 datapath lookup state applies RIB changes with some delay.
In that scenario, PCB cache will invalidate on the RIB change,
 but the new lookup may result in the same nexthop being returned.
When fib algo finally gets in sync with the RIB changes, PCB cache
 will not receive any notification and will end up caching the stale data.

To fix this, introduce additional counter, rnh_gen_rib, which is used
 only when FIB_ALGO is enabled.
This counter is incremented by the control plane. Each time when fib algo
 synchronises with the RIB, it updates rnh_gen to the current rnh_gen_rib 
value.

Differential Revision: https://reviews.freebsd.org/D29812
Reviewed by:donner
MFC after:  2 weeks
---
 sys/net/route/fib_algo.c  | 13 -
 sys/net/route/route_ctl.c |  6 +++---
 sys/net/route/route_var.h | 15 ++-
 3 files changed, 29 insertions(+), 5 deletions(-)

diff --git a/sys/net/route/fib_algo.c b/sys/net/route/fib_algo.c
index 30e715e1e1ef..91565d727a9c 100644
--- a/sys/net/route/fib_algo.c
+++ b/sys/net/route/fib_algo.c
@@ -525,6 +525,13 @@ schedule_fd_rebuild(struct fib_data *fd, const char 
*reason)
}
 }
 
+static void
+sync_rib_gen(struct fib_data *fd)
+{
+   FD_PRINTF(LOG_DEBUG, fd, "Sync gen %u -> %u", fd->fd_rh->rnh_gen, 
fd->fd_rh->rnh_gen_rib);
+   fd->fd_rh->rnh_gen = fd->fd_rh->rnh_gen_rib;
+}
+
 static int64_t
 get_tv_diff_ms(const struct timeval *old_tv, const struct timeval *new_tv)
 {
@@ -680,6 +687,7 @@ apply_rtable_changes(struct fib_data *fd)
result = fd->fd_flm->flm_change_rib_items_cb(fd->fd_rh, q, 
fd->fd_algo_data);
 
if (result == FLM_SUCCESS) {
+   sync_rib_gen(fd);
for (int i = 0; i < q->count; i++)
if (q->entries[i].nh_old)
fib_unref_nhop(fd, q->entries[i].nh_old);
@@ -811,6 +819,7 @@ handle_rtable_change_cb(struct rib_head *rnh, struct 
rib_cmd_info *rc,
 
switch (result) {
case FLM_SUCCESS:
+   sync_rib_gen(fd);
/* Unref old nexthop on success */
if (rc->rc_nh_old != NULL)
fib_unref_nhop(fd, rc->rc_nh_old);
@@ -1236,7 +1245,9 @@ setup_fd_instance(struct fib_lookup_module *flm, struct 
rib_head *rh,
result = try_setup_fd_instance(flm, rh, prev_fd, &new_fd);
 
if ((result == FLM_SUCCESS) && attach) {
-   if (!fib_set_datapath_ptr(new_fd, &new_fd->fd_dp))
+   if (fib_set_datapath_ptr(new_fd, &new_fd->fd_dp))
+   sync_rib_gen(new_fd);
+   else
result = FLM_REBUILD;
}
 
diff --git a/sys/net/route/route_ctl.c b/sys/net/route/route_ctl.c
index fb3dfff87019..a0c4a2283a00 100644
--- a/sys/net/route/route_ctl.c
+++ b/sys/net/route/route_ctl.c
@@ -808,7 +808,7 @@ rt_unlinkrte(struct rib_head *rnh, struct rt_addrinfo 
*info, struct rib_cmd_info
rt->rte_flags &= ~RTF_UP;
 
/* Finalize notification */
-   rnh->rnh_gen++;
+   rib_bump_gen(rnh);
rnh->rnh_prefixes--;
 
rc->rc_cmd = RTM_DELETE;
@@ -1060,7 +1060,7 @@ add_route_nhop(struct rib_head *rnh, struct rtentry *rt,
tmproutes_update(rnh, rt);
 
/* Finalize notification */
-   rnh->rnh_gen++;
+   rib_bump_gen(rnh);
rnh->rnh_prefixes++;
 
rc->rc_cmd = RTM_ADD;
@@ -1116,7 +1116,7 @@ change_route_nhop(struct rib_head *rnh, struct rtentry 
*rt,
}
 
/* Finalize notification */
-   rnh->rnh_gen++;
+   rib_bump_gen(rnh);
if (rnd->rnd_nhop == NULL)
rnh->rnh_prefixes--;
 
diff --git a/sys/net/route/route_var.h b/sys/net/route/route_var.h
index 427c286a5090..f12931476fd3 100644
--- a/sys/net/route/route_var.h
+++ b/sys/net/route/route_var.h
@@ -60,7 +60,7 @@ struct rib_head {
rn_walktree_t   *rnh_walktree;  /* traverse tree */
rn_walktree_from_t  *rnh_walktree_from; /* traverse tree below a */
rnh_preadd_entry_f_t*rnh_preadd;/* hook to alter record prior 
to insertion */
-   rt_gen_t

git: 4044af03a4e9 - main - Fix vtnet TCP lro panic

2021-04-22 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit 4044af03a4e95642d8d1982800c079029c2b087c
Author: Alexander V. Chernikov 
AuthorDate: 2021-04-19 15:58:41 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-04-19 16:06:34 +

Fix vtnet TCP lro panic

Differential Revision: https://reviews.freebsd.org/D29900
Reviewed by:hps, kp
---
 sys/dev/virtio/network/if_vtnet.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/sys/dev/virtio/network/if_vtnet.c 
b/sys/dev/virtio/network/if_vtnet.c
index 3650d19fbe0e..e65914c5184f 100644
--- a/sys/dev/virtio/network/if_vtnet.c
+++ b/sys/dev/virtio/network/if_vtnet.c
@@ -2145,7 +2145,8 @@ vtnet_rxq_eof(struct vtnet_rxq *rxq)
 
if (deq > 0) {
 #if defined(INET) || defined(INET6)
-   tcp_lro_flush_all(&rxq->vtnrx_lro);
+   if (vtnet_software_lro(sc))
+   tcp_lro_flush_all(&rxq->vtnrx_lro);
 #endif
virtqueue_notify(vq);
}
___
dev-commits-src-main@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-main
To unsubscribe, send any mail to "dev-commits-src-main-unsubscr...@freebsd.org"


git: 5d1403a79a3e - main - [rtsock] Enforce netmask/RTF_HOST consistency.

2021-04-24 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit 5d1403a79a3e56403fb63c062252a23fce81e5f1
Author: Alexander V. Chernikov 
AuthorDate: 2021-04-23 21:53:47 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-04-24 22:41:27 +

[rtsock] Enforce netmask/RTF_HOST consistency.

Traditionally we had 2 sources of information whether the
 added/delete route request targets network or a host route:
netmask (RTA_NETMASK) and RTF_HOST flag.

The former one is tricky: netmask can be empty or can explicitly
 specify the host netmask. Parsing netmask sockaddr requires per-family
 parsing and that's what rtsock code traditionally avoided. As a result,
 consistency was not enforced and it was possible to specify network with
 the RTF_HOST flag and vice versa.

Continue normalization efforts from D29826 and D29826 and ensure that
 RTF_HOST flag always reflects host/network data from netmask field.

Differential Revision: https://reviews.freebsd.org/D29958
MFC after:  2 days
---
 sys/net/rtsock.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/sys/net/rtsock.c b/sys/net/rtsock.c
index b7a7e5170c74..fae15fdf4be6 100644
--- a/sys/net/rtsock.c
+++ b/sys/net/rtsock.c
@@ -1503,6 +1503,7 @@ cleanup_xaddrs_inet(struct rt_addrinfo *info, struct 
linear_buffer *lb)
return (ENOBUFS);
fill_sockaddr_inet(mask_sa, mask);
info->rti_info[RTAX_NETMASK] = (struct sockaddr *)mask_sa;
+   info->rti_flags &= ~RTF_HOST;
} else
remove_netmask(info);
 
@@ -1563,6 +1564,7 @@ cleanup_xaddrs_inet6(struct rt_addrinfo *info, struct 
linear_buffer *lb)
return (ENOBUFS);
fill_sockaddr_inet6((struct sockaddr_in6 *)sa, &mask, 0);
info->rti_info[RTAX_NETMASK] = sa;
+   info->rti_flags &= ~RTF_HOST;
} else
remove_netmask(info);
 
___
dev-commits-src-main@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-main
To unsubscribe, send any mail to "dev-commits-src-main-unsubscr...@freebsd.org"


git: bddae5c8a64d - main - Improve debugging output on routing tests failure.

2021-04-24 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit bddae5c8a64dc6b292198945cbe676bb2158d438
Author: Alexander V. Chernikov 
AuthorDate: 2021-04-23 21:28:38 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-04-24 22:41:27 +

Improve debugging output on routing tests failure.

Most of the routing tests create per-test VNET, making
 it harder to repeat the failure with CLI tools.
Provide an additional route/nexthop data on failure.

Differential Revision: https://reviews.freebsd.org/D29957
Reviewed by:kp
MFC after:  2 weeks
---
 tests/sys/net/routing/rtsock_print.h | 32 +++-
 1 file changed, 31 insertions(+), 1 deletion(-)

diff --git a/tests/sys/net/routing/rtsock_print.h 
b/tests/sys/net/routing/rtsock_print.h
index b44fcca25053..20bb1c51bc33 100644
--- a/tests/sys/net/routing/rtsock_print.h
+++ b/tests/sys/net/routing/rtsock_print.h
@@ -40,7 +40,10 @@
 #defineRTSOCK_ATF_REQUIRE_MSG(_rtm, _cond, _fmt, ...)   do {   \
if (!(_cond)) { \
printf("-- CONDITION FAILED, rtm dump  --\n\n");\
-   rtsock_print_message(_rtm); \
+   rtsock_print_message(_rtm); \
+   rtsock_print_table(AF_INET);\
+   rtsock_print_table(AF_INET6);   \
+   printf("===\n");\
}   \
ATF_REQUIRE_MSG(_cond, _fmt, ##__VA_ARGS__);\
 } while (0);
@@ -381,4 +384,31 @@ rtsock_print_message(struct rt_msghdr *rtm)
}
 }
 
+static void
+print_command(char *cmd)
+{
+   char line[1024];
+
+   FILE *fp = popen(cmd, "r");
+   if (fp != NULL) {
+   while (fgets(line, sizeof(line), fp) != NULL)
+   printf("%s", line);
+   pclose(fp);
+   }
+}
+
+void
+rtsock_print_table(int family)
+{
+   char cmdbuf[128];
+   char *key = (family == AF_INET) ? "4" : "6";
+
+   snprintf(cmdbuf, sizeof(cmdbuf), "/usr/bin/netstat -%srnW", key);
+   printf(" %s ===\n", cmdbuf);
+   print_command(cmdbuf);
+   snprintf(cmdbuf, sizeof(cmdbuf), "/usr/bin/netstat -%sonW", key);
+   printf(" %s ===\n", cmdbuf);
+   print_command(cmdbuf);
+}
+
 #endif
___
dev-commits-src-main@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-main
To unsubscribe, send any mail to "dev-commits-src-main-unsubscr...@freebsd.org"


git: 6993187a8c30 - main - Add FIB_ALGO to GENERIC on amd64/arm64.

2021-04-24 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit 6993187a8c30e83a408aad631a8d8629d8273c9d
Author: Alexander V. Chernikov 
AuthorDate: 2021-04-24 23:05:04 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-04-24 23:22:58 +

Add FIB_ALGO to GENERIC on amd64/arm64.

Option `FIB_ALGO` gates new modular fib lookup functionality,
 enabling more performant routing table lookups and improving
 control plane convergence under the load.

Detailed feature description is available in D27401.

Reviewed By: olivier, gnn
Differential Revision: https://reviews.freebsd.org/D28434
---
 sys/amd64/conf/GENERIC | 1 +
 sys/arm64/conf/GENERIC | 1 +
 2 files changed, 2 insertions(+)

diff --git a/sys/amd64/conf/GENERIC b/sys/amd64/conf/GENERIC
index f5f4bdf49c5f..bb7299a60382 100644
--- a/sys/amd64/conf/GENERIC
+++ b/sys/amd64/conf/GENERIC
@@ -32,6 +32,7 @@ options   INET# InterNETworking
 optionsINET6   # IPv6 communications protocols
 optionsIPSEC_SUPPORT   # Allow kldload of ipsec and tcpmd5
 optionsROUTE_MPATH # Multipath routing support
+optionsFIB_ALGO# Modular fib lookups
 optionsTCP_OFFLOAD # TCP offload
 optionsTCP_BLACKBOX# Enhanced TCP event logging
 optionsTCP_HHOOK   # hhook(9) framework for TCP
diff --git a/sys/arm64/conf/GENERIC b/sys/arm64/conf/GENERIC
index cf137417fbc5..430ba8a4a45f 100644
--- a/sys/arm64/conf/GENERIC
+++ b/sys/arm64/conf/GENERIC
@@ -32,6 +32,7 @@ options   INET# InterNETworking
 optionsINET6   # IPv6 communications protocols
 optionsIPSEC_SUPPORT   # Allow kldload of ipsec and tcpmd5
 optionsROUTE_MPATH # Multipath routing support
+optionsFIB_ALGO# Modular fib lookups
 optionsTCP_OFFLOAD # TCP offload
 optionsTCP_HHOOK   # hhook(9) framework for TCP
 optionsTCP_RFC7413 # TCP Fast Open
___
dev-commits-src-main@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-main
To unsubscribe, send any mail to "dev-commits-src-main-unsubscr...@freebsd.org"


git: a81e2e7890c2 - main - Make gcc happy by initializing error in rib_handle_ifaddr_info().

2021-04-25 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit a81e2e7890c2fce2a74dbb859e6855e0414a6ea1
Author: Alexander V. Chernikov 
AuthorDate: 2021-04-25 08:44:20 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-04-25 08:44:59 +

Make gcc happy by initializing error in rib_handle_ifaddr_info().
---
 sys/net/route/route_ifaddrs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sys/net/route/route_ifaddrs.c b/sys/net/route/route_ifaddrs.c
index e6d97f3c74f0..15ee13201059 100644
--- a/sys/net/route/route_ifaddrs.c
+++ b/sys/net/route/route_ifaddrs.c
@@ -100,7 +100,7 @@ rib_handle_ifaddr_one(uint32_t fibnum, int cmd, struct 
rt_addrinfo *info)
 int
 rib_handle_ifaddr_info(uint32_t fibnum, int cmd, struct rt_addrinfo *info)
 {
-   int error, last_error = 0;
+   int error = 0, last_error = 0;
bool didwork = false;
 
if (V_rt_add_addr_allfibs == 0) {
___
dev-commits-src-main@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-main
To unsubscribe, send any mail to "dev-commits-src-main-unsubscr...@freebsd.org"


git: c23385612da5 - main - [fib algo] Do not print algo attach/detach message on boot

2021-04-25 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit c23385612da5dd3195a9b73bfb22bd969dbd26c2
Author: Alexander V. Chernikov 
AuthorDate: 2021-04-25 08:51:57 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-04-25 08:58:06 +

[fib algo] Do not print algo attach/detach message on boot

MFC after:  1 day
---
 sys/net/route/fib_algo.c | 8 +---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/sys/net/route/fib_algo.c b/sys/net/route/fib_algo.c
index cd7abd282728..43db482d73da 100644
--- a/sys/net/route/fib_algo.c
+++ b/sys/net/route/fib_algo.c
@@ -239,7 +239,9 @@ SYSCTL_INT(_net_route_algo, OID_AUTO, debug_level, 
CTLFLAG_RW | CTLFLAG_RWTUN,
 #endif
 
 #define_PASS_MSG(_l)   (flm_debug_level >= (_l))
-#defineALGO_PRINTF(_fmt, ...)  printf("[fib_algo] %s: " _fmt "\n", 
__func__, ##__VA_ARGS__)
+#defineALGO_PRINTF(_l, _fmt, ...)  if (_PASS_MSG(_l)) {
\
+   printf("[fib_algo] %s: " _fmt "\n", __func__, ##__VA_ARGS__);   \
+}
 #define_ALGO_PRINTF(_fib, _fam, _aname, _gen, _func, _fmt, ...) \
 printf("[fib_algo] %s.%u (%s#%u) %s: " _fmt "\n",\
 print_family(_fam), _fib, _aname, _gen, _func, ## __VA_ARGS__)
@@ -1971,7 +1973,7 @@ fib_module_register(struct fib_lookup_module *flm)
 {
 
FIB_MOD_LOCK();
-   ALGO_PRINTF("attaching %s to %s", flm->flm_name,
+   ALGO_PRINTF(LOG_INFO, "attaching %s to %s", flm->flm_name,
print_family(flm->flm_family));
TAILQ_INSERT_TAIL(&all_algo_list, flm, entries);
FIB_MOD_UNLOCK();
@@ -1995,7 +1997,7 @@ fib_module_unregister(struct fib_lookup_module *flm)
return (EBUSY);
}
fib_error_clear_flm(flm);
-   ALGO_PRINTF("detaching %s from %s", flm->flm_name,
+   ALGO_PRINTF(LOG_INFO, "detaching %s from %s", flm->flm_name,
print_family(flm->flm_family));
TAILQ_REMOVE(&all_algo_list, flm, entries);
FIB_MOD_UNLOCK();
___
dev-commits-src-main@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-main
To unsubscribe, send any mail to "dev-commits-src-main-unsubscr...@freebsd.org"


git: 67372fb3e06e - main - Fix NOINET[6] build after enabling FIB_ALGO in GENERIC.

2021-04-25 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit 67372fb3e06ebaccfe7c093aa78009d161fa58e6
Author: Alexander V. Chernikov 
AuthorDate: 2021-04-21 01:45:49 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-04-21 01:49:18 +

Fix NOINET[6] build after enabling FIB_ALGO in GENERIC.

Submitted by:   jbeich
PR: 255389
---
 sys/net/route/fib_algo.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/sys/net/route/fib_algo.c b/sys/net/route/fib_algo.c
index 43db482d73da..83fff1ec43e0 100644
--- a/sys/net/route/fib_algo.c
+++ b/sys/net/route/fib_algo.c
@@ -706,12 +706,16 @@ fill_change_entry(struct fib_data *fd, struct 
fib_change_entry *ce, struct rib_c
int plen = 0;
 
switch (fd->fd_family) {
+#ifdef INET
case AF_INET:
rt_get_inet_prefix_plen(rc->rc_rt, &ce->addr4, &plen, 
&ce->scopeid);
break;
+#endif
+#ifdef INET6
case AF_INET6:
rt_get_inet6_prefix_plen(rc->rc_rt, &ce->addr6, &plen, 
&ce->scopeid);
break;
+#endif
}
 
ce->plen = plen;
___
dev-commits-src-main@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-main
To unsubscribe, send any mail to "dev-commits-src-main-unsubscr...@freebsd.org"


git: 7d222ce3c10b - main - Fix NOINET[6], !VIMAGE builds after FIB_ALGO addition to GENERIC

2021-04-25 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit 7d222ce3c10bdc23c8dc92d6b13e376ede5840d5
Author: Alexander V. Chernikov 
AuthorDate: 2021-04-21 04:52:38 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-04-21 04:53:42 +

Fix NOINET[6],!VIMAGE builds after FIB_ALGO addition to GENERIC

Reported by:jbeich
PR: 255390
---
 sys/net/route/fib_algo.c | 16 ++--
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/sys/net/route/fib_algo.c b/sys/net/route/fib_algo.c
index 83fff1ec43e0..5dff2690454d 100644
--- a/sys/net/route/fib_algo.c
+++ b/sys/net/route/fib_algo.c
@@ -108,19 +108,19 @@ SYSCTL_NODE(_net_route, OID_AUTO, algo, CTLFLAG_RW | 
CTLFLAG_MPSAFE, 0,
 /* Algorithm sync policy */
 
 /* Time interval to bucket updates */
-VNET_DEFINE(unsigned int, bucket_time_ms) = 50;
-#defineV_bucket_time_msVNET(bucket_time_ms)
+VNET_DEFINE_STATIC(unsigned int, update_bucket_time_ms) = 50;
+#defineV_update_bucket_time_ms VNET(update_bucket_time_ms)
 SYSCTL_UINT(_net_route_algo, OID_AUTO, bucket_time_ms, CTLFLAG_RW | 
CTLFLAG_VNET,
-&VNET_NAME(bucket_time_ms), 0, "Time interval to calculate update rate");
+&VNET_NAME(update_bucket_time_ms), 0, "Time interval to calculate update 
rate");
 
 /* Minimum update rate to delay sync */
-VNET_DEFINE(unsigned int, bucket_change_threshold_rate) = 500;
+VNET_DEFINE_STATIC(unsigned int, bucket_change_threshold_rate) = 500;
 #defineV_bucket_change_threshold_rate  
VNET(bucket_change_threshold_rate)
 SYSCTL_UINT(_net_route_algo, OID_AUTO, bucket_change_threshold_rate, 
CTLFLAG_RW | CTLFLAG_VNET,
 &VNET_NAME(bucket_change_threshold_rate), 0, "Minimum update rate to delay 
sync");
 
 /* Max allowed delay to sync */
-VNET_DEFINE(unsigned int, fib_max_sync_delay_ms) = 1000;
+VNET_DEFINE_STATIC(unsigned int, fib_max_sync_delay_ms) = 1000;
 #defineV_fib_max_sync_delay_ms VNET(fib_max_sync_delay_ms)
 SYSCTL_UINT(_net_route_algo, OID_AUTO, fib_max_sync_delay_ms, CTLFLAG_RW | 
CTLFLAG_VNET,
 &VNET_NAME(fib_max_sync_delay_ms), 0, "Maximum time to delay sync (ms)");
@@ -589,7 +589,7 @@ update_rebuild_delay(struct fib_data *fd, enum 
fib_callout_action action)
struct timeval tv;
 
/* Fetch all variables at once to ensure consistent reads */
-   uint32_t bucket_time_ms = V_bucket_time_ms;
+   uint32_t bucket_time_ms = V_update_bucket_time_ms;
uint32_t threshold_rate = V_bucket_change_threshold_rate;
uint32_t max_delay_ms = V_fib_max_sync_delay_ms;
 
@@ -1618,10 +1618,14 @@ static struct fib_dp **
 get_family_dp_ptr(int family)
 {
switch (family) {
+#ifdef INET
case AF_INET:
return (&V_inet_dp);
+#endif
+#ifdef INET6
case AF_INET6:
return (&V_inet6_dp);
+#endif
}
return (NULL);
 }
___
dev-commits-src-main@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-main
To unsubscribe, send any mail to "dev-commits-src-main-unsubscr...@freebsd.org"


git: bc5ef45aec3f - main - Fix drace CTF for the rib_head.

2021-04-27 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit bc5ef45aec3fa8acf2dd3408cebd207317543a8b
Author: Alexander V. Chernikov 
AuthorDate: 2021-04-27 07:47:53 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-04-27 07:47:53 +

Fix drace CTF for the rib_head.

33cb3cb2e321 introduced an `rib_head` structure field under the
FIB_ALGO define. This may be problematic for the CTF, as some
 of the files including `route_var.h` do not have `fib_algo`
 defined.

Make dtrace happy by making the field unconditional.

Suggested by:   markj
---
 sys/net/route/route_var.h | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/sys/net/route/route_var.h b/sys/net/route/route_var.h
index f12931476fd3..86fc64493e75 100644
--- a/sys/net/route/route_var.h
+++ b/sys/net/route/route_var.h
@@ -71,9 +71,7 @@ struct rib_head {
struct callout  expire_callout; /* Callout for expiring dynamic 
routes */
time_t  next_expire;/* Next expire run ts */
uint32_trnh_prefixes;   /* Number of prefixes */
-#ifdef FIB_ALGO
-   rt_gen_trnh_gen_rib;/* rib generation counter */
-#endif
+   rt_gen_trnh_gen_rib;/* fib algo: rib generation 
counter */
uint32_trib_dying:1;/* rib is detaching */
uint32_trib_algo_fixed:1;/* fixed algorithm */
struct nh_control   *nh_control;/* nexthop subsystem data */
___
dev-commits-src-main@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-main
To unsubscribe, send any mail to "dev-commits-src-main-unsubscr...@freebsd.org"


git: 25682e6a495f - main - Fix rtsock sockaddr alignment.

2021-04-27 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit 25682e6a495fc6669d799bb64acdaf14d653173e
Author: Alexander V. Chernikov 
AuthorDate: 2021-04-27 08:04:19 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-04-27 08:04:19 +

Fix rtsock sockaddr alignment.

b31fbebeb3 introduced alloc_sockaddr_aligned() which, in fact,
 failed to produce aligned addresses.

Reported by:Oskar Holmlund 
MFC after:  immediately
---
 sys/net/rtsock.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sys/net/rtsock.c b/sys/net/rtsock.c
index fae15fdf4be6..6930bd167ac1 100644
--- a/sys/net/rtsock.c
+++ b/sys/net/rtsock.c
@@ -1009,7 +1009,7 @@ save_add_notification(struct rib_cmd_info *rc, void 
*_cbdata)
 static struct sockaddr *
 alloc_sockaddr_aligned(struct linear_buffer *lb, int len)
 {
-   len |= (sizeof(uint64_t) - 1);
+   len = roundup2(len, sizeof(uint64_t));
if (lb->offset + len > lb->size)
return (NULL);
struct sockaddr *sa = (struct sockaddr *)(lb->base + lb->offset);
___
dev-commits-src-main@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-main
To unsubscribe, send any mail to "dev-commits-src-main-unsubscr...@freebsd.org"


git: 439d087d0b55 - main - [fib algo] always commit static routes synchronously.

2021-04-27 Thread Alexander V. Chernikov
The branch main has been updated by melifaro:

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

commit 439d087d0b55574db81f4a2799a411c1236d95e3
Author: Alexander V. Chernikov 
AuthorDate: 2021-04-27 08:23:29 +
Commit: Alexander V. Chernikov 
CommitDate: 2021-04-27 08:31:40 +

[fib algo] always commit static routes synchronously.

Modular fib lookup framework features logic that allows
 route update batching for the algorithms that cannot easily
 apply the routing change without rebuilding. As a result,
 dataplane lookups may return old data until the the sync
 takes place. With the default sync timeout of 50ms, it is
 possible that new binary like ping(8) executed exactly after
 route(8) will still use the old fib data.

To address some aspects of the problem, framework executes
 all rtable changes without RTF_GATEWAY synchronously.

To fix the aforementioned problem, this diff extends sync
 execution for all RTF_STATIC routes (e.g. ones maintained by
 route(8).
This fixes a bunch of tests in the networking space.

Reported by:ci, arichardson
MFC after:  2 weeks
---
 sys/net/route/fib_algo.c | 16 
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/sys/net/route/fib_algo.c b/sys/net/route/fib_algo.c
index 5dff2690454d..9fdc80001986 100644
--- a/sys/net/route/fib_algo.c
+++ b/sys/net/route/fib_algo.c
@@ -667,13 +667,21 @@ need_immediate_sync(struct fib_data *fd, struct 
rib_cmd_info *rc)
switch (rc->rc_cmd) {
case RTM_ADD:
nh = rc->rc_nh_new;
-   if (!NH_IS_NHGRP(nh) && (!(nh->nh_flags & NHF_GATEWAY)))
-   return (true);
+   if (!NH_IS_NHGRP(nh)) {
+   if (!(nh->nh_flags & NHF_GATEWAY))
+   return (true);
+   if (nhop_get_rtflags(nh) & RTF_STATIC)
+   return (true);
+   }
break;
case RTM_DELETE:
nh = rc->rc_nh_old;
-   if (!NH_IS_NHGRP(nh) && (!(nh->nh_flags & NHF_GATEWAY)))
-   return (true);
+   if (!NH_IS_NHGRP(nh)) {
+   if (!(nh->nh_flags & NHF_GATEWAY))
+   return (true);
+   if (nhop_get_rtflags(nh) & RTF_STATIC)
+   return (true);
+   }
break;
}
 
___
dev-commits-src-main@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-main
To unsubscribe, send any mail to "dev-commits-src-main-unsubscr...@freebsd.org"


Re: git: 5d1403a79a3e - main - [rtsock] Enforce netmask/RTF_HOST consistency.

2021-04-27 Thread Alexander V . Chernikov


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


  1   2   3   4   5   6   >