Skip to content

Commit b9242da

Browse files
committed
Merge branch 'nf_tables_offload-vlan-matching-support'
Pablo Neira Ayuso says: ==================== nf_tables_offload: vlan matching support The following patchset contains Netfilter support for vlan matching offloads: 1) Constify nft_reg_load() as a preparation patch. 2) Restrict rule matching to ingress interface type ARPHRD_ETHER. 3) Add new vlan_tci field to flow_dissector_key_vlan structure, to allow to set up vlan_id, vlan_dei and vlan_priority in one go. 4) C-VLAN matching support. ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 2f1d370 + 89d8fd4 commit b9242da

File tree

5 files changed

+59
-6
lines changed

5 files changed

+59
-6
lines changed

include/net/flow_dissector.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,12 @@ struct flow_dissector_key_tags {
4848
};
4949

5050
struct flow_dissector_key_vlan {
51-
u16 vlan_id:12,
52-
vlan_dei:1,
53-
vlan_priority:3;
51+
union {
52+
u16 vlan_id:12,
53+
vlan_dei:1,
54+
vlan_priority:3;
55+
__be16 vlan_tci;
56+
};
5457
__be16 vlan_tpid;
5558
};
5659

@@ -203,9 +206,11 @@ struct flow_dissector_key_ip {
203206
/**
204207
* struct flow_dissector_key_meta:
205208
* @ingress_ifindex: ingress ifindex
209+
* @ingress_iftype: ingress interface type
206210
*/
207211
struct flow_dissector_key_meta {
208212
int ingress_ifindex;
213+
u16 ingress_iftype;
209214
};
210215

211216
/**

include/net/netfilter/nf_tables.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ static inline void nft_reg_store8(u32 *dreg, u8 val)
114114
*(u8 *)dreg = val;
115115
}
116116

117-
static inline u8 nft_reg_load8(u32 *sreg)
117+
static inline u8 nft_reg_load8(const u32 *sreg)
118118
{
119119
return *(u8 *)sreg;
120120
}
@@ -125,7 +125,7 @@ static inline void nft_reg_store16(u32 *dreg, u16 val)
125125
*(u16 *)dreg = val;
126126
}
127127

128-
static inline u16 nft_reg_load16(u32 *sreg)
128+
static inline u16 nft_reg_load16(const u32 *sreg)
129129
{
130130
return *(u16 *)sreg;
131131
}
@@ -135,7 +135,7 @@ static inline void nft_reg_store64(u32 *dreg, u64 val)
135135
put_unaligned(val, (u64 *)dreg);
136136
}
137137

138-
static inline u64 nft_reg_load64(u32 *sreg)
138+
static inline u64 nft_reg_load64(const u32 *sreg)
139139
{
140140
return get_unaligned((u64 *)sreg);
141141
}

net/netfilter/nft_cmp.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <linux/module.h>
1111
#include <linux/netlink.h>
1212
#include <linux/netfilter.h>
13+
#include <linux/if_arp.h>
1314
#include <linux/netfilter/nf_tables.h>
1415
#include <net/netfilter/nf_tables_core.h>
1516
#include <net/netfilter/nf_tables_offload.h>
@@ -125,6 +126,11 @@ static int __nft_cmp_offload(struct nft_offload_ctx *ctx,
125126
flow->match.dissector.used_keys |= BIT(reg->key);
126127
flow->match.dissector.offset[reg->key] = reg->base_offset;
127128

129+
if (reg->key == FLOW_DISSECTOR_KEY_META &&
130+
reg->offset == offsetof(struct nft_flow_key, meta.ingress_iftype) &&
131+
nft_reg_load16(priv->data.data) != ARPHRD_ETHER)
132+
return -EOPNOTSUPP;
133+
128134
nft_offload_update_dependency(ctx, &priv->data, priv->len);
129135

130136
return 0;

net/netfilter/nft_meta.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,10 @@ static int nft_meta_get_offload(struct nft_offload_ctx *ctx,
551551
NFT_OFFLOAD_MATCH(FLOW_DISSECTOR_KEY_META, meta,
552552
ingress_ifindex, sizeof(__u32), reg);
553553
break;
554+
case NFT_META_IIFTYPE:
555+
NFT_OFFLOAD_MATCH(FLOW_DISSECTOR_KEY_META, meta,
556+
ingress_iftype, sizeof(__u16), reg);
557+
break;
554558
default:
555559
return -EOPNOTSUPP;
556560
}

net/netfilter/nft_payload.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,44 @@ static int nft_payload_offload_ll(struct nft_offload_ctx *ctx,
182182
NFT_OFFLOAD_MATCH(FLOW_DISSECTOR_KEY_ETH_ADDRS, eth_addrs,
183183
dst, ETH_ALEN, reg);
184184
break;
185+
case offsetof(struct ethhdr, h_proto):
186+
if (priv->len != sizeof(__be16))
187+
return -EOPNOTSUPP;
188+
189+
NFT_OFFLOAD_MATCH(FLOW_DISSECTOR_KEY_BASIC, basic,
190+
n_proto, sizeof(__be16), reg);
191+
nft_offload_set_dependency(ctx, NFT_OFFLOAD_DEP_NETWORK);
192+
break;
193+
case offsetof(struct vlan_ethhdr, h_vlan_TCI):
194+
if (priv->len != sizeof(__be16))
195+
return -EOPNOTSUPP;
196+
197+
NFT_OFFLOAD_MATCH(FLOW_DISSECTOR_KEY_VLAN, vlan,
198+
vlan_tci, sizeof(__be16), reg);
199+
break;
200+
case offsetof(struct vlan_ethhdr, h_vlan_encapsulated_proto):
201+
if (priv->len != sizeof(__be16))
202+
return -EOPNOTSUPP;
203+
204+
NFT_OFFLOAD_MATCH(FLOW_DISSECTOR_KEY_VLAN, vlan,
205+
vlan_tpid, sizeof(__be16), reg);
206+
nft_offload_set_dependency(ctx, NFT_OFFLOAD_DEP_NETWORK);
207+
break;
208+
case offsetof(struct vlan_ethhdr, h_vlan_TCI) + sizeof(struct vlan_hdr):
209+
if (priv->len != sizeof(__be16))
210+
return -EOPNOTSUPP;
211+
212+
NFT_OFFLOAD_MATCH(FLOW_DISSECTOR_KEY_CVLAN, vlan,
213+
vlan_tci, sizeof(__be16), reg);
214+
break;
215+
case offsetof(struct vlan_ethhdr, h_vlan_encapsulated_proto) +
216+
sizeof(struct vlan_hdr):
217+
if (priv->len != sizeof(__be16))
218+
return -EOPNOTSUPP;
219+
220+
NFT_OFFLOAD_MATCH(FLOW_DISSECTOR_KEY_CVLAN, vlan,
221+
vlan_tpid, sizeof(__be16), reg);
222+
break;
185223
default:
186224
return -EOPNOTSUPP;
187225
}

0 commit comments

Comments
 (0)