Skip to content

Commit

Permalink
Fix 100-continue with multi-packet headers
Browse files Browse the repository at this point in the history
Also adds —output-null for testing purpose
  • Loading branch information
buger committed Jul 1, 2016
1 parent 5a0c03e commit f17f513
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 11 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SOURCE = emitter.go gor.go gor_stat.go input_dummy.go input_file.go input_raw.go input_tcp.go limiter.go output_dummy.go output_file.go input_http.go output_http.go output_tcp.go plugins.go settings.go test_input.go elasticsearch.go http_modifier.go http_modifier_settings.go http_client.go middleware.go protocol.go output_file_settings.go
SOURCE = emitter.go gor.go gor_stat.go input_dummy.go input_file.go input_raw.go input_tcp.go limiter.go output_dummy.go output_null.go output_file.go input_http.go output_http.go output_tcp.go plugins.go settings.go test_input.go elasticsearch.go http_modifier.go http_modifier_settings.go http_client.go middleware.go protocol.go output_file_settings.go
SOURCE_PATH = /go/src/github.com/buger/gor/
PORT = 8000
FADDR = :8000
Expand Down Expand Up @@ -77,7 +77,7 @@ file-server:
go run $(SOURCE) file-server $(FADDR)

readpcap:
go run $(SOURCE) --input-raw $(FILE) --input-raw-engine pcap_file --output-stdout
go run $(SOURCE) --input-raw $(FILE) --input-raw-engine pcap_file --output-null

record:
$(RUN) go run $(SOURCE) --input-dummy=0 --output-file=requests.gor --verbose --debug
Expand Down
18 changes: 18 additions & 0 deletions output_null.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package main

// NullOutput used for debugging, prints nothing
type NullOutput struct {
}

// NullOutput constructor for NullOutput
func NewNullOutput() (o *NullOutput) {
return new(NullOutput)
}

func (o *NullOutput) Write(data []byte) (int, error) {
return len(data), nil
}

func (o *NullOutput) String() string {
return "Null Output"
}
4 changes: 4 additions & 0 deletions plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ func InitPlugins() {
registerPlugin(NewDummyOutput)
}

if Settings.outputNull {
registerPlugin(NewNullOutput)
}

engine := EnginePcap
if Settings.inputRAWEngine == "raw_socket" {
engine = EngineRawSocket
Expand Down
19 changes: 10 additions & 9 deletions raw_socket_listener/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,8 @@ func (t *Listener) dispatchMessage(message *TCPMessage) {
return
}

log.Println("MESSAGE:", message, message.BodySize(), message.contentLength, message.methodType, message.bodyType)

t.deleteMessage(message)

if message.methodType == httpMethodNotFound {
return
}

if !message.complete {
if !message.IsIncoming {
delete(t.respAliases, message.Ack)
Expand Down Expand Up @@ -494,7 +488,6 @@ func (t *Listener) readPcapFile() {
data = append(tcp.LayerContents(), tcp.LayerPayload()...)
copy(data[2:4], []byte{0, 1})
} else {
log.Println("Can't find TCP layer", packet)
continue
}

Expand All @@ -505,7 +498,15 @@ func (t *Listener) readPcapFile() {
ip, _ := ipLayer.(*layers.IPv6)
addr = ip.SrcIP
} else {
log.Println("Can't find IP layer", packet)
// log.Println("Can't find IP layer", packet)
continue
}

dataOffset := (data[12] & 0xF0) >> 4

// We need only packets with data inside
// Check that the buffer is larger than the size of the TCP header
if len(data) <= int(dataOffset*4) {
continue
}

Expand Down Expand Up @@ -650,7 +651,7 @@ func (t *Listener) processTCPPacket(packet *TCPPacket) {

// Handling Expect: 100-continue requests
if message.expectType == httpExpect100Continue && len(message.packets) == message.headerPacket+1 {
seq := packet.Seq + uint32(len(packet.Data))
seq := packet.Seq + uint32(message.Size())
t.seqWithData[seq] = packet.Ack
message.DataSeq = seq
message.complete = false
Expand Down
3 changes: 3 additions & 0 deletions settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type AppSettings struct {
inputDummy MultiOption
outputDummy MultiOption
outputStdout bool
outputNull bool

inputTCP MultiOption
outputTCP MultiOption
Expand Down Expand Up @@ -81,6 +82,8 @@ func init() {

flag.BoolVar(&Settings.outputStdout, "output-stdout", false, "Used for testing inputs. Just prints to console data coming from inputs.")

flag.BoolVar(&Settings.outputNull, "output-null", false, "Used for testing inputs. Drops all requests.")

flag.Var(&Settings.inputTCP, "input-tcp", "Used for internal communication between Gor instances. Example: \n\t# Receive requests from other Gor instances on 28020 port, and redirect output to staging\n\tgor --input-tcp :28020 --output-http staging.com")
flag.Var(&Settings.outputTCP, "output-tcp", "Used for internal communication between Gor instances. Example: \n\t# Listen for requests on 80 port and forward them to other Gor instance on 28020 port\n\tgor --input-raw :80 --output-tcp replay.local:28020")
flag.BoolVar(&Settings.outputTCPStats, "output-tcp-stats", false, "Report TCP output queue stats to console every 5 seconds.")
Expand Down

0 comments on commit f17f513

Please sign in to comment.