From 90497af7bb97ebb000d0edd2f47512a7c2f62265 Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Mon, 18 Jul 2016 09:48:59 +0200 Subject: [PATCH] Add optional support for RFC863, Discard Protocol Signed-off-by: Joachim Nilsson --- README.md | 25 +++++++++++++---- configure.ac | 17 ++++++------ plugins/Makefile.am | 8 ++++++ plugins/discard.c | 67 +++++++++++++++++++++++++++++++++++++++++++++ plugins/echo.c | 6 ++-- plugins/time.c | 6 ++-- 6 files changed, 109 insertions(+), 20 deletions(-) create mode 100644 plugins/discard.c diff --git a/README.md b/README.md index c03dccf3..28d6f1af 100644 --- a/README.md +++ b/README.md @@ -73,8 +73,9 @@ interface, reducing the need for a full blown firewall. Built-in optional inetd services: -- time (rdate) RFC862 -- echo RFC868 +- echo RFC862 +- discard RFC863 +- time (rdate) RFC868 **Runlevels** @@ -484,10 +485,11 @@ The original `inetd` had a few standard services built-in: - chargen - discard -Finit currently supports the `time` and `echo` services. Both of which -are realized as plugins to provide a simple means of testing the inetd -functionality stand-alone. But this also provides both a useful network -testing/availability and a rudimentary time server for rdate clients. +Finit currently supports the `time`, `echo`, and `discard` services. +Both of which are realized as plugins to provide a simple means of +testing the inetd functionality stand-alone. But this also provides +both a useful network testing/availability and a rudimentary time server +for rdate clients. Internal inetd services are set up as follows: @@ -496,6 +498,8 @@ Internal inetd services are set up as follows: inetd time/tcp nowait [2345] internal inetd echo/udp wait [2345] internal inetd echo/tcp nowait [2345] internal + inetd discard/udp wait [2345] internal + inetd discard/tcp nowait [2345] internal ``` Then call `rdate` from a remote machine (or use localhost): @@ -512,6 +516,13 @@ Or `echoping` to reach the echo service: echoping -uv ``` +Or `echoping -d` to reach the discard service: + +```shell + echoping -dv + echoping -duv +``` + If you use `time/udp` you must use the standard rdate implementation and then call it with `rdate -up` to connect using UDP. Without the `-p` argument rdate will try to set the system clock. Please note that rdate @@ -554,6 +565,8 @@ For your convenience a set of *optional* plugins are available: * *echo.so*: RFC 862 plugin. Start as inetd service, like time below. +* *discard.so*: RFC 863 plugin. Start as inetd service, like time below. + * *hwclock.so*: Restore and save system clock from/to RTC on startup/shutdown. diff --git a/configure.ac b/configure.ac index f265edb8..8146b80b 100644 --- a/configure.ac +++ b/configure.ac @@ -53,14 +53,15 @@ AC_ARG_ENABLE(quiet, # Check for extra plugins to enable enable_all_plugins=auto -AC_PLUGIN([alsa-utils], [no], [Save and restore ALSA sound settings using alsactl]) -AC_PLUGIN([dbus], [no], [Setup and start system message bus, D-Bus]) -AC_PLUGIN([inetd-echo], [no], [Inetd plugin: echo server, RFC862]) -AC_PLUGIN([inetd-time], [no], [Inetd plugin: time (rdate) server, RFC868]) -AC_PLUGIN([lost], [no], [Example HOOK_SVC_LOST plugin, very noisy as-is!]) -AC_PLUGIN([resolvconf], [no], [Setup necessary files for resolvconf]) -AC_PLUGIN([x11-common], [no], [Console setup (for X)]) -AC_PLUGIN([netlink], [yes], [Basic netlink plugin for IFUP/IFDN and GW events. Can be replaced with externally built plugin that links with libnl or similar.]) +AC_PLUGIN([alsa-utils], [no], [Save and restore ALSA sound settings using alsactl]) +AC_PLUGIN([dbus], [no], [Setup and start system message bus, D-Bus]) +AC_PLUGIN([inetd-echo], [no], [Inetd plugin: echo server, RFC862]) +AC_PLUGIN([inetd-discard], [no], [Inetd plugin: discard server, RFC862]) +AC_PLUGIN([inetd-time], [no], [Inetd plugin: time (rdate) server, RFC868]) +AC_PLUGIN([lost], [no], [Example HOOK_SVC_LOST plugin, very noisy as-is!]) +AC_PLUGIN([resolvconf], [no], [Setup necessary files for resolvconf]) +AC_PLUGIN([x11-common], [no], [Console setup (for X)]) +AC_PLUGIN([netlink], [yes], [Basic netlink plugin for IFUP/IFDN and GW events. Can be replaced with externally built plugin that links with libnl or similar.]) # Check for extra arguments or packages AC_ARG_WITH(heading, diff --git a/plugins/Makefile.am b/plugins/Makefile.am index e25cf87d..528a9457 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -19,6 +19,10 @@ if BUILD_INETD_ECHO_PLUGIN libplug_la_SOURCES += echo.c endif +if BUILD_INETD_DISCARD_PLUGIN +libplug_la_SOURCES += discard.c +endif + if BUILD_INETD_TIME_PLUGIN libplug_la_SOURCES += time.c endif @@ -50,6 +54,10 @@ if BUILD_INETD_ECHO_PLUGIN pkglib_LTLIBRARIES += echo.la endif +if BUILD_INETD_DISCARD_PLUGIN +pkglib_LTLIBRARIES += discard.la +endif + if BUILD_INETD_TIME_PLUGIN pkglib_LTLIBRARIES += time.la endif diff --git a/plugins/discard.c b/plugins/discard.c new file mode 100644 index 00000000..94bc56c7 --- /dev/null +++ b/plugins/discard.c @@ -0,0 +1,67 @@ +/* Optional inetd plugin for the Discard Protocol, RFC 863 + * + * Copyright (c) 2016 Joachim Nilsson + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include +#include /* STDIN_FILENO */ +#include + +#include "../plugin.h" + +static int cb(int type) +{ + int sd = STDIN_FILENO; + char buf[BUFSIZ]; + ssize_t len; + struct sockaddr_storage sa; + socklen_t sa_len = sizeof(sa); + + len = recvfrom(sd, buf, sizeof(buf), MSG_DONTWAIT, (struct sockaddr *)&sa, &sa_len); + if (-1 == len) + return -1; /* On error, close connection. */ + + return 0; +} + +static plugin_t plugin = { + .name = "discard", /* Must match the inetd /etc/services entry */ + .inetd = { + .cmd = cb + }, +}; + +PLUGIN_INIT(plugin_init) +{ + plugin_register(&plugin); +} + +PLUGIN_EXIT(plugin_exit) +{ + plugin_unregister(&plugin); +} + +/** + * Local Variables: + * indent-tabs-mode: t + * c-file-style: "linux" + * End: + */ diff --git a/plugins/echo.c b/plugins/echo.c index 6cad05a5..1e44f8df 100644 --- a/plugins/echo.c +++ b/plugins/echo.c @@ -1,4 +1,4 @@ -/* Optional inetd plugin for the echo protocol RFC 862 +/* Optional inetd plugin for the Echo Protocol, RFC 862 * * Copyright (c) 2016 Joachim Nilsson * @@ -27,7 +27,7 @@ #include "../plugin.h" -static int echo_cb(int type) +static int cb(int type) { int sd = STDIN_FILENO; char buf[BUFSIZ]; @@ -45,7 +45,7 @@ static int echo_cb(int type) static plugin_t plugin = { .name = "echo", /* Must match the inetd /etc/services entry */ .inetd = { - .cmd = echo_cb + .cmd = cb }, }; diff --git a/plugins/time.c b/plugins/time.c index 6a014342..14e10af6 100644 --- a/plugins/time.c +++ b/plugins/time.c @@ -1,4 +1,4 @@ -/* Optional inetd plugin for time (rdate) protocol RFC 868 +/* Optional inetd plugin for Time Protocol (rdate), RFC 868 * * Copyright (c) 2015 Joachim Nilsson * @@ -32,7 +32,7 @@ #define EPOCH_OFFSET 2208988800ULL /* Return number of seconds since midnight, 1st Jan, 1900 */ -static int rfc868(int type) +static int cb(int type) { int sd = STDIN_FILENO; time_t now; @@ -64,7 +64,7 @@ static int rfc868(int type) static plugin_t plugin = { .name = "time", /* Must match the inetd /etc/services entry */ .inetd = { - .cmd = rfc868 + .cmd = cb } };