plugins_types.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /* $Id$ */
  2. /*
  3. * Copyright (c) 2001-2010 Aaron Turner <aturner at synfin dot net>
  4. * Copyright (c) 2013-2018 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. #ifndef _PLUGINS_TYPES_H_
  20. #define _PLUGINS_TYPES_H_
  21. #include "defines.h"
  22. #include "tcpr.h"
  23. #include "tcpedit_types.h"
  24. #ifdef __cplusplus
  25. extern "C" {
  26. #endif
  27. /*
  28. * Plugin Requires/Provides Bit Masks
  29. * If you add any fields to the provides/requires bitmask,
  30. * then you also must add appropriate records for
  31. * tcpeditdlt_bit_map[] and tcpeditdlt_bit_info[]
  32. * in dlt_plugins.c
  33. */
  34. typedef enum {
  35. PLUGIN_MASK_PROTO = 0x01,
  36. PLUGIN_MASK_SRCADDR = 0x02,
  37. PLUGIN_MASK_DSTADDR = 0x04
  38. } tcpeditdlt_bit_mask_t;
  39. /* Union of all possible L2 address types */
  40. typedef union {
  41. u_char ethernet[ETHER_ADDR_LEN]; /* ethernet is 6 bytes long */
  42. u_int8_t c_hdlc; /* Cisco HDLC is a single byte */
  43. } tcpeditdlt_l2address_t;
  44. /* What kind of address is the union? */
  45. typedef enum {
  46. NONE, /* DLT has no L2 address */
  47. ETHERNET, /* support ethernet */
  48. C_HDLC, /* Cisco HDLC uses a 1 byte addr which has only two values 0x0F & 0xBF */
  49. } tcpeditdlt_l2addr_type_t;
  50. /* src or dst mac */
  51. typedef enum {
  52. SRC_MAC,
  53. DST_MAC
  54. } tcpeditdlt_mac_type_t;
  55. /* MAC address buffer length */
  56. #define MAX_MAC_LEN 10
  57. typedef struct tcpeditdlt_plugin_s tcpeditdlt_plugin_t;
  58. typedef struct tcpeditdlt_s tcpeditdlt_t;
  59. /*
  60. * Each plugin must fill this out so that we know what function
  61. * to call from the external API
  62. */
  63. struct tcpeditdlt_plugin_s {
  64. u_int16_t dlt; /* dlt to register for */
  65. char *name; /* plugin prefix name */
  66. struct tcpeditdlt_plugin_s *next; /* next in linked list */
  67. int requires; /* bit mask for which fields this plugin encoder requires */
  68. int provides; /* bit mask for which fields this plugin decoder provides */
  69. int (*plugin_init)(tcpeditdlt_t *);
  70. int (*plugin_post_init)(tcpeditdlt_t *);
  71. int (*plugin_cleanup)(tcpeditdlt_t *);
  72. int (*plugin_parse_opts)(tcpeditdlt_t *);
  73. int (*plugin_decode)(tcpeditdlt_t *, const u_char *, const int);
  74. int (*plugin_encode)(tcpeditdlt_t *, u_char *, int, tcpr_dir_t);
  75. int (*plugin_proto)(tcpeditdlt_t *, const u_char *, const int);
  76. int (*plugin_l2len)(tcpeditdlt_t *, const u_char *, const int);
  77. u_char *(*plugin_get_layer3)(tcpeditdlt_t *, u_char *, const int);
  78. u_char *(*plugin_merge_layer3)(tcpeditdlt_t *, u_char *, const int, u_char *);
  79. tcpeditdlt_l2addr_type_t (*plugin_l2addr_type)(void);
  80. u_char *(*plugin_get_mac)(tcpeditdlt_t *, tcpeditdlt_mac_type_t, const u_char *, const int);
  81. void *config; /* user configuration data for the encoder */
  82. size_t config_size;
  83. };
  84. #define L2EXTRA_LEN 255 /* size of buffer to hold any extra L2 data parsed from the decoder */
  85. /*
  86. * internal DLT plugin context
  87. */
  88. struct tcpeditdlt_s {
  89. tcpedit_t *tcpedit; /* pointer to our tcpedit context */
  90. #ifdef FORCE_ALIGN
  91. u_char *l3buff; /* pointer for L3 buffer on strictly aligned systems */
  92. #endif
  93. tcpeditdlt_plugin_t *plugins; /* registered plugins */
  94. tcpeditdlt_plugin_t *decoder; /* Encoder plugin */
  95. tcpeditdlt_plugin_t *encoder; /* Decoder plugin */
  96. /* decoder validator tells us which kind of address we're processing */
  97. tcpeditdlt_l2addr_type_t addr_type;
  98. /* skip rewriting IP/MAC's which are broadcast or multicast? */
  99. int skip_broadcast;
  100. /* original DLT */
  101. u_int16_t dlt;
  102. /*
  103. * These variables are filled out for each packet by the decoder
  104. */
  105. tcpeditdlt_l2address_t srcaddr; /* filled out source address */
  106. tcpeditdlt_l2address_t dstaddr; /* filled out dst address */
  107. int l2len; /* set by decoder and updated by encoder */
  108. u_int16_t proto; /* layer 3 proto type?? */
  109. void *decoded_extra; /* any extra L2 data from decoder like VLAN tags */
  110. size_t decoded_extra_size; /* size of decode_extra buffer */
  111. u_char srcmac[MAX_MAC_LEN]; /* buffers to store the src & dst MAC */
  112. u_char dstmac[MAX_MAC_LEN];
  113. };
  114. #ifdef __cplusplus
  115. }
  116. #endif
  117. #endif