Jakub Grajciar | e74c04f | 2021-01-04 11:28:33 +0100 | [diff] [blame] | 1 | #include <common.h> |
| 2 | |
| 3 | void |
| 4 | print_memif_ring_details (memif_connection_t *c, uint16_t qid, uint8_t is_rx) |
| 5 | { |
| 6 | /* TODO: print memif shared memory details */ |
| 7 | } |
| 8 | |
| 9 | void |
| 10 | print_memif_rx_ring_details (memif_connection_t *c, uint16_t qid) |
| 11 | { |
| 12 | print_memif_ring_details (c, qid, /* RX */ 1); |
| 13 | } |
| 14 | |
| 15 | void |
| 16 | print_memif_tx_ring_details (memif_connection_t *c, uint16_t qid) |
| 17 | { |
| 18 | print_memif_ring_details (c, qid, /* TX */ 0); |
| 19 | } |
| 20 | |
| 21 | void |
| 22 | print_version () |
| 23 | { |
| 24 | printf ("libmemif version: %s, memif version: %s\n", LIBMEMIF_VERSION, |
| 25 | memif_get_version_str ()); |
| 26 | } |
| 27 | |
| 28 | int |
| 29 | parse_ip4 (const char *input, uint8_t out[4]) |
| 30 | { |
| 31 | char *ui, *end; |
| 32 | char *tmp = strdup (input); |
| 33 | |
| 34 | ui = strtok (tmp, "."); |
| 35 | if (ui == NULL) |
| 36 | return -1; |
| 37 | out[0] = strtol (ui, &end, 10); |
| 38 | |
| 39 | ui = strtok (NULL, "."); |
| 40 | if (ui == NULL) |
| 41 | return -1; |
| 42 | out[1] = strtol (ui, &end, 10); |
| 43 | |
| 44 | ui = strtok (NULL, "."); |
| 45 | if (ui == NULL) |
| 46 | return -1; |
| 47 | out[2] = strtol (ui, &end, 10); |
| 48 | |
| 49 | ui = strtok (NULL, "."); |
| 50 | if (ui == NULL) |
| 51 | return -1; |
| 52 | out[3] = strtol (ui, &end, 10); |
| 53 | |
| 54 | free (tmp); |
| 55 | |
| 56 | return 0; |
| 57 | } |
| 58 | |
| 59 | int |
| 60 | parse_mac (const char *input, uint8_t out[6]) |
| 61 | { |
| 62 | char *ui, *end; |
| 63 | char *tmp = strdup (input); |
| 64 | |
| 65 | ui = strtok (tmp, ":"); |
| 66 | if (ui == NULL) |
| 67 | return -1; |
| 68 | out[0] = strtol (ui, &end, 16); |
| 69 | ui = strtok (NULL, ":"); |
| 70 | if (ui == NULL) |
| 71 | return -1; |
| 72 | out[1] = strtol (ui, &end, 16); |
| 73 | ui = strtok (NULL, ":"); |
| 74 | if (ui == NULL) |
| 75 | return -1; |
| 76 | out[2] = strtol (ui, &end, 16); |
| 77 | ui = strtok (NULL, ":"); |
| 78 | if (ui == NULL) |
| 79 | return -1; |
| 80 | out[3] = strtol (ui, &end, 16); |
| 81 | ui = strtok (NULL, ":"); |
| 82 | if (ui == NULL) |
| 83 | return -1; |
| 84 | out[4] = strtol (ui, &end, 16); |
| 85 | ui = strtok (NULL, ":"); |
| 86 | if (ui == NULL) |
| 87 | return -1; |
| 88 | out[5] = strtol (ui, &end, 16); |
| 89 | |
| 90 | free (tmp); |
| 91 | |
| 92 | return 0; |
| 93 | } |
| 94 | |
| 95 | void |
| 96 | alloc_memif_buffers (memif_connection_t *c) |
| 97 | { |
| 98 | c->rx_bufs = |
| 99 | (memif_buffer_t *) malloc (sizeof (memif_buffer_t) * MAX_MEMIF_BUFS); |
| 100 | c->rx_buf_num = 0; |
| 101 | c->tx_bufs = |
| 102 | (memif_buffer_t *) malloc (sizeof (memif_buffer_t) * MAX_MEMIF_BUFS); |
| 103 | c->tx_buf_num = 0; |
| 104 | } |
| 105 | |
| 106 | void |
| 107 | free_memif_buffers (memif_connection_t *c) |
| 108 | { |
| 109 | if (c->rx_bufs != NULL) |
| 110 | free (c->rx_bufs); |
| 111 | c->rx_bufs = NULL; |
| 112 | c->rx_buf_num = 0; |
| 113 | if (c->tx_bufs != NULL) |
| 114 | free (c->tx_bufs); |
| 115 | c->tx_bufs = NULL; |
| 116 | c->tx_buf_num = 0; |
| 117 | } |
| 118 | |
| 119 | void |
| 120 | print_memif_details (memif_connection_t *c) |
| 121 | { |
| 122 | printf ("MEMIF DETAILS\n"); |
| 123 | printf ("==============================\n"); |
| 124 | |
| 125 | memif_details_t md; |
| 126 | memset (&md, 0, sizeof (md)); |
| 127 | ssize_t buflen = 2048; |
| 128 | char *buf = (char *) malloc (buflen); |
| 129 | memset (buf, 0, buflen); |
| 130 | int err, e; |
| 131 | |
| 132 | err = memif_get_details (c->conn, &md, buf, buflen); |
| 133 | if (err != MEMIF_ERR_SUCCESS) |
| 134 | { |
| 135 | INFO ("%s", memif_strerror (err)); |
| 136 | if (err == MEMIF_ERR_NOCONN) |
| 137 | { |
| 138 | free (buf); |
| 139 | return; |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | printf ("\tinterface name: %s\n", (char *) md.if_name); |
| 144 | printf ("\tapp name: %s\n", (char *) md.inst_name); |
| 145 | printf ("\tremote interface name: %s\n", (char *) md.remote_if_name); |
| 146 | printf ("\tremote app name: %s\n", (char *) md.remote_inst_name); |
| 147 | printf ("\tid: %u\n", md.id); |
| 148 | printf ("\tsecret: %s\n", (char *) md.secret); |
| 149 | printf ("\trole: "); |
| 150 | if (md.role) |
| 151 | printf ("slave\n"); |
| 152 | else |
| 153 | printf ("master\n"); |
| 154 | printf ("\tmode: "); |
| 155 | switch (md.mode) |
| 156 | { |
| 157 | case 0: |
| 158 | printf ("ethernet\n"); |
| 159 | break; |
| 160 | case 1: |
| 161 | printf ("ip\n"); |
| 162 | break; |
| 163 | case 2: |
| 164 | printf ("punt/inject\n"); |
| 165 | break; |
| 166 | default: |
| 167 | printf ("unknown\n"); |
| 168 | break; |
| 169 | } |
| 170 | printf ("\tsocket path: %s\n", (char *) md.socket_path); |
| 171 | printf ("\trx queues:\n"); |
| 172 | for (e = 0; e < md.rx_queues_num; e++) |
| 173 | { |
| 174 | printf ("\t\tqueue id: %u\n", md.rx_queues[e].qid); |
| 175 | printf ("\t\tring size: %u\n", md.rx_queues[e].ring_size); |
| 176 | printf ("\t\tbuffer size: %u\n", md.rx_queues[e].buffer_size); |
| 177 | } |
| 178 | printf ("\ttx queues:\n"); |
| 179 | for (e = 0; e < md.tx_queues_num; e++) |
| 180 | { |
| 181 | printf ("\t\tqueue id: %u\n", md.tx_queues[e].qid); |
| 182 | printf ("\t\tring size: %u\n", md.tx_queues[e].ring_size); |
| 183 | printf ("\t\tbuffer size: %u\n", md.tx_queues[e].buffer_size); |
| 184 | } |
| 185 | printf ("\tlink: "); |
| 186 | if (md.link_up_down) |
| 187 | printf ("up\n"); |
| 188 | else |
| 189 | printf ("down\n"); |
| 190 | |
| 191 | free (buf); |
| 192 | } |