netfilter: flowtable enhancements
Subsystems (10)
Pablo Neira Ayuso
maintainercover netfilter: flowtable enhancements
Hi,
The following patchset augments the Netfilter flowtable fastpath to support for network topologies that combine IP forwarding, bridge, classic VLAN devices, bridge VLAN filtering, DSA and PPPoE. This includes support for the flowtable software and hardware datapaths.
The following pictures provides an example scenario:
fast path!
.------------------------.
/ \
| IP forwarding |
| / \ \/
| br0 wan ..... eth0
. / \ host C
-> veth1 veth2
. switch/router
.
.
eth0
host AThe bridge master device 'br0' has an IP address and a DHCP server is also assumed to be running to provide connectivity to host A which reaches the Internet through 'br0' as default gateway. Then, packet enters the IP forwarding path and Netfilter is used to NAT the packets before they leave through the wan device.
The general idea is to accelerate forwarding by building a fast path that takes packets from the ingress path of the bridge port and place them in the egress path of the wan device (and vice versa). Hence, skipping the classic bridge and IP stack paths.
** Patch from #1 to #6 add the infrastructure which describes the list of
netdevice hops to reach a given destination MAC address in the local network topology.
Patch #1 adds dev_fill_forward_path() and .ndo_fill_forward_path() to
netdev_ops.
Patch #2 adds .ndo_fill_forward_path for vlan devices, which provides
the next device hop via vlan->real_dev, the vlan ID and the
protocol.Patch #3 adds .ndo_fill_forward_path for bridge devices, which allows to make
lookups to the FDB to locate the next device hop (bridge port) in the forwarding path.
Patch #4 extends bridge .ndo_fill_forward_path to support for bridge VLAN
filtering.
Patch #5 adds .ndo_fill_forward_path for PPPoE devices.
Patch #6 adds .ndo_fill_forward_path for DSA.
Patches from #7 to #14 update the flowtable software datapath:
Patch #7 adds the transmit path type field to the flow tuple. Two transmit
paths are supported so far: the neighbour and the xfrm transmit paths.
Patch #8 and #9 update the flowtable datapath to use dev_fill_forward_path()
to obtain the real ingress/egress device for the flowtable datapath. This adds the new ethernet xmit direct path to the flowtable.
Patch #10 adds native flowtable VLAN support (up to 2 VLAN tags) through
dev_fill_forward_path(). The flowtable stores the VLAN id and protocol in the flow tuple.
Patch #11 adds native flowtable bridge VLAN filter support through
dev_fill_forward_path().
Patch #12 adds native flowtable bridge PPPoE through dev_fill_forward_path().
Patch #13 adds DSA support through dev_fill_forward_path().
Patch #14 extends flowtable selftests to cover for flowtable software
datapath enhancements.
** Patches from #15 to #20 update the flowtable hardware offload datapath:
Patch #15 extends the flowtable hardware offload to support for the
direct ethernet xmit path. This also includes VLAN support.
Patch #16 stores the egress real device in the flow tuple. The software
flowtable datapath uses dev_hard_header() to transmit packets, hence it might refer to VLAN/DSA/PPPoE software device, not the real ethernet device.
Patch #17 deals with switchdev PVID hardware offload to skip it on
egress.
Patch #18 adds FLOW_ACTION_PPPOE_PUSH to the flow_offload action API.
Patch #19 extends the flowtable hardware offload to support for PPPoE
Patch #20 adds TC_SETUP_FT support for DSA.
** Patches from #20 to #23: Felix Fietkau adds a new driver which support
hardware offload for the mtk PPE engine through the existing flow offload API which supports for the flowtable enhancements coming in this batch.
Felix Fietkau (7):
net: bridge: resolve forwarding path for VLAN tag actions in bridge devices
net: ppp: resolve forwarding path for bridge pppoe devices
net: dsa: resolve forwarding path for dsa slave ports
netfilter: flowtable: bridge vlan hardware offload and switchdev
net: ethernet: mtk_eth_soc: add support for initializing the PPE
net: ethernet: mtk_eth_soc: add flow offloading support
net: ethernet: mtk_eth_soc: fix parsing packets in GDM
Pablo Neira Ayuso (16):
net: resolve forwarding path from virtual netdevice and HW destination address
net: 8021q: resolve forwarding path for vlan devices
net: bridge: resolve forwarding path for bridge devices
netfilter: flowtable: add xmit path types
netfilter: flowtable: use dev_fill_forward_path() to obtain ingress device
netfilter: flowtable: use dev_fill_forward_path() to obtain egress device
netfilter: flowtable: add vlan support
netfilter: flowtable: add bridge vlan filtering support
netfilter: flowtable: add pppoe support
netfilter: flowtable: add dsa support
selftests: netfilter: flowtable bridge and vlan support
netfilter: flowtable: add offload support for xmit path types
netfilter: nft_flow_offload: use direct xmit if hardware offload is enabled
net: flow_offload: add FLOW_ACTION_PPPOE_PUSH
netfilter: flowtable: support for FLOW_ACTION_PPPOE_PUSH
dsa: slave: add support for TC_SETUP_FT
drivers/net/ethernet/mediatek/Makefile | 2 +- drivers/net/ethernet/mediatek/mtk_eth_soc.c | 41 +- drivers/net/ethernet/mediatek/mtk_eth_soc.h | 23 +- drivers/net/ethernet/mediatek/mtk_ppe.c | 511 ++++++++++++++++++ drivers/net/ethernet/mediatek/mtk_ppe.h | 287 ++++++++++ .../net/ethernet/mediatek/mtk_ppe_debugfs.c | 217 ++++++++ .../net/ethernet/mediatek/mtk_ppe_offload.c | 485 +++++++++++++++++ drivers/net/ethernet/mediatek/mtk_ppe_regs.h | 144 +++++ drivers/net/ppp/ppp_generic.c | 22 + drivers/net/ppp/pppoe.c | 23 + include/linux/netdevice.h | 59 ++ include/linux/ppp_channel.h | 3 + include/net/flow_offload.h | 4 + include/net/netfilter/nf_flow_table.h | 47 +- net/8021q/vlan_dev.c | 21 + net/bridge/br_device.c | 49 ++ net/bridge/br_private.h | 20 + net/bridge/br_vlan.c | 55 ++ net/core/dev.c | 46 ++ net/dsa/slave.c | 36 +- net/netfilter/nf_flow_table_core.c | 49 +- net/netfilter/nf_flow_table_ip.c | 270 +++++++-- net/netfilter/nf_flow_table_offload.c | 179 ++++-- net/netfilter/nft_flow_offload.c | 211 +++++++- .../selftests/netfilter/nft_flowtable.sh | 82 +++ 25 files changed, 2768 insertions(+), 118 deletions(-) create mode 100644 drivers/net/ethernet/mediatek/mtk_ppe.c create mode 100644 drivers/net/ethernet/mediatek/mtk_ppe.h create mode 100644 drivers/net/ethernet/mediatek/mtk_ppe_debugfs.c create mode 100644 drivers/net/ethernet/mediatek/mtk_ppe_offload.c create mode 100644 drivers/net/ethernet/mediatek/mtk_ppe_regs.h
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerPATCH 1/23 net: resolve forwarding path from virtual netdevice and HW destination address
This patch adds dev_fill_forward_path() which resolves the path to reach the real netdevice from the IP forwarding side. This function takes as input the netdevice and the destination hardware address and it walks down the devices calling .ndo_fill_forward_path() for each device until the real device is found.
For instance, assuming the following topology:
IP forwarding
/ \
br0 eth0
/ \
eth1 eth2
.
.
.
ethXab:cd:ef:ab:cd:ef
where eth1 and eth2 are bridge ports and eth0 provides WAN connectivity. ethX is the interface in another box which is connected to the eth1 bridge port.
For packets going through IP forwarding to br0 whose destination MAC address is ab:cd:ef:ab:cd:ef, dev_fill_forward_path() provides the following path:
br0 -> eth1
.ndo_fill_forward_path for br0 looks up at the FDB for the bridge port from the destination MAC address to get the bridge port eth1.
This information allows to create a fast path that bypasses the classic bridge and IP forwarding paths, so packets go directly from the bridge port eth1 to eth0 (wan interface) and vice versa.
fast path
.------------------------.
/ \
| IP forwarding |
| / \ \/
| br0 eth0
. / \
-> eth1 eth2
.
.
.
ethXab:cd:ef:ab:cd:ef
--- include/linux/netdevice.h | 27 +++++++++++++++++++++++ net/core/dev.c | 46 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+)
include/linux/netdevice.h +27 -0
@@ -831,6 +831,27 @@ typedef u16 (*select_queue_fallback_t)(struct net_device *dev,struct sk_buff *skb, struct net_device *sb_dev); +enum net_device_path_type { +DEV_PATH_ETHERNET =0 , +}; + +struct net_device_path { +enum net_device_path_type type; +const struct net_device *dev; +}; + +#define NET_DEVICE_PATH_STACK_MAX 5 + +struct net_device_path_stack { +int num_paths; +struct net_device_path path[NET_DEVICE_PATH_STACK_MAX ]; +}; + +struct net_device_path_ctx { +const struct net_device *dev; +const u8 *daddr; +}; +enum tc_setup_type {TC_SETUP_QDISC_MQPRIO ,TC_SETUP_CLSU32 ,
@@ -1265,6 +1286,8 @@ struct netdev_net_notifier {* struct net_device *(*ndo_get_peer_dev)(struct net_device *dev); * If a device is paired with a peer device, return the peer instance. * The caller must be under RCU read context. +* int (*ndo_fill_forward_path)(struct net_device_path_ctx *ctx, struct net_device_path *path); +* Get the forwarding path to reach the real device from the HW destination address */ struct net_device_ops {int (*ndo_init)(struct net_device *dev);
@@ -1471,6 +1494,8 @@ struct net_device_ops {int (*ndo_tunnel_ctl)(struct net_device *dev,struct ip_tunnel_parm *p,int cmd);struct net_device * (*ndo_get_peer_dev)(struct net_device *dev); +int (*ndo_fill_forward_path)(struct net_device_path_ctx *ctx, +struct net_device_path *path); };/**
@@ -2844,6 +2869,8 @@ void dev_remove_offload(struct packet_offload *po);int dev_get_iflink (const struct net_device *dev);int dev_fill_metadata_dst (struct net_device *dev,struct sk_buff *skb); +int dev_fill_forward_path (const struct net_device *dev,const u8 *daddr, +struct net_device_path_stack *stack);struct net_device *__dev_get_by_flags (struct net *net,unsigned short flags,unsigned short mask);struct net_device *dev_get_by_name (struct net *net,const char *name);
net/core/dev.c +46 -0
52 lines not on this page · raw message
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerPATCH 2/23 net: 8021q: resolve forwarding path for vlan devices
In reply to Pablo Neira AyusoAdd .ndo_fill_forward_path for vlan devices.
For instance, assuming the following topology:
IP forwarding
/ \
eth0.100 eth0
|
eth0
.
.
.
ethX
ab:cd:ef:ab:cd:efFor packets going through IP forwarding to eth0.100 whose destination MAC address is ab:cd:ef:ab:cd:ef, dev_fill_forward_path() provides the following path:
eth0.100 -> eth0
--- include/linux/netdevice.h | 7 +++++++ net/8021q/vlan_dev.c | 15 +++++++++++++++ 2 files changed, 22 insertions(+)
include/linux/netdevice.h +7 -0
@@ -833,11 +833,18 @@ typedef u16 (*select_queue_fallback_t)(struct net_device *dev,enum net_device_path_type {DEV_PATH_ETHERNET =0 , +DEV_PATH_VLAN , };struct net_device_path {enum net_device_path_type type;const struct net_device *dev; +union { +struct { +u16 id; +__be16 proto; + } encap; + }; };#define NET_DEVICE_PATH_STACK_MAX 5
net/8021q/vlan_dev.c +15 -0
@@ -776,6 +776,20 @@ static int vlan_dev_get_iflink(const struct net_device *dev)return real_dev->ifindex; } +static int vlan_dev_fill_forward_path (struct net_device_path_ctx *ctx, +struct net_device_path *path) +{ +struct vlan_dev_priv *vlan =vlan_dev_priv (ctx->dev); + + path->type =DEV_PATH_VLAN ; + path->encap.id = vlan->vlan_id; + path->encap.proto = vlan->vlan_proto; + path->dev = ctx->dev; + ctx->dev = vlan->real_dev; + +return 0 ; +} +static const struct ethtool_ops vlan_ethtool_ops = { .get_link_ksettings = vlan_ethtool_get_link_ksettings, .get_drvinfo = vlan_ethtool_get_drvinfo,
@@ -814,6 +828,7 @@ static const struct net_device_ops vlan_netdev_ops = {#endif .ndo_fix_features = vlan_dev_fix_features, .ndo_get_iflink = vlan_dev_get_iflink, + .ndo_fill_forward_path = vlan_dev_fill_forward_path, };static void vlan_dev_free (struct net_device *dev)
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerPATCH 3/23 net: bridge: resolve forwarding path for bridge devices
In reply to Pablo Neira AyusoAdd .ndo_fill_forward_path for bridge devices.
--- include/linux/netdevice.h | 1 + net/bridge/br_device.c | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+)
include/linux/netdevice.h +1 -0
@@ -834,6 +834,7 @@ typedef u16 (*select_queue_fallback_t)(struct net_device *dev,enum net_device_path_type {DEV_PATH_ETHERNET =0 ,DEV_PATH_VLAN , +DEV_PATH_BRIDGE , };struct net_device_path {
net/bridge/br_device.c +27 -0
@@ -385,6 +385,32 @@ static int br_del_slave(struct net_device *dev, struct net_device *slave_dev)return br_del_if (br, slave_dev); } +static int br_fill_forward_path (struct net_device_path_ctx *ctx, +struct net_device_path *path) +{ +struct net_bridge_fdb_entry *f; +struct net_bridge_port *dst; +struct net_bridge *br; + +if (netif_is_bridge_port (ctx->dev)) +return -1 ; + + br =netdev_priv (ctx->dev); + f =br_fdb_find_rcu (br, ctx->daddr,0 ); +if (!f || !f->dst) +return -1 ; + + dst =READ_ONCE (f->dst); +if (!dst) +return -1 ; + + path->type =DEV_PATH_BRIDGE ; + path->dev = dst->br->dev; + ctx->dev = dst->dev; + +return 0 ; +} +static const struct ethtool_ops br_ethtool_ops = { .get_drvinfo = br_getinfo, .get_link = ethtool_op_get_link,
@@ -419,6 +445,7 @@ static const struct net_device_ops br_netdev_ops = { .ndo_bridge_setlink = br_setlink, .ndo_bridge_dellink = br_dellink, .ndo_features_check = passthru_features_check, + .ndo_fill_forward_path = br_fill_forward_path, };static struct device_type br_type = {
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerPATCH 4/23 net: bridge: resolve forwarding path for VLAN tag actions in bridge devices
In reply to Pablo Neira AyusoFrom: Felix Fietkau <[email protected]>
Depending on the VLAN settings of the bridge and the port, the bridge can either add or remove a tag. When vlan filtering is enabled, the fdb lookup also needs to know the VLAN tag/proto for the destination address To provide this, keep track of the stack of VLAN tags for the path in the lookup context
--- include/linux/netdevice.h | 16 ++++++++++++ net/8021q/vlan_dev.c | 6 +++++ net/bridge/br_device.c | 23 ++++++++++++++++- net/bridge/br_private.h | 20 +++++++++++++++ net/bridge/br_vlan.c | 53 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 117 insertions(+), 1 deletion(-)
include/linux/netdevice.h +16 -0
@@ -845,10 +845,20 @@ struct net_device_path {u16 id;__be16 proto; } encap; +struct { +enum { +DEV_PATH_BR_VLAN_KEEP , +DEV_PATH_BR_VLAN_TAG , +DEV_PATH_BR_VLAN_UNTAG , + } vlan_mode; +u16 vlan_id; +__be16 vlan_proto; + } bridge; }; };#define NET_DEVICE_PATH_STACK_MAX 5 +#define NET_DEVICE_PATH_VLAN_MAX 2struct net_device_path_stack {int num_paths;
@@ -858,6 +868,12 @@ struct net_device_path_stack {struct net_device_path_ctx {const struct net_device *dev;const u8 *daddr; + +int num_vlans; +struct { +u16 id; +__be16 proto; + } vlan[NET_DEVICE_PATH_VLAN_MAX ]; };enum tc_setup_type {
net/8021q/vlan_dev.c +6 -0
@@ -786,6 +786,12 @@ static int vlan_dev_fill_forward_path(struct net_device_path_ctx *ctx, path->encap.proto = vlan->vlan_proto; path->dev = ctx->dev; ctx->dev = vlan->real_dev; +if (ctx->num_vlans >=ARRAY_SIZE (ctx->vlan)) +return -ENOSPC ; + + ctx->vlan[ctx->num_vlans].id = vlan->vlan_id; + ctx->vlan[ctx->num_vlans].proto = vlan->vlan_proto; + ctx->num_vlans++;return 0 ; }
net/bridge/br_device.c +22 -1
@@ -396,7 +396,10 @@ static int br_fill_forward_path(struct net_device_path_ctx *ctx,return -1 ; br =netdev_priv (ctx->dev); - f =br_fdb_find_rcu (br, ctx->daddr,0 ); + +br_vlan_fill_forward_path_pvid (br, ctx, path); + + f =br_fdb_find_rcu (br, ctx->daddr, path->bridge.vlan_id);if (!f || !f->dst)return -1 ;
@@ -404,10 +407,28 @@ static int br_fill_forward_path(struct net_device_path_ctx *ctx,if (!dst)return -1 ; +if (br_vlan_fill_forward_path_mode (br, dst, path)) +return -1 ; + path->type =DEV_PATH_BRIDGE ; path->dev = dst->br->dev; ctx->dev = dst->dev; +switch (path->bridge.vlan_mode) { +case DEV_PATH_BR_VLAN_TAG : +if (ctx->num_vlans >=ARRAY_SIZE (ctx->vlan)) +return -ENOSPC ; + ctx->vlan[ctx->num_vlans].id = path->bridge.vlan_id; + ctx->vlan[ctx->num_vlans].proto = path->bridge.vlan_proto; + ctx->num_vlans++; +break ; +case DEV_PATH_BR_VLAN_UNTAG : + ctx->num_vlans--; +break ; +case DEV_PATH_BR_VLAN_KEEP : +break ; + } +return 0 ; }
net/bridge/br_private.h +20 -0
@@ -1118,6 +1118,13 @@ void br_vlan_notify(const struct net_bridge *br,bool br_vlan_can_enter_range (const struct net_bridge_vlan *v_curr,const struct net_bridge_vlan *range_end); +void br_vlan_fill_forward_path_pvid (struct net_bridge *br, +struct net_device_path_ctx *ctx, +struct net_device_path *path); +int br_vlan_fill_forward_path_mode (struct net_bridge *br, +struct net_bridge_port *dst, +struct net_device_path *path); +static inline struct net_bridge_vlan_group *br_vlan_group (const struct net_bridge *br) {
@@ -1277,6 +1284,19 @@ static inline int nbp_get_num_vlan_infos(struct net_bridge_port *p,return 0 ; } +static inline void br_vlan_fill_forward_path_pvid (struct net_bridge *br, +struct net_device_path_ctx *ctx, +struct net_device_path *path) +{ +} + +static inline int br_vlan_fill_forward_path_mode (struct net_bridge *br, +struct net_bridge_port *dst, +struct net_device_path *path) +{ +return 0 ; +} +static inline struct net_bridge_vlan_group *br_vlan_group (const struct net_bridge *br) {
net/bridge/br_vlan.c +53 -0
59 lines not on this page · raw message
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerPATCH 5/23 net: ppp: resolve forwarding path for bridge pppoe devices
In reply to Pablo Neira AyusoFrom: Felix Fietkau <[email protected]>
Pass on the PPPoE session ID, destination hardware address and the real device.
--- drivers/net/ppp/ppp_generic.c | 22 ++++++++++++++++++++++ drivers/net/ppp/pppoe.c | 23 +++++++++++++++++++++++ include/linux/netdevice.h | 2 ++ include/linux/ppp_channel.h | 3 +++ 4 files changed, 50 insertions(+)
drivers/net/ppp/ppp_generic.c +22 -0
@@ -1560,12 +1560,34 @@ static void ppp_dev_priv_destructor(struct net_device *dev)ppp_destroy_interface (ppp); } +static int ppp_fill_forward_path (struct net_device_path_ctx *ctx, +struct net_device_path *path) +{ +struct ppp *ppp =netdev_priv (ctx->dev); +struct ppp_channel *chan; +struct channel *pch; + +if (ppp->flags &SC_MULTILINK ) +return -EOPNOTSUPP ; + +if (list_empty (&ppp->channels)) +return -ENODEV ; + + pch = list_first_entry(&ppp->channels, struct channel, clist); + chan = pch->chan; +if (!chan->ops->fill_forward_path) +return -EOPNOTSUPP ; + +return chan->ops->fill_forward_path (ctx, path, chan); +} +static const struct net_device_ops ppp_netdev_ops = { .ndo_init = ppp_dev_init, .ndo_uninit = ppp_dev_uninit, .ndo_start_xmit = ppp_start_xmit, .ndo_do_ioctl = ppp_net_ioctl, .ndo_get_stats64 = ppp_get_stats64, + .ndo_fill_forward_path = ppp_fill_forward_path, };static struct device_type ppp_type = {
drivers/net/ppp/pppoe.c +23 -0
@@ -972,8 +972,31 @@ static int pppoe_xmit(struct ppp_channel *chan, struct sk_buff *skb)return __pppoe_xmit (sk, skb); } +static int pppoe_fill_forward_path (struct net_device_path_ctx *ctx, +struct net_device_path *path, +const struct ppp_channel *chan) +{ +struct sock *sk = (struct sock *)chan->private; +struct pppox_sock *po =pppox_sk (sk); +struct net_device *dev = po->pppoe_dev; + +if (sock_flag (sk,SOCK_DEAD ) || + !(sk->sk_state &PPPOX_CONNECTED ) || !dev) +return -1 ; + + path->type =DEV_PATH_PPPOE ; + path->encap.proto =htons (ETH_P_PPP_SES ); + path->encap.id =be16_to_cpu (po->num); +memcpy (path->encap.h_dest, po->pppoe_pa.remote,ETH_ALEN ); + path->dev = ctx->dev; + ctx->dev = dev; + +return 0 ; +} +static const struct ppp_channel_ops pppoe_chan_ops = { .start_xmit = pppoe_xmit, + .fill_forward_path = pppoe_fill_forward_path, }; static int pppoe_recvmsg(struct socket *sock, struct msghdr *m,
include/linux/netdevice.h +2 -0
@@ -835,6 +835,7 @@ enum net_device_path_type {DEV_PATH_ETHERNET =0 ,DEV_PATH_VLAN ,DEV_PATH_BRIDGE , + DEV_PATH_PPPOE, }; struct net_device_path {
@@ -844,6 +845,7 @@ struct net_device_path {struct {u16 id;__be16 proto; +u8 h_dest[ETH_ALEN ]; } encap; struct { enum {
include/linux/ppp_channel.h +3 -0
@@ -28,6 +28,9 @@ struct ppp_channel_ops {int (*start_xmit)(struct ppp_channel *,struct sk_buff *);/* Handle an ioctl call that has come in via /dev/ppp. */ int (*ioctl)(struct ppp_channel *,unsigned int ,unsigned long ); +int (*fill_forward_path)(struct net_device_path_ctx *, +struct net_device_path *, +const struct ppp_channel *); };struct ppp_channel {
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerPATCH 6/23 net: dsa: resolve forwarding path for dsa slave ports
In reply to Pablo Neira AyusoFrom: Felix Fietkau <[email protected]>
Add .ndo_fill_forward_path for dsa slave port devices
--- include/linux/netdevice.h | 5 +++++ net/dsa/slave.c | 16 ++++++++++++++++ 2 files changed, 21 insertions(+)
include/linux/netdevice.h +5 -0
@@ -836,6 +836,7 @@ enum net_device_path_type {DEV_PATH_VLAN ,DEV_PATH_BRIDGE ,DEV_PATH_PPPOE , + DEV_PATH_DSA, }; struct net_device_path {
@@ -856,6 +857,10 @@ struct net_device_path {u16 vlan_id;__be16 vlan_proto; } bridge; +struct { +int port; +u16 proto; + } dsa; }; };
net/dsa/slave.c +16 -0
@@ -1654,6 +1654,21 @@ static void dsa_slave_get_stats64(struct net_device *dev,dev_get_tstats64 (dev, s); } +static int dsa_slave_fill_forward_path (struct net_device_path_ctx *ctx, +struct net_device_path *path) +{ +struct dsa_port *dp =dsa_slave_to_port (ctx->dev); +struct dsa_port *cpu_dp = dp->cpu_dp; + + path->dev = ctx->dev; + path->type =DEV_PATH_DSA ; + path->dsa.proto = cpu_dp->tag_ops->proto; + path->dsa.port = dp->index; + ctx->dev = cpu_dp->master; + +return 0 ; +} +static const struct net_device_ops dsa_slave_netdev_ops = { .ndo_open = dsa_slave_open, .ndo_stop = dsa_slave_close,
@@ -1679,6 +1694,7 @@ static const struct net_device_ops dsa_slave_netdev_ops = { .ndo_vlan_rx_kill_vid = dsa_slave_vlan_rx_kill_vid, .ndo_get_devlink_port = dsa_slave_get_devlink_port, .ndo_change_mtu = dsa_slave_change_mtu, + .ndo_fill_forward_path = dsa_slave_fill_forward_path, };static struct device_type dsa_type = {
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerPATCH 7/23 netfilter: flowtable: add xmit path types
In reply to Pablo Neira AyusoAdd the xmit_type field that defines the two supported xmit paths in the flowtable data plane, which are the neighbour and the xfrm xmit paths. This patch prepares for new flowtable xmit path types to come.
--- include/net/netfilter/nf_flow_table.h | 11 +++++++-- net/netfilter/nf_flow_table_core.c | 1 + net/netfilter/nf_flow_table_ip.c | 32 ++++++++++++++++++--------- net/netfilter/nft_flow_offload.c | 20 +++++++++++++++-- 4 files changed, 50 insertions(+), 14 deletions(-)
include/net/netfilter/nf_flow_table.h +9 -2
@@ -89,6 +89,11 @@ enum flow_offload_tuple_dir {FLOW_OFFLOAD_DIR_MAX =IP_CT_DIR_MAX }; +enum flow_offload_xmit_type { +FLOW_OFFLOAD_XMIT_NEIGH =0 , +FLOW_OFFLOAD_XMIT_XFRM , +}; + struct flow_offload_tuple { union { struct in_addr src_v4;
@@ -111,7 +116,8 @@ struct flow_offload_tuple {/* All members above are keys for lookups, see flow_offload_hash(). */ struct { } __hash; -u8 dir; + u8 dir:6, + xmit_type:2;u16 mtu;
@@ -158,7 +164,8 @@ static inline __s32 nf_flow_timeout_delta(unsigned int timeout)struct nf_flow_route {struct { -struct dst_entry *dst; +struct dst_entry *dst; +enum flow_offload_xmit_type xmit_type; } tuple[FLOW_OFFLOAD_DIR_MAX ]; };
net/netfilter/nf_flow_table_core.c +1 -0
@@ -95,6 +95,7 @@ static int flow_offload_fill_route(struct flow_offload *flow, } flow_tuple->iifidx = other_dst->dev->ifindex; + flow_tuple->xmit_type = route->tuple[dir].xmit_type; flow_tuple->dst_cache = dst;return 0 ;
net/netfilter/nf_flow_table_ip.c +22 -10
@@ -220,10 +220,20 @@ static bool nf_flow_exceeds_mtu(const struct sk_buff *skb, unsigned int mtu)return true; } -static int nf_flow_offload_dst_check (struct dst_entry *dst) +static inline struct dst_entry * +nft_flow_dst (struct flow_offload_tuple_rhash *tuplehash) { -if (unlikely (dst_xfrm (dst))) +return tuplehash->tuple.dst_cache; +} + +static int nf_flow_offload_dst_check (struct flow_offload_tuple_rhash *tuplehash) +{ +struct dst_entry *dst; + +if (unlikely (tuplehash->tuple.xmit_type ==FLOW_OFFLOAD_XMIT_XFRM )) { + dst =nft_flow_dst (tuplehash);return dst_check (dst,0 ) ?0 :-1 ; + }return 0 ; }
@@ -265,8 +275,6 @@ nf_flow_offload_ip_hook(void *priv, struct sk_buff *skb, dir = tuplehash->tuple.dir; flow = container_of(tuplehash, struct flow_offload, tuplehash[dir]); - rt = (struct rtable *)flow->tuplehash[dir].tuple.dst_cache; - outdev = rt->dst.dev;if (unlikely (nf_flow_exceeds_mtu (skb, flow->tuplehash[dir].tuple.mtu)))return NF_ACCEPT ;
@@ -280,7 +288,7 @@ nf_flow_offload_ip_hook(void *priv, struct sk_buff *skb,flow_offload_refresh (flow_table, flow); -if (nf_flow_offload_dst_check (&rt->dst)) { +if (nf_flow_offload_dst_check (tuplehash)) {flow_offload_teardown (flow);return NF_ACCEPT ; }
@@ -295,13 +303,16 @@ nf_flow_offload_ip_hook(void *priv, struct sk_buff *skb,if (flow_table->flags &NF_FLOWTABLE_COUNTER )nf_ct_acct_update (flow->ct, tuplehash->tuple.dir, skb->len); -if (unlikely (dst_xfrm (&rt->dst))) { + rt = (struct rtable *)tuplehash->tuple.dst_cache; + +if (unlikely (tuplehash->tuple.xmit_type ==FLOW_OFFLOAD_XMIT_XFRM )) {memset (skb->cb,0 ,sizeof (struct inet_skb_parm ));IPCB (skb)->iif = skb->dev->ifindex;IPCB (skb)->flags =IPSKB_FORWARDED ;return nf_flow_xmit_xfrm (skb, state, &rt->dst); } + outdev = rt->dst.dev; skb->dev = outdev; nexthop =rt_nexthop (rt, flow->tuplehash[!dir].tuple.src_v4.s_addr);skb_dst_set_noref (skb, &rt->dst);
@@ -506,8 +517,6 @@ nf_flow_offload_ipv6_hook(void *priv, struct sk_buff *skb, dir = tuplehash->tuple.dir; flow = container_of(tuplehash, struct flow_offload, tuplehash[dir]); - rt = (struct rt6_info *)flow->tuplehash[dir].tuple.dst_cache; - outdev = rt->dst.dev;if (unlikely (nf_flow_exceeds_mtu (skb, flow->tuplehash[dir].tuple.mtu)))return NF_ACCEPT ;
@@ -518,7 +527,7 @@ nf_flow_offload_ipv6_hook(void *priv, struct sk_buff *skb,flow_offload_refresh (flow_table, flow); -if (nf_flow_offload_dst_check (&rt->dst)) { +if (nf_flow_offload_dst_check (tuplehash)) {flow_offload_teardown (flow);return NF_ACCEPT ; }
@@ -536,13 +545,16 @@ nf_flow_offload_ipv6_hook(void *priv, struct sk_buff *skb,if (flow_table->flags &NF_FLOWTABLE_COUNTER )nf_ct_acct_update (flow->ct, tuplehash->tuple.dir, skb->len); -if (unlikely (dst_xfrm (&rt->dst))) { + rt = (struct rt6_info *)tuplehash->tuple.dst_cache; + +if (unlikely (tuplehash->tuple.xmit_type ==FLOW_OFFLOAD_XMIT_XFRM )) {memset (skb->cb,0 ,sizeof (struct inet6_skb_parm ));IP6CB (skb)->iif = skb->dev->ifindex;IP6CB (skb)->flags =IP6SKB_FORWARDED ;return nf_flow_xmit_xfrm (skb, state, &rt->dst); } + outdev = rt->dst.dev; skb->dev = outdev; nexthop =rt6_nexthop (rt, &flow->tuplehash[!dir].tuple.src_v6);skb_dst_set_noref (skb, &rt->dst);
net/netfilter/nft_flow_offload.c +18 -2
@@ -19,6 +19,22 @@ struct nft_flow_offload {struct nft_flowtable *flowtable; }; +static enum flow_offload_xmit_type nft_xmit_type (struct dst_entry *dst) +{ +if (dst_xfrm (dst)) +return FLOW_OFFLOAD_XMIT_XFRM ; + +return FLOW_OFFLOAD_XMIT_NEIGH ; +} + +static void nft_default_forward_path (struct nf_flow_route *route, +struct dst_entry *dst_cache, +enum ip_conntrack_dir dir) +{ + route->tuple[dir].dst = dst_cache; + route->tuple[dir].xmit_type =nft_xmit_type (dst_cache); +} + static int nft_flow_route(const struct nft_pktinfo *pkt, const struct nf_conn *ct, struct nf_flow_route *route,
@@ -44,8 +60,8 @@ static int nft_flow_route(const struct nft_pktinfo *pkt,if (!other_dst)return -ENOENT ; - route->tuple[dir].dst = this_dst; - route->tuple[!dir].dst = other_dst; +nft_default_forward_path (route, this_dst, dir); +nft_default_forward_path (route, other_dst, !dir);return 0 ; }
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerPATCH 8/23 netfilter: flowtable: use dev_fill_forward_path() to obtain ingress device
In reply to Pablo Neira AyusoObtain the ingress device in the tuple from the route in the reply direction. Use dev_fill_forward_path() instead to get the real ingress device for this flow.
Fall back to use the ingress device that the IP forwarding route provides if:
- dev_fill_forward_path() finds no real ingress device.
- the ingress device that is obtained is not part of the flowtable devices.
- this route has a xfrm policy.
--- include/net/netfilter/nf_flow_table.h | 3 + net/netfilter/nf_flow_table_core.c | 3 +- net/netfilter/nft_flow_offload.c | 102 +++++++++++++++++++++++++- 3 files changed, 103 insertions(+), 5 deletions(-)
include/net/netfilter/nf_flow_table.h +3 -0
@@ -165,6 +165,9 @@ static inline __s32 nf_flow_timeout_delta(unsigned int timeout)struct nf_flow_route {struct {struct dst_entry *dst; +struct { +u32 ifindex; + } in;enum flow_offload_xmit_type xmit_type; } tuple[FLOW_OFFLOAD_DIR_MAX ]; };
net/netfilter/nf_flow_table_core.c +1 -2
@@ -79,7 +79,6 @@ static int flow_offload_fill_route(struct flow_offload *flow, enum flow_offload_tuple_dir dir) {struct flow_offload_tuple *flow_tuple = &flow->tuplehash[dir].tuple; -struct dst_entry *other_dst = route->tuple[!dir].dst;struct dst_entry *dst = route->tuple[dir].dst;if (!dst_hold_safe (route->tuple[dir].dst))
@@ -94,7 +93,7 @@ static int flow_offload_fill_route(struct flow_offload *flow,break ; } - flow_tuple->iifidx = other_dst->dev->ifindex; + flow_tuple->iifidx = route->tuple[dir].in.ifindex; flow_tuple->xmit_type = route->tuple[dir].xmit_type; flow_tuple->dst_cache = dst;
net/netfilter/nft_flow_offload.c +99 -3
134 lines not on this page · raw message
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerPATCH 9/23 netfilter: flowtable: use dev_fill_forward_path() to obtain egress device
In reply to Pablo Neira AyusoThe egress device in the tuple is obtained from route. Use dev_fill_forward_path() instead to provide the real egress device for this flow whenever this is available.
The new FLOW_OFFLOAD_XMIT_DIRECT type uses dev_queue_xmit() to transmit ethernet frames. Cache the source and destination hardware address to use dev_queue_xmit() to transfer packets.
The FLOW_OFFLOAD_XMIT_DIRECT replaces FLOW_OFFLOAD_XMIT_NEIGH if dev_fill_forward_path() finds a direct transmit path.
In case of topology updates, if peer is moved to different bridge port, the connection will time out, reconnect will result in a new entry with the correct path. Snooping fdb updates would allow for cleaning up stale flowtable entries.
--- include/net/netfilter/nf_flow_table.h | 16 +++++- net/netfilter/nf_flow_table_core.c | 35 ++++++++++--- net/netfilter/nf_flow_table_ip.c | 72 +++++++++++++++++++++------ net/netfilter/nft_flow_offload.c | 35 ++++++++++--- 4 files changed, 127 insertions(+), 31 deletions(-)
include/net/netfilter/nf_flow_table.h +14 -2
@@ -92,6 +92,7 @@ enum flow_offload_tuple_dir {enum flow_offload_xmit_type {FLOW_OFFLOAD_XMIT_NEIGH =0 ,FLOW_OFFLOAD_XMIT_XFRM , +FLOW_OFFLOAD_XMIT_DIRECT , };struct flow_offload_tuple {
@@ -120,8 +121,14 @@ struct flow_offload_tuple { xmit_type:2 ;u16 mtu; - -struct dst_entry *dst_cache; +union { +struct dst_entry *dst_cache; +struct { +u32 ifidx; +u8 h_source[ETH_ALEN ]; +u8 h_dest[ETH_ALEN ]; + } out; + }; };struct flow_offload_tuple_rhash {
@@ -168,6 +175,11 @@ struct nf_flow_route {struct {u32 ifindex; } in; +struct { +u32 ifindex; +u8 h_source[ETH_ALEN ]; +u8 h_dest[ETH_ALEN ]; + } out;enum flow_offload_xmit_type xmit_type; } tuple[FLOW_OFFLOAD_DIR_MAX ]; };
net/netfilter/nf_flow_table_core.c +28 -7
@@ -81,9 +81,6 @@ static int flow_offload_fill_route(struct flow_offload *flow,struct flow_offload_tuple *flow_tuple = &flow->tuplehash[dir].tuple;struct dst_entry *dst = route->tuple[dir].dst; -if (!dst_hold_safe (route->tuple[dir].dst)) -return -1 ; -switch (flow_tuple->l3proto) {case NFPROTO_IPV4 : flow_tuple->mtu =ip_dst_mtu_maybe_forward (dst, true);
@@ -94,12 +91,36 @@ static int flow_offload_fill_route(struct flow_offload *flow, } flow_tuple->iifidx = route->tuple[dir].in.ifindex; + +switch (route->tuple[dir].xmit_type) { +case FLOW_OFFLOAD_XMIT_DIRECT : +memcpy (flow_tuple->out.h_dest, route->tuple[dir].out.h_dest, +ETH_ALEN ); +memcpy (flow_tuple->out.h_source, route->tuple[dir].out.h_source, +ETH_ALEN ); + flow_tuple->out.ifidx = route->tuple[dir].out.ifindex; +break ; +case FLOW_OFFLOAD_XMIT_XFRM : +case FLOW_OFFLOAD_XMIT_NEIGH : +if (!dst_hold_safe (route->tuple[dir].dst)) +return -1 ; + + flow_tuple->dst_cache = dst; +break ; + } flow_tuple->xmit_type = route->tuple[dir].xmit_type; - flow_tuple->dst_cache = dst;return 0 ; } +static void nft_flow_dst_release (struct flow_offload *flow, +enum flow_offload_tuple_dir dir) +{ +if (flow->tuplehash[dir].tuple.xmit_type ==FLOW_OFFLOAD_XMIT_NEIGH || + flow->tuplehash[dir].tuple.xmit_type ==FLOW_OFFLOAD_XMIT_XFRM ) +dst_release (flow->tuplehash[dir].tuple.dst_cache); +} +int flow_offload_route_init (struct flow_offload *flow,const struct nf_flow_route *route) {
@@ -118,7 +139,7 @@ int flow_offload_route_init(struct flow_offload *flow,return 0 ; err_route_reply: -dst_release (route->tuple[FLOW_OFFLOAD_DIR_ORIGINAL ].dst); +nft_flow_dst_release (flow,FLOW_OFFLOAD_DIR_ORIGINAL );return err; }
@@ -169,8 +190,8 @@ static void flow_offload_fixup_ct(struct nf_conn *ct)static void flow_offload_route_release (struct flow_offload *flow) { -dst_release (flow->tuplehash[FLOW_OFFLOAD_DIR_ORIGINAL ].tuple.dst_cache); -dst_release (flow->tuplehash[FLOW_OFFLOAD_DIR_REPLY ].tuple.dst_cache); +nft_flow_dst_release (flow,FLOW_OFFLOAD_DIR_ORIGINAL ); +nft_flow_dst_release (flow,FLOW_OFFLOAD_DIR_REPLY ); }void flow_offload_free (struct flow_offload *flow)
net/netfilter/nf_flow_table_ip.c +56 -16
117 lines not on this page · raw message
net/netfilter/nft_flow_offload.c +29 -6
@@ -39,12 +39,11 @@ static void nft_default_forward_path(struct nf_flow_route *route,static int nft_dev_fill_forward_path (const struct nf_flow_route *route,const struct dst_entry *dst_cache,const struct nf_conn *ct, -enum ip_conntrack_dir dir, +enum ip_conntrack_dir dir,u8 *ha,struct net_device_path_stack *stack) {const void *daddr = &ct->tuplehash[!dir].tuple.src.u3;struct net_device *dev = dst_cache->dev; -unsigned char ha[ETH_ALEN ];struct neighbour *n;u8 nud_state;
@@ -66,27 +65,43 @@ static int nft_dev_fill_forward_path(const struct nf_flow_route *route,struct nft_forward_info {const struct net_device *indev; +const struct net_device *outdev; +u8 h_source[ETH_ALEN ]; +u8 h_dest[ETH_ALEN ]; +enum flow_offload_xmit_type xmit_type; };static void nft_dev_path_info (const struct net_device_path_stack *stack, -struct nft_forward_info *info) +struct nft_forward_info *info, +unsigned char *ha) {const struct net_device_path *path;int i; +memcpy (info->h_dest, ha,ETH_ALEN ); +for (i =0 ; i < stack->num_paths; i++) { path = &stack->path[i];switch (path->type) {case DEV_PATH_ETHERNET : info->indev = path->dev; +if (is_zero_ether_addr (info->h_source)) +memcpy (info->h_source, path->dev->dev_addr,ETH_ALEN );break ; -case DEV_PATH_VLAN :case DEV_PATH_BRIDGE : +if (is_zero_ether_addr (info->h_source)) +memcpy (info->h_source, path->dev->dev_addr,ETH_ALEN ); + + info->xmit_type =FLOW_OFFLOAD_XMIT_DIRECT ; +break ; +case DEV_PATH_VLAN :default : info->indev =NULL ;break ; } } +if (!info->outdev) + info->outdev = info->indev; } static bool nft_flowtable_find_dev(const struct net_device *dev,
@@ -114,14 +129,22 @@ static void nft_dev_forward_path(struct nf_flow_route *route,const struct dst_entry *dst = route->tuple[dir].dst;struct net_device_path_stack stack;struct nft_forward_info info = {}; +unsigned char ha[ETH_ALEN ]; -if (nft_dev_fill_forward_path (route, dst, ct, dir, &stack) >=0 ) -nft_dev_path_info (&stack, &info); +if (nft_dev_fill_forward_path (route, dst, ct, dir, ha, &stack) >=0 ) +nft_dev_path_info (&stack, &info, ha);if (!info.indev || !nft_flowtable_find_dev (info.indev, ft))return ; route->tuple[!dir].in.ifindex = info.indev->ifindex; + +if (info.xmit_type ==FLOW_OFFLOAD_XMIT_DIRECT ) { +memcpy (route->tuple[dir].out.h_source, info.h_source,ETH_ALEN ); +memcpy (route->tuple[dir].out.h_dest, info.h_dest,ETH_ALEN ); + route->tuple[dir].out.ifindex = info.outdev->ifindex; + route->tuple[dir].xmit_type = info.xmit_type; + } } static int nft_flow_route(const struct nft_pktinfo *pkt,
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerPATCH 10/23 netfilter: flowtable: add vlan support
In reply to Pablo Neira AyusoAdd the vlan id and protocol to the flow tuple to uniquely identify flows from the receive path. For the transmit path, dev_hard_header() on the vlan device push the headers. This patch includes support for two vlan headers (QinQ) from the ingress path.
Add a generic encap field to the flowtable entry which stores the protocol and the tag id. This allows to reuse these fields in the PPPoE support coming in a later patch.
--- include/net/netfilter/nf_flow_table.h | 17 +++- net/netfilter/nf_flow_table_core.c | 7 ++ net/netfilter/nf_flow_table_ip.c | 123 +++++++++++++++++++++----- net/netfilter/nft_flow_offload.c | 26 +++++- 4 files changed, 147 insertions(+), 26 deletions(-)
include/net/netfilter/nf_flow_table.h +14 -3
@@ -95,6 +95,8 @@ enum flow_offload_xmit_type { FLOW_OFFLOAD_XMIT_DIRECT, }; +#define NF_FLOW_TABLE_ENCAP_MAX 2 + struct flow_offload_tuple { union { struct in_addr src_v4;
@@ -113,13 +115,17 @@ struct flow_offload_tuple {u8 l3proto;u8 l4proto; +struct { +u16 id; +__be16 proto; + } encap[NF_FLOW_TABLE_ENCAP_MAX ];/* All members above are keys for lookups, see flow_offload_hash(). */ struct { } __hash; - u8 dir:6, - xmit_type:2; - + u8 dir:4, + xmit_type:2, + encap_num:2;u16 mtu;union {struct dst_entry *dst_cache;
@@ -174,6 +180,11 @@ struct nf_flow_route {struct dst_entry *dst;struct {u32 ifindex; +struct { +u16 id; +__be16 proto; + } encap[NF_FLOW_TABLE_ENCAP_MAX ]; +u8 num_encaps; } in;struct {u32 ifindex;
net/netfilter/nf_flow_table_core.c +7 -0
@@ -80,6 +80,7 @@ static int flow_offload_fill_route(struct flow_offload *flow, {struct flow_offload_tuple *flow_tuple = &flow->tuplehash[dir].tuple;struct dst_entry *dst = route->tuple[dir].dst; +int i, j =0 ;switch (flow_tuple->l3proto) {case NFPROTO_IPV4 :
@@ -91,6 +92,12 @@ static int flow_offload_fill_route(struct flow_offload *flow, } flow_tuple->iifidx = route->tuple[dir].in.ifindex; +for (i = route->tuple[dir].in.num_encaps -1 ; i >=0 ; i--) { + flow_tuple->encap[j].id = route->tuple[dir].in.encap[i].id; + flow_tuple->encap[j].proto = route->tuple[dir].in.encap[i].proto; + j++; + } + flow_tuple->encap_num = route->tuple[dir].in.num_encaps;switch (route->tuple[dir].xmit_type) {case FLOW_OFFLOAD_XMIT_DIRECT :
net/netfilter/nf_flow_table_ip.c +101 -22
231 lines not on this page · raw message
net/netfilter/nft_flow_offload.c +25 -1
@@ -66,6 +66,11 @@ static int nft_dev_fill_forward_path(const struct nf_flow_route *route,struct nft_forward_info {const struct net_device *indev;const struct net_device *outdev; +struct id { +__u16 id; +__be16 proto; + } encap[NF_FLOW_TABLE_ENCAP_MAX ]; +u8 num_encaps;u8 h_source[ETH_ALEN ];u8 h_dest[ETH_ALEN ];enum flow_offload_xmit_type xmit_type;
@@ -84,9 +89,23 @@ static void nft_dev_path_info(const struct net_device_path_stack *stack, path = &stack->path[i];switch (path->type) {case DEV_PATH_ETHERNET : +case DEV_PATH_VLAN : info->indev = path->dev;if (is_zero_ether_addr (info->h_source))memcpy (info->h_source, path->dev->dev_addr,ETH_ALEN ); + +if (path->type ==DEV_PATH_ETHERNET ) +break ; + +/* DEV_PATH_VLAN */ +if (info->num_encaps >=NF_FLOW_TABLE_ENCAP_MAX ) { + info->indev =NULL ; +break ; + } + info->outdev = path->dev; + info->encap[info->num_encaps].id = path->encap.id; + info->encap[info->num_encaps].proto = path->encap.proto; + info->num_encaps++;break ;case DEV_PATH_BRIDGE :if (is_zero_ether_addr (info->h_source))
@@ -94,7 +113,6 @@ static void nft_dev_path_info(const struct net_device_path_stack *stack, info->xmit_type =FLOW_OFFLOAD_XMIT_DIRECT ;break ; -case DEV_PATH_VLAN :default : info->indev =NULL ;break ;
@@ -130,6 +148,7 @@ static void nft_dev_forward_path(struct nf_flow_route *route,struct net_device_path_stack stack;struct nft_forward_info info = {};unsigned char ha[ETH_ALEN ]; +int i;if (nft_dev_fill_forward_path (route, dst, ct, dir, ha, &stack) >=0 )nft_dev_path_info (&stack, &info, ha);
@@ -138,6 +157,11 @@ static void nft_dev_forward_path(struct nf_flow_route *route,return ; route->tuple[!dir].in.ifindex = info.indev->ifindex; +for (i =0 ; i < info.num_encaps; i++) { + route->tuple[!dir].in.encap[i].id = info.encap[i].id; + route->tuple[!dir].in.encap[i].proto = info.encap[i].proto; + } + route->tuple[!dir].in.num_encaps = info.num_encaps;if (info.xmit_type ==FLOW_OFFLOAD_XMIT_DIRECT ) {memcpy (route->tuple[dir].out.h_source, info.h_source,ETH_ALEN );
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerPATCH 11/23 netfilter: flowtable: add bridge vlan filtering support
In reply to Pablo Neira AyusoAdd the vlan tag based when PVID is set on.
--- net/netfilter/nft_flow_offload.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
net/netfilter/nft_flow_offload.c +12 -0
@@ -111,6 +111,18 @@ static void nft_dev_path_info(const struct net_device_path_stack *stack,if (is_zero_ether_addr (info->h_source))memcpy (info->h_source, path->dev->dev_addr,ETH_ALEN ); +switch (path->bridge.vlan_mode) { +case DEV_PATH_BR_VLAN_TAG : + info->encap[info->num_encaps].id = path->bridge.vlan_id; + info->encap[info->num_encaps].proto = path->bridge.vlan_proto; + info->num_encaps++; +break ; +case DEV_PATH_BR_VLAN_UNTAG : + info->num_encaps--; +break ; +case DEV_PATH_BR_VLAN_KEEP : +break ; + } info->xmit_type =FLOW_OFFLOAD_XMIT_DIRECT ;break ;default :
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerPATCH 12/23 netfilter: flowtable: add pppoe support
In reply to Pablo Neira AyusoAdd the PPPoE protocol and session id to the flow tuple using the encap fields to uniquely identify flows from the receive path. For the transmit path, dev_hard_header() on the vlan device push the headers.
--- net/netfilter/nf_flow_table_ip.c | 83 +++++++++++++++++++++++++------- net/netfilter/nft_flow_offload.c | 5 +- 2 files changed, 69 insertions(+), 19 deletions(-)
net/netfilter/nf_flow_table_ip.c +65 -18
@@ -7,6 +7,9 @@#include <linux/ip.h> #include <linux/ipv6.h> #include <linux/netdevice.h> +#include <linux/if_ether.h> +#include <linux/if_pppox.h> +#include <linux/ppp_defs.h> #include <net/ip.h> #include <net/ipv6.h> #include <net/ip6_route.h>
@@ -162,6 +165,8 @@ static bool ip_has_options(unsigned int thoff)static void nf_flow_tuple_encap (struct sk_buff *skb,struct flow_offload_tuple *tuple) { +struct vlan_ethhdr *veth; +struct pppoe_hdr *phdr;int i =0 ;if (skb_vlan_tag_present (skb)) {
@@ -169,23 +174,35 @@ static void nf_flow_tuple_encap(struct sk_buff *skb, tuple->encap[i].proto = skb->vlan_proto; i++; } -if (skb->protocol ==htons (ETH_P_8021Q )) { -struct vlan_ethhdr *veth = (struct vlan_ethhdr *)skb_mac_header (skb); - +switch (skb->protocol) { +case htons (ETH_P_8021Q ): + veth = (struct vlan_ethhdr *)skb_mac_header (skb); tuple->encap[i].id =ntohs (veth->h_vlan_TCI); tuple->encap[i].proto = skb->protocol; +break ; +case htons (ETH_P_PPP_SES ): + phdr = (struct pppoe_hdr *)skb_mac_header (skb); + tuple->encap[i].id =ntohs (phdr->sid); + tuple->encap[i].proto = skb->protocol; +break ; } }static int nf_flow_tuple_ip (struct sk_buff *skb,const struct net_device *dev, -struct flow_offload_tuple *tuple) +struct flow_offload_tuple *tuple,u32 *nhoff) {unsigned int thoff, hdrsize, offset =0 ;struct flow_ports *ports;struct iphdr *iph; -if (skb->protocol ==htons (ETH_P_8021Q )) +switch (skb->protocol) { +case htons (ETH_P_8021Q ): offset +=VLAN_HLEN ; +break ; +case htons (ETH_P_PPP_SES ): + offset +=PPPOE_SES_HLEN ; +break ; + }if (!pskb_may_pull (skb,sizeof (*iph) + offset))return -1 ;
@@ -226,6 +243,7 @@ static int nf_flow_tuple_ip(struct sk_buff *skb, const struct net_device *dev, tuple->l4proto = iph->protocol; tuple->iifidx = dev->ifindex;nf_flow_tuple_encap (skb, tuple); + *nhoff = offset;return 0 ; }
@@ -270,14 +288,36 @@ static unsigned int nf_flow_xmit_xfrm(struct sk_buff *skb,return NF_STOLEN ; } +static inline __be16 nf_flow_pppoe_proto (const struct sk_buff *skb) +{ +__be16 proto; + + proto = *((__be16 *)(skb_mac_header (skb) +ETH_HLEN + +sizeof (struct pppoe_hdr ))); +switch (proto) { +case htons (PPP_IP ): +return htons (ETH_P_IP ); +case htons (PPP_IPV6 ): +return htons (ETH_P_IPV6 ); + } + +return 0 ; +} +static bool nf_flow_skb_encap_protocol (const struct sk_buff *skb,__be16 proto) { -if (skb->protocol ==htons (ETH_P_8021Q )) { -struct vlan_ethhdr *veth; +struct vlan_ethhdr *veth; +switch (skb->protocol) { +case htons (ETH_P_8021Q ): veth = (struct vlan_ethhdr *)skb_mac_header (skb);if (veth->h_vlan_encapsulated_proto == proto)return true; +break ; +case htons (ETH_P_PPP_SES ): +if (nf_flow_pppoe_proto (skb) == proto) +return true; +break ; }return false;
@@ -294,12 +334,18 @@ static void nf_flow_encap_pop(struct sk_buff *skb,__vlan_hwaccel_clear_tag (skb);continue ; } -if (skb->protocol ==htons (ETH_P_8021Q )) { +switch (skb->protocol) { +case htons (ETH_P_8021Q ): vlan_hdr = (struct vlan_hdr *)skb->data;__skb_pull (skb,VLAN_HLEN );vlan_set_encap_proto (skb, vlan_hdr);skb_reset_network_header (skb);break ; +case htons (ETH_P_PPP_SES ): + skb->protocol =nf_flow_pppoe_proto (skb); +skb_pull (skb,PPPOE_SES_HLEN ); +skb_reset_network_header (skb); +break ; } } }
@@ -343,7 +389,7 @@ nf_flow_offload_ip_hook(void *priv, struct sk_buff *skb, !nf_flow_skb_encap_protocol(skb, htons(ETH_P_IP)))return NF_ACCEPT ; -if (nf_flow_tuple_ip (skb, state->in, &tuple) <0 ) +if (nf_flow_tuple_ip (skb, state->in, &tuple, &offset) <0 )return NF_ACCEPT ; tuplehash =flow_offload_lookup (flow_table, &tuple);
@@ -357,9 +403,6 @@ nf_flow_offload_ip_hook(void *priv, struct sk_buff *skb,if (unlikely (nf_flow_exceeds_mtu (skb, mtu)))return NF_ACCEPT ; -if (skb->protocol ==htons (ETH_P_8021Q )) - offset +=VLAN_HLEN ; -if (skb_try_make_writable (skb,sizeof (*iph) + offset))return NF_DROP ;
@@ -543,14 +586,20 @@ static int nf_flow_nat_ipv6(const struct flow_offload *flow, }static int nf_flow_tuple_ipv6 (struct sk_buff *skb,const struct net_device *dev, -struct flow_offload_tuple *tuple) +struct flow_offload_tuple *tuple,u32 *nhoff) {unsigned int thoff, hdrsize, offset =0 ;struct flow_ports *ports;struct ipv6hdr *ip6h; -if (skb->protocol ==htons (ETH_P_8021Q )) +switch (skb->protocol) { +case htons (ETH_P_8021Q ): offset +=VLAN_HLEN ; +break ; +case htons (ETH_P_PPP_SES ): + offset +=PPPOE_SES_HLEN ; +break ; + }if (!pskb_may_pull (skb,sizeof (*ip6h) + offset))return -1 ;
@@ -586,6 +635,7 @@ static int nf_flow_tuple_ipv6(struct sk_buff *skb, const struct net_device *dev, tuple->l4proto = ip6h->nexthdr; tuple->iifidx = dev->ifindex;nf_flow_tuple_encap (skb, tuple); + *nhoff = offset;return 0 ; }
@@ -611,7 +661,7 @@ nf_flow_offload_ipv6_hook(void *priv, struct sk_buff *skb, !nf_flow_skb_encap_protocol(skb, htons(ETH_P_IPV6)))return NF_ACCEPT ; -if (nf_flow_tuple_ipv6 (skb, state->in, &tuple) <0 ) +if (nf_flow_tuple_ipv6 (skb, state->in, &tuple, &offset) <0 )return NF_ACCEPT ; tuplehash =flow_offload_lookup (flow_table, &tuple);
@@ -625,9 +675,6 @@ nf_flow_offload_ipv6_hook(void *priv, struct sk_buff *skb,if (unlikely (nf_flow_exceeds_mtu (skb, mtu)))return NF_ACCEPT ; -if (skb->protocol ==htons (ETH_P_8021Q )) - offset +=VLAN_HLEN ; - ip6h = (struct ipv6hdr *)(skb_network_header (skb) + offset);if (nf_flow_state_check (flow, ip6h->nexthdr, skb,sizeof (*ip6h)))return NF_ACCEPT ;
net/netfilter/nft_flow_offload.c +4 -1
@@ -90,6 +90,7 @@ static void nft_dev_path_info(const struct net_device_path_stack *stack,switch (path->type) {case DEV_PATH_ETHERNET :case DEV_PATH_VLAN : +case DEV_PATH_PPPOE : info->indev = path->dev;if (is_zero_ether_addr (info->h_source))memcpy (info->h_source, path->dev->dev_addr,ETH_ALEN );
@@ -97,7 +98,7 @@ static void nft_dev_path_info(const struct net_device_path_stack *stack,if (path->type ==DEV_PATH_ETHERNET )break ; -/* DEV_PATH_VLAN */ +/* DEV_PATH_VLAN and DEV_PATH_PPPOE */ if (info->num_encaps >=NF_FLOW_TABLE_ENCAP_MAX ) { info->indev =NULL ;break ;
@@ -106,6 +107,8 @@ static void nft_dev_path_info(const struct net_device_path_stack *stack, info->encap[info->num_encaps].id = path->encap.id; info->encap[info->num_encaps].proto = path->encap.proto; info->num_encaps++; +if (path->type ==DEV_PATH_PPPOE ) +memcpy (info->h_dest, path->encap.h_dest,ETH_ALEN );break ;case DEV_PATH_BRIDGE :if (is_zero_ether_addr (info->h_source))
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerPATCH 13/23 netfilter: flowtable: add dsa support
In reply to Pablo Neira AyusoReplace the master ethernet device by the dsa slave port. Packets coming in from the software ingress path use the dsa slave port as input device.
--- net/netfilter/nft_flow_offload.c | 5 +++++ 1 file changed, 5 insertions(+)
net/netfilter/nft_flow_offload.c +5 -0
@@ -89,6 +89,7 @@ static void nft_dev_path_info(const struct net_device_path_stack *stack, path = &stack->path[i];switch (path->type) {case DEV_PATH_ETHERNET : +case DEV_PATH_DSA :case DEV_PATH_VLAN :case DEV_PATH_PPPOE : info->indev = path->dev;
@@ -97,6 +98,10 @@ static void nft_dev_path_info(const struct net_device_path_stack *stack,if (path->type ==DEV_PATH_ETHERNET )break ; +if (path->type ==DEV_PATH_DSA ) { + i = stack->num_paths; +break ; + }/* DEV_PATH_VLAN and DEV_PATH_PPPOE */ if (info->num_encaps >=NF_FLOW_TABLE_ENCAP_MAX ) {
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerPATCH 14/23 selftests: netfilter: flowtable bridge and vlan support
In reply to Pablo Neira AyusoThis patch adds two new tests to cover bridge and vlan support:
- Add a bridge device to the Router1 (nsr1) container and attach the veth0 device to the bridge. Set the IP address to the bridge device to exercise the bridge forwarding path.
- Add vlan encapsulation between to the bridge device in the Router1 and one of the sender containers (ns1).
--- .../selftests/netfilter/nft_flowtable.sh | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+)
tools/testing/selftests/netfilter/nft_flowtable.sh +82 -0
@@ -371,6 +371,88 @@ else ip netns exec nsr1 nft list ruleset fi +# Another test: +# Add bridge interface br0 to Router1, with NAT enabled. +ip -net nsr1 link add name br0 type bridge +ip -net nsr1 addr flush dev veth0 +ip -net nsr1 link set up dev veth0 +ip -net nsr1 link set veth0 master br0 +ip -net nsr1 addr add 10.0.1.1/24 dev br0 +ip -net nsr1 addr add dead:1::1/64 dev br0 +ip -net nsr1 link set up dev br0 + +ip netns exec nsr1 sysctl net.ipv4.conf.br0.forwarding=1 > /dev/null + +# br0 with NAT enabled. +ip netns exec nsr1 nft -f - <<EOF +flush table ip nat +table ip nat { + chain prerouting { + type nat hook prerouting priority 0; policy accept; + meta iif "br0" ip daddr 10.6.6.6 tcp dport 1666 counter dnat ip to 10.0.2.99:12345 + } + + chain postrouting { + type nat hook postrouting priority 0; policy accept; + meta oifname "veth1" counter masquerade + } +} +EOF + +if test_tcp_forwarding_nat ns1 ns2; then + echo "PASS: flow offloaded for ns1/ns2 with bridge NAT" +else + echo "FAIL: flow offload for ns1/ns2 with bridge NAT" 1>&2 + ip netns exec nsr1 nft list ruleset + ret=1 +fi + +# Another test: +# Add bridge interface br0 to Router1, with NAT and VLAN. +ip -net nsr1 link set veth0 nomaster +ip -net nsr1 link set down dev veth0 +ip -net nsr1 link add link veth0 name veth0.10 type vlan id 10 +ip -net nsr1 link set up dev veth0 +ip -net nsr1 link set up dev veth0.10 +ip -net nsr1 link set veth0.10 master br0 + +ip -net ns1 addr flush dev eth0 +ip -net ns1 link add link eth0 name eth0.10 type vlan id 10 +ip -net ns1 link set eth0 up +ip -net ns1 link set eth0.10 up +ip -net ns1 addr add 10.0.1.99/24 dev eth0.10 +ip -net ns1 route add default via 10.0.1.1 +ip -net ns1 addr add dead:1::99/64 dev eth0.10 + +if test_tcp_forwarding_nat ns1 ns2; then + echo "PASS: flow offloaded for ns1/ns2 with bridge NAT and VLAN" +else + echo "FAIL: flow offload for ns1/ns2 with bridge NAT and VLAN" 1>&2 + ip netns exec nsr1 nft list ruleset + ret=1 +fi + +# restore test topology (remove bridge and VLAN) +ip -net nsr1 link set veth0 nomaster +ip -net nsr1 link set veth0 down +ip -net nsr1 link set veth0.10 down +ip -net nsr1 link delete veth0.10 type vlan +ip -net nsr1 link delete br0 type bridge +ip -net ns1 addr flush dev eth0.10 +ip -net ns1 link set eth0.10 down +ip -net ns1 link set eth0 down +ip -net ns1 link delete eth0.10 type vlan + +# restore address in ns1 and nsr1 +ip -net ns1 link set eth0 up +ip -net ns1 addr add 10.0.1.99/24 dev eth0 +ip -net ns1 route add default via 10.0.1.1 +ip -net ns1 addr add dead:1::99/64 dev eth0 +ip -net ns1 route add default via dead:1::1 +ip -net nsr1 addr add 10.0.1.1/24 dev veth0 +ip -net nsr1 addr add dead:1::1/64 dev veth0 +ip -net nsr1 link set up dev veth0 + KEY_SHA="0x"$(ps -xaf | sha1sum | cut -d " " -f 1) KEY_AES="0x"$(ps -xaf | md5sum | cut -d " " -f 1) SPI1=$RANDOM
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerPATCH 15/23 netfilter: flowtable: add offload support for xmit path types
In reply to Pablo Neira AyusoWhen the flow tuple xmit_type is set to FLOW_OFFLOAD_XMIT_DIRECT, the dst_cache pointer is not valid, and the h_source/h_dest/ifidx out fields need to be used.
This patch also adds the FLOW_ACTION_VLAN_PUSH action to pass the VLAN tag to the driver.
--- net/netfilter/nf_flow_table_offload.c | 166 +++++++++++++++++++------- 1 file changed, 124 insertions(+), 42 deletions(-)
net/netfilter/nf_flow_table_offload.c +124 -42
@@ -175,28 +175,45 @@ static int flow_offload_eth_src(struct net *net,enum flow_offload_tuple_dir dir, struct nf_flow_rule *flow_rule) { - const struct flow_offload_tuple *tuple = &flow->tuplehash[!dir].tuple; struct flow_action_entry *entry0 = flow_action_entry_next(flow_rule);struct flow_action_entry *entry1 =flow_action_entry_next (flow_rule); -struct net_device *dev; +const struct flow_offload_tuple *other_tuple, *this_tuple; +struct net_device *dev =NULL ; +const unsigned char *addr;u32 mask, val;u16 val16; - dev =dev_get_by_index (net, tuple->iifidx); -if (!dev) -return -ENOENT ; + this_tuple = &flow->tuplehash[dir].tuple; + +switch (this_tuple->xmit_type) { +case FLOW_OFFLOAD_XMIT_DIRECT : + addr = this_tuple->out.h_source; +break ; +case FLOW_OFFLOAD_XMIT_NEIGH : + other_tuple = &flow->tuplehash[!dir].tuple; + dev =dev_get_by_index (net, other_tuple->iifidx); +if (!dev) +return -ENOENT ; + + addr = dev->dev_addr; +break ; +default : +return -EOPNOTSUPP ; + } mask = ~0xffff0000 ; -memcpy (&val16, dev->dev_addr,2 ); +memcpy (&val16, addr,2 ); val = val16 <<16 ;flow_offload_mangle (entry0,FLOW_ACT_MANGLE_HDR_TYPE_ETH ,4 , &val, &mask); mask = ~0xffffffff ; -memcpy (&val, dev->dev_addr +2 ,4 ); +memcpy (&val, addr +2 ,4 );flow_offload_mangle (entry1,FLOW_ACT_MANGLE_HDR_TYPE_ETH ,8 , &val, &mask); -dev_put (dev); + +if (dev) +dev_put (dev);return 0 ; }
@@ -208,27 +225,40 @@ static int flow_offload_eth_dst(struct net *net, {struct flow_action_entry *entry0 =flow_action_entry_next (flow_rule);struct flow_action_entry *entry1 =flow_action_entry_next (flow_rule); -const void *daddr = &flow->tuplehash[!dir].tuple.src_v4; +const struct flow_offload_tuple *other_tuple, *this_tuple;const struct dst_entry *dst_cache;unsigned char ha[ETH_ALEN ];struct neighbour *n; +const void *daddr;u32 mask, val;u8 nud_state;u16 val16; - dst_cache = flow->tuplehash[dir].tuple.dst_cache; - n =dst_neigh_lookup (dst_cache, daddr); -if (!n) -return -ENOENT ; + this_tuple = &flow->tuplehash[dir].tuple; -read_lock_bh (&n->lock); - nud_state = n->nud_state; -ether_addr_copy (ha, n->ha); -read_unlock_bh (&n->lock); - -if (!(nud_state &NUD_VALID )) { +switch (this_tuple->xmit_type) { +case FLOW_OFFLOAD_XMIT_DIRECT : +ether_addr_copy (ha, this_tuple->out.h_dest); +break ; +case FLOW_OFFLOAD_XMIT_NEIGH : + other_tuple = &flow->tuplehash[!dir].tuple; + daddr = &other_tuple->src_v4; + dst_cache = this_tuple->dst_cache; + n =dst_neigh_lookup (dst_cache, daddr); +if (!n) +return -ENOENT ; + +read_lock_bh (&n->lock); + nud_state = n->nud_state; +ether_addr_copy (ha, n->ha); +read_unlock_bh (&n->lock);neigh_release (n); -return -ENOENT ; + +if (!(nud_state &NUD_VALID )) +return -ENOENT ; +break ; +default : +return -EOPNOTSUPP ; } mask = ~0xffffffff ;
@@ -241,7 +271,6 @@ static int flow_offload_eth_dst(struct net *net, val = val16;flow_offload_mangle (entry1,FLOW_ACT_MANGLE_HDR_TYPE_ETH ,4 , &val, &mask); -neigh_release (n);return 0 ; }
@@ -463,27 +492,52 @@ static void flow_offload_ipv4_checksum(struct net *net, } } -static void flow_offload_redirect (const struct flow_offload *flow, +static void flow_offload_redirect (struct net *net, +const struct flow_offload *flow,enum flow_offload_tuple_dir dir,struct nf_flow_rule *flow_rule) { -struct flow_action_entry *entry =flow_action_entry_next (flow_rule); -struct rtable *rt; +const struct flow_offload_tuple *this_tuple, *other_tuple; +struct flow_action_entry *entry; +struct net_device *dev; +int ifindex; - rt = (struct rtable *)flow->tuplehash[dir].tuple.dst_cache; + this_tuple = &flow->tuplehash[dir].tuple; +switch (this_tuple->xmit_type) { +case FLOW_OFFLOAD_XMIT_DIRECT : + this_tuple = &flow->tuplehash[dir].tuple; + ifindex = this_tuple->out.ifidx; +break ; +case FLOW_OFFLOAD_XMIT_NEIGH : + other_tuple = &flow->tuplehash[!dir].tuple; + ifindex = other_tuple->iifidx; +break ; +default : +return ; + } + + dev =dev_get_by_index (net, ifindex); +if (!dev) +return ; + + entry =flow_action_entry_next (flow_rule); entry->id =FLOW_ACTION_REDIRECT ; - entry->dev = rt->dst.dev; -dev_hold (rt->dst.dev); + entry->dev = dev; }static void flow_offload_encap_tunnel (const struct flow_offload *flow,enum flow_offload_tuple_dir dir,struct nf_flow_rule *flow_rule) { +const struct flow_offload_tuple *this_tuple;struct flow_action_entry *entry;struct dst_entry *dst; - dst = flow->tuplehash[dir].tuple.dst_cache; + this_tuple = &flow->tuplehash[dir].tuple; +if (this_tuple->xmit_type ==FLOW_OFFLOAD_XMIT_DIRECT ) +return ; + + dst = this_tuple->dst_cache;if (dst && dst->lwtstate) {struct ip_tunnel_info *tun_info;
@@ -500,10 +554,15 @@ static void flow_offload_decap_tunnel(const struct flow_offload *flow,enum flow_offload_tuple_dir dir, struct nf_flow_rule *flow_rule) { + const struct flow_offload_tuple *other_tuple;struct flow_action_entry *entry;struct dst_entry *dst; - dst = flow->tuplehash[!dir].tuple.dst_cache; + other_tuple = &flow->tuplehash[!dir].tuple; +if (other_tuple->xmit_type ==FLOW_OFFLOAD_XMIT_DIRECT ) +return ; + + dst = other_tuple->dst_cache;if (dst && dst->lwtstate) {struct ip_tunnel_info *tun_info;
@@ -515,10 +574,14 @@ static void flow_offload_decap_tunnel(const struct flow_offload *flow, } } -int nf_flow_rule_route_ipv4 (struct net *net,const struct flow_offload *flow, -enum flow_offload_tuple_dir dir, -struct nf_flow_rule *flow_rule) +static int +nf_flow_rule_route_common (struct net *net,const struct flow_offload *flow, +enum flow_offload_tuple_dir dir, +struct nf_flow_rule *flow_rule) { +const struct flow_offload_tuple *other_tuple; +int i; +flow_offload_decap_tunnel (flow, dir, flow_rule);flow_offload_encap_tunnel (flow, dir, flow_rule);
@@ -526,6 +589,26 @@ int nf_flow_rule_route_ipv4(struct net *net, const struct flow_offload *flow, flow_offload_eth_dst(net, flow, dir, flow_rule) < 0)return -1 ; + other_tuple = &flow->tuplehash[!dir].tuple; + +for (i =0 ; i < other_tuple->encap_num; i++) { +struct flow_action_entry *entry =flow_action_entry_next (flow_rule); + + entry->id =FLOW_ACTION_VLAN_PUSH ; + entry->vlan.vid = other_tuple->encap[i].id; + entry->vlan.proto = other_tuple->encap[i].proto; + } + +return 0 ; +} + +int nf_flow_rule_route_ipv4 (struct net *net,const struct flow_offload *flow, +enum flow_offload_tuple_dir dir, +struct nf_flow_rule *flow_rule) +{ +if (nf_flow_rule_route_common (net, flow, dir, flow_rule) <0 ) +return -1 ; +if (test_bit (NF_FLOW_SNAT , &flow->flags)) {flow_offload_ipv4_snat (net, flow, dir, flow_rule);flow_offload_port_snat (net, flow, dir, flow_rule);
@@ -538,7 +621,7 @@ int nf_flow_rule_route_ipv4(struct net *net, const struct flow_offload *flow, test_bit(NF_FLOW_DNAT, &flow->flags))flow_offload_ipv4_checksum (net, flow, flow_rule); -flow_offload_redirect (flow, dir, flow_rule); +flow_offload_redirect (net, flow, dir, flow_rule);return 0 ; }
@@ -548,11 +631,7 @@ int nf_flow_rule_route_ipv6(struct net *net, const struct flow_offload *flow, enum flow_offload_tuple_dir dir, struct nf_flow_rule *flow_rule) { -flow_offload_decap_tunnel (flow ,dir ,flow_rule ); -flow_offload_encap_tunnel (flow, dir, flow_rule); - -if (flow_offload_eth_src (net, flow, dir, flow_rule) <0 || -flow_offload_eth_dst (net, flow, dir, flow_rule) <0 ) + if (nf_flow_rule_route_common(net, flow, dir, flow_rule) < 0) return -1; if (test_bit(NF_FLOW_SNAT, &flow->flags)) {
@@ -564,7 +643,7 @@ int nf_flow_rule_route_ipv6(struct net *net, const struct flow_offload *flow,flow_offload_port_dnat (net, flow, dir, flow_rule); } -flow_offload_redirect (flow, dir, flow_rule); +flow_offload_redirect (net, flow, dir, flow_rule);return 0 ; }
@@ -578,10 +657,10 @@ nf_flow_offload_rule_alloc(struct net *net, enum flow_offload_tuple_dir dir) {const struct nf_flowtable *flowtable = offload->flowtable; +const struct flow_offload_tuple *tuple, *other_tuple;const struct flow_offload *flow = offload->flow; -const struct flow_offload_tuple *tuple; +struct dst_entry *other_dst =NULL ;struct nf_flow_rule *flow_rule; -struct dst_entry *other_dst;int err = -ENOMEM ; flow_rule =kzalloc (sizeof (*flow_rule),GFP_KERNEL );
@@ -597,7 +676,10 @@ nf_flow_offload_rule_alloc(struct net *net, flow_rule->rule->match.key = &flow_rule->match.key; tuple = &flow->tuplehash[dir].tuple; - other_dst = flow->tuplehash[!dir].tuple.dst_cache; + other_tuple = &flow->tuplehash[!dir].tuple; +if (other_tuple->xmit_type ==FLOW_OFFLOAD_XMIT_NEIGH ) + other_dst = other_tuple->dst_cache; + err =nf_flow_rule_match (&flow_rule->match, tuple, other_dst);if (err <0 ) goto err_flow_match;
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerPATCH 16/23 netfilter: nft_flow_offload: use direct xmit if hardware offload is enabled
In reply to Pablo Neira AyusoIf there is a forward path to reach an ethernet device and hardware offload is enabled, then use the direct xmit path.
Moreover, store the real device in the direct xmit path info since software datapath uses dev_hard_header() to push the layer encapsulation headers while hardware offload refers to the real device.
--- include/net/netfilter/nf_flow_table.h | 2 ++ net/netfilter/nf_flow_table_core.c | 1 + net/netfilter/nf_flow_table_offload.c | 2 +- net/netfilter/nft_flow_offload.c | 21 +++++++++++++++++++-- 4 files changed, 23 insertions(+), 3 deletions(-)
include/net/netfilter/nf_flow_table.h +2 -0
@@ -131,6 +131,7 @@ struct flow_offload_tuple {struct dst_entry *dst_cache;struct {u32 ifidx; +u32 hw_ifidx;u8 h_source[ETH_ALEN ];u8 h_dest[ETH_ALEN ]; } out;
@@ -188,6 +189,7 @@ struct nf_flow_route { } in;struct {u32 ifindex; +u32 hw_ifindex;u8 h_source[ETH_ALEN ];u8 h_dest[ETH_ALEN ]; } out;
net/netfilter/nf_flow_table_core.c +1 -0
@@ -106,6 +106,7 @@ static int flow_offload_fill_route(struct flow_offload *flow,memcpy (flow_tuple->out.h_source, route->tuple[dir].out.h_source,ETH_ALEN ); flow_tuple->out.ifidx = route->tuple[dir].out.ifindex; + flow_tuple->out.hw_ifidx = route->tuple[dir].out.hw_ifindex;break ;case FLOW_OFFLOAD_XMIT_XFRM :case FLOW_OFFLOAD_XMIT_NEIGH :
net/netfilter/nf_flow_table_offload.c +1 -1
@@ -506,7 +506,7 @@ static void flow_offload_redirect(struct net *net,switch (this_tuple->xmit_type) {case FLOW_OFFLOAD_XMIT_DIRECT : this_tuple = &flow->tuplehash[dir].tuple; - ifindex = this_tuple->out.ifidx; + ifindex = this_tuple->out.hw_ifidx;break ;case FLOW_OFFLOAD_XMIT_NEIGH : other_tuple = &flow->tuplehash[!dir].tuple;
net/netfilter/nft_flow_offload.c +19 -2
@@ -66,6 +66,7 @@ static int nft_dev_fill_forward_path(const struct nf_flow_route *route,struct nft_forward_info {const struct net_device *indev;const struct net_device *outdev; +const struct net_device *hw_outdev;struct id {__u16 id;__be16 proto;
@@ -76,9 +77,18 @@ struct nft_forward_info {enum flow_offload_xmit_type xmit_type; }; +static bool nft_is_valid_ether_device (const struct net_device *dev) +{ +if (!dev || (dev->flags &IFF_LOOPBACK ) || dev->type !=ARPHRD_ETHER || + dev->addr_len !=ETH_ALEN || !is_valid_ether_addr (dev->dev_addr)) +return false; + +return true; +} +static void nft_dev_path_info (const struct net_device_path_stack *stack,struct nft_forward_info *info, -unsigned char *ha) +unsigned char *ha,struct nf_flowtable *flowtable) {const struct net_device_path *path;int i;
@@ -140,6 +150,12 @@ static void nft_dev_path_info(const struct net_device_path_stack *stack, }if (!info->outdev) info->outdev = info->indev; + + info->hw_outdev = info->indev; + +if (nf_flowtable_hw_offload (flowtable) && +nft_is_valid_ether_device (info->indev)) + info->xmit_type =FLOW_OFFLOAD_XMIT_DIRECT ; } static bool nft_flowtable_find_dev(const struct net_device *dev,
@@ -171,7 +187,7 @@ static void nft_dev_forward_path(struct nf_flow_route *route,int i;if (nft_dev_fill_forward_path (route, dst, ct, dir, ha, &stack) >=0 ) -nft_dev_path_info (&stack, &info, ha); +nft_dev_path_info (&stack, &info, ha, &ft->data);if (!info.indev || !nft_flowtable_find_dev (info.indev, ft))return ;
@@ -187,6 +203,7 @@ static void nft_dev_forward_path(struct nf_flow_route *route,memcpy (route->tuple[dir].out.h_source, info.h_source,ETH_ALEN );memcpy (route->tuple[dir].out.h_dest, info.h_dest,ETH_ALEN ); route->tuple[dir].out.ifindex = info.outdev->ifindex; + route->tuple[dir].out.hw_ifindex = info.hw_outdev->ifindex; route->tuple[dir].xmit_type = info.xmit_type; } }
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerPATCH 17/23 netfilter: flowtable: bridge vlan hardware offload and switchdev
In reply to Pablo Neira AyusoFrom: Felix Fietkau <[email protected]>
The switch might have already added the VLAN tag through PVID hardware offload. Keep this extra VLAN in the flowtable but skip it on egress.
--- include/linux/netdevice.h | 1 + include/net/netfilter/nf_flow_table.h | 8 +++++--- net/bridge/br_device.c | 1 + net/bridge/br_vlan.c | 2 ++ net/netfilter/nf_flow_table_core.c | 2 ++ net/netfilter/nf_flow_table_offload.c | 6 +++++- net/netfilter/nft_flow_offload.c | 5 +++++ 7 files changed, 21 insertions(+), 4 deletions(-)
include/linux/netdevice.h +1 -0
@@ -853,6 +853,7 @@ struct net_device_path {DEV_PATH_BR_VLAN_KEEP ,DEV_PATH_BR_VLAN_TAG ,DEV_PATH_BR_VLAN_UNTAG , +DEV_PATH_BR_VLAN_UNTAG_HW , } vlan_mode;u16 vlan_id;__be16 vlan_proto;
include/net/netfilter/nf_flow_table.h +5 -3
@@ -123,9 +123,10 @@ struct flow_offload_tuple {/* All members above are keys for lookups, see flow_offload_hash(). */ struct { } __hash; - u8 dir:4, + u8 dir:2, xmit_type:2, - encap_num:2; + encap_num:2, + in_vlan_ingress:2;u16 mtu;union {struct dst_entry *dst_cache;
@@ -185,7 +186,8 @@ struct nf_flow_route {u16 id;__be16 proto; } encap[NF_FLOW_TABLE_ENCAP_MAX ]; -u8 num_encaps; + u8 num_encaps:2, + ingress_vlans:2; } in;struct {u32 ifindex;
net/bridge/br_device.c +1 -0
@@ -422,6 +422,7 @@ static int br_fill_forward_path(struct net_device_path_ctx *ctx, ctx->vlan[ctx->num_vlans].proto = path->bridge.vlan_proto; ctx->num_vlans++;break ; +case DEV_PATH_BR_VLAN_UNTAG_HW :case DEV_PATH_BR_VLAN_UNTAG : ctx->num_vlans--;break ;
net/bridge/br_vlan.c +2 -0
@@ -1386,6 +1386,8 @@ int br_vlan_fill_forward_path_mode(struct net_bridge *br,if (path->bridge.vlan_mode ==DEV_PATH_BR_VLAN_TAG ) path->bridge.vlan_mode =DEV_PATH_BR_VLAN_KEEP ; +else if (v->priv_flags &BR_VLFLAG_ADDED_BY_SWITCHDEV ) + path->bridge.vlan_mode =DEV_PATH_BR_VLAN_UNTAG_HW ;else path->bridge.vlan_mode =DEV_PATH_BR_VLAN_UNTAG ;
net/netfilter/nf_flow_table_core.c +2 -0
@@ -95,6 +95,8 @@ static int flow_offload_fill_route(struct flow_offload *flow,for (i = route->tuple[dir].in.num_encaps -1 ; i >=0 ; i--) { flow_tuple->encap[j].id = route->tuple[dir].in.encap[i].id; flow_tuple->encap[j].proto = route->tuple[dir].in.encap[i].proto; +if (route->tuple[dir].in.ingress_vlans &BIT (i)) + flow_tuple->in_vlan_ingress |=BIT (j); j++; } flow_tuple->encap_num = route->tuple[dir].in.num_encaps;
net/netfilter/nf_flow_table_offload.c +5 -1
@@ -592,8 +592,12 @@ nf_flow_rule_route_common(struct net *net, const struct flow_offload *flow, other_tuple = &flow->tuplehash[!dir].tuple;for (i =0 ; i < other_tuple->encap_num; i++) { -struct flow_action_entry *entry =flow_action_entry_next (flow_rule); +struct flow_action_entry *entry; +if (other_tuple->in_vlan_ingress &BIT (i)) +continue ; + + entry =flow_action_entry_next (flow_rule); entry->id =FLOW_ACTION_VLAN_PUSH ; entry->vlan.vid = other_tuple->encap[i].id; entry->vlan.proto = other_tuple->encap[i].proto;
net/netfilter/nft_flow_offload.c +5 -0
@@ -72,6 +72,7 @@ struct nft_forward_info {__be16 proto; } encap[NF_FLOW_TABLE_ENCAP_MAX ];u8 num_encaps; +u8 ingress_vlans;u8 h_source[ETH_ALEN ];u8 h_dest[ETH_ALEN ];enum flow_offload_xmit_type xmit_type;
@@ -130,6 +131,9 @@ static void nft_dev_path_info(const struct net_device_path_stack *stack,memcpy (info->h_source, path->dev->dev_addr,ETH_ALEN );switch (path->bridge.vlan_mode) { +case DEV_PATH_BR_VLAN_UNTAG_HW : + info->ingress_vlans |=BIT (info->num_encaps -1 ); +break ;case DEV_PATH_BR_VLAN_TAG : info->encap[info->num_encaps].id = path->bridge.vlan_id; info->encap[info->num_encaps].proto = path->bridge.vlan_proto;
@@ -198,6 +202,7 @@ static void nft_dev_forward_path(struct nf_flow_route *route, route->tuple[!dir].in.encap[i].proto = info.encap[i].proto; } route->tuple[!dir].in.num_encaps = info.num_encaps; + route->tuple[!dir].in.ingress_vlans = info.ingress_vlans;if (info.xmit_type ==FLOW_OFFLOAD_XMIT_DIRECT ) {memcpy (route->tuple[dir].out.h_source, info.h_source,ETH_ALEN );
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerPATCH 18/23 net: flow_offload: add FLOW_ACTION_PPPOE_PUSH
In reply to Pablo Neira AyusoAdd an action to represent the PPPoE hardware offload support that includes the session ID.
--- include/net/flow_offload.h | 4 ++++ 1 file changed, 4 insertions(+)
include/net/flow_offload.h +4 -0
@@ -147,6 +147,7 @@ enum flow_action_id {FLOW_ACTION_MPLS_POP ,FLOW_ACTION_MPLS_MANGLE ,FLOW_ACTION_GATE , +FLOW_ACTION_PPPOE_PUSH , NUM_FLOW_ACTIONS, };
@@ -272,6 +273,9 @@ struct flow_action_entry {u32 num_entries;struct action_gate_entry *entries; } gate; +struct {/* FLOW_ACTION_PPPOE_PUSH */ +u16 sid; + } pppoe; };struct flow_action_cookie *cookie;/* user defined action cookie */ };
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerPATCH 19/23 netfilter: flowtable: support for FLOW_ACTION_PPPOE_PUSH
In reply to Pablo Neira AyusoAdd a PPPoE push action if layer 2 protocol is ETH_P_PPP_SES to add PPPoE flowtable hardware offload support.
--- net/netfilter/nf_flow_table_offload.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
net/netfilter/nf_flow_table_offload.c +12 -3
@@ -598,9 +598,18 @@ nf_flow_rule_route_common(struct net *net, const struct flow_offload *flow,continue ; entry =flow_action_entry_next (flow_rule); - entry->id =FLOW_ACTION_VLAN_PUSH ; - entry->vlan.vid = other_tuple->encap[i].id; - entry->vlan.proto = other_tuple->encap[i].proto; + +switch (other_tuple->encap[i].proto) { +case htons (ETH_P_PPP_SES ): + entry->id =FLOW_ACTION_PPPOE_PUSH ; + entry->pppoe.sid = other_tuple->encap[i].id; +break ; +case htons (ETH_P_8021Q ): + entry->id =FLOW_ACTION_VLAN_PUSH ; + entry->vlan.vid = other_tuple->encap[i].id; + entry->vlan.proto = other_tuple->encap[i].proto; +break ; + } }return 0 ;
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerPATCH 20/23 dsa: slave: add support for TC_SETUP_FT
In reply to Pablo Neira AyusoThe dsa infrastructure provides a well-defined hierarchy of devices, pass up the call to set up the flow block to the master device. From the software dataplane, the netfilter infrastructure uses the dsa slave devices to refer to the input and output device for the given skbuff. Similarly, the flowtable definition in the ruleset refers to the dsa slave port devices.
This patch adds the glue code to call ndo_setup_tc with TC_SETUP_FT with the master device via the dsa slave devices.
--- net/dsa/slave.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-)
net/dsa/slave.c +19 -1
@@ -1278,14 +1278,32 @@ static int dsa_slave_setup_tc_block(struct net_device *dev, } } +static int dsa_slave_setup_ft_block (struct dsa_switch *ds,int port, +void *type_data) +{ +struct dsa_port *cpu_dp =dsa_to_port (ds, port)->cpu_dp; +struct net_device *master = cpu_dp->master; + +if (!master->netdev_ops->ndo_setup_tc) +return -EOPNOTSUPP ; + +return master->netdev_ops->ndo_setup_tc (master,TC_SETUP_FT , type_data); +} +static int dsa_slave_setup_tc (struct net_device *dev,enum tc_setup_type type,void *type_data) {struct dsa_port *dp =dsa_slave_to_port (dev);struct dsa_switch *ds = dp->ds; -if (type ==TC_SETUP_BLOCK ) +switch (type) { +case TC_SETUP_BLOCK :return dsa_slave_setup_tc_block (dev, type_data); +case TC_SETUP_FT : +return dsa_slave_setup_ft_block (ds, dp->index, type_data); +default : +break ; + }if (!ds->ops->port_setup_tc)return -EOPNOTSUPP ;
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerPATCH 21/23 net: ethernet: mtk_eth_soc: add support for initializing the PPE
In reply to Pablo Neira AyusoFrom: Felix Fietkau <[email protected]>
The PPE (packet processing engine) is used to offload NAT/routed or even bridged flows. This patch brings up the PPE and uses it to get a packet hash. It also contains some functionality that will be used to bring up flow offloading.
--- drivers/net/ethernet/mediatek/Makefile | 2 +- drivers/net/ethernet/mediatek/mtk_eth_soc.c | 21 +- drivers/net/ethernet/mediatek/mtk_eth_soc.h | 11 + drivers/net/ethernet/mediatek/mtk_ppe.c | 511 ++++++++++++++++++ drivers/net/ethernet/mediatek/mtk_ppe.h | 287 ++++++++++ .../net/ethernet/mediatek/mtk_ppe_debugfs.c | 217 ++++++++ drivers/net/ethernet/mediatek/mtk_ppe_regs.h | 144 +++++ 7 files changed, 1190 insertions(+), 3 deletions(-) create mode 100644 drivers/net/ethernet/mediatek/mtk_ppe.c create mode 100644 drivers/net/ethernet/mediatek/mtk_ppe.h create mode 100644 drivers/net/ethernet/mediatek/mtk_ppe_debugfs.c create mode 100644 drivers/net/ethernet/mediatek/mtk_ppe_regs.h
drivers/net/ethernet/mediatek/Makefile +1 -1
@@ -4,5 +4,5 @@ # obj-$(CONFIG_NET_MEDIATEK_SOC) += mtk_eth.o -mtk_eth-y := mtk_eth_soc.o mtk_sgmii.o mtk_eth_path.o +mtk_eth-y := mtk_eth_soc.o mtk_sgmii.o mtk_eth_path.o mtk_ppe.o mtk_ppe_debugfs.o obj-$(CONFIG_NET_MEDIATEK_STAR_EMAC) += mtk_star_emac.o
drivers/net/ethernet/mediatek/mtk_eth_soc.c +19 -2
@@ -2255,12 +2255,17 @@ static int mtk_open(struct net_device *dev)/* we run 2 netdevs on the same dma ring so we only bring it up once */ if (!refcount_read (ð->dma_refcnt)) { -int err =mtk_start_dma (eth); +u32 gdm_config =MTK_GDMA_TO_PDMA ; +int err; + err =mtk_start_dma (eth);if (err)return err; -mtk_gdm_config (eth,MTK_GDMA_TO_PDMA ); +if (eth->soc->offload_version &&mtk_ppe_start (ð->ppe) ==0 ) + gdm_config =MTK_GDMA_TO_PPE ; + +mtk_gdm_config (eth, gdm_config);napi_enable (ð->tx_napi);napi_enable (ð->rx_napi);
@@ -2327,6 +2332,9 @@ static int mtk_stop(struct net_device *dev)mtk_dma_free (eth); +if (eth->soc->offload_version) +mtk_ppe_stop (ð->ppe); +return 0 ; }
@@ -3088,6 +3096,13 @@ static int mtk_probe(struct platform_device *pdev) goto err_free_dev; } +if (eth->soc->offload_version) { + err =mtk_ppe_init (ð->ppe, eth->dev, + eth->base +MTK_ETH_PPE_BASE ,2 ); +if (err) + goto err_free_dev; + } +for (i =0 ; i <MTK_MAX_DEVS ; i++) {if (!eth->netdev[i])continue ;
@@ -3162,6 +3177,7 @@ static const struct mtk_soc_data mt7621_data = { .hw_features = MTK_HW_FEATURES, .required_clks = MT7621_CLKS_BITMAP, .required_pctl = false, + .offload_version = 2, };static const struct mtk_soc_data mt7622_data = {
@@ -3170,6 +3186,7 @@ static const struct mtk_soc_data mt7622_data = { .hw_features = MTK_HW_FEATURES, .required_clks = MT7622_CLKS_BITMAP, .required_pctl = false, + .offload_version = 2, };static const struct mtk_soc_data mt7623_data = {
drivers/net/ethernet/mediatek/mtk_eth_soc.h +11 -0
@@ -15,6 +15,7 @@#include <linux/u64_stats_sync.h> #include <linux/refcount.h> #include <linux/phylink.h> +#include "mtk_ppe.h" #define MTK_QDMA_PAGE_SIZE 2048#define MTK_MAX_RX_LENGTH 1536
@@ -86,6 +87,7 @@#define MTK_GDMA_TCS_EN BIT(21)#define MTK_GDMA_UCS_EN BIT(20)#define MTK_GDMA_TO_PDMA 0x0 +#define MTK_GDMA_TO_PPE 0x4444#define MTK_GDMA_DROP_ALL 0x7777/* Unicast Filter MAC Address Register - Low */
@@ -300,6 +302,12 @@/* QDMA descriptor rxd3 */ #define RX_DMA_VID (_x) ((_x) & 0xfff) +/* QDMA descriptor rxd4 */ +#define MTK_RXD4_FOE_ENTRY GENMASK(13, 0) +#define MTK_RXD4_PPE_CPU_REASON GENMASK(18, 14) +#define MTK_RXD4_SRC_PORT GENMASK(21, 19) +#define MTK_RXD4_ALG GENMASK(31, 22) +/* QDMA descriptor rxd4 */ #define RX_DMA_L4_VALID BIT(24)#define RX_DMA_L4_VALID_PDMA BIT(30)/* when PDMA is used */
@@ -802,6 +810,7 @@ struct mtk_soc_data {u32 caps;u32 required_clks;bool required_pctl; +u8 offload_version;netdev_features_t hw_features; };
@@ -901,6 +910,8 @@ struct mtk_eth {u32 tx_int_status_reg;u32 rx_dma_l4_valid;int ip_align; + +struct mtk_ppe ppe; };/* struct mtk_mac - the structure that holds the info about the MACs of the
drivers/net/ethernet/mediatek/mtk_ppe.c new file +511 -0
511 lines not on this page · raw message
drivers/net/ethernet/mediatek/mtk_ppe.h new file +287 -0
287 lines not on this page · raw message
drivers/net/ethernet/mediatek/mtk_ppe_debugfs.c new file +217 -0
217 lines not on this page · raw message
drivers/net/ethernet/mediatek/mtk_ppe_regs.h new file +144 -0
144 lines not on this page · raw message
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerPATCH 22/23 net: ethernet: mtk_eth_soc: add flow offloading support
In reply to Pablo Neira AyusoFrom: Felix Fietkau <[email protected]>
This adds support for offloading IPv4 routed flows, including SNAT/DNAT, one VLAN, PPPoE and DSA.
--- drivers/net/ethernet/mediatek/Makefile | 2 +- drivers/net/ethernet/mediatek/mtk_eth_soc.c | 5 + drivers/net/ethernet/mediatek/mtk_eth_soc.h | 10 +- .../net/ethernet/mediatek/mtk_ppe_offload.c | 485 ++++++++++++++++++ 4 files changed, 500 insertions(+), 2 deletions(-) create mode 100644 drivers/net/ethernet/mediatek/mtk_ppe_offload.c
drivers/net/ethernet/mediatek/Makefile +1 -1
@@ -4,5 +4,5 @@ # obj-$(CONFIG_NET_MEDIATEK_SOC) += mtk_eth.o -mtk_eth-y := mtk_eth_soc.o mtk_sgmii.o mtk_eth_path.o mtk_ppe.o mtk_ppe_debugfs.o +mtk_eth-y := mtk_eth_soc.o mtk_sgmii.o mtk_eth_path.o mtk_ppe.o mtk_ppe_debugfs.o mtk_ppe_offload.o obj-$(CONFIG_NET_MEDIATEK_STAR_EMAC) += mtk_star_emac.o
drivers/net/ethernet/mediatek/mtk_eth_soc.c +5 -0
@@ -2840,6 +2840,7 @@ static const struct net_device_ops mtk_netdev_ops = {#ifdef CONFIG_NET_POLL_CONTROLLER .ndo_poll_controller = mtk_poll_controller, #endif + .ndo_setup_tc = mtk_eth_setup_tc, };static int mtk_add_mac (struct mtk_eth *eth,struct device_node *np)
@@ -3101,6 +3102,10 @@ static int mtk_probe(struct platform_device *pdev) eth->base + MTK_ETH_PPE_BASE, 2);if (err) goto err_free_dev; + + err =mtk_eth_offload_init (eth); +if (err) + goto err_free_dev; }for (i =0 ; i <MTK_MAX_DEVS ; i++) {
drivers/net/ethernet/mediatek/mtk_eth_soc.h +9 -1
@@ -15,6 +15,7 @@#include <linux/u64_stats_sync.h> #include <linux/refcount.h> #include <linux/phylink.h> +#include <linux/rhashtable.h> #include "mtk_ppe.h" #define MTK_QDMA_PAGE_SIZE 2048
@@ -41,7 +42,8 @@ NETIF_F_HW_VLAN_CTAG_RX | \ NETIF_F_SG | NETIF_F_TSO | \ NETIF_F_TSO6 | \ - NETIF_F_IPV6_CSUM) + NETIF_F_IPV6_CSUM |\ + NETIF_F_HW_TC)#define MTK_HW_FEATURES_MT7628 (NETIF_F_SG | NETIF_F_RXCSUM)#define NEXT_DESP_IDX (X ,Y ) (((X) + 1) & ((Y) - 1))
@@ -912,6 +914,7 @@ struct mtk_eth {int ip_align;struct mtk_ppe ppe; +struct rhashtable flow_table; };/* struct mtk_mac - the structure that holds the info about the MACs of the
@@ -956,4 +959,9 @@ int mtk_gmac_sgmii_path_setup(struct mtk_eth *eth, int mac_id);int mtk_gmac_gephy_path_setup (struct mtk_eth *eth,int mac_id);int mtk_gmac_rgmii_path_setup (struct mtk_eth *eth,int mac_id); +int mtk_eth_offload_init (struct mtk_eth *eth); +int mtk_eth_setup_tc (struct net_device *dev,enum tc_setup_type type, +void *type_data); + +#endif /* MTK_ETH_H */
drivers/net/ethernet/mediatek/mtk_ppe_offload.c new file +485 -0
485 lines not on this page · raw message
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerPATCH 23/23 net: ethernet: mtk_eth_soc: fix parsing packets in GDM
In reply to Pablo Neira AyusoFrom: Felix Fietkau <[email protected]>
When using DSA, set the special tag in GDM ingress control to allow the MAC to parse packets properly earlier. This affects rx DMA source port reporting.
--- drivers/net/ethernet/mediatek/mtk_eth_soc.c | 15 +++++++++------ drivers/net/ethernet/mediatek/mtk_eth_soc.h | 2 ++ 2 files changed, 11 insertions(+), 6 deletions(-)
drivers/net/ethernet/mediatek/mtk_eth_soc.c +9 -6
@@ -19,6 +19,7 @@#include <linux/interrupt.h> #include <linux/pinctrl/devinfo.h> #include <linux/phylink.h> +#include <net/dsa.h> #include "mtk_eth_soc.h"
@@ -1264,13 +1265,12 @@ static int mtk_poll_rx(struct napi_struct *napi, int budget,break ;/* find out which mac the packet come from. values start at 1 */ -if (MTK_HAS_CAPS (eth->soc->caps,MTK_SOC_MT7628 )) { +if (MTK_HAS_CAPS (eth->soc->caps,MTK_SOC_MT7628 ) || + (trxd.rxd4 &RX_DMA_SPECIAL_TAG )) mac =0 ; - }else { - mac = (trxd.rxd4 >>RX_DMA_FPORT_SHIFT ) & -RX_DMA_FPORT_MASK ; - mac--; - } +else + mac = ((trxd.rxd4 >>RX_DMA_FPORT_SHIFT ) & +RX_DMA_FPORT_MASK ) -1 ;if (unlikely (mac <0 || mac >=MTK_MAC_COUNT || !eth->netdev[mac]))
@@ -2233,6 +2233,9 @@ static void mtk_gdm_config(struct mtk_eth *eth, u32 config) val |= config; +if (!i && eth->netdev[0 ] &&netdev_uses_dsa (eth->netdev[0 ])) + val |=MTK_GDMA_SPECIAL_TAG ; +mtk_w32 (eth, val,MTK_GDMA_FWD_CFG (i)); }/* Reset and enable PSE */
drivers/net/ethernet/mediatek/mtk_eth_soc.h +2 -0
@@ -85,6 +85,7 @@/* GDM Exgress Control Register */ #define MTK_GDMA_FWD_CFG (x) (0x500 + (x * 0x1000)) +#define MTK_GDMA_SPECIAL_TAG BIT(24)#define MTK_GDMA_ICS_EN BIT(22)#define MTK_GDMA_TCS_EN BIT(21)#define MTK_GDMA_UCS_EN BIT(20)
@@ -315,6 +316,7 @@#define RX_DMA_L4_VALID_PDMA BIT(30)/* when PDMA is used */ #define RX_DMA_FPORT_SHIFT 19#define RX_DMA_FPORT_MASK 0x7 +#define RX_DMA_SPECIAL_TAG BIT(22)/* PHY Indirect Access Control registers */ #define MTK_PHY_IAC 0x10004
Signature · 1 line
2.20.1
Felix Fietkau
maintainerRe: [PATCH net-next 23/23] net: ethernet: mtk_eth_soc: fix parsing packets in GDM
Quoted 11 lines · Pablo Neira Ayuso
From: Felix Fietkau <[email protected]>
When using DSA, set the special tag in GDM ingress control to allow the MAC to parse packets properly earlier. This affects rx DMA source port reporting.
Signed-off-by Felix Fietkau <[email protected]>Signed-off-by Pablo Neira Ayuso <[email protected]>---
In order to avoid regressions within the series, this patch needs to come before patch 21
- Felix
Jakub Kicinski
maintainerQuoted 27 lines · On Thu, 11 Mar 2021 01:35:41 +0100 Pablo Neira Ayuso wrote:
The following patchset augments the Netfilter flowtable fastpath to support for network topologies that combine IP forwarding, bridge, classic VLAN devices, bridge VLAN filtering, DSA and PPPoE. This includes support for the flowtable software and hardware datapaths.
The following pictures provides an example scenario:
fast path! .------------------------. / \ | IP forwarding | | / \ \/ | br0 wan ..... eth0 . / \ host C -> veth1 veth2 . switch/router . . eth0 host AThe bridge master device 'br0' has an IP address and a DHCP server is also assumed to be running to provide connectivity to host A which reaches the Internet through 'br0' as default gateway. Then, packet enters the IP forwarding path and Netfilter is used to NAT the packets before they leave through the wan device.
Quoted 4 lines
The general idea is to accelerate forwarding by building a fast path that takes packets from the ingress path of the bridge port and place them in the egress path of the wan device (and vice versa). Hence, skipping the classic bridge and IP stack paths.
And how did you solve the invalidation problem?
Pablo Neira Ayuso
maintainerQuoted 28 lines · Jakub Kicinski
Quoted 27 lines · On Thu, 11 Mar 2021 01:35:41 +0100 Pablo Neira Ayuso wrote:
The following patchset augments the Netfilter flowtable fastpath to support for network topologies that combine IP forwarding, bridge, classic VLAN devices, bridge VLAN filtering, DSA and PPPoE. This includes support for the flowtable software and hardware datapaths.
The following pictures provides an example scenario:
fast path! .------------------------. / \ | IP forwarding | | / \ \/ | br0 wan ..... eth0 . / \ host C -> veth1 veth2 . switch/router . . eth0 host AThe bridge master device 'br0' has an IP address and a DHCP server is also assumed to be running to provide connectivity to host A which reaches the Internet through 'br0' as default gateway. Then, packet enters the IP forwarding path and Netfilter is used to NAT the packets before they leave through the wan device.
Quoted 6 lines
Quoted 4 lines
The general idea is to accelerate forwarding by building a fast path that takes packets from the ingress path of the bridge port and place them in the egress path of the wan device (and vice versa). Hence, skipping the classic bridge and IP stack paths.
And how did you solve the invalidation problem?
The flowtable fast datapath is entirely optional, users turn it on via ruleset. Users also have full control on what flows are added to the flowtable datapath and _when_ those flows are added to the flowtable datapath, *it's highly configurable*. The main concern about the previous caches that have were removed from the kernel (such as the routing table cache) are that:
1) Those mechanisms were enabled by default.
2) Configurability was completely lacking, you can just enable/disable the cache.
If a user consider that the invalidation problem is a real concern, then they can just opt out from adopting the flowtable solution by now. Cache invalidation is not a requirement in the scenarios where this is planned to be deployed at this stage.
I can extend the documentation to describe the invalidation problem in a follow up patch and to explicit state that this is not addressed at this stage.
David Miller
maintainerFrom: Pablo Neira Ayuso <[email protected]>
Date: Thu, 11 Mar 2021 22:45:05 +0100
Quoted 4 lines
I can extend the documentation to describe the invalidation problem in a follow up patch and to explicit state that this is not addressed at this stage.
Please do, thank you.