-
Notifications
You must be signed in to change notification settings - Fork 20
/
Makefile
55 lines (42 loc) · 1.6 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
SHELL = /bin/sh
BRIDGE := diyc0
ETH0 := $(shell ip -o -4 route show to default | awk '{print $$5}')
CC = gcc
CFLAGS = -std=c99 -Wall -Wno-unused-result -Werror -O2
all: diyc nsexec
diyc: src/diyc.c
$(CC) $(CFLAGS) src/diyc.c -o $@
nsexec: src/nsexec.c
$(CC) $(CFLAGS) src/nsexec.c -o $@
.PHONY: clean, net-setup, net-clean, setup, rmi, rm
clean:
rm -rf nsexec diyc
rmi:
rm -rf images/$(img)
rm:
sudo rm -rf containers/*
pull:
if [ -d images/$(img) ]; then rm -rf images/$(img); fi
mkdir -p images/$(img)
tar xf $(tar) -C images/$(img)
setup: net-setup
mkdir -p containers
mkdir -p images
net-setup:
sudo iptables -A FORWARD -i $(ETH0) -o veth -j ACCEPT || true
sudo iptables -A FORWARD -o $(ETH0) -i veth -j ACCEPT || true
sudo iptables -t nat -A POSTROUTING -s 172.16.0.0/16 -j MASQUERADE || true
sudo ip link add name $(BRIDGE) type bridge || true
sudo ip addr add dev $(BRIDGE) 172.16.0.1/24 || true
sudo ip link set $(BRIDGE) up || true
sudo iptables -A FORWARD -i $(ETH0) -o $(BRIDGE) -j ACCEPT || true
sudo iptables -A FORWARD -o $(ETH0) -i $(BRIDGE) -j ACCEPT || true
sudo iptables -A FORWARD -o $(BRIDGE) -i $(BRIDGE) -j ACCEPT || true
net-clean:
sudo iptables -D FORWARD -i $(ETH0) -o veth -j ACCEPT || true
sudo iptables -D FORWARD -o $(ETH0) -i veth -j ACCEPT || true
sudo iptables -t nat -D POSTROUTING -s 172.16.0.0/16 -j MASQUERADE || true
sudo iptables -D FORWARD -i $(ETH0) -o $(BRIDGE) -j ACCEPT || true
sudo iptables -D FORWARD -o $(ETH0) -i $(BRIDGE) -j ACCEPT || true
sudo iptables -D FORWARD -o $(BRIDGE) -i $(BRIDGE) -j ACCEPT || true
sudo ip link delete $(BRIDGE) || true