1 /*
2  * pkt.h
3  *
4  * Copyright (c) 2001 Dug Song <dugsong@monkey.org>
5  *
6  * $Id: pkt.h,v 1.8 2002/04/07 22:55:20 dugsong Exp $
7  */
8 
9 #ifndef PKT_H
10 #define PKT_H
11 
12 #include <sys/queue.h>
13 #include <sys/time.h>
14 #include <dnet.h>
15 #include <event.h>
16 
17 #ifndef TAILQ_END
18 #define TAILQ_END(head)	NULL
19 #endif
20 
21 #define PKT_BUF_LEN	(ETH_HDR_LEN + ETH_MTU)
22 #define PKT_BUF_ALIGN	2
23 
24 struct pkt {
25 	struct timeval	 pkt_ts;
26 	struct event	 pkt_ev;
27 
28 	struct eth_hdr	*pkt_eth;
29 	union {
30 		u_char		*eth_data;
31 		struct ip_hdr	*ip;
32 	} pkt_n_hdr_u;
33 	union {
34 		u_char		*ip_data;
35 		struct icmp_hdr	*icmp;
36 		struct tcp_hdr	*tcp;
37 		struct udp_hdr	*udp;
38 	} pkt_t_hdr_u;
39 	union {
40 		u_char		*t_data;
41 		union icmp_msg	*icmp;
42 	} pkt_t_data_u;
43 
44 	u_char		 pkt_buf[PKT_BUF_ALIGN + PKT_BUF_LEN];
45 	u_char		*pkt_data;
46 	u_char		*pkt_end;
47 
48 	TAILQ_ENTRY(pkt) pkt_next;
49 };
50 #define pkt_ip		 pkt_n_hdr_u.ip
51 #define pkt_eth_data	 pkt_n_hdr_u.eth_data
52 
53 #define pkt_icmp	 pkt_t_hdr_u.icmp
54 #define pkt_tcp		 pkt_t_hdr_u.tcp
55 #define pkt_udp		 pkt_t_hdr_u.udp
56 #define pkt_ip_data	 pkt_t_hdr_u.ip_data
57 
58 #define pkt_tcp_data	 pkt_t_data_u.t_data
59 #define pkt_udp_data	 pkt_t_data_u.t_data
60 #define pkt_icmp_msg	 pkt_t_data_u.icmp
61 
62 TAILQ_HEAD(pktq, pkt);
63 
64 void		 pkt_init(int size);
65 
66 struct pkt	*pkt_new(void);
67 struct pkt	*pkt_dup(struct pkt *);
68 void		 pkt_decorate(struct pkt *pkt);
69 void		 pkt_free(struct pkt *pkt);
70 
71 void		 pktq_reverse(struct pktq *pktq);
72 void		 pktq_shuffle(rand_t *r, struct pktq *pktq);
73 struct pkt	*pktq_random(rand_t *r, struct pktq *pktq);
74 
75 #endif /* PKT_H */
76