1.\" $OpenBSD: rdomain.4,v 1.14 2020/07/30 21:44:34 kn Exp $ 2.\" 3.\" Copyright (c) 2015 Peter Hessler <phessler@openbsd.org> 4.\" 5.\" Permission to use, copy, modify, and distribute this software for any 6.\" purpose with or without fee is hereby granted, provided that the above 7.\" copyright notice and this permission notice appear in all copies. 8.\" 9.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16.\" 17.Dd $Mdocdate: July 30 2020 $ 18.Dt RDOMAIN 4 19.Os 20.Sh NAME 21.Nm rtable , 22.Nm rdomain 23.Nd routing tables and routing domains 24.Sh DESCRIPTION 25The traditional kernel routing system had a single table for routes and 26allowed only non-conflicting IP address assignments. 27The 28.Nm rtable 29feature allows multiple lookup tables for routes. 30The 31.Nm rdomain 32feature provides a way to logically segment a router 33between network paths. 34.Ss Routing tables 35Each 36.Nm rtable 37contains routes for outbound network packets. 38A routing domain can contain more than one 39.Nm rtable . 40Multiple routing tables are commonly used for Policy Based Routing. 41.Pp 42The highest ID that can be used for an 43.Nm rtable 44is 255. 45.Ss Routing domains 46Each 47.Nm rdomain 48is a completely separate address space in the kernel. 49An IP address (e.g. 10.0.0.1/16) can be assigned in more than one 50.Nm rdomain , 51but cannot be assigned more than once per 52.Nm rdomain . 53An interface belongs to one and only one 54.Nm rdomain . 55The interface's 56.Nm rdomain 57determines which rdomain an incoming packet will 58be in. 59Virtual interfaces do not need to belong to the same 60.Nm rdomain 61as the parent. 62Each 63.Nm rdomain 64contains at least one routing table. 65.Pp 66Network traffic within an 67.Nm rdomain 68stays within the current routing domain. 69.Xr pf 4 70is used to move traffic from one 71.Nm rdomain 72to a different 73.Nm rdomain . 74.Pp 75When an interface is assigned to a non-existent 76.Nm rdomain 77it gets created automatically. 78At the same time an 79.Nm rtable 80with the same ID and a 81.Xr lo 4 82interface with a unit number matching the ID get created and assigned to the new 83domain. 84.Pp 85An rdomain can be deleted by removing all interfaces from it and then 86destroying the 87.Xr lo 4 88interface with the unit number matching the ID. 89.Pp 90The highest ID that can be used for an 91.Nm rdomain 92is 255. 93.Sh EXAMPLES 94Put em0 and lo4 in rdomain 4: 95.Bd -literal -offset indent 96# ifconfig em0 rdomain 4 97# ifconfig lo4 inet 127.0.0.1/8 98# ifconfig em0 192.0.2.100/24 99.Ed 100.Pp 101Set a default route and localhost reject route within rtable 4: 102.Bd -literal -offset indent 103# route -T4 -qn add -net 127 127.0.0.1 -reject 104# route -T4 -n add default 192.0.2.1 105.Ed 106.Pp 107Start 108.Xr sshd 8 109in rtable 4: 110.Pp 111.Dl # route -T4 exec /usr/sbin/sshd 112.Pp 113Display to which rdomain processes are assigned: 114.Pp 115.Dl # ps aux -o rtable 116.Pp 117A 118.Xr pf.conf 5 119snippet to block incoming port 80, 120and nat-to and move to rtable 0 on interface em1: 121.Bd -literal -offset indent 122block in on rdomain 4 proto tcp to any port 80 123match out on rdomain 4 to !$internal_net nat-to (em1) rtable 0 124.Ed 125.Pp 126Delete rdomain 4 again: 127.Bd -literal -offset indent 128# ifconfig em0 -rdomain 129# ifconfig lo4 destroy 130.Ed 131.Sh SEE ALSO 132.Xr ps 1 , 133.Xr lo 4 , 134.Xr route 4 , 135.Xr pf.conf 5 , 136.Xr ifconfig 8 , 137.Xr route 8 138.Sh HISTORY 139.Ox 140support for 141.Nm rdomain 142first appeared in 143.Ox 4.9 144and IPv6 support first appeared in 145.Ox 5.5 . 146.Sh CAVEATS 147No tool is available to assign more than one rtable to an rdomain 148other than to the default one (0). 149