github.com/SagerNet/gvisor@v0.0.0-20210707092255-7731c139d75c/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 } // namespace testing 66 } // namespace gvisor 67 68 #endif // GVISOR_TEST_SYSCALLS_LINUX_SOCKET_NETLINK_ROUTE_UTIL_H_