TCP ECN源代码 [英] TCP ECN source code

查看:167
本文介绍了TCP ECN源代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在理解TCP的Linux源代码时遇到了问题(net/ipv4/tcp_input.c) 在include/net/tcp.h中,它已经定义了TCP_ECN_OK = 1,但实际上是什么意思

tp->ecn_flags & TCP_ECN_OK

此外,请在套接字,袜子,tcp_sock和sk_buff之间进行说明.

是否有任何参考资料可以解释得更详细或更清楚.

谢谢.

更新:

内核的联网部分主要使用两种数据结构:一种保留称为 sock (用于套接字")的连接状态,另一种保留数据和两者的状态称为 sk_buff 的传入和传出数据包(用于套接字缓存器").这两个部分都在本节中进行了描述.我们还包括tcp_opt的简要说明,tcp_opt是sock结构的一部分,用于维护TCP连接状态. (来自"Linux内核2.4.20中的网络代码映射" )

解决方案

TCP_ECN_OK是linuxkernel内部内部 include/net/tcp.h文件(来自Linux内核资源):

398 #define TCP_ECN_OK              1
399 #define TCP_ECN_QUEUE_CWR       2
400 #define TCP_ECN_DEMAND_CWR      4
401 #define TCP_ECN_SEEN            8

表达式tp->ecn_flags & TCP_ECN_OK是逻辑测试,是否仍设置TCP_ECN_OK.

更新:我认为打开tcp套接字时会设置TCP_ECN_OK位(如果sysctl的当前设置在Linux中启用了ECN支持),并且如果套接字的另一端也支持ECN,它将保持置位状态. /p>

如Wikipedia中所述 http://en.wikipedia.org/wiki/Explicit_Congestion_Notification

ECN是一项可选功能,仅在两个端点都支持并愿意使用时使用.

...跳至Linux部分

Linux内核通过sysctl接口通过/proc/sys/net/ipv4/tcp_ecn变量的值配置,支持TCP的ECN的三种工作模式:[11-1)时,我们将tcp头中的ECE位置1,并将TCP_ECN_OK设置为1. net/ipv4/tcp_output.c 315行

315 /* Packet ECN state for a SYN.  */
316 static inline void TCP_ECN_send_syn(struct sock *sk, struct sk_buff *skb)
....
320         tp->ecn_flags = 0;
321         if (sock_net(sk)->ipv4.sysctl_tcp_ecn == 1) {
322                 TCP_SKB_CB(skb)->tcp_flags |= TCPHDR_ECE | TCPHDR_CWR;
323                 tp->ecn_flags = TCP_ECN_OK;
324         }

稍后,如果连接的另一端不支持ECN或将其禁用,我们将取消设置TCP_ECN_OK标志. net/ipv4/tcp_input.c 246行

246 static inline void TCP_ECN_rcv_synack(struct tcp_sock *tp, const struct tcphdr *th)
247 {
248         if ((tp->ecn_flags & TCP_ECN_OK) && (!th->ece || th->cwr))
249                 tp->ecn_flags &= ~TCP_ECN_OK;
250 }

对于传入连接,我们取消设置TCP_ECN_OK,如果传入SYN中没有ECE tcp标头标志(请参阅 RFC3168"将显式拥塞通知(ECN)添加到IP " )

252 static inline void TCP_ECN_rcv_syn(struct tcp_sock *tp, const struct tcphdr *th)
253 {
254         if ((tp->ecn_flags & TCP_ECN_OK) && (!th->ece || !th->cwr))
255                 tp->ecn_flags &= ~TCP_ECN_OK;
256 }

I had problem understanding Linux Source Code of TCP (net/ipv4/tcp_input.c) in include/net/tcp.h it already defined TCP_ECN_OK = 1 but what really means

tp->ecn_flags & TCP_ECN_OK

Besides, please explain between socket, sock, tcp_sock, sk_buff.

Is there any references that explain more detailed or make it clearer.

Thank you.

Update:

The networking part of the kernel uses mainly two data structures: one to keep the state of a connection called sock (for "socket"), and another to keep the data and the status of both incoming and outgoing packets called sk_buff (for "socket buffer"). Both of them are described in this section. We also include a brief description of tcp_opt, a structure that is part of the sock structure and is used to maintain the TCP connection state. (from "A Map of the Networking Code in Linux Kernel 2.4.20")

解决方案

TCP_ECN_OK is bit flag from linuxkernel's internal struct tcp_sock as (field ecn_flags). There are several bitflags in it (include/net/tcp.h file from linux kernel sources):

398 #define TCP_ECN_OK              1
399 #define TCP_ECN_QUEUE_CWR       2
400 #define TCP_ECN_DEMAND_CWR      4
401 #define TCP_ECN_SEEN            8

Expression tp->ecn_flags & TCP_ECN_OK is the logic test, is the TCP_ECN_OK still set or not.

Update: I think that TCP_ECN_OK bit is set when the tcp socket is open (if the current settings of sysctl enables ECN support in Linux), and it will stay set if the other side of socket supports ECN too.

As said in wikipedia http://en.wikipedia.org/wiki/Explicit_Congestion_Notification

ECN is an optional feature that is only used when both endpoints support it and are willing to use it.

... skip to Linux section

The Linux kernel supports three working modes of the ECN for TCP, as configured by value of the /proc/sys/net/ipv4/tcp_ecn variable, through the sysctl interface:[11 - tcp_ecn in Documentation/networking/ip-sysctl.txt]

  • 0 – disable ECN and neither initiate nor accept it
  • 1 – enable ECN when requested by incoming connections, and also request ECN on outgoing connection attempts
  • 2 – enable ECN when requested by incoming connections, but do not request ECN on outgoing connections. // DEFAULT in 3.14 //

The default value is 2, meaning that by default ECN is enabled when requested by incoming connections, but it is not requested on outgoing connections. Anyway, ECN is used by the Linux kernel only when both ends of the TCP connection indicate support for it.[11]

For example, when we send SYN in beginning of outgoing socket connection, and sysctl tcp_ecn is enabled for outgoing connections ("sysctl_tcp_ecn" flag is 1), we set ECE bit in tcp header and set TCP_ECN_OK. net/ipv4/tcp_output.c Line 315

315 /* Packet ECN state for a SYN.  */
316 static inline void TCP_ECN_send_syn(struct sock *sk, struct sk_buff *skb)
....
320         tp->ecn_flags = 0;
321         if (sock_net(sk)->ipv4.sysctl_tcp_ecn == 1) {
322                 TCP_SKB_CB(skb)->tcp_flags |= TCPHDR_ECE | TCPHDR_CWR;
323                 tp->ecn_flags = TCP_ECN_OK;
324         }

Later, if the other side of connection have no support of ECN or it is disabled, we will unset TCP_ECN_OK flag. net/ipv4/tcp_input.c Line 246

246 static inline void TCP_ECN_rcv_synack(struct tcp_sock *tp, const struct tcphdr *th)
247 {
248         if ((tp->ecn_flags & TCP_ECN_OK) && (!th->ece || th->cwr))
249                 tp->ecn_flags &= ~TCP_ECN_OK;
250 }

For incoming connections, we unset TCP_ECN_OK, if in incoming SYN there was no ECE tcp header flag (read more about flags and ECN in RFC3168 "The Addition of Explicit Congestion Notification (ECN) to IP")

252 static inline void TCP_ECN_rcv_syn(struct tcp_sock *tp, const struct tcphdr *th)
253 {
254         if ((tp->ecn_flags & TCP_ECN_OK) && (!th->ece || !th->cwr))
255                 tp->ecn_flags &= ~TCP_ECN_OK;
256 }

这篇关于TCP ECN源代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆