10-mtu 957 B

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