|
| 1 | +// SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and IronCore contributors |
| 2 | +// SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +#include "rte_flow/dp_rte_flow_isolation.h" |
| 5 | + |
| 6 | +#include "dp_error.h" |
| 7 | +#include "dp_log.h" |
| 8 | +#include "rte_flow/dp_rte_flow_helpers.h" |
| 9 | +#include "dp_conf.h" |
| 10 | +#include "monitoring/dp_monitoring.h" |
| 11 | + |
| 12 | +static const struct rte_flow_attr dp_flow_attr_prio_ingress = { |
| 13 | + .group = 0, |
| 14 | + .priority = 1, |
| 15 | + .ingress = 1, |
| 16 | + .egress = 0, |
| 17 | + .transfer = 0, |
| 18 | +}; |
| 19 | + |
| 20 | + |
| 21 | +int dp_install_isolated_mode(uint16_t port_id) |
| 22 | +{ |
| 23 | + struct rte_flow_item_eth eth_spec; // #1 |
| 24 | + struct rte_flow_item_ipv6 ipv6_spec; // #2 |
| 25 | + struct rte_flow_item pattern[3]; // + end |
| 26 | + int pattern_cnt = 0; |
| 27 | + struct rte_flow_action_queue queue_action; // #1 |
| 28 | + struct rte_flow_action action[2]; // + end |
| 29 | + int action_cnt = 0; |
| 30 | + union dp_ipv6 ul_addr6; |
| 31 | + |
| 32 | + ul_addr6._ul.prefix = dp_conf_get_underlay_ip()->_prefix; |
| 33 | + ul_addr6._ul.kernel = htons(DP_UNDERLAY_KERNEL_BYTES); |
| 34 | + |
| 35 | + // create match pattern: IP in IPv6 tunnel packets |
| 36 | + dp_set_eth_flow_item(&pattern[pattern_cnt++], ð_spec, htons(RTE_ETHER_TYPE_IPV6)); |
| 37 | + dp_set_ipv6_dst_pfx68_flow_item(&pattern[pattern_cnt++], &ipv6_spec, &ul_addr6); |
| 38 | + dp_set_end_flow_item(&pattern[pattern_cnt++]); |
| 39 | + |
| 40 | + // create flow action: allow packets to enter dp-service packet queue |
| 41 | + dp_set_redirect_queue_action(&action[action_cnt++], &queue_action, 0); |
| 42 | + dp_set_end_action(&action[action_cnt++]); |
| 43 | + |
| 44 | + if (!dp_install_rte_flow(port_id, &dp_flow_attr_prio_ingress, pattern, action)) |
| 45 | + return DP_ERROR; |
| 46 | + |
| 47 | + DPS_LOG_DEBUG("Installed IPIP isolation flow rule", DP_LOG_PORTID(port_id)); |
| 48 | + return DP_OK; |
| 49 | +} |
| 50 | + |
0 commit comments