Skip to content

Commit 01c2431

Browse files
committed
Merge pull request #288 from danwinship/debug-fixes
debug.sh fixes for vxlan anti-spoofing
2 parents 855a002 + 6f48c37 commit 01c2431

File tree

1 file changed

+31
-25
lines changed

1 file changed

+31
-25
lines changed

hack/debug.sh

+31-25
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,18 @@ do_master () {
9292
continue
9393
fi
9494

95-
resolv_ip=$(awk '/\s'$node'$/ { print $1; exit; }' /etc/hosts)
96-
if [ -z "$resolv_ip" ]; then
97-
resolv_ip=$(host $node 2>/dev/null | sed -ne 's/.*has address //p' | head -1)
95+
if ! [[ $node =~ ^[0-9.]*$ ]]; then
96+
resolv_ip=$(awk '/\s'$node'$/ { print $1; exit; }' /etc/hosts)
9897
if [ -z "$resolv_ip" ]; then
99-
echo "Node $node: no IP address in either DNS or /etc/hosts"
98+
resolv_ip=$(host $node 2>/dev/null | sed -ne 's/.*has address //p' | head -1)
99+
if [ -z "$resolv_ip" ]; then
100+
echo "Node $node: no IP address in either DNS or /etc/hosts"
101+
fi
100102
fi
101-
fi
102103

103-
if [ "$reg_ip" != "$resolv_ip" ]; then
104-
echo "Node $node: the IP in OpenShift ($reg_ip) does not match DNS/hosts ($resolv_ip)"
104+
if [ "$reg_ip" != "$resolv_ip" ]; then
105+
echo "Node $node: the IP in OpenShift ($reg_ip) does not match DNS/hosts ($resolv_ip)"
106+
fi
105107
fi
106108

107109
try_eval ping -c1 -W2 $node
@@ -110,10 +112,10 @@ do_master () {
110112
# Outputs a list of nodes in the form "nodename IP"
111113
oc get nodes --template '{{range .items}}{{$name := .metadata.name}}{{range .status.addresses}}{{if eq .type "InternalIP"}}{{$name}} {{.address}}{{"\n"}}{{end}}{{end}}{{end}}' > $logdir/meta/nodeinfo
112114

113-
# Outputs a list of pods in the form "minion-1 mypod namespace 10.1.0.2 e4f1d61b"
114-
oc get pods --all-namespaces --template '{{range .items}}{{if .status.containerStatuses}}{{if (index .status.containerStatuses 0).ready}}{{if not .spec.hostNetwork}}{{.spec.nodeName}} {{.metadata.name}} {{.metadata.namespace}} {{.status.podIP}} {{printf "%.21s" (index .status.containerStatuses 0).containerID}}{{"\n"}}{{end}}{{end}}{{end}}{{end}}' | sed -e 's|docker://||' > $logdir/meta/podinfo
115+
# Outputs a list of pods in the form "minion-1 172.17.0.1 mypod namespace 10.1.0.2 e4f1d61b"
116+
oc get pods --all-namespaces --template '{{range .items}}{{if .status.containerStatuses}}{{if (index .status.containerStatuses 0).ready}}{{if not .spec.hostNetwork}}{{.spec.nodeName}} {{.status.hostIP}} {{.metadata.name}} {{.metadata.namespace}} {{.status.podIP}} {{printf "%.21s" (index .status.containerStatuses 0).containerID}}{{"\n"}}{{end}}{{end}}{{end}}{{end}}' | sed -e 's|docker://||' > $logdir/meta/podinfo
115117

116-
# Outputs a list of services in the form "myservice:namespace:172.30.0.99:tcp:5454"
118+
# Outputs a list of services in the form "myservice namespace 172.30.0.99 tcp 5454"
117119
oc get services --all-namespaces --template '{{range .items}}{{if ne .spec.clusterIP "None"}}{{.metadata.name}} {{.metadata.namespace}} {{.spec.clusterIP}} {{(index .spec.ports 0).protocol}} {{(index .spec.ports 0).port}}{{"\n"}}{{end}}{{end}}' | sed -e 's/ TCP / tcp /g' -e 's/ UDP / udp /g' > $logdir/meta/serviceinfo
118120
}
119121

@@ -145,14 +147,16 @@ do_pod_to_pod_connectivity_check () {
145147
base_pod_ether=$8
146148
other_pod_name=$9
147149
other_pod_addr=${10}
150+
other_pod_nodeaddr=${11}
148151

149152
echo $where pod, $namespace namespace: | tr '[a-z]' '[A-Z]'
150153
echo ""
151154

152155
other_pod_port=$(get_port_for_addr $other_pod_addr)
153-
other_pod_vnid=$(get_vnid_for_addr $other_pod_addr)
154-
if [ -z "$other_pod_port" ]; then
155-
other_pod_port=1 # vxlan
156+
if [ -n "$other_pod_port" ]; then
157+
other_pod_vnid=$(get_vnid_for_addr $other_pod_addr)
158+
in_spec="in_port=${other_pod_port}"
159+
else
156160
case $namespace in
157161
default)
158162
other_pod_vnid=0
@@ -165,13 +169,14 @@ do_pod_to_pod_connectivity_check () {
165169
other_pod_vnid=6
166170
;;
167171
esac
172+
in_spec="in_port=1,tun_src=${other_pod_nodeaddr},tun_id=${other_pod_vnid}"
168173
fi
169174

170175
echo "$base_pod_name -> $other_pod_name"
171176
echo_and_eval ovs-appctl ofproto/trace br0 "in_port=${base_pod_port},reg0=${base_pod_vnid},ip,nw_src=${base_pod_addr},nw_dst=${other_pod_addr}"
172177
echo ""
173178
echo "$other_pod_name -> $base_pod_name"
174-
echo_and_eval ovs-appctl ofproto/trace br0 "in_port=${other_pod_port},reg0=${other_pod_vnid},ip,nw_src=${other_pod_addr},nw_dst=${base_pod_addr},dl_dst=${base_pod_ether}"
179+
echo_and_eval ovs-appctl ofproto/trace br0 "${in_spec},ip,nw_src=${other_pod_addr},nw_dst=${base_pod_addr},dl_dst=${base_pod_ether}"
175180
echo ""
176181

177182
if nsenter -n -t $base_pod_pid -- ping -c 1 -W 2 $other_pod_addr &> /dev/null; then
@@ -281,7 +286,7 @@ do_node () {
281286
# Remember the name, address, namespace, and pid of the first pod we find on
282287
# this node which is not in the default namespace
283288
base_pod_addr=
284-
while read pod_node pod_name pod_ns pod_addr pod_id; do
289+
while read pod_node pod_nodeaddr pod_name pod_ns pod_addr pod_id; do
285290
if [ "$pod_node" != "$node" ]; then
286291
continue
287292
fi
@@ -341,7 +346,7 @@ do_node () {
341346

342347
# Now find other pods of various types to test connectivity against
343348
touch $lognode/pod-connectivity
344-
while read pod_node pod_name pod_ns pod_addr pod_id; do
349+
while read pod_node pod_nodeaddr pod_name pod_ns pod_addr pod_id; do
345350
if [ "$pod_addr" = "$base_pod_addr" ]; then
346351
continue
347352
fi
@@ -367,7 +372,7 @@ do_node () {
367372
$base_pod_name $base_pod_addr \
368373
$base_pod_pid $base_pod_port \
369374
$base_pod_vnid $base_pod_ether \
370-
$pod_name $pod_addr \
375+
$pod_name $pod_addr $pod_nodeaddr \
371376
&>> $lognode/pod-connectivity
372377
eval did_${where}_${namespace}=1
373378
done < $logdir/meta/podinfo
@@ -456,14 +461,15 @@ do_master_and_nodes ()
456461

457462
######## Main program starts here
458463

459-
systemd_dir=/usr/lib/systemd/system/
460-
for name in openshift origin atomic-openshift; do
461-
if [ -f $systemd_dir/$name-master.service ]; then
462-
aos_master_service=$name-master.service
463-
fi
464-
if [ -f $systemd_dir/$name-node.service ]; then
465-
aos_node_service=$name-node.service
466-
fi
464+
for systemd_dir in /etc/systemd/system /usr/lib/systemd/system; do
465+
for name in openshift origin atomic-openshift; do
466+
if [ -f $systemd_dir/$name-master.service ]; then
467+
aos_master_service=$name-master.service
468+
fi
469+
if [ -f $systemd_dir/$name-node.service ]; then
470+
aos_node_service=$name-node.service
471+
fi
472+
done
467473
done
468474

469475
case "$1" in

0 commit comments

Comments
 (0)