aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Dumazet <eric.dumazet@gmail.com>2010-11-18 16:56:38 -0500
committerDavid S. Miller <davem@davemloft.net>2010-11-19 13:04:23 -0500
commit8c1592d68bc89248bfd0ee287648f41c1370d826 (patch)
tree1c1d7abe548c92839c55cfe0f0a3745e7ddd3b78
parent93aaae2e01e57483256b7da05c9a7ebd65ad4686 (diff)
filter: cleanup codes[] init
Starting the translated instruction to 1 instead of 0 allows us to remove one descrement at check time and makes codes[] array init cleaner. Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com> Acked-by: Changli Gao <xiaosuo@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--net/core/filter.c95
1 files changed, 47 insertions, 48 deletions
diff --git a/net/core/filter.c b/net/core/filter.c
index 9e77b3c816c5..c0b68f7c8036 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -39,7 +39,7 @@
39#include <linux/filter.h> 39#include <linux/filter.h>
40 40
41enum { 41enum {
42 BPF_S_RET_K = 0, 42 BPF_S_RET_K = 1,
43 BPF_S_RET_A, 43 BPF_S_RET_A,
44 BPF_S_ALU_ADD_K, 44 BPF_S_ALU_ADD_K,
45 BPF_S_ALU_ADD_X, 45 BPF_S_ALU_ADD_X,
@@ -439,51 +439,51 @@ int sk_chk_filter(struct sock_filter *filter, int flen)
439 * Invalid instructions are initialized to 0. 439 * Invalid instructions are initialized to 0.
440 */ 440 */
441 static const u8 codes[] = { 441 static const u8 codes[] = {
442 [BPF_ALU|BPF_ADD|BPF_K] = BPF_S_ALU_ADD_K + 1, 442 [BPF_ALU|BPF_ADD|BPF_K] = BPF_S_ALU_ADD_K,
443 [BPF_ALU|BPF_ADD|BPF_X] = BPF_S_ALU_ADD_X + 1, 443 [BPF_ALU|BPF_ADD|BPF_X] = BPF_S_ALU_ADD_X,
444 [BPF_ALU|BPF_SUB|BPF_K] = BPF_S_ALU_SUB_K + 1, 444 [BPF_ALU|BPF_SUB|BPF_K] = BPF_S_ALU_SUB_K,
445 [BPF_ALU|BPF_SUB|BPF_X] = BPF_S_ALU_SUB_X + 1, 445 [BPF_ALU|BPF_SUB|BPF_X] = BPF_S_ALU_SUB_X,
446 [BPF_ALU|BPF_MUL|BPF_K] = BPF_S_ALU_MUL_K + 1, 446 [BPF_ALU|BPF_MUL|BPF_K] = BPF_S_ALU_MUL_K,
447 [BPF_ALU|BPF_MUL|BPF_X] = BPF_S_ALU_MUL_X + 1, 447 [BPF_ALU|BPF_MUL|BPF_X] = BPF_S_ALU_MUL_X,
448 [BPF_ALU|BPF_DIV|BPF_X] = BPF_S_ALU_DIV_X + 1, 448 [BPF_ALU|BPF_DIV|BPF_X] = BPF_S_ALU_DIV_X,
449 [BPF_ALU|BPF_AND|BPF_K] = BPF_S_ALU_AND_K + 1, 449 [BPF_ALU|BPF_AND|BPF_K] = BPF_S_ALU_AND_K,
450 [BPF_ALU|BPF_AND|BPF_X] = BPF_S_ALU_AND_X + 1, 450 [BPF_ALU|BPF_AND|BPF_X] = BPF_S_ALU_AND_X,
451 [BPF_ALU|BPF_OR|BPF_K] = BPF_S_ALU_OR_K + 1, 451 [BPF_ALU|BPF_OR|BPF_K] = BPF_S_ALU_OR_K,
452 [BPF_ALU|BPF_OR|BPF_X] = BPF_S_ALU_OR_X + 1, 452 [BPF_ALU|BPF_OR|BPF_X] = BPF_S_ALU_OR_X,
453 [BPF_ALU|BPF_LSH|BPF_K] = BPF_S_ALU_LSH_K + 1, 453 [BPF_ALU|BPF_LSH|BPF_K] = BPF_S_ALU_LSH_K,
454 [BPF_ALU|BPF_LSH|BPF_X] = BPF_S_ALU_LSH_X + 1, 454 [BPF_ALU|BPF_LSH|BPF_X] = BPF_S_ALU_LSH_X,
455 [BPF_ALU|BPF_RSH|BPF_K] = BPF_S_ALU_RSH_K + 1, 455 [BPF_ALU|BPF_RSH|BPF_K] = BPF_S_ALU_RSH_K,
456 [BPF_ALU|BPF_RSH|BPF_X] = BPF_S_ALU_RSH_X + 1, 456 [BPF_ALU|BPF_RSH|BPF_X] = BPF_S_ALU_RSH_X,
457 [BPF_ALU|BPF_NEG] = BPF_S_ALU_NEG + 1, 457 [BPF_ALU|BPF_NEG] = BPF_S_ALU_NEG,
458 [BPF_LD|BPF_W|BPF_ABS] = BPF_S_LD_W_ABS + 1, 458 [BPF_LD|BPF_W|BPF_ABS] = BPF_S_LD_W_ABS,
459 [BPF_LD|BPF_H|BPF_ABS] = BPF_S_LD_H_ABS + 1, 459 [BPF_LD|BPF_H|BPF_ABS] = BPF_S_LD_H_ABS,
460 [BPF_LD|BPF_B|BPF_ABS] = BPF_S_LD_B_ABS + 1, 460 [BPF_LD|BPF_B|BPF_ABS] = BPF_S_LD_B_ABS,
461 [BPF_LD|BPF_W|BPF_LEN] = BPF_S_LD_W_LEN + 1, 461 [BPF_LD|BPF_W|BPF_LEN] = BPF_S_LD_W_LEN,
462 [BPF_LD|BPF_W|BPF_IND] = BPF_S_LD_W_IND + 1, 462 [BPF_LD|BPF_W|BPF_IND] = BPF_S_LD_W_IND,
463 [BPF_LD|BPF_H|BPF_IND] = BPF_S_LD_H_IND + 1, 463 [BPF_LD|BPF_H|BPF_IND] = BPF_S_LD_H_IND,
464 [BPF_LD|BPF_B|BPF_IND] = BPF_S_LD_B_IND + 1, 464 [BPF_LD|BPF_B|BPF_IND] = BPF_S_LD_B_IND,
465 [BPF_LD|BPF_IMM] = BPF_S_LD_IMM + 1, 465 [BPF_LD|BPF_IMM] = BPF_S_LD_IMM,
466 [BPF_LDX|BPF_W|BPF_LEN] = BPF_S_LDX_W_LEN + 1, 466 [BPF_LDX|BPF_W|BPF_LEN] = BPF_S_LDX_W_LEN,
467 [BPF_LDX|BPF_B|BPF_MSH] = BPF_S_LDX_B_MSH + 1, 467 [BPF_LDX|BPF_B|BPF_MSH] = BPF_S_LDX_B_MSH,
468 [BPF_LDX|BPF_IMM] = BPF_S_LDX_IMM + 1, 468 [BPF_LDX|BPF_IMM] = BPF_S_LDX_IMM,
469 [BPF_MISC|BPF_TAX] = BPF_S_MISC_TAX + 1, 469 [BPF_MISC|BPF_TAX] = BPF_S_MISC_TAX,
470 [BPF_MISC|BPF_TXA] = BPF_S_MISC_TXA + 1, 470 [BPF_MISC|BPF_TXA] = BPF_S_MISC_TXA,
471 [BPF_RET|BPF_K] = BPF_S_RET_K + 1, 471 [BPF_RET|BPF_K] = BPF_S_RET_K,
472 [BPF_RET|BPF_A] = BPF_S_RET_A + 1, 472 [BPF_RET|BPF_A] = BPF_S_RET_A,
473 [BPF_ALU|BPF_DIV|BPF_K] = BPF_S_ALU_DIV_K + 1, 473 [BPF_ALU|BPF_DIV|BPF_K] = BPF_S_ALU_DIV_K,
474 [BPF_LD|BPF_MEM] = BPF_S_LD_MEM + 1, 474 [BPF_LD|BPF_MEM] = BPF_S_LD_MEM,
475 [BPF_LDX|BPF_MEM] = BPF_S_LDX_MEM + 1, 475 [BPF_LDX|BPF_MEM] = BPF_S_LDX_MEM,
476 [BPF_ST] = BPF_S_ST + 1, 476 [BPF_ST] = BPF_S_ST,
477 [BPF_STX] = BPF_S_STX + 1, 477 [BPF_STX] = BPF_S_STX,
478 [BPF_JMP|BPF_JA] = BPF_S_JMP_JA + 1, 478 [BPF_JMP|BPF_JA] = BPF_S_JMP_JA,
479 [BPF_JMP|BPF_JEQ|BPF_K] = BPF_S_JMP_JEQ_K + 1, 479 [BPF_JMP|BPF_JEQ|BPF_K] = BPF_S_JMP_JEQ_K,
480 [BPF_JMP|BPF_JEQ|BPF_X] = BPF_S_JMP_JEQ_X + 1, 480 [BPF_JMP|BPF_JEQ|BPF_X] = BPF_S_JMP_JEQ_X,
481 [BPF_JMP|BPF_JGE|BPF_K] = BPF_S_JMP_JGE_K + 1, 481 [BPF_JMP|BPF_JGE|BPF_K] = BPF_S_JMP_JGE_K,
482 [BPF_JMP|BPF_JGE|BPF_X] = BPF_S_JMP_JGE_X + 1, 482 [BPF_JMP|BPF_JGE|BPF_X] = BPF_S_JMP_JGE_X,
483 [BPF_JMP|BPF_JGT|BPF_K] = BPF_S_JMP_JGT_K + 1, 483 [BPF_JMP|BPF_JGT|BPF_K] = BPF_S_JMP_JGT_K,
484 [BPF_JMP|BPF_JGT|BPF_X] = BPF_S_JMP_JGT_X + 1, 484 [BPF_JMP|BPF_JGT|BPF_X] = BPF_S_JMP_JGT_X,
485 [BPF_JMP|BPF_JSET|BPF_K] = BPF_S_JMP_JSET_K + 1, 485 [BPF_JMP|BPF_JSET|BPF_K] = BPF_S_JMP_JSET_K,
486 [BPF_JMP|BPF_JSET|BPF_X] = BPF_S_JMP_JSET_X + 1, 486 [BPF_JMP|BPF_JSET|BPF_X] = BPF_S_JMP_JSET_X,
487 }; 487 };
488 int pc; 488 int pc;
489 489
@@ -498,8 +498,7 @@ int sk_chk_filter(struct sock_filter *filter, int flen)
498 if (code >= ARRAY_SIZE(codes)) 498 if (code >= ARRAY_SIZE(codes))
499 return -EINVAL; 499 return -EINVAL;
500 code = codes[code]; 500 code = codes[code];
501 /* Undo the '+ 1' in codes[] after validation. */ 501 if (!code)
502 if (!code--)
503 return -EINVAL; 502 return -EINVAL;
504 /* Some instructions need special checks */ 503 /* Some instructions need special checks */
505 switch (code) { 504 switch (code) {