summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Hemminger <stephen.hemminger@vyatta.com>2009-06-03 16:11:52 -0700
committerStephen Hemminger <stephen.hemminger@vyatta.com>2009-06-03 16:11:52 -0700
commitad4f2a101203e71076a3e23a0a2a093326927d45 (patch)
treee4c069e0fdcd80b082a1cde4b5a692fe2cfb16ce
parent6cbf6cfd5dfd154b6173136c149fa75c56a48dca (diff)
downloadvyatta-cfg-ad4f2a101203e71076a3e23a0a2a093326927d45.tar.gz
vyatta-cfg-ad4f2a101203e71076a3e23a0a2a093326927d45.zip
Handle speed/duplex settings better
Bugs 3952 and 3797 Make the ethtool settings management smarter. Don't try and set a device that has been unplugged (causing commit fail). Don't force autonegotiation if device is already in that mode.
-rw-r--r--templates/interfaces/ethernet/node.tag/duplex/node.def32
-rw-r--r--templates/interfaces/ethernet/node.tag/speed/node.def30
2 files changed, 32 insertions, 30 deletions
diff --git a/templates/interfaces/ethernet/node.tag/duplex/node.def b/templates/interfaces/ethernet/node.tag/duplex/node.def
index a44efd1..ba81cca 100644
--- a/templates/interfaces/ethernet/node.tag/duplex/node.def
+++ b/templates/interfaces/ethernet/node.tag/duplex/node.def
@@ -2,21 +2,23 @@ type: txt
help: Set the duplex mode for this interface
default: "auto"
syntax:expression: $VAR(@) in "auto", "half", "full"; "duplex must be auto, half or full"
-commit:expression: exec "if [ x$VAR(@) != xauto ]; then \
- if [ x$VAR(../speed/@) == xauto ]; then \
- exit 1; \
- fi; \
- else \
- if [ x$VAR(../speed/@) != xauto ]; then \
- exit 1; \
- fi; \
- fi; " ; "if duplex is hardcoded, speed must also be hardcoded"
-update:expression: "if [ x$VAR(@) != xauto ]; then \
- sudo ethtool -s $VAR(../@) speed $VAR(../speed/@) duplex $VAR(@) autoneg off; \
- else \
- sudo ethtool -s $VAR(../@) autoneg on; \
- fi; "
-delete:expression: "sudo ethtool -s $VAR(../@) autoneg on"
+commit:expression: ( $VAR(@) == "auto" && $VAR(../speed/@) == "auto" ) || \
+ ( $VAR(@) != "auto" && $VAR(../speed/@) != "auto" ) ; \
+ "if duplex is hardcoded, speed must also be hardcoded"
+
+update: if [ "$VAR(@)" = "auto" ]
+ then
+ if ! sudo ethtool $VAR(../@) | grep -q 'Auto-negotiation: on'
+ then sudo ethtool -s $VAR(../@) autoneg on
+ fi
+ else
+ sudo ethtool -s $VAR(../@) \
+ speed $VAR(../speed/@) duplex $VAR(@) autoneg off
+ fi
+
+delete: if [ -d /sys/class/net/$VAR(../@) ]; then
+ sudo ethtool -s $VAR(../@) autoneg on
+ fi
comp_help:Possible completions:
auto\t\tAuto negotiation
half\t\tHalf duplex
diff --git a/templates/interfaces/ethernet/node.tag/speed/node.def b/templates/interfaces/ethernet/node.tag/speed/node.def
index d042074..b22e93c 100644
--- a/templates/interfaces/ethernet/node.tag/speed/node.def
+++ b/templates/interfaces/ethernet/node.tag/speed/node.def
@@ -2,18 +2,18 @@ type: txt
help: Set the speed for this interface
default: "auto"
syntax:expression: $VAR(@) in "auto", "10", "100", "1000", "2500", "10000"; "Speed must be auto, 10, 100, 1000, 2500, or 10000"
-commit:expression: exec "if [ x$VAR(@) != xauto ]; then \
- if [ x$VAR(../duplex/@) == xauto ]; then \
- exit 1; \
- fi; \
- else \
- if [ x$VAR(../duplex/@) != xauto ]; then \
- exit 1; \
- fi; \
- fi;"; "if speed is hardcoded, duplex must also be hardcoded"
-update:expression: "if [ x$VAR(@) != xauto ]; then \
- sudo ethtool -s $VAR(../@) speed $VAR(@) duplex $VAR(../duplex/@) autoneg off; \
- else \
- sudo ethtool -s $VAR(../@) autoneg on; \
- fi; "
-delete:expression: "sudo ethtool -s $VAR(../@) autoneg on"
+commit:expression: ( $VAR(@) == "auto" && $VAR(../speed/@) == "auto" ) || \
+ ( $VAR(@) != "auto" && $VAR(../speed/@) != "auto" ) ; \
+ "if speed is hardcoded, duplex must also be hardcoded"
+update: if [ "$VAR(@)" = "auto" ]
+ then
+ if ! sudo ethtool $VAR(../@) | grep -q 'Auto-negotiation: on'
+ then sudo ethtool -s $VAR(../@) autoneg on
+ fi
+ else
+ sudo ethtool -s $VAR(../@) \
+ speed $VAR(../speed/@) duplex $VAR(@) autoneg off
+ fi
+delete: if [ -d /sys/class/net/$VAR(../@) ]; then
+ sudo ethtool -s $VAR(../@) autoneg on
+ fi