blob: 8d88e0f2ec493be2e519dbaec3e7995f5027a325 [file] [log] [blame]
Jamal Hadi Salimb8a99522006-04-14 15:05:16 -07001
2The sync patches work is based on initial patches from
3Krisztian <hidden@balabit.hu> and others and additional patches
4from Jamal <hadi@cyberus.ca>.
5
6The end goal for syncing is to be able to insert attributes + generate
Eric Engestromedb9a1b2016-04-25 07:36:56 +01007events so that the SA can be safely moved from one machine to another
Jamal Hadi Salimb8a99522006-04-14 15:05:16 -07008for HA purposes.
9The idea is to synchronize the SA so that the takeover machine can do
10the processing of the SA as accurate as possible if it has access to it.
11
12We already have the ability to generate SA add/del/upd events.
13These patches add ability to sync and have accurate lifetime byte (to
14ensure proper decay of SAs) and replay counters to avoid replay attacks
15with as minimal loss at failover time.
Eric Engestromedb9a1b2016-04-25 07:36:56 +010016This way a backup stays as closely up-to-date as an active member.
Jamal Hadi Salimb8a99522006-04-14 15:05:16 -070017
18Because the above items change for every packet the SA receives,
19it is possible for a lot of the events to be generated.
20For this reason, we also add a nagle-like algorithm to restrict
21the events. i.e we are going to set thresholds to say "let me
22know if the replay sequence threshold is reached or 10 secs have passed"
23These thresholds are set system-wide via sysctls or can be updated
24per SA.
25
26The identified items that need to be synchronized are:
27- the lifetime byte counter
28note that: lifetime time limit is not important if you assume the failover
29machine is known ahead of time since the decay of the time countdown
30is not driven by packet arrival.
31- the replay sequence for both inbound and outbound
32
331) Message Structure
34----------------------
35
36nlmsghdr:aevent_id:optional-TLVs.
37
38The netlink message types are:
39
40XFRM_MSG_NEWAE and XFRM_MSG_GETAE.
41
42A XFRM_MSG_GETAE does not have TLVs.
43A XFRM_MSG_NEWAE will have at least two TLVs (as is
44discussed further below).
45
46aevent_id structure looks like:
47
48 struct xfrm_aevent_id {
49 struct xfrm_usersa_id sa_id;
Jamal Hadi Salim2b5f6dc2006-12-02 22:22:25 -080050 xfrm_address_t saddr;
Jamal Hadi Salimb8a99522006-04-14 15:05:16 -070051 __u32 flags;
Jamal Hadi Salim2b5f6dc2006-12-02 22:22:25 -080052 __u32 reqid;
Jamal Hadi Salimb8a99522006-04-14 15:05:16 -070053 };
54
Jamal Hadi Salim2b5f6dc2006-12-02 22:22:25 -080055The unique SA is identified by the combination of xfrm_usersa_id,
56reqid and saddr.
Jamal Hadi Salimb8a99522006-04-14 15:05:16 -070057
58flags are used to indicate different things. The possible
59flags are:
60 XFRM_AE_RTHR=1, /* replay threshold*/
61 XFRM_AE_RVAL=2, /* replay value */
62 XFRM_AE_LVAL=4, /* lifetime value */
63 XFRM_AE_ETHR=8, /* expiry timer threshold */
64 XFRM_AE_CR=16, /* Event cause is replay update */
65 XFRM_AE_CE=32, /* Event cause is timer expiry */
66 XFRM_AE_CU=64, /* Event cause is policy update */
67
68How these flags are used is dependent on the direction of the
69message (kernel<->user) as well the cause (config, query or event).
70This is described below in the different messages.
71
72The pid will be set appropriately in netlink to recognize direction
73(0 to the kernel and pid = processid that created the event
74when going from kernel to user space)
75
76A program needs to subscribe to multicast group XFRMNLGRP_AEVENTS
77to get notified of these events.
78
792) TLVS reflect the different parameters:
80-----------------------------------------
81
82a) byte value (XFRMA_LTIME_VAL)
83This TLV carries the running/current counter for byte lifetime since
84last event.
85
86b)replay value (XFRMA_REPLAY_VAL)
87This TLV carries the running/current counter for replay sequence since
88last event.
89
90c)replay threshold (XFRMA_REPLAY_THRESH)
91This TLV carries the threshold being used by the kernel to trigger events
92when the replay sequence is exceeded.
93
94d) expiry timer (XFRMA_ETIMER_THRESH)
95This is a timer value in milliseconds which is used as the nagle
96value to rate limit the events.
97
983) Default configurations for the parameters:
99----------------------------------------------
100
101By default these events should be turned off unless there is
102at least one listener registered to listen to the multicast
103group XFRMNLGRP_AEVENTS.
104
105Programs installing SAs will need to specify the two thresholds, however,
106in order to not change existing applications such as racoon
107we also provide default threshold values for these different parameters
108in case they are not specified.
109
110the two sysctls/proc entries are:
111a) /proc/sys/net/core/sysctl_xfrm_aevent_etime
112used to provide default values for the XFRMA_ETIMER_THRESH in incremental
113units of time of 100ms. The default is 10 (1 second)
114
115b) /proc/sys/net/core/sysctl_xfrm_aevent_rseqth
116used to provide default values for XFRMA_REPLAY_THRESH parameter
117in incremental packet count. The default is two packets.
118
1194) Message types
120----------------
121
122a) XFRM_MSG_GETAE issued by user-->kernel.
123XFRM_MSG_GETAE does not carry any TLVs.
124The response is a XFRM_MSG_NEWAE which is formatted based on what
125XFRM_MSG_GETAE queried for.
126The response will always have XFRMA_LTIME_VAL and XFRMA_REPLAY_VAL TLVs.
127*if XFRM_AE_RTHR flag is set, then XFRMA_REPLAY_THRESH is also retrieved
128*if XFRM_AE_ETHR flag is set, then XFRMA_ETIMER_THRESH is also retrieved
129
130b) XFRM_MSG_NEWAE is issued by either user space to configure
131or kernel to announce events or respond to a XFRM_MSG_GETAE.
132
133i) user --> kernel to configure a specific SA.
134any of the values or threshold parameters can be updated by passing the
135appropriate TLV.
136A response is issued back to the sender in user space to indicate success
137or failure.
138In the case of success, additionally an event with
139XFRM_MSG_NEWAE is also issued to any listeners as described in iii).
140
141ii) kernel->user direction as a response to XFRM_MSG_GETAE
142The response will always have XFRMA_LTIME_VAL and XFRMA_REPLAY_VAL TLVs.
143The threshold TLVs will be included if explicitly requested in
144the XFRM_MSG_GETAE message.
145
146iii) kernel->user to report as event if someone sets any values or
147thresholds for an SA using XFRM_MSG_NEWAE (as described in #i above).
148In such a case XFRM_AE_CU flag is set to inform the user that
149the change happened as a result of an update.
150The message will always have XFRMA_LTIME_VAL and XFRMA_REPLAY_VAL TLVs.
151
152iv) kernel->user to report event when replay threshold or a timeout
153is exceeded.
154In such a case either XFRM_AE_CR (replay exceeded) or XFRM_AE_CE (timeout
155happened) is set to inform the user what happened.
156Note the two flags are mutually exclusive.
157The message will always have XFRMA_LTIME_VAL and XFRMA_REPLAY_VAL TLVs.
158
159Exceptions to threshold settings
160--------------------------------
161
162If you have an SA that is getting hit by traffic in bursts such that
163there is a period where the timer threshold expires with no packets
164seen, then an odd behavior is seen as follows:
165The first packet arrival after a timer expiry will trigger a timeout
Eric Engestromedb9a1b2016-04-25 07:36:56 +0100166event; i.e we don't wait for a timeout period or a packet threshold
Jamal Hadi Salimb8a99522006-04-14 15:05:16 -0700167to be reached. This is done for simplicity and efficiency reasons.
168
169-JHS