Closed czxichen closed 4 years ago
`package main
import ( "flag" "fmt"
"github.com/intel-go/nff-go/flow" "github.com/intel-go/nff-go/packet" "github.com/intel-go/nff-go/types"
)
func main() { inport := flag.Uint("inport", 0, "port for receiver") flag.Parse()
err := flow.SystemInit(nil) if err != nil { panic(err) } inputFlow, err := flow.SetReceiver(uint16(*inport)) if err != nil { panic(err) } if err = flow.SetIPForPort(uint16(*inport), types.BytesToIPv4(192, 168, 80, 136)); err != nil { panic(err) } if err = flow.DealARPICMP(inputFlow); err != nil { panic(err) } passFlow, err := flow.SetSeparator(inputFlow, ssh, nil) if err != nil { panic(err) } if err = flow.SetStopper(passFlow); err != nil { panic(err) } if err = flow.SetStopper(inputFlow); err != nil { panic(err) } if err := flow.SystemStart(); err != nil { println(err.Error()) }
}
func ssh(p *packet.Packet, c flow.UserContext) bool { p.ParseL4ForIPv4()
tcpHeader := p.GetTCPForIPv4() if tcpHeader == nil { return false } if packet.SwapBytesUint16(tcpHeader.DstPort) == 22 { fmt.Printf("SSH packet:\n%s\n%s\n", p.Ether.String(), tcpHeader.String()) return true } return false
} `
run reseult
`root@cc:/data/nff-go/examples/ping: ./ping -------------------- Initializing DPDK -------------------- EAL: Detected 4 lcore(s) EAL: Detected 1 NUMA nodes EAL: Multi-process socket /var/run/dpdk/rte/mp_socket EAL: Selected IOVA mode 'PA' EAL: No available hugepages reported in hugepages-1048576kB EAL: Probing VFIO support... EAL: PCI device 0000:02:01.0 on NUMA socket -1 EAL: Invalid NUMA socket, default to 0 EAL: probe driver: 8086:100f net_e1000_em EAL: PCI device 0000:02:06.0 on NUMA socket -1 EAL: Invalid NUMA socket, default to 0 EAL: probe driver: 8086:100f net_e1000_em EAL: Error reading from file descriptor 27: Input/output error ------------------ Initializing scheduler ----------------- DEBUG: Scheduler can use cores: [0 1 2 3] ---------------------- Creating ports --------------------- Warning! Port 0 does not support requested number of TX queues 2. Setting number of TX queues to 1 EAL: Error enabling interrupts for fd 27 (Input/output error) DEBUG: Port 0 MAC address: 00:0c:29:d7:58:41 ------------------ Starting FlowFunctions ----------------- DEBUG: Start SCHEDULER at 0 core DEBUG: Start STOP at scheduler 0 core DEBUG: Start new instance for receiverPort1 DEBUG: Start new clone for receiverPort1 instance 0 at 1 core DEBUG: Start new instance for segment1 DEBUG: Start new clone for segment1 instance 0 at 2 core SSH packet: L2 protocol: Ethernet, EtherType: 0x0008 (IPv4) Ethernet Source: 00:50:56:c0:00:08 Ethernet Destination: 00:0c:29:d7:58:37
L4 protocol: TCP L4 Source: 54999 L4 Destination: 22
`
The mac-address of my running port is 00:0c:29:d7:58:41,Why do you receive data on 00:0c:29:d7:58:37 ?
`package main
import ( "flag" "fmt"
)
func main() { inport := flag.Uint("inport", 0, "port for receiver") flag.Parse()
}
func ssh(p *packet.Packet, c flow.UserContext) bool { p.ParseL4ForIPv4()
} `
run reseult
`root@cc:/data/nff-go/examples/ping: ./ping -------------------- Initializing DPDK -------------------- EAL: Detected 4 lcore(s) EAL: Detected 1 NUMA nodes EAL: Multi-process socket /var/run/dpdk/rte/mp_socket EAL: Selected IOVA mode 'PA' EAL: No available hugepages reported in hugepages-1048576kB EAL: Probing VFIO support... EAL: PCI device 0000:02:01.0 on NUMA socket -1 EAL: Invalid NUMA socket, default to 0 EAL: probe driver: 8086:100f net_e1000_em EAL: PCI device 0000:02:06.0 on NUMA socket -1 EAL: Invalid NUMA socket, default to 0 EAL: probe driver: 8086:100f net_e1000_em EAL: Error reading from file descriptor 27: Input/output error ------------------ Initializing scheduler ----------------- DEBUG: Scheduler can use cores: [0 1 2 3] ---------------------- Creating ports --------------------- Warning! Port 0 does not support requested number of TX queues 2. Setting number of TX queues to 1 EAL: Error enabling interrupts for fd 27 (Input/output error) DEBUG: Port 0 MAC address: 00:0c:29:d7:58:41 ------------------ Starting FlowFunctions ----------------- DEBUG: Start SCHEDULER at 0 core DEBUG: Start STOP at scheduler 0 core DEBUG: Start new instance for receiverPort1 DEBUG: Start new clone for receiverPort1 instance 0 at 1 core DEBUG: Start new instance for segment1 DEBUG: Start new clone for segment1 instance 0 at 2 core SSH packet: L2 protocol: Ethernet, EtherType: 0x0008 (IPv4) Ethernet Source: 00:50:56:c0:00:08 Ethernet Destination: 00:0c:29:d7:58:37
`
The mac-address of my running port is 00:0c:29:d7:58:41,Why do you receive data on 00:0c:29:d7:58:37 ?