github.com/MerlinKodo/gvisor@v0.0.0-20231110090155-957f62ecf90e/pkg/abi/linux/netlink_route.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  // Netlink message types for NETLINK_ROUTE sockets, from uapi/linux/rtnetlink.h.
    18  const (
    19  	RTM_NEWLINK = 16
    20  	RTM_DELLINK = 17
    21  	RTM_GETLINK = 18
    22  	RTM_SETLINK = 19
    23  
    24  	RTM_NEWADDR = 20
    25  	RTM_DELADDR = 21
    26  	RTM_GETADDR = 22
    27  
    28  	RTM_NEWROUTE = 24
    29  	RTM_DELROUTE = 25
    30  	RTM_GETROUTE = 26
    31  
    32  	RTM_NEWNEIGH = 28
    33  	RTM_DELNEIGH = 29
    34  	RTM_GETNEIGH = 30
    35  
    36  	RTM_NEWRULE = 32
    37  	RTM_DELRULE = 33
    38  	RTM_GETRULE = 34
    39  
    40  	RTM_NEWQDISC = 36
    41  	RTM_DELQDISC = 37
    42  	RTM_GETQDISC = 38
    43  
    44  	RTM_NEWTCLASS = 40
    45  	RTM_DELTCLASS = 41
    46  	RTM_GETTCLASS = 42
    47  
    48  	RTM_NEWTFILTER = 44
    49  	RTM_DELTFILTER = 45
    50  	RTM_GETTFILTER = 46
    51  
    52  	RTM_NEWACTION = 48
    53  	RTM_DELACTION = 49
    54  	RTM_GETACTION = 50
    55  
    56  	RTM_NEWPREFIX = 52
    57  
    58  	RTM_GETMULTICAST = 58
    59  
    60  	RTM_GETANYCAST = 62
    61  
    62  	RTM_NEWNEIGHTBL = 64
    63  	RTM_GETNEIGHTBL = 66
    64  	RTM_SETNEIGHTBL = 67
    65  
    66  	RTM_NEWNDUSEROPT = 68
    67  
    68  	RTM_NEWADDRLABEL = 72
    69  	RTM_DELADDRLABEL = 73
    70  	RTM_GETADDRLABEL = 74
    71  
    72  	RTM_GETDCB = 78
    73  	RTM_SETDCB = 79
    74  
    75  	RTM_NEWNETCONF = 80
    76  	RTM_GETNETCONF = 82
    77  
    78  	RTM_NEWMDB = 84
    79  	RTM_DELMDB = 85
    80  	RTM_GETMDB = 86
    81  
    82  	RTM_NEWNSID = 88
    83  	RTM_DELNSID = 89
    84  	RTM_GETNSID = 90
    85  )
    86  
    87  // InterfaceInfoMessage is struct ifinfomsg, from uapi/linux/rtnetlink.h.
    88  //
    89  // +marshal
    90  type InterfaceInfoMessage struct {
    91  	Family uint8
    92  	_      uint8
    93  	Type   uint16
    94  	Index  int32
    95  	Flags  uint32
    96  	Change uint32
    97  }
    98  
    99  // InterfaceInfoMessageSize is the size of InterfaceInfoMessage.
   100  const InterfaceInfoMessageSize = 16
   101  
   102  // Interface flags, from uapi/linux/if.h.
   103  const (
   104  	IFF_UP          = 1 << 0
   105  	IFF_BROADCAST   = 1 << 1
   106  	IFF_DEBUG       = 1 << 2
   107  	IFF_LOOPBACK    = 1 << 3
   108  	IFF_POINTOPOINT = 1 << 4
   109  	IFF_NOTRAILERS  = 1 << 5
   110  	IFF_RUNNING     = 1 << 6
   111  	IFF_NOARP       = 1 << 7
   112  	IFF_PROMISC     = 1 << 8
   113  	IFF_ALLMULTI    = 1 << 9
   114  	IFF_MASTER      = 1 << 10
   115  	IFF_SLAVE       = 1 << 11
   116  	IFF_MULTICAST   = 1 << 12
   117  	IFF_PORTSEL     = 1 << 13
   118  	IFF_AUTOMEDIA   = 1 << 14
   119  	IFF_DYNAMIC     = 1 << 15
   120  	IFF_LOWER_UP    = 1 << 16
   121  	IFF_DORMANT     = 1 << 17
   122  	IFF_ECHO        = 1 << 18
   123  )
   124  
   125  // Interface link attributes, from uapi/linux/if_link.h.
   126  const (
   127  	IFLA_UNSPEC          = 0
   128  	IFLA_ADDRESS         = 1
   129  	IFLA_BROADCAST       = 2
   130  	IFLA_IFNAME          = 3
   131  	IFLA_MTU             = 4
   132  	IFLA_LINK            = 5
   133  	IFLA_QDISC           = 6
   134  	IFLA_STATS           = 7
   135  	IFLA_COST            = 8
   136  	IFLA_PRIORITY        = 9
   137  	IFLA_MASTER          = 10
   138  	IFLA_WIRELESS        = 11
   139  	IFLA_PROTINFO        = 12
   140  	IFLA_TXQLEN          = 13
   141  	IFLA_MAP             = 14
   142  	IFLA_WEIGHT          = 15
   143  	IFLA_OPERSTATE       = 16
   144  	IFLA_LINKMODE        = 17
   145  	IFLA_LINKINFO        = 18
   146  	IFLA_NET_NS_PID      = 19
   147  	IFLA_IFALIAS         = 20
   148  	IFLA_NUM_VF          = 21
   149  	IFLA_VFINFO_LIST     = 22
   150  	IFLA_STATS64         = 23
   151  	IFLA_VF_PORTS        = 24
   152  	IFLA_PORT_SELF       = 25
   153  	IFLA_AF_SPEC         = 26
   154  	IFLA_GROUP           = 27
   155  	IFLA_NET_NS_FD       = 28
   156  	IFLA_EXT_MASK        = 29
   157  	IFLA_PROMISCUITY     = 30
   158  	IFLA_NUM_TX_QUEUES   = 31
   159  	IFLA_NUM_RX_QUEUES   = 32
   160  	IFLA_CARRIER         = 33
   161  	IFLA_PHYS_PORT_ID    = 34
   162  	IFLA_CARRIER_CHANGES = 35
   163  	IFLA_PHYS_SWITCH_ID  = 36
   164  	IFLA_LINK_NETNSID    = 37
   165  	IFLA_PHYS_PORT_NAME  = 38
   166  	IFLA_PROTO_DOWN      = 39
   167  	IFLA_GSO_MAX_SEGS    = 40
   168  	IFLA_GSO_MAX_SIZE    = 41
   169  )
   170  
   171  // InterfaceAddrMessage is struct ifaddrmsg, from uapi/linux/if_addr.h.
   172  //
   173  // +marshal
   174  type InterfaceAddrMessage struct {
   175  	Family    uint8
   176  	PrefixLen uint8
   177  	Flags     uint8
   178  	Scope     uint8
   179  	Index     uint32
   180  }
   181  
   182  // InterfaceAddrMessageSize is the size of InterfaceAddrMessage.
   183  const InterfaceAddrMessageSize = 8
   184  
   185  // Interface attributes, from uapi/linux/if_addr.h.
   186  const (
   187  	IFA_UNSPEC    = 0
   188  	IFA_ADDRESS   = 1
   189  	IFA_LOCAL     = 2
   190  	IFA_LABEL     = 3
   191  	IFA_BROADCAST = 4
   192  	IFA_ANYCAST   = 5
   193  	IFA_CACHEINFO = 6
   194  	IFA_MULTICAST = 7
   195  	IFA_FLAGS     = 8
   196  )
   197  
   198  // Device types, from uapi/linux/if_arp.h.
   199  const (
   200  	ARPHRD_NONE     = 65534
   201  	ARPHRD_ETHER    = 1
   202  	ARPHRD_LOOPBACK = 772
   203  )
   204  
   205  // RouteMessage is struct rtmsg, from uapi/linux/rtnetlink.h.
   206  //
   207  // +marshal
   208  type RouteMessage struct {
   209  	Family uint8
   210  	DstLen uint8
   211  	SrcLen uint8
   212  	TOS    uint8
   213  
   214  	Table    uint8
   215  	Protocol uint8
   216  	Scope    uint8
   217  	Type     uint8
   218  
   219  	Flags uint32
   220  }
   221  
   222  // SizeOfRouteMessage is the size of RouteMessage.
   223  const SizeOfRouteMessage = 12
   224  
   225  // Route types, from uapi/linux/rtnetlink.h.
   226  const (
   227  	// RTN_UNSPEC represents an unspecified route type.
   228  	RTN_UNSPEC = 0
   229  
   230  	// RTN_UNICAST represents a unicast route.
   231  	RTN_UNICAST = 1
   232  
   233  	// RTN_LOCAL represents a route that is accepted locally.
   234  	RTN_LOCAL = 2
   235  
   236  	// RTN_BROADCAST represents a broadcast route (Traffic is accepted locally
   237  	// as broadcast, and sent as broadcast).
   238  	RTN_BROADCAST = 3
   239  
   240  	// RTN_ANYCAST represents a anycast route (Traffic is accepted locally as
   241  	// broadcast but sent as unicast).
   242  	RTN_ANYCAST = 6
   243  
   244  	// RTN_MULTICAST represents a multicast route.
   245  	RTN_MULTICAST = 5
   246  
   247  	// RTN_BLACKHOLE represents a route where all traffic is dropped.
   248  	RTN_BLACKHOLE = 6
   249  
   250  	// RTN_UNREACHABLE represents a route where the destination is unreachable.
   251  	RTN_UNREACHABLE = 7
   252  
   253  	RTN_PROHIBIT = 8
   254  	RTN_THROW    = 9
   255  	RTN_NAT      = 10
   256  	RTN_XRESOLVE = 11
   257  )
   258  
   259  // Route protocols/origins, from uapi/linux/rtnetlink.h.
   260  const (
   261  	RTPROT_UNSPEC   = 0
   262  	RTPROT_REDIRECT = 1
   263  	RTPROT_KERNEL   = 2
   264  	RTPROT_BOOT     = 3
   265  	RTPROT_STATIC   = 4
   266  	RTPROT_GATED    = 8
   267  	RTPROT_RA       = 9
   268  	RTPROT_MRT      = 10
   269  	RTPROT_ZEBRA    = 11
   270  	RTPROT_BIRD     = 12
   271  	RTPROT_DNROUTED = 13
   272  	RTPROT_XORP     = 14
   273  	RTPROT_NTK      = 15
   274  	RTPROT_DHCP     = 16
   275  	RTPROT_MROUTED  = 17
   276  	RTPROT_BABEL    = 42
   277  	RTPROT_BGP      = 186
   278  	RTPROT_ISIS     = 187
   279  	RTPROT_OSPF     = 188
   280  	RTPROT_RIP      = 189
   281  	RTPROT_EIGRP    = 192
   282  )
   283  
   284  // Route scopes, from uapi/linux/rtnetlink.h.
   285  const (
   286  	RT_SCOPE_UNIVERSE = 0
   287  	RT_SCOPE_SITE     = 200
   288  	RT_SCOPE_LINK     = 253
   289  	RT_SCOPE_HOST     = 254
   290  	RT_SCOPE_NOWHERE  = 255
   291  )
   292  
   293  // Route flags, from uapi/linux/rtnetlink.h.
   294  const (
   295  	RTM_F_NOTIFY       = 0x100
   296  	RTM_F_CLONED       = 0x200
   297  	RTM_F_EQUALIZE     = 0x400
   298  	RTM_F_PREFIX       = 0x800
   299  	RTM_F_LOOKUP_TABLE = 0x1000
   300  	RTM_F_FIB_MATCH    = 0x2000
   301  )
   302  
   303  // Route tables, from uapi/linux/rtnetlink.h.
   304  const (
   305  	RT_TABLE_UNSPEC  = 0
   306  	RT_TABLE_COMPAT  = 252
   307  	RT_TABLE_DEFAULT = 253
   308  	RT_TABLE_MAIN    = 254
   309  	RT_TABLE_LOCAL   = 255
   310  )
   311  
   312  // Route attributes, from uapi/linux/rtnetlink.h.
   313  const (
   314  	RTA_UNSPEC        = 0
   315  	RTA_DST           = 1
   316  	RTA_SRC           = 2
   317  	RTA_IIF           = 3
   318  	RTA_OIF           = 4
   319  	RTA_GATEWAY       = 5
   320  	RTA_PRIORITY      = 6
   321  	RTA_PREFSRC       = 7
   322  	RTA_METRICS       = 8
   323  	RTA_MULTIPATH     = 9
   324  	RTA_PROTOINFO     = 10
   325  	RTA_FLOW          = 11
   326  	RTA_CACHEINFO     = 12
   327  	RTA_SESSION       = 13
   328  	RTA_MP_ALGO       = 14
   329  	RTA_TABLE         = 15
   330  	RTA_MARK          = 16
   331  	RTA_MFC_STATS     = 17
   332  	RTA_VIA           = 18
   333  	RTA_NEWDST        = 19
   334  	RTA_PREF          = 20
   335  	RTA_ENCAP_TYPE    = 21
   336  	RTA_ENCAP         = 22
   337  	RTA_EXPIRES       = 23
   338  	RTA_PAD           = 24
   339  	RTA_UID           = 25
   340  	RTA_TTL_PROPAGATE = 26
   341  	RTA_IP_PROTO      = 27
   342  	RTA_SPORT         = 28
   343  	RTA_DPORT         = 29
   344  )
   345  
   346  // Route flags, from include/uapi/linux/route.h.
   347  const (
   348  	RTF_GATEWAY = 0x2
   349  	RTF_UP      = 0x1
   350  )
   351  
   352  // RtAttr is the header of optional addition route information, as a netlink
   353  // attribute. From include/uapi/linux/rtnetlink.h.
   354  //
   355  // +marshal
   356  type RtAttr struct {
   357  	Len  uint16
   358  	Type uint16
   359  }
   360  
   361  // SizeOfRtAttr is the size of RtAttr.
   362  const SizeOfRtAttr = 4