Comments (1)
Yes, it should be possible by adding an offset to the xdp.Desc.Addr
before Transmit()
ing them.
For example,
diff --git a/examples/sendudp/sendudp.go b/examples/sendudp/sendudp.go
index c193c68..45e4a2d 100644
--- a/examples/sendudp/sendudp.go
+++ b/examples/sendudp/sendudp.go
@@ -61,11 +61,16 @@ func main() {
srcMAC, _ := hex.DecodeString(SrcMAC)
dstMAC, _ := hex.DecodeString(DstMAC)
- eth := &layers.Ethernet{
+ eth1 := &layers.Ethernet{
SrcMAC: net.HardwareAddr(srcMAC),
DstMAC: net.HardwareAddr(dstMAC),
EthernetType: layers.EthernetTypeIPv4,
}
+ eth2 := &layers.Ethernet{
+ SrcMAC: net.HardwareAddr{ 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, },
+ DstMAC: net.HardwareAddr{ 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, },
+ EthernetType: layers.EthernetTypeIPv4,
+ }
ip := &layers.IPv4{
Version: 4,
IHL: 5,
@@ -90,7 +95,7 @@ func main() {
FixLengths: true,
ComputeChecksums: true,
}
- err = gopacket.SerializeLayers(buf, opts, eth, ip, udp, gopacket.Payload(payload))
+ err = gopacket.SerializeLayers(buf, opts, eth1, eth2, ip, udp, gopacket.Payload(payload))
if err != nil {
panic(err)
}
@@ -107,7 +112,7 @@ func main() {
// endless loop printing statistics of the number of sent frames and
// the number of sent bytes every second.
- fmt.Printf("sending UDP packets from %v (%v) to %v (%v)...\n", ip.SrcIP, eth.SrcMAC, ip.DstIP, eth.DstMAC)
+ fmt.Printf("sending UDP packets from %v (%v) to %v (%v)...\n", ip.SrcIP, eth2.SrcMAC, ip.DstIP, eth2.DstMAC)
go func() {
var err error
@@ -129,6 +134,7 @@ func main() {
for {
descs := xsk.GetDescs(xsk.NumFreeTxSlots())
for i := range descs {
+ descs[i].Addr += 14
descs[i].Len = uint32(frameLen)
}
xsk.Transmit(descs)
the descs[i].Addr += 14
line above "removes" the eth1 layer.
from xdp.
Related Issues (18)
- Q: what is the correct way to use this for RX and TX at the same time? HOT 4
- Redirecting to another port HOT 1
- xsk stats report Tx_ring_empty_descs when change argument of GetDescs()
- Q: Attach xdp program to interface raises "cannot allocate memory" HOT 4
- xdp_pass
- error HOT 1
- Filter based on the value of a specific byte
- how to do example rate limiting of ip based on this?
- At high throughput receiving same packet twice at expense of another packet disappearing altogether.
- how do also listen to a specific port and forward to another application port based on ip address? HOT 1
- possible to provide example for tcp and ipv6 together?
- getting error for ubuntu 22.04, golang 1.19 go build sendudp.go
- Detaching program hangs when using SKB mode
- map xdp_stats_map: pin by name: missing MapOptions.PinPath
- Memory allocations on Rx/Tx paths limit maximum performance
- Review "kernel kick" code
- examples/sendudp stuck at Poll() after a while HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from xdp.