blob: 0b511db70c39c210076bff68ee246db406a1d948 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0 */
Joe Hershberger586cbd12015-03-22 17:09:21 -05002/*
3 * Copyright (c) 2015 National Instruments
4 *
5 * (C) Copyright 2015
6 * Joe Hershberger <joe.hershberger@ni.com>
Joe Hershberger586cbd12015-03-22 17:09:21 -05007 */
8
9#ifndef __ETH_RAW_OS_H
10#define __ETH_RAW_OS_H
11
Joe Hershbergere5691402018-07-02 14:47:50 -050012#define IFNAMSIZ 16
13
Joe Hershberger586cbd12015-03-22 17:09:21 -050014/**
15 * struct eth_sandbox_raw_priv - raw socket session
16 *
17 * sd: socket descriptor - the open socket during a session
Joe Hershbergere5691402018-07-02 14:47:50 -050018 * host_ifname: interface name on the host to use for sending our packets
19 * host_ifindex: interface index number on the host
Joe Hershberger586cbd12015-03-22 17:09:21 -050020 * device: struct sockaddr_ll - the host interface packets move to/from
Joe Hershbergera8921922015-03-22 17:09:23 -050021 * 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 Hershberger586cbd12015-03-22 17:09:21 -050026 */
27struct eth_sandbox_raw_priv {
28 int sd;
Joe Hershbergere5691402018-07-02 14:47:50 -050029 char host_ifname[IFNAMSIZ];
30 unsigned int host_ifindex;
Joe Hershberger586cbd12015-03-22 17:09:21 -050031 void *device;
Joe Hershbergera8921922015-03-22 17:09:23 -050032 int local;
33 int local_bind_sd;
34 unsigned short local_bind_udp_port;
Joe Hershberger586cbd12015-03-22 17:09:21 -050035};
36
Joe Hershberger89590c82018-07-02 14:47:54 -050037/* A struct to mimic if_nameindex but that does not depend on Linux headers */
38struct sandbox_eth_raw_if_nameindex {
39 unsigned int if_index; /* Index of interface (1, 2, ...) */
40 char *if_name; /* Null-terminated name ("eth0", etc.) */
41};
42
43/* Enumerate host network interfaces */
44struct sandbox_eth_raw_if_nameindex *sandbox_eth_raw_if_nameindex(void);
45/* Free the data structure of enumerated network interfaces */
46void sandbox_eth_raw_if_freenameindex(struct sandbox_eth_raw_if_nameindex *ptr);
47
Joe Hershberger1b312cb2018-07-02 14:47:51 -050048/*
49 * Check if the interface named "ifname" is a localhost interface or not.
50 * ifname - the interface name on the host to check
51 *
52 * returns - 0 if real interface, 1 if local, negative if error
53 */
54int sandbox_eth_raw_os_is_local(const char *ifname);
55
Joe Hershberger144e14b2018-07-02 14:47:52 -050056/*
57 * Look up the name of the interface based on the ifindex populated in priv.
58 *
59 * Overwrite the host_ifname member in priv based on looking up host_ifindex
60 *
61 * returns - 0 if success, negative if error
62 */
63int sandbox_eth_raw_os_idx_to_name(struct eth_sandbox_raw_priv *priv);
64
Joe Hershbergere5691402018-07-02 14:47:50 -050065int sandbox_eth_raw_os_start(struct eth_sandbox_raw_priv *priv,
66 unsigned char *ethmac);
Joe Hershberger586cbd12015-03-22 17:09:21 -050067int sandbox_eth_raw_os_send(void *packet, int length,
Joe Hershbergera8921922015-03-22 17:09:23 -050068 struct eth_sandbox_raw_priv *priv);
Joe Hershberger586cbd12015-03-22 17:09:21 -050069int sandbox_eth_raw_os_recv(void *packet, int *length,
70 const struct eth_sandbox_raw_priv *priv);
71void sandbox_eth_raw_os_stop(struct eth_sandbox_raw_priv *priv);
72
73#endif /* __ETH_RAW_OS_H */