5 #include <netinet/tcp.h>
6 #include <netinet/if_ether.h>
9 #include <linux/if_ether.h>
11 #include <netinet/in.h>
12 #include <arpa/inet.h>
13 #include <netinet/ip.h>
18 #ifndef __MTCP_MANAGER
19 #define __MTCP_MANAGER
95 typedef union event_data {
103 #define MOS_ETH_HDR (1 << 0)
104 #define MOS_IP_HDR (1 << 1)
105 #define MOS_TCP_HDR (1 << 2)
106 #define MOS_TCP_PAYLOAD (1 << 3)
107 #define MOS_UPDATE_IP_CHKSUM (1 << 4)
108 #define MOS_UPDATE_TCP_CHKSUM (1 << 5)
109 #define MOS_DROP (1 << 6)
110 #define MOS_OVERWRITE (1 << 7)
111 #define MOS_CHOMP (1 << 8)
112 #define MOS_INSERT (1 << 9)
167 #define PKT_INFO_LEN offsetof(struct pkt_info, ethh)
190 #define SOL_SOCKET 0xffff
192 #define SOL_MONSOCKET 0xfffe
246 MOS_NO_CLIBUF = 0x0f,
247 MOS_NO_SVRBUF = 0x10,
443 char *buf,
size_t len);
466 char *buf,
size_t count, uint64_t off);
469 #define MTCP_CB_GETCURPKT_CREATE_COPY
549 byte *data, uint16_t datalen,
int option);
Definition: mos_api.h:296
TCP state is being changed.
Definition: mos_api.h:77
MOS tcp buf info structure.
Definition: mos_api.h:257
Definition: mos_api.h:233
Definition: mos_api.h:242
bool(* filter_t)(mctx_t mctx, int sock, int side, event_t event, filter_arg_t *arg)
Prototype of UDE's filter function.
Definition: mos_api.h:326
ssize_t mtcp_ppeek(mctx_t mctx, int sock, int side, char *buf, size_t count, uint64_t off)
The mtcp_ppeek() function reads up to count bytes from the TCP ring buffer of the monitor socket sock...
int mtcp_sendpkt(mctx_t mctx, int sock, const struct pkt_info *pkt)
Send a TCP packet of struct pkt_info.
uint32_t seq
Definition: mos_api.h:134
int mtcp_register_callback(mctx_t mctx, int sock, event_t event, int hook_point, callback_t cb)
Register a callback function in hook_point.
int8_t in_ifidx
input interface (ro)
Definition: mos_api.h:162
New data is now readable.
Definition: mos_api.h:68
Definition: mos_api.h:319
struct socket_map * socket_map_t
Definition: mos_api.h:24
struct pkt_info p
Definition: mos_api.h:158
struct mtcp_manager * mtcp_manager_t
Definition: mos_api.h:20
Definition: mos_api.h:299
uint32_t len
Definition: mos_api.h:284
int64_t seq_off
Definition: mos_api.h:174
Definition: mos_api.h:237
mos_event_type
Built-in events provided by mOS.
Definition: mos_api.h:43
Definition: mos_api.h:311
uint64_t offset
TCP ring buffer offset.
Definition: mos_api.h:132
int mtcp_raise_event(mctx_t mctx, event_t event)
Raise a event.
char * stream_syn_filter
Definition: mos_api.h:336
uint8_t * payload
Definition: mos_api.h:150
mos_socket_opts
MOS monitor socket option names (and values) This will contain options pertaining to monitor stream s...
Definition: mos_api.h:228
struct ethhdr * ethh
Definition: mos_api.h:147
uint32_t base_seq
Definition: mos_api.h:176
int mtcp_getlastpkt(mctx_t mctx, int sock, int side, struct pkt_info *p)
Get current packet of mtcp context.
event_t mtcp_alloc_event(event_t event)
Allocate a child event.
event_t mtcp_define_event(event_t event, filter_t filter, struct filter_arg *arg)
Define a user-defined event function.
Definition: mos_api.h:305
Definition: mos_api.h:173
int8_t batch_index
index of packet in the rx batch
Definition: mos_api.h:164
int mtcp_settimer(mctx_t mctx, int id, struct timeval *timeout, callback_t cb)
Register user's custom timer.
PACKET CONTEXT is the packet structure that goes through the mOS core...
Definition: mos_api.h:157
Definition: mos_api.h:301
Definition: mos_api.h:298
void(* callback_t)(mctx_t mctx, int sock, int side, event_t event, filter_arg_t *arg)
Prototype of callback function.
Definition: mos_api.h:323
Definition: mos_api.h:229
mtcp_hook_point
Available hooking points.
Definition: mos_api.h:28
Definition: mos_api.h:319
Definition: mos_api.h:300
struct tcphdr * tcph
Definition: mos_api.h:149
uint32_t mtcp_cb_get_ts(mctx_t mctx)
A sibling function to mtcp_settimer that returns the current timestamp of the machine in microseconds...
Definition: mos_api.h:297
char * raw_pkt_filter
For MOS_SOCK_MONITOR_RAW type socket.
Definition: mos_api.h:333
struct filter_arg filter_arg_t
Definition: mos_api.h:179
uint32_t tcpbi_last_byte_read
TCP sequence number of the 'last byte of payload that has already been read by the end application' (...
Definition: mos_api.h:264
No packet is seen for a long time.
Definition: mos_api.h:75
This event is for debugging.
Definition: mos_api.h:90
uint32_t tcpbi_last_byte_received
TCP sequence number of the 'last byte of the payload that is currently stored' in the TCP ring buffer...
Definition: mos_api.h:278
uint16_t eth_len
Definition: mos_api.h:126
int mtcp_bind_monitor_filter(mctx_t mctx, int sock, monitor_filter_t ft)
Definition: mos_api.h:236
tcpstate
mOS tcp stream states.
Definition: mos_api.h:293
Definition: mos_api.h:304
int8_t direction
where does this packet originate from? (ro)
Definition: mos_api.h:160
Definition: mos_api.h:243
Definition: mos_api.h:312
uint32_t tcpbi_next_byte_expected
TCP sequence number of the 'last byte of the payload that is currently buffered and needs to be read ...
Definition: mos_api.h:272
Definition: mos_api.h:232
char * stream_orphan_filter
Definition: mos_api.h:337
Definition: mos_api.h:240
Definition: mos_api.h:331
3-way handshake is finished.
Definition: mos_api.h:64
uint8_t forward
0: drop, 1: forward to out_ifidx (rw)
Definition: mos_api.h:161
Hooking point after TCP sender.
Definition: mos_api.h:39
SYN packet as seen by the monitor client side: activated when the client state is set to SYN_SENT ser...
Definition: mos_api.h:59
Definition: mos_api.h:235
int mtcp_setlastpkt(mctx_t mctx, int sock, int side, off_t offset, byte *data, uint16_t datalen, int option)
Updates the Ethernet frame at a given offset across datalen bytes.
uint64_t event_t
Definition of event type.
Definition: mos_api.h:316
uint64_t offset
Definition: mos_api.h:283
void mtcp_set_uctx(mctx_t mctx, int sock, void *uctx)
Set user-level context (e.g., to store any per-flow user-defined meatadata)
uint16_t ip_len
Definition: mos_api.h:129
Definition: mos_api.h:244
uint16_t payloadlen
Definition: mos_api.h:133
Definition: mos_api.h:302
void * mtcp_get_uctx(mctx_t mctx, int sock)
Get user-level context (e.g., to retrieve user-defined metadata stored in mtcp_set_uctx()) ...
uint32_t ack_seq
Definition: mos_api.h:135
int mtcp_set_debug_string(mtcp_manager_t mtcp, const char *fmt,...)
Definition: mos_api.h:231
Definition: mos_api.h:303
uint32_t cur_ts
packet receiving time (read-only:ro)
Definition: mos_api.h:123
Definition: mos_api.h:241
int mtcp_reset_conn(mctx_t mctx, int sock)
Drop current packet (don't forward it to the peer node)
Definition: mos_api.h:239
A flow is about to be destroyed.
Definition: mos_api.h:87
A packet is not SYN and has no identified flow.
Definition: mos_api.h:79
Very first hooking point of incoming packet even before flow identification.
Definition: mos_api.h:35
void mtcp_app_join(mctx_t mctx)
Pause mtcp application context since it is not running anything.
invalid event
Definition: mos_api.h:46
Definition: mos_api.h:310
struct iphdr * iph
Definition: mos_api.h:148
uint32_t tcpbi_init_seq
The initial TCP sequence number of TCP ring buffer.
Definition: mos_api.h:259
int mtcp_get_debug_string(mctx_t mctx, char *buf, int len)
mTCP context
Definition: mtcp_api.h:23
A packet is coming in.
Definition: mos_api.h:49
Structure to expose TCP ring buffer's fragment information.
Definition: mos_api.h:282
size_t len
Definition: mos_api.h:181
Definition: mos_api.h:319
Definition: mos_api.h:238
Abnormal behavior is detected.
Definition: mos_api.h:71
uint16_t window
Definition: mos_api.h:136
Definition: mos_api.h:230
Definition: mos_api.h:295
struct pkt_info is the struct that is actually exposed to the monitor application.
Definition: mos_api.h:122
Definition: mos_api.h:234
int8_t out_ifidx
output interface (rw)
Definition: mos_api.h:163
ssize_t mtcp_peek(mctx_t mctx, int sock, int side, char *buf, size_t len)
Peeking bytestream from flow_context.
int mtcp_getpeername(mctx_t mctx, int sock, struct sockaddr *saddr, socklen_t *addrlen, int side)
Get IP addrs/ports for both sides.
Retransmission is detected.
Definition: mos_api.h:81
int side
Definition: mos_api.h:175
unsigned char byte
Definition: mtcp_api.h:16
union monitor_filter * monitor_filter_t
Definition: mos_api.h:340
A packet is going out.
Definition: mos_api.h:52
void * arg
Definition: mos_api.h:180
Hooking point before TCP receiver.
Definition: mos_api.h:37