Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding ipv6 support #1655

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 44 additions & 10 deletions heartbeat/aws-vpc-move-ip
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ USAGE="usage: $0 {start|stop|status|meta-data}";
#
###############################################################################


metadata() {
cat <<END
<?xml version="1.0"?>
Expand Down Expand Up @@ -180,7 +179,6 @@ Name of resource type to lookup in route table.
END
}


execute_cmd_as_role(){
cmd=$1
role=$2
Expand Down Expand Up @@ -240,11 +238,21 @@ ec2ip_monitor() {
for rtb in $(echo $OCF_RESKEY_routing_table | sed -e 's/,/ /g'); do
ocf_log info "monitor: check routing table (API call) - $rtb"
if [ -z "${OCF_RESKEY_routing_table_role}" ]; then
cmd="$OCF_RESKEY_awscli --profile $OCF_RESKEY_profile $region_opt --output text ec2 describe-route-tables --route-table-ids $rtb --query RouteTables[*].Routes[?DestinationCidrBlock=='$OCF_RESKEY_ip/32'].$OCF_RESKEY_lookup_type"
if [[ "$OCF_RESKEY_ip" == *[:]* ]];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should use case to avoid these bashables.

Example:

case "$OCF_RESKEY_clientspec" in
*:*:*)

And also bump the indentation back a tab for this section.

then #ipv6
cmd="$OCF_RESKEY_awscli --profile $OCF_RESKEY_profile $region_opt --output text ec2 describe-route-tables --route-table-ids $rtb --query RouteTables[*].Routes[?DestinationIpv6CidrBlock=='$OCF_RESKEY_ip/128'].$OCF_RESKEY_lookup_type"
else #ipv4
cmd="$OCF_RESKEY_awscli --profile $OCF_RESKEY_profile $region_opt --output text ec2 describe-route-tables --route-table-ids $rtb --query RouteTables[*].Routes[?DestinationCidrBlock=='$OCF_RESKEY_ip/32'].$OCF_RESKEY_lookup_type"
fi
ocf_log debug "executing command: $cmd"
ROUTE_TO_INSTANCE="$($cmd)"
else
cmd="$OCF_RESKEY_awscli $region_opt --output text ec2 describe-route-tables --route-table-ids $rtb --query RouteTables[*].Routes[?DestinationCidrBlock=='$OCF_RESKEY_ip/32'].$OCF_RESKEY_lookup_type"
if [[ "$OCF_RESKEY_ip" == *[:]* ]];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This section should also have one less tab to fit match the rest of the code.

then #ipv6
cmd="$OCF_RESKEY_awscli $region_opt --output text ec2 describe-route-tables --route-table-ids $rtb --query RouteTables[*].Routes[?DestinationIpv6CidrBlock=='$OCF_RESKEY_ip/128'].$OCF_RESKEY_lookup_type"
else #ipv4
cmd="$OCF_RESKEY_awscli $region_opt --output text ec2 describe-route-tables --route-table-ids $rtb --query RouteTables[*].Routes[?DestinationCidrBlock=='$OCF_RESKEY_ip/32'].$OCF_RESKEY_lookup_type"
fi
ROUTE_TO_INSTANCE="$(execute_cmd_as_role "$cmd" $OCF_RESKEY_routing_table_role)"
fi
ocf_log debug "Overlay IP is currently routed to ${ROUTE_TO_INSTANCE}"
Expand Down Expand Up @@ -287,7 +295,12 @@ ec2ip_monitor() {


ec2ip_drop() {
cmd="ip addr delete ${OCF_RESKEY_ip}/32 dev $OCF_RESKEY_interface"
if [[ "$OCF_RESKEY_ip" == *[:]* ]];
then
cmd="ip addr delete ${OCF_RESKEY_ip}/128 dev $OCF_RESKEY_interface"
else
cmd="ip addr delete ${OCF_RESKEY_ip}/32 dev $OCF_RESKEY_interface"
fi
ocf_log debug "executing command: $cmd"
output=$($cmd 2>&1)
rc=$?
Expand All @@ -308,8 +321,14 @@ ec2ip_drop() {
fi

# delete remaining route-entries if any
ip route show to exact ${OCF_RESKEY_ip}/32 dev $OCF_RESKEY_interface | xargs -r ip route delete
ip route show table local to exact ${OCF_RESKEY_ip}/32 dev $OCF_RESKEY_interface | xargs -r ip route delete
if [[ "$OCF_RESKEY_ip" == *[:]* ]];
then
ip route show to exact ${OCF_RESKEY_ip}/128 dev $OCF_RESKEY_interface | xargs -r ip route delete
ip route show table local to exact ${OCF_RESKEY_ip}/128 dev $OCF_RESKEY_interface | xargs -r ip route delete
else
ip route show to exact ${OCF_RESKEY_ip}/32 dev $OCF_RESKEY_interface | xargs -r ip route delete
ip route show table local to exact ${OCF_RESKEY_ip}/32 dev $OCF_RESKEY_interface | xargs -r ip route delete
fi

return $OCF_SUCCESS
}
Expand Down Expand Up @@ -346,11 +365,21 @@ ec2ip_get_and_configure() {
EC2_NETWORK_INTERFACE_ID="$(ec2ip_get_instance_eni)"
for rtb in $(echo $OCF_RESKEY_routing_table | sed -e 's/,/ /g'); do
if [ -z "${OCF_RESKEY_routing_table_role}" ]; then
cmd="$OCF_RESKEY_awscli --profile $OCF_RESKEY_profile $region_opt --output text ec2 replace-route --route-table-id $rtb --destination-cidr-block ${OCF_RESKEY_ip}/32 --network-interface-id $EC2_NETWORK_INTERFACE_ID"
if [[ "$OCF_RESKEY_ip" == *[:]* ]];
then
cmd="$OCF_RESKEY_awscli --profile $OCF_RESKEY_profile $region_opt --output text ec2 replace-route --route-table-id $rtb --destination-ipv6-cidr-block ${OCF_RESKEY_ip}/128 --network-interface-id $EC2_NETWORK_INTERFACE_ID"
else
cmd="$OCF_RESKEY_awscli --profile $OCF_RESKEY_profile $region_opt --output text ec2 replace-route --route-table-id $rtb --destination-cidr-block ${OCF_RESKEY_ip}/32 --network-interface-id $EC2_NETWORK_INTERFACE_ID"
fi
ocf_log debug "executing command: $cmd"
$cmd
else
cmd="$OCF_RESKEY_awscli $region_opt --output text ec2 replace-route --route-table-id $rtb --destination-cidr-block ${OCF_RESKEY_ip}/32 --network-interface-id $EC2_NETWORK_INTERFACE_ID"
if [[ "$OCF_RESKEY_ip" == *[:]* ]];
then
cmd="$OCF_RESKEY_awscli $region_opt --output text ec2 replace-route --route-table-id $rtb --destination-ipv6-cidr-block ${OCF_RESKEY_ip}/128 --network-interface-id $EC2_NETWORK_INTERFACE_ID"
else
cmd="$OCF_RESKEY_awscli $region_opt --output text ec2 replace-route --route-table-id $rtb --destination-cidr-block ${OCF_RESKEY_ip}/32 --network-interface-id $EC2_NETWORK_INTERFACE_ID"
fi
update_response="$(execute_cmd_as_role "$cmd" $OCF_RESKEY_routing_table_role)"
fi
rc=$?
Expand All @@ -363,7 +392,12 @@ ec2ip_get_and_configure() {

# Reconfigure the local ip address
ec2ip_drop
cmd="ip addr add ${OCF_RESKEY_ip}/32 dev $OCF_RESKEY_interface"
if [[ "$OCF_RESKEY_ip" == *[:]* ]];
then
cmd="ip addr add ${OCF_RESKEY_ip}/128 dev $OCF_RESKEY_interface"
else
cmd="ip addr add ${OCF_RESKEY_ip}/32 dev $OCF_RESKEY_interface"
fi
ocf_log debug "executing command: $cmd"
$cmd
rc=$?
Expand Down