|
| 1 | +mode: 0755 |
| 2 | +path: "/usr/local/bin/ipsec-connect-wait.sh" |
| 3 | +contents: |
| 4 | + inline: | |
| 5 | + #!/bin/bash |
| 6 | + set -x |
| 7 | +
|
| 8 | + if [ ! -e "/etc/ipsec.d/openshift.conf" ]; then |
| 9 | + exit 0 |
| 10 | + fi |
| 11 | +
|
| 12 | + # Modify existing IPsec connection entries with "auto=start" |
| 13 | + # option and restart ipsec systemd service. This helps to |
| 14 | + # establish IKE SAs for the existing IPsec connections with |
| 15 | + # peer nodes. This option will be deleted from connections |
| 16 | + # once ovs-monitor-ipsec process spinned up on the node by |
| 17 | + # ovn-ipsec-host pod, but still it won't reestablish IKE SAs |
| 18 | + # again with peer nodes, so it shouldn't be a problem. |
| 19 | + if ! grep -q "auto=start" /etc/ipsec.d/openshift.conf; then |
| 20 | + sed -i '/^.*conn ovn.*$/a\ auto=start' /etc/ipsec.d/openshift.conf |
| 21 | + fi |
| 22 | + chroot /proc/1/root ipsec restart |
| 23 | +
|
| 24 | + # Wait for upto 60s to get IPsec SAs to establish with peer nodes. |
| 25 | + timeout=60 |
| 26 | + elapsed=0 |
| 27 | + desiredconn="" |
| 28 | + establishedsa="" |
| 29 | + while [[ $elapsed -lt $timeout ]]; do |
| 30 | + desiredconn=$(grep -E '^\s*conn\s+' /etc/ipsec.d/openshift.conf | grep -v '%default' | awk '{print $2}' | tr ' ' '\n' | sort | tr '\n' ' ') |
| 31 | + establishedsa=$(ipsec showstates | grep STATE_V2_ESTABLISHED_CHILD_SA | grep -o '"[^"]*"' | sed 's/"//g' | tr ' ' '\n' | sort | uniq | tr '\n' ' ') |
| 32 | + if [ "$desiredconn" == "$establishedsa" ]; then |
| 33 | + echo "IPsec SAs are established for desired connections after ${elapsed}s" |
| 34 | + break |
| 35 | + else |
| 36 | + echo "IPsec SAs are not established yet, total waited time ${elapsed}s" |
| 37 | + sleep 2s |
| 38 | + fi |
| 39 | + elapsed=$((elapsed + 2)) |
| 40 | + done |
| 41 | +
|
| 42 | + if [[ $elapsed -ge $timeout ]]; then |
| 43 | + echo "Timed out waiting, some connections are not established, desired conns $desiredconn, established conns $establishedsa" |
| 44 | + fi |
0 commit comments