User Tools

Site Tools


mywiki:linux:generic_netlink

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
mywiki:linux:generic_netlink [2015/05/16 08:41] shaoguohmywiki:linux:generic_netlink [2019/09/15 18:55] (current) – external edit 127.0.0.1
Line 44: Line 44:
  
 </file> </file>
 +
 +
 +====== Data Structure of Generic Netlink ======
 +
 +
 +{{:mywiki:linux:generic_netlink_data_structure.jpg|}}
 +
 +
 +One Family Data structure
 +<file>
 +                   --------------------------
 +               -- |Global attribute: attrbuf |            
 +                   ----------------------- --
 +                         
 +               |
 +               |
 + One Family -- |           
 +               |
 +                                             -----------------------------------------------
 +                                           --| 1st operation: unique command and its policy |
 +                                             ----------------------------------------------- 
 +                   ------------------------    -----------------------------------------------
 +               -- |operation list:ops_list | --| 2nd operation: unique command and its policy |          
 +                   ------------------------    -----------------------------------------------
 +                                               -----------------------------------------------
 +                                             --| nth operation: unique command and its policy |
 +                                               ----------------------------------------------- 
 +                 
 +
 +</file>
 +
  
 ====== Generic Netlink message format ====== ====== Generic Netlink message format ======
Line 64: Line 95:
 </file> </file>
  
-====== Data Structure of Generic Netlink ====== +{{:mywiki:linux:message_hdr.png|}}
- +
- +
-{{:mywiki:linux:generic_netlink_data_structure.jpg|}}+
  
 +{{:mywiki:linux:message_map.png|}}
 ====== Procedure in kernel ====== ====== Procedure in kernel ======
-<file> 
-             ----------------------------  
-           - |Global attribute: attrbuf  |             
-             ----------------------- ----- 
-                      
-One Family | 
-           | 
-           | 
-                                         --------------------------------------------- 
-                                       --|1st operation: unique command and its policy| 
-                                         ----------------------------------------------  
-             --------------------------    --------------------------------------------- 
-           - | operation list:ops_list | --|2nd operation: unique command and its policy|           
-             --------------------------    --------------------------------------------- 
-                                         --------------------------------------------- 
-                                       --|nth operation: unique command and its policy| 
-                                         ----------------------------------------------  
-                  
  
-</file> 
 ===== 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 216: Line 226:
  
 </file>    </file>   
 +
 +
 +===== Define attribute =====
 +
 +
 +<file>
 + 
 +
 +</file>
 +
 +
 +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 250: Line 279:
 </file>   </file>  
  
- 
-===== Define attribute policy ===== 
- 
- 
-<file> 
- The nla_policy Structure 
- 
-Generic Netlink attribute policy is defined by the nla_policy structure, which is shown below: 
- 
-    struct nla_policy 
-    { 
-       u16             type; 
-       u16             len; 
-    }; 
- 
-     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's payload. 
-    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. 
-</file> 
- 
- 
-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.1431736903.txt.gz · Last modified: (external edit)