2
* This is the implementation of the build-in forwarding output module.
4
* NOTE: read comments in module-template.h to understand how this file
7
* File begun on 2007-07-20 by RGerhards (extracted from syslogd.c)
8
* This file is under development and has not yet arrived at being fully
9
* self-contained and a real object. So far, it is mostly an excerpt
10
* of the "old" message code without any modifications. However, it
11
* helps to have things at the right place one we go to the meat of it.
13
* Copyright 2007 Rainer Gerhards and Adiscon GmbH.
15
* This program is free software; you can redistribute it and/or
16
* modify it under the terms of the GNU General Public License
17
* as published by the Free Software Foundation; either version 2
18
* of the License, or (at your option) any later version.
20
* This program is distributed in the hope that it will be useful,
21
* but WITHOUT ANY WARRANTY; without even the implied warranty of
22
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
* GNU General Public License for more details.
25
* You should have received a copy of the GNU General Public License
26
* along with this program; if not, write to the Free Software
27
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29
* A copy of the GPL can be found in the file "COPYING" in this distribution.
39
#include <netinet/in.h>
52
#include "syslogd-types.h"
58
#include "tcpsyslog.h"
59
#include "module-template.h"
62
//#define INET_SUSPEND_TIME 60 /* equal to 1 minute
63
#define INET_SUSPEND_TIME 2 /* equal to 1 minute
64
* rgerhards, 2005-07-26: This was 3 minutes. As the
65
* same timer is used for tcp based syslog, we have
66
* reduced it. However, it might actually be worth
67
* thinking about a buffered tcp sender, which would be
68
* a much better alternative. When that happens, this
69
* time here can be re-adjusted to 3 minutes (or,
70
* even better, made configurable).
72
#define INET_RETRY_MAX 30 /* maximum of retries for gethostbyname() */
73
/* was 10, changed to 30 because we reduced INET_SUSPEND_TIME by one third. So
74
* this "fixes" some of implications of it (see comment on INET_SUSPEND_TIME).
75
* rgerhards, 2005-07-26
79
/* internal structures
83
typedef struct _instanceData {
84
char f_hname[MAXHOSTNAMELEN+1];
85
short sock; /* file descriptor */
86
enum { /* TODO: we shoud revisit these definitions */
92
struct addrinfo *f_addr;
93
int compressionLevel; /* 0 - no compression, else level for zlib */
96
TCPFRAMINGMODE tcp_framing;
99
/* following fields for TCP-based delivery */
101
TCP_SEND_NOTCONNECTED = 0,
102
TCP_SEND_CONNECTING = 1,
106
int savedMsgLen; /* length of savedMsg in octets */
107
time_t ttSuspend; /* time selector was suspended */
109
pthread_mutex_t mtxTCPSend;
115
CODESTARTcreateInstance
119
BEGINisCompatibleWithFeature
120
CODESTARTisCompatibleWithFeature
121
if(eFeat == sFEATURERepeatedMsgReduction)
123
ENDisCompatibleWithFeature
127
CODESTARTfreeInstance
128
switch (pData->eDestState) {
131
freeaddrinfo(pData->f_addr);
134
if(pData->port != NULL)
139
/* delete any mutex objects, if present */
140
if(pData->protocol == FORW_TCP) {
141
pthread_mutex_destroy(&pData->mtxTCPSend);
147
BEGINdbgPrintInstInfo
148
CODESTARTdbgPrintInstInfo
149
printf("%s", pData->f_hname);
152
/* CODE FOR SENDING TCP MESSAGES */
155
* rgerhards, 2005-10-24
157
static void TCPSendSetStatus(instanceData *pData, enum TCPSendStatus iNewState)
159
assert(pData != NULL);
160
assert(pData->protocol == FORW_TCP);
161
assert( (iNewState == TCP_SEND_NOTCONNECTED)
162
|| (iNewState == TCP_SEND_CONNECTING)
163
|| (iNewState == TCP_SEND_READY));
165
/* there can potentially be a race condition, so guard by mutex */
167
pthread_mutex_lock(&pData->mtxTCPSend);
169
pData->status = iNewState;
171
pthread_mutex_unlock(&pData->mtxTCPSend);
177
* rgerhards, 2005-10-24
179
static enum TCPSendStatus TCPSendGetStatus(instanceData *pData)
181
enum TCPSendStatus eState;
182
assert(pData != NULL);
183
assert(pData->protocol == FORW_TCP);
185
/* there can potentially be a race condition, so guard by mutex */
187
pthread_mutex_lock(&pData->mtxTCPSend);
189
eState = pData->status;
191
pthread_mutex_unlock(&pData->mtxTCPSend);
198
/* Initialize TCP sockets (for sender)
199
* This is done once per selector line, if not yet initialized.
201
static int TCPSendCreateSocket(instanceData *pData, struct addrinfo *addrDest)
206
assert(pData != NULL);
211
fd = socket(r->ai_family, r->ai_socktype, r->ai_protocol);
213
/* We can not allow the TCP sender to block syslogd, at least
214
* not in a single-threaded design. That would cause rsyslogd to
215
* loose input messages - which obviously also would affect
216
* other selector lines, too. So we do set it to non-blocking and
217
* handle the situation ourselfs (by discarding messages). IF we run
218
* dual-threaded, however, the situation is different: in this case,
219
* the receivers and the selector line processing are only loosely
220
* coupled via a memory buffer. Now, I think, we can afford the extra
221
* wait time. Thus, we enable blocking mode for TCP if we compile with
223
* rgerhards, 2005-10-25
225
# ifndef USE_PTHREADS
226
/* set to nonblocking - rgerhards 2005-07-20 */
227
fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK);
229
if (connect (fd, r->ai_addr, r->ai_addrlen) != 0) {
230
if(errno == EINPROGRESS) {
231
/* this is normal - will complete during select */
232
TCPSendSetStatus(pData, TCP_SEND_CONNECTING);
236
dbgprintf("create tcp connection failed, reason %s",
237
strerror_r(errno, errStr, sizeof(errStr)));
242
TCPSendSetStatus(pData, TCP_SEND_READY);
249
dbgprintf("couldn't create send socket, reason %s", strerror_r(errno, errStr, sizeof(errStr)));
254
dbgprintf("no working socket could be obtained");
259
/* Sends a TCP message. It is first checked if the
260
* session is open and, if not, it is opened. Then the send
261
* is tried. If it fails, one silent re-try is made. If the send
262
* fails again, an error status (-1) is returned. If all goes well,
263
* 0 is returned. The TCP session is NOT torn down.
264
* For now, EAGAIN is ignored (causing message loss) - but it is
265
* hard to do something intelligent in this case. With this
266
* implementation here, we can not block and/or defer. Things are
267
* probably a bit better when we move to liblogging. The alternative
268
* would be to enhance the current select server with buffering and
269
* write descriptors. This seems not justified, given the expected
270
* short life span of this code (and the unlikeliness of this event).
271
* rgerhards 2005-07-06
272
* This function is now expected to stay. Libloging won't be used for
273
* that purpose. I have added the param "len", because it is known by the
274
* caller and so safes us some time. Also, it MUST be given because there
275
* may be NULs inside msg so that we can not rely on strlen(). Please note
276
* that the restrictions outlined above do not existin in multi-threaded
277
* mode, which we assume will now be most often used. So there is no
278
* real issue with the potential message loss in single-threaded builds.
279
* rgerhards, 2006-11-30
281
* In order to support compressed messages via TCP, we must support an
282
* octet-counting based framing (LF may be part of the compressed message).
283
* We are now supporting the same mode that is available in IETF I-D
284
* syslog-transport-tls-05 (current at the time of this writing). This also
285
* eases things when we go ahead and implement that framing. I have now made
286
* available two cases where this framing is used: either by explitely
287
* specifying it in the config file or implicitely when sending a compressed
288
* message. In the later case, compressed and uncompressed messages within
289
* the same session have different framings. If it is explicitely set to
290
* octet-counting, only this framing mode is used within the session.
291
* rgerhards, 2006-12-07
293
static int TCPSend(instanceData *pData, char *msg, size_t len)
299
char *buf = NULL; /* if this is non-NULL, it MUST be freed before return! */
300
enum TCPSendStatus eState;
301
TCPFRAMINGMODE framingToUse;
303
assert(pData != NULL);
307
bIsCompressed = *msg == 'z'; /* cache this, so that we can modify the message buffer */
308
/* select framing for this record. If we have a compressed record, we always need to
309
* use octet counting because the data potentially contains all control characters
312
framingToUse = bIsCompressed ? TCP_FRAMING_OCTET_COUNTING : pData->tcp_framing;
314
do { /* try to send message */
315
if(pData->sock <= 0) {
316
/* we need to open the socket first */
317
if((pData->sock = TCPSendCreateSocket(pData, pData->f_addr)) <= 0) {
322
eState = TCPSendGetStatus(pData); /* cache info */
324
if(eState == TCP_SEND_CONNECTING) {
325
/* In this case, we save the buffer. If we have a
326
* system with few messages, that hopefully prevents
327
* message loss at all. However, we make no further attempts,
328
* just the first message is saved. So we only try this
329
* if there is not yet a saved message present.
330
* rgerhards 2005-07-20
332
if(pData->savedMsg == NULL) {
333
pData->savedMsg = malloc(len * sizeof(char));
334
if(pData->savedMsg == NULL)
335
return 0; /* nothing we can do... */
336
memcpy(pData->savedMsg, msg, len);
337
pData->savedMsgLen = len;
340
} else if(eState != TCP_SEND_READY)
341
/* This here is debatable. For the time being, we
342
* accept the loss of a single message (e.g. during
343
* connection setup in favour of not messing with
344
* wait time and timeouts. The reason is that such
345
* things might otherwise cost us considerable message
346
* loss on the receiving side (even at a timeout set
347
* to just 1 second). - rgerhards 2005-07-20
351
/* now check if we need to add a line terminator. We need to
352
* copy the string in memory in this case, this is probably
353
* quicker than using writev and definitely quicker than doing
355
* rgerhards 2005-07-22
357
* Some messages already contain a \n character at the end
358
* of the message. We append one only if we there is not
359
* already one. This seems the best fit, though this also
360
* means the message does not arrive unaltered at the final
361
* destination. But in the spirit of legacy syslog, this is
362
* probably the best to do...
363
* rgerhards 2005-07-20
366
/* Build frame based on selected framing */
367
if(framingToUse == TCP_FRAMING_OCTET_STUFFING) {
368
if((*(msg+len-1) != '\n')) {
371
/* in the malloc below, we need to add 2 to the length. The
372
* reason is that we a) add one character and b) len does
373
* not take care of the '\0' byte. Up until today, it was just
374
* +1 , which caused rsyslogd to sometimes dump core.
375
* I have added this comment so that the logic is not accidently
376
* changed again. rgerhards, 2005-10-25
378
if((buf = malloc((len + 2) * sizeof(char))) == NULL) {
379
/* extreme mem shortage, try to solve
380
* as good as we can. No point in calling
381
* any alarms, they might as well run out
382
* of memory (the risk is very high, so we
383
* do NOT risk that). If we have a message of
384
* more than 1 byte (what I guess), we simply
385
* overwrite the last character.
386
* rgerhards 2005-07-22
391
/* we simply can not do anything in
392
* this case (its an error anyhow...).
396
/* we got memory, so we can copy the message */
397
memcpy(buf, msg, len); /* do not copy '\0' */
400
msg = buf; /* use new one */
401
++len; /* care for the \n */
406
* In this case, we need to always allocate a buffer. This is because
407
* we need to put a header in front of the message text
412
/* important: the printf-mask is "%d<sp>" because there must be a
413
* space after the len!
414
*//* The chairs of the IETF syslog-sec WG have announced that it is
415
* consensus to do the octet count on the SYSLOG-MSG part only. I am
416
* now changing the code to reflect this. Hopefully, it will not change
417
* once again (there can no compatibility layer programmed for this).
418
* To be on the save side, I just comment the code out. I mark these
419
* comments with "IETF20061218".
420
* rgerhards, 2006-12-19
422
iLenBuf = snprintf(szLenBuf, sizeof(szLenBuf)/sizeof(char), "%d ", (int) len);
423
/* IETF20061218 iLenBuf =
424
snprintf(szLenBuf, sizeof(szLenBuf)/sizeof(char), "%d ", len + iLenBuf);*/
426
if((buf = malloc((len + iLenBuf) * sizeof(char))) == NULL) {
427
/* we are out of memory. This is an extreme situation. We do not
428
* call any alarm handlers because they most likely run out of mem,
429
* too. We are brave enough to call debug output, though. Other than
430
* that, there is nothing left to do. We can not sent the message (as
431
* in case of the other framing, because the message is incomplete.
432
* We could, however, send two chunks (header and text separate), but
433
* that would cause a lot of complexity in the code. So we think it
434
* is appropriate enough to just make sure we do not crash in this
435
* very unlikely case. For this, it is justified just to loose
436
* the message. Rgerhards, 2006-12-07
438
dbgprintf("Error: out of memory when building TCP octet-counted "
439
"frame. Message is lost, trying to continue.\n");
443
memcpy(buf, szLenBuf, iLenBuf); /* header */
444
memcpy(buf + iLenBuf, msg, len); /* message */
445
len += iLenBuf; /* new message size */
446
msg = buf; /* set message buffer */
449
/* frame building complete, on to actual sending */
451
lenSend = send(pData->sock, msg, len, 0);
452
dbgprintf("TCP sent %d bytes, requested %d, msg: '%s'\n", lenSend, len,
453
bIsCompressed ? "***compressed***" : msg);
454
if((unsigned)lenSend == len) {
460
} else if(lenSend != -1) {
461
/* no real error, could "just" not send everything...
462
* For the time being, we ignore this...
463
* rgerhards, 2005-10-25
465
dbgprintf("message not completely (tcp)send, ignoring %d\n", lenSend);
467
usleep(1000); /* experimental - might be benefitial in this situation */
476
dbgprintf("message not (tcp)send, too large\n");
477
/* This is not a real error, so it is not flagged as one */
484
dbgprintf("message not (tcp)send, would block\n");
486
usleep(1000); /* experimental - might be benefitial in this situation */
488
/* we loose this message, but that's better than loosing
491
/* This is not a real error, so it is not flagged as one */
497
dbgprintf("message not (tcp)send");
505
TCPSendSetStatus(pData, TCP_SEND_NOTCONNECTED);
512
} while(!done); /* warning: do ... while() */
517
return -1; /* only to avoid compiler warning! */
521
/* get the syslog forward port from selector_t. The passed in
522
* struct must be one that is setup for forwarding.
523
* rgerhards, 2007-06-28
524
* We may change the implementation to try to lookup the port
525
* if it is unspecified. So far, we use the IANA default auf 514.
527
static char *getFwdSyslogPt(instanceData *pData)
529
assert(pData != NULL);
530
if(pData->port == NULL)
537
/* try to resume connection if it is not ready
538
* rgerhards, 2007-08-02
540
static rsRetVal doTryResume(instanceData *pData)
543
struct addrinfo *res;
544
struct addrinfo hints;
547
switch (pData->eDestState) {
549
iRet = RS_RET_OK; /* the actual check happens during doAction() only */
550
pData->eDestState = eDestFORW;
554
/* The remote address is not yet known and needs to be obtained */
555
dbgprintf(" %s\n", pData->f_hname);
556
memset(&hints, 0, sizeof(hints));
557
/* port must be numeric, because config file syntax requests this */
558
/* TODO: this code is a duplicate from cfline() - we should later create
561
hints.ai_flags = AI_NUMERICSERV;
562
hints.ai_family = family;
563
hints.ai_socktype = pData->protocol == FORW_UDP ? SOCK_DGRAM : SOCK_STREAM;
564
if((e = getaddrinfo(pData->f_hname,
565
getFwdSyslogPt(pData), &hints, &res)) == 0) {
566
dbgprintf("%s found, resuming.\n", pData->f_hname);
569
pData->eDestState = eDestFORW;
571
iRet = RS_RET_SUSPENDED;
575
/* rgerhards, 2007-09-11: this can not happen, but I've included it to
576
* a) make the compiler happy, b) detect any logic errors */
587
iRet = doTryResume(pData);
591
char *psz; /* temporary buffering */
598
switch (pData->eDestState) {
600
dbgprintf("internal error in omfwd.c, eDestFORW_SUSP in doAction()!\n");
601
iRet = RS_RET_SUSPENDED;
605
dbgprintf("doAction eDestFORW_UNKN\n");
606
iRet = doTryResume(pData);
610
dbgprintf(" %s:%s/%s\n", pData->f_hname, getFwdSyslogPt(pData),
611
pData->protocol == FORW_UDP ? "udp" : "tcp");
612
if ( 0) // TODO: think about this strcmp(getHOSTNAME(f->f_pMsg), LocalHostName) && NoHops )
613
/* what we need to do is get the hostname as an additonal string (during parseSe..). Then,
614
* we can compare that string to LocalHostName. That way, we do not need to access the
615
* msgobject, and everything is clean. The question remains, though, if that functionality
616
* here actually makes sense or not. If we really need it, it might make more sense to compare
617
* the target IP address to the IP addresses of the local machene - that is a far better way of
618
* handling things than to relay on the error-prone hostname property.
619
* rgerhards, 2007-07-27
621
dbgprintf("Not sending message to remote.\n");
623
pData->ttSuspend = time(NULL);
624
psz = (char*) ppString[0];
625
l = strlen((char*) psz);
630
/* Check if we should compress and, if so, do it. We also
631
* check if the message is large enough to justify compression.
632
* The smaller the message, the less likely is a gain in compression.
633
* To save CPU cycles, we do not try to compress very small messages.
634
* What "very small" means needs to be configured. Currently, it is
635
* hard-coded but this may be changed to a config parameter.
636
* rgerhards, 2006-11-30
638
if(pData->compressionLevel && (l > MIN_SIZE_FOR_COMPRESS)) {
639
Bytef out[MAXLINE+MAXLINE/100+12] = "z";
640
uLongf destLen = sizeof(out) / sizeof(Bytef);
643
ret = compress2((Bytef*) out+1, &destLen, (Bytef*) psz,
644
srcLen, pData->compressionLevel);
645
dbgprintf("Compressing message, length was %d now %d, return state %d.\n",
646
l, (int) destLen, ret);
648
/* if we fail, we complain, but only in debug mode
649
* Otherwise, we are silent. In any case, we ignore the
650
* failed compression and just sent the uncompressed
651
* data, which is still valid. So this is probably the
652
* best course of action.
653
* rgerhards, 2006-11-30
655
dbgprintf("Compression failed, sending uncompressed message\n");
656
} else if(destLen+1 < l) {
657
/* only use compression if there is a gain in using it! */
658
dbgprintf("there is gain in compression, so we do it\n");
660
l = destLen + 1; /* take care for the "z" at message start! */
666
if(pData->protocol == FORW_UDP) {
667
/* forward via UDP */
669
/* we need to track if we have success sending to the remote
670
* peer. Success is indicated by at least one sendto() call
671
* succeeding. We track this be bSendSuccess. We can not simply
672
* rely on lsent, as a call might initially work, but a later
673
* call fails. Then, lsent has the error status, even though
674
* the sendto() succeeded.
675
* rgerhards, 2007-06-22
677
bSendSuccess = FALSE;
678
for (r = pData->f_addr; r; r = r->ai_next) {
679
for (i = 0; i < *finet; i++) {
680
lsent = sendto(finet[i+1], psz, l, 0,
681
r->ai_addr, r->ai_addrlen);
688
dbgprintf("sendto() error: %d = %s.\n",
689
eno, strerror_r(eno, errStr, sizeof(errStr)));
692
if (lsent == l && !send_to_all)
695
/* finished looping */
696
if (bSendSuccess == FALSE) {
697
dbgprintf("error forwarding via udp, suspending\n");
698
iRet = RS_RET_SUSPENDED;
702
/* forward via TCP */
703
if(TCPSend(pData, psz, l) != 0) {
705
dbgprintf("error forwarding via tcp, suspending\n");
706
iRet = RS_RET_SUSPENDED;
715
BEGINparseSelectorAct
720
struct addrinfo hints, *res;
721
CODESTARTparseSelectorAct
722
CODE_STD_STRING_REQUESTparseSelectorAct(1)
724
if((iRet = createInstance(&pData)) != RS_RET_OK)
727
if(*p == '@') { /* indicator for TCP! */
728
pData->protocol = FORW_TCP;
729
++p; /* eat this '@', too */
730
/* in this case, we also need a mutex... */
732
pthread_mutex_init(&pData->mtxTCPSend, 0);
735
pData->protocol = FORW_UDP;
737
/* we are now after the protocol indicator. Now check if we should
738
* use compression. We begin to use a new option format for this:
739
* @(option,option)host:port
740
* The first option defined is "z[0..9]" where the digit indicates
741
* the compression level. If it is not given, 9 (best compression) is
742
* assumed. An example action statement might be:
743
* @@(z5,o)127.0.0.1:1400
744
* Which means send via TCP with medium (5) compresion (z) to the local
745
* host on port 1400. The '0' option means that octet-couting (as in
746
* IETF I-D syslog-transport-tls) is to be used for framing (this option
747
* applies to TCP-based syslog only and is ignored when specified with UDP).
748
* That is not yet implemented.
749
* rgerhards, 2006-12-07
752
/* at this position, it *must* be an option indicator */
754
++p; /* eat '(' or ',' (depending on when called) */
756
if(*p == 'z') { /* compression */
759
if(isdigit((int) *p)) {
763
pData->compressionLevel = iLevel;
765
logerrorInt("Invalid compression level '%c' specified in "
766
"forwardig action - NOT turning on compression.",
770
logerror("Compression requested, but rsyslogd is not compiled "
771
"with compression support - request ignored.");
772
# endif /* #ifdef USE_NETZIP */
773
} else if(*p == 'o') { /* octet-couting based TCP framing? */
775
/* no further options settable */
776
pData->tcp_framing = TCP_FRAMING_OCTET_COUNTING;
777
} else { /* invalid option! Just skip it... */
778
logerrorInt("Invalid option %c in forwarding action - ignoring.", *p);
779
++p; /* eat invalid option */
781
/* the option processing is done. We now do a generic skip
782
* to either the next option or the end of the option
785
while(*p && *p != ')' && *p != ',')
786
++p; /* just skip it */
787
} while(*p && *p == ','); /* Attention: do.. while() */
789
++p; /* eat terminator, on to next */
791
/* we probably have end of string - leave it for the rest
792
* of the code to handle it (but warn the user)
794
logerror("Option block not terminated in forwarding action.");
796
/* extract the host first (we do a trick - we replace the ';' or ':' with a '\0')
797
* now skip to port and then template name. rgerhards 2005-07-06
799
for(q = p ; *p && *p != ';' && *p != ':' ; ++p)
803
if(*p == ':') { /* process port */
806
*p = '\0'; /* trick to obtain hostname (later)! */
808
for(i=0 ; *p && isdigit((int) *p) ; ++p, ++i)
809
/* SKIP AND COUNT */;
810
pData->port = malloc(i + 1);
811
if(pData->port == NULL) {
812
logerror("Could not get memory to store syslog forwarding port, "
813
"using default port, results may not be what you intend\n");
814
/* we leave f_forw.port set to NULL, this is then handled by
818
memcpy(pData->port, tmp, i);
819
*(pData->port + i) = '\0';
823
/* now skip to template */
825
while(*p && *p != ';') {
826
if(*p && *p != ';' && !isspace((int) *p)) {
827
if(bErr == 0) { /* only 1 error msg! */
830
logerror("invalid selector line (port), probably not doing "
831
"what was intended");
837
/* TODO: make this if go away! */
839
*p = '\0'; /* trick to obtain hostname (later)! */
840
strcpy(pData->f_hname, (char*) q);
843
strcpy(pData->f_hname, (char*) q);
845
/* process template */
846
if((iRet = cflineParseTemplateName(&p, *ppOMSR, 0, OMSR_NO_RQD_TPL_OPTS, (uchar*) " StdFwdFmt"))
850
/* first set the pData->eDestState */
851
memset(&hints, 0, sizeof(hints));
852
/* port must be numeric, because config file syntax requests this */
853
hints.ai_flags = AI_NUMERICSERV;
854
hints.ai_family = family;
855
hints.ai_socktype = pData->protocol == FORW_UDP ? SOCK_DGRAM : SOCK_STREAM;
856
if( (error = getaddrinfo(pData->f_hname, getFwdSyslogPt(pData), &hints, &res)) != 0) {
857
pData->eDestState = eDestFORW_UNKN;
858
pData->iRtryCnt = INET_RETRY_MAX;
859
pData->ttSuspend = time(NULL);
861
pData->eDestState = eDestFORW;
866
* Otherwise the host might be unknown due to an
867
* inaccessible nameserver (perhaps on the same
868
* host). We try to get the ip number later, like
872
iRet = RS_RET_CONFLINE_UNPROCESSED;
875
/* TODO: do we need to call freeInstance if we failed - this is a general question for
876
* all output modules. I'll address it lates as the interface evolves. rgerhards, 2007-07-25
878
CODE_STD_FINALIZERparseSelectorAct
883
CODESTARTneedUDPSocket
888
BEGINonSelectReadyWrite
889
CODESTARTonSelectReadyWrite
890
dbgprintf("tcp send socket %d ready for writing.\n", pData->sock);
891
TCPSendSetStatus(pData, TCP_SEND_READY);
892
/* Send stored message (if any) */
893
if(pData->savedMsg != NULL) {
894
if(TCPSend(pData, pData->savedMsg,
895
pData->savedMsgLen) != 0) {
897
pData->eDestState = eDestFORW_SUSP;
899
logerror("error forwarding via tcp, suspending...");
901
free(pData->savedMsg);
902
pData->savedMsg = NULL;
904
ENDonSelectReadyWrite
907
BEGINgetWriteFDForSelect
908
CODESTARTgetWriteFDForSelect
909
if( (pData->eDestState == eDestFORW)
910
&& (pData->protocol == FORW_TCP)
911
&& TCPSendGetStatus(pData) == TCP_SEND_CONNECTING) {
915
ENDgetWriteFDForSelect
920
CODEqueryEtryPt_STD_OMOD_QUERIES
926
*ipIFVersProvided = 1; /* so far, we only support the initial definition */
927
CODEmodInit_QueryRegCFSLineHdlr
930
#endif /* #ifdef SYSLOG_INET */