examples:dns_matching: fixed loop break condition
The for loop was copying garbase characters after domain name.
Fixed this by adding correct terminating condition. Also removed
unnecessary code
@@ -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.
@@ -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;
}
}
