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