rpcd-mod-rrdns: add new rpcd plugin for rapid reverse DNS lookups
[project/luci.git] / libs / rpcd-mod-rrdns / src / rrdns.h
1 /*
2 * rrdns - Rapid Reverse DNS lookup plugin for the UBUS RPC server
3 *
4 * Copyright (C) 2016-2017 Jo-Philipp Wich <jo@mein.io>
5 *
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18
19 #include <libubus.h>
20 #include <libubox/avl.h>
21 #include <libubox/uloop.h>
22
23 #define RRDNS_MAX_TIMEOUT 5000
24 #define RRDNS_DEF_TIMEOUT 250
25
26 #define RRDNS_MAX_LIMIT 1000
27 #define RRDNS_DEF_LIMIT 10
28
29
30 struct rrdns_request {
31 struct avl_node by_id;
32 struct avl_node by_addr;
33 uint16_t id;
34 uint16_t family;
35 union {
36 struct in_addr in;
37 struct in6_addr in6;
38 } addr;
39 };
40
41 struct rrdns_context {
42 struct ubus_context *context;
43 struct ubus_request_data request;
44 struct uloop_timeout timeout;
45 struct blob_attr *addr_cur;
46 int addr_rem;
47 struct uloop_fd socket;
48 struct blob_buf blob;
49 struct avl_tree request_ids;
50 struct avl_tree request_addrs;
51 };