summaryrefslogtreecommitdiffstats
path: root/plugins/imudp/imudp.c
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 /plugins/imudp/imudp.c
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"...
Diffstat (limited to 'plugins/imudp/imudp.c')
-rw-r--r--plugins/imudp/imudp.c62
1 files changed, 61 insertions, 1 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;