Wednesday, March 23, 2016

Patch draft to make mTCP+DPDK work in vlan tagged network

Here is a patch idea draft to make mTCP + DPDK work in vlan tagged environment,  the next thing is to figure out how to run mTCP + DPDK in vlan tagged VMware ESXi environment, which would be great to run mTCP + DPDK in VMware ESXi VM and easy to clone the VM for everybody need it

 diff --git a/mtcp/src/dpdk_module.c b/mtcp/src/dpdk_module.c  

 index 33d349e..3c08e25 100644
 --- a/mtcp/src/dpdk_module.c
 +++ b/mtcp/src/dpdk_module.c
 @@ -66,7 +66,7 @@ static uint16_t nb_txd = RTE_TEST_TX_DESC_DEFAULT;
  /* packet memory pools for storing packet bufs */
  static struct rte_mempool *pktmbuf_pool[MAX_CPUS] = {NULL};
 -//#define DEBUG                1
 +#define DEBUG             1
  #ifdef DEBUG
  /* ethernet addresses of ports */
  static struct ether_addr ports_eth_addr[RTE_MAX_ETHPORTS];
 @@ -79,7 +79,8 @@ static struct rte_eth_conf port_conf = {
         .split_hdr_size =    0,
         .header_split  =    0, /**< Header Split disabled */
         .hw_ip_checksum =    1, /**< IP checksum offload enabled */
 -        .hw_vlan_filter =    0, /**< VLAN filtering disabled */
 +        .hw_vlan_filter =    1, /**< VLAN filtering disabled */
 +        .hw_vlan_strip =    1, /**< VLAN strip enabled */
         .jumbo_frame  =    0, /**< Jumbo Frame Support disabled */
         .hw_strip_crc  =    1, /**< CRC stripped by hardware */
     },
 @@ -127,6 +128,7 @@ static const struct rte_eth_txconf tx_conf = {
     .txq_flags =          0x0,
  };
 +
  struct mbuf_table {
     unsigned len; /* length of queued packets */
     struct rte_mbuf *m_table[MAX_PKT_BURST];
 @@ -266,6 +268,8 @@ dpdk_send_pkts(struct mtcp_thread_context *ctxt, int nif)
                       ctxt->cpu, i, nif);
                 exit(EXIT_FAILURE);
             }
 +            dpc->wmbufs[nif].m_table[i]->ol_flags = PKT_TX_VLAN_PKT;
 +            dpc->wmbufs[nif].m_table[i]->vlan_tci = 4094;
         }
         /* reset the len of mbufs var after flushing of packets */
         dpc->wmbufs[nif].len = 0;
 @@ -534,6 +538,12 @@ dpdk_load_module(void)
             if (ret < 0)
                 rte_exit(EXIT_FAILURE, "Cannot configure device: err=%d, port=%u\n",
                      ret, (unsigned) portid);
 +
 +            ret = rte_eth_dev_vlan_filter(portid, 4094, 1);
 +
 +            if (ret < 0)
 +                rte_exit(EXIT_FAILURE, "Cannot configure device: err=%d, port=%u\n",
 +                    ret, (unsigned) portid);
             /* init one RX queue per CPU */
             fflush(stdout);

Friday, March 18, 2016

Patch to make lighttpd run in multiple core properly with mtcp with the configuration

diff --git a/apps/lighttpd-1.4.32/src/server.c b/apps/lighttpd-1.4.32/src/server.c
index 7c76fd7..f0dde58 100644
--- a/apps/lighttpd-1.4.32/src/server.c
+++ b/apps/lighttpd-1.4.32/src/server.c
@@ -1213,7 +1213,8 @@ int
 main(int argc, char **argv) {
 #ifdef MULTI_THREADED
        server **srv_states = NULL;
-       char *conf_file = NULL;
+       //char *conf_file = NULL;
+       char *conf_file = "/etc/mtcp/config/m-lighttpd.conf";
 #ifdef USE_MTCP
        struct mtcp_conf mcfg;
 #endif
@@ -1594,7 +1595,7 @@ main(int argc, char **argv) {
        mcfg.num_cores = cpus;
        mtcp_setconf(&mcfg);
        /* initialize the mtcp context */
-       if (mtcp_init("mtcp.conf")) {
+       if (mtcp_init("/etc/mtcp/config/lighttpd-mtcp.conf")) {
                fprintf(stderr, "Failed to initialize mtcp\n");
                goto clean_up;
        }

diff --git a/mtcp/src/config.c b/mtcp/src/config.c
index c4faea5..b4e24d0 100644
--- a/mtcp/src/config.c
+++ b/mtcp/src/config.c
@@ -23,8 +23,8 @@
 #define MAX_OPTLINE_LEN 1024
 #define ALL_STRING "all"

-static const char *route_file = "config/route.conf";
-static const char *arp_file = "config/arp.conf";
+static const char *route_file = "/etc/mtcp/config/route.conf";
+static const char *arp_file = "/etc/mtcp/config/arp.conf";


the configuration directory looks like:

root@pktgen:/home/pktgen/mtcp# ls -l /etc/mtcp/config/
total 48
-rw-r--r-- 1 root root   530 Mar  4 14:18 arp.conf
-rw-r--r-- 1 root root  1360 Nov 13 10:34 brute-shake.conf
drwxr-xr-x 2 root root  4096 Mar  4 14:43 conf.d
-rw-r--r-- 1 root root  1370 Nov 13 10:32 epwget.conf
-rw-r--r-- 1 root root  1237 Mar  4 14:15 lighttpd-mtcp.conf
-rw-r--r-- 1 root root 11857 Mar  4 14:40 m-lighttpd.conf
-rw-r--r-- 1 root root  3235 Mar  4 14:42 modules.conf
-rw-r--r-- 1 root root   646 Nov 12 20:18 mtcp.conf
-rw-r--r-- 1 root root   352 Mar  4 14:19 route.conf
-rw-r--r-- 1 root root  1366 Nov 13 10:38 synflood.conf


top output:


top - 14:14:15 up 18 days, 35 min,  4 users,  load average: 7.98, 5.51, 2.53
Threads: 304 total,   9 running, 295 sleeping,   0 stopped,   0 zombie

  PID USER      PR  NI    VIRT    RES    SHR S %CPU %MEM     TIME+ COMMAND                                                                                                                                                                  P
15707 root      20   0 14.071g 0.010t   9680 R 99.9 14.9   5:44.92 lighttpd -n 8 -f /etc/mtcp/config/m-lighttpd.conf                                                                                                                        1
15730 root      20   0 14.071g 0.010t   9680 R 99.9 14.9   5:44.93 lighttpd -n 8 -f /etc/mtcp/config/m-lighttpd.conf                                                                                                                        0
15708 root      20   0 14.071g 0.010t   9680 R 99.7 14.9   5:44.95 lighttpd -n 8 -f /etc/mtcp/config/m-lighttpd.conf                                                                                                                        2
15709 root      20   0 14.071g 0.010t   9680 R 99.7 14.9   5:45.08 lighttpd -n 8 -f /etc/mtcp/config/m-lighttpd.conf                                                                                                                        3
15710 root      20   0 14.071g 0.010t   9680 R 99.7 14.9   5:44.99 lighttpd -n 8 -f /etc/mtcp/config/m-lighttpd.conf                                                                                                                        4
15711 root      20   0 14.071g 0.010t   9680 R 99.7 14.9   5:44.94 lighttpd -n 8 -f /etc/mtcp/config/m-lighttpd.conf                                                                                                                        5
15712 root      20   0 14.071g 0.010t   9680 R 99.7 14.9   5:44.89 lighttpd -n 8 -f /etc/mtcp/config/m-lighttpd.conf                                                                                                                        6
15713 root      20   0 14.071g 0.010t   9680 R 99.7 14.9   5:44.96 lighttpd -n 8 -f /etc/mtcp/config/m-lighttpd.conf                

How to re-injecting TCP segment after TCP 4-way close with scapy

At work, I do lot of in-house reproduction of customers issue with lots of different tools, scapy is one I used often to simulate some odd TCP behavior. for example, a customer has a PoS terminal establish tcp connections to our load balancer,  the terminal would FIN+ACK the TCP connection after sending a transaction request (PSH+ACK), our load balancer would FIN+ACK , the PoS terminal send final ACK to close the TCP connection. this is all sound and good.

here is an interesting problem though,  intermittently, some customers PoS terminal would re-send the transaction request (PSH+ACK) about ~1 second later after the TCP 4-way close. This of course will be dropped by load balancer with RST since the TCP connections has been closed and TCP connection flows in memory has been cleared. I think this is a good example to use scapy to simulate the PoS terminal client behavior and show how flexible with scapy to simulate some odd TCP behavior, see the script from my githup:




https://github.com/vincentmli/bash_scripts/blob/master/scapy-http-responder/pshack-after-tcp4wayclose.py

Followers