udpheader在内核代码中添加到data的哪里

Where is udp header added to data in the kernel code

我正在内核中编写一个新的基于 UDP 的协议,所以我只是分叉了 UDP 代码以抢先一步。我需要 header 结构中现有字段以外的一些新字段。我为此创建了一个新结构,但我不知道在何处初始化此结构以在通过 udp_sendmsg 函数(我从 udp 代码复制)发送 udp 帧时附加到数据。

明确地说,我只想更改 udp_sendmsg() 放在数据之前的 header。所以知道 header 和数据在内核代码中的什么地方结合就足够了。

谢谢。

对于 IPv4,一个好的切入点是 net/ipv4/udp.c

static int udp_send_skb(struct sk_buff *skb, struct flowi4 *fl4)
{
    [...]
    * Create a UDP header
    */
    uh = udp_hdr(skb);
    uh->source = inet->inet_sport;
    uh->dest = fl4->fl4_dport;
    uh->len = htons(len);
    uh->check = 0;

特别注意 udp_hdr,它只是 returns skbuff 中的一个内存位置。

static inline struct udphdr *udp_hdr(const struct sk_buff *skb)
{
    return (struct udphdr *)skb_transport_header(skb);
}