2015年8月5日水曜日

Postfwd キャッシュの取り扱い

postfwdはルールセットにマッチしたものをキャッシュとして保持し、以降、保持期間が過ぎるまでキャッシュを利用して応答します。
今回は、そのキャッシュについてまとめてみます。

※評価は、CentOS6.6(x86_64) + Postfwd2 v1.35で行っています
※また、以下のようなドメイン名の入力ミスにエラーをかえすルールセットを作って行っています
id=WRONG_DOMAINS
        recipient_domain = (gmal.com|gmaile.com)
        action = REJECT Isn't it gmail.com?



キャッシュの保持期間


これは、Postfwdの起動時の引数として指定する"--cache"の値で決まります。
※キャッシュに関するオプションは結構あるので、"postfwd2 -m"と実行し、Cache:の箇所を確認してみてください。



キャッシュの内容確認


--dumpcache”オプションで確認する事ができます。
以下、出力例です(変な改行が入って見にくいですが、"%request_cache ->"から次の"%request_cache ->"のところまでが1行です)。
# postfwd2 --dumpcache
%request_cache -> %192.168.233.1;unknown;mail.example.com;mail.example.com;SMTP;RCPT;user01@gmal.com;gmal.com;user01;smtpd_access_policy;1.233.168.192;unknown;user01@mail.example.com;mail.example.com;user01;mail.example.com;mail.example.com;mail.example.com;mail.example.com;postfwd2 1.35; -> @action -> 'REJECT Isn't an address gmail.com?'
%request_cache -> %192.168.233.1;unknown;mail.example.com;mail.example.com;SMTP;RCPT;user01@gmal.com;gmal.com;user01;smtpd_access_policy;1.233.168.192;unknown;user01@mail.example.com;mail.example.com;user01;mail.example.com;mail.example.com;mail.example.com;mail.example.com;postfwd2 1.35; -> @hit    -> '3'
%request_cache -> %192.168.233.1;unknown;mail.example.com;mail.example.com;SMTP;RCPT;user01@gmal.com;gmal.com;user01;smtpd_access_policy;1.233.168.192;unknown;user01@mail.example.com;mail.example.com;user01;mail.example.com;mail.example.com;mail.example.com;mail.example.com;postfwd2 1.35; -> @hits   -> 'WRONG_DOMAINS'
%request_cache -> %192.168.233.1;unknown;mail.example.com;mail.example.com;SMTP;RCPT;user01@gmal.com;gmal.com;user01;smtpd_access_policy;1.233.168.192;unknown;user01@mail.example.com;mail.example.com;user01;mail.example.com;mail.example.com;mail.example.com;mail.example.com;postfwd2 1.35; -> @id     -> 'WRONG_DOMAINS'
%request_cache -> %192.168.233.1;unknown;mail.example.com;mail.example.com;SMTP;RCPT;user01@gmal.com;gmal.com;user01;smtpd_access_policy;1.233.168.192;unknown;user01@mail.example.com;mail.example.com;user01;mail.example.com;mail.example.com;mail.example.com;mail.example.com;postfwd2 1.35; -> @ttl    -> '600'
%request_cache -> %192.168.233.1;unknown;mail.example.com;mail.example.com;SMTP;RCPT;user01@gmal.com;gmal.com;user01;smtpd_access_policy;1.233.168.192;unknown;user01@mail.example.com;mail.example.com;user01;mail.example.com;mail.example.com;mail.example.com;mail.example.com;postfwd2 1.35; -> @until  -> '1438783060.04902'

※各行のお尻の部分だけに注目すると内容を把握しやすいと思います。
@action -> 'REJECT Isn't an address gmail.com?'
@hit    -> '3'
@hits   -> 'WRONG_DOMAINS'
@id     -> 'WRONG_DOMAINS'
@ttl    -> '600'
@until  -> '1438783060.04902'


キャッシュのクリア


基本的にpostfwdの再起動をすればキャッシュはクリアされますが、全てのキャッシュが対象になってしまいます。
そうではなく、間違ってキャッシュしてしまった一部のキャッシュだけ削除する場合は以下のように実施します。

書式は以下のようになります。
# postfwd2 --delcache <item>
この<item>が意外と分かりにくいのですが、"--dumpcache"で出力される以下の青字部分を指定します。
%request_cache ->  %192.168.233.1;unknown;mail.example.com;mail.example.com;SMTP;RCPT;user01@gmal.com;gmal.com;user01;smtpd_access_policy;1.233.168.192;unknown;user01@mail.example.com;mail.example.com;user01;mail.example.com;mail.example.com;mail.example.com;mail.example.com;postfwd2 1.35; -> @until  -> '1438783708.62979'

以下、実行例です。
# postfwd2 --delcache="  %192.168.233.1;unknown;mail.example.com;mail.example.com;SMTP;RCPT;user01@gmal.com;gmal.com;user01;smtpd_access_policy;1.233.168.192;unknown;user01@mail.example.com;mail.example.com;user01;mail.example.com;mail.example.com;mail.example.com;mail.example.com;postfwd2 1.35;"

request cache item '192.168.233.1;unknown;mail.example.com;mail.example.com;SMTP;RCPT;user01@gmal.com;gmal.com;user01;smtpd_access_policy;1.233.168.192;unknown;user01@mail.example.com;mail.example.com;user01;mail.example.com;mail.example.com;mail.example.com;mail.example.com;postfwd2 1.35;' removed
#