Skip to content

Commit

Permalink
examples:dns_matching: fixed loop break condition
Browse files Browse the repository at this point in the history
The for loop was copying garbase characters after domain name.
Fixed this by adding correct terminating condition. Also removed
unnecessary code

Signed-off-by: Prashant Bhole <[email protected]>
  • Loading branch information
pbhole committed Sep 28, 2017
1 parent 3c40c02 commit 1e21149
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions examples/networking/dns_matching/dns_matching.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,6 @@ int dns_matching(struct __sk_buff *skb)
struct udp_t *udp = cursor_advance(cursor, sizeof(*udp));
if(udp->dport == 53){

// Our Cursor + the length of our udp packet - size of the udp header
// - the two 16bit values for QTYPE and QCLASS.
u8 *sentinel = cursor + udp->length - sizeof(*udp) - 4;

struct dns_hdr_t *dns_hdr = cursor_advance(cursor, sizeof(*dns_hdr));

// Do nothing if packet is not a request.
Expand All @@ -86,15 +82,17 @@ int dns_matching(struct __sk_buff *skb)
struct dns_char_t *c;
#pragma unroll
for(i = 0; i<255;i++){
if (cursor == sentinel) goto end; c = cursor_advance(cursor, 1); key.p[i] = c->c;
c = cursor_advance(cursor, 1);
if (c->c == 0)
break;
key.p[i] = c->c;
}
end:
{}

struct Leaf * lookup_leaf = cache.lookup(&key);

// If DNS name is contained in our map, drop packet.
if(lookup_leaf) {
bpf_trace_printk("Matched1\n");
return 0;
}
}
Expand Down

0 comments on commit 1e21149

Please sign in to comment.