How to debug "Malformed Packet (Exception occurred)" when send a udp packet?

ankur dwivedi ankurengg2003 at gmail.com
Tue Sep 16 11:12:37 EDT 2014


What is getting shown in tcpdump?

I guess its a checksum problem.

On Sun, Sep 7, 2014 at 2:42 PM, lx <lxlenovostar at gmail.com> wrote:

> hi all:
>       I want to send a udp packet in kernel module. the codes is:
> ####################################################
>                        /*
> * send UDP packet
> */
> char *dest_addr = "192.168.109.176";
> int eth_len, udph_len, iph_len, len;
> eth_len = sizeof(struct ethhdr);
> iph_len = sizeof(struct iphdr);
> udph_len  = sizeof(struct udphdr);
> len = eth_len + iph_len + udph_len;
>
> struct sk_buff *send_skb = alloc_skb(len, GFP_ATOMIC);
> if (!send_skb)
> return NF_DROP;
>
> //skb_put(send_skb, len);
> skb_reserve(send_skb, len);
>
> skb_push(send_skb, sizeof(struct udphdr));
>
> skb_reset_transport_header(send_skb);
>  udph = udp_hdr(send_skb);
> udph->source = dport;
> udph->dest = dport;
> udph->len = htons(udph_len);
> udph->check = 0;
> udph->check = csum_tcpudp_magic(daddr, in_aton(dest_addr), udph_len,
> IPPROTO_UDP, csum_partial(udph, udph_len, 0));
>  //if (udph->check == 0)
> // udph->check = CSUM_MANGLED_0;
>
> skb_push(send_skb, sizeof(struct iphdr));
> skb_reset_network_header(send_skb);
> send_iph = ip_hdr(send_skb);
>
> // iph->version = 4; iph->ihl = 5;
> put_unaligned(0x45, (unsigned char *)send_iph);
> send_iph->tos      = 0;
> put_unaligned(htons(iph_len), &(send_iph->tot_len));
> //send_iph->id       = htons(atomic_inc_return(&ip_ident));
> send_iph->id       = 0;
> send_iph->frag_off = 0;
> send_iph->ttl      = 64;
> send_iph->protocol = IPPROTO_UDP;
> send_iph->check    = 0;
> put_unaligned(daddr, &(send_iph->saddr));
> put_unaligned(in_aton(dest_addr), &(send_iph->daddr));
> send_iph->check    = ip_fast_csum((unsigned char *)send_iph,
> send_iph->ihl);
>
> eth = (struct ethhdr *) skb_push(send_skb, ETH_HLEN);
> skb_reset_mac_header(send_skb);
> send_skb->protocol = eth->h_proto = htons(ETH_P_IP);
> memcpy(eth->h_source, dev->dev_addr, ETH_ALEN);
> memcpy(eth->h_dest, "00:0C:29:DC:2D:F5", ETH_ALEN);
>
> send_skb->dev = dev;
> dev_queue_xmit(send_skb);
> ####################################################
>
> I think the udp packe is sent,but the wirshark detect this packet is
> error.
> The Error message is:
> ####################################################
>
>> ####################################################
>
> Tell me how to debug it? I'm a new one,
> Thank you.
>
>
>
>
>
>
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
>


-- 


-- 

ankur dwivedi
http://about.me/ankur_dwivedi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20140916/da1708d0/attachment-0001.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ????_090714_051024_PM.jpg
Type: image/jpeg
Size: 198083 bytes
Desc: not available
Url : http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20140916/da1708d0/attachment-0001.jpg 


More information about the Kernelnewbies mailing list