Skip to content

Commit

Permalink
Merge pull request #43 from vearne/develop
Browse files Browse the repository at this point in the history
fix bug:connection's direction
  • Loading branch information
vearne authored Sep 11, 2024
2 parents f67a34b + fc98fc1 commit ca92542
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION := v0.1.6
VERSION := v0.1.7

BIN_NAME = grpcr
CONTAINER = grpcr
Expand Down
6 changes: 4 additions & 2 deletions http2/net_pkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,12 @@ func ProcessPacket(packet gopacket.Packet, ipSet *util.StringSet, port int) (*Ne
return nil, errors.New("invalid TCP package")
}
p.TCP = tcpLayer.(*layers.TCP)
if ipSet.Has(p.DstIP) && int(p.TCP.SrcPort) == port {
if ipSet.Has(p.SrcIP) && int(p.TCP.SrcPort) == port {
p.Direction = DirOutcoming
} else {
} else if ipSet.Has(p.DstIP) && int(p.TCP.DstPort) == port {
p.Direction = DirIncoming
} else {
p.Direction = DirUnknown
}
return &p, nil
}
Expand Down
2 changes: 1 addition & 1 deletion http2/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (p *Processor) ProcessTCPPkg() {
continue
}

dc := pkg.DirectConn()
dc = pkg.DirectConn()
f.DirectConn = &dc
slog.Debug("Connection:%v, seq:%v, FrameType:%v, length:%v, len(payload):%v, streamID:%v",
f.DirectConn, pkg.TCP.Seq, GetFrameType(f.Type), f.Length, len(f.Payload), f.StreamID)
Expand Down
1 change: 0 additions & 1 deletion plugin/input_raw.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ func (l *DeviceListener) listen() error {
&conn, http2.GetDirection(netPkg.Direction))
if netPkg.Direction == http2.DirIncoming {
//l.rawInput.outputChan <- packet
conn := netPkg.DirectConn()
if l.rawInput.connSet.Has(conn) { // history connection
if netPkg.TCP.ACK {
slog.Debug("send RST, for connection:%v", &conn)
Expand Down
8 changes: 4 additions & 4 deletions util/string_set.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package util

type StringSet struct {
internal map[string]int
internal map[string]struct{}
}

func NewStringSet() *StringSet {
return &StringSet{internal: make(map[string]int)}
return &StringSet{internal: make(map[string]struct{})}
}

func (set *StringSet) Add(str string) {
set.internal[str] = 1
set.internal[str] = struct{}{}
}

func (set *StringSet) AddAll(itemSlice []string) {
for _, item := range itemSlice {
set.internal[item] = 1
set.internal[item] = struct{}{}
}
}

Expand Down

0 comments on commit ca92542

Please sign in to comment.