summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2012-03-10 18:29:40 +0100
committerRainer Gerhards <rgerhards@adiscon.com>2012-03-10 18:29:40 +0100
commit50a94aa1c72ba8aab5443ecc04b51190da0df513 (patch)
tree91cf4bf30f8419195d9c2a66cafa462124a76038
parent68301c98db00dc1b6bc7e09c5f5e47286a16ab95 (diff)
downloadrsyslog-50a94aa1c72ba8aab5443ecc04b51190da0df513.tar.gz
rsyslog-50a94aa1c72ba8aab5443ecc04b51190da0df513.tar.xz
rsyslog-50a94aa1c72ba8aab5443ecc04b51190da0df513.zip
added capability to use a local interface IP address as fromhost-ip for imklog
-rw-r--r--ChangeLog4
-rw-r--r--doc/imklog.html5
-rw-r--r--doc/imuxsock.html2
-rw-r--r--plugins/imklog/imklog.c27
4 files changed, 34 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index 78f74695..9fb59495 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,6 @@
- added capability to use a local interface IP address as fromhost-ip for
- imuxsock
- new config directives: $IMUXSockLocalIPIF
+ imuxsock imklog
+ new config directives: $IMUXSockLocalIPIF, $klogLocalIPIF
- added configuration directives to customize queue light delay marks
$MainMsgQueueLightDelayMark, $ActionQueueLightDelayMark; both
specify number of messages starting at which a delay happens.
diff --git a/doc/imklog.html b/doc/imklog.html
index f273753f..2e3b3bc2 100644
--- a/doc/imklog.html
+++ b/doc/imklog.html
@@ -36,6 +36,11 @@ processing.<span style="font-weight: bold;"></span></li>
<li><span style="font-weight: bold;"></span>$DebugPrintKernelSymbols
[on/<b>off</b>]<br>
Linux only, ignored on other platforms (but may be specified)</li>
+<li><b>$klogLocalIPIF</b> [interface name] - (available since 5.9.6) - if provided, the IP of the specified
+interface (e.g. "eth0") shall be used as fromhost-ip for imklog-originating messages.
+If this directive is not given OR the interface cannot be found (or has no IP address),
+the default of "127.0.0.1" is used.
+</li>
<li>$klogSymbolLookup [on/<b>off</b>] --
disables imklog kernel symbol translation (former klogd -x option). NOTE that
this option is counter-productive on recent kernels (>= 2.6) because the
diff --git a/doc/imuxsock.html b/doc/imuxsock.html
index 1b79dd0d..f54b5564 100644
--- a/doc/imuxsock.html
+++ b/doc/imuxsock.html
@@ -64,7 +64,7 @@ burst in number of messages. Default is 200.
<li><b>$IMUXSockRateLimitSeverity</b> [numerical severity] - specifies the severity of
messages that shall be rate-limited.
</li>
-<li><b>$IMUXSockLocalIPIF</b> [interface name] - if provided, the IP of the specified
+<li><b>$IMUXSockLocalIPIF</b> [interface name] - (available since 5.9.6) - if provided, the IP of the specified
interface (e.g. "eth0") shall be used as fromhost-ip for imuxsock-originating messages.
If this directive is not given OR the interface cannot be found (or has no IP address),
the default of "127.0.0.1" is used.
diff --git a/plugins/imklog/imklog.c b/plugins/imklog/imklog.c
index 16adbc21..66d7d143 100644
--- a/plugins/imklog/imklog.c
+++ b/plugins/imklog/imklog.c
@@ -44,6 +44,7 @@
#include <stdarg.h>
#include <ctype.h>
#include <stdlib.h>
+#include <sys/socket.h>
#include "dirty.h"
#include "cfsysline.h"
@@ -52,6 +53,7 @@
#include "module-template.h"
#include "datetime.h"
#include "imklog.h"
+#include "net.h"
#include "glbl.h"
#include "prop.h"
#include "unicode-helper.h"
@@ -64,6 +66,7 @@ DEF_IMOD_STATIC_DATA
DEFobjCurrIf(datetime)
DEFobjCurrIf(glbl)
DEFobjCurrIf(prop)
+DEFobjCurrIf(net)
/* configuration settings */
int dbgPrintSymbols = 0; /* this one is extern so the helpers can access it! */
@@ -71,6 +74,7 @@ int symbols_twice = 0;
int use_syscall = 0;
int symbol_lookup = 0; /* on recent kernels > 2.6, the kernel does this */
int bPermitNonKernel = 0; /* permit logging of messages not having LOG_KERN facility */
+static uchar *pLocalIPIF = NULL;
int iFacilIntMsg; /* the facility to use for internal messages (set by driver) */
uchar *pszPath = NULL;
int console_log_level = -1;
@@ -233,10 +237,22 @@ ENDrunInput
BEGINwillRun
+ uchar myIP[128];
+ rsRetVal localRet;
CODESTARTwillRun
/* we need to create the inputName property (only once during our lifetime) */
CHKiRet(prop.CreateStringProp(&pInputName, UCHAR_CONSTANT("imklog"), sizeof("imklog") - 1));
- CHKiRet(prop.CreateStringProp(&pLocalHostIP, UCHAR_CONSTANT("127.0.0.1"), sizeof("127.0.0.1") - 1));
+ if(pLocalIPIF == NULL) {
+ strcpy((char*)myIP, "127.0.0.1");
+ } else {
+ localRet = net.GetIFIPAddr(pLocalIPIF, AF_UNSPEC, myIP, (int) sizeof(myIP));
+ if(localRet != RS_RET_OK) {
+ DBGPRINTF("imuxsock: could not obtain my IP, using 127.0.0.1 instead\n");
+ strcpy((char*)myIP, "127.0.0.1");
+ }
+ }
+ DBGPRINTF("imklog: using '%s' as localhost IP\n", myIP);
+ CHKiRet(prop.CreateStringProp(&pLocalHostIP, myIP, ustrlen(myIP)));
iRet = klogWillRun();
finalize_it:
@@ -251,6 +267,7 @@ CODESTARTafterRun
prop.Destruct(&pInputName);
if(pLocalHostIP != NULL)
prop.Destruct(&pLocalHostIP);
+ free(pLocalIPIF);
ENDafterRun
@@ -258,6 +275,7 @@ BEGINmodExit
CODESTARTmodExit
/* release objects we used */
objRelease(glbl, CORE_COMPONENT);
+ objRelease(net, CORE_COMPONENT);
objRelease(datetime, CORE_COMPONENT);
objRelease(prop, CORE_COMPONENT);
if(pszPath != NULL)
@@ -282,6 +300,10 @@ static rsRetVal resetConfigVariables(uchar __attribute__((unused)) *pp, void __a
free(pszPath);
pszPath = NULL;
}
+ if(pLocalIPIF != NULL) {
+ free(pLocalIPIF);
+ pLocalIPIF = NULL;
+ }
iFacilIntMsg = klogFacilIntMsg();
return RS_RET_OK;
}
@@ -293,6 +315,7 @@ CODEmodInit_QueryRegCFSLineHdlr
CHKiRet(objUse(datetime, CORE_COMPONENT));
CHKiRet(objUse(glbl, CORE_COMPONENT));
CHKiRet(objUse(prop, CORE_COMPONENT));
+ CHKiRet(objUse(net, CORE_COMPONENT));
iFacilIntMsg = klogFacilIntMsg();
@@ -304,6 +327,8 @@ CODEmodInit_QueryRegCFSLineHdlr
CHKiRet(omsdRegCFSLineHdlr((uchar *)"klogpermitnonkernelfacility", 0, eCmdHdlrBinary, NULL, &bPermitNonKernel, STD_LOADABLE_MODULE_ID));
CHKiRet(omsdRegCFSLineHdlr((uchar *)"klogconsoleloglevel", 0, eCmdHdlrInt, NULL, &console_log_level, STD_LOADABLE_MODULE_ID));
CHKiRet(omsdRegCFSLineHdlr((uchar *)"kloginternalmsgfacility", 0, eCmdHdlrFacility, NULL, &iFacilIntMsg, STD_LOADABLE_MODULE_ID));
+ CHKiRet(omsdRegCFSLineHdlr((uchar *)"kloglocalipif", 0, eCmdHdlrGetWord,
+ NULL, &pLocalIPIF, STD_LOADABLE_MODULE_ID));
CHKiRet(omsdRegCFSLineHdlr((uchar *)"resetconfigvariables", 1, eCmdHdlrCustomHandler, resetConfigVariables, NULL, STD_LOADABLE_MODULE_ID));
ENDmodInit
/* vim:set ai: