This repository was archived by the owner on Aug 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
add coreos-teardown-initramfs-network.service #159
Merged
+110
−0
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8bdbbbe
add coreos-teardown-initramfs-network.service
dustymabe 70c7cd5
coreos-teardown-initramfs-network: refactor into more functions
dustymabe 0d219cb
coreos-teardown-initramfs-network: also propagate initramfs networkin…
dustymabe e0efb09
coreos-teardown-initramfs-network: remove state files on switch
dustymabe 42b2f06
coreos-teardown-initramfs-network: take down teams as well
dustymabe 03b0035
coreos-teardown-initramfs-network: take down routes too
dustymabe 38c1c35
coreos-teardown-initramfs-network: simplify networking takedown
dustymabe 89f2673
coreos-teardown-initramfs-network: enable the service statically
dustymabe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
dracut/30ignition/coreos-teardown-initramfs-network.service
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| # Clean up the initramfs networking on first boot | ||
| # so the real network is being brought up | ||
| # https://github.com/coreos/fedora-coreos-tracker/issues/394#issuecomment-599721763 | ||
|
|
||
| [Unit] | ||
| Description=Tear down initramfs networking | ||
| DefaultDependencies=false | ||
| After=ignition-files.service | ||
| Before=ignition-complete.target | ||
|
|
||
| # Make sure ExecStop= runs before we switch root | ||
| Conflicts=initrd-switch-root.target umount.target | ||
| Before=initrd-switch-root.target | ||
|
|
||
| # Make sure if ExecStart= fails, the boot fails | ||
| OnFailure=emergency.target | ||
| OnFailureJobMode=isolate | ||
|
|
||
| [Service] | ||
| Type=oneshot | ||
| RemainAfterExit=yes | ||
| ExecStop=/usr/sbin/coreos-teardown-initramfs-network |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| #!/bin/bash | ||
| # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- | ||
| # ex: ts=8 sw=4 sts=4 et filetype=sh | ||
|
|
||
| set -euo pipefail | ||
|
|
||
|
|
||
| # Propagate initramfs networking if desired. The policy here is: | ||
| # | ||
| # - If a networking configuration was provided before this point | ||
| # (most likely via Ignition) and exists in the real root then | ||
| # we do nothing and don't propagate any initramfs networking. | ||
| # - If a user did not provide any networking configuration | ||
| # then we'll propagate the initramfs networking configuration | ||
| # into the real root. | ||
| # | ||
| # See https://github.com/coreos/fedora-coreos-tracker/issues/394#issuecomment-599721173 | ||
| propagate_initramfs_networking() { | ||
| if [ -n "$(ls -A /sysroot/etc/NetworkManager/system-connections/)" ]; then | ||
| echo "info: networking config is defined in the real root" | ||
| echo "info: will not attempt to propagate initramfs networking" | ||
| else | ||
| echo "info: no networking config is defined in the real root" | ||
| if [ -n "$(ls -A /run/NetworkManager/system-connections/)" ]; then | ||
| echo "info: propagating initramfs networking config to the real root" | ||
| cp /run/NetworkManager/system-connections/* /sysroot/etc/NetworkManager/system-connections/ | ||
| else | ||
| echo "info: no initramfs networking information to propagate" | ||
| fi | ||
| fi | ||
| } | ||
|
|
||
| down_interface() { | ||
| echo "info: taking down network device: $1" | ||
| # On recommendation from the NM team let's try to delete the device | ||
| # first and if that doesn't work then set it to down and flush any | ||
| # associated addresses. Deleting virtual devices (bonds, teams, bridges, | ||
| # ip-tunnels, etc) will clean up any associated kernel resources. A real | ||
| # device can't be deleted so that will fail and we'll fallback to setting | ||
| # it down and flushing addresses. | ||
| if ! ip link delete $1; then | ||
| ip link set $1 down | ||
| ip addr flush dev $1 | ||
| fi | ||
| } | ||
|
|
||
| # Iterate through the interfaces in the machine and take them down. | ||
| # Note that in the futre we would like to possibly use `nmcli` networking off` | ||
| # for this. See the following two comments for details: | ||
| # https://github.com/coreos/fedora-coreos-tracker/issues/394#issuecomment-599721763 | ||
| # https://github.com/coreos/fedora-coreos-tracker/issues/394#issuecomment-599746049 | ||
| down_interfaces() { | ||
| if ! [ -z "$(ls /sys/class/net)" ]; then | ||
| for f in /sys/class/net/*; do | ||
dustymabe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| interface=$(basename "$f") | ||
| # The `bonding_masters` entry is not a true interface and thus | ||
| # cannot be taken down. | ||
| if [ "$interface" == "bonding_masters" ]; then continue; fi | ||
| down_interface $interface | ||
| done | ||
| fi | ||
| } | ||
|
|
||
| main() { | ||
| # Take down all interfaces set up in the initramfs | ||
| down_interfaces | ||
|
|
||
| # Clean up all routing | ||
| echo "info: flushing all routing" | ||
| ip route flush table main | ||
| ip route flush cache | ||
|
|
||
| # Propagate initramfs networking if needed | ||
| propagate_initramfs_networking | ||
|
|
||
| # Now that the configuration has been propagated (or not) | ||
| # clean it up so that no information from outside of the | ||
| # real root is passed on to NetworkManager in the real root | ||
| rm -rf /run/NetworkManager/ | ||
| } | ||
|
|
||
| main | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.