rsyslog-8.24.0-fix-tcpflood-without-librelp-r1.patch 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. Patch to allow building of tcpflood without librelp
  2. Cherry pick of
  3. https://github.com/rsyslog/rsyslog/commit/73e3b7ab2f8a3974d31844b492ad02d61ed5727f
  4. https://github.com/rsyslog/rsyslog/pull/1493
  5. Gentoo-Bug: https://bugs.gentoo.org/613264
  6. Gentoo-Bug: https://bugs.gentoo.org/614424
  7. diff -u b/tests/tcpflood.c b/tests/tcpflood.c
  8. --- b/tests/tcpflood.c
  9. +++ b/tests/tcpflood.c
  10. @@ -96,7 +96,9 @@
  11. #include <string.h>
  12. #include <netinet/in.h>
  13. #include <pthread.h>
  14. +#ifdef ENABLE_RELP
  15. #include <librelp.h>
  16. +#endif
  17. #include <sys/resource.h>
  18. #include <sys/time.h>
  19. #include <errno.h>
  20. @@ -149,7 +151,9 @@
  21. static int numConnections = 1; /* number of connections to create */
  22. static int softLimitConnections = 0; /* soft connection limit, see -c option description */
  23. static int *sockArray; /* array of sockets to use */
  24. +#ifdef ENABLE_RELP
  25. static relpClt_t **relpCltArray; /* array of sockets to use */
  26. +#endif
  27. static int msgNum = 0; /* initial message number to start with */
  28. static int bShowProgress = 1; /* show progress messages */
  29. static int bSilent = 0; /* completely silent operation */
  30. @@ -216,6 +220,7 @@
  31. static int sendTLS(int i, char *buf, int lenBuf);
  32. static void closeTLSSess(int __attribute__((unused)) i);
  33. +#ifdef ENABLE_RELP
  34. /* RELP subsystem */
  35. #pragma GCC diagnostic push
  36. #pragma GCC diagnostic ignored "-Wformat-security"
  37. @@ -235,6 +240,7 @@
  38. CHKRELP(relpEngineSetEnableCmd(pRelpEngine, (unsigned char*)"syslog",
  39. eRelpCmdState_Required));
  40. }
  41. +#endif /* #ifdef ENABLE_RELP */
  42. /* prepare send subsystem for UDP send */
  43. static int
  44. @@ -273,6 +279,7 @@
  45. port = targetPort;
  46. }
  47. if(transport == TP_RELP_PLAIN) {
  48. + #ifdef ENABLE_RELP
  49. relpRetVal relp_r;
  50. relpClt_t *relpClt;
  51. char relpPort[16];
  52. @@ -286,6 +293,7 @@
  53. return(1);
  54. }
  55. *fd = 1; /* mimic "all ok" state */
  56. + #endif
  57. } else { /* TCP, with or without TLS */
  58. if((sock=socket(AF_INET, SOCK_STREAM, 0))==-1) {
  59. perror("\nsocket()");
  60. @@ -336,8 +344,10 @@
  61. sessArray = calloc(numConnections, sizeof(gnutls_session_t));
  62. # endif
  63. sockArray = calloc(numConnections, sizeof(int));
  64. + #ifdef ENABLE_RELP
  65. if(transport == TP_RELP_PLAIN)
  66. relpCltArray = calloc(numConnections, sizeof(relpClt_t*));
  67. + #endif
  68. for(i = 0 ; i < numConnections ; ++i) {
  69. if(i % 10 == 0) {
  70. if(bShowProgress)
  71. @@ -356,8 +366,10 @@
  72. * at least something.
  73. */
  74. if(transport == TP_RELP_PLAIN) {
  75. + #ifdef ENABLE_RELP
  76. CHKRELP(relpEngineCltDestruct(pRelpEngine,
  77. relpCltArray+i));
  78. + #endif
  79. } else { /* TCP and TLS modes */
  80. if(transport == TP_TLS)
  81. closeTLSSess(i);
  82. @@ -403,14 +415,13 @@
  83. if(bShowProgress)
  84. if(write(1, " close connections", sizeof(" close connections")-1)){}
  85. - //if(transport == TP_RELP_PLAIN)
  86. - //sleep(10); /* we need to let librelp settle a bit */
  87. for(i = 0 ; i < numConnections ; ++i) {
  88. if(i % 10 == 0 && bShowProgress) {
  89. lenMsg = sprintf(msgBuf, "\r%5.5d", i);
  90. if(write(1, msgBuf, lenMsg)){}
  91. }
  92. if(transport == TP_RELP_PLAIN) {
  93. + #ifdef ENABLE_RELP
  94. relpRetVal relpr;
  95. if(sockArray[i] != -1) {
  96. relpr = relpEngineCltDestruct(pRelpEngine, relpCltArray+i);
  97. @@ -419,6 +430,7 @@
  98. }
  99. sockArray[i] = -1;
  100. }
  101. + #endif
  102. } else { /* TCP and TLS modes */
  103. if(sockArray[i] != -1) {
  104. /* we try to not overrun the receiver by trying to flush buffers
  105. @@ -610,6 +622,7 @@
  106. offsSendBuf = lenBuf;
  107. }
  108. } else if(transport == TP_RELP_PLAIN) {
  109. + #ifdef ENABLE_RELP
  110. relpRetVal relp_ret;
  111. if(sockArray[socknum] == -1) {
  112. /* connection was dropped, need to re-establish */
  113. @@ -627,6 +640,7 @@
  114. printf("\nrelpCltSendSyslog() failed with relp error code %d\n",
  115. relp_ret);
  116. }
  117. + #endif
  118. }
  119. if(lenSend != lenBuf) {
  120. printf("\r%5.5d\n", i);
  121. @@ -1106,7 +1120,9 @@
  122. transport = TP_RELP_PLAIN;
  123. # else
  124. fprintf(stderr, "compiled without RELP support: "
  125. - "\"-Trelp-plain\" not supported!\n");
  126. + "\"-Trelp-plain\" not supported!\n"
  127. + "(add --enable-relp to ./configure options "
  128. + "if desired)\n");
  129. exit(1);
  130. # endif
  131. } else {
  132. @@ -1168,7 +1184,9 @@
  133. if(transport == TP_TLS) {
  134. initTLS();
  135. } else if(transport == TP_RELP_PLAIN) {
  136. + #ifdef ENABLE_RELP
  137. initRELP_PLAIN();
  138. + #endif
  139. }
  140. if(openConnections() != 0) {
  141. @@ -1183,9 +1201,11 @@
  142. closeConnections(); /* this is important so that we do not finish too early! */
  143. + #ifdef ENABLE_RELP
  144. if(transport == TP_RELP_PLAIN) {
  145. CHKRELP(relpEngineDestruct(&pRelpEngine));
  146. }
  147. + #endif
  148. if(nConnDrops > 0 && !bSilent)
  149. printf("-D option initiated %ld connection closures\n", nConnDrops);