ip_dummynet.h revision 39119
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/* 20 * Definition of dummynet data structures. 21 * Dummynet handles a list of pipes, each one identified by a unique 22 * number (hopefully the list is short so we use a linked list). 23 * 24 * Each list contains a set of parameters identifying the pipe, and 25 * a set of packets queued on the pipe itself. 26 * 27 * I could have used queue macros, but the management i have 28 * is pretty simple and this makes the code more portable. 29 */ 30 31/* 32 * struct dn_pkt identifies a packet in the dummynet queue. The 33 * first part is really an m_hdr for implementation purposes, and some 34 * fields are saved there. When passing the packet back to the ip_input/ 35 * ip_output(), the struct is prepended to the mbuf chain with type 36 * MT_DUMMYNET, and contains the pointer to the matching rule. 37 */ 38struct dn_pkt { 39 struct m_hdr hdr ; 40#define dn_next hdr.mh_nextpkt /* next element in queue */ 41#define dn_m hdr.mh_next /* packet to be forwarded */ 42#define dn_hlen hdr.mh_len /* hlen, for ip_output */ 43#define dn_dir hdr.mh_flags /* IP_FW_F_IN or IP_FW_F_OUT */ 44 int delay; /* stays queued until delay=0 */ 45 struct ifnet *ifp; /* interface, for ip_output */ 46 struct route ro; /* route, for ip_output. MUST COPY */ 47 48#ifdef DUMMYNET_DEBUG 49 struct timeval beg, mid; /* testing only */ 50 int act_delay; /* testing only */ 51 int in_delay; /* testing only */ 52#endif 53}; 54 55struct dn_queue { 56 struct dn_pkt *head, *tail; 57} ; 58 59/* 60 * descriptor of a pipe. The flags field will be used to speed up the 61 * forwarding code paths, in case some of the parameters are not 62 * used. 63 */ 64struct dn_pipe { /* a pipe */ 65 struct dn_pipe *next ; 66 67 u_short pipe_nr ; /* number */ 68 u_short flags ; /* to speed up things */ 69#define DN_HAVE_BW 1 70#define DN_HAVE_QUEUE 2 71#define DN_HAVE_DELAY 4 72 int bandwidth; /* really, bytes/tick. */ 73 int queue_size ; 74 int queue_size_bytes ; 75 int delay ; /* really, ticks */ 76 int plr ; /* pkt loss rate (2^31-1 means 100%) */ 77 78 struct dn_queue r; 79 int r_len; /* elements in r_queue */ 80 int r_len_bytes; /* bytes in r_queue */ 81 int r_drops; /* drops from r_queue */ 82 struct dn_queue p ; 83 int ticks_from_last_insert; 84 long numbytes; /* which can send or receive */ 85}; 86 87/* 88 * what to do of a packet when it comes out of a pipe 89 */ 90#define DN_TO_IP_OUT 1 91#define DN_TO_IP_IN 2 92#define DN_TO_BDG_FWD 3 93#ifdef KERNEL 94void ip_dn_init(void); /* called in ip_input.c */ 95void dn_rule_delete(void *r); /* used in ip_fw.c */ 96int dummynet_io(int pipe, int dir, 97 struct mbuf *m, struct ifnet *ifp, struct route *ro, int hlen, 98 struct ip_fw_chain *rule); 99#endif 100#endif /* _IP_DUMMYNET_H */ 101