summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2012-06-01 16:11:11 +0200
committerRainer Gerhards <rgerhards@adiscon.com>2012-06-01 16:11:11 +0200
commit56fc7acc06ad9b22f88566c1e9dc5ed4f203de45 (patch)
tree9726d5647bdcfc2fd80bc48e8a12b69d02abeb59 /plugins
parent68f7a7bfd21a63c6b3f753341ac48a8873a260a7 (diff)
parent9020647cdcdb0ef132491838e36c870f4e4e90ea (diff)
downloadrsyslog-56fc7acc06ad9b22f88566c1e9dc5ed4f203de45.tar.gz
rsyslog-56fc7acc06ad9b22f88566c1e9dc5ed4f203de45.tar.xz
rsyslog-56fc7acc06ad9b22f88566c1e9dc5ed4f203de45.zip
Merge branch 'v5-stable' into v6-stable
Diffstat (limited to 'plugins')
-rw-r--r--plugins/omudpspoof/omudpspoof.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/plugins/omudpspoof/omudpspoof.c b/plugins/omudpspoof/omudpspoof.c
index fd4551c9..35ce2a9f 100644
--- a/plugins/omudpspoof/omudpspoof.c
+++ b/plugins/omudpspoof/omudpspoof.c
@@ -132,6 +132,7 @@ ENDinitConfVars
/* add some variables needed for libnet */
libnet_t *libnet_handle;
char errbuf[LIBNET_ERRBUF_SIZE];
+pthread_mutex_t mutLibnet;
/* forward definitions */
static rsRetVal doTryResume(instanceData *pData);
@@ -194,6 +195,8 @@ ENDdbgPrintInstInfo
/* Send a message via UDP
+ * Note: libnet is not thread-safe, so we need to ensure that only one
+ * instance ever is calling libnet code.
* rgehards, 2007-12-20
*/
static inline rsRetVal
@@ -207,6 +210,7 @@ UDPSend(instanceData *pData, uchar *pszSourcename, char *msg, size_t len)
struct sockaddr_in *tempaddr,source_ip;
libnet_ptag_t ip, ipo;
libnet_ptag_t udp;
+ sbool bNeedUnlock = 0;
DEFiRet;
if(pData->pSockArray == NULL) {
@@ -221,6 +225,8 @@ UDPSend(instanceData *pData, uchar *pszSourcename, char *msg, size_t len)
inet_pton(AF_INET, (char*)pszSourcename, &(source_ip.sin_addr));
bSendSuccess = FALSE;
+ d_pthread_mutex_lock(&mutLibnet);
+ bNeedUnlock = 1;
for (r = pData->f_addr; r; r = r->ai_next) {
tempaddr = (struct sockaddr_in *)r->ai_addr;
libnet_clear_packet(libnet_handle);
@@ -281,6 +287,9 @@ UDPSend(instanceData *pData, uchar *pszSourcename, char *msg, size_t len)
}
finalize_it:
+ if(bNeedUnlock) {
+ d_pthread_mutex_unlock(&mutLibnet);
+ }
RETiRet;
}
@@ -454,6 +463,7 @@ BEGINmodExit
CODESTARTmodExit
/* destroy the libnet state needed for forged UDP sources */
libnet_destroy(libnet_handle);
+ pthread_mutex_destroy(&mutLibnet);
/* release what we no longer need */
objRelease(errmsg, CORE_COMPONENT);
objRelease(glbl, CORE_COMPONENT);
@@ -503,6 +513,7 @@ CODEmodInit_QueryRegCFSLineHdlr
errmsg.LogError(0, NO_ERRCODE, "Error initializing libnet, can not continue ");
ABORT_FINALIZE(RS_RET_ERR_LIBNET_INIT);
}
+ pthread_mutex_init(&mutLibnet, NULL);
CHKiRet(regCfSysLineHdlr((uchar *)"actionomudpspoofdefaulttemplate", 0, eCmdHdlrGetWord, NULL, &cs.pszTplName, NULL));
CHKiRet(regCfSysLineHdlr((uchar *)"actionomudpspoofsourcenametemplate", 0, eCmdHdlrGetWord, NULL, &cs.pszSourceNameTemplate, NULL));