Commit 2a6a5c51 authored by yonghong-song's avatar yonghong-song Committed by GitHub

Merge pull request #1368 from pbhole/fix_dns_matching

examples: fix dns_matching
parents c5ca2a67 1e21149c
...@@ -43,7 +43,7 @@ struct dns_char_t ...@@ -43,7 +43,7 @@ struct dns_char_t
} BPF_PACKET_HEADER; } BPF_PACKET_HEADER;
struct Key { struct Key {
unsigned char p[32]; unsigned char p[255];
}; };
struct Leaf { struct Leaf {
...@@ -70,10 +70,6 @@ int dns_matching(struct __sk_buff *skb) ...@@ -70,10 +70,6 @@ int dns_matching(struct __sk_buff *skb)
struct udp_t *udp = cursor_advance(cursor, sizeof(*udp)); struct udp_t *udp = cursor_advance(cursor, sizeof(*udp));
if(udp->dport == 53){ 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)); struct dns_hdr_t *dns_hdr = cursor_advance(cursor, sizeof(*dns_hdr));
// Do nothing if packet is not a request. // Do nothing if packet is not a request.
...@@ -84,17 +80,19 @@ int dns_matching(struct __sk_buff *skb) ...@@ -84,17 +80,19 @@ int dns_matching(struct __sk_buff *skb)
u16 i = 0; u16 i = 0;
struct dns_char_t *c; struct dns_char_t *c;
// This unroll worked not in latest BCC version. #pragma unroll
for(u8 j = 0; i<255;i++){ 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); struct Leaf * lookup_leaf = cache.lookup(&key);
// If DNS name is contained in our map, drop packet. // If DNS name is contained in our map, drop packet.
if(lookup_leaf) { if(lookup_leaf) {
bpf_trace_printk("Matched1\n");
return 0; return 0;
} }
} }
......
...@@ -11,8 +11,8 @@ import struct ...@@ -11,8 +11,8 @@ import struct
def encode_dns(name): def encode_dns(name):
size = 32 size = 255
if len(name) > 253: if len(name) > 255:
raise Exception("DNS Name too long.") raise Exception("DNS Name too long.")
b = bytearray(size) b = bytearray(size)
i = 0; i = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment