summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2009-05-22 17:06:52 +0200
committerRainer Gerhards <rgerhards@adiscon.com>2009-05-22 17:06:52 +0200
commitaba90e82484118f3568ec51c01de5ba845da589a (patch)
treedee21fce32d09af5ab80ccbad8c51772e7645dd8
parent2aca3c2d33dd1a19daf44168e90a5f64bd4095b0 (diff)
downloadrsyslog-aba90e82484118f3568ec51c01de5ba845da589a.tar.gz
rsyslog-aba90e82484118f3568ec51c01de5ba845da589a.tar.xz
rsyslog-aba90e82484118f3568ec51c01de5ba845da589a.zip
added capability to run multiple tcp listeners (on different ports)
Well, actually this and a lot of related things. I improved the testbench so that the new capabilities are automatically tested and also did some general cleanup. The current multiple tcp listener solution will probably receive some further cleanup, too, but looks quite OK so far. I also reviewed the way tcpsrv et all work, in preparation of using this code for imdiag. I need to document the findings, especially as the code is rather complicated "thanks" to the combination of plain tcp and gssapi transport modes.
-rw-r--r--ChangeLog1
-rw-r--r--doc/imtcp.html6
-rw-r--r--plugins/imfile/imfile.c5
-rw-r--r--plugins/imgssapi/imgssapi.c4
-rw-r--r--plugins/imklog/imklog.c7
-rw-r--r--plugins/imtcp/imtcp.c35
-rw-r--r--plugins/imudp/imudp.c5
-rw-r--r--runtime/Makefile.am1
-rw-r--r--runtime/datetime.c12
-rw-r--r--runtime/datetime.h4
-rw-r--r--runtime/msg.c104
-rw-r--r--runtime/msg.h8
-rw-r--r--runtime/netstrm.c4
-rw-r--r--runtime/netstrm.h1
-rw-r--r--runtime/parser.c2
-rw-r--r--runtime/rsyslog.h3
-rw-r--r--runtime/unicode-helper.h54
-rw-r--r--tcps_sess.c17
-rw-r--r--tcps_sess.h11
-rw-r--r--tcpsrv.c150
-rw-r--r--tcpsrv.h16
-rw-r--r--tests/Makefile.am15
-rwxr-xr-xtests/fieldtest.sh13
-rwxr-xr-xtests/imtcp-multiport.sh80
-rwxr-xr-xtests/inputname.sh20
-rwxr-xr-xtests/killrsyslog.sh7
-rw-r--r--tests/nettester.c101
-rwxr-xr-xtests/omod-if-array.sh6
-rwxr-xr-xtests/parsertest.sh6
-rw-r--r--tests/tcpflood.c2
-rw-r--r--tests/testsuites/1.field13
-rw-r--r--tests/testsuites/1.inputname_imtcp_125143
-rw-r--r--tests/testsuites/1.inputname_imtcp_125153
-rw-r--r--tests/testsuites/1.inputname_imtcp_125163
-rw-r--r--tests/testsuites/field1.conf8
-rw-r--r--tests/testsuites/imtcp-multiport.conf13
-rw-r--r--tests/testsuites/inputname_imtcp.conf19
-rw-r--r--tools/syslogd.c53
38 files changed, 584 insertions, 221 deletions
diff --git a/ChangeLog b/ChangeLog
index 30fb7bff..b7a0a67a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,6 @@
---------------------------------------------------------------------------
Version 4.3.1 [DEVEL] (rgerhards), 2009-04-??
+- added capability to run multiple tcp listeners (on different ports)
- performance enhancement: imtcp calls parser no longer on input thread
but rather inside on of the potentially many main msg queue worker
threads (an enhancement scheduled for all input plugins where this is
diff --git a/doc/imtcp.html b/doc/imtcp.html
index 0ee0f96a..9ea7efa1 100644
--- a/doc/imtcp.html
+++ b/doc/imtcp.html
@@ -14,9 +14,10 @@ Encryption can be provided by using <a href="rsyslog_stunnel.html">stunnel</a>
(an alternative is the use
the&nbsp;<a href="imgssapi.html">imgssapi</a>
modul).</p>
-<p>In the future, multiple receivers may be configured by
+<p>Multiple receivers may be configured by
specifying
-$InputTCPServerRun multiple times. This is not currently supported.
+$InputTCPServerRun multiple times. This is available since version 4.3.1, earlier
+versions do NOT support it.
</p>
<p><b>Configuration Directives</b>:</p>
<ul>
@@ -58,7 +59,6 @@ AuthMode and&nbsp; <a href="netstream.html">network stream driver</a>. Permitted
<b>Caveats/Known Bugs:</b>
<ul>
<li>module always binds to all interfaces</li>
-<li>only a single listener can be bound</li>
<li>can not be loaded together with <a href="imgssapi.html">imgssapi</a>
(which includes the functionality of imtcp)</li>
</ul>
diff --git a/plugins/imfile/imfile.c b/plugins/imfile/imfile.c
index b0211bf6..92fd30c3 100644
--- a/plugins/imfile/imfile.c
+++ b/plugins/imfile/imfile.c
@@ -45,6 +45,7 @@
#include "errmsg.h"
#include "glbl.h"
#include "datetime.h"
+#include "unicode-helper.h"
MODULE_TYPE_INPUT /* must be present for input modules, do not remove */
@@ -94,11 +95,11 @@ static rsRetVal enqLine(fileInfo_t *pInfo, cstr_t *cstrLine)
CHKiRet(msgConstruct(&pMsg));
MsgSetFlowControlType(pMsg, eFLOWCTL_FULL_DELAY);
- MsgSetInputName(pMsg, "imfile");
+ MsgSetInputName(pMsg, UCHAR_CONSTANT("imfile"));
MsgSetUxTradMsg(pMsg, (char*)rsCStrGetSzStr(cstrLine));
MsgSetRawMsg(pMsg, (char*)rsCStrGetSzStr(cstrLine));
MsgSetMSG(pMsg, (char*)rsCStrGetSzStr(cstrLine));
- MsgSetHOSTNAME(pMsg, (char*)glbl.GetLocalHostName());
+ MsgSetHOSTNAME(pMsg, glbl.GetLocalHostName());
MsgSetTAG(pMsg, (char*)pInfo->pszTag);
pMsg->iFacility = LOG_FAC(pInfo->iFacility);
pMsg->iSeverity = LOG_PRI(pInfo->iSeverity);
diff --git a/plugins/imgssapi/imgssapi.c b/plugins/imgssapi/imgssapi.c
index b9d7dfe3..d8791880 100644
--- a/plugins/imgssapi/imgssapi.c
+++ b/plugins/imgssapi/imgssapi.c
@@ -9,7 +9,7 @@
* NOTE: read comments in module-template.h to understand how this file
* works!
*
- * Copyright 2007 Rainer Gerhards and Adiscon GmbH.
+ * Copyright 2007, 2009 Rainer Gerhards and Adiscon GmbH.
*
* This file is part of rsyslog.
*
@@ -330,7 +330,7 @@ addGSSListener(void __attribute__((unused)) *pVal, uchar *pNewVal)
CHKiRet(tcpsrv.SetCBOnSessAccept(pOurTcpsrv, onSessAccept));
CHKiRet(tcpsrv.SetCBOnRegularClose(pOurTcpsrv, onRegularClose));
CHKiRet(tcpsrv.SetCBOnErrClose(pOurTcpsrv, onErrClose));
- tcpsrv.configureTCPListen(pOurTcpsrv, (char *) pNewVal);
+ tcpsrv.configureTCPListen(pOurTcpsrv, pNewVal);
CHKiRet(tcpsrv.ConstructFinalize(pOurTcpsrv));
}
diff --git a/plugins/imklog/imklog.c b/plugins/imklog/imklog.c
index 20bc34ab..ecb6c100 100644
--- a/plugins/imklog/imklog.c
+++ b/plugins/imklog/imklog.c
@@ -53,6 +53,7 @@
#include "datetime.h"
#include "imklog.h"
#include "glbl.h"
+#include "unicode-helper.h"
MODULE_TYPE_INPUT
@@ -94,14 +95,14 @@ enqMsg(uchar *msg, uchar* pszTag, int iFacility, int iSeverity)
CHKiRet(msgConstruct(&pMsg));
MsgSetFlowControlType(pMsg, eFLOWCTL_LIGHT_DELAY);
- MsgSetInputName(pMsg, "imklog");
+ MsgSetInputName(pMsg, UCHAR_CONSTANT("imklog"));
MsgSetRawMsg(pMsg, (char*)msg);
MsgSetUxTradMsg(pMsg, (char*)msg);
MsgSetRawMsg(pMsg, (char*)msg);
MsgSetMSG(pMsg, (char*)msg);
- MsgSetRcvFrom(pMsg, (char*)glbl.GetLocalHostName());
+ MsgSetRcvFrom(pMsg, glbl.GetLocalHostName());
MsgSetRcvFromIP(pMsg, (uchar*)"127.0.0.1");
- MsgSetHOSTNAME(pMsg, (char*)glbl.GetLocalHostName());
+ MsgSetHOSTNAME(pMsg, glbl.GetLocalHostName());
MsgSetTAG(pMsg, (char*)pszTag);
pMsg->iFacility = LOG_FAC(iFacility);
pMsg->iSeverity = LOG_PRI(iSeverity);
diff --git a/plugins/imtcp/imtcp.c b/plugins/imtcp/imtcp.c
index 5a8a62f6..f0efe1ee 100644
--- a/plugins/imtcp/imtcp.c
+++ b/plugins/imtcp/imtcp.c
@@ -3,7 +3,7 @@
*
* File begun on 2007-12-21 by RGerhards (extracted from syslogd.c)
*
- * Copyright 2007 Rainer Gerhards and Adiscon GmbH.
+ * Copyright 2007, 2009 Rainer Gerhards and Adiscon GmbH.
*
* This file is part of rsyslog.
*
@@ -56,6 +56,7 @@
#include "dirty.h"
#include "cfsysline.h"
#include "module-template.h"
+#include "unicode-helper.h"
#include "net.h"
#include "netstrm.h"
#include "errmsg.h"
@@ -91,7 +92,7 @@ static int
isPermittedHost(struct sockaddr *addr, char *fromHostFQDN, void __attribute__((unused)) *pUsrSrv,
void __attribute__((unused)) *pUsrSess)
{
- return net.isAllowedSender((uchar*) "TCP", addr, fromHostFQDN);
+ return net.isAllowedSender(UCHAR_CONSTANT("TCP"), addr, fromHostFQDN);
}
@@ -169,7 +170,6 @@ static rsRetVal addTCPListener(void __attribute__((unused)) *pVal, uchar *pNewVa
CHKiRet(tcpsrv.SetCBOnRegularClose(pOurTcpsrv, onRegularClose));
CHKiRet(tcpsrv.SetCBOnErrClose(pOurTcpsrv, onErrClose));
CHKiRet(tcpsrv.SetDrvrMode(pOurTcpsrv, iStrmDrvrMode));
- CHKiRet(tcpsrv.SetInputName(pOurTcpsrv, pszInputName == NULL ? (uchar*)"imtcp" : pszInputName));
CHKiRet(tcpsrv.SetAddtlFrameDelim(pOurTcpsrv, iAddtlFrameDelim));
/* now set optional params, but only if they were actually configured */
if(pszStrmDrvrAuthMode != NULL) {
@@ -178,11 +178,14 @@ static rsRetVal addTCPListener(void __attribute__((unused)) *pVal, uchar *pNewVa
if(pPermPeersRoot != NULL) {
CHKiRet(tcpsrv.SetDrvrPermPeers(pOurTcpsrv, pPermPeersRoot));
}
- /* most params set, now start listener */
- tcpsrv.configureTCPListen(pOurTcpsrv, (char *) pNewVal);
- CHKiRet(tcpsrv.ConstructFinalize(pOurTcpsrv));
}
+dbgprintf("XXX: try add listen port %s\n", pNewVal);
+ /* initialized, now add socket */
+ CHKiRet(tcpsrv.SetInputName(pOurTcpsrv, pszInputName == NULL ?
+ UCHAR_CONSTANT("imtcp") : pszInputName));
+ tcpsrv.configureTCPListen(pOurTcpsrv, pNewVal);
+
finalize_it:
if(iRet != RS_RET_OK) {
errmsg.LogError(0, NO_ERRCODE, "error %d trying to add listener", iRet);
@@ -199,7 +202,9 @@ CODESTARTrunInput
/* TODO: we must be careful to start the listener here. Currently, tcpsrv.c seems to
* do that in ConstructFinalize
*/
+ CHKiRet(tcpsrv.ConstructFinalize(pOurTcpsrv));
iRet = tcpsrv.Run(pOurTcpsrv);
+finalize_it:
ENDrunInput
@@ -217,7 +222,7 @@ ENDwillRun
BEGINafterRun
CODESTARTafterRun
/* do cleanup here */
- net.clearAllowedSenders((uchar*)"TCP");
+ net.clearAllowedSenders(UCHAR_CONSTANT("TCP"));
ENDafterRun
@@ -277,21 +282,21 @@ CODEmodInit_QueryRegCFSLineHdlr
CHKiRet(objUse(errmsg, CORE_COMPONENT));
/* register config file handlers */
- CHKiRet(omsdRegCFSLineHdlr((uchar *)"inputtcpserverrun", 0, eCmdHdlrGetWord,
+ CHKiRet(omsdRegCFSLineHdlr(UCHAR_CONSTANT("inputtcpserverrun"), 0, eCmdHdlrGetWord,
addTCPListener, NULL, STD_LOADABLE_MODULE_ID));
- CHKiRet(omsdRegCFSLineHdlr((uchar *)"inputtcpmaxsessions", 0, eCmdHdlrInt,
+ CHKiRet(omsdRegCFSLineHdlr(UCHAR_CONSTANT("inputtcpmaxsessions"), 0, eCmdHdlrInt,
NULL, &iTCPSessMax, STD_LOADABLE_MODULE_ID));
- CHKiRet(omsdRegCFSLineHdlr((uchar *)"inputtcpserverstreamdrivermode", 0,
+ CHKiRet(omsdRegCFSLineHdlr(UCHAR_CONSTANT("inputtcpserverstreamdrivermode"), 0,
eCmdHdlrInt, NULL, &iStrmDrvrMode, STD_LOADABLE_MODULE_ID));
- CHKiRet(omsdRegCFSLineHdlr((uchar *)"inputtcpserverstreamdriverauthmode", 0,
+ CHKiRet(omsdRegCFSLineHdlr(UCHAR_CONSTANT("inputtcpserverstreamdriverauthmode"), 0,
eCmdHdlrGetWord, NULL, &pszStrmDrvrAuthMode, STD_LOADABLE_MODULE_ID));
- CHKiRet(omsdRegCFSLineHdlr((uchar *)"inputtcpserverstreamdriverpermittedpeer", 0,
+ CHKiRet(omsdRegCFSLineHdlr(UCHAR_CONSTANT("inputtcpserverstreamdriverpermittedpeer"), 0,
eCmdHdlrGetWord, setPermittedPeer, NULL, STD_LOADABLE_MODULE_ID));
- CHKiRet(omsdRegCFSLineHdlr((uchar *)"inputtcpserveraddtlframedelimiter", 0, eCmdHdlrInt,
+ CHKiRet(omsdRegCFSLineHdlr(UCHAR_CONSTANT("inputtcpserveraddtlframedelimiter"), 0, eCmdHdlrInt,
NULL, &iAddtlFrameDelim, STD_LOADABLE_MODULE_ID));
- CHKiRet(omsdRegCFSLineHdlr((uchar *)"inputtcpserverinputname", 0,
+ CHKiRet(omsdRegCFSLineHdlr(UCHAR_CONSTANT("inputtcpserverinputname"), 0,
eCmdHdlrGetWord, NULL, &pszInputName, STD_LOADABLE_MODULE_ID));
- CHKiRet(omsdRegCFSLineHdlr((uchar *)"resetconfigvariables", 1, eCmdHdlrCustomHandler,
+ CHKiRet(omsdRegCFSLineHdlr(UCHAR_CONSTANT("resetconfigvariables"), 1, eCmdHdlrCustomHandler,
resetConfigVariables, NULL, STD_LOADABLE_MODULE_ID));
ENDmodInit
diff --git a/plugins/imudp/imudp.c b/plugins/imudp/imudp.c
index c7e8c1d4..f3448095 100644
--- a/plugins/imudp/imudp.c
+++ b/plugins/imudp/imudp.c
@@ -43,6 +43,7 @@
#include "msg.h"
#include "parser.h"
#include "datetime.h"
+#include "unicode-helper.h"
MODULE_TYPE_INPUT
@@ -219,11 +220,11 @@ processSocket(int fd, struct sockaddr_storage *frominetPrev, int *pbIsPermitted,
CHKmalloc(pMsg->pszRawMsg = malloc(sizeof(uchar)* lenRcvBuf));
memcpy(pMsg->pszRawMsg, pRcvBuf, lenRcvBuf);
pMsg->iLenRawMsg = lenRcvBuf;
- MsgSetInputName(pMsg, "imudp");
+ MsgSetInputName(pMsg, UCHAR_CONSTANT("imudp"));
MsgSetFlowControlType(pMsg, eFLOWCTL_NO_DELAY);
pMsg->msgFlags = NEEDS_PARSING | PARSE_HOSTNAME;
pMsg->bParseHOSTNAME = 1;
- MsgSetRcvFrom(pMsg, (char*)fromHost);
+ MsgSetRcvFrom(pMsg, fromHost);
CHKiRet(MsgSetRcvFromIP(pMsg, fromHostIP));
CHKiRet(submitMsg(pMsg));
}
diff --git a/runtime/Makefile.am b/runtime/Makefile.am
index 2f0a1aa0..8331882f 100644
--- a/runtime/Makefile.am
+++ b/runtime/Makefile.am
@@ -7,6 +7,7 @@ pkglib_LTLIBRARIES =
librsyslog_la_SOURCES = \
rsyslog.c \
rsyslog.h \
+ unicode_helper.h \
atomic.h \
syslogd-types.h \
module-template.h \
diff --git a/runtime/datetime.c b/runtime/datetime.c
index deb66eb4..19e61a0a 100644
--- a/runtime/datetime.c
+++ b/runtime/datetime.c
@@ -150,7 +150,7 @@ static void getCurrTime(struct syslogTime *t, time_t *ttSeconds)
* \retval The number parsed.
*/
-static int srSLMGParseInt32(char** ppsz)
+static int srSLMGParseInt32(uchar** ppsz)
{
int i;
@@ -172,9 +172,9 @@ static int srSLMGParseInt32(char** ppsz)
* could be obtained (restriction added 2008-09-16 by rgerhards).
*/
static rsRetVal
-ParseTIMESTAMP3339(struct syslogTime *pTime, char** ppszTS)
+ParseTIMESTAMP3339(struct syslogTime *pTime, uchar** ppszTS)
{
- char *pszTS = *ppszTS;
+ uchar *pszTS = *ppszTS;
/* variables to temporarily hold time information while we parse */
int year;
int month;
@@ -234,7 +234,7 @@ ParseTIMESTAMP3339(struct syslogTime *pTime, char** ppszTS)
/* Now let's see if we have secfrac */
if(*pszTS == '.') {
- char *pszStart = ++pszTS;
+ uchar *pszStart = ++pszTS;
secfrac = srSLMGParseInt32(&pszTS);
secfracPrecision = (int) (pszTS - pszStart);
} else {
@@ -307,7 +307,7 @@ finalize_it:
* time() call reduction ;).
*/
static rsRetVal
-ParseTIMESTAMP3164(struct syslogTime *pTime, char** ppszTS)
+ParseTIMESTAMP3164(struct syslogTime *pTime, uchar** ppszTS)
{
/* variables to temporarily hold time information while we parse */
int month;
@@ -317,7 +317,7 @@ ParseTIMESTAMP3164(struct syslogTime *pTime, char** ppszTS)
int minute;
int second;
/* end variables to temporarily hold time information while we parse */
- char *pszTS;
+ uchar *pszTS;
DEFiRet;
assert(ppszTS != NULL);
diff --git a/runtime/datetime.h b/runtime/datetime.h
index 0739588d..efb0a0af 100644
--- a/runtime/datetime.h
+++ b/runtime/datetime.h
@@ -36,8 +36,8 @@ typedef struct datetime_s {
/* interfaces */
BEGINinterface(datetime) /* name must also be changed in ENDinterface macro! */
void (*getCurrTime)(struct syslogTime *t, time_t *ttSeconds);
- rsRetVal (*ParseTIMESTAMP3339)(struct syslogTime *pTime, char** ppszTS);
- rsRetVal (*ParseTIMESTAMP3164)(struct syslogTime *pTime, char** pszTS);
+ rsRetVal (*ParseTIMESTAMP3339)(struct syslogTime *pTime, uchar** ppszTS);
+ rsRetVal (*ParseTIMESTAMP3164)(struct syslogTime *pTime, uchar** pszTS);
int (*formatTimestampToMySQL)(struct syslogTime *ts, char* pDst, size_t iLenDst);
int (*formatTimestampToPgSQL)(struct syslogTime *ts, char *pDst, size_t iLenDst);
int (*formatTimestamp3339)(struct syslogTime *ts, char* pBuf, size_t iLenBuf);
diff --git a/runtime/msg.c b/runtime/msg.c
index 9d5f3838..dbc3c779 100644
--- a/runtime/msg.c
+++ b/runtime/msg.c
@@ -45,6 +45,7 @@
#include "glbl.h"
#include "regexp.h"
#include "atomic.h"
+#include "unicode-helper.h"
/* static data */
DEFobjStaticHelpers
@@ -341,52 +342,29 @@ CODESTARTobjDestruct(msg)
if(currRefCount == 0)
{
/* DEV Debugging Only! dbgprintf("msgDestruct\t0x%lx, RefCount now 0, doing DESTROY\n", (unsigned long)pThis); */
- if(pThis->pszUxTradMsg != NULL)
- free(pThis->pszUxTradMsg);
- if(pThis->pszRawMsg != NULL)
- free(pThis->pszRawMsg);
- if(pThis->pszTAG != NULL)
- free(pThis->pszTAG);
- if(pThis->pszHOSTNAME != NULL)
- free(pThis->pszHOSTNAME);
- if(pThis->pszInputName != NULL)
- free(pThis->pszInputName);
- if(pThis->pszRcvFrom != NULL)
- free(pThis->pszRcvFrom);
- if(pThis->pszRcvFromIP != NULL)
- free(pThis->pszRcvFromIP);
- if(pThis->pszMSG != NULL)
- free(pThis->pszMSG);
- if(pThis->pszFacility != NULL)
- free(pThis->pszFacility);
- if(pThis->pszFacilityStr != NULL)
- free(pThis->pszFacilityStr);
- if(pThis->pszSeverity != NULL)
- free(pThis->pszSeverity);
- if(pThis->pszSeverityStr != NULL)
- free(pThis->pszSeverityStr);
- if(pThis->pszRcvdAt3164 != NULL)
- free(pThis->pszRcvdAt3164);
- if(pThis->pszRcvdAt3339 != NULL)
- free(pThis->pszRcvdAt3339);
- if(pThis->pszRcvdAt_SecFrac != NULL)
- free(pThis->pszRcvdAt_SecFrac);
- if(pThis->pszRcvdAt_MySQL != NULL)
- free(pThis->pszRcvdAt_MySQL);
- if(pThis->pszRcvdAt_PgSQL != NULL)
- free(pThis->pszRcvdAt_PgSQL);
- if(pThis->pszTIMESTAMP3164 != NULL)
- free(pThis->pszTIMESTAMP3164);
- if(pThis->pszTIMESTAMP3339 != NULL)
- free(pThis->pszTIMESTAMP3339);
- if(pThis->pszTIMESTAMP_SecFrac != NULL)
- free(pThis->pszTIMESTAMP_SecFrac);
- if(pThis->pszTIMESTAMP_MySQL != NULL)
- free(pThis->pszTIMESTAMP_MySQL);
- if(pThis->pszTIMESTAMP_PgSQL != NULL)
- free(pThis->pszTIMESTAMP_PgSQL);
- if(pThis->pszPRI != NULL)
- free(pThis->pszPRI);
+ free(pThis->pszUxTradMsg);
+ free(pThis->pszRawMsg);
+ free(pThis->pszTAG);
+ free(pThis->pszHOSTNAME);
+ free(pThis->pszInputName);
+ free(pThis->pszRcvFrom);
+ free(pThis->pszRcvFromIP);
+ free(pThis->pszMSG);
+ free(pThis->pszFacility);
+ free(pThis->pszFacilityStr);
+ free(pThis->pszSeverity);
+ free(pThis->pszSeverityStr);
+ free(pThis->pszRcvdAt3164);
+ free(pThis->pszRcvdAt3339);
+ free(pThis->pszRcvdAt_SecFrac);
+ free(pThis->pszRcvdAt_MySQL);
+ free(pThis->pszRcvdAt_PgSQL);
+ free(pThis->pszTIMESTAMP3164);
+ free(pThis->pszTIMESTAMP3339);
+ free(pThis->pszTIMESTAMP_SecFrac);
+ free(pThis->pszTIMESTAMP_MySQL);
+ free(pThis->pszTIMESTAMP_PgSQL);
+ free(pThis->pszPRI);
if(pThis->pCSProgName != NULL)
rsCStrDestruct(&pThis->pCSProgName);
if(pThis->pCSStrucData != NULL)
@@ -1306,15 +1284,15 @@ uchar *getInputName(msg_t *pM)
}
-char *getRcvFrom(msg_t *pM)
+uchar *getRcvFrom(msg_t *pM)
{
if(pM == NULL)
- return "";
+ return UCHAR_CONSTANT("");
else
if(pM->pszRcvFrom == NULL)
- return "";
+ return UCHAR_CONSTANT("");
else
- return (char*) pM->pszRcvFrom;
+ return pM->pszRcvFrom;
}
@@ -1488,13 +1466,13 @@ static int getAPPNAMELen(msg_t *pM)
/* rgerhards 2008-09-10: set pszInputName in msg object
*/
-void MsgSetInputName(msg_t *pMsg, char* pszInputName)
+void MsgSetInputName(msg_t *pMsg, uchar* pszInputName)
{
assert(pMsg != NULL);
if(pMsg->pszInputName != NULL)
free(pMsg->pszInputName);
- pMsg->iLenInputName = strlen(pszInputName);
+ pMsg->iLenInputName = ustrlen(pszInputName);
if((pMsg->pszInputName = malloc(pMsg->iLenInputName + 1)) != NULL) {
memcpy(pMsg->pszInputName, pszInputName, pMsg->iLenInputName + 1);
}
@@ -1502,13 +1480,12 @@ void MsgSetInputName(msg_t *pMsg, char* pszInputName)
/* rgerhards 2004-11-16: set pszRcvFrom in msg object
*/
-void MsgSetRcvFrom(msg_t *pMsg, char* pszRcvFrom)
+void MsgSetRcvFrom(msg_t *pMsg, uchar* pszRcvFrom)
{
assert(pMsg != NULL);
- if(pMsg->pszRcvFrom != NULL)
- free(pMsg->pszRcvFrom);
+ free(pMsg->pszRcvFrom);
- pMsg->iLenRcvFrom = strlen(pszRcvFrom);
+ pMsg->iLenRcvFrom = ustrlen(pszRcvFrom);
if((pMsg->pszRcvFrom = malloc(pMsg->iLenRcvFrom + 1)) != NULL) {
memcpy(pMsg->pszRcvFrom, pszRcvFrom, pMsg->iLenRcvFrom + 1);
}
@@ -1559,13 +1536,12 @@ void MsgAssignHOSTNAME(msg_t *pMsg, char *pBuf)
* we need it. The rest of the code already knows how to handle an
* unset HOSTNAME.
*/
-void MsgSetHOSTNAME(msg_t *pMsg, char* pszHOSTNAME)
+void MsgSetHOSTNAME(msg_t *pMsg, uchar* pszHOSTNAME)
{
assert(pMsg != NULL);
- if(pMsg->pszHOSTNAME != NULL)
- free(pMsg->pszHOSTNAME);
+ free(pMsg->pszHOSTNAME);
- pMsg->iLenHOSTNAME = strlen(pszHOSTNAME);
+ pMsg->iLenHOSTNAME = ustrlen(pszHOSTNAME);
if((pMsg->pszHOSTNAME = malloc(pMsg->iLenHOSTNAME + 1)) != NULL)
memcpy(pMsg->pszHOSTNAME, pszHOSTNAME, pMsg->iLenHOSTNAME + 1);
else
@@ -1790,7 +1766,7 @@ char *MsgGetProp(msg_t *pMsg, struct templateEntry *pTpe,
} else if(!strcmp((char*) pName, "inputname")) {
pRes = (char*) getInputName(pMsg);
} else if(!strcmp((char*) pName, "fromhost")) {
- pRes = getRcvFrom(pMsg);
+ pRes = (char*) getRcvFrom(pMsg);
} else if(!strcmp((char*) pName, "fromhost-ip")) {
pRes = (char*) getRcvFromIP(pMsg);
} else if(!strcmp((char*) pName, "source") || !strcmp((char*) pName, "hostname")) {
@@ -2517,13 +2493,13 @@ rsRetVal MsgSetProperty(msg_t *pThis, var_t *pProp)
} else if(isProp("pszTAG")) {
MsgSetTAG(pThis, (char*) rsCStrGetSzStrNoNULL(pProp->val.pStr));
} else if(isProp("pszInputName")) {
- MsgSetInputName(pThis, (char*) rsCStrGetSzStrNoNULL(pProp->val.pStr));
+ MsgSetInputName(pThis, rsCStrGetSzStrNoNULL(pProp->val.pStr));
} else if(isProp("pszRcvFromIP")) {
MsgSetRcvFromIP(pThis, rsCStrGetSzStrNoNULL(pProp->val.pStr));
} else if(isProp("pszRcvFrom")) {
- MsgSetRcvFrom(pThis, (char*) rsCStrGetSzStrNoNULL(pProp->val.pStr));
+ MsgSetRcvFrom(pThis, rsCStrGetSzStrNoNULL(pProp->val.pStr));
} else if(isProp("pszHOSTNAME")) {
- MsgSetHOSTNAME(pThis, (char*) rsCStrGetSzStrNoNULL(pProp->val.pStr));
+ MsgSetHOSTNAME(pThis, rsCStrGetSzStrNoNULL(pProp->val.pStr));
} else if(isProp("pCSStrucData")) {
MsgSetStructuredData(pThis, (char*) rsCStrGetSzStrNoNULL(pProp->val.pStr));
} else if(isProp("pCSAPPNAME")) {
diff --git a/runtime/msg.h b/runtime/msg.h
index c8350626..a14f6b15 100644
--- a/runtime/msg.h
+++ b/runtime/msg.h
@@ -158,7 +158,7 @@ char *getSeverity(msg_t *pM);
char *getSeverityStr(msg_t *pM);
char *getFacility(msg_t *pM);
char *getFacilityStr(msg_t *pM);
-void MsgSetInputName(msg_t *pMsg, char*);
+void MsgSetInputName(msg_t *pMsg, uchar*);
rsRetVal MsgSetAPPNAME(msg_t *pMsg, char* pszAPPNAME);
char *getAPPNAME(msg_t *pM);
rsRetVal MsgSetPROCID(msg_t *pMsg, char* pszPROCID);
@@ -171,15 +171,15 @@ rsRetVal MsgSetFlowControlType(msg_t *pMsg, flowControl_t eFlowCtl);
char *getTAG(msg_t *pM);
int getHOSTNAMELen(msg_t *pM);
char *getHOSTNAME(msg_t *pM);
-char *getRcvFrom(msg_t *pM);
+uchar *getRcvFrom(msg_t *pM);
rsRetVal MsgSetStructuredData(msg_t *pMsg, char* pszStrucData);
char *getStructuredData(msg_t *pM);
int getProgramNameLen(msg_t *pM);
char *getProgramName(msg_t *pM);
-void MsgSetRcvFrom(msg_t *pMsg, char* pszRcvFrom);
+void MsgSetRcvFrom(msg_t *pMsg, uchar* pszRcvFrom);
rsRetVal MsgSetRcvFromIP(msg_t *pMsg, uchar* pszRcvFromIP);
void MsgAssignHOSTNAME(msg_t *pMsg, char *pBuf);
-void MsgSetHOSTNAME(msg_t *pMsg, char* pszHOSTNAME);
+void MsgSetHOSTNAME(msg_t *pMsg, uchar* pszHOSTNAME);
int MsgSetUxTradMsg(msg_t *pMsg, char* pszUxTradMsg);
void MsgSetMSG(msg_t *pMsg, char* pszMSG);
void MsgSetRawMsg(msg_t *pMsg, char* pszRawMsg);
diff --git a/runtime/netstrm.c b/runtime/netstrm.c
index ffa1c578..459561bc 100644
--- a/runtime/netstrm.c
+++ b/runtime/netstrm.c
@@ -17,7 +17,7 @@
* Rainer Gerhards and Adiscon GmbH have agreed to permit using the code
* under the terms of the GNU Lesser General Public License.
*
- * Copyright 2007, 2008 Rainer Gerhards and Adiscon GmbH.
+ * Copyright 2007-2009 Rainer Gerhards and Adiscon GmbH.
*
* This file is part of the rsyslog runtime library.
*
@@ -114,6 +114,7 @@ AcceptConnReq(netstrm_t *pThis, netstrm_t **ppNew)
ISOBJ_TYPE_assert(pThis, netstrm);
assert(ppNew != NULL);
+RUNLOG_STR("XXX: accept conn reqeust");
/* accept the new connection */
CHKiRet(pThis->Drvr.AcceptConnReq(pThis->pDrvrData, &pNewNsd));
/* construct our object so that we can use it... */
@@ -147,6 +148,7 @@ LstnInit(netstrms_t *pNS, void *pUsr, rsRetVal(*fAddLstn)(void*,netstrm_t*),
ISOBJ_TYPE_assert(pNS, netstrms);
assert(fAddLstn != NULL);
assert(pLstnPort != NULL);
+RUNLOG_STR("XXX: Init Lstn");
CHKiRet(pNS->Drvr.LstnInit(pNS, pUsr, fAddLstn, pLstnPort, pLstnIP, iSessMax));
diff --git a/runtime/netstrm.h b/runtime/netstrm.h
index 3ab790e8..b00dd223 100644
--- a/runtime/netstrm.h
+++ b/runtime/netstrm.h
@@ -31,6 +31,7 @@ struct netstrm_s {
BEGINobjInstance; /* Data to implement generic object - MUST be the first data element! */
nsd_t *pDrvrData; /**< the driver's data elements (at most other places, this is called pNsd) */
nsd_if_t Drvr; /**< our stream driver */
+ void *pUsr; /**< pointer to user-provided data structure */
netstrms_t *pNS; /**< pointer to our netstream subsystem object */
};
diff --git a/runtime/parser.c b/runtime/parser.c
index b4ab0a3e..212d40f3 100644
--- a/runtime/parser.c
+++ b/runtime/parser.c
@@ -283,7 +283,7 @@ rsRetVal parseMsg(msg_t *pMsg)
MsgSetUxTradMsg(pMsg, (char*) msg);
if(pMsg->bParseHOSTNAME == 0)
- MsgSetHOSTNAME(pMsg, (char*) pMsg->pszRcvFrom);
+ MsgSetHOSTNAME(pMsg, pMsg->pszRcvFrom);
/* rger 2005-11-24 (happy thanksgiving!): we now need to check if we have
* a traditional syslog message or one formatted according to syslog-protocol.
diff --git a/runtime/rsyslog.h b/runtime/rsyslog.h
index fd5a5371..8e8a9f2a 100644
--- a/runtime/rsyslog.h
+++ b/runtime/rsyslog.h
@@ -87,6 +87,8 @@ typedef struct tcpsrv_s tcpsrv_t;
typedef struct vmstk_s vmstk_t;
typedef rsRetVal (*prsf_t)(struct vmstk_s*, int); /* pointer to a RainerScript function */
+typedef struct tcpLstnPortList_s tcpLstnPortList_t; // TODO: rename?
+
/* some universal 64 bit define... */
typedef long long int64;
typedef long long unsigned uint64;
@@ -359,6 +361,7 @@ typedef enum rsObjectID rsObjID;
/* The following prototype is convenient, even though it may not be the 100% correct place.. -- rgerhards 2008-01-07 */
void dbgprintf(char *, ...) __attribute__((format(printf, 1, 2)));
+
#include "debug.h"
#include "obj.h"
diff --git a/runtime/unicode-helper.h b/runtime/unicode-helper.h
new file mode 100644
index 00000000..36d76a78
--- /dev/null
+++ b/runtime/unicode-helper.h
@@ -0,0 +1,54 @@
+/* This is the header file for unicode support.
+ *
+ * Currently, this is a dummy module.
+ * The following functions are wrappers which hopefully enable us to move
+ * from 8-bit chars to unicode with relative ease when we finally attack this
+ *
+ * Begun 2009-05-21 RGerhards
+ *
+ * Copyright (C) 2009 by Rainer Gerhards and Adiscon GmbH
+ *
+ * This file is part of the rsyslog runtime library.
+ *
+ * The rsyslog runtime library is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * The rsyslog runtime library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with the rsyslog runtime library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * A copy of the GPL can be found in the file "COPYING" in this distribution.
+ * A copy of the LGPL can be found in the file "COPYING.LESSER" in this distribution.
+ */
+#ifndef INCLUDED_UNICODE_HELPER_H
+#define INCLUDED_UNICODE_HELPER_H
+
+#include <string.h>
+
+static inline int ustrcmp(uchar *psz1, uchar *psz2)
+{
+ return strcmp((char*) psz1, (char*) psz2);
+}
+
+static inline int ustrlen(uchar *psz)
+{
+ return strlen((char*) psz);
+}
+
+static inline uchar* ustrdup(uchar *psz)
+{
+ return (uchar*) strdup((char*)psz);
+}
+
+
+#define UCHAR_CONSTANT(x) ((uchar*) (x))
+
+#endif /* multi-include protection */
+/* vim:set ai:
+ */
diff --git a/tcps_sess.c b/tcps_sess.c
index ceb6142f..c564caea 100644
--- a/tcps_sess.c
+++ b/tcps_sess.c
@@ -185,6 +185,18 @@ SetTcpsrv(tcps_sess_t *pThis, tcpsrv_t *pSrv)
}
+/* set our parent listener info*/
+static rsRetVal
+SetLstnInfo(tcps_sess_t *pThis, tcpLstnPortList_t *pLstnInfo)
+{
+ DEFiRet;
+ ISOBJ_TYPE_assert(pThis, tcps_sess);
+ assert(pLstnInfo != NULL);
+ pThis->pLstnInfo = pLstnInfo;
+ RETiRet;
+}
+
+
static rsRetVal
SetUsrP(tcps_sess_t *pThis, void *pUsr)
{
@@ -223,11 +235,11 @@ doSubmitMessage(tcps_sess_t *pThis)
CHKmalloc(pMsg->pszRawMsg = malloc(sizeof(uchar) * pThis->iMsg));
memcpy(pMsg->pszRawMsg, pThis->pMsg, pThis->iMsg);
pMsg->iLenRawMsg = pThis->iMsg;
- MsgSetInputName(pMsg, (char*)pThis->pSrv->pszInputName);
+ MsgSetInputName(pMsg, pThis->pLstnInfo->pszInputName);
MsgSetFlowControlType(pMsg, eFLOWCTL_LIGHT_DELAY);
pMsg->msgFlags = NEEDS_PARSING | PARSE_HOSTNAME;
pMsg->bParseHOSTNAME = 1;
- MsgSetRcvFrom(pMsg, (char*)pThis->fromHost);
+ MsgSetRcvFrom(pMsg, pThis->fromHost);
CHKiRet(MsgSetRcvFromIP(pMsg, pThis->fromHostIP));
CHKiRet(submitMsg(pMsg));
@@ -457,6 +469,7 @@ CODESTARTobjQueryInterface(tcps_sess)
pIf->SetUsrP = SetUsrP;
pIf->SetTcpsrv = SetTcpsrv;
+ pIf->SetLstnInfo = SetLstnInfo;
pIf->SetHost = SetHost;
pIf->SetHostIP = SetHostIP;
pIf->SetStrm = SetStrm;
diff --git a/tcps_sess.h b/tcps_sess.h
index 576466ff..2ef28264 100644
--- a/tcps_sess.h
+++ b/tcps_sess.h
@@ -31,7 +31,8 @@ struct tcpsrv_s;
/* the tcps_sess object */
typedef struct tcps_sess_s {
BEGINobjInstance; /* Data to implement generic object - MUST be the first data element! */
- struct tcpsrv_s *pSrv; /* pointer back to my server (e.g. for callbacks) */
+ tcpsrv_t *pSrv; /* pointer back to my server (e.g. for callbacks) */
+ tcpLstnPortList_t *pLstnInfo; /* pointer back to listener info */
netstrm_t *pStrm;
int iMsg; /* index of next char to store in msg */
int bAtStrtOfFram; /* are we at the very beginning of a new frame? */
@@ -60,13 +61,19 @@ BEGINinterface(tcps_sess) /* name must also be changed in ENDinterface macro! */
rsRetVal (*DataRcvd)(tcps_sess_t *pThis, char *pData, size_t iLen);
/* set methods */
rsRetVal (*SetTcpsrv)(tcps_sess_t *pThis, struct tcpsrv_s *pSrv);
+ rsRetVal (*SetLstnInfo)(tcps_sess_t *pThis, tcpLstnPortList_t *pLstnInfo);
rsRetVal (*SetUsrP)(tcps_sess_t*, void*);
rsRetVal (*SetHost)(tcps_sess_t *pThis, uchar*);
rsRetVal (*SetHostIP)(tcps_sess_t *pThis, uchar*);
rsRetVal (*SetStrm)(tcps_sess_t *pThis, netstrm_t*);
rsRetVal (*SetMsgIdx)(tcps_sess_t *pThis, int);
ENDinterface(tcps_sess)
-#define tcps_sessCURR_IF_VERSION 1 /* increment whenever you change the interface structure! */
+#define tcps_sessCURR_IF_VERSION 2 /* increment whenever you change the interface structure! */
+/* interface changes
+ * to version v2, rgerhards, 2009-05-22
+ * - Data structures changed
+ * - SetLstnInfo entry point added
+ */
/* prototypes */
diff --git a/tcpsrv.c b/tcpsrv.c
index 7af45d3c..bbd95058 100644
--- a/tcpsrv.c
+++ b/tcpsrv.c
@@ -66,6 +66,7 @@
#include "netstrm.h"
#include "nssel.h"
#include "errmsg.h"
+#include "unicode-helper.h"
MODULE_TYPE_LIB
@@ -85,43 +86,61 @@ DEFobjCurrIf(netstrm)
DEFobjCurrIf(nssel)
-/* configure TCP listener settings. This is called during command
- * line parsing. The argument following -t is supplied as an argument.
- * The format of this argument is
- * "<port-to-use>, <nbr-of-sessions>"
- * Typically, there is no whitespace between port and session number.
- * (but it may be...).
- * NOTE: you can not use dbgprintf() in here - the dbgprintf() system is
- * not yet initilized when this function is called.
- * rgerhards, 2007-06-21
- * The port in cOptarg is handed over to us - the caller MUST NOT free it!
+/* add new listener port to listener port list
+ * rgerhards, 2009-05-21
+ */
+static inline rsRetVal
+addNewLstnPort(tcpsrv_t *pThis, uchar *pszPort)
+{
+ tcpLstnPortList_t *pEntry;
+ DEFiRet;
+
+ ISOBJ_TYPE_assert(pThis, tcpsrv);
+
+dbgprintf("XXX: tcpsrv.c add port %s, name '%s'\n", pszPort, pThis->pszInputName);
+ /* create entry */
+ CHKmalloc(pEntry = malloc(sizeof(tcpLstnPortList_t)));
+ pEntry->pszPort = pszPort;
+ pEntry->pSrv = pThis;
+ CHKmalloc(pEntry->pszInputName = ustrdup(pThis->pszInputName));
+
+ /* and add to list */
+ pEntry->pNext = pThis->pLstnPorts;
+ pThis->pLstnPorts = pEntry;
+
+finalize_it:
+ RETiRet;
+}
+
+
+/* configure TCP listener settings.
+ * Note: pszPort is handed over to us - the caller MUST NOT free it!
* rgerhards, 2008-03-20
*/
-static void
-configureTCPListen(tcpsrv_t *pThis, char *cOptarg)
+static rsRetVal
+configureTCPListen(tcpsrv_t *pThis, uchar *pszPort)
{
- register int i;
- register char *pArg = cOptarg;
+ int i;
+ uchar *pPort = pszPort;
+ DEFiRet;
- assert(cOptarg != NULL);
+ assert(pszPort != NULL);
ISOBJ_TYPE_assert(pThis, tcpsrv);
/* extract port */
i = 0;
- while(isdigit((int) *pArg)) {
- i = i * 10 + *pArg++ - '0';
+ while(isdigit((int) *pPort)) {
+ i = i * 10 + *pPort++ - '0';
}
- if(pThis->TCPLstnPort != NULL) {
- free(pThis->TCPLstnPort);
- pThis->TCPLstnPort = NULL;
- }
-
- if( i >= 0 && i <= 65535) {
- pThis->TCPLstnPort = cOptarg;
+ if(i >= 0 && i <= 65535) {
+ CHKiRet(addNewLstnPort(pThis, pszPort));
} else {
- errmsg.LogError(0, NO_ERRCODE, "Invalid TCP listen port %s - changed to 514.\n", cOptarg);
+ errmsg.LogError(0, NO_ERRCODE, "Invalid TCP listen port %s - ignored.\n", pszPort);
}
+
+finalize_it:
+ RETiRet;
}
@@ -202,6 +221,8 @@ TCPSessGetNxtSess(tcpsrv_t *pThis, int iCurr)
static void deinit_tcp_listener(tcpsrv_t *pThis)
{
int i;
+ tcpLstnPortList_t *pEntry;
+ tcpLstnPortList_t *pDel;
ISOBJ_TYPE_assert(pThis, tcpsrv);
@@ -219,7 +240,15 @@ static void deinit_tcp_listener(tcpsrv_t *pThis)
pThis->pSessions = NULL; /* just to make sure... */
}
- free(pThis->TCPLstnPort);
+ /* free list of tcp listen ports */
+ pEntry = pThis->pLstnPorts;
+ while(pEntry != NULL) {
+ free(pEntry->pszPort);
+ free(pEntry->pszInputName);
+ pDel = pEntry;
+ pEntry = pEntry->pNext;
+ free(pDel);
+ }
/* finally close our listen streams */
for(i = 0 ; i < pThis->iLstnMax ; ++i) {
@@ -234,9 +263,11 @@ static void deinit_tcp_listener(tcpsrv_t *pThis)
static rsRetVal
addTcpLstn(void *pUsr, netstrm_t *pLstn)
{
- tcpsrv_t *pThis = (tcpsrv_t*) pUsr;
+ tcpLstnPortList_t *pPortList = (tcpLstnPortList_t *) pUsr;
+ tcpsrv_t *pThis = pPortList->pSrv;
DEFiRet;
+dbgprintf("XXX: addTcpLst name %s\n", pPortList->pszInputName);
ISOBJ_TYPE_assert(pThis, tcpsrv);
ISOBJ_TYPE_assert(pLstn, netstrm);
@@ -244,6 +275,7 @@ addTcpLstn(void *pUsr, netstrm_t *pLstn)
ABORT_FINALIZE(RS_RET_MAX_LSTN_REACHED);
pThis->ppLstn[pThis->iLstnMax] = pLstn;
+ pThis->ppLstnPort[pThis->iLstnMax] = pPortList;
++pThis->iLstnMax;
finalize_it:
@@ -251,19 +283,20 @@ finalize_it:
}
-/* Initialize TCP sockets (for listener) and listens on them */
-static rsRetVal
-create_tcp_socket(tcpsrv_t *pThis)
+/* Initialize TCP listener socket for a single port
+ * rgerhards, 2009-05-21
+ */
+static inline rsRetVal
+initTCPListener(tcpsrv_t *pThis, tcpLstnPortList_t *pPortEntry)
{
DEFiRet;
uchar *TCPLstnPort;
ISOBJ_TYPE_assert(pThis, tcpsrv);
+ assert(pPortEntry != NULL);
- if(!strcmp((char*)pThis->TCPLstnPort, "0"))
- TCPLstnPort = (uchar*)"514";
- // TODO: we need to enable the caller to set a port (based on who is
- // using this, 514 may be totally unsuitable... --- rgerhards, 2008-04-22
+ if(!ustrcmp(pPortEntry->pszPort, UCHAR_CONSTANT("0")))
+ TCPLstnPort = UCHAR_CONSTANT("514");
/* use default - we can not do service db update, because there is
* no IANA-assignment for syslog/tcp. In the long term, we might
* re-use RFC 3195 port of 601, but that would probably break to
@@ -271,10 +304,32 @@ create_tcp_socket(tcpsrv_t *pThis)
* rgerhards, 2007-06-28
*/
else
- TCPLstnPort = (uchar*)pThis->TCPLstnPort;
+ TCPLstnPort = pPortEntry->pszPort;
/* TODO: add capability to specify local listen address! */
- CHKiRet(netstrm.LstnInit(pThis->pNS, (void*)pThis, addTcpLstn, TCPLstnPort, NULL, pThis->iSessMax));
+ CHKiRet(netstrm.LstnInit(pThis->pNS, (void*)pPortEntry, addTcpLstn, TCPLstnPort, NULL, pThis->iSessMax));
+
+finalize_it:
+ RETiRet;
+}
+
+
+/* Initialize TCP sockets (for listener) and listens on them */
+static rsRetVal
+create_tcp_socket(tcpsrv_t *pThis)
+{
+ tcpLstnPortList_t *pEntry;
+ DEFiRet;
+
+ ISOBJ_TYPE_assert(pThis, tcpsrv);
+
+ /* init all configured ports */
+ pEntry = pThis->pLstnPorts;
+ while(pEntry != NULL) {
+dbgprintf("XXX: tcpsrv.c create_tcp_socket do port %s\n", pEntry->pszPort);
+ CHKiRet(initTCPListener(pThis, pEntry));
+ pEntry = pEntry->pNext;
+ }
/* OK, we had success. Now it is also time to
* initialize our connections
@@ -296,7 +351,7 @@ finalize_it:
/* Accept new TCP connection; make entry in session table. If there
* is no more space left in the connection table, the new TCP
* connection is immediately dropped.
- * ppSess has a pointer to the newly created session, if it succeds.
+ * ppSess has a pointer to the newly created session, if it succeeds.
* If it does not succeed, no session is created and ppSess is
* undefined. If the user has provided an OnSessAccept Callback,
* this one is executed immediately after creation of the
@@ -304,7 +359,7 @@ finalize_it:
* rgerhards, 2008-03-02
*/
static rsRetVal
-SessAccept(tcpsrv_t *pThis, tcps_sess_t **ppSess, netstrm_t *pStrm)
+SessAccept(tcpsrv_t *pThis, tcpLstnPortList_t *pLstnInfo, tcps_sess_t **ppSess, netstrm_t *pStrm)
{
DEFiRet;
tcps_sess_t *pSess = NULL;
@@ -315,6 +370,7 @@ SessAccept(tcpsrv_t *pThis, tcps_sess_t **ppSess, netstrm_t *pStrm)
uchar *fromHostIP = NULL;
ISOBJ_TYPE_assert(pThis, tcpsrv);
+ assert(pLstnInfo != NULL);
CHKiRet(netstrm.AcceptConnReq(pStrm, &pNewStrm));
@@ -328,6 +384,7 @@ SessAccept(tcpsrv_t *pThis, tcps_sess_t **ppSess, netstrm_t *pStrm)
/* we found a free spot and can construct our session object */
CHKiRet(tcps_sess.Construct(&pSess));
CHKiRet(tcps_sess.SetTcpsrv(pSess, pThis));
+ CHKiRet(tcps_sess.SetLstnInfo(pSess, pLstnInfo));
}
/* OK, we have a "good" index... */
@@ -375,12 +432,10 @@ finalize_it:
if(iRet != RS_RET_OK) {
if(pSess != NULL)
tcps_sess.Destruct(&pSess);
- if(fromHostFQDN != NULL)
- free(fromHostFQDN);
- if(fromHostIP != NULL)
- free(fromHostIP);
if(pNewStrm != NULL)
netstrm.Destruct(&pNewStrm);
+ free(fromHostFQDN);
+ free(fromHostIP);
}
RETiRet;
@@ -444,7 +499,7 @@ Run(tcpsrv_t *pThis)
CHKiRet(nssel.IsReady(pSel, pThis->ppLstn[i], NSDSEL_RD, &bIsReady, &nfds));
if(bIsReady) {
dbgprintf("New connect on NSD %p.\n", pThis->ppLstn[i]);
- SessAccept(pThis, &pNewSess, pThis->ppLstn[i]);
+ SessAccept(pThis, pThis->ppLstnPort[i], &pNewSess, pThis->ppLstn[i]);
--nfds; /* indicate we have processed one */
}
}
@@ -535,6 +590,7 @@ tcpsrvConstructFinalize(tcpsrv_t *pThis)
/* set up listeners */
CHKmalloc(pThis->ppLstn = calloc(TCPLSTN_MAX_DEFAULT, sizeof(netstrm_t*)));
+ CHKmalloc(pThis->ppLstnPort = calloc(TCPLSTN_MAX_DEFAULT, sizeof(tcpLstnPortList_t*)));
iRet = pThis->OpenLstnSocks(pThis);
finalize_it:
@@ -558,6 +614,7 @@ CODESTARTobjDestruct(tcpsrv)
netstrms.Destruct(&pThis->pNS);
free(pThis->pszDrvrAuthMode);
free(pThis->ppLstn);
+ free(pThis->ppLstnPort);
free(pThis->pszInputName);
ENDobjDestruct(tcpsrv)
@@ -674,11 +731,12 @@ SetInputName(tcpsrv_t *pThis, uchar *name)
{
uchar *pszName;
DEFiRet;
+dbgprintf("XXX: SetInputName: %s\n", name);
ISOBJ_TYPE_assert(pThis, tcpsrv);
if(name == NULL)
pszName = NULL;
else
- CHKmalloc(pszName = (uchar*)strdup((char*)name));
+ CHKmalloc(pszName = ustrdup(name));
free(pThis->pszInputName);
pThis->pszInputName = pszName;
finalize_it:
@@ -708,7 +766,7 @@ SetDrvrAuthMode(tcpsrv_t *pThis, uchar *mode)
{
DEFiRet;
ISOBJ_TYPE_assert(pThis, tcpsrv);
- CHKmalloc(pThis->pszDrvrAuthMode = (uchar*)strdup((char*)mode));
+ CHKmalloc(pThis->pszDrvrAuthMode = ustrdup(mode));
finalize_it:
RETiRet;
}
@@ -763,7 +821,7 @@ CODESTARTobjQueryInterface(tcpsrv)
pIf->ConstructFinalize = tcpsrvConstructFinalize;
pIf->Destruct = tcpsrvDestruct;
- pIf->SessAccept = SessAccept;
+ //pIf->SessAccept = SessAccept;
pIf->configureTCPListen = configureTCPListen;
pIf->create_tcp_socket = create_tcp_socket;
pIf->Run = Run;
diff --git a/tcpsrv.h b/tcpsrv.h
index e5ecb865..0f7dd6c6 100644
--- a/tcpsrv.h
+++ b/tcpsrv.h
@@ -32,6 +32,15 @@ typedef enum ETCPsyslogFramingAnomaly {
frame_CiscoIOS = 2
} eTCPsyslogFramingAnomaly;
+
+/* list of tcp listen ports */
+struct tcpLstnPortList_s {
+ uchar *pszPort; /**< the ports the listener shall listen on */
+ uchar *pszInputName; /**< value to be used as input name */
+ tcpsrv_t *pSrv; /**< pointer to higher-level server instance */
+ tcpLstnPortList_t *pNext; /**< next port or NULL */
+};
+
#define TCPSRV_NO_ADDTL_DELIMITER -1 /* specifies that no additional delimiter is to be used in TCP framing */
/* the tcpsrv object */
@@ -44,8 +53,9 @@ struct tcpsrv_s {
permittedPeers_t *pPermPeers;/**< driver's permitted peers */
int iLstnMax; /**< max nbr of listeners currently supported */
netstrm_t **ppLstn; /**< our netstream listners */
+ tcpLstnPortList_t **ppLstnPort; /**< pointer to relevant listen port description */
int iSessMax; /**< max number of sessions supported */
- char *TCPLstnPort; /**< the port the listener shall listen on */
+ tcpLstnPortList_t *pLstnPorts; /**< head pointer for listen ports */
int addtlFrameDelim; /**< additional frame delimiter for plain TCP syslog framing (e.g. to handle NetScreen) */
tcps_sess_t **pSessions;/**< array of all of our sessions */
void *pUsr; /**< a user-settable pointer (provides extensibility for "derived classes")*/
@@ -70,8 +80,8 @@ BEGINinterface(tcpsrv) /* name must also be changed in ENDinterface macro! */
rsRetVal (*Construct)(tcpsrv_t **ppThis);
rsRetVal (*ConstructFinalize)(tcpsrv_t __attribute__((unused)) *pThis);
rsRetVal (*Destruct)(tcpsrv_t **ppThis);
- void (*configureTCPListen)(tcpsrv_t*, char *cOptarg);
- rsRetVal (*SessAccept)(tcpsrv_t *pThis, tcps_sess_t **ppSess, netstrm_t *pStrm);
+ rsRetVal (*configureTCPListen)(tcpsrv_t*, uchar *pszPort);
+ //rsRetVal (*SessAccept)(tcpsrv_t *pThis, tcpLstnPortList_t*, tcps_sess_t **ppSess, netstrm_t *pStrm);
rsRetVal (*create_tcp_socket)(tcpsrv_t *pThis);
rsRetVal (*Run)(tcpsrv_t *pThis);
/* set methods */
diff --git a/tests/Makefile.am b/tests/Makefile.am
index ed415a1e..bc1849f0 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1,8 +1,8 @@
TESTRUNS = rt_init rscript
check_PROGRAMS = $(TESTRUNS) ourtail nettester tcpflood chkseq
-TESTS = $(TESTRUNS) cfg.sh manytcp.sh diskqueue.sh
+TESTS = $(TESTRUNS) cfg.sh manytcp.sh diskqueue.sh imtcp-multiport.sh
if ENABLE_OMSTDOUT
-TESTS += omod-if-array.sh parsertest.sh
+TESTS += omod-if-array.sh parsertest.sh inputname.sh fieldtest.sh
endif
TESTS_ENVIRONMENT = RSYSLOG_MODDIR='$(abs_top_builddir)'/runtime/.libs/
DISTCLEANFILES=rsyslog.pid
@@ -29,11 +29,22 @@ EXTRA_DIST= 1.rstest 2.rstest 3.rstest err1.rstest \
testsuites/rfc5424-4.parse1 \
testsuites/omod-if-array.conf \
testsuites/1.omod-if-array \
+ killrsyslog.sh \
parsertest.sh \
diskqueue.sh \
testsuites/diskqueue.conf \
+ imtcp-multiport.sh \
+ testsuites/imtcp-multiport.conf \
manytcp.sh \
testsuites/manytcp.conf \
+ fieldtest.sh \
+ testsuites/field.conf \
+ testsuites/1.field1 \
+ inputname.sh \
+ testsuites/inputname_imtcp.conf \
+ testsuites/1.inputname_imtcp_12514 \
+ testsuites/1.inputname_imtcp_12515 \
+ testsuites/1.inputname_imtcp_12516 \
omod-if-array.sh \
cfg.sh
diff --git a/tests/fieldtest.sh b/tests/fieldtest.sh
new file mode 100755
index 00000000..7a646f00
--- /dev/null
+++ b/tests/fieldtest.sh
@@ -0,0 +1,13 @@
+echo test fieldtest via udp
+./killrsyslog.sh # kill rsyslogd if it runs for some reason
+
+./nettester -tfield1 -iudp
+if [ "$?" -ne "0" ]; then
+ exit 1
+fi
+
+echo test fieldtest via tcp
+./nettester -tfield1 -itcp
+if [ "$?" -ne "0" ]; then
+ exit 1
+fi
diff --git a/tests/imtcp-multiport.sh b/tests/imtcp-multiport.sh
new file mode 100755
index 00000000..aa1f15e8
--- /dev/null
+++ b/tests/imtcp-multiport.sh
@@ -0,0 +1,80 @@
+# Test for multiple ports in imtcp
+# This test checks if multiple tcp listener ports are correctly
+# handled by imtcp
+#
+# NOTE: this test must (and can) be enhanced when we merge in the
+# upgraded tcpflood program
+#
+# added 2009-05-22 by Rgerhards
+# This file is part of the rsyslog project, released under GPLv3
+echo testing imtcp multiple listeners
+rm -f work rsyslog.out.log rsyslog.out.log.save # work files
+../tools/rsyslogd -c4 -u2 -n -irsyslog.pid -M../runtime/.libs:../.libs -f$srcdir/testsuites/imtcp-multiport.conf &
+sleep 1
+echo "rsyslogd started with pid " `cat rsyslog.pid`
+./tcpflood 127.0.0.1 13514 1 10000
+if [ "$?" -ne "0" ]; then
+ echo "error during tcpflood! see rsyslog.out.log.save for what was written"
+ cp rsyslog.out.log rsyslog.out.log.save
+fi
+sleep 2 # we need this so that rsyslogd can receive all outstanding messages
+kill `cat rsyslog.pid`
+rm -f work
+sort < rsyslog.out.log > work
+./chkseq work 0 9999
+if [ "$?" -ne "0" ]; then
+ # rm -f work rsyslog.out.log
+ echo "sequence error detected"
+ exit 1
+fi
+rm -f work rsyslog.out.log
+#
+#
+# ### now complete new cycle with other port ###
+#
+#
+rm -f work rsyslog.out.log rsyslog.out.log.save # work files
+../tools/rsyslogd -c4 -u2 -n -irsyslog.pid -M../runtime/.libs:../.libs -f$srcdir/testsuites/imtcp-multiport.conf &
+sleep 1
+echo "rsyslogd started with pid " `cat rsyslog.pid`
+./tcpflood 127.0.0.1 13515 1 10000
+if [ "$?" -ne "0" ]; then
+ echo "error during tcpflood! see rsyslog.out.log.save for what was written"
+ cp rsyslog.out.log rsyslog.out.log.save
+fi
+sleep 2 # we need this so that rsyslogd can receive all outstanding messages
+kill `cat rsyslog.pid`
+rm -f work
+sort < rsyslog.out.log > work
+./chkseq work 0 9999
+if [ "$?" -ne "0" ]; then
+ # rm -f work rsyslog.out.log
+ echo "sequence error detected"
+ exit 1
+fi
+rm -f work rsyslog.out.log
+#
+#
+# ### now complete new cycle with other port ###
+#
+#
+rm -f work rsyslog.out.log rsyslog.out.log.save # work files
+../tools/rsyslogd -c4 -u2 -n -irsyslog.pid -M../runtime/.libs:../.libs -f$srcdir/testsuites/imtcp-multiport.conf &
+sleep 1
+echo "rsyslogd started with pid " `cat rsyslog.pid`
+./tcpflood 127.0.0.1 13516 1 10000
+if [ "$?" -ne "0" ]; then
+ echo "error during tcpflood! see rsyslog.out.log.save for what was written"
+ cp rsyslog.out.log rsyslog.out.log.save
+fi
+sleep 2 # we need this so that rsyslogd can receive all outstanding messages
+kill `cat rsyslog.pid`
+rm -f work
+sort < rsyslog.out.log > work
+./chkseq work 0 9999
+if [ "$?" -ne "0" ]; then
+ # rm -f work rsyslog.out.log
+ echo "sequence error detected"
+ exit 1
+fi
+rm -f work rsyslog.out.log
diff --git a/tests/inputname.sh b/tests/inputname.sh
new file mode 100755
index 00000000..7d9ea111
--- /dev/null
+++ b/tests/inputname.sh
@@ -0,0 +1,20 @@
+echo testing $InputTCPServerInputName directive
+./killrsyslog.sh # kill rsyslogd if it runs for some reason
+
+echo port 12514
+./nettester -tinputname_imtcp_12514 -cinputname_imtcp -itcp -p12514
+if [ "$?" -ne "0" ]; then
+ exit 1
+fi
+
+echo port 12515
+./nettester -tinputname_imtcp_12515 -cinputname_imtcp -itcp -p12515
+if [ "$?" -ne "0" ]; then
+ exit 1
+fi
+
+echo port 12516
+./nettester -tinputname_imtcp_12516 -cinputname_imtcp -itcp -p12516
+if [ "$?" -ne "0" ]; then
+ exit 1
+fi
diff --git a/tests/killrsyslog.sh b/tests/killrsyslog.sh
new file mode 100755
index 00000000..b1be757b
--- /dev/null
+++ b/tests/killrsyslog.sh
@@ -0,0 +1,7 @@
+#check if rsyslog instance exists and, if so, kill it
+if [ -e "rsyslog.pid" ]
+then
+ echo rsyslog.pid exists, trying to shut down rsyslogd process `cat rsyslog.pid`.
+ kill `cat rsyslog.pid`
+ sleep 1
+fi
diff --git a/tests/nettester.c b/tests/nettester.c
index 37183ac9..566f553b 100644
--- a/tests/nettester.c
+++ b/tests/nettester.c
@@ -45,16 +45,36 @@
#include <glob.h>
#include <signal.h>
#include <netinet/in.h>
+#include <getopt.h>
#define EXIT_FAILURE 1
#define INVALID_SOCKET -1
/* Name of input file, must match $IncludeConfig in test suite .conf files */
#define NETTEST_INPUT_CONF_FILE "nettest.input.conf" /* name of input file, must match $IncludeConfig in .conf files */
-static enum { inputUDP, inputTCP } inputMode; /* input for which tests are to be run */
+typedef enum { inputUDP, inputTCP } inputMode_t;
+inputMode_t inputMode = inputTCP; /* input for which tests are to be run */
static pid_t rsyslogdPid = 0; /* pid of rsyslog instance being tested */
static char *srcdir; /* global $srcdir, set so that we can run outside of "make check" */
-static char *testSuite; /* name of current test suite */
+static char *testSuite = NULL; /* name of current test suite */
+static int iPort = 12514; /* port which shall be used for sending data */
+static char* pszCustomConf = NULL; /* custom config file, use -c conf to specify */
+static int verbose = 0; /* verbose output? -v option */
+
+
+/* provide user-friednly name of input mode
+ */
+static char *inputMode2Str(inputMode_t mode)
+{
+ char *pszMode;
+
+ if(mode == inputUDP)
+ pszMode = "udp";
+ else
+ pszMode = "tcp";
+
+ return pszMode;
+}
void readLine(int fd, char *ln)
@@ -94,7 +114,7 @@ tcpSend(char *buf, int lenBuf)
memset((char *) &addr, 0, sizeof(addr));
addr.sin_family = AF_INET;
- addr.sin_port = htons(13514);
+ addr.sin_port = htons(iPort);
if(inet_aton("127.0.0.1", &addr.sin_addr)==0) {
fprintf(stderr, "inet_aton() failed\n");
return(1);
@@ -139,7 +159,7 @@ udpSend(char *buf, int lenBuf)
memset((char *) &si_other, 0, sizeof(si_other));
si_other.sin_family = AF_INET;
- si_other.sin_port = htons(12514);
+ si_other.sin_port = htons(iPort);
if(inet_aton("127.0.0.1", &si_other.sin_addr)==0) {
fprintf(stderr, "inet_aton() failed\n");
return(1);
@@ -169,9 +189,14 @@ int openPipe(char *configFile, pid_t *pid, int *pfd)
"-M../runtime/.libs:../.libs", NULL };
char confFile[1024];
char *newenviron[] = { NULL };
+ /* debug aide...
+ char *newenviron[] = { "RSYSLOG_DEBUG=debug nostdout",
+ "RSYSLOG_DEBUGLOG=tmp", NULL };
+ */
- sprintf(confFile, "-f%s/testsuites/%s.conf", srcdir, configFile);
+ sprintf(confFile, "-f%s/testsuites/%s.conf", srcdir,
+ (pszCustomConf == NULL) ? configFile : pszCustomConf);
newargv[1] = confFile;
if (pipe(pipefd) == -1) {
@@ -291,12 +316,12 @@ doTests(int fd, char *files)
++iTests;
/* all regular files are run through the test logic. Symlinks don't work. */
if(S_ISREG(fileInfo.st_mode)) { /* config file */
- printf("processing test case '%s' ... ", testFile);
+ if(verbose) printf("processing test case '%s' ... ", testFile);
ret = processTestFile(fd, testFile);
if(ret == 0) {
- printf("successfully completed\n");
+ if(verbose) printf("successfully completed\n");
} else {
- printf("failed!\n");
+ if(verbose) printf("failed!\n");
++iFailed;
}
}
@@ -334,36 +359,54 @@ void doAtExit(void)
int main(int argc, char *argv[])
{
int fd;
+ int opt;
int ret = 0;
FILE *fp;
char buf[4096];
char testcases[4096];
- if(argc != 3) {
- printf("Invalid call of nettester\n");
- printf("Usage: nettester testsuite-name input\n");
- printf(" input = udp|tcp\n");
- exit(1);
+ while((opt = getopt(argc, argv, "c:i:p:t:v")) != EOF) {
+ switch((char)opt) {
+ case 'c':
+ pszCustomConf = optarg;
+ break;
+ case 'i':
+ if(!strcmp(optarg, "udp"))
+ inputMode = inputUDP;
+ else if(!strcmp(optarg, "tcp"))
+ inputMode = inputTCP;
+ else {
+ printf("error: unsupported input mode '%s'\n", optarg);
+ exit(1);
+ }
+ break;
+ case 'p':
+ iPort = atoi(optarg);
+ break;
+ case 't':
+ testSuite = optarg;
+ break;
+ case 'v':
+ verbose = 1;
+ break;
+ default:printf("Invalid call of nettester, invalid option '%c'.\n", opt);
+ printf("Usage: nettester -ttestsuite-name -iudp|tcp [-pport] [-ccustomConfFile] \n");
+ exit(1);
+ }
}
- atexit(doAtExit);
-
- testSuite = argv[1];
-
- if(!strcmp(argv[2], "udp"))
- inputMode = inputUDP;
- else if(!strcmp(argv[2], "tcp"))
- inputMode = inputTCP;
- else {
- printf("error: unsupported input mode '%s'\n", argv[2]);
+ if(testSuite == NULL) {
+ printf("error: no testsuite given, need to specify -t testsuite!\n");
exit(1);
}
+ atexit(doAtExit);
+
if((srcdir = getenv("srcdir")) == NULL)
srcdir = ".";
- printf("Start of nettester run ($srcdir=%s, testsuite=%s, input=%s)\n",
- srcdir, testSuite, argv[2]);
+ if(verbose) printf("Start of nettester run ($srcdir=%s, testsuite=%s, input=%s/%d)\n",
+ srcdir, testSuite, inputMode2Str(inputMode), iPort);
/* create input config file */
if((fp = fopen(NETTEST_INPUT_CONF_FILE, "w")) == NULL) {
@@ -373,15 +416,15 @@ int main(int argc, char *argv[])
}
if(inputMode == inputUDP) {
fputs("$ModLoad ../plugins/imudp/.libs/imudp\n", fp);
- fputs("$UDPServerRun 12514\n", fp);
+ fprintf(fp, "$UDPServerRun %d\n", iPort);
} else {
fputs("$ModLoad ../plugins/imtcp/.libs/imtcp\n", fp);
- fputs("$InputTCPServerRun 13514\n", fp);
+ fprintf(fp, "$InputTCPServerRun %d\n", iPort);
}
fclose(fp);
/* start to be tested rsyslogd */
- openPipe(argv[1], &rsyslogdPid, &fd);
+ openPipe(testSuite, &rsyslogdPid, &fd);
readLine(fd, buf);
/* generate filename */
@@ -389,6 +432,6 @@ int main(int argc, char *argv[])
if(doTests(fd, testcases) != 0)
ret = 1;
- printf("End of nettester run (%d).\n", ret);
+ if(verbose) printf("End of nettester run (%d).\n", ret);
exit(ret);
}
diff --git a/tests/omod-if-array.sh b/tests/omod-if-array.sh
index fd845b4d..7b4b5611 100755
--- a/tests/omod-if-array.sh
+++ b/tests/omod-if-array.sh
@@ -1,11 +1,13 @@
echo test omod-if-array via udp
-./nettester omod-if-array udp
+./killrsyslog.sh # kill rsyslogd if it runs for some reason
+
+./nettester -tomod-if-array -iudp -p4711
if [ "$?" -ne "0" ]; then
exit 1
fi
echo test omod-if-array via tcp
-./nettester omod-if-array tcp
+./nettester -tomod-if-array -itcp
if [ "$?" -ne "0" ]; then
exit 1
fi
diff --git a/tests/parsertest.sh b/tests/parsertest.sh
index a6b7d45c..152d8b60 100755
--- a/tests/parsertest.sh
+++ b/tests/parsertest.sh
@@ -1,11 +1,13 @@
echo test parsertest via udp
-./nettester parse1 udp
+./killrsyslog.sh # kill rsyslogd if it runs for some reason
+
+./nettester -tparse1 -iudp
if [ "$?" -ne "0" ]; then
exit 1
fi
echo test parsertest via tcp
-./nettester parse1 tcp
+./nettester -tparse1 -itcp
if [ "$?" -ne "0" ]; then
exit 1
fi
diff --git a/tests/tcpflood.c b/tests/tcpflood.c
index 8dbc201b..c3c9c871 100644
--- a/tests/tcpflood.c
+++ b/tests/tcpflood.c
@@ -154,8 +154,6 @@ int sendMessages(void)
int lenBuf;
int lenSend;
char buf[2048];
- char msgBuf[128];
- size_t lenMsg;
srand(time(NULL)); /* seed is good enough for our needs */
diff --git a/tests/testsuites/1.field1 b/tests/testsuites/1.field1
new file mode 100644
index 00000000..54751171
--- /dev/null
+++ b/tests/testsuites/1.field1
@@ -0,0 +1,3 @@
+<167>Mar 6 16:57:54 172.20.245.8 %PIX-7-710005: DROP_url_www.sina.com.cn:IN=eth1 OUT=eth0 SRC=192.168.10.78 DST=61.172.201.194 LEN=1182 TOS=0x00 PREC=0x00 TTL=63 ID=14368 DF PROTO=TCP SPT=33343 DPT=80 WINDOW=92 RES=0x00 ACK PSH URGP=0
+DROP_url_www.sina.com.cn:IN=eth1
+#Only the first two lines are important, you may place anything behind them!
diff --git a/tests/testsuites/1.inputname_imtcp_12514 b/tests/testsuites/1.inputname_imtcp_12514
new file mode 100644
index 00000000..178b1724
--- /dev/null
+++ b/tests/testsuites/1.inputname_imtcp_12514
@@ -0,0 +1,3 @@
+<167>Mar 6 16:57:54 172.20.245.8 %PIX-7-710005: MSG
+12514
+#Only the first two lines are important, you may place anything behind them!
diff --git a/tests/testsuites/1.inputname_imtcp_12515 b/tests/testsuites/1.inputname_imtcp_12515
new file mode 100644
index 00000000..d616098b
--- /dev/null
+++ b/tests/testsuites/1.inputname_imtcp_12515
@@ -0,0 +1,3 @@
+<167>Mar 6 16:57:54 172.20.245.8 %PIX-7-710005: MSG
+12515
+#Only the first two lines are important, you may place anything behind them!
diff --git a/tests/testsuites/1.inputname_imtcp_12516 b/tests/testsuites/1.inputname_imtcp_12516
new file mode 100644
index 00000000..8e6997ce
--- /dev/null
+++ b/tests/testsuites/1.inputname_imtcp_12516
@@ -0,0 +1,3 @@
+<167>Mar 6 16:57:54 172.20.245.8 %PIX-7-710005: MSG
+12516
+#Only the first two lines are important, you may place anything behind them!
diff --git a/tests/testsuites/field1.conf b/tests/testsuites/field1.conf
new file mode 100644
index 00000000..1ff833dd
--- /dev/null
+++ b/tests/testsuites/field1.conf
@@ -0,0 +1,8 @@
+$ModLoad ../plugins/omstdout/.libs/omstdout
+$IncludeConfig nettest.input.conf # This picks the to be tested input from the test driver!
+
+$ErrorMessagesToStderr off
+
+# use a special format that we can easily parse in expect
+$template fmt,"%msg:F,32:2%\n"
+*.* :omstdout:;fmt
diff --git a/tests/testsuites/imtcp-multiport.conf b/tests/testsuites/imtcp-multiport.conf
new file mode 100644
index 00000000..00b63cb2
--- /dev/null
+++ b/tests/testsuites/imtcp-multiport.conf
@@ -0,0 +1,13 @@
+# Test for queue disk mode (see .sh file for details)
+# rgerhards, 2009-05-22
+$ModLoad ../plugins/imtcp/.libs/imtcp
+$MainMsgQueueTimeoutShutdown 10000
+$InputTCPServerRun 13514
+$InputTCPServerRun 13515
+$InputTCPServerRun 13516
+
+$ErrorMessagesToStderr off
+
+$template outfmt,"%msg:F,58:2%\n"
+$template dynfile,"rsyslog.out.log" # trick to use relative path names!
+:msg, contains, "msgnum:" ?dynfile;outfmt
diff --git a/tests/testsuites/inputname_imtcp.conf b/tests/testsuites/inputname_imtcp.conf
new file mode 100644
index 00000000..a25eab37
--- /dev/null
+++ b/tests/testsuites/inputname_imtcp.conf
@@ -0,0 +1,19 @@
+# This is a special case, thus we define the inputs ourselfs
+$ModLoad ../plugins/omstdout/.libs/omstdout
+
+$ModLoad ../plugins/imtcp/.libs/imtcp
+
+$InputTCPServerInputname 12514
+$InputTCPServerRun 12514
+
+$InputTCPServerInputname 12515
+$InputTCPServerRun 12515
+
+$InputTCPServerInputname 12516
+$InputTCPServerRun 12516
+
+$ErrorMessagesToStderr off
+
+# use a special format that we can easily parse in expect
+$template fmt,"%inputname%\n"
+*.* :omstdout:;fmt
diff --git a/tools/syslogd.c b/tools/syslogd.c
index 3a751a30..dc5b8fee 100644
--- a/tools/syslogd.c
+++ b/tools/syslogd.c
@@ -137,6 +137,7 @@
#include "datetime.h"
#include "parser.h"
#include "sysvar.h"
+#include "unicode-helper.h"
/* definitions for objects we access */
DEFobjCurrIf(obj)
@@ -620,7 +621,7 @@ static inline rsRetVal printline(uchar *hname, uchar *hnameIP, uchar *msg, int f
CHKiRet(msgConstructWithTime(&pMsg, stTime, ttGenTime));
}
if(pszInputName != NULL)
- MsgSetInputName(pMsg, (char*) pszInputName);
+ MsgSetInputName(pMsg, pszInputName);
MsgSetFlowControlType(pMsg, flowCtlType);
MsgSetRawMsg(pMsg, (char*)msg);
@@ -649,8 +650,8 @@ static inline rsRetVal printline(uchar *hname, uchar *hnameIP, uchar *msg, int f
* being the local host). rgerhards 2004-11-16
*/
if((pMsg->msgFlags & PARSE_HOSTNAME) == 0)
- MsgSetHOSTNAME(pMsg, (char*)hname);
- MsgSetRcvFrom(pMsg, (char*)hname);
+ MsgSetHOSTNAME(pMsg, hname);
+ MsgSetRcvFrom(pMsg, hname);
CHKiRet(MsgSetRcvFromIP(pMsg, hnameIP));
/* rgerhards 2004-11-19: well, well... we've now seen that we
@@ -928,12 +929,12 @@ logmsgInternal(int iErr, int pri, uchar *msg, int flags)
DEFiRet;
CHKiRet(msgConstruct(&pMsg));
- MsgSetInputName(pMsg, "rsyslogd");
+ MsgSetInputName(pMsg, UCHAR_CONSTANT("rsyslogd"));
MsgSetUxTradMsg(pMsg, (char*)msg);
MsgSetRawMsg(pMsg, (char*)msg);
- MsgSetHOSTNAME(pMsg, (char*)glbl.GetLocalHostName());
- MsgSetRcvFrom(pMsg, (char*)glbl.GetLocalHostName());
- MsgSetRcvFromIP(pMsg, (uchar*)"127.0.0.1");
+ MsgSetHOSTNAME(pMsg, glbl.GetLocalHostName());
+ MsgSetRcvFrom(pMsg, glbl.GetLocalHostName());
+ MsgSetRcvFromIP(pMsg, UCHAR_CONSTANT("127.0.0.1"));
/* check if we have an error code associated and, if so,
* adjust the tag. -- r5gerhards, 2008-06-27
*/
@@ -1233,9 +1234,9 @@ msgConsumer(void __attribute__((unused)) *notNeeded, void *pUsr)
* SP-terminated or any other error occurs.
* rger, 2005-11-24
*/
-static int parseRFCField(char **pp2parse, char *pResult)
+static int parseRFCField(uchar **pp2parse, uchar *pResult)
{
- char *p2parse;
+ uchar *p2parse;
int iRet = 0;
assert(pp2parse != NULL);
@@ -1271,9 +1272,9 @@ static int parseRFCField(char **pp2parse, char *pResult)
* SP-terminated or any other error occurs.
* rger, 2005-11-24
*/
-static int parseRFCStructuredData(char **pp2parse, char *pResult)
+static int parseRFCStructuredData(uchar **pp2parse, uchar *pResult)
{
- char *p2parse;
+ uchar *p2parse;
int bCont = 1;
int iRet = 0;
@@ -1340,14 +1341,14 @@ static int parseRFCStructuredData(char **pp2parse, char *pResult)
*/
int parseRFCSyslogMsg(msg_t *pMsg, int flags)
{
- char *p2parse;
- char *pBuf;
+ uchar *p2parse;
+ uchar *pBuf;
int bContParse = 1;
BEGINfunc
assert(pMsg != NULL);
assert(pMsg->pszUxTradMsg != NULL);
- p2parse = (char*) pMsg->pszUxTradMsg;
+ p2parse = pMsg->pszUxTradMsg;
/* do a sanity check on the version and eat it */
assert(p2parse[0] == '1' && p2parse[1] == ' ');
@@ -1358,7 +1359,7 @@ int parseRFCSyslogMsg(msg_t *pMsg, int flags)
* message, so we can not run into any troubles. I think this is
* more wise then to use individual buffers.
*/
- if((pBuf = malloc(sizeof(char)* strlen(p2parse) + 1)) == NULL)
+ if((pBuf = malloc(sizeof(uchar) * ustrlen(p2parse) + 1)) == NULL)
return 1;
/* IMPORTANT NOTE:
@@ -1393,29 +1394,29 @@ int parseRFCSyslogMsg(msg_t *pMsg, int flags)
/* APP-NAME */
if(bContParse) {
parseRFCField(&p2parse, pBuf);
- MsgSetAPPNAME(pMsg, pBuf);
+ MsgSetAPPNAME(pMsg, (char*)pBuf);
}
/* PROCID */
if(bContParse) {
parseRFCField(&p2parse, pBuf);
- MsgSetPROCID(pMsg, pBuf);
+ MsgSetPROCID(pMsg, (char*)pBuf);
}
/* MSGID */
if(bContParse) {
parseRFCField(&p2parse, pBuf);
- MsgSetMSGID(pMsg, pBuf);
+ MsgSetMSGID(pMsg, (char*)pBuf);
}
/* STRUCTURED-DATA */
if(bContParse) {
parseRFCStructuredData(&p2parse, pBuf);
- MsgSetStructuredData(pMsg, pBuf);
+ MsgSetStructuredData(pMsg, (char*)pBuf);
}
/* MSG */
- MsgSetMSG(pMsg, p2parse);
+ MsgSetMSG(pMsg, (char*)p2parse);
free(pBuf);
ENDfunc
@@ -1438,7 +1439,7 @@ int parseRFCSyslogMsg(msg_t *pMsg, int flags)
*/
int parseLegacySyslogMsg(msg_t *pMsg, int flags)
{
- char *p2parse;
+ uchar *p2parse;
char *pBuf;
char *pWork;
cstr_t *pStrB;
@@ -1448,7 +1449,7 @@ int parseLegacySyslogMsg(msg_t *pMsg, int flags)
assert(pMsg != NULL);
assert(pMsg->pszUxTradMsg != NULL);
- p2parse = (char*) pMsg->pszUxTradMsg;
+ p2parse = pMsg->pszUxTradMsg;
/* Check to see if msg contains a timestamp. We start by assuming
* that the message timestamp is the time of reciption (which we
@@ -1503,7 +1504,7 @@ int parseLegacySyslogMsg(msg_t *pMsg, int flags)
/* the memory allocated is far too much in most cases. But on the plus side,
* it is quite fast... - rgerhards, 2007-09-20
*/
- if((pBuf = malloc(sizeof(char)* (strlen(p2parse) +1))) == NULL)
+ if((pBuf = malloc(sizeof(char)* (ustrlen(p2parse) +1))) == NULL)
return 1;
pWork = pBuf;
/* this is the actual parsing loop */
@@ -1609,7 +1610,7 @@ int parseLegacySyslogMsg(msg_t *pMsg, int flags)
}
/* The rest is the actual MSG */
- MsgSetMSG(pMsg, p2parse);
+ MsgSetMSG(pMsg, (char*)p2parse);
ENDfunc
return 0; /* all ok */
@@ -1919,10 +1920,10 @@ static void doDie(int sig)
# define MSG1 "DoDie called.\n"
# define MSG2 "DoDie called 5 times - unconditional exit\n"
static int iRetries = 0; /* debug aid */
- if(Debug || NoFork)
+ if(Debug)
write(1, MSG1, sizeof(MSG1) - 1);
if(iRetries++ == 4) {
- if(Debug || NoFork)
+ if(Debug)
write(1, MSG2, sizeof(MSG2) - 1);
abort();
}