Sophie

Sophie

distrib > Fedora > 14 > x86_64 > media > updates > by-pkgid > 87b89b73c41f4440bb86afd421c7548f > files > 88

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/netfilter/ct.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/netfilter/ct.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/netfilter/ct.c   Conntrack</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"> * Copyright (c) 2007 Philip Craig &lt;philipc@snapgear.com&gt;</span>
<a name="l00011"></a>00011 <span class="comment"> * Copyright (c) 2007 Secure Computing Corporation</span>
<a name="l00012"></a>00012 <span class="comment"> */</span>
<a name="l00013"></a>00013 <span class="comment"></span>
<a name="l00014"></a>00014 <span class="comment">/**</span>
<a name="l00015"></a>00015 <span class="comment"> * @ingroup nfnl</span>
<a name="l00016"></a>00016 <span class="comment"> * @defgroup ct Conntrack</span>
<a name="l00017"></a>00017 <span class="comment"> * @brief</span>
<a name="l00018"></a>00018 <span class="comment"> * @{</span>
<a name="l00019"></a>00019 <span class="comment"> */</span>
<a name="l00020"></a>00020 
<a name="l00021"></a>00021 <span class="preprocessor">#include &lt;byteswap.h&gt;</span>
<a name="l00022"></a>00022 <span class="preprocessor">#include &lt;sys/types.h&gt;</span>
<a name="l00023"></a>00023 <span class="preprocessor">#include &lt;linux/netfilter/nfnetlink_conntrack.h&gt;</span>
<a name="l00024"></a>00024 
<a name="l00025"></a>00025 <span class="preprocessor">#include &lt;netlink-local.h&gt;</span>
<a name="l00026"></a>00026 <span class="preprocessor">#include &lt;netlink/attr.h&gt;</span>
<a name="l00027"></a>00027 <span class="preprocessor">#include &lt;netlink/netfilter/nfnl.h&gt;</span>
<a name="l00028"></a>00028 <span class="preprocessor">#include &lt;netlink/netfilter/ct.h&gt;</span>
<a name="l00029"></a>00029 
<a name="l00030"></a>00030 <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> nfnl_ct_ops;
<a name="l00031"></a>00031 
<a name="l00032"></a>00032 <span class="preprocessor">#if __BYTE_ORDER == __BIG_ENDIAN</span>
<a name="l00033"></a>00033 <span class="preprocessor"></span><span class="keyword">static</span> uint64_t ntohll(uint64_t x)
<a name="l00034"></a>00034 {
<a name="l00035"></a>00035         <span class="keywordflow">return</span> x;
<a name="l00036"></a>00036 }
<a name="l00037"></a>00037 <span class="preprocessor">#elif __BYTE_ORDER == __LITTLE_ENDIAN</span>
<a name="l00038"></a>00038 <span class="preprocessor"></span><span class="keyword">static</span> uint64_t ntohll(uint64_t x)
<a name="l00039"></a>00039 {
<a name="l00040"></a>00040         <span class="keywordflow">return</span> __bswap_64(x);
<a name="l00041"></a>00041 }
<a name="l00042"></a>00042 <span class="preprocessor">#endif</span>
<a name="l00043"></a>00043 <span class="preprocessor"></span>
<a name="l00044"></a>00044 <span class="keyword">static</span> <span class="keyword">struct </span><a class="code" href="structnla__policy.html" title="attribute validation policy">nla_policy</a> ct_policy[CTA_MAX+1] = {
<a name="l00045"></a>00045         [CTA_TUPLE_ORIG]        = { .<a class="code" href="structnla__policy.html#aaa36c9d1e298fc9e4ee16a8fb553b32a" title="Type of attribute or NLA_UNSPEC.">type</a> = <a class="code" href="group__attr.html#gga06fc87d81c62e9abb8790b6e5713c55ba925c06a260a9ffaef80ee4aa13738e19" title="nested attributes">NLA_NESTED</a> },
<a name="l00046"></a>00046         [CTA_TUPLE_REPLY]       = { .type = <a class="code" href="group__attr.html#gga06fc87d81c62e9abb8790b6e5713c55ba925c06a260a9ffaef80ee4aa13738e19" title="nested attributes">NLA_NESTED</a> },
<a name="l00047"></a>00047         [CTA_STATUS]            = { .type = <a class="code" href="group__attr.html#gga06fc87d81c62e9abb8790b6e5713c55babddb836025b456b06b025c293bff6dc8" title="32bit integer">NLA_U32</a> },
<a name="l00048"></a>00048         [CTA_PROTOINFO]         = { .type = <a class="code" href="group__attr.html#gga06fc87d81c62e9abb8790b6e5713c55ba925c06a260a9ffaef80ee4aa13738e19" title="nested attributes">NLA_NESTED</a> },
<a name="l00049"></a>00049         <span class="comment">//[CTA_HELP]</span>
<a name="l00050"></a>00050         <span class="comment">//[CTA_NAT_SRC]</span>
<a name="l00051"></a>00051         [CTA_TIMEOUT]           = { .type = <a class="code" href="group__attr.html#gga06fc87d81c62e9abb8790b6e5713c55babddb836025b456b06b025c293bff6dc8" title="32bit integer">NLA_U32</a> },
<a name="l00052"></a>00052         [CTA_MARK]              = { .type = <a class="code" href="group__attr.html#gga06fc87d81c62e9abb8790b6e5713c55babddb836025b456b06b025c293bff6dc8" title="32bit integer">NLA_U32</a> },
<a name="l00053"></a>00053         [CTA_COUNTERS_ORIG]     = { .type = <a class="code" href="group__attr.html#gga06fc87d81c62e9abb8790b6e5713c55ba925c06a260a9ffaef80ee4aa13738e19" title="nested attributes">NLA_NESTED</a> },
<a name="l00054"></a>00054         [CTA_COUNTERS_REPLY]    = { .type = <a class="code" href="group__attr.html#gga06fc87d81c62e9abb8790b6e5713c55ba925c06a260a9ffaef80ee4aa13738e19" title="nested attributes">NLA_NESTED</a> },
<a name="l00055"></a>00055         [CTA_USE]               = { .type = <a class="code" href="group__attr.html#gga06fc87d81c62e9abb8790b6e5713c55babddb836025b456b06b025c293bff6dc8" title="32bit integer">NLA_U32</a> },
<a name="l00056"></a>00056         [CTA_ID]                = { .type = <a class="code" href="group__attr.html#gga06fc87d81c62e9abb8790b6e5713c55babddb836025b456b06b025c293bff6dc8" title="32bit integer">NLA_U32</a> },
<a name="l00057"></a>00057         <span class="comment">//[CTA_NAT_DST]</span>
<a name="l00058"></a>00058 };
<a name="l00059"></a>00059 
<a name="l00060"></a>00060 <span class="keyword">static</span> <span class="keyword">struct </span><a class="code" href="structnla__policy.html" title="attribute validation policy">nla_policy</a> ct_tuple_policy[CTA_TUPLE_MAX+1] = {
<a name="l00061"></a>00061         [CTA_TUPLE_IP]          = { .<a class="code" href="structnla__policy.html#aaa36c9d1e298fc9e4ee16a8fb553b32a" title="Type of attribute or NLA_UNSPEC.">type</a> = <a class="code" href="group__attr.html#gga06fc87d81c62e9abb8790b6e5713c55ba925c06a260a9ffaef80ee4aa13738e19" title="nested attributes">NLA_NESTED</a> },
<a name="l00062"></a>00062         [CTA_TUPLE_PROTO]       = { .type = <a class="code" href="group__attr.html#gga06fc87d81c62e9abb8790b6e5713c55ba925c06a260a9ffaef80ee4aa13738e19" title="nested attributes">NLA_NESTED</a> },
<a name="l00063"></a>00063 };
<a name="l00064"></a>00064 
<a name="l00065"></a>00065 <span class="keyword">static</span> <span class="keyword">struct </span><a class="code" href="structnla__policy.html" title="attribute validation policy">nla_policy</a> ct_ip_policy[CTA_IP_MAX+1] = {
<a name="l00066"></a>00066         [CTA_IP_V4_SRC]         = { .<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="l00067"></a>00067         [CTA_IP_V4_DST]         = { .type = <a class="code" href="group__attr.html#gga06fc87d81c62e9abb8790b6e5713c55babddb836025b456b06b025c293bff6dc8" title="32bit integer">NLA_U32</a> },
<a name="l00068"></a>00068         [CTA_IP_V6_SRC]         = { .minlen = 16 },
<a name="l00069"></a>00069         [CTA_IP_V6_DST]         = { .minlen = 16 },
<a name="l00070"></a>00070 };
<a name="l00071"></a>00071 
<a name="l00072"></a>00072 <span class="keyword">static</span> <span class="keyword">struct </span><a class="code" href="structnla__policy.html" title="attribute validation policy">nla_policy</a> ct_proto_policy[CTA_PROTO_MAX+1] = {
<a name="l00073"></a>00073         [CTA_PROTO_NUM]         = { .<a class="code" href="structnla__policy.html#aaa36c9d1e298fc9e4ee16a8fb553b32a" title="Type of attribute or NLA_UNSPEC.">type</a> = <a class="code" href="group__attr.html#gga06fc87d81c62e9abb8790b6e5713c55ba5e9fb615f67cd1b0232f82f978d76b39" title="8bit integer">NLA_U8</a> },
<a name="l00074"></a>00074         [CTA_PROTO_SRC_PORT]    = { .type = <a class="code" href="group__attr.html#gga06fc87d81c62e9abb8790b6e5713c55ba8ca718be156e8f388cbcbc4c3d1d874d" title="16bit integer">NLA_U16</a> },
<a name="l00075"></a>00075         [CTA_PROTO_DST_PORT]    = { .type = <a class="code" href="group__attr.html#gga06fc87d81c62e9abb8790b6e5713c55ba8ca718be156e8f388cbcbc4c3d1d874d" title="16bit integer">NLA_U16</a> },
<a name="l00076"></a>00076         [CTA_PROTO_ICMP_ID]     = { .type = <a class="code" href="group__attr.html#gga06fc87d81c62e9abb8790b6e5713c55ba8ca718be156e8f388cbcbc4c3d1d874d" title="16bit integer">NLA_U16</a> },
<a name="l00077"></a>00077         [CTA_PROTO_ICMP_TYPE]   = { .type = <a class="code" href="group__attr.html#gga06fc87d81c62e9abb8790b6e5713c55ba5e9fb615f67cd1b0232f82f978d76b39" title="8bit integer">NLA_U8</a> },
<a name="l00078"></a>00078         [CTA_PROTO_ICMP_CODE]   = { .type = <a class="code" href="group__attr.html#gga06fc87d81c62e9abb8790b6e5713c55ba5e9fb615f67cd1b0232f82f978d76b39" title="8bit integer">NLA_U8</a> },
<a name="l00079"></a>00079         [CTA_PROTO_ICMPV6_ID]   = { .type = <a class="code" href="group__attr.html#gga06fc87d81c62e9abb8790b6e5713c55ba8ca718be156e8f388cbcbc4c3d1d874d" title="16bit integer">NLA_U16</a> },
<a name="l00080"></a>00080         [CTA_PROTO_ICMPV6_TYPE] = { .type = <a class="code" href="group__attr.html#gga06fc87d81c62e9abb8790b6e5713c55ba5e9fb615f67cd1b0232f82f978d76b39" title="8bit integer">NLA_U8</a> },
<a name="l00081"></a>00081         [CTA_PROTO_ICMPV6_CODE] = { .type = <a class="code" href="group__attr.html#gga06fc87d81c62e9abb8790b6e5713c55ba5e9fb615f67cd1b0232f82f978d76b39" title="8bit integer">NLA_U8</a> },
<a name="l00082"></a>00082 };
<a name="l00083"></a>00083 
<a name="l00084"></a>00084 <span class="keyword">static</span> <span class="keyword">struct </span><a class="code" href="structnla__policy.html" title="attribute validation policy">nla_policy</a> ct_protoinfo_policy[CTA_PROTOINFO_MAX+1] = {
<a name="l00085"></a>00085         [CTA_PROTOINFO_TCP]     = { .<a class="code" href="structnla__policy.html#aaa36c9d1e298fc9e4ee16a8fb553b32a" title="Type of attribute or NLA_UNSPEC.">type</a> = <a class="code" href="group__attr.html#gga06fc87d81c62e9abb8790b6e5713c55ba925c06a260a9ffaef80ee4aa13738e19" title="nested attributes">NLA_NESTED</a> },
<a name="l00086"></a>00086 };
<a name="l00087"></a>00087 
<a name="l00088"></a>00088 <span class="keyword">static</span> <span class="keyword">struct </span><a class="code" href="structnla__policy.html" title="attribute validation policy">nla_policy</a> ct_protoinfo_tcp_policy[CTA_PROTOINFO_TCP_MAX+1] = {
<a name="l00089"></a>00089         [CTA_PROTOINFO_TCP_STATE]               = { .<a class="code" href="structnla__policy.html#aaa36c9d1e298fc9e4ee16a8fb553b32a" title="Type of attribute or NLA_UNSPEC.">type</a> = <a class="code" href="group__attr.html#gga06fc87d81c62e9abb8790b6e5713c55ba5e9fb615f67cd1b0232f82f978d76b39" title="8bit integer">NLA_U8</a> },
<a name="l00090"></a>00090         [CTA_PROTOINFO_TCP_WSCALE_ORIGINAL]     = { .type = <a class="code" href="group__attr.html#gga06fc87d81c62e9abb8790b6e5713c55ba5e9fb615f67cd1b0232f82f978d76b39" title="8bit integer">NLA_U8</a> },
<a name="l00091"></a>00091         [CTA_PROTOINFO_TCP_WSCALE_REPLY]        = { .type = <a class="code" href="group__attr.html#gga06fc87d81c62e9abb8790b6e5713c55ba5e9fb615f67cd1b0232f82f978d76b39" title="8bit integer">NLA_U8</a> },
<a name="l00092"></a>00092         [CTA_PROTOINFO_TCP_FLAGS_ORIGINAL]      = { .minlen = 2 },
<a name="l00093"></a>00093         [CTA_PROTOINFO_TCP_FLAGS_REPLY]         = { .minlen = 2 },
<a name="l00094"></a>00094 
<a name="l00095"></a>00095 };
<a name="l00096"></a>00096 
<a name="l00097"></a>00097 <span class="keyword">static</span> <span class="keyword">struct </span><a class="code" href="structnla__policy.html" title="attribute validation policy">nla_policy</a> ct_counters_policy[CTA_COUNTERS_MAX+1] = {
<a name="l00098"></a>00098         [CTA_COUNTERS_PACKETS]  = { .<a class="code" href="structnla__policy.html#aaa36c9d1e298fc9e4ee16a8fb553b32a" title="Type of attribute or NLA_UNSPEC.">type</a> = <a class="code" href="group__attr.html#gga06fc87d81c62e9abb8790b6e5713c55ba210e5e3c0d9281fbe9481092ba2ef201" title="64bit integer">NLA_U64</a> },
<a name="l00099"></a>00099         [CTA_COUNTERS_BYTES]    = { .type = <a class="code" href="group__attr.html#gga06fc87d81c62e9abb8790b6e5713c55ba210e5e3c0d9281fbe9481092ba2ef201" title="64bit integer">NLA_U64</a> },
<a name="l00100"></a>00100         [CTA_COUNTERS32_PACKETS]= { .type = <a class="code" href="group__attr.html#gga06fc87d81c62e9abb8790b6e5713c55babddb836025b456b06b025c293bff6dc8" title="32bit integer">NLA_U32</a> },
<a name="l00101"></a>00101         [CTA_COUNTERS32_BYTES]  = { .type = <a class="code" href="group__attr.html#gga06fc87d81c62e9abb8790b6e5713c55babddb836025b456b06b025c293bff6dc8" title="32bit integer">NLA_U32</a> },
<a name="l00102"></a>00102 };
<a name="l00103"></a>00103 
<a name="l00104"></a>00104 <span class="keyword">static</span> <span class="keywordtype">int</span> ct_parse_ip(<span class="keyword">struct</span> nfnl_ct *ct, <span class="keywordtype">int</span> repl, <span class="keyword">struct</span> nlattr *attr)
<a name="l00105"></a>00105 {
<a name="l00106"></a>00106         <span class="keyword">struct </span>nlattr *tb[CTA_IP_MAX+1];
<a name="l00107"></a>00107         <span class="keyword">struct </span>nl_addr *addr;
<a name="l00108"></a>00108         <span class="keywordtype">int</span> err;
<a name="l00109"></a>00109 
<a name="l00110"></a>00110         err = <a class="code" href="group__attr.html#ga974ec0720b2d863a5c65da868bcb7a6e" title="parse nested attributes">nla_parse_nested</a>(tb, CTA_IP_MAX, attr, ct_ip_policy);
<a name="l00111"></a>00111         <span class="keywordflow">if</span> (err &lt; 0)
<a name="l00112"></a>00112                 <span class="keywordflow">goto</span> errout;
<a name="l00113"></a>00113 
<a name="l00114"></a>00114         <span class="keywordflow">if</span> (tb[CTA_IP_V4_SRC]) {
<a name="l00115"></a>00115                 addr = <a class="code" href="group__attr.html#ga98a5ac1eefea9266cf46c91b9a9867f3" title="Return payload of address attribute.">nla_get_addr</a>(tb[CTA_IP_V4_SRC], AF_INET);
<a name="l00116"></a>00116                 <span class="keywordflow">if</span> (addr == NULL)
<a name="l00117"></a>00117                         <span class="keywordflow">goto</span> errout_errno;
<a name="l00118"></a>00118                 err = nfnl_ct_set_src(ct, repl, addr);
<a name="l00119"></a>00119                 nl_addr_put(addr);
<a name="l00120"></a>00120                 <span class="keywordflow">if</span> (err &lt; 0)
<a name="l00121"></a>00121                         <span class="keywordflow">goto</span> errout;
<a name="l00122"></a>00122         }
<a name="l00123"></a>00123         <span class="keywordflow">if</span> (tb[CTA_IP_V4_DST]) {
<a name="l00124"></a>00124                 addr = <a class="code" href="group__attr.html#ga98a5ac1eefea9266cf46c91b9a9867f3" title="Return payload of address attribute.">nla_get_addr</a>(tb[CTA_IP_V4_DST], AF_INET);
<a name="l00125"></a>00125                 <span class="keywordflow">if</span> (addr == NULL)
<a name="l00126"></a>00126                         <span class="keywordflow">goto</span> errout_errno;
<a name="l00127"></a>00127                 err = nfnl_ct_set_dst(ct, repl, addr);
<a name="l00128"></a>00128                 nl_addr_put(addr);
<a name="l00129"></a>00129                 <span class="keywordflow">if</span> (err &lt; 0)
<a name="l00130"></a>00130                         <span class="keywordflow">goto</span> errout;
<a name="l00131"></a>00131         }
<a name="l00132"></a>00132         <span class="keywordflow">if</span> (tb[CTA_IP_V6_SRC]) {
<a name="l00133"></a>00133                 addr = <a class="code" href="group__attr.html#ga98a5ac1eefea9266cf46c91b9a9867f3" title="Return payload of address attribute.">nla_get_addr</a>(tb[CTA_IP_V6_SRC], AF_INET6);
<a name="l00134"></a>00134                 <span class="keywordflow">if</span> (addr == NULL)
<a name="l00135"></a>00135                         <span class="keywordflow">goto</span> errout_errno;
<a name="l00136"></a>00136                 err = nfnl_ct_set_src(ct, repl, addr);
<a name="l00137"></a>00137                 nl_addr_put(addr);
<a name="l00138"></a>00138                 <span class="keywordflow">if</span> (err &lt; 0)
<a name="l00139"></a>00139                         <span class="keywordflow">goto</span> errout;
<a name="l00140"></a>00140         }
<a name="l00141"></a>00141         <span class="keywordflow">if</span> (tb[CTA_IP_V6_DST]) {
<a name="l00142"></a>00142                 addr = <a class="code" href="group__attr.html#ga98a5ac1eefea9266cf46c91b9a9867f3" title="Return payload of address attribute.">nla_get_addr</a>(tb[CTA_IP_V6_DST], AF_INET6);
<a name="l00143"></a>00143                 <span class="keywordflow">if</span> (addr == NULL)
<a name="l00144"></a>00144                         <span class="keywordflow">goto</span> errout_errno;
<a name="l00145"></a>00145                 err = nfnl_ct_set_dst(ct, repl, addr);
<a name="l00146"></a>00146                 nl_addr_put(addr);
<a name="l00147"></a>00147                 <span class="keywordflow">if</span> (err &lt; 0)
<a name="l00148"></a>00148                         <span class="keywordflow">goto</span> errout;
<a name="l00149"></a>00149         }
<a name="l00150"></a>00150 
<a name="l00151"></a>00151         <span class="keywordflow">return</span> 0;
<a name="l00152"></a>00152 
<a name="l00153"></a>00153 errout_errno:
<a name="l00154"></a>00154         <span class="keywordflow">return</span> nl_get_errno();
<a name="l00155"></a>00155 errout:
<a name="l00156"></a>00156         <span class="keywordflow">return</span> err;
<a name="l00157"></a>00157 }
<a name="l00158"></a>00158 
<a name="l00159"></a>00159 <span class="keyword">static</span> <span class="keywordtype">int</span> ct_parse_proto(<span class="keyword">struct</span> nfnl_ct *ct, <span class="keywordtype">int</span> repl, <span class="keyword">struct</span> nlattr *attr)
<a name="l00160"></a>00160 {
<a name="l00161"></a>00161         <span class="keyword">struct </span>nlattr *tb[CTA_PROTO_MAX+1];
<a name="l00162"></a>00162         <span class="keywordtype">int</span> err;
<a name="l00163"></a>00163 
<a name="l00164"></a>00164         err = <a class="code" href="group__attr.html#ga974ec0720b2d863a5c65da868bcb7a6e" title="parse nested attributes">nla_parse_nested</a>(tb, CTA_PROTO_MAX, attr, ct_proto_policy);
<a name="l00165"></a>00165         <span class="keywordflow">if</span> (err &lt; 0)
<a name="l00166"></a>00166                 <span class="keywordflow">return</span> err;
<a name="l00167"></a>00167 
<a name="l00168"></a>00168         <span class="keywordflow">if</span> (!repl &amp;&amp; tb[CTA_PROTO_NUM])
<a name="l00169"></a>00169                 nfnl_ct_set_proto(ct, <a class="code" href="group__attr.html#ga9ca4618a38f1567b1e42b1f21be887c9" title="Return payload of u8 attribute.">nla_get_u8</a>(tb[CTA_PROTO_NUM]));
<a name="l00170"></a>00170         <span class="keywordflow">if</span> (tb[CTA_PROTO_SRC_PORT])
<a name="l00171"></a>00171                 nfnl_ct_set_src_port(ct, repl,
<a name="l00172"></a>00172                                 <a class="code" href="group__attr.html#ga60c1be303721d4a39ad810876a13d304" title="Return payload of u16 attribute.">nla_get_u16</a>(tb[CTA_PROTO_SRC_PORT]));
<a name="l00173"></a>00173         <span class="keywordflow">if</span> (tb[CTA_PROTO_DST_PORT])
<a name="l00174"></a>00174                 nfnl_ct_set_dst_port(ct, repl,
<a name="l00175"></a>00175                                 <a class="code" href="group__attr.html#ga60c1be303721d4a39ad810876a13d304" title="Return payload of u16 attribute.">nla_get_u16</a>(tb[CTA_PROTO_DST_PORT]));
<a name="l00176"></a>00176         <span class="keywordflow">if</span> (tb[CTA_PROTO_ICMP_ID])
<a name="l00177"></a>00177                 nfnl_ct_set_icmp_id(ct, repl,
<a name="l00178"></a>00178                                 <a class="code" href="group__attr.html#ga60c1be303721d4a39ad810876a13d304" title="Return payload of u16 attribute.">nla_get_u16</a>(tb[CTA_PROTO_ICMP_ID]));
<a name="l00179"></a>00179         <span class="keywordflow">if</span> (tb[CTA_PROTO_ICMP_TYPE])
<a name="l00180"></a>00180                 nfnl_ct_set_icmp_type(ct, repl,
<a name="l00181"></a>00181                                 <a class="code" href="group__attr.html#ga9ca4618a38f1567b1e42b1f21be887c9" title="Return payload of u8 attribute.">nla_get_u8</a>(tb[CTA_PROTO_ICMP_TYPE]));
<a name="l00182"></a>00182         <span class="keywordflow">if</span> (tb[CTA_PROTO_ICMP_CODE])
<a name="l00183"></a>00183                 nfnl_ct_set_icmp_code(ct, repl,
<a name="l00184"></a>00184                                 <a class="code" href="group__attr.html#ga9ca4618a38f1567b1e42b1f21be887c9" title="Return payload of u8 attribute.">nla_get_u8</a>(tb[CTA_PROTO_ICMP_CODE]));
<a name="l00185"></a>00185 
<a name="l00186"></a>00186         <span class="keywordflow">return</span> 0;
<a name="l00187"></a>00187 }
<a name="l00188"></a>00188 
<a name="l00189"></a>00189 <span class="keyword">static</span> <span class="keywordtype">int</span> ct_parse_tuple(<span class="keyword">struct</span> nfnl_ct *ct, <span class="keywordtype">int</span> repl, <span class="keyword">struct</span> nlattr *attr)
<a name="l00190"></a>00190 {
<a name="l00191"></a>00191         <span class="keyword">struct </span>nlattr *tb[CTA_TUPLE_MAX+1];
<a name="l00192"></a>00192         <span class="keywordtype">int</span> err;
<a name="l00193"></a>00193 
<a name="l00194"></a>00194         err = <a class="code" href="group__attr.html#ga974ec0720b2d863a5c65da868bcb7a6e" title="parse nested attributes">nla_parse_nested</a>(tb, CTA_TUPLE_MAX, attr, ct_tuple_policy);
<a name="l00195"></a>00195         <span class="keywordflow">if</span> (err &lt; 0)
<a name="l00196"></a>00196                 <span class="keywordflow">return</span> err;
<a name="l00197"></a>00197 
<a name="l00198"></a>00198         <span class="keywordflow">if</span> (tb[CTA_TUPLE_IP]) {
<a name="l00199"></a>00199                 err = ct_parse_ip(ct, repl, tb[CTA_TUPLE_IP]);
<a name="l00200"></a>00200                 <span class="keywordflow">if</span> (err &lt; 0)
<a name="l00201"></a>00201                         <span class="keywordflow">return</span> err;
<a name="l00202"></a>00202         }
<a name="l00203"></a>00203 
<a name="l00204"></a>00204         <span class="keywordflow">if</span> (tb[CTA_TUPLE_PROTO]) {
<a name="l00205"></a>00205                 err = ct_parse_proto(ct, repl, tb[CTA_TUPLE_PROTO]);
<a name="l00206"></a>00206                 <span class="keywordflow">if</span> (err &lt; 0)
<a name="l00207"></a>00207                         <span class="keywordflow">return</span> err;
<a name="l00208"></a>00208         }
<a name="l00209"></a>00209 
<a name="l00210"></a>00210         <span class="keywordflow">return</span> 0;
<a name="l00211"></a>00211 }
<a name="l00212"></a>00212 
<a name="l00213"></a>00213 <span class="keyword">static</span> <span class="keywordtype">int</span> ct_parse_protoinfo_tcp(<span class="keyword">struct</span> nfnl_ct *ct, <span class="keyword">struct</span> nlattr *attr)
<a name="l00214"></a>00214 {
<a name="l00215"></a>00215         <span class="keyword">struct </span>nlattr *tb[CTA_PROTOINFO_TCP_MAX+1];
<a name="l00216"></a>00216         <span class="keywordtype">int</span> err;
<a name="l00217"></a>00217 
<a name="l00218"></a>00218         err = <a class="code" href="group__attr.html#ga974ec0720b2d863a5c65da868bcb7a6e" title="parse nested attributes">nla_parse_nested</a>(tb, CTA_PROTOINFO_TCP_MAX, attr,
<a name="l00219"></a>00219                                ct_protoinfo_tcp_policy);
<a name="l00220"></a>00220         <span class="keywordflow">if</span> (err &lt; 0)
<a name="l00221"></a>00221                 <span class="keywordflow">return</span> err;
<a name="l00222"></a>00222 
<a name="l00223"></a>00223         <span class="keywordflow">if</span> (tb[CTA_PROTOINFO_TCP_STATE])
<a name="l00224"></a>00224                 nfnl_ct_set_tcp_state(ct,
<a name="l00225"></a>00225                                 <a class="code" href="group__attr.html#ga9ca4618a38f1567b1e42b1f21be887c9" title="Return payload of u8 attribute.">nla_get_u8</a>(tb[CTA_PROTOINFO_TCP_STATE]));
<a name="l00226"></a>00226 
<a name="l00227"></a>00227         <span class="keywordflow">return</span> 0;
<a name="l00228"></a>00228 }
<a name="l00229"></a>00229 
<a name="l00230"></a>00230 <span class="keyword">static</span> <span class="keywordtype">int</span> ct_parse_protoinfo(<span class="keyword">struct</span> nfnl_ct *ct, <span class="keyword">struct</span> nlattr *attr)
<a name="l00231"></a>00231 {
<a name="l00232"></a>00232         <span class="keyword">struct </span>nlattr *tb[CTA_PROTOINFO_MAX+1];
<a name="l00233"></a>00233         <span class="keywordtype">int</span> err;
<a name="l00234"></a>00234 
<a name="l00235"></a>00235         err = <a class="code" href="group__attr.html#ga974ec0720b2d863a5c65da868bcb7a6e" title="parse nested attributes">nla_parse_nested</a>(tb, CTA_PROTOINFO_MAX, attr,
<a name="l00236"></a>00236                                ct_protoinfo_policy);
<a name="l00237"></a>00237         <span class="keywordflow">if</span> (err &lt; 0)
<a name="l00238"></a>00238                 <span class="keywordflow">return</span> err;
<a name="l00239"></a>00239 
<a name="l00240"></a>00240         <span class="keywordflow">if</span> (tb[CTA_PROTOINFO_TCP]) {
<a name="l00241"></a>00241                 err = ct_parse_protoinfo_tcp(ct, tb[CTA_PROTOINFO_TCP]);
<a name="l00242"></a>00242                 <span class="keywordflow">if</span> (err &lt; 0)
<a name="l00243"></a>00243                         <span class="keywordflow">return</span> err;
<a name="l00244"></a>00244         }
<a name="l00245"></a>00245 
<a name="l00246"></a>00246         <span class="keywordflow">return</span> 0;
<a name="l00247"></a>00247 }
<a name="l00248"></a>00248 
<a name="l00249"></a>00249 <span class="keyword">static</span> <span class="keywordtype">int</span> ct_parse_counters(<span class="keyword">struct</span> nfnl_ct *ct, <span class="keywordtype">int</span> repl, <span class="keyword">struct</span> nlattr *attr)
<a name="l00250"></a>00250 {
<a name="l00251"></a>00251         <span class="keyword">struct </span>nlattr *tb[CTA_COUNTERS_MAX+1];
<a name="l00252"></a>00252         <span class="keywordtype">int</span> err;
<a name="l00253"></a>00253 
<a name="l00254"></a>00254         err = <a class="code" href="group__attr.html#ga974ec0720b2d863a5c65da868bcb7a6e" title="parse nested attributes">nla_parse_nested</a>(tb, CTA_COUNTERS_MAX, attr, ct_counters_policy);
<a name="l00255"></a>00255         <span class="keywordflow">if</span> (err &lt; 0)
<a name="l00256"></a>00256                 <span class="keywordflow">return</span> err;
<a name="l00257"></a>00257 
<a name="l00258"></a>00258         <span class="keywordflow">if</span> (tb[CTA_COUNTERS_PACKETS])
<a name="l00259"></a>00259                 nfnl_ct_set_packets(ct, repl,
<a name="l00260"></a>00260                         ntohll(<a class="code" href="group__attr.html#ga517d3ae28480ef44fec7b1e3d2fb29e6" title="Return payload of u64 attribute.">nla_get_u64</a>(tb[CTA_COUNTERS_PACKETS])));
<a name="l00261"></a>00261         <span class="keywordflow">if</span> (tb[CTA_COUNTERS32_PACKETS])
<a name="l00262"></a>00262                 nfnl_ct_set_packets(ct, repl,
<a name="l00263"></a>00263                         ntohl(<a class="code" href="group__attr.html#gabda0290a8b26cc577c2c5cefa814aeac" title="Return payload of u32 attribute.">nla_get_u32</a>(tb[CTA_COUNTERS32_PACKETS])));
<a name="l00264"></a>00264         <span class="keywordflow">if</span> (tb[CTA_COUNTERS_BYTES])
<a name="l00265"></a>00265                 nfnl_ct_set_bytes(ct, repl,
<a name="l00266"></a>00266                         ntohll(<a class="code" href="group__attr.html#ga517d3ae28480ef44fec7b1e3d2fb29e6" title="Return payload of u64 attribute.">nla_get_u64</a>(tb[CTA_COUNTERS_BYTES])));
<a name="l00267"></a>00267         <span class="keywordflow">if</span> (tb[CTA_COUNTERS32_BYTES])
<a name="l00268"></a>00268                 nfnl_ct_set_bytes(ct, repl,
<a name="l00269"></a>00269                         ntohl(<a class="code" href="group__attr.html#gabda0290a8b26cc577c2c5cefa814aeac" title="Return payload of u32 attribute.">nla_get_u32</a>(tb[CTA_COUNTERS32_BYTES])));
<a name="l00270"></a>00270 
<a name="l00271"></a>00271         <span class="keywordflow">return</span> 0;
<a name="l00272"></a>00272 }
<a name="l00273"></a>00273 
<a name="l00274"></a>00274 <span class="keywordtype">int</span> nfnlmsg_ct_group(<span class="keyword">struct</span> <a class="code" href="structnlmsghdr.html" title="Netlink message header.">nlmsghdr</a> *nlh)
<a name="l00275"></a>00275 {
<a name="l00276"></a>00276         <span class="keywordflow">switch</span> (<a class="code" href="group__nfnl.html#gaf1bb10eb2462b46f2a4bf48d1a0e0c33" title="Get netfilter message type from message.">nfnlmsg_subtype</a>(nlh)) {
<a name="l00277"></a>00277         <span class="keywordflow">case</span> IPCTNL_MSG_CT_NEW:
<a name="l00278"></a>00278                 <span class="keywordflow">if</span> (nlh-&gt;<a class="code" href="structnlmsghdr.html#abcf664d354ea35ebb9b3d8a50088fec6" title="Message flags.">nlmsg_flags</a> &amp; (<a class="code" href="group__msg.html#ga20a00ae52e4c150f54649d7346d23a7a" title="Create config object if it doesn&amp;#39;t already exist.">NLM_F_CREATE</a>|<a class="code" href="group__msg.html#ga0b0f8c9581ee93747c7d9e94ca0e0596" title="Don&amp;#39;t replace the config object if it already exists.">NLM_F_EXCL</a>))
<a name="l00279"></a>00279                         <span class="keywordflow">return</span> NFNLGRP_CONNTRACK_NEW;
<a name="l00280"></a>00280                 <span class="keywordflow">else</span>
<a name="l00281"></a>00281                         <span class="keywordflow">return</span> NFNLGRP_CONNTRACK_UPDATE;
<a name="l00282"></a>00282         <span class="keywordflow">case</span> IPCTNL_MSG_CT_DELETE:
<a name="l00283"></a>00283                 <span class="keywordflow">return</span> NFNLGRP_CONNTRACK_DESTROY;
<a name="l00284"></a>00284         <span class="keywordflow">default</span>:
<a name="l00285"></a>00285                 <span class="keywordflow">return</span> NFNLGRP_NONE;
<a name="l00286"></a>00286         }
<a name="l00287"></a>00287 }
<a name="l00288"></a>00288 
<a name="l00289"></a>00289 <span class="keyword">struct </span>nfnl_ct *nfnlmsg_ct_parse(<span class="keyword">struct</span> <a class="code" href="structnlmsghdr.html" title="Netlink message header.">nlmsghdr</a> *nlh)
<a name="l00290"></a>00290 {
<a name="l00291"></a>00291         <span class="keyword">struct </span>nfnl_ct *ct;
<a name="l00292"></a>00292         <span class="keyword">struct </span>nlattr *tb[CTA_MAX+1];
<a name="l00293"></a>00293         <span class="keywordtype">int</span> err;
<a name="l00294"></a>00294 
<a name="l00295"></a>00295         ct = nfnl_ct_alloc();
<a name="l00296"></a>00296         <span class="keywordflow">if</span> (!ct)
<a name="l00297"></a>00297                 <span class="keywordflow">return</span> NULL;
<a name="l00298"></a>00298 
<a name="l00299"></a>00299         ct-&gt;ce_msgtype = nlh-&gt;<a class="code" href="structnlmsghdr.html#a7232c4e6cb513010e64887b7eebf8823" title="Message type (content type)">nlmsg_type</a>;
<a name="l00300"></a>00300 
<a name="l00301"></a>00301         err = <a class="code" href="group__msg.html#ga2671eefe95c3e44dec8ddab51ae57593" title="parse attributes of a netlink message">nlmsg_parse</a>(nlh, <span class="keyword">sizeof</span>(<span class="keyword">struct</span> nfgenmsg), tb, CTA_MAX,
<a name="l00302"></a>00302                           ct_policy);
<a name="l00303"></a>00303         <span class="keywordflow">if</span> (err &lt; 0)
<a name="l00304"></a>00304                 <span class="keywordflow">goto</span> errout;
<a name="l00305"></a>00305 
<a name="l00306"></a>00306         nfnl_ct_set_family(ct, <a class="code" href="group__nfnl.html#ga91b2b1c9b8e243fe070229ef3fff3d6c" title="Get netfilter family from message.">nfnlmsg_family</a>(nlh));
<a name="l00307"></a>00307 
<a name="l00308"></a>00308         <span class="keywordflow">if</span> (tb[CTA_TUPLE_ORIG]) {
<a name="l00309"></a>00309                 err = ct_parse_tuple(ct, 0, tb[CTA_TUPLE_ORIG]);
<a name="l00310"></a>00310                 <span class="keywordflow">if</span> (err &lt; 0)
<a name="l00311"></a>00311                         <span class="keywordflow">goto</span> errout;
<a name="l00312"></a>00312         }
<a name="l00313"></a>00313         <span class="keywordflow">if</span> (tb[CTA_TUPLE_REPLY]) {
<a name="l00314"></a>00314                 err = ct_parse_tuple(ct, 1, tb[CTA_TUPLE_REPLY]);
<a name="l00315"></a>00315                 <span class="keywordflow">if</span> (err &lt; 0)
<a name="l00316"></a>00316                         <span class="keywordflow">goto</span> errout;
<a name="l00317"></a>00317         }
<a name="l00318"></a>00318 
<a name="l00319"></a>00319         <span class="keywordflow">if</span> (tb[CTA_PROTOINFO]) {
<a name="l00320"></a>00320                 err = ct_parse_protoinfo(ct, tb[CTA_PROTOINFO]);
<a name="l00321"></a>00321                 <span class="keywordflow">if</span> (err &lt; 0)
<a name="l00322"></a>00322                         <span class="keywordflow">goto</span> errout;
<a name="l00323"></a>00323         }
<a name="l00324"></a>00324 
<a name="l00325"></a>00325         <span class="keywordflow">if</span> (tb[CTA_STATUS])
<a name="l00326"></a>00326                 nfnl_ct_set_status(ct, ntohl(<a class="code" href="group__attr.html#gabda0290a8b26cc577c2c5cefa814aeac" title="Return payload of u32 attribute.">nla_get_u32</a>(tb[CTA_STATUS])));
<a name="l00327"></a>00327         <span class="keywordflow">if</span> (tb[CTA_TIMEOUT])
<a name="l00328"></a>00328                 nfnl_ct_set_timeout(ct, ntohl(<a class="code" href="group__attr.html#gabda0290a8b26cc577c2c5cefa814aeac" title="Return payload of u32 attribute.">nla_get_u32</a>(tb[CTA_TIMEOUT])));
<a name="l00329"></a>00329         <span class="keywordflow">if</span> (tb[CTA_MARK])
<a name="l00330"></a>00330                 nfnl_ct_set_mark(ct, ntohl(<a class="code" href="group__attr.html#gabda0290a8b26cc577c2c5cefa814aeac" title="Return payload of u32 attribute.">nla_get_u32</a>(tb[CTA_MARK])));
<a name="l00331"></a>00331         <span class="keywordflow">if</span> (tb[CTA_USE])
<a name="l00332"></a>00332                 nfnl_ct_set_use(ct, ntohl(<a class="code" href="group__attr.html#gabda0290a8b26cc577c2c5cefa814aeac" title="Return payload of u32 attribute.">nla_get_u32</a>(tb[CTA_USE])));
<a name="l00333"></a>00333         <span class="keywordflow">if</span> (tb[CTA_ID])
<a name="l00334"></a>00334                 nfnl_ct_set_id(ct, ntohl(<a class="code" href="group__attr.html#gabda0290a8b26cc577c2c5cefa814aeac" title="Return payload of u32 attribute.">nla_get_u32</a>(tb[CTA_ID])));
<a name="l00335"></a>00335 
<a name="l00336"></a>00336         <span class="keywordflow">if</span> (tb[CTA_COUNTERS_ORIG]) {
<a name="l00337"></a>00337                 err = ct_parse_counters(ct, 0, tb[CTA_COUNTERS_ORIG]);
<a name="l00338"></a>00338                 <span class="keywordflow">if</span> (err &lt; 0)
<a name="l00339"></a>00339                         <span class="keywordflow">goto</span> errout;
<a name="l00340"></a>00340         }
<a name="l00341"></a>00341 
<a name="l00342"></a>00342         <span class="keywordflow">if</span> (tb[CTA_COUNTERS_REPLY]) {
<a name="l00343"></a>00343                 err = ct_parse_counters(ct, 1, tb[CTA_COUNTERS_REPLY]);
<a name="l00344"></a>00344                 <span class="keywordflow">if</span> (err &lt; 0)
<a name="l00345"></a>00345                         <span class="keywordflow">goto</span> errout;
<a name="l00346"></a>00346         }
<a name="l00347"></a>00347 
<a name="l00348"></a>00348         <span class="keywordflow">return</span> ct;
<a name="l00349"></a>00349 
<a name="l00350"></a>00350 errout:
<a name="l00351"></a>00351         nfnl_ct_put(ct);
<a name="l00352"></a>00352         <span class="keywordflow">return</span> NULL;
<a name="l00353"></a>00353 }
<a name="l00354"></a>00354 
<a name="l00355"></a>00355 <span class="keyword">static</span> <span class="keywordtype">int</span> ct_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="structsockaddr__nl.html" title="Netlink socket address.">sockaddr_nl</a> *who,
<a name="l00356"></a>00356                          <span class="keyword">struct</span> <a class="code" href="structnlmsghdr.html" title="Netlink message header.">nlmsghdr</a> *nlh, <span class="keyword">struct</span> <a class="code" href="structnl__parser__param.html">nl_parser_param</a> *pp)
<a name="l00357"></a>00357 {
<a name="l00358"></a>00358         <span class="keyword">struct </span>nfnl_ct *ct;
<a name="l00359"></a>00359         <span class="keywordtype">int</span> err;
<a name="l00360"></a>00360 
<a name="l00361"></a>00361         ct = nfnlmsg_ct_parse(nlh);
<a name="l00362"></a>00362         <span class="keywordflow">if</span> (ct == NULL)
<a name="l00363"></a>00363                 <span class="keywordflow">goto</span> errout_errno;
<a name="l00364"></a>00364 
<a name="l00365"></a>00365         err = pp-&gt;pp_cb((<span class="keyword">struct</span> nl_object *) ct, pp);
<a name="l00366"></a>00366         <span class="keywordflow">if</span> (err &lt; 0)
<a name="l00367"></a>00367                 <span class="keywordflow">goto</span> errout;
<a name="l00368"></a>00368 
<a name="l00369"></a>00369         err = P_ACCEPT;
<a name="l00370"></a>00370 
<a name="l00371"></a>00371 errout:
<a name="l00372"></a>00372         nfnl_ct_put(ct);
<a name="l00373"></a>00373         <span class="keywordflow">return</span> err;
<a name="l00374"></a>00374 
<a name="l00375"></a>00375 errout_errno:
<a name="l00376"></a>00376         err = nl_get_errno();
<a name="l00377"></a>00377         <span class="keywordflow">goto</span> errout;
<a name="l00378"></a>00378 }
<a name="l00379"></a>00379 
<a name="l00380"></a>00380 <span class="keywordtype">int</span> nfnl_ct_dump_request(<span class="keyword">struct</span> nl_handle *h)
<a name="l00381"></a>00381 {
<a name="l00382"></a>00382         <span class="keywordflow">return</span> <a class="code" href="group__nfnl.html#ga0c1b3dd550e49dfc74f4ba18cc6cfebf" title="Send trivial netfilter netlink message.">nfnl_send_simple</a>(h, NFNL_SUBSYS_CTNETLINK, IPCTNL_MSG_CT_GET,
<a name="l00383"></a>00383                                 <a class="code" href="group__msg.html#ga8d4fb2458c013decb6673f41c52c07b1" title="Dump all entries.">NLM_F_DUMP</a>, AF_UNSPEC, 0);
<a name="l00384"></a>00384 }
<a name="l00385"></a>00385 
<a name="l00386"></a>00386 <span class="keyword">static</span> <span class="keywordtype">int</span> ct_request_update(<span class="keyword">struct</span> nl_cache *c, <span class="keyword">struct</span> nl_handle *h)
<a name="l00387"></a>00387 {
<a name="l00388"></a>00388         <span class="keywordflow">return</span> nfnl_ct_dump_request(h);
<a name="l00389"></a>00389 }
<a name="l00390"></a>00390 <span class="comment"></span>
<a name="l00391"></a>00391 <span class="comment">/**</span>
<a name="l00392"></a>00392 <span class="comment"> * @name Cache Management</span>
<a name="l00393"></a>00393 <span class="comment"> * @{</span>
<a name="l00394"></a>00394 <span class="comment"> */</span>
<a name="l00395"></a>00395 <span class="comment"></span>
<a name="l00396"></a>00396 <span class="comment">/**</span>
<a name="l00397"></a>00397 <span class="comment"> * Build a conntrack cache holding all conntrack currently in the kernel</span>
<a name="l00398"></a>00398 <span class="comment"> * @arg handle          netlink handle</span>
<a name="l00399"></a>00399 <span class="comment"> *</span>
<a name="l00400"></a>00400 <span class="comment"> * Allocates a new cache, initializes it properly and updates it to</span>
<a name="l00401"></a>00401 <span class="comment"> * contain all conntracks currently in the kernel.</span>
<a name="l00402"></a>00402 <span class="comment"> *</span>
<a name="l00403"></a>00403 <span class="comment"> * @note The caller is responsible for destroying and freeing the</span>
<a name="l00404"></a>00404 <span class="comment"> *       cache after using it.</span>
<a name="l00405"></a>00405 <span class="comment"> * @return The cache or NULL if an error has occured.</span>
<a name="l00406"></a>00406 <span class="comment"> */</span>
<a name="l00407"></a><a class="code" href="group__ct.html#ga418aad867d4f08e98b7b423795ff8914">00407</a> <span class="keyword">struct </span>nl_cache *<a class="code" href="group__ct.html#ga418aad867d4f08e98b7b423795ff8914" title="Build a conntrack cache holding all conntrack currently in the kernel.">nfnl_ct_alloc_cache</a>(<span class="keyword">struct</span> nl_handle *handle)
<a name="l00408"></a>00408 {
<a name="l00409"></a>00409         <span class="keyword">struct </span>nl_cache *cache;
<a name="l00410"></a>00410 
<a name="l00411"></a>00411         cache = <a class="code" href="group__cache.html#ga9520ae0f2158db3c081f34c851d92252" title="Allocate an empty cache.">nl_cache_alloc</a>(&amp;nfnl_ct_ops);
<a name="l00412"></a>00412         <span class="keywordflow">if</span> (!cache)
<a name="l00413"></a>00413                 <span class="keywordflow">return</span> NULL;
<a name="l00414"></a>00414 
<a name="l00415"></a>00415         <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="l00416"></a>00416                 free(cache);
<a name="l00417"></a>00417                 <span class="keywordflow">return</span> NULL;
<a name="l00418"></a>00418         }
<a name="l00419"></a>00419 
<a name="l00420"></a>00420         <span class="keywordflow">return</span> cache;
<a name="l00421"></a>00421 }
<a name="l00422"></a>00422 <span class="comment"></span>
<a name="l00423"></a>00423 <span class="comment">/** @} */</span>
<a name="l00424"></a>00424 <span class="comment"></span>
<a name="l00425"></a>00425 <span class="comment">/**</span>
<a name="l00426"></a>00426 <span class="comment"> * @name Conntrack Addition</span>
<a name="l00427"></a>00427 <span class="comment"> * @{</span>
<a name="l00428"></a>00428 <span class="comment"> */</span>
<a name="l00429"></a>00429 <span class="comment"></span>
<a name="l00430"></a>00430 <span class="comment">/** @} */</span>
<a name="l00431"></a>00431 
<a name="l00432"></a>00432 <span class="keyword">static</span> <span class="keyword">struct </span><a class="code" href="structnl__af__group.html" title="Address family to netlink group association.">nl_af_group</a> ct_groups[] = {
<a name="l00433"></a>00433         { AF_UNSPEC, NFNLGRP_CONNTRACK_NEW },
<a name="l00434"></a>00434         { AF_UNSPEC, NFNLGRP_CONNTRACK_UPDATE },
<a name="l00435"></a>00435         { AF_UNSPEC, NFNLGRP_CONNTRACK_DESTROY },
<a name="l00436"></a>00436         { END_OF_GROUP_LIST },
<a name="l00437"></a>00437 };
<a name="l00438"></a>00438 
<a name="l00439"></a>00439 <span class="preprocessor">#define NFNLMSG_CT_TYPE(type) NFNLMSG_TYPE(NFNL_SUBSYS_CTNETLINK, (type))</span>
<a name="l00440"></a>00440 <span class="preprocessor"></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> nfnl_ct_ops = {
<a name="l00441"></a>00441         .co_name                = <span class="stringliteral">&quot;netfilter/ct&quot;</span>,
<a name="l00442"></a>00442         .co_hdrsize             = NFNL_HDRLEN,
<a name="l00443"></a>00443         .co_msgtypes            = {
<a name="l00444"></a>00444                 { NFNLMSG_CT_TYPE(IPCTNL_MSG_CT_NEW), NL_ACT_NEW, <span class="stringliteral">&quot;new&quot;</span> },
<a name="l00445"></a>00445                 { NFNLMSG_CT_TYPE(IPCTNL_MSG_CT_GET), NL_ACT_GET, <span class="stringliteral">&quot;get&quot;</span> },
<a name="l00446"></a>00446                 { NFNLMSG_CT_TYPE(IPCTNL_MSG_CT_DELETE), NL_ACT_DEL, <span class="stringliteral">&quot;del&quot;</span> },
<a name="l00447"></a>00447                 END_OF_MSGTYPES_LIST,
<a name="l00448"></a>00448         },
<a name="l00449"></a>00449         .co_protocol            = NETLINK_NETFILTER,
<a name="l00450"></a>00450         .co_groups              = ct_groups,
<a name="l00451"></a>00451         .co_request_update      = ct_request_update,
<a name="l00452"></a>00452         .co_msg_parser          = ct_msg_parser,
<a name="l00453"></a>00453         .co_obj_ops             = &amp;ct_obj_ops,
<a name="l00454"></a>00454 };
<a name="l00455"></a>00455 
<a name="l00456"></a>00456 <span class="keyword">static</span> <span class="keywordtype">void</span> __init ct_init(<span class="keywordtype">void</span>)
<a name="l00457"></a>00457 {
<a name="l00458"></a>00458         <a class="code" href="group__cache__mngt.html#ga390eeb1fa61634cf1c216792c6df63c3" title="Register a set of cache operations.">nl_cache_mngt_register</a>(&amp;nfnl_ct_ops);
<a name="l00459"></a>00459 }
<a name="l00460"></a>00460 
<a name="l00461"></a>00461 <span class="keyword">static</span> <span class="keywordtype">void</span> __exit ct_exit(<span class="keywordtype">void</span>)
<a name="l00462"></a>00462 {
<a name="l00463"></a>00463         <a class="code" href="group__cache__mngt.html#ga09f56b767b3868b7e0cf8559863dde77" title="Unregister a set of cache operations.">nl_cache_mngt_unregister</a>(&amp;nfnl_ct_ops);
<a name="l00464"></a>00464 }
<a name="l00465"></a>00465 <span class="comment"></span>
<a name="l00466"></a>00466 <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>