Skip to content

Instantly share code, notes, and snippets.

@DRiKE
DRiKE / xdp1-5-udp_dns_reply.c
Last active Jul 16, 2020
XDP blog, post 1 gist 5
View xdp1-5-udp_dns_reply.c
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;
View xdp1-6-udp_dns_reply-part2.c
// 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 Jul 16, 2020
XDP blog, post 1 gist 7
View xdp1-7-dns_says_no_final.c
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)