Skip to content

Instantly share code, notes, and snippets.

@DRiKE
DRiKE / xdp1-5-udp_dns_reply.c
Last active July 16, 2020 18:33
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;
@DRiKE
DRiKE / xdp1-6-udp_dns_reply-part2.c
Created July 16, 2020 18:34
XDP blog, post 1 gist 6
// continuing:
if (dns->arcount) {
struct dns_rr *opt_rr;
uint8_t *opt_owner = c->pos;
opt_owner = c->pos;
if (++c->pos > c->end || *opt_owner
|| !(opt_rr = parse_dns_rr(c))
|| opt_rr->type != __bpf_htons(RR_TYPE_OPT))
@DRiKE
DRiKE / xdp1-7-dns_says_no_final.c
Created July 16, 2020 18:35
XDP blog, post 1 gist 7
static __always_inline
void csum_remove_data(uint32_t *csum, struct cursor *c, uint16_t len)
{
if (c->pos + len <= c->end) {
*csum = bpf_csum_diff(c->pos, len, 0, 0, *csum);
c->pos += len;
}
}
int xdp_dns_says_no(struct xdp_md *ctx)