Commit Diff
Diff:
8084b28461b5160fbab4de7fc89e81936fa2776c
54f6b64563368fb31c5a1ce93f96ee5886584c40
Commit:
54f6b64563368fb31c5a1ce93f96ee5886584c40
Tree:
e1b94178db0ab3f4a6f62e00f23a83bf17d5771d
Author:
pjp <pjp@delphinusdns.org>
Committer:
pjp <pjp@delphinusdns.org>
Date:
Mon Jul 13 22:02:26 2020 UTC
Message:
this makes my Linux work. Tested on OpenBSD/amd64 and Linux Raspberry Pi
blob - 39e0fc62dd0afbd45ca97b3c0ee6bf385711649d
blob + fe7e8046960fccca23785a0d72dae8c3e239827c
--- additional.c
+++ additional.c
@@ -27,7 +27,7 @@
*/
/*
- * $Id: additional.c,v 1.37 2020/07/06 07:17:40 pjp Exp $
+ * $Id: additional.c,v 1.38 2020/07/13 22:02:26 pjp Exp $
*/
#include <sys/types.h>
@@ -421,6 +421,9 @@ additional_tsig(struct question *question, char *reply
char tsigkey[512];
time_t now;
static int priordigest = 1;
+#ifdef __linux__
+ uint64_t tmp64;
+#endif
pseudo_packet = malloc(replylen);
if (pseudo_packet == NULL) {
@@ -428,6 +431,9 @@ additional_tsig(struct question *question, char *reply
}
now = time(NULL);
+#ifdef __linux__
+ tmp64 = now;
+#endif
rollback = offset;
if (envelope > 1 || envelope < -1) {
@@ -528,12 +534,20 @@ additional_tsig(struct question *question, char *reply
answer = (struct dns_tsigrr *)&reply[offset];
if (envelope > 1 || envelope < -1) {
+#ifdef __linux__
+ answer->timefudge = htobe64(((u_int64_t)tmp64 << 16) | (DEFAULT_TSIG_FUDGE & 0xffff));
+#else
answer->timefudge = htobe64(((u_int64_t)now << 16) | (DEFAULT_TSIG_FUDGE & 0xffff));
+#endif
} else {
if (request == 0 || envelope == 1) {
answer->timefudge = question->tsig.tsig_timefudge;
} else {
+#ifdef __linux__
+ answer->timefudge = htobe64((tmp64 << 16) | (DEFAULT_TSIG_FUDGE & 0xffff));
+#else
answer->timefudge = htobe64((now << 16) | (DEFAULT_TSIG_FUDGE & 0xffff));
+#endif
}
}
@@ -568,7 +582,11 @@ additional_tsig(struct question *question, char *reply
if (request == 0 || envelope == 1)
ppanswer->timefudge = question->tsig.tsig_timefudge;
else
+#ifdef __linux__
+ ppanswer->timefudge = htobe64(((u_int64_t)tmp64 << 16) | (DEFAULT_TSIG_FUDGE & 0xffff));
+#else
ppanswer->timefudge = htobe64(((u_int64_t)now << 16) | (DEFAULT_TSIG_FUDGE & 0xffff));
+#endif
ppoffset += 8;
blob - 20040db9e79918db54f8cb4647619d764a03a9f5
blob + 27685aae297e26d22a9dc50894da389a24af338e
--- cache.c
+++ cache.c
@@ -27,12 +27,11 @@
*/
/*
- * $Id: cache.c,v 1.4 2020/07/12 20:23:37 pjp Exp $
+ * $Id: cache.c,v 1.5 2020/07/13 22:02:26 pjp Exp $
*/
#include <sys/types.h>
#include <sys/socket.h>
-#include <sys/queue.h>
#include <sys/uio.h>
#include <sys/select.h>
@@ -48,7 +47,6 @@
#include <syslog.h>
#include <unistd.h>
-#include <imsg.h>
#ifdef __linux__
#include <grp.h>
blob - 224012d7f096d27b87de1620bbce641a2ffbdb56
blob + 5a42309ba1b93b572c3a27e20fa6377ae61ab128
--- db.c
+++ db.c
@@ -27,13 +27,11 @@
*/
/*
- * $Id: db.c,v 1.21 2020/07/10 10:42:27 pjp Exp $
+ * $Id: db.c,v 1.22 2020/07/13 22:02:26 pjp Exp $
*/
#include <sys/types.h>
#include <sys/socket.h>
-#include <sys/queue.h>
-#include <sys/tree.h>
#include <netinet/in.h>
#include <arpa/inet.h>
blob - c9769ae530123003522a92d38929c44923aedf93
blob + a61da49abba2459b1350f9cba0d8db7fe42218de
--- delphinusdnsd.c
+++ delphinusdnsd.c
@@ -27,7 +27,7 @@
*/
/*
- * $Id: delphinusdnsd.c,v 1.123 2020/07/12 20:23:37 pjp Exp $
+ * $Id: delphinusdnsd.c,v 1.124 2020/07/13 22:02:26 pjp Exp $
*/
@@ -63,6 +63,8 @@
#include <time.h>
#ifdef __linux__
+#include <linux/bpf.h>
+#include <linux/filter.h>
#include <grp.h>
#define __USE_BSD 1
#include <endian.h>
@@ -189,6 +191,8 @@ void tcploop(struct cfg *, struct imsgbuf *, struct
void parseloop(struct cfg *, struct imsgbuf *);
struct imsgbuf * register_cortex(struct imsgbuf *, int);
void nomore_neurons(struct imsgbuf *);
+int bind_this_res(struct addrinfo *, int);
+int bind_this_pifap(struct ifaddrs *, int, int);
/* aliases */
@@ -619,49 +623,17 @@ main(int argc, char *argv[], char *environ[])
res = res0;
- if ((dup[i] = socket(res->ai_family, res->ai_socktype, res->ai_protocol)) < 0) {
- dolog(LOG_INFO, "dup socket: %s\n", strerror(errno));
- ddd_shutdown();
- exit(1);
- }
-
- on = 1;
- if (setsockopt(dup[i], SOL_SOCKET, SO_REUSEPORT,
- &on, sizeof(on)) < 0) {
- dolog(LOG_INFO, "setsockopt: %s\n", strerror(errno));
- }
-
- if (shutdown(dup[i], SHUT_RD) < 0) {
- dolog(LOG_INFO, "shutdown: %s\n", strerror(errno));
- ddd_shutdown();
- exit(1);
- }
+#ifdef __linux__
- if (bind(dup[i], res->ai_addr, res->ai_addrlen) < 0) {
- dolog(LOG_INFO, "bind: %s\n", strerror(errno));
- ddd_shutdown();
- exit(1);
- }
+ udp[i] = bind_this_res(res, 0);
+ dup[i] = bind_this_res(res, 0);
+#else
+ /* first dup, then udp */
+ dup[i] = bind_this_res(res, 1);
+ udp[i] = bind_this_res(res, 0);
+#endif
- if ((udp[i] = socket(res->ai_family, res->ai_socktype, res->ai_protocol)) < 0) {
- dolog(LOG_INFO, "socket: %s\n", strerror(errno));
- ddd_shutdown();
- exit(1);
- }
-
- on = 1;
- if (setsockopt(udp[i], SOL_SOCKET, SO_REUSEPORT,
- &on, sizeof(on)) < 0) {
- dolog(LOG_INFO, "setsockopt: %s\n", strerror(errno));
- }
-
- if (bind(udp[i], res->ai_addr, res->ai_addrlen) < 0) {
- dolog(LOG_INFO, "bind: %s\n", strerror(errno));
- ddd_shutdown();
- exit(1);
- }
-
if (res->ai_family == AF_INET) {
on = 1;
if (setsockopt(udp[i], IPPROTO_IP, IP_RECVTTL,
@@ -810,50 +782,15 @@ main(int argc, char *argv[], char *environ[])
continue;
}
- if ((dup[i] = socket(pifap->ifa_addr->sa_family, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
- dolog(LOG_INFO, "dup socket: %s\n", strerror(errno));
- ddd_shutdown();
- exit(1);
- }
+#if __linux__
+ udp[i] = bind_this_pifap(pifap, 0, salen);
+ dup[i] = bind_this_pifap(pifap, 0, salen);
+#else
+ /* first dup, then udp */
+ dup[i] = bind_this_pifap(pifap, 1, salen);
+ udp[i] = bind_this_pifap(pifap, 0, salen);
+#endif
- on = 1;
- if (setsockopt(dup[i], SOL_SOCKET, SO_REUSEPORT,
- &on, sizeof(on)) < 0) {
- dolog(LOG_INFO, "setsockopt: %s\n", strerror(errno));
- }
-
- if (shutdown(dup[i], SHUT_RD) < 0) {
- dolog(LOG_INFO, "shutdown: %s\n", strerror(errno));
- ddd_shutdown();
- exit(1);
- }
-
- if (bind(dup[i], (struct sockaddr *)pifap->ifa_addr, salen) < 0) {
- dolog(LOG_INFO, "bind: %s\n", strerror(errno));
- ddd_shutdown();
- exit(1);
- }
-
-
- if ((udp[i] = socket(pifap->ifa_addr->sa_family, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
- dolog(LOG_INFO, "socket: %s\n", strerror(errno));
- ddd_shutdown();
- exit(1);
- }
-
- on = 1;
- if (setsockopt(udp[i], SOL_SOCKET, SO_REUSEPORT,
- &on, sizeof(on)) < 0) {
- dolog(LOG_INFO, "setsockopt: %s\n", strerror(errno));
- }
-
-
- if (bind(udp[i], (struct sockaddr *)pifap->ifa_addr, salen) < 0) {
- dolog(LOG_INFO, "bind: %s\n", strerror(errno));
- ddd_shutdown();
- exit(1);
- }
-
if (pifap->ifa_addr->sa_family == AF_INET) {
on = 1;
if (setsockopt(udp[i], IPPROTO_IP, IP_RECVTTL,
@@ -933,6 +870,7 @@ main(int argc, char *argv[], char *environ[])
}
} /* if bflag? */
+
#if __OpenBSD__
if (unveil(DELPHINUS_RZONE_PATH, "rwc") < 0) {
perror("unveil");
@@ -1179,8 +1117,10 @@ main(int argc, char *argv[], char *environ[])
cfg->db = db;
/* shptr has no business in parse process */
+#if __OpenBSD__
minherit(cfg->shptr, cfg->shptrsize,
MAP_INHERIT_NONE);
+#endif
setproctitle("FORWARD engine");
forwardloop(db, cfg, ibuf, &cortex_ibuf);
@@ -1644,12 +1584,14 @@ mainloop(struct cfg *cfg, struct imsgbuf *ibuf)
}
/* shptr has no business in a tcp parse process */
if (forward) {
+#if __OpenBSD__
minherit(cfg->shptr, cfg->shptrsize,
MAP_INHERIT_NONE);
minherit(cfg->shptr2, cfg->shptr2size,
MAP_INHERIT_NONE);
minherit(cfg->shptr3, cfg->shptr3size,
MAP_INHERIT_NONE);
+#endif
}
setproctitle("TCP engine %d", cfg->pid);
@@ -1665,12 +1607,14 @@ mainloop(struct cfg *cfg, struct imsgbuf *ibuf)
/* shptr has no business in a udp parse process */
if (forward) {
+#if __OpenBSD__
minherit(cfg->shptr, cfg->shptrsize,
MAP_INHERIT_NONE);
minherit(cfg->shptr2, cfg->shptr2size,
MAP_INHERIT_NONE);
minherit(cfg->shptr3, cfg->shptr3size,
MAP_INHERIT_NONE);
+#endif
}
sforward = (struct sforward *)calloc(1, sizeof(struct sforward));
@@ -4334,4 +4278,115 @@ nomore_neurons(struct imsgbuf *cortex)
imsg_compose(cortex, IMSG_CRIPPLE_NEURON, 0, 0, -1, &desc, sizeof(int));
msgbuf_write(&cortex->w);
+}
+
+
+int
+bind_this_res(struct addrinfo *res, int shut)
+{
+ int on;
+ int so;
+
+ if ((so = socket(res->ai_family, res->ai_socktype, res->ai_protocol)) < 0) {
+ dolog(LOG_INFO, "socket: %s\n", strerror(errno));
+ ddd_shutdown();
+ exit(1);
+ }
+
+ on = 1;
+ if (setsockopt(so, SOL_SOCKET, SO_REUSEPORT,
+ &on, sizeof(on)) < 0) {
+ dolog(LOG_INFO, "setsockopt: %s\n", strerror(errno));
+ }
+
+ if (shut) {
+ if (shutdown(so, SHUT_RD) < 0) {
+ dolog(LOG_INFO, "shutdown: %s\n", strerror(errno));
+ ddd_shutdown();
+ exit(1);
+ }
+ }
+
+ if (bind(so, res->ai_addr, res->ai_addrlen) < 0) {
+ dolog(LOG_INFO, "bind: %s\n", strerror(errno));
+ ddd_shutdown();
+ exit(1);
+ }
+
+#ifdef __linux__
+ {
+ struct sock_filter code[] = {
+ BPF_STMT(BPF_RET+BPF_K, 0)
+ };
+
+ struct sock_fprog sfp = {
+ .len = 1,
+ .filter = code,
+ };
+
+ if (setsockopt(so, SOL_SOCKET, SO_ATTACH_REUSEPORT_CBPF,
+ &sfp, sizeof(sfp)) < 0) {
+ dolog(LOG_INFO, "bpf: %s\n", strerror(errno));
+ ddd_shutdown();
+ exit(1);
+ }
+ }
+#endif
+
+ return (so);
+}
+
+int
+bind_this_pifap(struct ifaddrs *pifap, int shut, int salen)
+{
+ int on;
+ int so;
+
+ if ((so = socket(pifap->ifa_addr->sa_family, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
+ dolog(LOG_INFO, "socket: %s\n", strerror(errno));
+ ddd_shutdown();
+ exit(1);
+ }
+
+ on = 1;
+ if (setsockopt(so, SOL_SOCKET, SO_REUSEPORT,
+ &on, sizeof(on)) < 0) {
+ dolog(LOG_INFO, "setsockopt: %s\n", strerror(errno));
+ }
+
+
+ if (shut) {
+ if (shutdown(so, SHUT_RD) < 0) {
+ dolog(LOG_INFO, "shutdown: %s\n", strerror(errno));
+ ddd_shutdown();
+ exit(1);
+ }
+ }
+
+ if (bind(so, (struct sockaddr *)pifap->ifa_addr, salen) < 0) {
+ dolog(LOG_INFO, "bind: %s\n", strerror(errno));
+ ddd_shutdown();
+ exit(1);
+ }
+#ifdef __linux__
+ {
+ struct sock_filter code[] = {
+ BPF_STMT(BPF_RET+BPF_K, 0),
+ };
+
+ struct sock_fprog sfp = {
+ .len = 1,
+ .filter = code,
+ };
+
+ if (setsockopt(so, SOL_SOCKET, SO_ATTACH_REUSEPORT_CBPF,
+ &sfp, sizeof(sfp)) < 0) {
+ dolog(LOG_INFO, "bpf: %s\n", strerror(errno));
+ ddd_shutdown();
+ exit(1);
+ }
+ }
+#endif
+
+ return (so);
}
blob - 28ee26a5e893ce0380ec9cbe40e04c50e6e0ea9c
blob + adb20cf5cddc290a0519f1e98a1a7e30e7b7d5ac
--- forward.c
+++ forward.c
@@ -27,12 +27,11 @@
*/
/*
- * $Id: forward.c,v 1.21 2020/07/12 20:23:37 pjp Exp $
+ * $Id: forward.c,v 1.22 2020/07/13 22:02:26 pjp Exp $
*/
#include <sys/types.h>
#include <sys/socket.h>
-#include <sys/queue.h>
#include <sys/uio.h>
#include <sys/select.h>
#include <sys/mman.h>
@@ -51,7 +50,6 @@
#include <unistd.h>
#include <fcntl.h>
-#include <imsg.h>
#ifdef __linux__
#include <grp.h>
@@ -1897,10 +1895,14 @@ fwdparseloop(struct imsgbuf *ibuf, struct imsgbuf *bib
ssize_t n, datalen;
int flags;
- fcntl(bibuf->fd, F_GETFL, &flags, sizeof(flags));
- flags |= O_NONBLOCK;
- if (fcntl(bibuf->fd, F_SETFL, &flags, sizeof(flags)) < 0) {
+ flags = fcntl(bibuf->fd, F_GETFL);
+ if (flags < 0) {
dolog(LOG_INFO, "fcntl: %s\n", strerror(errno));
+ } else {
+ flags |= O_NONBLOCK;
+ if (fcntl(bibuf->fd, F_SETFL, &flags, sizeof(flags)) < 0) {
+ dolog(LOG_INFO, "fcntl: %s\n", strerror(errno));
+ }
}
#if __OpenBSD__
blob - c0004b59b7cce99fbeb4cc9a404bbd466f882985
blob + 32f2b59bd2223f3e9f356d3cdf70fb68a576d89c
--- parse.y
+++ parse.y
@@ -21,7 +21,7 @@
*/
/*
- * $Id: parse.y,v 1.103 2020/07/08 12:29:02 pjp Exp $
+ * $Id: parse.y,v 1.104 2020/07/13 22:02:26 pjp Exp $
*/
%{
@@ -262,9 +262,6 @@ int drop_privs(char *, struct passwd *);
%token <v.string> IPV6
%token <v.string> SLASH
%token <v.string> QUOTEDSTRING
-%token <v.string> DESTINATION
-%token <v.string> INCOMINGTSIG
-%token <v.string> CACHE
%token <v.intval> NUMBER
@@ -1454,7 +1451,9 @@ forwardstatement : INCOMINGTSIG STRING SEMICOLON CRLF
inet_pton(AF_INET6, $2, &sin6->sin6_addr);
sin6->sin6_family = AF_INET6;
sin6->sin6_port = htons($4);
+#ifndef __linux__
sin6->sin6_len = sizeof(struct sockaddr_in6);
+#endif
insert_forward(AF_INET6, &sso, $4, $6);
} else {
inet_pton(AF_INET, $2, &sin->sin_addr);
repomaster@centroid.eu