imtcp bugfix: multiple listnerPortFile parameter did not work

... because they were treated as module-global. If we had multiple imtcp
listeners with multiple port files, only the last filename was always used.

closes https://github.com/rsyslog/rsyslog/issues/3817
This commit is contained in:
Rainer Gerhards 2019-08-14 14:39:55 +02:00
parent 628631cd10
commit ff4887280e
4 changed files with 18 additions and 10 deletions

View File

@ -587,7 +587,7 @@ static rsRetVal addTCPListener(void __attribute__((unused)) *pVal, uchar *pNewVa
UCHAR_CONSTANT("imdiag") : pszInputName));
CHKiRet(tcpsrv.SetOrigin(pOurTcpsrv, (uchar*)"imdiag"));
/* we support octect-counted frame (constant 1 below) */
tcpsrv.configureTCPListen(pOurTcpsrv, pNewVal, 1, NULL);
tcpsrv.configureTCPListen(pOurTcpsrv, pNewVal, 1, NULL, pszLstnPortFileName);
finalize_it:
if(iRet != RS_RET_OK) {

View File

@ -400,12 +400,12 @@ addListner(modConfData_t *modConf, instanceConf_t *inst)
CHKiRet(tcpsrv.SetbSPFramingFix(pOurTcpsrv, inst->bSPFramingFix));
CHKiRet(tcpsrv.SetLinuxLikeRatelimiters(pOurTcpsrv, inst->ratelimitInterval, inst->ratelimitBurst));
CHKiRet(tcpsrv.SetLstnPortFileName(pOurTcpsrv, inst->pszLstnPortFileName));
if((ustrcmp(inst->pszBindPort, UCHAR_CONSTANT("0")) == 0 && inst->pszLstnPortFileName == NULL)
|| ustrcmp(inst->pszBindPort, UCHAR_CONSTANT("0")) < 0) {
CHKmalloc(inst->pszBindPort = (uchar*)strdup("514"));
}
tcpsrv.configureTCPListen(pOurTcpsrv, inst->pszBindPort, inst->bSuppOctetFram, inst->pszBindAddr);
tcpsrv.configureTCPListen(pOurTcpsrv, inst->pszBindPort, inst->bSuppOctetFram,
inst->pszBindAddr, inst->pszLstnPortFileName);
finalize_it:
if(iRet != RS_RET_OK) {

View File

@ -124,7 +124,8 @@ static int wrkrRunning;
*/
static rsRetVal ATTR_NONNULL(1, 2)
addNewLstnPort(tcpsrv_t *const pThis, const uchar *const pszPort,
const int bSuppOctetFram, const uchar *const pszAddr)
const int bSuppOctetFram, const uchar *const pszAddr,
const uchar *const pszLstnPortFileName)
{
tcpLstnPortList_t *pEntry;
uchar statname[64];
@ -147,6 +148,7 @@ addNewLstnPort(tcpsrv_t *const pThis, const uchar *const pszPort,
pEntry->pSrv = pThis;
pEntry->pRuleset = pThis->pRuleset;
pEntry->bSuppOctetFram = bSuppOctetFram;
pEntry->pszLstnPortFileName = pszLstnPortFileName;
/* we need to create a property */
CHKiRet(prop.Construct(&pEntry->pInputName));
@ -198,11 +200,15 @@ finalize_it:
* Note: pszPort is handed over to us - the caller MUST NOT free it!
* rgerhards, 2008-03-20
*/
static rsRetVal
configureTCPListen(tcpsrv_t *pThis, uchar *pszPort, int bSuppOctetFram, uchar *pszAddr)
static rsRetVal ATTR_NONNULL(1,2)
configureTCPListen(tcpsrv_t *const pThis,
const uchar *const pszPort,
const int bSuppOctetFram,
const uchar *const pszAddr,
const uchar *const pszLstnPortFileName)
{
int i;
uchar *pPort = pszPort;
const uchar *pPort = pszPort;
DEFiRet;
assert(pszPort != NULL);
@ -215,7 +221,7 @@ configureTCPListen(tcpsrv_t *pThis, uchar *pszPort, int bSuppOctetFram, uchar *p
}
if(i >= 0 && i <= 65535) {
CHKiRet(addNewLstnPort(pThis, pszPort, bSuppOctetFram, pszAddr));
CHKiRet(addNewLstnPort(pThis, pszPort, bSuppOctetFram, pszAddr, pszLstnPortFileName));
} else {
LogError(0, NO_ERRCODE, "Invalid TCP listen port %s - ignored.\n", pszPort);
}
@ -382,7 +388,7 @@ initTCPListener(tcpsrv_t *pThis, tcpLstnPortList_t *pPortEntry)
// pPortEntry->pszAddr = NULL ==> bind to all interfaces
CHKiRet(netstrm.LstnInit(pThis->pNS, (void*)pPortEntry, addTcpLstn, TCPLstnPort,
pPortEntry->pszAddr, pThis->iSessMax, pThis->pszLstnPortFileName));
pPortEntry->pszAddr, pThis->iSessMax, (uchar*)pPortEntry->pszLstnPortFileName));
finalize_it:
RETiRet;

View File

@ -46,6 +46,7 @@ struct tcpLstnPortList_s {
ratelimit_t *ratelimiter;
uchar dfltTZ[8]; /**< default TZ if none in timestamp; '\0' =No Default */
sbool bSPFramingFix; /**< support work-around for broken Cisco ASA framing? */
const uchar *pszLstnPortFileName; /**< File in which the dynamic port is written */
STATSCOUNTER_DEF(ctrSubmit, mutCtrSubmit)
tcpLstnPortList_t *pNext; /**< next port or NULL */
};
@ -126,7 +127,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);
rsRetVal (*configureTCPListen)(tcpsrv_t*, uchar *pszPort, int bSuppOctetFram, uchar *pszAddr);
rsRetVal (*ATTR_NONNULL(1,2) configureTCPListen)(tcpsrv_t*,
const uchar *pszPort, int bSuppOctetFram, const uchar *pszAddr, const uchar *);
rsRetVal (*create_tcp_socket)(tcpsrv_t *pThis);
rsRetVal (*Run)(tcpsrv_t *pThis);
/* set methods */