Skip to content

Commit 9c2d07b

Browse files
author
Mario Macias
authored
Fix reported bytes (#14)
1 parent 3cef18a commit 9c2d07b

File tree

7 files changed

+65
-5
lines changed

7 files changed

+65
-5
lines changed

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ WORKDIR /opt/app-root/src
1616
# END OF LINES TO REMOVE
1717

1818
# Copy the go manifests and source
19+
COPY .git/ .git/
1920
COPY bpf/ bpf/
2021
COPY cmd/ cmd/
2122
COPY pkg/ pkg/

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,10 @@ make generate
3636
```
3737

3838
Tested in Fedora 35 and Red Hat Enterprise Linux 8.
39+
40+
## Known issues
41+
42+
## Extrenal Traffic in Openshift (OVN-Kubernetes CNI)
43+
44+
For egress traffic, you can see the source Pod metadata. For ingress traffic (e.g. an HTTP response),
45+
you see the destination **Host** metadata.

bpf/flow.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,22 @@ typedef __u64 u64;
1414
struct data_link {
1515
u8 src_mac[ETH_ALEN];
1616
u8 dst_mac[ETH_ALEN];
17-
};
17+
} __attribute__((packed));
1818

1919
// L3 network layer
2020
struct network {
2121
// todo: add protocol
2222
// todo: support ipv6
2323
u32 src_ip;
2424
u32 dst_ip;
25-
};
25+
} __attribute__((packed));
2626

2727
// L4 transport layer
2828
struct transport {
2929
u16 src_port;
3030
u16 dst_port;
3131
u8 protocol;
32-
};
32+
} __attribute__((packed));
3333

3434
// TODO: L5 session layer to bound flows to connections?
3535

examples/performance/deployment.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,10 @@ spec:
6767
value: call_error,cares_resolver,dns_resolver
6868
- name: GRPC_DNS_RESOLVER
6969
value: "ares"
70-
- name: FLOWS_TARGET
71-
value: "packet-counter:9999"
70+
- name: FLOWS_TARGET_HOST
71+
value: "packet-counter"
72+
- name: FLOWS_TARGET_PORT
73+
value: "9999"
7274
# resources:
7375
# limits:
7476
# cpu: "1000m"

pkg/ebpf/bpf_bpfeb.o

0 Bytes
Binary file not shown.

pkg/ebpf/bpf_bpfel.o

0 Bytes
Binary file not shown.

pkg/flow/record_test.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package flow
2+
3+
import (
4+
"bytes"
5+
"testing"
6+
7+
"github.com/stretchr/testify/assert"
8+
"github.com/stretchr/testify/require"
9+
)
10+
11+
func TestRecordBinaryEncoding(t *testing.T) {
12+
// Makes sure that we read the C *packed* flow structure according
13+
// to the order defined in bpf/flow.h
14+
fr, err := ReadFrom(bytes.NewReader([]byte{
15+
0x01, 0x02, // u16 protocol
16+
0x03, // u16 direction
17+
0x04, 0x05, 0x06, 0x07, 0x08, 0x09, // data_link: u8[6] src_mac
18+
0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, // data_link: u8[6] dst_mac
19+
0x06, 0x07, 0x08, 0x09, // network: u32 src_ip
20+
0x0a, 0x0b, 0x0c, 0x0d, // network: u32 dst_ip
21+
0x0e, 0x0f, // transport: u16 src_port
22+
0x10, 0x11, // transport: u16 dst_port
23+
0x12, // transport: u8protocol
24+
0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, // u64 bytes
25+
}))
26+
require.NoError(t, err)
27+
28+
assert.Equal(t, Record{
29+
rawRecord: rawRecord{
30+
key: key{
31+
Protocol: 0x0201,
32+
Direction: 0x03,
33+
DataLink: DataLink{
34+
SrcMac: MacAddr{0x04, 0x05, 0x06, 0x07, 0x08, 0x09},
35+
DstMac: MacAddr{0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f},
36+
},
37+
Network: Network{
38+
SrcAddr: 0x09080706,
39+
DstAddr: 0x0d0c0b0a,
40+
},
41+
Transport: Transport{
42+
SrcPort: 0x0f0e,
43+
DstPort: 0x1110,
44+
Protocol: 0x12,
45+
},
46+
},
47+
Bytes: 0x1a19181716151413,
48+
},
49+
}, *fr)
50+
}

0 commit comments

Comments
 (0)