Commit graph

52 commits

Author SHA1 Message Date
Victor Vieux
8165e51ecc Merge branch '858-disable-network-configuration' of https://github.com/stfp/docker into stfp-858-disable-network-configuration 2013-07-23 08:44:12 +00:00
Solomon Hykes
4714f102d7 Allocate a /16 IP range by default, with fallback to /24. Try a total of 12 ranges instead of 3. 2013-07-22 12:06:24 -07:00
Stefan Praszalowicz
49673fc45c Support completely disabling network configuration with docker -d -b none 2013-07-21 17:49:09 -07:00
Louis Opter
fac0d87d00 Add support for UDP (closes #33)
API Changes
-----------

The port notation is extended to support "/udp" or "/tcp" at the *end*
of the specifier string (and defaults to tcp if "/tcp" or "/udp" are
missing)

`docker ps` now shows UDP ports as "frontend->backend/udp". Nothing
changes for TCP ports.

`docker inspect` now displays two sub-dictionaries: "Tcp" and "Udp",
under "PortMapping" in "NetworkSettings".

Theses changes stand true for the values returned by the HTTP API too.

This changeset will definitely break tools built upon the API (or upon
`docker inspect`). A less intrusive way to add UDP ports in `docker
inspect` would be to simply add "/udp" for UDP ports but it will still
break existing applications which tries to convert the whole field to an
integer. I believe that having two TCP/UDP sub-dictionaries is better
because it makes the whole thing more clear and more easy to parse right
away (i.e: you don't have to check the format of the string, split it
and convert the right part to an integer)

Code Changes
------------

Significant changes in network.go:

- A second PortAllocator is instantiated for the UDP range;
- PortMapper maintains separate mapping for TCP and UDP;
- The extPorts array in NetworkInterface is now an array of Nat objects
  (so we can know on which protocol a given port was mapped when
  NetworkInterface.Release() is called);
- TCP proxying on localhost has been moved away in network_proxy.go.

localhost proxy code rewrite in network_proxy.go:

We have to proxy the traffic between localhost:frontend-port and
container:backend-port because Netfilter doesn't work properly on the
loopback interface and DNAT iptable rules aren't applied there.

- Goroutines in the TCP proxying code are now explicitly stopped when
  the proxy is stopped;
- UDP connection tracking using a map (more infos in [1]);
- Support for IPv6 (to be more accurate, the code is transparent to the
  Go net package, so you can use, tcp/tcp4/tcp6/udp/udp4/udp6);
- Single Proxy interface for both UDP and TCP proxying;
- Full test suite.

[1] https://github.com/dotcloud/docker/issues/33#issuecomment-20010400
2013-07-09 17:42:35 -07:00
Caleb Spare
1cf9c80e97 Mutex style change.
For structs protected by a single mutex, embed the mutex for more
concise usage.

Also use a sync.Mutex directly, rather than a pointer, to avoid the
need for initialization (because a Mutex's zero-value is valid and
ready to be used).
2013-07-02 15:53:08 -07:00
Jonathan Rudenberg
50b70eeb68 Remove code unreachable using Go 1.1 2013-06-20 23:19:44 -04:00
Victor Vieux
95d66ebc6b specify public port 2013-06-10 13:56:43 +00:00
Guillaume J. Charmes
7ef9833dbb Put back panic for go1.0.3 compatibility 2013-06-04 14:26:40 -07:00
Victor Vieux
fd224ee590 linted names 2013-06-04 18:00:22 +00:00
Victor Vieux
86ada2fa5d drop/omit 2013-06-04 13:51:12 +00:00
Victor Vieux
b515a5a9ec go vet 2013-06-04 13:24:58 +00:00
Guillaume J. Charmes
2e69e1727b Create a subpackage for utils 2013-05-14 22:37:35 +00:00
Solomon Hykes
7f1a32b9ff Shutdown loopback-to-loopback proxy when unmapping a port 2013-04-19 20:44:25 -07:00
Solomon Hykes
930e9a7e43 Emulate DNAT in userland for loopback-to-loopback connections. This makes container ports available from localhost. 2013-04-19 19:35:44 -07:00
Solomon Hykes
61259ab4b4 Exclude loopback-to-loopback connections from DNAT rules, to allow userland proxying 2013-04-19 19:32:32 -07:00
Guillaume J. Charmes
22893429ed Go fmt 2013-04-12 07:37:24 -07:00
Solomon Hykes
1601366cb6 Make it more clear when Docker fails to allocate a free IP range for its bridge 2013-04-08 18:16:58 -07:00
Solomon Hykes
8cf30395a1 Changed default bridge interface do 'docker0' 2013-04-05 14:16:19 -07:00
Solomon Hykes
793c1ad990 Merge remote-tracking branch 'origin/219-default-bridge-2' 2013-04-05 14:02:16 -07:00
Solomon Hykes
febaeebfb8 Add tests of tcp port allocator 2013-04-05 13:03:24 -07:00
Solomon Hykes
d32f184696 Fix a race condition when running the port allocator 2013-04-05 13:03:04 -07:00
Solomon Hykes
2aad4a3478 Choose which TCP frontend port to allocate with '-p :PORT' 2013-04-04 22:58:01 -07:00
Solomon Hykes
a5fb1d6c01 Refactored PortAllocator to allow for same-frontend constraint 2013-04-04 22:56:12 -07:00
Solomon Hykes
f344212b93 Renamed PortAllocator.populate() to run() 2013-04-04 19:49:32 -07:00
Solomon Hykes
0424998f38 Print a less confusing error message when lxcbr0 doesn't exist 2013-04-04 19:14:10 -07:00
Solomon Hykes
586a79cca0 Merge remote-tracking branch 'dominikh/minor-code-touchups' 2013-04-04 16:20:37 -07:00
Solomon Hykes
ebc837957f Continue cleaning up iptables rules from previous version, to avoid crashing after an upgrade 2013-04-04 15:16:42 -07:00
unclejack
32f5811476 stop looping remote:port from host to containers 2013-04-04 23:07:10 +03:00
Guillaume J. Charmes
1b370f9d8d Move the default bridge name to a constant 2013-04-04 05:33:28 -07:00
Guillaume J. Charmes
aa4bf4284b If bridge does not exists, try to create it 2013-04-03 16:17:03 -07:00
Guillaume J. Charmes
90a6e310fe Add an helper function to check if two network overlaps. Also add unit tests for this function 2013-04-03 16:15:43 -07:00
Guillaume J. Charmes
f39af7e05d Put the bridge interface name in the command line 2013-04-03 16:15:43 -07:00
unclejack
3b65be9127 Fix NAT problem with ports looping back to containers 2013-04-04 01:32:46 +03:00
Dominik Honnef
22f1cc955d replace unreachable returns with panics
Not only is this a more common idiom, it'll make finding bugs easier,
and it'll make porting to Go 1.1 easier.

Go 1.1 will not require the final return or panic because it has a
notion of terminating statements.
2013-04-03 11:18:23 +02:00
Dominik Honnef
6f9a67a7c7 Make IP allocator lazy
Instead of allocating all possible IPs in advance, generate them as
needed.

A loop will cycle through all possible IPs in sequential order,
allocating them as needed and marking them as in use. Once the loop
exhausts all IPs, it will wrap back to the beginning. IPs that are
already in use will be skipped. When an IP is released, it will be
cleared and be available for allocation again.

Two decisions went into this design:

1) Minimize memory footprint by only allocating IPs that are actually
in use

2) Minimize reuse of released IP addresses to avoid sending traffic to
the wrong containers

As a side effect, the functions for IP/Mask<->int conversion have been
rewritten to never be able to fail in order to reduce the amount of
error returns.

Fixes gh-231
2013-04-01 06:02:44 +02:00
Shawn Siefkas
523803d633 Handling iptables() errors more usefully during portmapper setup 2013-03-28 14:44:54 -05:00
Shawn Siefkas
c66d2b6a53 Return error when iptables is not found 2013-03-28 14:30:56 -05:00
Shawn Siefkas
dfc3904f77 Looking for iptables in PATH 2013-03-28 14:02:50 -05:00
Guillaume J. Charmes
51455b1ee0 Merge pull request #138 from srid/handle-port-mapper-error
handle errors during the creation of port mapper
2013-03-24 10:27:03 -07:00
Sridhar Ratnakumar
371225520f handle errors during the creation of port mapper
example:

  2013/03/22 21:42:55 Unable to setup port networking: Failed to create DOCKER chain

  (which was possibly introduced by commit 3c6b8bb88)
2013-03-22 21:44:01 -07:00
Solomon Hykes
301a8afff5 Properly cleanup iptables rules inserted in OUTPUT (introduced in 3c6b8bb888) 2013-03-22 22:31:20 -07:00
Shawn Siefkas
3c6b8bb888 Fixing Issue #98: Adding DOCKER to output chain during iptables setup 2013-03-22 11:28:15 -05:00
shin-
3aefed2dc2 When lxcbr0 has several associated IPs, default to first one found 2013-03-21 09:19:22 -07:00
creack
ab99e9252d Complete pull request #121, init TCPAddr with named field 2013-03-20 06:02:25 -07:00
ezbercih
fac32cda5a Fix issue #120, initialize TCPAddr w/ field names
Current Go tip (+74e65f07a0c8) and likely Go 1.1 does not build docker since net.TCPAddr struct has an additional field now for IPv6:

type TCPAddr struct {
    IP   IP
    Port int
    Zone string // IPv6 scoped addressing zone
}

Initializing the struct with named fields resolves this problem.
2013-03-21 00:11:16 -03:00
Andrea Luzzardi
799ffa1763 Network: Port mapping support.
Implemented a port allocator and a port mapper that is able to forward TCP ports
from the host to the container.
2013-02-28 11:50:02 -08:00
Andrea Luzzardi
c08f5b2b84 Integrated the network allocator into Docker. A networking environment
is assigned to each container upon Start and released whenever the
container exits.
2013-02-25 14:06:22 -08:00
Andrea Luzzardi
797bb6e75b Network allocator 2013-02-25 10:45:23 -08:00
Andrea Luzzardi
e0e49b9a22 Network: Do not assume that we are using a class C. Instead, compute the
IP addresses range and network size in order to allocate an IP address.
2013-02-21 18:33:23 -08:00
Andrea Luzzardi
6124c5eb31 Network: Simple random IP allocation on the bridge network. 2013-02-21 10:47:57 -08:00