summaryrefslogtreecommitdiffstats
path: root/prog/6/daemon.c
diff options
context:
space:
mode:
Diffstat (limited to 'prog/6/daemon.c')
-rw-r--r--prog/6/daemon.c59
1 files changed, 47 insertions, 12 deletions
diff --git a/prog/6/daemon.c b/prog/6/daemon.c
index 849ebb3..a808487 100644
--- a/prog/6/daemon.c
+++ b/prog/6/daemon.c
@@ -10,7 +10,35 @@
#include <sys/types.h>
#include <resolv.h>
#include <errno.h>
-#define DEBUG 1
+#include <string.h>
+#include "functions.c"
+#include "conf.c"
+int write_ptr6c (FILE * stream, const struct ptr ptr6c) {
+ if (!fwrite(ptr6c.addr.s6_addr, sizeof ptr6c.addr.s6_addr, 1, stream))
+ return 1;
+ if (!fwrite(&ptr6c.ttl, sizeof ptr6c.ttl, 1, stream))
+ return 2;
+ if (fputs(ptr6c.hostname, stream) == EOF)
+ return 3;
+ fputc('\0', stream);
+ return 0;
+}
+int prune (struct config * config, const char * filename) {
+ FILE * file = fopen(filename, "w");
+ if (!filename) {
+ fprintf(stderr, "fopen(\"%s\", \"w\"): %s", filename, strerror(errno));
+ return 1;
+ }
+ int ret = 0;
+ for (struct trie * trie = config->trie; trie; trie = next(trie))
+ if (trie->type == ptr6c) {
+ if (((struct ptr *) trie->data)->ttl+60*48 >= timestamp())
+ ret += write_ptr6c(file, *((struct ptr *) trie->data));
+ else
+ free_trie_ptr(trie);
+ }
+ return ret;
+}
int handle (unsigned char * packet, int bytes) {
HEADER * header = (HEADER *) packet;
ns_msg handle;
@@ -31,30 +59,37 @@ int handle (unsigned char * packet, int bytes) {
return bytes;
}
ns_rr rr;
- if (ns_parserr(handle, ms_s_qd, 0, &rr) == -1) {
+ if (ns_parserr(&handle, ns_s_qd, 0, &rr) == -1) {
header->rcode = FORMERR;
return bytes;
}
-
+ return -1;
}
int main (int argc, char ** argv) {
if (argc != 3) {
fprintf(stderr, "%s port config\n"
- " port: 53 (UDP listening port) (configurable to allow many daemons)\n"
- " config: file name of the configuration file (use 6c to check syntax)\n"
- "creates PTR and AAAA records with on-the-fly method (RFC 8501, section 2.5)\n"
- "an example of records created for IPv6 2001:db8:1\n"
- " 1.0.[...].0.8.B.D.0.1.0.0.2.IP6.ARPA. 127800 IN PTR 1.0.[...].0.8.B.D.0.1.0.0.2.IP6.ARPA.\n"
- " 1.0.[...].0.8.B.D.0.1.0.0.2.IP6.ARPA. 127800 IN AAAA 2001:db8::1\n"
+ " port: 53 (TCP+UDP listening port) (configurable to allow many daemons)\n"
+ " TCP is only for inter-6d zone transfers, queries will not work over TCP\n"
+ " config: file name of the configuration file (check the example config for documentation)\n"
"more information:\n"
- " - SOA serial will be the number of days since 2023-08-06\n"
+ " - SOA serial will be the number of UTC/UNIX (not real) minutes since 2023-08-08 00:00 UTC\n"
" - refresh, retry and expire in SOA will have values conforming to standard, but\n"
" they are irrelevant, as potential 6d slaves are not real DNS slaves\n"
- " - negative cache TTL is 1337, this is irrelevant, as nxdomains aren't expected\n"
- " - to exit after reading and printing out the configuration, run %s dry <config>\n"
, argv[0]);
return 1;
}
+ struct config conf;
+ memset(&conf, 0, sizeof conf);
+ FILE * conf_output = stderr;
+ if (argv[1][0] == 'd')
+ conf_output = stdout;
+ int ret = config(&conf, argv[2], conf_output);
+ if (ret) {
+ fprintf(stderr, "error %d while parsing the configuration file!\n", ret);
+ return 9+ret;
+ }
+ if (argv[1][0] == 'd')
+ return 0;
int sock = socket(AF_INET6, SOCK_DGRAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0);
if (sock == -1) {
perror("socket(AF_INET6, SOCK_DGRAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0)");