aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPavel Emelyanov2012-10-31 21:01:48 -0500
committerDavid S. Miller2012-11-01 10:17:15 -0500
commita8fc92778080c845eaadc369a0ecf5699a03bef0 (patch)
tree2d83a965c40765c52195e32a903bd8c7678f014d /arch/mn10300
parent96442e42429e5f268ab97a3586c7694a3acc55a7 (diff)
downloadam43-linux-kernel-a8fc92778080c845eaadc369a0ecf5699a03bef0.tar.gz
am43-linux-kernel-a8fc92778080c845eaadc369a0ecf5699a03bef0.tar.xz
am43-linux-kernel-a8fc92778080c845eaadc369a0ecf5699a03bef0.zip
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>
Diffstat (limited to 'arch/mn10300')
-rw-r--r--arch/mn10300/include/uapi/asm/socket.h1
1 files changed, 1 insertions, 0 deletions
diff --git a/arch/mn10300/include/uapi/asm/socket.h b/arch/mn10300/include/uapi/asm/socket.h
index 820463a484b..af5366bbfe6 100644
--- a/arch/mn10300/include/uapi/asm/socket.h
+++ b/arch/mn10300/include/uapi/asm/socket.h
@@ -40,6 +40,7 @@
40/* Socket filtering */ 40/* Socket filtering */
41#define SO_ATTACH_FILTER 26 41#define SO_ATTACH_FILTER 26
42#define SO_DETACH_FILTER 27 42#define SO_DETACH_FILTER 27
43#define SO_GET_FILTER SO_ATTACH_FILTER
43 44
44#define SO_PEERNAME 28 45#define SO_PEERNAME 28
45#define SO_TIMESTAMP 29 46#define SO_TIMESTAMP 29