libnet  latest
A Portable Framework for Low-Level Network Packet Construction
libnet-structures.h
1 /*
2  * libnet-structures.h - Network routine library structures header file
3  *
4  * Copyright (c) 1998 - 2004 Mike D. Schiffman <mike@infonexus.com>
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  * 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  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  *
28  */
29 
30 #ifndef __LIBNET_STRUCTURES_H
31 #define __LIBNET_STRUCTURES_H
32 
33 #if ((_WIN32) && !(__CYGWIN__))
34 #include "Packet32.h"
35 #endif
36 
37 /* port list chain structure */
40 {
41  uint16_t node; /* node number */
42  uint16_t bport; /* beginning port */
43  uint16_t eport; /* terminating port */
44  uint8_t id; /* global array offset */
45  libnet_plist_t *next; /* next node in the list */
46 };
47 
48 
49 /* libnet statistics structure */
51 {
52  int64_t packets_sent; /* packets sent */
53  int64_t packet_errors; /* packets errors */
54  int64_t bytes_written; /* bytes written */
55 };
56 
57 
58 /*
59  * Libnet ptags are how we identify specific protocol blocks inside the
60  * list.
61  */
62 typedef int32_t libnet_ptag_t;
63 #define LIBNET_PTAG_INITIALIZER 0
64 
65 
66 /*
67  * Libnet generic protocol block memory object. Sort of a poor man's mbuf.
68  */
70 {
71  uint8_t *buf; /* protocol buffer */
72  uint32_t b_len; /* length of buf */
73  uint16_t h_len; /* header length */
74  /* Passed as last argument to libnet_do_checksum(). Not necessarily used
75  * by that function, it is essentially a pblock specific number, passed
76  * from _builder to the _do_checksum
77  *
78  * Unused for IPV4_H block types.
79  *
80  * For protocols that sit on top of IP, it should be the the amount of
81  * buf that will be included in the checksum, starting from the beginning
82  * of the header.
83  */
84  uint32_t copied; /* bytes copied - the amount of data copied into buf */
85  /* Used and updated by libnet_pblock_append(). */
86  uint8_t type; /* type of pblock */
87 /* this needs to be updated every time a new packet builder is added */
88 /* libnet_diag_dump_pblock_type() also needs updating for every new pblock tag */
89 #define LIBNET_PBLOCK_ARP_H 0x01 /* ARP header */
90 #define LIBNET_PBLOCK_DHCPV4_H 0x02 /* DHCP v4 header */
91 #define LIBNET_PBLOCK_DNSV4_H 0x03 /* DNS v4 header */
92 #define LIBNET_PBLOCK_ETH_H 0x04 /* Ethernet header */
93 #define LIBNET_PBLOCK_ICMPV4_H 0x05 /* ICMP v4 base header */
94 #define LIBNET_PBLOCK_ICMPV4_ECHO_H 0x06 /* ICMP v4 echo header */
95 #define LIBNET_PBLOCK_ICMPV4_MASK_H 0x07 /* ICMP v4 mask header */
96 #define LIBNET_PBLOCK_ICMPV4_UNREACH_H 0x08 /* ICMP v4 unreach header */
97 #define LIBNET_PBLOCK_ICMPV4_TIMXCEED_H 0x09 /* ICMP v4 exceed header */
98 #define LIBNET_PBLOCK_ICMPV4_REDIRECT_H 0x0a /* ICMP v4 redirect header */
99 #define LIBNET_PBLOCK_ICMPV4_TS_H 0x0b /* ICMP v4 timestamp header */
100 #define LIBNET_PBLOCK_IGMP_H 0x0c /* IGMP header */
101 #define LIBNET_PBLOCK_IPV4_H 0x0d /* IP v4 header */
102 #define LIBNET_PBLOCK_IPO_H 0x0e /* IP v4 options */
103 #define LIBNET_PBLOCK_IPDATA 0x0f /* IP data */
104 #define LIBNET_PBLOCK_OSPF_H 0x10 /* OSPF base header */
105 #define LIBNET_PBLOCK_OSPF_HELLO_H 0x11 /* OSPF hello header */
106 #define LIBNET_PBLOCK_OSPF_DBD_H 0x12 /* OSPF dbd header */
107 #define LIBNET_PBLOCK_OSPF_LSR_H 0x13 /* OSPF lsr header */
108 #define LIBNET_PBLOCK_OSPF_LSU_H 0x14 /* OSPF lsu header */
109 #define LIBNET_PBLOCK_OSPF_LSA_H 0x15 /* OSPF lsa header */
110 #define LIBNET_PBLOCK_OSPF_AUTH_H 0x16 /* OSPF auth header */
111 #define LIBNET_PBLOCK_OSPF_CKSUM 0x17 /* OSPF checksum header */
112 #define LIBNET_PBLOCK_LS_RTR_H 0x18 /* linkstate rtr header */
113 #define LIBNET_PBLOCK_LS_NET_H 0x19 /* linkstate net header */
114 #define LIBNET_PBLOCK_LS_SUM_H 0x1a /* linkstate as sum header */
115 #define LIBNET_PBLOCK_LS_AS_EXT_H 0x1b /* linkstate as ext header */
116 #define LIBNET_PBLOCK_NTP_H 0x1c /* NTP header */
117 #define LIBNET_PBLOCK_RIP_H 0x1d /* RIP header */
118 #define LIBNET_PBLOCK_TCP_H 0x1e /* TCP header */
119 #define LIBNET_PBLOCK_TCPO_H 0x1f /* TCP options */
120 #define LIBNET_PBLOCK_TCPDATA 0x20 /* TCP data */
121 #define LIBNET_PBLOCK_UDP_H 0x21 /* UDP header */
122 #define LIBNET_PBLOCK_VRRP_H 0x22 /* VRRP header */
123 #define LIBNET_PBLOCK_DATA_H 0x23 /* generic data */
124 #define LIBNET_PBLOCK_CDP_H 0x24 /* CDP header */
125 #define LIBNET_PBLOCK_IPSEC_ESP_HDR_H 0x25 /* IPSEC ESP header */
126 #define LIBNET_PBLOCK_IPSEC_ESP_FTR_H 0x26 /* IPSEC ESP footer */
127 #define LIBNET_PBLOCK_IPSEC_AH_H 0x27 /* IPSEC AH header */
128 #define LIBNET_PBLOCK_802_1Q_H 0x28 /* 802.1q header */
129 #define LIBNET_PBLOCK_802_2_H 0x29 /* 802.2 header */
130 #define LIBNET_PBLOCK_802_2SNAP_H 0x2a /* 802.2 SNAP header */
131 #define LIBNET_PBLOCK_802_3_H 0x2b /* 802.3 header */
132 #define LIBNET_PBLOCK_STP_CONF_H 0x2c /* STP configuration header */
133 #define LIBNET_PBLOCK_STP_TCN_H 0x2d /* STP TCN header */
134 #define LIBNET_PBLOCK_ISL_H 0x2e /* ISL header */
135 #define LIBNET_PBLOCK_IPV6_H 0x2f /* IP v6 header */
136 #define LIBNET_PBLOCK_802_1X_H 0x30 /* 802.1x header */
137 #define LIBNET_PBLOCK_RPC_CALL_H 0x31 /* RPC Call header */
138 #define LIBNET_PBLOCK_MPLS_H 0x32 /* MPLS header */
139 #define LIBNET_PBLOCK_FDDI_H 0x33 /* FDDI header */
140 #define LIBNET_PBLOCK_TOKEN_RING_H 0x34 /* TOKEN RING header */
141 #define LIBNET_PBLOCK_BGP4_HEADER_H 0x35 /* BGP4 header */
142 #define LIBNET_PBLOCK_BGP4_OPEN_H 0x36 /* BGP4 open header */
143 #define LIBNET_PBLOCK_BGP4_UPDATE_H 0x37 /* BGP4 update header */
144 #define LIBNET_PBLOCK_BGP4_NOTIFICATION_H 0x38 /* BGP4 notification header */
145 #define LIBNET_PBLOCK_GRE_H 0x39 /* GRE header */
146 #define LIBNET_PBLOCK_GRE_SRE_H 0x3a /* GRE SRE header */
147 #define LIBNET_PBLOCK_IPV6_FRAG_H 0x3b /* IPv6 frag header */
148 #define LIBNET_PBLOCK_IPV6_ROUTING_H 0x3c /* IPv6 routing header */
149 #define LIBNET_PBLOCK_IPV6_DESTOPTS_H 0x3d /* IPv6 dest opts header */
150 #define LIBNET_PBLOCK_IPV6_HBHOPTS_H 0x3e /* IPv6 hop/hop opts header */
151 #define LIBNET_PBLOCK_SEBEK_H 0x3f /* Sebek header */
152 #define LIBNET_PBLOCK_HSRP_H 0x40 /* HSRP header */
153 #define LIBNET_PBLOCK_ICMPV6_H 0x41 /* ICMPv6 header (unused) */
154 #define LIBNET_PBLOCK_ICMPV6_ECHO_H 0x46 /* ICMPv6 echo header */
155 #define LIBNET_PBLOCK_ICMPV6_UNREACH_H 0x42 /* ICMPv6 unreach header */
156 #define LIBNET_PBLOCK_ICMPV6_NDP_NSOL_H 0x43 /* ICMPv6 NDP neighbor solicitation header */
157 #define LIBNET_PBLOCK_ICMPV6_NDP_NADV_H 0x44 /* ICMPv6 NDP neighbor advertisement header */
158 #define LIBNET_PBLOCK_ICMPV6_NDP_OPT_H 0x45 /* ICMPv6 NDP option */
159 #define LIBNET_PBLOCK_LLDP_H 0x50 /* LLDP header */
160 #define LIBNET_PBLOCK_LLDP_CHASSIS_H 0x51 /* LLDP Chassis header */
161 #define LIBNET_PBLOCK_LLDP_PORT_H 0x52 /* LLDP Port header */
162 #define LIBNET_PBLOCK_LLDP_TTL_H 0x53 /* LLDP TTL header */
163 #define LIBNET_PBLOCK_LLDP_END_H 0x54 /* LLDP End of LLDPDU header */
164 #define LIBNET_PBLOCK_LLDP_ORG_SPEC_H 0x55 /* LLDP Organization Specific header */
165 #define LIBNET_PBLOCK_UDLD_H 0x56 /* UDLD header */
166 #define LIBNET_PBLOCK_UDLD_DEVICE_ID_H 0x57 /* UDLD Device ID header*/
167 #define LIBNET_PBLOCK_UDLD_PORT_ID_H 0x58 /* UDLD Port ID header */
168 #define LIBNET_PBLOCK_UDLD_ECHO_H 0x59 /* UDLD Echo ID header */
169 #define LIBNET_PBLOCK_UDLD_MSG_INTERVAL_H 0x60 /* UDLD Message Interval header */
170 #define LIBNET_PBLOCK_UDLD_TMT_INTERVAL_H 0x61 /* UDLD Timeout Interval header */
171 #define LIBNET_PBLOCK_UDLD_DEVICE_NAME_H 0x62 /* UDLD Device Name header*/
172 #define LIBNET_PBLOCK_UDLD_SEQ_NUMBER_H 0x63 /* UDLD Sequence Number header */
173 
174  uint8_t flags; /* control flags */
175 #define LIBNET_PBLOCK_DO_CHECKSUM 0x01 /* needs a checksum */
176  libnet_ptag_t ptag; /* protocol block tag */
177  /* Chains are built from highest level protocol, towards the link level, so
178  * prev traverses away from link level, and next traverses towards the
179  * link level.
180  */
181  struct libnet_protocol_block *next; /* next pblock */
182  struct libnet_protocol_block *prev; /* prev pblock */
183 };
184 typedef struct libnet_protocol_block libnet_pblock_t;
185 
186 
187 /*
188  * Libnet context
189  * Opaque structure. Nothing in here should ever been touched first hand by
190  * the applications programmer.
191  */
193 {
194 #if ((_WIN32) && !(__CYGWIN__))
195  SOCKET fd;
196  LPADAPTER lpAdapter;
197 #else
198  int fd; /* file descriptor of packet device */
199 #endif
200  int injection_type; /* one of: */
201 #define LIBNET_NONE 0xf8 /* no injection type, only construct packets */
202 #define LIBNET_LINK 0x00 /* link-layer interface */
203 #define LIBNET_RAW4 0x01 /* raw socket interface (ipv4) */
204 #define LIBNET_RAW6 0x02 /* raw socket interface (ipv6) */
205 /* the following should actually set a flag in the flags variable above */
206 #define LIBNET_LINK_ADV 0x08 /* advanced mode link-layer */
207 #define LIBNET_RAW4_ADV 0x09 /* advanced mode raw socket (ipv4) */
208 #define LIBNET_RAW6_ADV 0x0a /* advanced mode raw socket (ipv6) */
209 #define LIBNET_ADV_MASK 0x08 /* mask to determine adv mode */
210 
211  /* _blocks is the highest level, and _end is closest to link-level */
212  libnet_pblock_t *protocol_blocks; /* protocol headers / data */
213  libnet_pblock_t *pblock_end; /* last node in list */
214  uint32_t n_pblocks; /* number of pblocks */
215 
216  int link_type; /* link-layer type, a DLT_ value. */
217  /* These are the only values used by libnet (see libnet_build_arp and
218  * libnet_build_link). Other values are assigned by the various
219  * libnet_link_*.c OS support functions, but are not yet used or supported,
220  * they are effectively dead code. <pcap.h> claims these two are invariant
221  * across operating systems... hopefully it is correct!
222  */
223 #ifndef DLT_EN10MB
224 # define DLT_EN10MB 1 /* Ethernet (10Mb) */
225 #endif
226 #ifndef DLT_IEEE802
227 # define DLT_IEEE802 6 /* IEEE 802 Networks */
228 #endif
229 
230  int link_offset; /* link-layer header size */
231  int aligner; /* used to align packets */
232  char *device; /* device name */
233 
234  struct libnet_stats stats; /* statistics */
235  libnet_ptag_t ptag_state; /* state holder for pblock tag */
236  char label[LIBNET_LABEL_SIZE]; /* textual label for cq interface */
237 
238  char err_buf[LIBNET_ERRBUF_SIZE]; /* error buffer */
239  uint32_t total_size; /* total size */
240 
241  struct libnet_ether_addr link_addr; /* Link HW addr */
242 };
243 typedef struct libnet_context libnet_t;
244 
245 /*
246  * Libnet context queue structure
247  * Opaque structure. Nothing in here should ever been touched first hand by
248  * the applications programmer.
249  */
250 typedef struct _libnet_context_queue libnet_cq_t;
252 {
253  libnet_t *context; /* pointer to libnet context */
254  libnet_cq_t *next; /* next node in the list */
255  libnet_cq_t *prev; /* previous node in the list */
256 };
257 
259 {
260  uint32_t node; /* number of nodes in the list */
261  uint32_t cq_lock; /* lock status */
262  libnet_cq_t *current; /* current context */
263 };
264 typedef struct _libnet_context_queue_descriptor libnet_cqd_t;
265 
266 #endif /* __LIBNET_STRUCTURES_H */
267 
Definition: libnet-structures.h:251
Definition: libnet-structures.h:192
Definition: libnet-structures.h:69
Definition: libnet-structures.h:50
Definition: libnet-structures.h:258
#define LIBNET_ERRBUF_SIZE
The libnet error buffer is 256 bytes long.
Definition: libnet-macros.h:112
Definition: libnet-structures.h:39
Definition: libnet-headers.h:626