Commit 8b10cab6 authored by Jamal Hadi Salim's avatar Jamal Hadi Salim Committed by David S. Miller

net: simplify and make pkt_type_ok() available for other users

Suggested-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
Signed-off-by: default avatarJamal Hadi Salim <jhs@mojatatu.com>
Acked-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 8186f6e3
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
#include <net/flow_dissector.h> #include <net/flow_dissector.h>
#include <linux/splice.h> #include <linux/splice.h>
#include <linux/in6.h> #include <linux/in6.h>
#include <linux/if_packet.h>
#include <net/flow.h> #include <net/flow.h>
/* The interface for checksum offload between the stack and networking drivers /* The interface for checksum offload between the stack and networking drivers
...@@ -881,6 +882,15 @@ static inline struct rtable *skb_rtable(const struct sk_buff *skb) ...@@ -881,6 +882,15 @@ static inline struct rtable *skb_rtable(const struct sk_buff *skb)
return (struct rtable *)skb_dst(skb); return (struct rtable *)skb_dst(skb);
} }
/* For mangling skb->pkt_type from user space side from applications
* such as nft, tc, etc, we only allow a conservative subset of
* possible pkt_types to be set.
*/
static inline bool skb_pkt_type_ok(u32 ptype)
{
return ptype <= PACKET_OTHERHOST;
}
void kfree_skb(struct sk_buff *skb); void kfree_skb(struct sk_buff *skb);
void kfree_skb_list(struct sk_buff *segs); void kfree_skb_list(struct sk_buff *segs);
void skb_tx_error(struct sk_buff *skb); void skb_tx_error(struct sk_buff *skb);
......
...@@ -199,13 +199,6 @@ void nft_meta_get_eval(const struct nft_expr *expr, ...@@ -199,13 +199,6 @@ void nft_meta_get_eval(const struct nft_expr *expr,
} }
EXPORT_SYMBOL_GPL(nft_meta_get_eval); EXPORT_SYMBOL_GPL(nft_meta_get_eval);
/* don't change or set _LOOPBACK, _USER, etc. */
static bool pkt_type_ok(u32 p)
{
return p == PACKET_HOST || p == PACKET_BROADCAST ||
p == PACKET_MULTICAST || p == PACKET_OTHERHOST;
}
void nft_meta_set_eval(const struct nft_expr *expr, void nft_meta_set_eval(const struct nft_expr *expr,
struct nft_regs *regs, struct nft_regs *regs,
const struct nft_pktinfo *pkt) const struct nft_pktinfo *pkt)
...@@ -223,7 +216,7 @@ void nft_meta_set_eval(const struct nft_expr *expr, ...@@ -223,7 +216,7 @@ void nft_meta_set_eval(const struct nft_expr *expr,
break; break;
case NFT_META_PKTTYPE: case NFT_META_PKTTYPE:
if (skb->pkt_type != value && if (skb->pkt_type != value &&
pkt_type_ok(value) && pkt_type_ok(skb->pkt_type)) skb_pkt_type_ok(value) && skb_pkt_type_ok(skb->pkt_type))
skb->pkt_type = value; skb->pkt_type = value;
break; break;
case NFT_META_NFTRACE: case NFT_META_NFTRACE:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment