Created
July 16, 2020 18:34
-
-
Save DRiKE/78aebd7630c31d6fb1b26a9e79f28f82 to your computer and use it in GitHub Desktop.
XDP blog, post 1 gist 6
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
// 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)) | |
return -1; | |
if (opt_rr->rdata_len == 0) | |
; /* pass */ | |
else if (c->pos + 1 > c->end) | |
return -1; | |
else if (((void *)&opt_rr->rdata_len - (void *)dns) % 2 == 1) { | |
uint16_t old1 = *(uint16_t *)(c->pos - 3); | |
uint16_t old2 = *(uint16_t *)(c->pos - 1); | |
opt_rr->rdata_len = 0; | |
update_checksum(&udp->check, old1, | |
*(uint16_t *)(c->pos - 3)); | |
update_checksum(&udp->check, old2, | |
*(uint16_t *)(c->pos - 1)); | |
} else { | |
uint16_t old_val = opt_rr->rdata_len; | |
opt_rr->rdata_len = 0; | |
update_checksum(&udp->check, old_val, 0); | |
} | |
} | |
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