-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #622 from intel-go/agadiyar/decrementTTL
new example decrementTTL
- Loading branch information
Showing
4 changed files
with
44 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,3 +14,4 @@ devbind | |
OSforwarding | ||
generate | ||
jumbo | ||
decrementTTL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,3 +22,4 @@ COPY netlink . | |
COPY generate . | ||
COPY OSforwarding . | ||
COPY jumbo . | ||
COPY decrementTTL . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |