1 /* $Id$ */
2 
3 /*
4  *   Copyright (c) 2001-2010 Aaron Turner <aturner at synfin dot net>
5  *   Copyright (c) 2013-2018 Fred Klassen <tcpreplay at appneta dot com> - AppNeta
6  *
7  *   The Tcpreplay Suite of tools is free software: you can redistribute it
8  *   and/or modify it under the terms of the GNU General Public License as
9  *   published by the Free Software Foundation, either version 3 of the
10  *   License, or with the authors permission any later version.
11  *
12  *   The Tcpreplay Suite is distributed in the hope that it will be useful,
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *   GNU General Public License for more details.
16  *
17  *   You should have received a copy of the GNU General Public License
18  *   along with the Tcpreplay Suite.  If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 
22 #ifndef _PLUGINS_TYPES_H_
23 #define _PLUGINS_TYPES_H_
24 
25 #include "defines.h"
26 #include "tcpr.h"
27 #include "tcpedit_types.h"
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 
34 /*
35  * Plugin Requires/Provides Bit Masks
36  * If you add any fields to the provides/requires bitmask,
37  * then you also must add appropriate records for
38  * tcpeditdlt_bit_map[] and tcpeditdlt_bit_info[]
39  * in dlt_plugins.c
40  */
41 typedef enum {
42     PLUGIN_MASK_PROTO         = 0x01,
43     PLUGIN_MASK_SRCADDR       = 0x02,
44     PLUGIN_MASK_DSTADDR       = 0x04
45 } tcpeditdlt_bit_mask_t;
46 
47 /* Union of all possible L2 address types */
48 typedef union {
49     u_char ethernet[ETHER_ADDR_LEN]; /* ethernet is 6 bytes long */
50     u_int8_t c_hdlc;                 /* Cisco HDLC is a single byte */
51 } tcpeditdlt_l2address_t;
52 
53 /* What kind of address is the union? */
54 typedef enum {
55     NONE,           /* DLT has no L2 address */
56     ETHERNET,       /* support ethernet */
57     C_HDLC,         /* Cisco HDLC uses a 1 byte addr which has only two values 0x0F & 0xBF */
58 } tcpeditdlt_l2addr_type_t;
59 
60 /* src or dst mac */
61 typedef enum {
62     SRC_MAC,
63     DST_MAC
64 } tcpeditdlt_mac_type_t;
65 
66 /* MAC address buffer length */
67 #define MAX_MAC_LEN 10
68 
69 typedef struct tcpeditdlt_plugin_s tcpeditdlt_plugin_t;
70 typedef struct tcpeditdlt_s tcpeditdlt_t;
71 
72 /*
73  * Each plugin must fill this out so that we know what function
74  * to call from the external API
75  */
76 struct tcpeditdlt_plugin_s {
77     u_int16_t dlt;  /* dlt to register for */
78     char *name;     /* plugin prefix name */
79     struct tcpeditdlt_plugin_s *next; /* next in linked list */
80     int requires; /* bit mask for which fields this plugin encoder requires */
81     int provides; /* bit mask for which fields this plugin decoder provides */
82     int (*plugin_init)(tcpeditdlt_t *);
83     int (*plugin_post_init)(tcpeditdlt_t *);
84     int (*plugin_cleanup)(tcpeditdlt_t *);
85     int (*plugin_parse_opts)(tcpeditdlt_t *);
86     int (*plugin_decode)(tcpeditdlt_t *, const u_char *, const int);
87     int (*plugin_encode)(tcpeditdlt_t *, u_char *, int, tcpr_dir_t);
88     int (*plugin_proto)(tcpeditdlt_t *, const u_char *, const int);
89     int (*plugin_l2len)(tcpeditdlt_t *, const u_char *, const int);
90     u_char *(*plugin_get_layer3)(tcpeditdlt_t *,  u_char *, const int);
91     u_char *(*plugin_merge_layer3)(tcpeditdlt_t *, u_char *, const int, u_char *);
92     tcpeditdlt_l2addr_type_t (*plugin_l2addr_type)(void);
93     u_char *(*plugin_get_mac)(tcpeditdlt_t *, tcpeditdlt_mac_type_t, const u_char *, const int);
94     void *config; /* user configuration data for the encoder */
95     size_t config_size;
96 };
97 
98 
99 #define L2EXTRA_LEN 255 /* size of buffer to hold any extra L2 data parsed from the decoder */
100 
101 /*
102  * internal DLT plugin context
103  */
104 struct tcpeditdlt_s {
105     tcpedit_t *tcpedit;                 /* pointer to our tcpedit context */
106 #ifdef FORCE_ALIGN
107     u_char *l3buff;                     /* pointer for L3 buffer on strictly aligned systems */
108 #endif
109     tcpeditdlt_plugin_t *plugins;       /* registered plugins */
110     tcpeditdlt_plugin_t *decoder;       /* Encoder plugin */
111     tcpeditdlt_plugin_t *encoder;       /* Decoder plugin */
112 
113     /* decoder validator tells us which kind of address we're processing */
114     tcpeditdlt_l2addr_type_t addr_type;
115 
116     /* skip rewriting IP/MAC's which are broadcast or multicast? */
117     int skip_broadcast;
118 
119     /* original DLT */
120     u_int16_t dlt;
121 
122     /*
123      * These variables are filled out for each packet by the decoder
124      */
125     tcpeditdlt_l2address_t srcaddr;         /* filled out source address */
126     tcpeditdlt_l2address_t dstaddr;         /* filled out dst address */
127     int l2len;                              /* set by decoder and updated by encoder */
128     u_int16_t proto;                        /* layer 3 proto type?? */
129     void *decoded_extra;                    /* any extra L2 data from decoder like VLAN tags */
130     size_t decoded_extra_size;              /* size of decode_extra buffer */
131     u_char srcmac[MAX_MAC_LEN];             /* buffers to store the src & dst MAC */
132     u_char dstmac[MAX_MAC_LEN];
133 };
134 
135 
136 
137 #ifdef __cplusplus
138 }
139 #endif
140 
141 
142 #endif
143 
144