@@ -31,12 +31,12 @@ function setup_network() {
31
31
# The pod may die and get restarted; only try to add the
32
32
# address/route/rules if they are not already there.
33
33
if ! ip route get " ${EGRESS_GATEWAY} " | grep -q macvlan0; then
34
- ip addr add " ${EGRESS_SOURCE} " /32 dev macvlan0
35
- ip link set up dev macvlan0
34
+ ip addr add " ${EGRESS_SOURCE} " /32 dev macvlan0
35
+ ip link set up dev macvlan0
36
36
37
- ip route add " ${EGRESS_GATEWAY} " /32 dev macvlan0
38
- ip route del default
39
- ip route add default via " ${EGRESS_GATEWAY} " dev macvlan0
37
+ ip route add " ${EGRESS_GATEWAY} " /32 dev macvlan0
38
+ ip route del default
39
+ ip route add default via " ${EGRESS_GATEWAY} " dev macvlan0
40
40
fi
41
41
42
42
# Update neighbor ARP caches in case another node previously had the IP. (This is
@@ -61,43 +61,43 @@ function gen_iptables_rules() {
61
61
did_fallback=
62
62
declare -A used_ports=()
63
63
while read dest; do
64
- if [[ " ${dest} " =~ ^${BLANK_LINE_OR_COMMENT_REGEX} $ ]]; then
65
- # comment or blank line
66
- continue
67
- fi
68
- if [[ -n " ${did_fallback} " ]]; then
69
- die " EGRESS_DESTINATION fallback IP must be the last line" 1>&2
70
- fi
71
-
72
- localport=" "
73
- if [[ " ${dest} " =~ ^${IP_REGEX} $ ]]; then
74
- # single IP address: do fallback "all ports to same IP"
75
- echo -A PREROUTING -i eth0 -j DNAT --to-destination " ${dest} "
76
- did_fallback=1
77
-
78
- elif [[ " ${dest} " =~ ^${PORT_REGEX} \ +${PROTO_REGEX} \ +${IP_REGEX} $ ]]; then
79
- read localport proto destip <<< " ${dest}"
80
- echo -A PREROUTING -i eth0 -p " ${proto} " --dport " ${localport} " -j DNAT --to-destination " ${destip} "
81
-
82
- elif [[ " ${dest} " =~ ^${PORT_REGEX} \ +${PROTO_REGEX} \ +${IP_REGEX} \ +${PORT_REGEX} $ ]]; then
83
- read localport proto destip destport <<< " ${dest}"
84
- validate_port ${destport}
85
- echo -A PREROUTING -i eth0 -p " ${proto} " --dport " ${localport} " -j DNAT --to-destination " ${destip} :${destport} "
86
-
87
- else
88
- die " EGRESS_DESTINATION value '${dest} ' is invalid" 1>&2
89
-
90
- fi
91
-
92
- if [[ -n " ${localport} " ]]; then
93
- validate_port ${localport}
94
-
95
- if [[ " ${used_ports[${localport}]:- x} " == " x" ]]; then
96
- used_ports[${localport} ]=1
97
- else
98
- die " EGRESS_DESTINATION localport $localport is already used, must be unique for each destination"
99
- fi
64
+ if [[ " ${dest} " =~ ^${BLANK_LINE_OR_COMMENT_REGEX} $ ]]; then
65
+ # comment or blank line
66
+ continue
67
+ fi
68
+ if [[ -n " ${did_fallback} " ]]; then
69
+ die " EGRESS_DESTINATION fallback IP must be the last line" 1>&2
70
+ fi
71
+
72
+ localport=" "
73
+ if [[ " ${dest} " =~ ^${IP_REGEX} $ ]]; then
74
+ # single IP address: do fallback "all ports to same IP"
75
+ echo -A PREROUTING -i eth0 -j DNAT --to-destination " ${dest} "
76
+ did_fallback=1
77
+
78
+ elif [[ " ${dest} " =~ ^${PORT_REGEX} \ +${PROTO_REGEX} \ +${IP_REGEX} $ ]]; then
79
+ read localport proto destip <<< " ${dest}"
80
+ echo -A PREROUTING -i eth0 -p " ${proto} " --dport " ${localport} " -j DNAT --to-destination " ${destip} "
81
+
82
+ elif [[ " ${dest} " =~ ^${PORT_REGEX} \ +${PROTO_REGEX} \ +${IP_REGEX} \ +${PORT_REGEX} $ ]]; then
83
+ read localport proto destip destport <<< " ${dest}"
84
+ validate_port ${destport}
85
+ echo -A PREROUTING -i eth0 -p " ${proto} " --dport " ${localport} " -j DNAT --to-destination " ${destip} :${destport} "
86
+
87
+ else
88
+ die " EGRESS_DESTINATION value '${dest} ' is invalid" 1>&2
89
+
90
+ fi
91
+
92
+ if [[ -n " ${localport} " ]]; then
93
+ validate_port ${localport}
94
+
95
+ if [[ " ${used_ports[${localport}]:- x} " == " x" ]]; then
96
+ used_ports[${localport} ]=1
97
+ else
98
+ die " EGRESS_DESTINATION localport $localport is already used, must be unique for each destination"
100
99
fi
100
+ fi
101
101
102
102
done <<< " ${EGRESS_DESTINATION}"
103
103
echo -A POSTROUTING -j SNAT --to-source " ${EGRESS_SOURCE} "
@@ -133,23 +133,23 @@ function wait_until_killed() {
133
133
134
134
case " ${EGRESS_ROUTER_MODE:= legacy} " in
135
135
init)
136
- setup_network
137
- setup_iptables
138
- ;;
136
+ setup_network
137
+ setup_iptables
138
+ ;;
139
139
140
140
legacy)
141
- setup_network
142
- setup_iptables
143
- wait_until_killed
144
- ;;
141
+ setup_network
142
+ setup_iptables
143
+ wait_until_killed
144
+ ;;
145
145
146
146
http-proxy)
147
- setup_network
148
- ;;
147
+ setup_network
148
+ ;;
149
149
150
150
unit-test)
151
- gen_iptables_rules
152
- ;;
151
+ gen_iptables_rules
152
+ ;;
153
153
154
154
* )
155
155
die " Unrecognized EGRESS_ROUTER_MODE '${EGRESS_ROUTER_MODE} '"
0 commit comments