Re: Adding new protocol to linux.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx> 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@xxxxxxxxxxxxxxxxx
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@xxxxxxxxxxxxxxxxx
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies



[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux