Brandon Kim | dab96f1 | 2021-02-18 11:21:37 -0800 | [diff] [blame] | 1 | // Copyright 2021 Google LLC |
| 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 | |
William A. Kennington III | 7d6fa42 | 2021-02-08 17:04:02 -0800 | [diff] [blame] | 15 | #include "net_iface_mock.h" |
| 16 | |
Willy Tu | adb8ffe | 2023-07-17 13:44:22 -0700 | [diff] [blame] | 17 | #include <linux/if.h> |
| 18 | #include <sys/ioctl.h> |
| 19 | |
William A. Kennington III | 7d6fa42 | 2021-02-08 17:04:02 -0800 | [diff] [blame] | 20 | namespace mock |
| 21 | { |
| 22 | |
Willy Tu | a9a9825 | 2023-09-18 14:49:23 -0700 | [diff] [blame] | 23 | int IFace::bind_sock(int sockfd) const |
William A. Kennington III | 7d6fa42 | 2021-02-08 17:04:02 -0800 | [diff] [blame] | 24 | { |
| 25 | bound_socks.push_back(sockfd); |
| 26 | return 0; |
| 27 | } |
| 28 | |
| 29 | int IFace::ioctl_sock(int, int request, struct ifreq* ifr) const |
| 30 | { |
| 31 | return ioctl(request, ifr); |
| 32 | } |
| 33 | |
| 34 | int IFace::ioctl(int request, struct ifreq* ifr) const |
| 35 | { |
| 36 | int ret = 0; |
| 37 | switch (request) |
| 38 | { |
| 39 | case SIOCGIFINDEX: |
| 40 | ifr->ifr_ifindex = index; |
| 41 | break; |
| 42 | case SIOCGIFFLAGS: |
| 43 | ifr->ifr_flags = flags; |
| 44 | break; |
| 45 | case SIOCSIFFLAGS: |
| 46 | flags = ifr->ifr_flags; |
| 47 | break; |
| 48 | default: |
| 49 | ret = -1; |
| 50 | } |
| 51 | |
| 52 | return ret; |
| 53 | } |
| 54 | |
| 55 | } // namespace mock |