Commit 2d93c30c authored by David S. Miller's avatar David S. Miller

Merge branch 'mlxsw-redirection'

Petr Machata says:

====================
mlxsw: Support traffic redirection from a locked bridge port

Ido Schimmel writes:

It is possible to add a filter that redirects traffic from the ingress
of a bridge port that is locked (i.e., performs security / SMAC lookup)
and has learning enabled. For example:

 # ip link add name br0 type bridge
 # ip link set dev swp1 master br0
 # bridge link set dev swp1 learning on locked on mab on
 # tc qdisc add dev swp1 clsact
 # tc filter add dev swp1 ingress pref 1 proto ip flower skip_sw src_ip 192.0.2.1 action mirred egress redirect dev swp2

In the kernel's Rx path, this filter is evaluated before the Rx handler
of the bridge, which means that redirected traffic should not be
affected by bridge port configuration such as learning.

However, the hardware data path is a bit different and the redirect
action (FORWARDING_ACTION in hardware) merely attaches a pointer to the
packet, which is later used by the L2 lookup stage to understand how to
forward the packet. Between both stages - ingress ACL and L2 lookup -
learning and security lookup are performed, which means that redirected
traffic is affected by bridge port configuration, unlike in the kernel's
data path.

The learning discrepancy was handled in commit 577fa14d ("mlxsw:
spectrum: Do not process learned records with a dummy FID") by simply
ignoring learning notifications generated by the redirected traffic. A
similar solution is not possible for the security / SMAC lookup since
- unlike learning - the CPU is not involved and packets that failed the
lookup are dropped by the device.

Instead, solve this by prepending the ignore action to the redirect
action and use it to instruct the device to disable both learning and
the security / SMAC lookup for redirected traffic.

Patch #1 adds the ignore action.

Patch #2 prepends the action to the redirect action in flower offload
code.

Patch #3 removes the workaround in commit 577fa14d ("mlxsw:
spectrum: Do not process learned records with a dummy FID") since it is
no longer needed.

Patch #4 adds a test case.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 58c1e0ba 38c43a1c
......@@ -1887,6 +1887,46 @@ int mlxsw_afa_block_append_fid_set(struct mlxsw_afa_block *block, u16 fid,
}
EXPORT_SYMBOL(mlxsw_afa_block_append_fid_set);
/* Ignore Action
* -------------
* The ignore action is used to ignore basic switching functions such as
* learning on a per-packet basis.
*/
#define MLXSW_AFA_IGNORE_CODE 0x0F
#define MLXSW_AFA_IGNORE_SIZE 1
/* afa_ignore_disable_learning
* Disable learning on ingress.
*/
MLXSW_ITEM32(afa, ignore, disable_learning, 0x00, 29, 1);
/* afa_ignore_disable_security
* Disable security lookup on ingress.
* Reserved when Spectrum-1.
*/
MLXSW_ITEM32(afa, ignore, disable_security, 0x00, 28, 1);
static void mlxsw_afa_ignore_pack(char *payload, bool disable_learning,
bool disable_security)
{
mlxsw_afa_ignore_disable_learning_set(payload, disable_learning);
mlxsw_afa_ignore_disable_security_set(payload, disable_security);
}
int mlxsw_afa_block_append_ignore(struct mlxsw_afa_block *block,
bool disable_learning, bool disable_security)
{
char *act = mlxsw_afa_block_append_action(block, MLXSW_AFA_IGNORE_CODE,
MLXSW_AFA_IGNORE_SIZE);
if (IS_ERR(act))
return PTR_ERR(act);
mlxsw_afa_ignore_pack(act, disable_learning, disable_security);
return 0;
}
EXPORT_SYMBOL(mlxsw_afa_block_append_ignore);
/* MC Routing Action
* -----------------
* The Multicast router action. Can be used by RMFT_V2 - Router Multicast
......
......@@ -89,6 +89,8 @@ int mlxsw_afa_block_append_counter(struct mlxsw_afa_block *block,
struct netlink_ext_ack *extack);
int mlxsw_afa_block_append_fid_set(struct mlxsw_afa_block *block, u16 fid,
struct netlink_ext_ack *extack);
int mlxsw_afa_block_append_ignore(struct mlxsw_afa_block *block,
bool disable_learning, bool disable_security);
int mlxsw_afa_block_append_mcrouter(struct mlxsw_afa_block *block,
u16 expected_irif, u16 min_mtu,
bool rmid_valid, u32 kvdl_index);
......
......@@ -1050,6 +1050,9 @@ int mlxsw_sp_acl_rulei_act_count(struct mlxsw_sp *mlxsw_sp,
int mlxsw_sp_acl_rulei_act_fid_set(struct mlxsw_sp *mlxsw_sp,
struct mlxsw_sp_acl_rule_info *rulei,
u16 fid, struct netlink_ext_ack *extack);
int mlxsw_sp_acl_rulei_act_ignore(struct mlxsw_sp *mlxsw_sp,
struct mlxsw_sp_acl_rule_info *rulei,
bool disable_learning, bool disable_security);
int mlxsw_sp_acl_rulei_act_sample(struct mlxsw_sp *mlxsw_sp,
struct mlxsw_sp_acl_rule_info *rulei,
struct mlxsw_sp_flow_block *block,
......@@ -1268,7 +1271,6 @@ int mlxsw_sp_setup_tc_block_qevent_mark(struct mlxsw_sp_port *mlxsw_sp_port,
struct flow_block_offload *f);
/* spectrum_fid.c */
bool mlxsw_sp_fid_is_dummy(struct mlxsw_sp *mlxsw_sp, u16 fid_index);
struct mlxsw_sp_fid *mlxsw_sp_fid_lookup_by_index(struct mlxsw_sp *mlxsw_sp,
u16 fid_index);
int mlxsw_sp_fid_nve_ifindex(const struct mlxsw_sp_fid *fid, int *nve_ifindex);
......
......@@ -775,6 +775,15 @@ int mlxsw_sp_acl_rulei_act_fid_set(struct mlxsw_sp *mlxsw_sp,
return mlxsw_afa_block_append_fid_set(rulei->act_block, fid, extack);
}
int mlxsw_sp_acl_rulei_act_ignore(struct mlxsw_sp *mlxsw_sp,
struct mlxsw_sp_acl_rule_info *rulei,
bool disable_learning, bool disable_security)
{
return mlxsw_afa_block_append_ignore(rulei->act_block,
disable_learning,
disable_security);
}
int mlxsw_sp_acl_rulei_act_sample(struct mlxsw_sp *mlxsw_sp,
struct mlxsw_sp_acl_rule_info *rulei,
struct mlxsw_sp_flow_block *block,
......
......@@ -137,16 +137,6 @@ static const int *mlxsw_sp_packet_type_sfgc_types[] = {
[MLXSW_SP_FLOOD_TYPE_MC] = mlxsw_sp_sfgc_mc_packet_types,
};
bool mlxsw_sp_fid_is_dummy(struct mlxsw_sp *mlxsw_sp, u16 fid_index)
{
enum mlxsw_sp_fid_type fid_type = MLXSW_SP_FID_TYPE_DUMMY;
struct mlxsw_sp_fid_family *fid_family;
fid_family = mlxsw_sp->fid_core->fid_family_arr[fid_type];
return fid_family->start_index == fid_index;
}
struct mlxsw_sp_fid *mlxsw_sp_fid_lookup_by_index(struct mlxsw_sp *mlxsw_sp,
u16 fid_index)
{
......
......@@ -160,6 +160,16 @@ static int mlxsw_sp_flower_parse_actions(struct mlxsw_sp *mlxsw_sp,
*/
rulei->egress_bind_blocker = 1;
/* Ignore learning and security lookup as redirection
* using ingress filters happens before the bridge.
*/
err = mlxsw_sp_acl_rulei_act_ignore(mlxsw_sp, rulei,
true, true);
if (err) {
NL_SET_ERR_MSG_MOD(extack, "Cannot append ignore action");
return err;
}
fid = mlxsw_sp_acl_dummy_fid(mlxsw_sp);
fid_index = mlxsw_sp_fid_index(fid);
err = mlxsw_sp_acl_rulei_act_fid_set(mlxsw_sp, rulei,
......
......@@ -3066,9 +3066,6 @@ static void mlxsw_sp_fdb_notify_mac_process(struct mlxsw_sp *mlxsw_sp,
goto just_remove;
}
if (mlxsw_sp_fid_is_dummy(mlxsw_sp, fid))
goto just_remove;
mlxsw_sp_port_vlan = mlxsw_sp_port_vlan_find_by_fid(mlxsw_sp_port, fid);
if (!mlxsw_sp_port_vlan) {
netdev_err(mlxsw_sp_port->dev, "Failed to find a matching {Port, VID} following FDB notification\n");
......@@ -3136,9 +3133,6 @@ static void mlxsw_sp_fdb_notify_mac_lag_process(struct mlxsw_sp *mlxsw_sp,
goto just_remove;
}
if (mlxsw_sp_fid_is_dummy(mlxsw_sp, fid))
goto just_remove;
mlxsw_sp_port_vlan = mlxsw_sp_port_vlan_find_by_fid(mlxsw_sp_port, fid);
if (!mlxsw_sp_port_vlan) {
netdev_err(mlxsw_sp_port->dev, "Failed to find a matching {Port, VID} following FDB notification\n");
......
......@@ -9,6 +9,7 @@ ALL_TESTS="
locked_port_mab_roam
locked_port_mab_config
locked_port_mab_flush
locked_port_mab_redirect
"
NUM_NETIFS=4
......@@ -319,6 +320,41 @@ locked_port_mab_flush()
log_test "Locked port MAB FDB flush"
}
# Check that traffic can be redirected from a locked bridge port and that it
# does not create locked FDB entries.
locked_port_mab_redirect()
{
RET=0
check_port_mab_support || return 0
bridge link set dev $swp1 learning on locked on mab on
tc qdisc add dev $swp1 clsact
tc filter add dev $swp1 ingress protocol all pref 1 handle 101 flower \
action mirred egress redirect dev $swp2
ping_do $h1 192.0.2.2
check_err $? "Ping did not work with redirection"
bridge fdb get `mac_get $h1` br br0 vlan 1 2> /dev/null | \
grep "dev $swp1" | grep -q "locked"
check_fail $? "Locked entry created for redirected traffic"
tc filter del dev $swp1 ingress protocol all pref 1 handle 101 flower
ping_do $h1 192.0.2.2
check_fail $? "Ping worked without redirection"
bridge fdb get `mac_get $h1` br br0 vlan 1 2> /dev/null | \
grep "dev $swp1" | grep -q "locked"
check_err $? "Locked entry not created after deleting filter"
bridge fdb del `mac_get $h1` vlan 1 dev $swp1 master
tc qdisc del dev $swp1 clsact
bridge link set dev $swp1 learning off locked off mab off
log_test "Locked port MAB redirect"
}
trap cleanup EXIT
setup_prepare
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment