123192Smckusick /* 269644Skarels * Copyright (c) 1982, 1986, 1993, 1995 363218Sbostic * The Regents of the University of California. All rights reserved. 423192Smckusick * 544487Sbostic * %sccs.include.redist.c% 632789Sbostic * 7*69974Skarels * @(#)tcp_seq.h 8.3 (Berkeley) 06/21/95 823192Smckusick */ 95124Swnj 105124Swnj /* 115124Swnj * TCP sequence numbers are 32 bit integers operated 125124Swnj * on with modular arithmetic. These macros can be 135124Swnj * used to compare such integers. 145124Swnj */ 155124Swnj #define SEQ_LT(a,b) ((int)((a)-(b)) < 0) 165124Swnj #define SEQ_LEQ(a,b) ((int)((a)-(b)) <= 0) 175124Swnj #define SEQ_GT(a,b) ((int)((a)-(b)) > 0) 185124Swnj #define SEQ_GEQ(a,b) ((int)((a)-(b)) >= 0) 195124Swnj 205124Swnj /* 215124Swnj * Macros to initialize tcp sequence numbers for 225124Swnj * send and receive from initial send and receive 235124Swnj * sequence numbers. 245124Swnj */ 255124Swnj #define tcp_rcvseqinit(tp) \ 2625203Skarels (tp)->rcv_adv = (tp)->rcv_nxt = (tp)->irs + 1 275124Swnj 285124Swnj #define tcp_sendseqinit(tp) \ 295124Swnj (tp)->snd_una = (tp)->snd_nxt = (tp)->snd_max = (tp)->snd_up = \ 305124Swnj (tp)->iss 315124Swnj 3269644Skarels #ifdef KERNEL 3369644Skarels /* 3469644Skarels * Increment for tcp_iss each second. 3569644Skarels * This is designed to increment at the standard 250 KB/s, 3669644Skarels * but with a random component averaging 128 KB. 3769644Skarels * We also increment tcp_iss by a quarter of this amount 3869644Skarels * each time we use the value for a new connection. 3969644Skarels * If defined, the tcp_random18() macro should produce a 4069644Skarels * number in the range [0-0x3ffff] that is hard to predict. 4169644Skarels */ 42*69974Skarels #ifndef tcp_random18 4369644Skarels #define tcp_random18() ((random() >> 14) & 0x3ffff) 4469644Skarels #endif 4569644Skarels #define TCP_ISSINCR (122*1024 + tcp_random18()) 465124Swnj 475124Swnj tcp_seq tcp_iss; /* tcp initial send seq # */ 4869644Skarels #else 4969644Skarels #define TCP_ISSINCR (250*1024) /* increment for tcp_iss each second */ 505124Swnj #endif 51