netmap.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*
  2. * Copyright (c) 2013 Fred Klassen <fklassen at appneta dot com> - AppNeta
  3. *
  4. * The Tcpreplay Suite of tools is free software: you can redistribute it
  5. * and/or modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation, either version 3 of the
  7. * License, or with the authors permission any later version.
  8. *
  9. * The Tcpreplay Suite is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with the Tcpreplay Suite. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #ifndef NETMAP_H_
  18. #define NETMAP_H_
  19. #include "config.h"
  20. #include "defines.h"
  21. #include <sys/socket.h>
  22. #ifdef __NetBSD__
  23. #include <net/if_ether.h>
  24. #else
  25. #include <netinet/if_ether.h>
  26. #endif
  27. #include <net/if.h>
  28. #include <net/netmap.h>
  29. #include <net/netmap_user.h>
  30. #ifdef linux
  31. # include <linux/ethtool.h>
  32. # include <linux/sockios.h>
  33. #endif /* linux */
  34. #ifndef NETMAP_API
  35. #define NETMAP_API 0
  36. #endif
  37. #if NETMAP_API >= 10
  38. #define NETMAP_TX_RING_EMPTY(ring) (!nm_tx_pending(ring))
  39. #define NETMAP_RING_NEXT(r, i) nm_ring_next(r, i)
  40. #elif defined HAVE_NETMAP_RING_HEAD_TAIL
  41. #define NETMAP_TX_RING_EMPTY(ring) (nm_ring_space(ring) >= (ring)->num_slots - 1)
  42. #define NETMAP_RING_NEXT(r, i) nm_ring_next(r, i)
  43. #else
  44. #define nm_ring_space(ring) (ring->avail)
  45. #endif
  46. #ifndef HAVE_NETMAP_NR_REG
  47. #define NR_REG_MASK 0xf /* values for nr_flags */
  48. #if NETMAP_API < 11
  49. enum { NR_REG_DEFAULT = 0, /* backward compat, used in older versions. */
  50. NR_REG_ALL_NIC,
  51. NR_REG_SW,
  52. NR_REG_NIC_SW,
  53. NR_REG_ONE_NIC,
  54. NR_REG_PIPE_MASTER,
  55. NR_REG_PIPE_SLAVE,
  56. };
  57. #endif /* NETMAP_API < 11 */
  58. #endif
  59. #ifndef NETMAP_HW_RING
  60. #define NETMAP_HW_RING 0x4000 /* single NIC ring pair */
  61. #endif
  62. #ifndef NETMAP_SW_RING
  63. #define NETMAP_SW_RING 0x2000 /* only host ring pair */
  64. #endif
  65. #ifndef NETMAP_RING_MASK
  66. #define NETMAP_RING_MASK 0x0fff /* the ring number */
  67. #endif
  68. #ifndef NETMAP_NO_TX_POLL
  69. #define NETMAP_NO_TX_POLL 0x1000 /* no automatic txsync on poll */
  70. #endif
  71. #ifndef NETMAP_DO_RX_POLL
  72. #define NETMAP_DO_RX_POLL 0x8000 /* DO automatic rxsync on poll */
  73. #endif
  74. #ifndef NETMAP_BDG_ATTACH
  75. #define NETMAP_BDG_ATTACH 1 /* attach the NIC */
  76. #endif
  77. #ifndef NETMAP_BDG_DETACH
  78. #define NETMAP_BDG_DETACH 2 /* detach the NIC */
  79. #endif
  80. #ifndef NETMAP_BDG_LOOKUP_REG
  81. #define NETMAP_BDG_LOOKUP_REG 3 /* register lookup function */
  82. #endif
  83. #ifndef NETMAP_BDG_LIST
  84. #define NETMAP_BDG_LIST 4 /* get bridge's info */
  85. #endif
  86. #ifndef NETMAP_BDG_VNET_HDR
  87. #define NETMAP_BDG_VNET_HDR 5 /* set the port virtio-net-hdr length */
  88. #endif
  89. #ifndef NETMAP_BDG_OFFSET
  90. #define NETMAP_BDG_OFFSET NETMAP_BDG_VNET_HDR /* deprecated alias */
  91. #endif
  92. #ifndef NETMAP_BDG_HOST
  93. #define NETMAP_BDG_HOST 1 /* attach the host stack on ATTACH */
  94. #endif
  95. #ifdef HAVE_NETMAP_NR_FLAGS
  96. typedef struct nmreq nmreq_t;
  97. #else
  98. struct tcpr_nmreq {
  99. char nr_name[IFNAMSIZ];
  100. uint32_t nr_version; /* API version */
  101. uint32_t nr_offset; /* nifp offset in the shared region */
  102. uint32_t nr_memsize; /* size of the shared region */
  103. uint32_t nr_tx_slots; /* slots in tx rings */
  104. uint32_t nr_rx_slots; /* slots in rx rings */
  105. uint16_t nr_tx_rings; /* number of tx rings */
  106. uint16_t nr_rx_rings; /* number of rx rings */
  107. uint16_t nr_ringid; /* ring(s) we care about */
  108. uint16_t nr_cmd;
  109. uint16_t nr_arg1; /* reserve extra rings in NIOCREGIF */
  110. uint16_t nr_arg2;
  111. uint32_t nr_arg3; /* req. extra buffers in NIOCREGIF */
  112. uint32_t nr_flags;
  113. /* various modes, extends nr_ringid */
  114. uint32_t spare2[1];
  115. };
  116. typedef struct tcpr_nmreq nmreq_t;
  117. #endif /* HAVE_NETMAP_NR_FLAGS */
  118. #define NETMAP_TX_TIMEOUT_SEC 10
  119. int get_netmap_version(void);
  120. void *sendpacket_open_netmap(const char *device, char *errbuf, void *arg);
  121. void sendpacket_close_netmap(void *p);
  122. bool netmap_tx_queues_empty(void *p);
  123. int sendpacket_send_netmap(void *p, const u_char *data, size_t len);
  124. #endif /* NETMAP_H_ */