mywiki:linux:generic_netlink
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| mywiki:linux:generic_netlink [2015/05/16 08:23] – [define operation and policy] shaoguoh | mywiki:linux:generic_netlink [2019/09/15 18:55] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 11: | Line 11: | ||
| Users who want to use a service query the controller to see if the service exists and to determine the correct channel number. | Users who want to use a service query the controller to see if the service exists and to determine the correct channel number. | ||
| + | |||
| < | < | ||
| Line 43: | Line 44: | ||
| </ | </ | ||
| + | |||
| + | |||
| + | ====== Data Structure of Generic Netlink ====== | ||
| + | |||
| + | |||
| + | {{: | ||
| + | |||
| + | |||
| + | One Family Data structure | ||
| + | < | ||
| + | | ||
| + | -- |Global attribute: attrbuf | | ||
| + | | ||
| + | | ||
| + | | | ||
| + | | | ||
| + | One Family -- | | ||
| + | | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | -- |operation list: | ||
| + | | ||
| + | | ||
| + | --| nth operation: unique command and its policy | | ||
| + | | ||
| + | |||
| + | |||
| + | </ | ||
| + | |||
| ====== Generic Netlink message format ====== | ====== Generic Netlink message format ====== | ||
| Line 63: | Line 95: | ||
| </ | </ | ||
| - | ====== Data Structure of Generic Netlink ====== | + | {{: |
| + | {{: | ||
| + | ====== Procedure in kernel ====== | ||
| - | {{: | ||
| - | |||
| - | ====== Procedure in kernel ====== | ||
| ===== Register a family ===== | ===== Register a family ===== | ||
| Generic Netlink families are defined by the genl_family structure, which is shown below: | Generic Netlink families are defined by the genl_family structure, which is shown below: | ||
| Line 107: | Line 138: | ||
| </ | </ | ||
| - | ===== define | + | ===== Define |
| - | Policy is to validate the attributes before the payload is accessed. | + | |
| + | |||
| + | ==== Operation ===== | ||
| Generic Netlink operations are defined by the genl_ops structure, which is shown below: | Generic Netlink operations are defined by the genl_ops structure, which is shown below: | ||
| < | < | ||
| Line 146: | Line 179: | ||
| </ | </ | ||
| + | ==== Policy ===== | ||
| + | when sending netlink messages the sender needs to adhere to the protocol format. | ||
| + | The receiver of the message will use struct nla_policy to validate the attributes before the payload is accessed. | ||
| + | |||
| < | < | ||
| - | The nla_policy Structure | ||
| - | Generic Netlink attribute policy is defined by the nla_policy structure, which is | + | The nla_policy Structure |
| - | shown below: | + | |
| + | Generic Netlink attribute policy is defined by the nla_policy structure, which is shown below: | ||
| struct nla_policy | struct nla_policy | ||
| Line 158: | Line 195: | ||
| }; | }; | ||
| - | Figure 11: The nla_policy structure | + | Fig: The nla_policy structure |
| The fields are used in the following manner: | The fields are used in the following manner: | ||
| Line 189: | Line 226: | ||
| </ | </ | ||
| + | |||
| + | |||
| + | ===== Define attribute ===== | ||
| + | |||
| + | |||
| + | < | ||
| + | |||
| + | |||
| + | </ | ||
| + | |||
| + | |||
| + | Notes: Attributes And Message Payloads | ||
| + | |||
| + | Most common data structures can be represented with Netlink attributes: | ||
| + | scalar values: Most scalar values already have well-defined attribute types; | ||
| + | Arrays: Arrays can be represented by using a single nested attribute as a container with several of the same attribute type inside each representing a spot in the array. | ||
| + | |||
| + | It is also important to use unique attributes as much as possible. This helps make the most of the Netlink attribute mechanisms and provides for easy changes to the message format in the future. | ||
| + | |||
| ===== Define Message structure ===== | ===== Define Message structure ===== | ||
| Line 223: | Line 279: | ||
| </ | </ | ||
| - | |||
| - | ===== Define attribute policy ===== | ||
| - | |||
| - | |||
| - | < | ||
| - | The nla_policy Structure | ||
| - | |||
| - | Generic Netlink attribute policy is defined by the nla_policy structure, which is shown below: | ||
| - | |||
| - | struct nla_policy | ||
| - | { | ||
| - | | ||
| - | | ||
| - | }; | ||
| - | |||
| - | Fig: The nla_policy structure | ||
| - | |||
| - | The fields are used in the following manner: | ||
| - | |||
| - | u16 type | ||
| - | This specifies the type of the attribute; presently the following types are defined for general use: | ||
| - | NLA_UNSPEC | ||
| - | Undefined type | ||
| - | NLA_U8 | ||
| - | An 8-bit unsigned integer | ||
| - | NLA_U16 | ||
| - | A 16-bit unsigned integer | ||
| - | NLA_U32 | ||
| - | A 32-bit unsigned integer | ||
| - | NLA_U64 | ||
| - | A 64-bit unsigned integer | ||
| - | NLA_FLAG | ||
| - | A simple boolean flag | ||
| - | NLA_MSECS | ||
| - | A 64-bit time value in msecs | ||
| - | NLA_STRING | ||
| - | A variable length string | ||
| - | NLA_NUL_STRING | ||
| - | A variable length NULL terminated string | ||
| - | NLA_NESTED | ||
| - | A stream of attributes | ||
| - | u16 len | ||
| - | When the attribute type is one of the string types then this field should be set to the maximum length of the string, not including the terminal NULL byte. If the attribute type is unknown or NLA_UNSPEC then this field should be set to the exact length of the attribute' | ||
| - | Unless the attribute type is one of the fixed-length types above, a value of zero indicates that no validation of the attribute should be performed. | ||
| - | </ | ||
| - | |||
| - | |||
| - | Notes: Attributes And Message Payloads | ||
| - | |||
| - | Most common data structures can be represented with Netlink attributes: | ||
| - | scalar values: Most scalar values already have well-defined attribute types; | ||
| - | Arrays: Arrays can be represented by using a single nested attribute as a container with several of the same attribute type inside each representing a spot in the array. | ||
| - | |||
| - | It is also important to use unique attributes as much as possible. This helps make the most of the Netlink attribute mechanisms and provides for easy changes to the message format in the future. | ||
mywiki/linux/generic_netlink.1431735804.txt.gz · Last modified: (external edit)
