Sophie

Sophie

distrib > Fedora > 14 > x86_64 > by-pkgid > 87b89b73c41f4440bb86afd421c7548f > files > 91

libnl-devel-1.1-14.fc14.x86_64.rpm

<!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: lib/genl/ctrl.c Source File</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&#160;<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&#160;Page</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
    </ul>
  </div>
<div class="header">
  <div class="headertitle">
<h1>lib/genl/ctrl.c</h1>  </div>
</div>
<div class="contents">
<div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
<a name="l00002"></a>00002 <span class="comment"> * lib/genl/ctrl.c              Generic Netlink Controller</span>
<a name="l00003"></a>00003 <span class="comment"> *</span>
<a name="l00004"></a>00004 <span class="comment"> *      This library is free software; you can redistribute it and/or</span>
<a name="l00005"></a>00005 <span class="comment"> *      modify it under the terms of the GNU Lesser General Public</span>
<a name="l00006"></a>00006 <span class="comment"> *      License as published by the Free Software Foundation version 2.1</span>
<a name="l00007"></a>00007 <span class="comment"> *      of the License.</span>
<a name="l00008"></a>00008 <span class="comment"> *</span>
<a name="l00009"></a>00009 <span class="comment"> * Copyright (c) 2003-2006 Thomas Graf &lt;tgraf@suug.ch&gt;</span>
<a name="l00010"></a>00010 <span class="comment"> */</span>
<a name="l00011"></a>00011 <span class="comment"></span>
<a name="l00012"></a>00012 <span class="comment">/**</span>
<a name="l00013"></a>00013 <span class="comment"> * @ingroup genl_mngt</span>
<a name="l00014"></a>00014 <span class="comment"> * @defgroup ctrl Controller</span>
<a name="l00015"></a>00015 <span class="comment"> * @brief</span>
<a name="l00016"></a>00016 <span class="comment"> *</span>
<a name="l00017"></a>00017 <span class="comment"> * @{</span>
<a name="l00018"></a>00018 <span class="comment"> */</span>
<a name="l00019"></a>00019 
<a name="l00020"></a>00020 <span class="preprocessor">#include &lt;netlink-generic.h&gt;</span>
<a name="l00021"></a>00021 <span class="preprocessor">#include &lt;netlink/netlink.h&gt;</span>
<a name="l00022"></a>00022 <span class="preprocessor">#include &lt;netlink/genl/genl.h&gt;</span>
<a name="l00023"></a>00023 <span class="preprocessor">#include &lt;netlink/genl/family.h&gt;</span>
<a name="l00024"></a>00024 <span class="preprocessor">#include &lt;netlink/genl/mngt.h&gt;</span>
<a name="l00025"></a>00025 <span class="preprocessor">#include &lt;netlink/genl/ctrl.h&gt;</span>
<a name="l00026"></a>00026 <span class="preprocessor">#include &lt;netlink/utils.h&gt;</span>
<a name="l00027"></a>00027 <span class="comment"></span>
<a name="l00028"></a>00028 <span class="comment">/** @cond SKIP */</span>
<a name="l00029"></a>00029 <span class="preprocessor">#define CTRL_VERSION            0x0001</span>
<a name="l00030"></a>00030 <span class="preprocessor"></span>
<a name="l00031"></a>00031 <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_ctrl_ops;<span class="comment"></span>
<a name="l00032"></a>00032 <span class="comment">/** @endcond */</span>
<a name="l00033"></a>00033 
<a name="l00034"></a>00034 <span class="keyword">static</span> <span class="keywordtype">int</span> ctrl_request_update(<span class="keyword">struct</span> nl_cache *c, <span class="keyword">struct</span> nl_handle *h)
<a name="l00035"></a>00035 {
<a name="l00036"></a>00036         <span class="keywordflow">return</span> <a class="code" href="group__genl.html#ga3454e19240e23a023ea469f780d9899d" title="Send trivial generic netlink message.">genl_send_simple</a>(h, GENL_ID_CTRL, CTRL_CMD_GETFAMILY,
<a name="l00037"></a>00037                                 CTRL_VERSION, <a class="code" href="group__msg.html#ga8d4fb2458c013decb6673f41c52c07b1" title="Dump all entries.">NLM_F_DUMP</a>);
<a name="l00038"></a>00038 }
<a name="l00039"></a>00039 
<a name="l00040"></a>00040 <span class="keyword">static</span> <span class="keyword">struct </span><a class="code" href="structnla__policy.html" title="attribute validation policy">nla_policy</a> ctrl_policy[CTRL_ATTR_MAX+1] = {
<a name="l00041"></a>00041         [CTRL_ATTR_FAMILY_ID]   = { .<a class="code" href="structnla__policy.html#aaa36c9d1e298fc9e4ee16a8fb553b32a" title="Type of attribute or NLA_UNSPEC.">type</a> = <a class="code" href="group__attr.html#gga06fc87d81c62e9abb8790b6e5713c55ba8ca718be156e8f388cbcbc4c3d1d874d" title="16bit integer">NLA_U16</a> },
<a name="l00042"></a>00042         [CTRL_ATTR_FAMILY_NAME] = { .type = <a class="code" href="group__attr.html#gga06fc87d81c62e9abb8790b6e5713c55ba284d1eafd6d5d99cedaff3cd5f5a8378" title="character string">NLA_STRING</a>,
<a name="l00043"></a>00043                                     .maxlen = GENL_NAMSIZ },
<a name="l00044"></a>00044         [CTRL_ATTR_VERSION]     = { .type = <a class="code" href="group__attr.html#gga06fc87d81c62e9abb8790b6e5713c55babddb836025b456b06b025c293bff6dc8" title="32bit integer">NLA_U32</a> },
<a name="l00045"></a>00045         [CTRL_ATTR_HDRSIZE]     = { .type = <a class="code" href="group__attr.html#gga06fc87d81c62e9abb8790b6e5713c55babddb836025b456b06b025c293bff6dc8" title="32bit integer">NLA_U32</a> },
<a name="l00046"></a>00046         [CTRL_ATTR_MAXATTR]     = { .type = <a class="code" href="group__attr.html#gga06fc87d81c62e9abb8790b6e5713c55babddb836025b456b06b025c293bff6dc8" title="32bit integer">NLA_U32</a> },
<a name="l00047"></a>00047         [CTRL_ATTR_OPS]         = { .type = <a class="code" href="group__attr.html#gga06fc87d81c62e9abb8790b6e5713c55ba925c06a260a9ffaef80ee4aa13738e19" title="nested attributes">NLA_NESTED</a> },
<a name="l00048"></a>00048 };
<a name="l00049"></a>00049 
<a name="l00050"></a>00050 <span class="keyword">static</span> <span class="keyword">struct </span><a class="code" href="structnla__policy.html" title="attribute validation policy">nla_policy</a> family_op_policy[CTRL_ATTR_OP_MAX+1] = {
<a name="l00051"></a>00051         [CTRL_ATTR_OP_ID]       = { .<a class="code" href="structnla__policy.html#aaa36c9d1e298fc9e4ee16a8fb553b32a" title="Type of attribute or NLA_UNSPEC.">type</a> = <a class="code" href="group__attr.html#gga06fc87d81c62e9abb8790b6e5713c55babddb836025b456b06b025c293bff6dc8" title="32bit integer">NLA_U32</a> },
<a name="l00052"></a>00052         [CTRL_ATTR_OP_FLAGS]    = { .type = <a class="code" href="group__attr.html#gga06fc87d81c62e9abb8790b6e5713c55babddb836025b456b06b025c293bff6dc8" title="32bit integer">NLA_U32</a> },
<a name="l00053"></a>00053 };
<a name="l00054"></a>00054 
<a name="l00055"></a>00055 <span class="keyword">static</span> <span class="keywordtype">int</span> ctrl_msg_parser(<span class="keyword">struct</span> <a class="code" href="structnl__cache__ops.html" title="Cache Operations.">nl_cache_ops</a> *ops, <span class="keyword">struct</span> <a class="code" href="structgenl__cmd.html" title="Generic Netlink Command.">genl_cmd</a> *cmd,
<a name="l00056"></a>00056                            <span class="keyword">struct</span> genl_info *info, <span class="keywordtype">void</span> *arg)
<a name="l00057"></a>00057 {
<a name="l00058"></a>00058         <span class="keyword">struct </span>genl_family *family;
<a name="l00059"></a>00059         <span class="keyword">struct </span><a class="code" href="structnl__parser__param.html">nl_parser_param</a> *pp = arg;
<a name="l00060"></a>00060         <span class="keywordtype">int</span> err;
<a name="l00061"></a>00061 
<a name="l00062"></a>00062         family = genl_family_alloc();
<a name="l00063"></a>00063         <span class="keywordflow">if</span> (family == NULL) {
<a name="l00064"></a>00064                 err = nl_errno(ENOMEM);
<a name="l00065"></a>00065                 <span class="keywordflow">goto</span> errout;
<a name="l00066"></a>00066         }
<a name="l00067"></a>00067 
<a name="l00068"></a>00068         <span class="keywordflow">if</span> (info-&gt;attrs[CTRL_ATTR_FAMILY_NAME] == NULL) {
<a name="l00069"></a>00069                 err = nl_error(EINVAL, <span class="stringliteral">&quot;Missing family name TLV&quot;</span>);
<a name="l00070"></a>00070                 <span class="keywordflow">goto</span> errout;
<a name="l00071"></a>00071         }
<a name="l00072"></a>00072 
<a name="l00073"></a>00073         <span class="keywordflow">if</span> (info-&gt;attrs[CTRL_ATTR_FAMILY_ID] == NULL) {
<a name="l00074"></a>00074                 err = nl_error(EINVAL, <span class="stringliteral">&quot;Missing family id TLV&quot;</span>);
<a name="l00075"></a>00075                 <span class="keywordflow">goto</span> errout;
<a name="l00076"></a>00076         }
<a name="l00077"></a>00077 
<a name="l00078"></a>00078         family-&gt;ce_msgtype = info-&gt;nlh-&gt;nlmsg_type;
<a name="l00079"></a>00079         genl_family_set_id(family,
<a name="l00080"></a>00080                            <a class="code" href="group__attr.html#ga60c1be303721d4a39ad810876a13d304" title="Return payload of u16 attribute.">nla_get_u16</a>(info-&gt;attrs[CTRL_ATTR_FAMILY_ID]));
<a name="l00081"></a>00081         genl_family_set_name(family,
<a name="l00082"></a>00082                      <a class="code" href="group__attr.html#ga99baaa7c85d04eaece8f5eea34d8e2e9" title="return payload of string attribute">nla_get_string</a>(info-&gt;attrs[CTRL_ATTR_FAMILY_NAME]));
<a name="l00083"></a>00083 
<a name="l00084"></a>00084         <span class="keywordflow">if</span> (info-&gt;attrs[CTRL_ATTR_VERSION]) {
<a name="l00085"></a>00085                 uint32_t version = <a class="code" href="group__attr.html#gabda0290a8b26cc577c2c5cefa814aeac" title="Return payload of u32 attribute.">nla_get_u32</a>(info-&gt;attrs[CTRL_ATTR_VERSION]);
<a name="l00086"></a>00086                 genl_family_set_version(family, version);
<a name="l00087"></a>00087         }
<a name="l00088"></a>00088 
<a name="l00089"></a>00089         <span class="keywordflow">if</span> (info-&gt;attrs[CTRL_ATTR_HDRSIZE]) {
<a name="l00090"></a>00090                 uint32_t hdrsize = <a class="code" href="group__attr.html#gabda0290a8b26cc577c2c5cefa814aeac" title="Return payload of u32 attribute.">nla_get_u32</a>(info-&gt;attrs[CTRL_ATTR_HDRSIZE]);
<a name="l00091"></a>00091                 genl_family_set_hdrsize(family, hdrsize);
<a name="l00092"></a>00092         }
<a name="l00093"></a>00093 
<a name="l00094"></a>00094         <span class="keywordflow">if</span> (info-&gt;attrs[CTRL_ATTR_MAXATTR]) {
<a name="l00095"></a>00095                 uint32_t maxattr = <a class="code" href="group__attr.html#gabda0290a8b26cc577c2c5cefa814aeac" title="Return payload of u32 attribute.">nla_get_u32</a>(info-&gt;attrs[CTRL_ATTR_MAXATTR]);
<a name="l00096"></a>00096                 genl_family_set_maxattr(family, maxattr);
<a name="l00097"></a>00097         }
<a name="l00098"></a>00098 
<a name="l00099"></a>00099         <span class="keywordflow">if</span> (info-&gt;attrs[CTRL_ATTR_OPS]) {
<a name="l00100"></a>00100                 <span class="keyword">struct </span>nlattr *nla, *nla_ops;
<a name="l00101"></a>00101                 <span class="keywordtype">int</span> remaining;
<a name="l00102"></a>00102 
<a name="l00103"></a>00103                 nla_ops = info-&gt;attrs[CTRL_ATTR_OPS];
<a name="l00104"></a>00104                 <a class="code" href="group__attr.html#gac2634af90bda4393105b6323da2044fa" title="iterate over a stream of nested attributes">nla_for_each_nested</a>(nla, nla_ops, remaining) {
<a name="l00105"></a>00105                         <span class="keyword">struct </span>nlattr *tb[CTRL_ATTR_OP_MAX+1];
<a name="l00106"></a>00106                         <span class="keywordtype">int</span> flags = 0, id;
<a name="l00107"></a>00107 
<a name="l00108"></a>00108                         err = <a class="code" href="group__attr.html#ga974ec0720b2d863a5c65da868bcb7a6e" title="parse nested attributes">nla_parse_nested</a>(tb, CTRL_ATTR_OP_MAX, nla,
<a name="l00109"></a>00109                                                family_op_policy);
<a name="l00110"></a>00110                         <span class="keywordflow">if</span> (err &lt; 0)
<a name="l00111"></a>00111                                 <span class="keywordflow">goto</span> errout;
<a name="l00112"></a>00112 
<a name="l00113"></a>00113                         <span class="keywordflow">if</span> (tb[CTRL_ATTR_OP_ID] == NULL) {
<a name="l00114"></a>00114                                 err = nl_errno(EINVAL);
<a name="l00115"></a>00115                                 <span class="keywordflow">goto</span> errout;
<a name="l00116"></a>00116                         }
<a name="l00117"></a>00117                         
<a name="l00118"></a>00118                         <span class="keywordtype">id</span> = <a class="code" href="group__attr.html#gabda0290a8b26cc577c2c5cefa814aeac" title="Return payload of u32 attribute.">nla_get_u32</a>(tb[CTRL_ATTR_OP_ID]);
<a name="l00119"></a>00119 
<a name="l00120"></a>00120                         <span class="keywordflow">if</span> (tb[CTRL_ATTR_OP_FLAGS])
<a name="l00121"></a>00121                                 flags = <a class="code" href="group__attr.html#gabda0290a8b26cc577c2c5cefa814aeac" title="Return payload of u32 attribute.">nla_get_u32</a>(tb[CTRL_ATTR_OP_FLAGS]);
<a name="l00122"></a>00122 
<a name="l00123"></a>00123                         err = genl_family_add_op(family, <span class="keywordtype">id</span>, flags);
<a name="l00124"></a>00124                         <span class="keywordflow">if</span> (err &lt; 0)
<a name="l00125"></a>00125                                 <span class="keywordflow">goto</span> errout;
<a name="l00126"></a>00126 
<a name="l00127"></a>00127                 }
<a name="l00128"></a>00128         }
<a name="l00129"></a>00129 
<a name="l00130"></a>00130         err = pp-&gt;pp_cb((<span class="keyword">struct</span> nl_object *) family, pp);
<a name="l00131"></a>00131         <span class="keywordflow">if</span> (err &lt; 0)
<a name="l00132"></a>00132                 <span class="keywordflow">goto</span> errout;
<a name="l00133"></a>00133 
<a name="l00134"></a>00134         err = P_ACCEPT;
<a name="l00135"></a>00135 
<a name="l00136"></a>00136 errout:
<a name="l00137"></a>00137         genl_family_put(family);
<a name="l00138"></a>00138         <span class="keywordflow">return</span> err;
<a name="l00139"></a>00139 }
<a name="l00140"></a>00140 <span class="comment"></span>
<a name="l00141"></a>00141 <span class="comment">/**</span>
<a name="l00142"></a>00142 <span class="comment"> * @name Cache Management</span>
<a name="l00143"></a>00143 <span class="comment"> * @{</span>
<a name="l00144"></a>00144 <span class="comment"> */</span>
<a name="l00145"></a>00145 
<a name="l00146"></a>00146 <span class="keyword">struct </span>nl_cache *genl_ctrl_alloc_cache(<span class="keyword">struct</span> nl_handle *handle)
<a name="l00147"></a>00147 {
<a name="l00148"></a>00148         <span class="keyword">struct </span>nl_cache * cache;
<a name="l00149"></a>00149         
<a name="l00150"></a>00150         cache = <a class="code" href="group__cache.html#ga9520ae0f2158db3c081f34c851d92252" title="Allocate an empty cache.">nl_cache_alloc</a>(&amp;genl_ctrl_ops);
<a name="l00151"></a>00151         <span class="keywordflow">if</span> (cache == NULL)
<a name="l00152"></a>00152                 <span class="keywordflow">return</span> NULL;
<a name="l00153"></a>00153         
<a name="l00154"></a>00154         <span class="keywordflow">if</span> (handle &amp;&amp; <a class="code" href="group__cache.html#gaf5bd584017847e6ef69ec36739a6aaf0" title="(Re)fill a cache with the contents in the kernel.">nl_cache_refill</a>(handle, cache) &lt; 0) {
<a name="l00155"></a>00155                 <a class="code" href="group__cache.html#ga530c896db26d72001d011114b1e6cfaa" title="Free a cache.">nl_cache_free</a>(cache);
<a name="l00156"></a>00156                 <span class="keywordflow">return</span> NULL;
<a name="l00157"></a>00157         }
<a name="l00158"></a>00158 
<a name="l00159"></a>00159         <span class="keywordflow">return</span> cache;
<a name="l00160"></a>00160 }
<a name="l00161"></a>00161 <span class="comment"></span>
<a name="l00162"></a>00162 <span class="comment">/**</span>
<a name="l00163"></a>00163 <span class="comment"> * Look up generic netlink family by id in the provided cache.</span>
<a name="l00164"></a>00164 <span class="comment"> * @arg cache           Generic netlink family cache.</span>
<a name="l00165"></a>00165 <span class="comment"> * @arg id              Family identifier.</span>
<a name="l00166"></a>00166 <span class="comment"> *</span>
<a name="l00167"></a>00167 <span class="comment"> * Searches through the cache looking for a registered family</span>
<a name="l00168"></a>00168 <span class="comment"> * matching the specified identifier. The caller will own a</span>
<a name="l00169"></a>00169 <span class="comment"> * reference on the returned object which needs to be given</span>
<a name="l00170"></a>00170 <span class="comment"> * back after usage using genl_family_put().</span>
<a name="l00171"></a>00171 <span class="comment"> *</span>
<a name="l00172"></a>00172 <span class="comment"> * @return Generic netlink family object or NULL if no match was found.</span>
<a name="l00173"></a>00173 <span class="comment"> */</span>
<a name="l00174"></a><a class="code" href="group__ctrl.html#ga0b2f0bb288b9e0f4ad3159a5db881e27">00174</a> <span class="keyword">struct </span>genl_family *<a class="code" href="group__ctrl.html#ga0b2f0bb288b9e0f4ad3159a5db881e27" title="Look up generic netlink family by id in the provided cache.">genl_ctrl_search</a>(<span class="keyword">struct</span> nl_cache *cache, <span class="keywordtype">int</span> <span class="keywordtype">id</span>)
<a name="l00175"></a>00175 {
<a name="l00176"></a>00176         <span class="keyword">struct </span>genl_family *fam;
<a name="l00177"></a>00177 
<a name="l00178"></a>00178         <span class="keywordflow">if</span> (cache-&gt;c_ops != &amp;genl_ctrl_ops)
<a name="l00179"></a>00179                 BUG();
<a name="l00180"></a>00180 
<a name="l00181"></a>00181         nl_list_for_each_entry(fam, &amp;cache-&gt;c_items, ce_list) {
<a name="l00182"></a>00182                 <span class="keywordflow">if</span> (fam-&gt;gf_id == <span class="keywordtype">id</span>) {
<a name="l00183"></a>00183                         <a class="code" href="group__object.html#gabd5767ac47ec6f09d1ac643f44eb8bfd" title="Acquire a reference on a object.">nl_object_get</a>((<span class="keyword">struct</span> nl_object *) fam);
<a name="l00184"></a>00184                         <span class="keywordflow">return</span> fam;
<a name="l00185"></a>00185                 }
<a name="l00186"></a>00186         }
<a name="l00187"></a>00187 
<a name="l00188"></a>00188         <span class="keywordflow">return</span> NULL;
<a name="l00189"></a>00189 }
<a name="l00190"></a>00190 <span class="comment"></span>
<a name="l00191"></a>00191 <span class="comment">/**</span>
<a name="l00192"></a>00192 <span class="comment"> * @name Resolver</span>
<a name="l00193"></a>00193 <span class="comment"> * @{</span>
<a name="l00194"></a>00194 <span class="comment"> */</span>
<a name="l00195"></a>00195 <span class="comment"></span>
<a name="l00196"></a>00196 <span class="comment">/**</span>
<a name="l00197"></a>00197 <span class="comment"> * Look up generic netlink family by family name in the provided cache.</span>
<a name="l00198"></a>00198 <span class="comment"> * @arg cache           Generic netlink family cache.</span>
<a name="l00199"></a>00199 <span class="comment"> * @arg name            Family name.</span>
<a name="l00200"></a>00200 <span class="comment"> *</span>
<a name="l00201"></a>00201 <span class="comment"> * Searches through the cache looking for a registered family</span>
<a name="l00202"></a>00202 <span class="comment"> * matching the specified name. The caller will own a reference</span>
<a name="l00203"></a>00203 <span class="comment"> * on the returned object which needs to be given back after</span>
<a name="l00204"></a>00204 <span class="comment"> * usage using genl_family_put().</span>
<a name="l00205"></a>00205 <span class="comment"> *</span>
<a name="l00206"></a>00206 <span class="comment"> * @return Generic netlink family object or NULL if no match was found.</span>
<a name="l00207"></a>00207 <span class="comment"> */</span>
<a name="l00208"></a><a class="code" href="group__ctrl.html#ga8546fd167091c03774f530bc56e8e544">00208</a> <span class="keyword">struct </span>genl_family *<a class="code" href="group__ctrl.html#ga8546fd167091c03774f530bc56e8e544" title="Look up generic netlink family by family name in the provided cache.">genl_ctrl_search_by_name</a>(<span class="keyword">struct</span> nl_cache *cache,
<a name="l00209"></a>00209                                             <span class="keyword">const</span> <span class="keywordtype">char</span> *name)
<a name="l00210"></a>00210 {
<a name="l00211"></a>00211         <span class="keyword">struct </span>genl_family *fam;
<a name="l00212"></a>00212 
<a name="l00213"></a>00213         <span class="keywordflow">if</span> (cache-&gt;c_ops != &amp;genl_ctrl_ops)
<a name="l00214"></a>00214                 BUG();
<a name="l00215"></a>00215 
<a name="l00216"></a>00216         nl_list_for_each_entry(fam, &amp;cache-&gt;c_items, ce_list) {
<a name="l00217"></a>00217                 <span class="keywordflow">if</span> (!strcmp(name, fam-&gt;gf_name)) {
<a name="l00218"></a>00218                         <a class="code" href="group__object.html#gabd5767ac47ec6f09d1ac643f44eb8bfd" title="Acquire a reference on a object.">nl_object_get</a>((<span class="keyword">struct</span> nl_object *) fam);
<a name="l00219"></a>00219                         <span class="keywordflow">return</span> fam;
<a name="l00220"></a>00220                 }
<a name="l00221"></a>00221         }
<a name="l00222"></a>00222 
<a name="l00223"></a>00223         <span class="keywordflow">return</span> NULL;
<a name="l00224"></a>00224 }
<a name="l00225"></a>00225 <span class="comment"></span>
<a name="l00226"></a>00226 <span class="comment">/** @} */</span>
<a name="l00227"></a>00227 <span class="comment"></span>
<a name="l00228"></a>00228 <span class="comment">/**</span>
<a name="l00229"></a>00229 <span class="comment"> * Resolve generic netlink family name to its identifier</span>
<a name="l00230"></a>00230 <span class="comment"> * @arg handle          Netlink Handle</span>
<a name="l00231"></a>00231 <span class="comment"> * @arg name            Name of generic netlink family</span>
<a name="l00232"></a>00232 <span class="comment"> *</span>
<a name="l00233"></a>00233 <span class="comment"> * Resolves the generic netlink family name to its identifer and returns</span>
<a name="l00234"></a>00234 <span class="comment"> * it.</span>
<a name="l00235"></a>00235 <span class="comment"> *</span>
<a name="l00236"></a>00236 <span class="comment"> * @return A positive identifier or a negative error code.</span>
<a name="l00237"></a>00237 <span class="comment"> */</span>
<a name="l00238"></a><a class="code" href="group__ctrl.html#ga765fbbec4a11e318a286f743da89ff47">00238</a> <span class="keywordtype">int</span> <a class="code" href="group__ctrl.html#ga765fbbec4a11e318a286f743da89ff47" title="Resolve generic netlink family name to its identifier.">genl_ctrl_resolve</a>(<span class="keyword">struct</span> nl_handle *handle, <span class="keyword">const</span> <span class="keywordtype">char</span> *name)
<a name="l00239"></a>00239 {
<a name="l00240"></a>00240         <span class="keyword">struct </span>nl_cache *cache;
<a name="l00241"></a>00241         <span class="keyword">struct </span>genl_family *family;
<a name="l00242"></a>00242         <span class="keywordtype">int</span> err;
<a name="l00243"></a>00243 
<a name="l00244"></a>00244         cache = genl_ctrl_alloc_cache(handle);
<a name="l00245"></a>00245         <span class="keywordflow">if</span> (cache == NULL)
<a name="l00246"></a>00246                 <span class="keywordflow">return</span> nl_get_errno();
<a name="l00247"></a>00247 
<a name="l00248"></a>00248         family = <a class="code" href="group__ctrl.html#ga8546fd167091c03774f530bc56e8e544" title="Look up generic netlink family by family name in the provided cache.">genl_ctrl_search_by_name</a>(cache, name);
<a name="l00249"></a>00249         <span class="keywordflow">if</span> (family == NULL) {
<a name="l00250"></a>00250                 err = nl_error(ENOENT, <span class="stringliteral">&quot;Generic Netlink Family not found&quot;</span>);
<a name="l00251"></a>00251                 <span class="keywordflow">goto</span> errout;
<a name="l00252"></a>00252         }
<a name="l00253"></a>00253 
<a name="l00254"></a>00254         err = genl_family_get_id(family);
<a name="l00255"></a>00255         genl_family_put(family);
<a name="l00256"></a>00256 errout:
<a name="l00257"></a>00257         <a class="code" href="group__cache.html#ga530c896db26d72001d011114b1e6cfaa" title="Free a cache.">nl_cache_free</a>(cache);
<a name="l00258"></a>00258 
<a name="l00259"></a>00259         <span class="keywordflow">return</span> err;
<a name="l00260"></a>00260 }
<a name="l00261"></a>00261 <span class="comment"></span>
<a name="l00262"></a>00262 <span class="comment">/** @} */</span>
<a name="l00263"></a>00263 
<a name="l00264"></a>00264 <span class="keyword">static</span> <span class="keyword">struct </span><a class="code" href="structgenl__cmd.html" title="Generic Netlink Command.">genl_cmd</a> genl_cmds[] = {
<a name="l00265"></a>00265         {
<a name="l00266"></a>00266                 .<a class="code" href="structgenl__cmd.html#a44973cc65dbac22f07415820d33bc75e" title="Unique command identifier.">c_id</a>           = CTRL_CMD_NEWFAMILY,
<a name="l00267"></a>00267                 .c_name         = <span class="stringliteral">&quot;NEWFAMILY&quot;</span> ,
<a name="l00268"></a>00268                 .c_maxattr      = CTRL_ATTR_MAX,
<a name="l00269"></a>00269                 .c_attr_policy  = ctrl_policy,
<a name="l00270"></a>00270                 .c_msg_parser   = ctrl_msg_parser,
<a name="l00271"></a>00271         },
<a name="l00272"></a>00272         {
<a name="l00273"></a>00273                 .c_id           = CTRL_CMD_DELFAMILY,
<a name="l00274"></a>00274                 .c_name         = <span class="stringliteral">&quot;DELFAMILY&quot;</span> ,
<a name="l00275"></a>00275         },
<a name="l00276"></a>00276         {
<a name="l00277"></a>00277                 .c_id           = CTRL_CMD_GETFAMILY,
<a name="l00278"></a>00278                 .c_name         = <span class="stringliteral">&quot;GETFAMILY&quot;</span> ,
<a name="l00279"></a>00279         },
<a name="l00280"></a>00280         {
<a name="l00281"></a>00281                 .c_id           = CTRL_CMD_NEWOPS,
<a name="l00282"></a>00282                 .c_name         = <span class="stringliteral">&quot;NEWOPS&quot;</span> ,
<a name="l00283"></a>00283         },
<a name="l00284"></a>00284         {
<a name="l00285"></a>00285                 .c_id           = CTRL_CMD_DELOPS,
<a name="l00286"></a>00286                 .c_name         = <span class="stringliteral">&quot;DELOPS&quot;</span> ,
<a name="l00287"></a>00287         },
<a name="l00288"></a>00288 };
<a name="l00289"></a>00289 
<a name="l00290"></a>00290 <span class="keyword">static</span> <span class="keyword">struct </span><a class="code" href="structgenl__ops.html" title="Generic Netlink Operations.">genl_ops</a> <a class="code" href="structgenl__ops.html" title="Generic Netlink Operations.">genl_ops</a> = {
<a name="l00291"></a>00291         .o_cmds                 = genl_cmds,
<a name="l00292"></a>00292         .o_ncmds                = ARRAY_SIZE(genl_cmds),
<a name="l00293"></a>00293 };
<a name="l00294"></a>00294 <span class="comment"></span>
<a name="l00295"></a>00295 <span class="comment">/** @cond SKIP */</span>
<a name="l00296"></a>00296 <span class="keyword">extern</span> <span class="keyword">struct </span><a class="code" href="structnl__object__ops.html" title="Object Operations.">nl_object_ops</a> genl_family_ops;<span class="comment"></span>
<a name="l00297"></a>00297 <span class="comment">/** @endcond */</span>
<a name="l00298"></a>00298 
<a name="l00299"></a>00299 <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_ctrl_ops = {
<a name="l00300"></a>00300         .co_name                = <span class="stringliteral">&quot;genl/family&quot;</span>,
<a name="l00301"></a>00301         .co_hdrsize             = GENL_HDRSIZE(0),
<a name="l00302"></a>00302         .co_msgtypes            = GENL_FAMILY(GENL_ID_CTRL, <span class="stringliteral">&quot;nlctrl&quot;</span>),
<a name="l00303"></a>00303         .co_genl                = &amp;genl_ops,
<a name="l00304"></a>00304         .co_protocol            = NETLINK_GENERIC,
<a name="l00305"></a>00305         .co_request_update      = ctrl_request_update,
<a name="l00306"></a>00306         .co_obj_ops             = &amp;genl_family_ops,
<a name="l00307"></a>00307 };
<a name="l00308"></a>00308 
<a name="l00309"></a>00309 <span class="keyword">static</span> <span class="keywordtype">void</span> __init ctrl_init(<span class="keywordtype">void</span>)
<a name="l00310"></a>00310 {
<a name="l00311"></a>00311         <a class="code" href="group__genl__mngt.html#ga090500dc23450349a7c2861fb3ae5f54" title="Register generic netlink operations.">genl_register</a>(&amp;genl_ctrl_ops);
<a name="l00312"></a>00312 }
<a name="l00313"></a>00313 
<a name="l00314"></a>00314 <span class="keyword">static</span> <span class="keywordtype">void</span> __exit ctrl_exit(<span class="keywordtype">void</span>)
<a name="l00315"></a>00315 {
<a name="l00316"></a>00316         <a class="code" href="group__genl__mngt.html#ga3fa959e2873bd588fbef31d0dabbf014" title="Unregister generic netlink operations.">genl_unregister</a>(&amp;genl_ctrl_ops);
<a name="l00317"></a>00317 }
<a name="l00318"></a>00318 <span class="comment"></span>
<a name="l00319"></a>00319 <span class="comment">/** @} */</span>
</pre></div></div>
</div>
<hr class="footer"/><address class="footer"><small>Generated on Mon Mar 21 2011 for libnl by&#160;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.3 </small></address>
</body>
</html>