1 /* 2 * Copyright (C) 2014 John Crispin <blogic@openwrt.org> 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License version 2.1 6 * as published by the Free Software Foundation 7 * 8 * This program is distributed in the hope that it will be useful, 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * GNU General Public License for more details. 12 */ 13 14 #include <sys/stat.h> 15 #include <sys/types.h> 16 17 #include <time.h> 18 #include <stdio.h> 19 #include <fcntl.h> 20 #include <getopt.h> 21 #include <resolv.h> 22 #include <unistd.h> 23 #include <sys/types.h> 24 #include <arpa/inet.h> 25 #include <sys/socket.h> 26 #include <netinet/in.h> 27 #include <arpa/nameser.h> 28 29 #include <libubus.h> 30 #include <libubox/uloop.h> 31 32 #include "dns.h" 33 #include "ubus.h" 34 #include "util.h" 35 #include "cache.h" 36 #include "service.h" 37 #include "announce.h" 38 #include "interface.h" 39 40 int cfg_proto = 0; 41 int cfg_no_subnet = 0; 42 43 static struct udebug ud; 44 static struct udebug_buf udb_log; 45 static const struct udebug_buf_meta meta_log = { 46 .name = "umdns_log", 47 .format = UDEBUG_FORMAT_STRING, 48 }; 49 50 static struct udebug_ubus_ring rings[] = { 51 { 52 .buf = &udb_log, 53 .meta = &meta_log, 54 .default_entries = 1024, 55 .default_size = 64 * 1024, 56 } 57 }; 58 59 static void 60 umdns_udebug_vprintf(const char *format, va_list ap) 61 { 62 if (!udebug_buf_valid(&udb_log)) 63 return; 64 65 udebug_entry_init(&udb_log); 66 udebug_entry_vprintf(&udb_log, format, ap); 67 udebug_entry_add(&udb_log); 68 } 69 70 void umdns_udebug_printf(const char *format, ...) 71 { 72 va_list ap; 73 74 va_start(ap, format); 75 umdns_udebug_vprintf(format, ap); 76 va_end(ap); 77 } 78 79 80 void umdns_udebug_config(struct udebug_ubus *ctx, struct blob_attr *data, 81 bool enabled) 82 { 83 udebug_ubus_apply_config(&ud, rings, ARRAY_SIZE(rings), data, enabled); 84 } 85 86 static void 87 signal_shutdown(int signal) 88 { 89 uloop_end(); 90 } 91 92 int 93 main(int argc, char **argv) 94 { 95 int ch, ttl; 96 97 uloop_init(); 98 udebug_init(&ud); 99 udebug_auto_connect(&ud, NULL); 100 101 while ((ch = getopt(argc, argv, "t:i:d46n")) != -1) { 102 switch (ch) { 103 case 't': 104 ttl = atoi(optarg); 105 if (ttl > 0) 106 announce_ttl = ttl; 107 else 108 fprintf(stderr, "invalid ttl\n"); 109 break; 110 case 'd': 111 debug++; 112 break; 113 case 'i': 114 interface_add(optarg); 115 break; 116 case '4': 117 cfg_proto = 4; 118 break; 119 case '6': 120 cfg_proto = 6; 121 break; 122 case 'n': 123 cfg_no_subnet = 1; 124 break; 125 126 default: 127 return -1; 128 } 129 } 130 131 signal(SIGPIPE, SIG_IGN); 132 signal(SIGTERM, signal_shutdown); 133 signal(SIGKILL, signal_shutdown); 134 135 if (cache_init()) 136 return -1; 137 138 ubus_startup(); 139 140 service_init(0); 141 142 uloop_run(); 143 uloop_done(); 144 145 interface_shutdown(); 146 cache_cleanup(NULL); 147 service_cleanup(); 148 vlist_flush(&interfaces); 149 150 return 0; 151 } 152
This page was automatically generated by LXR 0.3.1. • OpenWrt