xfrm_sync.rst 6.5 KB

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