Skip to content

Commit e1ee59f

Browse files
committed
Add nogw/nogw4/nogw6 options to prevent assignment of gateway
1 parent b609bf4 commit e1ee59f

4 files changed

Lines changed: 144 additions & 4 deletions

File tree

README.md

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,31 @@ By default it will simply create a pair of veth interfaces for each container.
3131
One will be pushed inside the container and another will remain on host
3232
(without any IP assigned).
3333

34-
Plugin accepts optional `parent` parameter, which is a name of bridge
35-
interface that the second interface should be added to:
34+
## Options
35+
36+
To use options, add `--opt option=value` as an argument of `docker network create`:
3637

3738
```bash
3839
docker network create --driver jacekkow/pyveth:latest --opt parent=br0 new-network
3940
```
4041

41-
This way host interface will be automatically attached to the specified bridge.
42+
Available options:
43+
44+
`parent=brname`
45+
46+
Automatically attach host interface to the bridge interface `brname`.
47+
48+
`nogw=1`
49+
50+
Disable assignment of gateway IP.
51+
52+
`nogw4=1`
53+
54+
Disable assignment of IPv4 gateway IP.
55+
56+
`nogw6=1`
57+
58+
Disable assignment of IPv6 gateway IP.
4259

4360
## Manual packaging
4461

lib/NetworkDriver.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,21 @@ def GetCapabilities():
5757
return {
5858
'Scope': 'local',
5959
'ConnectivityScope': 'global',
60+
'GwAllocChecker': True,
61+
}
62+
63+
64+
@app.route('/NetworkDriver.GwAllocCheck', methods=['POST'])
65+
def GwAllocCheck():
66+
request = GwAllocCheckEntity(**flask.request.get_json(force=True))
67+
skip_ipv4 = skip_ipv6 = request.Options.get('com.docker.network.generic', {}).get('nogw') == '1'
68+
if request.Options.get('com.docker.network.generic', {}).get('nogw4') == '1':
69+
skip_ipv4 = True
70+
if request.Options.get('com.docker.network.generic', {}).get('nogw6') == '1':
71+
skip_ipv6 = True
72+
return {
73+
'SkipIPv4': skip_ipv4,
74+
'SkipIPv6': skip_ipv6,
6075
}
6176

6277

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
docker-plugin-api>=0.3
1+
docker-plugin-api>=0.4
22
Flask
33
pyroute2
44
waitress

test_integration.sh

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ docker network rm test2 || true
1212

1313
docker plugin install jacekkow/pyipam:latest || true
1414

15+
16+
##########################
17+
# Test address assignment
18+
1519
docker network create \
1620
--internal \
1721
--driver "${PLUGIN}" \
@@ -56,6 +60,9 @@ fi
5660
docker network rm test1
5761

5862

63+
######################
64+
# Test routing config
65+
5966
docker network create \
6067
--driver "${PLUGIN}" \
6168
--ipam-driver jacekkow/pyipam:latest \
@@ -85,3 +92,104 @@ if ! echo "${ROUTES}" | grep 2001:db8:ffff:ffff:ffff:ffff:ffff:ffff; then
8592
fi
8693

8794
docker network rm test2
95+
96+
97+
##############
98+
# Test nogw=1
99+
100+
docker network create \
101+
--driver "${PLUGIN}" \
102+
--opt nogw=1 \
103+
--ipam-driver jacekkow/pyipam:latest \
104+
--ipv6 \
105+
--subnet 192.168.255.0/24 \
106+
--subnet 2001:db8::/32 \
107+
test2
108+
109+
ROUTES=$(docker run --rm --network test2 \
110+
alpine \
111+
/sbin/ip route show
112+
)
113+
if echo "${ROUTES}" | grep 192.168.255.254; then
114+
echo "ERROR: IPv4 route assigned with nogw=1"
115+
exit 1
116+
fi
117+
118+
ROUTES=$(docker run --rm --network test2 \
119+
alpine \
120+
/sbin/ip -6 route show
121+
)
122+
if echo "${ROUTES}" | grep 2001:db8:ffff:ffff:ffff:ffff:ffff:ffff; then
123+
echo "ERROR: IPv6 route assigned with nogw=1"
124+
exit 1
125+
fi
126+
127+
docker network rm test2
128+
129+
130+
###############
131+
# Test nogw4=1
132+
133+
docker network create \
134+
--driver "${PLUGIN}" \
135+
--opt nogw4=1 \
136+
--ipam-driver jacekkow/pyipam:latest \
137+
--ipv6 \
138+
--subnet 192.168.255.0/24 \
139+
--subnet 2001:db8::/32 \
140+
--gateway 2001:db8:ffff:ffff:ffff:ffff:ffff:ffff \
141+
test2
142+
143+
ROUTES=$(docker run --rm --network test2 \
144+
alpine \
145+
/sbin/ip route show
146+
)
147+
if echo "${ROUTES}" | grep 192.168.255.254; then
148+
echo "ERROR: IPv4 route assigned with nogw4=1"
149+
exit 1
150+
fi
151+
152+
ROUTES=$(docker run --rm --network test2 \
153+
alpine \
154+
/sbin/ip -6 route show
155+
)
156+
if ! echo "${ROUTES}" | grep 2001:db8:ffff:ffff:ffff:ffff:ffff:ffff; then
157+
echo "ERROR: IPv6 route not assigned with nogw4=1"
158+
exit 1
159+
fi
160+
161+
docker network rm test2
162+
163+
164+
################
165+
# Test nogw6=1
166+
167+
docker network create \
168+
--driver "${PLUGIN}" \
169+
--opt nogw6=1 \
170+
--ipam-driver jacekkow/pyipam:latest \
171+
--ipv6 \
172+
--subnet 192.168.255.0/24 \
173+
--gateway 192.168.255.254 \
174+
--subnet 2001:db8::/32 \
175+
test2
176+
177+
ROUTES=$(docker run --rm --network test2 \
178+
alpine \
179+
/sbin/ip route show
180+
)
181+
if ! echo "${ROUTES}" | grep 192.168.255.254; then
182+
echo "ERROR: IPv4 route not assigned with nogw6=1"
183+
exit 1
184+
fi
185+
186+
ROUTES=$(docker run --rm --network test2 \
187+
alpine \
188+
/sbin/ip -6 route show
189+
)
190+
if echo "${ROUTES}" | grep 2001:db8:ffff:ffff:ffff:ffff:ffff:ffff; then
191+
echo "ERROR: IPv6 route assigned with nogw6=1"
192+
exit 1
193+
fi
194+
195+
docker network rm test2

0 commit comments

Comments
 (0)