Skip to content

Commit

Permalink
Merge branch 'master' into wflag
Browse files Browse the repository at this point in the history
  • Loading branch information
gcla committed May 15, 2021
2 parents b773bb5 + bfea053 commit 82c0600
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 23 deletions.
22 changes: 20 additions & 2 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
],
"imageSize": 72,
"commit": false,
"contributorsPerLine": 8,
"commitConvention": "none",
"contributors": [
{
Expand Down Expand Up @@ -428,7 +429,24 @@
"contributions": [
"bug"
]
},
{
"login": "thordy",
"name": "Thord Setsaas",
"avatar_url": "https://avatars.githubusercontent.com/u/1622278?v=4",
"profile": "https://github.com/thordy",
"contributions": [
"doc"
]
},
{
"login": "deliciouslytyped",
"name": "deliciouslytyped",
"avatar_url": "https://avatars.githubusercontent.com/u/47436522?v=4",
"profile": "https://github.com/deliciouslytyped",
"contributions": [
"bug"
]
}
],
"contributorsPerLine": 7
]
}
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- prepare or apply the same filter as a display filter
- A new console-command, "wormhole", allows you to send termshark's current pcap with magic wormhole. Pair
with the tmux plugin tmux-wormhole to open the pcap quickly in Wireshark.
- Added a -w flag - if supplied for a live capture, termshark will write the packets to this capture file.

### Changed

Expand Down
15 changes: 7 additions & 8 deletions README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion capinfo/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func (c *Loader) loadCapinfoAsync(pcapf string, app gowid.IApp, cb ICapinfoCallb
}
}

if state == pcap.Terminated || (cancelledChan == nil && state == pcap.NotStarted) {
if state == pcap.Terminated || (procChan == nil && state == pcap.NotStarted) {
break loop
}
}
Expand Down
2 changes: 1 addition & 1 deletion convs/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func (c *Loader) loadConvAsync(pcapf string, convs []string, filter string, abs
}
}

if state == pcap.Terminated || (cancelledChan == nil && state == pcap.NotStarted) {
if state == pcap.Terminated || (procChan == nil && state == pcap.NotStarted) {
break loop
}
}
Expand Down
4 changes: 2 additions & 2 deletions docs/FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* [Can I pass extra arguments to tshark?](#can-i-pass-extra-arguments-to-tshark)
* [How does termshark use tshark?](#how-does-termshark-use-tshark)
* [How can I make termshark run without root?](#how-can-i-make-termshark-run-without-root)
* [Why do is termshark generating traffic on port 5037?](#why-is-termshark-generating-traffic-on-port-5037)
* [Why is termshark generating traffic on port 5037?](#why-is-termshark-generating-traffic-on-port-5037)
* [How can termshark capture from extcap interfaces with dumpcap?](#how-can-termshark-capture-from-extcap-interfaces-with-dumpcap)
* [Termshark is laggy or using a lot of RAM](#termshark-is-laggy-or-using-a-lot-of-ram)
* [How much memory does termshark use?](#how-much-memory-does-termshark-use)
Expand Down Expand Up @@ -321,7 +321,7 @@ sudo setcap cap_net_raw,cap_net_admin+eip /usr/sbin/dumpcap
You can find more detail at https://wiki.wireshark.org/CaptureSetup/CapturePrivileges.
## Why do is termshark generating traffic on port 5037?
## Why is termshark generating traffic on port 5037?
See [this issue](https://github.com/gcla/termshark/issues/98).
Expand Down
35 changes: 28 additions & 7 deletions pcap/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -1009,8 +1009,17 @@ func (c *PdmlLoader) loadPcapSync(row int, visible bool, ps iPdmlLoaderEnv, cb i
// a message means the proc has started
// closed means it won't be started
// if closed, then pdmlCmd == nil
if (pdmlState == Terminated || (pdmlCancelledChan == nil && pdmlState == NotStarted)) &&
(pcapState == Terminated || (pcapCancelledChan == nil && pcapState == NotStarted)) {
// 04/11/21: I can't take a shortcut here and condition on Terminated || (cancelledChan == nil && NotStarted)
// See the pcap or pdml goroutines below. I block at the beginning, checking on the stage2 cancellation.
// If I get past that point, and there are no errors in the process invocation, I am guaranteed to start both
// the pdml and pcap processes. If there are errors, I am guaranteed to close the pcapPidChan with a defer.
// If I take a shortcut and end this goroutine via a stage2 cancellation before waiting for the pcap pid,
// then I'll block in that goroutine, trying to send to the pcapPidChan, but with nothing here to receive
// the value. In the pcap process goroutine, if I get past the stage2 cancellation check, then I need to
// have something to receive the pid - this goroutine. It needs to stay alive until it gets the pid, or a
// zero.
if (pdmlState == Terminated || (pdmlPidChan == nil && c.PdmlPid == 0)) &&
(pcapState == Terminated || (pcapPidChan == nil && c.PcapPid == 0)) {
// nothing to select on so break
break loop
}
Expand Down Expand Up @@ -1353,6 +1362,15 @@ func (p *PsmlLoader) loadPsmlSync(iloader *InterfaceLoader, e iPsmlLoaderEnv, cb

//======================================================================

closedPipe := false
closePipe := func() {
if !closedPipe {
fifoPipeWriter.Close()
fifoPipeReader.Close()
closedPipe = true
}
}

if p.ReadingFromFifo() {
// PcapPsml will be nil if here

Expand All @@ -1372,8 +1390,7 @@ func (p *PsmlLoader) loadPsmlSync(iloader *InterfaceLoader, e iPsmlLoaderEnv, cb
// is used as stdin for the psml command, which also runs in this
// goroutine.
defer func() {
fifoPipeWriter.Close()
fifoPipeReader.Close()
closePipe()
}()

// wrap the read end of the pipe with a Read() function that counts
Expand Down Expand Up @@ -1419,6 +1436,10 @@ func (p *PsmlLoader) loadPsmlSync(iloader *InterfaceLoader, e iPsmlLoaderEnv, cb
if err != nil {
log.Infof("Did not kill tshark psml process: %v", err)
}

if p.ReadingFromFifo() {
closePipe()
}
}

loop:
Expand Down Expand Up @@ -1458,7 +1479,7 @@ func (p *PsmlLoader) loadPsmlSync(iloader *InterfaceLoader, e iPsmlLoaderEnv, cb
}
}

if state == Terminated || (intCancelledChan == nil && state == NotStarted) {
if state == Terminated || (pidChan == nil && state == NotStarted) {
break loop
}
}
Expand Down Expand Up @@ -1584,7 +1605,7 @@ func (p *PsmlLoader) loadPsmlSync(iloader *InterfaceLoader, e iPsmlLoaderEnv, cb

// successfully started then died/kill, OR
// was never started, won't be started, and cancelled
if state == Terminated || (cancelledChan == nil && state == NotStarted) {
if state == Terminated || (pidChan == nil && state == NotStarted) {
break loop
}
}
Expand Down Expand Up @@ -2112,7 +2133,7 @@ func (i *InterfaceLoader) loadIfacesSync(e iIfaceLoaderEnv, cb interface{}, app
// a message means the proc has started
// closed means it won't be started
// if closed, then pdmlCmd == nil
if state == Terminated || (cancelledChan == nil && state == NotStarted) {
if state == Terminated || (pidChan == nil && state == NotStarted) {
// nothing to select on so break
break loop
}
Expand Down
4 changes: 2 additions & 2 deletions streams/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func (c *Loader) loadStreamReassemblyAsync(pcapf string, proto string, idx int,
}
}

if state == pcap.Terminated || (cancelled == nil && state == pcap.NotStarted) {
if state == pcap.Terminated || (procChan == nil && state == pcap.NotStarted) {
break loop
}
}
Expand Down Expand Up @@ -300,7 +300,7 @@ func (c *Loader) startStreamIndexerAsync(pcapf string, proto string, idx int, ap

}

if state == pcap.Terminated || (cancelledChan == nil && state == pcap.NotStarted) {
if state == pcap.Terminated || (procChan == nil && state == pcap.NotStarted) {
break loop
}

Expand Down

0 comments on commit 82c0600

Please sign in to comment.