linux网络设备驱动 (四)

/** include/linux/net.h
 *  struct socket - general BSD socket
 *  @state: socket state (%SS_CONNECTED, etc)
 *  @type: socket type (%SOCK_STREAM, etc)
 *  @flags: socket flags (%SOCK_NOSPACE, etc)
 *  @ops: protocol specific socket operations
 *  @file: File back pointer for gc
 *  @sk: internal networking protocol agnostic socket representation
 *  @wq: wait queue for several uses
 */
struct socket {
    socket_state       state;
    short              type;
    unsigned long      flags;
    struct socket_wq   *wq;
    struct file        *file;
    struct sock        *sk;
    const struct proto_ops  *ops;
};

/* include/linux/net.h */
struct proto_ops {
    ...
}

/* include/net/sock.h */
struct tcp_sock {
    /* inet_connection_sock has to be the first member of tcp_sock */
    struct inet_connection_sock inet_conn;
    ...
}

struct inet_connection_sock {
    struct inet_sock icsk_inet;
    ...
}

/* include/net/inet_sock.h */
struct inet_sock {
    /* sk and pinet6 has to be the first two members of inet_sock */
    struct sock sk;
    ...
}

struct sock {
    struct sock_common __sk_common;
    ...
};

static inline struct sk_buff *tcp_send_head(const struct sock *sk)
{
	return sk->sk_send_head;
}

//未发送的数据是否已经超过最大窗口的一半了
static inline bool forced_push(const struct tcp_sock *tp)
{
	return after(tp->write_seq, tp->pushed_seq + (tp->max_window >> 1));
}

static inline bool before(__u32 seq1, __u32 seq2)
{
        return (__s32)(seq1-seq2) < 0;
}
#define after(seq2, seq1) 	before(seq1, seq2)



u32	write_seq;	/* Tail(+1) of data held in tcp send buffer */
u32	pushed_seq;	/* Last pushed seq, required to talk to windows */
int			sk_wmem_queued;  //
int			sk_sndbuf;   //


static int tcp_send_mss(struct sock *sk, int *size_goal, int flags)
{   
    mss_now = tcp_current_mss(sk);
    *size_goal = tcp_xmit_size_goal(sk, mss_now, !(flags & MSG_OOB));    
    return mss_now;
}



/* 如果发送队列的总大小(sk_wmem_queued)>= 发送缓存上限(sk_sndbuf)
 * 或者发送缓冲区中尚未发送的数据量,超过了用户的设置值,那么进入等待状态。
*/

static inline bool sk_stream_memory_free(const struct sock *sk)
{
    //这个是什么意思?
	if (sk->sk_wmem_queued >= sk->sk_sndbuf)
		return false;

	return sk->sk_prot->stream_memory_free ?
		sk->sk_prot->stream_memory_free(sk) : true;
}

ref:

sock.h - include/net/sock.h - Linux source code (v4.20.17) - Bootlin

Linux in Depth - 文件系统及 Socket 源码解析

[内核源码] 网络协议栈 - socket (tcp)

tcpcomment/tcp_ipv4.c at master · PerthCharles/tcpcomment · GitHub

[内核源码] 网络协议栈 - write (tcp) 发送数据

深入浅出TCP的MSS选项(3):TCP选项的影响 - 知乎

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值