Created
July 16, 2020 14:08
-
-
Save DRiKE/adec28bbdc11b99406eb9215e4e1a9b5 to your computer and use it in GitHub Desktop.
XDP blog, post 1 gist 2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct dnshdr { | |
uint16_t id; | |
union { | |
struct { | |
uint8_t rd : 1; | |
uint8_t tc : 1; | |
uint8_t aa : 1; | |
uint8_t opcode : 4; | |
uint8_t qr : 1; | |
uint8_t rcode : 4; | |
uint8_t cd : 1; | |
uint8_t ad : 1; | |
uint8_t z : 1; | |
uint8_t ra : 1; | |
} as_bits_and_pieces; | |
uint16_t as_value; | |
} flags; | |
uint16_t qdcount; | |
uint16_t ancount; | |
uint16_t nscount; | |
uint16_t arcount; | |
}; | |
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; | |
uint16_t old_val = dns->flags.as_value; | |
dns->flags.as_bits_and_pieces.ad = 0; | |
dns->flags.as_bits_and_pieces.qr = 1; | |
dns->flags.as_bits_and_pieces.rcode = RCODE_REFUSED; | |
update_checksum(&udp->check, old_val, dns->flags.as_value); | |
udp->dest = udp->source; | |
udp->source = __bpf_htons(DNS_PORT); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@Wqrld, these are just snippets (embedded in blog posts). Please checkout https://github.com/NLnetLabs/XDPeriments/ for the full code.