Skip to contentSkip to conversation

A illogical problem with the tcphdr->syn!

DISCUSSION supercodeing35271 supercodeing35271 2 participants 2 messages Apr 11, 2010 netfilter

lore
Share & tools
lore
#0 lore raw

Hi,i had written a kernel module with the netfilter.But i found a problem when i judged the value of tcphdr->syn.This is the main code:

static unsigned int hook_func_in(unsigned int hooknum,
struct sk_buff *skb, const struct net_device *in, const struct net_device *out, int (*okfn)(struct sk_buff *))

{
    struct tcphdr *tcp;
    struct icmphdr *icmp;
    struct udphdr *udp;
    struct iphdr *ip;
    char msgk_to_userspace[200];
    char *pointer_mtu;
    pointer_mtu = &msgk_to_userspace[0];

    if(skb == NULL)
    {
	return NF_DROP;
    }
    if(ip_hdr(skb))
    {
	ip = ip_hdr(skb);
	
    }
    else
    {
	return NF_DROP;
    }

    if((skb->dev != NULL) && (in != NULL))
    {
	if(skb->dev == in)
	{
	
	    if(ip->protocol == IPPROTO_TCP)
	    {
		tcp = tcp_hdr(skb);
		
		
		if(tcp->syn)
		{
		    printk("the syn flag is 1 \n");
		    /*here,when i send a tcp packet from other machine which had set

the syn flag by NMAP(command:nmap -sS myIP -p 6000),and i also used wireshark to confirm that the packet had set the syn flag,but the program didn't print "the syn flag is 1" to var/log/message.Otherwise,when i changed the code to"if(!(tcp->syn))","the syn flag is 1" could be print.Yes, it's
opposite!Then i could not thought of why this happened........ */

#1 lore raw
Quoted 8 lines · On Sunday 2010-04-11 14:56, supercodeing35271 supercodeing35271 wrote:

Hi,i had written a kernel module with the netfilter.But i found a problem when i judged the value of tcphdr->syn.This is the main code:

static unsigned int hook_func_in(unsigned int hooknum,
struct sk_buff *skb, const struct net_device *in, const struct net_device *out, int (*okfn)(struct sk_buff *))

Quoted 13 lines
{
   struct tcphdr *tcp;
   struct icmphdr *icmp;
   struct udphdr *udp;
   struct iphdr *ip;
   char msgk_to_userspace[200];
   char *pointer_mtu;
   pointer_mtu = &msgk_to_userspace[0];

   if(skb == NULL)
   {
	return NF_DROP;
   }

Pointless check, skb is never NULL.

Quoted 5 lines
   if(ip_hdr(skb))
   {
	ip = ip_hdr(skb);
	
   }

Pointless check, ip_hdr won't usually return NULL either.

Quoted 9 lines
   else
   {
	return NF_DROP;
   }

   if((skb->dev != NULL) && (in != NULL))
   {
	if(skb->dev == in)
	{

Redundant check. in is the interface.

Quoted 6 lines
	    if(ip->protocol == IPPROTO_TCP)
	    {
		tcp = tcp_hdr(skb);
		
		
		if(tcp->syn)

Must use skb_header_pointer to access parts that lie beyond skb->data.

Quoted 14 lines
		{
		    printk("the syn flag is 1 \n");
		    /*here,when i send a tcp packet from other machine which had set

the syn flag by NMAP(command:nmap -sS myIP -p 6000),and i also used wireshark to confirm that the packet had set the syn flag,but the program didn't print "the syn flag is 1" to var/log/message.Otherwise,when i changed the code to"if(!(tcp->syn))","the syn flag is 1" could be print.Yes, it's
opposite!Then i could not thought of why this happened........ */
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html