github.com/nicocha30/gvisor-ligolo@v0.0.0-20230726075806-989fa2c0a413/pkg/sentry/socket/netlink/uevent/protocol.go (about)

     1  // Copyright 2019 The gVisor Authors.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  // Package uevent provides a NETLINK_KOBJECT_UEVENT socket protocol.
    16  //
    17  // NETLINK_KOBJECT_UEVENT sockets send udev-style device events. gVisor does
    18  // not support any device events, so these sockets never send any messages.
    19  package uevent
    20  
    21  import (
    22  	"github.com/nicocha30/gvisor-ligolo/pkg/abi/linux"
    23  	"github.com/nicocha30/gvisor-ligolo/pkg/context"
    24  	"github.com/nicocha30/gvisor-ligolo/pkg/sentry/kernel"
    25  	"github.com/nicocha30/gvisor-ligolo/pkg/sentry/socket/netlink"
    26  	"github.com/nicocha30/gvisor-ligolo/pkg/syserr"
    27  )
    28  
    29  // Protocol implements netlink.Protocol.
    30  //
    31  // +stateify savable
    32  type Protocol struct{}
    33  
    34  var _ netlink.Protocol = (*Protocol)(nil)
    35  
    36  // NewProtocol creates a NETLINK_KOBJECT_UEVENT netlink.Protocol.
    37  func NewProtocol(t *kernel.Task) (netlink.Protocol, *syserr.Error) {
    38  	return &Protocol{}, nil
    39  }
    40  
    41  // Protocol implements netlink.Protocol.Protocol.
    42  func (p *Protocol) Protocol() int {
    43  	return linux.NETLINK_KOBJECT_UEVENT
    44  }
    45  
    46  // CanSend implements netlink.Protocol.CanSend.
    47  func (p *Protocol) CanSend() bool {
    48  	return false
    49  }
    50  
    51  // ProcessMessage implements netlink.Protocol.ProcessMessage.
    52  func (p *Protocol) ProcessMessage(ctx context.Context, msg *netlink.Message, ms *netlink.MessageSet) *syserr.Error {
    53  	// Silently ignore all messages.
    54  	return nil
    55  }
    56  
    57  // init registers the NETLINK_KOBJECT_UEVENT provider.
    58  func init() {
    59  	netlink.RegisterProvider(linux.NETLINK_KOBJECT_UEVENT, NewProtocol)
    60  }