Commit Graph
1232 Commits
Author SHA1 Message Date
Leonid Bugaev 61b377d123 Do not use buffer pool for messages
This buffers are get re-used and data gets corrupted
2021-07-08 23:00:12 +03:00
Leonid Bugaev 625ed54f1e Allow input file read ahead
Input file now pre-reads N requests, sort them by timestamp and emit on demand.
You can control read depth using --input-file-read-depth which is 100 by default.

It makes implementaiton faster, and it fix various issues when due to concurrenccy, or another issues requests gets addeed out of order.
2021-07-08 10:30:22 +03:00
Leonid Bugaev 889c1e6d41 Fix windows interface matching
In windows pcap.Name differ from net.Interface Name, so instead we have to match by interface addrs
2021-07-07 21:11:11 +03:00
Leonid Bugaev 8edb74e572 Add support for "go" timestamp source
Windows having issues with generating timestamps, so adding application level timestamp generation
Made small refactoring to move "accurate-enough" time to own package.
2021-07-07 20:56:22 +03:00
Leonid Bugaev 59b12abbe1 Fix linux compilation issue 2021-07-07 19:33:49 +03:00
Leonid Bugaev 5d718e92ea Add exvar to expose debug variables 2021-07-07 12:30:13 +03:00
Leonid Bugaev 148846be93 GC optimisations 2021-07-07 03:04:28 +03:00
Leonid Bugaev 0bb72e0f60 Add buffer pooling for message data 2021-07-07 02:58:00 +03:00
Leonid Bugaev af19f0feb8 Remove GOGC trick 2021-07-07 02:24:48 +03:00
Leonid Bugaev 724c0890c9 Improve memory allocations
A lot of improvements, and own GC for packet pool
2021-07-07 02:08:23 +03:00
Leonid Bugaev a727ade006 Fix BPF filter when listen on all interfaces
It was caching bpf filter of first interface
2021-07-06 19:13:48 +03:00
Leonid Bugaev 92c63de753 Fix replay of requests with timestampp in "past"
In some rare cases, requests can be recorded out of order.
It was causing replay from file significanty slodown when such issue met.
Now it replays them but without adding sleep.
2021-07-01 23:27:34 +03:00
Leonid Bugaev b6cc6a3606 Add a way to add process ID to file names
When you use S3 and write from multiple machines, you need to ensure that file will have unique name for each machine.
This PR adds special %i function which you can use in file templates, which will add some random process uniq string to the file.
2021-07-01 21:22:03 +03:00
Leonid Bugaev 2b993eda49 Fix --input-raw-bpf-filter
It was just ignored

Should fix #955
2021-07-01 09:17:41 +03:00
Leonid Bugaev de8a74fdca Fix compilation error 2021-07-01 09:17:20 +03:00
Leonid Bugaev f701dace50 Fix MacOS builds v1.3.0_RC6 2021-06-29 23:10:39 +03:00
Leonid Bugaev ad43405793 Fix MacOS compilation 2021-06-29 21:11:31 +03:00
Leonid BugaevandGitHub 9468978353 Skip not complete HTTP messages (#953)
Added `--input-raw-allow-incomplete` if you really need it.

Fixed Bug when outpuut binary response not tracked
Additionally fixed bug which prevents Gor from exiting.
2021-06-28 23:01:58 +03:00
Leonid Bugaev db32671c52 Memory utilization improvements
Do not use sync.Pool, use channel based impementation instead. Sync pool does not work for long lived objects, and trigger frequent GC.
Because of MUCH more efficient memory utilization, GOGC now set to 500, which significantly improve CPU as wel.
2021-06-27 21:05:10 +00:00
Leonid Bugaev 4b864199cd Add ZeroCopy back and fix ring packet processing
The cause was not ZeroCopy but wrong SetTimeout (block cause a lot of overhead).

Packet processing previously used channels, but now, with ring buffer, using select was causing issue. Adding `default` clause fixed the issue.
2021-06-27 19:17:06 +00:00
Leonid Bugaev 67154f6a62 Replace channels with Ring Buffer
Channes cause a lot of locking, and Ring Buffer data structure shows way better performance in our case
2021-06-27 17:18:57 +00:00
Leonid BugaevandGitHub 05d09ce049 Add af_packet capture engine (#950)
It is a high performant alternative to libpcap engine.
Only Linux supported.

Performance gain can be up to 50% depending on traffic type.
Can be enabled using:

`--input-raw-engine af_packet`
2021-06-26 23:03:20 +03:00
Leonid Bugaev e613a3156e Do not use ZeroCopy packet ccapture
While by nature this methods should be way faster, for some reason this functions cause large cgo overhead and cause a lot of futex locks.
2021-06-26 17:35:46 +00:00
Leonid Bugaev bbefdf5710 Fix tests
They were duplicated in tcp package
2021-06-26 15:05:29 +00:00
Dima GolomozyandGitHub 35865bfd8c Capture interfaces with ip (#944)
* capture nic only with ips

* pcap.Interface and net.Interface flags are not the same.
using net.Flags
2021-06-17 20:20:19 +03:00
Leonid Bugaev 5b0dc99caa Ignore deb files v1.3.0_RC5 2021-06-10 15:01:55 +03:00
Leonid Bugaev 972c59abfe Fix merge issue 2021-06-10 14:53:15 +03:00
Dima GolomozyandGitHub 642bb35124 capture list of ports (#935)
Co-authored-by: Leonid Bugaev <leonsbox@gmail.com>

Added a way to capture multiple ports at the same time, with a single listener. 
Ports should be separated by comma like this: --input-raw :80,8080,3000
2021-06-10 14:49:17 +03:00
Leonid BugaevandGitHub 58ff8865df Fix windows packet capture (#943)
Issues is that Go built-in net.Interfaces function in newer Windows versions return wrong interface names, which libpcap can't consume.
Now we use pcap.FindDevices instead of net.Interfaces.
See this Article for deep understanding of the issue https://haydz.github.io/2020/07/06/Go-Windows-NIC.html

Additionally, found a bug causing big memory allocations, for large requests, when we perform check if messages finished or not.
Because of this bug chunked body encoding check was not working properly.
Was not caught in tests, because test was working on packet array level, and this issue happens when dealing with TCP message object.

Additionally, added a small fix for windows Makefile task, it now generates proper file name.
2021-06-10 14:46:17 +03:00
Leonid Bugaev 763ad9b051 Merge branch 'DimaGolomozy-more-exact-bpf-filter' v1.3.0_RC4 2021-06-09 18:26:09 +03:00
Leonid Bugaev b1972fb0a8 Add way to test looping from webserver to itsef 2021-06-09 18:25:31 +03:00
Dima GolomozyandLeonid Bugaev 361ea8967e support only 1.15 and above (#942) 2021-06-09 18:08:11 +03:00
Leonid Bugaev f00817c13e Add windows support (#940)
For a long time there were no official binaries for the windows platform.
One of the reasons is the complexities of the build toolchain. Not only CGO is required, but also installing the needed libraries and header files, not talking about mingw and etc.

2 weeks ago [golang-crossbuild](https://github.com/elastic/golang-crossbuild) project added native support for Libpcap based applications.
Windows support is based on the WinPcap which is a bit (a lot) outdated, BUT, since we depend only on its interface, it is still possible to use projects like npcap https://nmap.org/npcap/#download.

Npcap needs be installed with WinPcap compatibe mode (checkbox during installation)
It is also possibe install it in silent mode like this: `npcap-0.86.exe /S /winpcap_mode=yes`

After PR merge, will be updated related documentation.

Additionally fix dependency on "unix" package (apparently it can be totally replaced using universal syscall package)
2021-06-09 18:08:11 +03:00
Leonid Bugaev ebe9e222f3 Bump version 2021-06-09 18:08:11 +03:00
Leonid Bugaev f2857424b0 Update to use Go 1.15 and latest libpcap 2021-06-09 18:08:11 +03:00
Erik SchwellerandLeonid Bugaev 76fe71c0fd Go report corrections (#939)
* A few misspell corrections

* apply 'gofmt -s'
2021-06-09 18:08:11 +03:00
Erik SchwellerandLeonid Bugaev d315290564 Address issues flagged by (#938) 2021-06-09 18:08:11 +03:00
Dima GolomozyandGitHub 7e173b08bb support only 1.15 and above (#942) 2021-06-09 17:43:06 +03:00
dimagolomozy 061a02e370 evaluate filters for each nic 2021-06-09 11:47:12 +03:00
dimagolomozy 9a2187ff96 more exact bpf filter for only incoming traffic 2021-06-09 11:46:56 +03:00
Leonid BugaevandGitHub 07a4ef626c Add windows support (#940)
For a long time there were no official binaries for the windows platform.
One of the reasons is the complexities of the build toolchain. Not only CGO is required, but also installing the needed libraries and header files, not talking about mingw and etc.

2 weeks ago [golang-crossbuild](https://github.com/elastic/golang-crossbuild) project added native support for Libpcap based applications.
Windows support is based on the WinPcap which is a bit (a lot) outdated, BUT, since we depend only on its interface, it is still possible to use projects like npcap https://nmap.org/npcap/#download.

Npcap needs be installed with WinPcap compatibe mode (checkbox during installation)
It is also possibe install it in silent mode like this: `npcap-0.86.exe /S /winpcap_mode=yes`

After PR merge, will be updated related documentation.

Additionally fix dependency on "unix" package (apparently it can be totally replaced using universal syscall package)
2021-06-09 09:46:41 +03:00
Leonid Bugaev 71a338cb02 Bump version 2021-06-09 07:04:27 +03:00
Leonid Bugaev 14143e46ca Update to use Go 1.15 and latest libpcap 2021-06-09 07:02:09 +03:00
Erik SchwellerandGitHub 7c10776064 Go report corrections (#939)
* A few misspell corrections

* apply 'gofmt -s'
2021-06-08 22:43:19 +03:00
Erik SchwellerandGitHub 09d7d42254 Address issues flagged by (#938) 2021-06-08 21:05:16 +03:00
田小波andGitHub 22f0b09883 Close http.Response.Body to avoid http connection leak. (#927) 2021-05-21 21:40:49 +03:00
Vincent ComposieuxandGitHub 1e8c879bc6 Fixed unusued "fmt" error in tcp_message.go (#933) 2021-05-21 21:40:11 +03:00
Urban IshimweandGitHub e74e945e7f Fixing performance issues and out-of-order packets (#916)
### Reducing CPU context switching and number of goroutines. 
Packet capture and packet processing now use only two goroutines which helps to minimize CPU context switches. Spawning too many goroutines is harmful here. 

### Optimized packet capture - allocated memory only when required, and only for data which is used
Using ZeroCopy methods from libpcap library to avoid unnecessary allocations. Now memory gets allocated ONLY for the valid packets, and only for the packets which have the data. E.g. no SYN/FIN packets are used now. Additionally we now use `sync.Pool` for re-using packet objects, which helps to re-use already allocated memory. 

### Simplification and optimization of request/response detection
There is no SYN/FIN packets anymore etc. Now only packet payload is used to detect start and end of the packet. More over payload detection now does not require generating a total “message” buffer, and works with individual packet payloads. 

Message payloads now concatenated from packets only in the end when message is dispatched. Also, before checking if message is complete, added additional check if all received packets in the valid order, e.g. if their SEQ is valid, and no packets are missing. 

Reworked chunked encoding validation, and now it does not need expensive operation of re-calculating all the chunks. Now it “trust” that client gives valid chunk body, check if packets are in the right order (e.g. SEQ match), and checks if message ends with the right suffix. All is done with 0 allocations. 

Parsing all Headers using `proto.GetHeaders` was proved to be very slow. Now we only parse the headers we need(and do it only once).

Packets gets matched together using ACK, which on high RPS removed chances of duplicating IDs. Additionally, even if packets are received out of order, now it will properly sort them, before dispatching the message.

### Changes in ID generation algorithm
Message ID generation and relations between request and response IDs is fully rewritten. Responses now do not have to lookup for request data in order to get the same ID. ID no rely on the fact that SEQ of the first packet of the response should be the same as ACK of the request. If previously Message ID contained random values, like current timestamp, now it has a consistent algorithm which is based on TCP stream id (SrcPort + DstPort + SrcIP/DstIP) and current ACK/SEQ number (to distinguish multiple messages within the same stream).

### BPF filter optimizations
When tracking response it now uses a more accurate BPF rule to filter only needed traffic. 

### Misc
The packet code is now fully moved to tcp/Packet, so packet processing done only once in one place.

TCP output now has a 5 second timeout, and has a proper Close method.

Fully switching to go modules and removing vendoring.
2021-05-19 20:11:25 +03:00
Ankit DobhalandGitHub 8f14d5b178 Fixed bug risk and antipattern using deepsource (#904)
## Description

Hi 👋 I ran the [DeepSource](https://deepsource.io/) static analyzer on the forked copy of this repo and found some [interesting code quality issues](https://deepsource.io/gh/ankitdobhal/goreplay/issues/). This PR fixes a few of them.

## Summary of Fixes

- Added .deepsource.toml to fix bug risks
- Empty string test can be improved
- Nested if can be replaced with else-if

## Type of change

- [✔] Antipattern
- [ ] New feature (non-breaking change which adds functionality)

## Checklist:

- [✔] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my own code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
2021-02-23 20:15:24 +03:00
Urban IshimweandGitHub 5e27c92f80 fix middlewares bugs: (#887)
bugs include:
- middleware doesn't send message meta
- send empty request when prettifier is off
- handle shutdown gracefully
- disable debug in example middlewares during test
2021-01-25 16:08:57 +03:00