This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
networking:generic_netlink_howto [2016/08/12 05:17] AliceSmith [Generic Netlink By Example] |
networking:generic_netlink_howto [2017/05/18 15:45] (current) Yaron_Shragai genl_register_ops is deprecated - provided appropriate replacement information. |
||
---|---|---|---|
Line 14: | Line 14: | ||
=====Contents===== | =====Contents===== | ||
- | * [[https://www.linuxfoundation.org/#Generic_Netlink_By_Example|1 Generic Netlink By Example]] | + | * [[#Generic Netlink By Example|1 Generic Netlink By Example]] |
- | * [[https://www.linuxfoundation.org/#Registering_A_Family|1.1 Registering A Family]] | + | * [[#Registering A Family|1.1 Registering A Family]] |
- | * [[https://www.linuxfoundation.org/#Kernel_Communication|1.2 Kernel Communication]] | + | * [[#Kernel Communication|1.2 Kernel Communication]] |
- | * [[https://www.linuxfoundation.org/#Sending_Messages|1.2.1 Sending Messages]] | + | * [[#Sending Messages|1.2.1 Sending Messages]] |
- | * [[https://www.linuxfoundation.org/#Receiving_Messages|1.2.2 Receiving Messages]] | + | * [[#Receiving Messages|1.2.2 Receiving Messages]] |
- | * [[https://www.linuxfoundation.org/#Userspace_Communication|1.3 Userspace Communication]] | + | * [[#Userspace Communication|1.3 Userspace Communication]] |
- | * [[https://www.linuxfoundation.org/#Architectural_Overview|2 Architectural Overview]] | + | * [[#Architectural Overview|2 Architectural Overview]] |
- | * [[https://www.linuxfoundation.org/#Implementation_Details|3 Implementation Details]] | + | * [[#Implementation Details|3 Implementation Details]] |
- | * [[https://www.linuxfoundation.org/#Message_Format|3.1 Message Format]] | + | * [[#Message Format|3.1 Message Format]] |
- | * [[https://www.linuxfoundation.org/#Data_Structures|3.2 Data Structures]] | + | * [[#Data Structures|3.2 Data Structures]] |
- | * [[https://www.linuxfoundation.org/#The_genl_family_Structure|3.2.1 The genl_family Structure]] | + | * [[#The genl_family Structure|3.2.1 The genl_family Structure]] |
- | * [[https://www.linuxfoundation.org/#The_genl_ops_Structure|3.2.2 The genl_ops Structure]] | + | * [[#The genl_ops Structure|3.2.2 The genl_ops Structure]] |
- | * [[https://www.linuxfoundation.org/#The_genl_info_Structure|3.2.3 The genl_info Structure]] | + | * [[#The genl_info Structure|3.2.3 The genl_info Structure]] |
- | * [[https://www.linuxfoundation.org/#The_nla_policy_Structure|3.2.4 The nla_policy Structure]] | + | * [[#The nla_policy Structure|3.2.4 The nla_policy Structure]] |
- | * [[https://www.linuxfoundation.org/#Recommendations|4 Recommendations]] | + | * [[#Recommendations|4 Recommendations]] |
- | * [[https://www.linuxfoundation.org/#Attributes_And_Message_Payloads|4.1 Attributes And Message Payloads]] | + | * [[#Attributes And Message Payloads|4.1 Attributes And Message Payloads]] |
- | * [[https://www.linuxfoundation.org/#Operation_Granularity|4.2 Operation Granularity]] | + | * [[#Operation Granularity|4.2 Operation Granularity]] |
- | * [[https://www.linuxfoundation.org/#Acknowledgment_and_Error_Reporting|4.3 Acknowledgment and Error Reporting]] | + | * [[#Acknowledgment and Error Reporting|4.3 Acknowledgment and Error Reporting]] |
- | * [[https://www.linuxfoundation.org/#References|5 References]] | + | * [[#References|5 References]] |
===== Generic Netlink By Example===== | ===== Generic Netlink By Example===== | ||
Line 38: | Line 38: | ||
This section deals with the Generic Netlink subsystem in the Linux kernel and | This section deals with the Generic Netlink subsystem in the Linux kernel and | ||
provides a simple example of how in-kernel users can make use of the Generic | provides a simple example of how in-kernel users can make use of the Generic | ||
- | Netlink API. Don't forget to review section #4, "Recommendations", before | + | Netlink API. Don't forget to review section #4, "Recommendations", before writing any code as it can save you, and the people who review your code, |
- | [[https://twitter.com/redgage | writing]] any code as it can save you, and the people who review your code, | + | |
lots of time! | lots of time! | ||
Line 119: | Line 118: | ||
if (rc != 0) | if (rc != 0) | ||
goto failure;</code> | goto failure;</code> | ||
+ | |||
This call registers the new family name with the Generic Netlink mechanism and | This call registers the new family name with the Generic Netlink mechanism and | ||
requests a new channel number which is stored in the genl_family struct, | requests a new channel number which is stored in the genl_family struct, | ||
Line 132: | Line 131: | ||
if (rc != 0) | if (rc != 0) | ||
goto failure;</code> | goto failure;</code> | ||
+ | |||
+ | NOTE: This function doesn't exist past linux 3.12. | ||
+ | Up to linux 4.10, use genl_register_family_with_ops(). | ||
+ | On 4.10 and later, include a reference to your genl_ops struct as an element | ||
+ | in the genl_family struct (element .ops), as well as the number of commands | ||
+ | (element .n_ops). | ||
This call registers the DOC_EXMPL_C_ECHO operation in association with the | This call registers the DOC_EXMPL_C_ECHO operation in association with the | ||
Line 441: | Line 446: | ||
- [[http://people.suug.ch/~tgr/libnl|http://people.suug.ch/~tgr/libnl]] | - [[http://people.suug.ch/~tgr/libnl|http://people.suug.ch/~tgr/libnl]] | ||
+ | NOTE: This link is no longer valid. Try [[http://www.infradead.org/~tgr/libnl|http://www.infradead.org/~tgr/libnl]] |