txring.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /* $Id$ */
  2. /* Copyright (c) 2010 Dmitriy Gerasimov <gesser@demlabs.ru>
  3. * Copyright (c) 2010 Aaron Turner.
  4. * Copyright (c) 2023 Fred Klassen - AppNet Inc.
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. *
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * 2. Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in the
  15. * documentation and/or other materials provided with the distribution.
  16. * 3. Neither the names of the copyright owners nor the names of its
  17. * contributors may be used to endorse or promote products derived from
  18. * this software without specific prior written permission.
  19. *
  20. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  21. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  22. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  23. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  24. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  25. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  26. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  27. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
  28. * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  29. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  30. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. */
  32. #ifndef COMMON_TXRING_H
  33. #define COMMON_TXRING_H
  34. #include "config.h"
  35. #include "defines.h"
  36. #ifdef HAVE_TX_RING
  37. #if __GLIBC__ >= 2 && __GLIBC_MINOR >= 1
  38. #include <netpacket/packet.h>
  39. #include <net/ethernet.h> /* the L2 protocols */
  40. #else
  41. #include <asm/types.h>
  42. #include <linux/if_packet.h>
  43. #include <linux/if_ether.h> /* The L2 protocols */
  44. #endif
  45. #include <pthread.h>
  46. struct txring_s
  47. {
  48. pthread_t tx_send; /*Poll TX thread*/
  49. volatile struct tpacket_hdr * tx_head; /* Pointer to mmaped memory with TX ring */
  50. struct tpacket_req* treq; /* TX ring parametrs */
  51. volatile unsigned int tx_index; /* TX index */
  52. int tx_size; /* Size of mmaped TX ring */
  53. };
  54. typedef struct txring_s txring_t;
  55. int txring_put(txring_t *txp, const void * data, size_t length);
  56. txring_t* txring_init(int fd, unsigned int mtu);
  57. #endif /* HAVE_TX_RING */
  58. #endif /*COMMON_TXRING_H */