All of lore.kernel.org
 help / color / mirror / Atom feed
From: roszenrami@gmail.com (Rami Rosen)
To: kernelnewbies@lists.kernelnewbies.org
Subject: Adding new protocol to linux.
Date: Sat, 26 Mar 2016 14:04:24 +0300	[thread overview]
Message-ID: <CAKoUArkVtYfwbXoX2-=K10eRAP-ye7vPuX76DZEbXJ95EM1FhQ@mail.gmail.com> (raw)
In-Reply-To: <CAF3SDA7r32PzH+szXqQRdAQGxQc+J2gPUDsKs30AVSAYYKmsrw@mail.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

  reply	other threads:[~2016-03-26 11:04 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-26  2:00 Adding new protocol to linux Daniel.
2016-03-26 11:04 ` Rami Rosen [this message]
     [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
2016-03-26 23:49   ` Res: " Daniel
2016-03-28 13:35 Manoj Nayak
2016-03-28 15:03 Manoj Nayak
2016-03-28 20:08 ` Rami Rosen
2016-03-28 21:36   ` Daniel.
2016-03-29  4:36 Manoj Nayak

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAKoUArkVtYfwbXoX2-=K10eRAP-ye7vPuX76DZEbXJ95EM1FhQ@mail.gmail.com' \
    --to=roszenrami@gmail.com \
    --cc=kernelnewbies@lists.kernelnewbies.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.