eth-raw-os.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (c) 2015 National Instruments
  4. *
  5. * (C) Copyright 2015
  6. * Joe Hershberger <joe.hershberger@ni.com>
  7. */
  8. #ifndef __ETH_RAW_OS_H
  9. #define __ETH_RAW_OS_H
  10. #define IFNAMSIZ 16
  11. /**
  12. * struct eth_sandbox_raw_priv - raw socket session
  13. *
  14. * sd: socket descriptor - the open socket during a session
  15. * host_ifname: interface name on the host to use for sending our packets
  16. * host_ifindex: interface index number on the host
  17. * device: struct sockaddr_ll - the host interface packets move to/from
  18. * local: 1 or 0 to select the local interface ('lo') or not
  19. * local_bindsd: socket descriptor to prevent the kernel from sending
  20. * a message to the server claiming the port is
  21. * unreachable
  22. * local_bind_udp_port: The UDP port number that we bound to
  23. */
  24. struct eth_sandbox_raw_priv {
  25. int sd;
  26. char host_ifname[IFNAMSIZ];
  27. unsigned int host_ifindex;
  28. void *device;
  29. int local;
  30. int local_bind_sd;
  31. unsigned short local_bind_udp_port;
  32. };
  33. /* A struct to mimic if_nameindex but that does not depend on Linux headers */
  34. struct sandbox_eth_raw_if_nameindex {
  35. unsigned int if_index; /* Index of interface (1, 2, ...) */
  36. char *if_name; /* Null-terminated name ("eth0", etc.) */
  37. };
  38. /* Enumerate host network interfaces */
  39. struct sandbox_eth_raw_if_nameindex *sandbox_eth_raw_if_nameindex(void);
  40. /* Free the data structure of enumerated network interfaces */
  41. void sandbox_eth_raw_if_freenameindex(struct sandbox_eth_raw_if_nameindex *ptr);
  42. /*
  43. * Check if the interface named "ifname" is a localhost interface or not.
  44. * ifname - the interface name on the host to check
  45. *
  46. * returns - 0 if real interface, 1 if local, negative if error
  47. */
  48. int sandbox_eth_raw_os_is_local(const char *ifname);
  49. /*
  50. * Look up the name of the interface based on the ifindex populated in priv.
  51. *
  52. * Overwrite the host_ifname member in priv based on looking up host_ifindex
  53. *
  54. * returns - 0 if success, negative if error
  55. */
  56. int sandbox_eth_raw_os_idx_to_name(struct eth_sandbox_raw_priv *priv);
  57. int sandbox_eth_raw_os_start(struct eth_sandbox_raw_priv *priv,
  58. unsigned char *ethmac);
  59. int sandbox_eth_raw_os_send(void *packet, int length,
  60. struct eth_sandbox_raw_priv *priv);
  61. int sandbox_eth_raw_os_recv(void *packet, int *length,
  62. const struct eth_sandbox_raw_priv *priv);
  63. void sandbox_eth_raw_os_stop(struct eth_sandbox_raw_priv *priv);
  64. #endif /* __ETH_RAW_OS_H */