System() function is hang in linux

102 Views Asked by At

Situation: In my project, I want modify OVS source code to perform some my functions. I want when OVS receive a specific packet, it will add a flow to userspace don't need controller, to do that i used system() function in a source c file to execute the following command:

ovs-ofctl add-flow s1 priority=5,tcp,in_port="s1-eth1",eth_src=32:3b:8c:9d:13:5f,eth_dst=d2:5f:67:a6:80:81,ipv4_src=10.0.0.1,ipv4_dst=10.0.0.2,tcp_src=25000,tcp_dst=59174,action=output:"s1-eth2"

Problem: After remake source code, whenever OVS run to my funtions which I added, system() funtion will hang like in image. Even if I stop OVS, process system() have been running . image

Someone can help me?

I add my functions to connmgr_send_async_msg() in ovs/ofproto/connmgr.c . This function will recieve packet coming to OVS. It looks like :

void connmgr_send_async_msg(struct connmgr *mgr, const struct ofproto_async_msg *am)
     {
      struct dp_packet packet_in; // this is packet comes in OVS

      // then i get interface name, MAC, IPv4, TCP port of packet_in into
      //in, out, sMAC, dMAC, sIP, dIP, sPort, dPort

      char cmd[1000]; // command i want pass to system()
      
      snprintf(bar1, sizeof(bar1), "ovs-ofctl add-flow s1 priority=5,tcp,in_port=\"%s\",eth_src=%s,eth_dst=%s,  ipv4_src=%s,ipv4_dst=%s,tcp_src=%u,tcp_dst=%u,action=output:\"%s\""
                 ,in ,sMAC ,dMAC, sIP, dIP, sPort, dPort, out); // pass agr to cmd
    
       // call system() funtion with cmd
       int systemRet1 = system(cmd);

       // logging to my log file
       log = fopen("/home/log_file.txt", "a");
       fprintf(log, "Status when add flow %d \n", systemRet1);
       fclose(log);

       .................................// normal OVS source code 

        }
0

There are 0 best solutions below