Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fixed compilation with modern systems, warnings removed, minor TCP bu…

…g fixed with practially no real world effects.
  • Loading branch information...
commit ed951b83e09e4652cf153f2b649d47e805fa855d 1 parent 071893d
Salvatore Sanfilippo authored
4 .gitignore
View
@@ -0,0 +1,4 @@
+.depend
+*.o
+yaku-ns
+getzone
2  assert.h
View
@@ -21,7 +21,7 @@
#define assert(x) \
do { \
if ((x) == 0) { \
- log(VERB_FORCE, \
+ ylog(VERB_FORCE, \
"assert failed: %s is false in %s at line %d\n", \
#x, __FILE__, __LINE__); \
abort(); \
24 axfr_out.c
View
@@ -75,7 +75,6 @@
#include <string.h>
#include <stdlib.h>
#include <signal.h>
-#include <wait.h>
#define AXFR_CLIENT_MAX 50
#define AXFR_CLIENT_TIMEOUT 120 /* At least 2 min, see RFC1034 */
@@ -132,7 +131,7 @@ int axfr_init(void)
} else {
struct in_addr tmp;
if (inet_aton(bindaddr, &tmp) == 0) {
- log(VERB_FORCE, "[axfr_init] bad IP address "
+ ylog(VERB_FORCE, "[axfr_init] bad IP address "
"for binding\n");
exit(1);
}
@@ -184,10 +183,11 @@ void tcp_handler(void)
{
HEADER *hdr;
byte tmp[2];
- byte request[512]; /* even under TCP we limit to 512 bytes */
+ char request[512]; /* even under TCP we limit to 512 bytes */
byte *data; /* points after the DNS header */
int data_size; /* data size left */
- int new, addrlen; /* the new socket fd and the accept addrlen */
+ socklen_t addrlen;
+ int new; /* new socket fd */
int query_count; /* question sections in the query */
unsigned int size; /* query size */
int retval, n_read;
@@ -213,14 +213,14 @@ void tcp_handler(void)
/* Check the ACL */
if (acl_check_axfr(straddr) == ACL_DENY) {
- log(VERB_MED, "AXFR: access denied to client %s-%d\n",
+ ylog(VERB_MED, "AXFR: access denied to client %s-%d\n",
straddr, ntohs(newsa.sin_port));
goto out;
}
/* Max number of clients reached? */
if (axfr_clients >= AXFR_CLIENT_MAX) {
- log(VERB_MED, "AXFR: too many AXFR clients, "
+ ylog(VERB_MED, "AXFR: too many AXFR clients, "
"access denied to %s-%d\n",
straddr, ntohs(newsa.sin_port));
goto out;
@@ -268,14 +268,14 @@ void tcp_handler(void)
hdr->opcode != 0)
goto child_out;
data_size = size;
- data = request + sizeof(HEADER);
+ data = (unsigned char*)request + sizeof(HEADER);
query_count = ntohs(hdr->qdcount);
if (query_count != 1)
goto child_out;
/* parse the query */
- retval = name_decode(data, data_size, request,
- &name, 1);
+ retval = name_decode(data, data_size,
+ (unsigned char*)request, &name, 1);
if (name == NULL)
goto child_out;
updatep(retval);
@@ -288,19 +288,19 @@ void tcp_handler(void)
/* The only two accepted requests under TCP are
* IN/AXFR and IN/SOA */
if (qclass == C_IN && qtype == T_AXFR) {
- log(VERB_LOW, "AXFR requested for (%s) from "
+ ylog(VERB_LOW, "AXFR requested for (%s) from "
"%s-%d\n", name, straddr,
ntohs(newsa.sin_port));
send_zone(hdr, request+sizeof(HEADER), retval+4,
name, new);
} else if (qclass == C_IN && qtype == T_SOA) {
- log(VERB_MED, "TCP IN SOA requested for (%s) from "
+ ylog(VERB_MED, "TCP IN SOA requested for (%s) from "
"%s-%d\n", name, straddr,
ntohs(newsa.sin_port));
send_soa(hdr, request+sizeof(HEADER), retval+4,
name, new);
} else {
- log(VERB_MED, "TCP unaccepted request (%s %s) "
+ ylog(VERB_MED, "TCP unaccepted request (%s %s) "
"from %s-%d\n",
qclass_to_str(qclass),
qtype_to_str(qtype),
4 cache.c
View
@@ -187,7 +187,7 @@ int cache_free_expired(void)
}
current = ht_value(&cache_table, index);
if (current->creat_timestamp + current->ttl <= (unsigned)now) {
- log(VERB_HIG, "Expired cache entry %s %s %s\n",
+ ylog(VERB_HIG, "Expired cache entry %s %s %s\n",
qtype_to_str(current->qtype),
qclass_to_str(current->qclass),
current->name);
@@ -217,7 +217,7 @@ struct cacheentry *cache_search_entry(char *name, int qclass, int qtype)
/* Expired? Free the entry and return NULL */
if (opt_cachenoexpire == 0 &&
cache->creat_timestamp + cache->ttl <= (unsigned)now) {
- log(VERB_HIG, "Expired cache entry %s %s %s\n",
+ ylog(VERB_HIG, "Expired cache entry %s %s %s\n",
qtype_to_str(cache->qtype),
qclass_to_str(cache->qclass),
cache->name);
42 config.c
View
@@ -145,10 +145,10 @@ int config_read(char *filename)
} else {
fp = fopen(filename, "r");
if (fp == NULL) {
- log(VERB_FORCE, "Can't open the config file %s\n",
+ ylog(VERB_FORCE, "Can't open the config file %s\n",
filename);
perror("fopen");
- log(VERB_FORCE, "Remember that you MUST "
+ ylog(VERB_FORCE, "Remember that you MUST "
"specify the absolute path\n");
exit(1);
}
@@ -170,8 +170,8 @@ int config_read(char *filename)
static void config_error(int linenum, char *line, char *errormsg)
{
- log(VERB_FORCE, "--\n`%s' at line %d\n", errormsg, linenum);
- log(VERB_FORCE, "%d: %s--\n", linenum, line);
+ ylog(VERB_FORCE, "--\n`%s' at line %d\n", errormsg, linenum);
+ ylog(VERB_FORCE, "%d: %s--\n", linenum, line);
exit(1);
}
@@ -190,9 +190,9 @@ static int op_include(int argc, char **argv)
if (securelevel >= 1)
return CERROR_PERM;
- log(VERB_HIG, "> include %s\n", argv[1]);
+ ylog(VERB_HIG, "> include %s\n", argv[1]);
config_read(argv[1]);
- log(VERB_HIG, "< end of inclusion of %s\n", argv[1]);
+ ylog(VERB_HIG, "< end of inclusion of %s\n", argv[1]);
return CERROR_SUCCESS;
}
@@ -206,7 +206,7 @@ static int op_forwarder(int argc, char **argv)
&forward_server[forward_server_count]) == 0)
return CERROR_BADIP;
opt_forward = 1;
- log(VERB_HIG, "(forwarding) external server: %s\n", argv[1]);
+ ylog(VERB_HIG, "(forwarding) external server: %s\n", argv[1]);
forward_server_count++;
/* accept responses from this external server */
acl_add_rule(argv[1], &acl_dns_allow_head, &acl_dns_allow_tail);
@@ -221,9 +221,9 @@ static int op_forward_max(int argc, char **argv)
if (forward_max <= 0) {
forward_max = 0;
opt_forward = 0;
- log(VERB_MED, "forwarding disabled\n");
+ ylog(VERB_MED, "forwarding disabled\n");
} else {
- log(VERB_HIG, "forwarding: max queue %d\n", forward_max);
+ ylog(VERB_HIG, "forwarding: max queue %d\n", forward_max);
}
return CERROR_SUCCESS;
}
@@ -236,7 +236,7 @@ static int op_forward_entry_timeout(int argc, char **argv)
if (forward_timeout <= 0) {
return CERROR_INVALID;
} else {
- log(VERB_HIG, "forwarding: entry timeout %d\n", forward_timeout);
+ ylog(VERB_HIG, "forwarding: entry timeout %d\n", forward_timeout);
}
return CERROR_SUCCESS;
}
@@ -249,7 +249,7 @@ static int op_forward_next_timeout(int argc, char **argv)
if (next_server_timeout < 0) {
return CERROR_INVALID;
} else {
- log(VERB_HIG, "forwarding: next server timeout %d\n",
+ ylog(VERB_HIG, "forwarding: next server timeout %d\n",
next_server_timeout);
}
return CERROR_SUCCESS;
@@ -263,9 +263,9 @@ static int op_cache_max(int argc, char **argv)
if (cache_max <= 0) {
cache_max = 0;
opt_cache = 0;
- log(VERB_MED, "cache: disabled\n");
+ ylog(VERB_MED, "cache: disabled\n");
} else {
- log(VERB_HIG, "cache: max size %d\n", cache_max);
+ ylog(VERB_HIG, "cache: max size %d\n", cache_max);
}
return CERROR_SUCCESS;
}
@@ -275,7 +275,7 @@ static int op_cache_minttl(int argc, char **argv)
ARG_UNUSED(argc)
cache_minttl = atoi(argv[1]);
- log(VERB_HIG, "cache: min TTL %d\n", cache_minttl);
+ ylog(VERB_HIG, "cache: min TTL %d\n", cache_minttl);
return CERROR_SUCCESS;
}
@@ -284,7 +284,7 @@ static int op_cache_maxttl(int argc, char **argv)
ARG_UNUSED(argc)
cache_maxttl = atoi(argv[1]);
- log(VERB_HIG, "cache: max TTL %d\n", cache_maxttl);
+ ylog(VERB_HIG, "cache: max TTL %d\n", cache_maxttl);
return CERROR_SUCCESS;
}
@@ -326,7 +326,7 @@ static int op_ttl(int argc, char **argv)
ARG_UNUSED(argc)
local_ttl = atoi(argv[1]);
- log(VERB_HIG, "> Time To Live is %u\n", local_ttl);
+ ylog(VERB_HIG, "> Time To Live is %u\n", local_ttl);
return CERROR_SUCCESS;
}
@@ -335,7 +335,7 @@ static int op_tcp_requests_for_connection(int argc, char **argv)
ARG_UNUSED(argc)
opt_tcp_requests_for_connection = atoi(argv[1]);
- log(VERB_HIG, "TCP requests for connection set to %d\n",
+ ylog(VERB_HIG, "TCP requests for connection set to %d\n",
opt_tcp_requests_for_connection);
return CERROR_SUCCESS;
}
@@ -346,13 +346,13 @@ static int op_class(int argc, char **argv)
if (!strcasecmp(argv[1], "IN")) {
local_class = C_IN;
- log(VERB_HIG, "> Class is IN\n");
+ ylog(VERB_HIG, "> Class is IN\n");
} else if (!strcasecmp(argv[1], "CHAOS")) {
local_class = C_CHAOS;
- log(VERB_HIG, "> Class is CHAOS\n");
+ ylog(VERB_HIG, "> Class is CHAOS\n");
} else if (!strcasecmp(argv[1], "ANY")) {
local_class = C_ANY;
- log(VERB_HIG, "> Class is ANY\n");
+ ylog(VERB_HIG, "> Class is ANY\n");
} else {
return CERROR_INVALID;
}
@@ -396,7 +396,7 @@ static int op_acl(int argc, char **argv)
return CERROR_BADACL;
}
acl_add_rule(argv[j], head, tail);
- log(VERB_HIG, "acl: loaded %s %s\n", argv[1], argv[j]);
+ ylog(VERB_HIG, "acl: loaded %s %s\n", argv[1], argv[j]);
}
return CERROR_SUCCESS;
}
89 core.c
View
@@ -60,11 +60,11 @@ static void initialize(void);
static void core(void);
static int scheduler(void);
static void packet_processor(byte *packet, unsigned int size,
- struct sockaddr *from, int fromlen);
+ struct sockaddr *from, socklen_t fromlen);
static void response_processor(byte *packet, unsigned int size,
- struct sockaddr *from, int fromlen);
+ struct sockaddr *from, socklen_t fromlen);
static void query_processor(byte *packet, unsigned int size,
- struct sockaddr *from, int fromlen);
+ struct sockaddr *from, socklen_t fromlen);
#ifdef PROFILING
unsigned long long get_clock(void)
@@ -162,7 +162,8 @@ int net_init(void)
{
struct sockaddr_in sa;
int retval;
- int size, optsize;
+ int size;
+ socklen_t optsize;
/* open the main UDP socket */
s = socket(AF_INET, SOCK_DGRAM, 0);
@@ -203,7 +204,7 @@ int net_init(void)
} else {
struct in_addr tmp;
if (inet_aton(bindaddr, &tmp) == 0) {
- log(VERB_FORCE, "[main] bad IP address to bind\n");
+ ylog(VERB_FORCE, "[main] bad IP address to bind\n");
return -1;
}
sa.sin_addr.s_addr = tmp.s_addr;
@@ -225,7 +226,7 @@ int security_init(void)
if (getuid() == 0) {
pw = getpwnam(safeuser);
if (!pw) {
- log(VERB_FORCE, "[main] getpwnam error, does user '%s' exist?\n",
+ ylog(VERB_FORCE, "[main] getpwnam error, does user '%s' exist?\n",
safeuser);
exit(1);
}
@@ -245,14 +246,14 @@ int security_init(void)
exit(1);
}
- log(VERB_MED, "switched to user '%s'\n", safeuser);
+ ylog(VERB_MED, "switched to user '%s'\n", safeuser);
}
return 0;
}
static void initialize(void)
{
- log(VERB_LOW, "DNS server started, verbosity set to %d\n",
+ ylog(VERB_LOW, "DNS server started, verbosity set to %d\n",
opt_verbose);
/* for the uptime */
@@ -286,20 +287,20 @@ static void initialize(void)
/* Net initialization */
if (net_init() == -1) {
- log(VERB_FORCE, "[initialize] Net initialization failed\n");
+ ylog(VERB_FORCE, "[initialize] Net initialization failed\n");
exit(1);
}
/* Initialize DNS over TCP for AXFR requests */
if (opt_axfr && axfr_init() == -1) {
- log(VERB_FORCE, "[initialize] failed initializing AXFR\n");
+ ylog(VERB_FORCE, "[initialize] failed initializing AXFR\n");
opt_axfr = 0;
/* This isn't fatail */
}
/* Security initialization */
if (security_init() == -1) {
- log(VERB_FORCE, "[initialize] Security initialization "
+ ylog(VERB_FORCE, "[initialize] Security initialization "
"failed\n");
exit(1);
}
@@ -316,7 +317,7 @@ static void initialize(void)
if (opt_logfile)
open_logfile(logfile);
- log(VERB_LOW, "Local resource records loaded\n");
+ ylog(VERB_LOW, "Local resource records loaded\n");
}
/* The DNS server main loop */
@@ -327,7 +328,7 @@ static void core(void)
while(1) {
int size;
struct sockaddr_in from;
- int fromlen;
+ socklen_t fromlen;
fd_set rfds;
struct timeval tv;
int t;
@@ -387,7 +388,7 @@ static void core(void)
continue;
}
statistic_received_packet++;
- DEBUG(log(VERB_DEBUG, "Packet received\n");)
+ DEBUG(ylog(VERB_DEBUG, "Packet received\n");)
packet_processor(packet, size, (struct sockaddr*)&from, fromlen);
}
@@ -447,14 +448,14 @@ static int scheduler(void)
unsigned int old_size = cache_table.size;
ht_resize(&cache_table);
- log(VERB_HIG, "Cache table resize (%u -> %u)\n",
+ ylog(VERB_HIG, "Cache table resize (%u -> %u)\n",
old_size, cache_table.size);
}
if (opt_forward) {
unsigned int old_size = forward_table.size;
ht_resize(&forward_table);
- log(VERB_HIG, "Forward table resize "
+ ylog(VERB_HIG, "Forward table resize "
"(%u -> %u)\n",
old_size, forward_table.size);
}
@@ -472,7 +473,7 @@ static int scheduler(void)
}
/* This function pass the control to the right function */
-static void packet_processor(byte *packet, unsigned int size, struct sockaddr *from, int fromlen)
+static void packet_processor(byte *packet, unsigned int size, struct sockaddr *from, socklen_t fromlen)
{
struct sockaddr_in *in = (struct sockaddr_in *) from;
char straddr[64];
@@ -481,7 +482,7 @@ static void packet_processor(byte *packet, unsigned int size, struct sockaddr *f
/* Check the ACL */
strlcpy(straddr, inet_ntoa(in->sin_addr), 64);
if (acl_check_dns(straddr) == ACL_DENY) {
- log(VERB_MED, "DNS Access denied to client %s-%d\n",
+ ylog(VERB_MED, "DNS Access denied to client %s-%d\n",
straddr, ntohs(in->sin_port));
send_udp_error(s, (struct sockaddr*) from,
fromlen, packet, size, ERR_REFUSED);
@@ -490,7 +491,7 @@ static void packet_processor(byte *packet, unsigned int size, struct sockaddr *f
/* SANITYCHECK: size is < of the DNS header size */
if (size < sizeof(HEADER)) {
- DEBUG(log(VERB_DEBUG, "Packet too short\n");)
+ DEBUG(ylog(VERB_DEBUG, "Packet too short\n");)
return;
}
@@ -509,20 +510,20 @@ static void packet_processor(byte *packet, unsigned int size, struct sockaddr *f
break;
case IQUERY: /* NOT IMPLEMENTED */
statistic_iquery_count++;
- DEBUG(log(VERB_DEBUG, "Iquery received\n");)
+ DEBUG(ylog(VERB_DEBUG, "Iquery received\n");)
send_udp_error(s, from, fromlen, packet, size, ERR_NOTIMPLEMENTED);
break;
case STATUS: /* NOT IMPLEMENTED */
- DEBUG(log(VERB_DEBUG, "Status query received\n");)
+ DEBUG(ylog(VERB_DEBUG, "Status query received\n");)
send_udp_error(s, from, fromlen, packet, size, ERR_NOTIMPLEMENTED);
break;
case NS_NOTIFY_OP: /* NOT IMPLEMENTED */
- DEBUG(log(VERB_DEBUG, "NS notify query received\n");)
+ DEBUG(ylog(VERB_DEBUG, "NS notify query received\n");)
send_udp_error(s, from, fromlen, packet, size, ERR_NOTIMPLEMENTED);
break;
default: /* reserved opcodes */
statistic_invalid_packet++;
- DEBUG(log(VERB_DEBUG, "Invalid or unsupported opcode\n");)
+ DEBUG(ylog(VERB_DEBUG, "Invalid or unsupported opcode\n");)
send_udp_error(s, from, fromlen, packet, size, ERR_FORMAT);
break;
}
@@ -535,7 +536,7 @@ static void packet_processor(byte *packet, unsigned int size, struct sockaddr *f
* the response to the original requester (the client), put
* this record in the cache and erase the entry in the forwarded
* requests table */
-static void response_processor(byte *packet, unsigned int size, struct sockaddr *from, int fromlen)
+static void response_processor(byte *packet, unsigned int size, struct sockaddr *from, socklen_t fromlen)
{
HEADER *hdr = (HEADER*) packet;
int id = ntohs(hdr->id), retval;
@@ -550,7 +551,7 @@ static void response_processor(byte *packet, unsigned int size, struct sockaddr
if (!opt_forward)
return;
- DEBUG(log(VERB_DEBUG, "Response received ID: %d\n", id);)
+ DEBUG(ylog(VERB_DEBUG, "Response received ID: %d\n", id);)
/* the shortest name `.' is 1 byte, + 4 for qtype/qclass = 5 bytes */
if (qdcount < 1 || data_size < 5)
@@ -574,7 +575,7 @@ static void response_processor(byte *packet, unsigned int size, struct sockaddr
qclass = (data[2] << 8) | data[3];
updatep(4);
- log(VERB_LOW, "%s,%d name server replied (%s %s %s ID:%d)\n",
+ ylog(VERB_LOW, "%s,%d name server replied (%s %s %s ID:%d)\n",
inet_ntoa(((struct sockaddr_in*)from)->sin_addr),
ntohs(((struct sockaddr_in*)from)->sin_port),
qtype_to_str(qtype), qclass_to_str(qclass), name, id);
@@ -582,7 +583,7 @@ static void response_processor(byte *packet, unsigned int size, struct sockaddr
/* saerch in the forward table */
p = forward_search(id, qtype, qclass, name, &index);
if (p != NULL) {
- DEBUG(log(VERB_DEBUG, "Previous response matches [%s %s %s]\n",
+ DEBUG(ylog(VERB_DEBUG, "Previous response matches [%s %s %s]\n",
p->name,
qtype_to_str(p->qtype),
qclass_to_str(p->qclass));)
@@ -598,9 +599,9 @@ static void response_processor(byte *packet, unsigned int size, struct sockaddr
* check for this condition. */
if (!cache_search_entry(p->name, p->qclass, p->qtype)) {
cache_add_entry(p, packet, size);
- log(VERB_HIG, "Previous response cached\n");
+ ylog(VERB_HIG, "Previous response cached\n");
} else {
- DEBUG(log(VERB_DEBUG, "Already in cache\n");)
+ DEBUG(ylog(VERB_DEBUG, "Already in cache\n");)
}
}
/* send the response to the client */
@@ -611,17 +612,17 @@ static void response_processor(byte *packet, unsigned int size, struct sockaddr
forward_free_by_index(index);
if (forward_count > 0)
forward_count--;
- DEBUG(log(VERB_DEBUG, "Response sent to client\n");)
+ DEBUG(ylog(VERB_DEBUG, "Response sent to client\n");)
return;
}
- DEBUG(log(VERB_DEBUG, "Response doesn't match\n");)
+ DEBUG(ylog(VERB_DEBUG, "Response doesn't match\n");)
free(name);
return;
invalid:
if(name) free(name);
statistic_invalid_packet++;
- DEBUG(log(VERB_DEBUG, "Response is an invalid DNS packet\n");)
+ DEBUG(ylog(VERB_DEBUG, "Response is an invalid DNS packet\n");)
}
/* count the number of occurrences of the char 'c' in the string 's' */
@@ -644,7 +645,7 @@ size_t strcount(char *s, int c)
* It searches in the cache, if the cache match it sends the response,
* otherwise forwards the request to the external DNS server and creates
* a new forwarded request entry. */
-static void query_processor(byte *packet, unsigned int size, struct sockaddr *from, int fromlen)
+static void query_processor(byte *packet, unsigned int size, struct sockaddr *from, socklen_t fromlen)
{
HEADER *hdr = (HEADER*) packet;
struct sockaddr_in *in = (struct sockaddr_in *) from;
@@ -663,7 +664,7 @@ static void query_processor(byte *packet, unsigned int size, struct sockaddr *fr
goto invalid;
/* Log a warning if the incoming DNS packet is truncated */
- DEBUG(if (hdr->tc) log(VERB_DEBUG, "Truncated packet\n");)
+ DEBUG(if (hdr->tc) ylog(VERB_DEBUG, "Truncated packet\n");)
/* answer only to the first query in the request */
if (query_count > 1)
@@ -683,7 +684,7 @@ static void query_processor(byte *packet, unsigned int size, struct sockaddr *fr
updatep(retval);
query_size = retval+4;
- DEBUG(log(VERB_DEBUG, "name: %s\n", name);)
+ DEBUG(ylog(VERB_DEBUG, "name: %s\n", name);)
/* Enough space for qtype and qclass? */
if (data_size < 4)
@@ -693,9 +694,9 @@ static void query_processor(byte *packet, unsigned int size, struct sockaddr *fr
qclass = (data[2] << 8) | data[3];
updatep(4);
- DEBUG(log(VERB_DEBUG, "(%s %s)\n",
+ DEBUG(ylog(VERB_DEBUG, "(%s %s)\n",
qtype_to_str(qtype), qclass_to_str(qclass));)
- log(VERB_LOW, "%s,%d asks for (%s %s %s)\n",
+ ylog(VERB_LOW, "%s,%d asks for (%s %s %s)\n",
inet_ntoa(((struct sockaddr_in*)from)->sin_addr),
ntohs(((struct sockaddr_in*)from)->sin_port),
qtype_to_str(qtype), qclass_to_str(qclass), name);
@@ -761,7 +762,7 @@ static void query_processor(byte *packet, unsigned int size, struct sockaddr *fr
dns_shuffle(response, response_size);
send_udp(s, response, response_size, from, fromlen);
free(response);
- DEBUG(log(VERB_DEBUG,
+ DEBUG(ylog(VERB_DEBUG,
"Response sent using local RRs\n");)
return;
}
@@ -770,7 +771,7 @@ static void query_processor(byte *packet, unsigned int size, struct sockaddr *fr
strlcpy(straddr, inet_ntoa(in->sin_addr), 64);
if (acl_check_fwd(straddr) == ACL_DENY) {
free(name);
- log(VERB_MED, "DNS forwarding Access denied to client %s-%d\n",
+ ylog(VERB_MED, "DNS forwarding Access denied to client %s-%d\n",
straddr, ntohs(in->sin_port));
send_udp_error(s, (struct sockaddr*) from,
fromlen, packet, size, ERR_NAME);
@@ -782,7 +783,7 @@ static void query_processor(byte *packet, unsigned int size, struct sockaddr *fr
if (opt_forward == 0) {
free(name);
send_udp_error(s, from, fromlen, packet, size, ERR_NAME);
- DEBUG(log(VERB_DEBUG, "No such RR\n");)
+ DEBUG(ylog(VERB_DEBUG, "No such RR\n");)
return;
} else {
struct cacheentry *cached;
@@ -801,15 +802,15 @@ static void query_processor(byte *packet, unsigned int size, struct sockaddr *fr
send_udp(s, cached->answer,
cached->answer_size, from,
fromlen);
- DEBUG(log(VERB_DEBUG,
+ DEBUG(ylog(VERB_DEBUG,
"Sent from cache\n");)
free(name);
return;
}
}
/* Forward the request to the first external server */
- forward_request(hdr, packet, size, from, name, qtype, qclass);
- DEBUG(log(VERB_DEBUG, "Previous forwarded\n");)
+ forward_request(hdr, (char*)packet, size, from, name, qtype, qclass);
+ DEBUG(ylog(VERB_DEBUG, "Previous forwarded\n");)
free(name);
return;
}
@@ -820,5 +821,5 @@ static void query_processor(byte *packet, unsigned int size, struct sockaddr *fr
if (name != NULL)
free(name);
send_udp_error(s, from, fromlen, packet, size, ERR_FORMAT);
- DEBUG(log(VERB_DEBUG, "Invalid DNS packet\n");)
+ DEBUG(ylog(VERB_DEBUG, "Invalid DNS packet\n");)
}
11 dns.c
View
@@ -533,15 +533,16 @@ int send_udp(int fd, void *packet, unsigned int size, struct sockaddr *to, int t
/* Send a TCP DNS response */
int send_tcp(byte *packet, int len, int sd)
{
- u_int16_t size = htons(len);
+ u_int16_t size;
int retval;
HEADER *hdr = (HEADER*) packet;
/* TCP truncation */
- if (size > TCPPACKETSZ) {
+ if (len > TCPPACKETSZ) {
len = TCPPACKETSZ;
hdr->tc = 1; /* truncation flag ON */
}
+ size = htons(len);
if (send(sd, &size, 2, 0) == -1) {
perror("[send_tcp] send");
@@ -569,7 +570,7 @@ static byte *get_qsection(byte *packet, unsigned int size, int *qsize)
goto out;
}
if (size < sizeof(HEADER)+retval+4) goto out;
- encoded = name_encode(name, &encoded_size, '.');
+ encoded = (char*)name_encode(name, &encoded_size, '.');
if (encoded == NULL) {
*qsize = encoded_size;
goto out;
@@ -585,7 +586,7 @@ static byte *get_qsection(byte *packet, unsigned int size, int *qsize)
free(encoded);
/* the caller must free qsection */
*qsize = encoded_size+4;
- return qsection;
+ return (byte*) qsection;
out:
free(name);
free(qsection);
@@ -815,7 +816,7 @@ byte *name_encode(char *msg, int *size, char sep)
while(1) {
p = strchr(p, sep);
- label_len = (p != NULL) ? (p - last) : strlen(last);
+ label_len = (p != NULL) ? (p - last) : (signed)strlen(last);
if (label_len == 0) { /* end of the name */
break;
} else if (label_len > MAXLABEL) { /* out of range label len */
4 ens.h
View
@@ -61,7 +61,7 @@
/* ---------------------------- macros -------------------------------------- */
/* ENS's perror */
-#define perror(x) log(VERB_FORCE, "%s: %s\n", x, strerror(errno))
+#define perror(x) ylog(VERB_FORCE, "%s: %s\n", x, strerror(errno))
/* A simple way to trace memory leaks -- sorry if it seems obfustated code :) */
#ifdef TRACE_LEAKS
@@ -389,7 +389,7 @@ void tcp_handler(void);
/*********
* log.c *
*********/
-int log(int level, char *fmt, ...);
+int ylog(int level, char *fmt, ...);
int log_flush(void);
void open_logfile(char *filename);
4 forward.c
View
@@ -197,7 +197,7 @@ void forward_free_expired(void)
}
f = ht_value(&forward_table, index);
if (now - f->timestamp > forward_timeout) {
- log(VERB_HIG, "Expired forwarded request %s %s %s, "
+ ylog(VERB_HIG, "Expired forwarded request %s %s %s, "
"ID:%d\n",
qtype_to_str(f->qtype),
qclass_to_str(f->qclass),
@@ -215,7 +215,7 @@ void forward_free_expired(void)
forward_addr.sin_port = htons(dns_forward_port);
forward_addr.sin_addr.s_addr =
forward_server[f->server_number].s_addr;
- DEBUG(log(VERB_FORCE, "ASK TO SERVER %d [%s %s %s]\n",
+ DEBUG(ylog(VERB_FORCE, "ASK TO SERVER %d [%s %s %s]\n",
f->server_number,
qtype_to_str(f->qtype),
qclass_to_str(f->qclass),
2  getzone.c
View
@@ -499,7 +499,7 @@ void remove_trailer_dot(char *name)
}
}
-int log(int level, char *fmt, ...)
+int ylog(int level, char *fmt, ...)
{
ARG_UNUSED(level);
ARG_UNUSED(fmt);
20 local.c
View
@@ -154,14 +154,14 @@ int local_add_entry(struct RRentry *rr)
return j;
oom:
- log(VERB_FORCE, "ht_add() failed adding a local"
+ ylog(VERB_FORCE, "ht_add() failed adding a local"
"Resource Record with exit code %d\n", ret);
exit(1);
}
-void local_log(struct RRentry *rr)
+void local_ylog(struct RRentry *rr)
{
- log(VERB_HIG, "loaded: %s %s %s\n",
+ ylog(VERB_HIG, "loaded: %s %s %s\n",
qtype_to_str(rr->qtype),
qclass_to_str(rr->qclass),
rr->name);
@@ -182,7 +182,7 @@ int local_add_A(char *name, char *addr)
return -1;
}
local_add_entry(rr);
- local_log(rr);
+ local_ylog(rr);
return 0;
}
@@ -204,7 +204,7 @@ int local_add_MX(char *name, char *priority, char *exchange)
memcpy(rr->data+2, enc_exchange, enc_exchange_size);
free(enc_exchange);
local_add_entry(rr);
- local_log(rr);
+ local_ylog(rr);
return 0;
}
@@ -222,7 +222,7 @@ int local_add_PTR(char *name, char *ptr)
memcpy(rr->data, enc_ptr, enc_ptr_size);
free(enc_ptr);
local_add_entry(rr);
- local_log(rr);
+ local_ylog(rr);
return 0;
}
@@ -240,7 +240,7 @@ int local_add_CNAME(char *name, char *canonical)
memcpy(rr->data, enc_cname, enc_cname_size);
free(enc_cname);
local_add_entry(rr);
- local_log(rr);
+ local_ylog(rr);
return 0;
}
@@ -258,7 +258,7 @@ int local_add_NS(char *name, char *ns)
memcpy(rr->data, enc_ns, enc_ns_size);
free(enc_ns);
local_add_entry(rr);
- local_log(rr);
+ local_ylog(rr);
return 0;
}
@@ -285,7 +285,7 @@ int local_add_TXT(char *argv[])
memcpy(rr->data, enc_txt, enc_txt_size);
free(enc_txt);
local_add_entry(rr);
- local_log(rr);
+ local_ylog(rr);
return 0;
}
@@ -320,7 +320,7 @@ int local_add_SOA(int argc, char **argv)
free(enc_dns);
free(enc_mailbox);
local_add_entry(rr);
- log(VERB_HIG, "loaded: SOA for %s\n"
+ ylog(VERB_HIG, "loaded: SOA for %s\n"
"\tdns : %s\n"
"\tmailbox: %s\n"
"\tserial : %lu\n"
4 log.c
View
@@ -21,12 +21,12 @@ int opt_logtime = 1;
int opt_verbose = 0;
/* exported functions */
-int log(int level, char *fmt, ...);
+int ylog(int level, char *fmt, ...);
int log_flush(void);
void open_logfile(char *filename);
/* Just log the printf-like message */
-int log(int level, char *fmt, ...)
+int ylog(int level, char *fmt, ...)
{
time_t t;
struct tm *tmtime;
2  misc.c
View
@@ -181,7 +181,7 @@ int line_splitter(char *buffer, char *commandargs[], int argmax)
void dump_state(void)
{
- log(VERB_FORCE,
+ ylog(VERB_FORCE,
"dump_state() requested, dump follows\n"
"\n-- GENERAL\n"
"s = %d\n"
4 nameser.h
View
@@ -247,8 +247,8 @@
#define CONV_BADCKSUM (-3)
#define CONV_BADBUFLEN (-4)
-/* glibc always has byte order info in <endian.h> */
-#include <endian.h>
+/* Include endianess info in mostly portable way */
+#include "yakuendian.h"
__BEGIN_DECLS
8 signal.c
View
@@ -33,12 +33,12 @@ void signal_handler(int signum)
signal_usr2++;
break;
case SIGSEGV:
- log(VERB_FORCE, "SIGSEGV trapped -- INTERNAL ERROR\n");
+ ylog(VERB_FORCE, "SIGSEGV trapped -- INTERNAL ERROR\n");
dump_state();
abort();
break;
default:
- log(VERB_FORCE, "Signal %d trapped: exit\n", signum);
+ ylog(VERB_FORCE, "Signal %d trapped: exit\n", signum);
exit(1);
}
install_signal_handler();
@@ -51,7 +51,7 @@ int handle_signals(void)
if (signal_up) {
signal_up--;
- log(VERB_LOW, "SIGHUP trapped: read the config file\n");
+ ylog(VERB_LOW, "SIGHUP trapped: read the config file\n");
config_reset();
config_read(configfile);
count++;
@@ -66,7 +66,7 @@ int handle_signals(void)
if (signal_usr2) {
signal_usr2--;
opt_forward = !opt_forward;
- log(VERB_LOW, "SIGUSR2 trapped, forwarding is %s\n",
+ ylog(VERB_LOW, "SIGUSR2 trapped, forwarding is %s\n",
opt_forward ? "ON" : "OFF");
fflush(logfp);
count++;
4 utils.h
View
@@ -29,7 +29,7 @@
* warning for unused function parameters when you use -W.
* This macro is better than -Wno-unused. We want all the
* other unused warnings */
-#define ARG_UNUSED(a) while(0) { if (&a) break; }
+#define ARG_UNUSED(a) ((void) a);
#ifndef MIN
#define MIN(x,y) ((x)<(y)?(x):(y))
@@ -47,7 +47,7 @@
#define yakuns_assert(x) \
do { \
if ((x) == 0) { \
- log(VERB_FORCE, \
+ ylog(VERB_FORCE, \
"assert failed: %s is false in %s at line %d\n", \
#x, __FILE__, __LINE__); \
abort(); \
53 yakuendian.h
View
@@ -0,0 +1,53 @@
+#ifndef __YAKUENDIAN_H
+#define __YAKUENDIAN_H
+
+#ifndef BYTE_ORDER
+#if (BSD >= 199103)
+# include <machine/endian.h>
+#else
+#if defined(linux) || defined(__linux__)
+# include <endian.h>
+#else
+#define LITTLE_ENDIAN 1234 /* least-significant byte first (vax, pc) */
+#define BIG_ENDIAN 4321 /* most-significant byte first (IBM, net) */
+#define PDP_ENDIAN 3412 /* LSB first in word, MSW first in long (pdp)*/
+
+#if defined(vax) || defined(ns32000) || defined(sun386) || defined(__i386__) || \
+ defined(MIPSEL) || defined(_MIPSEL) || defined(BIT_ZERO_ON_RIGHT) || \
+ defined(__alpha__) || defined(__alpha)
+#define BYTE_ORDER LITTLE_ENDIAN
+#endif
+
+#if defined(sel) || defined(pyr) || defined(mc68000) || defined(sparc) || \
+ defined(is68k) || defined(tahoe) || defined(ibm032) || defined(ibm370) || \
+ defined(MIPSEB) || defined(_MIPSEB) || defined(_IBMR2) || defined(DGUX) ||\
+ defined(apollo) || defined(__convex__) || defined(_CRAY) || \
+ defined(__hppa) || defined(__hp9000) || \
+ defined(__hp9000s300) || defined(__hp9000s700) || \
+ defined (BIT_ZERO_ON_LEFT) || defined(m68k) || defined(__sparc)
+#define BYTE_ORDER BIG_ENDIAN
+#endif
+#endif /* linux */
+#endif /* BSD */
+#endif /* BYTE_ORDER */
+
+#if defined(__BYTE_ORDER) && !defined(BYTE_ORDER)
+#if (__BYTE_ORDER == __LITTLE_ENDIAN)
+#define BYTE_ORDER LITTLE_ENDIAN
+#else
+#define BYTE_ORDER BIG_ENDIAN
+#endif
+#endif
+
+#if !defined(BYTE_ORDER) || \
+ (BYTE_ORDER != BIG_ENDIAN && BYTE_ORDER != LITTLE_ENDIAN && \
+ BYTE_ORDER != PDP_ENDIAN)
+ /* you must determine what the correct bit order is for
+ * your compiler - the next line is an intentional error
+ * which will force your compiles to bomb until you fix
+ * the above macros.
+ */
+#error "Undefined or invalid BYTE_ORDER"
+#endif
+
+#endif
Please sign in to comment.
Something went wrong with that request. Please try again.