Skip to content

Commit c7f63d3

Browse files
joe-usa-amznsaiharsha1994
authored andcommitted
removing uncessary IMDS calls and overwrite of configs
We want to remove the IMDS call which is made for the ipv6-cidr block for ipv4 interfaces by checking to see if supports ipv6 first. Then we want to prevent the case where IMDS is throttled, an empty local-ipv4 is returned and the script overwrites an existing config using _install_and_reload. We want to make sure value are not empty before overwriting anything.
1 parent 80ce62f commit c7f63d3

File tree

2 files changed

+25
-16
lines changed

2 files changed

+25
-16
lines changed

debian/patches/update-networkd-priorities.patch

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
From 3c792705401188860d8c40fd192701696f77c43c Mon Sep 17 00:00:00 2001
2-
From: Noah Meyerhans <nmeyerha@amazon.com>
3-
Date: Thu, 7 Mar 2024 17:00:45 -0800
1+
From 2761694987b588be2f6cc63e704a421e8a088b81 Mon Sep 17 00:00:00 2001
2+
From: Joe Kurokawa <joekurok@amazon.com>
3+
Date: Tue, 6 May 2025 21:31:36 +0000
44
Subject: [PATCH] change the priority of the networkd configs
55

66
ensure they're order before netplan
@@ -25,19 +25,19 @@ index a79fd09..9cb623b 100755
2525
;;
2626
stop|cleanup)
2727
diff --git a/lib/lib.sh b/lib/lib.sh
28-
index 0a2ebc2..de3b00f 100644
28+
index 981f643..858dc86 100644
2929
--- a/lib/lib.sh
3030
+++ b/lib/lib.sh
31-
@@ -151,7 +151,7 @@ create_ipv4_aliases() {
32-
local addresses
33-
subnet_supports_ipv4 "$iface" || return 0
34-
addresses=$(get_iface_imds $mac local-ipv4s | tail -n +2 | sort)
31+
@@ -149,7 +149,7 @@ create_ipv4_aliases() {
32+
info "No addresses found for ${iface}"
33+
return 0
34+
fi
3535
- local drop_in_dir="${unitdir}/70-${iface}.network.d"
3636
+ local drop_in_dir="${unitdir}/07-${iface}.network.d"
3737
mkdir -p "$drop_in_dir"
3838
local file="$drop_in_dir/ec2net_alias.conf"
3939
local work="${file}.new"
40-
@@ -210,7 +210,7 @@ create_rules() {
40+
@@ -208,7 +208,7 @@ create_rules() {
4141
local family=$4
4242
local addrs prefixes
4343
local local_addr_key subnet_pd_key
@@ -46,7 +46,7 @@ index 0a2ebc2..de3b00f 100644
4646
mkdir -p "$drop_in_dir"
4747

4848
local -i ruleid=$((device_number+rule_base+100*network_card))
49-
@@ -373,7 +373,7 @@ create_interface_config() {
49+
@@ -376,7 +376,7 @@ create_interface_config() {
5050

5151
local -i retval=0
5252

@@ -56,5 +56,5 @@ index 0a2ebc2..de3b00f 100644
5656
[ ! -v EC2_IF_INITIAL_SETUP ]; then
5757
debug "Using existing cfgfile ${cfgfile}"
5858
--
59-
2.25.1
59+
2.47.1
6060

lib/lib.sh

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ get_iface_imds() {
116116
_install_and_reload() {
117117
local src=$1
118118
local dest=$2
119-
if [ -e "$dest" ]; then
119+
if [[ -e "$dest" && -s "$src" ]]; then
120120
if [ "$(md5sum < $dest)" = "$(md5sum < $src)" ]; then
121121
# The config is unchanged since last run. Nothing left to do:
122122
rm "$src"
@@ -145,6 +145,10 @@ create_ipv4_aliases() {
145145
local addresses
146146
subnet_supports_ipv4 "$iface" || return 0
147147
addresses=$(get_iface_imds $mac local-ipv4s | tail -n +2 | sort)
148+
if [[ -z "$addresses" ]]; then
149+
info "No addresses found for ${iface}"
150+
return 0
151+
fi
148152
local drop_in_dir="${unitdir}/70-${iface}.network.d"
149153
mkdir -p "$drop_in_dir"
150154
local file="$drop_in_dir/ec2net_alias.conf"
@@ -234,6 +238,10 @@ create_rules() {
234238
# IMDS failure, a propagation delay, or a legitimately empty
235239
# response.
236240
addrs=$(get_iface_imds ${ether} ${local_addr_key} || true)
241+
if [[ -z "$addrs" ]]; then
242+
info "No addresses found for ${ether}"
243+
return 0
244+
fi
237245

238246
# don't fail or retry prefix retrieval. IMDS currently returns an
239247
# error, rather than an empty response, if no prefixes are
@@ -294,15 +302,16 @@ Table=${tableid}
294302
Gateway=_ipv6ra
295303
296304
EOF
297-
for dest in $(subnet_prefixroutes "$ether" ipv6); do
298-
cat <<EOF >> "${dropin}.tmp"
305+
if subnet_supports_ipv6 "$iface"; then
306+
for dest in $(subnet_prefixroutes "$ether" ipv6); do
307+
cat <<EOF >> "${dropin}.tmp"
299308
[Route]
300309
Table=${tableid}
301310
Destination=${dest}
302311
303312
EOF
304-
done
305-
313+
done
314+
fi
306315
if subnet_supports_ipv4 "$iface"; then
307316
# if not in a v6-only network, add IPv4 routes to the private table
308317
cat <<EOF >> "${dropin}.tmp"

0 commit comments

Comments
 (0)