All of lore.kernel.org
 help / color / mirror / Atom feed
* How to debug "Malformed Packet (Exception occurred)" when send a udp packet?
@ 2014-09-07  9:12 lx
  2014-09-16 15:05 ` Kristof Provost
  2014-09-16 15:12 ` ankur dwivedi
  0 siblings, 2 replies; 4+ messages in thread
From: lx @ 2014-09-07  9:12 UTC (permalink / raw)
  To: kernelnewbies

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 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* How to debug "Malformed Packet (Exception occurred)" when send a udp packet?
  2014-09-07  9:12 How to debug "Malformed Packet (Exception occurred)" when send a udp packet? lx
@ 2014-09-16 15:05 ` Kristof Provost
  2014-09-16 15:12 ` ankur dwivedi
  1 sibling, 0 replies; 4+ messages in thread
From: Kristof Provost @ 2014-09-16 15:05 UTC (permalink / raw)
  To: kernelnewbies

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* How to debug "Malformed Packet (Exception occurred)" when send a udp packet?
  2014-09-07  9:12 How to debug "Malformed Packet (Exception occurred)" when send a udp packet? lx
  2014-09-16 15:05 ` Kristof Provost
@ 2014-09-16 15:12 ` ankur dwivedi
  2014-09-28  6:38   ` lx
  1 sibling, 1 reply; 4+ messages in thread
From: ankur dwivedi @ 2014-09-16 15:12 UTC (permalink / raw)
  To: kernelnewbies

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 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 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* How to debug "Malformed Packet (Exception occurred)" when send a udp packet?
  2014-09-16 15:12 ` ankur dwivedi
@ 2014-09-28  6:38   ` lx
  0 siblings, 0 replies; 4+ messages in thread
From: lx @ 2014-09-28  6:38 UTC (permalink / raw)
  To: kernelnewbies

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 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/20140928/01c369c0/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/20140928/01c369c0/attachment-0001.jpg 

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-09-28  6:38 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-07  9:12 How to debug "Malformed Packet (Exception occurred)" when send a udp packet? lx
2014-09-16 15:05 ` Kristof Provost
2014-09-16 15:12 ` ankur dwivedi
2014-09-28  6:38   ` lx

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.