--- ./sysklogd/syslogd.c.orig 2006-03-07 20:19:12.000000000 +0100 +++ ./sysklogd/syslogd.c 2006-03-07 21:55:28.000000000 +0100 @@ -91,6 +91,20 @@ static int local_logging = FALSE; #endif +#ifdef CONFIG_FEATURE_SYSLOG_LISTEN_UDP +/* udp socket for receiving local UDP messages */ +static int listen_udp_fd = -1; +static struct sockaddr_in listen_udp_addr; + +/* where are we listening to? */ +static char *ListenHost; + +/* what port are we listening to? */ +static int ListenPort = 514; +static int doListenUDP = FALSE; +#endif + + /* Make loging output smaller. */ static bool small = false; @@ -394,6 +408,22 @@ } #endif +#ifdef CONFIG_FEATURE_SYSLOG_LISTEN_UDP +static void init_LocalLog(void) +{ + memset(&listen_udp_addr, 0, sizeof(listen_udp_addr)); + listen_udp_fd = socket(AF_INET, SOCK_DGRAM, 0); + + if (listen_udp_fd < 0) { + bb_error_msg("cannot create socket"); + } + + listen_udp_addr.sin_family = AF_INET; + listen_udp_addr.sin_addr = *(struct in_addr *) *(xgethostbyname(ListenHost))->h_addr_list; + listen_udp_addr.sin_port = htons(ListenPort); +} +#endif + static void logMessage(int pri, char *msg) { time_t now; @@ -569,6 +599,18 @@ if (chmod(lfile, 0666) < 0) { bb_perror_msg_and_die("Could not set permission on " _PATH_LOG); } + +#ifdef CONFIG_FEATURE_SYSLOG_LISTEN_UDP + if (doListenUDP) { + init_LocalLog(); + + if (bind(listen_udp_fd, (struct sockaddr *) &listen_udp_addr, + sizeof(listen_udp_addr)) < 0) { + bb_perror_msg_and_die("Could not bind to local UDP socket"); + } + } +#endif + #ifdef CONFIG_FEATURE_IPC_SYSLOG if (circular_logging == TRUE) { ipcsyslog_init(); @@ -584,11 +626,18 @@ logMessage(LOG_SYSLOG | LOG_INFO, "syslogd started: " BB_BANNER); for (;;) { - + int nbfd; FD_ZERO(&fds); FD_SET(sock_fd, &fds); - - if (select(sock_fd + 1, &fds, NULL, NULL, NULL) < 0) { + nbfd = sock_fd + 1; +#ifdef CONFIG_FEATURE_SYSLOG_LISTEN_UDP + if (doListenUDP) { + FD_SET(listen_udp_fd, &fds); + if (listen_udp_fd >= nbfd) + nbfd = listen_udp_fd + 1; + } +#endif + if (select(nbfd, &fds, NULL, NULL, NULL) < 0) { if (errno == EINTR) { /* alarm may have happened. */ continue; @@ -596,8 +645,6 @@ bb_perror_msg_and_die("select error"); } - if (FD_ISSET(sock_fd, &fds)) { - int i; #if MAXLINE > BUFSIZ # define TMP_BUF_SZ BUFSIZ #else @@ -605,6 +652,9 @@ #endif #define tmpbuf bb_common_bufsiz1 + if (FD_ISSET(sock_fd, &fds)) { + int i; + if ((i = recv(sock_fd, tmpbuf, TMP_BUF_SZ, 0)) > 0) { tmpbuf[i] = '\0'; serveConnection(tmpbuf, i); @@ -612,6 +662,17 @@ bb_perror_msg_and_die("UNIX socket error"); } } /* FD_ISSET() */ + +#ifdef CONFIG_FEATURE_SYSLOG_LISTEN_UDP + if (doListenUDP && FD_ISSET(listen_udp_fd, &fds)) { + int i; + + if ((i = recv(listen_udp_fd, tmpbuf, TMP_BUF_SZ, 0)) > 0) { + tmpbuf[i] = '\0'; + serveConnection(tmpbuf, i); + } + } /* FD_ISSET() */ +#endif /* SYSLOG_LISTEN_UDP */ } /* for main loop */ } @@ -624,7 +685,7 @@ char *p; /* do normal option parsing */ - while ((opt = getopt(argc, argv, "m:nO:s:Sb:R:LC::")) > 0) { + while ((opt = getopt(argc, argv, "m:nO:s:Sb:R:Ll:C::")) > 0) { switch (opt) { case 'm': MarkInterval = atoi(optarg) * 60; @@ -657,6 +718,16 @@ local_logging = TRUE; break; #endif +#ifdef CONFIG_FEATURE_SYSLOG_LISTEN_UDP + case 'l': + ListenHost = bb_xstrdup(optarg); + if ((p = strchr(ListenHost, ':'))) { + ListenPort = atoi(p + 1); + *p = '\0'; + } + doListenUDP = TRUE; + break; +#endif #ifdef CONFIG_FEATURE_IPC_SYSLOG case 'C': if (optarg) { --- ./sysklogd/Config.in.orig 2006-03-07 20:37:28.000000000 +0100 +++ ./sysklogd/Config.in 2006-03-07 20:40:32.000000000 +0100 @@ -42,6 +42,17 @@ measure to prevent system logs from being tampered with by an intruder. +config CONFIG_FEATURE_SYSLOG_LISTEN_UDP + bool " Listen to UDP socket" + default n + depends on CONFIG_SYSLOGD + help + When you enable this feature, the syslogd utility will + be able to listen to a local UDP socket, which will + make it reachable by tools which can only log to network. + The real goal is not to provide a big local syslog server, + but to use it as a centralized repeater. + config CONFIG_FEATURE_IPC_SYSLOG bool " Circular Buffer support" default n --- ./include/usage.h.orig 2006-03-07 20:53:55.000000000 +0100 +++ ./include/usage.h 2006-03-07 20:56:22.000000000 +0100 @@ -2864,6 +2864,11 @@ #else # define USAGE_REMOTE_LOG(a) #endif +#ifdef CONFIG_FEATURE_SYSLOG_LISTEN_UDP +# define USAGE_SYSLOG_LISTEN_UDP(a) a +#else +# define USAGE_SYSLOG_LISTEN_UDP(a) +#endif #ifdef CONFIG_FEATURE_IPC_SYSLOG # define USAGE_IPC_LOG(a) a #else @@ -2903,6 +2908,8 @@ USAGE_REMOTE_LOG( \ "\n\t-R HOST[:PORT]\tLog to IP or hostname on PORT (default PORT=514/UDP)\n" \ "\t-L\t\tLog locally and via network logging (default is network only)") \ + USAGE_SYSLOG_LISTEN_UDP( \ + "\n\t-l HOST[:PORT]\tAccept UDP packets on this local IP or hostname on PORT (default PORT=514/UDP)\n") \ USAGE_IPC_LOG( \ "\n\t-C [size(KiB)]\tLog to a circular buffer (read the buffer using logread)") #define syslogd_example_usage \