Skip to content

Instantly share code, notes, and snippets.

View ahupowerdns's full-sized avatar

bert hubert ahupowerdns

View GitHub Profile
@ahupowerdns
ahupowerdns / h2o-dnsdist.md
Last active June 7, 2018 13:52
H2O dnsdist usecase

h2o 2.2.5

So it is likely I am doing it wrong, or that I have unrealistic expectations.

The repo is: https://github.com/ahupowerdns/pdns/tree/dnsdist-doh The file with all the H2O in there: https://github.com/ahupowerdns/pdns/blob/dnsdist-doh/pdns/dnsdistdist/doh.cc

The model is that I register a handler (in register_handler). This receives DNS over HTTPS requests, in the function doh_handler, and forwards these queries to a DNS thread which does no h2o interactions. Crucially, it forwards the h2o_req_t pointer to that thread too.

This separate DNS thread does its thing, and then forwards the answer to yet another thread that receives DNS responses and feeds them back to h2o. This sender thread receives the h2o_req_t pointer that was originally sent from the doh_handler and uses it to send the response.

#include <algorithm>
#include <vector>
#include <parallel/algorithm>
using namespace std;
extern "C" int cmp(const void* a, const void* b)
{
return *(int*)a < *(int*)b;
}

dnsdist has a built-in cache that is 1) really fast 2) saves a lot of packets from being sent.

the recursor supports EDNS Client Subnet where it feeds part of the client IP address to authoritative servers, to get better answers

If the recursor is hidden behind dnsdist, dnsdist can be configured to send on part of the client IP address to the recursor. So ECS then gets used twice: once to the recursor, once to the authoritative server.

When this setup is enabled, the dnsdist cache contains packets with the ECS option on the question. This means the cache hitrate goes down tremendously, as it will only deliver 'hits' within the same /24 (say).

When ECS is enabled, most domains are still not ECS-variable. This means we have split up the cache into thousands of /24 shards for no good reason.

// g++ syncio.cc -o syncio -std=c++11
#include <iostream>
#include <thread>
#include <string>
#include <unistd.h>
using namespace std;
void theThread()
{
#!/bin/bash
for a in {1774..2080}
do for b in {0..6}
do
wget http://navigation-office.esa.int/products/gnss-products/$a/esr${a}$b.erp.Z
done
done
zcat esr20805.erp.Z | grep MJD > erp.csv
zcat *.Z | grep ^5 | sort -n >> erp.raw
fig, ax = plt.subplots()
xdata, ydata = [], []
hi, = plt.plot([], [], 'ro')
ax.grid()
Writer = animation.writers['ffmpeg']
writer = Writer(fps=7, metadata=dict(artist='bert hubert'), bitrate=2500)
def init():