gvisor.dev/gvisor@v0.0.0-20240520182842-f9d4d51c7e0f/test/syscalls/linux/socket_netlink_route_util.h (about)

     1  // Copyright 2020 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  #ifndef GVISOR_TEST_SYSCALLS_LINUX_SOCKET_NETLINK_ROUTE_UTIL_H_
    16  #define GVISOR_TEST_SYSCALLS_LINUX_SOCKET_NETLINK_ROUTE_UTIL_H_
    17  
    18  #include <linux/netlink.h>
    19  #include <linux/rtnetlink.h>
    20  
    21  #include <vector>
    22  
    23  #include "test/syscalls/linux/socket_netlink_util.h"
    24  
    25  namespace gvisor {
    26  namespace testing {
    27  
    28  struct Link {
    29    int index;
    30    int16_t type;
    31    std::string name;
    32  };
    33  
    34  PosixError DumpLinks(const FileDescriptor& fd, uint32_t seq,
    35                       const std::function<void(const struct nlmsghdr* hdr)>& fn);
    36  
    37  PosixErrorOr<std::vector<Link>> DumpLinks();
    38  
    39  // Returns the loopback link on the system. ENOENT if not found.
    40  PosixErrorOr<Link> LoopbackLink();
    41  
    42  // LinkAddLocalAddr adds a new IFA_LOCAL address to the interface.
    43  PosixError LinkAddLocalAddr(int index, int family, int prefixlen,
    44                              const void* addr, int addrlen);
    45  
    46  // LinkAddExclusiveLocalAddr adds a new IFA_LOCAL address with NLM_F_EXCL flag
    47  // to the interface.
    48  PosixError LinkAddExclusiveLocalAddr(int index, int family, int prefixlen,
    49                                       const void* addr, int addrlen);
    50  
    51  // LinkReplaceLocalAddr replaces an IFA_LOCAL address on the interface.
    52  PosixError LinkReplaceLocalAddr(int index, int family, int prefixlen,
    53                                  const void* addr, int addrlen);
    54  
    55  // LinkDelLocalAddr removes IFA_LOCAL attribute on the interface.
    56  PosixError LinkDelLocalAddr(int index, int family, int prefixlen,
    57                              const void* addr, int addrlen);
    58  
    59  // LinkChangeFlags changes interface flags. E.g. IFF_UP.
    60  PosixError LinkChangeFlags(int index, unsigned int flags, unsigned int change);
    61  
    62  // LinkSetMacAddr sets IFLA_ADDRESS attribute of the interface.
    63  PosixError LinkSetMacAddr(int index, const void* addr, int addrlen);
    64  
    65  // AddRoute adds a route to the given dst subnet via the given interface.
    66  PosixError AddUnicastRoute(int interface, int family, int prefixlen,
    67                             const void* dst, int dstlen);
    68  
    69  // DelRoute removes a route to the given dst subnet via the given interface.
    70  PosixError DelUnicastRoute(int interface, int family, int prefixlen,
    71                             const void* dst, int dstlen);
    72  
    73  // AddExclusiveLookupInTableRule adds a PBR rule that performs a route lookup
    74  // against the given table, for all packets destined to the given subnet.
    75  PosixError AddExclusiveLookupInTableRule(int family, int table, int priority,
    76                                           int prefixlen, const void* dst,
    77                                           int dstlen);
    78  
    79  // DelLookupInTableRule deletes a PBR rule that performs a route lookup against
    80  // given table, for all packets destined to the given subnet.
    81  PosixError DelLookupInTableRule(int family, int table, int priority,
    82                                  int prefixlen, const void* dst, int dstlen);
    83  
    84  }  // namespace testing
    85  }  // namespace gvisor
    86  
    87  #endif  // GVISOR_TEST_SYSCALLS_LINUX_SOCKET_NETLINK_ROUTE_UTIL_H_