TSG-13837 支持decrypted traffic steering/mirroring,并重构packet_io

This commit is contained in:
luwenpeng
2023-03-14 16:10:44 +08:00
parent 29755f2162
commit 0e85d3c9c5
26 changed files with 1960 additions and 1941 deletions

View File

@@ -4,6 +4,24 @@
#include "addr_tuple4.h"
void addr_tuple4_copy(struct addr_tuple4 *dst, struct addr_tuple4 *src)
{
dst->addr_type = src->addr_type;
dst->src_port = src->src_port;
dst->dst_port = src->dst_port;
if (src->addr_type == ADDR_TUPLE4_TYPE_V4)
{
memcpy(&(dst->addr_v4.src_addr), &(src->addr_v4.src_addr), sizeof(struct in_addr));
memcpy(&(dst->addr_v4.dst_addr), &(src->addr_v4.dst_addr), sizeof(struct in_addr));
}
else
{
memcpy(&(dst->addr_v6.src_addr), &(src->addr_v6.src_addr), sizeof(struct addr_v6));
memcpy(&(dst->addr_v6.dst_addr), &(src->addr_v6.dst_addr), sizeof(struct addr_v6));
}
}
char *addr_tuple4_to_str(const struct addr_tuple4 *addr)
{
char *str_ret = NULL;

View File

@@ -272,7 +272,7 @@ int raw_packet_parser_get_most_outer_address(struct raw_pkt_parser *handler, str
return -1;
}
uint64_t raw_packet_parser_get_hash_value(struct raw_pkt_parser *handler, enum ldbc_method method, int dir_is_internal)
uint64_t raw_packet_parser_get_hash_value(struct raw_pkt_parser *handler, enum ldbc_method method, int dir_is_i2e)
{
uint64_t temp = 0;
uint64_t hash_value = 1;
@@ -333,7 +333,7 @@ uint64_t raw_packet_parser_get_hash_value(struct raw_pkt_parser *handler, enum l
switch (method)
{
case LDBC_METHOD_HASH_INT_IP:
if (dir_is_internal)
if (dir_is_i2e)
{
// outer src ip
HASH_VALUE(outer_src_addr, outer_addr_len, hash_value);
@@ -345,7 +345,7 @@ uint64_t raw_packet_parser_get_hash_value(struct raw_pkt_parser *handler, enum l
}
break;
case LDBC_METHOD_HASH_EXT_IP:
if (dir_is_internal)
if (dir_is_i2e)
{
// outer dst ip
HASH_VALUE(outer_dst_addr, outer_addr_len, hash_value);
@@ -363,7 +363,7 @@ uint64_t raw_packet_parser_get_hash_value(struct raw_pkt_parser *handler, enum l
hash_value = hash_value ^ temp;
break;
case LDBC_METHOD_HASH_INNERMOST_INT_IP:
if (dir_is_internal)
if (dir_is_i2e)
{
// innner src ip
HASH_VALUE(inner_src_addr, inner_addr_len, hash_value);
@@ -375,7 +375,7 @@ uint64_t raw_packet_parser_get_hash_value(struct raw_pkt_parser *handler, enum l
}
break;
case LDBC_METHOD_HASH_INNERMOST_EXT_IP:
if (dir_is_internal)
if (dir_is_i2e)
{
// innner dst ip
HASH_VALUE(inner_dst_addr, inner_addr_len, hash_value);
@@ -393,7 +393,7 @@ uint64_t raw_packet_parser_get_hash_value(struct raw_pkt_parser *handler, enum l
char *inner_addr_str = addr_tuple4_to_str(&inner_addr);
char *outer_addr_str = addr_tuple4_to_str(&outer_addr);
LOG_DEBUG("%s: pkt_trace_id: %lu, outer_addr: %s, inner_addr: %s, is_internal: %d, hash_method: %s, hash_value: %lu",
LOG_TAG_RAWPKT, handler->pkt_trace_id, outer_addr_str, inner_addr_str, dir_is_internal, ldbc_method_to_string(method), hash_value);
LOG_TAG_RAWPKT, handler->pkt_trace_id, outer_addr_str, inner_addr_str, dir_is_i2e, ldbc_method_to_string(method), hash_value);
free(inner_addr_str);
free(outer_addr_str);
@@ -814,7 +814,7 @@ static const void *parse_vxlan(struct raw_pkt_parser *handler, const void *data,
return data;
}
struct vxlan_hdr *vxlan_hdr = (struct vxlan_hdr *)data;
// struct vxlan_hdr *vxlan_hdr = (struct vxlan_hdr *)data;
uint16_t hdr_len = sizeof(struct vxlan_hdr);
const void *data_next_layer = (const char *)data + hdr_len;
size_t data_next_length = length - hdr_len;

View File

@@ -2,7 +2,6 @@
#include "session_table.h"
#include "utils.h"
#include "log.h"
struct session_table
{
@@ -33,9 +32,9 @@ void session_table_destory(struct session_table *table)
HASH_DELETE(hh1, table->root_by_id, node);
HASH_DELETE(hh2, table->root_by_addr, node);
if (node->val_freecb && node->val_data)
if (node->value_free_cb && node->value)
{
node->val_freecb(node->val_data);
node->value_free_cb(node->value);
}
free(node);
@@ -58,9 +57,9 @@ void session_table_reset(struct session_table *table)
HASH_DELETE(hh1, table->root_by_id, node);
HASH_DELETE(hh2, table->root_by_addr, node);
if (node->val_freecb && node->val_data)
if (node->value_free_cb && node->value)
{
node->val_freecb(node->val_data);
node->value_free_cb(node->value);
}
free(node);
@@ -84,14 +83,13 @@ uint64_t session_table_count(struct session_table *table)
}
// session_addr : deep copy
// val_data : shallow copy (malloc by user, free by val_freecb)
int session_table_insert(struct session_table *table, uint64_t session_id, const struct addr_tuple4 *session_addr, void *val_data, const fn_free_cb *val_freecb)
// value : shallow copy (malloc by user, free by value_free_cb)
int session_table_insert(struct session_table *table, uint64_t session_id, const struct addr_tuple4 *session_addr, void *value, const fn_free_cb *value_free_cb)
{
struct session_node *temp = NULL;
HASH_FIND(hh1, table->root_by_id, &session_id, sizeof(session_id), temp);
if (temp)
{
LOG_DEBUG("%s: insert: key %lu exists", LOG_TAG_STABLE, session_id);
return -1;
}
@@ -100,13 +98,12 @@ int session_table_insert(struct session_table *table, uint64_t session_id, const
temp->session_id = session_id;
memcpy(&temp->session_addr, session_addr, sizeof(struct addr_tuple4));
temp->val_data = val_data;
temp->val_freecb = val_freecb;
temp->value = value;
temp->value_free_cb = value_free_cb;
HASH_ADD(hh1, table->root_by_id, session_id, sizeof(temp->session_id), temp);
HASH_ADD(hh2, table->root_by_addr, session_addr, sizeof(temp->session_addr), temp);
LOG_DEBUG("%s: insert: key %lu success", LOG_TAG_STABLE, session_id);
table->session_node_count++;
return 0;
@@ -118,23 +115,21 @@ int session_table_delete_by_id(struct session_table *table, uint64_t session_id)
HASH_FIND(hh1, table->root_by_id, &session_id, sizeof(session_id), temp);
if (!temp)
{
LOG_DEBUG("%s: delete: key %lu not exists", LOG_TAG_STABLE, session_id);
return -1;
}
HASH_DELETE(hh1, table->root_by_id, temp);
HASH_DELETE(hh2, table->root_by_addr, temp);
if (temp->val_freecb && temp->val_data)
if (temp->value_free_cb && temp->value)
{
temp->val_freecb(temp->val_data);
temp->val_data = NULL;
temp->value_free_cb(temp->value);
temp->value = NULL;
}
free(temp);
temp = NULL;
LOG_DEBUG("%s: delete: key %lu success", LOG_TAG_STABLE, session_id);
table->session_node_count--;
return 0;
@@ -143,7 +138,6 @@ int session_table_delete_by_id(struct session_table *table, uint64_t session_id)
int session_table_delete_by_addr(struct session_table *table, const struct addr_tuple4 *session_addr)
{
struct session_node *temp = NULL;
char *addr_str = addr_tuple4_to_str(session_addr);
HASH_FIND(hh2, table->root_by_addr, session_addr, sizeof(struct addr_tuple4), temp);
if (!temp)
{
@@ -152,8 +146,6 @@ int session_table_delete_by_addr(struct session_table *table, const struct addr_
HASH_FIND(hh2, table->root_by_addr, &reverse_addr, sizeof(struct addr_tuple4), temp);
if (!temp)
{
LOG_DEBUG("%s: delete: key %s not exists", LOG_TAG_STABLE, addr_str);
free(addr_str);
return -1;
}
}
@@ -161,18 +153,15 @@ int session_table_delete_by_addr(struct session_table *table, const struct addr_
HASH_DELETE(hh1, table->root_by_id, temp);
HASH_DELETE(hh2, table->root_by_addr, temp);
if (temp->val_freecb && temp->val_data)
if (temp->value_free_cb && temp->value)
{
temp->val_freecb(temp->val_data);
temp->val_data = NULL;
temp->value_free_cb(temp->value);
temp->value = NULL;
}
free(temp);
temp = NULL;
LOG_DEBUG("%s: delete: key %s success", LOG_TAG_STABLE, addr_str);
free(addr_str);
addr_str = NULL;
table->session_node_count--;
return 0;
@@ -184,19 +173,15 @@ struct session_node *session_table_search_by_id(struct session_table *table, uin
HASH_FIND(hh1, table->root_by_id, &session_id, sizeof(session_id), temp);
if (!temp)
{
LOG_DEBUG("%s: search: key %lu not exists", LOG_TAG_STABLE, session_id);
return NULL;
}
LOG_DEBUG("%s: search: key %lu success", LOG_TAG_STABLE, session_id);
return temp;
}
struct session_node *session_table_search_by_addr(struct session_table *table, const struct addr_tuple4 *session_addr)
{
struct session_node *temp = NULL;
char *addr_str = addr_tuple4_to_str(session_addr);
HASH_FIND(hh2, table->root_by_addr, session_addr, sizeof(struct addr_tuple4), temp);
if (!temp)
{
@@ -205,16 +190,9 @@ struct session_node *session_table_search_by_addr(struct session_table *table, c
HASH_FIND(hh2, table->root_by_addr, &reverse_addr, sizeof(struct addr_tuple4), temp);
if (!temp)
{
LOG_DEBUG("%s: search: key %s not exists", LOG_TAG_STABLE, addr_str);
free(addr_str);
addr_str = NULL;
return NULL;
}
}
LOG_DEBUG("%s: search: key %s success", LOG_TAG_STABLE, addr_str);
free(addr_str);
addr_str = NULL;
return temp;
}

View File

@@ -20,9 +20,9 @@ struct timestamp *timestamp_new(uint64_t update_interval_ms)
ts->update_interval_ms = update_interval_ms;
timestamp_update(ts);
LOG_DEBUG("%s: TIMESTAMP->update_interval_ms : %lu", LOG_TAG_TIMESTAMP, timestamp_update_interval_ms(ts));
LOG_DEBUG("%s: TIMESTAMP->current_sec : %lu", LOG_TAG_TIMESTAMP, timestamp_get_sec(ts));
LOG_DEBUG("%s: TIMESTAMP->current_msec : %lu", LOG_TAG_TIMESTAMP, timestamp_get_msec(ts));
LOG_DEBUG("%s: TIMESTAMP->update_interval_ms : %lu", LOG_TAG_TIMESTAMP, timestamp_update_interval_ms(ts));
LOG_DEBUG("%s: TIMESTAMP->current_sec : %lu", LOG_TAG_TIMESTAMP, timestamp_get_sec(ts));
LOG_DEBUG("%s: TIMESTAMP->current_msec : %lu", LOG_TAG_TIMESTAMP, timestamp_get_msec(ts));
return ts;
}

View File

@@ -126,15 +126,14 @@ void sids_copy(struct sids *dst, struct sids *src)
* route_ctx
******************************************************************************/
int route_ctx_is_empty(struct route_ctx *ctx)
void route_ctx_write_once(struct route_ctx *dst, struct route_ctx *src)
{
if (ctx->len == 0)
if (dst && src)
{
return 1;
}
else
{
return 0;
if (dst->len == 0)
{
route_ctx_copy(dst, src);
}
}
}
@@ -150,8 +149,8 @@ void route_ctx_copy(struct route_ctx *dst, struct route_ctx *src)
void throughput_metrics_inc(struct throughput_metrics *iterm, uint64_t n_pkts, uint64_t n_bytes)
{
__atomic_fetch_add(&iterm->n_bytes, n_bytes, __ATOMIC_RELAXED);
__atomic_fetch_add(&iterm->n_pkts, n_pkts, __ATOMIC_RELAXED);
ATOMIC_ADD(&iterm->n_bytes, n_bytes);
ATOMIC_ADD(&iterm->n_pkts, n_pkts);
}
/******************************************************************************