Aug 272011
 

After having spent several nights searching in a 1500-users network for a rogue dhcp server, coming from a “smart” user who bought a junk router for Christmas, I have decided it’s time to use our knowledge instead of using our nights to solve this issue.

How it was done:

Two different services work aggregated for this issue:

1. DHCPD ROGUE DETECTOR

it is a smart component which is able to transform any network adapter into a dhcp client adapter, for a limited amount of time. The really smart thing is that it DOES NOT interfere with the IP addresses already assigned to that specific interface, which usually works as gateway – such as during the sniff, the same interface works as gateway as previously assigned.

The component asks for an IP address and remembers the IP address and MAC Address of the DHCP server only if this one is different than that already present on the same interface. The component will NOT bind the IP address asssigned by the dhcp server to the interface, instead it will write to a log and send an email. All parameters are configurable (from, to, mail server etc) and the component is easily distributable as compiled noarch ELF on both i386 and x86_64 architectures.

2. DHCP Slapper

The first component only tells us about a rogue dhcp server in the network, but it does not interfere with it. Without the second component, the rogue dhcp server is able to do its dirty work without any problem.

This is where the dhcp slapper comes into action.

A regular DHCP traffic is as follows:

client looks for dhcp server using broadcast

DHCPDISCOVER from MACADDRESS via ethx

dhcp server offers client via broadcast an IP address

DHCPOFFER on IPADDRESS to MACADDRESS via ethx

client requests IP address via broadcast

DHCPREQUEST for IPADDRESS (DHCPIPADDRESS) from MACADDRESS via ethx

dhcp server acknowledges and lends the IP address to the client via broadcast
DHCPACK on IPADDRESS to MACADDRESS via ethx

The last message can also be the following:

dhcp server does not acknowledge the IP address to the client via broadcast because it detects an IP conflict
DHCPNACK on IPADDRESS to MACADDRESS via ethx

What did we do?

In simple terms, a broadcast is a communication between two computers using MAC addresses instead of using unicast, i.e IP Adresses

Broadcast communication may be computed by any computer in the same subnet because broadcast is essentially a “noise on the wire”. It gets in all the subnet and data is transmitted through all possible ports to all network devices, including computers.

What if we could define a dhcp server authoritative ont for an IP subnet (or several) but instead on an interface and tell this dhcp server to fight any other dhcp server it hears. Since a rogue dhcp server is using the same schematic to talk to a client, it would be enough if, after the rogue DHCP server transmits a DHCPACK signal, our DHCP server would transmit to the same client a DHCPNAK signal. DHCP theory (the RFC defining DHCP operation) states that, in this case, the client should restart all the process with DHCPDISCOVER and so on.

Practice showed that our clients will receive correct IP addresses from this DHCP server after a maximum of 3 DHCPDISCOVERs. Our DHCP server starts to answer quicker and quicker until the client will hear the authoritative DHCP server instead of the rogue one.

While this process comes with a broadcast overhead, it is not important enough as to disturb the network in such a manner as to make communications impossible. It does though kill all rogue DHCP servers, long enough to let us go on the field and disconnect physically the cable going to the rogue DHCP server (the next day) and also allows a correct operation of the clients.

Aug 272011
 

After having been recently bitten by Ethernet’s flow control mechanism, I decided to learn about this somewhat obscure but commonly used facet of modern networks. This post is a summary of what I discovered about it and its associated benefits and dangers.

What is flow control?

Ethernet flow control, or 802.3x, is a way for a network device to tell its immediate neighbor that it is overloaded with data, such as when a device is receiving data faster than it can process it. It allows for an overloaded device to send out a special Ethernet frame, called a pause frame, that asks the device on the other end of the wire to stop sending data temporarily. If the receiving device honors the pause frame then the sending device has time to catch up on the stack of received data that it hasn’t had time to process yet.

There also exists an older method for flow control called “back pressure” that is used in half-duplex environments (i.e. non-switched Ethernet). It consists of the overloaded device “jamming” the medium temporarily until it has the ability to accept more data. I don’t know much about half-duplex flow control, and thus I won’t mention it again; everything here applies solely to full-duplex flow control via 802.3x. Also, TCP has a mechanism for performing its own flow control that is entirely different from Ethernet’s flow control; I will not be fully explaining TCP’s flow control method here, as it would merit a lengthy discussion itself.

Rules of the game

When thinking about Ethernet flow control, it is important to keep several things in mind:

  1. Flow control operates at a lower layer than TCP or IP, and thus is independent of them. Put another way, flow control is capable of being used regardless of what higher-level protocols are put on top of it. An important side-effect of this is that neither TCP nor IP know what Ethernet’s flow control is doing; they operate under the assumption that there is no flow control other than what they may or may not provide themselves.
  2. Flow control functions between two directly connected network devices, and flow control frames are never forwarded between links. Thus, two computers that are connected via a switch will never send pause frames to each other, but could send pause frames to the switch itself (and vice versa: the switch can send pause frames to the two computers).
  3. Pause frames have a limited duration; they will automatically “expire” after a certain amount of time. The expiration time is set by the device that transmits the pause frame.
  4. A paused link is not a discriminator of protocols; it will prevent any data from being passed across the link other than more pause frames.

Perhaps you have begun to see some issues with flow control in light of some of the above points. Let’s start looking at them.

TCP breakage

Okay, it isn’t true, TCP doesn’t stop working when flow control is enabled. However, an important part of it does stop working correctly: its own flow control mechanism. TCP flow control uses a more complex mechanism of timeouts and acknowledgement segments to determine when a remote device is overloaded. It basically sends at a faster and faster pace until it sees that some of its sent data isn’t getting to the remote device and then slows down. This allows TCP to utilize network links in a somewhat intelligent manner, as an overloaded network or device will cause some TCP segments to be lost and thus cause the sender to send data at a slower rate.

Now consider what happens when Ethernet flow control is mixed with TCP flow control. Let’s assume that we have two directly connected computers, one of which is much slower than the other. The faster sending computer starts sending lots of data to the slower receiving computer. The receiver eventually notices that it is getting overloaded with data and sends a pause frame to the sender. The sender sees the pause frame and stops sending temporarily. Once the pause frame expires, the sender will resume sending its flood of data to the other computer. Unfortunately, the TCP engine on the sender will not recognize that the receiver is overloaded, as there was no lost data — the receiver will typically stop the sender before it loses any data. Thus, the sender will continue to speed up at an exponential rate; because it didn’t see any lost data, it will send data twice as fast as before! Because the receiver has a permanent speed disadvantage, this will require the receiver to send out pause frames twice as often. Things start snowballing until the receiver pauses the sender so often that the sender starts dropping its own data before it sends it, and thus finally sees some data being lost and slows down.

Is this a problem? In some ways it isn’t. Because TCP is a reliable protocol, nothing is ever really “lost”; it is simply retransmitted and life goes on. Ethernet flow control accomplishes the same thing as TCP flow control in this situation, as they both slow down the data transmission to the speed that the slower device can handle. There are some arguments to be made for there being an awkward overlap between the two flow control mechanisms, but it could be worse.

Unfortunately, it does get worse.

Head-of-line blocking

In the last example, I considered the case where two computers were directly connected to each other. This example is too simplistic to be of much use — when was the last time you saw two directly connected computers? It is a bit of a rarity. Let’s now look at what happens when you introduce a switch into the mix. For our purposes, let us assume that the switch fully supports Ethernet flow control and that it is willing to use it. Our new setup will consist of two desktop computers and one file server, all of which are attached to the switch. It isn’t any fun to make everything perfect, so let’s also say that one of the desktops has a 10 Mbps connection to the switch while the other desktop and the server have 100 Mbps connections.

This setup is usually fine — the 10 Mbps connection will be slower than the others, but it doesn’t cause too many problems, just slower service to the one desktop. Things could get ugly, though, if Ethernet flow control is enabled on the switch. Imagine that the 10 Mbps desktop requests a large file from the file server. The file server begins to send the file to the desktop initially at a slow rate, but quickly picks up steam. Eventually, the file server will start to send data to the desktop at 11 Mbps, which is more than the poor 10 Mbps connection can handle. Without flow control enabled on the switch, the switch would start to simply drop data segments destined to the desktop, which the file server would notice and start to throttle back its sending rate.

With flow control enabled on the switch, though, the switch takes a very different approach; it will send out its own pause frames to any port that is sending data to the now-overloaded 10 Mbps port. This means that the file server will receive a pause frame from the switch, requesting it to cease all transmissions for a certain amount of time. Is this a problem? Yes! Because pause frames cease all transmissions on the link, any other data that the file server is sending will be paused as well, including data that may be destined to the 100 Mbps desktop computer. Eventually the pause will expire and the file server will continue sending out data. Unfortunately, the TCP mechanism on the file server will not know that anything is wrong and will continue sending out data at faster and faster speeds, thus overloading the 10 Mbps desktop again. As before, the cycle will keep repeating itself until the file server starts dropping its own data. Unlike the previous situation, the innocent 100 Mbps desktop bystander is penalized and will see its transfers from the file server drop to 10 Mbps speeds.

This situation is called head-of-line blocking, and it is the major reason why Ethernet flow control is somewhat dangerous to use. When enabled on network switches, it can create situations where one slow link in a network can bring the rest of the network to a crawl. It gets especially bad if the backbones in your network have flow control enabled; it should be obvious by this point just how bad that could get.

When to enable flow control

So what should you do? Should you completely disable flow control on all computers and switches? Not necessarily. It is generally safe to leave flow control enabled on computers. Switches, though, should either have flow control disabled or configured such that they will honor received pause frames but will never send out new pause frames. Some Cisco switches are even permanently configured this way — they can receive pause frames but never emit them. To be honest, the complete answer to flow control is somewhat more complicated than this (e.g. you could probably enable pause frame emission if a switch port is connected to a slow backplane), but the safest bet is to disable flow control when given the option.

ref: http://virtualthreads.blogspot.com/2006/02/beware-ethernet-flow-control.html

Switch to mobile version
Advertisment ad adsense adlogger