xref: /freebsd/sys/netinet/ip_dummynet.h (revision 2ad872c5794e4c26fdf6ed219ad3f09ca0d5304a)
1 /*
2  * Copyright (c) 1998 Luigi Rizzo
3  *
4  * Redistribution and use in source forms, with and without modification,
5  * are permitted provided that this entire comment appears intact.
6  *
7  * Redistribution in binary form may occur without any restrictions.
8  * Obviously, it would be nice if you gave credit where credit is due
9  * but requiring it would be too onerous.
10  *
11  * This software is provided ``AS IS'' without any warranties of any kind.
12  *
13  *	$Id: ip_dummynet.h,v 1.1 1998/05/10 01:30:23 luigi Exp $
14  */
15 
16 #ifndef _IP_DUMMYNET_H
17 #define _IP_DUMMYNET_H
18 
19 typedef int ip_dn_ctl_t __P((struct sockopt *)) ;
20 extern ip_dn_ctl_t *ip_dn_ctl_ptr;
21 /*
22  * Definition of dummynet data structures.
23  * Dummynet handles a list of pipes, each one identified by a unique
24  * number (hopefully the list is short so we use a linked list).
25  *
26  * Each list contains a set of parameters identifying the pipe, and
27  * a set of packets queued on the pipe itself.
28  *
29  * I could have used queue macros, but the management i have
30  * is pretty simple and this makes the code more portable.
31  */
32 
33 /*
34  * struct dn_pkt identifies a packet in the dummynet queue. The
35  * first part is really an m_hdr for implementation purposes, and some
36  * fields are saved there. When passing the packet back to the ip_input/
37  * ip_output(), the struct is prepended to the mbuf chain with type
38  * MT_DUMMYNET, and contains the pointer to the matching rule.
39  */
40 struct dn_pkt {
41 	struct m_hdr hdr ;
42 #define dn_next	hdr.mh_nextpkt	/* next element in queue */
43 #define dn_m	hdr.mh_next	/* packet to be forwarded */
44 #define dn_hlen	hdr.mh_len	/* hlen, for ip_output			*/
45 #define dn_dir	hdr.mh_flags	/* IP_FW_F_IN or IP_FW_F_OUT		*/
46         int     delay;		/* stays queued until delay=0		*/
47         struct ifnet *ifp;	/* interface, for ip_output		*/
48         struct route ro;	/* route, for ip_output. MUST COPY	*/
49 
50 #ifdef   DUMMYNET_DEBUG
51         struct timeval beg, mid;        /* testing only */
52         int     act_delay;      /* testing only */
53         int     in_delay;       /* testing only */
54 #endif
55 };
56 
57 struct dn_queue {
58 	struct dn_pkt *head, *tail;
59 } ;
60 
61 /*
62  * descriptor of a pipe. The flags field will be used to speed up the
63  * forwarding code paths, in case some of the parameters are not
64  * used.
65  */
66 struct dn_pipe {			/* a pipe */
67 	struct dn_pipe *next ;
68 
69 	u_short	pipe_nr ;		/* number	*/
70 	u_short	flags ;			/* to speed up things	*/
71 #define DN_HAVE_BW	1
72 #define DN_HAVE_QUEUE	2
73 #define DN_HAVE_DELAY	4
74 	int	bandwidth;		/* really, bytes/tick.	*/
75 	int	queue_size ;
76 	int	queue_size_bytes ;
77 	int	delay ;			/* really, ticks	*/
78 	int	plr ;		/* pkt loss rate (2^31-1 means 100%) */
79 
80         struct	dn_queue r;
81         int	r_len;			/* elements in r_queue */
82         int	r_len_bytes;		/* bytes in r_queue */
83         int	r_drops;		/* drops from r_queue */
84         struct	dn_queue p ;
85         int     ticks_from_last_insert;
86         long    numbytes;		/* which can send or receive */
87 };
88 
89 /*
90  * The following is used to define a new mbuf type that is
91  * prepended to the packet when it comes out of a pipe. The definition
92  * ought to go in /sys/sys/mbuf.h but here it is less intrusive.
93  */
94 
95 #define MT_DUMMYNET MT_CONTROL
96 /*
97  * what to do of a packet when it comes out of a pipe
98  */
99 #define DN_TO_IP_OUT	1
100 #define DN_TO_IP_IN	2
101 #define DN_TO_BDG_FWD	3
102 #ifdef KERNEL
103 MALLOC_DECLARE(M_IPFW);
104 void ip_dn_init(void);	/* called in ip_input.c */
105 void dn_rule_delete(void *r);		/* used in ip_fw.c */
106 int dummynet_io(int pipe, int dir,
107 	struct mbuf *m, struct ifnet *ifp, struct route *ro, int hlen,
108 	struct ip_fw_chain *rule);
109 #endif
110 #endif /* _IP_DUMMYNET_H */
111