How to debug "Malformed Packet (Exception occurred)" when send a udp packet?
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.
On 2014-09-07 17:12:33 (+0800), lx <lxlenovostar@gmail.com> wrote:
I want to send a udp packet in kernel module. the codes is:
Why?
// 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)); ^- That's probably your problem.
Regards, Kristof
What is getting shown in tcpdump? I guess its a checksum problem. On Sun, Sep 7, 2014 at 2:42 PM, lx <lxlenovostar@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@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
-- -- ankur dwivedi http://about.me/ankur_dwivedi
Thank you. I make a error with "tot_len". 2014-09-16 23:05 GMT+08:00 ankur dwivedi <ankurengg2003@gmail.com>:
What is getting shown in tcpdump?
I guess its a checksum problem.
On Sun, Sep 7, 2014 at 2:42 PM, lx <lxlenovostar@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@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
--
--
ankur dwivedi http://about.me/ankur_dwivedi
participants (3)
-
ankur dwivedi -
Kristof Provost -
lx