1 # Configure the MTU for the interface 2 3 mtu_dir="$state_dir/mtu" 4 5 set_mtu() 6 { 7 local mtu=$1 8 9 if [ -w /sys/class/net/$interface/mtu ]; then 10 echo "$mtu" >/sys/class/net/$interface/mtu 11 else 12 ifconfig "$interface" mtu "$mtu" 13 fi 14 } 15 16 if [ "$reason" = PREINIT -a -e "$mtu_dir/$interface" ]; then 17 rm "$mtu_dir/$interface" 18 elif [ -n "$new_interface_mtu" ] && $if_up; then 19 # The smalled MTU dhcpcd can work with is 576 20 if [ "$new_interface_mtu" -ge 576 ]; then 21 if set_mtu "$new_interface_mtu"; then 22 syslog info "MTU set to $new_interface_mtu" 23 # Save the MTU so we can restore it later 24 if [ ! -e "$mtu_dir/$interface" ]; then 25 mkdir -p "$mtu_dir" 26 echo "$ifmtu" > "$mtu_dir/$interface" 27 fi 28 fi 29 fi 30 elif [ -e "$mtu_dir/$interface" ]; then 31 if $if_up || $if_down; then 32 # No MTU in this state, so restore the prior MTU 33 mtu=$(cat "$mtu_dir/$interface") 34 syslog info "MTU restored to $mtu" 35 set_mtu "$mtu" 36 rm "$mtu_dir/$interface" 37 fi 38 fi 39