21 #include <sys/types.h> 23 #include <sys/ioctl.h> 24 #include <sys/socket.h> 28 #include <sys/prctl.h> 34 #include <linux/icmp.h> 35 #include <arpa/inet.h> 37 #include <netinet/if_ether.h> 38 #include <net/if_arp.h> 39 #include <asm/byteorder.h> 42 #include <sys/epoll.h> 50 #define APP_NAME "ICMP_Responder" 51 #define IF_NAME "memif_connection" 55 #define DBG(...) do { \ 56 printf (APP_NAME":%s:%d: ", __func__, __LINE__); \ 57 printf (__VA_ARGS__); \ 64 #define INFO(...) do { \ 65 printf ("INFO: "__VA_ARGS__); \ 70 #define MAX_MEMIF_BUFS 256 100 printf (
"MEMIF DETAILS\n");
101 printf (
"==============================\n");
105 memset (&md, 0,
sizeof (md));
106 ssize_t buflen = 2048;
107 char *buf = malloc (buflen);
122 printf (
"\tinterface name: %s\n", (
char *) md.
if_name);
123 printf (
"\tapp name: %s\n", (
char *) md.
inst_name);
124 printf (
"\tremote interface name: %s\n", (
char *) md.
remote_if_name);
126 printf (
"\tid: %u\n", md.
id);
127 printf (
"\tsecret: %s\n", (
char *) md.
secret);
137 printf (
"ethernet\n");
143 printf (
"punt/inject\n");
146 printf (
"unknown\n");
151 printf (
"\trx queues:\n");
158 printf (
"\ttx queues:\n");
179 INFO (
"memif connected!");
188 INFO (
"memif disconnected!");
206 printf (
"LIBMEMIF EXAMPLE APP: %s",
APP_NAME);
211 printf (
"==============================\n");
218 printf (
"\tuse CTRL+C to exit\n");
236 DBG (
"allocated %d/%ld buffers, %u free buffers", r, n,
297 DBG (
"received %d buffers. %u/%u alloc/free buffers",
302 INFO (
"buffer_alloc error");
306 for (i = 0; i < rx; i++)
310 (
void *) (c->
tx_bufs + i)->data,
319 DBG (
"freed %d buffers. %u/%u alloc/free buffers",
331 DBG (
"freed %d buffers. %u/%u alloc/free buffers",
342 memset (&args, 0,
sizeof (args));
379 c->
tx_qid = strtol (argv[1], &end, 10);
412 DBG (
"poll_event error!");
int on_disconnect(memif_conn_handle_t conn, void *private_ctx)
uint8_t * remote_inst_name
#define LIBMEMIF_VERSION
Libmemif version.
int memif_refill_queue(memif_conn_handle_t conn, uint16_t qid, uint16_t count, uint16_t headroom)
Memif refill ring.
int on_connect(memif_conn_handle_t conn, void *private_ctx)
memset(h->entries, 0, sizeof(h->entries[0])*entries)
int memif_get_details(memif_conn_handle_t conn, memif_details_t *md, char *buf, ssize_t buflen)
Memif get details.
memif_interface_mode_t mode
char * memif_strerror(int err_code)
Memif strerror.
int icmpr_memif_create(int is_master)
uint8_t interface_name[32]
int resolve_packet(void *in_pck, ssize_t in_size, void *out_pck, uint32_t *out_size, uint8_t ip_addr[4])
uint8_t * socket_filename
struct memif_connection memif_connection_t
int memif_init(memif_control_fd_update_t *on_control_fd_update, char *app_name, memif_alloc_t *memif_alloc, memif_realloc_t *memif_realloc, memif_free_t *memif_free)
Memif initialization.
int icmpr_tx_burst(uint16_t qid)
int on_interrupt(memif_conn_handle_t conn, void *private_ctx, uint16_t qid)
int memif_tx_burst(memif_conn_handle_t conn, uint16_t qid, memif_buffer_t *bufs, uint16_t count, uint16_t *tx)
Memif transmit buffer burst.
int memif_buffer_alloc(memif_conn_handle_t conn, uint16_t qid, memif_buffer_t *bufs, uint16_t count, uint16_t *count_out, uint16_t size)
Memif buffer alloc.
int memif_poll_event(int timeout)
Memif poll event.
static void print_memif_details()
memif_queue_details_t * rx_queues
int memif_cleanup()
Memif cleanup.
int memif_create(memif_conn_handle_t *c, memif_conn_args_t *args, memif_connection_update_t *on_connect, memif_connection_update_t *on_disconnect, memif_interrupt_t *on_interrupt, void *private_ctx)
Memory interface create function.
memif_connection_t memif_connection
void * memif_conn_handle_t
Memif connection handle pointer of type void, pointing to internal structure.
int icmpr_buffer_alloc(long n, uint16_t qid)
int memif_rx_burst(memif_conn_handle_t conn, uint16_t qid, memif_buffer_t *bufs, uint16_t count, uint16_t *rx)
Memif receive buffer burst.
int memif_delete(memif_conn_handle_t *conn)
Memif delete.
int main(int argc, char *argv[])
memif_queue_details_t * tx_queues
uint16_t memif_get_version()
Memif get version.
Memif connection arguments.