1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
From 950c00d1b183796034d227ef47a90eb248d79b72 Mon Sep 17 00:00:00 2001
From: Dave Reisner <d@falconindy.com>
Date: Tue, 21 Jun 2011 09:32:47 -0400
Subject: [PATCH] set MTU via sysfs if file is available
On Linux, a network interface's MTU can be set by writing to
/sys/class/net/$interface/mtu, which removes the dependency on ifconfig.
Signed-off-by: Dave Reisner <d@falconindy.com>
---
dhcpcd-hooks/10-mtu | 4 ++--
dhcpcd-run-hooks.in | 11 +++++++++++
2 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/dhcpcd-hooks/10-mtu b/dhcpcd-hooks/10-mtu
index 639697c..8763930 100644
--- a/dhcpcd-hooks/10-mtu
+++ b/dhcpcd-hooks/10-mtu
@@ -7,7 +7,7 @@ if [ "$reason" = PREINIT -a -e "$mtu_dir/$interface" ]; then
elif [ -n "$new_interface_mtu" ] && $if_up; then
# The smalled MTU dhcpcd can work with is 576
if [ "$new_interface_mtu" -ge 576 ]; then
- if ifconfig "$interface" mtu "$new_interface_mtu"; then
+ if set_mtu "$interface" "$new_interface_mtu"; then
syslog info "$interface: MTU set to $new_interface_mtu"
# Save the MTU so we can restore it later
if [ ! -e "$mtu_dir/$interface" ]; then
@@ -21,7 +21,7 @@ elif [ -e "$mtu_dir/$interface" ]; then
# No MTU in this state, so restore the prior MTU
mtu=$(cat "$mtu_dir/$interface")
syslog info "$interface: MTU restored to $mtu"
- ifconfig "$interface" mtu "$mtu"
+ set_mtu "$interface" "$mtu"
rm "$mtu_dir/$interface"
fi
fi
diff --git a/dhcpcd-run-hooks.in b/dhcpcd-run-hooks.in
index 0e60338..843f3ca 100644
--- a/dhcpcd-run-hooks.in
+++ b/dhcpcd-run-hooks.in
@@ -215,6 +215,17 @@ service_condcommand()
service_exists $1 && service_status $1 && service_cmd $1 $2
}
+# Set MTU for an interface
+set_mtu() {
+ local interface=$1 mtu=$2
+
+ if [ -e /sys/class/net/$interface/mtu ]; then
+ echo "$mtu" > /sys/class/net/$interface/mtu
+ else
+ ifconfig "$interface" mtu "$mtu"
+ fi
+}
+
# We source each script into this one so that scripts run earlier can
# remove variables from the environment so later scripts don't see them.
# Thus, the user can create their dhcpcd.enter/exit-hook script to configure
--
1.7.5.4
|