ip_dummynet.h revision 55009
1217309Snwhitehorn/*
2251843Sbapt * Copyright (c) 1998 Luigi Rizzo
3217309Snwhitehorn *
4220749Snwhitehorn * Redistribution and use in source forms, with and without modification,
5217309Snwhitehorn * are permitted provided that this entire comment appears intact.
6251843Sbapt *
7217309Snwhitehorn * Redistribution in binary form may occur without any restrictions.
8217309Snwhitehorn * Obviously, it would be nice if you gave credit where credit is due
9217309Snwhitehorn * but requiring it would be too onerous.
10217309Snwhitehorn *
11217309Snwhitehorn * This software is provided ``AS IS'' without any warranties of any kind.
12217309Snwhitehorn *
13217309Snwhitehorn * $FreeBSD: head/sys/netinet/ip_dummynet.h 55009 1999-12-22 19:13:38Z shin $
14217309Snwhitehorn */
15217309Snwhitehorn
16217309Snwhitehorn#ifndef _IP_DUMMYNET_H
17217309Snwhitehorn#define _IP_DUMMYNET_H
18217309Snwhitehorn
19217309Snwhitehorn/*
20217309Snwhitehorn * Definition of dummynet data structures.
21217309Snwhitehorn * Dummynet handles a list of pipes, each one identified by a unique
22217309Snwhitehorn * number (hopefully the list is short so we use a linked list).
23217309Snwhitehorn *
24217309Snwhitehorn * Each list contains a set of parameters identifying the pipe, and
25217309Snwhitehorn * a set of packets queued on the pipe itself.
26217309Snwhitehorn *
27217309Snwhitehorn * I could have used queue macros, but the management i have
28217309Snwhitehorn * is pretty simple and this makes the code more portable.
29220749Snwhitehorn */
30217309Snwhitehorn
31217309Snwhitehorn/*
32217309Snwhitehorn * struct dn_pkt identifies a packet in the dummynet queue. The
33217309Snwhitehorn * first part is really an m_hdr for implementation purposes, and some
34217309Snwhitehorn * fields are saved there. When passing the packet back to the ip_input/
35217309Snwhitehorn * ip_output(), the struct is prepended to the mbuf chain with type
36217309Snwhitehorn * MT_DUMMYNET, and contains the pointer to the matching rule.
37217309Snwhitehorn */
38217309Snwhitehornstruct dn_pkt {
39217309Snwhitehorn	struct m_hdr hdr ;
40217309Snwhitehorn#define dn_next	hdr.mh_nextpkt	/* next element in queue */
41217309Snwhitehorn#define dn_m	hdr.mh_next	/* packet to be forwarded */
42217309Snwhitehorn#define dn_dst	hdr.mh_len	/* dst, for ip_output			*/
43217309Snwhitehorn#define dn_dir	hdr.mh_flags	/* IP_FW_F_IN or IP_FW_F_OUT		*/
44217309Snwhitehorn        int     delay;		/* stays queued until delay=0		*/
45217309Snwhitehorn        struct ifnet *ifp;	/* interface, for ip_output		*/
46217309Snwhitehorn        struct route ro;	/* route, for ip_output. MUST COPY	*/
47223289Sjh	int	flags;		/* flags, for ip_output			*/
48223289Sjh
49223289Sjh#ifdef   DUMMYNET_DEBUG
50223289Sjh        struct timeval beg, mid;        /* testing only */
51220749Snwhitehorn        int     act_delay;      /* testing only */
52217309Snwhitehorn        int     in_delay;       /* testing only */
53217309Snwhitehorn#endif
54217309Snwhitehorn};
55217309Snwhitehorn
56217309Snwhitehornstruct dn_queue {
57217309Snwhitehorn	struct dn_pkt *head, *tail;
58217309Snwhitehorn} ;
59217309Snwhitehorn
60217309Snwhitehorn/*
61217309Snwhitehorn * descriptor of a pipe. The flags field will be used to speed up the
62217309Snwhitehorn * forwarding code paths, in case some of the parameters are not
63251843Sbapt * used.
64217309Snwhitehorn */
65251843Sbaptstruct dn_pipe {			/* a pipe */
66217309Snwhitehorn	struct dn_pipe *next ;
67220749Snwhitehorn
68220749Snwhitehorn	u_short	pipe_nr ;		/* number	*/
69220749Snwhitehorn	u_short	flags ;			/* to speed up things	*/
70220749Snwhitehorn#define DN_HAVE_BW	1
71220749Snwhitehorn#define DN_HAVE_QUEUE	2
72220749Snwhitehorn#define DN_HAVE_DELAY	4
73220749Snwhitehorn	int	bandwidth;		/* really, bytes/tick.	*/
74220749Snwhitehorn	int	queue_size ;
75220749Snwhitehorn	int	queue_size_bytes ;
76220749Snwhitehorn	int	delay ;			/* really, ticks	*/
77220749Snwhitehorn	int	plr ;		/* pkt loss rate (2^31-1 means 100%) */
78220749Snwhitehorn
79220749Snwhitehorn        struct	dn_queue r;
80217309Snwhitehorn        int	r_len;			/* elements in r_queue */
81217309Snwhitehorn        int	r_len_bytes;		/* bytes in r_queue */
82217309Snwhitehorn        int	r_drops;		/* drops from r_queue */
83217309Snwhitehorn        struct	dn_queue p ;
84217309Snwhitehorn        int     ticks_from_last_insert;
85217309Snwhitehorn        long    numbytes;		/* which can send or receive */
86217309Snwhitehorn};
87217309Snwhitehorn
88217309Snwhitehorn/*
89217309Snwhitehorn * The following is used to define a new mbuf type that is
90217309Snwhitehorn * prepended to the packet when it comes out of a pipe. The definition
91217309Snwhitehorn * ought to go in /sys/sys/mbuf.h but here it is less intrusive.
92217309Snwhitehorn */
93217309Snwhitehorn
94217309Snwhitehorn#define MT_DUMMYNET MT_CONTROL
95217309Snwhitehorn/*
96217309Snwhitehorn * what to do of a packet when it comes out of a pipe
97217309Snwhitehorn */
98251843Sbapt#define DN_TO_IP_OUT	1
99251843Sbapt#define DN_TO_IP_IN	2
100251843Sbapt#define DN_TO_BDG_FWD	3
101251843Sbapt
102217309Snwhitehorn#ifdef KERNEL
103217309Snwhitehorn
104217309SnwhitehornMALLOC_DECLARE(M_IPFW);
105217309Snwhitehorn
106217309Snwhitehorntypedef int ip_dn_ctl_t __P((struct sockopt *)) ;
107217309Snwhitehornextern ip_dn_ctl_t *ip_dn_ctl_ptr;
108217309Snwhitehorn
109217309Snwhitehornvoid dn_rule_delete(void *r);		/* used in ip_fw.c */
110217309Snwhitehornint dummynet_io(int pipe, int dir,
111217309Snwhitehorn	struct mbuf *m, struct ifnet *ifp, struct route *ro,
112217309Snwhitehorn	struct sockaddr_in * dst,
113217309Snwhitehorn	struct ip_fw_chain *rule, int flags);
114217309Snwhitehorn#endif /* KERNEL */
115217309Snwhitehorn
116217309Snwhitehorn#endif /* _IP_DUMMYNET_H */
117217309Snwhitehorn