Bernhard Reutner-Fischer | dac7ff1 | 2006-04-12 17:55:51 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
"Vladimir N. Oleynik" | 7b4aa6f | 2006-01-25 14:19:11 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Mini DNS server implementation for busybox |
| 4 | * |
| 5 | * Copyright (C) 2005 Roberto A. Foglietta (me@roberto.foglietta.name) |
| 6 | * Copyright (C) 2005 Odd Arild Olsen (oao at fibula dot no) |
| 7 | * Copyright (C) 2003 Paul Sheer |
Bernhard Reutner-Fischer | 2c99851 | 2006-04-12 18:09:26 +0000 | [diff] [blame] | 8 | * |
"Vladimir N. Oleynik" | 7b4aa6f | 2006-01-25 14:19:11 +0000 | [diff] [blame] | 9 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
| 10 | * |
| 11 | * Odd Arild Olsen started out with the sheerdns [1] of Paul Sheer and rewrote |
"Vladimir N. Oleynik" | 2e5ee8e | 2006-01-25 14:40:24 +0000 | [diff] [blame] | 12 | * it into a shape which I believe is both easier to understand and maintain. |
| 13 | * I also reused the input buffer for output and removed services he did not |
"Vladimir N. Oleynik" | 7b4aa6f | 2006-01-25 14:19:11 +0000 | [diff] [blame] | 14 | * need. [1] http://threading.2038bug.com/sheerdns/ |
"Vladimir N. Oleynik" | 2e5ee8e | 2006-01-25 14:40:24 +0000 | [diff] [blame] | 15 | * |
"Vladimir N. Oleynik" | 7b4aa6f | 2006-01-25 14:19:11 +0000 | [diff] [blame] | 16 | * Some bugfix and minor changes was applied by Roberto A. Foglietta who made |
| 17 | * the first porting of oao' scdns to busybox also. |
| 18 | */ |
| 19 | |
Denis Vlasenko | b6adbf1 | 2007-05-26 19:00:18 +0000 | [diff] [blame] | 20 | #include "libbb.h" |
Bernhard Reutner-Fischer | f470196 | 2008-01-27 12:50:12 +0000 | [diff] [blame] | 21 | #include <syslog.h> |
"Vladimir N. Oleynik" | 7b4aa6f | 2006-01-25 14:19:11 +0000 | [diff] [blame] | 22 | |
Denis Vlasenko | c12f530 | 2006-10-06 09:49:47 +0000 | [diff] [blame] | 23 | //#define DEBUG 1 |
Denis Vlasenko | 2c91652 | 2007-01-12 14:57:37 +0000 | [diff] [blame] | 24 | #define DEBUG 0 |
Denis Vlasenko | c12f530 | 2006-10-06 09:49:47 +0000 | [diff] [blame] | 25 | |
Rob Landley | bc68cd1 | 2006-03-10 19:22:06 +0000 | [diff] [blame] | 26 | enum { |
Denis Vlasenko | ef1b439 | 2009-04-12 19:03:01 +0000 | [diff] [blame] | 27 | /* can tweak this */ |
Denis Vlasenko | ddbf3bf | 2009-04-12 04:09:09 +0000 | [diff] [blame] | 28 | DEFAULT_TTL = 120, |
"Vladimir N. Oleynik" | 7b4aa6f | 2006-01-25 14:19:11 +0000 | [diff] [blame] | 29 | |
Denis Vlasenko | ef1b439 | 2009-04-12 19:03:01 +0000 | [diff] [blame] | 30 | /* cannot get bigger packets than 512 per RFC1035. */ |
Denis Vlasenko | 081eb71 | 2008-03-17 09:02:21 +0000 | [diff] [blame] | 31 | MAX_PACK_LEN = 512, |
Denis Vlasenko | ddbf3bf | 2009-04-12 04:09:09 +0000 | [diff] [blame] | 32 | IP_STRING_LEN = sizeof(".xxx.xxx.xxx.xxx"), |
| 33 | MAX_NAME_LEN = IP_STRING_LEN - 1 + sizeof(".in-addr.arpa"), |
Rob Landley | bc68cd1 | 2006-03-10 19:22:06 +0000 | [diff] [blame] | 34 | REQ_A = 1, |
Denis Vlasenko | ddbf3bf | 2009-04-12 04:09:09 +0000 | [diff] [blame] | 35 | REQ_PTR = 12, |
Rob Landley | bc68cd1 | 2006-03-10 19:22:06 +0000 | [diff] [blame] | 36 | }; |
"Vladimir N. Oleynik" | 7b4aa6f | 2006-01-25 14:19:11 +0000 | [diff] [blame] | 37 | |
Denis Vlasenko | ddbf3bf | 2009-04-12 04:09:09 +0000 | [diff] [blame] | 38 | /* the message from client and first part of response msg */ |
| 39 | struct dns_head { |
"Vladimir N. Oleynik" | 2e5ee8e | 2006-01-25 14:40:24 +0000 | [diff] [blame] | 40 | uint16_t id; |
| 41 | uint16_t flags; |
Denis Vlasenko | ddbf3bf | 2009-04-12 04:09:09 +0000 | [diff] [blame] | 42 | uint16_t nquer; |
| 43 | uint16_t nansw; |
| 44 | uint16_t nauth; |
| 45 | uint16_t nadd; |
"Vladimir N. Oleynik" | 7b4aa6f | 2006-01-25 14:19:11 +0000 | [diff] [blame] | 46 | }; |
| 47 | struct dns_prop { |
"Vladimir N. Oleynik" | 2e5ee8e | 2006-01-25 14:40:24 +0000 | [diff] [blame] | 48 | uint16_t type; |
| 49 | uint16_t class; |
"Vladimir N. Oleynik" | 7b4aa6f | 2006-01-25 14:19:11 +0000 | [diff] [blame] | 50 | }; |
Denis Vlasenko | ddbf3bf | 2009-04-12 04:09:09 +0000 | [diff] [blame] | 51 | /* element of known name, ip address and reversed ip address */ |
| 52 | struct dns_entry { |
"Vladimir N. Oleynik" | 2e5ee8e | 2006-01-25 14:40:24 +0000 | [diff] [blame] | 53 | struct dns_entry *next; |
Denis Vlasenko | ddbf3bf | 2009-04-12 04:09:09 +0000 | [diff] [blame] | 54 | uint32_t ip; |
| 55 | char rip[IP_STRING_LEN]; /* length decimal reversed IP */ |
| 56 | char name[1]; |
"Vladimir N. Oleynik" | 7b4aa6f | 2006-01-25 14:19:11 +0000 | [diff] [blame] | 57 | }; |
| 58 | |
Denis Vlasenko | a19e649 | 2009-03-11 14:40:00 +0000 | [diff] [blame] | 59 | #define OPT_verbose (option_mask32) |
Denis Vlasenko | d3bac03 | 2007-03-24 12:13:04 +0000 | [diff] [blame] | 60 | |
| 61 | |
"Vladimir N. Oleynik" | 7b4aa6f | 2006-01-25 14:19:11 +0000 | [diff] [blame] | 62 | /* |
Bernhard Reutner-Fischer | c418d48 | 2006-05-31 10:19:51 +0000 | [diff] [blame] | 63 | * Insert length of substrings instead of dots |
"Vladimir N. Oleynik" | 7b4aa6f | 2006-01-25 14:19:11 +0000 | [diff] [blame] | 64 | */ |
Denis Vlasenko | ddbf3bf | 2009-04-12 04:09:09 +0000 | [diff] [blame] | 65 | static void undot(char *rip) |
"Vladimir N. Oleynik" | 7b4aa6f | 2006-01-25 14:19:11 +0000 | [diff] [blame] | 66 | { |
Denis Vlasenko | ddbf3bf | 2009-04-12 04:09:09 +0000 | [diff] [blame] | 67 | int i = 0; |
| 68 | int s = 0; |
| 69 | |
Denis Vlasenko | c12f530 | 2006-10-06 09:49:47 +0000 | [diff] [blame] | 70 | while (rip[i]) |
| 71 | i++; |
| 72 | for (--i; i >= 0; i--) { |
| 73 | if (rip[i] == '.') { |
"Vladimir N. Oleynik" | 7b4aa6f | 2006-01-25 14:19:11 +0000 | [diff] [blame] | 74 | rip[i] = s; |
| 75 | s = 0; |
Denis Vlasenko | ddbf3bf | 2009-04-12 04:09:09 +0000 | [diff] [blame] | 76 | } else { |
| 77 | s++; |
| 78 | } |
"Vladimir N. Oleynik" | 7b4aa6f | 2006-01-25 14:19:11 +0000 | [diff] [blame] | 79 | } |
| 80 | } |
| 81 | |
"Vladimir N. Oleynik" | 2e5ee8e | 2006-01-25 14:40:24 +0000 | [diff] [blame] | 82 | /* |
"Vladimir N. Oleynik" | 7b4aa6f | 2006-01-25 14:19:11 +0000 | [diff] [blame] | 83 | * Read hostname/IP records from file |
| 84 | */ |
Denis Vlasenko | a19e649 | 2009-03-11 14:40:00 +0000 | [diff] [blame] | 85 | static struct dns_entry *parse_conf_file(const char *fileconf) |
"Vladimir N. Oleynik" | 7b4aa6f | 2006-01-25 14:19:11 +0000 | [diff] [blame] | 86 | { |
Denis Vlasenko | 084266e | 2008-07-26 23:08:31 +0000 | [diff] [blame] | 87 | char *token[2]; |
Denis Vlasenko | a34f1ed | 2008-07-20 17:48:59 +0000 | [diff] [blame] | 88 | parser_t *parser; |
Denis Vlasenko | ddbf3bf | 2009-04-12 04:09:09 +0000 | [diff] [blame] | 89 | struct dns_entry *m, *conf_data; |
| 90 | struct dns_entry **nextp; |
"Vladimir N. Oleynik" | 7b4aa6f | 2006-01-25 14:19:11 +0000 | [diff] [blame] | 91 | |
Denis Vlasenko | ddbf3bf | 2009-04-12 04:09:09 +0000 | [diff] [blame] | 92 | conf_data = NULL; |
| 93 | nextp = &conf_data; |
| 94 | |
Denis Vlasenko | a34f1ed | 2008-07-20 17:48:59 +0000 | [diff] [blame] | 95 | parser = config_open(fileconf); |
Denis Vlasenko | 084266e | 2008-07-26 23:08:31 +0000 | [diff] [blame] | 96 | while (config_read(parser, token, 2, 2, "# \t", PARSE_NORMAL)) { |
Denis Vlasenko | ddbf3bf | 2009-04-12 04:09:09 +0000 | [diff] [blame] | 97 | struct in_addr ip; |
| 98 | uint32_t v32; |
"Vladimir N. Oleynik" | 7b4aa6f | 2006-01-25 14:19:11 +0000 | [diff] [blame] | 99 | |
Denis Vlasenko | ddbf3bf | 2009-04-12 04:09:09 +0000 | [diff] [blame] | 100 | if (inet_aton(token[1], &ip) == 0) { |
| 101 | bb_error_msg("error at line %u, skipping", parser->lineno); |
| 102 | continue; |
| 103 | } |
"Vladimir N. Oleynik" | 7b4aa6f | 2006-01-25 14:19:11 +0000 | [diff] [blame] | 104 | |
Denis Vlasenko | 084266e | 2008-07-26 23:08:31 +0000 | [diff] [blame] | 105 | if (OPT_verbose) |
Denis Vlasenko | ddbf3bf | 2009-04-12 04:09:09 +0000 | [diff] [blame] | 106 | bb_error_msg("name:%s, ip:%s", token[0], token[1]); |
Denis Vlasenko | a34f1ed | 2008-07-20 17:48:59 +0000 | [diff] [blame] | 107 | |
Denis Vlasenko | ddbf3bf | 2009-04-12 04:09:09 +0000 | [diff] [blame] | 108 | /* sizeof(*m) includes 1 byte for m->name[0] */ |
| 109 | m = xzalloc(sizeof(*m) + strlen(token[0]) + 1); |
| 110 | /*m->next = NULL;*/ |
| 111 | *nextp = m; |
| 112 | nextp = &m->next; |
| 113 | |
| 114 | m->name[0] = '.'; |
| 115 | strcpy(m->name + 1, token[0]); |
| 116 | undot(m->name); |
| 117 | m->ip = ip.s_addr; /* in network order */ |
| 118 | v32 = ntohl(m->ip); |
| 119 | /* inverted order */ |
| 120 | sprintf(m->rip, ".%u.%u.%u.%u", |
| 121 | (uint8_t)(v32), |
| 122 | (uint8_t)(v32 >> 8), |
| 123 | (uint8_t)(v32 >> 16), |
| 124 | (v32 >> 24) |
| 125 | ); |
| 126 | undot(m->rip); |
"Vladimir N. Oleynik" | 2e5ee8e | 2006-01-25 14:40:24 +0000 | [diff] [blame] | 127 | } |
Denis Vlasenko | 084266e | 2008-07-26 23:08:31 +0000 | [diff] [blame] | 128 | config_close(parser); |
Denis Vlasenko | a19e649 | 2009-03-11 14:40:00 +0000 | [diff] [blame] | 129 | return conf_data; |
"Vladimir N. Oleynik" | 7b4aa6f | 2006-01-25 14:19:11 +0000 | [diff] [blame] | 130 | } |
| 131 | |
"Vladimir N. Oleynik" | 7b4aa6f | 2006-01-25 14:19:11 +0000 | [diff] [blame] | 132 | /* |
Denis Vlasenko | ddbf3bf | 2009-04-12 04:09:09 +0000 | [diff] [blame] | 133 | * Look query up in dns records and return answer if found. |
"Vladimir N. Oleynik" | 2e5ee8e | 2006-01-25 14:40:24 +0000 | [diff] [blame] | 134 | */ |
Denis Vlasenko | 5c32993 | 2009-04-12 12:16:21 +0000 | [diff] [blame] | 135 | static char *table_lookup(struct dns_entry *d, |
| 136 | uint16_t type, |
| 137 | char* query_string) |
"Vladimir N. Oleynik" | 7b4aa6f | 2006-01-25 14:19:11 +0000 | [diff] [blame] | 138 | { |
Denis Vlasenko | ddbf3bf | 2009-04-12 04:09:09 +0000 | [diff] [blame] | 139 | while (d) { |
| 140 | unsigned len = d->name[0]; |
| 141 | /* d->name[len] is the last (non NUL) char */ |
Denis Vlasenko | 91f20ab | 2007-01-20 01:47:44 +0000 | [diff] [blame] | 142 | #if DEBUG |
Denis Vlasenko | a19e649 | 2009-03-11 14:40:00 +0000 | [diff] [blame] | 143 | char *p, *q; |
Denis Vlasenko | 5c32993 | 2009-04-12 12:16:21 +0000 | [diff] [blame] | 144 | q = query_string + 1; |
| 145 | p = d->name + 1; |
Denis Vlasenko | ddbf3bf | 2009-04-12 04:09:09 +0000 | [diff] [blame] | 146 | fprintf(stderr, "%d/%d p:%s q:%s %d\n", |
| 147 | (int)strlen(p), len, |
| 148 | p, q, (int)strlen(q) |
| 149 | ); |
"Vladimir N. Oleynik" | 7b4aa6f | 2006-01-25 14:19:11 +0000 | [diff] [blame] | 150 | #endif |
Denis Vlasenko | ddbf3bf | 2009-04-12 04:09:09 +0000 | [diff] [blame] | 151 | if (type == htons(REQ_A)) { |
Denis Vlasenko | a19e649 | 2009-03-11 14:40:00 +0000 | [diff] [blame] | 152 | /* search by host name */ |
Denis Vlasenko | ddbf3bf | 2009-04-12 04:09:09 +0000 | [diff] [blame] | 153 | if (len != 1 || d->name[1] != '*') { |
Denis Vlasenko | 5c32993 | 2009-04-12 12:16:21 +0000 | [diff] [blame] | 154 | /* we are lax, hope no name component is ever >64 so that length |
| 155 | * (which will be represented as 'A','B'...) matches a lowercase letter. |
| 156 | * Actually, I think false matches are hard to construct. |
| 157 | * Example. |
| 158 | * [31] len is represented as '1', [65] as 'A', [65+32] as 'a'. |
| 159 | * [65] <65 same chars>[31]<31 same chars>NUL |
| 160 | * [65+32]<65 same chars>1 <31 same chars>NUL |
| 161 | * This example seems to be the minimal case when false match occurs. |
| 162 | */ |
| 163 | if (strcasecmp(d->name, query_string) != 0) |
Denis Vlasenko | ddbf3bf | 2009-04-12 04:09:09 +0000 | [diff] [blame] | 164 | goto next; |
| 165 | } |
Denis Vlasenko | 5c32993 | 2009-04-12 12:16:21 +0000 | [diff] [blame] | 166 | return (char *)&d->ip; |
Denis Vlasenko | 91f20ab | 2007-01-20 01:47:44 +0000 | [diff] [blame] | 167 | #if DEBUG |
Denis Vlasenko | 5c32993 | 2009-04-12 12:16:21 +0000 | [diff] [blame] | 168 | fprintf(stderr, "Found IP:%x\n", (int)d->ip); |
"Vladimir N. Oleynik" | 7b4aa6f | 2006-01-25 14:19:11 +0000 | [diff] [blame] | 169 | #endif |
Denis Vlasenko | ddbf3bf | 2009-04-12 04:09:09 +0000 | [diff] [blame] | 170 | return 0; |
"Vladimir N. Oleynik" | 2e5ee8e | 2006-01-25 14:40:24 +0000 | [diff] [blame] | 171 | } |
Denis Vlasenko | ddbf3bf | 2009-04-12 04:09:09 +0000 | [diff] [blame] | 172 | /* search by IP-address */ |
| 173 | if ((len != 1 || d->name[1] != '*') |
Denis Vlasenko | 5c32993 | 2009-04-12 12:16:21 +0000 | [diff] [blame] | 174 | /* we assume (do not check) that query_string |
| 175 | * ends in ".in-addr.arpa" */ |
| 176 | && strncmp(d->rip, query_string, strlen(d->rip)) == 0 |
Denis Vlasenko | ddbf3bf | 2009-04-12 04:09:09 +0000 | [diff] [blame] | 177 | ) { |
Denis Vlasenko | ddbf3bf | 2009-04-12 04:09:09 +0000 | [diff] [blame] | 178 | #if DEBUG |
Denis Vlasenko | 5c32993 | 2009-04-12 12:16:21 +0000 | [diff] [blame] | 179 | fprintf(stderr, "Found name:%s\n", d->name); |
Denis Vlasenko | ddbf3bf | 2009-04-12 04:09:09 +0000 | [diff] [blame] | 180 | #endif |
Denis Vlasenko | 5c32993 | 2009-04-12 12:16:21 +0000 | [diff] [blame] | 181 | return d->name; |
Denis Vlasenko | ddbf3bf | 2009-04-12 04:09:09 +0000 | [diff] [blame] | 182 | } |
| 183 | next: |
Denis Vlasenko | c12f530 | 2006-10-06 09:49:47 +0000 | [diff] [blame] | 184 | d = d->next; |
Denis Vlasenko | ddbf3bf | 2009-04-12 04:09:09 +0000 | [diff] [blame] | 185 | } |
| 186 | |
Denis Vlasenko | 5c32993 | 2009-04-12 12:16:21 +0000 | [diff] [blame] | 187 | return NULL; |
"Vladimir N. Oleynik" | 7b4aa6f | 2006-01-25 14:19:11 +0000 | [diff] [blame] | 188 | } |
| 189 | |
"Vladimir N. Oleynik" | 2e5ee8e | 2006-01-25 14:40:24 +0000 | [diff] [blame] | 190 | /* |
"Vladimir N. Oleynik" | 7b4aa6f | 2006-01-25 14:19:11 +0000 | [diff] [blame] | 191 | * Decode message and generate answer |
| 192 | */ |
Denis Vlasenko | ddbf3bf | 2009-04-12 04:09:09 +0000 | [diff] [blame] | 193 | /* RFC 1035 |
| 194 | ... |
| 195 | Whenever an octet represents a numeric quantity, the left most bit |
| 196 | in the diagram is the high order or most significant bit. |
| 197 | That is, the bit labeled 0 is the most significant bit. |
| 198 | ... |
| 199 | |
| 200 | 4.1.1. Header section format |
Denis Vlasenko | 5c32993 | 2009-04-12 12:16:21 +0000 | [diff] [blame] | 201 | 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
Denis Vlasenko | ddbf3bf | 2009-04-12 04:09:09 +0000 | [diff] [blame] | 202 | +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ |
| 203 | | ID | |
| 204 | +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ |
Denis Vlasenko | 5c32993 | 2009-04-12 12:16:21 +0000 | [diff] [blame] | 205 | |QR| OPCODE |AA|TC|RD|RA| 0 0 0| RCODE | |
Denis Vlasenko | ddbf3bf | 2009-04-12 04:09:09 +0000 | [diff] [blame] | 206 | +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ |
| 207 | | QDCOUNT | |
| 208 | +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ |
| 209 | | ANCOUNT | |
| 210 | +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ |
| 211 | | NSCOUNT | |
| 212 | +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ |
| 213 | | ARCOUNT | |
| 214 | +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ |
Denis Vlasenko | 5c32993 | 2009-04-12 12:16:21 +0000 | [diff] [blame] | 215 | ID 16 bit random identifier assigned by querying peer. |
Denis Vlasenko | ddbf3bf | 2009-04-12 04:09:09 +0000 | [diff] [blame] | 216 | Used to match query/response. |
| 217 | QR message is a query (0), or a response (1). |
| 218 | OPCODE 0 standard query (QUERY) |
| 219 | 1 inverse query (IQUERY) |
| 220 | 2 server status request (STATUS) |
Denis Vlasenko | 5c32993 | 2009-04-12 12:16:21 +0000 | [diff] [blame] | 221 | AA Authoritative Answer - this bit is valid in responses. |
| 222 | Responding name server is an authority for the domain name |
Denis Vlasenko | ef1b439 | 2009-04-12 19:03:01 +0000 | [diff] [blame] | 223 | in question section. Answer section may have multiple owner names |
| 224 | because of aliases. The AA bit corresponds to the name which matches |
| 225 | the query name, or the first owner name in the answer section. |
Denis Vlasenko | 5c32993 | 2009-04-12 12:16:21 +0000 | [diff] [blame] | 226 | TC TrunCation - this message was truncated. |
Denis Vlasenko | ddbf3bf | 2009-04-12 04:09:09 +0000 | [diff] [blame] | 227 | RD Recursion Desired - this bit may be set in a query and |
| 228 | is copied into the response. If RD is set, it directs |
| 229 | the name server to pursue the query recursively. |
| 230 | Recursive query support is optional. |
| 231 | RA Recursion Available - this be is set or cleared in a |
| 232 | response, and denotes whether recursive query support is |
| 233 | available in the name server. |
Denis Vlasenko | ddbf3bf | 2009-04-12 04:09:09 +0000 | [diff] [blame] | 234 | RCODE Response code. |
| 235 | 0 No error condition |
| 236 | 1 Format error |
Denis Vlasenko | 5c32993 | 2009-04-12 12:16:21 +0000 | [diff] [blame] | 237 | 2 Server failure - server was unable to process the query |
Denis Vlasenko | ef1b439 | 2009-04-12 19:03:01 +0000 | [diff] [blame] | 238 | due to a problem with the name server. |
Denis Vlasenko | 5c32993 | 2009-04-12 12:16:21 +0000 | [diff] [blame] | 239 | 3 Name Error - meaningful only for responses from |
Denis Vlasenko | ef1b439 | 2009-04-12 19:03:01 +0000 | [diff] [blame] | 240 | an authoritative name server. The referenced domain name |
| 241 | does not exist. |
Denis Vlasenko | ddbf3bf | 2009-04-12 04:09:09 +0000 | [diff] [blame] | 242 | 4 Not Implemented. |
| 243 | 5 Refused. |
| 244 | QDCOUNT number of entries in the question section. |
Denis Vlasenko | 5c32993 | 2009-04-12 12:16:21 +0000 | [diff] [blame] | 245 | ANCOUNT number of records in the answer section. |
| 246 | NSCOUNT number of records in the authority records section. |
| 247 | ARCOUNT number of records in the additional records section. |
Denis Vlasenko | ddbf3bf | 2009-04-12 04:09:09 +0000 | [diff] [blame] | 248 | |
| 249 | 4.1.2. Question section format |
| 250 | |
Denis Vlasenko | 5c32993 | 2009-04-12 12:16:21 +0000 | [diff] [blame] | 251 | The section contains QDCOUNT (usually 1) entries, each of this format: |
| 252 | 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
Denis Vlasenko | ddbf3bf | 2009-04-12 04:09:09 +0000 | [diff] [blame] | 253 | +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ |
| 254 | / QNAME / |
| 255 | / / |
| 256 | +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ |
| 257 | | QTYPE | |
| 258 | +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ |
| 259 | | QCLASS | |
| 260 | +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ |
| 261 | QNAME a domain name represented as a sequence of labels, where |
| 262 | each label consists of a length octet followed by that |
| 263 | number of octets. The domain name terminates with the |
| 264 | zero length octet for the null label of the root. Note |
| 265 | that this field may be an odd number of octets; no |
| 266 | padding is used. |
| 267 | QTYPE a two octet type of the query. |
| 268 | 1 a host address [REQ_A const] |
| 269 | 2 an authoritative name server |
| 270 | 3 a mail destination (Obsolete - use MX) |
| 271 | 4 a mail forwarder (Obsolete - use MX) |
| 272 | 5 the canonical name for an alias |
| 273 | 6 marks the start of a zone of authority |
| 274 | 7 a mailbox domain name (EXPERIMENTAL) |
| 275 | 8 a mail group member (EXPERIMENTAL) |
| 276 | 9 a mail rename domain name (EXPERIMENTAL) |
| 277 | 10 a null RR (EXPERIMENTAL) |
| 278 | 11 a well known service description |
| 279 | 12 a domain name pointer [REQ_PTR const] |
| 280 | 13 host information |
| 281 | 14 mailbox or mail list information |
| 282 | 15 mail exchange |
| 283 | 16 text strings |
| 284 | 0x1c IPv6? |
| 285 | 252 a request for a transfer of an entire zone |
| 286 | 253 a request for mailbox-related records (MB, MG or MR) |
| 287 | 254 a request for mail agent RRs (Obsolete - see MX) |
| 288 | 255 a request for all records |
| 289 | QCLASS a two octet code that specifies the class of the query. |
| 290 | 1 the Internet |
Denis Vlasenko | ef1b439 | 2009-04-12 19:03:01 +0000 | [diff] [blame] | 291 | (others are historic only) |
Denis Vlasenko | ddbf3bf | 2009-04-12 04:09:09 +0000 | [diff] [blame] | 292 | 255 any class |
| 293 | |
| 294 | 4.1.3. Resource record format |
| 295 | |
Denis Vlasenko | 5c32993 | 2009-04-12 12:16:21 +0000 | [diff] [blame] | 296 | The answer, authority, and additional sections all share the same format: |
| 297 | a variable number of resource records, where the number of records |
| 298 | is specified in the corresponding count field in the header. |
| 299 | Each resource record has this format: |
| 300 | 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
Denis Vlasenko | ddbf3bf | 2009-04-12 04:09:09 +0000 | [diff] [blame] | 301 | +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ |
| 302 | / / |
| 303 | / NAME / |
| 304 | +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ |
| 305 | | TYPE | |
| 306 | +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ |
| 307 | | CLASS | |
| 308 | +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ |
| 309 | | TTL | |
| 310 | | | |
| 311 | +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ |
| 312 | | RDLENGTH | |
| 313 | +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--| |
| 314 | / RDATA / |
| 315 | / / |
| 316 | +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ |
| 317 | NAME a domain name to which this resource record pertains. |
| 318 | TYPE two octets containing one of the RR type codes. This |
Denis Vlasenko | 5c32993 | 2009-04-12 12:16:21 +0000 | [diff] [blame] | 319 | field specifies the meaning of the data in the RDATA field. |
| 320 | CLASS two octets which specify the class of the data in the RDATA field. |
| 321 | TTL a 32 bit unsigned integer that specifies the time interval |
| 322 | (in seconds) that the record may be cached. |
| 323 | RDLENGTH a 16 bit integer, length in octets of the RDATA field. |
| 324 | RDATA a variable length string of octets that describes the resource. |
| 325 | The format of this information varies according to the TYPE |
| 326 | and CLASS of the resource record. |
| 327 | If the TYPE is A and the CLASS is IN, it's a 4 octet IP address. |
Denis Vlasenko | ddbf3bf | 2009-04-12 04:09:09 +0000 | [diff] [blame] | 328 | |
| 329 | 4.1.4. Message compression |
| 330 | |
Denis Vlasenko | 5c32993 | 2009-04-12 12:16:21 +0000 | [diff] [blame] | 331 | In order to reduce the size of messages, domain names coan be compressed. |
| 332 | An entire domain name or a list of labels at the end of a domain name |
| 333 | is replaced with a pointer to a prior occurance of the same name. |
Denis Vlasenko | ddbf3bf | 2009-04-12 04:09:09 +0000 | [diff] [blame] | 334 | |
| 335 | The pointer takes the form of a two octet sequence: |
| 336 | +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ |
| 337 | | 1 1| OFFSET | |
| 338 | +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ |
| 339 | The first two bits are ones. This allows a pointer to be distinguished |
| 340 | from a label, since the label must begin with two zero bits because |
| 341 | labels are restricted to 63 octets or less. The OFFSET field specifies |
| 342 | an offset from the start of the message (i.e., the first octet |
| 343 | of the ID field in the domain header). |
| 344 | A zero offset specifies the first byte of the ID field, etc. |
Denis Vlasenko | 5c32993 | 2009-04-12 12:16:21 +0000 | [diff] [blame] | 345 | Domain name in a message can be represented as either: |
Denis Vlasenko | ddbf3bf | 2009-04-12 04:09:09 +0000 | [diff] [blame] | 346 | - a sequence of labels ending in a zero octet |
| 347 | - a pointer |
| 348 | - a sequence of labels ending with a pointer |
| 349 | */ |
Denis Vlasenko | 5c32993 | 2009-04-12 12:16:21 +0000 | [diff] [blame] | 350 | static int process_packet(struct dns_entry *conf_data, |
| 351 | uint32_t conf_ttl, |
| 352 | uint8_t *buf) |
"Vladimir N. Oleynik" | 7b4aa6f | 2006-01-25 14:19:11 +0000 | [diff] [blame] | 353 | { |
Denis Vlasenko | 5c32993 | 2009-04-12 12:16:21 +0000 | [diff] [blame] | 354 | char *answstr; |
"Vladimir N. Oleynik" | 2e5ee8e | 2006-01-25 14:40:24 +0000 | [diff] [blame] | 355 | struct dns_head *head; |
Denis Vlasenko | ddbf3bf | 2009-04-12 04:09:09 +0000 | [diff] [blame] | 356 | struct dns_prop *unaligned_qprop; |
Denis Vlasenko | 5c32993 | 2009-04-12 12:16:21 +0000 | [diff] [blame] | 357 | char *query_string; |
| 358 | uint8_t *answb; |
Denis Vlasenko | 081eb71 | 2008-03-17 09:02:21 +0000 | [diff] [blame] | 359 | uint16_t outr_rlen; |
| 360 | uint16_t outr_flags; |
Denis Vlasenko | ddbf3bf | 2009-04-12 04:09:09 +0000 | [diff] [blame] | 361 | uint16_t type; |
| 362 | uint16_t class; |
Denis Vlasenko | 081eb71 | 2008-03-17 09:02:21 +0000 | [diff] [blame] | 363 | int querystr_len; |
"Vladimir N. Oleynik" | 7b4aa6f | 2006-01-25 14:19:11 +0000 | [diff] [blame] | 364 | |
"Vladimir N. Oleynik" | 2e5ee8e | 2006-01-25 14:40:24 +0000 | [diff] [blame] | 365 | head = (struct dns_head *)buf; |
Denis Vlasenko | d3bac03 | 2007-03-24 12:13:04 +0000 | [diff] [blame] | 366 | if (head->nquer == 0) { |
Denis Vlasenko | ddbf3bf | 2009-04-12 04:09:09 +0000 | [diff] [blame] | 367 | bb_error_msg("packet has 0 queries, ignored"); |
Denis Vlasenko | b5b45a9 | 2007-03-24 13:09:07 +0000 | [diff] [blame] | 368 | return -1; |
Denis Vlasenko | d3bac03 | 2007-03-24 12:13:04 +0000 | [diff] [blame] | 369 | } |
"Vladimir N. Oleynik" | 7b4aa6f | 2006-01-25 14:19:11 +0000 | [diff] [blame] | 370 | |
Denis Vlasenko | ddbf3bf | 2009-04-12 04:09:09 +0000 | [diff] [blame] | 371 | if (head->flags & htons(0x8000)) { /* QR bit */ |
| 372 | bb_error_msg("response packet, ignored"); |
Denis Vlasenko | b5b45a9 | 2007-03-24 13:09:07 +0000 | [diff] [blame] | 373 | return -1; |
Denis Vlasenko | d3bac03 | 2007-03-24 12:13:04 +0000 | [diff] [blame] | 374 | } |
"Vladimir N. Oleynik" | 7b4aa6f | 2006-01-25 14:19:11 +0000 | [diff] [blame] | 375 | |
Denis Vlasenko | ddbf3bf | 2009-04-12 04:09:09 +0000 | [diff] [blame] | 376 | /* start of query string */ |
Denis Vlasenko | 5c32993 | 2009-04-12 12:16:21 +0000 | [diff] [blame] | 377 | query_string = (void *)(head + 1); |
Denis Vlasenko | ddbf3bf | 2009-04-12 04:09:09 +0000 | [diff] [blame] | 378 | /* caller guarantees strlen is <= MAX_PACK_LEN */ |
Denis Vlasenko | 5c32993 | 2009-04-12 12:16:21 +0000 | [diff] [blame] | 379 | querystr_len = strlen(query_string) + 1; |
Denis Vlasenko | ddbf3bf | 2009-04-12 04:09:09 +0000 | [diff] [blame] | 380 | /* may be unaligned! */ |
Denis Vlasenko | 5c32993 | 2009-04-12 12:16:21 +0000 | [diff] [blame] | 381 | unaligned_qprop = (void *)(query_string + querystr_len); |
| 382 | querystr_len += sizeof(unaligned_qprop); |
Denis Vlasenko | ddbf3bf | 2009-04-12 04:09:09 +0000 | [diff] [blame] | 383 | /* where to append answer block */ |
| 384 | answb = (void *)(unaligned_qprop + 1); |
"Vladimir N. Oleynik" | 7b4aa6f | 2006-01-25 14:19:11 +0000 | [diff] [blame] | 385 | |
Denis Vlasenko | ddbf3bf | 2009-04-12 04:09:09 +0000 | [diff] [blame] | 386 | /* QR = 1 "response", RCODE = 4 "Not Implemented" */ |
| 387 | outr_flags = htons(0x8000 | 4); |
"Vladimir N. Oleynik" | 7b4aa6f | 2006-01-25 14:19:11 +0000 | [diff] [blame] | 388 | |
Denis Vlasenko | ddbf3bf | 2009-04-12 04:09:09 +0000 | [diff] [blame] | 389 | move_from_unaligned16(type, &unaligned_qprop->type); |
| 390 | if (type != htons(REQ_A) && type != htons(REQ_PTR)) { |
| 391 | /* we can't handle the query type */ |
"Vladimir N. Oleynik" | 2e5ee8e | 2006-01-25 14:40:24 +0000 | [diff] [blame] | 392 | goto empty_packet; |
| 393 | } |
Denis Vlasenko | ddbf3bf | 2009-04-12 04:09:09 +0000 | [diff] [blame] | 394 | move_from_unaligned16(class, &unaligned_qprop->class); |
| 395 | if (class != htons(1)) { /* not class INET? */ |
"Vladimir N. Oleynik" | 2e5ee8e | 2006-01-25 14:40:24 +0000 | [diff] [blame] | 396 | goto empty_packet; |
Denis Vlasenko | ddbf3bf | 2009-04-12 04:09:09 +0000 | [diff] [blame] | 397 | } |
| 398 | /* OPCODE != 0 "standard query" ? */ |
| 399 | if ((head->flags & htons(0x7800)) != 0) { |
| 400 | goto empty_packet; |
| 401 | } |
"Vladimir N. Oleynik" | 7b4aa6f | 2006-01-25 14:19:11 +0000 | [diff] [blame] | 402 | |
Denis Vlasenko | 5c32993 | 2009-04-12 12:16:21 +0000 | [diff] [blame] | 403 | /* look up the name */ |
| 404 | #if DEBUG |
| 405 | /* need to convert lengths to dots before we can use it in non-debug */ |
| 406 | bb_info_msg("%s", query_string); |
| 407 | #endif |
| 408 | answstr = table_lookup(conf_data, type, query_string); |
| 409 | outr_rlen = 4; |
| 410 | if (answstr && type == htons(REQ_PTR)) { |
| 411 | /* return a host name */ |
| 412 | outr_rlen = strlen(answstr) + 1; |
| 413 | } |
| 414 | if (!answstr |
| 415 | || (unsigned)(answb - buf) + querystr_len + 4 + 2 + outr_rlen > MAX_PACK_LEN |
| 416 | ) { |
Denis Vlasenko | ddbf3bf | 2009-04-12 04:09:09 +0000 | [diff] [blame] | 417 | /* QR = 1 "response" |
| 418 | * AA = 1 "Authoritative Answer" |
| 419 | * RCODE = 3 "Name Error" */ |
| 420 | outr_flags = htons(0x8000 | 0x0400 | 3); |
"Vladimir N. Oleynik" | 2e5ee8e | 2006-01-25 14:40:24 +0000 | [diff] [blame] | 421 | goto empty_packet; |
| 422 | } |
Denis Vlasenko | 5c32993 | 2009-04-12 12:16:21 +0000 | [diff] [blame] | 423 | |
Denis Vlasenko | ddbf3bf | 2009-04-12 04:09:09 +0000 | [diff] [blame] | 424 | /* copy query block to answer block */ |
Denis Vlasenko | 5c32993 | 2009-04-12 12:16:21 +0000 | [diff] [blame] | 425 | memcpy(answb, query_string, querystr_len); |
Denis Vlasenko | 081eb71 | 2008-03-17 09:02:21 +0000 | [diff] [blame] | 426 | answb += querystr_len; |
Denis Vlasenko | ddbf3bf | 2009-04-12 04:09:09 +0000 | [diff] [blame] | 427 | /* append answer Resource Record */ |
| 428 | move_to_unaligned32((uint32_t *)answb, htonl(conf_ttl)); |
Denis Vlasenko | 081eb71 | 2008-03-17 09:02:21 +0000 | [diff] [blame] | 429 | answb += 4; |
Denis Vlasenko | ddbf3bf | 2009-04-12 04:09:09 +0000 | [diff] [blame] | 430 | move_to_unaligned32((uint16_t *)answb, htons(outr_rlen)); |
Denis Vlasenko | 081eb71 | 2008-03-17 09:02:21 +0000 | [diff] [blame] | 431 | answb += 2; |
| 432 | memcpy(answb, answstr, outr_rlen); |
| 433 | answb += outr_rlen; |
"Vladimir N. Oleynik" | 7b4aa6f | 2006-01-25 14:19:11 +0000 | [diff] [blame] | 434 | |
Denis Vlasenko | 5c32993 | 2009-04-12 12:16:21 +0000 | [diff] [blame] | 435 | /* QR = 1 "response", |
| 436 | * AA = 1 "Authoritative Answer", |
| 437 | * RCODE = 0 "success" */ |
| 438 | outr_flags = htons(0x8000 | 0x0400 | 0); |
| 439 | /* we have one answer */ |
| 440 | head->nansw = htons(1); |
| 441 | |
Denis Vlasenko | c12f530 | 2006-10-06 09:49:47 +0000 | [diff] [blame] | 442 | empty_packet: |
Denis Vlasenko | ddbf3bf | 2009-04-12 04:09:09 +0000 | [diff] [blame] | 443 | head->flags |= outr_flags; |
Denis Vlasenko | 081eb71 | 2008-03-17 09:02:21 +0000 | [diff] [blame] | 444 | head->nauth = head->nadd = 0; |
Denis Vlasenko | ddbf3bf | 2009-04-12 04:09:09 +0000 | [diff] [blame] | 445 | head->nquer = htons(1); // why??? |
"Vladimir N. Oleynik" | 7b4aa6f | 2006-01-25 14:19:11 +0000 | [diff] [blame] | 446 | |
Denis Vlasenko | ddbf3bf | 2009-04-12 04:09:09 +0000 | [diff] [blame] | 447 | return answb - buf; |
"Vladimir N. Oleynik" | 7b4aa6f | 2006-01-25 14:19:11 +0000 | [diff] [blame] | 448 | } |
| 449 | |
Denis Vlasenko | 9b49a5e | 2007-10-11 10:05:36 +0000 | [diff] [blame] | 450 | int dnsd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
Denis Vlasenko | a60f84e | 2008-07-05 09:18:54 +0000 | [diff] [blame] | 451 | int dnsd_main(int argc UNUSED_PARAM, char **argv) |
"Vladimir N. Oleynik" | 7b4aa6f | 2006-01-25 14:19:11 +0000 | [diff] [blame] | 452 | { |
Denis Vlasenko | d3bac03 | 2007-03-24 12:13:04 +0000 | [diff] [blame] | 453 | const char *listen_interface = "0.0.0.0"; |
Denis Vlasenko | a19e649 | 2009-03-11 14:40:00 +0000 | [diff] [blame] | 454 | const char *fileconf = "/etc/dnsd.conf"; |
| 455 | struct dns_entry *conf_data; |
| 456 | uint32_t conf_ttl = DEFAULT_TTL; |
Denis Vlasenko | 2c91652 | 2007-01-12 14:57:37 +0000 | [diff] [blame] | 457 | char *sttl, *sport; |
Denis Vlasenko | 081eb71 | 2008-03-17 09:02:21 +0000 | [diff] [blame] | 458 | len_and_sockaddr *lsa, *from, *to; |
| 459 | unsigned lsa_size; |
Denis Vlasenko | a19e649 | 2009-03-11 14:40:00 +0000 | [diff] [blame] | 460 | int udps, opts; |
"Vladimir N. Oleynik" | 2e5ee8e | 2006-01-25 14:40:24 +0000 | [diff] [blame] | 461 | uint16_t port = 53; |
Denis Vlasenko | ef1b439 | 2009-04-12 19:03:01 +0000 | [diff] [blame] | 462 | uint8_t buf[MAX_PACK_LEN + 1]; |
"Vladimir N. Oleynik" | 7b4aa6f | 2006-01-25 14:19:11 +0000 | [diff] [blame] | 463 | |
Denis Vlasenko | a19e649 | 2009-03-11 14:40:00 +0000 | [diff] [blame] | 464 | opts = getopt32(argv, "vi:c:t:p:d", &listen_interface, &fileconf, &sttl, &sport); |
| 465 | //if (opts & 0x1) // -v |
| 466 | //if (opts & 0x2) // -i |
| 467 | //if (opts & 0x4) // -c |
| 468 | if (opts & 0x8) // -t |
| 469 | conf_ttl = xatou_range(sttl, 1, 0xffffffff); |
| 470 | if (opts & 0x10) // -p |
Denis Vlasenko | d3bac03 | 2007-03-24 12:13:04 +0000 | [diff] [blame] | 471 | port = xatou_range(sport, 1, 0xffff); |
Denis Vlasenko | a19e649 | 2009-03-11 14:40:00 +0000 | [diff] [blame] | 472 | if (opts & 0x20) { // -d |
Denis Vlasenko | 5a14202 | 2007-03-26 13:20:54 +0000 | [diff] [blame] | 473 | bb_daemonize_or_rexec(DAEMON_CLOSE_EXTRA_FDS, argv); |
Denis Vlasenko | 5b27fbe | 2007-03-24 14:06:51 +0000 | [diff] [blame] | 474 | openlog(applet_name, LOG_PID, LOG_DAEMON); |
Denis Vlasenko | 2c91652 | 2007-01-12 14:57:37 +0000 | [diff] [blame] | 475 | logmode = LOGMODE_SYSLOG; |
| 476 | } |
Denis Vlasenko | a19e649 | 2009-03-11 14:40:00 +0000 | [diff] [blame] | 477 | /* Clear all except "verbose" bit */ |
| 478 | option_mask32 &= 1; |
"Vladimir N. Oleynik" | 7b4aa6f | 2006-01-25 14:19:11 +0000 | [diff] [blame] | 479 | |
Denis Vlasenko | a19e649 | 2009-03-11 14:40:00 +0000 | [diff] [blame] | 480 | conf_data = parse_conf_file(fileconf); |
"Vladimir N. Oleynik" | 2e5ee8e | 2006-01-25 14:40:24 +0000 | [diff] [blame] | 481 | |
Denis Vlasenko | d3bac03 | 2007-03-24 12:13:04 +0000 | [diff] [blame] | 482 | lsa = xdotted2sockaddr(listen_interface, port); |
Bernhard Reutner-Fischer | 8c69afd | 2008-01-29 10:33:34 +0000 | [diff] [blame] | 483 | udps = xsocket(lsa->u.sa.sa_family, SOCK_DGRAM, 0); |
| 484 | xbind(udps, &lsa->u.sa, lsa->len); |
Denis Vlasenko | 081eb71 | 2008-03-17 09:02:21 +0000 | [diff] [blame] | 485 | socket_want_pktinfo(udps); /* needed for recv_from_to to work */ |
| 486 | lsa_size = LSA_LEN_SIZE + lsa->len; |
| 487 | from = xzalloc(lsa_size); |
| 488 | to = xzalloc(lsa_size); |
| 489 | |
Denis Vlasenko | ddbf3bf | 2009-04-12 04:09:09 +0000 | [diff] [blame] | 490 | { |
| 491 | char *p = xmalloc_sockaddr2dotted(&lsa->u.sa); |
| 492 | bb_info_msg("Accepting UDP packets on %s", p); |
| 493 | free(p); |
| 494 | } |
"Vladimir N. Oleynik" | 7b4aa6f | 2006-01-25 14:19:11 +0000 | [diff] [blame] | 495 | |
"Vladimir N. Oleynik" | 2e5ee8e | 2006-01-25 14:40:24 +0000 | [diff] [blame] | 496 | while (1) { |
"Vladimir N. Oleynik" | 2e5ee8e | 2006-01-25 14:40:24 +0000 | [diff] [blame] | 497 | int r; |
Denis Vlasenko | 081eb71 | 2008-03-17 09:02:21 +0000 | [diff] [blame] | 498 | /* Try to get *DEST* address (to which of our addresses |
| 499 | * this query was directed), and reply from the same address. |
| 500 | * Or else we can exhibit usual UDP ugliness: |
| 501 | * [ip1.multihomed.ip2] <= query to ip1 <= peer |
| 502 | * [ip1.multihomed.ip2] => reply from ip2 => peer (confused) */ |
| 503 | memcpy(to, lsa, lsa_size); |
| 504 | r = recv_from_to(udps, buf, MAX_PACK_LEN + 1, 0, &from->u.sa, &to->u.sa, lsa->len); |
| 505 | if (r < 12 || r > MAX_PACK_LEN) { |
Denis Vlasenko | ddbf3bf | 2009-04-12 04:09:09 +0000 | [diff] [blame] | 506 | bb_error_msg("packet size %d, ignored", r); |
Denis Vlasenko | d3bac03 | 2007-03-24 12:13:04 +0000 | [diff] [blame] | 507 | continue; |
Denis Vlasenko | 2c91652 | 2007-01-12 14:57:37 +0000 | [diff] [blame] | 508 | } |
Denis Vlasenko | 081eb71 | 2008-03-17 09:02:21 +0000 | [diff] [blame] | 509 | if (OPT_verbose) |
| 510 | bb_info_msg("Got UDP packet"); |
| 511 | buf[r] = '\0'; /* paranoia */ |
Denis Vlasenko | a19e649 | 2009-03-11 14:40:00 +0000 | [diff] [blame] | 512 | r = process_packet(conf_data, conf_ttl, buf); |
Denis Vlasenko | d3bac03 | 2007-03-24 12:13:04 +0000 | [diff] [blame] | 513 | if (r <= 0) |
| 514 | continue; |
Denis Vlasenko | e9b76e1 | 2008-05-22 17:41:01 +0000 | [diff] [blame] | 515 | send_to_from(udps, buf, r, 0, &from->u.sa, &to->u.sa, lsa->len); |
Denis Vlasenko | 2c91652 | 2007-01-12 14:57:37 +0000 | [diff] [blame] | 516 | } |
Denis Vlasenko | b5b45a9 | 2007-03-24 13:09:07 +0000 | [diff] [blame] | 517 | return 0; |
"Vladimir N. Oleynik" | 7b4aa6f | 2006-01-25 14:19:11 +0000 | [diff] [blame] | 518 | } |