gvisor.dev/gvisor@v0.0.0-20240520182842-f9d4d51c7e0f/pkg/abi/linux/netdevice.go (about)

     1  // Copyright 2018 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 linux
    16  
    17  const (
    18  	// IFNAMSIZ is the size of the name field for IFReq.
    19  	IFNAMSIZ = 16
    20  )
    21  
    22  // IFReq is an interface request.
    23  //
    24  // +marshal
    25  type IFReq struct {
    26  	// IFName is an encoded name, normally null-terminated. This should be
    27  	// accessed via the Name and SetName functions.
    28  	IFName [IFNAMSIZ]byte
    29  
    30  	// Data is the union of the following structures:
    31  	//
    32  	//	struct sockaddr ifr_addr;
    33  	//	struct sockaddr ifr_dstaddr;
    34  	//	struct sockaddr ifr_broadaddr;
    35  	//	struct sockaddr ifr_netmask;
    36  	//	struct sockaddr ifr_hwaddr;
    37  	//	short           ifr_flags;
    38  	//	int             ifr_ifindex;
    39  	//	int             ifr_metric;
    40  	//	int             ifr_mtu;
    41  	//	struct ifmap    ifr_map;
    42  	//	char            ifr_slave[IFNAMSIZ];
    43  	//	char            ifr_newname[IFNAMSIZ];
    44  	//	char           *ifr_data;
    45  	Data [24]byte
    46  }
    47  
    48  // Name returns the name.
    49  func (ifr *IFReq) Name() string {
    50  	for c := 0; c < len(ifr.IFName); c++ {
    51  		if ifr.IFName[c] == 0 {
    52  			return string(ifr.IFName[:c])
    53  		}
    54  	}
    55  	return string(ifr.IFName[:])
    56  }
    57  
    58  // SetName sets the name.
    59  func (ifr *IFReq) SetName(name string) {
    60  	n := copy(ifr.IFName[:], []byte(name))
    61  	clear(ifr.IFName[n:])
    62  }
    63  
    64  // SizeOfIFReq is the binary size of an IFReq struct (40 bytes).
    65  var SizeOfIFReq = (*IFReq)(nil).SizeBytes()
    66  
    67  // IFMap contains interface hardware parameters.
    68  type IFMap struct {
    69  	MemStart uint64
    70  	MemEnd   uint64
    71  	BaseAddr int16
    72  	IRQ      byte
    73  	DMA      byte
    74  	Port     byte
    75  	_        [3]byte // Pad to sizeof(struct ifmap).
    76  }
    77  
    78  // IFConf is used to return a list of interfaces and their addresses. See
    79  // netdevice(7) and struct ifconf for more detail on its use.
    80  //
    81  // +marshal
    82  type IFConf struct {
    83  	Len int32
    84  	_   [4]byte // Pad to sizeof(struct ifconf).
    85  	Ptr uint64
    86  }
    87  
    88  // EthtoolCmd is a marshallable type to be able to easily copyin the
    89  // the command for an SIOCETHTOOL ioctl.
    90  //
    91  // +marshal
    92  type EthtoolCmd uint32
    93  
    94  const (
    95  	// ETHTOOL_GFEATURES is the command to SIOCETHTOOL to query device
    96  	// features.
    97  	// See: <linux/ethtool.h>
    98  	ETHTOOL_GFEATURES EthtoolCmd = 0x3a
    99  )
   100  
   101  // EthtoolGFeatures is used to return a list of device features.
   102  // See: <linux/ethtool.h>
   103  //
   104  // +marshal
   105  type EthtoolGFeatures struct {
   106  	Cmd  uint32
   107  	Size uint32
   108  }
   109  
   110  // EthtoolGetFeaturesBlock is used to return state of upto 32 device
   111  // features.
   112  // See: <linux/ethtool.h>
   113  //
   114  // +marshal
   115  type EthtoolGetFeaturesBlock struct {
   116  	Available    uint32
   117  	Requested    uint32
   118  	Active       uint32
   119  	NeverChanged uint32
   120  }