Hugo Benichi | f818c78 | 2021-04-10 00:09:50 +0900 | [diff] [blame] | 1 | // Copyright 2021 The Chromium OS Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef PATCHPANEL_SYSTEM_H_ |
| 6 | #define PATCHPANEL_SYSTEM_H_ |
| 7 | |
| 8 | #include <net/if.h> |
| 9 | #include <net/route.h> |
| 10 | #include <sys/ioctl.h> |
| 11 | |
| 12 | namespace patchpanel { |
| 13 | |
| 14 | // cros lint will yell to force using int16/int64 instead of long here, however |
| 15 | // note that unsigned long IS the correct signature for ioctl in Linux kernel - |
| 16 | // it's 32 bits on 32-bit platform and 64 bits on 64-bit one. |
| 17 | using ioctl_req_t = unsigned long; // NOLINT(runtime/int) |
| 18 | |
| 19 | // Stateless class used for holding all utility functions with side |
| 20 | // effects on the environment. Facilitates mocking these functions in unit |
| 21 | // tests. |
| 22 | class System { |
| 23 | public: |
| 24 | System() = default; |
| 25 | System(const System&) = delete; |
| 26 | System& operator=(const System&) = delete; |
| 27 | virtual ~System() = default; |
| 28 | |
| 29 | virtual int Ioctl(int fd, ioctl_req_t request, const char* argp); |
| 30 | int Ioctl(int fd, ioctl_req_t request, uint64_t arg); |
| 31 | int Ioctl(int fd, ioctl_req_t request, struct ifreq* ifr); |
| 32 | int Ioctl(int fd, ioctl_req_t request, struct rtentry* route); |
| 33 | |
| 34 | private: |
| 35 | }; |
| 36 | |
| 37 | } // namespace patchpanel |
| 38 | |
| 39 | #endif // PATCHPANEL_SYSTEM_H_ |