* [PATCH net-next] bpf: allow BPF programs access skb->skb_iif and skb->dev->ifindex fields
@ 2015-05-27 22:30 Alexei Starovoitov
2015-05-28 19:22 ` Daniel Borkmann
2015-05-31 0:51 ` David Miller
0 siblings, 2 replies; 6+ messages in thread
From: Alexei Starovoitov @ 2015-05-27 22:30 UTC (permalink / raw)
To: David S. Miller; +Cc: Daniel Borkmann, netdev
classic BPF already exposes skb->dev->ifindex via SKF_AD_IFINDEX extension.
Allow eBPF program to access it as well. Note that classic aborts execution
of the program if 'skb->dev == NULL' (which is inconvenient for program
writers), whereas eBPF returns zero in such case.
Also expose the 'skb_iif' field, since programs triggered by redirected
packet need to known the original interface index.
Summary:
__skb->ifindex -> skb->dev->ifindex
__skb->ingress_ifindex -> skb->skb_iif
Signed-off-by: Alexei Starovoitov <ast@plumgrid.com>
---
include/uapi/linux/bpf.h | 2 ++
net/core/filter.c | 18 ++++++++++++++++++
2 files changed, 20 insertions(+)
diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
index f0a9af8b4dae..72f3080afa1e 100644
--- a/include/uapi/linux/bpf.h
+++ b/include/uapi/linux/bpf.h
@@ -236,6 +236,8 @@ struct __sk_buff {
__u32 vlan_tci;
__u32 vlan_proto;
__u32 priority;
+ __u32 ingress_ifindex;
+ __u32 ifindex;
};
#endif /* _UAPI__LINUX_BPF_H__ */
diff --git a/net/core/filter.c b/net/core/filter.c
index 3adcca6f17a4..2c30d6632d66 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -1499,6 +1499,24 @@ static u32 sk_filter_convert_ctx_access(int dst_reg, int src_reg, int ctx_off,
offsetof(struct sk_buff, priority));
break;
+ case offsetof(struct __sk_buff, ingress_ifindex):
+ BUILD_BUG_ON(FIELD_SIZEOF(struct sk_buff, skb_iif) != 4);
+
+ *insn++ = BPF_LDX_MEM(BPF_W, dst_reg, src_reg,
+ offsetof(struct sk_buff, skb_iif));
+ break;
+
+ case offsetof(struct __sk_buff, ifindex):
+ BUILD_BUG_ON(FIELD_SIZEOF(struct net_device, ifindex) != 4);
+
+ *insn++ = BPF_LDX_MEM(bytes_to_bpf_size(FIELD_SIZEOF(struct sk_buff, dev)),
+ dst_reg, src_reg,
+ offsetof(struct sk_buff, dev));
+ *insn++ = BPF_JMP_IMM(BPF_JEQ, dst_reg, 0, 1);
+ *insn++ = BPF_LDX_MEM(BPF_W, dst_reg, dst_reg,
+ offsetof(struct net_device, ifindex));
+ break;
+
case offsetof(struct __sk_buff, mark):
return convert_skb_access(SKF_AD_MARK, dst_reg, src_reg, insn);
--
1.7.9.5
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH net-next] bpf: allow BPF programs access skb->skb_iif and skb->dev->ifindex fields
2015-05-27 22:30 [PATCH net-next] bpf: allow BPF programs access skb->skb_iif and skb->dev->ifindex fields Alexei Starovoitov
@ 2015-05-28 19:22 ` Daniel Borkmann
2015-05-29 3:40 ` Alexei Starovoitov
2015-05-31 0:51 ` David Miller
1 sibling, 1 reply; 6+ messages in thread
From: Daniel Borkmann @ 2015-05-28 19:22 UTC (permalink / raw)
To: Alexei Starovoitov, David S. Miller; +Cc: netdev
On 05/28/2015 12:30 AM, Alexei Starovoitov wrote:
> classic BPF already exposes skb->dev->ifindex via SKF_AD_IFINDEX extension.
> Allow eBPF program to access it as well. Note that classic aborts execution
> of the program if 'skb->dev == NULL' (which is inconvenient for program
> writers), whereas eBPF returns zero in such case.
That's better, yep.
> Also expose the 'skb_iif' field, since programs triggered by redirected
> packet need to known the original interface index.
> Summary:
> __skb->ifindex -> skb->dev->ifindex
> __skb->ingress_ifindex -> skb->skb_iif
>
> Signed-off-by: Alexei Starovoitov <ast@plumgrid.com>
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net-next] bpf: allow BPF programs access skb->skb_iif and skb->dev->ifindex fields
2015-05-28 19:22 ` Daniel Borkmann
@ 2015-05-29 3:40 ` Alexei Starovoitov
2015-05-29 3:43 ` David Miller
0 siblings, 1 reply; 6+ messages in thread
From: Alexei Starovoitov @ 2015-05-29 3:40 UTC (permalink / raw)
To: Daniel Borkmann, David S. Miller; +Cc: netdev
On 5/28/15 12:22 PM, Daniel Borkmann wrote:
>>
>> Signed-off-by: Alexei Starovoitov <ast@plumgrid.com>
>
> Acked-by: Daniel Borkmann <daniel@iogearbox.net>
btw, Daniel, your ack appeared on the mailing list, but didn't make
it into patchwork...
Same issue as I was having.
I noticed when I send email via gmail web interface it always
appears as separate thread and doesn't register in patchwork.
So now I've switched to mutt and thunderbird only :)
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net-next] bpf: allow BPF programs access skb->skb_iif and skb->dev->ifindex fields
2015-05-29 3:40 ` Alexei Starovoitov
@ 2015-05-29 3:43 ` David Miller
2015-05-29 8:44 ` Daniel Borkmann
0 siblings, 1 reply; 6+ messages in thread
From: David Miller @ 2015-05-29 3:43 UTC (permalink / raw)
To: ast; +Cc: daniel, netdev
From: Alexei Starovoitov <ast@plumgrid.com>
Date: Thu, 28 May 2015 20:40:44 -0700
> On 5/28/15 12:22 PM, Daniel Borkmann wrote:
>>>
>>> Signed-off-by: Alexei Starovoitov <ast@plumgrid.com>
>>
>> Acked-by: Daniel Borkmann <daniel@iogearbox.net>
>
> btw, Daniel, your ack appeared on the mailing list, but didn't make
> it into patchwork...
> Same issue as I was having.
> I noticed when I send email via gmail web interface it always
> appears as separate thread and doesn't register in patchwork.
> So now I've switched to mutt and thunderbird only :)
patchwork lost 22 hours of list traffic, but it should be functioning
normally now
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net-next] bpf: allow BPF programs access skb->skb_iif and skb->dev->ifindex fields
2015-05-29 3:43 ` David Miller
@ 2015-05-29 8:44 ` Daniel Borkmann
0 siblings, 0 replies; 6+ messages in thread
From: Daniel Borkmann @ 2015-05-29 8:44 UTC (permalink / raw)
To: David Miller, ast; +Cc: netdev
On 05/29/2015 05:43 AM, David Miller wrote:
> From: Alexei Starovoitov <ast@plumgrid.com>
> Date: Thu, 28 May 2015 20:40:44 -0700
...
>> btw, Daniel, your ack appeared on the mailing list, but didn't make
>> it into patchwork...
>> Same issue as I was having.
>> I noticed when I send email via gmail web interface it always
>> appears as separate thread and doesn't register in patchwork.
>> So now I've switched to mutt and thunderbird only :)
>
> patchwork lost 22 hours of list traffic, but it should be functioning
> normally now
Ok, great. So, lets try once more. :)
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net-next] bpf: allow BPF programs access skb->skb_iif and skb->dev->ifindex fields
2015-05-27 22:30 [PATCH net-next] bpf: allow BPF programs access skb->skb_iif and skb->dev->ifindex fields Alexei Starovoitov
2015-05-28 19:22 ` Daniel Borkmann
@ 2015-05-31 0:51 ` David Miller
1 sibling, 0 replies; 6+ messages in thread
From: David Miller @ 2015-05-31 0:51 UTC (permalink / raw)
To: ast; +Cc: daniel, netdev
From: Alexei Starovoitov <ast@plumgrid.com>
Date: Wed, 27 May 2015 15:30:39 -0700
> classic BPF already exposes skb->dev->ifindex via SKF_AD_IFINDEX extension.
> Allow eBPF program to access it as well. Note that classic aborts execution
> of the program if 'skb->dev == NULL' (which is inconvenient for program
> writers), whereas eBPF returns zero in such case.
> Also expose the 'skb_iif' field, since programs triggered by redirected
> packet need to known the original interface index.
> Summary:
> __skb->ifindex -> skb->dev->ifindex
> __skb->ingress_ifindex -> skb->skb_iif
>
> Signed-off-by: Alexei Starovoitov <ast@plumgrid.com>
Applied, thank you.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2015-05-31 0:51 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-05-27 22:30 [PATCH net-next] bpf: allow BPF programs access skb->skb_iif and skb->dev->ifindex fields Alexei Starovoitov
2015-05-28 19:22 ` Daniel Borkmann
2015-05-29 3:40 ` Alexei Starovoitov
2015-05-29 3:43 ` David Miller
2015-05-29 8:44 ` Daniel Borkmann
2015-05-31 0:51 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).