Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
unified var and func name for pkt capturing
Browse files Browse the repository at this point in the history
byteocean committed Oct 25, 2023
1 parent b40e8e0 commit 23d27f2
Showing 10 changed files with 49 additions and 54 deletions.
2 changes: 1 addition & 1 deletion include/grpc/dp_grpc_conv.h
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@ namespace GrpcConv
bool GrpcToDpFwallDirection(const TrafficDirection& grpc_dir, enum dp_fwall_direction *dp_dir);
bool GrpcToDpFwallPort(int32_t grpc_port, uint32_t *dp_port);

bool GrpcToDpCaptureInterfaceType(const CaptureInterfaceType& grpc_type, enum dpgrpc_capture_iface_type *dp_capture_iface_type);
bool GrpcToDpCaptureInterfaceType(const CaptureInterfaceType & grpc_type, enum dpgrpc_capture_iface_type *dp_capture_iface_type);
CaptureInterfaceType CaptureInterfaceTypeToGrpc(enum dpgrpc_capture_iface_type dp_capture_iface_type);

const char *Ipv4ToStr(uint32_t ipv4);
2 changes: 0 additions & 2 deletions include/monitoring/dp_monitoring.h
Original file line number Diff line number Diff line change
@@ -45,8 +45,6 @@ uint16_t dp_get_capture_udp_dst_port(void);
void dp_set_capture_enabled(bool enabled);

bool dp_get_capture_enabled(void);



#ifdef __cplusplus
}
2 changes: 1 addition & 1 deletion include/rte_flow/dp_rte_flow.h
Original file line number Diff line number Diff line change
@@ -33,7 +33,7 @@ extern "C"

enum {
DP_RTE_FLOW_DEFAULT_GROUP,
DP_RTE_FLOW_MONITORING_GROUP,
DP_RTE_FLOW_CAPTURE_GROUP,
DP_RTE_FLOW_VNET_GROUP,
};

10 changes: 5 additions & 5 deletions include/rte_flow/dp_rte_flow_init.h
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ extern "C" {
int dp_install_isolated_mode_ipip(int port_id, uint8_t proto_id);

int dp_install_jump_rule_in_default_group(uint16_t port_id, uint32_t group_id);
int dp_install_default_rule_in_monitoring_group(uint16_t port_id, bool is_on);
int dp_install_default_rule_in_capture_group(uint16_t port_id, bool is_on);


int dp_turn_on_offload_pkt_capture_on_single_iface(uint16_t port_id);
@@ -25,10 +25,10 @@ int dp_turn_off_offload_pkt_capture_on_all_ifaces(void);
int dp_destroy_default_flow(struct dp_port *port);

void dp_configure_packet_capture_action(uint8_t *encaped_mirror_hdr,
struct rte_flow_action_raw_encap *encap_action,
struct rte_flow_action_port_id *port_id_action,
struct rte_flow_action *sub_action,
uint32_t install_to_port);
struct rte_flow_action_raw_encap *encap_action,
struct rte_flow_action_port_id *port_id_action,
struct rte_flow_action *sub_action,
uint32_t install_to_port);

#ifdef ENABLE_VIRTSVC
int dp_install_isolated_mode_virtsvc(int port_id, uint8_t proto_id, const uint8_t svc_ipv6[16], uint16_t svc_port);
4 changes: 2 additions & 2 deletions src/dp_port.c
Original file line number Diff line number Diff line change
@@ -502,10 +502,10 @@ static int dp_install_pf_init_rte_rules(uint32_t port_id)
}

if (dp_conf_is_offload_enabled() && port_id == dp_port_get_pf0_id()) {
ret = dp_install_default_rule_in_monitoring_group(port_id, false);
ret = dp_install_default_rule_in_capture_group(port_id, false);

if (DP_FAILED(ret)) {
DPS_LOG_ERR("Cannot install default rule in monitoring group", DP_LOG_PORTID(port_id), DP_LOG_RET(ret));
DPS_LOG_ERR("Cannot install default rule in capturing group", DP_LOG_PORTID(port_id), DP_LOG_RET(ret));
return DP_ERROR;
}
}
4 changes: 2 additions & 2 deletions src/grpc/dp_async_grpc.cpp
Original file line number Diff line number Diff line change
@@ -568,13 +568,13 @@ const char* CaptureStartCall::FillRequest(struct dpgrpc_request* request)
return "Invalid udp_src_port";
if (request_.udp_dst_port() > UINT16_MAX)
return "Invalid udp_dst_port";

request->start_capture.udp_src_port = request_.udp_src_port();
request->start_capture.udp_dst_port = request_.udp_dst_port();

if (request_.interfaces_size() > DP_CAPTURE_MAX_PORT_NUM)
return "Too many interfaces to be captured";

request->start_capture.filled_interface_info_count = 0;
for (int i = 0; i < request_.interfaces_size(); ++i) {
if (!GrpcConv::GrpcToDpCaptureInterfaceType(request_.interfaces(i).interface_type(), &request->start_capture.interfaces[i].type)) {
8 changes: 3 additions & 5 deletions src/grpc/dp_grpc_impl.c
Original file line number Diff line number Diff line change
@@ -921,9 +921,8 @@ static int dp_process_capture_start(struct dp_grpc_responder *responder)
}

if (status != DP_GRPC_OK) {
if (DP_FAILED(dp_turn_off_offload_pkt_capture_on_all_ifaces())) {
if (DP_FAILED(dp_turn_off_offload_pkt_capture_on_all_ifaces()))
status = DP_GRPC_ERR_CAPTURE_INIT_CANNOT_ROLLBACK;
}
}

return status;
@@ -933,10 +932,9 @@ static int dp_process_capture_stop(struct dp_grpc_responder *responder)
{
struct dpgrpc_capture_stop *reply = dp_grpc_single_reply(responder);
int ret = dp_turn_off_offload_pkt_capture_on_all_ifaces();
if (DP_FAILED(ret)) {

if (DP_FAILED(ret))
return DP_GRPC_ERR_CAPTURE_CANNOT_STOP;
}

reply->port_cnt = ret;
return DP_GRPC_OK;
2 changes: 1 addition & 1 deletion src/monitoring/dp_graphtrace.c
Original file line number Diff line number Diff line change
@@ -78,7 +78,7 @@ static int dp_handle_graphtrace_stop(void)
_dp_graphtrace_enabled = false;
DPS_LOG_INFO("Graphtrace disabled");
}

return DP_OK;
}

35 changes: 17 additions & 18 deletions src/rte_flow/dp_rte_flow_init.c
Original file line number Diff line number Diff line change
@@ -27,10 +27,10 @@ static const struct rte_flow_attr dp_flow_attr_default_jump_ingress = {
.transfer = 1,
};

// it is used to install the flow capturing rule into the monitoring group
// it is used to install the flow capturing rule into the capturing group
// transfer flag is set to allow the port action
static const struct rte_flow_attr dp_flow_attr_default_monitoring_ingress = {
.group = DP_RTE_FLOW_MONITORING_GROUP,
static const struct rte_flow_attr dp_flow_attr_default_capture_ingress = {
.group = DP_RTE_FLOW_CAPTURE_GROUP,
.priority = 0,
.ingress = 0,
.egress = 0,
@@ -69,7 +69,7 @@ int dp_install_jump_rule_in_default_group(uint16_t port_id, uint32_t dst_group)
struct rte_flow_item pattern[2]; // first is a NULL ethernet header matching, second is the end
int pattern_cnt = 0;

// jump action from default group to monitoring group
// jump action from default group to capturing group
struct rte_flow_action_jump jump_action; // #1
struct rte_flow_action action[2]; // + end
int action_cnt = 0;
@@ -107,8 +107,8 @@ void dp_configure_packet_capture_action(uint8_t *encaped_mirror_hdr,
uint32_t install_to_port)
{
struct rte_ether_hdr *encap_eth_hdr = (struct rte_ether_hdr *)encaped_mirror_hdr;
struct rte_ipv6_hdr *new_ipv6_hdr = (struct rte_ipv6_hdr*)(&encaped_mirror_hdr[sizeof(struct rte_ether_hdr)]);
struct rte_udp_hdr *udp_hdr = (struct rte_udp_hdr*)(&encaped_mirror_hdr[sizeof(struct rte_ether_hdr) + sizeof(struct rte_ipv6_hdr)]);
struct rte_ipv6_hdr *new_ipv6_hdr = (struct rte_ipv6_hdr *)(&encaped_mirror_hdr[sizeof(struct rte_ether_hdr)]);
struct rte_udp_hdr *udp_hdr = (struct rte_udp_hdr *)(&encaped_mirror_hdr[sizeof(struct rte_ether_hdr) + sizeof(struct rte_ipv6_hdr)]);
int sub_action_cnt = 0;
// uint32_t dst_port = install_to_port == dp_port_get_pf1_id() ? dp_port_get_pf1_id() : dp_port_get_pf0_id();

@@ -120,7 +120,7 @@ void dp_configure_packet_capture_action(uint8_t *encaped_mirror_hdr,
rte_memcpy(new_ipv6_hdr->dst_addr, dp_get_capture_node_ipv6_addr(), sizeof(new_ipv6_hdr->dst_addr));
new_ipv6_hdr->vtc_flow = htonl(DP_IP6_VTC_FLOW);
new_ipv6_hdr->payload_len = 0;
new_ipv6_hdr->proto = DP_IP_PROTO_UDP;
new_ipv6_hdr->proto = DP_IP_PROTO_UDP;
new_ipv6_hdr->hop_limits = DP_IP6_HOP_LIMIT;


@@ -134,7 +134,7 @@ void dp_configure_packet_capture_action(uint8_t *encaped_mirror_hdr,
}


int dp_install_default_rule_in_monitoring_group(uint16_t port_id, bool is_on)
int dp_install_default_rule_in_capture_group(uint16_t port_id, bool is_on)
{

struct rte_flow_item pattern[2]; // first is a NULL ethernet header matching, second is the end
@@ -171,13 +171,12 @@ int dp_install_default_rule_in_monitoring_group(uint16_t port_id, bool is_on)
dp_set_end_action(&action[action_cnt++]);

// validate and install flow rule
flow = dp_install_rte_flow(port_id, &dp_flow_attr_default_monitoring_ingress, pattern, action);
flow = dp_install_rte_flow(port_id, &dp_flow_attr_default_capture_ingress, pattern, action);

if (!flow) {
DPS_LOG_DEBUG("Failed to install default monitoring flow rule on port %d \n", DP_LOG_PORTID(port_id));
return DP_ERROR;
}


port->default_capture_flow = flow;

@@ -216,7 +215,7 @@ static int dp_install_pf_default_flow(struct dp_port *port, bool is_on)
{
int ret;

ret = dp_install_default_rule_in_monitoring_group(port->port_id, is_on);
ret = dp_install_default_rule_in_capture_group(port->port_id, is_on);
if (DP_FAILED(ret)) {
DPS_LOG_WARNING("Failed to install default flow", DP_LOG_PORTID(port->port_id), DP_LOG_RET(ret));
return DP_ERROR;
@@ -242,7 +241,7 @@ static int dp_install_vf_default_capture_flow(struct dp_port *port)
{
int ret;

ret = dp_install_default_rule_in_monitoring_group(port->port_id, true);
ret = dp_install_default_rule_in_capture_group(port->port_id, true);
if (DP_FAILED(ret)) {
DPS_LOG_WARNING("Failed to install default capture flow", DP_LOG_PORTID(port->port_id), DP_LOG_RET(ret));
return DP_ERROR;
@@ -255,17 +254,17 @@ static int dp_turn_on_offload_pkt_capture(struct dp_port *port)
{
if (!port->allocated || port->captured)
return DP_OK;

if (DP_FAILED(dp_destroy_default_flow(port)))
return DP_ERROR;

switch (port->port_type) {
case DP_PORT_PF:
if (DP_FAILED(dp_install_pf_default_flow(port, true)))
return DP_ERROR;
break;
case DP_PORT_VF:
if (DP_FAILED(dp_install_vf_default_jump_flow(port, DP_RTE_FLOW_MONITORING_GROUP)))
if (DP_FAILED(dp_install_vf_default_jump_flow(port, DP_RTE_FLOW_CAPTURE_GROUP)))
return DP_ERROR;
// rollback flow rules if failed on the second one for VF.
if (DP_FAILED(dp_install_vf_default_capture_flow(port))) {
@@ -288,7 +287,7 @@ static int dp_turn_off_offload_pkt_capture(struct dp_port *port)
{
if (!port->allocated || !port->captured)
return DP_OK;

if (DP_FAILED(dp_destroy_default_flow(port)))
return DP_ERROR;

@@ -317,7 +316,7 @@ int dp_turn_on_offload_pkt_capture_on_single_iface(uint16_t port_id)
int dp_turn_off_offload_pkt_capture_on_single_iface(uint16_t port_id)
{
struct dp_port *port = dp_port_get(port_id);

return dp_turn_off_offload_pkt_capture(port);
}

@@ -342,7 +341,7 @@ int dp_turn_off_offload_pkt_capture_on_all_ifaces(void)
if (port->captured) {
if (DP_FAILED(dp_turn_off_offload_pkt_capture(port)))
return DP_ERROR;
count ++;
count++;
}
}
return count;
34 changes: 17 additions & 17 deletions src/rte_flow/dp_rte_flow_traffic_forward.c
Original file line number Diff line number Diff line change
@@ -38,13 +38,13 @@ static const struct rte_flow_attr dp_flow_attr_egress = {

// it is used during the decap operation on pf to install a redirecting rule
// to point a specific flow to either capturing rule or vnet rule
static const struct rte_flow_attr dp_flow_pf_attr_transfer_special = {
static const struct rte_flow_attr dp_flow_pf_attr_transfer_capture = {
.group = DP_RTE_FLOW_DEFAULT_GROUP,
.priority = 0,
.ingress = 0,
.egress = 0,
.transfer = 1,
};
};

// it is used during the decap/decap operation to install a decap/encap rule to transfer pkts
static const struct rte_flow_attr dp_flow_attr_transfer_multi_stage = {
@@ -354,13 +354,13 @@ static __rte_always_inline int dp_offload_handle_tunnel_decap_traffic(struct rte
int action_cnt = 0;

struct rte_flow_action_jump jump_action; // 1
struct rte_flow_action_age flow_age_special;
struct rte_flow_action_age flow_age_capture; // 2
struct rte_flow_action special_moni_action[3];
int special_moni_action_cnt = 0;

// misc variables needed to create the flow
struct flow_age_ctx *agectx, *agectx_special;
struct rte_flow_action *age_action, *age_action_special;
struct flow_age_ctx *agectx, *agectx_capture;
struct rte_flow_action *age_action, *age_action_capture;
struct dp_port *port;
struct rte_ether_hdr new_eth_hdr;
rte_be32_t actual_ol_ipv4_addr;
@@ -404,23 +404,23 @@ static __rte_always_inline int dp_offload_handle_tunnel_decap_traffic(struct rte

// create special actions
if ((!cross_pf_port) && dp_port_get(m->port)->captured) {
agectx_special = allocate_agectx();
if (!agectx_special)
agectx_capture = allocate_agectx();
if (!agectx_capture)
return DP_ERROR;

attr = &dp_flow_attr_transfer_multi_stage;

age_action_special = &special_moni_action[special_moni_action_cnt++];
dp_set_flow_age_action(age_action_special, &flow_age_special, df->conntrack->timeout_value, agectx_special);
dp_set_jump_group_action(&special_moni_action[special_moni_action_cnt++], &jump_action, DP_RTE_FLOW_MONITORING_GROUP);
age_action_capture = &special_moni_action[special_moni_action_cnt++];
dp_set_flow_age_action(age_action_capture, &flow_age_capture, df->conntrack->timeout_value, agectx_capture);

dp_set_jump_group_action(&special_moni_action[special_moni_action_cnt++], &jump_action, DP_RTE_FLOW_CAPTURE_GROUP);

dp_set_end_action(&special_moni_action[special_moni_action_cnt++]);
// struct rte_flow *sp_flow;

if (DP_FAILED(dp_install_rte_flow_with_indirect(m->port, &dp_flow_pf_attr_transfer_special,
pattern, special_moni_action, age_action_special, df, agectx_special))) {
dp_destroy_rte_flow_agectx(agectx_special);
if (DP_FAILED(dp_install_rte_flow_with_indirect(m->port, &dp_flow_pf_attr_transfer_capture,
pattern, special_moni_action, age_action_capture, df, agectx_capture))) {
dp_destroy_rte_flow_agectx(agectx_capture);
return DP_ERROR;
}

@@ -466,7 +466,7 @@ static __rte_always_inline int dp_offload_handle_tunnel_decap_traffic(struct rte
dp_set_end_action(&actions[action_cnt++]);

if (DP_FAILED(dp_install_rte_flow_with_indirect(m->port,
cross_pf_port? &dp_flow_pf_attr_ingress : attr,
cross_pf_port ? &dp_flow_pf_attr_ingress : attr,
pattern, actions,
age_action, df, agectx))
) {
@@ -478,7 +478,7 @@ static __rte_always_inline int dp_offload_handle_tunnel_decap_traffic(struct rte
DPS_LOG_DEBUG("Installed flow rules to handle hairpin pkts on both PF and VF", DP_LOG_PORTID(m->port), DP_LOG_PORTID(df->nxt_hop));
else
DPS_LOG_DEBUG("Installed normal decap flow rule on PF", DP_LOG_PORTID(m->port));

return DP_OK;
}

0 comments on commit 23d27f2

Please sign in to comment.