Skip to content

Commit

Permalink
examples:dns_matching: helper function for adding cache entry
Browse files Browse the repository at this point in the history
Makes it slightly easier to add more cache entries
  • Loading branch information
pbhole committed Oct 2, 2017
1 parent 2a6a5c5 commit 7436872
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions examples/networking/dns_matching/dns_matching.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ def encode_dns(name):

return (c_ubyte * size).from_buffer(b)


def add_cache_entry(cache, name):
key = cache.Key()
key.p = encode_dns(name)
leaf = cache.Leaf()
leaf.p = (c_ubyte * 4).from_buffer(bytearray(4))
cache[key] = leaf

# initialize BPF - load source code from http-parse-simple.c
bpf = BPF(src_file = "dns_matching.c", debug=0)
Expand All @@ -46,12 +51,8 @@ def encode_dns(name):
# Get the table.
cache = bpf.get_table("cache")

# Create first entry for foo.bar
key = cache.Key()
key.p = encode_dns("foo.bar")

leaf = cache.Leaf()
leaf.p = (c_ubyte * 4).from_buffer(bytearray(4))
cache[key] = leaf
# Add cache entries
add_cache_entry(cache, "foo.bar")
add_cache_entry(cache, "another.sample.domain")

bpf.trace_print()

0 comments on commit 7436872

Please sign in to comment.