Access to TCP header from tcp congestion control Linux kernel module

I am working on a TCP congestion control algorithm for a Linux kernel, which I understand as a kernel module. In the code, I want to access the tcp header and use the following function for this.

void get_hdr(struct sock *sk){ struct sk_buff *skb; skb = skb_peek_tail(&sk->sk_receive_queue); if (skb != NULL) printk(KERN_INFO "skb address: %p", skb); struct tcphdr *tcp_header = tcp_hdr(skb); if(tcp_header != 0) printk(KERN_INFO "tcp_header address: %p", tcp_header); else printk(KERN_INFO "tcp_header is NULL"); } 

I think this should basically work, as it is done here inside the kernel .

Hower, looking at my kern.log, I see the following:

 skb address: dbd94501 tcp_header address is NULL 

Apparently, the call to tcp_hdr (skb) fails.

I do not know why this should be. Does anyone have an inspiring hint where I should look or what I need to change to return the tcp header?

Greetings

Stephen

+4
source share
2 answers

In line

 struct tcphdr *tcp_header = tcp_hdr(skb); 

you can still have skb == NULL.

Why don't you put the whole if section in braces?

 void get_hdr(struct sock *sk){ struct sk_buff *skb; skb = skb_peek_tail(&sk->sk_receive_queue); if (skb != NULL) { printk(KERN_INFO "skb address: %p", skb); struct tcphdr *tcp_header = tcp_hdr(skb); if(tcp_header != 0) printk(KERN_INFO "tcp_header address: %p", tcp_header); else printk(KERN_INFO "tcp_header is NULL"); } } 
+1
source

This may be a package in which transport_header is missing.

+1
source

Source: https://habr.com/ru/post/1332600/


All Articles