MAJOR: namespace: add Linux network namespace support
authorKOVACS Krisztian <hidden@balabit.com>
Mon, 17 Nov 2014 14:11:45 +0000 (15:11 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 21 Nov 2014 06:51:57 +0000 (07:51 +0100)
commitb3e54fe387c7c1ea750f39d3029672d640c499f9
treec7dea2c3c8421abffd62a9bdc11ab74d4fc7b186
parentefd3aa93412648cf923bf3d2e171c0b84e9d7a69
MAJOR: namespace: add Linux network namespace support

This patch makes it possible to create binds and servers in separate
namespaces.  This can be used to proxy between multiple completely independent
virtual networks (with possibly overlapping IP addresses) and a
non-namespace-aware proxy implementation that supports the proxy protocol (v2).

The setup is something like this:

net1 on VLAN 1 (namespace 1) -\
net2 on VLAN 2 (namespace 2) -- haproxy ==== proxy (namespace 0)
net3 on VLAN 3 (namespace 3) -/

The proxy is configured to make server connections through haproxy and sending
the expected source/target addresses to haproxy using the proxy protocol.

The network namespace setup on the haproxy node is something like this:

= 8< =
$ cat setup.sh
ip netns add 1
ip link add link eth1 type vlan id 1
ip link set eth1.1 netns 1
ip netns exec 1 ip addr add 192.168.91.2/24 dev eth1.1
ip netns exec 1 ip link set eth1.$id up
...
= 8< =

= 8< =
$ cat haproxy.cfg
frontend clients
  bind 127.0.0.1:50022 namespace 1 transparent
  default_backend scb

backend server
  mode tcp
  server server1 192.168.122.4:2222 namespace 2 send-proxy-v2
= 8< =

A bind line creates the listener in the specified namespace, and connections
originating from that listener also have their network namespace set to
that of the listener.

A server line either forces the connection to be made in a specified
namespace or may use the namespace from the client-side connection if that
was set.

For more documentation please read the documentation included in the patch
itself.

Signed-off-by: KOVACS Tamas <ktamas@balabit.com>
Signed-off-by: Sarkozi Laszlo <laszlo.sarkozi@balabit.com>
Signed-off-by: KOVACS Krisztian <hidden@balabit.com>
15 files changed:
Makefile
doc/network-namespaces.txt [new file with mode: 0644]
include/common/namespace.h [new file with mode: 0644]
include/proto/connection.h
include/types/connection.h
include/types/listener.h
include/types/server.h
src/backend.c
src/cfgparse.c
src/connection.c
src/haproxy.c
src/namespace.c [new file with mode: 0644]
src/proto_tcp.c
src/server.c
src/session.c