aboutsummaryrefslogtreecommitdiffstats
path: root/samples
diff options
context:
space:
mode:
authorAlexei Starovoitov <ast@plumgrid.com>2015-06-04 13:11:53 -0400
committerDavid S. Miller <davem@davemloft.net>2015-06-07 05:01:33 -0400
commit3431205e03977aaf32bce6d4b16fb8244b510056 (patch)
tree0d9405acb8ac34a6bc5ad93a9b9ae674c4d3879e /samples
parent98da81a426a76c351f3c2854d5bc31f17bba3194 (diff)
bpf: make programs see skb->data == L2 for ingress and egress
eBPF programs attached to ingress and egress qdiscs see inconsistent skb->data. For ingress L2 header is already pulled, whereas for egress it's present. This is known to program writers which are currently forced to use BPF_LL_OFF workaround. Since programs don't change skb internal pointers it is safe to do pull/push right around invocation of the program and earlier taps and later pt->func() will not be affected. Multiple taps via packet_rcv(), tpacket_rcv() are doing the same trick around run_filter/BPF_PROG_RUN even if skb_shared. This fix finally allows programs to use optimized LD_ABS/IND instructions without BPF_LL_OFF for higher performance. tc ingress + cls_bpf + samples/bpf/tcbpf1_kern.o w/o JIT w/JIT before 20.5 23.6 Mpps after 21.8 26.6 Mpps Old programs with BPF_LL_OFF will still work as-is. We can now undo most of the earlier workaround commit: a166151cbe33 ("bpf: fix bpf helpers to use skb->mac_header relative offsets") Signed-off-by: Alexei Starovoitov <ast@plumgrid.com> Acked-by: Jamal Hadi Salim <jhs@mojatatu.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'samples')
-rw-r--r--samples/bpf/tcbpf1_kern.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/samples/bpf/tcbpf1_kern.c b/samples/bpf/tcbpf1_kern.c
index 7c27710f8296..9bfb2eb34563 100644
--- a/samples/bpf/tcbpf1_kern.c
+++ b/samples/bpf/tcbpf1_kern.c
@@ -21,7 +21,7 @@ static inline void set_dst_mac(struct __sk_buff *skb, char *mac)
21 21
22static inline void set_ip_tos(struct __sk_buff *skb, __u8 new_tos) 22static inline void set_ip_tos(struct __sk_buff *skb, __u8 new_tos)
23{ 23{
24 __u8 old_tos = load_byte(skb, BPF_LL_OFF + TOS_OFF); 24 __u8 old_tos = load_byte(skb, TOS_OFF);
25 25
26 bpf_l3_csum_replace(skb, IP_CSUM_OFF, htons(old_tos), htons(new_tos), 2); 26 bpf_l3_csum_replace(skb, IP_CSUM_OFF, htons(old_tos), htons(new_tos), 2);
27 bpf_skb_store_bytes(skb, TOS_OFF, &new_tos, sizeof(new_tos), 0); 27 bpf_skb_store_bytes(skb, TOS_OFF, &new_tos, sizeof(new_tos), 0);
@@ -34,7 +34,7 @@ static inline void set_ip_tos(struct __sk_buff *skb, __u8 new_tos)
34 34
35static inline void set_tcp_ip_src(struct __sk_buff *skb, __u32 new_ip) 35static inline void set_tcp_ip_src(struct __sk_buff *skb, __u32 new_ip)
36{ 36{
37 __u32 old_ip = _htonl(load_word(skb, BPF_LL_OFF + IP_SRC_OFF)); 37 __u32 old_ip = _htonl(load_word(skb, IP_SRC_OFF));
38 38
39 bpf_l4_csum_replace(skb, TCP_CSUM_OFF, old_ip, new_ip, IS_PSEUDO | sizeof(new_ip)); 39 bpf_l4_csum_replace(skb, TCP_CSUM_OFF, old_ip, new_ip, IS_PSEUDO | sizeof(new_ip));
40 bpf_l3_csum_replace(skb, IP_CSUM_OFF, old_ip, new_ip, sizeof(new_ip)); 40 bpf_l3_csum_replace(skb, IP_CSUM_OFF, old_ip, new_ip, sizeof(new_ip));
@@ -44,7 +44,7 @@ static inline void set_tcp_ip_src(struct __sk_buff *skb, __u32 new_ip)
44#define TCP_DPORT_OFF (ETH_HLEN + sizeof(struct iphdr) + offsetof(struct tcphdr, dest)) 44#define TCP_DPORT_OFF (ETH_HLEN + sizeof(struct iphdr) + offsetof(struct tcphdr, dest))
45static inline void set_tcp_dest_port(struct __sk_buff *skb, __u16 new_port) 45static inline void set_tcp_dest_port(struct __sk_buff *skb, __u16 new_port)
46{ 46{
47 __u16 old_port = htons(load_half(skb, BPF_LL_OFF + TCP_DPORT_OFF)); 47 __u16 old_port = htons(load_half(skb, TCP_DPORT_OFF));
48 48
49 bpf_l4_csum_replace(skb, TCP_CSUM_OFF, old_port, new_port, sizeof(new_port)); 49 bpf_l4_csum_replace(skb, TCP_CSUM_OFF, old_port, new_port, sizeof(new_port));
50 bpf_skb_store_bytes(skb, TCP_DPORT_OFF, &new_port, sizeof(new_port), 0); 50 bpf_skb_store_bytes(skb, TCP_DPORT_OFF, &new_port, sizeof(new_port), 0);
@@ -53,7 +53,7 @@ static inline void set_tcp_dest_port(struct __sk_buff *skb, __u16 new_port)
53SEC("classifier") 53SEC("classifier")
54int bpf_prog1(struct __sk_buff *skb) 54int bpf_prog1(struct __sk_buff *skb)
55{ 55{
56 __u8 proto = load_byte(skb, BPF_LL_OFF + ETH_HLEN + offsetof(struct iphdr, protocol)); 56 __u8 proto = load_byte(skb, ETH_HLEN + offsetof(struct iphdr, protocol));
57 long *value; 57 long *value;
58 58
59 if (proto == IPPROTO_TCP) { 59 if (proto == IPPROTO_TCP) {