local data PTR shorthand.

git-svn-id: file:///svn/unbound/trunk@1277 be551aaa-1e26-0410-a405-d3ace91eadb9
This commit is contained in:
Wouter Wijngaards 2008-09-30 15:04:32 +00:00
parent 3385bcc255
commit 896e4fea2a
11 changed files with 1061 additions and 896 deletions

View file

@ -6,6 +6,7 @@
- when using stub on localhost (127.0.0.1@10053) unbound works.
Like when running NSD to host a local zone, on the same machine.
The noprime feature. manpages more explanation. Added a test for it.
- shorthand for reverse PTR, local-data-ptr: "1.2.3.4 www.ex.com"
29 September 2008: Wouter
- EDNS lameness detection, if EDNS packets are dropped this is

View file

@ -368,6 +368,11 @@ server:
# (this makes example.com, www.example.com, etc, all go to 192.0.2.3)
# local-zone: "example.com" redirect
# local-data: "example.com A 192.0.2.3"
#
# Shorthand to make PTR records, "IPv4 name" or "IPv6 name".
# You can also add PTR records using local-data directly, but then
# you need to do the reverse notation yourself.
# local-data-ptr: "192.0.2.3 www.example.com"
# Remote control config section.
remote-control:

View file

@ -67,9 +67,9 @@ not stats on SIGUSR1. perhaps also see which slow auth servers cause >1sec value
* negative caching to avoid DS queries, NSEC, NSEC3 (w params).
+ SHA256 supported fully.
+ Make stub to localhost on different port work.
* IPv6 reverse, IP4 reverse local-data shorthand for PTR records (?).
+ IPv6 reverse, IP4 reverse local-data shorthand for PTR records (?).
cumbersome to reverse notate by hand for the operator. For local-data.
local-reverse-data: "1.2.3.4 mypc.example.com"
local-data-ptr: "1.2.3.4 mypc.example.com"
* dns-0x20 fallback TODO item. Consider.
*** from draft resolver-mitigation

View file

@ -674,6 +674,11 @@ local\-data: 'example. TXT "text"'.
If you need more complicated authoritative data, with referrals, wildcards,
CNAME/DNAME support, or DNSSEC authoritative service, setup a stub\-zone for
it as detailed in the stub zone section below.
.TP 5
.B local\-data\-ptr: \fI"IPaddr name"
Configure local data shorthand for a PTR record with the reversed IPv4 or
IPv6 address and the host name. For example "192.0.2.4 www.example.com".
TTL can be inserted like this: "2001:DB8::4 7200 www.example.com"
.SS "Remote Control Options"
In the
.B remote\-control:

View file

@ -890,3 +890,104 @@ fname_after_chroot(const char* fname, struct config_file* cfg, int use_chdir)
return buf;
}
/** return next space character in string */
static char* next_space_pos(char* str)
{
char* sp = strchr(str, ' ');
char* tab = strchr(str, '\t');
if(!tab && !sp)
return NULL;
if(!sp) return tab;
if(!tab) return sp;
return (sp<tab)?sp:tab;
}
/** return last space character in string */
static char* last_space_pos(char* str)
{
char* sp = strrchr(str, ' ');
char* tab = strrchr(str, '\t');
if(!tab && !sp)
return NULL;
if(!sp) return tab;
if(!tab) return sp;
return (sp>tab)?sp:tab;
}
char* cfg_ptr_reverse(char* str)
{
char* ip, *ip_end;
char* name;
char* result;
char buf[1024];
struct sockaddr_storage addr;
socklen_t addrlen;
/* parse it as: [IP] [between stuff] [name] */
ip = str;
while(*ip && isspace(*ip))
ip++;
if(!*ip) {
log_err("syntax error: too short: %s", str);
return NULL;
}
ip_end = next_space_pos(ip);
if(!ip_end || !*ip_end) {
log_err("syntax error: expected name: %s", str);
return NULL;
}
name = last_space_pos(ip_end);
if(!name || !*name) {
log_err("syntax error: expected name: %s", str);
return NULL;
}
sscanf(ip, "%100s", buf);
buf[sizeof(buf)-1]=0;
if(!ipstrtoaddr(buf, UNBOUND_DNS_PORT, &addr, &addrlen)) {
log_err("syntax error: cannot parse address: %s", str);
return NULL;
}
/* reverse IPv4:
* ddd.ddd.ddd.ddd.in-addr-arpa.
* IPv6: (h.){32}.ip6.arpa. */
if(addr_is_ip6(&addr, addrlen)) {
struct in6_addr* ad = &((struct sockaddr_in6*)&addr)->sin6_addr;
char* hex = "0123456789abcdef";
char *p = buf;
int i;
for(i=15; i>=0; i--) {
uint8_t b = ((uint8_t*)ad)[i];
*p++ = hex[ (b&0x0f) ];
*p++ = '.';
*p++ = hex[ (b&0xf0) >> 4 ];
*p++ = '.';
}
snprintf(buf+16*4, sizeof(buf)-16*4, "ip6.arpa. ");
} else {
struct in_addr* ad = &((struct sockaddr_in*)&addr)->sin_addr;
snprintf(buf, sizeof(buf), "%u.%u.%u.%u.in-addr.arpa. ",
(unsigned)((uint8_t*)ad)[3], (unsigned)((uint8_t*)ad)[2],
(unsigned)((uint8_t*)ad)[1], (unsigned)((uint8_t*)ad)[0]);
}
/* printed the reverse address, now the between goop and name on end */
while(*ip_end && isspace(*ip_end))
ip_end++;
if(name>ip_end) {
snprintf(buf+strlen(buf), sizeof(buf)-strlen(buf), "%.*s",
(int)(name-ip_end), ip_end);
}
snprintf(buf+strlen(buf), sizeof(buf)-strlen(buf), " PTR %s", name);
result = strdup(buf);
if(!result) {
log_err("out of memory parsing %s", str);
return NULL;
}
return result;
}

View file

@ -421,6 +421,13 @@ int cfg_scan_ports(int* avail, int num);
char* fname_after_chroot(const char* fname, struct config_file* cfg,
int use_chdir);
/**
* Convert a ptr shorthand into a full reverse-notation PTR record.
* @param str: input string, "IP name"
* @return: malloced string "reversed-ip-name PTR name"
*/
char* cfg_ptr_reverse(char* str);
/**
* Used during options parsing
*/

File diff suppressed because it is too large Load diff

View file

@ -182,6 +182,7 @@ val-nsec3-keysize-iterations{COLON} { YDOUT; return VAR_VAL_NSEC3_KEYSIZE_ITERAT
use-syslog{COLON} { YDOUT; return VAR_USE_SYSLOG;}
local-zone{COLON} { YDOUT; return VAR_LOCAL_ZONE;}
local-data{COLON} { YDOUT; return VAR_LOCAL_DATA;}
local-data-ptr{COLON} { YDOUT; return VAR_LOCAL_DATA_PTR;}
statistics-interval{COLON} { YDOUT; return VAR_STATISTICS_INTERVAL;}
statistics-cumulative{COLON} { YDOUT; return VAR_STATISTICS_CUMULATIVE;}
extended-statistics{COLON} { YDOUT; return VAR_EXTENDED_STATISTICS;}

File diff suppressed because it is too large Load diff

View file

@ -132,7 +132,8 @@
VAR_SERVER_CERT_FILE = 348,
VAR_CONTROL_KEY_FILE = 349,
VAR_CONTROL_CERT_FILE = 350,
VAR_EXTENDED_STATISTICS = 351
VAR_EXTENDED_STATISTICS = 351,
VAR_LOCAL_DATA_PTR = 352
};
#endif
/* Tokens. */
@ -230,6 +231,7 @@
#define VAR_CONTROL_KEY_FILE 349
#define VAR_CONTROL_CERT_FILE 350
#define VAR_EXTENDED_STATISTICS 351
#define VAR_LOCAL_DATA_PTR 352
@ -241,7 +243,7 @@ typedef union YYSTYPE
char* str;
}
/* Line 1489 of yacc.c. */
#line 245 "util/configparser.h"
#line 247 "util/configparser.h"
YYSTYPE;
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
# define YYSTYPE_IS_DECLARED 1

View file

@ -95,7 +95,7 @@ extern struct config_parser_state* cfg_parser;
%token VAR_PRIVATE_DOMAIN VAR_REMOTE_CONTROL VAR_CONTROL_ENABLE
%token VAR_CONTROL_INTERFACE VAR_CONTROL_PORT VAR_SERVER_KEY_FILE
%token VAR_SERVER_CERT_FILE VAR_CONTROL_KEY_FILE VAR_CONTROL_CERT_FILE
%token VAR_EXTENDED_STATISTICS
%token VAR_EXTENDED_STATISTICS VAR_LOCAL_DATA_PTR
%%
toplevelvars: /* empty */ | toplevelvars toplevelvar ;
@ -140,7 +140,8 @@ content_server: server_num_threads | server_verbosity | server_port |
server_outgoing_port_permit | server_outgoing_port_avoid |
server_dlv_anchor_file | server_dlv_anchor | server_neg_cache_size |
server_harden_referral_path | server_private_address |
server_private_domain | server_extended_statistics
server_private_domain | server_extended_statistics |
server_local_data_ptr
;
stubstart: VAR_STUB_ZONE
{
@ -831,6 +832,21 @@ server_local_data: VAR_LOCAL_DATA STRING
fatal_exit("out of memory adding local-data");
}
;
server_local_data_ptr: VAR_LOCAL_DATA_PTR STRING
{
char* ptr;
OUTYY(("P(server_local_data_ptr:%s)\n", $2));
ptr = cfg_ptr_reverse($2);
free($2);
if(ptr) {
if(!cfg_strlist_insert(&cfg_parser->cfg->
local_data, ptr))
fatal_exit("out of memory adding local-data");
} else {
yyerror("local-data-ptr could not be reversed");
}
}
;
stub_name: VAR_NAME STRING
{
OUTYY(("P(name:%s)\n", $2));