2005-05-07 05:00:22

by rajat swarup

[permalink] [raw]
Subject: sending ICMP messages in kernel module

Hi,
I have placed a netfilter hook in which I grab the packets in the
pre-routing stage.
I need to send ICMP messages in response to certain messages in this hook.
I looked at alloc_skb(), skb_reserve() and skb_put() functions but it
is still not clear to me as to how to construct the packets using
these methods.
Since I am getting the packets in the Pre-routing stage should I
explicitly construct the MAC header, IP header & data & ICMP message?
Also, I'll need to calculate the checksum to be transmitted in the
ICMP packet...which method could I use to do that?

Any help will be really appreciated!

Thanks and regards,
Rajat.
http://rajatswarup.blogspot.com/


2005-05-07 22:17:56

by J. Scott Kasten

[permalink] [raw]
Subject: Re: sending ICMP messages in kernel module


rajat swarup wrote:

>Hi,
>I have placed a netfilter hook in which I grab the packets in the
>pre-routing stage.
>I need to send ICMP messages in response to certain messages in this hook.
>I looked at alloc_skb(), skb_reserve() and skb_put() functions but it
>is still not clear to me as to how to construct the packets using
>these methods.
>Since I am getting the packets in the Pre-routing stage should I
>explicitly construct the MAC header, IP header & data & ICMP message?
>Also, I'll need to calculate the checksum to be transmitted in the
>ICMP packet...which method could I use to do that?
>
>
Hello,

I had a similar problem once. In the icmp.c file, look at how the ping
echo reply works. That is as close to a tutorial as you will find in
the code. I think you might find it strait forward from there.

-Scott-

2005-05-07 23:39:52

by rajat swarup

[permalink] [raw]
Subject: Re: sending ICMP messages in kernel module

On 5/7/05, J. Scott Kasten <[email protected]> wrote:
>
> rajat swarup wrote:
>
> >I have placed a netfilter hook in which I grab the packets in the
> >pre-routing stage.
> >I need to send ICMP messages in response to certain messages in this hook.
> >I looked at alloc_skb(), skb_reserve() and skb_put() functions but it
> >is still not clear to me as to how to construct the packets using
> >these methods.
> >Since I am getting the packets in the Pre-routing stage should I
> >explicitly construct the MAC header, IP header & data & ICMP message?
> >Also, I'll need to calculate the checksum to be transmitted in the
> >ICMP packet...which method could I use to do that?
> >
> >
>
> I had a similar problem once. In the icmp.c file, look at how the ping
> echo reply works. That is as close to a tutorial as you will find in
> the code. I think you might find it strait forward from there.
>

Hi Scott,
I am trying to send ICMP messages but not in reply to anything else.
We have to generate ICMP messages from scratch.
So we do not have access to an existing sk_buff structure that has all
the parameters already set.
icmp_echo(struct skbuff*) assumes that you already have the sk_buff
structure and you are just assigning a few more fields.
Do you have an idea about how can we create ICMP messages from scratch?

Thanks for the help!

-Rajat.
http://rajatswarup.blogspot.com/