• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************/
2 /*                                                                            */
3 /*   Copyright (c) International Business Machines  Corp., 2005, 2006         */
4 /*                                                                            */
5 /*   This program is free software;  you can redistribute it and/or modify    */
6 /*   it under the terms of the GNU General Public License as published by     */
7 /*   the Free Software Foundation; either version 2 of the License, or        */
8 /*   (at your option) any later version.                                      */
9 /*                                                                            */
10 /*   This program is distributed in the hope that it will be useful,          */
11 /*   but WITHOUT ANY WARRANTY;  without even the implied warranty of          */
12 /*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See                */
13 /*   the GNU General Public License for more details.                         */
14 /*                                                                            */
15 /*   You should have received a copy of the GNU General Public License        */
16 /*   along with this program;  if not, write to the Free Software             */
17 /*   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA  */
18 /*                                                                            */
19 /******************************************************************************/
20 
21 
22 /*
23  * File:
24  *	ns-traffic.h
25  *
26  * Description:
27  *	Header file for TCP/UDP traffic utilities
28  *
29  * Author:
30  *	Mitsuru Chinen <mitch@jp.ibm.com>
31  *
32  * History:
33  *	Oct 19 2005 - Created (Mitsuru Chinen)
34  *	May  1 2006 - Added functions for broken_ip, route, multicast tests
35  *---------------------------------------------------------------------------*/
36 
37 #ifndef _NS_TRAFFIC_H
38 #define _NS_TRAFFIC_H 1
39 
40 /*
41  * Gloval variables
42  */
43 #ifdef NS_COMMON
44 #  define EXTERN
45 #else
46 #  define EXTERN extern
47 #endif
48 EXTERN int debug;		/* If nonzero, output debug information. */
49 
50 /*
51  * Include headers
52  */
53 #include <netdb.h>
54 #include <net/if.h>
55 #include <net/if_arp.h>
56 #include <netinet/ip_icmp.h>
57 #include <netinet/ip6.h>
58 #include <netinet/icmp6.h>
59 #include <netpacket/packet.h>
60 #include <linux/if_ether.h>
61 
62 
63 /*
64  * Fixed Values
65  */
66 #define PORTNUMMIN		IPPORT_RESERVED + 1
67 #define PORTNUMMAX		0xFFFF
68 #define ETH_DATA_MAXSIZE	1500
69 #define IPV4_PACKET_ID		0xBEEF
70 #define IPV4_DEFAULT_TTL	64
71 #define IPV4_DEFAULT_FLAG	0x4000
72 #define IPV4_PAYLOAD_MAXSIZE	1480
73 #define IPV6_DEFAULT_HOPLIMIT	255
74 #define IPV6_PAYLOAD_MAXSIZE	1460
75 #define ICMP_ECHO_ID		0xCAFE
76 #define ICMPV4_DATA_MAXSIZE	1472
77 #define ICMPV6_DATA_MAXSIZE	1452
78 #define RDOPT_MAXSIZE		1412
79 
80 #define FAKE_VERSION	0x01
81 #define FAKE_IHL	0x02
82 #define FAKE_TOT_LEN	0x04
83 #define FAKE_PLEN	0x04
84 #define FAKE_FRAGMENT	0x08
85 #define FAKE_PROTOCOL	0x10
86 #define FAKE_NXT	0x10
87 #define FAKE_CHECK	0x20
88 #define FAKE_DADDR	0x40
89 
90 #define PROC_IFINET6_FILE		"/proc/net/if_inet6"
91 #define PROC_IFINET6_FILE_LINELENGTH	64
92 #define PROC_IFINET6_LINKLOCAL		0x20
93 
94 
95 /*
96  * Structure definition
97  */
98 struct eth_frame {
99     struct ethhdr hdr;
100     unsigned char data[ETH_DATA_MAXSIZE];
101 };
102 
103 struct arp_datagram {
104     struct arphdr hdr;
105     unsigned char ar_sha[ETH_ALEN];
106     unsigned char ar_sip[4];
107     unsigned char ar_tha[ETH_ALEN];
108     unsigned char ar_tip[4];
109 };
110 
111 struct ip4_datagram {
112     struct iphdr hdr;
113     unsigned char payload[IPV4_PAYLOAD_MAXSIZE];
114 };
115 
116 struct icmp4_segment {
117     struct icmphdr hdr;
118     unsigned char data[ICMPV4_DATA_MAXSIZE];
119 };
120 
121 struct ip6_datagram {
122     struct ip6_hdr hdr;
123     unsigned char payload[IPV6_PAYLOAD_MAXSIZE];
124 };
125 
126 struct pseudo_ip6_hdr {
127     struct in6_addr p_ip6_src;
128     struct in6_addr p_ip6_dst;
129     u_int32_t p_ip6_plen;
130     u_int16_t p_ip6_zero1;
131     u_int8_t p_ip6_zero2;
132     u_int8_t p_ip6_nxt;
133 };
134 
135 struct pseudo_ip6_datagram {
136     struct pseudo_ip6_hdr hdr;
137     unsigned char payload[IPV6_PAYLOAD_MAXSIZE];
138 };
139 
140 struct icmp6_segment {
141     struct icmp6_hdr hdr;
142     unsigned char data[ICMPV6_DATA_MAXSIZE];
143 };
144 
145 struct neighbor_sol {
146     struct nd_neighbor_solicit defs;
147     struct nd_opt_hdr sla_opt;
148     unsigned char src_laddr[ETH_ALEN];
149 };
150 
151 struct neighbor_adv {
152     struct nd_neighbor_advert defs;
153     struct nd_opt_hdr tla_opt;
154     unsigned char tgt_laddr[ETH_ALEN];
155 };
156 
157 struct neighbor_redirect {
158     struct nd_redirect defs;
159     struct nd_opt_rd_hdr rdopt_hdr;
160     unsigned rdopt_data[RDOPT_MAXSIZE];
161 };
162 
163 
164 struct hbh_router_alert {
165     uint8_t  nxthdr;
166     uint8_t  hbh_len;
167     uint8_t  alart_type;
168     uint8_t  alart_len;
169     uint16_t alart_data;
170     uint8_t  padn_type;
171     uint8_t  padn_len;
172     uint8_t  padn_data[0];
173 };
174 
175 
176 #if !defined(__LITTLE_ENDIAN_BITFIELD) || !defined(__BIG_ENDIAN_BITFIELD)
177 #  include <endian.h>
178 #endif
179 struct my_mldv2_query {
180     uint8_t type;
181     uint8_t code;
182     uint16_t cksum;
183     uint16_t maxdelay;
184     uint16_t reserved;
185     struct in6_addr addr;
186 #if __BYTE_ORDER == __LITTLE_ENDIAN
187     uint8_t qrv:3;
188     uint8_t suppress:1;
189     uint8_t resv:4;
190 #elif __BYTE_ORDER == __BIG_ENDIAN
191     uint8_t resv:4;
192     uint8_t suppress:1;
193     uint8_t qrv:3;
194 #else
195 #  error "Failed to detect endian"
196 #endif
197     uint8_t qqic;
198     uint16_t nsrcs;
199     struct in6_addr srcs[0];
200 };
201 
202 
203 /*
204  * Macros
205  */
206 #define MY_IGMPV3_QUERY_SIZE(numsrc) \
207 		(sizeof(struct igmpv3_query) + (numsrc) * sizeof(uint32_t))
208 
209 #define MY_MLDV2_QUERY_SIZE(numsrc) \
210 		(sizeof(struct my_mldv2_query) \
211 		 + (numsrc) * sizeof(struct in6_addr))
212 
213 #ifdef MLD_MAX_HOST_REPORT_DELAY
214 #  define MY_MLD_MAX_HOST_REPORT_DELAY	MLD_MAX_HOST_REPORT_DELAY
215 #else
216 #  define MY_MLD_MAX_HOST_REPORT_DELAY	1000
217 #endif
218 
219 #define IN6ADDR_ALLNODES_MULTICAST_INIT \
220 	    { { { 0xff,0x02,0,0,0,0,0,0,0,0,0,0,0,0,0,1 } } }
221 
222 /*
223  * Functions in ns-common.c
224  */
225 void fatal_error(char *errmsg);
226 void maximize_sockbuf(int sd);
227 u_int16_t calc_checksum(u_int16_t *data, size_t size);
228 void fill_payload(unsigned char *payload_p, size_t size);
229 int rand_within(int first, int last);
230 u_int32_t bit_change_seed(size_t bitsize, size_t oversize);
231 int eth_pton(int af, const char *str, struct sockaddr_ll *ll);
232 void get_ifinfo(struct ifreq *ans, int sock_fd, const char *ifname, int query);
233 int strtotimespec(const char *str, struct timespec *ts_p);
234 int get_a_lla_byifindex(struct sockaddr_in6 *lla_p, int ifindex);
235 struct addrinfo *get_maddrinfo(sa_family_t family, const char *maddr, const char *portnum);
236 struct group_req *create_group_info(uint32_t ifindex, struct addrinfo *mainfo_p);
237 struct group_filter *create_source_filter(uint32_t ifindex, struct addrinfo *mainfo_p, uint32_t fmode, char *saddrs);
238 
239 #endif
240