/* * Copyright (c) 1982, 1986, 1993, 1995 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ /* * * Declarations and data structures used by the Berkeley snoop protocol. */ #ifndef SNOOP_H #define SNOOP_H #include #include #include #include #include #define LASTBYTEMASK 0xff #define SNOOP_MAXWIND 40 #define SNOOP_MAXMOBILE 32 #define SNOOP_MAXCONN 64 #define SNOOP_HIGH_THRESH (9*SNOOP_MAXWIND/10) #define SNOOP_MAXPERSIST 4 /* persist timeouts */ #define SNOOP_RTTDEFAULT 100000 #define SNOOP_TIMERGRAN 200 /* Snoop timer granularity */ #define SNOOP_MIN_TIMO 200000 #define SNOOP_MAX_RXMIT 8 #define SNOOP_PERSIST_TIMO 500000 #define SNOOP_GARBAGE_TIMO 20000000 /* Snoop states */ #define SNOOP_ACTIVE 0x01 /* connection active */ #define SNOOP_CLOSED 0x02 /* connection closed */ #define SNOOP_NOACK 0x04 /* no ack seen yet */ #define SNOOP_FULL 0x08 /* snoop cache full */ #define SNOOP_HIGHWATER 0x10 /* snoop highwater mark reached */ #define SNOOP_RTTFLAG 0x20 /* can compute RTT if this is set */ #define SNOOP_ALIVE 0x40 /* connection has been alive past 1 sec */ #define SNOOP_SL_REXMT 0x80 /* for persist timeout */ /* forwarding and buffering states in the multicast-based mobility algorithm */ #define SNOOP_FWD 0 /* forward packet */ #define SNOOP_BUF 1 /* buffer, don't forward */ #define FROM_FH 0 /* segment from fixed host */ #define FROM_MH 1 /* from mobile */ struct iphdr { short len; /* ip header length */ u_short id; /* ip id */ short off; /* ip header offset */ u_char ttl; /* ttl of datagram */ char padding; /* to make it word aligned */ }; typedef struct timeval timev; #define TIMEV typedef struct packet { struct mbuf *mb; /* mbuf chain of data */ struct iphdr iph; /* some fields of IP header */ int tcp_sum; /* tcp chksum */ tcp_seq seq; /* sequence number of first byte */ int size; /* amount of actual TCP data */ timev snd_time; /* local xmit time */ int num_rxmit; /* number of local rexmits */ int sender_rxmit; /* sender rexmitted this pkt? */ } packet_t; typedef struct conn_state { int conn_id; /* which connection -- unique from dst:port */ u_short fstate; /* state of connection */ u_short dest_port; /* destination port */ u_short last_win; /* last flow control window size from sender */ struct in_addr dest_addr; /* identifies mobile host */ struct mbuf *ack_mb; tcp_seq last_seen; /* first byte of last packet buffered */ int last_size; /* size of last cached segment */ tcp_seq last_ack; /* last byte recd. by mh for sure */ tcp_seq initseq; /* initial seq no for this connection */ tcp_seq expected_next_ack; /* expected next ack after dup sequence */ short expected_dacks; /* expected number of dup acks */ long srtt; /* smoothed rtt estimate */ long rttvar; /* linear deviation */ short bufhead; /* next pkt goes here */ short buftail; /* first unack'd pkt */ #ifdef SMART_SNOOP tcp_seq smart_start; /* start of out-of-order recd. block */ tcp_seq smart_end; /* end of block at receiver */ #endif /* SMART_SNOOP */ packet_t *pkts[SNOOP_MAXWIND]; /* ringbuf of cached mbufs */ short timeout_pending; /* # pending timeouts */ } conn_state_t; typedef struct snoop_state { short num_mobiles; /* number of active mobile hosts */ short num_connections; /* number of active connections */ struct in_addr nosnoop; /* no snoop on this addr (for demos, tests) */ int disable; /* to disable snoop for experiments */ conn_state_t *cstate[SNOOP_MAXCONN]; /* array of per-connection state*/ } snoop_state_t; #define CEIL(a,b) (((a)+(b)+1)/(b)) /* ceiling of a/b */ #define NEXT(j) ((j)+1) % SNOOP_MAXWIND /* next element in ring */ #define PREV(j) ((j) == 0) ? SNOOP_MAXWIND - 1 : (j) - 1 /* previous element */ #ifndef TIMERDIFF #define TIMERDIFF #define timerdiff(nowp, thenp) \ (((nowp)->tv_sec - (thenp)->tv_sec) * 1000000 + \ (nowp)->tv_usec - (thenp)->tv_usec) #endif #define SNOOP_TIMO(cs) \ ((cs)->srtt > SNOOP_MIN_TIMO) ? (cs)->srtt : SNOOP_MIN_TIMO /*#define SNOOP_TIMO(cs) SNOOP_MIN_TIMO*/ /* Function prototypes */ void snoop_ctrl __P((struct mbuf *, short, short, int)); void snoop_init __P((void)); int snoop_conninit __P((struct mbuf *, struct in_addr, u_short, ushort)); void snoop_data __P((struct mbuf *, int, short, int, int)); void snoop_insert __P((conn_state_t *, struct mbuf *, tcp_seq, short)); void snoop_ack __P((struct mbuf *, int, int)); void snoop_cleanbufs __P((conn_state_t *, tcp_seq, timev *)); void snoop_done __P((int)); int snoop_getmobconn __P((struct in_addr, u_short port)); void snoop_timeout __P((void)); void *snoop_malloc __P((int)); void snoop_rexmt_pkt __P((conn_state_t *, packet_t *, u_char)); void snoop_rexmt_timeout __P((void *)); void snoop_persist_timeout __P((void *)); void snoop_garbage_timeout __P((void *)); void snoop_freebuf __P((packet_t *pkt)); long time_diff __P((timev *, timev *)); #ifndef NOMIP int snoop_mip_change __P((struct in_addr, MIP_STATES, MIP_STATES)); #endif #endif