filter: add XOR instruction for use with X/K
authorDaniel Borkmann <dxchgb@gmail.com>
Mon, 24 Sep 2012 02:23:59 +0000 (02:23 +0000)
committerDavid S. Miller <davem@davemloft.net>
Mon, 24 Sep 2012 20:49:21 +0000 (16:49 -0400)
SKF_AD_ALU_XOR_X has been added a while ago, but as an 'ancillary'
operation that is invoked through a negative offset in K within BPF
load operations. Since BPF_MOD has recently been added, BPF_XOR should
also be part of the common ALU operations. Removing SKF_AD_ALU_XOR_X
might not be an option since this is exposed to user space.

Signed-off-by: Daniel Borkmann <daniel.borkmann@tik.ee.ethz.ch>
Acked-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/linux/filter.h
net/core/filter.c

index 3cf5fd561d8649ce9647bce45a0e40dc28124a91..2ded090e10f4e511461cacdbfcdc031dc1dd0b3e 100644 (file)
@@ -75,6 +75,7 @@ struct sock_fprog {   /* Required for SO_ATTACH_FILTER. */
 #define         BPF_RSH         0x70
 #define         BPF_NEG         0x80
 #define                BPF_MOD         0x90
+#define                BPF_XOR         0xa0
 
 #define         BPF_JA          0x00
 #define         BPF_JEQ         0x10
@@ -204,6 +205,8 @@ enum {
        BPF_S_ALU_AND_X,
        BPF_S_ALU_OR_K,
        BPF_S_ALU_OR_X,
+       BPF_S_ALU_XOR_K,
+       BPF_S_ALU_XOR_X,
        BPF_S_ALU_LSH_K,
        BPF_S_ALU_LSH_X,
        BPF_S_ALU_RSH_K,
index fbe3a8d12570b9604825043e9f68764af15b0aa0..3d92ebb7fbcf71471d4b3d90e5309f459c47bea0 100644 (file)
@@ -187,6 +187,13 @@ unsigned int sk_run_filter(const struct sk_buff *skb,
                case BPF_S_ALU_OR_K:
                        A |= K;
                        continue;
+               case BPF_S_ANC_ALU_XOR_X:
+               case BPF_S_ALU_XOR_X:
+                       A ^= X;
+                       continue;
+               case BPF_S_ALU_XOR_K:
+                       A ^= K;
+                       continue;
                case BPF_S_ALU_LSH_X:
                        A <<= X;
                        continue;
@@ -334,9 +341,6 @@ load_b:
                case BPF_S_ANC_CPU:
                        A = raw_smp_processor_id();
                        continue;
-               case BPF_S_ANC_ALU_XOR_X:
-                       A ^= X;
-                       continue;
                case BPF_S_ANC_NLATTR: {
                        struct nlattr *nla;
 
@@ -483,6 +487,8 @@ int sk_chk_filter(struct sock_filter *filter, unsigned int flen)
                [BPF_ALU|BPF_AND|BPF_X]  = BPF_S_ALU_AND_X,
                [BPF_ALU|BPF_OR|BPF_K]   = BPF_S_ALU_OR_K,
                [BPF_ALU|BPF_OR|BPF_X]   = BPF_S_ALU_OR_X,
+               [BPF_ALU|BPF_XOR|BPF_K]  = BPF_S_ALU_XOR_K,
+               [BPF_ALU|BPF_XOR|BPF_X]  = BPF_S_ALU_XOR_X,
                [BPF_ALU|BPF_LSH|BPF_K]  = BPF_S_ALU_LSH_K,
                [BPF_ALU|BPF_LSH|BPF_X]  = BPF_S_ALU_LSH_X,
                [BPF_ALU|BPF_RSH|BPF_K]  = BPF_S_ALU_RSH_K,