diff -uNpr vblade-15-orig/freebsd.c vblade-15-lsf/freebsd.c --- vblade-15-orig/freebsd.c 2008-03-07 20:22:16.000000000 +0000 +++ vblade-15-lsf/freebsd.c 2008-04-30 10:45:11.000000000 +0100 @@ -54,40 +54,44 @@ dial(char *eth) /* packet filter for bpf */ struct bpf_insn bpf_insns[] = { - /* Load the type into register */ - BPF_STMT(BPF_LD+BPF_H+BPF_ABS, 12), - /* Does it match AoE Type (0x88a2)? No, goto INVALID */ - BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, 0x88a2, 0, 10), - /* Load the flags into register */ - BPF_STMT(BPF_LD+BPF_B+BPF_ABS, 14), - /* Check to see if the Resp flag is set */ - BPF_STMT(BPF_ALU+BPF_AND+BPF_K, Resp), - /* Yes, goto INVALID */ - BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, 0, 0, 7), - /* Load the command into register */ - BPF_STMT(BPF_LD+BPF_B+BPF_ABS, 19), - /* Is this a ATAcmd? No, goto VALID */ - BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, ATAcmd, 0, 4), - /* Load the shelf number into register */ - BPF_STMT(BPF_LD+BPF_H+BPF_ABS, 16), - /* Does it match shelf number? No, goto INVALID */ - BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, (u_int) shelf, 0, 3), - /* Load the slot number into register */ - BPF_STMT(BPF_LD+BPF_B+BPF_ABS, 18), - /* Does it match shelf number? No, goto INVALID */ - BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, (u_int) slot, 0, 1), - /* VALID: return -1 (allow the packet to be read) */ - BPF_STMT(BPF_RET+BPF_K, (u_int)-1), - /* INVALID: return 0 (ignore the packet) */ - BPF_STMT(BPF_RET+BPF_K, 0), + /* Load the type into register */ + BPF_STMT(BPF_LD+BPF_H+BPF_ABS, 12), + /* Does it match AoE Type (0x88a2)? No, goto INVALID */ + BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, 0x88a2, 0, 12), + /* Load the flags into register */ + BPF_STMT(BPF_LD+BPF_B+BPF_ABS, 14), + /* Check to see if the Resp flag is set */ + BPF_STMT(BPF_ALU+BPF_AND+BPF_K, Resp), + /* Yes, goto INVALID */ + BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, 0, 0, 9), + /* Load the shelf number into register */ + BPF_STMT(BPF_LD+BPF_H+BPF_ABS, 16), + /* Does it match shelf number? No, goto CHECKBROADCAST */ + BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, (u_int) shelf, 0, 2), + /* Load the slot number into register */ + BPF_STMT(BPF_LD+BPF_B+BPF_ABS, 18), + /* Does it match shelf number? Yes, goto VALID */ + BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, (u_int) slot, 4, 0), + /* CHECKBROADCAST: is (shelf, slot) == (0xffff, 0xff)? */ + /* Load the shelf number into register */ + BPF_STMT(BPF_LD+BPF_H+BPF_ABS, 16), + /* Is it 0xffff? No, goto INVALID */ + BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, (u_int) 0xffff, 0, 3), + /* Load the slot number into register */ + BPF_STMT(BPF_LD+BPF_B+BPF_ABS, 18), + /* Is it 0xff? No, goto INVALID */ + BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, (u_int) 0xff, 0, 1), + /* VALID: return -1 (allow the packet to be read) */ + BPF_STMT(BPF_RET+BPF_K, (u_int) -1), + /* INVALID: return 0 (ignore the packet) */ + BPF_STMT(BPF_RET+BPF_K, 0), }; struct bpf_program bpf_program = { - sizeof(bpf_insns)/sizeof(struct bpf_insn), - bpf_insns + sizeof(bpf_insns)/sizeof(struct bpf_insn), + bpf_insns }; - - + strncpy(device, BPF_DEV, sizeof BPF_DEV); /* find a bpf device we can use, check /dev/bpf[0-9] */ diff -uNpr vblade-15-orig/linux.c vblade-15-lsf/linux.c --- vblade-15-orig/linux.c 2008-03-07 20:22:16.000000000 +0000 +++ vblade-15-lsf/linux.c 2008-04-30 10:46:04.000000000 +0100 @@ -22,6 +22,7 @@ #include #include #include +#include #include "dat.h" #include "fns.h" @@ -54,6 +55,49 @@ dial(char *eth) // get us a raw connect perror("bind funky"); return -1; } + + /* bpf packet filter for socket */ + struct bpf_insn bpf_insns[] = { + /* Load the type into register */ + BPF_STMT(BPF_LD+BPF_H+BPF_ABS, 12), + /* Does it match AoE Type (0x88a2)? No, goto INVALID */ + BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, 0x88a2, 0, 12), + /* Load the flags into register */ + BPF_STMT(BPF_LD+BPF_B+BPF_ABS, 14), + /* Check to see if the Resp flag is set */ + BPF_STMT(BPF_ALU+BPF_AND+BPF_K, Resp), + /* Yes, goto INVALID */ + BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, 0, 0, 9), + /* Load the shelf number into register */ + BPF_STMT(BPF_LD+BPF_H+BPF_ABS, 16), + /* Does it match shelf number? No, goto CHECKBROADCAST */ + BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, (u_int) shelf, 0, 2), + /* Load the slot number into register */ + BPF_STMT(BPF_LD+BPF_B+BPF_ABS, 18), + /* Does it match shelf number? Yes, goto VALID */ + BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, (u_int) slot, 4, 0), + /* CHECKBROADCAST: is (shelf, slot) == (0xffff, 0xff)? */ + /* Load the shelf number into register */ + BPF_STMT(BPF_LD+BPF_H+BPF_ABS, 16), + /* Is it 0xffff? No, goto INVALID */ + BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, (u_int) 0xffff, 0, 3), + /* Load the slot number into register */ + BPF_STMT(BPF_LD+BPF_B+BPF_ABS, 18), + /* Is it 0xff? No, goto INVALID */ + BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, (u_int) 0xff, 0, 1), + /* VALID: return -1 (allow the packet to be read) */ + BPF_STMT(BPF_RET+BPF_K, (u_int) -1), + /* INVALID: return 0 (ignore the packet) */ + BPF_STMT(BPF_RET+BPF_K, 0), + }; + + struct bpf_program bpf_program = { + sizeof(bpf_insns)/sizeof(struct bpf_insn), + bpf_insns + }; + + setsockopt(s, SOL_SOCKET, SO_ATTACH_FILTER, &bpf_program, sizeof(bpf_program)); + return s; }