2 // Copyright (c) 2017 Intel Corporation
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
19 * Pipeline CG-NAPT FE Implementation.
21 * Implementation of Pipeline CG-NAPT Front End (FE).
22 * Provides CLI support.
23 * Runs on master core.
27 #include <cmdline_parse.h>
28 #include <cmdline_parse_num.h>
29 #include <cmdline_parse_string.h>
30 #include <cmdline_parse_ipaddr.h>
31 #include <cmdline_parse_etheraddr.h>
32 #include <cmdline_rdline.h>
33 #include <cmdline_socket.h>
40 #include "pipeline_common_fe.h"
41 #include "pipeline_cgnapt.h"
42 #include "pipeline_cgnapt_common.h"
43 #include "pipeline_common_be.h"
44 #include "pipeline_cgnapt_be.h"
46 #include "cgnapt_pcp_fe.h"
49 #define MAX_BUF_SIZE 2048
52 * A structure defining the CG-NAPT entry that is stored on
55 struct app_pipeline_cgnapt_entry {
56 struct pipeline_cgnapt_entry_key key;
57 struct app_pipeline_cgnapt_entry_params params;
60 TAILQ_ENTRY(app_pipeline_cgnapt_entry) node;
64 * A structure defining the FE representation of a CG-NAPT pipeline
66 struct pipeline_cgnapt_t {
72 TAILQ_HEAD(, app_pipeline_cgnapt_entry) entries;
77 int nat_load_handler(struct mg_connection *conn, __rte_unused void *cbdata);
78 int nat_handler(struct mg_connection *conn, __rte_unused void *cbdata);
79 uint32_t rules_loaded = 0;
80 extern struct cmdline *pipe_cl;
81 struct app_params *myapp;
84 * Init function for CG-NAPT FE.
87 * A pointer to the pipeline params.
90 static void *pipeline_cgnapt_init(struct pipeline_params *params,
91 __rte_unused void *arg)
93 struct pipeline_cgnapt_t *p;
96 /* Check input arguments */
97 if ((params == NULL) ||
98 (params->n_ports_in == 0) || (params->n_ports_out == 0))
101 /* Memory allocation */
102 size = RTE_CACHE_LINE_ROUNDUP(sizeof(struct pipeline_cgnapt_t));
103 p = rte_zmalloc(NULL, size, RTE_CACHE_LINE_SIZE);
108 p->n_ports_in = params->n_ports_in;
109 p->n_ports_out = params->n_ports_out;
111 TAILQ_INIT(&p->entries);
118 * Function for CG-NAPT FE cleanup.
121 * A pointer to the pipeline.
124 static int app_pipeline_cgnapt_free(void *pipeline)
126 struct pipeline_cgnapt_t *p = pipeline;
128 /* Check input arguments */
133 while (!TAILQ_EMPTY(&p->entries)) {
134 struct app_pipeline_cgnapt_entry *entry;
136 entry = TAILQ_FIRST(&p->entries);
137 TAILQ_REMOVE(&p->entries, entry, node);
146 * Function to print an IPv6 address
149 * A uint8_t array containing an IPv6 address
151 static void print_ipv6_address_u8(uint8_t ipv6_addr[16])
153 printf("Ipv6Address-%x:%x:%x:%x:%x:%x:%x:%x:%x:%x:%x:%x:%x:%x:%x:%x\n",
154 ipv6_addr[0], ipv6_addr[1], ipv6_addr[2], ipv6_addr[3],
155 ipv6_addr[4], ipv6_addr[5], ipv6_addr[6], ipv6_addr[7],
156 ipv6_addr[8], ipv6_addr[9], ipv6_addr[10], ipv6_addr[11],
157 ipv6_addr[12], ipv6_addr[13], ipv6_addr[14], ipv6_addr[15]);
161 * Function to print an IPv6 address
164 * A uint16_t array containing an IPv6 address
166 static void print_ipv6_address_u16(uint16_t ipv6_addr[8])
168 printf("Ipv6Address-%x:%x:%x:%x:%x:%x:%x:%x\n", ipv6_addr[0],
169 ipv6_addr[1], ipv6_addr[2], ipv6_addr[3], ipv6_addr[4],
170 ipv6_addr[5], ipv6_addr[6], ipv6_addr[7]);
174 * Function to print an IPv6 address
177 * A uint32_t array containing an IPv6 address
179 static void print_ipv6_address_u32(uint32_t ipv6_addr[4])
181 printf("Ipv6Address: %x:%x:%x:%x\n", ipv6_addr[0], ipv6_addr[1],
182 ipv6_addr[2], ipv6_addr[3]);
186 * Function to print a NAPT entry
189 * A pointer to a NAPT entry
191 static void print_entry(const struct app_pipeline_cgnapt_entry *entry)
193 const struct pipeline_cgnapt_entry_key *key = &entry->key;
195 if (entry->params.type == CGNAPT_ENTRY_IPV4) {
196 printf("CGNAPT Entry: Key = %" PRIu32 ".%" PRIu32 ".%" PRIu32
197 ".%" PRIu32 ":%" PRIu32 ":%" PRIu16 " => Prv = %" PRIu32
198 ".%" PRIu32 ".%" PRIu32 ".%" PRIu32 ":%" PRIu32
199 " => Pub = %" PRIu32 ".%" PRIu32 ".%" PRIu32 ".%" PRIu32
200 ":%" PRIu32 " => ttl = %" PRIu32 "\n",
201 (key->ip >> 24) & 0xFF, (key->ip >> 16) & 0xFF,
202 (key->ip >> 8) & 0xFF, key->ip & 0xFF, key->port,
203 key->pid, (entry->params.u.prv_ip >> 24) & 0xFF,
204 (entry->params.u.prv_ip >> 16) & 0xFF,
205 (entry->params.u.prv_ip >> 8) & 0xFF,
206 entry->params.u.prv_ip & 0xFF, entry->params.prv_port,
207 (entry->params.pub_ip >> 24) & 0xFF,
208 (entry->params.pub_ip >> 16) & 0xFF,
209 (entry->params.pub_ip >> 8) & 0xFF,
210 entry->params.pub_ip & 0xFF, entry->params.pub_port,
213 printf("CGNAPT Entry: Key = %" PRIu32 ".%" PRIu32 ".%" PRIu32
214 ".%" PRIu32 ":%" PRIu32 ":%" PRIu16 " => Prv = %" PRIu32
215 "%" PRIu32 ":%" PRIu32 "%" PRIu32 ":%" PRIu32 "%" PRIu32
216 ":%" PRIu32 "%" PRIu32 ":%" PRIu32 "%" PRIu32 ":%" PRIu32
217 "%" PRIu32 ":%" PRIu32 "%" PRIu32 ":%" PRIu32 "%" PRIu32
218 ":%" PRIu32 " => Pub = %" PRIu32 ".%" PRIu32 ".%"
219 PRIu32 ".%" PRIu32 ":%" PRIu32 " => ttl = %" PRIu32
220 "\n", (key->ip >> 24) & 0xFF, (key->ip >> 16) & 0xFF,
221 (key->ip >> 8) & 0xFF, key->ip & 0xFF, key->port,
222 key->pid, entry->params.u.prv_ipv6[0],
223 entry->params.u.prv_ipv6[1], entry->params.u.prv_ipv6[2],
224 entry->params.u.prv_ipv6[3], entry->params.u.prv_ipv6[4],
225 entry->params.u.prv_ipv6[5], entry->params.u.prv_ipv6[6],
226 entry->params.u.prv_ipv6[7], entry->params.u.prv_ipv6[8],
227 entry->params.u.prv_ipv6[9],
228 entry->params.u.prv_ipv6[10],
229 entry->params.u.prv_ipv6[11],
230 entry->params.u.prv_ipv6[12],
231 entry->params.u.prv_ipv6[13],
232 entry->params.u.prv_ipv6[14],
233 entry->params.u.prv_ipv6[15], entry->params.prv_port,
234 (entry->params.pub_ip >> 24) & 0xFF,
235 (entry->params.pub_ip >> 16) & 0xFF,
236 (entry->params.pub_ip >> 8) & 0xFF,
237 entry->params.pub_ip & 0xFF, entry->params.pub_port,
244 * Function to list NAPT entries from FE storage
247 * A pointer to pipeline app
252 * 0 on success, negative on error.
255 app_pipeline_cgnapt_entry_ls(struct app_params *app, uint32_t pipeline_id)
257 struct pipeline_cgnapt_t *p;
258 struct app_pipeline_cgnapt_entry *it;
260 p = app_pipeline_data_fe(app, pipeline_id,
261 (struct pipeline_type *)&pipeline_cgnapt);
265 TAILQ_FOREACH(it, &p->entries, node)
267 print_static_cgnapt_entries();
268 printf(" - end of napt fe entry list -\n");
273 * Function to send a debug message to BE
276 * A pointer to pipeline app
280 * debug message contents
283 * 0 on success, negative on error.
286 app_pipeline_cgnapt_entry_dbg(struct app_params *app,
287 uint32_t pipeline_id, uint8_t *msg)
289 struct pipeline_cgnapt_t *p;
291 struct pipeline_cgnapt_entry_dbg_msg_req *req;
292 struct pipeline_cgnapt_entry_dbg_msg_rsp *rsp;
294 /* Check input arguments */
298 p = app_pipeline_data_fe(app, pipeline_id,
299 (struct pipeline_type *)&pipeline_cgnapt);
303 /* Allocate and write request */
304 req = app_msg_alloc(app);
308 req->type = PIPELINE_MSG_REQ_CUSTOM;
309 req->subtype = PIPELINE_CGNAPT_MSG_REQ_ENTRY_DBG;
310 req->data[0] = msg[0];
311 req->data[1] = msg[1];
312 req->data[2] = msg[2];
314 rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT_DEFAULT);
320 app_msg_free(app, rsp);
321 printf("Error rsp->status %d\n", rsp->status);
326 app_msg_free(app, rsp);
332 * Function to send a NAPT entry add message to BE
335 * A pointer to pipeline app
339 * A pointer to NAPT entry key
340 * @param entry_params
341 * A pointer to NAPT entry params
344 * 0 on success, negative on error.
346 int app_pipeline_cgnapt_add_entry(
347 struct app_params *app,
348 uint32_t pipeline_id,
349 struct app_pipeline_cgnapt_entry_params *entry_params)
351 struct pipeline_cgnapt_t *p;
353 struct pipeline_cgnapt_entry_add_msg_req *req;
354 struct pipeline_cgnapt_entry_add_msg_rsp *rsp;
356 /* Check input arguments */
357 if ((app == NULL) || (entry_params == NULL))
360 p = app_pipeline_data_fe(app, pipeline_id,
361 (struct pipeline_type *)&pipeline_cgnapt);
365 /* Allocate and write request */
366 req = app_msg_alloc(app);
370 req->type = PIPELINE_MSG_REQ_CUSTOM;
371 req->subtype = PIPELINE_CGNAPT_MSG_REQ_ENTRY_ADD;
372 memcpy(&req->data, entry_params, sizeof(*entry_params));
374 rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT_DEFAULT);
378 /* Message buffer free */
379 app_msg_free(app, rsp);
384 * Function to send a multiple NAPT entry add message to BE
387 * A pointer to pipeline app
391 * A pointer to NAPT entry key
392 * @param entry_params
393 * A pointer to multiple NAPT entry params
396 * 0 on success, negative on error.
398 int app_pipeline_cgnapt_addm_entry(
399 struct app_params *app,
400 uint32_t pipeline_id,
401 struct app_pipeline_cgnapt_mentry_params *entry_params)
403 struct pipeline_cgnapt_t *p;
405 struct pipeline_cgnapt_entry_addm_msg_req *req;
406 struct pipeline_cgnapt_entry_addm_msg_rsp *rsp;
408 /* Check input arguments */
409 if ((app == NULL) || (entry_params == NULL))
412 p = app_pipeline_data_fe(app, pipeline_id,
413 (struct pipeline_type *)&pipeline_cgnapt);
417 /* Allocate and write request */
418 req = app_msg_alloc(app);
422 req->type = PIPELINE_MSG_REQ_CUSTOM;
423 req->subtype = PIPELINE_CGNAPT_MSG_REQ_ENTRY_ADDM;
424 memcpy(&req->data, entry_params, sizeof(*entry_params));
426 rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT_DEFAULT);
430 /* Message buffer free */
431 app_msg_free(app, rsp);
436 * Function to send a NAPT entry delete message to BE
439 * A pointer to pipeline app
443 * A pointer to NAPT entry key
446 * 0 on success, negative on error.
449 app_pipeline_cgnapt_delete_entry(struct app_params *app,
450 uint32_t pipeline_id,
451 struct pipeline_cgnapt_entry_key *key)
453 struct pipeline_cgnapt_t *p;
455 struct pipeline_cgnapt_entry_delete_msg_req *req;
456 struct pipeline_cgnapt_entry_delete_msg_rsp *rsp;
459 uint8_t *KeyP = (uint8_t *) key;
462 printf("app_pipeline_cgnapt_delete_entry - Key: ");
463 for (i = 0; i < (int)sizeof(*key); i++)
464 printf(" %02x", KeyP[i]);
465 printf(" ,KeySize %u\n", (int)sizeof(*key));
467 /* Check input arguments */
468 if ((app == NULL) || (key == NULL))
471 p = app_pipeline_data_fe(app, pipeline_id,
472 (struct pipeline_type *)&pipeline_cgnapt);
476 /* Allocate and write request */
477 req = app_msg_alloc(app);
481 req->type = PIPELINE_MSG_REQ_CUSTOM;
482 req->subtype = PIPELINE_CGNAPT_MSG_REQ_ENTRY_DEL;
483 memcpy(&req->key, key, sizeof(*key));
485 rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT_DEFAULT);
490 if (rsp->status || !rsp->key_found) {
491 app_msg_free(app, rsp);
492 #ifdef CGNAPT_DBG_PRNT
493 printf("Successfully deleted the entry\n");
499 app_msg_free(app, rsp);
505 * A structure defining the entry add parse arguments.
507 struct cmd_entry_add_result {
508 cmdline_fixed_string_t p_string;
510 cmdline_fixed_string_t entry_string;
511 cmdline_fixed_string_t add_string;
512 cmdline_ipaddr_t prv_ip;
514 cmdline_ipaddr_t pub_ip;
520 * Helping function for add entry
522 * @param parsed_result
523 * A pointer parsed add arguments
525 * unused pointer to struct cmdline
531 cmd_entry_add_parsed(void *parsed_result,
532 __rte_unused struct cmdline *cl, void *data)
534 struct cmd_entry_add_result *params = parsed_result;
535 struct app_params *app = data;
536 struct app_pipeline_cgnapt_entry_params ent_params;
539 if (params->prv_ip.family == AF_INET) {
540 ent_params.type = CGNAPT_ENTRY_IPV4;
541 ent_params.u.prv_ip =
542 rte_bswap32((uint32_t) params->prv_ip.addr.ipv4.s_addr);
544 print_ipv6_address_u8(params->prv_ip.addr.ipv6.s6_addr);
545 print_ipv6_address_u16(params->prv_ip.addr.ipv6.s6_addr16);
546 print_ipv6_address_u32(params->prv_ip.addr.ipv6.s6_addr32);
547 ent_params.type = CGNAPT_ENTRY_IPV6;
548 memcpy(ent_params.u.prv_ipv6, params->prv_ip.addr.ipv6.s6_addr,
552 ent_params.prv_port = params->prv_port;
554 rte_bswap32((uint32_t) params->pub_ip.addr.ipv4.s_addr);
555 ent_params.pub_port = params->pub_port;
556 ent_params.prv_phy_port = params->pid;
557 ent_params.ttl = params->ttl;
559 status = app_pipeline_cgnapt_add_entry(app, params->p, &ent_params);
562 printf("CG-NAPT add multiple entry command failed, %d\n",
568 static cmdline_parse_token_string_t cmd_entry_add_p_string =
569 TOKEN_STRING_INITIALIZER(struct cmd_entry_add_result, p_string,
572 static cmdline_parse_token_num_t cmd_entry_add_p =
573 TOKEN_NUM_INITIALIZER(struct cmd_entry_add_result, p, UINT32);
575 static cmdline_parse_token_string_t cmd_entry_add_entry_string =
576 TOKEN_STRING_INITIALIZER(struct cmd_entry_add_result, entry_string,
579 static cmdline_parse_token_string_t cmd_entry_add_add_string =
580 TOKEN_STRING_INITIALIZER(struct cmd_entry_add_result, add_string,
583 static cmdline_parse_token_ipaddr_t cmd_entry_add_prv_ip =
584 TOKEN_IPADDR_INITIALIZER(struct cmd_entry_add_result, prv_ip);
586 static cmdline_parse_token_num_t cmd_entry_add_prv_port =
587 TOKEN_NUM_INITIALIZER(struct cmd_entry_add_result, prv_port, UINT16);
589 static cmdline_parse_token_ipaddr_t cmd_entry_add_pub_ip =
590 TOKEN_IPV4_INITIALIZER(struct cmd_entry_add_result, pub_ip);
592 static cmdline_parse_token_num_t cmd_entry_add_pub_port =
593 TOKEN_NUM_INITIALIZER(struct cmd_entry_add_result, pub_port, UINT16);
595 static cmdline_parse_token_num_t cmd_entry_add_pid =
596 TOKEN_NUM_INITIALIZER(struct cmd_entry_add_result, pid, UINT16);
598 static cmdline_parse_token_num_t cmd_entry_add_ttl =
599 TOKEN_NUM_INITIALIZER(struct cmd_entry_add_result, ttl, UINT32);
601 static cmdline_parse_inst_t cmd_entry_add = {
602 .f = cmd_entry_add_parsed,
604 .help_str = "NAPT entry add",
606 (void *)&cmd_entry_add_p_string,
607 (void *)&cmd_entry_add_p,
608 (void *)&cmd_entry_add_entry_string,
609 (void *)&cmd_entry_add_add_string,
610 (void *)&cmd_entry_add_prv_ip,
611 (void *)&cmd_entry_add_prv_port,
612 (void *)&cmd_entry_add_pub_ip,
613 (void *)&cmd_entry_add_pub_port,
614 (void *)&cmd_entry_add_pid,
615 (void *)&cmd_entry_add_ttl,
621 * A structure defining the multiple entry add parse arguments.
623 struct cmd_entry_addm_result {
624 cmdline_fixed_string_t p_string;
626 cmdline_fixed_string_t entry_string;
627 cmdline_fixed_string_t addm_string;
628 cmdline_ipaddr_t prv_ip;
630 cmdline_ipaddr_t pub_ip;
635 uint16_t prv_port_max;
636 uint16_t pub_port_max;
640 * Helping function for add multiple entries
642 * @param parsed_result
643 * A pointer parsed add arguments
645 * unused pointer to struct cmdline
650 cmd_entry_addm_parsed(void *parsed_result,
651 __rte_unused struct cmdline *cl, void *data)
653 struct cmd_entry_addm_result *params = parsed_result;
654 struct app_params *app = data;
655 struct app_pipeline_cgnapt_mentry_params ent_params;
658 if (params->prv_ip.family == AF_INET) {
659 ent_params.type = CGNAPT_ENTRY_IPV4;
660 ent_params.u.prv_ip =
661 rte_bswap32((uint32_t) params->prv_ip.addr.ipv4.s_addr);
663 print_ipv6_address_u8(params->prv_ip.addr.ipv6.s6_addr);
664 print_ipv6_address_u16(params->prv_ip.addr.ipv6.s6_addr16);
665 print_ipv6_address_u32(params->prv_ip.addr.ipv6.s6_addr32);
666 ent_params.type = CGNAPT_ENTRY_IPV6;
667 memcpy(ent_params.u.prv_ipv6, params->prv_ip.addr.ipv6.s6_addr,
671 ent_params.prv_port = params->prv_port;
673 rte_bswap32((uint32_t) params->pub_ip.addr.ipv4.s_addr);
674 ent_params.pub_port = params->pub_port;
675 ent_params.prv_phy_port = params->pid;
676 ent_params.ttl = params->ttl;
677 ent_params.num_ue = params->num_ue;
678 ent_params.prv_port_max = params->prv_port_max;
679 ent_params.pub_port_max = params->pub_port_max;
681 status = app_pipeline_cgnapt_addm_entry(app, params->p, &ent_params);
684 printf("CG-NAPT add multiple entry command failed, %d\n",
690 static cmdline_parse_token_string_t cmd_entry_add_addm_string =
691 TOKEN_STRING_INITIALIZER(struct cmd_entry_addm_result, addm_string,
694 static cmdline_parse_token_num_t cmd_entry_addm_prv_port =
695 TOKEN_NUM_INITIALIZER(struct cmd_entry_addm_result, prv_port_max, UINT16);
697 static cmdline_parse_token_num_t cmd_entry_addm_pub_port =
698 TOKEN_NUM_INITIALIZER(struct cmd_entry_addm_result, pub_port_max, UINT16);
700 static cmdline_parse_token_num_t cmd_entry_addm_max_ue =
701 TOKEN_NUM_INITIALIZER(struct cmd_entry_addm_result, num_ue, UINT32);
703 static cmdline_parse_inst_t cmd_entry_addm = {
704 .f = cmd_entry_addm_parsed,
706 .help_str = "NAPT entry add multiple",
708 (void *)&cmd_entry_add_p_string,
709 (void *)&cmd_entry_add_p,
710 (void *)&cmd_entry_add_entry_string,
711 (void *)&cmd_entry_add_addm_string,
712 (void *)&cmd_entry_add_prv_ip,
713 (void *)&cmd_entry_add_prv_port,
714 (void *)&cmd_entry_add_pub_ip,
715 (void *)&cmd_entry_add_pub_port,
716 (void *)&cmd_entry_add_pid,
717 (void *)&cmd_entry_add_ttl,
718 (void *)&cmd_entry_addm_max_ue,
719 (void *)&cmd_entry_addm_prv_port,
720 (void *)&cmd_entry_addm_pub_port,
726 * A structure defining the entry delete parse arguments.
728 struct cmd_entry_del_result {
729 cmdline_fixed_string_t p_string;
731 cmdline_fixed_string_t entry_string;
732 cmdline_fixed_string_t del_string;
739 * Helping function for delete entry
741 * @param parsed_result
742 * A pointer parsed add arguments
744 * unused pointer to struct cmdline
749 cmd_entry_del_parsed(void *parsed_result,
750 __rte_unused struct cmdline *cl, void *data)
752 struct cmd_entry_del_result *params = parsed_result;
753 struct app_params *app = data;
754 struct pipeline_cgnapt_entry_key key;
759 if (params->ip.family == AF_INET)
760 key.ip = rte_bswap32((uint32_t) params->ip.addr.ipv4.s_addr);
763 rte_bswap32((uint32_t) params->ip.addr.ipv6.s6_addr32[3]);
764 key.port = params->port;
765 key.pid = params->pid;
767 status = app_pipeline_cgnapt_delete_entry(app, params->p, &key);
770 printf("CG-NAPT entry del command failed\n");
775 static cmdline_parse_token_string_t cmd_entry_del_p_string =
776 TOKEN_STRING_INITIALIZER(struct cmd_entry_del_result, p_string,
779 static cmdline_parse_token_num_t cmd_entry_del_p =
780 TOKEN_NUM_INITIALIZER(struct cmd_entry_del_result, p, UINT32);
782 static cmdline_parse_token_string_t cmd_entry_del_entry_string =
783 TOKEN_STRING_INITIALIZER(struct cmd_entry_del_result, entry_string,
786 static cmdline_parse_token_string_t cmd_entry_del_del_string =
787 TOKEN_STRING_INITIALIZER(struct cmd_entry_del_result, del_string,
790 static cmdline_parse_token_ipaddr_t cmd_entry_del_ip =
791 TOKEN_IPADDR_INITIALIZER(struct cmd_entry_del_result, ip);
793 static cmdline_parse_token_num_t cmd_entry_del_port =
794 TOKEN_NUM_INITIALIZER(struct cmd_entry_del_result, port, UINT16);
796 static cmdline_parse_token_num_t cmd_entry_del_pid =
797 TOKEN_NUM_INITIALIZER(struct cmd_entry_del_result, pid, UINT16);
799 static cmdline_parse_inst_t cmd_entry_del = {
800 .f = cmd_entry_del_parsed,
802 .help_str = "Entry delete",
804 (void *)&cmd_entry_del_p_string,
805 (void *)&cmd_entry_del_p,
806 (void *)&cmd_entry_del_entry_string,
807 (void *)&cmd_entry_del_del_string,
808 (void *)&cmd_entry_del_ip,
809 (void *)&cmd_entry_del_port,
810 (void *)&cmd_entry_del_pid,
816 * A structure defining the list entry parse arguments.
818 struct cmd_entry_ls_result {
819 cmdline_fixed_string_t p_string;
821 cmdline_fixed_string_t entry_string;
822 cmdline_fixed_string_t ls_string;
826 * Helping function for list entry
828 * @param parsed_result
829 * A pointer parsed add arguments
831 * unused pointer to struct cmdline
836 cmd_entry_ls_parsed(void *parsed_result,
837 __rte_unused struct cmdline *cl, void *data)
839 struct cmd_entry_ls_result *params = parsed_result;
840 struct app_params *app = data;
843 status = app_pipeline_cgnapt_entry_ls(app, params->p);
846 printf("Ls command failed\n");
851 static cmdline_parse_token_string_t cmd_entry_ls_p_string =
852 TOKEN_STRING_INITIALIZER(struct cmd_entry_ls_result, p_string, "p");
854 static cmdline_parse_token_num_t cmd_entry_ls_p =
855 TOKEN_NUM_INITIALIZER(struct cmd_entry_ls_result, p, UINT32);
857 static cmdline_parse_token_string_t cmd_entry_ls_entry_string =
858 TOKEN_STRING_INITIALIZER(struct cmd_entry_ls_result,
859 entry_string, "entry");
861 static cmdline_parse_token_string_t cmd_entry_ls_ls_string =
862 TOKEN_STRING_INITIALIZER(struct cmd_entry_ls_result, ls_string,
865 static cmdline_parse_inst_t cmd_entry_ls = {
866 .f = cmd_entry_ls_parsed,
868 .help_str = "Entry list",
870 (void *)&cmd_entry_ls_p_string,
871 (void *)&cmd_entry_ls_p,
872 (void *)&cmd_entry_ls_entry_string,
873 (void *)&cmd_entry_ls_ls_string,
879 * A structure defining the dbg cmd parse arguments.
881 struct cmd_entry_dbg_result {
882 cmdline_fixed_string_t p_string;
884 cmdline_fixed_string_t entry_string;
885 cmdline_fixed_string_t dbg_string;
892 * Helping function for dbg cmd
894 * @param parsed_result
895 * A pointer parsed add arguments
897 * unused pointer to struct cmdline
902 cmd_entry_dbg_parsed(void *parsed_result,
903 __rte_unused struct cmdline *cl, void *data)
905 struct cmd_entry_dbg_result *params = parsed_result;
906 struct app_params *app = data;
910 msg[0] = params->cmd;
913 status = app_pipeline_cgnapt_entry_dbg(app, params->p, msg);
916 printf("Dbg Command failed\n");
921 static cmdline_parse_token_string_t cmd_entry_dbg_p_string =
922 TOKEN_STRING_INITIALIZER(struct cmd_entry_dbg_result, p_string, "p");
924 static cmdline_parse_token_num_t cmd_entry_dbg_p =
925 TOKEN_NUM_INITIALIZER(struct cmd_entry_dbg_result, p, UINT32);
927 static cmdline_parse_token_string_t cmd_entry_dbg_entry_string =
928 TOKEN_STRING_INITIALIZER(struct cmd_entry_dbg_result,
929 entry_string, "entry");
931 static cmdline_parse_token_string_t cmd_entry_dbg_dbg_string =
932 TOKEN_STRING_INITIALIZER(struct cmd_entry_dbg_result, dbg_string,
935 static cmdline_parse_token_num_t cmd_entry_dbg_cmd =
936 TOKEN_NUM_INITIALIZER(struct cmd_entry_dbg_result, cmd, UINT8);
938 static cmdline_parse_token_num_t cmd_entry_dbg_d1 =
939 TOKEN_NUM_INITIALIZER(struct cmd_entry_dbg_result, d1, UINT8);
941 static cmdline_parse_token_num_t cmd_entry_dbg_d2 =
942 TOKEN_NUM_INITIALIZER(struct cmd_entry_dbg_result, d2, UINT8);
944 static cmdline_parse_inst_t cmd_entry_dbg = {
945 .f = cmd_entry_dbg_parsed,
947 .help_str = "NAPT dbg cmd",
949 (void *)&cmd_entry_dbg_p_string,
950 (void *)&cmd_entry_dbg_p,
951 (void *)&cmd_entry_dbg_entry_string,
952 (void *)&cmd_entry_dbg_dbg_string,
953 (void *)&cmd_entry_dbg_cmd,
954 (void *)&cmd_entry_dbg_d1,
955 (void *)&cmd_entry_dbg_d2,
961 * A structure defining num ip clients cmd parse arguments.
963 struct cmd_numipcli_result {
964 cmdline_fixed_string_t p_string;
966 cmdline_fixed_string_t numipcli_string;
970 * Helping function for printing num ip clients
972 * @param parsed_result
973 * Unused pointer parsed add arguments
975 * unused pointer to struct cmdline
977 * Unused void pointer data
980 cmd_numipcli_parsed(__rte_unused void *parsed_result,
981 __rte_unused struct cmdline *cl, __rte_unused void *data)
983 print_num_ip_clients();
986 static cmdline_parse_token_string_t cmd_numipcli_p_string =
987 TOKEN_STRING_INITIALIZER(struct cmd_numipcli_result, p_string, "p");
989 static cmdline_parse_token_num_t cmd_numipcli_p =
990 TOKEN_NUM_INITIALIZER(struct cmd_numipcli_result, p, UINT32);
992 static cmdline_parse_token_string_t cmd_numipcli_string =
993 TOKEN_STRING_INITIALIZER(struct cmd_numipcli_result,
994 numipcli_string, "numipcli");
996 static cmdline_parse_inst_t cmd_numipcli = {
997 .f = cmd_numipcli_parsed,
999 .help_str = "Num IP Clients command",
1001 (void *)&cmd_numipcli_p_string,
1002 (void *)&cmd_numipcli_p,
1003 (void *)&cmd_numipcli_string,
1009 * Function to send a ver cmd message to BE
1012 * A pointer to pipeline app
1013 * @param pipeline_id
1016 * debug message contents
1019 * 0 on success, negative on error.
1022 app_pipeline_cgnapt_ver(struct app_params *app,
1023 uint32_t pipeline_id, uint8_t *msg)
1026 struct pipeline_cgnapt_t *p;
1027 struct pipeline_cgnapt_entry_dbg_msg_req *req;
1028 struct pipeline_cgnapt_entry_dbg_msg_rsp *rsp;
1030 /* Check input arguments */
1034 p = app_pipeline_data_fe(app, pipeline_id,
1035 (struct pipeline_type *)&pipeline_cgnapt);
1039 /* Allocate and write request */
1040 req = app_msg_alloc(app);
1044 req->type = PIPELINE_MSG_REQ_CUSTOM;
1045 req->subtype = PIPELINE_CGNAPT_MSG_REQ_VER;
1046 req->data[0] = msg[0];
1047 req->data[1] = msg[1];
1049 rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT_DEFAULT);
1055 app_msg_free(app, rsp);
1056 printf("Error rsp->status %d\n", rsp->status);
1061 app_msg_free(app, rsp);
1067 * A structure defining ver cmd parse arguments.
1069 struct cmd_ver_result {
1070 cmdline_fixed_string_t p_string;
1072 cmdline_fixed_string_t ver_string;
1078 * Helping function for ver cmd
1080 * @param parsed_result
1081 * A pointer parsed add arguments
1083 * unused pointer to struct cmdline
1088 cmd_ver_parsed(void *parsed_result, __rte_unused struct cmdline *cl, void *data)
1090 struct cmd_ver_result *params = parsed_result;
1091 struct app_params *app = data;
1095 msg[0] = params->cmd;
1096 msg[1] = params->d1;
1097 status = app_pipeline_cgnapt_ver(app, params->p, msg);
1100 printf("Version Command failed\n");
1105 static cmdline_parse_token_string_t cmd_ver_p_string =
1106 TOKEN_STRING_INITIALIZER(struct cmd_ver_result, p_string, "p");
1108 static cmdline_parse_token_num_t cmd_ver_p =
1109 TOKEN_NUM_INITIALIZER(struct cmd_ver_result, p, UINT32);
1111 static cmdline_parse_token_string_t cmd_ver_string =
1112 TOKEN_STRING_INITIALIZER(struct cmd_ver_result,
1115 static cmdline_parse_token_num_t cmd_ver_cmd =
1116 TOKEN_NUM_INITIALIZER(struct cmd_ver_result, cmd, UINT8);
1118 static cmdline_parse_token_num_t cmd_ver_d1 =
1119 TOKEN_NUM_INITIALIZER(struct cmd_ver_result, d1, UINT8);
1121 static cmdline_parse_inst_t cmd_ver = {
1122 .f = cmd_ver_parsed,
1124 .help_str = "NAPT ver cmd",
1126 (void *)&cmd_ver_p_string,
1128 (void *)&cmd_ver_string,
1129 (void *)&cmd_ver_cmd,
1130 (void *)&cmd_ver_d1,
1136 * Function to send a nsp add cmd message to BE
1139 * A pointer to pipeline app
1140 * @param pipeline_id
1143 * A pointer to struct pipeline_cgnapt_nsp_t
1146 * 0 on success, negative on error.
1149 app_pipeline_cgnapt_add_nsp(struct app_params *app,
1150 uint32_t pipeline_id,
1151 struct pipeline_cgnapt_nsp_t *nsp)
1154 struct pipeline_cgnapt_t *p;
1155 struct pipeline_cgnapt_nsp_add_msg_req *req;
1156 struct pipeline_cgnapt_nsp_add_msg_rsp *rsp;
1158 /* Check input arguments */
1162 printf("1st if condition\n");
1164 p = app_pipeline_data_fe(app, pipeline_id,
1165 (struct pipeline_type *)&pipeline_cgnapt);
1169 printf("2st if condition\n");
1170 /* Allocate and write request */
1171 req = app_msg_alloc(app);
1175 printf("3st if condition\n");
1176 req->type = PIPELINE_MSG_REQ_CUSTOM;
1177 req->subtype = PIPELINE_CGNAPT_MSG_REQ_NSP_ADD;
1178 memcpy(&req->nsp, nsp, sizeof(struct pipeline_cgnapt_nsp_t));
1180 rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT_DEFAULT);
1184 printf("4st if condition\n");
1187 app_msg_free(app, rsp);
1188 printf("Error rsp->status %d\n", rsp->status);
1193 app_msg_free(app, rsp);
1199 * A structure defining nsp add cmd parse arguments.
1201 struct cmd_nsp_add_result {
1202 cmdline_fixed_string_t p_string;
1204 cmdline_fixed_string_t nsp_string;
1205 cmdline_fixed_string_t add_string;
1206 cmdline_ipaddr_t ip;
1210 * Helping function for nsp add cmd
1212 * @param parsed_result
1213 * A pointer parsed add arguments
1215 * unused pointer to struct cmdline
1220 cmd_nsp_add_parsed(void *parsed_result, __rte_unused struct cmdline *cl,
1223 struct cmd_nsp_add_result *params = parsed_result;
1224 struct app_params *app = data;
1226 struct pipeline_cgnapt_nsp_t nsp;
1228 memcpy(&nsp.prefix, ¶ms->ip.addr.ipv6.s6_addr, 16);
1229 nsp.depth = params->ip.prefixlen;
1230 status = app_pipeline_cgnapt_add_nsp(app, params->p, &nsp);
1232 printf("NSP ADD Command failed\n");
1237 static cmdline_parse_token_string_t cmd_add_nsp_p_string =
1238 TOKEN_STRING_INITIALIZER(struct cmd_nsp_add_result, p_string, "p");
1240 static cmdline_parse_token_num_t cmd_add_nsp_p =
1241 TOKEN_NUM_INITIALIZER(struct cmd_nsp_add_result, p, UINT32);
1243 static cmdline_parse_token_string_t cmd_add_nsp_string =
1244 TOKEN_STRING_INITIALIZER(struct cmd_nsp_add_result,
1247 static cmdline_parse_token_string_t cmd_add_nsp_add_string =
1248 TOKEN_STRING_INITIALIZER(struct cmd_nsp_add_result,
1251 static cmdline_parse_token_ipaddr_t cmd_add_nsp_ip =
1252 TOKEN_IPNET_INITIALIZER(struct cmd_nsp_add_result, ip);
1254 static cmdline_parse_inst_t cmd_nsp_add = {
1255 .f = cmd_nsp_add_parsed,
1257 .help_str = "NAPT NSP ADD cmd",
1259 (void *)&cmd_add_nsp_p_string,
1260 (void *)&cmd_add_nsp_p,
1261 (void *)&cmd_add_nsp_string,
1262 (void *)&cmd_add_nsp_add_string,
1263 (void *)&cmd_add_nsp_ip,
1269 * Function to send a nsp del cmd message to BE
1272 * A pointer to pipeline app
1273 * @param pipeline_id
1276 * A pointer to struct pipeline_cgnapt_nsp_t
1279 * 0 on success, negative on error.
1282 app_pipeline_cgnapt_del_nsp(struct app_params *app,
1283 uint32_t pipeline_id,
1284 struct pipeline_cgnapt_nsp_t *nsp)
1287 struct pipeline_cgnapt_t *p;
1288 struct pipeline_cgnapt_nsp_del_msg_req *req;
1289 struct pipeline_cgnapt_nsp_del_msg_rsp *rsp;
1291 /* Check input arguments */
1295 p = app_pipeline_data_fe(app, pipeline_id,
1296 (struct pipeline_type *)&pipeline_cgnapt);
1300 /* Allocate and write request */
1301 req = app_msg_alloc(app);
1305 req->type = PIPELINE_MSG_REQ_CUSTOM;
1306 req->subtype = PIPELINE_CGNAPT_MSG_REQ_NSP_DEL;
1307 memcpy(&req->nsp, nsp, sizeof(struct pipeline_cgnapt_nsp_t));
1309 rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT_DEFAULT);
1315 app_msg_free(app, rsp);
1316 printf("Error rsp->status %d\n", rsp->status);
1321 app_msg_free(app, rsp);
1327 * A structure defining nsp del cmd parse arguments.
1329 struct cmd_nsp_del_result {
1330 cmdline_fixed_string_t p_string;
1332 cmdline_fixed_string_t nsp_string;
1333 cmdline_fixed_string_t del_string;
1334 cmdline_ipaddr_t ip;
1338 * Helping function for nsp del cmd
1340 * @param parsed_result
1341 * A pointer parsed add arguments
1343 * unused pointer to struct cmdline
1348 cmd_nsp_del_parsed(void *parsed_result, __rte_unused struct cmdline *cl,
1351 struct cmd_nsp_del_result *params = parsed_result;
1352 struct app_params *app = data;
1354 struct pipeline_cgnapt_nsp_t nsp;
1356 memcpy(&nsp.prefix, ¶ms->ip.addr.ipv6.s6_addr, 16);
1357 nsp.depth = params->ip.prefixlen;
1358 status = app_pipeline_cgnapt_del_nsp(app, params->p, &nsp);
1361 printf("NSP DEL Command failed\n");
1366 static cmdline_parse_token_string_t cmd_del_nsp_p_string =
1367 TOKEN_STRING_INITIALIZER(struct cmd_nsp_del_result, p_string, "p");
1369 static cmdline_parse_token_num_t cmd_del_nsp_p =
1370 TOKEN_NUM_INITIALIZER(struct cmd_nsp_del_result, p, UINT32);
1372 static cmdline_parse_token_string_t cmd_del_nsp_string =
1373 TOKEN_STRING_INITIALIZER(struct cmd_nsp_del_result,
1376 static cmdline_parse_token_string_t cmd_del_nsp_del_string =
1377 TOKEN_STRING_INITIALIZER(struct cmd_nsp_del_result,
1380 static cmdline_parse_token_ipaddr_t cmd_del_nsp_ip =
1381 TOKEN_IPNET_INITIALIZER(struct cmd_nsp_del_result, ip);
1383 static cmdline_parse_inst_t cmd_nsp_del = {
1384 .f = cmd_nsp_del_parsed,
1386 .help_str = "NAPT NSP DEL cmd",
1388 (void *)&cmd_del_nsp_p_string,
1389 (void *)&cmd_del_nsp_p,
1390 (void *)&cmd_del_nsp_string,
1391 (void *)&cmd_del_nsp_del_string,
1392 (void *)&cmd_del_nsp_ip,
1398 * A structure defining the cgnapt stats cmd parse arguments.
1400 struct cmd_cgnapt_stats_result {
1401 cmdline_fixed_string_t p_string;
1402 cmdline_fixed_string_t cgnapt_string;
1403 cmdline_fixed_string_t stats_string;
1407 * Helping function for cgnapt stats cmd
1409 * @param parsed_result
1410 * A pointer parsed add arguments
1412 * unused pointer to struct cmdline
1417 cmd_cgnapt_stats_parsed(
1418 __rte_unused void *parsed_result,
1419 __rte_unused struct cmdline *cl,
1420 __rte_unused void *data)
1423 all_cgnapt_stats(&buf[0]);
1426 static cmdline_parse_token_string_t cmd_cgnapt_stats_p_string =
1427 TOKEN_STRING_INITIALIZER(struct cmd_cgnapt_stats_result, p_string, "p");
1429 static cmdline_parse_token_string_t cmd_cgnapt_stats_cgnapt_string =
1430 TOKEN_STRING_INITIALIZER(struct cmd_cgnapt_stats_result,
1431 cgnapt_string, "cgnapt");
1433 static cmdline_parse_token_string_t cmd_cgnapt_stats_stats_string =
1434 TOKEN_STRING_INITIALIZER(struct cmd_cgnapt_stats_result, stats_string,
1437 static cmdline_parse_inst_t cmd_stats = {
1438 .f = cmd_cgnapt_stats_parsed,
1440 .help_str = "CGNAPT stats cmd",
1442 (void *)&cmd_cgnapt_stats_p_string,
1443 (void *)&cmd_cgnapt_stats_cgnapt_string,
1444 (void *)&cmd_cgnapt_stats_stats_string,
1450 * A structure defining the cgnapt clear stats cmd parse arguments.
1452 struct cmd_cgnapt_clear_stats_result {
1453 cmdline_fixed_string_t p_string;
1454 cmdline_fixed_string_t cgnapt_string;
1455 cmdline_fixed_string_t clear_string;
1456 cmdline_fixed_string_t stats_string;
1460 * Helping function for cgnapt clear stats cmd
1462 * @param parsed_result
1463 * A pointer parsed add arguments
1465 * unused pointer to struct cmdline
1470 cmd_cgnapt_clear_stats_parsed(
1471 __rte_unused void *parsed_result,
1472 __rte_unused struct cmdline *cl,
1473 __rte_unused void *data)
1476 all_cgnapt_clear_stats(&buf[0]);
1479 static cmdline_parse_token_string_t cmd_cgnapt_clear_stats_p_string =
1480 TOKEN_STRING_INITIALIZER(struct cmd_cgnapt_clear_stats_result, p_string, "p");
1482 static cmdline_parse_token_string_t cmd_cgnapt_clear_stats_cgnapt_string =
1483 TOKEN_STRING_INITIALIZER(struct cmd_cgnapt_clear_stats_result,
1484 cgnapt_string, "cgnapt");
1486 static cmdline_parse_token_string_t cmd_cgnapt_clear_stats_clear_string =
1487 TOKEN_STRING_INITIALIZER(struct cmd_cgnapt_clear_stats_result,
1488 clear_string, "clear");
1490 static cmdline_parse_token_string_t cmd_cgnapt_clear_stats_stats_string =
1491 TOKEN_STRING_INITIALIZER(struct cmd_cgnapt_clear_stats_result, stats_string,
1494 int cgnapt_stats_handler(struct mg_connection *conn, void *cbdata)
1496 uint32_t num_links = 0, len = 0;
1498 const struct mg_request_info *ri = mg_get_request_info(conn);
1499 struct app_params *app = myapp;
1502 if (!strcmp(ri->request_method, "GET")) {
1503 all_cgnapt_stats(&buf[0]);
1504 mg_printf(conn, "%s\n", &buf[0]);
1508 if (strcmp(ri->request_method, "POST")) {
1510 "HTTP/1.1 405 Method Not Allowed\r\nConnection: close\r\n");
1511 mg_printf(conn, "Content-Type: text/plain\r\n\r\n");
1513 "%s method not allowed in the GET handler\n",
1514 ri->request_method);
1517 all_cgnapt_clear_stats(&buf[0]);
1518 mg_printf(conn, "%s\n", &buf[0]);
1523 int cgnapt_cmd_ver_handler(struct mg_connection *conn, void *cbdata)
1525 const struct mg_request_info *req_info = mg_get_request_info(conn);
1528 "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nConnection: "
1530 mg_printf(conn, "<html><body>");
1531 mg_printf(conn, "<p>Command Passed</p>");
1532 mg_printf(conn, "</body></html>\n");
1542 * Open file and process all commands in the file.
1545 * A pointer to the CLI context
1547 * A pointer to the file to process.
1550 static void cgnapt_loadrules_file(cmdline_parse_ctx_t *ctx, const char *file_name)
1552 struct cmdline *file_cl;
1555 fd = open(file_name, O_RDONLY);
1557 printf("Cannot open file \"%s\"\n", file_name);
1561 file_cl = cmdline_new(ctx, "", fd, 1);
1562 cmdline_interact(file_cl);
1567 int nat_handler(struct mg_connection *conn, __rte_unused void *cbdata)
1570 const struct mg_request_info *req_info = mg_get_request_info(conn);
1571 if (strcmp(req_info->request_method, "GET")) {
1572 mg_printf(conn, "Only GET method allowed");
1577 "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nConnection: "
1579 mg_printf(conn, "<html><body>");
1580 mg_printf(conn, "<h2> These are the methods that are supported </h2>");
1581 mg_printf(conn, "<h3> /load </h3>");
1582 mg_printf(conn, "<html><body>");
1584 mg_printf(conn, "</body></html>\n");
1589 static int nat_field_found(const char *key,
1590 const char *filename,
1595 struct mg_connection *conn = (struct mg_connection *)user_data;
1597 mg_printf(conn, "\r\n\r\n%s:\r\n", key);
1598 mg_printf(conn, "Inside vfw_field_found %s \n", filename);
1600 if (filename && *filename) {
1601 snprintf(path, pathlen, "/tmp/%s", filename);
1602 struct app_params *app = myapp;
1606 mg_printf(conn, "path: %s\n", path);
1608 /* Make sure the file exists before clearing rules and actions */
1609 fd = open(path, O_RDONLY);
1611 mg_printf(conn, "Cannot open file \"%s\"\n", filename);
1612 return FORM_FIELD_STORAGE_GET;
1616 return FORM_FIELD_STORAGE_STORE;
1619 return FORM_FIELD_STORAGE_GET;
1622 static int nat_field_get(const char *key, const char *value, size_t valuelen,
1625 struct mg_connection *conn = (struct mg_connection *)user_data;
1628 mg_printf(conn, "%s = ", key);
1630 mg_write(conn, value, valuelen);
1635 static int nat_field_stored(const char *path, long long file_size,
1638 struct mg_connection *conn = (struct mg_connection *)user_data;
1642 "stored as %s (%lu bytes)\r\n\r\n",
1644 (unsigned long)file_size);
1646 /* Process commands in script file */
1647 cgnapt_loadrules_file(pipe_cl->ctx, path);
1653 int nat_load_handler(struct mg_connection *conn, __rte_unused void *cbdata)
1655 /* Handler may access the request info using mg_get_request_info */
1657 const struct mg_request_info *req_info = mg_get_request_info(conn);
1658 struct mg_form_data_handler fdh = {nat_field_found, nat_field_get,
1659 nat_field_stored, 0};
1661 /* It would be possible to check the request info here before calling
1662 * mg_handle_form_request. */
1666 "HTTP/1.1 200 OK\r\nContent-Type: "
1667 "text/plain\r\nConnection: close\r\n\r\n");
1669 if (!strcmp(req_info->request_method, "GET")) {
1670 mg_printf(conn, "Rule file is %s\n", rules_loaded? "LOADED":"NOT LOADED");
1673 if (strcmp(req_info->request_method, "PUT")) {
1674 mg_printf(conn, "Only PUT method allowed");
1678 fdh.user_data = (void *)conn;
1680 /* Call the form handler */
1681 mg_printf(conn, "Form data:");
1682 ret = mg_handle_form_request(conn, &fdh);
1683 mg_printf(conn, "\r\n%i fields found", ret);
1688 void rest_api_cgnapt_init(struct mg_context *ctx, struct app_params *app)
1692 /* vCGNAPT commands */
1693 mg_set_request_handler(ctx, "/vnf/config/nat", nat_handler, 0);
1694 mg_set_request_handler(ctx, "/vnf/config/nat/load", nat_load_handler, 0);
1695 mg_set_request_handler(ctx, "/vnf/status", cgnapt_cmd_ver_handler, 0);
1696 mg_set_request_handler(ctx, "/vnf/stats", cgnapt_stats_handler, 0);
1700 static cmdline_parse_inst_t cmd_clear_stats = {
1701 .f = cmd_cgnapt_clear_stats_parsed,
1703 .help_str = "CGNAPT clear stats cmd",
1705 (void *)&cmd_cgnapt_clear_stats_p_string,
1706 (void *)&cmd_cgnapt_clear_stats_cgnapt_string,
1707 (void *)&cmd_cgnapt_clear_stats_clear_string,
1708 (void *)&cmd_cgnapt_clear_stats_stats_string,
1714 static cmdline_parse_ctx_t pipeline_cmds[] = {
1715 (cmdline_parse_inst_t *) &cmd_entry_add,
1716 (cmdline_parse_inst_t *) &cmd_entry_del,
1717 (cmdline_parse_inst_t *) &cmd_entry_ls,
1718 (cmdline_parse_inst_t *) &cmd_entry_dbg,
1719 (cmdline_parse_inst_t *) &cmd_entry_addm,
1720 (cmdline_parse_inst_t *) &cmd_ver,
1721 (cmdline_parse_inst_t *) &cmd_nsp_add,
1722 (cmdline_parse_inst_t *) &cmd_nsp_del,
1723 (cmdline_parse_inst_t *) &cmd_numipcli,
1725 (cmdline_parse_inst_t *) &cmd_pcp,
1727 (cmdline_parse_inst_t *) &cmd_stats,
1728 (cmdline_parse_inst_t *) &cmd_clear_stats,
1732 static struct pipeline_fe_ops pipeline_cgnapt_fe_ops = {
1733 .f_init = pipeline_cgnapt_init,
1734 .f_free = app_pipeline_cgnapt_free,
1735 .cmds = pipeline_cmds,
1738 struct pipeline_type pipeline_cgnapt = {
1740 .be_ops = &pipeline_cgnapt_be_ops,
1741 .fe_ops = &pipeline_cgnapt_fe_ops,