Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Joe Hershberger | 586cbd1 | 2015-03-22 17:09:21 -0500 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2015 National Instruments |
| 4 | * |
| 5 | * (C) Copyright 2015 |
| 6 | * Joe Hershberger <joe.hershberger@ni.com> |
Joe Hershberger | 586cbd1 | 2015-03-22 17:09:21 -0500 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #ifndef __ETH_RAW_OS_H |
| 10 | #define __ETH_RAW_OS_H |
| 11 | |
Joe Hershberger | e569140 | 2018-07-02 14:47:50 -0500 | [diff] [blame] | 12 | #define IFNAMSIZ 16 |
| 13 | |
Joe Hershberger | 586cbd1 | 2015-03-22 17:09:21 -0500 | [diff] [blame] | 14 | /** |
| 15 | * struct eth_sandbox_raw_priv - raw socket session |
| 16 | * |
| 17 | * sd: socket descriptor - the open socket during a session |
Joe Hershberger | e569140 | 2018-07-02 14:47:50 -0500 | [diff] [blame] | 18 | * host_ifname: interface name on the host to use for sending our packets |
| 19 | * host_ifindex: interface index number on the host |
Joe Hershberger | 586cbd1 | 2015-03-22 17:09:21 -0500 | [diff] [blame] | 20 | * device: struct sockaddr_ll - the host interface packets move to/from |
Joe Hershberger | a892192 | 2015-03-22 17:09:23 -0500 | [diff] [blame] | 21 | * local: 1 or 0 to select the local interface ('lo') or not |
| 22 | * local_bindsd: socket descriptor to prevent the kernel from sending |
| 23 | * a message to the server claiming the port is |
| 24 | * unreachable |
| 25 | * local_bind_udp_port: The UDP port number that we bound to |
Joe Hershberger | 586cbd1 | 2015-03-22 17:09:21 -0500 | [diff] [blame] | 26 | */ |
| 27 | struct eth_sandbox_raw_priv { |
| 28 | int sd; |
Joe Hershberger | e569140 | 2018-07-02 14:47:50 -0500 | [diff] [blame] | 29 | char host_ifname[IFNAMSIZ]; |
| 30 | unsigned int host_ifindex; |
Joe Hershberger | 586cbd1 | 2015-03-22 17:09:21 -0500 | [diff] [blame] | 31 | void *device; |
Joe Hershberger | a892192 | 2015-03-22 17:09:23 -0500 | [diff] [blame] | 32 | int local; |
| 33 | int local_bind_sd; |
| 34 | unsigned short local_bind_udp_port; |
Joe Hershberger | 586cbd1 | 2015-03-22 17:09:21 -0500 | [diff] [blame] | 35 | }; |
| 36 | |
Joe Hershberger | 1b312cb | 2018-07-02 14:47:51 -0500 | [diff] [blame] | 37 | /* |
| 38 | * Check if the interface named "ifname" is a localhost interface or not. |
| 39 | * ifname - the interface name on the host to check |
| 40 | * |
| 41 | * returns - 0 if real interface, 1 if local, negative if error |
| 42 | */ |
| 43 | int sandbox_eth_raw_os_is_local(const char *ifname); |
| 44 | |
Joe Hershberger | 144e14b | 2018-07-02 14:47:52 -0500 | [diff] [blame] | 45 | /* |
| 46 | * Look up the name of the interface based on the ifindex populated in priv. |
| 47 | * |
| 48 | * Overwrite the host_ifname member in priv based on looking up host_ifindex |
| 49 | * |
| 50 | * returns - 0 if success, negative if error |
| 51 | */ |
| 52 | int sandbox_eth_raw_os_idx_to_name(struct eth_sandbox_raw_priv *priv); |
| 53 | |
Joe Hershberger | e569140 | 2018-07-02 14:47:50 -0500 | [diff] [blame] | 54 | int sandbox_eth_raw_os_start(struct eth_sandbox_raw_priv *priv, |
| 55 | unsigned char *ethmac); |
Joe Hershberger | 586cbd1 | 2015-03-22 17:09:21 -0500 | [diff] [blame] | 56 | int sandbox_eth_raw_os_send(void *packet, int length, |
Joe Hershberger | a892192 | 2015-03-22 17:09:23 -0500 | [diff] [blame] | 57 | struct eth_sandbox_raw_priv *priv); |
Joe Hershberger | 586cbd1 | 2015-03-22 17:09:21 -0500 | [diff] [blame] | 58 | int sandbox_eth_raw_os_recv(void *packet, int *length, |
| 59 | const struct eth_sandbox_raw_priv *priv); |
| 60 | void sandbox_eth_raw_os_stop(struct eth_sandbox_raw_priv *priv); |
| 61 | |
| 62 | #endif /* __ETH_RAW_OS_H */ |