Skip to content

Commit

Permalink
Indicate packet parsing error on return
Browse files Browse the repository at this point in the history
  • Loading branch information
mozzieongit committed Oct 11, 2024
1 parent ee3aac0 commit 9e49b30
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions xdp-server.c
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ process_packet(struct xdp_server *xdp, uint8_t *pkt,
* a udp header.
*/
if (*len < (sizeof(*eth) + sizeof(struct iphdr) + sizeof(*udp)))
return 0;
return -1;

data_before_dnshdr_len = sizeof(*eth) + sizeof(*udp);

Expand All @@ -706,28 +706,28 @@ process_packet(struct xdp_server *xdp, uint8_t *pkt,
ipv6 = (struct ipv6hdr *)(eth + 1);

if (*len < (sizeof(*eth) + sizeof(*ipv6) + sizeof(*udp)))
return 0;
return -2;
if (!(udp = parse_ipv6(ipv6)))
return 0;
return -3;

dnslen -= (uint32_t) (sizeof(*eth) + sizeof(*ipv6) + sizeof(*udp));
data_before_dnshdr_len += sizeof(*ipv6);

if (!dest_ip_allowed6(xdp, ipv6))
return 0;
return -4;

break;
} case ETH_P_IP: {
ipv4 = (struct iphdr *)(eth + 1);

if (!(udp = parse_ipv4(ipv4)))
return 0;
return -5;

dnslen -= (uint32_t) (sizeof(*eth) + sizeof(*ipv4) + sizeof(*udp));
data_before_dnshdr_len += sizeof(*ipv4);

if (!dest_ip_allowed4(xdp, ipv4))
return 0;
return -6;

break;
}
Expand All @@ -737,11 +737,11 @@ process_packet(struct xdp_server *xdp, uint8_t *pkt,
/* if (*len < (sizeof(*eth) + sizeof(*vlan))) */
/* break; */
default:
return 0;
return -7;
}

if (!(dnshdr = parse_udp(udp)))
return 0;
return -8;

query_set_buffer_data(query, dnshdr, XDP_FRAME_SIZE - data_before_dnshdr_len);

Expand All @@ -768,7 +768,7 @@ process_packet(struct xdp_server *xdp, uint8_t *pkt,

dnslen = parse_dns(xdp->nsd, dnslen, query);
if (!dnslen) {
return 0;
return -9;
}

// should the packet be too long in the end... well...
Expand Down

0 comments on commit 9e49b30

Please sign in to comment.