<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
    <title>Vsevolod Stakhov, Notes</title>
    <link rel="alternate" type="text/html" href="http://cebka.pp.ru/blog_en/" />
    <link rel="self" type="application/atom+xml" href="http://cebka.pp.ru/blog_en/atom.xml" />
    <id>tag:cebka.pp.ru,2007-12-12:/blog_en//2</id>
    <updated>2009-04-13T16:49:59Z</updated>
    
    <generator uri="http://www.sixapart.com/movabletype/">Movable Type Publishing Platform 4.01</generator>

<entry>
    <title>Rspamd</title>
    <link rel="alternate" type="text/html" href="http://cebka.pp.ru/blog_en/2009/04/rspamd.html" />
    <id>tag:cebka.pp.ru,2009:/blog_en//2.36</id>

    <published>2009-04-13T16:48:58Z</published>
    <updated>2009-04-13T16:49:59Z</updated>

    <summary>First public version of rspamd is available for beta-testing. Rspamd is fast, modular and lightweight spam filter. It is designed to work with big ammount of mail and can be easily extended with own filters written in lua or perl.Rspamd...</summary>
    <author>
        <name>Vsevolod Stakhov</name>
        
    </author>
    
    <category term="work" label="work" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en-us" xml:base="http://cebka.pp.ru/blog_en/">
        <![CDATA[First public version of rspamd is available for beta-testing. Rspamd is fast, modular and lightweight spam filter. It is designed to
work with big ammount of mail and can be easily extended with own
filters written in lua or perl.<br />Rspamd can be found here: <a href="http://cebka.pp.ru/trac">http://cebka.pp.ru/trac</a> ]]>
        
    </content>
</entry>

<entry>
    <title></title>
    <link rel="alternate" type="text/html" href="http://cebka.pp.ru/blog_en/2008/08/-here-is-mercurial-repository.html" />
    <id>tag:cebka.pp.ru,2008:/blog_en//2.30</id>

    <published>2008-08-12T14:23:57Z</published>
    <updated>2008-08-12T14:33:17Z</updated>

    <summary> Here is mercurial repository of some of my software.- http://cebka.pp.ru/hg/rmilter/ - mail filter for sendmail/postfix, that can check mail with spamassassin/clamav/dcc/spf, check limits and do greylisting (via memcached), and check regexps.- http://cebka.pp.ru/hg/nginx-smtp-policy/ - async (libevent based) DNS resolver with...</summary>
    <author>
        <name>Vsevolod Stakhov</name>
        
    </author>
    
    <category term="work" label="work" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en-us" xml:base="http://cebka.pp.ru/blog_en/">
        <![CDATA[<div class="asset-header"><div class="asset-meta">
    
</div>

    </div>
    <div class="asset-content">

        <div class="asset-body">
Here is mercurial <a href="http://cebka.pp.ru/hg/">repository</a> of some of my software.<br />-
<a href="http://cebka.pp.ru/hg/rmilter/">http://cebka.pp.ru/hg/rmilter/</a> - mail filter for sendmail/postfix, that can check mail with spamassassin/clamav/dcc/spf, check limits and do greylisting (via memcached), and check regexps.<br />-
<a href="http://cebka.pp.ru/hg/nginx-smtp-policy/">http://cebka.pp.ru/hg/nginx-smtp-policy/</a> - async (libevent based) DNS resolver with patch to nginx (versions up to 0.6.11) mail module (originnally written by Max Dounin http://mdounin.ru/) that can do load balancing of incoming mail (weight based) check rbls and monitor state of mx's (with nginx-smtp-watchdog). Nginx-smtp-policy designed for huge mail traffic and can help to low load on backend mx's.<br />- <a href="http://cebka.pp.ru/hg/libevent/">http://cebka.pp.ru/hg/libevent/</a> - libevent patches for faster DNS search (hashed list instead of linear list) and for allowing TXT requests (for RBL checks).<br /></div></div> ]]>
        
    </content>
</entry>

<entry>
    <title>Migration from jabberd2 to openfire</title>
    <link rel="alternate" type="text/html" href="http://cebka.pp.ru/blog_en/2008/02/migration-from-jabberd2-to-ope.html" />
    <id>tag:cebka.pp.ru,2008:/blog_en//2.26</id>

    <published>2008-02-05T17:26:23Z</published>
    <updated>2008-02-05T17:28:09Z</updated>

    <summary>Here is script that allows to convert jabberd2 database items to xml format that can be used by openfire import/export plugin. jabber_to_xml.pl...</summary>
    <author>
        <name>Vsevolod Stakhov</name>
        
    </author>
    
    <category term="jabber" label="jabber" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en-us" xml:base="http://cebka.pp.ru/blog_en/">
        <![CDATA[Here is script that allows to convert jabberd2 database items to xml format that can be used by openfire import/export plugin.<br /><br /> <div><a href="http://cebka.pp.ru/blog/jabber_to_xml.pl">jabber_to_xml.pl</a></div>]]>
        
    </content>
</entry>

<entry>
    <title>Memcached UDP</title>
    <link rel="alternate" type="text/html" href="http://cebka.pp.ru/blog_en/2007/12/memcached-udp.html" />
    <id>tag:cebka.pp.ru,2007:/blog_en//2.24</id>

    <published>2007-12-13T14:37:22Z</published>
    <updated>2007-12-13T14:40:19Z</updated>

    <summary><![CDATA[This patch fixes memcached support of udp protocol. Now UDP packets with wrong header can break&nbsp; memcached server down. Also I've made some fixes in cleaning UDP sessions after closing.Results of testing (UDP vs TCP):UDP:Results of memcached stress test:Total number...]]></summary>
    <author>
        <name>Vsevolod Stakhov</name>
        
    </author>
    
    <category term="work" label="work" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en-us" xml:base="http://cebka.pp.ru/blog_en/">
        <![CDATA[This patch fixes memcached support of udp protocol. Now UDP packets with wrong header can break&nbsp; memcached server down. Also I've made some fixes in cleaning UDP sessions after closing.<br />Results of testing (UDP vs TCP):<br /><br />UDP:<br />Results of memcached stress test:<br />Total number of connections: 10000<br />Number of seconds for test: 2.23<br />Number of successfull connections: 10000<br />Connections per second: 4494.25<br />TCP:<br />Results of memcached stress test:<br />Total number of connections: 10000<br />Number of seconds for test: 4.38<br />Number of successfull connections: 10000<br />Connections per second: 2280.87<br /><br /><a href="http://cebka.pp.ru/blog/patch-memcached-udp">patch-memcached-udp</a><br /><div><br /></div>]]>
        
    </content>
</entry>

<entry>
    <title>XCLIENT in Exim</title>
    <link rel="alternate" type="text/html" href="http://cebka.pp.ru/blog_en/2007/12/xclient-in-exim.html" />
    <id>tag:cebka.pp.ru,2007:/blog_en//2.21</id>

    <published>2007-12-12T14:51:01Z</published>
    <updated>2007-12-12T14:54:50Z</updated>

    <summary> I wrote small patch for exim 4.68 that allows using of XCLIENT command in exim. The description of this command you can find here: http://www.postfix.org/XCLIENT_README.htmlBy default xclient is not allowed from any hosts, but you can specify hosts in...</summary>
    <author>
        <name>Vsevolod Stakhov</name>
        
    </author>
    
    <category term="work" label="work" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en-us" xml:base="http://cebka.pp.ru/blog_en/">
        <![CDATA[


    
    <div class="asset-content">

        <div class="asset-body">
I wrote small patch for exim 4.68 that allows using of XCLIENT command in exim. The description of this command you can find here: <a href="http://www.postfix.org/XCLIENT_README.html">http://www.postfix.org/XCLIENT_README.html</a><br />By default xclient is not allowed from any hosts, but you can specify hosts in option xclient_allow_hosts in configuration file:<br /><br />xclient_allow_hosts = 127.0.0.1 : 192.168.1.1<br /><br />Example of smtp dialog with XCLIENT:<br />Connected to localhost.<br />Escape character is '^]'.<br />220 dhcp-ng2 ESMTP Exim 4.68 Mon, 10 Dec 2007 19:26:44 +0300<br />XCLIENT NAME=spike.porcupine.org ADDR=168.100.189.2 HELO=blah<br />220 XCLIENT success<br />MAIL FROM:&lt;wietse@porcupine.org&gt;<br />250 OK<br />RCPT TO:&lt;user@example.com&gt;<br />550 relay not permitted<br /><br /><a href="http://cebka.pp.ru/blog/patch-exim-xclient">patch-exim-xclient</a><br /></div></div> ]]>
        
    </content>
</entry>

<entry>
    <title>Determining order of passing packets throught packet filters in FreeBSD</title>
    <link rel="alternate" type="text/html" href="http://cebka.pp.ru/blog_en/2007/12/determining-order-of-passing-p-1.html" />
    <id>tag:cebka.pp.ru,2007:/blog_en//2.20</id>

    <published>2007-12-12T14:50:01Z</published>
    <updated>2007-12-12T15:07:40Z</updated>

    <summary><![CDATA[The order of loading kernel modules of packet filters affects the order of registering hooks in pfil interface.So this code shows how pfil calls specified hook:for (pfh = pfil_hook_get(dir, ph); &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; pfh != NULL;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pfh = TAILQ_NEXT(pfh, pfil_link)) {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;...]]></summary>
    <author>
        <name>Vsevolod Stakhov</name>
        
    </author>
    
    <category term="freebsd" label="freebsd" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en-us" xml:base="http://cebka.pp.ru/blog_en/">
        <![CDATA[The order of loading kernel modules of packet filters affects the order of registering hooks in pfil interface.<br />So this code shows how pfil calls specified hook:<br /><br />for (pfh = pfil_hook_get(dir, ph); <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; pfh != NULL;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pfh = TAILQ_NEXT(pfh, pfil_link)) {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (pfh-&gt;pfil_func != NULL) {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; rv = (*pfh-&gt;pfil_func)(pfh-&gt;pfil_arg, &amp;m, ifp, dir, inp);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (rv != 0 || m == NULL)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }&nbsp;&nbsp; <br />}<br /><br />So we check all hooks begining from TAILQ_FIRST and pass packet to each hook as parameter.<br />If hook drops packet, we do not check other hooks.<br /><br />This code register hooks in pfil interface:<br /><br />&nbsp;&nbsp;&nbsp; /*<br />&nbsp;&nbsp;&nbsp;&nbsp; * insert the input list in reverse order of the output list<br />&nbsp;&nbsp;&nbsp;&nbsp; * so that the same path is followed in or out of the kernel.<br />&nbsp;&nbsp;&nbsp;&nbsp; */<br />&nbsp;&nbsp;&nbsp; if (flags &amp; PFIL_IN)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TAILQ_INSERT_HEAD(list, pfh1, pfil_link);<br />&nbsp;&nbsp;&nbsp; else<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TAILQ_INSERT_TAIL(list, pfh1, pfil_link);<br /><br />So for inbound traffic module that adds its hook&nbsp; <b>last </b>would process packets first, and for outbound traffic module that adds its hook <b>first</b> would process packets first.<br />Now let's determine load order of kernel modules.<br />Modules on load attach to subsystems, that are described in sys/kernel.h:<br /><br />&nbsp;&nbsp;&nbsp; SI_SUB_PROTO_IF&nbsp;&nbsp;&nbsp;&nbsp; = 0x8400000,&nbsp;&nbsp;&nbsp; /* interfaces*/<br />&nbsp;&nbsp;&nbsp; SI_SUB_PROTO_DOMAIN = 0x8800000,&nbsp;&nbsp;&nbsp; /* domains (address families?)*/<br />&nbsp;&nbsp;&nbsp; SI_SUB_PROTO_IFATTACHDOMAIN = 0x8800001,&nbsp;&nbsp;&nbsp; /* domain dependent data init*/<br />Subsystems are loading in order of their number, first are loaded subsystems with lesser number.<br />Module on load can be attached to subsystem in different module too, this order is declared in macro DECLARE_MODULE:<br /><br />enum sysinit_elem_order {<br />&nbsp;&nbsp;&nbsp; SI_ORDER_FIRST&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = 0x0000000,&nbsp;&nbsp;&nbsp; /* first*/<br />&nbsp;&nbsp;&nbsp; SI_ORDER_SECOND&nbsp;&nbsp;&nbsp;&nbsp; = 0x0000001,&nbsp;&nbsp;&nbsp; /* second*/<br />&nbsp;&nbsp;&nbsp; SI_ORDER_THIRD&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = 0x0000002,&nbsp;&nbsp;&nbsp; /* third*/<br />&nbsp;&nbsp;&nbsp; SI_ORDER_MIDDLE&nbsp;&nbsp;&nbsp;&nbsp; = 0x1000000,&nbsp;&nbsp;&nbsp; /* somewhere in the middle */<br />&nbsp;&nbsp;&nbsp; SI_ORDER_ANY&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = 0xfffffff /* last*/<br />};<br />So we should check subsystem of module and order of attachement to subsystem for each packet filter module:<br />pf:<br />DECLARE_MODULE(pf, pf_mod, SI_SUB_PROTO_IFATTACHDOMAIN, SI_ORDER_FIRST);<br />ipfw:<br />DECLARE_MODULE(ipfw, ipfwmod, SI_SUB_PROTO_IFATTACHDOMAIN, SI_ORDER_ANY);<br />ipfilter:<br />DECLARE_MODULE(ipfilter, ipfiltermod, SI_SUB_PROTO_DOMAIN, SI_ORDER_ANY);<br /><br />Subsystems
loads in this order:&nbsp; SI_SUB_PROTO_DOMAIN -&gt;
SI_SUB_PROTO_IFATTACHDOMAIN (ipfilter -&gt; (ipfw, pf)), according to
order of attachement of modules to subsystems the chain of loading must
look like ipfilter -&gt; pf -&gt; ipfw.<br />Process order for inbound traffic:<br />ipfw -&gt; pf -&gt; ipfilter -&gt; stack<br />and for outbound:<br />stack -&gt; ipfilter -&gt; pf -&gt; ipfw<br /><br />On
the other hand ps is often loaded as kld, and is not statically
compiled in the kernel, so if you can see pf.ko in loaded modules list
(kldstat), pf is loaded <b>after </b>ipfw, not before. So traffic pass chains must look like this:<br />pf -&gt; ipfw -&gt; ipfilter -&gt; stack - for inbound<br />stack -&gt; ipfilter -&gt; ipfw -&gt; pf - for outbound<i><br /><br /></i>The
order of passing trafic throught packet filters is very important in
case of NAT, as next filter in chain can receive modified packet. ]]>
        
    </content>
</entry>

</feed>
