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

lx lxlenovostar at gmail.com
Sun Sep 7 05:12:33 EDT 2014


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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20140907/0ccac3e4/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/20140907/0ccac3e4/attachment-0001.jpg 


More information about the Kernelnewbies mailing list