I'd like to keep rtalloc(9) for the hot path since it increments the use
counter. This will become more important when routes entries will be
cached in PF states. This counter will allow us to really see how many
times a lookup have been done.
So here's a diff that change a rtalloc(9) into rtable_match() when
checking for an existing entry.
ok?
Index: sys/net/route.c
===================================================================
RCS file: /cvs/src/sys/net/route.c,v
retrieving revision 1.351
diff -u -p -r1.351 route.c
--- sys/net/route.c 15 Feb 2017 18:53:29 -0000 1.351
+++ sys/net/route.c 22 Feb 2017 12:03:12 -0000
@@ -1084,7 +1084,8 @@ rtrequest(int req, struct rt_addrinfo *i
error = rtable_insert(tableid, ndst,
info->rti_info[RTAX_NETMASK], info->rti_info[RTAX_GATEWAY],
rt->rt_priority, rt);
- if (error != 0 && (crt = rtalloc(ndst, 0, tableid)) != NULL) {
+ if (error != 0 &&
+ (crt = rtable_match(tableid, ndst, NULL)) != NULL) {
/* overwrite cloned route */
if (ISSET(crt->rt_flags, RTF_CLONED)) {
struct ifnet *cifp;
Index: regress/sbin/route/rttest3.ok
===================================================================
RCS file: /cvs/src/regress/sbin/route/rttest3.ok,v
retrieving revision 1.9
diff -u -p -r1.9 rttest3.ok
--- regress/sbin/route/rttest3.ok 1 Sep 2016 11:36:15 -0000 1.9
+++ regress/sbin/route/rttest3.ok 22 Feb 2017 12:07:46 -0000
@@ -2,7 +2,7 @@ Routing tables
Internet:
Destination Gateway Flags Refs Use Mtu Prio Iface
-10.8.1/24 192.0.2.3 UGS 0 1 32768 8 lo10003
+10.8.1/24 192.0.2.3 UGS 0 0 32768 8 lo10003
192.0.2.1 192.0.2.1 UHl 0 0 32768 1 lo10001
192.0.2.2 192.0.2.2 UHl 0 0 32768 1 lo10002
192.0.2.3 192.0.2.3 UHhl 1 4 32768 1 lo10003
Index: regress/sbin/route/rttest5.ok
===================================================================
RCS file: /cvs/src/regress/sbin/route/rttest5.ok,v
retrieving revision 1.9
diff -u -p -r1.9 rttest5.ok
--- regress/sbin/route/rttest5.ok 1 Sep 2016 11:36:15 -0000 1.9
+++ regress/sbin/route/rttest5.ok 22 Feb 2017 12:07:46 -0000
@@ -2,7 +2,7 @@ Routing tables
Internet:
Destination Gateway Flags Refs Use Mtu Prio Iface
-10.8.1/24 192.0.2.2 UGS 0 1 32768 16 lo10002
+10.8.1/24 192.0.2.2 UGS 0 0 32768 16 lo10002
10.8.1/24 192.0.2.2 UGS 0 0 32768 17 lo10002
10.8.1/24 192.0.2.2 UGS 0 0 32768 18 lo10002
192.0.2.1 192.0.2.1 UHl 0 0 32768 1 lo10001
Index: regress/sbin/route/rttest6.ok
===================================================================
RCS file: /cvs/src/regress/sbin/route/rttest6.ok,v
retrieving revision 1.9
diff -u -p -r1.9 rttest6.ok
--- regress/sbin/route/rttest6.ok 1 Sep 2016 11:36:15 -0000 1.9
+++ regress/sbin/route/rttest6.ok 22 Feb 2017 12:07:46 -0000
@@ -2,7 +2,7 @@ Routing tables
Internet:
Destination Gateway Flags Refs Use Mtu Prio Iface
-10.8.1/24 192.0.2.1 UGS 0 1 32768 16 lo10001
+10.8.1/24 192.0.2.1 UGS 0 0 32768 16 lo10001
10.8.1/24 192.0.2.2 UGS 0 0 32768 17 lo10002
10.8.1/24 192.0.2.3 UGS 0 0 32768 18 lo10003
192.0.2.1 192.0.2.1 UHhl 1 2 32768 1 lo10001
Index: regress/sbin/route/rttest8.ok
===================================================================
RCS file: /cvs/src/regress/sbin/route/rttest8.ok,v
retrieving revision 1.10
diff -u -p -r1.10 rttest8.ok
--- regress/sbin/route/rttest8.ok 1 Sep 2016 11:36:15 -0000 1.10
+++ regress/sbin/route/rttest8.ok 22 Feb 2017 12:07:46 -0000
@@ -2,7 +2,7 @@ Routing tables
Internet:
Destination Gateway Flags Refs Use Mtu Prio Iface
-10.8.1/24 192.0.2.1 UGS 0 1 32768 16 lo10001
+10.8.1/24 192.0.2.1 UGS 0 0 32768 16 lo10001
10.8.1/24 192.0.2.3 UGS 0 0 32768 18 lo10003
10.8.1/24 192.0.2.2 GS 0 0 32768 17 lo10002
192.0.2.1 192.0.2.1 UHhl 1 2 32768 1 lo10001