Skip to content

Commit

Permalink
final touches
Browse files Browse the repository at this point in the history
  • Loading branch information
mogaika committed Feb 2, 2024
1 parent 1af2003 commit 50cdf22
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 33 deletions.
3 changes: 1 addition & 2 deletions upf/flowtable.c
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,8 @@ flowtable_entry_lookup_create (flowtable_main_t *fm,
pool_get_zero (fm->flows, f);

flow_key_apply_direction (&f->key, (flow_key_t *) kv->key, key_direction);

// make it so FT_INITIATOR corresponds to first packet
f->key_direction = key_direction;

f->lifetime = flowtable_lifetime_calculate (fm, &f->key);
f->active = now;
f->flow_start_time = timestamp_ns;
Expand Down
6 changes: 2 additions & 4 deletions upf/flowtable.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,9 @@ typedef struct flow_entry
CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);

/* flow signature */
// key elements can be addressed directily with flow_direction_t
// key elements indexes are flow_direction_t
key_directioned_t key;
u32 session_index;

u8 key_direction : 1; // flow_direction_op_t of bihash key
u8 is_redirect : 1;
u8 is_l3_proxy : 1;
Expand All @@ -189,10 +188,9 @@ typedef struct flow_entry
u16 timer_slot; /* timer list index in the timer lists pool */
flow_timeout_list_anchor_t timer_anchor;

// elements addressed directily with flow_direction_t
// elements indexes are flow_direction_t
flow_side_t side[FT_DIRECTION_MAX];

/* UPF data */
u32 application_id; /* L7 app index */

u8 *app_uri;
Expand Down
2 changes: 1 addition & 1 deletion upf/upf_adf.c
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ upf_application_detection (vlib_main_t *vm, u8 *p, flow_entry_t *flow,
clib_net_to_host_u16 (flow->key.port[FTK_EL_DST ^ FT_INITIATOR]);
upf_debug (
"Using port %u, instead of %u", port,
clib_net_to_host_u16 (flow->key.port[FT_INITIATOR ^ FTK_EL_SRC]));
clib_net_to_host_u16 (flow->key.port[FTK_EL_SRC ^ FT_INITIATOR]));

if (*p == TLS_HANDSHAKE)
r = upf_adr_try_tls (server_port, p, &uri);
Expand Down
42 changes: 21 additions & 21 deletions upf/upf_flow_node.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ format_get_flowinfo (u8 *s, va_list *args)
always_inline u32
load_gtpu_flow_info (flowtable_main_t *fm, vlib_buffer_t *b,
flow_entry_t *flow, struct rules *r,
flow_direction_op_t flow_key_direction, u16 generation)
flow_direction_op_t key_direction, u16 generation)
{
flow_direction_t direction = flow->key_direction ^ flow_key_direction;
flow_direction_t direction = flow->key_direction ^ key_direction;

upf_buffer_opaque (b)->gtpu.flow_key_direction = flow_key_direction;
upf_buffer_opaque (b)->gtpu.flow_key_direction = key_direction;
upf_buffer_opaque (b)->gtpu.direction = direction;
upf_buffer_opaque (b)->gtpu.flow_id = flow - fm->flows;

Expand Down Expand Up @@ -138,7 +138,7 @@ upf_flow_process (vlib_main_t *vm, vlib_node_runtime_t *node,
u32 next0, next1;
clib_bihash_kv_48_8_t kv0, kv1;
int created0, created1;
flow_direction_op_t flow_key_direction0, flow_key_direction1;
flow_direction_op_t key_direction0, key_direction1;
u32 flow_idx0, flow_idx1;
flow_entry_t *flow0, *flow1;
u8 *p0, *p1;
Expand Down Expand Up @@ -169,7 +169,7 @@ upf_flow_process (vlib_main_t *vm, vlib_node_runtime_t *node,
UPF_CHECK_INNER_NODE (b1);

created0 = created1 = 0;
flow_key_direction0 = flow_key_direction1 = 0;
key_direction0 = key_direction1 = 0;

if (PREDICT_FALSE (
pool_is_free_index (
Expand Down Expand Up @@ -213,12 +213,12 @@ upf_flow_process (vlib_main_t *vm, vlib_node_runtime_t *node,
active0 = pfcp_get_rules (sx0, PFCP_ACTIVE);
active1 = pfcp_get_rules (sx1, PFCP_ACTIVE);

flow_mk_key (sx0->up_seid, p0, is_ip4, &flow_key_direction0, &kv0);
flow_mk_key (sx1->up_seid, p1, is_ip4, &flow_key_direction1, &kv1);
flow_mk_key (sx0->up_seid, p0, is_ip4, &key_direction0, &kv0);
flow_mk_key (sx1->up_seid, p1, is_ip4, &key_direction1, &kv1);

/* lookup/create flow */
flow_idx0 = flowtable_entry_lookup_create (
fm, fmt, &kv0, timestamp_ns, current_time, flow_key_direction0,
fm, fmt, &kv0, timestamp_ns, current_time, key_direction0,
sx0->generation, sx0 - gtm->sessions, &created0);
if (created0)
{
Expand All @@ -228,7 +228,7 @@ upf_flow_process (vlib_main_t *vm, vlib_node_runtime_t *node,
}

flow_idx1 = flowtable_entry_lookup_create (
fm, fmt, &kv1, timestamp_ns, current_time, flow_key_direction1,
fm, fmt, &kv1, timestamp_ns, current_time, key_direction1,
sx1->generation, sx1 - gtm->sessions, &created1);
if (created1)
{
Expand Down Expand Up @@ -264,10 +264,10 @@ upf_flow_process (vlib_main_t *vm, vlib_node_runtime_t *node,
current_time);

/* fill buffer with flow data */
next0 = load_gtpu_flow_info (fm, b0, flow0, active0,
flow_key_direction0, sx0->generation);
next1 = load_gtpu_flow_info (fm, b1, flow1, active1,
flow_key_direction1, sx1->generation);
next0 = load_gtpu_flow_info (fm, b0, flow0, active0, key_direction0,
sx0->generation);
next1 = load_gtpu_flow_info (fm, b1, flow1, active1, key_direction1,
sx1->generation);

/* flowtable counters */
CPT_THRU += 2;
Expand Down Expand Up @@ -325,7 +325,7 @@ upf_flow_process (vlib_main_t *vm, vlib_node_runtime_t *node,
int created = 0;
u32 flow_idx;
flow_entry_t *flow = NULL;
flow_direction_op_t flow_key_direction = 0;
flow_direction_op_t key_direction = 0;
clib_bihash_kv_48_8_t kv;
u8 *p;
uword len0;
Expand Down Expand Up @@ -360,9 +360,9 @@ upf_flow_process (vlib_main_t *vm, vlib_node_runtime_t *node,
active0 = pfcp_get_rules (sx0, PFCP_ACTIVE);

/* lookup/create flow */
flow_mk_key (sx0->up_seid, p, is_ip4, &flow_key_direction, &kv);
flow_mk_key (sx0->up_seid, p, is_ip4, &key_direction, &kv);
flow_idx = flowtable_entry_lookup_create (
fm, fmt, &kv, timestamp_ns, current_time, flow_key_direction,
fm, fmt, &kv, timestamp_ns, current_time, key_direction,
sx0->generation, sx0 - gtm->sessions, &created);
if (created)
{
Expand All @@ -383,19 +383,19 @@ upf_flow_process (vlib_main_t *vm, vlib_node_runtime_t *node,
flow->session_index = upf_buffer_opaque (b0)->gtpu.session_index;
FLOW_DEBUG (fm, flow);

flow_debug ("flow_key_direction: %u, key_direction: %u, "
flow_debug ("key_direction: %u, key_direction: %u, "
"direction: %u c: %u",
flow_key_direction, flow->key_direction,
flow_key_direction ^ flow->key_direction, created);
key_direction, flow->key_direction,
key_direction ^ flow->key_direction, created);

/* update activity timer */
flow_update (vm, flow, p, is_ip4,
len0 - upf_buffer_opaque (b0)->gtpu.data_offset,
current_time);

/* fill opaque buffer with flow data */
next0 = load_gtpu_flow_info (fm, b0, flow, active0,
flow_key_direction, sx0->generation);
next0 = load_gtpu_flow_info (fm, b0, flow, active0, key_direction,
sx0->generation);
flow_debug ("flow next: %u, origin: %u, reverse: %u", next0,
flow_side (flow, FT_INITIATOR)->next,
flow_side (flow, FT_RESPONDER)->next);
Expand Down
10 changes: 5 additions & 5 deletions upf/upf_proxy_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ static uword
upf_proxy_output (vlib_main_t *vm, vlib_node_runtime_t *node,
vlib_frame_t *from_frame,
const flow_direction_t output_direction, int is_ip4,
int no_opaque, int far_only)
int far_only)
{
u32 n_left_from, next_index, *from, *to_next;
upf_main_t *gtm = &upf_main;
Expand Down Expand Up @@ -306,28 +306,28 @@ VLIB_NODE_FN (upf_ip4_proxy_server_output_node)
(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *from_frame)
{
return upf_proxy_output (vm, node, from_frame, FT_RESPONDER, /* is_ip4 */ 1,
/* no_opaque */ 0, /* far_only */ 0);
/* far_only */ 0);
}

VLIB_NODE_FN (upf_ip6_proxy_server_output_node)
(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *from_frame)
{
return upf_proxy_output (vm, node, from_frame, FT_RESPONDER, /* is_ip4 */ 0,
/* no_opaque */ 0, /* far_only */ 0);
/* far_only */ 0);
}

VLIB_NODE_FN (upf_ip4_proxy_server_far_only_output_node)
(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *from_frame)
{
return upf_proxy_output (vm, node, from_frame, FT_INITIATOR, /* is_ip4 */ 1,
/* no_opaque */ 0, /* far_only */ 1);
/* far_only */ 1);
}

VLIB_NODE_FN (upf_ip6_proxy_server_far_only_output_node)
(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *from_frame)
{
return upf_proxy_output (vm, node, from_frame, FT_INITIATOR, /* is_ip4 */ 0,
/* no_opaque */ 0, /* far_only */ 1);
/* far_only */ 1);
}

/* clang-format off */
Expand Down

0 comments on commit 50cdf22

Please sign in to comment.