router: support ra_mininterval and ra_lifetime uci parameters (FS#397)
[project/odhcpd.git] / src / odhcpd.c
index 2b0ea98..8a18fbf 100644 (file)
@@ -24,6 +24,7 @@
 #include <unistd.h>
 #include <signal.h>
 #include <stdbool.h>
+#include <syslog.h>
 
 #include <arpa/inet.h>
 #include <net/if.h>
@@ -53,7 +54,6 @@ static int ioctl_sock;
 static struct nl_sock *rtnl_socket = NULL;
 static int urandom_fd = -1;
 
-
 static void sighandler(_unused int signal)
 {
        uloop_end();
@@ -65,7 +65,7 @@ static void print_usage(const char *app)
        "== %s Usage ==\n\n"
        "  -h, --help   Print this help\n"
        "  -l level     Specify log level 0..7 (default %d)\n",
-               app, LOG_WARNING
+               app, config.log_level
        );
 }
 
@@ -73,19 +73,19 @@ int main(int argc, char **argv)
 {
        openlog("odhcpd", LOG_PERROR | LOG_PID, LOG_DAEMON);
        int opt;
-       int log_level = LOG_INFO;
+
        while ((opt = getopt(argc, argv, "hl:")) != -1) {
                switch (opt) {
                case 'h':
                        print_usage(argv[0]);
                        return 0;
                case 'l':
-                       log_level = atoi(optarg);
-                       fprintf(stderr, "Log level set to %d\n", log_level);
+                       config.log_level = (atoi(optarg) & LOG_PRIMASK);
+                       fprintf(stderr, "Log level set to %d\n", config.log_level);
                        break;
                }
        }
-       setlogmask(LOG_UPTO(log_level));
+       setlogmask(LOG_UPTO(config.log_level));
        uloop_init();
 
        if (getuid() != 0) {
@@ -566,6 +566,12 @@ int odhcpd_register(struct odhcpd_event *event)
                        ((event->handle_error) ? ULOOP_ERROR_CB : 0));
 }
 
+int odhcpd_deregister(struct odhcpd_event *event)
+{
+       event->uloop.cb = NULL;
+       return uloop_fd_delete(&event->uloop);
+}
+
 void odhcpd_process(struct odhcpd_event *event)
 {
        odhcpd_receive_packets(&event->uloop, 0);