Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
bcc
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
bcc
Commits
2a6a5c51
Commit
2a6a5c51
authored
Sep 30, 2017
by
yonghong-song
Committed by
GitHub
Sep 30, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1368 from pbhole/fix_dns_matching
examples: fix dns_matching
parents
c5ca2a67
1e21149c
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
12 deletions
+10
-12
examples/networking/dns_matching/dns_matching.c
examples/networking/dns_matching/dns_matching.c
+8
-10
examples/networking/dns_matching/dns_matching.py
examples/networking/dns_matching/dns_matching.py
+2
-2
No files found.
examples/networking/dns_matching/dns_matching.c
View file @
2a6a5c51
...
@@ -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
;
}
}
}
}
...
...
examples/networking/dns_matching/dns_matching.py
View file @
2a6a5c51
...
@@ -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
)
>
25
3
:
if
len
(
name
)
>
25
5
:
raise
Exception
(
"DNS Name too long."
)
raise
Exception
(
"DNS Name too long."
)
b
=
bytearray
(
size
)
b
=
bytearray
(
size
)
i
=
0
;
i
=
0
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment