Commit b5bdc6f9 authored by Pablo Neira Ayuso's avatar Pablo Neira Ayuso

netfilter: nf_tables: convert pktinfo->tprot_set to flags field

Generalize boolean field to store more flags on the pktinfo structure.
Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
parent 56fa9501
...@@ -21,10 +21,14 @@ struct module; ...@@ -21,10 +21,14 @@ struct module;
#define NFT_JUMP_STACK_SIZE 16 #define NFT_JUMP_STACK_SIZE 16
enum {
NFT_PKTINFO_L4PROTO = (1 << 0),
};
struct nft_pktinfo { struct nft_pktinfo {
struct sk_buff *skb; struct sk_buff *skb;
const struct nf_hook_state *state; const struct nf_hook_state *state;
bool tprot_set; u8 flags;
u8 tprot; u8 tprot;
u16 fragoff; u16 fragoff;
unsigned int thoff; unsigned int thoff;
...@@ -75,7 +79,7 @@ static inline void nft_set_pktinfo(struct nft_pktinfo *pkt, ...@@ -75,7 +79,7 @@ static inline void nft_set_pktinfo(struct nft_pktinfo *pkt,
static inline void nft_set_pktinfo_unspec(struct nft_pktinfo *pkt) static inline void nft_set_pktinfo_unspec(struct nft_pktinfo *pkt)
{ {
pkt->tprot_set = false; pkt->flags = 0;
pkt->tprot = 0; pkt->tprot = 0;
pkt->thoff = 0; pkt->thoff = 0;
pkt->fragoff = 0; pkt->fragoff = 0;
......
...@@ -10,7 +10,7 @@ static inline void nft_set_pktinfo_ipv4(struct nft_pktinfo *pkt) ...@@ -10,7 +10,7 @@ static inline void nft_set_pktinfo_ipv4(struct nft_pktinfo *pkt)
struct iphdr *ip; struct iphdr *ip;
ip = ip_hdr(pkt->skb); ip = ip_hdr(pkt->skb);
pkt->tprot_set = true; pkt->flags = NFT_PKTINFO_L4PROTO;
pkt->tprot = ip->protocol; pkt->tprot = ip->protocol;
pkt->thoff = ip_hdrlen(pkt->skb); pkt->thoff = ip_hdrlen(pkt->skb);
pkt->fragoff = ntohs(ip->frag_off) & IP_OFFSET; pkt->fragoff = ntohs(ip->frag_off) & IP_OFFSET;
...@@ -36,7 +36,7 @@ static inline int __nft_set_pktinfo_ipv4_validate(struct nft_pktinfo *pkt) ...@@ -36,7 +36,7 @@ static inline int __nft_set_pktinfo_ipv4_validate(struct nft_pktinfo *pkt)
else if (len < thoff) else if (len < thoff)
return -1; return -1;
pkt->tprot_set = true; pkt->flags = NFT_PKTINFO_L4PROTO;
pkt->tprot = iph->protocol; pkt->tprot = iph->protocol;
pkt->thoff = thoff; pkt->thoff = thoff;
pkt->fragoff = ntohs(iph->frag_off) & IP_OFFSET; pkt->fragoff = ntohs(iph->frag_off) & IP_OFFSET;
...@@ -71,7 +71,7 @@ static inline int nft_set_pktinfo_ipv4_ingress(struct nft_pktinfo *pkt) ...@@ -71,7 +71,7 @@ static inline int nft_set_pktinfo_ipv4_ingress(struct nft_pktinfo *pkt)
goto inhdr_error; goto inhdr_error;
} }
pkt->tprot_set = true; pkt->flags = NFT_PKTINFO_L4PROTO;
pkt->tprot = iph->protocol; pkt->tprot = iph->protocol;
pkt->thoff = thoff; pkt->thoff = thoff;
pkt->fragoff = ntohs(iph->frag_off) & IP_OFFSET; pkt->fragoff = ntohs(iph->frag_off) & IP_OFFSET;
...@@ -82,4 +82,5 @@ static inline int nft_set_pktinfo_ipv4_ingress(struct nft_pktinfo *pkt) ...@@ -82,4 +82,5 @@ static inline int nft_set_pktinfo_ipv4_ingress(struct nft_pktinfo *pkt)
__IP_INC_STATS(nft_net(pkt), IPSTATS_MIB_INHDRERRORS); __IP_INC_STATS(nft_net(pkt), IPSTATS_MIB_INHDRERRORS);
return -1; return -1;
} }
#endif #endif
...@@ -18,7 +18,7 @@ static inline void nft_set_pktinfo_ipv6(struct nft_pktinfo *pkt) ...@@ -18,7 +18,7 @@ static inline void nft_set_pktinfo_ipv6(struct nft_pktinfo *pkt)
return; return;
} }
pkt->tprot_set = true; pkt->flags = NFT_PKTINFO_L4PROTO;
pkt->tprot = protohdr; pkt->tprot = protohdr;
pkt->thoff = thoff; pkt->thoff = thoff;
pkt->fragoff = frag_off; pkt->fragoff = frag_off;
...@@ -50,7 +50,7 @@ static inline int __nft_set_pktinfo_ipv6_validate(struct nft_pktinfo *pkt) ...@@ -50,7 +50,7 @@ static inline int __nft_set_pktinfo_ipv6_validate(struct nft_pktinfo *pkt)
if (protohdr < 0) if (protohdr < 0)
return -1; return -1;
pkt->tprot_set = true; pkt->flags = NFT_PKTINFO_L4PROTO;
pkt->tprot = protohdr; pkt->tprot = protohdr;
pkt->thoff = thoff; pkt->thoff = thoff;
pkt->fragoff = frag_off; pkt->fragoff = frag_off;
...@@ -96,7 +96,7 @@ static inline int nft_set_pktinfo_ipv6_ingress(struct nft_pktinfo *pkt) ...@@ -96,7 +96,7 @@ static inline int nft_set_pktinfo_ipv6_ingress(struct nft_pktinfo *pkt)
if (protohdr < 0) if (protohdr < 0)
goto inhdr_error; goto inhdr_error;
pkt->tprot_set = true; pkt->flags = NFT_PKTINFO_L4PROTO;
pkt->tprot = protohdr; pkt->tprot = protohdr;
pkt->thoff = thoff; pkt->thoff = thoff;
pkt->fragoff = frag_off; pkt->fragoff = frag_off;
......
...@@ -79,7 +79,7 @@ static bool nft_payload_fast_eval(const struct nft_expr *expr, ...@@ -79,7 +79,7 @@ static bool nft_payload_fast_eval(const struct nft_expr *expr,
if (priv->base == NFT_PAYLOAD_NETWORK_HEADER) if (priv->base == NFT_PAYLOAD_NETWORK_HEADER)
ptr = skb_network_header(skb); ptr = skb_network_header(skb);
else { else {
if (!pkt->tprot_set) if (!(pkt->flags & NFT_PKTINFO_L4PROTO))
return false; return false;
ptr = skb_network_header(skb) + nft_thoff(pkt); ptr = skb_network_header(skb) + nft_thoff(pkt);
} }
......
...@@ -113,13 +113,13 @@ static int nf_trace_fill_pkt_info(struct sk_buff *nlskb, ...@@ -113,13 +113,13 @@ static int nf_trace_fill_pkt_info(struct sk_buff *nlskb,
int off = skb_network_offset(skb); int off = skb_network_offset(skb);
unsigned int len, nh_end; unsigned int len, nh_end;
nh_end = pkt->tprot_set ? nft_thoff(pkt) : skb->len; nh_end = pkt->flags & NFT_PKTINFO_L4PROTO ? nft_thoff(pkt) : skb->len;
len = min_t(unsigned int, nh_end - skb_network_offset(skb), len = min_t(unsigned int, nh_end - skb_network_offset(skb),
NFT_TRACETYPE_NETWORK_HSIZE); NFT_TRACETYPE_NETWORK_HSIZE);
if (trace_fill_header(nlskb, NFTA_TRACE_NETWORK_HEADER, skb, off, len)) if (trace_fill_header(nlskb, NFTA_TRACE_NETWORK_HEADER, skb, off, len))
return -1; return -1;
if (pkt->tprot_set) { if (pkt->flags & NFT_PKTINFO_L4PROTO) {
len = min_t(unsigned int, skb->len - nft_thoff(pkt), len = min_t(unsigned int, skb->len - nft_thoff(pkt),
NFT_TRACETYPE_TRANSPORT_HSIZE); NFT_TRACETYPE_TRANSPORT_HSIZE);
if (trace_fill_header(nlskb, NFTA_TRACE_TRANSPORT_HEADER, skb, if (trace_fill_header(nlskb, NFTA_TRACE_TRANSPORT_HEADER, skb,
......
...@@ -333,7 +333,7 @@ void nft_meta_get_eval(const struct nft_expr *expr, ...@@ -333,7 +333,7 @@ void nft_meta_get_eval(const struct nft_expr *expr,
nft_reg_store8(dest, nft_pf(pkt)); nft_reg_store8(dest, nft_pf(pkt));
break; break;
case NFT_META_L4PROTO: case NFT_META_L4PROTO:
if (!pkt->tprot_set) if (!(pkt->flags & NFT_PKTINFO_L4PROTO))
goto err; goto err;
nft_reg_store8(dest, pkt->tprot); nft_reg_store8(dest, pkt->tprot);
break; break;
......
...@@ -108,7 +108,7 @@ void nft_payload_eval(const struct nft_expr *expr, ...@@ -108,7 +108,7 @@ void nft_payload_eval(const struct nft_expr *expr,
offset = skb_network_offset(skb); offset = skb_network_offset(skb);
break; break;
case NFT_PAYLOAD_TRANSPORT_HEADER: case NFT_PAYLOAD_TRANSPORT_HEADER:
if (!pkt->tprot_set) if (!(pkt->flags & NFT_PKTINFO_L4PROTO))
goto err; goto err;
offset = nft_thoff(pkt); offset = nft_thoff(pkt);
break; break;
...@@ -610,7 +610,7 @@ static void nft_payload_set_eval(const struct nft_expr *expr, ...@@ -610,7 +610,7 @@ static void nft_payload_set_eval(const struct nft_expr *expr,
offset = skb_network_offset(skb); offset = skb_network_offset(skb);
break; break;
case NFT_PAYLOAD_TRANSPORT_HEADER: case NFT_PAYLOAD_TRANSPORT_HEADER:
if (!pkt->tprot_set) if (!(pkt->flags & NFT_PKTINFO_L4PROTO))
goto err; goto err;
offset = nft_thoff(pkt); offset = nft_thoff(pkt);
break; break;
......
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