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, max; 96 97 uloop_init(); 98 udebug_init(&ud); 99 udebug_auto_connect(&ud, NULL); 100 101 while ((ch = getopt(argc, argv, "t:i:d46nc:")) != -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 'c': 111 max = atoi(optarg); 112 if (max > 0) 113 cache_entries_max = max; 114 else 115 fprintf(stderr, "invalid cache size\n"); 116 break; 117 case 'd': 118 debug++; 119 break; 120 case 'i': 121 interface_add(optarg); 122 break; 123 case '4': 124 cfg_proto = 4; 125 break; 126 case '6': 127 cfg_proto = 6; 128 break; 129 case 'n': 130 cfg_no_subnet = 1; 131 break; 132 133 default: 134 return -1; 135 } 136 } 137 138 signal(SIGPIPE, SIG_IGN); 139 signal(SIGTERM, signal_shutdown); 140 signal(SIGKILL, signal_shutdown); 141 142 if (cache_init()) 143 return -1; 144 145 ubus_startup(); 146 147 service_init(0); 148 149 uloop_run(); 150 uloop_done(); 151 152 interface_shutdown(); 153 cache_cleanup(NULL); 154 service_cleanup(); 155 vlist_flush(&interfaces); 156 157 return 0; 158 } 159
This page was automatically generated by LXR 0.3.1. • OpenWrt