blob: 6246503ceab2d294d389ba2b819c1e5945d2aa91 [file] [log] [blame]
Mauro Carvalho Chehaba5cfea32020-05-01 16:44:31 +02001.. SPDX-License-Identifier: GPL-2.0
2
3====
4XFRM
5====
Jamal Hadi Salimb8a99522006-04-14 15:05:16 -07006
7The sync patches work is based on initial patches from
8Krisztian <hidden@balabit.hu> and others and additional patches
9from Jamal <hadi@cyberus.ca>.
10
11The end goal for syncing is to be able to insert attributes + generate
Eric Engestromedb9a1b2016-04-25 07:36:56 +010012events so that the SA can be safely moved from one machine to another
Jamal Hadi Salimb8a99522006-04-14 15:05:16 -070013for HA purposes.
14The idea is to synchronize the SA so that the takeover machine can do
15the processing of the SA as accurate as possible if it has access to it.
16
17We already have the ability to generate SA add/del/upd events.
18These patches add ability to sync and have accurate lifetime byte (to
19ensure proper decay of SAs) and replay counters to avoid replay attacks
20with as minimal loss at failover time.
Eric Engestromedb9a1b2016-04-25 07:36:56 +010021This way a backup stays as closely up-to-date as an active member.
Jamal Hadi Salimb8a99522006-04-14 15:05:16 -070022
23Because the above items change for every packet the SA receives,
24it is possible for a lot of the events to be generated.
25For this reason, we also add a nagle-like algorithm to restrict
26the events. i.e we are going to set thresholds to say "let me
27know if the replay sequence threshold is reached or 10 secs have passed"
28These thresholds are set system-wide via sysctls or can be updated
29per SA.
30
31The identified items that need to be synchronized are:
32- the lifetime byte counter
33note that: lifetime time limit is not important if you assume the failover
34machine is known ahead of time since the decay of the time countdown
35is not driven by packet arrival.
36- the replay sequence for both inbound and outbound
37
381) Message Structure
39----------------------
40
41nlmsghdr:aevent_id:optional-TLVs.
42
43The netlink message types are:
44
45XFRM_MSG_NEWAE and XFRM_MSG_GETAE.
46
47A XFRM_MSG_GETAE does not have TLVs.
Mauro Carvalho Chehaba5cfea32020-05-01 16:44:31 +020048
Jamal Hadi Salimb8a99522006-04-14 15:05:16 -070049A XFRM_MSG_NEWAE will have at least two TLVs (as is
50discussed further below).
51
Mauro Carvalho Chehaba5cfea32020-05-01 16:44:31 +020052aevent_id structure looks like::
Jamal Hadi Salimb8a99522006-04-14 15:05:16 -070053
54 struct xfrm_aevent_id {
Mauro Carvalho Chehaba5cfea32020-05-01 16:44:31 +020055 struct xfrm_usersa_id sa_id;
56 xfrm_address_t saddr;
57 __u32 flags;
58 __u32 reqid;
Jamal Hadi Salimb8a99522006-04-14 15:05:16 -070059 };
60
Jamal Hadi Salim2b5f6dc2006-12-02 22:22:25 -080061The unique SA is identified by the combination of xfrm_usersa_id,
62reqid and saddr.
Jamal Hadi Salimb8a99522006-04-14 15:05:16 -070063
64flags are used to indicate different things. The possible
Mauro Carvalho Chehaba5cfea32020-05-01 16:44:31 +020065flags are::
66
67 XFRM_AE_RTHR=1, /* replay threshold*/
68 XFRM_AE_RVAL=2, /* replay value */
69 XFRM_AE_LVAL=4, /* lifetime value */
70 XFRM_AE_ETHR=8, /* expiry timer threshold */
71 XFRM_AE_CR=16, /* Event cause is replay update */
72 XFRM_AE_CE=32, /* Event cause is timer expiry */
73 XFRM_AE_CU=64, /* Event cause is policy update */
Jamal Hadi Salimb8a99522006-04-14 15:05:16 -070074
75How these flags are used is dependent on the direction of the
76message (kernel<->user) as well the cause (config, query or event).
77This is described below in the different messages.
78
79The pid will be set appropriately in netlink to recognize direction
80(0 to the kernel and pid = processid that created the event
81when going from kernel to user space)
82
83A program needs to subscribe to multicast group XFRMNLGRP_AEVENTS
84to get notified of these events.
85
862) TLVS reflect the different parameters:
87-----------------------------------------
88
89a) byte value (XFRMA_LTIME_VAL)
Mauro Carvalho Chehaba5cfea32020-05-01 16:44:31 +020090
Jamal Hadi Salimb8a99522006-04-14 15:05:16 -070091This TLV carries the running/current counter for byte lifetime since
92last event.
93
94b)replay value (XFRMA_REPLAY_VAL)
Mauro Carvalho Chehaba5cfea32020-05-01 16:44:31 +020095
Jamal Hadi Salimb8a99522006-04-14 15:05:16 -070096This TLV carries the running/current counter for replay sequence since
97last event.
98
99c)replay threshold (XFRMA_REPLAY_THRESH)
Mauro Carvalho Chehaba5cfea32020-05-01 16:44:31 +0200100
Jamal Hadi Salimb8a99522006-04-14 15:05:16 -0700101This TLV carries the threshold being used by the kernel to trigger events
102when the replay sequence is exceeded.
103
104d) expiry timer (XFRMA_ETIMER_THRESH)
Mauro Carvalho Chehaba5cfea32020-05-01 16:44:31 +0200105
Jamal Hadi Salimb8a99522006-04-14 15:05:16 -0700106This is a timer value in milliseconds which is used as the nagle
107value to rate limit the events.
108
1093) Default configurations for the parameters:
Mauro Carvalho Chehaba5cfea32020-05-01 16:44:31 +0200110---------------------------------------------
Jamal Hadi Salimb8a99522006-04-14 15:05:16 -0700111
112By default these events should be turned off unless there is
113at least one listener registered to listen to the multicast
114group XFRMNLGRP_AEVENTS.
115
116Programs installing SAs will need to specify the two thresholds, however,
117in order to not change existing applications such as racoon
118we also provide default threshold values for these different parameters
119in case they are not specified.
120
121the two sysctls/proc entries are:
Mauro Carvalho Chehaba5cfea32020-05-01 16:44:31 +0200122
Jamal Hadi Salimb8a99522006-04-14 15:05:16 -0700123a) /proc/sys/net/core/sysctl_xfrm_aevent_etime
124used to provide default values for the XFRMA_ETIMER_THRESH in incremental
125units of time of 100ms. The default is 10 (1 second)
126
127b) /proc/sys/net/core/sysctl_xfrm_aevent_rseqth
128used to provide default values for XFRMA_REPLAY_THRESH parameter
129in incremental packet count. The default is two packets.
130
1314) Message types
132----------------
133
134a) XFRM_MSG_GETAE issued by user-->kernel.
Mauro Carvalho Chehaba5cfea32020-05-01 16:44:31 +0200135 XFRM_MSG_GETAE does not carry any TLVs.
136
Jamal Hadi Salimb8a99522006-04-14 15:05:16 -0700137The response is a XFRM_MSG_NEWAE which is formatted based on what
138XFRM_MSG_GETAE queried for.
Mauro Carvalho Chehaba5cfea32020-05-01 16:44:31 +0200139
Jamal Hadi Salimb8a99522006-04-14 15:05:16 -0700140The response will always have XFRMA_LTIME_VAL and XFRMA_REPLAY_VAL TLVs.
Mauro Carvalho Chehaba5cfea32020-05-01 16:44:31 +0200141* if XFRM_AE_RTHR flag is set, then XFRMA_REPLAY_THRESH is also retrieved
142* if XFRM_AE_ETHR flag is set, then XFRMA_ETIMER_THRESH is also retrieved
Jamal Hadi Salimb8a99522006-04-14 15:05:16 -0700143
144b) XFRM_MSG_NEWAE is issued by either user space to configure
Mauro Carvalho Chehaba5cfea32020-05-01 16:44:31 +0200145 or kernel to announce events or respond to a XFRM_MSG_GETAE.
Jamal Hadi Salimb8a99522006-04-14 15:05:16 -0700146
147i) user --> kernel to configure a specific SA.
Mauro Carvalho Chehaba5cfea32020-05-01 16:44:31 +0200148
Jamal Hadi Salimb8a99522006-04-14 15:05:16 -0700149any of the values or threshold parameters can be updated by passing the
150appropriate TLV.
Mauro Carvalho Chehaba5cfea32020-05-01 16:44:31 +0200151
Jamal Hadi Salimb8a99522006-04-14 15:05:16 -0700152A response is issued back to the sender in user space to indicate success
153or failure.
Mauro Carvalho Chehaba5cfea32020-05-01 16:44:31 +0200154
Jamal Hadi Salimb8a99522006-04-14 15:05:16 -0700155In the case of success, additionally an event with
156XFRM_MSG_NEWAE is also issued to any listeners as described in iii).
157
158ii) kernel->user direction as a response to XFRM_MSG_GETAE
Mauro Carvalho Chehaba5cfea32020-05-01 16:44:31 +0200159
Jamal Hadi Salimb8a99522006-04-14 15:05:16 -0700160The response will always have XFRMA_LTIME_VAL and XFRMA_REPLAY_VAL TLVs.
Mauro Carvalho Chehaba5cfea32020-05-01 16:44:31 +0200161
Jamal Hadi Salimb8a99522006-04-14 15:05:16 -0700162The threshold TLVs will be included if explicitly requested in
163the XFRM_MSG_GETAE message.
164
165iii) kernel->user to report as event if someone sets any values or
Mauro Carvalho Chehaba5cfea32020-05-01 16:44:31 +0200166 thresholds for an SA using XFRM_MSG_NEWAE (as described in #i above).
167 In such a case XFRM_AE_CU flag is set to inform the user that
168 the change happened as a result of an update.
169 The message will always have XFRMA_LTIME_VAL and XFRMA_REPLAY_VAL TLVs.
Jamal Hadi Salimb8a99522006-04-14 15:05:16 -0700170
171iv) kernel->user to report event when replay threshold or a timeout
Mauro Carvalho Chehaba5cfea32020-05-01 16:44:31 +0200172 is exceeded.
173
Jamal Hadi Salimb8a99522006-04-14 15:05:16 -0700174In such a case either XFRM_AE_CR (replay exceeded) or XFRM_AE_CE (timeout
175happened) is set to inform the user what happened.
176Note the two flags are mutually exclusive.
177The message will always have XFRMA_LTIME_VAL and XFRMA_REPLAY_VAL TLVs.
178
179Exceptions to threshold settings
180--------------------------------
181
182If you have an SA that is getting hit by traffic in bursts such that
183there is a period where the timer threshold expires with no packets
184seen, then an odd behavior is seen as follows:
185The first packet arrival after a timer expiry will trigger a timeout
Eric Engestromedb9a1b2016-04-25 07:36:56 +0100186event; i.e we don't wait for a timeout period or a packet threshold
Jamal Hadi Salimb8a99522006-04-14 15:05:16 -0700187to be reached. This is done for simplicity and efficiency reasons.
188
189-JHS