tools/testing/selftests/net/arp_ndisc_evict_nocarrier.sh

Source file repositories/reference/linux-study-clean/tools/testing/selftests/net/arp_ndisc_evict_nocarrier.sh

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/net/arp_ndisc_evict_nocarrier.sh
Extension
.sh
Size
5324 bytes
Lines
214
Domain
Support Tooling And Documentation
Bucket
tools
Inferred role
Support Tooling And Documentation: tools
Status
atlas-only

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
#
# Tests sysctl options {arp,ndisc}_evict_nocarrier={0,1}
#
# Create a veth pair and set IPs/routes on both. Then ping to establish
# an entry in the ARP/ND table. Depending on the test set sysctl option to
# 1 or 0. Set remote veth down which will cause local veth to go into a no
# carrier state. Depending on the test check the ARP/ND table:
#
# {arp,ndisc}_evict_nocarrier=1 should contain no ARP/ND after no carrier
# {arp,ndisc}_evict_nocarrer=0 should still contain the single ARP/ND entry
#

source lib.sh

readonly V4_ADDR0=10.0.10.1
readonly V4_ADDR1=10.0.10.2
readonly V6_ADDR0=2001:db8:91::1
readonly V6_ADDR1=2001:db8:91::2
nsid=100
ret=0

cleanup_v6()
{
    cleanup_ns ${me} ${peer}

    sysctl -w net.ipv6.conf.veth1.ndisc_evict_nocarrier=1 >/dev/null 2>&1
    sysctl -w net.ipv6.conf.all.ndisc_evict_nocarrier=1 >/dev/null 2>&1
}

setup_v6() {
    setup_ns me peer

    IP="ip -netns ${me}"

    $IP li add veth1 type veth peer name veth2
    $IP li set veth1 up
    $IP -6 addr add $V6_ADDR0/64 dev veth1 nodad
    $IP li set veth2 netns ${peer} up
    ip -netns ${peer} -6 addr add $V6_ADDR1/64 dev veth2 nodad

    ip netns exec ${me} sysctl -w $1 >/dev/null 2>&1

    # Establish an ND cache entry
    ip netns exec ${me} ping -6 -c1 -Iveth1 $V6_ADDR1 >/dev/null 2>&1
    # Should have the veth1 entry in ND table
    ip netns exec ${me} ip -6 neigh get $V6_ADDR1 dev veth1 >/dev/null 2>&1
    if [ $? -ne 0 ]; then
        cleanup_v6
        echo "failed"
        exit 1
    fi

    # Set veth2 down, which will put veth1 in NOCARRIER state
    ip netns exec ${peer} ip link set veth2 down
}

setup_v4() {
    setup_ns PEER_NS
    ip link add name veth0 type veth peer name veth1
    ip link set dev veth0 up
    ip link set dev veth1 netns "${PEER_NS}"
    ip netns exec "${PEER_NS}" ip link set dev veth1 up
    ip addr add $V4_ADDR0/24 dev veth0
    ip netns exec "${PEER_NS}" ip addr add $V4_ADDR1/24 dev veth1
    ip netns exec ${PEER_NS} ip route add default via $V4_ADDR1 dev veth1
    ip route add default via $V4_ADDR0 dev veth0

    sysctl -w "$1" >/dev/null 2>&1

Annotation

Implementation Notes