linux-stable/arch/avr32
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
..
boards avr32: fix build error in ATSTK1002 code 2012-07-30 17:25:13 -07:00
boot Kbuild: centralize MKIMAGE and cmd_uimage definitions 2012-03-26 15:49:20 +02:00
configs rtc: fix build warnings in defconfigs 2011-06-15 20:04:02 -07:00
include sk-filter: Add ability to get socket filter program (v2) 2012-11-01 11:17:15 -04:00
kernel vfs: define struct filename and have getname() return it 2012-10-12 20:14:55 -04:00
lib asm-generic: rename generic little-endian bitops functions 2011-03-23 19:46:11 -07:00
mach-at32ap dw_dmac: autoconfigure data_width or get it via platform data 2012-09-27 15:35:23 +05:30
mm readahead: fault retry breaks mmap file read random detection 2012-10-09 16:22:47 +09:00
oprofile Disintegrate asm/system.h for AVR32 2012-03-28 18:30:01 +01:00
Kconfig net/cadence: get rid of HAVE_NET_MACB 2012-10-23 02:40:09 -04:00
Kconfig.debug [AVR32] Include instrumentation menu 2008-01-25 08:31:40 +01:00
Makefile kbuild: allow assignment to {A,C,LD}FLAGS_MODULE on the command line 2010-08-03 14:09:45 +02:00