Adding new protocol to linux.
Daniel
danielhilst at gmail.com
Sat Mar 26 19:30:02 EDT 2016
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 at 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 at 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
More information about the Kernelnewbies
mailing list