You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

93 lines
3.2 KiB

  1. From ee12145d38a7dee81a20cf232c724ccb7a46ad8b Mon Sep 17 00:00:00 2001
  2. From: Willy Tarreau <w@1wt.eu>
  3. Date: Tue, 18 Aug 2015 17:15:20 +0200
  4. Subject: [PATCH 11/13] BUG/MEDIUM: counters: ensure that src_{inc,clr}_gpc0
  5. creates a missing entry
  6. During 1.5-dev20 there was some code refactoring to make the src_* fetch
  7. function use the same code as sc_*. Unfortunately this introduced a
  8. regression where src_* doesn't create an entry anymore if it does not
  9. exist in the table. The reason is that smp_fetch_sc_stkctr() only calls
  10. stktable_lookup_key() while src_inc_*/src_clr_* used to make use of
  11. stktable_update_key() which additionally create the entry if it does
  12. not exist.
  13. There's no point modifying the common function for these two exceptions,
  14. so instead we now have a function dedicated to the creation of this entry
  15. for src_* only. It is called when the entry didn't exist, so that requires
  16. minimal modifications to existing code.
  17. Thanks to Thierry Fournier for helping diagnose the issue.
  18. This fix must be backported to 1.5.
  19. (cherry picked from commit 0f4eadd4830279f5ee83aa545728fb750f5c8185)
  20. [Note: the backport to 1.5 significantly differs from the version in 1.6
  21. since we need to use the table's type and to retrieve the source address
  22. directly from the connection. At least it matches the way other src_*
  23. fetch functions work, and it's been verified to work fine]
  24. ---
  25. src/session.c | 33 +++++++++++++++++++++++++++++++++
  26. 1 file changed, 33 insertions(+)
  27. diff --git a/src/session.c b/src/session.c
  28. index 5b9e407..6d62e36 100644
  29. --- a/src/session.c
  30. +++ b/src/session.c
  31. @@ -2806,6 +2806,33 @@ smp_fetch_sc_stkctr(struct session *l4, const struct arg *args, const char *kw)
  32. return &l4->stkctr[num];
  33. }
  34. +/* same as smp_fetch_sc_stkctr() but dedicated to src_* and can create
  35. + * the entry if it doesn't exist yet. This is needed for a few fetch
  36. + * functions which need to create an entry, such as src_inc_gpc* and
  37. + * src_clr_gpc*.
  38. + */
  39. +struct stkctr *
  40. +smp_create_src_stkctr(struct session *sess, const struct arg *args, const char *kw)
  41. +{
  42. + static struct stkctr stkctr;
  43. + struct stktable_key *key;
  44. + struct connection *conn = objt_conn(sess->si[0].end);
  45. +
  46. + if (strncmp(kw, "src_", 4) != 0)
  47. + return NULL;
  48. +
  49. + if (!conn)
  50. + return NULL;
  51. +
  52. + key = addr_to_stktable_key(&conn->addr.from, args->data.prx->table.type);
  53. + if (!key)
  54. + return NULL;
  55. +
  56. + stkctr.table = &args->data.prx->table;
  57. + stkctr_set_entry(&stkctr, stktable_update_key(stkctr.table, key));
  58. + return &stkctr;
  59. +}
  60. +
  61. /* set return a boolean indicating if the requested session counter is
  62. * currently being tracked or not.
  63. * Supports being called as "sc[0-9]_tracked" only.
  64. @@ -2887,6 +2914,9 @@ smp_fetch_sc_inc_gpc0(struct proxy *px, struct session *l4, void *l7, unsigned i
  65. if (!stkctr)
  66. return 0;
  67. + if (stkctr_entry(stkctr) == NULL)
  68. + stkctr = smp_create_src_stkctr(l4, args, kw);
  69. +
  70. smp->flags = SMP_F_VOL_TEST;
  71. smp->type = SMP_T_UINT;
  72. smp->data.uint = 0;
  73. @@ -2924,6 +2954,9 @@ smp_fetch_sc_clr_gpc0(struct proxy *px, struct session *l4, void *l7, unsigned i
  74. if (!stkctr)
  75. return 0;
  76. + if (stkctr_entry(stkctr) == NULL)
  77. + stkctr = smp_create_src_stkctr(l4, args, kw);
  78. +
  79. smp->flags = SMP_F_VOL_TEST;
  80. smp->type = SMP_T_UINT;
  81. smp->data.uint = 0;
  82. --
  83. 2.4.6