Hey, My question is quite simple, I have an sk_buff that I want to transmit, the sk_buff is an ICMP message and so far, I've built the headers and set up everything. The problem is, when I want to do such a thing, I typically use a function called: dev_queue_xmit which takes the skb and transmits the packet using the net_device specified in the skb; but time time I can't set the net_device, I need the packet to go through the routing code and get it sent normally; so what function can I use to that? Some notes: *The kernel I am working on is 3.2.0-37 *I am working using Modules, so symbols that are not exported are unreachable for me *I set the IP header using htons, so my header data is already in network byte-order. Regards, Adel
Hi, Adel, You should use ip_route_output_flow(). For this you should construct a flowi4 instance. ip_route_output_flow() is exported via EXPORT_SYMBOL_GPL. See for example how this is done in udp_sendmsg(). Good luck! Rami Rosen http://ramirose.wix.com/ramirosen On Fri, Feb 22, 2013 at 2:36 PM, Adel Qodmani <mpcadel@gmail.com> wrote:
Hey,
My question is quite simple, I have an sk_buff that I want to transmit, the sk_buff is an ICMP message and so far, I've built the headers and set up everything.
The problem is, when I want to do such a thing, I typically use a function called: dev_queue_xmit which takes the skb and transmits the packet using the net_device specified in the skb; but time time I can't set the net_device, I need the packet to go through the routing code and get it sent normally; so what function can I use to that?
Some notes: *The kernel I am working on is 3.2.0-37 *I am working using Modules, so symbols that are not exported are unreachable for me *I set the IP header using htons, so my header data is already in network byte-order.
Regards, Adel
_______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
On Fri, Feb 22, 2013 at 3:47 PM, Rami Rosen <roszenrami@gmail.com> wrote:
Hi, Adel,
You should use ip_route_output_flow(). For this you should construct a flowi4 instance. ip_route_output_flow() is exported via EXPORT_SYMBOL_GPL.
See for example how this is done in udp_sendmsg().
Good luck!
Rami Rosen http://ramirose.wix.com/ramirosen
On Fri, Feb 22, 2013 at 2:36 PM, Adel Qodmani <mpcadel@gmail.com> wrote:
Hey,
My question is quite simple, I have an sk_buff that I want to transmit, the sk_buff is an ICMP message and so far, I've built the headers and set up everything.
The problem is, when I want to do such a thing, I typically use a function called: dev_queue_xmit which takes the skb and transmits the packet using the net_device specified in the skb; but time time I can't set the net_device, I need the packet to go through the routing code and get it sent normally; so what function can I use to that?
Some notes: *The kernel I am working on is 3.2.0-37 *I am working using Modules, so symbols that are not exported are unreachable for me *I set the IP header using htons, so my header data is already in network byte-order.
Regards, Adel
_______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Hi Rami, Using ip_route_output_flow() or using udp_sendmsg() would require not only constructing a flowi4 but also a sock; I am intentionally trying to avoid building a sock at the time being. Is there a way I can deliver my sk_buff to the routing code so that it'd set the net_device in there or at least tell me which interface to use and then I'd set it up myself? Thankful, Adel
Hi, Adel, ip_route_output_flow() calls __ip_route_output_key(). The return value is the routing entry, rtable. the parameters for __ip_route_output_key() do not include sock; only net and flow (flp4). And the __ip_route_output_key() is exported. There is a call for xfrm_lookup() which does need a sock in ip_route_output_flow() The xfrm_lookup() is empty when building without IPsec. So in you case, if you know that your solution does not require IPSec traffic, you can use __ip_route_output_key(). rgs. Rami Rosen http://ramirose.wix.com/ramirosen On Fri, Feb 22, 2013 at 3:53 PM, Adel Qodmani <mpcadel@gmail.com> wrote:
On Fri, Feb 22, 2013 at 3:47 PM, Rami Rosen <roszenrami@gmail.com> wrote:
Hi, Adel,
You should use ip_route_output_flow(). For this you should construct a flowi4 instance. ip_route_output_flow() is exported via EXPORT_SYMBOL_GPL.
See for example how this is done in udp_sendmsg().
Good luck!
Rami Rosen http://ramirose.wix.com/ramirosen
On Fri, Feb 22, 2013 at 2:36 PM, Adel Qodmani <mpcadel@gmail.com> wrote:
Hey,
My question is quite simple, I have an sk_buff that I want to transmit, the sk_buff is an ICMP message and so far, I've built the headers and set up everything.
The problem is, when I want to do such a thing, I typically use a function called: dev_queue_xmit which takes the skb and transmits the packet using the net_device specified in the skb; but time time I can't set the net_device, I need the packet to go through the routing code and get it sent normally; so what function can I use to that?
Some notes: *The kernel I am working on is 3.2.0-37 *I am working using Modules, so symbols that are not exported are unreachable for me *I set the IP header using htons, so my header data is already in network byte-order.
Regards, Adel
_______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Hi Rami,
Using ip_route_output_flow() or using udp_sendmsg() would require not only constructing a flowi4 but also a sock; I am intentionally trying to avoid building a sock at the time being. Is there a way I can deliver my sk_buff to the routing code so that it'd set the net_device in there or at least tell me which interface to use and then I'd set it up myself?
Thankful, Adel
On Fri, 22 Feb 2013 14:36:17 +0200, Adel Qodmani said:
My question is quite simple, I have an sk_buff that I want to transmit, the sk_buff is an ICMP message and so far, I've built the headers and set up everything.
Others have given some details on "how". A better question is "why". Sending an ICMP message without the rest of the IP stack's knowledge is usually a bad idea, because it can cause the remote end's concept of network state to become desynchronized with the local concept. As a quick example, consider a spurious 'host/port unreachable' sent to the remote end - many IP stacks will use that info to abort a TCP 3-packet handshake. However, the rest of *your* end thinks the connection is still trying to establish. So what are you trying to accomplish by sending a forged ICMP packet from within the kernel? There may be better ways to approach it (for example, if you're trying to say "this port is closed", a better way is to use iptables with a '-j REJECT --reject-with xxxx', which will (a) do all the heavy lifting of sending the ICMP for you and (b) also prevent the packet from making it to the rest of the local IP stack...
On Fri, Feb 22, 2013 at 4:54 PM, <Valdis.Kletnieks@vt.edu> wrote:
On Fri, 22 Feb 2013 14:36:17 +0200, Adel Qodmani said:
Others have given some details on "how". A better question is "why".
Well, the why is the following: I am trying to implement a new protocol that we've designed which works on top of the IP layer, so I am using ICMP messages to carry control information for the protocol. Why using ICMP, it seemed natural since our protocol is a Network-layer protocol and ICMP is a control messages protocol. Does that make sense? Regards, Adel
Hi, Adel, - In your first message you said you are using kernel modules. - In case you intend to add code in ICMP for your special requirements from the control protocol, then this seems not a good idea (because this means patching the kernel for using your module; and probably such patches will not go to mainline) I don't know of any usage of ICMP for purposes beyond what is declared in the ICMP RFC. regards, Rami Rosen http://ramirose.wix.com/ramirosen On Fri, Feb 22, 2013 at 5:15 PM, Adel Qodmani <mpcadel@gmail.com> wrote:
On Fri, Feb 22, 2013 at 4:54 PM, <Valdis.Kletnieks@vt.edu> wrote:
On Fri, 22 Feb 2013 14:36:17 +0200, Adel Qodmani said:
Others have given some details on "how". A better question is "why".
Well, the why is the following:
I am trying to implement a new protocol that we've designed which works on top of the IP layer, so I am using ICMP messages to carry control information for the protocol. Why using ICMP, it seemed natural since our protocol is a Network-layer protocol and ICMP is a control messages protocol.
Does that make sense?
Regards, Adel
_______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
On Fri, 22 Feb 2013 17:15:35 +0200, you said:
I am trying to implement a new protocol that we've designed which works on top of the IP layer, so I am using ICMP messages to carry control information for the protocol. Why using ICMP, it seemed natural since our protocol is a Network-layer protocol and ICMP is a control messages protocol.
In that case, you *really* want to go look at how TCP and SCTP and other protocols handle ICMP integration. You want an API that integrates your ICMP handling with the rest of the protocol stack, because otherwise you'll end up with an unmaintainable mess. Also, it will be about 436 times easier to extend your protocol to work correctly over IPv6. :) Go look at net/ipv4/udp.c, functions __udp4_lib_err() and __udp_lib_rcv(), particularly the latter's use of icmp_send(). You'll want to extend icmp_send() to handle your additional control information.
participants (3)
-
Adel Qodmani -
Rami Rosen -
Valdis.Kletnieks@vt.edu