Friday, December 21, 2012

Communication between VM’s in ESX on ESX setup

VMware ESX is a hypervisor from VMware which helps you to virtualize your infrastructure. Refer this link for more details.

Virtualizing the ESX hypervisor (i.e. running it as a VM) itself is a great way to experiment with different setups and scenarios without needing physical lab setup to perform the same. One can create his own mini-lab on the virtual ESX setup, add networking and storage to it, and thus can simulate a wide variety of test scenarios. Virtualizing the ESX also gives user the freedom to clone/snapshot the ESX. Thus, user can simply bring up this virtualized ESX on some other host and he has his whole lab setup, up and running within a few minutes.

VMware ESX has the capability of running “ESX as a VM” on top of the physical ESX host. This virtual ESX host has all the capabilities as that of the physical host. Thus, one can have a VM running inside a VM (virtual ESX) present on physical server.

 


VM’s communicate with each other through the virtual switches (vswitch) provided by ESX.  Considering the case of Virtual ESX on the physical ESX, one gets the following connectivity between the vswitches:-


Looking at the above setup, let’s have a scenario where machine A wants to communicate to machine B. Packets from machine A needs to travel through vswitch1 and vswitch2 to reach to machine B. Assuming there are no VLANs configured on the switches and all ports are a part of default VLAN (native VLAN), one might say that A will be able to communicate with B. But in reality, A is unable to communicate with B. If A sends a ping request to B, then only ARP resolution takes place (mac address of B gets learn at A). Ping’s reply is not received by A. The workaround to facilitate this communication is by putting vswitch1 on promiscuous mode. Let’s discuss about the cause of failure and how promiscuous mode solves the issue.


Cause of failure:-
VMware vswitch does not have the capability of mac learning. It maintains a table of the port to mac binding only for the VM’s present on the vswitch. Anything except that, it forwards through the uplink (physical NIC).


Promiscuous mode:-
It is a mode of operation which allows network device to intercept and read each network packet that arrives in its entirety. Enabling promiscuous mode on a switch makes the switch work like a hub.


How vswitch works while in non-promiscuous mode (default):-

For ARP request, since it’s a broadcast, following steps take place:-

  1.  Machine A sends an ARP broadcast.
  2. vswitch1 forwards this broadcast packet to all members present in that VLAN as well as on Physical NIC. This broadcast packet is received both by vswitch2 and a Physical Switch.
  3. On receiving the ARP request vswitch2 again broadcasts it and now it is received by machine B.
  4. Machine B sends a unicast reply. This reply is seen by vswitch2.
  5. Since the destination is not in its table, vswitch2 forward this response through physical NIC and is received at vswitch1.
  6. Vswitch1 finds the destination mac-address entry in its table and it forwards the reply to machine A. Hence, machine A learns the mac-address of machine B.


Next, if one tries to ping to machine B from machine A, following steps take place:-

  1. Machine A sends a ping request with destination mac-address of machine B (which it learnt from ARP broadcast).
  2. Since it is a unicast request, vswitch1 tries to find the destination mac-address entry in its table. It is unable to find that entry and hence it sends that packet out to physical switch through the NIC. This packet is not forwarded to vswitch2 and hence machine A is unable to communicate with machine B.


When vswitch1 is in promiscuous mode:-

ARP request is resolved in the same way as it’s resolved for non-promiscuous mode discussed above.

For ping request/response, following actions take place:-

  1. Unicast ping request is sent by machine A to machine B. This is received by vswitch1.
  2. Since vswitch1 is in promiscuous mode, all the ports on the switch are able to see the traffic of other ports who are part of the same VLAN. Therefore, this packet is sent out to both physical port and vswitch2.
  3. Vswitch2 finds port to mac entry for destination machine B and forwards the packet to machine B.
  4. Machine B replies to ping request. This packet is received at vswitch2.
  5. Since no entry for destination mac is found on vswitch2, it is forwarded to vswitch1.
  6. Vswitch1 is able to find the entry for destination mac in its table, and hence the response is forwarded to A. Thus, the response from B is received by A.

With promiscuous mode enabled, VM’s on the internal ESX host are able to communicate with the outside world.

However, drawback of promiscuous mode is that it will lead to increase in the traffic on vswitch and it will degrade the performance of the switch. One solution could be to put only the port which is attached to vswitch2 in promiscuous mode. But then, A needs to be a part of the same VLAN which that port allows. Another solution could be to use the advanced virtual switches available in the market which also perform mac learning. Some examples of the advanced switches are VMware DVS, Cisco’s N1KV, IBM DOVE, etc.

References:-

Allowing FTP through Firewall by Inspecting traffic

Problem statement:-

FTP traffic needs to be allowed through the firewall. Basic details about FTP can be found here. This cannot be done by simply allowing the traffic for control connection ( by default port 21 ) and not taking care for the data-connection. For this, one needs to analyze the FTP control path (control connection) data to get the details about the data-path (data connection). Once the data-path details are known, one just needs to create embryonic flow entries for the data-connection.


Embryonic flow: A flow entry created for the traffic-flow before there is actual traffic flowing which matches the flow specifications.
flowID: This is a five-tuple field to differentiate the various connections.

Control path activities for a particular FTP request are as follows :-

For Active Mode

Active Mode


For Passive Mode 
  
Passive Mode


Out of these 8 packets on control-path, ignoring ACK, we have ‘Five’ generic packets in our flow. We can list these requests/responses in terms of states.
These states are:-
1.    Opening
2.    Opened
3.    command_sent
4.    execution_started
5.    execution_complete

One needs to keep track of FTP control connection’s state and the data-connection details negotiated. This can be done by storing the details in a table called “flow table”.


Flow table column’s are as follows :-
1.    Command Type
2.    IP Address exchanged for data-connection( required for creating embryonic flow )
3.    Port number exchanged for data-connection( required for creating embryonic flow )
4.    Response_code of the command
5.    State of the FTP connection

When a new FTP connection is initiated (is in opening state), one entry is made in the flow table. It then goes through all the states; when it reaches to the state of execution_complete, that entry is removed.


STATE TRANSITIONS FOR PORT COMMANDS:-
Now lets consider the case for PORT command. Five request/response actions occur in this. These are:-
( Client[XYZ] to Server[FTP 21] ) – FTP Request: PORT          -> OPENING
( Server[FTP 21] to Client[XYZ] ) – Response: 200 PORT      ->  OPENED
( Client[XYZ] to Server[FTP 21] ) – FTP Request: <CMD>    ->  CMD_SENT
( Server[FTP 21] to Client[XYZ] ) – Response: 150                ->  EXEC_STARTED
( Server[FTP 21] to Client[XYZ] ) – Response: 226                ->  EXEC_COMP

Steps followed for each of the above requests/responses:-
Packet1:-
First packet sent is the packet with PORT command from client to server.
 

When this packet is received, a flow-entry is made and IP_Address and PORT negotiated are calculated from the message. Also the state is changed to OPENING.


Packet 2:-
Second packet is the response to the PORT command.


Once it is received, Response code is calculated from the message. If  the response-code is positive ( like 200), a flow-entry is present in the flow_table for this packet’s flowID and state is OPENING, then the state is changed from OPENING to OPENED.



Packet 3:-
On the next packet if flow table has a entry for its flowID and is in the OPENED state with the direction from Client to server, then it’s a request from Client to server to perform a specified operation.


After receiving this packet, the state is now changed from OPENED to CMD_SENT.


In case of PORT commands, TCP 3-way handshake for the data-connection occurs after this packet is received by the server. Therefore, embryonic-flow-entry is made in the allowed-connections table on the firewall so that this data-connection traffic is not blocked by the firewall.


Packet4:-
Next packet for the particular flow is the response from the server. Based on the response code received, the state will be changed.


If the response from the server is positive preliminary reply and the state for the particular flow-entry is CMD_SENT, then the state is changed to EXEC_STARTED. If the response is negative, then the flow-entry is deleted, embryonic-flow-entry is also deleted.



Packet5:-
This is the last packet received indicating the status of the FTP command.


If the response code is ‘226’, this means the transfer has occurred successfully. If the previous state was EXEC_STARTED, the state is now changed to EXEC_COMP and the embryonic-flow-entry and flow-entry can be deleted from the respective tables. If some negative reply is received, even then the embryonic-flow-entry and the flow-entry are deleted from the tables.


STATE TRANSITIONS FOR PASV COMMANDS:-

For passive commands, it again goes through the five states mentioned below:-
( Client[XYZ] to Server[FTP 21] ) – FTP Request: PASV                   ->   OPENING
( Server[FTP 21] to Client[XYZ] ) – Response: 227 (port_no)         ->   OPENED
( Client[XYZ] to Server[FTP 21] ) – FTP Request: <CMD>             ->   CMD_SENT
( Server[FTP 21] to Client[XYZ] ) – Response: 150                         ->   EXEC_STARTED
( Server[FTP 21] to Client[XYZ] ) – Response: 226                         ->   EXEC_COMP

Steps followed for each of the above requests/responses:-
Packet1:-
First packet sent is the packet with PASV command.


Once it is received, a flow-entry is made in the flow_table. Also the state is changed to OPENING.



Packet 2:-
Second packet is the response to the PASV command. If a flow-entry is present in the flow_table for the packet’s flowID and its state is OPENING and the direction is from server to client, then its a response from the server.


Once it is received, Response code and PORT negotiated is calculated. According to the response code received, a particular action is taken. Suppose if its 227, then the state is changed from OPENING to OPENED.


In case of PASV commands, TCP 3-way handshake on the data-connection occurs after this packet is received by the client. Therefore, an embryonic flow-entry is made in the firewall’s allowed-connections table with the data-connection details.


Packet 3:-
If the next packet for the particular flowID is from Client to server and state is OPENED, then it is a request from Client to server to perform some operation.


After receiving this packet, the state is now changed from OPENED to CMD_SENT.



Packet4:-
Next packet for the particular flowID would be response from the server.


If the response from the server is positive and state is CMD_SENT, then the state is changed from CMD_SENT to EXEC_STARTED. If the response is negative, then the flow-entry and embryonic-flow-entry are deleted  from the respective tables.



Packet5:-
This is the last packet received indicating the status of the FTP command.


If the response code is ‘226’ and state is EXEC_STARTED, this means the transfer has occurred successfully, state is changed to EXEC_COMP and the flow-entry and embryonic-flow-entry can now be deleted from the respective tables. In case of negative replies also, the same action is taken.


Conclusion:-
This approach can be followed in all the cases where you have the data-path created dynamically and its information is negotiated on the control-path. Above example listed how this can be applied to FTP. Similarly, one can use it for RSH, MSRPC with different set of columns in flow_table( as per the protocol needs).