Commit | Line | Data |
---|---|---|
15637ed4 RG |
1 | /* |
2 | * Copyright (c) 1984, 1985, 1986, 1987 Regents of the University of California. | |
3 | * All rights reserved. | |
4 | * | |
5 | * Redistribution and use in source and binary forms, with or without | |
6 | * modification, are permitted provided that the following conditions | |
7 | * are met: | |
8 | * 1. Redistributions of source code must retain the above copyright | |
9 | * notice, this list of conditions and the following disclaimer. | |
10 | * 2. Redistributions in binary form must reproduce the above copyright | |
11 | * notice, this list of conditions and the following disclaimer in the | |
12 | * documentation and/or other materials provided with the distribution. | |
13 | * 3. All advertising materials mentioning features or use of this software | |
14 | * must display the following acknowledgement: | |
15 | * This product includes software developed by the University of | |
16 | * California, Berkeley and its contributors. | |
17 | * 4. Neither the name of the University nor the names of its contributors | |
18 | * may be used to endorse or promote products derived from this software | |
19 | * without specific prior written permission. | |
20 | * | |
21 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
27 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
28 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
30 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
31 | * SUCH DAMAGE. | |
32 | * | |
136b31f1 | 33 | * from: @(#)spp_usrreq.c 7.15 (Berkeley) 6/27/91 |
fde1aeb2 | 34 | * $Id: spp_usrreq.c,v 1.4 1993/11/25 01:36:36 wollman Exp $ |
15637ed4 RG |
35 | */ |
36 | ||
37 | #include "param.h" | |
38 | #include "systm.h" | |
39 | #include "malloc.h" | |
40 | #include "mbuf.h" | |
41 | #include "protosw.h" | |
42 | #include "socket.h" | |
43 | #include "socketvar.h" | |
44 | #include "errno.h" | |
45 | ||
46 | #include "../net/if.h" | |
47 | #include "../net/route.h" | |
48 | #include "../netinet/tcp_fsm.h" | |
49 | ||
50 | #include "ns.h" | |
51 | #include "ns_pcb.h" | |
52 | #include "idp.h" | |
53 | #include "idp_var.h" | |
54 | #include "ns_error.h" | |
55 | #include "sp.h" | |
56 | #include "spidp.h" | |
57 | #include "spp_timer.h" | |
58 | #include "spp_var.h" | |
59 | #include "spp_debug.h" | |
60 | ||
fde1aeb2 GW |
61 | static void spp_quench(struct nspcb *, int); |
62 | static void spp_abort(struct nspcb *, int); | |
4c45483e GW |
63 | static void spp_setpersist(struct sppcb *); |
64 | static void spp_template(struct sppcb *); | |
65 | ||
8ace4366 GW |
66 | struct spp_istat spp_istat; |
67 | u_short spp_iss; | |
68 | ||
15637ed4 RG |
69 | /* |
70 | * SP protocol implementation. | |
71 | */ | |
4c45483e | 72 | void |
15637ed4 RG |
73 | spp_init() |
74 | { | |
75 | ||
76 | spp_iss = 1; /* WRONG !! should fish it out of TODR */ | |
77 | } | |
78 | struct spidp spp_savesi; | |
79 | int traceallspps = 0; | |
80 | extern int sppconsdebug; | |
81 | int spp_hardnosed; | |
82 | int spp_use_delack = 0; | |
83 | u_short spp_newchecks[50]; | |
84 | ||
85 | /*ARGSUSED*/ | |
4c45483e | 86 | void |
15637ed4 RG |
87 | spp_input(m, nsp) |
88 | register struct mbuf *m; | |
89 | register struct nspcb *nsp; | |
90 | { | |
91 | register struct sppcb *cb; | |
92 | register struct spidp *si = mtod(m, struct spidp *); | |
93 | register struct socket *so; | |
4c45483e | 94 | short ostate = 0; |
15637ed4 RG |
95 | int dropsocket = 0; |
96 | ||
97 | ||
98 | sppstat.spps_rcvtotal++; | |
99 | if (nsp == 0) { | |
100 | panic("No nspcb in spp_input\n"); | |
101 | return; | |
102 | } | |
103 | ||
104 | cb = nstosppcb(nsp); | |
105 | if (cb == 0) goto bad; | |
106 | ||
107 | if (m->m_len < sizeof(*si)) { | |
108 | if ((m = m_pullup(m, sizeof(*si))) == 0) { | |
109 | sppstat.spps_rcvshort++; | |
110 | return; | |
111 | } | |
112 | si = mtod(m, struct spidp *); | |
113 | } | |
114 | si->si_seq = ntohs(si->si_seq); | |
115 | si->si_ack = ntohs(si->si_ack); | |
116 | si->si_alo = ntohs(si->si_alo); | |
117 | ||
118 | so = nsp->nsp_socket; | |
119 | if (so->so_options & SO_DEBUG || traceallspps) { | |
120 | ostate = cb->s_state; | |
121 | spp_savesi = *si; | |
122 | } | |
123 | if (so->so_options & SO_ACCEPTCONN) { | |
124 | struct sppcb *ocb = cb; | |
125 | ||
126 | so = sonewconn(so, 0); | |
127 | if (so == 0) { | |
128 | goto drop; | |
129 | } | |
130 | /* | |
131 | * This is ugly, but .... | |
132 | * | |
133 | * Mark socket as temporary until we're | |
134 | * committed to keeping it. The code at | |
135 | * ``drop'' and ``dropwithreset'' check the | |
136 | * flag dropsocket to see if the temporary | |
137 | * socket created here should be discarded. | |
138 | * We mark the socket as discardable until | |
139 | * we're committed to it below in TCPS_LISTEN. | |
140 | */ | |
141 | dropsocket++; | |
142 | nsp = (struct nspcb *)so->so_pcb; | |
143 | nsp->nsp_laddr = si->si_dna; | |
144 | cb = nstosppcb(nsp); | |
145 | cb->s_mtu = ocb->s_mtu; /* preserve sockopts */ | |
146 | cb->s_flags = ocb->s_flags; /* preserve sockopts */ | |
147 | cb->s_flags2 = ocb->s_flags2; /* preserve sockopts */ | |
148 | cb->s_state = TCPS_LISTEN; | |
149 | } | |
150 | ||
151 | /* | |
152 | * Packet received on connection. | |
153 | * reset idle time and keep-alive timer; | |
154 | */ | |
155 | cb->s_idle = 0; | |
156 | cb->s_timer[SPPT_KEEP] = SPPTV_KEEP; | |
157 | ||
158 | switch (cb->s_state) { | |
159 | ||
160 | case TCPS_LISTEN:{ | |
161 | struct mbuf *am; | |
162 | register struct sockaddr_ns *sns; | |
163 | struct ns_addr laddr; | |
164 | ||
165 | /* | |
166 | * If somebody here was carying on a conversation | |
167 | * and went away, and his pen pal thinks he can | |
168 | * still talk, we get the misdirected packet. | |
169 | */ | |
170 | if (spp_hardnosed && (si->si_did != 0 || si->si_seq != 0)) { | |
171 | spp_istat.gonawy++; | |
172 | goto dropwithreset; | |
173 | } | |
174 | am = m_get(M_DONTWAIT, MT_SONAME); | |
175 | if (am == NULL) | |
176 | goto drop; | |
177 | am->m_len = sizeof (struct sockaddr_ns); | |
178 | sns = mtod(am, struct sockaddr_ns *); | |
179 | sns->sns_len = sizeof(*sns); | |
180 | sns->sns_family = AF_NS; | |
181 | sns->sns_addr = si->si_sna; | |
182 | laddr = nsp->nsp_laddr; | |
183 | if (ns_nullhost(laddr)) | |
184 | nsp->nsp_laddr = si->si_dna; | |
185 | if (ns_pcbconnect(nsp, am)) { | |
186 | nsp->nsp_laddr = laddr; | |
187 | (void) m_free(am); | |
188 | spp_istat.noconn++; | |
189 | goto drop; | |
190 | } | |
191 | (void) m_free(am); | |
192 | spp_template(cb); | |
193 | dropsocket = 0; /* committed to socket */ | |
194 | cb->s_did = si->si_sid; | |
195 | cb->s_rack = si->si_ack; | |
196 | cb->s_ralo = si->si_alo; | |
197 | #define THREEWAYSHAKE | |
198 | #ifdef THREEWAYSHAKE | |
199 | cb->s_state = TCPS_SYN_RECEIVED; | |
200 | cb->s_force = 1 + SPPT_KEEP; | |
201 | sppstat.spps_accepts++; | |
202 | cb->s_timer[SPPT_KEEP] = SPPTV_KEEP; | |
203 | } | |
204 | break; | |
205 | /* | |
206 | * This state means that we have heard a response | |
207 | * to our acceptance of their connection | |
208 | * It is probably logically unnecessary in this | |
209 | * implementation. | |
210 | */ | |
211 | case TCPS_SYN_RECEIVED: { | |
212 | if (si->si_did!=cb->s_sid) { | |
213 | spp_istat.wrncon++; | |
214 | goto drop; | |
215 | } | |
216 | #endif | |
217 | nsp->nsp_fport = si->si_sport; | |
218 | cb->s_timer[SPPT_REXMT] = 0; | |
219 | cb->s_timer[SPPT_KEEP] = SPPTV_KEEP; | |
220 | soisconnected(so); | |
221 | cb->s_state = TCPS_ESTABLISHED; | |
222 | sppstat.spps_accepts++; | |
223 | } | |
224 | break; | |
225 | ||
226 | /* | |
227 | * This state means that we have gotten a response | |
228 | * to our attempt to establish a connection. | |
229 | * We fill in the data from the other side, | |
230 | * telling us which port to respond to, instead of the well- | |
231 | * known one we might have sent to in the first place. | |
232 | * We also require that this is a response to our | |
233 | * connection id. | |
234 | */ | |
235 | case TCPS_SYN_SENT: | |
236 | if (si->si_did!=cb->s_sid) { | |
237 | spp_istat.notme++; | |
238 | goto drop; | |
239 | } | |
240 | sppstat.spps_connects++; | |
241 | cb->s_did = si->si_sid; | |
242 | cb->s_rack = si->si_ack; | |
243 | cb->s_ralo = si->si_alo; | |
244 | cb->s_dport = nsp->nsp_fport = si->si_sport; | |
245 | cb->s_timer[SPPT_REXMT] = 0; | |
246 | cb->s_flags |= SF_ACKNOW; | |
247 | soisconnected(so); | |
248 | cb->s_state = TCPS_ESTABLISHED; | |
249 | /* Use roundtrip time of connection request for initial rtt */ | |
250 | if (cb->s_rtt) { | |
251 | cb->s_srtt = cb->s_rtt << 3; | |
252 | cb->s_rttvar = cb->s_rtt << 1; | |
253 | SPPT_RANGESET(cb->s_rxtcur, | |
254 | ((cb->s_srtt >> 2) + cb->s_rttvar) >> 1, | |
255 | SPPTV_MIN, SPPTV_REXMTMAX); | |
256 | cb->s_rtt = 0; | |
257 | } | |
258 | } | |
259 | if (so->so_options & SO_DEBUG || traceallspps) | |
260 | spp_trace(SA_INPUT, (u_char)ostate, cb, &spp_savesi, 0); | |
261 | ||
262 | m->m_len -= sizeof (struct idp); | |
263 | m->m_pkthdr.len -= sizeof (struct idp); | |
264 | m->m_data += sizeof (struct idp); | |
265 | ||
266 | if (spp_reass(cb, si)) { | |
267 | (void) m_freem(m); | |
268 | } | |
269 | if (cb->s_force || (cb->s_flags & (SF_ACKNOW|SF_WIN|SF_RXT))) | |
270 | (void) spp_output(cb, (struct mbuf *)0); | |
271 | cb->s_flags &= ~(SF_WIN|SF_RXT); | |
272 | return; | |
273 | ||
274 | dropwithreset: | |
275 | if (dropsocket) | |
276 | (void) soabort(so); | |
277 | si->si_seq = ntohs(si->si_seq); | |
278 | si->si_ack = ntohs(si->si_ack); | |
279 | si->si_alo = ntohs(si->si_alo); | |
280 | ns_error(dtom(si), NS_ERR_NOSOCK, 0); | |
281 | if (cb->s_nspcb->nsp_socket->so_options & SO_DEBUG || traceallspps) | |
282 | spp_trace(SA_DROP, (u_char)ostate, cb, &spp_savesi, 0); | |
283 | return; | |
284 | ||
285 | drop: | |
286 | bad: | |
287 | if (cb == 0 || cb->s_nspcb->nsp_socket->so_options & SO_DEBUG || | |
288 | traceallspps) | |
289 | spp_trace(SA_DROP, (u_char)ostate, cb, &spp_savesi, 0); | |
290 | m_freem(m); | |
291 | } | |
292 | ||
293 | int spprexmtthresh = 3; | |
294 | ||
295 | /* | |
296 | * This is structurally similar to the tcp reassembly routine | |
297 | * but its function is somewhat different: It merely queues | |
298 | * packets up, and suppresses duplicates. | |
299 | */ | |
4c45483e | 300 | int |
15637ed4 | 301 | spp_reass(cb, si) |
fde1aeb2 GW |
302 | register struct sppcb *cb; |
303 | register struct spidp *si; | |
15637ed4 RG |
304 | { |
305 | register struct spidp_q *q; | |
306 | register struct mbuf *m; | |
307 | register struct socket *so = cb->s_nspcb->nsp_socket; | |
308 | char packetp = cb->s_flags & SF_HI; | |
309 | int incr; | |
310 | char wakeup = 0; | |
311 | ||
312 | if (si == SI(0)) | |
313 | goto present; | |
314 | /* | |
315 | * Update our news from them. | |
316 | */ | |
317 | if (si->si_cc & SP_SA) | |
318 | cb->s_flags |= (spp_use_delack ? SF_DELACK : SF_ACKNOW); | |
319 | if (SSEQ_GT(si->si_alo, cb->s_ralo)) | |
320 | cb->s_flags |= SF_WIN; | |
321 | if (SSEQ_LEQ(si->si_ack, cb->s_rack)) { | |
322 | if ((si->si_cc & SP_SP) && cb->s_rack != (cb->s_smax + 1)) { | |
323 | sppstat.spps_rcvdupack++; | |
324 | /* | |
325 | * If this is a completely duplicate ack | |
326 | * and other conditions hold, we assume | |
327 | * a packet has been dropped and retransmit | |
328 | * it exactly as in tcp_input(). | |
329 | */ | |
330 | if (si->si_ack != cb->s_rack || | |
331 | si->si_alo != cb->s_ralo) | |
332 | cb->s_dupacks = 0; | |
333 | else if (++cb->s_dupacks == spprexmtthresh) { | |
334 | u_short onxt = cb->s_snxt; | |
335 | int cwnd = cb->s_cwnd; | |
336 | ||
337 | cb->s_snxt = si->si_ack; | |
338 | cb->s_cwnd = CUNIT; | |
339 | cb->s_force = 1 + SPPT_REXMT; | |
340 | (void) spp_output(cb, (struct mbuf *)0); | |
341 | cb->s_timer[SPPT_REXMT] = cb->s_rxtcur; | |
342 | cb->s_rtt = 0; | |
343 | if (cwnd >= 4 * CUNIT) | |
344 | cb->s_cwnd = cwnd / 2; | |
345 | if (SSEQ_GT(onxt, cb->s_snxt)) | |
346 | cb->s_snxt = onxt; | |
347 | return (1); | |
348 | } | |
349 | } else | |
350 | cb->s_dupacks = 0; | |
351 | goto update_window; | |
352 | } | |
353 | cb->s_dupacks = 0; | |
354 | /* | |
355 | * If our correspondent acknowledges data we haven't sent | |
356 | * TCP would drop the packet after acking. We'll be a little | |
357 | * more permissive | |
358 | */ | |
359 | if (SSEQ_GT(si->si_ack, (cb->s_smax + 1))) { | |
360 | sppstat.spps_rcvacktoomuch++; | |
361 | si->si_ack = cb->s_smax + 1; | |
362 | } | |
363 | sppstat.spps_rcvackpack++; | |
364 | /* | |
365 | * If transmit timer is running and timed sequence | |
366 | * number was acked, update smoothed round trip time. | |
367 | * See discussion of algorithm in tcp_input.c | |
368 | */ | |
369 | if (cb->s_rtt && SSEQ_GT(si->si_ack, cb->s_rtseq)) { | |
370 | sppstat.spps_rttupdated++; | |
371 | if (cb->s_srtt != 0) { | |
372 | register short delta; | |
373 | delta = cb->s_rtt - (cb->s_srtt >> 3); | |
374 | if ((cb->s_srtt += delta) <= 0) | |
375 | cb->s_srtt = 1; | |
376 | if (delta < 0) | |
377 | delta = -delta; | |
378 | delta -= (cb->s_rttvar >> 2); | |
379 | if ((cb->s_rttvar += delta) <= 0) | |
380 | cb->s_rttvar = 1; | |
381 | } else { | |
382 | /* | |
383 | * No rtt measurement yet | |
384 | */ | |
385 | cb->s_srtt = cb->s_rtt << 3; | |
386 | cb->s_rttvar = cb->s_rtt << 1; | |
387 | } | |
388 | cb->s_rtt = 0; | |
389 | cb->s_rxtshift = 0; | |
390 | SPPT_RANGESET(cb->s_rxtcur, | |
391 | ((cb->s_srtt >> 2) + cb->s_rttvar) >> 1, | |
392 | SPPTV_MIN, SPPTV_REXMTMAX); | |
393 | } | |
394 | /* | |
395 | * If all outstanding data is acked, stop retransmit | |
396 | * timer and remember to restart (more output or persist). | |
397 | * If there is more data to be acked, restart retransmit | |
398 | * timer, using current (possibly backed-off) value; | |
399 | */ | |
400 | if (si->si_ack == cb->s_smax + 1) { | |
401 | cb->s_timer[SPPT_REXMT] = 0; | |
402 | cb->s_flags |= SF_RXT; | |
403 | } else if (cb->s_timer[SPPT_PERSIST] == 0) | |
404 | cb->s_timer[SPPT_REXMT] = cb->s_rxtcur; | |
405 | /* | |
406 | * When new data is acked, open the congestion window. | |
407 | * If the window gives us less than ssthresh packets | |
408 | * in flight, open exponentially (maxseg at a time). | |
409 | * Otherwise open linearly (maxseg^2 / cwnd at a time). | |
410 | */ | |
411 | incr = CUNIT; | |
412 | if (cb->s_cwnd > cb->s_ssthresh) | |
413 | incr = max(incr * incr / cb->s_cwnd, 1); | |
414 | cb->s_cwnd = min(cb->s_cwnd + incr, cb->s_cwmx); | |
415 | /* | |
416 | * Trim Acked data from output queue. | |
417 | */ | |
418 | while ((m = so->so_snd.sb_mb) != NULL) { | |
419 | if (SSEQ_LT((mtod(m, struct spidp *))->si_seq, si->si_ack)) | |
420 | sbdroprecord(&so->so_snd); | |
421 | else | |
422 | break; | |
423 | } | |
424 | sowwakeup(so); | |
425 | cb->s_rack = si->si_ack; | |
426 | update_window: | |
427 | if (SSEQ_LT(cb->s_snxt, cb->s_rack)) | |
428 | cb->s_snxt = cb->s_rack; | |
429 | if (SSEQ_LT(cb->s_swl1, si->si_seq) || cb->s_swl1 == si->si_seq && | |
430 | (SSEQ_LT(cb->s_swl2, si->si_ack) || | |
431 | cb->s_swl2 == si->si_ack && SSEQ_LT(cb->s_ralo, si->si_alo))) { | |
432 | /* keep track of pure window updates */ | |
433 | if ((si->si_cc & SP_SP) && cb->s_swl2 == si->si_ack | |
434 | && SSEQ_LT(cb->s_ralo, si->si_alo)) { | |
435 | sppstat.spps_rcvwinupd++; | |
436 | sppstat.spps_rcvdupack--; | |
437 | } | |
438 | cb->s_ralo = si->si_alo; | |
439 | cb->s_swl1 = si->si_seq; | |
440 | cb->s_swl2 = si->si_ack; | |
441 | cb->s_swnd = (1 + si->si_alo - si->si_ack); | |
442 | if (cb->s_swnd > cb->s_smxw) | |
443 | cb->s_smxw = cb->s_swnd; | |
444 | cb->s_flags |= SF_WIN; | |
445 | } | |
446 | /* | |
447 | * If this packet number is higher than that which | |
448 | * we have allocated refuse it, unless urgent | |
449 | */ | |
450 | if (SSEQ_GT(si->si_seq, cb->s_alo)) { | |
451 | if (si->si_cc & SP_SP) { | |
452 | sppstat.spps_rcvwinprobe++; | |
453 | return (1); | |
454 | } else | |
455 | sppstat.spps_rcvpackafterwin++; | |
456 | if (si->si_cc & SP_OB) { | |
457 | if (SSEQ_GT(si->si_seq, cb->s_alo + 60)) { | |
458 | ns_error(dtom(si), NS_ERR_FULLUP, 0); | |
459 | return (0); | |
460 | } /* else queue this packet; */ | |
461 | } else { | |
462 | /*register struct socket *so = cb->s_nspcb->nsp_socket; | |
463 | if (so->so_state && SS_NOFDREF) { | |
464 | ns_error(dtom(si), NS_ERR_NOSOCK, 0); | |
465 | (void)spp_close(cb); | |
466 | } else | |
467 | would crash system*/ | |
468 | spp_istat.notyet++; | |
469 | ns_error(dtom(si), NS_ERR_FULLUP, 0); | |
470 | return (0); | |
471 | } | |
472 | } | |
473 | /* | |
474 | * If this is a system packet, we don't need to | |
475 | * queue it up, and won't update acknowledge # | |
476 | */ | |
477 | if (si->si_cc & SP_SP) { | |
478 | return (1); | |
479 | } | |
480 | /* | |
481 | * We have already seen this packet, so drop. | |
482 | */ | |
483 | if (SSEQ_LT(si->si_seq, cb->s_ack)) { | |
484 | spp_istat.bdreas++; | |
485 | sppstat.spps_rcvduppack++; | |
486 | if (si->si_seq == cb->s_ack - 1) | |
487 | spp_istat.lstdup++; | |
488 | return (1); | |
489 | } | |
490 | /* | |
491 | * Loop through all packets queued up to insert in | |
492 | * appropriate sequence. | |
493 | */ | |
494 | for (q = cb->s_q.si_next; q!=&cb->s_q; q = q->si_next) { | |
495 | if (si->si_seq == SI(q)->si_seq) { | |
496 | sppstat.spps_rcvduppack++; | |
497 | return (1); | |
498 | } | |
499 | if (SSEQ_LT(si->si_seq, SI(q)->si_seq)) { | |
500 | sppstat.spps_rcvoopack++; | |
501 | break; | |
502 | } | |
503 | } | |
504 | insque(si, q->si_prev); | |
505 | /* | |
506 | * If this packet is urgent, inform process | |
507 | */ | |
508 | if (si->si_cc & SP_OB) { | |
509 | cb->s_iobc = ((char *)si)[1 + sizeof(*si)]; | |
510 | sohasoutofband(so); | |
511 | cb->s_oobflags |= SF_IOOB; | |
512 | } | |
513 | present: | |
514 | #define SPINC sizeof(struct sphdr) | |
515 | /* | |
516 | * Loop through all packets queued up to update acknowledge | |
517 | * number, and present all acknowledged data to user; | |
518 | * If in packet interface mode, show packet headers. | |
519 | */ | |
520 | for (q = cb->s_q.si_next; q!=&cb->s_q; q = q->si_next) { | |
521 | if (SI(q)->si_seq == cb->s_ack) { | |
522 | cb->s_ack++; | |
523 | m = dtom(q); | |
524 | if (SI(q)->si_cc & SP_OB) { | |
525 | cb->s_oobflags &= ~SF_IOOB; | |
526 | if (so->so_rcv.sb_cc) | |
527 | so->so_oobmark = so->so_rcv.sb_cc; | |
528 | else | |
529 | so->so_state |= SS_RCVATMARK; | |
530 | } | |
531 | q = q->si_prev; | |
532 | remque(q->si_next); | |
533 | wakeup = 1; | |
534 | sppstat.spps_rcvpack++; | |
535 | #ifdef SF_NEWCALL | |
536 | if (cb->s_flags2 & SF_NEWCALL) { | |
537 | struct sphdr *sp = mtod(m, struct sphdr *); | |
538 | u_char dt = sp->sp_dt; | |
539 | spp_newchecks[4]++; | |
540 | if (dt != cb->s_rhdr.sp_dt) { | |
541 | struct mbuf *mm = | |
542 | m_getclr(M_DONTWAIT, MT_CONTROL); | |
543 | spp_newchecks[0]++; | |
544 | if (mm != NULL) { | |
545 | u_short *s = | |
546 | mtod(mm, u_short *); | |
547 | cb->s_rhdr.sp_dt = dt; | |
548 | mm->m_len = 5; /*XXX*/ | |
549 | s[0] = 5; | |
550 | s[1] = 1; | |
551 | *(u_char *)(&s[2]) = dt; | |
552 | sbappend(&so->so_rcv, mm); | |
553 | } | |
554 | } | |
555 | if (sp->sp_cc & SP_OB) { | |
556 | MCHTYPE(m, MT_OOBDATA); | |
557 | spp_newchecks[1]++; | |
558 | so->so_oobmark = 0; | |
559 | so->so_state &= ~SS_RCVATMARK; | |
560 | } | |
561 | if (packetp == 0) { | |
562 | m->m_data += SPINC; | |
563 | m->m_len -= SPINC; | |
564 | m->m_pkthdr.len -= SPINC; | |
565 | } | |
566 | if ((sp->sp_cc & SP_EM) || packetp) { | |
567 | sbappendrecord(&so->so_rcv, m); | |
568 | spp_newchecks[9]++; | |
569 | } else | |
570 | sbappend(&so->so_rcv, m); | |
571 | } else | |
572 | #endif | |
573 | if (packetp) { | |
574 | sbappendrecord(&so->so_rcv, m); | |
575 | } else { | |
576 | cb->s_rhdr = *mtod(m, struct sphdr *); | |
577 | m->m_data += SPINC; | |
578 | m->m_len -= SPINC; | |
579 | m->m_pkthdr.len -= SPINC; | |
580 | sbappend(&so->so_rcv, m); | |
581 | } | |
582 | } else | |
583 | break; | |
584 | } | |
585 | if (wakeup) sorwakeup(so); | |
586 | return (0); | |
587 | } | |
588 | ||
4c45483e | 589 | void |
15637ed4 RG |
590 | spp_ctlinput(cmd, arg) |
591 | int cmd; | |
592 | caddr_t arg; | |
593 | { | |
594 | struct ns_addr *na; | |
4c45483e | 595 | struct ns_errp *errp = 0; |
15637ed4 RG |
596 | struct nspcb *nsp; |
597 | struct sockaddr_ns *sns; | |
598 | int type; | |
599 | ||
600 | if (cmd < 0 || cmd > PRC_NCMDS) | |
601 | return; | |
602 | type = NS_ERR_UNREACH_HOST; | |
603 | ||
604 | switch (cmd) { | |
605 | ||
606 | case PRC_ROUTEDEAD: | |
607 | return; | |
608 | ||
609 | case PRC_IFDOWN: | |
610 | case PRC_HOSTDEAD: | |
611 | case PRC_HOSTUNREACH: | |
612 | sns = (struct sockaddr_ns *)arg; | |
613 | if (sns->sns_family != AF_NS) | |
614 | return; | |
615 | na = &sns->sns_addr; | |
616 | break; | |
617 | ||
618 | default: | |
619 | errp = (struct ns_errp *)arg; | |
620 | na = &errp->ns_err_idp.idp_dna; | |
621 | type = errp->ns_err_num; | |
622 | type = ntohs((u_short)type); | |
623 | } | |
624 | switch (type) { | |
625 | ||
626 | case NS_ERR_UNREACH_HOST: | |
627 | ns_pcbnotify(na, (int)nsctlerrmap[cmd], spp_abort, (long) 0); | |
628 | break; | |
629 | ||
630 | case NS_ERR_TOO_BIG: | |
631 | case NS_ERR_NOSOCK: | |
632 | nsp = ns_pcblookup(na, errp->ns_err_idp.idp_sna.x_port, | |
633 | NS_WILDCARD); | |
634 | if (nsp) { | |
635 | if(nsp->nsp_pcb) | |
636 | (void) spp_drop((struct sppcb *)nsp->nsp_pcb, | |
637 | (int)nsctlerrmap[cmd]); | |
638 | else | |
639 | (void) idp_drop(nsp, (int)nsctlerrmap[cmd]); | |
640 | } | |
641 | break; | |
642 | ||
643 | case NS_ERR_FULLUP: | |
644 | ns_pcbnotify(na, 0, spp_quench, (long) 0); | |
645 | } | |
646 | } | |
647 | /* | |
648 | * When a source quench is received, close congestion window | |
649 | * to one packet. We will gradually open it again as we proceed. | |
650 | */ | |
4c45483e | 651 | static void |
fde1aeb2 | 652 | spp_quench(nsp, errno) |
15637ed4 | 653 | struct nspcb *nsp; |
fde1aeb2 | 654 | int errno; |
15637ed4 RG |
655 | { |
656 | struct sppcb *cb = nstosppcb(nsp); | |
657 | ||
658 | if (cb) | |
659 | cb->s_cwnd = CUNIT; | |
660 | } | |
661 | ||
662 | #ifdef notdef | |
663 | int | |
664 | spp_fixmtu(nsp) | |
665 | register struct nspcb *nsp; | |
666 | { | |
667 | register struct sppcb *cb = (struct sppcb *)(nsp->nsp_pcb); | |
668 | register struct mbuf *m; | |
669 | register struct spidp *si; | |
670 | struct ns_errp *ep; | |
671 | struct sockbuf *sb; | |
672 | int badseq, len; | |
673 | struct mbuf *firstbad, *m0; | |
674 | ||
675 | if (cb) { | |
676 | /* | |
677 | * The notification that we have sent | |
678 | * too much is bad news -- we will | |
679 | * have to go through queued up so far | |
680 | * splitting ones which are too big and | |
681 | * reassigning sequence numbers and checksums. | |
682 | * we should then retransmit all packets from | |
683 | * one above the offending packet to the last one | |
684 | * we had sent (or our allocation) | |
685 | * then the offending one so that the any queued | |
686 | * data at our destination will be discarded. | |
687 | */ | |
688 | ep = (struct ns_errp *)nsp->nsp_notify_param; | |
689 | sb = &nsp->nsp_socket->so_snd; | |
690 | cb->s_mtu = ep->ns_err_param; | |
691 | badseq = SI(&ep->ns_err_idp)->si_seq; | |
692 | for (m = sb->sb_mb; m; m = m->m_act) { | |
693 | si = mtod(m, struct spidp *); | |
694 | if (si->si_seq == badseq) | |
695 | break; | |
696 | } | |
697 | if (m == 0) return; | |
698 | firstbad = m; | |
699 | /*for (;;) {*/ | |
700 | /* calculate length */ | |
701 | for (m0 = m, len = 0; m ; m = m->m_next) | |
702 | len += m->m_len; | |
703 | if (len > cb->s_mtu) { | |
704 | } | |
705 | /* FINISH THIS | |
706 | } */ | |
707 | } | |
708 | } | |
709 | #endif | |
710 | ||
4c45483e | 711 | int |
15637ed4 RG |
712 | spp_output(cb, m0) |
713 | register struct sppcb *cb; | |
714 | struct mbuf *m0; | |
715 | { | |
716 | struct socket *so = cb->s_nspcb->nsp_socket; | |
717 | register struct mbuf *m; | |
718 | register struct spidp *si = (struct spidp *) 0; | |
719 | register struct sockbuf *sb = &so->so_snd; | |
720 | int len = 0, win, rcv_win; | |
721 | short span, off, recordp = 0; | |
722 | u_short alo; | |
723 | int error = 0, sendalot; | |
724 | #ifdef notdef | |
725 | int idle; | |
726 | #endif | |
727 | struct mbuf *mprev; | |
728 | extern int idpcksum; | |
729 | ||
730 | if (m0) { | |
731 | int mtu = cb->s_mtu; | |
732 | int datalen; | |
733 | /* | |
734 | * Make sure that packet isn't too big. | |
735 | */ | |
736 | for (m = m0; m ; m = m->m_next) { | |
737 | mprev = m; | |
738 | len += m->m_len; | |
739 | if (m->m_flags & M_EOR) | |
740 | recordp = 1; | |
741 | } | |
742 | datalen = (cb->s_flags & SF_HO) ? | |
743 | len - sizeof (struct sphdr) : len; | |
744 | if (datalen > mtu) { | |
745 | if (cb->s_flags & SF_PI) { | |
746 | m_freem(m0); | |
747 | return (EMSGSIZE); | |
748 | } else { | |
749 | int oldEM = cb->s_cc & SP_EM; | |
750 | ||
751 | cb->s_cc &= ~SP_EM; | |
752 | while (len > mtu) { | |
753 | /* | |
754 | * Here we are only being called | |
755 | * from usrreq(), so it is OK to | |
756 | * block. | |
757 | */ | |
758 | m = m_copym(m0, 0, mtu, M_WAIT); | |
759 | if (cb->s_flags & SF_NEWCALL) { | |
760 | struct mbuf *mm = m; | |
761 | spp_newchecks[7]++; | |
762 | while (mm) { | |
763 | mm->m_flags &= ~M_EOR; | |
764 | mm = mm->m_next; | |
765 | } | |
766 | } | |
767 | error = spp_output(cb, m); | |
768 | if (error) { | |
769 | cb->s_cc |= oldEM; | |
770 | m_freem(m0); | |
771 | return(error); | |
772 | } | |
773 | m_adj(m0, mtu); | |
774 | len -= mtu; | |
775 | } | |
776 | cb->s_cc |= oldEM; | |
777 | } | |
778 | } | |
779 | /* | |
780 | * Force length even, by adding a "garbage byte" if | |
781 | * necessary. | |
782 | */ | |
783 | if (len & 1) { | |
784 | m = mprev; | |
785 | if (M_TRAILINGSPACE(m) >= 1) | |
786 | m->m_len++; | |
787 | else { | |
788 | struct mbuf *m1 = m_get(M_DONTWAIT, MT_DATA); | |
789 | ||
790 | if (m1 == 0) { | |
791 | m_freem(m0); | |
792 | return (ENOBUFS); | |
793 | } | |
794 | m1->m_len = 1; | |
795 | *(mtod(m1, u_char *)) = 0; | |
796 | m->m_next = m1; | |
797 | } | |
798 | } | |
799 | m = m_gethdr(M_DONTWAIT, MT_HEADER); | |
800 | if (m == 0) { | |
801 | m_freem(m0); | |
802 | return (ENOBUFS); | |
803 | } | |
804 | /* | |
805 | * Fill in mbuf with extended SP header | |
806 | * and addresses and length put into network format. | |
807 | */ | |
808 | MH_ALIGN(m, sizeof (struct spidp)); | |
809 | m->m_len = sizeof (struct spidp); | |
810 | m->m_next = m0; | |
811 | si = mtod(m, struct spidp *); | |
812 | si->si_i = *cb->s_idp; | |
813 | si->si_s = cb->s_shdr; | |
814 | if ((cb->s_flags & SF_PI) && (cb->s_flags & SF_HO)) { | |
815 | register struct sphdr *sh; | |
816 | if (m0->m_len < sizeof (*sh)) { | |
817 | if((m0 = m_pullup(m0, sizeof(*sh))) == NULL) { | |
818 | (void) m_free(m); | |
819 | m_freem(m0); | |
820 | return (EINVAL); | |
821 | } | |
822 | m->m_next = m0; | |
823 | } | |
824 | sh = mtod(m0, struct sphdr *); | |
825 | si->si_dt = sh->sp_dt; | |
826 | si->si_cc |= sh->sp_cc & SP_EM; | |
827 | m0->m_len -= sizeof (*sh); | |
828 | m0->m_data += sizeof (*sh); | |
829 | len -= sizeof (*sh); | |
830 | } | |
831 | len += sizeof(*si); | |
832 | if ((cb->s_flags2 & SF_NEWCALL) && recordp) { | |
833 | si->si_cc |= SP_EM; | |
834 | spp_newchecks[8]++; | |
835 | } | |
836 | if (cb->s_oobflags & SF_SOOB) { | |
837 | /* | |
838 | * Per jqj@cornell: | |
839 | * make sure OB packets convey exactly 1 byte. | |
840 | * If the packet is 1 byte or larger, we | |
841 | * have already guaranted there to be at least | |
842 | * one garbage byte for the checksum, and | |
843 | * extra bytes shouldn't hurt! | |
844 | */ | |
845 | if (len > sizeof(*si)) { | |
846 | si->si_cc |= SP_OB; | |
847 | len = (1 + sizeof(*si)); | |
848 | } | |
849 | } | |
850 | si->si_len = htons((u_short)len); | |
851 | m->m_pkthdr.len = ((len - 1) | 1) + 1; | |
852 | /* | |
853 | * queue stuff up for output | |
854 | */ | |
855 | sbappendrecord(sb, m); | |
856 | cb->s_seq++; | |
857 | } | |
858 | #ifdef notdef | |
859 | idle = (cb->s_smax == (cb->s_rack - 1)); | |
860 | #endif | |
861 | again: | |
862 | sendalot = 0; | |
863 | off = cb->s_snxt - cb->s_rack; | |
864 | win = min(cb->s_swnd, (cb->s_cwnd/CUNIT)); | |
865 | ||
866 | /* | |
867 | * If in persist timeout with window of 0, send a probe. | |
868 | * Otherwise, if window is small but nonzero | |
869 | * and timer expired, send what we can and go into | |
870 | * transmit state. | |
871 | */ | |
872 | if (cb->s_force == 1 + SPPT_PERSIST) { | |
873 | if (win != 0) { | |
874 | cb->s_timer[SPPT_PERSIST] = 0; | |
875 | cb->s_rxtshift = 0; | |
876 | } | |
877 | } | |
878 | span = cb->s_seq - cb->s_rack; | |
879 | len = min(span, win) - off; | |
880 | ||
881 | if (len < 0) { | |
882 | /* | |
883 | * Window shrank after we went into it. | |
884 | * If window shrank to 0, cancel pending | |
885 | * restransmission and pull s_snxt back | |
886 | * to (closed) window. We will enter persist | |
887 | * state below. If the widndow didn't close completely, | |
888 | * just wait for an ACK. | |
889 | */ | |
890 | len = 0; | |
891 | if (win == 0) { | |
892 | cb->s_timer[SPPT_REXMT] = 0; | |
893 | cb->s_snxt = cb->s_rack; | |
894 | } | |
895 | } | |
896 | if (len > 1) | |
897 | sendalot = 1; | |
898 | rcv_win = sbspace(&so->so_rcv); | |
899 | ||
900 | /* | |
901 | * Send if we owe peer an ACK. | |
902 | */ | |
903 | if (cb->s_oobflags & SF_SOOB) { | |
904 | /* | |
905 | * must transmit this out of band packet | |
906 | */ | |
907 | cb->s_oobflags &= ~ SF_SOOB; | |
908 | sendalot = 1; | |
909 | sppstat.spps_sndurg++; | |
910 | goto found; | |
911 | } | |
912 | if (cb->s_flags & SF_ACKNOW) | |
913 | goto send; | |
914 | if (cb->s_state < TCPS_ESTABLISHED) | |
915 | goto send; | |
916 | /* | |
917 | * Silly window can't happen in spp. | |
918 | * Code from tcp deleted. | |
919 | */ | |
920 | if (len) | |
921 | goto send; | |
922 | /* | |
923 | * Compare available window to amount of window | |
924 | * known to peer (as advertised window less | |
925 | * next expected input.) If the difference is at least two | |
926 | * packets or at least 35% of the mximum possible window, | |
927 | * then want to send a window update to peer. | |
928 | */ | |
929 | if (rcv_win > 0) { | |
930 | u_short delta = 1 + cb->s_alo - cb->s_ack; | |
931 | int adv = rcv_win - (delta * cb->s_mtu); | |
932 | ||
933 | if ((so->so_rcv.sb_cc == 0 && adv >= (2 * cb->s_mtu)) || | |
934 | (100 * adv / so->so_rcv.sb_hiwat >= 35)) { | |
935 | sppstat.spps_sndwinup++; | |
936 | cb->s_flags |= SF_ACKNOW; | |
937 | goto send; | |
938 | } | |
939 | ||
940 | } | |
941 | /* | |
942 | * Many comments from tcp_output.c are appropriate here | |
943 | * including . . . | |
944 | * If send window is too small, there is data to transmit, and no | |
945 | * retransmit or persist is pending, then go to persist state. | |
946 | * If nothing happens soon, send when timer expires: | |
947 | * if window is nonzero, transmit what we can, | |
948 | * otherwise send a probe. | |
949 | */ | |
950 | if (so->so_snd.sb_cc && cb->s_timer[SPPT_REXMT] == 0 && | |
951 | cb->s_timer[SPPT_PERSIST] == 0) { | |
952 | cb->s_rxtshift = 0; | |
953 | spp_setpersist(cb); | |
954 | } | |
955 | /* | |
956 | * No reason to send a packet, just return. | |
957 | */ | |
958 | cb->s_outx = 1; | |
959 | return (0); | |
960 | ||
961 | send: | |
962 | /* | |
963 | * Find requested packet. | |
964 | */ | |
965 | si = 0; | |
966 | if (len > 0) { | |
967 | cb->s_want = cb->s_snxt; | |
968 | for (m = sb->sb_mb; m; m = m->m_act) { | |
969 | si = mtod(m, struct spidp *); | |
970 | if (SSEQ_LEQ(cb->s_snxt, si->si_seq)) | |
971 | break; | |
972 | } | |
973 | found: | |
974 | if (si) { | |
975 | if (si->si_seq == cb->s_snxt) | |
976 | cb->s_snxt++; | |
977 | else | |
978 | sppstat.spps_sndvoid++, si = 0; | |
979 | } | |
980 | } | |
981 | /* | |
982 | * update window | |
983 | */ | |
984 | if (rcv_win < 0) | |
985 | rcv_win = 0; | |
986 | alo = cb->s_ack - 1 + (rcv_win / ((short)cb->s_mtu)); | |
987 | if (SSEQ_LT(alo, cb->s_alo)) | |
988 | alo = cb->s_alo; | |
989 | ||
990 | if (si) { | |
991 | /* | |
992 | * must make a copy of this packet for | |
993 | * idp_output to monkey with | |
994 | */ | |
995 | m = m_copy(dtom(si), 0, (int)M_COPYALL); | |
996 | if (m == NULL) { | |
997 | return (ENOBUFS); | |
998 | } | |
999 | si = mtod(m, struct spidp *); | |
1000 | if (SSEQ_LT(si->si_seq, cb->s_smax)) | |
1001 | sppstat.spps_sndrexmitpack++; | |
1002 | else | |
1003 | sppstat.spps_sndpack++; | |
1004 | } else if (cb->s_force || cb->s_flags & SF_ACKNOW) { | |
1005 | /* | |
1006 | * Must send an acknowledgement or a probe | |
1007 | */ | |
1008 | if (cb->s_force) | |
1009 | sppstat.spps_sndprobe++; | |
1010 | if (cb->s_flags & SF_ACKNOW) | |
1011 | sppstat.spps_sndacks++; | |
1012 | m = m_gethdr(M_DONTWAIT, MT_HEADER); | |
1013 | if (m == 0) | |
1014 | return (ENOBUFS); | |
1015 | /* | |
1016 | * Fill in mbuf with extended SP header | |
1017 | * and addresses and length put into network format. | |
1018 | */ | |
1019 | MH_ALIGN(m, sizeof (struct spidp)); | |
1020 | m->m_len = sizeof (*si); | |
1021 | m->m_pkthdr.len = sizeof (*si); | |
1022 | si = mtod(m, struct spidp *); | |
1023 | si->si_i = *cb->s_idp; | |
1024 | si->si_s = cb->s_shdr; | |
1025 | si->si_seq = cb->s_smax + 1; | |
1026 | si->si_len = htons(sizeof (*si)); | |
1027 | si->si_cc |= SP_SP; | |
1028 | } else { | |
1029 | cb->s_outx = 3; | |
1030 | if (so->so_options & SO_DEBUG || traceallspps) | |
1031 | spp_trace(SA_OUTPUT, cb->s_state, cb, si, 0); | |
1032 | return (0); | |
1033 | } | |
1034 | /* | |
1035 | * Stuff checksum and output datagram. | |
1036 | */ | |
1037 | if ((si->si_cc & SP_SP) == 0) { | |
1038 | if (cb->s_force != (1 + SPPT_PERSIST) || | |
1039 | cb->s_timer[SPPT_PERSIST] == 0) { | |
1040 | /* | |
1041 | * If this is a new packet and we are not currently | |
1042 | * timing anything, time this one. | |
1043 | */ | |
1044 | if (SSEQ_LT(cb->s_smax, si->si_seq)) { | |
1045 | cb->s_smax = si->si_seq; | |
1046 | if (cb->s_rtt == 0) { | |
1047 | sppstat.spps_segstimed++; | |
1048 | cb->s_rtseq = si->si_seq; | |
1049 | cb->s_rtt = 1; | |
1050 | } | |
1051 | } | |
1052 | /* | |
1053 | * Set rexmt timer if not currently set, | |
1054 | * Initial value for retransmit timer is smoothed | |
1055 | * round-trip time + 2 * round-trip time variance. | |
1056 | * Initialize shift counter which is used for backoff | |
1057 | * of retransmit time. | |
1058 | */ | |
1059 | if (cb->s_timer[SPPT_REXMT] == 0 && | |
1060 | cb->s_snxt != cb->s_rack) { | |
1061 | cb->s_timer[SPPT_REXMT] = cb->s_rxtcur; | |
1062 | if (cb->s_timer[SPPT_PERSIST]) { | |
1063 | cb->s_timer[SPPT_PERSIST] = 0; | |
1064 | cb->s_rxtshift = 0; | |
1065 | } | |
1066 | } | |
1067 | } else if (SSEQ_LT(cb->s_smax, si->si_seq)) { | |
1068 | cb->s_smax = si->si_seq; | |
1069 | } | |
1070 | } else if (cb->s_state < TCPS_ESTABLISHED) { | |
1071 | if (cb->s_rtt == 0) | |
1072 | cb->s_rtt = 1; /* Time initial handshake */ | |
1073 | if (cb->s_timer[SPPT_REXMT] == 0) | |
1074 | cb->s_timer[SPPT_REXMT] = cb->s_rxtcur; | |
1075 | } | |
1076 | { | |
1077 | /* | |
1078 | * Do not request acks when we ack their data packets or | |
1079 | * when we do a gratuitous window update. | |
1080 | */ | |
1081 | if (((si->si_cc & SP_SP) == 0) || cb->s_force) | |
1082 | si->si_cc |= SP_SA; | |
1083 | si->si_seq = htons(si->si_seq); | |
1084 | si->si_alo = htons(alo); | |
1085 | si->si_ack = htons(cb->s_ack); | |
1086 | ||
1087 | if (idpcksum) { | |
1088 | si->si_sum = 0; | |
1089 | len = ntohs(si->si_len); | |
1090 | if (len & 1) | |
1091 | len++; | |
1092 | si->si_sum = ns_cksum(m, len); | |
1093 | } else | |
1094 | si->si_sum = 0xffff; | |
1095 | ||
1096 | cb->s_outx = 4; | |
1097 | if (so->so_options & SO_DEBUG || traceallspps) | |
1098 | spp_trace(SA_OUTPUT, cb->s_state, cb, si, 0); | |
1099 | ||
1100 | if (so->so_options & SO_DONTROUTE) | |
1101 | error = ns_output(m, (struct route *)0, NS_ROUTETOIF); | |
1102 | else | |
1103 | error = ns_output(m, &cb->s_nspcb->nsp_route, 0); | |
1104 | } | |
1105 | if (error) { | |
1106 | return (error); | |
1107 | } | |
1108 | sppstat.spps_sndtotal++; | |
1109 | /* | |
1110 | * Data sent (as far as we can tell). | |
1111 | * If this advertises a larger window than any other segment, | |
1112 | * then remember the size of the advertized window. | |
1113 | * Any pending ACK has now been sent. | |
1114 | */ | |
1115 | cb->s_force = 0; | |
1116 | cb->s_flags &= ~(SF_ACKNOW|SF_DELACK); | |
1117 | if (SSEQ_GT(alo, cb->s_alo)) | |
1118 | cb->s_alo = alo; | |
1119 | if (sendalot) | |
1120 | goto again; | |
1121 | cb->s_outx = 5; | |
1122 | return (0); | |
1123 | } | |
1124 | ||
1125 | int spp_do_persist_panics = 0; | |
1126 | ||
4c45483e | 1127 | static void |
15637ed4 RG |
1128 | spp_setpersist(cb) |
1129 | register struct sppcb *cb; | |
1130 | { | |
1131 | register t = ((cb->s_srtt >> 2) + cb->s_rttvar) >> 1; | |
1132 | extern int spp_backoff[]; | |
1133 | ||
1134 | if (cb->s_timer[SPPT_REXMT] && spp_do_persist_panics) | |
1135 | panic("spp_output REXMT"); | |
1136 | /* | |
1137 | * Start/restart persistance timer. | |
1138 | */ | |
1139 | SPPT_RANGESET(cb->s_timer[SPPT_PERSIST], | |
1140 | t*spp_backoff[cb->s_rxtshift], | |
1141 | SPPTV_PERSMIN, SPPTV_PERSMAX); | |
1142 | if (cb->s_rxtshift < SPP_MAXRXTSHIFT) | |
1143 | cb->s_rxtshift++; | |
1144 | } | |
4c45483e | 1145 | |
15637ed4 | 1146 | /*ARGSUSED*/ |
4c45483e | 1147 | int |
15637ed4 RG |
1148 | spp_ctloutput(req, so, level, name, value) |
1149 | int req; | |
1150 | struct socket *so; | |
4c45483e | 1151 | int level; |
15637ed4 RG |
1152 | int name; |
1153 | struct mbuf **value; | |
1154 | { | |
1155 | register struct mbuf *m; | |
1156 | struct nspcb *nsp = sotonspcb(so); | |
1157 | register struct sppcb *cb; | |
1158 | int mask, error = 0; | |
1159 | ||
1160 | if (level != NSPROTO_SPP) { | |
1161 | /* This will have to be changed when we do more general | |
1162 | stacking of protocols */ | |
1163 | return (idp_ctloutput(req, so, level, name, value)); | |
1164 | } | |
1165 | if (nsp == NULL) { | |
1166 | error = EINVAL; | |
1167 | goto release; | |
1168 | } else | |
1169 | cb = nstosppcb(nsp); | |
1170 | ||
1171 | switch (req) { | |
1172 | ||
1173 | case PRCO_GETOPT: | |
1174 | if (value == NULL) | |
1175 | return (EINVAL); | |
1176 | m = m_get(M_DONTWAIT, MT_DATA); | |
1177 | if (m == NULL) | |
1178 | return (ENOBUFS); | |
1179 | switch (name) { | |
1180 | ||
1181 | case SO_HEADERS_ON_INPUT: | |
1182 | mask = SF_HI; | |
1183 | goto get_flags; | |
1184 | ||
1185 | case SO_HEADERS_ON_OUTPUT: | |
1186 | mask = SF_HO; | |
1187 | get_flags: | |
1188 | m->m_len = sizeof(short); | |
1189 | *mtod(m, short *) = cb->s_flags & mask; | |
1190 | break; | |
1191 | ||
1192 | case SO_MTU: | |
1193 | m->m_len = sizeof(u_short); | |
1194 | *mtod(m, short *) = cb->s_mtu; | |
1195 | break; | |
1196 | ||
1197 | case SO_LAST_HEADER: | |
1198 | m->m_len = sizeof(struct sphdr); | |
1199 | *mtod(m, struct sphdr *) = cb->s_rhdr; | |
1200 | break; | |
1201 | ||
1202 | case SO_DEFAULT_HEADERS: | |
1203 | m->m_len = sizeof(struct spidp); | |
1204 | *mtod(m, struct sphdr *) = cb->s_shdr; | |
1205 | break; | |
1206 | ||
1207 | default: | |
1208 | error = EINVAL; | |
1209 | } | |
1210 | *value = m; | |
1211 | break; | |
1212 | ||
1213 | case PRCO_SETOPT: | |
1214 | if (value == 0 || *value == 0) { | |
1215 | error = EINVAL; | |
1216 | break; | |
1217 | } | |
1218 | switch (name) { | |
1219 | int *ok; | |
1220 | ||
1221 | case SO_HEADERS_ON_INPUT: | |
1222 | mask = SF_HI; | |
1223 | goto set_head; | |
1224 | ||
1225 | case SO_HEADERS_ON_OUTPUT: | |
1226 | mask = SF_HO; | |
1227 | set_head: | |
1228 | if (cb->s_flags & SF_PI) { | |
1229 | ok = mtod(*value, int *); | |
1230 | if (*ok) | |
1231 | cb->s_flags |= mask; | |
1232 | else | |
1233 | cb->s_flags &= ~mask; | |
1234 | } else error = EINVAL; | |
1235 | break; | |
1236 | ||
1237 | case SO_MTU: | |
1238 | cb->s_mtu = *(mtod(*value, u_short *)); | |
1239 | break; | |
1240 | ||
1241 | #ifdef SF_NEWCALL | |
1242 | case SO_NEWCALL: | |
1243 | ok = mtod(*value, int *); | |
1244 | if (*ok) { | |
1245 | cb->s_flags2 |= SF_NEWCALL; | |
1246 | spp_newchecks[5]++; | |
1247 | } else { | |
1248 | cb->s_flags2 &= ~SF_NEWCALL; | |
1249 | spp_newchecks[6]++; | |
1250 | } | |
1251 | break; | |
1252 | #endif | |
1253 | ||
1254 | case SO_DEFAULT_HEADERS: | |
1255 | { | |
1256 | register struct sphdr *sp | |
1257 | = mtod(*value, struct sphdr *); | |
1258 | cb->s_dt = sp->sp_dt; | |
1259 | cb->s_cc = sp->sp_cc & SP_EM; | |
1260 | } | |
1261 | break; | |
1262 | ||
1263 | default: | |
1264 | error = EINVAL; | |
1265 | } | |
1266 | m_freem(*value); | |
1267 | break; | |
1268 | } | |
1269 | release: | |
1270 | return (error); | |
1271 | } | |
1272 | ||
1273 | /*ARGSUSED*/ | |
4c45483e | 1274 | int |
fde1aeb2 | 1275 | spp_usrreq(so, req, m, nam, controlp, dummy) |
15637ed4 RG |
1276 | struct socket *so; |
1277 | int req; | |
1278 | struct mbuf *m, *nam, *controlp; | |
fde1aeb2 | 1279 | struct mbuf *dummy; |
15637ed4 RG |
1280 | { |
1281 | struct nspcb *nsp = sotonspcb(so); | |
4c45483e | 1282 | register struct sppcb *cb = 0; |
15637ed4 RG |
1283 | int s = splnet(); |
1284 | int error = 0, ostate; | |
1285 | struct mbuf *mm; | |
1286 | register struct sockbuf *sb; | |
1287 | ||
1288 | if (req == PRU_CONTROL) | |
1289 | return (ns_control(so, (int)m, (caddr_t)nam, | |
1290 | (struct ifnet *)controlp)); | |
1291 | if (nsp == NULL) { | |
1292 | if (req != PRU_ATTACH) { | |
1293 | error = EINVAL; | |
1294 | goto release; | |
1295 | } | |
1296 | } else | |
1297 | cb = nstosppcb(nsp); | |
1298 | ||
1299 | ostate = cb ? cb->s_state : 0; | |
1300 | ||
1301 | switch (req) { | |
1302 | ||
1303 | case PRU_ATTACH: | |
1304 | if (nsp != NULL) { | |
1305 | error = EISCONN; | |
1306 | break; | |
1307 | } | |
1308 | error = ns_pcballoc(so, &nspcb); | |
1309 | if (error) | |
1310 | break; | |
1311 | if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) { | |
1312 | error = soreserve(so, (u_long) 3072, (u_long) 3072); | |
1313 | if (error) | |
1314 | break; | |
1315 | } | |
1316 | nsp = sotonspcb(so); | |
1317 | ||
1318 | mm = m_getclr(M_DONTWAIT, MT_PCB); | |
1319 | sb = &so->so_snd; | |
1320 | ||
1321 | if (mm == NULL) { | |
1322 | error = ENOBUFS; | |
1323 | break; | |
1324 | } | |
1325 | cb = mtod(mm, struct sppcb *); | |
1326 | mm = m_getclr(M_DONTWAIT, MT_HEADER); | |
1327 | if (mm == NULL) { | |
1328 | (void) m_free(dtom(m)); | |
1329 | error = ENOBUFS; | |
1330 | break; | |
1331 | } | |
1332 | cb->s_idp = mtod(mm, struct idp *); | |
1333 | cb->s_state = TCPS_LISTEN; | |
1334 | cb->s_smax = -1; | |
1335 | cb->s_swl1 = -1; | |
1336 | cb->s_q.si_next = cb->s_q.si_prev = &cb->s_q; | |
1337 | cb->s_nspcb = nsp; | |
1338 | cb->s_mtu = 576 - sizeof (struct spidp); | |
1339 | cb->s_cwnd = sbspace(sb) * CUNIT / cb->s_mtu; | |
1340 | cb->s_ssthresh = cb->s_cwnd; | |
1341 | cb->s_cwmx = sbspace(sb) * CUNIT / | |
1342 | (2 * sizeof (struct spidp)); | |
1343 | /* Above is recomputed when connecting to account | |
1344 | for changed buffering or mtu's */ | |
1345 | cb->s_rtt = SPPTV_SRTTBASE; | |
1346 | cb->s_rttvar = SPPTV_SRTTDFLT << 2; | |
1347 | SPPT_RANGESET(cb->s_rxtcur, | |
1348 | ((SPPTV_SRTTBASE >> 2) + (SPPTV_SRTTDFLT << 2)) >> 1, | |
1349 | SPPTV_MIN, SPPTV_REXMTMAX); | |
1350 | nsp->nsp_pcb = (caddr_t) cb; | |
1351 | break; | |
1352 | ||
1353 | case PRU_DETACH: | |
1354 | if (nsp == NULL) { | |
1355 | error = ENOTCONN; | |
1356 | break; | |
1357 | } | |
1358 | if (cb->s_state > TCPS_LISTEN) | |
1359 | cb = spp_disconnect(cb); | |
1360 | else | |
1361 | cb = spp_close(cb); | |
1362 | break; | |
1363 | ||
1364 | case PRU_BIND: | |
1365 | error = ns_pcbbind(nsp, nam); | |
1366 | break; | |
1367 | ||
1368 | case PRU_LISTEN: | |
1369 | if (nsp->nsp_lport == 0) | |
1370 | error = ns_pcbbind(nsp, (struct mbuf *)0); | |
1371 | if (error == 0) | |
1372 | cb->s_state = TCPS_LISTEN; | |
1373 | break; | |
1374 | ||
1375 | /* | |
1376 | * Initiate connection to peer. | |
1377 | * Enter SYN_SENT state, and mark socket as connecting. | |
1378 | * Start keep-alive timer, setup prototype header, | |
1379 | * Send initial system packet requesting connection. | |
1380 | */ | |
1381 | case PRU_CONNECT: | |
1382 | if (nsp->nsp_lport == 0) { | |
1383 | error = ns_pcbbind(nsp, (struct mbuf *)0); | |
1384 | if (error) | |
1385 | break; | |
1386 | } | |
1387 | error = ns_pcbconnect(nsp, nam); | |
1388 | if (error) | |
1389 | break; | |
1390 | soisconnecting(so); | |
1391 | sppstat.spps_connattempt++; | |
1392 | cb->s_state = TCPS_SYN_SENT; | |
1393 | cb->s_did = 0; | |
1394 | spp_template(cb); | |
1395 | cb->s_timer[SPPT_KEEP] = SPPTV_KEEP; | |
1396 | cb->s_force = 1 + SPPTV_KEEP; | |
1397 | /* | |
1398 | * Other party is required to respond to | |
1399 | * the port I send from, but he is not | |
1400 | * required to answer from where I am sending to, | |
1401 | * so allow wildcarding. | |
1402 | * original port I am sending to is still saved in | |
1403 | * cb->s_dport. | |
1404 | */ | |
1405 | nsp->nsp_fport = 0; | |
1406 | error = spp_output(cb, (struct mbuf *) 0); | |
1407 | break; | |
1408 | ||
1409 | case PRU_CONNECT2: | |
1410 | error = EOPNOTSUPP; | |
1411 | break; | |
1412 | ||
1413 | /* | |
1414 | * We may decide later to implement connection closing | |
1415 | * handshaking at the spp level optionally. | |
1416 | * here is the hook to do it: | |
1417 | */ | |
1418 | case PRU_DISCONNECT: | |
1419 | cb = spp_disconnect(cb); | |
1420 | break; | |
1421 | ||
1422 | /* | |
1423 | * Accept a connection. Essentially all the work is | |
1424 | * done at higher levels; just return the address | |
1425 | * of the peer, storing through addr. | |
1426 | */ | |
1427 | case PRU_ACCEPT: { | |
1428 | struct sockaddr_ns *sns = mtod(nam, struct sockaddr_ns *); | |
1429 | ||
1430 | nam->m_len = sizeof (struct sockaddr_ns); | |
1431 | sns->sns_family = AF_NS; | |
1432 | sns->sns_addr = nsp->nsp_faddr; | |
1433 | break; | |
1434 | } | |
1435 | ||
1436 | case PRU_SHUTDOWN: | |
1437 | socantsendmore(so); | |
1438 | cb = spp_usrclosed(cb); | |
1439 | if (cb) | |
1440 | error = spp_output(cb, (struct mbuf *) 0); | |
1441 | break; | |
1442 | ||
1443 | /* | |
1444 | * After a receive, possibly send acknowledgment | |
1445 | * updating allocation. | |
1446 | */ | |
1447 | case PRU_RCVD: | |
1448 | cb->s_flags |= SF_RVD; | |
1449 | (void) spp_output(cb, (struct mbuf *) 0); | |
1450 | cb->s_flags &= ~SF_RVD; | |
1451 | break; | |
1452 | ||
1453 | case PRU_ABORT: | |
1454 | (void) spp_drop(cb, ECONNABORTED); | |
1455 | break; | |
1456 | ||
1457 | case PRU_SENSE: | |
1458 | case PRU_CONTROL: | |
1459 | m = NULL; | |
1460 | error = EOPNOTSUPP; | |
1461 | break; | |
1462 | ||
1463 | case PRU_RCVOOB: | |
1464 | if ((cb->s_oobflags & SF_IOOB) || so->so_oobmark || | |
1465 | (so->so_state & SS_RCVATMARK)) { | |
1466 | m->m_len = 1; | |
1467 | *mtod(m, caddr_t) = cb->s_iobc; | |
1468 | break; | |
1469 | } | |
1470 | error = EINVAL; | |
1471 | break; | |
1472 | ||
1473 | case PRU_SENDOOB: | |
1474 | if (sbspace(&so->so_snd) < -512) { | |
1475 | error = ENOBUFS; | |
1476 | break; | |
1477 | } | |
1478 | cb->s_oobflags |= SF_SOOB; | |
1479 | /* fall into */ | |
1480 | case PRU_SEND: | |
1481 | if (controlp) { | |
1482 | u_short *p = mtod(controlp, u_short *); | |
1483 | spp_newchecks[2]++; | |
1484 | if ((p[0] == 5) && p[1] == 1) { /* XXXX, for testing */ | |
1485 | cb->s_shdr.sp_dt = *(u_char *)(&p[2]); | |
1486 | spp_newchecks[3]++; | |
1487 | } | |
1488 | m_freem(controlp); | |
1489 | } | |
1490 | controlp = NULL; | |
1491 | error = spp_output(cb, m); | |
1492 | m = NULL; | |
1493 | break; | |
1494 | ||
1495 | case PRU_SOCKADDR: | |
1496 | ns_setsockaddr(nsp, nam); | |
1497 | break; | |
1498 | ||
1499 | case PRU_PEERADDR: | |
1500 | ns_setpeeraddr(nsp, nam); | |
1501 | break; | |
1502 | ||
1503 | case PRU_SLOWTIMO: | |
1504 | cb = spp_timers(cb, (int)nam); | |
1505 | req |= ((int)nam) << 8; | |
1506 | break; | |
1507 | ||
1508 | case PRU_FASTTIMO: | |
1509 | case PRU_PROTORCV: | |
1510 | case PRU_PROTOSEND: | |
1511 | error = EOPNOTSUPP; | |
1512 | break; | |
1513 | ||
1514 | default: | |
1515 | panic("sp_usrreq"); | |
1516 | } | |
1517 | if (cb && (so->so_options & SO_DEBUG || traceallspps)) | |
1518 | spp_trace(SA_USER, (u_char)ostate, cb, (struct spidp *)0, req); | |
1519 | release: | |
1520 | if (controlp != NULL) | |
1521 | m_freem(controlp); | |
1522 | if (m != NULL) | |
1523 | m_freem(m); | |
1524 | splx(s); | |
1525 | return (error); | |
1526 | } | |
1527 | ||
4c45483e | 1528 | int |
fde1aeb2 | 1529 | spp_usrreq_sp(so, req, m, nam, controlp, dummy) |
15637ed4 RG |
1530 | struct socket *so; |
1531 | int req; | |
1532 | struct mbuf *m, *nam, *controlp; | |
fde1aeb2 | 1533 | struct mbuf *dummy; |
15637ed4 | 1534 | { |
fde1aeb2 | 1535 | int error = spp_usrreq(so, req, m, nam, controlp, dummy); |
15637ed4 RG |
1536 | |
1537 | if (req == PRU_ATTACH && error == 0) { | |
1538 | struct nspcb *nsp = sotonspcb(so); | |
1539 | ((struct sppcb *)nsp->nsp_pcb)->s_flags |= | |
1540 | (SF_HI | SF_HO | SF_PI); | |
1541 | } | |
1542 | return (error); | |
1543 | } | |
1544 | ||
1545 | /* | |
1546 | * Create template to be used to send spp packets on a connection. | |
1547 | * Called after host entry created, fills | |
1548 | * in a skeletal spp header (choosing connection id), | |
1549 | * minimizing the amount of work necessary when the connection is used. | |
1550 | */ | |
4c45483e | 1551 | static void |
15637ed4 RG |
1552 | spp_template(cb) |
1553 | register struct sppcb *cb; | |
1554 | { | |
1555 | register struct nspcb *nsp = cb->s_nspcb; | |
1556 | register struct idp *idp = cb->s_idp; | |
1557 | register struct sockbuf *sb = &(nsp->nsp_socket->so_snd); | |
1558 | ||
1559 | idp->idp_pt = NSPROTO_SPP; | |
1560 | idp->idp_sna = nsp->nsp_laddr; | |
1561 | idp->idp_dna = nsp->nsp_faddr; | |
1562 | cb->s_sid = htons(spp_iss); | |
1563 | spp_iss += SPP_ISSINCR/2; | |
1564 | cb->s_alo = 1; | |
1565 | cb->s_cwnd = (sbspace(sb) * CUNIT) / cb->s_mtu; | |
1566 | cb->s_ssthresh = cb->s_cwnd; /* Try to expand fast to full complement | |
1567 | of large packets */ | |
1568 | cb->s_cwmx = (sbspace(sb) * CUNIT) / (2 * sizeof(struct spidp)); | |
1569 | cb->s_cwmx = max(cb->s_cwmx, cb->s_cwnd); | |
1570 | /* But allow for lots of little packets as well */ | |
1571 | } | |
1572 | ||
1573 | /* | |
1574 | * Close a SPIP control block: | |
1575 | * discard spp control block itself | |
1576 | * discard ns protocol control block | |
1577 | * wake up any sleepers | |
1578 | */ | |
1579 | struct sppcb * | |
1580 | spp_close(cb) | |
1581 | register struct sppcb *cb; | |
1582 | { | |
1583 | register struct spidp_q *s; | |
1584 | struct nspcb *nsp = cb->s_nspcb; | |
1585 | struct socket *so = nsp->nsp_socket; | |
1586 | register struct mbuf *m; | |
1587 | ||
1588 | s = cb->s_q.si_next; | |
1589 | while (s != &(cb->s_q)) { | |
1590 | s = s->si_next; | |
1591 | m = dtom(s->si_prev); | |
1592 | remque(s->si_prev); | |
1593 | m_freem(m); | |
1594 | } | |
1595 | (void) m_free(dtom(cb->s_idp)); | |
1596 | (void) m_free(dtom(cb)); | |
1597 | nsp->nsp_pcb = 0; | |
1598 | soisdisconnected(so); | |
1599 | ns_pcbdetach(nsp); | |
1600 | sppstat.spps_closed++; | |
1601 | return ((struct sppcb *)0); | |
1602 | } | |
1603 | /* | |
1604 | * Someday we may do level 3 handshaking | |
1605 | * to close a connection or send a xerox style error. | |
1606 | * For now, just close. | |
1607 | */ | |
1608 | struct sppcb * | |
1609 | spp_usrclosed(cb) | |
1610 | register struct sppcb *cb; | |
1611 | { | |
1612 | return (spp_close(cb)); | |
1613 | } | |
1614 | struct sppcb * | |
1615 | spp_disconnect(cb) | |
1616 | register struct sppcb *cb; | |
1617 | { | |
1618 | return (spp_close(cb)); | |
1619 | } | |
1620 | /* | |
1621 | * Drop connection, reporting | |
1622 | * the specified error. | |
1623 | */ | |
1624 | struct sppcb * | |
1625 | spp_drop(cb, errno) | |
1626 | register struct sppcb *cb; | |
1627 | int errno; | |
1628 | { | |
1629 | struct socket *so = cb->s_nspcb->nsp_socket; | |
1630 | ||
1631 | /* | |
1632 | * someday, in the xerox world | |
1633 | * we will generate error protocol packets | |
1634 | * announcing that the socket has gone away. | |
1635 | */ | |
1636 | if (TCPS_HAVERCVDSYN(cb->s_state)) { | |
1637 | sppstat.spps_drops++; | |
1638 | cb->s_state = TCPS_CLOSED; | |
1639 | /*(void) tcp_output(cb);*/ | |
1640 | } else | |
1641 | sppstat.spps_conndrops++; | |
1642 | so->so_error = errno; | |
1643 | return (spp_close(cb)); | |
1644 | } | |
1645 | ||
4c45483e | 1646 | static void |
fde1aeb2 | 1647 | spp_abort(nsp, errno) |
15637ed4 | 1648 | struct nspcb *nsp; |
fde1aeb2 | 1649 | int errno; |
15637ed4 RG |
1650 | { |
1651 | ||
1652 | (void) spp_close((struct sppcb *)nsp->nsp_pcb); | |
1653 | } | |
1654 | ||
1655 | int spp_backoff[SPP_MAXRXTSHIFT+1] = | |
1656 | { 1, 2, 4, 8, 16, 32, 64, 64, 64, 64, 64, 64, 64 }; | |
1657 | /* | |
1658 | * Fast timeout routine for processing delayed acks | |
1659 | */ | |
4c45483e | 1660 | void |
15637ed4 RG |
1661 | spp_fasttimo() |
1662 | { | |
1663 | register struct nspcb *nsp; | |
1664 | register struct sppcb *cb; | |
1665 | int s = splnet(); | |
1666 | ||
1667 | nsp = nspcb.nsp_next; | |
1668 | if (nsp) | |
1669 | for (; nsp != &nspcb; nsp = nsp->nsp_next) | |
1670 | if ((cb = (struct sppcb *)nsp->nsp_pcb) && | |
1671 | (cb->s_flags & SF_DELACK)) { | |
1672 | cb->s_flags &= ~SF_DELACK; | |
1673 | cb->s_flags |= SF_ACKNOW; | |
1674 | sppstat.spps_delack++; | |
1675 | (void) spp_output(cb, (struct mbuf *) 0); | |
1676 | } | |
1677 | splx(s); | |
1678 | } | |
1679 | ||
1680 | /* | |
1681 | * spp protocol timeout routine called every 500 ms. | |
1682 | * Updates the timers in all active pcb's and | |
1683 | * causes finite state machine actions if timers expire. | |
1684 | */ | |
4c45483e | 1685 | void |
15637ed4 RG |
1686 | spp_slowtimo() |
1687 | { | |
1688 | register struct nspcb *ip, *ipnxt; | |
1689 | register struct sppcb *cb; | |
1690 | int s = splnet(); | |
1691 | register int i; | |
1692 | ||
1693 | /* | |
1694 | * Search through tcb's and update active timers. | |
1695 | */ | |
1696 | ip = nspcb.nsp_next; | |
1697 | if (ip == 0) { | |
1698 | splx(s); | |
1699 | return; | |
1700 | } | |
1701 | while (ip != &nspcb) { | |
1702 | cb = nstosppcb(ip); | |
1703 | ipnxt = ip->nsp_next; | |
1704 | if (cb == 0) | |
1705 | goto tpgone; | |
1706 | for (i = 0; i < SPPT_NTIMERS; i++) { | |
1707 | if (cb->s_timer[i] && --cb->s_timer[i] == 0) { | |
1708 | (void) spp_usrreq(cb->s_nspcb->nsp_socket, | |
fde1aeb2 GW |
1709 | PRU_SLOWTIMO, |
1710 | (struct mbuf *)0, | |
1711 | (struct mbuf *)i, | |
1712 | (struct mbuf *)0, | |
1713 | (struct mbuf *)0); | |
15637ed4 RG |
1714 | if (ipnxt->nsp_prev != ip) |
1715 | goto tpgone; | |
1716 | } | |
1717 | } | |
1718 | cb->s_idle++; | |
1719 | if (cb->s_rtt) | |
1720 | cb->s_rtt++; | |
1721 | tpgone: | |
1722 | ip = ipnxt; | |
1723 | } | |
1724 | spp_iss += SPP_ISSINCR/PR_SLOWHZ; /* increment iss */ | |
1725 | splx(s); | |
1726 | } | |
1727 | /* | |
1728 | * SPP timer processing. | |
1729 | */ | |
1730 | struct sppcb * | |
1731 | spp_timers(cb, timer) | |
1732 | register struct sppcb *cb; | |
1733 | int timer; | |
1734 | { | |
1735 | long rexmt; | |
1736 | int win; | |
1737 | ||
1738 | cb->s_force = 1 + timer; | |
1739 | switch (timer) { | |
1740 | ||
1741 | /* | |
1742 | * 2 MSL timeout in shutdown went off. TCP deletes connection | |
1743 | * control block. | |
1744 | */ | |
1745 | case SPPT_2MSL: | |
1746 | printf("spp: SPPT_2MSL went off for no reason\n"); | |
1747 | cb->s_timer[timer] = 0; | |
1748 | break; | |
1749 | ||
1750 | /* | |
1751 | * Retransmission timer went off. Message has not | |
1752 | * been acked within retransmit interval. Back off | |
1753 | * to a longer retransmit interval and retransmit one packet. | |
1754 | */ | |
1755 | case SPPT_REXMT: | |
1756 | if (++cb->s_rxtshift > SPP_MAXRXTSHIFT) { | |
1757 | cb->s_rxtshift = SPP_MAXRXTSHIFT; | |
1758 | sppstat.spps_timeoutdrop++; | |
1759 | cb = spp_drop(cb, ETIMEDOUT); | |
1760 | break; | |
1761 | } | |
1762 | sppstat.spps_rexmttimeo++; | |
1763 | rexmt = ((cb->s_srtt >> 2) + cb->s_rttvar) >> 1; | |
1764 | rexmt *= spp_backoff[cb->s_rxtshift]; | |
1765 | SPPT_RANGESET(cb->s_rxtcur, rexmt, SPPTV_MIN, SPPTV_REXMTMAX); | |
1766 | cb->s_timer[SPPT_REXMT] = cb->s_rxtcur; | |
1767 | /* | |
1768 | * If we have backed off fairly far, our srtt | |
1769 | * estimate is probably bogus. Clobber it | |
1770 | * so we'll take the next rtt measurement as our srtt; | |
1771 | * move the current srtt into rttvar to keep the current | |
1772 | * retransmit times until then. | |
1773 | */ | |
1774 | if (cb->s_rxtshift > SPP_MAXRXTSHIFT / 4 ) { | |
1775 | cb->s_rttvar += (cb->s_srtt >> 2); | |
1776 | cb->s_srtt = 0; | |
1777 | } | |
1778 | cb->s_snxt = cb->s_rack; | |
1779 | /* | |
1780 | * If timing a packet, stop the timer. | |
1781 | */ | |
1782 | cb->s_rtt = 0; | |
1783 | /* | |
1784 | * See very long discussion in tcp_timer.c about congestion | |
1785 | * window and sstrhesh | |
1786 | */ | |
1787 | win = min(cb->s_swnd, (cb->s_cwnd/CUNIT)) / 2; | |
1788 | if (win < 2) | |
1789 | win = 2; | |
1790 | cb->s_cwnd = CUNIT; | |
1791 | cb->s_ssthresh = win * CUNIT; | |
1792 | (void) spp_output(cb, (struct mbuf *) 0); | |
1793 | break; | |
1794 | ||
1795 | /* | |
1796 | * Persistance timer into zero window. | |
1797 | * Force a probe to be sent. | |
1798 | */ | |
1799 | case SPPT_PERSIST: | |
1800 | sppstat.spps_persisttimeo++; | |
1801 | spp_setpersist(cb); | |
1802 | (void) spp_output(cb, (struct mbuf *) 0); | |
1803 | break; | |
1804 | ||
1805 | /* | |
1806 | * Keep-alive timer went off; send something | |
1807 | * or drop connection if idle for too long. | |
1808 | */ | |
1809 | case SPPT_KEEP: | |
1810 | sppstat.spps_keeptimeo++; | |
1811 | if (cb->s_state < TCPS_ESTABLISHED) | |
1812 | goto dropit; | |
1813 | if (cb->s_nspcb->nsp_socket->so_options & SO_KEEPALIVE) { | |
1814 | if (cb->s_idle >= SPPTV_MAXIDLE) | |
1815 | goto dropit; | |
1816 | sppstat.spps_keepprobe++; | |
1817 | (void) spp_output(cb, (struct mbuf *) 0); | |
1818 | } else | |
1819 | cb->s_idle = 0; | |
1820 | cb->s_timer[SPPT_KEEP] = SPPTV_KEEP; | |
1821 | break; | |
1822 | dropit: | |
1823 | sppstat.spps_keepdrops++; | |
1824 | cb = spp_drop(cb, ETIMEDOUT); | |
1825 | break; | |
1826 | } | |
1827 | return (cb); | |
1828 | } | |
fde1aeb2 | 1829 | #if 0 |
15637ed4 RG |
1830 | int SppcbSize = sizeof (struct sppcb); |
1831 | int NspcbSize = sizeof (struct nspcb); | |
fde1aeb2 | 1832 | #endif |