summaryrefslogtreecommitdiffhomepage
path: root/pkg/tcpip
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/tcpip')
-rw-r--r--pkg/tcpip/link/fdbased/endpoint.go2
-rw-r--r--pkg/tcpip/link/fdbased/packet_dispatchers.go14
-rw-r--r--pkg/tcpip/link/tun/device.go37
-rw-r--r--pkg/tcpip/transport/tcp/snd.go4
4 files changed, 27 insertions, 30 deletions
diff --git a/pkg/tcpip/link/fdbased/endpoint.go b/pkg/tcpip/link/fdbased/endpoint.go
index e17e2085c..2bb1be5d6 100644
--- a/pkg/tcpip/link/fdbased/endpoint.go
+++ b/pkg/tcpip/link/fdbased/endpoint.go
@@ -492,7 +492,7 @@ func (e *endpoint) sendBatch(batchFD int, batch []*stack.PacketBuffer) (int, tcp
var mmsgHdr rawfile.MMsgHdr
mmsgHdr.Msg.Iov = &iovecs[0]
- mmsgHdr.Msg.Iovlen = uint64(len(iovecs))
+ mmsgHdr.Msg.SetIovlen((len(iovecs)))
mmsgHdrs = append(mmsgHdrs, mmsgHdr)
}
diff --git a/pkg/tcpip/link/fdbased/packet_dispatchers.go b/pkg/tcpip/link/fdbased/packet_dispatchers.go
index 46df87f44..a7adf822b 100644
--- a/pkg/tcpip/link/fdbased/packet_dispatchers.go
+++ b/pkg/tcpip/link/fdbased/packet_dispatchers.go
@@ -68,10 +68,8 @@ func (b *iovecBuffer) nextIovecs() []unix.Iovec {
// The kernel adds virtioNetHdr before each packet, but
// we don't use it, so so we allocate a buffer for it,
// add it in iovecs but don't add it in a view.
- b.iovecs[0] = unix.Iovec{
- Base: &vnetHdr[0],
- Len: uint64(virtioNetHdrSize),
- }
+ b.iovecs[0] = unix.Iovec{Base: &vnetHdr[0]}
+ b.iovecs[0].SetLen(virtioNetHdrSize)
vnetHdrOff++
}
for i := range b.views {
@@ -80,10 +78,8 @@ func (b *iovecBuffer) nextIovecs() []unix.Iovec {
}
v := buffer.NewView(b.sizes[i])
b.views[i] = v
- b.iovecs[i+vnetHdrOff] = unix.Iovec{
- Base: &v[0],
- Len: uint64(len(v)),
- }
+ b.iovecs[i+vnetHdrOff] = unix.Iovec{Base: &v[0]}
+ b.iovecs[i+vnetHdrOff].SetLen(len(v))
}
return b.iovecs
}
@@ -235,7 +231,7 @@ func (d *recvMMsgDispatcher) dispatch() (bool, tcpip.Error) {
iovLen := len(iovecs)
d.msgHdrs[k].Len = 0
d.msgHdrs[k].Msg.Iov = &iovecs[0]
- d.msgHdrs[k].Msg.Iovlen = uint64(iovLen)
+ d.msgHdrs[k].Msg.SetIovlen(iovLen)
}
nMsgs, err := rawfile.BlockingRecvMMsg(d.fd, d.msgHdrs)
diff --git a/pkg/tcpip/link/tun/device.go b/pkg/tcpip/link/tun/device.go
index c1678c4f4..80fb343c5 100644
--- a/pkg/tcpip/link/tun/device.go
+++ b/pkg/tcpip/link/tun/device.go
@@ -17,7 +17,6 @@ package tun
import (
"fmt"
- "gvisor.dev/gvisor/pkg/abi/linux"
"gvisor.dev/gvisor/pkg/context"
"gvisor.dev/gvisor/pkg/sync"
"gvisor.dev/gvisor/pkg/syserror"
@@ -49,7 +48,14 @@ type Device struct {
mu sync.RWMutex `state:"nosave"`
endpoint *tunEndpoint
notifyHandle *channel.NotificationHandle
- flags uint16
+ flags Flags
+}
+
+// Flags set properties of a Device
+type Flags struct {
+ TUN bool
+ TAP bool
+ NoPacketInfo bool
}
// beforeSave is invoked by stateify.
@@ -77,7 +83,7 @@ func (d *Device) Release(ctx context.Context) {
}
// SetIff services TUNSETIFF ioctl(2) request.
-func (d *Device) SetIff(s *stack.Stack, name string, flags uint16) error {
+func (d *Device) SetIff(s *stack.Stack, name string, flags Flags) error {
d.mu.Lock()
defer d.mu.Unlock()
@@ -85,21 +91,18 @@ func (d *Device) SetIff(s *stack.Stack, name string, flags uint16) error {
return syserror.EINVAL
}
- // Input validations.
- isTun := flags&linux.IFF_TUN != 0
- isTap := flags&linux.IFF_TAP != 0
- supportedFlags := uint16(linux.IFF_TUN | linux.IFF_TAP | linux.IFF_NO_PI)
- if isTap && isTun || !isTap && !isTun || flags&^supportedFlags != 0 {
+ // Input validation.
+ if flags.TAP && flags.TUN || !flags.TAP && !flags.TUN {
return syserror.EINVAL
}
prefix := "tun"
- if isTap {
+ if flags.TAP {
prefix = "tap"
}
linkCaps := stack.CapabilityNone
- if isTap {
+ if flags.TAP {
linkCaps |= stack.CapabilityResolutionRequired
}
@@ -177,7 +180,7 @@ func (d *Device) Write(data []byte) (int64, error) {
// Packet information.
var pktInfoHdr PacketInfoHeader
- if !d.hasFlags(linux.IFF_NO_PI) {
+ if !d.flags.NoPacketInfo {
if len(data) < PacketInfoHeaderSize {
// Ignore bad packet.
return dataLen, nil
@@ -188,7 +191,7 @@ func (d *Device) Write(data []byte) (int64, error) {
// Ethernet header (TAP only).
var ethHdr header.Ethernet
- if d.hasFlags(linux.IFF_TAP) {
+ if d.flags.TAP {
if len(data) < header.EthernetMinimumSize {
// Ignore bad packet.
return dataLen, nil
@@ -253,7 +256,7 @@ func (d *Device) encodePkt(info *channel.PacketInfo) (buffer.View, bool) {
var vv buffer.VectorisedView
// Packet information.
- if !d.hasFlags(linux.IFF_NO_PI) {
+ if !d.flags.NoPacketInfo {
hdr := make(PacketInfoHeader, PacketInfoHeaderSize)
hdr.Encode(&PacketInfoFields{
Protocol: info.Proto,
@@ -269,7 +272,7 @@ func (d *Device) encodePkt(info *channel.PacketInfo) (buffer.View, bool) {
}
// Ethernet header (TAP only).
- if d.hasFlags(linux.IFF_TAP) {
+ if d.flags.TAP {
// Add ethernet header if not provided.
if info.Pkt.LinkHeader().View().IsEmpty() {
d.endpoint.AddHeader(info.Route.LocalLinkAddress, info.Route.RemoteLinkAddress, info.Proto, info.Pkt)
@@ -298,16 +301,12 @@ func (d *Device) Name() string {
}
// Flags returns the flags set for d. Zero value if unset.
-func (d *Device) Flags() uint16 {
+func (d *Device) Flags() Flags {
d.mu.RLock()
defer d.mu.RUnlock()
return d.flags
}
-func (d *Device) hasFlags(flags uint16) bool {
- return d.flags&flags == flags
-}
-
// Readiness implements watier.Waitable.Readiness.
func (d *Device) Readiness(mask waiter.EventMask) waiter.EventMask {
if mask&waiter.EventIn != 0 {
diff --git a/pkg/tcpip/transport/tcp/snd.go b/pkg/tcpip/transport/tcp/snd.go
index 18817029d..faca35892 100644
--- a/pkg/tcpip/transport/tcp/snd.go
+++ b/pkg/tcpip/transport/tcp/snd.go
@@ -323,7 +323,9 @@ func newSender(ep *endpoint, iss, irs seqnum.Value, sndWnd seqnum.Size, mss uint
// their initial values.
func (s *sender) initCongestionControl(congestionControlName tcpip.CongestionControlOption) congestionControl {
s.sndCwnd = InitialCwnd
- s.sndSsthresh = math.MaxInt64
+ // Set sndSsthresh to the maximum int value, which depends on the
+ // platform.
+ s.sndSsthresh = int(^uint(0) >> 1)
switch congestionControlName {
case ccCubic: