Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
XDP blog, post 1 gist 2
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;
}
@Wqrld

This comment has been minimized.

Copy link

@Wqrld Wqrld commented Mar 20, 2021

Is the code for parse_dnshdr public?

@DRiKE

This comment has been minimized.

Copy link
Owner Author

@DRiKE DRiKE commented Mar 23, 2021

@Wqrld, these are just snippets (embedded in blog posts). Please checkout https://github.com/NLnetLabs/XDPeriments/ for the full code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment