xref: /openbsd/share/man/man4/enc.4 (revision c97a4bc7)
1*c97a4bc7Skn.\"	$OpenBSD: enc.4,v 1.30 2020/02/15 22:19:51 kn Exp $
20387f474Sjmc.\"
3c206d1e0Sjmc.\" Copyright (c) 2006 Jason McIntyre <jmc@openbsd.org>
40387f474Sjmc.\"
5c206d1e0Sjmc.\" Permission to use, copy, modify, and distribute this software for any
6c206d1e0Sjmc.\" purpose with or without fee is hereby granted, provided that the above
7c206d1e0Sjmc.\" copyright notice and this permission notice appear in all copies.
80387f474Sjmc.\"
9c206d1e0Sjmc.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10c206d1e0Sjmc.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11c206d1e0Sjmc.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12c206d1e0Sjmc.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13c206d1e0Sjmc.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14c206d1e0Sjmc.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15c206d1e0Sjmc.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
160387f474Sjmc.\"
17*c97a4bc7Skn.Dd $Mdocdate: February 15 2020 $
181c3af0bcSangelos.Dt ENC 4
191c3af0bcSangelos.Os
201c3af0bcSangelos.Sh NAME
211c3af0bcSangelos.Nm enc
22c206d1e0Sjmc.Nd encapsulating interface
231c3af0bcSangelos.Sh SYNOPSIS
248ddcae73Sreyk.Cd "pseudo-device enc"
251c3af0bcSangelos.Sh DESCRIPTION
26979acbf0SangelosThe
27979acbf0Sangelos.Nm
28c206d1e0Sjmcinterface is a virtual interface for
29979acbf0Sangelos.Xr ipsec 4
30c206d1e0Sjmctraffic.
31c206d1e0SjmcIt allows packet filtering using
32c206d1e0Sjmc.Xr pf 4 ;
33c206d1e0Sjmcprior to encapsulation and after decapsulation,
34c206d1e0Sjmcpackets may be monitored using
35c4f2acd3Sderaadt.Xr tcpdump 8 .
368ddcae73Sreyk.Pp
378ddcae73SreykAn
38c206d1e0Sjmc.Nm
398ddcae73Sreykinterface can be created at runtime using the
408ddcae73Sreyk.Ic ifconfig enc Ns Ar N Ic create
418ddcae73Sreykcommand or by setting up a
428ddcae73Sreyk.Xr hostname.if 5
438ddcae73Sreykconfiguration file for
448ddcae73Sreyk.Xr netstart 8 .
458ddcae73SreykThe
468ddcae73Sreyk.Nm enc0
478ddcae73Sreykinterface will always exist and cannot be destroyed using
488ddcae73Sreyk.Xr ifconfig 8 .
491c3af0bcSangelos.Pp
50c206d1e0SjmcPacket filtering is documented in greater detail in
51c206d1e0Sjmc.Xr pf.conf 5 ,
52c206d1e0Sjmchowever some details relevant to filtering on the
53c206d1e0Sjmc.Nm
54c206d1e0Sjmcinterface are documented below.
55c206d1e0Sjmc.Pp
56c206d1e0SjmcFirstly,
57c206d1e0Sjmc.Xr pf 4
58c206d1e0Sjmcis a stateful packet filter,
59c206d1e0Sjmcwhich means it can track the state of a connection.
60c206d1e0SjmcIt does this
61c206d1e0Sjmc.Em automatically .
62c206d1e0SjmcStates are normally
63c206d1e0Sjmc.Em floating ,
64c206d1e0Sjmcwhich means they can match packets on any interface.
65c206d1e0SjmcHowever this is a potential problem for filtering IPsec traffic:
66c206d1e0Sjmcstates need to be interface bound,
67c206d1e0Sjmcto avoid permitting unencrypted traffic
68c206d1e0Sjmcshould the SAs expire and not be replaced.
69c206d1e0SjmcTherefore all rules on the
70c206d1e0Sjmc.Nm
71c206d1e0Sjmcinterface should explicitly set
7258b6c770Sjmc.Dq keep state (if-bound) .
73c206d1e0SjmcFor example:
74c206d1e0Sjmc.Bd -literal -offset indent
757b442d13Sjmcpass in on enc0 proto ipencap from 172.25.0.45 to 1.2.3.4 \e
76c206d1e0Sjmc	keep state (if-bound)
77c206d1e0Sjmc.Ed
78c206d1e0Sjmc.Pp
79c206d1e0SjmcSecondly, the
80c206d1e0Sjmc.Nm
81c206d1e0Sjmcinterface does not directly support bandwidth control via
82c206d1e0Sjmc.Xr pf 4
83c206d1e0Sjmcqueueing.
84c206d1e0SjmcInstead, IPsec packets must be tagged and the tagged packets
85c206d1e0Sjmcare assigned to queues.
8658b6c770Sjmc.Xr ipsec.conf 5
87c206d1e0Sjmcprovides an example of tag-based queueing
88c206d1e0Sjmcand further information on packet tagging.
89c206d1e0Sjmc.Pp
90c206d1e0SjmcFinally,
91c206d1e0Sjmcthe use of translation rules to map and redirect network traffic
92c206d1e0Sjmcrequires some care.
93c206d1e0SjmcPackets destined to be IPsec processed are seen by the
94267ff36bSgrunkfilter/translation engine twice,
95c206d1e0Sjmcboth before and after being IPsec processed.
96c206d1e0SjmcIf a packet's translated address
97c206d1e0Sjmcon the way back fails to match an existing IPsec flow,
98c206d1e0Sjmcfrom the translated address to the original source address,
99c206d1e0Sjmcit will be discarded by the filter.
100c206d1e0SjmcIt is best to avoid this situation where possible,
101c206d1e0Sjmcthough a flow may be explicitly created to work around it.
102c206d1e0Sjmc.Pp
103c206d1e0SjmcAs noted above,
104c206d1e0Sjmc.Xr tcpdump 8
105c206d1e0Sjmcmay be invoked on the
106c206d1e0Sjmc.Nm
107c206d1e0Sjmcinterface to see packets prior to encapsulation and after decapsulation.
108c206d1e0SjmcFor example:
1097b442d13Sjmc.Bd -literal -offset 3n
1107b442d13Sjmc# tcpdump -envps 1500 -i enc0 -l | grep 10.0.0.33
1117b442d13Sjmctcpdump: listening on enc0, link-type ENC
1127b442d13Sjmc15:05:08.934708 (authentic,confidential): SPI 0x6bcac587: \e
11390211f92Snaddy	172.25.0.45 > 1.2.3.4: 10.9.9.28.7001 > 10.0.0.33.7000: \e
1147b442d13Sjmc	[udp sum ok] udp 52 (ttl 64, id 5672, len 80) \e
1157b442d13Sjmc	(ttl 64, id 30009, len 100, bad cksum 0!)
1167b442d13Sjmc15:05:09.063517 (authentic,confidential): SPI 0x4b70c05a: \e
11790211f92Snaddy	1.2.3.4 > 172.25.0.45: 10.0.0.33.7000 > 10.9.9.28.7001: \e
1187b442d13Sjmc	[udp sum ok] udp 156 (ttl 63, id 14880, len 184) \e
1197b442d13Sjmc	(ttl 51, id 19689, len 204)
1207b442d13Sjmc.Ed
121951aedbeSjmc.Pp
1227b442d13SjmcThe packets above show (for each direction):
1237b442d13Sjmcdate, ESP (not AH), SPI, direction, and encapsulated part.
1247b442d13SjmcThe first packet is headed from 172.25.0.45 to 1.2.3.4
1257b442d13Sjmcand the encapsulated part from 10.9.9.28 to 10.0.0.33.
1267b442d13Sjmc.Pp
1277b442d13SjmcNegotiations can be watched on the physical interface too:
1287b442d13Sjmc.Bd -literal -offset 3n
1297b442d13Sjmc# tcpdump -envps 1500 -i wi0 port 500 or port 4500
1307b442d13Sjmctcpdump: listening on wi0, link-type EN10MB
1317b442d13Sjmc15:15:58.188747 0:2:6f:3a:3f:3e 0:10:f3:3:bd:8a 0800 226: \e
13290211f92Snaddy    172.25.0.45.500 > 1.2.3.4.500: [udp sum ok] \e
1337b442d13Sjmc[...]
1347b442d13Sjmc	attribute ENCRYPTION_ALGORITHM = AES_CBC
1357b442d13Sjmc	attribute HASH_ALGORITHM = SHA
1367b442d13Sjmc	attribute AUTHENTICATION_METHOD = RSA_SIG
1377b442d13Sjmc	attribute GROUP_DESCRIPTION = MODP_1024
1387b442d13Sjmc	attribute LIFE_TYPE = SECONDS
1397b442d13Sjmc	attribute LIFE_DURATION = 3600
1407b442d13Sjmc	attribute KEY_LENGTH = 128
1417b442d13Sjmc[...]
1427b442d13Sjmc15:15:59.080058 0:10:f3:3:bd:8a 0:2:6f:3a:3f:3e 0800 226: \e
14390211f92Snaddy    1.2.3.4.500 > 172.25.0.45.500: [udp sum ok] \e
1447b442d13Sjmc[...]
1457b442d13Sjmc	attribute ENCRYPTION_ALGORITHM = AES_CBC
1467b442d13Sjmc	attribute HASH_ALGORITHM = SHA
1477b442d13Sjmc	attribute AUTHENTICATION_METHOD = RSA_SIG
1487b442d13Sjmc	attribute GROUP_DESCRIPTION = MODP_1024
1497b442d13Sjmc	attribute LIFE_TYPE = SECONDS
1507b442d13Sjmc	attribute LIFE_DURATION = 3600
1517b442d13Sjmc	attribute KEY_LENGTH = 128
1527b442d13Sjmc[...]
1537b442d13Sjmc.Ed
1547b442d13Sjmc.Pp
1557b442d13SjmcThe attribute lines for the negotiation must match.
1561c3af0bcSangelos.Sh SEE ALSO
1571c3af0bcSangelos.Xr ipsec 4 ,
158979acbf0Sangelos.Xr pf 4 ,
15958b6c770Sjmc.Xr ipsec.conf 5 ,
16058b6c770Sjmc.Xr pf.conf 5 ,
161937c2feaSderaadt.Xr tcpdump 8
162