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