Skip to content

Commit

Permalink
fix bug: read all buf
Browse files Browse the repository at this point in the history
  • Loading branch information
KusakabeShi committed Aug 3, 2021
1 parent 4e5c82a commit 721c146
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ To run with more logging you may set the environment variable `LOG_LEVEL=debug`.

Remember to replace the path to real path
```
export LDP_DEBUG=0
export VCL_DEBUG=0
export VCL_VPP_API_SOCKET="/run/vpp/api.sock"
export LD_PRELOAD="/usr/lib/x86_64-linux-gnu/libvcl_ldpreload.so"
```
Expand Down
23 changes: 22 additions & 1 deletion tun/tun_linux_vpp.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ type NativeTun struct {
secret string
RxQueues int
RxintCh <-chan uint8
RxintChNext chan uint8
RxintErrCh <-chan error
TxQueues int
TxCount uint
Expand Down Expand Up @@ -332,16 +333,35 @@ func (tun *NativeTun) Read(buf []byte, offset int) (n int, err error) {
tun.logger.Errorf("tun error: %v\n", err)
return 0, err
case queueID := <-tun.RxintCh:
select {
case tun.RxintChNext <- queueID:
{
// Use non-blocking write to prevent program stuck
}
default:
tun.logger.Debugln("Buffer full")
}

case queueID := <-tun.RxintChNext:
packets, err := tun.memif.RxBurst(queueID, 1)
if err != nil {
tun.logger.Errorf("libmemif.Memif.RxBurst() error: %v\n", err)
return 0, err
}
if len(packets) == 0 {
// No more packets to read until the next interrupt.
break
return 0, nil
}
for _, packetData := range packets {
select {
case tun.RxintChNext <- queueID:
{
// Use non-blocking write to prevent program stuck
// repeatedly call RxBurst() until returns an empty slice of packets
}
default:
tun.logger.Debugln("Buffer full")
}
//check if dst mac addr is a boardcast mac
destMac := packetData[0:6]

Expand Down Expand Up @@ -1284,6 +1304,7 @@ func CreateTUN(name string, mtu int) (Device, error) {
VppBridgeID: ifConfig.VppBridgeID,
tempMTU: 9000,
logger: thelogger,
RxintChNext: make(chan uint8, 1<<6),
events: make(chan Event, 5),
errors: make(chan error, 5),
statusListenersShutdown: make(chan struct{}),
Expand Down

0 comments on commit 721c146

Please sign in to comment.