summaryrefslogtreecommitdiffhomepage
path: root/pkg/tcpip/socketops.go
diff options
context:
space:
mode:
authorNayana Bidari <nybidari@google.com>2020-12-22 14:41:11 -0800
committergVisor bot <gvisor-bot@google.com>2020-12-22 14:44:02 -0800
commit7c8ba72b026db3b79f12e679ab69078a25c143e8 (patch)
tree71c5c14dd973fc55b218c635f37b11a72a1de190 /pkg/tcpip/socketops.go
parent202e9fa3695e015ba8875c094f70d75bce18b95e (diff)
Move SO_BINDTODEVICE to socketops.
PiperOrigin-RevId: 348696094
Diffstat (limited to 'pkg/tcpip/socketops.go')
-rw-r--r--pkg/tcpip/socketops.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/pkg/tcpip/socketops.go b/pkg/tcpip/socketops.go
index 095d1734a..f3ad40fdf 100644
--- a/pkg/tcpip/socketops.go
+++ b/pkg/tcpip/socketops.go
@@ -45,6 +45,9 @@ type SocketOptionsHandler interface {
// UpdateLastError updates the endpoint specific last error field.
UpdateLastError(err *Error)
+
+ // HasNIC is invoked to check if the NIC is valid for SO_BINDTODEVICE.
+ HasNIC(v int32) bool
}
// DefaultSocketOptionsHandler is an embeddable type that implements no-op
@@ -76,6 +79,11 @@ func (*DefaultSocketOptionsHandler) LastError() *Error {
// UpdateLastError implements SocketOptionsHandler.UpdateLastError.
func (*DefaultSocketOptionsHandler) UpdateLastError(*Error) {}
+// HasNIC implements SocketOptionsHandler.HasNIC.
+func (*DefaultSocketOptionsHandler) HasNIC(int32) bool {
+ return false
+}
+
// SocketOptions contains all the variables which store values for SOL_SOCKET,
// SOL_IP, SOL_IPV6 and SOL_TCP level options.
//
@@ -159,6 +167,9 @@ type SocketOptions struct {
errQueueMu sync.Mutex `state:"nosave"`
errQueue sockErrorList
+ // bindToDevice determines the device to which the socket is bound.
+ bindToDevice int32
+
// mu protects the access to the below fields.
mu sync.Mutex `state:"nosave"`
@@ -492,3 +503,18 @@ func (so *SocketOptions) QueueLocalErr(err *Error, net NetworkProtocolNumber, in
NetProto: net,
})
}
+
+// GetBindToDevice gets value for SO_BINDTODEVICE option.
+func (so *SocketOptions) GetBindToDevice() int32 {
+ return atomic.LoadInt32(&so.bindToDevice)
+}
+
+// SetBindToDevice sets value for SO_BINDTODEVICE option.
+func (so *SocketOptions) SetBindToDevice(bindToDevice int32) *Error {
+ if !so.handler.HasNIC(bindToDevice) {
+ return ErrUnknownDevice
+ }
+
+ atomic.StoreInt32(&so.bindToDevice, bindToDevice)
+ return nil
+}