Skip to content

Commit 388457a

Browse files
authored
[arp_update]: Flush neighbors with incorrect MAC info (sonic-net#17238) (sonic-net#17677)
1 parent 38c5e68 commit 388457a

File tree

1 file changed

+34
-5
lines changed

1 file changed

+34
-5
lines changed

files/scripts/arp_update

+34-5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99

1010
ARP_UPDATE_VARS_FILE="/usr/share/sonic/templates/arp_update_vars.j2"
1111

12+
# Overload `logger` command to include arp_update tag
13+
logger () {
14+
command logger -t "arp_update" "$@"
15+
}
16+
1217
while /bin/true; do
1318
# find L3 interfaces which are UP, send ipv6 multicast pings
1419
ARP_UPDATE_VARS=$(sonic-cfggen -d -t ${ARP_UPDATE_VARS_FILE})
@@ -19,7 +24,7 @@ while /bin/true; do
1924
STATIC_ROUTE_IFNAMES=($(echo $ARP_UPDATE_VARS | jq -r '.static_route_ifnames'))
2025
# on supervisor/rp exit the script gracefully
2126
if [[ -z "$STATIC_ROUTE_NEXTHOPS" ]] || [[ -z "$STATIC_ROUTE_IFNAMES" ]]; then
22-
logger "arp_update: exiting as no static route in packet based chassis"
27+
logger "exiting as no static route in packet based chassis"
2328
exit 0
2429
fi
2530
for i in ${!STATIC_ROUTE_NEXTHOPS[@]}; do
@@ -38,7 +43,7 @@ while /bin/true; do
3843
interface="${STATIC_ROUTE_IFNAMES[i]}"
3944
if [[ -z "$interface" ]]; then
4045
# should never be here, handling just in case
41-
logger "ERR: arp_update: missing interface entry for static route $nexthop"
46+
logger -p error "missing interface entry for static route $nexthop"
4247
continue
4348
fi
4449
intf_up=$(ip link show $interface | grep "state UP")
@@ -47,7 +52,7 @@ while /bin/true; do
4752
eval $pingcmd
4853
# STALE entries may appear more often, not logging to prevent periodic syslogs
4954
if [[ -z $(echo ${neigh_state} | grep 'STALE') ]]; then
50-
logger "arp_update: static route nexthop not resolved ($neigh_state), pinging $nexthop on $interface"
55+
logger "static route nexthop not resolved ($neigh_state), pinging $nexthop on $interface"
5156
fi
5257
fi
5358
fi
@@ -70,6 +75,30 @@ while /bin/true; do
7075
fi
7176
done
7277

78+
# find neighbor entries with aged MAC and flush/relearn them
79+
STALE_NEIGHS=$(ip neigh show | grep -v "fe80" | grep "STALE" | awk '{print $1 "," $5}' | tr [:lower:] [:upper:])
80+
for neigh in $STALE_NEIGHS; do
81+
ip="$( cut -d ',' -f 1 <<< "$neigh" )"
82+
mac="$( cut -d ',' -f 2 <<< "$neigh" )"
83+
if [[ -z $(sonic-db-cli ASIC_DB keys "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY*${mac}*") ]]; then
84+
timeout 0.2 ping -c1 -w1 $ip > /dev/null
85+
fi
86+
done
87+
88+
# Flush neighbor entries with MAC mismatch between kernel and APPL_DB
89+
KERNEL_NEIGH=$(ip neigh show | grep -v "fe80" | grep -v "FAILED\|INCOMPLETE" | cut -d ' ' -f 1,3,5 --output-delimiter=',' | tr -d ' ')
90+
for neigh in $KERNEL_NEIGH; do
91+
ip="$( cut -d ',' -f 1 <<< "$neigh" )"
92+
intf="$( cut -d ',' -f 2 <<< "$neigh" )"
93+
kernel_mac="$( cut -d ',' -f 3 <<< "$neigh" )"
94+
appl_db_mac="$(sonic-db-cli APPL_DB hget NEIGH_TABLE:$intf:$ip neigh)"
95+
if [[ $kernel_mac != $appl_db_mac ]]; then
96+
logger -p warning "MAC mismatch for ${ip} on ${intf} - kernel: ${kernel_mac}, APPL_DB: ${appl_db_mac}"
97+
ip neigh flush $ip
98+
timeout 0.2 ping -c1 -w1 $ip > /dev/null
99+
fi
100+
done
101+
73102
VLAN=$(echo $ARP_UPDATE_VARS | jq -r '.vlan')
74103
SUBTYPE=$(sonic-db-cli CONFIG_DB hget 'DEVICE_METADATA|localhost' 'subtype' | tr '[:upper:]' '[:lower:]')
75104
for vlan in $VLAN; do
@@ -158,11 +187,11 @@ while /bin/true; do
158187
if [[ $ip == *"."* ]] && [[ ! $KERNEIGH4 =~ "${ip},${intf}" ]]; then
159188
pingcmd="timeout 0.2 ping -I $intf -n -q -i 0 -c 1 -W 1 $ip >/dev/null"
160189
eval $pingcmd
161-
logger "arp_update: mismatch arp entry, pinging ${ip} on ${intf}"
190+
logger "mismatch arp entry, pinging ${ip} on ${intf}"
162191
elif [[ $ip == *":"* ]] && [[ ! $KERNEIGH6 =~ "${ip},${intf}" ]]; then
163192
ping6cmd="timeout 0.2 ping6 -I $intf -n -q -i 0 -c 1 -W 1 $ip >/dev/null"
164193
eval $ping6cmd
165-
logger "arp_update: mismatch v6 nbr entry, pinging ${ip} on ${intf}"
194+
logger "mismatch v6 nbr entry, pinging ${ip} on ${intf}"
166195
fi
167196
fi
168197
done

0 commit comments

Comments
 (0)