summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2007-12-21 16:15:20 +0000
committerRainer Gerhards <rgerhards@adiscon.com>2007-12-21 16:15:20 +0000
commitfe6b6de3035b6bcea07f302ec0ef2895ac6f2285 (patch)
treea436b76a6f02453bb88c5ba6c3c5c1e2ffc56a6e
parent17a2d137b6134e02301eda68e6c1bfe94901e2d5 (diff)
downloadrsyslog-fe6b6de3035b6bcea07f302ec0ef2895ac6f2285.tar.gz
rsyslog-fe6b6de3035b6bcea07f302ec0ef2895ac6f2285.tar.xz
rsyslog-fe6b6de3035b6bcea07f302ec0ef2895ac6f2285.zip
- created an initial version of imudp.c. The majority of UDP reception code
is now in that module and it is dynamically loadable. HOWEVER, that doesn't mean it is a proper module. There are still many, many dependencies on global variables, cross-module calls and such. However, havin the code base separated allows me to carry out some other cleanup before I return to create a really clean implementation of these modules. So it is kind of a stage work. Just don't mistake it with "the real thing"...
-rw-r--r--plugins/imudp/imudp.c62
-rw-r--r--syslogd.c72
-rw-r--r--syslogd.h2
3 files changed, 65 insertions, 71 deletions
diff --git a/plugins/imudp/imudp.c b/plugins/imudp/imudp.c
index 7d739de4..ed18ddf1 100644
--- a/plugins/imudp/imudp.c
+++ b/plugins/imudp/imudp.c
@@ -31,6 +31,7 @@
#include <string.h>
#include <errno.h>
#include <unistd.h>
+#include <netdb.h>
#include "rsyslog.h"
#include "syslogd.h"
#include "cfsysline.h"
@@ -57,6 +58,12 @@ BEGINrunInput
int nfds;
int i;
fd_set readfds;
+ struct sockaddr_storage frominet;
+ socklen_t socklen;
+ uchar fromHost[NI_MAXHOST];
+ uchar fromHostFQDN[NI_MAXHOST];
+ char line[MAXLINE +1];
+ ssize_t l;
CODESTARTrunInput
/* this is an endless loop - it is terminated when the thread is
* signalled to do so. This, however, is handled by the framework,
@@ -72,8 +79,20 @@ CODESTARTrunInput
maxfds = 0;
FD_ZERO (&readfds);
+ /* Add the UDP listen sockets to the list of read descriptors.
+ */
+ if(finet != NULL && AcceptRemote) {
+ for (i = 0; i < *finet; i++) {
+ if (finet[i+1] != -1) {
+ if(Debug)
+ debugListenInfo(finet[i+1], "UDP");
+ FD_SET(finet[i+1], &readfds);
+ if(finet[i+1]>maxfds) maxfds=finet[i+1];
+ }
+ }
+ }
if(Debug) {
- dbgprintf("--------imTCP calling select, active file descriptors (max %d): ", maxfds);
+ dbgprintf("--------imUDP calling select, active file descriptors (max %d): ", maxfds);
for (nfds = 0; nfds <= maxfds; ++nfds)
if ( FD_ISSET(nfds, &readfds) )
dbgprintf("%d ", nfds);
@@ -82,6 +101,47 @@ CODESTARTrunInput
/* wait for io to become ready */
nfds = select(maxfds+1, (fd_set *) &readfds, NULL, NULL, NULL);
+
+ if (finet != NULL && AcceptRemote) {
+ for (i = 0; nfds && i < *finet; i++) {
+ if (FD_ISSET(finet[i+1], &readfds)) {
+ socklen = sizeof(frominet);
+ memset(line, 0xff, sizeof(line)); // TODO: I think we need this for debug only - remove after bug hunt
+ l = recvfrom(finet[i+1], line, MAXLINE - 1, 0,
+ (struct sockaddr *)&frominet, &socklen);
+ if (l > 0) {
+ if(cvthname(&frominet, fromHost, fromHostFQDN) == RS_RET_OK) {
+ dbgprintf("Message from inetd socket: #%d, host: %s\n",
+ finet[i+1], fromHost);
+ /* Here we check if a host is permitted to send us
+ * syslog messages. If it isn't, we do not further
+ * process the message but log a warning (if we are
+ * configured to do this).
+ * rgerhards, 2005-09-26
+ */
+ if(isAllowedSender(pAllowedSenders_UDP,
+ (struct sockaddr *)&frominet, (char*)fromHostFQDN)) {
+ printchopped((char*)fromHost, line, l, finet[i+1], 1);
+ } else {
+ dbgprintf("%s is not an allowed sender\n", (char*)fromHostFQDN);
+ if(option_DisallowWarning) {
+ logerrorSz("UDP message from disallowed sender %s discarded",
+ (char*)fromHost);
+ }
+ }
+ }
+ } else if (l < 0 && errno != EINTR && errno != EAGAIN) {
+ char errStr[1024];
+ strerror_r(errno, errStr, sizeof(errStr));
+ dbgprintf("INET socket error: %d = %s.\n", errno, errStr);
+ logerror("recvfrom inet");
+ /* should be harmless */
+ sleep(1);
+ }
+ --nfds; /* indicate we have processed one */
+ }
+ }
+ }
}
return iRet;
diff --git a/syslogd.c b/syslogd.c
index a6fc28bb..317a5d6c 100644
--- a/syslogd.c
+++ b/syslogd.c
@@ -193,9 +193,7 @@
#include <arpa/inet.h>
#include <resolv.h>
#include "pidfile.h"
-
#include <assert.h>
-
#include <pthread.h>
#if HAVE_PATHS_H
@@ -464,7 +462,7 @@ static int MarkInterval = 20 * 60; /* interval between marks in seconds - read-o
int family = PF_UNSPEC; /* protocol family (IPv4, IPv6 or both), set via cmdline */
int send_to_all = 0; /* send message to all IPv4/IPv6 addresses */
static int NoFork = 0; /* don't fork - don't run in daemon mode - read-only after startup */
-static int AcceptRemote = 0;/* receive messages that come via UDP - read-only after startup */
+int AcceptRemote = 0;/* receive messages that come via UDP - read-only after startup */
int ACLAddHostnameOnFail = 0; /* add hostname to acl when DNS resolving has failed */
int ACLDontResolve = 0; /* add hostname to acl instead of resolving it to IP(s) */
int DisableDNS = 0; /* don't look up IP addresses of remote messages */
@@ -590,7 +588,7 @@ static rsRetVal resetConfigVariables(uchar __attribute__((unused)) *pp, void __a
*/
#ifdef SYSLOG_INET
/* All of the five below are read-only after startup */
-static struct AllowedSenders *pAllowedSenders_UDP = NULL; /* the roots of the allowed sender */
+struct AllowedSenders *pAllowedSenders_UDP = NULL; /* the roots of the allowed sender */
struct AllowedSenders *pAllowedSenders_TCP = NULL; /* lists. If NULL, all senders are ok! */
static struct AllowedSenders *pLastAllowedSenders_UDP = NULL; /* and now the pointers to the last */
static struct AllowedSenders *pLastAllowedSenders_TCP = NULL; /* element in the respective list */
@@ -5378,14 +5376,6 @@ static rsRetVal processSelectAfter(int maxfds, int nfds, fd_set *pReadfds)
{
DEFiRet;
int i;
- char line[MAXLINE +1];
-#ifdef SYSLOG_INET
- struct sockaddr_storage frominet;
- socklen_t socklen;
- uchar fromHost[NI_MAXHOST];
- uchar fromHostFQDN[NI_MAXHOST];
- ssize_t l;
-#endif /* #ifdef SYSLOG_INET */
/* the following macro is used to decrement the number of to-be-probed
* fds and abort this function when we are done with all.
@@ -5406,49 +5396,6 @@ static rsRetVal processSelectAfter(int maxfds, int nfds, fd_set *pReadfds)
dbgprintf("%d ", i);
dbgprintf(("\n"));
}
-
-#ifdef SYSLOG_INET
- if (finet != NULL && AcceptRemote) {
- for (i = 0; i < *finet; i++) {
- if (FD_ISSET(finet[i+1], pReadfds)) {
- socklen = sizeof(frominet);
- memset(line, 0xff, sizeof(line)); // TODO: I think we need this for debug only - remove after bug hunt
- l = recvfrom(finet[i+1], line, MAXLINE - 1, 0,
- (struct sockaddr *)&frominet, &socklen);
- if (l > 0) {
- if(cvthname(&frominet, fromHost, fromHostFQDN) == RS_RET_OK) {
- dbgprintf("Message from inetd socket: #%d, host: %s\n",
- finet[i+1], fromHost);
- /* Here we check if a host is permitted to send us
- * syslog messages. If it isn't, we do not further
- * process the message but log a warning (if we are
- * configured to do this).
- * rgerhards, 2005-09-26
- */
- if(isAllowedSender(pAllowedSenders_UDP,
- (struct sockaddr *)&frominet, (char*)fromHostFQDN)) {
- printchopped((char*)fromHost, line, l, finet[i+1], 1);
- } else {
- dbgprintf("%s is not an allowed sender\n", (char*)fromHostFQDN);
- if(option_DisallowWarning) {
- logerrorSz("UDP message from disallowed sender %s discarded",
- (char*)fromHost);
- }
- }
- }
- } else if (l < 0 && errno != EINTR && errno != EAGAIN) {
- char errStr[1024];
- strerror_r(errno, errStr, sizeof(errStr));
- dbgprintf("INET socket error: %d = %s.\n", errno, errStr);
- logerror("recvfrom inet");
- /* should be harmless */
- sleep(1);
- }
- FDPROCESSED();
- }
- }
- }
-#endif
finalize_it:
return iRet;
}
@@ -5472,21 +5419,6 @@ static void mainloop(void)
/* first check if we have any internal messages queued and spit them out */
processImInternal();
-#ifdef SYSLOG_INET
- /* Add the UDP listen sockets to the list of read descriptors.
- */
- if(finet != NULL && AcceptRemote) {
- for (i = 0; i < *finet; i++) {
- if (finet[i+1] != -1) {
- if(Debug)
- debugListenInfo(finet[i+1], "UDP");
- FD_SET(finet[i+1], &readfds);
- if(finet[i+1]>maxfds) maxfds=finet[i+1];
- }
- }
- }
-#endif
-
if ( debugging_on ) {
dbgprintf("----------------------------------------\n");
dbgprintf("Calling select, active file descriptors (max %d): ", maxfds);
diff --git a/syslogd.h b/syslogd.h
index aa4331e9..cf2cd0a5 100644
--- a/syslogd.h
+++ b/syslogd.h
@@ -72,6 +72,7 @@ void logmsgInternal(int pri, char *msg, int flags);
void logmsg(int pri, msg_t *pMsg, int flags);
void debugListenInfo(int fd, char *type);
extern int bFinished; /* used by termination signal handler, read-only except there */
+extern int AcceptRemote; /* receive messages that come via UDP - read-only after startup */
extern int glblHadMemShortage; /* indicates if we had memory shortage some time during the run */
extern char LocalHostName[];
@@ -86,6 +87,7 @@ extern int DisableDNS;
extern char **StripDomains;
extern char *LocalDomain;
extern int bDropMalPTRMsgs;
+extern struct AllowedSenders *pAllowedSenders_UDP;
extern struct AllowedSenders *pAllowedSenders_TCP;
extern struct AllowedSenders *pAllowedSenders_GSS;
extern char ctty[];