Skip to content
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

retry arping one more time in ifup-eth when sendto failed #490

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

xanoxes
Copy link

@xanoxes xanoxes commented Sep 25, 2024

retry arping one more time in ifup-eth when sendto failed

network-scripts/ifup-eth Fixed Show fixed Hide fixed
@lnykryn
Copy link
Member

lnykryn commented Sep 25, 2024

Honestly, I don't like the "try things again if they fail" approach. It is not a sign of good design. But the network-scripts always had ton of hacks, so I am probably fine with adding one.

But please try to do this a bit nicer; copying a code and putting it in else close under is ugly as hell.
What I could imagine is a new ARPING_RETRY or ARPING_TRIES option and then looping over arping until the limit is hit. And this would also allow not to change the behaviour and keep this opt-in.

network-scripts/ifup-eth Fixed Show fixed Hide fixed
@xanoxes
Copy link
Author

xanoxes commented Oct 11, 2024

You're right, its ugly. So i refactor it with ARPING_TRIES. Please review this PR again.

net_log $"Error, some other host ($ARPINGMAC) already uses address ${ipaddr[$idx]}."
exit 1
fi
while [ $tries -le $ARPING_TRIES ]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We tend to keep "while ...; do" on one line. Also, it is a good practice to always put variables in the statement into double quotes

network-scripts/ifup-eth Outdated Show resolved Hide resolved
ARPINGMAC=$(echo $ARPING | sed -ne 's/.*\[\(.*\)\].*/\1/p')
net_log $"Error, some other host ($ARPINGMAC) already uses address ${ipaddr[$idx]}."
tries=$((tries+1))
if [ $tries -gt $ARPING_TRIES ]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above, this should be checked after the cycle. And again missing double quotes

tries=$((tries+1))
if [ $tries -gt $ARPING_TRIES ]
then
net_log "arping failed after $tries tries"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing $ so the string could be translated ($"string")

@lnykryn
Copy link
Member

lnykryn commented Oct 11, 2024

And please squash your commits.

@xanoxes
Copy link
Author

xanoxes commented Oct 21, 2024

@lnykryn

1 similar comment
@xanoxes
Copy link
Author

xanoxes commented Nov 11, 2024

@lnykryn

@lnykryn
Copy link
Member

lnykryn commented Nov 11, 2024

This will cause that "Error, some other host ".... message to be needlessly printed several times. It would be better to structure the code something like this: while .. do arping ret=$? done if [ ret =1 ] ....

I don't think this was addressed.

@xanoxes
Copy link
Author

xanoxes commented Nov 13, 2024

This will cause that "Error, some other host ".... message to be needlessly printed several times. It would be better to structure the code something like this: while .. do arping ret=$? done if [ ret =1 ] ....

I don't think this was addressed.

We now only print "Error, some other host ".... once there really is an $ARPINGMAC in output of ARPING. In this case we exit the loop directly so there would not be a repeated Error msg print.

@lnykryn
Copy link
Member

lnykryn commented Nov 15, 2024

This will cause that "Error, some other host ".... message to be needlessly printed several times. It would be better to structure the code something like this: while .. do arping ret=$? done if [ ret =1 ] ....

I don't think this was addressed.

We now only print "Error, some other host ".... once there really is an $ARPINGMAC in output of ARPING. In this case we exit the loop directly so there would not be a repeated Error msg print.

Ah, I missed the break, sorry.

break
fi
tries=$((tries+1))
else
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you flip this a bit? I think this would be nicer:
ARPING=$(/sbin/arping -c 2 -w ${ARPING_WAIT:-3} -D -I ${REALDEVICE} ${ipaddr[$idx]})
[ $? = 0 ] && break
ARPINGMAC=$(echo $ARPING | sed -ne 's/.[(.)].*/\1/p')
....

network-scripts/ifup-eth Dismissed Show dismissed Hide dismissed
net_log $"Error, some other host ($ARPINGMAC) already uses address ${ipaddr[$idx]}."
if [ -n "${ARPINGMAC}" ]; then
net_log $"Error, some other host ($ARPINGMAC) already uses address ${ipaddr[$idx]}."
break
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it be here "exit 1" instead of "break"? If we find a duplicate address on the first iteration loop, then the if [ "${tries}" -gt "${ARPING_TRIES}" ]; check below will be false, and we will continue with the rest of the code.

@xanoxes
Copy link
Author

xanoxes commented Nov 19, 2024

@lnykryn All done, plz check.

@lnykryn
Copy link
Member

lnykryn commented Nov 19, 2024

I still think that there should be exit 1 instead of break on line 302 in your code

@xanoxes
Copy link
Author

xanoxes commented Nov 19, 2024

I still think that there should be exit 1 instead of break on line 302 in your code

YES, its wrong to use break, fixed.

@xanoxes
Copy link
Author

xanoxes commented Dec 9, 2024

@lnykryn ALL fixed, plz check

@@ -293,10 +293,18 @@ else

if ! LC_ALL=C ip addr ls ${REALDEVICE} | LC_ALL=C grep -q "${ipaddr[$idx]}/${prefix[$idx]}" ; then
if [ "${REALDEVICE}" != "lo" ] && ! is_false "${arpcheck[$idx]}"; then
ARPING=$(/sbin/arping -c 2 -w ${ARPING_WAIT:-3} -D -I ${REALDEVICE} ${ipaddr[$idx]})
if [ $? = 1 ]; then
while [ "${tries}" -le "${ARPING_TRIES}" ]; do
Copy link
Member

@jamacku jamacku Dec 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather see the use of a for loop instead of a while loop. Also, you are missing the initialization of tries and ARPING_TRIES

Suggested change
while [ "${tries}" -le "${ARPING_TRIES}" ]; do
for (( tries=0; tries<${ARPING_TRIES:=1}; tries++ )); do

net_log $"Error, some other host ($ARPINGMAC) already uses address ${ipaddr[$idx]}."
exit 1
fi
tries=$((tries+1))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will be handled in the head of the for loop.

Suggested change
tries=$((tries+1))

fi
tries=$((tries+1))
done
if [ "${tries}" -gt "${ARPING_TRIES}" ]; then
Copy link
Member

@jamacku jamacku Dec 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When using for loop, you need to update this condition

Suggested change
if [ "${tries}" -gt "${ARPING_TRIES}" ]; then
if [ "${tries}" -eq "${ARPING_TRIES}" ]; then

if [ $? = 1 ]; then
while [ "${tries}" -le "${ARPING_TRIES}" ]; do
ARPING=$(/sbin/arping -c 2 -w ${ARPING_WAIT:-3} -D -I ${REALDEVICE} ${ipaddr[$idx]})
[ $? = 0 ] && break
Copy link
Member

@jamacku jamacku Dec 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
[ $? = 0 ] && break
[ "$?" -eq 0 ] && break

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants