Skip to content

Commit

Permalink
Merge pull request #622 from intel-go/agadiyar/decrementTTL
Browse files Browse the repository at this point in the history
new example decrementTTL
  • Loading branch information
gshimansky authored Jun 14, 2019
2 parents 044e5c2 + 66f71d3 commit 376f7e7
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 1 deletion.
1 change: 1 addition & 0 deletions examples/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ devbind
OSforwarding
generate
jumbo
decrementTTL
1 change: 1 addition & 0 deletions examples/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ COPY netlink .
COPY generate .
COPY OSforwarding .
COPY jumbo .
COPY decrementTTL .
3 changes: 2 additions & 1 deletion examples/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ IMAGENAME = nff-go-examples
EXECUTABLES = dump clonablePcapDumper kni copy errorHandling timer \
createPacket sendFixedPktsNumber gtpu pingReplay \
netlink gopacketParserExample devbind generate \
OSforwarding jumbo
OSforwarding jumbo decrementTTL

SUBDIRS = tutorial antiddos demo fileReadWrite firewall forwarding ipsec lb

.PHONY: dpi nffPktgen
Expand Down
40 changes: 40 additions & 0 deletions examples/decrementTTL.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright 2017 Intel Corporation.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package main

import (
"flag"

"github.com/intel-go/nff-go/flow"
"github.com/intel-go/nff-go/packet"
)

// Main function for constructing packet processing graph.
func main() {
inPort := flag.Uint("inPort", 0, "port for receiver")
outPort := flag.Uint("outPort", 1, "port for sender")
flag.Parse()

flow.SystemInit(nil)
inputFlow, _ := flow.SetReceiver(uint16(*inPort))
flow.SetHandlerDrop(inputFlow, decrementTTL, nil)
flow.SetSender(inputFlow, uint16(*outPort))
flow.SystemStart()
}

func decrementTTL(current *packet.Packet, c flow.UserContext) bool {
current.ParseL3() // must parse before header can be read
header := current.GetIPv4()
if header == nil { // not IPv4
return false
}

header.TimeToLive--
if header.TimeToLive == 0 { // TTL exceeded, drop
return false
} else {
return true
}
}

0 comments on commit 376f7e7

Please sign in to comment.