Skip to content

Commit

Permalink
implement IP and port filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
pouriyajamshidi committed Nov 8, 2024
1 parent 8f04657 commit 25d838a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions internal/probe/probe.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/pouriyajamshidi/flat/clsact"
"github.com/pouriyajamshidi/flat/internal/flowtable"
"github.com/pouriyajamshidi/flat/internal/packet"
"github.com/pouriyajamshidi/flat/internal/types"
"github.com/vishvananda/netlink"
"golang.org/x/sys/unix"
)
Expand Down Expand Up @@ -180,7 +181,7 @@ func (p *probe) Close() error {

// Run attaches the probe, reads from the eBPF map
// as well as calculating and displaying the flow latencies
func Run(ctx context.Context, iface netlink.Link) error {
func Run(ctx context.Context, userInput types.UserInput) error {
log.Println("Starting up the probe")

if err := setRlimit(); err != nil {
Expand All @@ -196,7 +197,7 @@ func Run(ctx context.Context, iface netlink.Link) error {
}
}()

probe, err := newProbe(iface)
probe, err := newProbe(userInput.Interface)

if err != nil {
return err
Expand Down Expand Up @@ -235,7 +236,16 @@ func Run(ctx context.Context, iface netlink.Link) error {
log.Printf("Could not unmarshall packet: %+v", pkt)
continue
}
packet.CalcLatency(packetAttrs, flowtable)
if !userInput.IP.IsValid() && userInput.Port == 0 {
packet.CalcLatency(packetAttrs, flowtable)
// FIXME:
// } else if (userInput.Port == packetAttrs.DstPort || userInput.Port == packetAttrs.SrcPort) && (userInput.IP == packetAttrs.DstIP.Unmap() || userInput.IP == packetAttrs.SrcIP.Unmap()) {
// packet.CalcLatency(packetAttrs, flowtable)
} else if userInput.IP == packetAttrs.DstIP.Unmap() || userInput.IP == packetAttrs.SrcIP.Unmap() {
packet.CalcLatency(packetAttrs, flowtable)
} else if userInput.Port == packetAttrs.DstPort || userInput.Port == packetAttrs.SrcPort {
packet.CalcLatency(packetAttrs, flowtable)
}
}
}
}
Binary file modified internal/probe/probe_bpfeb.o
Binary file not shown.
Binary file modified internal/probe/probe_bpfel.o
Binary file not shown.

0 comments on commit 25d838a

Please sign in to comment.