-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathdump.go
73 lines (67 loc) · 1.4 KB
/
dump.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//go:build linux && cgo
package main
import (
"log"
"github.com/urfave/cli/v2"
"github.com/usnistgov/ndn-dpdk/ndn"
"github.com/usnistgov/ndn-dpdk/ndn/l3"
"github.com/usnistgov/ndn-dpdk/ndn/packettransport/afpacket"
)
func init() {
var cfg afpacket.Config
var netif string
var respond bool
defineCommand(&cli.Command{
Name: "dump",
Usage: "Capture traffic on an AF_PACKET face.",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "netif",
Usage: "Network `interface` name.",
Destination: &netif,
Required: true,
},
&cli.GenericFlag{
Name: "local",
Usage: "local MAC `address`",
Value: &cfg.Local,
},
&cli.GenericFlag{
Name: "remote",
Usage: "remote MAC `address`",
Value: &cfg.Remote,
},
&cli.BoolFlag{
Name: "respond",
Usage: "respond every Interest with Data",
Destination: &respond,
},
},
Action: func(c *cli.Context) error {
tr, e := afpacket.New(netif, cfg)
if e != nil {
return e
}
f, e := l3.NewFace(tr, l3.FaceConfig{})
if e != nil {
return e
}
defer close(f.Tx())
for {
select {
case <-c.Context.Done():
return nil
case packet := <-f.Rx():
log.Println(packet)
if respond && packet.Interest != nil {
data := ndn.MakeData(packet.Interest)
select {
case f.Tx() <- data:
default:
}
}
}
}
},
})
}