tcpedit_types.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /* $Id$ */
  2. /*
  3. * Copyright (c) 2001-2010 Aaron Turner <aturner at synfin dot net>
  4. * Copyright (c) 2013-2024 Fred Klassen <tcpreplay at appneta dot com> - AppNeta
  5. *
  6. * The Tcpreplay Suite of tools is free software: you can redistribute it
  7. * and/or modify it under the terms of the GNU General Public License as
  8. * published by the Free Software Foundation, either version 3 of the
  9. * License, or with the authors permission any later version.
  10. *
  11. * The Tcpreplay Suite is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with the Tcpreplay Suite. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #pragma once
  20. #include "defines.h"
  21. #include "common.h"
  22. #include "tcpr.h"
  23. #ifdef __cplusplus
  24. extern "C" {
  25. #endif
  26. #define TCPEDIT_SOFT_ERROR -2
  27. #define TCPEDIT_ERROR -1
  28. #define TCPEDIT_OK 0
  29. #define TCPEDIT_WARN 1
  30. typedef enum { TCPEDIT_FIXLEN_OFF = 0, TCPEDIT_FIXLEN_PAD, TCPEDIT_FIXLEN_TRUNC, TCPEDIT_FIXLEN_DEL } tcpedit_fixlen;
  31. typedef enum {
  32. TCPEDIT_TTL_MODE_OFF = 0,
  33. TCPEDIT_TTL_MODE_SET,
  34. TCPEDIT_TTL_MODE_ADD,
  35. TCPEDIT_TTL_MODE_SUB
  36. } tcpedit_ttl_mode;
  37. typedef enum { TCPEDIT_EDIT_BOTH = 0, TCPEDIT_EDIT_C2S, TCPEDIT_EDIT_S2C } tcpedit_direction;
  38. typedef enum { BEFORE_PROCESS, AFTER_PROCESS } tcpedit_coder;
  39. #define TCPEDIT_ERRSTR_LEN 1024
  40. typedef struct {
  41. COUNTER packetnum;
  42. COUNTER total_bytes;
  43. COUNTER pkts_edited;
  44. int dlt1;
  45. int dlt2;
  46. char errstr[TCPEDIT_ERRSTR_LEN];
  47. char warnstr[TCPEDIT_ERRSTR_LEN];
  48. #ifdef FORCE_ALIGN
  49. u_char *l3buff;
  50. #endif
  51. } tcpedit_runtime_t;
  52. /*
  53. * need to track some packet info at runtime
  54. */
  55. typedef struct {
  56. int l2len;
  57. int l3len;
  58. int datalen;
  59. u_int8_t l4proto;
  60. u_char *l4data;
  61. u_int16_t sport, dport;
  62. union {
  63. u_int32_t ipv4;
  64. struct tcpr_in6_addr ipv6;
  65. } sip, dip;
  66. } tcpedit_packet_t;
  67. /*
  68. * portmap data struct
  69. */
  70. typedef struct tcpedit_portmap_s {
  71. long from;
  72. long to;
  73. struct tcpedit_portmap_s *next;
  74. } tcpedit_portmap_t;
  75. /*
  76. * all the arguments that the packet editing library supports
  77. */
  78. typedef struct {
  79. bool validated; /* have we run tcpedit_validate()? */
  80. struct tcpeditdlt_s *dlt_ctx;
  81. /* runtime variables, don't mess with these */
  82. tcpedit_runtime_t runtime;
  83. /* skip rewriting IP/MAC's which are broadcast or multicast? */
  84. bool skip_broadcast;
  85. /* pad or truncate packets */
  86. tcpedit_fixlen fixlen;
  87. tcpedit_direction editdir;
  88. /* rewrite ip? */
  89. bool rewrite_ip;
  90. /* rewrite TCP seq/ack numbers? */
  91. u_int32_t tcp_sequence_enable;
  92. u_int32_t tcp_sequence_adjust;
  93. /* fix IP/TCP/UDP checksums */
  94. bool fixcsum;
  95. /* remove ethernet FCS */
  96. bool efcs;
  97. tcpedit_ttl_mode ttl_mode;
  98. u_int8_t ttl_value;
  99. /* TOS/DiffServ/ECN, -1 is disabled, else copy value */
  100. int tos;
  101. /* IPv6 FlowLabel, -1 is disabled, else copy value */
  102. int flowlabel;
  103. /* IPv6 TClass, -1 is disabled, else copy value */
  104. int tclass;
  105. /* rewrite end-point IP addresses between cidrmap1 & cidrmap2 */
  106. tcpr_cidrmap_t *cidrmap1; /* tcpprep cache data */
  107. tcpr_cidrmap_t *cidrmap2;
  108. /* src & dst IP mapping */
  109. tcpr_cidrmap_t *srcipmap;
  110. tcpr_cidrmap_t *dstipmap;
  111. /* pseudo-randomize IP addresses using a seed */
  112. uint32_t seed;
  113. /* rewrite tcp/udp ports */
  114. tcpedit_portmap_t *portmap;
  115. int mtu; /* Deal with different MTU's */
  116. bool mtu_truncate; /* Should we truncate frames > MTU? */
  117. int maxpacket; /* L2 header + MTU */
  118. uint32_t fuzz_seed;
  119. uint32_t fuzz_factor;
  120. /* fix header length */
  121. bool fixhdrlen;
  122. } tcpedit_t;
  123. #ifdef __cplusplus
  124. }
  125. #endif