Resending IP packets within dev packet handler

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

I try to write a packet handjavascript:SetCmd(cmdSend);ler vor resending packets from an input device to an output device. All the time when i try to resend the packet using "ip_finish_output(o_skb);" the system crashes with a "<0>Kernel panic: not syncing: Fatal exception in interrupt".
Now I am rather confused. Do i have to lock/unlock anything?

I would be very thankful if somebody could take a look into the piece of source code below! Is my attempt right? 

Bye
Matthias 

---

static int ip_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt) {
    struct sk_buff *o_skb = skb_clone(skb, GFP_ATOMIC);
    struct iphdr *iph = o_skb->nh.iph;
    struct tcphdr *th = (struct tcphdr *) ((char *) o_skb->h.th + (iph->ihl << 2));

    //prevent OS for handling packet
    skb->pkt_type = PACKET_OTHERHOST;

    if (iph->saddr == ext_addr) {      
        //modify header
        iph->saddr = gw_int_addr;
        iph->daddr = int_addr;
        o_skb->dev = devs[2];
    } else if (iph->saddr == int_addr) {   
        //modify header
        iph->saddr = gw_ext_addr;
        iph->daddr = ext_addr;
        o_skb->dev = devs[1];
    } else {
        return 0;
    }
    
    //ip checksum
    ...works 

    //route packet
    struct flowi flow = { 
        .nl_u = { 
            .ip4_u = {
                .saddr = iph->saddr,
                .daddr = iph->daddr,
                .tos = RT_TOS(iph->tos) 
            } 
        },
        .proto = iph->protocol
    };
    struct rtable *rt;
    ip_route_output_key(&rt, &flow);
    o_skb->dst = &(rt->u.dst);

    ip_finish_output(o_skb);

    kfree_skb(o_skb);
    
    return 0;
}

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/



[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux