pretty spicy

This commit is contained in:
JackDoan
2026-04-17 14:00:18 -05:00
parent 1dc30df88b
commit f60cbfdc71
10 changed files with 364 additions and 5 deletions

View File

@@ -355,17 +355,54 @@ func (f *Interface) listenIn(reader overlay.Queue, i int) {
}
func (f *Interface) flushBatch(batch *sendBatch, q int) {
if len(batch.bufs) == 1 {
if err := f.writers[q].WriteTo(batch.bufs[0], batch.dsts[0]); err != nil {
f.l.WithError(err).WithField("writer", q).Error("Failed to write outgoing single-batch")
//if len(batch.bufs) == 1 {
// if err := f.writers[q].WriteTo(batch.bufs[0], batch.dsts[0]); err != nil {
// f.l.WithError(err).WithField("writer", q).Error("Failed to write outgoing single-batch")
// }
// return
//}
w := f.writers[q]
if w.SupportsGSO() {
if segSize, ok := batchSegmentable(batch); ok {
if err := w.WriteSegmented(batch.bufs, batch.dsts[0], segSize); err != nil {
f.l.WithError(err).WithField("writer", q).Error("Failed to write outgoing GSO batch")
}
return
}
return
}
if err := f.writers[q].WriteBatch(batch.bufs, batch.dsts); err != nil {
if err := w.WriteBatch(batch.bufs, batch.dsts); err != nil {
f.l.WithError(err).WithField("writer", q).Error("Failed to write outgoing batch")
}
}
// batchSegmentable reports whether a batch can be emitted as a single UDP GSO
// superpacket: all packets go to the same destination, and every packet
// except possibly the last has the same length. Returns the segment size on
// success. The single-packet case is handled in flushBatch before this runs.
func batchSegmentable(b *sendBatch) (int, bool) {
segSize := len(b.bufs[0])
if segSize == 0 {
return 0, false
}
dst := b.dsts[0]
last := len(b.bufs) - 1
for i := 1; i <= last; i++ {
if b.dsts[i] != dst {
return 0, false
}
if i < last {
if len(b.bufs[i]) != segSize {
return 0, false
}
} else {
if len(b.bufs[i]) == 0 || len(b.bufs[i]) > segSize {
return 0, false
}
}
}
return segSize, true
}
func (f *Interface) RegisterConfigChangeCallbacks(c *config.C) {
c.RegisterReloadCallback(f.reloadFirewall)
c.RegisterReloadCallback(f.reloadSendRecvError)