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
5526c3db
Commit
5526c3db
authored
Jun 10, 2015
by
Brenden Blanco
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #45 from iovisor/yhs_dev
use 64bit ulonglong to represent mac address
parents
77b26e1a
5604fc8e
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
18 deletions
+9
-18
tests/cc/test_brb.c
tests/cc/test_brb.c
+6
-7
tests/cc/test_brb.py
tests/cc/test_brb.py
+3
-11
No files found.
tests/cc/test_brb.c
View file @
5526c3db
...
...
@@ -15,8 +15,10 @@ typedef struct bpf_dest {
u32
port_id
;
}
bpf_dest_t
;
// use u64 to represent eth_addr.
// maintain the structure though to indicate the semantics
typedef
struct
eth_addr
{
u
8
addr
[
6
]
;
u
64
addr
;
}
eth_addr_t
;
// Program table definitions for tail calls
...
...
@@ -115,7 +117,6 @@ static int br_common(struct __sk_buff *skb, int which_br) {
u32
tx_port_id
;
bpf_dest_t
*
dest_p
;
u32
index
,
*
rtrif_p
;
u64
mac_addr
;
if
(
skb
->
tc_index
==
0
)
{
skb
->
tc_index
=
1
;
...
...
@@ -128,11 +129,10 @@ static int br_common(struct __sk_buff *skb, int which_br) {
BEGIN
(
ethernet
);
PROTO
(
ethernet
)
{
mac_addr
=
bpf_htonll
(
ethernet
->
dst
);
_memcpy
(
dmac
.
addr
,
(
u8
*
)
&
mac_addr
+
2
,
6
);
dmac
.
addr
=
ethernet
->
dst
;
if
(
meta
.
prog_id
!=
0
)
{
/* send to the router */
if
(
dmac
.
addr
[
0
]
&
dmac
.
addr
[
1
]
&
dmac
.
addr
[
2
]
&
dmac
.
addr
[
3
]
&
dmac
.
addr
[
4
]
&
dmac
.
addr
[
5
]
==
0xff
)
{
if
(
dmac
.
addr
==
0xffffffffffffULL
)
{
index
=
0
;
if
(
which_br
==
1
)
rtrif_p
=
br1_rtr
.
lookup
(
&
index
);
...
...
@@ -181,8 +181,7 @@ static int br_common(struct __sk_buff *skb, int which_br) {
__u32
ifindex
=
*
rtrif_p
;
eth_addr_t
smac
;
mac_addr
=
bpf_htonll
(
ethernet
->
src
);
_memcpy
(
smac
.
addr
,
(
u8
*
)
&
mac_addr
+
2
,
6
);
smac
.
addr
=
ethernet
->
src
;
if
(
which_br
==
1
)
br1_mac_ifindex
.
update
(
&
smac
,
&
ifindex
);
else
...
...
tests/cc/test_brb.py
View file @
5526c3db
...
...
@@ -74,6 +74,7 @@ from time import sleep
from
unittest
import
main
,
TestCase
import
subprocess
import
commands
import
struct
arg1
=
sys
.
argv
.
pop
(
1
)
...
...
@@ -82,12 +83,7 @@ class Bpf_Dest(Structure):
(
"port_id"
,
c_uint
)]
class
Eth_Addr
(
Structure
):
_fields_
=
[(
"addr0"
,
c_ubyte
),
(
"addr1"
,
c_ubyte
),
(
"addr2"
,
c_ubyte
),
(
"addr3"
,
c_ubyte
),
(
"addr4"
,
c_ubyte
),
(
"addr5"
,
c_ubyte
)]
_fields_
=
[(
"addr"
,
c_ulonglong
)]
class
TestBPFSocket
(
TestCase
):
def
setup_vm_ns
(
self
,
ns
,
veth_in
,
veth_out
):
...
...
@@ -150,12 +146,10 @@ class TestBPFSocket(TestCase):
self
.
br1_dest
=
b
.
get_table
(
"br1_dest"
,
c_uint
,
Bpf_Dest
)
self
.
br1_mac
=
b
.
get_table
(
"br1_mac"
,
Eth_Addr
,
c_uint
)
self
.
br1_rtr
=
b
.
get_table
(
"br1_rtr"
,
c_uint
,
c_uint
)
self
.
br1_mac_ifindex
=
b
.
get_table
(
"br1_mac_ifindex"
,
Eth_Addr
,
c_uint
)
self
.
br2_dest
=
b
.
get_table
(
"br2_dest"
,
c_uint
,
Bpf_Dest
)
self
.
br2_mac
=
b
.
get_table
(
"br2_mac"
,
Eth_Addr
,
c_uint
)
self
.
br2_rtr
=
b
.
get_table
(
"br2_rtr"
,
c_uint
,
c_uint
)
self
.
br2_mac_ifindex
=
b
.
get_table
(
"br2_mac_ifindex"
,
Eth_Addr
,
c_uint
)
def
connect_ports
(
self
,
prog_id_pem
,
prog_id_br
,
curr_pem_pid
,
curr_br_pid
,
ip
,
br_dest_map
,
br_mac_map
,
...
...
@@ -167,9 +161,7 @@ class TestBPFSocket(TestCase):
ifindex
=
ip
.
link_lookup
(
ifname
=
ns_eth_out
)[
0
]
self
.
pem_port
.
update
(
c_uint
(
curr_pem_pid
),
c_uint
(
ifindex
))
self
.
pem_ifindex
.
update
(
c_uint
(
ifindex
),
c_uint
(
curr_pem_pid
))
mac1
=
vm_mac
.
split
(
':'
)
mac_addr
=
Eth_Addr
(
int
(
mac1
[
0
],
16
),
int
(
mac1
[
1
],
16
),
int
(
mac1
[
2
],
16
),
int
(
mac1
[
3
],
16
),
int
(
mac1
[
4
],
16
),
int
(
mac1
[
5
],
16
))
mac_addr
=
Eth_Addr
(
struct
.
unpack
(
'!Q'
,
"
\
0
\
0
"
+
vm_mac
.
replace
(
':'
,
''
).
decode
(
'hex'
))[
0
])
br_mac_map
.
update
(
mac_addr
,
c_uint
(
curr_br_pid
))
def
attach_filter
(
self
,
ip
,
ifname
,
fd
,
name
):
...
...
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