Skip to content

Instantly share code, notes, and snippets.

@DRiKE
Last active July 16, 2020 18:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DRiKE/a91ab69dd1bc8ea9bc3e3d784bc3aafd to your computer and use it in GitHub Desktop.
Save DRiKE/a91ab69dd1bc8ea9bc3e3d784bc3aafd to your computer and use it in GitHub Desktop.
XDP blog, post 1 gist 5
static __always_inline
int udp_dns_reply(struct cursor *c)
{
struct udphdr *udp;
struct dnshdr *dns;
if (!(udp = parse_udphdr(c))|| udp->dest != __bpf_htons(DNS_PORT)
|| !(dns = parse_dnshdr(c)))
return -1;
uint8_t *qname;
struct dns_qrr *qrr;
if (dns->flags.as_bits_and_pieces.qr
|| dns->qdcount != __bpf_htons(1)
|| dns->ancount || dns->nscount
|| dns->arcount > __bpf_htons(1)
|| !(qname = parse_dname(c, (void *)dns))
|| !(qrr = parse_dns_qrr(c)))
return -1;
// we continue below
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment