Skip to content

Commit

Permalink
Fix go structs inconsistencies
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelesabella committed Sep 16, 2019
1 parent 451d91b commit a927b9e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
7 changes: 5 additions & 2 deletions ebpflowexport.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,11 @@ func event_handler (event ebpf_flow.EBPFevent) {
fmt.Printf("[%s:%d <-> %s:%d]",
event.Saddr.String(), event.Sport, event.Daddr.String(), event.Dport)

if(event.Docker != nil) {
fmt.Printf("[container_id: %s][name: %s]", event.Cgroup_id[:16], event.Docker.Dname)
if (event.Docker != nil) {
fmt.Printf("[container_id: %s][name: %s]", event.Container_id[:16], event.Docker.Name)
} else if (event.Kube != nil) {
fmt.Printf("[container_id: %s][name: %s][ns: %s][pod: %s]",
event.Container_id[:16], event.Kube.Name, event.Kube.Ns, event.Kube.Pod)
}
fmt.Printf("\n")
}
18 changes: 10 additions & 8 deletions go/ebpf_flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,12 @@ type TaskInfo struct {
}

type DockerInfo struct {
Dname string // Docker container name
Name string // Docker container name
}

type KubeInfo struct {
Pod string
Name string // Container name
Pod string // Container pod
Ns string // Kubernetes namespace
}

Expand All @@ -135,7 +136,7 @@ type EBPFevent struct {
Proc TaskInfo
Father TaskInfo

Cgroup_id string // Container identifier
Container_id string // Container identifier
// Both next fields are initializated to nil and populated only during preprocessing
Docker *DockerInfo
Kube *KubeInfo
Expand Down Expand Up @@ -219,32 +220,33 @@ func go_handleEvent(t_bpfctx unsafe.Pointer, t_data unsafe.Pointer, t_datalen C.
Dport: (uint16)(filled_event.dport),
Proc: c2TaskInfo(filled_event.proc),
Father: c2TaskInfo(filled_event.father),
Cgroup_id: C.GoString(&filled_event.cgroup_id[0]),
Container_id: C.GoString(&filled_event.container_id[0]),
}
if(filled_event.ip_version == 4) {
ipv4 := (*C.struct_ipv4_kernel_data)(unsafe.Pointer(&filled_event.event[0]))
ipv4 := (*C.struct_ipv4_addr_t)(unsafe.Pointer(&filled_event.addr[0]))
goevent.Saddr = make(net.IP, 4)
binary.LittleEndian.PutUint32(goevent.Saddr, (uint32)(ipv4.saddr))
goevent.Daddr = make(net.IP, 4)
binary.LittleEndian.PutUint32(goevent.Daddr, (uint32)(ipv4.daddr))
} else {
ipv6 := (*C.struct_ipv6_kernel_data)(unsafe.Pointer(&filled_event.event[0]))
ipv6 := (*C.struct_ipv6_addr_t)(unsafe.Pointer(&filled_event.addr[0]))
saddr := ([16]byte)(ipv6.saddr)
goevent.Saddr = net.ParseIP(string(saddr[:]))
daddr := ([16]byte)(ipv6.daddr)
goevent.Daddr = net.ParseIP(string(daddr[:]))
}

if(filled_event.docker.dname != nil) {
if(filled_event.docker.name != nil) {
goevent.Docker = &DockerInfo {
Dname: C.GoString(filled_event.docker.dname),
Name: C.GoString(filled_event.docker.name),
}
} else {
goevent.Docker = nil
}

if(filled_event.kube.pod != nil) {
goevent.Kube = &KubeInfo {
Name: C.GoString(filled_event.kube.name),
Pod: C.GoString(filled_event.kube.pod),
Ns: C.GoString(filled_event.kube.ns),
}
Expand Down

0 comments on commit a927b9e

Please sign in to comment.