summaryrefslogtreecommitdiffstats
path: root/plugins/omudpspoof
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2012-05-29 11:36:13 +0200
committerRainer Gerhards <rgerhards@adiscon.com>2012-05-29 11:36:13 +0200
commit6bc629021eb008e1d48627bdac70b1c8b237937b (patch)
treeba46a74eeb318ea266061bdbcd382f9752453931 /plugins/omudpspoof
parent5fa3c34a1fe0144a2d8cb74cb82a73d8c61d435d (diff)
parentf4ec11fa779e7348f68ece1b3b50d499a0526ace (diff)
downloadrsyslog-6bc629021eb008e1d48627bdac70b1c8b237937b.tar.gz
rsyslog-6bc629021eb008e1d48627bdac70b1c8b237937b.tar.xz
rsyslog-6bc629021eb008e1d48627bdac70b1c8b237937b.zip
Merge branch 'v5-beta' into beta
Conflicts: ChangeLog
Diffstat (limited to 'plugins/omudpspoof')
-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 9a469c16..fadb2c7b 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);
@@ -280,6 +286,9 @@ UDPSend(instanceData *pData, uchar *pszSourcename, char *msg, size_t len)
}
finalize_it:
+ if(bNeedUnlock) {
+ d_pthread_mutex_unlock(&mutLibnet);
+ }
RETiRet;
}
@@ -453,6 +462,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);
@@ -502,6 +512,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));