All of lore.kernel.org
 help / color / mirror / Atom feed
* Adding new protocol to linux.
@ 2016-03-28 15:03 Manoj Nayak
  2016-03-28 20:08 ` Rami Rosen
  0 siblings, 1 reply; 9+ messages in thread
From: Manoj Nayak @ 2016-03-28 15:03 UTC (permalink / raw)
  To: kernelnewbies

> 1) Is it possible to write a new protocol for linux with an out of
> tree module without modifing socket.h file?

I think this has been already tried in the following code.

http://lxr.free-electrons.com/source/include/net/bluetooth/bluetooth.h#L36

http://lxr.free-electrons.com/source/include/linux/socket.h#L239

The challenge is to expose this development specific header file to
userspace.
The following document talks about that.

http://kernelnewbies.org/KernelHeaders

Regards
Manoj Nayak
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20160328/cbd945bb/attachment.html 

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

* Adding new protocol to linux.
  2016-03-28 15:03 Adding new protocol to linux Manoj Nayak
@ 2016-03-28 20:08 ` Rami Rosen
  2016-03-28 21:36   ` Daniel.
  0 siblings, 1 reply; 9+ messages in thread
From: Rami Rosen @ 2016-03-28 20:08 UTC (permalink / raw)
  To: kernelnewbies

Hi,
Header files under include/net are for kernel internal use.
Header files under include/uapi are for exposure to userspace:
http://lxr.free-electrons.com/source/include/uapi/

Regards,
Rami Rosen
http://ramirose.wix.com/ramirosen
?????? 28 ???? 2016 18:04, "Manoj Nayak" <manojnayak2005@gmail.com> ???:

> > 1) Is it possible to write a new protocol for linux with an out of
> > tree module without modifing socket.h file?
>
> I think this has been already tried in the following code.
>
> http://lxr.free-electrons.com/source/include/net/bluetooth/bluetooth.h#L36
>
> http://lxr.free-electrons.com/source/include/linux/socket.h#L239
>
> The challenge is to expose this development specific header file to
> userspace.
> The following document talks about that.
>
> http://kernelnewbies.org/KernelHeaders
>
> Regards
> Manoj Nayak
>
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20160328/69e3079b/attachment.html 

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

* Adding new protocol to linux.
  2016-03-28 20:08 ` Rami Rosen
@ 2016-03-28 21:36   ` Daniel.
  0 siblings, 0 replies; 9+ messages in thread
From: Daniel. @ 2016-03-28 21:36 UTC (permalink / raw)
  To: kernelnewbies

Hey everybody, I see that sockets, protocols and network device
drivers are pieces of a same puzzle. So after some digging and
thinking I'm considering write the driver in such way that it only
deals with data link layer, no socket bits. It should sit at 2nd OSI
layer and let routing and segmenting for the other layers. This way
everything that works with TCP/UDP/IP should work with our little
radio transciver. The one million dollars question remains, how do
this with only 32bytes MTU and as a bonus, how to spread the
communications of several nodes throughout all available channels so
that I have less collisions as possible. The first idea that I have
was using some connection based protocol where, when someone wants to
transfers some N bytes of data, the source makes a request to
destination which choses one avaible channel to be used for the
transfers. The data is transferred through the selected channel and
the connection is closed. The comunication used to open some
"connection" would be done on a "control channel" which should be used
as few as possible, while the realdata is transmitted on *some of*
"data channels". What you guys think?

I'll keep working (as much as my sparse time allows me) to get this up
and running then I think at details, if someone has interest here is
the (not yet finished) code: https://github.com/gkos/nrf24l01p

Cheers

2016-03-28 17:08 GMT-03:00 Rami Rosen <roszenrami@gmail.com>:
> Hi,
> Header files under include/net are for kernel internal use.
> Header files under include/uapi are for exposure to userspace:
> http://lxr.free-electrons.com/source/include/uapi/
>
> Regards,
> Rami Rosen
> http://ramirose.wix.com/ramirosen
>
> ?????? 28 ???? 2016 18:04, "Manoj Nayak" <manojnayak2005@gmail.com> ???:
>>
>> > 1) Is it possible to write a new protocol for linux with an out of
>> > tree module without modifing socket.h file?
>>
>> I think this has been already tried in the following code.
>>
>> http://lxr.free-electrons.com/source/include/net/bluetooth/bluetooth.h#L36
>>
>> http://lxr.free-electrons.com/source/include/linux/socket.h#L239
>>
>> The challenge is to expose this development specific header file to
>> userspace.
>> The following document talks about that.
>>
>> http://kernelnewbies.org/KernelHeaders
>>
>> Regards
>> Manoj Nayak
>>
>>
>> _______________________________________________
>> Kernelnewbies mailing list
>> Kernelnewbies at kernelnewbies.org
>> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>>
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>



-- 
"Do or do not. There is no try"
  Yoda Master

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

* Adding new protocol to linux.
@ 2016-03-29  4:36 Manoj Nayak
  0 siblings, 0 replies; 9+ messages in thread
From: Manoj Nayak @ 2016-03-29  4:36 UTC (permalink / raw)
  To: kernelnewbies

Hi Daniel,

Some of the Network application use two connections. One connection for
control channel to send commands and status update. Other connection is
used for real data transfer. For example: FTP. However this needs two
socket.

TCP talks about out-of-band data transfer using Urgent Pointer flag and
Urgent pointer offset in the tcp header. However the data transfer uses the
same connection.

Regards
Manoj Nayak
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20160329/7b1a00f2/attachment.html 

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

* Adding new protocol to linux
@ 2016-03-28 13:35 Manoj Nayak
  0 siblings, 0 replies; 9+ messages in thread
From: Manoj Nayak @ 2016-03-28 13:35 UTC (permalink / raw)
  To: kernelnewbies

> 2) Could netlink socket be used to solve this? .. and

Netlink is used to transfer information between kernel and user-space
processes.  It consists of a standard sockets-based interface for
user space processes and an internal kernel API for kernel modules.
netlink socket does not call dev_queue_xmit().

But here the requirement is to transfer the packet using Nordic's nRF24L01+.

AF_PACKET is used to output a raw packet from userspace to a device layer.
Even AF_PACKET does that using proto_ops and net_proto_family.

Regards
Manoj Nayak
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20160328/7238ca5e/attachment.html 

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

* Adding new protocol to linux.
       [not found]   ` <CAF3SDA5kn7_Pnx0=XpeQOB-D2UCeYZEnzPpcE=25U30ob9KSHQ@mail.gmail.com>
@ 2016-03-26 23:30     ` Daniel
  0 siblings, 0 replies; 9+ messages in thread
From: Daniel @ 2016-03-26 23:30 UTC (permalink / raw)
  To: kernelnewbies

Thanks Rami, it helps a lot. I'm using SocketCAN as reference for doing this, and I see AF_CAN at socket.h. I saw that protocol family create is called by __sock_create(). Also found that proto_ops bind is used (in the example of the CAN) to find the interface where the communication realy happens.. I am wondering if is possible to achieve my goal with and only with out of tree module. I'm planing to get this merged at main tree anyway, but first I would like to keep it out ou tree until is ready...
Cheers,?

2016-03-26 8:04 GMT-03:00 Rami Rosen <roszenrami@gmail.com>:
> Hi Daniel,
>
> Following are answers for several of your questions:
> Adding a protocol in Linux is done first by defining a protocol, and
> then registering it with the proto_register() method:
> http://lxr.free-electrons.com/source/net/core/sock.c#L2815
> For that you need to define a proto object; for TCPv4 it is done thus,
> for example:
> http://lxr.free-electrons.com/source/net/ipv4/tcp_ipv4.c#L2315
>
> Defining a protocol is not enough, you should also register a protocol
> handler for this protocol.
> Defining a protocol handler is done first by
> defining a packet_type object
> of this protocol and then defining a callback for this packet_type.
> So for example, for IPv4, a packet_type object called ip_packet_type is
> defined in http://lxr.free-electrons.com/source/net/ipv4/af_inet.c#L1677
>
> The protocol handler for this packet type is ip_rcv():
> http://lxr.free-electrons.com/source/net/ipv4/ip_input.c#L378
>
> This protocol is registered with dev_add_pack():
> http://lxr.free-electrons.com/source/net/core/dev.c#L397
>
> So, for example, for IPv4 it is done in inet_init():
> http://lxr.free-electrons.com/source/net/ipv4/af_inet.c#L1791
>
> Apart from the protocol handler, a unique Ethernet type should be
> defined for this protocol; for IPv4 we have 0x0800 (ETH_P_IP)
> http://lxr.free-electrons.com/source/include/uapi/linux/if_ether.h#L46
> and for the ARP protocol we have 0x0806 (ETH_P_ARP), and so on.
>
> The Ethernet type in the Ethernet header represents the protocol
> assigned to this packet.
>
> The net_device_ops structure is not related, it merely represents the
> interface of the of the kernel representation of network device (a
> net_device object) to userspace, for userspace operations like
> setting the MTU, setting the MAC address, bringing the device up and
> down, putting the device in promiscuous mode, and more.
>
> Hope this helps!
>
> Regards,
> Rami Rosen
> http://ramirose.wix.com/ramirosen
>
>
> On 26 March 2016 at 05:00, Daniel. <danielhilst@gmail.com> wrote:
>> Hi everybody,
>>
>> I'm planing to write a socket API for Nordic's nRF24L01+ and I was
>> digging on socket code and find all supported protocols at
>> include/linux/socket.h with all that #define AF_x y. So my questions
>> are:
>>
>> 1) Is it possible to write a new protocol for linux with an out of
>> tree module without modifing socket.h file?
>> 2) Could netlink socket be used to solve this? .. and
>> 3) I saw that there is net_device_ops and proto_ops. How they are tied together?
>>
>> Thanks in advance and
>> Best regards,
>>
>> --
>> "Do or do not. There is no try"
>> Yoda Master
>>
>> _______________________________________________
>> Kernelnewbies mailing list
>> Kernelnewbies at kernelnewbies.org
>> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies



-- 
"Do or do not. There is no try"
Yoda Master

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

* Adding new protocol to linux.
  2016-03-26  2:00 Daniel.
  2016-03-26 11:04 ` Rami Rosen
@ 2016-03-26 19:59 ` Valdis.Kletnieks at vt.edu
  1 sibling, 0 replies; 9+ messages in thread
From: Valdis.Kletnieks at vt.edu @ 2016-03-26 19:59 UTC (permalink / raw)
  To: kernelnewbies

On Fri, 25 Mar 2016 23:00:48 -0300, "Daniel." said:
> Hi everybody,
>
> I'm planing to write a socket API for Nordic's nRF24L01+ and I was
> digging on socket code and find all supported protocols at
> include/linux/socket.h with all that #define AF_x y. So my questions
> are:
>
> 1) Is it possible to write a new protocol for linux with an out of
> tree module without modifing socket.h file?

Rami Rosen gave a good outline of what's needed.  But the *first* question
you should ask is why a hardware device needs its own socket API rather than
re-using an existing one.  Basically, if it's an intelligent enough device
or SOC, you should be able to get it to talk at least UDP or something. And
if it's not that smart, maybe you shouldn't be trying to use sockets to talk to
it.

So what are the reasons you're doing a new socket API instead of using the
existing stuff?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 848 bytes
Desc: not available
Url : http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20160326/01ac9324/attachment.bin 

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

* Adding new protocol to linux.
  2016-03-26  2:00 Daniel.
@ 2016-03-26 11:04 ` Rami Rosen
       [not found]   ` <CAF3SDA5kn7_Pnx0=XpeQOB-D2UCeYZEnzPpcE=25U30ob9KSHQ@mail.gmail.com>
  2016-03-26 19:59 ` Valdis.Kletnieks at vt.edu
  1 sibling, 1 reply; 9+ messages in thread
From: Rami Rosen @ 2016-03-26 11:04 UTC (permalink / raw)
  To: kernelnewbies

Hi Daniel,

Following are answers for several of your questions:
Adding a protocol in Linux is done first by defining a protocol, and
then registering it with the proto_register() method:
http://lxr.free-electrons.com/source/net/core/sock.c#L2815
For that you need to define a proto object; for TCPv4 it is done thus,
for example:
http://lxr.free-electrons.com/source/net/ipv4/tcp_ipv4.c#L2315

Defining a protocol is not enough, you should also register a protocol
handler for this protocol.
Defining a protocol handler is done first by
defining a packet_type object
of this protocol and then defining a callback for this packet_type.
So for example, for IPv4, a packet_type object called ip_packet_type is
defined in http://lxr.free-electrons.com/source/net/ipv4/af_inet.c#L1677

The protocol handler for this packet type is ip_rcv():
http://lxr.free-electrons.com/source/net/ipv4/ip_input.c#L378

This protocol is registered with dev_add_pack():
http://lxr.free-electrons.com/source/net/core/dev.c#L397

So, for example, for IPv4 it is done in inet_init():
http://lxr.free-electrons.com/source/net/ipv4/af_inet.c#L1791

Apart from the protocol handler, a unique Ethernet type should be
defined for this protocol; for IPv4 we have  0x0800 (ETH_P_IP)
http://lxr.free-electrons.com/source/include/uapi/linux/if_ether.h#L46
and for the ARP protocol we have 0x0806 (ETH_P_ARP), and so on.

The Ethernet type in the Ethernet header represents the protocol
assigned to this packet.

The net_device_ops structure is not related, it merely represents the
interface of the of the kernel representation of network device (a
net_device object)  to userspace, for userspace operations like
setting the MTU, setting the MAC address, bringing the device up and
down, putting the device in promiscuous mode, and more.

Hope this helps!

Regards,
Rami Rosen
http://ramirose.wix.com/ramirosen


On 26 March 2016 at 05:00, Daniel. <danielhilst@gmail.com> wrote:
> Hi everybody,
>
> I'm planing to write a socket API for Nordic's nRF24L01+ and I was
> digging on socket code and find all supported protocols at
> include/linux/socket.h with all that #define AF_x y. So my questions
> are:
>
> 1) Is it possible to write a new protocol for linux with an out of
> tree module without modifing socket.h file?
> 2) Could netlink socket be used to solve this? .. and
> 3) I saw that there is net_device_ops and proto_ops. How they are tied together?
>
> Thanks in advance and
> Best regards,
>
> --
> "Do or do not. There is no try"
>   Yoda Master
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

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

* Adding new protocol to linux.
@ 2016-03-26  2:00 Daniel.
  2016-03-26 11:04 ` Rami Rosen
  2016-03-26 19:59 ` Valdis.Kletnieks at vt.edu
  0 siblings, 2 replies; 9+ messages in thread
From: Daniel. @ 2016-03-26  2:00 UTC (permalink / raw)
  To: kernelnewbies

Hi everybody,

I'm planing to write a socket API for Nordic's nRF24L01+ and I was
digging on socket code and find all supported protocols at
include/linux/socket.h with all that #define AF_x y. So my questions
are:

1) Is it possible to write a new protocol for linux with an out of
tree module without modifing socket.h file?
2) Could netlink socket be used to solve this? .. and
3) I saw that there is net_device_ops and proto_ops. How they are tied together?

Thanks in advance and
Best regards,

-- 
"Do or do not. There is no try"
  Yoda Master

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

end of thread, other threads:[~2016-03-29  4:36 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-03-28 15:03 Adding new protocol to linux Manoj Nayak
2016-03-28 20:08 ` Rami Rosen
2016-03-28 21:36   ` Daniel.
  -- strict thread matches above, loose matches on Subject: below --
2016-03-29  4:36 Manoj Nayak
2016-03-28 13:35 Manoj Nayak
2016-03-26  2:00 Daniel.
2016-03-26 11:04 ` Rami Rosen
     [not found]   ` <CAF3SDA5kn7_Pnx0=XpeQOB-D2UCeYZEnzPpcE=25U30ob9KSHQ@mail.gmail.com>
2016-03-26 23:30     ` Daniel
2016-03-26 19:59 ` Valdis.Kletnieks at vt.edu

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.