Linux内核中的TCP/IP协议栈

发布于 2024-12-27 01:22:06 字数 127 浏览 1 评论 0原文

我正在实现一个自定义 TCP 协议作为 LKM。除了普通数据包之外,我还需要每个 RTT 发送一个自定义数据包,以向接收者传达一些信息。但我无法理解如何确定每个 RTT 或传输轮的开始/结束。

有什么可以帮助的指示或建议吗?

I am implementing a custom TCP protocol as LKM. I need to send, other than normal packets, one custom packet every RTT to convey some information to the receiver. But I am unable to understand how to determine start/end of each RTT or transmission round.

Any pointers or suggestions that could help?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

云柯 2025-01-03 01:22:07

看看这个:

http://www.spinics.net/lists/newbies/msg47478.html

并在内核源代码(特别是 net/ipv4/ 分支)中搜索“srtt”签名:

net/ipv4/tcp_input.c:

/* Called to compute a smoothed rtt estimate. The data fed to this
 * routine either comes from timestamps, or from segments that were
 * known _not_ to have been retransmitted [see Karn/Partridge
 * Proceedings SIGCOMM 87]. The algorithm is from the SIGCOMM 88
 * piece by Van Jacobson.
 * NOTE: the next three routines used to be one big routine.
 * To save cycles in the RFC 1323 implementation it was better to break
 * it up into three procedures. -- erics
 */
static void tcp_rtt_estimator(struct sock *sk, long mrtt_us)
{
        struct tcp_sock *tp = tcp_sk(sk);
        long m = mrtt_us; /* RTT */
        u32 srtt = tp->srtt_us;

这是另一个示例使用 jiffies() 函数设置/重置 srtt 字段:

if (crtt > tp->srtt_us) {
            /* Set RTO like tcp_rtt_estimator(), but from cached RTT. */
            crtt /= 8 * USEC_PER_MSEC;
            inet_csk(sk)->icsk_rto = crtt + max(2 * crtt, tcp_rto_min(sk));
    } else if (tp->srtt_us == 0) {
            /* RFC6298: 5.7 We've failed to get a valid RTT sample from
             * 3WHS. This is most likely due to retransmission,
             * including spurious one. Reset the RTO back to 3secs
             * from the more aggressive 1sec to avoid more spurious
             * retransmission.
             */
            tp->rttvar_us = jiffies_to_usecs(TCP_TIMEOUT_FALLBACK);
            tp->mdev_us = tp->mdev_max_us = tp->rttvar_us;

            inet_csk(sk)->icsk_rto = TCP_TIMEOUT_FALLBACK;
    }

Check this out:

http://www.spinics.net/lists/newbies/msg47478.html

And searching the kernel source (esp the net/ipv4/ branch) for the "srtt" signature:

net/ipv4/tcp_input.c:

/* Called to compute a smoothed rtt estimate. The data fed to this
 * routine either comes from timestamps, or from segments that were
 * known _not_ to have been retransmitted [see Karn/Partridge
 * Proceedings SIGCOMM 87]. The algorithm is from the SIGCOMM 88
 * piece by Van Jacobson.
 * NOTE: the next three routines used to be one big routine.
 * To save cycles in the RFC 1323 implementation it was better to break
 * it up into three procedures. -- erics
 */
static void tcp_rtt_estimator(struct sock *sk, long mrtt_us)
{
        struct tcp_sock *tp = tcp_sk(sk);
        long m = mrtt_us; /* RTT */
        u32 srtt = tp->srtt_us;

and here is another example that set/reset the srtt field using the jiffies() function:

if (crtt > tp->srtt_us) {
            /* Set RTO like tcp_rtt_estimator(), but from cached RTT. */
            crtt /= 8 * USEC_PER_MSEC;
            inet_csk(sk)->icsk_rto = crtt + max(2 * crtt, tcp_rto_min(sk));
    } else if (tp->srtt_us == 0) {
            /* RFC6298: 5.7 We've failed to get a valid RTT sample from
             * 3WHS. This is most likely due to retransmission,
             * including spurious one. Reset the RTO back to 3secs
             * from the more aggressive 1sec to avoid more spurious
             * retransmission.
             */
            tp->rttvar_us = jiffies_to_usecs(TCP_TIMEOUT_FALLBACK);
            tp->mdev_us = tp->mdev_max_us = tp->rttvar_us;

            inet_csk(sk)->icsk_rto = TCP_TIMEOUT_FALLBACK;
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文