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