/* * Linux Socket Filter - Kernel level socket filtering * * Based on the design of the Berkeley Packet Filter. The new * internal format has been designed by PLUMgrid: * * Copyright (c) 2011 - 2014 PLUMgrid, http://plumgrid.com * * Authors: * * Jay Schulist <jschlst@samba.org> * Alexei Starovoitov <ast@plumgrid.com> * Daniel Borkmann <dborkman@redhat.com> * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version * 2 of the License, or (at your option) any later version. * * Andi Kleen - Fix a few bad bugs and races. * Kris Katterjohn - Added many additional checks in bpf_check_classic() */#include<linux/filter.h>#include<linux/skbuff.h>#include<linux/vmalloc.h>#include<linux/random.h>#include<linux/moduleloader.h>#include<linux/bpf.h>#include<linux/frame.h>#include<linux/rbtree_latch.h>#include<linux/kallsyms.h>#include<linux/rcupdate.h>#include<asm/unaligned.h>/* Registers */#define BPF_R0 regs[BPF_REG_0]#define BPF_R1 regs[BPF_REG_1]#define BPF_R2 regs[BPF_REG_2]#define BPF_R3 regs[BPF_REG_3]#define BPF_R4 regs[BPF_REG_4]#define BPF_R5 regs[BPF_REG_5]#define BPF_R6 regs[BPF_REG_6]#define BPF_R7 regs[BPF_REG_7]#define BPF_R8 regs[BPF_REG_8]#define BPF_R9 regs[BPF_REG_9]#define BPF_R10 regs[BPF_REG_10]/* Named registers */#define DST regs[insn->dst_reg]#define SRC regs[insn->src_reg]#define FP regs[BPF_REG_FP]#define ARG1 regs[BPF_REG_ARG1]#define CTX regs[BPF_REG_CTX]#define IMM insn->imm/* No hurry in this branch * * Exported for the bpf jit load helper. */void*bpf_internal_load_pointer_neg_helper(conststructsk_buff*skb,intk,unsignedintsize){u8*ptr=NULL;if(k>=SKF_NET_OFF)ptr=skb_network_header(skb)+k-SKF_NET_OFF;elseif(k>=SKF_LL_OFF)ptr=skb_mac_header(skb)+k-SKF_LL_OFF;if(ptr>=skb->head&&ptr+size<=skb_tail_pointer(skb))returnptr;returnNULL;}structbpf_prog*