<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/> <title>libnl: Management</title> <link href="tabs.css" rel="stylesheet" type="text/css"/> <link href="doxygen.css" rel="stylesheet" type="text/css"/> </head> <body> <!-- Generated by Doxygen 1.7.3 --> <div id="top"> <div id="titlearea"> <table cellspacing="0" cellpadding="0"> <tbody> <tr style="height: 56px;"> <td style="padding-left: 0.5em;"> <div id="projectname">libnl <span id="projectnumber">1.1</span></div> </td> </tr> </tbody> </table> </div> <div id="navrow1" class="tabs"> <ul class="tablist"> <li><a href="index.html"><span>Main Page</span></a></li> <li><a href="modules.html"><span>Modules</span></a></li> <li><a href="annotated.html"><span>Data Structures</span></a></li> <li><a href="files.html"><span>Files</span></a></li> </ul> </div> </div> <div class="header"> <div class="summary"> <a href="#nested-classes">Data Structures</a> | <a href="#groups">Modules</a> | <a href="#func-members">Functions</a> </div> <div class="headertitle"> <h1>Management</h1> </div> <div class="ingroups"><a class="el" href="group__genl.html">Generic Netlink</a></div></div> <div class="contents"> <table class="memberdecls"> <tr><td colspan="2"><h2><a name="nested-classes"></a> Data Structures</h2></td></tr> <tr><td class="memItemLeft" align="right" valign="top">struct  </td><td class="memItemRight" valign="bottom"><a class="el" href="structgenl__cmd.html">genl_cmd</a></td></tr> <tr><td class="mdescLeft"> </td><td class="mdescRight">Generic Netlink Command. <a href="structgenl__cmd.html#_details">More...</a><br/></td></tr> <tr><td class="memItemLeft" align="right" valign="top">struct  </td><td class="memItemRight" valign="bottom"><a class="el" href="structgenl__ops.html">genl_ops</a></td></tr> <tr><td class="mdescLeft"> </td><td class="mdescRight">Generic Netlink Operations. <a href="structgenl__ops.html#_details">More...</a><br/></td></tr> <tr><td colspan="2"><h2><a name="groups"></a> Modules</h2></td></tr> <tr><td class="memItemLeft" align="right" valign="top"> </td><td class="memItemRight" valign="bottom"><a class="el" href="group__ctrl.html">Controller</a></td></tr> <tr><td colspan="2"><h2><a name="func-members"></a> Functions</h2></td></tr> <tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="ga5aeced5f4d5270304efd96c28c67606f"></a><!-- doxytag: member="genl_mngt::genl_op2name" ref="ga5aeced5f4d5270304efd96c28c67606f" args="(int family, int op, char *buf, size_t len)" --> char * </td><td class="memItemRight" valign="bottom"><b>genl_op2name</b> (int family, int op, char *buf, size_t len)</td></tr> <tr><td colspan="2"><h2><a name="member-group"></a> Register/Unregister</h2></td></tr> <tr><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="group__genl__mngt.html#ga090500dc23450349a7c2861fb3ae5f54">genl_register</a> (struct <a class="el" href="structnl__cache__ops.html">nl_cache_ops</a> *ops)</td></tr> <tr><td class="mdescLeft"> </td><td class="mdescRight">Register generic netlink operations. <a href="#ga090500dc23450349a7c2861fb3ae5f54"></a><br/></td></tr> <tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="group__genl__mngt.html#ga3fa959e2873bd588fbef31d0dabbf014">genl_unregister</a> (struct <a class="el" href="structnl__cache__ops.html">nl_cache_ops</a> *ops)</td></tr> <tr><td class="mdescLeft"> </td><td class="mdescRight">Unregister generic netlink operations. <a href="#ga3fa959e2873bd588fbef31d0dabbf014"></a><br/></td></tr> <tr><td colspan="2"><h2><a name="member-group"></a> Resolving ID/Name</h2></td></tr> <tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="gaa1b921abecd5d28c313640cbe3b7222c"></a><!-- doxytag: member="genl_mngt::genl_ops_resolve" ref="gaa1b921abecd5d28c313640cbe3b7222c" args="(struct nl_handle *handle, struct genl_ops *ops)" --> int </td><td class="memItemRight" valign="bottom"><b>genl_ops_resolve</b> (struct nl_handle *handle, struct <a class="el" href="structgenl__ops.html">genl_ops</a> *ops)</td></tr> <tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="gab087aec2a4cb2835587a3cc73fd96b67"></a><!-- doxytag: member="genl_mngt::genl_mngt_resolve" ref="gab087aec2a4cb2835587a3cc73fd96b67" args="(struct nl_handle *handle)" --> int </td><td class="memItemRight" valign="bottom"><b>genl_mngt_resolve</b> (struct nl_handle *handle)</td></tr> </table> <hr/><a name="_details"></a><h2>Detailed Description</h2> <dl class="user"><dt><b>1) Registering a generic netlink module</b></dt><dd><div class="fragment"><pre class="fragment"><span class="preprocessor"> #include <netlink/genl/mngt.h></span> <span class="comment">// First step is to define all the commands being used in</span> <span class="comment">// particular generic netlink family. The ID and name are</span> <span class="comment">// mandatory to be filled out. A callback function and</span> <span class="comment">// most the attribute policy that comes with it must be</span> <span class="comment">// defined for commands expected to be issued towards</span> <span class="comment">// userspace.</span> <span class="keyword">static</span> <span class="keyword">struct </span><a class="code" href="structgenl__cmd.html" title="Generic Netlink Command.">genl_cmd</a> foo_cmds[] = { { .<a class="code" href="structgenl__cmd.html#a44973cc65dbac22f07415820d33bc75e" title="Unique command identifier.">c_id</a> = FOO_CMD_NEW, .c_name = <span class="stringliteral">"NEWFOO"</span> , .c_maxattr = FOO_ATTR_MAX, .c_attr_policy = foo_policy, .c_msg_parser = foo_msg_parser, }, { .c_id = FOO_CMD_DEL, .c_name = <span class="stringliteral">"DELFOO"</span> , }, }; <span class="comment">// The list of commands must then be integrated into a</span> <span class="comment">// struct genl_ops serving as handle for this particular</span> <span class="comment">// family.</span> <span class="keyword">static</span> <span class="keyword">struct </span><a class="code" href="structgenl__ops.html" title="Generic Netlink Operations.">genl_ops</a> my_genl_ops = { .o_cmds = foo_cmds, .o_ncmds = ARRAY_SIZE(foo_cmds), }; <span class="comment">// Using the above struct genl_ops an arbitary number of</span> <span class="comment">// cache handles can be associated to it.</span> <span class="comment">//</span> <span class="comment">// The macro GENL_HDRSIZE() must be used to specify the</span> <span class="comment">// length of the header to automatically take headers on</span> <span class="comment">// generic layers into account.</span> <span class="comment">//</span> <span class="comment">// The macro GENL_FAMILY() is used to represent the generic</span> <span class="comment">// netlink family id.</span> <span class="keyword">static</span> <span class="keyword">struct </span><a class="code" href="structnl__cache__ops.html" title="Cache Operations.">nl_cache_ops</a> genl_foo_ops = { .co_name = <span class="stringliteral">"genl/foo"</span>, .co_hdrsize = GENL_HDRSIZE(<span class="keyword">sizeof</span>(<span class="keyword">struct</span> my_hdr)), .co_msgtypes = GENL_FAMILY(GENL_ID_GENERATE, <span class="stringliteral">"foo"</span>), .co_genl = &my_genl_ops, .co_protocol = NETLINK_GENERIC, .co_request_update = foo_request_update, .co_obj_ops = &genl_foo_ops, }; <span class="comment">// Finally each cache handle for a generic netlink family</span> <span class="comment">// must be registered using genl_register().</span> <span class="keyword">static</span> <span class="keywordtype">void</span> __init foo_init(<span class="keywordtype">void</span>) { <a class="code" href="group__genl__mngt.html#ga090500dc23450349a7c2861fb3ae5f54" title="Register generic netlink operations.">genl_register</a>(&genl_foo_ops); } <span class="comment">// ... respectively unregsted again.</span> <span class="keyword">static</span> <span class="keywordtype">void</span> __exit foo_exit(<span class="keywordtype">void</span>) { <a class="code" href="group__genl__mngt.html#ga3fa959e2873bd588fbef31d0dabbf014" title="Unregister generic netlink operations.">genl_unregister</a>(&genl_foo_ops); } </pre></div> </dd></dl> <hr/><h2>Function Documentation</h2> <a class="anchor" id="ga090500dc23450349a7c2861fb3ae5f54"></a><!-- doxytag: member="mngt.c::genl_register" ref="ga090500dc23450349a7c2861fb3ae5f54" args="(struct nl_cache_ops *ops)" --> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname">int genl_register </td> <td>(</td> <td class="paramtype">struct <a class="el" href="structnl__cache__ops.html">nl_cache_ops</a> * </td> <td class="paramname"><em>ops</em></td><td>)</td> <td></td> </tr> </table> </div> <div class="memdoc"> <dl><dt><b>Parameters:</b></dt><dd> <table class="params"> <tr><td class="paramname">ops</td><td>cache operations </td></tr> </table> </dd> </dl> <p>Definition at line <a class="el" href="mngt_8c_source.html#l00172">172</a> of file <a class="el" href="mngt_8c_source.html">mngt.c</a>.</p> <p>References <a class="el" href="cache-api_8h_source.html#l00182">nl_cache_ops::co_msg_parser</a>, <a class="el" href="cache-api_8h_source.html#l00131">nl_msgtype::mt_id</a>, <a class="el" href="cache-api_8h_source.html#l00137">nl_msgtype::mt_name</a>, and <a class="el" href="cache__mngt_8c_source.html#l00127">nl_cache_mngt_register()</a>.</p> <div class="fragment"><pre class="fragment">{ <span class="keywordtype">int</span> err; <span class="keywordflow">if</span> (ops->co_protocol != NETLINK_GENERIC) { err = nl_error(EINVAL, <span class="stringliteral">"cache operations not for protocol "</span> \ <span class="stringliteral">"NETLINK_GENERIC (protocol=%s)"</span>, ops->co_protocol); <span class="keywordflow">goto</span> errout; } <span class="keywordflow">if</span> (ops->co_hdrsize < GENL_HDRSIZE(0)) { err = nl_error(EINVAL, <span class="stringliteral">"co_hdrsize too short, probably "</span> \ <span class="stringliteral">"not including genlmsghdr, minsize=%d"</span>, GENL_HDRSIZE(0)); <span class="keywordflow">goto</span> errout; } <span class="keywordflow">if</span> (ops->co_genl == NULL) { err = nl_error(EINVAL, <span class="stringliteral">"co_genl is NULL, must provide "</span> \ <span class="stringliteral">"valid genl operations"</span>); <span class="keywordflow">goto</span> errout; } ops->co_genl->o_cache_ops = ops; ops->co_genl->o_name = ops->co_msgtypes[0].<a class="code" href="structnl__msgtype.html#a8a50cfe0a76d4bbe95473f5d2a3a5b96" title="Name of operation for human-readable printing.">mt_name</a>; ops->co_genl->o_family = ops->co_msgtypes[0].<a class="code" href="structnl__msgtype.html#a2b51527c3258ef4231b84d856a7c4164" title="Netlink message type.">mt_id</a>; ops-><a class="code" href="structnl__cache__ops.html#aeea6ef6813bb58a76c3d44454271678f" title="Called whenever a message was received that needs to be parsed.">co_msg_parser</a> = genl_msg_parser; <span class="comment">/* FIXME: check for dup */</span> nl_list_add_tail(&ops->co_genl->o_list, &genl_ops_list); err = <a class="code" href="group__cache__mngt.html#ga390eeb1fa61634cf1c216792c6df63c3" title="Register a set of cache operations.">nl_cache_mngt_register</a>(ops); errout: <span class="keywordflow">return</span> err; } </pre></div> </div> </div> <a class="anchor" id="ga3fa959e2873bd588fbef31d0dabbf014"></a><!-- doxytag: member="mngt.c::genl_unregister" ref="ga3fa959e2873bd588fbef31d0dabbf014" args="(struct nl_cache_ops *ops)" --> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname">void genl_unregister </td> <td>(</td> <td class="paramtype">struct <a class="el" href="structnl__cache__ops.html">nl_cache_ops</a> * </td> <td class="paramname"><em>ops</em></td><td>)</td> <td></td> </tr> </table> </div> <div class="memdoc"> <dl><dt><b>Parameters:</b></dt><dd> <table class="params"> <tr><td class="paramname">ops</td><td>cache operations </td></tr> </table> </dd> </dl> <p>Definition at line <a class="el" href="mngt_8c_source.html#l00214">214</a> of file <a class="el" href="mngt_8c_source.html">mngt.c</a>.</p> <p>References <a class="el" href="cache__mngt_8c_source.html#l00157">nl_cache_mngt_unregister()</a>.</p> <div class="fragment"><pre class="fragment">{ <a class="code" href="group__cache__mngt.html#ga09f56b767b3868b7e0cf8559863dde77" title="Unregister a set of cache operations.">nl_cache_mngt_unregister</a>(ops); nl_list_del(&ops->co_genl->o_list); } </pre></div> </div> </div> </div> <hr class="footer"/><address class="footer"><small>Generated on Mon Mar 21 2011 for libnl by  <a href="http://www.doxygen.org/index.html"> <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.3 </small></address> </body> </html>