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.

110 lines
4.4 KiB

  1. From 8b3c808c37dd5672f87e7b61085295e1316a6694 Mon Sep 17 00:00:00 2001
  2. From: Willy Tarreau <w@1wt.eu>
  3. Date: Tue, 16 Sep 2014 15:39:51 +0200
  4. Subject: [PATCH 12/13] MEDIUM: config: report it when tcp-request rules are
  5. misplaced
  6. A config where a tcp-request rule appears after an http-request rule
  7. might seem valid but it is not. So let's report a warning about this
  8. since this case is hard to detect by the naked eye.
  9. (cherry picked from commit 3986b9c14037f446f5f5bec6207a39e1bd753fae)
  10. ---
  11. include/common/cfgparse.h | 2 ++
  12. src/cfgparse.c | 38 ++++++++++++++++++++++++++++++++++++++
  13. src/proto_tcp.c | 4 ++++
  14. 3 files changed, 44 insertions(+)
  15. diff --git a/include/common/cfgparse.h b/include/common/cfgparse.h
  16. index 80310ae..86a0035 100644
  17. --- a/include/common/cfgparse.h
  18. +++ b/include/common/cfgparse.h
  19. @@ -73,6 +73,8 @@ int check_config_validity();
  20. int str2listener(char *str, struct proxy *curproxy, struct bind_conf *bind_conf, const char *file, int line, char **err);
  21. int cfg_register_section(char *section_name,
  22. int (*section_parser)(const char *, int, char **, int));
  23. +int warnif_misplaced_tcp_conn(struct proxy *proxy, const char *file, int line, const char *arg);
  24. +int warnif_misplaced_tcp_cont(struct proxy *proxy, const char *file, int line, const char *arg);
  25. /*
  26. * Sends a warning if proxy <proxy> does not have at least one of the
  27. diff --git a/src/cfgparse.c b/src/cfgparse.c
  28. index 5668393..9ff44e9 100644
  29. --- a/src/cfgparse.c
  30. +++ b/src/cfgparse.c
  31. @@ -317,6 +317,19 @@ int str2listener(char *str, struct proxy *curproxy, struct bind_conf *bind_conf,
  32. return 0;
  33. }
  34. +/* Report a warning if a rule is placed after a 'tcp-request content' rule.
  35. + * Return 1 if the warning has been emitted, otherwise 0.
  36. + */
  37. +int warnif_rule_after_tcp_cont(struct proxy *proxy, const char *file, int line, const char *arg)
  38. +{
  39. + if (!LIST_ISEMPTY(&proxy->tcp_req.inspect_rules)) {
  40. + Warning("parsing [%s:%d] : a '%s' rule placed after a 'tcp-request content' rule will still be processed before.\n",
  41. + file, line, arg);
  42. + return 1;
  43. + }
  44. + return 0;
  45. +}
  46. +
  47. /* Report a warning if a rule is placed after a 'block' rule.
  48. * Return 1 if the warning has been emitted, otherwise 0.
  49. */
  50. @@ -408,6 +421,31 @@ int warnif_rule_after_use_server(struct proxy *proxy, const char *file, int line
  51. return 0;
  52. }
  53. +/* report a warning if a "tcp request connection" rule is dangerously placed */
  54. +int warnif_misplaced_tcp_conn(struct proxy *proxy, const char *file, int line, const char *arg)
  55. +{
  56. + return warnif_rule_after_tcp_cont(proxy, file, line, arg) ||
  57. + warnif_rule_after_block(proxy, file, line, arg) ||
  58. + warnif_rule_after_http_req(proxy, file, line, arg) ||
  59. + warnif_rule_after_reqxxx(proxy, file, line, arg) ||
  60. + warnif_rule_after_reqadd(proxy, file, line, arg) ||
  61. + warnif_rule_after_redirect(proxy, file, line, arg) ||
  62. + warnif_rule_after_use_backend(proxy, file, line, arg) ||
  63. + warnif_rule_after_use_server(proxy, file, line, arg);
  64. +}
  65. +
  66. +/* report a warning if a "tcp request content" rule is dangerously placed */
  67. +int warnif_misplaced_tcp_cont(struct proxy *proxy, const char *file, int line, const char *arg)
  68. +{
  69. + return warnif_rule_after_block(proxy, file, line, arg) ||
  70. + warnif_rule_after_http_req(proxy, file, line, arg) ||
  71. + warnif_rule_after_reqxxx(proxy, file, line, arg) ||
  72. + warnif_rule_after_reqadd(proxy, file, line, arg) ||
  73. + warnif_rule_after_redirect(proxy, file, line, arg) ||
  74. + warnif_rule_after_use_backend(proxy, file, line, arg) ||
  75. + warnif_rule_after_use_server(proxy, file, line, arg);
  76. +}
  77. +
  78. /* report a warning if a block rule is dangerously placed */
  79. int warnif_misplaced_block(struct proxy *proxy, const char *file, int line, const char *arg)
  80. {
  81. diff --git a/src/proto_tcp.c b/src/proto_tcp.c
  82. index 72dc92b..940c3f1 100644
  83. --- a/src/proto_tcp.c
  84. +++ b/src/proto_tcp.c
  85. @@ -1711,6 +1711,8 @@ static int tcp_parse_tcp_req(char **args, int section_type, struct proxy *curpx,
  86. warn++;
  87. }
  88. + /* the following function directly emits the warning */
  89. + warnif_misplaced_tcp_cont(curpx, file, line, args[0]);
  90. LIST_ADDQ(&curpx->tcp_req.inspect_rules, &rule->list);
  91. }
  92. else if (strcmp(args[1], "connection") == 0) {
  93. @@ -1754,6 +1756,8 @@ static int tcp_parse_tcp_req(char **args, int section_type, struct proxy *curpx,
  94. warn++;
  95. }
  96. + /* the following function directly emits the warning */
  97. + warnif_misplaced_tcp_conn(curpx, file, line, args[0]);
  98. LIST_ADDQ(&curpx->tcp_req.l4_rules, &rule->list);
  99. }
  100. else {
  101. --
  102. 1.8.5.5