/* // Copyright (c) 2010-2017 Intel Corporation // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. */ #ifndef _GENL4_STREAM_H_ #define _GENL4_STREAM_H_ #include "prox_lua_types.h" #include "pkt_parser.h" #include "token_time.h" #include "quit.h" enum tcp_state { CLOSED, LISTEN, SYN_SENT, SYN_RECEIVED, ESTABLISHED, CLOSE_WAIT, LAST_ACK, FIN_WAIT, TIME_WAIT }; static const char *tcp_state_to_str(const enum tcp_state s) { switch(s) { case CLOSED: return "CLOSED"; case LISTEN: return "LISTEN"; case SYN_SENT: return "SYN_SENT"; case SYN_RECEIVED: return "SYN_RECEIVED"; case ESTABLISHED: return "ESTABLISHED"; case CLOSE_WAIT: return "CLOSE_WAIT"; case LAST_ACK: return "LAST_ACK"; case FIN_WAIT: return "FIN_WAIT"; case TIME_WAIT: return "TIME_WAIT"; default: return "INVALID_STATE"; } } #define STREAM_CTX_F_EXPIRED 0x01 #define STREAM_CTX_F_NEW_DATA 0x02 /* Set on recv to track first ACK of data */ #define STREAM_CTX_F_TCP_ENDED 0x04 #define STREAM_CTX_F_TCP_GOT_SYN 0x08 /* Set only once when syn has been received */ #define STREAM_CTX_F_TCP_GOT_FIN 0x10 /* Set only once when fin has been received */ #define STREAM_CTX_F_MORE_DATA 0x20 #define STREAM_CTX_F_LAST_RX_PKT_MADE_PROGRESS 0x40 /* Run-time structure to management state information associated with current stream_cfg. */ struct stream_ctx { enum l4gen_peer peer; uint32_t cur_action; uint32_t cur_pos[2]; enum tcp_state tcp_state; struct token_time token_time; struct token_time token_time_other; uint16_t flags; uint16_t same_state; uint32_t next_seq; uint32_t ackd_seq; uint32_t recv_seq; uint32_t ackable_data_seq; uint32_t seq_first_byte; /* seq number - seq_first_byte gives offset within content. */ uint32_t other_seq_first_byte; /* seq number - seq_first_byte gives offset within content. */ uint32_t other_mss; uint64_t sched_tsc; uint32_t retransmits; const struct stream_cfg *stream_cfg; /* Current active steam_cfg */ struct pkt_tuple *tuple; }; struct host_set { uint32_t ip; uint32_t ip_mask; uint16_t port; uint16_t port_mask; }; struct stream_cfg { struct peer_data data[2]; struct host_set servers; // Current implementation only allows mask == 0. (i.e. single server) struct token_time_cfg tt_cfg[2]; // bytes per period rate uint16_t proto; uint64_t tsc_timeout; uint64_t tsc_timeout_time_wait; uint32_t n_actions; uint32_t n_pkts; uint32_t n_bytes; int (*proc)(struct stream_ctx *meta, struct rte_mbuf *mbuf, struct l4_meta *l4_meta, uint64_t *next_tsc); int (*is_ended)(struct stream_ctx *meta); struct peer_action actions[0]; }; static void scale_for_jitter(uint64_t *to_scale) { (*to_scale) *= 2; } static void reset_token_times(struct stream_ctx *ctx) { const uint64_t now = rte_rdtsc(); const str