Skip to content

Instantly share code, notes, and snippets.

@DRiKE
Created July 16, 2020 18:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DRiKE/06a98eabdbb5682a3c3bada84a8d300c to your computer and use it in GitHub Desktop.
Save DRiKE/06a98eabdbb5682a3c3bada84a8d300c to your computer and use it in GitHub Desktop.
XDP blog, post 1 gist 3
static __always_inline
uint8_t *parse_dname(struct cursor *c, uint8_t *pkt)
{
uint8_t *dname = c->pos;
int i;
for (i = 0; i < 128; i++) { /* Maximum 128 labels */
uint8_t o;
if (c->pos + 1 > c->end)
return 0;
o = *(uint8_t *)c->pos;
if ((o & 0xC0) == 0xC0) {
/* Compression label, Only back references! */
if ((o | 0x3F) >= (dname - pkt))
return 0;
/* Compression label is the last label of a dname. */
c->pos += 1;
break;
} else if (o & 0xC0)
/* Unknown label type */
return 0;
c->pos += o + 1;
if (!o)
break;
}
return dname;
}
@dtikhonov
Copy link

Should be o & 0x3F on line 16.

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