dlt_plugins-int.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /* $Id: dlt_plugins-int.h 1841 2007-04-26 03:43:14Z aturner $ */
  2. /*
  3. * Copyright (c) 2006-2007 Aaron Turner.
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. *
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * 3. Neither the names of the copyright owners nor the names of its
  16. * contributors may be used to endorse or promote products derived from
  17. * this software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  20. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  21. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  22. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  23. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  24. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  25. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  26. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
  27. * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  28. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  29. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. */
  31. /*
  32. * Internal data structures and helper functions for DLT plugins
  33. * Should not be available outside of the plugin framework
  34. */
  35. #ifndef _DLT_PLUGINS_INT_H_
  36. #define _DLT_PLUGINS_INT_H_
  37. #include "tcpedit-int.h"
  38. #include "tcpr.h"
  39. #include "dlt_plugins.h"
  40. #include "tcpedit_stub.h"
  41. /*
  42. * Plugin Requires/Provides Bit Masks
  43. * If you add any fields to the provides/requires bitmask,
  44. * then you also must add appropriate records for
  45. * tcpeditdlt_bit_map[] and tcpeditdlt_bit_info[]
  46. * in dlt_plugins.c
  47. */
  48. enum tcpeditdlt_bit_mask_e {
  49. PLUGIN_MASK_PROTO = 0x01,
  50. PLUGIN_MASK_SRCADDR = 0x02,
  51. PLUGIN_MASK_DSTADDR = 0x04
  52. };
  53. typedef enum tcpeditdlt_bit_mask_e tcpeditdlt_bit_mask_t;
  54. /* Union of all possible L2 address types */
  55. union tcpeditdlt_l2address_u {
  56. u_char ethernet[ETHER_ADDR_LEN]; /* ethernet is 6 bytes long */
  57. u_int8_t c_hdlc; /* Cisco HDLC is a single byte */
  58. };
  59. typedef union tcpeditdlt_l2address_u tcpeditdlt_l2address_t;
  60. /* What kind of address is the union? */
  61. enum tcpeditdlt_l2addr_type_e {
  62. NONE, /* DLT has no L2 address */
  63. ETHERNET, /* support ethernet */
  64. C_HDLC, /* Cisco HDLC uses a 1 byte addr which has only two values 0x0F & 0xBF */
  65. };
  66. typedef enum tcpeditdlt_l2addr_type_e tcpeditdlt_l2addr_type_t;
  67. /* src or dst mac */
  68. enum tcpeditdlt_mac_type_e {
  69. SRC_MAC,
  70. DST_MAC
  71. };
  72. typedef enum tcpeditdlt_mac_type_e tcpeditdlt_mac_type_t;
  73. /* MAC address buffer length */
  74. #define MAX_MAC_LEN 10
  75. /*
  76. * Each plugin must fill this out so that we know what function
  77. * to call from the external API
  78. */
  79. struct tcpeditdlt_plugin_s {
  80. u_int16_t dlt; /* dlt to register for */
  81. char *name; /* plugin prefix name */
  82. struct tcpeditdlt_plugin_s *next; /* next in linked list */
  83. int requires; /* bit mask for which fields this plugin encoder requires */
  84. int provides; /* bit mask for which fields this plugin decoder provides */
  85. int (*plugin_init)(tcpeditdlt_t *);
  86. int (*plugin_cleanup)(tcpeditdlt_t *);
  87. int (*plugin_parse_opts)(tcpeditdlt_t *);
  88. int (*plugin_decode)(tcpeditdlt_t *, const u_char *, const int);
  89. int (*plugin_encode)(tcpeditdlt_t *, u_char **, int, tcpr_dir_t);
  90. int (*plugin_proto)(tcpeditdlt_t *, const u_char *, const int);
  91. int (*plugin_l2len)(tcpeditdlt_t *, const u_char *, const int);
  92. u_char *(*plugin_get_layer3)(tcpeditdlt_t *, u_char *, const int);
  93. u_char *(*plugin_merge_layer3)(tcpeditdlt_t *, u_char *, const int, u_char *);
  94. tcpeditdlt_l2addr_type_t (*plugin_l2addr_type)(void);
  95. u_char *(*plugin_get_mac)(tcpeditdlt_t *, tcpeditdlt_mac_type_t, const u_char *, const int);
  96. void *config; /* user configuration data for the encoder */
  97. };
  98. typedef struct tcpeditdlt_plugin_s tcpeditdlt_plugin_t;
  99. #define L2EXTRA_LEN 255 /* size of buffer to hold any extra L2 data parsed from the decoder */
  100. /*
  101. * internal DLT plugin context
  102. */
  103. struct tcpeditdlt_s {
  104. tcpedit_t *tcpedit; /* pointer to our tcpedit context */
  105. #ifdef FORCE_ALIGN
  106. u_char *l3buff; /* pointer for L3 buffer on strictly aligned systems */
  107. #endif
  108. tcpeditdlt_plugin_t *plugins; /* registered plugins */
  109. tcpeditdlt_plugin_t *decoder; /* Encoder plugin */
  110. tcpeditdlt_plugin_t *encoder; /* Decoder plugin */
  111. /* decoder validator tells us which kind of address we're processing */
  112. tcpeditdlt_l2addr_type_t addr_type;
  113. /* skip rewriting IP/MAC's which are broadcast or multicast? */
  114. int skip_broadcast;
  115. /* original DLT */
  116. u_int16_t dlt;
  117. /*
  118. * These variables are filled out for each packet by the decoder
  119. */
  120. /* The following fields are updated on a per-packet basis by the decoder */
  121. tcpeditdlt_l2address_t srcaddr; /* filled out source address */
  122. tcpeditdlt_l2address_t dstaddr; /* filled out dst address */
  123. int l2len; /* set by decoder and updated by encoder */
  124. u_int16_t proto; /* layer 3 proto type?? */
  125. void *decoded_extra; /* any extra L2 data from decoder like VLAN tags */
  126. u_char srcmac[MAX_MAC_LEN]; /* buffers to store the src & dst MAC */
  127. u_char dstmac[MAX_MAC_LEN];
  128. };
  129. #endif