From: Daniel Borkmann Date: Wed, 17 Aug 2016 23:00:38 +0000 (+0200) Subject: bpf: use skb_pkt_type_ok helper in bpf_skb_change_type X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=45c7fffaf72e77baab9fd8ff1655540a1d5bac9f;p=openwrt%2Fstaging%2Fblogic.git bpf: use skb_pkt_type_ok helper in bpf_skb_change_type Since we have a skb_pkt_type_ok() helper for checking the type before mangling, make use of it instead of open coding. Follow-up to commit 8b10cab64c13 ("net: simplify and make pkt_type_ok() available for other users") that came in after d2485c4242a8 ("bpf: add bpf_skb_change_type helper"). Signed-off-by: Daniel Borkmann Acked-by: Alexei Starovoitov Signed-off-by: David S. Miller --- diff --git a/net/core/filter.c b/net/core/filter.c index cb06aceb512a..58b5e6dd25fe 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -1976,8 +1976,8 @@ static u64 bpf_skb_change_type(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5) u32 pkt_type = r2; /* We only allow a restricted subset to be changed for now. */ - if (unlikely(skb->pkt_type > PACKET_OTHERHOST || - pkt_type > PACKET_OTHERHOST)) + if (unlikely(!skb_pkt_type_ok(skb->pkt_type) || + !skb_pkt_type_ok(pkt_type))) return -EINVAL; skb->pkt_type = pkt_type;