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:50] – [Define Message structure] shaoguohmywiki:linux:generic_netlink [2019/09/15 18:55] (current) – external edit 127.0.0.1
Line 95: Line 95:
 </file> </file>
  
 +{{:mywiki:linux:message_hdr.png|}}
 +
 +{{:mywiki:linux:message_map.png|}}
 ====== Procedure in kernel ====== ====== Procedure in kernel ======
  
Line 241: Line 244:
  
 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.  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 ===== 
 +
 +Generic Netlink message information is passed by the genl_info structure, which is shown below:
 +
 +<file>
 +    struct genl_info
 +    {
 +       u32                     snd_seq;
 +       u32                     snd_pid;
 +       struct nlmsghdr *       nlhdr;
 +       struct genlmsghdr *     genlhdr;
 +       void *                  userhdr;
 +       struct nlattr **        attrs;
 +    };
 +
 +    Fig: The genl_info structure
 +
 +The fields are populated in the following manner:
 +
 +    u32 snd_seq
 +    This is the Netlink sequence number of the request.
 +    u32 snd_pid
 +    This is the Netlink PID of the client which issued the request; it is important to note that the Netlink PID is not the same as the standard kernel PID.
 +    struct nlmsghdr *nlhdr
 +    This is set to point to the Netlink message header of the request.
 +    struct genlmsghdr *genlhdr
 +    This is set to point to the Generic Netlink message header of the request.
 +    void *userhdr
 +    If the Generic Netlink family makes use of a family specific header, this pointer will be set to point to the start of the family specific header.
 +    struct nlattr **attrs
 +    The parsed Netlink attributes from the request; if the Generic Netlink family definition specified a Netlink attribute policy then the attributes would have already been validated.
 +    The doit() handler should do whatever processing is necessary and return zero on success or a negative value on failure. Negative return values will cause an NLMSG_ERROR message to be sent while a zero return value will only cause the NLMSG_ERROR message to be sent if the request is received with the NLM_F_ACK flag set.
 +</file>  
 +
mywiki/linux/generic_netlink.1431737457.txt.gz · Last modified: (external edit)