From: David Miller <davem@davemloft.net>
To: xemul@parallels.com
Cc: netdev@vger.kernel.org
Subject: Re: [PATCH net-next] sk-filter: Add ability to get socket filter program (v2)
Date: Thu, 01 Nov 2012 11:17:58 -0400 (EDT) [thread overview]
Message-ID: <20121101.111758.587399436547929971.davem@davemloft.net> (raw)
In-Reply-To: <509264AC.5090802@parallels.com>
From: Pavel Emelyanov <xemul@parallels.com>
Date: Thu, 01 Nov 2012 16:01:48 +0400
> The SO_ATTACH_FILTER option is set only. I propose to add the get
> ability by using SO_ATTACH_FILTER in getsockopt. To be less
> irritating to eyes the SO_GET_FILTER alias to it is declared. This
> ability is required by checkpoint-restore project to be able to
> save full state of a socket.
>
>
> There are two issues with getting filter back.
>
> First, kernel modifies the sock_filter->code on filter load, thus in
> order to return the filter element back to user we have to decode it
> into user-visible constants. Fortunately the modification in question
> is interconvertible.
>
> Second, the BPF_S_ALU_DIV_K code modifies the command argument k to
> speed up the run-time division by doing kernel_k = reciprocal(user_k).
> Bad news is that different user_k may result in same kernel_k, so we
> can't get the original user_k back. Good news is that we don't have
> to do it. What we need to is calculate a user2_k so, that
>
> reciprocal(user2_k) == reciprocal(user_k) == kernel_k
>
> i.e. if it's re-loaded back the compiled again value will be exactly
> the same as it was. That said, the user2_k can be calculated like this
>
> user2_k = reciprocal(kernel_k)
>
> with an exception, that if kernel_k == 0, then user2_k == 1.
>
>
> The optlen argument is treated like this -- when zero, kernel returns
> the amount of sock_fprog elements in filter, otherwise it should be
> large enough for the sock_fprog array.
>
> changes since v1:
> * Declared SO_GET_FILTER in all arch headers
> * Added decode of vlan-tag codes
>
> Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Applied, thanks.
prev parent reply other threads:[~2012-11-01 15:18 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-11-01 12:01 [PATCH net-next] sk-filter: Add ability to get socket filter program (v2) Pavel Emelyanov
2012-11-01 15:17 ` David Miller [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20121101.111758.587399436547929971.davem@davemloft.net \
--to=davem@davemloft.net \
--cc=netdev@vger.kernel.org \
--cc=xemul@parallels.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox