/*
* INET An implementation of the TCP/IP protocol suite for the LINUX
* operating system. INET is implemented using the BSD Socket
* interface as the means of communication with the user level.
*
* Implementation of the Transmission Control Protocol(TCP).
*
* Version: @(#)tcp.c 1.0.16 05/25/93
*
* Authors: Ross Biro, <bir7@leland.Stanford.Edu>
* Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
* Mark Evans, <evansmp@uhura.aston.ac.uk>
* Corey Minyard <wf-rch!minyard@relay.EU.net>
* Florian La Roche, <flla@stud.uni-sb.de>
*
* Fixes:
* Alan Cox : Numerous verify_area() calls
* Alan Cox : Set the ACK bit on a reset
* Alan Cox : Stopped it crashing if it closed while sk->inuse=1
* and was trying to connect (tcp_err()).
* Alan Cox : All icmp error handling was broken
* pointers passed where wrong and the
* socket was looked up backwards. Nobody
* tested any icmp error code obviously.
* Alan Cox : tcp_err() now handled properly. It wakes people
* on errors. select behaves and the icmp error race
* has gone by moving it into sock.c
* Alan Cox : tcp_reset() fixed to work for everything not just
* packets for unknown sockets.
* Alan Cox : tcp option processing.
* Alan Cox : Reset tweaked (still not 100%) [Had syn rule wrong]
* Herp Rosmanith : More reset fixes
* Alan Cox : No longer acks invalid rst frames. Acking
* any kind of RST is right out.
* Alan Cox : Sets an ignore me flag on an rst receive
* otherwise odd bits of prattle escape still
* Alan Cox : Fixed another acking RST frame bug. Should stop
* LAN workplace lockups.
* Alan Cox : Some tidyups using the new skb list facilities
* Alan Cox : sk->keepopen now seems to work
* Alan Cox : Pulls options out correctly on accepts
* Alan Cox : Fixed assorted sk->rqueue->next errors
* Alan Cox : PSH doesn't end a TCP read. Switched a bit to skb ops.
* Alan Cox : Tidied tcp_data to avoid a potential nasty.
* Alan Cox : Added some beter commenting, as the tcp is hard to follow
* Alan Cox : Removed incorrect check for 20 * psh
* Michael O'Reilly : ack < copied bug fix.
* Johannes Stille : Misc tcp fixes (not all in yet).
* Alan Cox : FIN with no memory -> CRASH
* Alan Cox : Added socket option proto entries. Also added awareness of them to accept.
* Alan Cox : Added TCP options (SOL_TCP)
* Alan Cox : Switched wakeup calls to callbacks, so the kernel can layer network sockets.
* Alan Cox : Use ip_tos/ip_ttl settings.
* Alan Cox : Handle FIN (more) properly (we hope).
* Alan Cox : RST frames sent on unsynchronised state ack error/
* Alan Cox : Put in missing check for SYN bit.
* Alan Cox : Added tcp_select_window() aka NET2E
* window non shrink trick.
* Alan Cox : Added a couple of small NET2E timer fixes
* Charles Hedrick : TCP fixes
* Toomas Tamm : TCP window fixes
* Alan Cox : Small URG fix to rlogin ^C ack fight
* Charles Hedrick : Window fix
* Linus : Rewrote tcp_read() and URG handling
* completely
*
*
* To Fix:
* Possibly a problem with accept(). BSD accept never fails after
* it causes a select. Linux can - given the official select semantics I
* feel that _really_ its the BSD network programs that are bust (notably
* inetd, which hangs occasionally because of this).
* Add VJ Fastrecovery algorithm ?
* Protocol closedown badly messed up.
* Incompatiblity with spider ports (tcp hangs on that
* socket occasionally).
* MSG_PEEK and read on same socket at once can cause crashes.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or(at your option) any later version.
*/
#include <linux/types.h>
#include <linux/sched.h>
#include <linux/mm.h>
#include <linux/string.h>
#include <linux/socket.h>
#include <linux/sockios.h>
#include <linux/termios.h>
#include <linux/in.h>
#include <linux/fcntl.h>
#include "inet.h"
#include "dev.h"
#include "ip.h"
#include "protocol.h"
#include "icmp.h"
#include "tcp.h"
#include "skbuff.h"
#include "sock.h"
#include "arp.h"
#include <linux/errno.h>
#include <linux/timer.h>
#include <asm/system.h>
#include <asm/segment.h>
#include <linux/mm.h>
#define SEQ_TICK 3
unsigned long seq_offset;
#define SUBNETSARELOCAL
static __inline__ int
min(unsigned int a, unsigned int b)
{
if (a < b) return(a);
return(b);
}
static void __print_th(struct tcphdr *th)
{
unsigned char *ptr;
printk("TCP header:\n");
printk(" source=%d, dest=%d, seq =%ld, ack_seq = %ld\n",
ntohs(th->source), ntohs(th->dest),
ntohl(th->seq), ntohl(th->ack_seq));
printk(" fin=%d, syn=%d, rst=%d, psh=%d, ack=%d, urg=%d res1=%d res2=%d\n",
th->fin, th->syn, th->rst, th->psh, th->ack,
th->urg, th->res1, th->res2);
printk(" window = %d, check = %d urg_ptr = %d\n",
ntohs(th->window), ntohs(th->check), ntohs(th->urg_ptr));
printk(" doff = %d\n", th->doff);
ptr =(unsigned char *)(th + 1);
printk(" options = %d %d %d %d\n", ptr[0], ptr[1], ptr[2], ptr[3]);
}
static inline void print_th(struct tcphdr *th)
{
if (inet_debug == DBG_TCP)
__print_th(th);
}
/* This routine grabs the first thing off of a rcv queue. */
static struct sk_buff *
get_firstr(struct sock *sk)
{
return skb_dequeue(&sk->rqueue);
}
/*
* Difference between two values in tcp ack terms.
*/
static long
diff(unsigned long seq1, unsigned long seq2)
{
long d;
d = seq1 - seq2;
if (d > 0) return(d);
/* I hope this returns what I want. */
return(~d+1);
}
/* This routine picks a TCP windows for a socket based on
the following constraints
1. The window can never be shrunk once it is offered (RFC 793)
2. We limit memory per socket
For now we use NET2E3's heuristic of offering half the memory
we have handy. All is not as bad as this seems however because
of two things. Firstly we will bin packets even within the window
in order to get the data we are waiting for into the memory limit.
Secondly we bin common duplicate forms at receive time
Better heuristics welcome
*/
static int tcp_select_window(struct sock *sk)
{
int new_window = sk->prot->rspace(sk);
/*
* two things are going on here. First, we don't ever offer a
* window less than min(sk->mss, MAX_WINDOW/2). This is the
* receiver side of SWS as specified in RFC1122.
* Second, we always give them at least the window they
* had before, in order to avoid retracting window. This
* is technically allowed, but RFC1122 advises against it and
* in practice it causes trouble.
*/
if (new_window < min(sk->mss, MAX_WINDOW/2) ||
new_window < sk->window)
return(sk->window);
return(new_window);
}
/* Enter the time wait state. */
static void tcp_time_wait(struct sock *sk)
{
sk->state = TCP_TIME_WAIT;
sk->shutdown = SHUTDOWN_MASK;
if (!sk->dead)
sk->state_change(sk);
reset_timer(sk, TIME_CLOSE, TCP_TIMEWAIT_LEN);
}
/*
* A timer event has trigger a tcp retransmit timeout. The
* socket xmit queue is ready and set up to send. Because
* the ack receive code keeps the queue straight we do
* nothing clever here.
*/
static void
tcp_retransmit(struct sock *sk, int all)
{
if (all) {
ip_retransmit(sk, all);
return;
}
sk->ssthresh = sk->cong_window >> 1; /* remember window where we lost */
/* sk->ssthresh in theory can be zero. I guess that's OK */
sk->cong_count = 0;
sk->cong_window = 1;
/* Do the actual retransmit. */
ip_retransmit(sk, all);
}
/*
* This routine is called by the ICMP module when it gets some
* sort of error condition. If err < 0 then the socket should
* be closed and the error ret
没有合适的资源?快使用搜索试试~ 我知道了~
LINUX 1.zip
共561个文件
c:282个
h:205个
makefile:28个
需积分: 10 0 下载量 117 浏览量
2008-11-03
18:51:37
上传
评论
收藏 1.49MB ZIP 举报
温馨提示
* linux/boot/head.S * * Copyright (C) 1991, 1992 Linus Torvalds */ /* * head.S contains the 32-bit startup code. */ .text .globl _idt,_gdt, .globl _swapper_pg_dir,_pg0 .globl _empty_bad_page .globl _empty_bad_page_table .globl _empty_zero_page .globl _tmp_floppy_area,_floppy_track_buffer
资源详情
资源评论
资源推荐
收起资源包目录
LINUX 1.zip (561个子文件)
.blurb 458B
tcp.c 96KB
sbpcd.c 83KB
tpqic02.c 81KB
NCR5380.c 77KB
gus_wave.c 74KB
aha152x.c 65KB
serial.c 55KB
cdu31a.c 52KB
console.c 50KB
tty_io.c 48KB
fdomain.c 47KB
scsi.c 46KB
sock.c 43KB
seagate.c 43KB
depca.c 43KB
ip.c 42KB
fpu_trig.c 42KB
hpfs_fs.c 41KB
st.c 40KB
reg_ld_str.c 38KB
floppy.c 36KB
eexpress.c 33KB
ultrastor.c 33KB
memory.c 33KB
slip.c 29KB
socket.c 29KB
3c507.c 29KB
sd.c 28KB
namei.c 28KB
lance.c 27KB
aha1542.c 27KB
arp.c 26KB
mcd.c 26KB
atp.c 25KB
buffer.c 25KB
sock.c 25KB
dev.c 25KB
8390.c 25KB
opl3.c 24KB
exec.c 24KB
sequencer.c 24KB
xd.c 24KB
inode.c 23KB
plip.c 23KB
namei.c 23KB
namei.c 23KB
sr.c 23KB
inflate.c 22KB
sched.c 22KB
binfmt_coff.c 22KB
keyboard.c 21KB
proc.c 21KB
d_link.c 21KB
swap.c 21KB
constants.c 20KB
dmabuf.c 20KB
defkeymap.c 20KB
namei.c 20KB
super.c 20KB
inode.c 19KB
3c509.c 19KB
namei.c 19KB
fpu_entry.c 19KB
slhc.c 19KB
at1700.c 19KB
balloc.c 19KB
sys.c 19KB
shm.c 19KB
hd.c 18KB
binfmt_elf.c 18KB
tty_ioctl.c 17KB
inode.c 17KB
errors.c 17KB
ialloc.c 16KB
malloc.c 16KB
dir.c 16KB
wd7000.c 16KB
configure.c 16KB
sb_dsp.c 16KB
namei.c 16KB
namei.c 15KB
udp.c 15KB
3c501.c 15KB
aha1740.c 15KB
pas2_mixer.c 15KB
vt.c 15KB
exit.c 15KB
scsi_debug.c 15KB
inode.c 14KB
skeleton.c 14KB
sb16_dsp.c 14KB
ne.c 14KB
main.c 14KB
misc.c 14KB
3c503.c 14KB
pas16.c 14KB
psaux.c 14KB
inode.c 14KB
rock.c 13KB
共 561 条
- 1
- 2
- 3
- 4
- 5
- 6
lp536
- 粉丝: 0
- 资源: 7
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0