docs: ikev2 usecases
[vpp.git] / docs / usecases / vpp_resp_sswan_init.md
1 VPP as IKEv2 responder and strongSwan as initiator
2 ==================================================
3
4
5 Prerequisites
6 -------------
7
8 To make the examples easier to configure ``docker`` it is required to pull strongSwan docker image. The networking is done using Linux' veth interfaces and namespaces.
9
10 Setup
11 -----
12
13 First a topology:
14
15 ```
16 192.168.3.2                      192.168.5.2
17      +                           loopback
18      |                                 +
19 +----+----+ 192.168.10.2         +-----+----+
20 |  VPP    |                      |initiator |
21 |responder+----------------------+strongSwan|
22 +---------+                      +----------+
23                      192.168.10.1
24 ```
25
26 Create veth interfaces and namespaces and configure them:
27
28 ```
29 sudo ip link add gw type veth peer name swanif
30 sudo ip link set dev gw up
31
32 sudo ip netns add ns
33 sudo ip link add veth_priv type veth peer name priv
34 sudo ip link set dev priv up
35 sudo ip link set dev veth_priv up netns ns
36
37 sudo ip netns exec ns \
38   bash -c "
39     ip link set dev lo up
40     ip addr add 192.168.3.2/24 dev veth_priv
41     ip route add 192.168.5.0/24 via 192.168.3.1"
42 ```
43
44
45 Create directory with strongswan configs that will be mounted to the docker container
46 ```
47 mkdir /tmp/sswan
48 ```
49
50 Create the ``ipsec.conf`` file in the ``/tmp/sswan`` directory with following content:
51 ```
52 config setup
53  strictcrlpolicy=no
54
55 conn initiator
56  mobike=no
57  auto=add
58  type=tunnel
59  keyexchange=ikev2
60  ike=aes256gcm16-prfsha256-modp2048!
61  esp=aes256gcm16-esn!
62
63  # local:
64  leftauth=psk
65  leftid=@roadwarrior.vpn.example.com
66  leftsubnet=192.168.5.0/24
67
68  # remote: (vpp gateway)
69  rightid=@vpp.home
70  right=192.168.10.2
71  rightauth=psk
72  rightsubnet=192.168.3.0/24
73 ```
74
75 ``/tmp/sswan/ipsec.secrets``
76 ```
77 : PSK 'Vpp123'
78 ```
79
80 ``/tmp/sswan/strongswan.conf``
81 ```
82 charon {
83   load_modular = yes
84   plugins {
85     include strongswan.d/charon/*.conf
86   }
87   filelog {
88     /tmp/charon.log {
89       time_format = %b %e %T
90       ike_name = yes
91       append = no
92       default = 2
93       flush_line = yes
94     }
95   }
96 }
97 include strongswan.d/*.conf
98 ```
99
100 Start docker container with strongSwan:
101
102 ```
103  docker run --name sswan -d --privileged --rm --net=none \
104   -v /tmp/sswan:/conf -v /tmp/sswan:/etc/ipsec.d philplckthun/strongswan
105 ```
106
107 Finish configuration of initiator's private network:
108
109 ```
110 pid=$(docker inspect --format "{{.State.Pid}}" sswan)
111 sudo ip link set netns $pid dev swanif
112
113 sudo nsenter -t $pid -n ip addr add 192.168.10.1/24 dev swanif
114 sudo nsenter -t $pid -n ip link set dev swanif up
115
116 sudo nsenter -t $pid -n ip addr add 192.168.5.2/32 dev lo
117 sudo nsenter -t $pid -n ip link set dev lo up
118 ```
119
120 Start VPP ...
121
122 ```
123 sudo /usr/bin/vpp unix { \
124       cli-listen /tmp/vpp.sock \
125       gid $(id -g) } \
126       api-segment { prefix vpp } \
127       plugins { plugin dpdk_plugin.so { disable } }
128 ```
129
130 ... and configure it:
131
132 ```
133 create host-interface name gw
134 set interface ip addr host-gw 192.168.10.2/24
135 set interface state host-gw up
136
137 create host-interface name priv
138 set interface ip addr host-priv 192.168.3.1/24
139 set interface state host-priv up
140
141 ikev2 profile add pr1
142 ikev2 profile set pr1 auth shared-key-mic string Vpp123
143 ikev2 profile set pr1 id local fqdn vpp.home
144 ikev2 profile set pr1 id remote fqdn roadwarrior.vpn.example.com
145
146 ikev2 profile set pr1 traffic-selector local ip-range 192.168.3.0 - 192.168.3.255 port-range 0 - 65535 protocol 0
147 ikev2 profile set pr1 traffic-selector remote ip-range 192.168.5.0 - 192.168.5.255 port-range 0 - 65535 protocol 0
148
149 create ipip tunnel src 192.168.10.2 dst 192.168.10.1
150 ikev2 profile set pr1 tunnel ipip0
151 ip route add 192.168.5.0/24 via 192.168.10.1 ipip0
152 set interface unnumbered ipip0 use host-gw
153 ```
154
155 Initiate the IKEv2 connection:
156
157 ```
158 $ sudo docker exec sswan ipsec up initiator
159
160 ...
161 CHILD_SA initiator{1} established with SPIs c320c95f_i 213932c2_o and TS 192.168.5.0/24 === 192.168.3.0/24
162 connection 'initiator' established successfully
163 ```
164
165 ```
166 vpp# show ikev2 sa details
167
168 iip 192.168.10.1 ispi 7849021d9f655f1b rip 192.168.10.2 rspi 5a9ca7469a035205
169  encr:aes-gcm-16 prf:hmac-sha2-256  dh-group:modp-2048
170  nonce i:692ce8fd8f1c1934f63bfa2b167c4de2cff25640dffe938cdfe01a5d7f6820e6
171        r:3ed84a14ea8526063e5aa762312be225d33e866d7152b9ce23e50f0ededca9e3
172  SK_d    9a9b896ed6c35c78134fcd6e966c04868b6ecacf6d5088b4b2aee8b05d30fdda
173  SK_e  i:00000000: 1b1619788d8c812ca5916c07e635bda860f15293099f3bf43e8d88e52074b006
174          00000020: 72c8e3e3
175        r:00000000: 89165ceb2cef6a6b3319f437386292d9ef2e96d8bdb21eeb0cb0d3b92733de03
176          00000020: bbc29c50
177  SK_p  i:fe35fca30985ee75e7c8bc0d7bc04db7a0e1655e997c0f5974c31458826b6fef
178        r:0dd318662a96a25fcdf4998d8c6e4180c67c03586cf91dab26ed43aeda250272
179  identifier (i) id-type fqdn data roadwarrior.vpn.example.com
180  identifier (r) id-type fqdn data vpp.home
181    child sa 0:encr:aes-gcm-16  esn:yes
182     spi(i) c320c95f spi(r) 213932c2
183     SK_e  i:2a6c9eae9dbed202c0ae6ccc001621aba5bb0b01623d4de4d14fd27bd5185435
184           r:15e2913d39f809040ca40a02efd27da298b6de05f67bd8f10210da5e6ae606fb
185     traffic selectors (i):0 type 7 protocol_id 0 addr 192.168.5.0 - 192.168.5.255 port 0 - 65535
186     traffic selectors (r):0 type 7 protocol_id 0 addr 192.168.3.0 - 192.168.3.255 port 0 - 65535
187
188 ```
189
190 Now we can generate some traffic between responder's and initiator's private networks and see it works.
191
192 ```
193 $ sudo ip netns exec ns ping 192.168.5.2
194 PING 192.168.5.2 (192.168.5.2) 56(84) bytes of data.
195 64 bytes from 192.168.5.2: icmp_seq=1 ttl=63 time=1.02 ms
196 64 bytes from 192.168.5.2: icmp_seq=2 ttl=63 time=0.599 ms
197 ```