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.

109 lines
5.0 KiB

  1. From d008394057c4fe46ca6eb775c66cc0ff986a5495 Mon Sep 17 00:00:00 2001
  2. From: Willy Tarreau <w@1wt.eu>
  3. Date: Wed, 25 Jun 2014 16:20:53 +0200
  4. Subject: [PATCH 5/6] MINOR: stick-table: make stktable_fetch_key() indicate
  5. why it failed
  6. stktable_fetch_key() does not indicate whether it returns NULL because
  7. the input sample was not found or because it's unstable. It causes trouble
  8. with track-sc* rules. Just like with sample_fetch_string(), we want it to
  9. be able to give more information to the caller about what it found. Thus,
  10. now we use the pointer to a sample passed by the caller, and fill it with
  11. the information we have about the sample. That way, even if we return NULL,
  12. the caller has the ability to check whether a sample was found and if it is
  13. still changing or not.
  14. (cherry picked from commit b5975defba61e7ef37ae771614166d0970ede04e)
  15. ---
  16. include/proto/stick_table.h | 2 +-
  17. src/proto_tcp.c | 4 ++--
  18. src/session.c | 4 ++--
  19. src/stick_table.c | 12 +++++++-----
  20. 4 files changed, 12 insertions(+), 10 deletions(-)
  21. diff --git a/include/proto/stick_table.h b/include/proto/stick_table.h
  22. index 0c26fbe..57ca223 100644
  23. --- a/include/proto/stick_table.h
  24. +++ b/include/proto/stick_table.h
  25. @@ -48,7 +48,7 @@ struct stksess *stktable_lookup_key(struct stktable *t, struct stktable_key *key
  26. struct stksess *stktable_update_key(struct stktable *table, struct stktable_key *key);
  27. struct stktable_key *stktable_fetch_key(struct stktable *t, struct proxy *px,
  28. struct session *l4, void *l7, unsigned int opt,
  29. - struct sample_expr *expr);
  30. + struct sample_expr *expr, struct sample *smp);
  31. int stktable_compatible_sample(struct sample_expr *expr, unsigned long table_type);
  32. int stktable_get_data_type(char *name);
  33. struct proxy *find_stktable(const char *name);
  34. diff --git a/src/proto_tcp.c b/src/proto_tcp.c
  35. index 65c4fda..1aac0d9 100644
  36. --- a/src/proto_tcp.c
  37. +++ b/src/proto_tcp.c
  38. @@ -1027,7 +1027,7 @@ int tcp_inspect_request(struct session *s, struct channel *req, int an_bit)
  39. continue;
  40. t = rule->act_prm.trk_ctr.table.t;
  41. - key = stktable_fetch_key(t, s->be, s, &s->txn, SMP_OPT_DIR_REQ|SMP_OPT_FINAL, rule->act_prm.trk_ctr.expr);
  42. + key = stktable_fetch_key(t, s->be, s, &s->txn, SMP_OPT_DIR_REQ|SMP_OPT_FINAL, rule->act_prm.trk_ctr.expr, NULL);
  43. if (key && (ts = stktable_get_entry(t, key))) {
  44. session_track_stkctr(&s->stkctr[tcp_trk_idx(rule->action)], t, ts);
  45. @@ -1228,7 +1228,7 @@ int tcp_exec_req_rules(struct session *s)
  46. continue;
  47. t = rule->act_prm.trk_ctr.table.t;
  48. - key = stktable_fetch_key(t, s->be, s, &s->txn, SMP_OPT_DIR_REQ|SMP_OPT_FINAL, rule->act_prm.trk_ctr.expr);
  49. + key = stktable_fetch_key(t, s->be, s, &s->txn, SMP_OPT_DIR_REQ|SMP_OPT_FINAL, rule->act_prm.trk_ctr.expr, NULL);
  50. if (key && (ts = stktable_get_entry(t, key)))
  51. session_track_stkctr(&s->stkctr[tcp_trk_idx(rule->action)], t, ts);
  52. diff --git a/src/session.c b/src/session.c
  53. index e26f5ad..df85170 100644
  54. --- a/src/session.c
  55. +++ b/src/session.c
  56. @@ -1458,7 +1458,7 @@ static int process_sticking_rules(struct session *s, struct channel *req, int an
  57. if (ret) {
  58. struct stktable_key *key;
  59. - key = stktable_fetch_key(rule->table.t, px, s, &s->txn, SMP_OPT_DIR_REQ|SMP_OPT_FINAL, rule->expr);
  60. + key = stktable_fetch_key(rule->table.t, px, s, &s->txn, SMP_OPT_DIR_REQ|SMP_OPT_FINAL, rule->expr, NULL);
  61. if (!key)
  62. continue;
  63. @@ -1561,7 +1561,7 @@ static int process_store_rules(struct session *s, struct channel *rep, int an_bi
  64. if (ret) {
  65. struct stktable_key *key;
  66. - key = stktable_fetch_key(rule->table.t, px, s, &s->txn, SMP_OPT_DIR_RES|SMP_OPT_FINAL, rule->expr);
  67. + key = stktable_fetch_key(rule->table.t, px, s, &s->txn, SMP_OPT_DIR_RES|SMP_OPT_FINAL, rule->expr, NULL);
  68. if (!key)
  69. continue;
  70. diff --git a/src/stick_table.c b/src/stick_table.c
  71. index c6463ec..a708d3c 100644
  72. --- a/src/stick_table.c
  73. +++ b/src/stick_table.c
  74. @@ -601,15 +601,17 @@ static sample_to_key_fct sample_to_key[SMP_TYPES][STKTABLE_TYPES] = {
  75. * Process a fetch + format conversion as defined by the sample expression <expr>
  76. * on request or response considering the <opt> parameter. Returns either NULL if
  77. * no key could be extracted, or a pointer to the converted result stored in
  78. - * static_table_key in format <table_type>.
  79. + * static_table_key in format <table_type>. If <smp> is not NULL, it will be reset
  80. + * and its flags will be initialized so that the caller gets a copy of the input
  81. + * sample, and knows why it was not accepted (eg: SMP_F_MAY_CHANGE is present).
  82. */
  83. struct stktable_key *stktable_fetch_key(struct stktable *t, struct proxy *px, struct session *l4, void *l7,
  84. - unsigned int opt,
  85. - struct sample_expr *expr)
  86. + unsigned int opt, struct sample_expr *expr, struct sample *smp)
  87. {
  88. - struct sample *smp;
  89. + if (smp)
  90. + memset(smp, 0, sizeof(*smp));
  91. - smp = sample_process(px, l4, l7, opt, expr, NULL);
  92. + smp = sample_process(px, l4, l7, opt, expr, smp);
  93. if (!smp)
  94. return NULL;
  95. --
  96. 1.8.5.5