Skip to content

Commit

Permalink
Make forcible stitching optional
Browse files Browse the repository at this point in the history
`set upf proxy` force-stitching on|off controls the option.
`show upf proxy` displays "Force-stitching" status.
  • Loading branch information
ivan4th committed Nov 4, 2021
1 parent 4146283 commit a4673d5
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 13 deletions.
19 changes: 16 additions & 3 deletions upf/upf_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -1345,6 +1345,16 @@ upf_proxy_set_command_fn (vlib_main_t * vm, unformat_input_t * input,
else if (unformat (input, "private-segment-size %U",
unformat_memory_size, &private_segment_size))
;
else if (unformat (input, "force-stitching"))
{
if (unformat (input, "on"))
force_stitching = 1;
else if (unformat (input, "off"))
force_stitching = 0;
else
return clib_error_return (0, "unknown input `%U'",
format_unformat_error, input);
}
else
return clib_error_return (0, "unknown input `%U'",
format_unformat_error, input);
Expand All @@ -1363,7 +1373,8 @@ VLIB_CLI_COMMAND (upf_proxy_set_command, static) =
.short_help = "set upf proxy [mss <nn>] [fifo-size <nn>[k|m]]"
"[max-fifo-size <nn>[k|m]][high-watermark <nn>]"
"[low-watermark <nn>][prealloc-fifos <nn>]"
"[private-segment-size <mem>][private-segment-count <nn>]",
"[private-segment-size <mem>][private-segment-count <nn>]"
"[force-stitching <on|off>]",
.function = upf_proxy_set_command_fn,
};
/* *INDENT-ON* */
Expand Down Expand Up @@ -1395,14 +1406,16 @@ upf_show_proxy_command_fn (vlib_main_t * vm,
"Hi/Lo Watermark: %u %% / %u %%\n"
"Prealloc FIFOs: %u\n"
"Private Segment Count: %u\n"
"Private Segment Size: %U\n",
"Private Segment Size: %U\n"
"Force stitching: %s\n",
pm->mss,
format_memory_size, pm->fifo_size,
format_memory_size, pm->max_fifo_size,
pm->high_watermark, pm->low_watermark,
pm->prealloc_fifos,
pm->private_segment_count,
format_memory_size, pm->private_segment_size);
format_memory_size, pm->private_segment_size,
pm->force_stitching ? "on" : "off");

done:
return error;
Expand Down
1 change: 1 addition & 0 deletions upf/upf_proxy.c
Original file line number Diff line number Diff line change
Expand Up @@ -1390,6 +1390,7 @@ upf_proxy_main_init (vlib_main_t * vm)
pm->prealloc_fifos = 0;
pm->private_segment_count = 0;
pm->private_segment_size = 512 << 20;
pm->force_stitching = 1;

pm->server_client_index = ~0;
pm->active_open_client_index = ~0;
Expand Down
5 changes: 3 additions & 2 deletions upf/upf_proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,13 @@ typedef struct
#define foreach_upf_proxy_config_fields \
_(u16, mss) /**< TCP MSS */ \
_(uword, fifo_size) /**< initial fifo size */ \
_(uword, max_fifo_size) /**< max fifo size */ \
_(uword, max_fifo_size) /**< max fifo size */ \
_(u8, high_watermark) /**< high watermark (%) */ \
_(u8, low_watermark) /**< low watermark (%) */ \
_(u32, private_segment_count) /**< Number of private fifo segs */ \
_(uword, private_segment_size) /**< size of private fifo segs */ \
_(uword, private_segment_size) /**< size of private fifo segs */ \
_(u8, prealloc_fifos) /**< Request fifo preallocation */ \
_(u8, force_stitching) /**< Force "dirty" proxy stitching */ \

typedef struct
{
Expand Down
20 changes: 12 additions & 8 deletions upf/upf_proxy_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ splice_tcp_connection (upf_main_t * gtm, flow_entry_t * flow,
transport_connection_t *tc;
tcp_connection_t *tcpRx, *tcpTx;
session_t *s;
upf_proxy_main_t *pm = &upf_proxy_main;

if (rev->conn_index == ~0)
return UPF_PROXY_INPUT_NEXT_TCP_INPUT;
Expand Down Expand Up @@ -198,24 +199,27 @@ splice_tcp_connection (upf_main_t * gtm, flow_entry_t * flow,
return UPF_PROXY_INPUT_NEXT_TCP_INPUT;
}

if (flow_seq_offs (flow, origin) == 0)
flow_seq_offs (flow, origin) = direction == FT_ORIGIN ?
tcpTx->snd_nxt - tcpRx->rcv_nxt : tcpRx->rcv_nxt - tcpTx->snd_nxt;

if (flow_seq_offs (flow, reverse) == 0)
flow_seq_offs (flow, reverse) = direction == FT_ORIGIN ?
tcpTx->rcv_nxt - tcpRx->snd_nxt : tcpRx->snd_nxt - tcpTx->rcv_nxt;

/* check fifo, proxy Tx/Rx are connected... */
if (svm_fifo_max_dequeue (s->rx_fifo) != 0 ||
svm_fifo_max_dequeue (s->tx_fifo) != 0)
{
if (!pm->force_stitching)
return UPF_PROXY_INPUT_NEXT_TCP_INPUT;

flow->spliced_dirty = 1;
vlib_increment_simple_counter (&gtm->upf_simple_counters
[UPF_FLOWS_STITCHED_DIRTY_FIFOS],
vlib_get_thread_index (), 0, 1);
}

if (flow_seq_offs (flow, origin) == 0)
flow_seq_offs (flow, origin) = direction == FT_ORIGIN ?
tcpTx->snd_nxt - tcpRx->rcv_nxt : tcpRx->rcv_nxt - tcpTx->snd_nxt;

if (flow_seq_offs (flow, reverse) == 0)
flow_seq_offs (flow, reverse) = direction == FT_ORIGIN ?
tcpTx->rcv_nxt - tcpRx->snd_nxt : tcpRx->snd_nxt - tcpTx->rcv_nxt;

/* kill the TCP connections, session and proxy session */
kill_connection_hard (tcpRx);
kill_connection_hard (tcpTx);
Expand Down

0 comments on commit a4673d5

Please sign in to comment.