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