make tp_ref structures allocated at protocol initialization time
[unix-history] / usr / src / sys / netiso / tp_pcb.h
index a6f5a54..e129759 100644 (file)
@@ -29,7 +29,7 @@ SOFTWARE.
  *
  * $Header: tp_pcb.h,v 5.2 88/11/18 17:09:32 nhall Exp $
  * $Source: /usr/argo/sys/netiso/RCS/tp_pcb.h,v $
  *
  * $Header: tp_pcb.h,v 5.2 88/11/18 17:09:32 nhall Exp $
  * $Source: /usr/argo/sys/netiso/RCS/tp_pcb.h,v $
- *     @(#)tp_pcb.h    7.4 (Berkeley) %G% *
+ *     @(#)tp_pcb.h    7.8 (Berkeley) %G% *
  *
  * 
  * This file defines the transport protocol control block (tpcb).
  *
  * 
  * This file defines the transport protocol control block (tpcb).
@@ -102,11 +102,11 @@ struct tp_rtc {
        struct mbuf             *tprt_data; /* ptr to the octets of data */
 };
 
        struct mbuf             *tprt_data; /* ptr to the octets of data */
 };
 
-extern
 struct nl_protosw {
        int             nlp_afamily;                    /* address family */
        int             (*nlp_putnetaddr)();    /* puts addresses in nl pcb */
        int             (*nlp_getnetaddr)();    /* gets addresses from nl pcb */
 struct nl_protosw {
        int             nlp_afamily;                    /* address family */
        int             (*nlp_putnetaddr)();    /* puts addresses in nl pcb */
        int             (*nlp_getnetaddr)();    /* gets addresses from nl pcb */
+       int             (*nlp_cmpnetaddr)();    /* compares address in pcb with sockaddr */
        int             (*nlp_putsufx)();               /* puts transport suffixes in nl pcb */
        int             (*nlp_getsufx)();               /* gets transport suffixes from nl pcb */
        int             (*nlp_recycle_suffix)();/* clears suffix from nl pcb */
        int             (*nlp_putsufx)();               /* puts transport suffixes in nl pcb */
        int             (*nlp_getsufx)();               /* gets transport suffixes from nl pcb */
        int             (*nlp_recycle_suffix)();/* clears suffix from nl pcb */
@@ -120,10 +120,13 @@ struct nl_protosw {
        int             (*nlp_dgoutput)();              /* prepare a packet to give to nl */
        int             (*nlp_ctloutput)();             /* hook for network set/get options */
        caddr_t nlp_pcblist;                    /* list of xx_pcb's for connections */
        int             (*nlp_dgoutput)();              /* prepare a packet to give to nl */
        int             (*nlp_ctloutput)();             /* hook for network set/get options */
        caddr_t nlp_pcblist;                    /* list of xx_pcb's for connections */
-} nl_protosw[];
+};
 
 
 struct tp_pcb {
 
 
 struct tp_pcb {
+       struct tp_pcb           *tp_next;
+       struct tp_pcb           *tp_prev;
+       struct tp_pcb           *tp_nextlisten; /* chain all listeners */
        u_short                         tp_state;               /* state of fsm */
        short                           tp_retrans;             /* # times can still retrans */
        struct tp_ref           *tp_refp;               /* rest of pcb  */
        u_short                         tp_state;               /* state of fsm */
        short                           tp_retrans;             /* # times can still retrans */
        struct tp_ref           *tp_refp;               /* rest of pcb  */
@@ -151,9 +154,13 @@ struct tp_pcb {
                                                                                 * Minimizes the amount sent in a
                                                                                 * regular tp_send() also.
                                                                                 */
                                                                                 * Minimizes the amount sent in a
                                                                                 * regular tp_send() also.
                                                                                 */
+       u_int   tp_ackrcvd; /* ACKs received since the send window was updated */
+       SeqNum              tp_last_retrans;
+       SeqNum              tp_retrans_hiwat;
        SeqNum                          tp_snduna;              /* seq # of lowest unacked DT */
        struct tp_rtc           *tp_snduna_rtc; /* lowest unacked stuff sent so far */
        SeqNum                          tp_sndhiwat;    /* highest seq # sent so far */
        SeqNum                          tp_snduna;              /* seq # of lowest unacked DT */
        struct tp_rtc           *tp_snduna_rtc; /* lowest unacked stuff sent so far */
        SeqNum                          tp_sndhiwat;    /* highest seq # sent so far */
+
        struct tp_rtc           *tp_sndhiwat_rtc;       /* last stuff sent so far */
        int                                     tp_Nwindow;             /* for perf. measurement */
        struct mbuf                     *tp_ucddata;    /* user connect/disconnect data */
        struct tp_rtc           *tp_sndhiwat_rtc;       /* last stuff sent so far */
        int                                     tp_Nwindow;             /* for perf. measurement */
        struct mbuf                     *tp_ucddata;    /* user connect/disconnect data */
@@ -168,6 +175,18 @@ struct tp_pcb {
        SeqNum                          tp_rcvnxt;              /* next DT seq # expect to recv */
        struct tp_rtc           *tp_rcvnxt_rtc; /* unacked stuff recvd out of order */
 
        SeqNum                          tp_rcvnxt;              /* next DT seq # expect to recv */
        struct tp_rtc           *tp_rcvnxt_rtc; /* unacked stuff recvd out of order */
 
+       /* receiver congestion state stuff ...  */
+       u_int               tp_win_recv;
+
+       /* receive window as a scaled int (8 bit fraction part) */
+
+       struct cong_sample {
+               ushort  cs_size;                                /* current window size */
+               ushort  cs_received;                    /* PDUs received in this sample */
+               ushort  cs_ce_set;    /* PDUs received in this sample with CE bit set */
+       } tp_cong_sample;
+
+
        /* parameters per-connection controllable by user */
        struct tp_conn_param _tp_param; 
 
        /* parameters per-connection controllable by user */
        struct tp_conn_param _tp_param; 
 
@@ -195,6 +214,7 @@ struct tp_pcb {
 #define        tp_no_disc_indications _tp_param.p_no_disc_indications
 #define        tp_dont_change_params _tp_param.p_dont_change_params
 #define        tp_netservice _tp_param.p_netservice
 #define        tp_no_disc_indications _tp_param.p_no_disc_indications
 #define        tp_dont_change_params _tp_param.p_dont_change_params
 #define        tp_netservice _tp_param.p_netservice
+#define        tp_version _tp_param.p_version
 
        int tp_l_tpdusize;
                /* whereas tp_tpdusize is log2(the negotiated max size)
 
        int tp_l_tpdusize;
                /* whereas tp_tpdusize is log2(the negotiated max size)
@@ -210,7 +230,8 @@ struct tp_pcb {
                tp_trace:1,                             /* is this pcb being traced? (not used yet) */
                tp_perf_on:1,                   /* 0/1 -> performance measuring on  */
                tp_reneged:1,                   /* have we reneged on cdt since last ack? */
                tp_trace:1,                             /* is this pcb being traced? (not used yet) */
                tp_perf_on:1,                   /* 0/1 -> performance measuring on  */
                tp_reneged:1,                   /* have we reneged on cdt since last ack? */
-               tp_decbit:4,                    /* dec bit was set, we're in reneg mode  */
+               tp_decbit:3,                    /* dec bit was set, we're in reneg mode  */
+               tp_cebit_off:1,                 /* the real DEC bit algorithms not in use */
                tp_flags:8,                             /* values: */
 #define TPF_CONN_DATA_OUT      TPFLAG_CONN_DATA_OUT
 #define TPF_CONN_DATA_IN       TPFLAG_CONN_DATA_IN
                tp_flags:8,                             /* values: */
 #define TPF_CONN_DATA_OUT      TPFLAG_CONN_DATA_OUT
 #define TPF_CONN_DATA_IN       TPFLAG_CONN_DATA_IN
@@ -262,9 +283,54 @@ struct tp_pcb {
 
 };
 
 
 };
 
+u_int  tp_start_win;
+
+#define ROUND(scaled_int) (((scaled_int) >> 8) + (((scaled_int) & 0x80) ? 1:0))
+
+/* to round off a scaled int with an 8 bit fraction part */
+
+#define CONG_INIT_SAMPLE(pcb) \
+       pcb->tp_cong_sample.cs_received = \
+    pcb->tp_cong_sample.cs_ce_set = 0; \
+    pcb->tp_cong_sample.cs_size = MAX(pcb->tp_lcredit, 1) << 1;
+
+#define CONG_UPDATE_SAMPLE(pcb, ce_bit) \
+    pcb->tp_cong_sample.cs_received++; \
+    if (ce_bit) { \
+        pcb->tp_cong_sample.cs_ce_set++; \
+    } \
+    if (pcb->tp_cong_sample.cs_size <= pcb->tp_cong_sample.cs_received) { \
+        if ((pcb->tp_cong_sample.cs_ce_set << 1) >=  \
+                    pcb->tp_cong_sample.cs_size ) { \
+            pcb->tp_win_recv -= pcb->tp_win_recv >> 3; /* multiply by .875 */ \
+            pcb->tp_win_recv = MAX(1 << 8, pcb->tp_win_recv); \
+        } \
+        else { \
+            pcb->tp_win_recv += (1 << 8); /* add one to the scaled int */ \
+        } \
+        pcb->tp_lcredit = ROUND(pcb->tp_win_recv); \
+        CONG_INIT_SAMPLE(pcb); \
+    }
+
+#define CONG_ACK(pcb, seq) \
+{ int   newacks = SEQ_SUB(pcb, seq, pcb->tp_snduna); \
+       if (newacks > 0) { \
+               pcb->tp_ackrcvd += newacks; \
+               if (pcb->tp_ackrcvd >= MIN(pcb->tp_fcredit, pcb->tp_cong_win)) { \
+                       ++pcb->tp_cong_win; \
+                       pcb->tp_ackrcvd = 0; \
+               } \
+       } \
+}
+
+#ifdef KERNEL
 extern struct timeval  time;
 extern struct timeval  time;
-extern struct tp_ref   tp_ref[];
+extern struct tp_ref   *tp_ref;
 extern struct tp_param tp_param;
 extern struct tp_param tp_param;
+extern struct nl_protosw  nl_protosw[];
+extern struct tp_pcb   *tp_listeners;
+extern struct tp_pcb   *tp_intercepts;
+#endif
 
 #define        sototpcb(so)    ((struct tp_pcb *)(so->so_tpcb))
 #define        sototpref(so)   ((struct tp_ref *)((so)->so_tpcb->tp_ref))
 
 #define        sototpcb(so)    ((struct tp_pcb *)(so->so_tpcb))
 #define        sototpref(so)   ((struct tp_ref *)((so)->so_tpcb->tp_ref))