-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
[SmartSwitch] DPU Management Traffic Forwarding script #19431
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
50e3f9b
DPU Management Traffic Forwarding script addition
gpunathilell 145c4c8
Preliminary check to run only on smart-switch systems
gpunathilell 27d5349
Add exit condition
gpunathilell 7054d3f
Add function call
gpunathilell 2bdd332
Added permission check
gpunathilell e27420e
Add execution permission
gpunathilell 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 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 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,79 @@ | ||
#!/bin/bash | ||
#Script to control the DPU management traffic forwarding through the SmartSwitch | ||
|
||
command_name=$0 | ||
|
||
usage(){ | ||
echo "Syntax: $command_name -e|--enable -d|--disable" | ||
echo "Arguments:" | ||
echo "-e Enable dpu management traffic forwarding" | ||
echo "-d Disable dpu management traffic forwarding" | ||
} | ||
|
||
add_rem_valid_iptable(){ | ||
local op=$1 | ||
local table=$2 | ||
local chain=$3 | ||
shift 3 | ||
local rule="$@" | ||
iptables -t $table -C $chain $rule &>/dev/null | ||
local exit_status=$? | ||
local exec_cond=0 | ||
if [ "$op" = "enable" ]; then | ||
exec_command="iptables -t $table -A $chain $rule" | ||
[ "$exit_status" -eq 0 ] || exec_cond=1 # Execute if rule is currently not present | ||
else | ||
exec_command="iptables -t $table -D $chain $rule" | ||
[ "$exit_status" -ne 0 ] || exec_cond=1 # Execute if rule is currently present | ||
fi | ||
if [ "$exec_cond" -eq 1 ]; then | ||
eval "$exec_command" | ||
else | ||
echo "$exec_command not requried, will not be executed" | ||
fi | ||
} | ||
|
||
control_forwarding(){ | ||
local op=$1 | ||
local value=0 | ||
if [ "$op" = "enable" ]; then | ||
value=1 | ||
fi | ||
echo $value > /proc/sys/net/ipv4/ip_forward | ||
gpunathilell marked this conversation as resolved.
Show resolved
Hide resolved
|
||
echo $value > /proc/sys/net/ipv4/conf/eth0/forwarding | ||
} | ||
|
||
ctrl_dpu_forwarding(){ | ||
local op=$1 | ||
control_forwarding $op | ||
add_rem_valid_iptable $op nat POSTROUTING -o ${mgmt_iface} -j MASQUERADE | ||
add_rem_valid_iptable $op filter FORWARD -i ${mgmt_iface} -o ${midplane_iface} -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT | ||
add_rem_valid_iptable $op filter FORWARD -i ${midplane_iface} -o ${mgmt_iface} -j ACCEPT | ||
if [ "$op" = "enable" ]; then | ||
echo "Enabled DPU management traffic Forwarding" | ||
else | ||
echo "Disabled DPU management traffic Forwarding" | ||
fi | ||
} | ||
|
||
mgmt_iface=eth0 | ||
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. Is mgmt_iface eth0 common for all vendor SKUs? 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. Yes in SONiC all vendors use |
||
midplane_iface=bridge-midplane | ||
|
||
if ! ifconfig "$midplane_iface" > /dev/null 2>&1; then | ||
echo "$midplane_iface doesn't exist! Please run on smart switch system" | ||
exit 1 | ||
fi | ||
|
||
case $1 in | ||
-e|--enable) | ||
ctrl_dpu_forwarding enable | ||
;; | ||
-d|--disable) | ||
ctrl_dpu_forwarding disable | ||
;; | ||
*) | ||
echo "Incorrect Usage!" | ||
usage | ||
exit 1 | ||
;; | ||
esac |
Oops, something went wrong.
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.
Where is the trigger to execute this script with enable/disable option? Is this part of pmon?
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.
There is no trigger for this script, this is just a utility script which would be helpful for enabling DPU traffic to reach the internet in cases where connectivity is required, Example Usage:
SONiC to SONiC upgrade on the dpu can be performed easily if we enable DPU management traffic forwarding using this script, as the DPU can download the image directly, instead of first transferring the image to switch and then to DPU