Chinaunix首页 | 论坛 | 博客
  • 博客访问: 154472
  • 博文数量: 41
  • 博客积分: 2500
  • 博客等级: 少校
  • 技术积分: 425
  • 用 户 组: 普通用户
  • 注册时间: 2009-07-14 10:16
文章分类
文章存档

2011年(1)

2010年(5)

2009年(35)

我的朋友

分类: LINUX

2009-09-27 11:17:53

Linux1.2.13内核的sock结构

978计划工作组 2009-9-27

1函数源码

/*

 * This structure really needs to be cleaned up.

 * Most of it is for TCP, and not used by any of

 * the other protocols.

 */

struct sock {

  struct options            *opt;

  volatile unsigned long wmem_alloc;

  volatile unsigned long rmem_alloc;

  unsigned long                   write_seq;

  unsigned long                   sent_seq;

  unsigned long                   acked_seq;

  unsigned long                   copied_seq;

  unsigned long                   rcv_ack_seq;

  unsigned long                   window_seq;

  unsigned long                   fin_seq;

  unsigned long                   urg_seq;

  unsigned long                   urg_data;

 

  /*

   * Not all are volatile, but some are, so we

   * might as well say they all are.

   */

  volatile char                 inuse,

                            dead,

                            urginline,

                            intr,

                            blog,

                            done,

                            reuse,

                            keepopen,

                            linger,

                            delay_acks,

                            destroy,

                            ack_timed,

                            no_check,

                            zapped,   /* In ax25 & ipx means not linked */

                            broadcast,

                            nonagle;

  unsigned long                    lingertime;

  int                            proc;

  struct sock                *next;

  struct sock                *prev; /* Doubly linked chain.. */

  struct sock                *pair;

  struct sk_buff           * volatile send_head;

  struct sk_buff           * volatile send_tail;

  struct sk_buff_head          back_log;

  struct sk_buff           *partial;

  struct timer_list         partial_timer;

  long                          retransmits;

  struct sk_buff_head          write_queue,

                            receive_queue;

  struct proto               *prot;

  struct wait_queue             **sleep;

  unsigned long                   daddr;

  unsigned long                   saddr;

  unsigned short           max_unacked;

  unsigned short           window;

  unsigned short           bytes_rcv;

/* mss is min(mtu, max_window) */

  unsigned short           mtu;       /* mss negotiated in the syn's */

  volatile unsigned short       mss;       /* current eff. mss - can change */

  volatile unsigned short       user_mss;  /* mss requested by user in ioctl */

  volatile unsigned short       max_window;

  unsigned long           window_clamp;

  unsigned short           num;

  volatile unsigned short       cong_window;

  volatile unsigned short       cong_count;

  volatile unsigned short       ssthresh;

  volatile unsigned short       packets_out;

  volatile unsigned short       shutdown;

  volatile unsigned long rtt;

  volatile unsigned long mdev;

  volatile unsigned long rto;

/* currently backoff isn't used, but I'm maintaining it in case

 * we want to go back to a backoff formula that needs it

 */

  volatile unsigned short       backoff;

  volatile short              err;

  unsigned char                   protocol;

  volatile unsigned char state;

  volatile unsigned char ack_backlog;

  unsigned char                   max_ack_backlog;

  unsigned char                   priority;

  unsigned char                   debug;

  unsigned short           rcvbuf;

  unsigned short           sndbuf;

  unsigned short           type;

  unsigned char                   localroute;      /* Route locally only */

#ifdef CONFIG_IPX

  ipx_address               ipx_dest_addr;

  ipx_interface                    *ipx_intrfc;

  unsigned short           ipx_port;

  unsigned short           ipx_type;

#endif#ifdef CONFIG_AX25

/* Really we want to add a per protocol private area */

  ax25_address                   ax25_source_addr,ax25_dest_addr;

  struct sk_buff *volatile      ax25_retxq[8];

  char                         ax25_state,ax25_vs,ax25_vr,ax25_lastrxnr,ax25_lasttxnr;

  char                         ax25_condition;

  char                         ax25_retxcnt;

  char                         ax25_xx;

  char                         ax25_retxqi;

  char                         ax25_rrtimer;

  char                         ax25_timer;

  unsigned char                   ax25_n2;

  unsigned short           ax25_t1,ax25_t2,ax25_t3;

  ax25_digi                  *ax25_digipeat;

#endif  

#ifdef CONFIG_ATALK

  struct atalk_sock              at;

#endif

/* IP 'private area' or will be eventually */

  int                            ip_ttl;             /* TTL setting */

  int                            ip_tos;            /* TOS */

  struct tcphdr                    dummy_th;

  struct timer_list         keepalive_timer;     /* TCP keepalive hack */

  struct timer_list         retransmit_timer;    /* TCP retransmit timer */

  struct timer_list         ack_timer;             /* TCP delayed ack timer */

  int                            ip_xmit_timeout;    /* Why the timeout is running */

#ifdef CONFIG_IP_MULTICAST 

  int                            ip_mc_ttl;                     /* Multicasting TTL */

  int                            ip_mc_loop;                  /* Loopback (not implemented yet) */

  char                         ip_mc_name[MAX_ADDR_LEN];       /* Multicast device name */

  struct ip_mc_socklist        *ip_mc_list;                  /* Group array */

#endif  

 

  /* This part is used for the timeout functions (timer.c). */

  int                            timeout;   /* What are we waiting for? */

  struct timer_list         timer;             /* This is the TIME_WAIT/receive timer when we are doing IP */

  struct timeval            stamp;

 

  /* identd */

  struct socket                    *socket;

 

  /* Callbacks */

  void                          (*state_change)(struct sock *sk);

  void                          (*data_ready)(struct sock *sk,int bytes);

  void                          (*write_space)(struct sock *sk);

  void                          (*error_report)(struct sock *sk);

 

};

2结构用途

TCP协议的核心结构,只应用于TCP协议。

3语句注释

3.1 成员注释

optIP选项缓存于此处。

wmem_alloc当前写缓冲区大小,该值不可大于系统规定的最大值。

rmem_alloc当前读缓冲区大小,该值不可大于系统规定最大值。

write_seq表示应用程序下一次写数据时所对应的第一个字节的序列号,write_queue队列的序列号

sent_seq表示本地将要发送的下一个数据包中第一个字节对应的序列号。

acked_seq表示本地希望从远端接收的下一个数据的序列号。

copied_seq应用程序有待读取但尚未读取的数据的第一个字节的序列号。

rcv_ack_seq表示目前本地接收到的远端对本地发送数据的应答序列号,表示本地已经发送的小于此序列号的所有数据已被远端成功接收。

window_seqsent_seq值加上远端窗口的大小,本地将要发送的数据包的最后一个字节的序列号不可大于此值。

其他域说明在以后不断补上

阅读(1974) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~