Skip to contentSkip to conversation

Netfilter queueing problems

DISCUSSION Robert SZABO 1 participant 1 message Apr 8, 2010 netfilter

lore
Share & tools
lore
#0 lore raw

Anyone have any input for me on this.. I have profiled all the code around this and cannot find anything wrong, all I can figure is that the queue is full and it takes time to clear. I have tried moving to a more recent kernel, modifying sysctl parameters but still no luck.

----- Original Message ----

Quoted 6 lines

From: Robert SZABO <[email protected]>
To: [email protected]
Sent: Thu, April 1, 2010 12:58:05 PM
Subject: Netfilter queueing problems

Hi All,

I have built a simple kernel module that listens on the

Quoted 3 lines

interfaces defined in a bridge (Created using bridge-utils) and when it receives a particular packet in the tcp stream, the hook queues that packet to user space.

In user space I then modify the payload, swap the

Quoted 2 lines

source/destination ip addresses and ports, re-calculate the checksums and put it back out using

nfq_set_verdict_mark(q_handle , id,

Quoted 1 line

NF_ACCEPT, BOOMERANG_NFMARK, datagramSize, datagram);

I then have a hook

Quoted 4 lines

that is invoked set as the last hook in the NF_IP_FORWARD chaing that checks the netfilter mark value and if correct, immediately, swaps source/destination mac address and the NIC assignments. The idea being that the modified packet is sent back to the client.

Here is the hook and the final packet

Quoted 1 line

manipulation:

unsigned int secondary_hook_cb(

Quoted 1 line

unsigned int hook,

struct sk_buff **pskb,

Quoted 1 line

const struct net_device *indev,

const struct net_device

Quoted 1 line

*outdev,

    int (*okfn)(struct sk_buff *))

{

Quoted 1 line

struct sk_buff *skb;

    skb= *pskb;

    // we 
Quoted 1 line

skip all interogation and get out of the way

    if (skb && 
Quoted 1 line

skb->nh.iph)

    {
        switch( (int) 
Quoted 1 line

ntohl(skb->nfmark))

        {
Quoted 13 lines
      case  BOOMERANG_NFMARK:
        
        if (skb->nh.iph->protocol == 

IPPROTO_TCP)

{

return swapAndQueuePacket(skb,ntohl(skb->nfmark));
      
          }
          
      break;
Quoted 3 lines

default:

break;

        }
    }
Quoted 1 line

return NF_ACCEPT;

}

int swapAndQueuePacket(struct sk_buff *skb,

Quoted 1 line

int mark)

{
    struct net_device *odev,*idev;
Quoted 1 line

struct ethhdr *ethdr;

    u_char tmp[6];
Quoted 1 line

odev = dev_get_by_name(getIngresIf());

idev =

Quoted 1 line

dev_get_by_name(getEgresIf());

ethdr = (struct ethhdr

Quoted 1 line

*)skb->mac.raw;

    if (ethdr != NULL)
Quoted 1 line

{

        skb->nfmark = htonl(mark);
Quoted 3 lines
    skb->dev=odev;

skb->input_dev=idev;

        skb->pkt_type = 
Quoted 1 line

PACKET_OTHERHOST;

        skb->protocol = 
Quoted 1 line

__constant_htons(ETH_P_IP);

        skb->priority = 
Quoted 1 line

0;

        skb->csum = skb_checksum (skb, 
Quoted 5 lines

skb->nh.iph->ihl*4, skb->len - skb->nh.iph->ihl * 4, 0);

memcpy(tmp,ethdr->h_dest,ETH_ALEN);

memcpy

Quoted 3 lines

(ethdr->h_dest, ethdr->h_source, ETH_ALEN);

memcpy (ethdr->h_source, tmp, ETH_ALEN);

    }
Quoted 1 line

return NF_ACCEPT;

}

This works a treat, however, the issue

Quoted 4 lines

I am running into is that I can pass hundreds of transactions throught the system and the throughput is high, then for some reason throughput drops to a grinding pace. A few seconds later its as fast a lightning and the whole thing repeats itself.

If I simpy use nfq_set_verdict(q_handle ,

Quoted 3 lines

id, NF_ACCEPT, 0,NULL) and avoid not call this last hook, I do not see any performance issues, but obviously I do not get the desired result.

Any ideas would be greatly

Quoted 1 line

appreciated..

Cheers,

Bob