summaryrefslogtreecommitdiff
path: root/regress
diff options
context:
space:
mode:
authorMartin Pieuchot <mpi@cvs.openbsd.org>2015-11-04 09:45:53 +0000
committerMartin Pieuchot <mpi@cvs.openbsd.org>2015-11-04 09:45:53 +0000
commit69c539482201a6a020707bac6a4915af49a8a886 (patch)
tree336bcb17c49fd43e8d48425220f7545760f88bb7 /regress
parent171b7cf2a516c8dac258d3513d855ae01accf5e2 (diff)
Basic framework to test the rtable_* API directly from userland.
You can replace inet{,6}-fullfeed.txt with a dump of your fullfeed table to really stress this test framework. I did not commit them because CVS certainly doesn't like ~7M file.
Diffstat (limited to 'regress')
-rw-r--r--regress/sys/net/rtable/Makefile5
-rw-r--r--regress/sys/net/rtable/Makefile.inc14
-rw-r--r--regress/sys/net/rtable/README2
-rw-r--r--regress/sys/net/rtable/delete/Makefile11
-rw-r--r--regress/sys/net/rtable/delete/main.c55
-rw-r--r--regress/sys/net/rtable/fullfeed/Makefile21
-rw-r--r--regress/sys/net/rtable/fullfeed/main.c61
-rw-r--r--regress/sys/net/rtable/inet-fullfeed.txt500
-rw-r--r--regress/sys/net/rtable/inet6-fullfeed.txt500
-rw-r--r--regress/sys/net/rtable/kern_compat.h54
-rw-r--r--regress/sys/net/rtable/util.c404
-rw-r--r--regress/sys/net/rtable/util.h32
12 files changed, 1659 insertions, 0 deletions
diff --git a/regress/sys/net/rtable/Makefile b/regress/sys/net/rtable/Makefile
new file mode 100644
index 00000000000..b456466bc3b
--- /dev/null
+++ b/regress/sys/net/rtable/Makefile
@@ -0,0 +1,5 @@
+# $OpenBSD: Makefile,v 1.1 2015/11/04 09:45:52 mpi Exp $
+
+SUBDIR = fullfeed delete
+
+.include <bsd.subdir.mk>
diff --git a/regress/sys/net/rtable/Makefile.inc b/regress/sys/net/rtable/Makefile.inc
new file mode 100644
index 00000000000..8e22e827dfa
--- /dev/null
+++ b/regress/sys/net/rtable/Makefile.inc
@@ -0,0 +1,14 @@
+# $OpenBSD: Makefile.inc,v 1.1 2015/11/04 09:45:52 mpi Exp $
+
+TOPDIR= ${.CURDIR}/..
+
+.ifdef ART
+SRCS+= art.c
+CFLAGS+= -DART
+.else
+SRCS+= radix.c
+.endif
+
+CPPFLAGS+= -I${TOPDIR} -Wall -DSMALL_KERNEL
+
+.PATH: ${TOPDIR} ${TOPDIR}/../../../../sys/net
diff --git a/regress/sys/net/rtable/README b/regress/sys/net/rtable/README
new file mode 100644
index 00000000000..a3599cdd8a1
--- /dev/null
+++ b/regress/sys/net/rtable/README
@@ -0,0 +1,2 @@
+fullfeed: tests that a fullfeed dump is correctly inserted in the table
+delete: tests that deleting entries with rtable_walk() is safe
diff --git a/regress/sys/net/rtable/delete/Makefile b/regress/sys/net/rtable/delete/Makefile
new file mode 100644
index 00000000000..928bf640d95
--- /dev/null
+++ b/regress/sys/net/rtable/delete/Makefile
@@ -0,0 +1,11 @@
+# $OpenBSD: Makefile,v 1.1 2015/11/04 09:45:52 mpi Exp $
+
+PROG= delete
+SRCS= main.c util.c rtable.c
+
+REGRESS_TARGETS+= fullfeed
+
+${REGRESS_TARGETS}: ${PROG}
+ ${PROG} ${TOPDIR}/inet6-${.TARGET}.txt
+
+.include <bsd.regress.mk>
diff --git a/regress/sys/net/rtable/delete/main.c b/regress/sys/net/rtable/delete/main.c
new file mode 100644
index 00000000000..a2e8c9ac40a
--- /dev/null
+++ b/regress/sys/net/rtable/delete/main.c
@@ -0,0 +1,55 @@
+/* $OpenBSD: main.c,v 1.1 2015/11/04 09:45:52 mpi Exp $ */
+
+/*
+ * Copyright (c) 2015 Martin Pieuchot
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/socket.h>
+#include <net/route.h>
+
+#include <err.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "util.h"
+
+__dead void
+usage(void)
+{
+ extern const char *__progname;
+ fprintf(stderr, "Usage: %s <file>\n", __progname);
+ exit(1);
+}
+
+int
+main(int argc, char *argv[])
+{
+ char *filename;
+
+ if (argc != 2)
+ usage();
+
+ filename = argv[1];
+
+ rtable_init();
+ if (rtable_add(0))
+ errx(1, "can't add rtable\n");
+
+ do_from_file(0, AF_INET6, filename, route_insert);
+
+ rtable_walk(0, AF_INET6, rtentry_delete, NULL);
+
+ return (0);
+}
diff --git a/regress/sys/net/rtable/fullfeed/Makefile b/regress/sys/net/rtable/fullfeed/Makefile
new file mode 100644
index 00000000000..cb612fcc4f0
--- /dev/null
+++ b/regress/sys/net/rtable/fullfeed/Makefile
@@ -0,0 +1,21 @@
+# $OpenBSD: Makefile,v 1.1 2015/11/04 09:45:52 mpi Exp $
+
+PROG= fullfeed
+SRCS= main.c util.c rtable.c
+
+
+REGRESS_TARGETS+= inet inet6
+
+# XXX route entries are sorted because the radix tree stores dup chains
+# XXX from the most specific to least specific
+.SUFFIXES: .txt .sorted
+.txt.sorted:
+ sort $< > $@
+
+CLEANFILES+= *.sorted
+
+${REGRESS_TARGETS}: ${PROG} ${.TARGET}-fullfeed.sorted
+ ${PROG} ${.TARGET} ${TOPDIR}/${.TARGET}-fullfeed.txt | \
+ sort | diff -u ${.TARGET}-fullfeed.sorted /dev/stdin
+
+.include <bsd.regress.mk>
diff --git a/regress/sys/net/rtable/fullfeed/main.c b/regress/sys/net/rtable/fullfeed/main.c
new file mode 100644
index 00000000000..4fbcb3b1d44
--- /dev/null
+++ b/regress/sys/net/rtable/fullfeed/main.c
@@ -0,0 +1,61 @@
+/* $OpenBSD: main.c,v 1.1 2015/11/04 09:45:52 mpi Exp $ */
+
+/*
+ * Copyright (c) 2015 Martin Pieuchot
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/socket.h>
+#include <net/route.h>
+
+#include <err.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "util.h"
+
+__dead void
+usage(void)
+{
+ extern const char *__progname;
+ fprintf(stderr, "Usage: %s [inet|inet6] <file>\n", __progname);
+ exit(1);
+}
+
+int
+main(int argc, char *argv[])
+{
+ char *filename;
+ sa_family_t af;
+
+ if (argc != 3)
+ usage();
+
+ af = strncmp(argv[1], "inet6", 5) ? AF_INET : AF_INET6;
+ filename = argv[2];
+
+ rtable_init();
+ if (rtable_add(0))
+ errx(1, "can't add rtable\n");
+
+ do_from_file(0, af, filename, route_insert);
+ do_from_file(0, af, filename, route_lookup);
+
+ rtable_walk(0, af, rtentry_dump, NULL);
+
+ do_from_file(0, af, filename, route_delete);
+
+ return (0);
+}
diff --git a/regress/sys/net/rtable/inet-fullfeed.txt b/regress/sys/net/rtable/inet-fullfeed.txt
new file mode 100644
index 00000000000..d471dcb3958
--- /dev/null
+++ b/regress/sys/net/rtable/inet-fullfeed.txt
@@ -0,0 +1,500 @@
+188.224.196/24
+12.255.83/24
+70.39.191/24
+201.130.12/24
+207.211.0/19
+216.16.175/24
+137.238/16
+31.130.200/24
+103.224.48/24
+178.250.92/24
+84.53.132/23
+103.37.10/23
+147.241.192/18
+179.50.4/24
+177.101.144/20
+185.56.240/22
+91.213.230/24
+190.152.165/24
+94.143.86/24
+121.45.160/19
+131.70.204/24
+194.190.76/23
+103.15.42/24
+37.56.0/17
+177.124.113/24
+202.70.118/24
+192.5.66/24
+115.178.114/23
+49.246.132/22
+66.117.16/24
+99.196.160/20
+60.50/15
+104.238.88/22
+180.212.142/24
+88.158.79/24
+208.166.48/20
+201.238.173/24
+190.95.150/24
+143.69.148/24
+182.253.46/24
+207.161.128/22
+190.196.244/24
+46.201.4/22
+67.98.201/24
+181.28.32/19
+70.52.156/22
+114.134.112/20
+115.159.148/23
+64.251.56/22
+179.184.76/22
+103.18.31/24
+205.166.216/24
+64.234.18/24
+24.247.64/20
+67.77.12/23
+181.225.72/24
+42.74.128/17
+199.248.166/24
+56.105.128/24
+199.5.26/24
+209.40.96/19
+91.239.241/24
+118.98.106/23
+23.248.183/24
+200.23.143/24
+91.146.252/22
+200.25.128/20
+121.242.22/23
+95.170.144/23
+41.249.32/21
+173.26.146/23
+208.80.224/24
+208.57.128/21
+37.230.193/24
+146.222.59/24
+78.24.208/21
+177.125.93/24
+14.50.76/24
+206.81.94/24
+111.30.133/24
+193.150.24/24
+189.25.192/18
+109.70.244/22
+71.82.176/20
+91.208.153/24
+125.21.72/24
+213.248.180/22
+206.193.170/24
+186.85.112/22
+69.84.235/24
+68.28.124/24
+185.89.244/22
+216.86.2/24
+210.87.43/24
+201.161.56/24
+192.64.67/24
+46.40.192/18
+178.22.13/24
+185.20.226/23
+103.228.147/24
+66.53.92/22
+209.136.38/24
+194.85.48/21
+112.196.8/24
+122.183.104/24
+110.163.18/23
+23.58.90/23
+202.28.64/24
+190.111.202/24
+133.14/16
+81.199.250/23
+209.54.120/24
+95.168.68/23
+89.240/14
+184.62.16/21
+66.81.81/24
+204.130.176/24
+204.119.25/24
+63.194.139/24
+207.35.18/24
+116.58.89/24
+4.16.62/23
+122.10.39/24
+167.64.92/24
+99.207.224/22
+207.171.206/24
+74.112.65/24
+202.88.247/24
+65.94.96/22
+116.50.225/24
+190.159.56/23
+146.16.116/23
+193.242.215/24
+193.242.103/24
+180.247.212/22
+67.55.10/23
+108.20/16
+125.209.113/24
+208.38.67/24
+64.229.136/22
+208.81.67/24
+220.146/15
+176.115.161/24
+65.211.84/24
+14.102.106/24
+59.101.10/24
+72.251.27/24
+80.214.128/18
+82.222.186/24
+109.251.165/24
+124.125.161/24
+178.216.232/21
+193.194.8/23
+211.241.77/24
+179.42.232/21
+177.87.20/24
+186.64.236/23
+46.34.72/23
+190.220.72/21
+203.111.85/24
+168.120.140/22
+84.55.0/20
+178.218.158/24
+160.131.67/24
+66.199.137/24
+72.29.128/20
+190.152.41/24
+203.101.116/24
+204.111.208/24
+170.194.18/23
+61.151.196/22
+203.25.176/24
+197.34.96/20
+24.153.111/24
+91.194.220/23
+150.198.17/24
+77.30.176/20
+190.153.48/24
+206.111.138/24
+77.87.232/21
+121.240.253/24
+115.108.108/24
+154.52.115/24
+37.239.24/21
+223.252.181/24
+148.80.254/23
+84.90.48/21
+165.193.75/24
+205.233.178/24
+202.43.139/24
+125.168.28/22
+194.105.224/19
+69.163.92/24
+81.22.195/24
+212.52.60/23
+78.100.64/20
+174.95.196/22
+125.19.193.96/29
+192.198.0/22
+59.56.74/24
+107.162.32/24
+125.99.119/24
+95.31.251/24
+210.210.5/24
+192.111.0/24
+5.140.234/24
+210.7.48/21
+222.61.160/22
+39.9/16
+216.162.13/24
+190.248.66/24
+101.167.192/22
+198.144.102/23
+69.171.224/20
+65.202.192/24
+203.27.58/24
+81.93.228/24
+117.135.222/24
+93.174.51/24
+195.142.160/24
+77.74.248/21
+141.105.103/24
+64.74.198/24
+41.214.172/22
+120.63.120/22
+145.225.150/23
+61.16.252/22
+190.60.64/19
+190.146.30/24
+192.30.10/24
+202.45.140/24
+192.158.252/24
+87.123/16
+96.45.48/22
+95.30/16
+190.121.227/24
+206.131.185/24
+195.110.39/24
+148.231.120/23
+83.172.111.248/29
+181.47.240/20
+194.44.172/24
+77.244.112/24
+110.49.242/24
+142.222/16
+209.163.180/24
+89.17.216/21
+184.170.184/21
+195.142.224/20
+200.83.224/24
+116.88.49/24
+49.239.191/24
+66.249.133/24
+27.112.67/24
+4.34.6/23
+211.156.208/24
+185.84.36/22
+118.26.160/21
+188.133.240/20
+138.123.100/24
+209.40.144/24
+209.233.177/24
+138.128.169/24
+85.115.232/23
+77.246.184/24
+89.29.229/24
+87.71.0/17
+203.234.101/24
+160.131.43/24
+57.250.243.0/25
+66.253.101/24
+85.10.64/18
+193.108.204/24
+207.144.219/24
+5.32.152/21
+136.223.11/24
+136.145.18/24
+216.220.87/24
+104.89.192/20
+74.80.222/24
+122.160.152/24
+168.144.59/24
+82.201.130/24
+192.71.95/24
+199.62.35/24
+208.69.160/21
+193.160.131/24
+202.124.159/24
+94.67/16
+115.64.168/23
+41.143.200/21
+24.181.0/20
+185.46.223/24
+217.72.221/24
+123.30.232/21
+123.136.172/24
+75.158.128/19
+186.148.142/24
+181.168.208/20
+216.246.128/20
+123.86.192/18
+69.18.105/24
+192.230.219/24
+195.32.56/21
+203.178.127/24
+185.18.72/22
+95.187.139/24
+199.202.234/23
+217.73.144/20
+216.126.122/24
+172.103.114/24
+64.111.72/21
+103.9.212/24
+117.210.208/20
+213.243.64/18
+190.25.32/20
+94.28.43/24
+121.247.190/23
+5.202.50/24
+158.58.136/21
+202.202.64/20
+98.173.28/24
+138.108.61/24
+217.72.160/19
+192.109.99/24
+181.174.10/23
+112.5.105/24
+219.177/16
+2.72.128/18
+70.62.112/20
+140.133.64/20
+200.6.116/23
+142.234.168/21
+125.212.64/23
+61.100.112/22
+132.251.248/21
+162.245.210/24
+122.70.128/18
+57.80.153/24
+199.103.211/24
+182.16.238/24
+210.98.128/18
+124.248.247/24
+71.123.0/20
+192.129.7/24
+168.151.230/24
+64.254.45/24
+190.90.114/24
+200.43.112/21
+216.21.215/24
+216.12.255/24
+211.47.82/24
+172.103.119/24
+162.249.62/24
+111.93.119/24
+94.203.128/19
+190.152.69/24
+205.176.73/24
+186.15.192/22
+27.111.125/24
+174.46.9/24
+203.253.106/24
+61.200.112/20
+204.112.4/23
+212.68.180/24
+185.12.126/24
+14.140.6/23
+5.42.192/23
+122.70.136/21
+31.134.120/21
+147.63/16
+173.247.227/24
+60.241.174/23
+68.206/16
+112.215.65/24
+190.254.4/24
+91.218.86/24
+152.192/13
+68.216.64/24
+168.78.238/24
+61.102.128/21
+177.13.56/24
+59.144.10/24
+216.241.1/24
+137.250/16
+163.10.10/24
+128.71.12/24
+5.222.64/20
+207.249.91/24
+191.242.215/24
+131.108.160/24
+117.224.128/20
+197.31.224/19
+123.241.208/22
+181.192.27/24
+152.62.112/24
+201.234.188/24
+117.121.200/24
+95.105.24/24
+157.56/16
+188.164.32/21
+103.4.202/24
+85.173.160/19
+187.61.13/24
+187.12.128/19
+117.211.32/20
+123.73.128/21
+195.210.9/24
+79.133.55.254/32
+200.63.240/20
+43.230.36/24
+174.34.48/21
+14.136/16
+38.80.68/23
+79.126.64/19
+97.85.0/21
+168.143.92/24
+91.151.73/24
+140.168.128/18
+95.111.34/24
+91.93.31/24
+170.202.204/24
+180.179.113/24
+14.201.104/24
+67.214.39/24
+202.67.223/24
+162.119.0/23
+139.1.144/21
+74.201.101/24
+24.248.155/24
+144.146/16
+204.10.170/24
+91.217.242/24
+198.177.2/24
+213.149.128/24
+216.21.211/24
+186.147.104/22
+123.60.177/24
+208.80.96/21
+86.51.26/24
+65.37.156/23
+214.69.122/24
+190.5.76/24
+213.156.120/22
+177.91.87/24
+223.62.207/24
+211.99.128/18
+65.97.48/20
+95.142.0/20
+72.252.144/21
+60.240.236/23
+81.163.102/23
+66.114.177/24
+103.250.116/22
+70.50.144/22
+131.176.149/24
+24.232.192/20
+80.184.111/24
+65.182.171/24
+108.167.128/22
+162.6.80/21
+192.161.90/23
+90.164.0/21
+216.213.130/24
+50.58.219/24
+77.93.172/24
+219.227.112/24
+64.190.14/23
+74.198.26/24
+67.159.54/24
+184.159.206/24
+205.167.40/24
+200.155.137/24
+8.34.96/20
+89.254.192/21
+24.156.64/18
+173.27.4/24
+196.203.12/22
+204.93.59/24
+216.212.132/23
+80.74.94/24
+185.61.237/24
+14.195.32/20
+23.92.74/24
+196.45.120/23
+193.234.200/24
+59.89.128/20
+183.218.128/17
+89.44.236/24
+217.147.40/24
+155.225.208/20
+186.14.136/21
+192.31.102/24
+177.185.102/24
+220.226.192/20
+104.223.207/24
+199.91.230/24
+79.139.56/21
+95.187.227/24
+24.160.227/24
diff --git a/regress/sys/net/rtable/inet6-fullfeed.txt b/regress/sys/net/rtable/inet6-fullfeed.txt
new file mode 100644
index 00000000000..69aa34654a3
--- /dev/null
+++ b/regress/sys/net/rtable/inet6-fullfeed.txt
@@ -0,0 +1,500 @@
+2a04:980::/29
+2a03:d680::/48
+2607:4e00::/32
+2a01:8580::/32
+2001:1688::/32
+2600:6001:f049::/48
+2620:47:c000::/48
+2001:d00::/32
+2406:3000:11:1004::/64
+2a01:b1c7::/32
+2404:8000:30::/48
+2607:7c00::/32
+2604:9780:14::/48
+2001:7a8:810::/44
+2a00:11e8::/32
+2a03:b500:2000::/35
+2600:6001:f04c::/48
+2a03:a400::/32
+2404:1a3::/32
+2a03:2e0::/32
+2a00:bd80::/32
+2a02:8108::/31
+2604:600::/33
+2a00:86c0:600::/48
+2605:b100:f700::/40
+2a02:26f0:5f::/48
+2408:8000::/24
+2804:1d80::/32
+2a04:d903::/32
+2406:c500:ff4::/48
+2001:468:c00::/40
+2604:2600::/32
+2001:4030::/32
+2001:590::451f:1f54/126
+2804:163c::/32
+2a00:1d48:5::/48
+2a03:43e0::/32
+2607:6000:8000::/33
+2001:418:3807::/48
+2001:4c20:2::/48
+2001:4de0:4001:1::/64
+2a01:367:1337::/48
+2403:bc00:1::/48
+2a05:34c0::/29
+2001:67c:267c::/48
+2600:100e:b020::/44
+2a02:4800:4::/48
+2602:ffb0:1::/48
+2605:9580::/40
+2a02:cf40::/29
+2001:1580::/32
+2607:f820:101::/48
+2600:1402:b::/48
+2607:f758:4000::/38
+2a03:7380:3000::/42
+2400:2000::/20
+2a00:1c98:fff0::/44
+2a02:26f0:5c::/48
+2620:1a0::/56
+2604:880:c::/48
+2001:df0:2fd:2000::/52
+2001:504:b:11::/64
+2606:9400:f800:157::/64
+2a00:8940::/32
+2620:113:80c2::/48
+2600:1:a00c::/46
+2600:387:5::/48
+2001:678:18::/48
+2406:8800:10::/44
+2804:7cc::/32
+2a00:1d58:8003::/48
+2a05:cac0::/29
+2610:a1:1024::/48
+2620:107:9028::/48
+2a03:8460:1::/48
+2001:1490:100::/48
+2a00:4ae0::/35
+2a02:26f0:b1::/48
+2c0f:fc89:a::/48
+2a00:e10:200:5::/64
+2a00:86c0:300::/48
+2001:df0:2f5::/48
+2a00:4e40:1::/48
+2620:171:58::/48
+240e::/24
+2605:3100:fffb::/48
+2600:1:8a10::/44
+2401:ee00:201::/48
+2a03:8c00::/32
+2001:2b8:c6::/48
+2a00:8a20::/32
+2001:978:3200::/48
+2a02:ce0::/32
+2001:67c:10b8::/48
+2600:380:1800::/38
+2a02:4c8:af::/48
+2600:1009:b110::/44
+2a00:1d58:8008::/48
+2001:fd0::/40
+2620:10a:9045::/48
+2804:150::/30
+2001:4830::/32
+2001:a48::/32
+2600:1406:2d::/48
+2001:129c::/32
+2804:214:816f::/48
+2607:f370::/32
+2c0f:fc70::/32
+2001:5b0:100::/40
+2620:100::/46
+2a01:320::/32
+2a00:14a0:7::/48
+2607:fdc8:1:3024::/64
+2a00:f480::/32
+2600:1:8460::/44
+2001:978:6704::/48
+2804:480:1000::/41
+2001:569:c000::/34
+2a01:7c00:80::/44
+2001:67c:540::/48
+2600:1415:5::/48
+2001:4d78:200::/40
+2a00:90c0::/32
+2620:10a:9098::/48
+2a04:7781::/32
+2001:15b8::/32
+2001:43f8:241::/48
+2620:10a:9084::/48
+2400:d400:9898::/48
+2a04:8000::/29
+2400:3100:4000::/40
+2001:49f0:c000:500::/56
+2001:49f0:a018::/48
+2406:f000:1fff::/48
+2607:fb90:800::/40
+2001:13e0:e000:131::/64
+2a00:1480::/48
+2a00:1728:20::/48
+2a03:7ec0::/32
+2804:f70::/32
+2001:2b8:51::/48
+2403:9f00::/32
+2001:49f0:7002::/48
+2a02:17c8::/32
+2400:7b80::/30
+2406:3003:1033::/48
+2a00:11c0:1::/48
+2a02:958::/32
+2606:a400:4::/48
+2001:15e8::/32
+2600:1:c6f0::/44
+2001:550:8900::/48
+2001:4830:2600::/42
+2a01:ce8e:1000::/36
+2407:e700:2::/48
+2a03:c400::/32
+2a03:2100::/32
+2a00:1f50::/32
+2403:9600::/32
+2610:20:8000::/38
+2001:4858::/32
+2604:eb80::/32
+2a00:16e0::/32
+2a03:dc40:ffef::/48
+2001:590::451f:8738/126
+2620:10a:9003::/48
+2001:49f0:2028::/48
+2803:2500::/48
+2403:bd00::/32
+2a03:70e0::/32
+2406:bd00:de00::/48
+2600:1:e210::/46
+2607:ff10::/32
+2804:b24::/32
+2406:3003:3031::/48
+2a02:26f0:79::/48
+2a02:ac8:1002::/48
+2406:8900:a5::/48
+2600:380:5c00::/38
+2001:67c:247c::/48
+2402:c800:ff61::/48
+2001:4868:701::/48
+2a02:598:4444::/48
+2800:6f0::/40
+2a03:14e0::/32
+2a04:180::/29
+2a02:26f0:c0::/48
+2001:67c:2214::/48
+2001:df0:214::/48
+2a02:d28:4::/48
+2a05:c040::/29
+2001:4948::/32
+2001:dc5:0:40::/64
+2a00:5ec0::/32
+2a03:5c00::/32
+2a00:e7a::/31
+2a00:4520:1::/48
+2402:5700::/32
+2a00:e100::/32
+2a04:1c0::/29
+2a00:1910::/32
+2804:214:816e::/48
+2a00:1af8::/32
+2607:fa78::/32
+2607:f350:1::/48
+2a05:1780::/48
+2406:8800:30::/44
+2403:9400:1::/48
+2001:16d8:fe00::/40
+2a03:b500:80::/48
+2607:f7a0:7::/48
+2a03:3e00::/32
+2a01:328::/32
+2404:e800:ee0f::/48
+2a00:f8c0::/32
+2001:4408:4508::/45
+2a00:15b8:400::/40
+2620:109:40::/43
+2001:1998::/32
+2620:115:9003::/48
+2001:4890:1800::/38
+2607:f738:c00::/41
+2620:10d:c080::/41
+2001:268:82c::/48
+2a03:7380:2380::/42
+2620:10e:a002::/48
+2620:10f:400d::/48
+2c0f:f738::/35
+2a03:2880:f00c::/48
+2403:7000:4000::/40
+2406:e006:4000::/34
+2400:3800::/32
+2620:1d0:5e::/48
+2a04:f340::/29
+2620:97:4000::/48
+2607:f790::/32
+2001:4878::/48
+2001:4408:5224::/48
+2402:b801:1000::/36
+2001:df6:1800::/48
+2a00:1188:9::/48
+2610:130:2301::/48
+2605:5500::/32
+2606:1b00::/32
+2405:b300:c000::/36
+2001:67c:11d8::/48
+2a01:230:1::/48
+2a00:d320::/29
+2620:0:a16::/48
+2001:d68:2041::/48
+2604:d700::/32
+2607:f058:1::/48
+2001:4130::/32
+2606:df00:2::/48
+2a00:6800::/32
+2a01:b300::/32
+2a01:5c00::/32
+2001:c80:b000::/36
+2a02:e70::/32
+2607:5f00::/32
+2001:67c:1230::/46
+2620:36:4000::/44
+2a01:a280:1::/56
+2001:4478:2200::/40
+2620:118:7000::/47
+2a02:fe9::/32
+2a02:a43f:9000::/36
+2a00:c4e0::/32
+2001:fa8::/32
+2a00:ea8::/32
+2001:67c:56c::/48
+2001:67c:2abc::/48
+2607:f160:10:414::/64
+2a00:e80::/32
+2607:f348::/32
+2406:3003:201c::/48
+2406:b100::/48
+2405:3300::/32
+2001:67c:1358::/48
+2607:f6f0:204::/48
+2804:14d:7200:a1::/126
+2620:10f:50d3::/48
+2001:67c:2548::/48
+2605:c400::/32
+2606:bc00:8000::/48
+2001:579:c180::/44
+2a02:4560:3::/48
+2607:f770:fff7::/48
+2406:3003:3037::/48
+2001:dc5:0:5::/64
+2001:4d78:fe07::/48
+2607:4a00::/32
+2a01:89a0::/34
+2804:1194::/32
+2402:a800:8000::/34
+2001:4de0:6300::/40
+2600:1:c530::/44
+2605:a00::/32
+2a03:6f00:2::/48
+2a00:11f8::/32
+2a02:e30::/48
+2a00:1cd0:2::/48
+2a02:2950::/32
+2600:1:c110::/44
+2a02:28a8::/32
+2a03:8d40::/32
+2610:e0:4000::/36
+2607:f3a0:2000::/35
+2607:6900::/32
+2a02:2518::/32
+2403:dc00::/32
+2605:1080::/32
+2001:fb0:100e::/48
+2001:4b78::/29
+2001:4408:7f08::/45
+2600:1004:b060::/44
+2a03:1f40::/32
+2a02:4b0:222::/48
+2a03:22e0::/32
+2a01:8840:dd::/48
+2a02:2b18::/32
+2804:620:ff01::/48
+2001:1320::/32
+2620:171:a0f::/48
+2600:8804:6900::/40
+2620:10b:9000::/48
+2600:6001:f06c::/48
+2620:113:f000::/45
+2001:43f8:30::/48
+2a06:2380::/29
+2400:fc00:e40::/44
+2405:8f00:edcb::/48
+2001:67c:78c::/48
+2600:1002:f000::/44
+2a01:5f80::/32
+2a05:2602::/32
+2a02:1d0::/32
+2607:f220:201::/48
+2605:ff80:9::/64
+2001:4600::/24
+2407:2c00::/32
+2001:4830:4030::/48
+2604:8b80:5::/48
+2001:e48:0:15::/64
+2a03:7380:2c0::/42
+2403:c500::/48
+2605:5c80::/32
+2403:a800::/32
+2001:468:c80::/48
+2604:c500::/32
+2620:59::/48
+2001:4878:4010::/48
+2001:67c:1998::/48
+2620:ec::/48
+2a02:a60::/33
+2600:100c:b000::/44
+2a03:6082::/32
+2606:2800:4a30::/48
+2a02:2818:15::/48
+2620:0:2d0::/48
+2804:1380:8000::/36
+2600:1009:b140::/44
+2a04:1b00:f::/48
+2a02:49e0::/32
+2a01:9ba0::/32
+2001:7fb:ff00::/48
+2607:f6c0::/32
+2606:2800:5a3d::/48
+2a00:84c0::/32
+2001:590::c62f:78c4/126
+2606:2800:4a6e::/48
+2a00:9f00:2000::/36
+2620:109:c00d::/48
+2001:49f0:a017::/48
+2600:8801:2a80::/41
+2a00:1238::/32
+2403:8600:80c0::/44
+2606:4900::/32
+2800:4f0:5::/48
+2001:d50::/32
+2001:678:16::/48
+2a03:5f80:ff02::/48
+2a00:e801::/32
+2a02:ab00::/29
+2400:6300:1f::/48
+2401:803f:ff40::/45
+2a01:8840:cb::/48
+2001:dd8:19::/48
+2a00:ab00:800::/48
+2804:14d:5ce0::/44
+2806:3:102::/48
+2a03:f87:ba25::/48
+2a00:fd40:1::/48
+2001:978:8300::/48
+2001:4b0::/32
+2a00:bac0::/32
+2a00:1d58:8009::/48
+2a05:dfc7:9::/48
+2001:67c:264c::/48
+2001:890:c000::/34
+2001:57a:e030::/45
+2620:11a:1000::/48
+2600:1:a06c::/46
+2001:590::c62f:7590/126
+2620:101:402f::/48
+2404:c8:0:2000:0:2:0:48/126
+2407::c/128
+2001:4410:2007::/48
+2001:e48:0:7::/64
+2606:9500:100::/40
+2001:19f0:1000::/38
+2607:fb90:2e00::/40
+2804:14d:72a0::/48
+2a04:2ac0:d016::/48
+2607:f7c0::/32
+2400:a980:4000::/36
+2a00:dc0::/32
+2600:380:7800::/40
+2804:14d:9000:a14::/126
+2a00:1db0:4000::/36
+2001:8c0::/32
+2001:320:b00:2000::/64
+2404:e800:e609::/48
+2a01:6340::/29
+2001:4830:134::/48
+2607:f1f0::/32
+2a02:4800::/48
+2402:5c80::/32
+2406:3003:2014::/48
+2a01:8840:4a::/48
+2a00:d0c0::/32
+2600:100c:b020::/44
+2400:8500:9d07::/48
+2605:ef80::/42
+2406:3003:1009::/48
+2001:1310:8111::/48
+2606:d00::/32
+2a02:3d0:600::/48
+2001:4ce8::/32
+2600:380:1000::/37
+2620:10e:6000::/40
+2001:913:1000::/36
+2401:9d00:1121::/48
+2a02:2980::/32
+2a02:26f0:d5::/48
+2a01:111:f003::/48
+2600:1806:12::/48
+2404:6c00::/32
+2a02:26f0:107::/48
+2a00:dc8:b::/48
+2403:b300::/32
+2a03:63c0::/32
+2600:1009:b060::/44
+2600:8801:1300::/41
+2a05:7f00:189::/48
+2a00:f80::/32
+2a00:86c0:26c::/48
+2804:14d:9000:a11::/126
+2001:4158::/29
+2001:4899::/32
+2001:4b28::/32
+2600:1:8610::/44
+2a00:9640::/32
+2620:34:4000::/48
+2600:1:e43c::/46
+2407::228/126
+2800:370:26::/48
+2804:14c:5f00::/40
+2001:67c:1111::/48
+2a02:2698:3c00::/38
+2001:4808::/32
+2001:678:1c::/48
+2a04:5d80::/31
+2607:f358:15::/48
+2602:fff0::/36
+2a02:3000::/23
+2a02:6d40::/32
+2604:a880:801::/48
+2a02:e00::/32
+2600:1:a230::/46
+2620:67:c000::/48
+2a05:5240::/32
+2801:96:fff9::/48
+2a01:8840:b1::/48
+2607:ff28:7000::/36
+2001:438:1c::/48
+2a04:92c0::/29
+2407:8c00:130::/44
+2001:270::/32
+2001:4878:8219::/48
+2607:f8a8::/32
+2605:4a00:211::/48
+2804:620::/48
+2600:1:a32c::/46
+2a01:8840:d3::/48
+2400:4000::/22
+2600:6001:f005::/48
+2402:6b00::/32
+2610:18:e80::/48
+2620:0:2f00::/41
diff --git a/regress/sys/net/rtable/kern_compat.h b/regress/sys/net/rtable/kern_compat.h
new file mode 100644
index 00000000000..a97f55cd499
--- /dev/null
+++ b/regress/sys/net/rtable/kern_compat.h
@@ -0,0 +1,54 @@
+/* $OpenBSD: kern_compat.h,v 1.1 2015/11/04 09:45:52 mpi Exp $ */
+
+#ifndef _KERN_COMPAT_H_
+#define _KERN_COMPAT_H_
+
+#include <sys/socket.h>
+#include <sys/domain.h>
+#include <sys/queue.h>
+#include <arpa/inet.h>
+
+#include <assert.h>
+#include <err.h>
+#include <errno.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#define DIAGNOSTIC
+#define INET
+#define INET6
+
+#define KASSERT(x) assert(x)
+#define KERNEL_ASSERT_LOCKED() /* nothing */
+
+#define panic(x...) errx(1, x)
+
+#define malloc(size, bucket, flag) calloc(1, size)
+#define mallocarray(nelems, size, bucket, flag) calloc(nelems, size)
+#define free(x, bucket, size) free(x)
+
+struct pool {
+ size_t pr_size;
+};
+
+#define pool_init(a, b, c, d, e, f, g) do { (a)->pr_size = (b); } while (0)
+#define pool_get(pp, flags) malloc((pp)->pr_size, 0, 0)
+#define pool_put(pp, rp) free((rp), 0, 0)
+
+#define log(lvl, x...) fprintf(stderr, x)
+
+#define min(a, b) (a < b ? a : b)
+#define max(a, b) (a < b ? b : a)
+
+#ifndef nitems
+#define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
+#endif
+
+#define rtref(_rt) ((_rt)->rt_refcnt++)
+#define rtfree(_rt) (assert(--(_rt)->rt_refcnt >= 0))
+
+extern struct domain *domains[];
+
+#endif /* _KERN_COMPAT_H_ */
diff --git a/regress/sys/net/rtable/util.c b/regress/sys/net/rtable/util.c
new file mode 100644
index 00000000000..ea31bf1adf2
--- /dev/null
+++ b/regress/sys/net/rtable/util.c
@@ -0,0 +1,404 @@
+/* $OpenBSD: util.c,v 1.1 2015/11/04 09:45:52 mpi Exp $ */
+
+/*
+ * Copyright (c) 2015 Martin Pieuchot
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/socket.h>
+#include <sys/domain.h>
+#include <sys/queue.h>
+#include <net/rtable.h>
+#include <net/route.h>
+
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+#include <assert.h>
+#include <err.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "util.h"
+
+struct domain inetdomain = {
+ AF_INET, "inet", NULL, NULL, NULL, NULL, NULL,
+ sizeof(struct sockaddr_in), offsetof(struct sockaddr_in, sin_addr),
+};
+
+struct domain inet6domain = {
+ AF_INET6, "inet6", NULL, NULL, NULL, NULL, NULL,
+ sizeof(struct sockaddr_in6), offsetof(struct sockaddr_in6, sin6_addr),
+};
+
+struct domain *domains[] = { &inetdomain, &inet6domain, NULL };
+
+int sa2plen(sa_family_t, struct sockaddr *);
+
+/*
+ * Insert a route from a string containing a destination: "192.168.1/24"
+ */
+void
+route_insert(unsigned int rid, sa_family_t af, char *string)
+{
+ struct sockaddr_storage ss, ms;
+ struct sockaddr *ndst, *dst = (struct sockaddr *)&ss;
+ struct sockaddr *mask = (struct sockaddr *)&ms;
+ struct rtentry *rt, *nrt;
+ char ip[INET6_ADDRSTRLEN];
+ int plen;
+
+ rt = calloc(1, sizeof(*rt));
+ if (rt == NULL)
+ errx(1, "out of memory");
+
+ plen = inet_net_ptosa(af, string, dst, mask);
+ if (plen == -1)
+ err(1, "wrong line: %s", string);
+
+ /* Normalize sockaddr a la rtrequest1(9) */
+ ndst = malloc(dst->sa_len);
+ if (ndst == NULL)
+ errx(1, "out of memory");
+ rt_maskedcopy(dst, ndst, mask);
+
+ if (rtable_insert(rid, ndst, mask, NULL, 0, rt)) {
+ inet_net_satop(af, rt_key(rt), plen, ip, sizeof(ip));
+ errx(1, "can't add route: %s\n", ip);
+ }
+ nrt = rtable_lookup(rid, dst, mask, NULL, RTP_ANY);
+ if (nrt != rt) {
+ inet_net_satop(af, rt_key(rt), plen, ip, sizeof(ip));
+ errx(1, "added route not found: %s\n", ip);
+ }
+}
+
+/*
+ * Delete a route from a string containing a destination: "192.168.1/24"
+ */
+void
+route_delete(unsigned int rid, sa_family_t af, char *string)
+{
+ struct sockaddr_storage ss, ms;
+ struct sockaddr *dst = (struct sockaddr *)&ss;
+ struct sockaddr *mask = (struct sockaddr *)&ms;
+ struct rtentry *rt, *nrt;
+ char ip[INET6_ADDRSTRLEN];
+ int plen;
+
+ plen = inet_net_ptosa(af, string, dst, mask);
+ if (plen == -1)
+ err(1, "wrong line: %s", string);
+
+ rt = rtable_lookup(0, dst, mask, NULL, RTP_ANY);
+ if (rt == NULL) {
+ inet_net_satop(af, dst, plen, ip, sizeof(ip));
+ errx(1, "can't find route: %s\n", ip);
+ }
+
+ assert(memcmp(rt_key(rt), dst, dst->sa_len) == 0);
+ assert(maskcmp(af, rt_mask(rt), mask) == 0);
+
+ if (rtable_delete(0, dst, mask, 0, rt)) {
+ inet_net_satop(af, dst, plen, ip, sizeof(ip));
+ errx(1, "can't rm route: %s\n", ip);
+ }
+
+ nrt = rtable_lookup(0, dst, mask, NULL, RTP_ANY);
+ if (nrt != NULL) {
+ char ip0[INET6_ADDRSTRLEN];
+ inet_net_satop(af, rt_key(nrt), plen, ip, sizeof(ip));
+ inet_net_satop(af, rt_key(rt), plen, ip0, sizeof(ip0));
+ errx(1, "found: %s after deleting: %s", ip, ip0);
+ }
+
+ free(rt_key(rt));
+ free(rt);
+}
+
+/*
+ * Lookup a route from a string containing a destination: "192.168.1/24"
+ */
+void
+route_lookup(unsigned int rid, sa_family_t af, char *string)
+{
+ struct sockaddr_storage ss, ms;
+ struct sockaddr *dst = (struct sockaddr *)&ss;
+ struct sockaddr *mask = (struct sockaddr *)&ms;
+ struct rtentry *rt;
+ char ip[INET6_ADDRSTRLEN];
+ int plen;
+
+ plen = inet_net_ptosa(af, string, dst, mask);
+ if (plen == -1)
+ err(1, "wrong line: %s", string);
+
+ rt = rtable_lookup(0, dst, mask, NULL, RTP_ANY);
+ if (rt == NULL) {
+ inet_net_satop(af, dst, plen, ip, sizeof(ip));
+ errx(1, "%s not found\n", ip);
+ }
+ assert(memcmp(rt_key(rt), dst, dst->sa_len) == 0);
+ assert(maskcmp(af, rt_mask(rt), mask) == 0);
+}
+
+int
+do_from_file(unsigned int rid, sa_family_t af, char *filename,
+ void (*func)(unsigned int, sa_family_t, char *))
+{
+ FILE *fp;
+ char *buf;
+ size_t len;
+ int lines = 0;
+
+ if ((fp = fopen(filename, "r")) == NULL)
+ errx(1, "No such file: %s\n", filename);
+
+ while ((buf = fgetln(fp, &len)) != NULL) {
+ if (buf[len - 1] == '\n')
+ buf[len - 1] = '\0';
+
+ (*func)(rid, af, buf);
+ lines++;
+ }
+ fclose(fp);
+
+ return (lines);
+}
+
+int
+rtentry_dump(struct rtentry *rt, void *w, unsigned int rid)
+{
+ char dest[INET6_ADDRSTRLEN];
+ int plen;
+ sa_family_t af = rt_key(rt)->sa_family;
+
+ plen = sa2plen(af, rt_mask(rt));
+ inet_net_satop(af, rt_key(rt), plen, dest, sizeof(dest));
+ printf("%s\n", dest);
+
+ return (0);
+}
+
+int
+rtentry_delete(struct rtentry *rt, void *w, unsigned int rid)
+{
+ char dest[INET6_ADDRSTRLEN];
+ int plen;
+ sa_family_t af = rt_key(rt)->sa_family;
+
+ plen = sa2plen(af, rt_mask(rt));
+
+ if (rtable_delete(0, rt_key(rt), rt_mask(rt), 0, rt)) {
+ inet_net_satop(af, rt_key(rt), plen, dest, sizeof(dest));
+ errx(1, "can't rm route: %s\n", dest);
+ }
+ return (0);
+}
+
+void
+rt_maskedcopy(struct sockaddr *src, struct sockaddr *dst,
+ struct sockaddr *netmask)
+{
+ uint8_t *cp1 = (uint8_t *)src;
+ uint8_t *cp2 = (uint8_t *)dst;
+ uint8_t *cp3 = (uint8_t *)netmask;
+ uint8_t *cplim = cp2 + *cp3;
+ uint8_t *cplim2 = cp2 + *cp1;
+
+ *cp2++ = *cp1++; *cp2++ = *cp1++; /* copies sa_len & sa_family */
+ cp3 += 2;
+ if (cplim > cplim2)
+ cplim = cplim2;
+ while (cp2 < cplim)
+ *cp2++ = *cp1++ & *cp3++;
+ if (cp2 < cplim2)
+ memset(cp2, 0, (unsigned int)(cplim2 - cp2));
+}
+
+int
+sa2plen(sa_family_t af, struct sockaddr *mask)
+{
+ uint8_t *ap, *ep;
+ int off, plen = 0;
+
+ switch (af) {
+ case AF_INET:
+ off = offsetof(struct sockaddr_in, sin_addr);
+ break;
+ case AF_INET6:
+ off = offsetof(struct sockaddr_in6, sin6_addr);
+ break;
+ default:
+ return (-1);
+ }
+
+ /* Default route */
+ if (mask->sa_len == 0)
+ return (0);
+
+ ap = (uint8_t *)((uint8_t *)mask) + off;
+ ep = (uint8_t *)((uint8_t *)mask) + mask->sa_len;
+ if (ap > ep)
+ return (-1);
+
+ if (ap == ep)
+ return (0);
+
+ /* "Beauty" adapted from sbin/route/show.c ... */
+ while (ap < ep) {
+ switch (*ap) {
+ case 0xff:
+ plen += 8;
+ ap++;
+ break;
+ case 0xfe:
+ plen += 7;
+ return (plen);
+ case 0xfc:
+ plen += 6;
+ return (plen);
+ case 0xf8:
+ plen += 5;
+ return (plen);
+ case 0xf0:
+ plen += 4;
+ return (plen);
+ case 0xe0:
+ plen += 3;
+ return (plen);
+ case 0xc0:
+ plen += 2;
+ return (plen);
+ case 0x80:
+ plen += 1;
+ return (plen);
+ case 0x00:
+ return (plen);
+ default:
+ /* Non contiguous mask. */
+ return (-1);
+ }
+
+ }
+
+ return (plen);
+}
+
+
+in_addr_t
+prefixlen2mask(u_int8_t prefixlen)
+{
+ if (prefixlen == 0)
+ return (0);
+
+ return (0xffffffff << (32 - prefixlen));
+}
+
+int
+inet_net_ptosa(sa_family_t af, const char *buf, struct sockaddr *sa,
+ struct sockaddr *ma)
+{
+ struct sockaddr_in *sin = (struct sockaddr_in *)sa;
+ struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sa;
+ int i, plen;
+
+ switch (af) {
+ case AF_INET:
+ memset(sin, 0, sizeof(*sin));
+ sin->sin_family = af;
+ sin->sin_len = sizeof(*sin);
+ plen = inet_net_pton(af, buf, &sin->sin_addr,
+ sizeof(sin->sin_addr));
+ if (plen == -1 || ma == NULL)
+ break;
+
+ sin = (struct sockaddr_in *)ma;
+ memset(sin, 0, sizeof(*sin));
+ sin->sin_len = sizeof(*sin);
+ sin->sin_family = 0;
+ sin->sin_addr.s_addr = htonl(prefixlen2mask(plen));
+ break;
+ case AF_INET6:
+ memset(sin6, 0, sizeof(*sin6));
+ sin6->sin6_family = af;
+ sin6->sin6_len = sizeof(*sin6);
+ plen = inet_net_pton(af, buf, &sin6->sin6_addr,
+ sizeof(sin6->sin6_addr));
+ if (plen == -1 || ma == NULL)
+ break;
+
+ sin6 = (struct sockaddr_in6 *)ma;
+ memset(sin6, 0, sizeof(*sin6));
+ sin6->sin6_len = sizeof(*sin6);
+ sin6->sin6_family = 0;
+ for (i = 0; i < plen / 8; i++)
+ sin6->sin6_addr.s6_addr[i] = 0xff;
+ i = plen % 8;
+ if (i)
+ sin6->sin6_addr.s6_addr[plen / 8] = 0xff00 >> i;
+ break;
+ default:
+ plen = -1;
+ }
+
+ return (plen);
+}
+
+/*
+ * Only compare the address fields, we cannot use memcmp(3) because
+ * the radix tree abuses the first fields of the mask sockaddr for
+ * a different purpose.
+ */
+int
+maskcmp(sa_family_t af, struct sockaddr *sa1, struct sockaddr *sa2)
+{
+ struct sockaddr_in *sin1, *sin2;
+ struct sockaddr_in6 *sin61, *sin62;
+ int len;
+
+ switch (af) {
+ case AF_INET:
+ sin1 = (struct sockaddr_in *)sa1;
+ sin2 = (struct sockaddr_in *)sa2;
+ len = sizeof(sin1->sin_addr);
+ return memcmp(&sin1->sin_addr, &sin2->sin_addr, len);
+ case AF_INET6:
+ sin61 = (struct sockaddr_in6 *)sa1;
+ sin62 = (struct sockaddr_in6 *)sa2;
+ len = sizeof(sin61->sin6_addr);
+ return memcmp(&sin61->sin6_addr, &sin62->sin6_addr, len);
+ default:
+ return (-1);
+ }
+}
+
+char *
+inet_net_satop(sa_family_t af, struct sockaddr *sa, int plen, char *buf,
+ size_t len)
+{
+ struct sockaddr_in *sin = (struct sockaddr_in *)sa;
+ struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sa;
+
+ switch (af) {
+ case AF_INET:
+ return inet_net_ntop(af, &sin->sin_addr, plen, buf, len);
+ case AF_INET6:
+ return inet_net_ntop(af, &sin6->sin6_addr, plen, buf, len);
+ default:
+ return (NULL);
+ }
+}
diff --git a/regress/sys/net/rtable/util.h b/regress/sys/net/rtable/util.h
new file mode 100644
index 00000000000..58f265f62a2
--- /dev/null
+++ b/regress/sys/net/rtable/util.h
@@ -0,0 +1,32 @@
+/* $OpenBSD: util.h,v 1.1 2015/11/04 09:45:52 mpi Exp $ */
+
+/*
+ * Copyright (c) 2015 Martin Pieuchot
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+void route_insert(unsigned int, sa_family_t, char *);
+void route_delete(unsigned int, sa_family_t, char *);
+void route_lookup(unsigned int, sa_family_t, char *);
+
+int do_from_file(unsigned int, sa_family_t, char *,
+ void (*f)(unsigned int, sa_family_t, char *));
+
+int rtentry_dump(struct rtentry *, void *, unsigned int);
+int rtentry_delete(struct rtentry *, void *, unsigned int);
+void rt_maskedcopy(struct sockaddr *, struct sockaddr *, struct sockaddr *);
+int maskcmp(sa_family_t, struct sockaddr *, struct sockaddr *);
+int inet_net_ptosa(sa_family_t, const char *, struct sockaddr *,
+ struct sockaddr *);
+char *inet_net_satop(sa_family_t, struct sockaddr *, int, char *, size_t);