-
Notifications
You must be signed in to change notification settings - Fork 5
RDK-59247: cleaning up network scripts. #402
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
base: develop
Are you sure you want to change the base?
Conversation
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.
Pull request overview
This PR refactors network script functionality by inlining code from updateGlobalIPInfo.sh directly into the dispatcher scripts, eliminating external script invocations and improving script organization.
Key Changes
- Refactored
updateGlobalIPInfo.shfunctionality into inline functions withinNM_preDown.shandNM_Dispatcher.sh - Replaced external script calls with direct function invocations for better performance
- Added helper functions
refresh_devicedetails(),check_valid_IPaddress(), andupdate_global_ip_info_{add,delete}()to both scripts
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 12 comments.
| File | Description |
|---|---|
| lib/rdk/NM_preDown.sh | Added three helper functions and replaced external updateGlobalIPInfo.sh calls with inline update_global_ip_info_delete() function for handling IP address deletion |
| lib/rdk/NM_Dispatcher.sh | Added three helper functions and replaced external updateGlobalIPInfo.sh calls with inline update_global_ip_info_add() function for handling IP address addition |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| NMdispatcherLog "update_global_ip_info: cmd:$cmd, mode:$mode, ifc:$ifc, addr:$addr, flags:$flags" | ||
|
|
||
| if [ "x$cmd" == "xadd" ] && [ "x$flags" == "xglobal" ]; then |
Copilot
AI
Dec 19, 2025
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.
Use single brackets '[' with '=' instead of double brackets '[[' with '==' for POSIX compliance in shell scripts. The current syntax is bash-specific, but the shebang indicates a generic sh interpreter.
| return 1 | ||
| fi | ||
| elif [ "x$mode" == "xipv4" ]; then | ||
| autoIPTrunc=$(echo $addr | cut -d "." -f1-2) |
Copilot
AI
Dec 19, 2025
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.
The variable 'autoIPTrunc' is not declared as local, which could lead to variable leakage in the shell environment. Declare it with 'local' to keep it scoped to this function.
| autoIPTrunc=$(echo $addr | cut -d "." -f1-2) | |
| local autoIPTrunc=$(echo $addr | cut -d "." -f1-2) |
| return 1 | ||
| fi | ||
| elif [ "x$mode" == "xipv4" ]; then | ||
| autoIPTrunc=$(echo $addr | cut -d "." -f1-2) |
Copilot
AI
Dec 19, 2025
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.
The variable 'autoIPTrunc' is not declared as local, which could lead to variable leakage in the shell environment. Declare it with 'local' to keep it scoped to this function.
| autoIPTrunc=$(echo $addr | cut -d "." -f1-2) | |
| local autoIPTrunc=$(echo $addr | cut -d "." -f1-2) |
|
|
||
| NMdispatcherLog "update_global_ip_info: cmd:$cmd, mode:$mode, ifc:$ifc, addr:$addr, flags:$flags" | ||
|
|
||
| if [ "x$cmd" == "xdelete" ] && [ "x$flags" == "xglobal" ]; then |
Copilot
AI
Dec 19, 2025
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.
Use single brackets '[' with '=' instead of double brackets '[[' with '==' for POSIX compliance in shell scripts. The current syntax is bash-specific, but the shebang indicates a generic sh interpreter.
| if [[ $addr == fc* || $addr == fd* ]]; then | ||
| return 1 | ||
| fi | ||
| elif [ "x$mode" == "xipv4" ]; then |
Copilot
AI
Dec 19, 2025
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.
Use single brackets '[' with '=' instead of double brackets '[[' with '==' for POSIX compliance in shell scripts. The current syntax is bash-specific, but the shebang indicates a generic sh interpreter.
| if [[ "$ifc" == "$ESTB_INTERFACE" || "$ifc" == "$DEFAULT_ESTB_INTERFACE" || "$ifc" == "$ESTB_INTERFACE:0" ]]; then | ||
| NMdispatcherLog "Updating Box/ESTB IP" | ||
| echo "$addr" > /tmp/.$mode$ESTB_INTERFACE | ||
| refresh_devicedetails "estb_ip" | ||
| elif [[ "$ifc" == "$MOCA_INTERFACE" || "$ifc" == "$MOCA_INTERFACE:0" ]]; then | ||
| NMdispatcherLog "Updating MoCA IP" | ||
| echo "$addr" > /tmp/.$mode$MOCA_INTERFACE | ||
| refresh_devicedetails "moca_ip" | ||
| elif [[ "$ifc" == "$WIFI_INTERFACE" || "$ifc" == "$WIFI_INTERFACE:0" ]]; then | ||
| NMdispatcherLog "Updating Wi-Fi IP" | ||
| echo "$addr" > /tmp/.$mode$WIFI_INTERFACE | ||
| refresh_devicedetails "boxIP" | ||
| fi |
Copilot
AI
Dec 19, 2025
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.
Use single brackets '[' with '=' instead of double brackets '[[' with '==' for POSIX compliance in shell scripts. The pattern matching in these conditions should use 'case' statements or be refactored to use single brackets with proper quoting.
| refresh_devicedetails() | ||
| { | ||
| #Refresh device cache info | ||
| if [ -f /lib/rdk/getDeviceDetails.sh ]; then | ||
| sh /lib/rdk/getDeviceDetails.sh refresh $1 | ||
| else | ||
| NMdispatcherLog "DeviceDetails file not present" | ||
| fi | ||
| } | ||
|
|
||
| check_valid_IPaddress() | ||
| { | ||
| local mode=$1 | ||
| local addr=$2 | ||
| # Neglect IPV6 ULA address and autoconfigured IPV4 address | ||
| if [ "x$mode" == "xipv6" ]; then | ||
| if [[ $addr == fc* || $addr == fd* ]]; then | ||
| return 1 | ||
| fi | ||
| elif [ "x$mode" == "xipv4" ]; then | ||
| autoIPTrunc=$(echo $addr | cut -d "." -f1-2) | ||
| if [ "$autoIPTrunc" == "169.254" ]; then | ||
| return 1 | ||
| fi | ||
| fi | ||
| return 0 | ||
| } |
Copilot
AI
Dec 19, 2025
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.
The code is duplicated between NM_preDown.sh and NM_Dispatcher.sh. Consider creating a shared library file that both scripts can source to avoid code duplication and improve maintainability.
| refresh_devicedetails() | ||
| { | ||
| #Refresh device cache info | ||
| if [ -f /lib/rdk/getDeviceDetails.sh ]; then | ||
| sh /lib/rdk/getDeviceDetails.sh refresh $1 | ||
| else | ||
| NMdispatcherLog "DeviceDetails file not present" | ||
| fi | ||
| } | ||
|
|
||
| check_valid_IPaddress() | ||
| { | ||
| local mode=$1 | ||
| local addr=$2 | ||
| # Neglect IPV6 ULA address and autoconfigured IPV4 address | ||
| if [ "x$mode" == "xipv6" ]; then | ||
| if [[ $addr == fc* || $addr == fd* ]]; then | ||
| return 1 | ||
| fi | ||
| elif [ "x$mode" == "xipv4" ]; then | ||
| autoIPTrunc=$(echo $addr | cut -d "." -f1-2) | ||
| if [ "$autoIPTrunc" == "169.254" ]; then | ||
| return 1 | ||
| fi | ||
| fi | ||
| return 0 | ||
| } |
Copilot
AI
Dec 19, 2025
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.
The code is duplicated between NM_preDown.sh and NM_Dispatcher.sh. Consider creating a shared library file that both scripts can source to avoid code duplication and improve maintainability.
lib/rdk/NM_preDown.sh
Outdated
| local mode=$1 | ||
| local addr=$2 | ||
| # Neglect IPV6 ULA address and autoconfigured IPV4 address | ||
| if [ "x$mode" == "xipv6" ]; then |
Copilot
AI
Dec 19, 2025
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.
Use single brackets '[' with '=' instead of double brackets '[[' with '==' for POSIX compliance in shell scripts. The current syntax is bash-specific, but the shebang indicates a generic sh interpreter.
3ba3a68 to
937d21f
Compare
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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.
Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.
|
I have read the CLA Document and I hereby sign the CLA You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot. |
No description provided.