-
Notifications
You must be signed in to change notification settings - Fork 73
Add support for translating ifcfg kernel cmdline argument to ip #1957
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
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
123 changes: 123 additions & 0 deletions
123
live/root/usr/lib/dracut/modules.d/99agama-cmdline/agama-network-compat.sh
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,123 @@ | ||
| #!/bin/bash | ||
|
|
||
| [ -e /dracut-state.sh ] && . /dracut-state.sh | ||
|
|
||
| . /lib/dracut-lib.sh | ||
| . /lib/net-lib.sh | ||
|
|
||
| ifcfg_to_ip() { | ||
| local ip | ||
| local v="${2}", | ||
| local interface="$1" | ||
| local conf_path="/etc/cmdline.d/40-agama-network.conf" | ||
| set -- | ||
| while [ -n "$v" ]; do | ||
| set -- "$@" "${v%%,*}" | ||
| v=${v#*,} | ||
| done | ||
|
|
||
| ### See https://en.opensuse.org/SDB:Linuxrc#Network_Config | ||
| # ifcfg=<interface_spec>=[try,]dhcp*,[rfc2132,]OPTION1=value1,OPTION2=value2... | ||
| if str_starts "$1" "dhcp"; then | ||
| autoconf="$1" | ||
| if [ "$autoconf" = "dhcp4" ]; then | ||
| autoconf="dhcp" | ||
| fi | ||
| case $autoconf in | ||
| "dhcp" | "dhcp6") | ||
| if [ "$interface" = "*" ]; then | ||
| echo "ip=${1}" >>$conf_path | ||
|
|
||
| else | ||
| echo "ip=${interface}:${1}" >>$conf_path | ||
| fi | ||
| ;; | ||
| *) | ||
| echo "No supported option ${1}" | ||
| ;; | ||
| esac | ||
|
|
||
| return 0 | ||
| fi | ||
|
|
||
| # ifcifg=<interface_spec>=ip,gateway,nameserver,domain | ||
| if strglob "$1" "*.*.*.*/*"; then | ||
| [[ -n "$2" ]] && gateway=$2 | ||
| [[ -n "$3" ]] && nameserver=$3 | ||
|
|
||
| ip="$1 " | ||
| set -- | ||
| while [ -n "$ip" ]; do | ||
| set -- "$@" "${ip%% *}" | ||
| ip="${ip#* }" | ||
| done | ||
|
|
||
| ## TODO: IP is a LIST_IP | ||
| ip="$1" | ||
| mask=${ip##*/} | ||
| ip=${ip%%/*} | ||
| shift | ||
|
|
||
| ## Configure the first interface, the gateway must belong to the same network | ||
| echo "ip=${ip}::${gateway}:$mask::${interface}" >>$conf_path | ||
|
|
||
| ## Configure multiple addresses for the same interface | ||
| while [[ $# -gt 0 ]]; do | ||
| ip="$1" | ||
| mask=${ip##*/} | ||
| ip=${ip%%/*} | ||
| echo "ip=${ip}:::$mask::${interface}" >>$conf_path | ||
| shift | ||
| done | ||
|
|
||
| ## Configure nameservers | ||
| if [[ -n $nameserver ]]; then | ||
| nameserver="$nameserver " | ||
| while [ -n "$nameserver" ]; do | ||
| echo "nameserver=${nameserver%% *}" >>$conf_path | ||
| nameserver="${nameserver#* }" | ||
| done | ||
| fi | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have to say that without automatic testing I would be very scared to touch this file to avoid breaking anything. |
||
| fi | ||
|
|
||
| return 0 | ||
| } | ||
|
|
||
| translate_ifcfg() { | ||
| local i | ||
| local vlan | ||
| local phydevice | ||
| local conf_path="/etc/cmdline.d/40-agama-network.conf" | ||
|
|
||
| while read -r i; do | ||
| set -- | ||
| echo "### Processing $i ###" | ||
| set -- "$@" "${i%%=*}" | ||
| options="${i#*=}" | ||
| pattern="$1" | ||
| unset vlan phydevice | ||
|
|
||
| if str_starts "$options" "try,"; then | ||
| options="${i#*try,*}" | ||
| fi | ||
|
|
||
| # The pattern Looks like a VLAN like eth0.10 | ||
| if strglobin "$pattern" "*.[0-9]*"; then | ||
| phydevice=${pattern%.*} | ||
| vlan="vlan=$1:$phydevice" | ||
| echo "$vlan" >>$conf_path | ||
| fi | ||
|
|
||
| # Try to translate the pattern as it is, we cannot try to apply the config to check if | ||
| # it is valid because the nm-initrd-generator is called by a cmdline hook unless we call | ||
| # explicitly passing the getcmdline result | ||
| ifcfg_to_ip "$pattern" "$options" | ||
|
|
||
| set -- | ||
| unset options pattern CMDLINE | ||
| done <<<"$(getargs ifcfg)" | ||
|
|
||
| return 0 | ||
| } | ||
|
|
||
| translate_ifcfg | ||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would write "Unsupported option ${1}"