Skip to content

Commit

Permalink
Merge pull request #1368 from pbhole/fix_dns_matching
Browse files Browse the repository at this point in the history
examples: fix dns_matching
  • Loading branch information
yonghong-song committed Oct 1, 2017
2 parents c5ca2a6 + 1e21149 commit 2a6a5c5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
18 changes: 8 additions & 10 deletions examples/networking/dns_matching/dns_matching.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ struct dns_char_t
} BPF_PACKET_HEADER;

struct Key {
unsigned char p[32];
unsigned char p[255];
};

struct Leaf {
Expand All @@ -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 @@ -84,17 +80,19 @@ int dns_matching(struct __sk_buff *skb)

u16 i = 0;
struct dns_char_t *c;
// This unroll worked not in latest BCC version.
for(u8 j = 0; i<255;i++){
if (cursor == sentinel) goto end; c = cursor_advance(cursor, 1); key.p[i++] = c->c;
#pragma unroll
for(i = 0; i<255;i++){
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
4 changes: 2 additions & 2 deletions examples/networking/dns_matching/dns_matching.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@


def encode_dns(name):
size = 32
if len(name) > 253:
size = 255
if len(name) > 255:
raise Exception("DNS Name too long.")
b = bytearray(size)
i = 0;
Expand Down

0 comments on commit 2a6a5c5

Please sign in to comment.