xfrm_sync.txt 6.5 KB

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