linux/arch
Pavel Emelyanov a8fc927780 sk-filter: Add ability to get socket filter program (v2)
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>
Signed-off-by: David S. Miller <davem@davemloft.net>
2012-11-01 11:17:15 -04:00
..
alpha sk-filter: Add ability to get socket filter program (v2) 2012-11-01 11:17:15 -04:00
arm net/at91_ether: add pdata flag for reverse Eth addr 2012-10-23 02:40:10 -04:00
arm64 UAPI headers for arm64 together with some clean-up to make it possible: 2012-10-13 11:20:04 +09:00
avr32 sk-filter: Add ability to get socket filter program (v2) 2012-11-01 11:17:15 -04:00
blackfin Merge branch 'modules-next' of git://git.kernel.org/pub/scm/linux/kernel/git/rusty/linux 2012-10-14 13:39:34 -07:00
c6x Merge branch 'modules-next' of git://git.kernel.org/pub/scm/linux/kernel/git/rusty/linux 2012-10-14 13:39:34 -07:00
cris sk-filter: Add ability to get socket filter program (v2) 2012-11-01 11:17:15 -04:00
frv sk-filter: Add ability to get socket filter program (v2) 2012-11-01 11:17:15 -04:00
h8300 sk-filter: Add ability to get socket filter program (v2) 2012-11-01 11:17:15 -04:00
hexagon Merge branch 'modules-next' of git://git.kernel.org/pub/scm/linux/kernel/git/rusty/linux 2012-10-14 13:39:34 -07:00
ia64 sk-filter: Add ability to get socket filter program (v2) 2012-11-01 11:17:15 -04:00
m32r sk-filter: Add ability to get socket filter program (v2) 2012-11-01 11:17:15 -04:00
m68k sk-filter: Add ability to get socket filter program (v2) 2012-11-01 11:17:15 -04:00
microblaze Merge branch 'modules-next' of git://git.kernel.org/pub/scm/linux/kernel/git/rusty/linux 2012-10-14 13:39:34 -07:00
mips sk-filter: Add ability to get socket filter program (v2) 2012-11-01 11:17:15 -04:00
mn10300 sk-filter: Add ability to get socket filter program (v2) 2012-11-01 11:17:15 -04:00
openrisc Merge branch 'modules-next' of git://git.kernel.org/pub/scm/linux/kernel/git/rusty/linux 2012-10-14 13:39:34 -07:00
parisc sk-filter: Add ability to get socket filter program (v2) 2012-11-01 11:17:15 -04:00
powerpc sk-filter: Add ability to get socket filter program (v2) 2012-11-01 11:17:15 -04:00
s390 sk-filter: Add ability to get socket filter program (v2) 2012-11-01 11:17:15 -04:00
score Merge branch 'modules-next' of git://git.kernel.org/pub/scm/linux/kernel/git/rusty/linux 2012-10-14 13:39:34 -07:00
sh UAPI: Make arch/sh/include/uapi/asm/hw_breakpoint.h non-empty 2012-10-17 12:32:35 +01:00
sparc sk-filter: Add ability to get socket filter program (v2) 2012-11-01 11:17:15 -04:00
tile UAPI: The tile arch uses the generic ucontext.h file 2012-10-17 12:31:16 +01:00
um Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/signal 2012-10-13 10:05:52 +09:00
unicore32 Merge branch 'modules-next' of git://git.kernel.org/pub/scm/linux/kernel/git/rusty/linux 2012-10-14 13:39:34 -07:00
x86 x86: bpf_jit_comp: add vlan tag support 2012-10-31 14:00:15 -04:00
xtensa sk-filter: Add ability to get socket filter program (v2) 2012-11-01 11:17:15 -04:00
.gitignore
Kconfig Merge branch 'modules-next' of git://git.kernel.org/pub/scm/linux/kernel/git/rusty/linux 2012-10-14 13:39:34 -07:00