Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 112049 | Differences between
and this patch

Collapse All | Expand All

(-)src/env_whitelist (-2 / +5 lines)
Lines 8-17 Link Here
8
# NB: Do not modify below this line if you do not know what you are doing!!
8
# NB: Do not modify below this line if you do not know what you are doing!!
9
#
9
#
10
10
11
# Hotplug ?
11
# Hotplug
12
IN_BACKGROUND
13
IN_HOTPLUG
12
IN_HOTPLUG
14
13
14
# RC network script support
15
IN_BACKGROUND
16
RC_INTERFACE_KEEP_CONFIG
17
15
# Default shell stuff
18
# Default shell stuff
16
SHELL
19
SHELL
17
USER
20
USER
(-)lib/rcscripts/net.modules.d/ifconfig (+18 lines)
Lines 394-399 Link Here
394
	return ${r}
394
	return ${r}
395
}
395
}
396
396
397
# void ifconfig_route_metric(char* interface, int metric)
398
#
399
# Change all routes for an interface to a given metric
400
ifconfig_route_metric() {
401
	local dest gateway mask flags metric ref use
402
	route -n | grep " $1$" | {
403
		while read dest gateway mask flags metric ref use ; do
404
			if [[ ${gateway} != "0.0.0.0" ]]; then
405
				gateway="gw ${gateway}"
406
			else
407
				unset gateway
408
			fi
409
			route del ${dest}
410
			route add -net ${dest} netmask ${mask} ${gateway} metric "$2" dev "$1"
411
		done
412
	}
413
}
414
397
# void ifconfig_default_route(char* interface, char* gateway_ip, int metric)
415
# void ifconfig_default_route(char* interface, char* gateway_ip, int metric)
398
#
416
#
399
# Force default route to the specified gateway
417
# Force default route to the specified gateway
(-)lib/rcscripts/net.modules.d/helpers.d/pppd-wrapper (+43 lines)
Line 0 Link Here
1
#!/bin/bash
2
# Copyright (c) 2005 Gentoo Foundation
3
# Distributed under the terms of the GNU General Public License v2
4
5
# Contributed by Roy Marples (uberlord@gentoo.org)
6
7
action="$1"
8
interface="$2"
9
export IN_BACKGROUND="true"
10
. /lib/rcscripts/net.modules.d/helpers.d/module-loader
11
resolv="${statedir}/${interface}/resolv.conf"
12
13
if [[ ${action} == "up" ]]; then
14
	if [[ -n ${DNS1} || -n ${DNS2} ]]; then
15
	    echo "# Generated by pppd for interface $1" > "${resolv}"
16
	    chmod 0644 "${resolv}"
17
	    [ -n ${DNS1} ] && echo "nameserver ${DNS1}" >> "${resolv}"
18
	    [ -n ${DNS2} ] && echo "nameserver ${DNS2}" >> "${resolv}"
19
	fi
20
	
21
	# Calculate the metric for our routes
22
	ifvar=$( bash_variable "${interface}" )
23
	eval metric=\"\$\{metric_${ifvar}\}\"
24
	if [[ -z ${metric} ]]; then
25
		if [[ ${RC_AUTO_INTERFACE} == "yes" ]]; then
26
			metric=$( calculate_metric "${interface}" )
27
		else
28
			metric="0"
29
		fi
30
		eval metric_${ifvar}="${metric}"
31
	fi
32
33
	[[ ${metric} != "0" ]] && interface_route_metric "${interface}" "${metric}"
34
35
	if service_inactive "net.${interface}" ; then
36
		export RC_INTERFACE_KEEP_CONFIG="yes"
37
		/etc/init.d/net."${interface}" start
38
	fi
39
else
40
	/etc/init.d/net."${interface}" stop
41
fi
42
43
# vim:ts=4
0
  + *
44
  + *
(-)lib/rcscripts/net.modules.d/helpers.d/functions (-13 / +11 lines)
Lines 96-116 Link Here
96
# (ie a state dir exists)
96
# (ie a state dir exists)
97
# require_gateway defaults to false
97
# require_gateway defaults to false
98
order_interfaces() {
98
order_interfaces() {
99
	local ifaces
99
	local ifaces extra
100
	
100
101
	if [[ ${1:-false} == "true" ]]; then
101
	${1:-false} && extra=' && $2=="00000000"'
102
		ifaces=$(awk '$2!="Gateway" { print $7, $1 }' /proc/net/route \
102
	ifaces=$(awk '{if (NR>1 && $1!="lo"'"${extra}"') print $7, $1}' /proc/net/route \
103
		| sort -n | cut -d' ' -f2 | uniq)
103
		| sort -n | cut -d' ' -f2 | uniq)
104
	else
105
		ifaces=$(awk '$2=="00000000" { print $7, $1 }' /proc/net/route \
106
		| sort -n | cut -d' ' -f2 )
107
	fi
108
104
109
	# Append lo if it's up
105
	# Append lo if it's up
110
	if grep -q "^lo[ \t]*" /proc/net/route ; then
106
	if ! ${1:-false} ; then
111
		ifaces="${ifaces} lo"
107
		if grep -q "^lo[ \t]*" /proc/net/route ; then
108
			ifaces="${ifaces} lo"
109
		fi
112
	fi
110
	fi
113
	
111
114
	local i order
112
	local i order
115
	for i in ${ifaces}; do
113
	for i in ${ifaces}; do
116
		[[ -d "${statedir}/${i}" ]] && order="${order}${i} "
114
		[[ -d "${statedir}/${i}" ]] && order="${order}${i} "
Lines 132-138 Link Here
132
		[[ ! -e "${statedir}/${ifaces[i]}/resolv.conf" ]] && unset ifaces[i]
130
		[[ ! -e "${statedir}/${ifaces[i]}/resolv.conf" ]] && unset ifaces[i]
133
	done
131
	done
134
	ifaces=( "${ifaces[@]}" )
132
	ifaces=( "${ifaces[@]}" )
135
	
133
136
	# No point merging unless there are two or more interfaces
134
	# No point merging unless there are two or more interfaces
137
	[[ ${#ifaces[@]} -lt 2 ]] && return
135
	[[ ${#ifaces[@]} -lt 2 ]] && return
138
136
Lines 151-157 Link Here
151
		opts[i]=$( sed -n -e 's/^[ \t]*options[ \t]*\([^#]*\).*/\1#/p;' "${f}" | xargs )
149
		opts[i]=$( sed -n -e 's/^[ \t]*options[ \t]*\([^#]*\).*/\1#/p;' "${f}" | xargs )
152
		sortlist[i]=$( sed -n -e 's/^[ \t]*sortlist[ \t]*\([^#]*\).*/\1/p' "${f}" )
150
		sortlist[i]=$( sed -n -e 's/^[ \t]*sortlist[ \t]*\([^#]*\).*/\1/p' "${f}" )
153
		
151
		
154
		if [[ -z ${srvs[i]} && -z ${opts[i]} && -z ${sortlist[i]} ]]; then
152
		if [[ -z ${srvs[i]} && -z ${opts[i]} && -z ${sortlist[i]} && -z ${search[i]} ]]; then
155
			unset srvs[i]
153
			unset srvs[i]
156
			unset search[i]
154
			unset search[i]
157
			unset opts[i]
155
			unset opts[i]
(-)lib/rcscripts/net.modules.d/pppd (-186 / +219 lines)
Lines 6-25 Link Here
6
#
6
#
7
# Sets up the dependancies for the module
7
# Sets up the dependancies for the module
8
pppd_depend() {
8
pppd_depend() {
9
    after interface
9
	after interface
10
    before dhcp
10
	before dhcp
11
    provide ppp
11
	provide ppp
12
}
12
}
13
13
14
# bool pppd_check_installed(void)
14
# bool pppd_check_installed(void)
15
#
15
#
16
# Returns 1 if pppd is installed, otherwise 0
16
# Returns 1 if pppd is installed, otherwise 0
17
pppd_check_installed() {
17
pppd_check_installed() {
18
    if [[ ! -x /usr/sbin/pppd ]]; then
18
	if [[ ! -x /usr/sbin/pppd ]]; then
19
    ${1:-false} && eerror "For PPP support, emerge net-dialup/ppp"
19
		${1:-false} && eerror "For PPP support, emerge net-dialup/ppp"
20
    return 1
20
		return 1
21
    fi
21
	fi
22
    return 0
22
	return 0
23
}
23
}
24
24
25
# char *pppd_regex_escape(char *string)
25
# char *pppd_regex_escape(char *string)
Lines 29-53 Link Here
29
# This may be a candidate for adding to /sbin/functions.sh or
29
# This may be a candidate for adding to /sbin/functions.sh or
30
# net-scripts functions at some point
30
# net-scripts functions at some point
31
pppd_regex_escape() {
31
pppd_regex_escape() {
32
    local escaped_result="$*"
32
	local escaped_result="$*"
33
    escaped_result=${escaped_result//\\/\\\\}
33
	escaped_result=${escaped_result//\\/\\\\}
34
    escaped_result=${escaped_result//./\\.}
34
	escaped_result=${escaped_result//./\\.}
35
    escaped_result=${escaped_result//+/\\+}
35
	escaped_result=${escaped_result//+/\\+}
36
    escaped_result=${escaped_result//(/\\(}
36
	escaped_result=${escaped_result//(/\\(}
37
    escaped_result=${escaped_result//)/\\)}
37
	escaped_result=${escaped_result//)/\\)}
38
    escaped_result=${escaped_result//[/\\[}
38
	escaped_result=${escaped_result//[/\\[}
39
    escaped_result=${escaped_result//]/\\]}
39
	escaped_result=${escaped_result//]/\\]}
40
    escaped_result=${escaped_result//\{/\\\{}
40
	escaped_result=${escaped_result//\{/\\\{}
41
    escaped_result=${escaped_result//\}/\\\}}
41
	escaped_result=${escaped_result//\}/\\\}}
42
    escaped_result=${escaped_result//\?/\\\?}
42
	escaped_result=${escaped_result//\?/\\\?}
43
    escaped_result=${escaped_result//\*/\\\*}
43
	escaped_result=${escaped_result//\*/\\\*}
44
    escaped_result=${escaped_result//\//\\/} 
44
	escaped_result=${escaped_result//\//\\/} 
45
    escaped_result=${escaped_result//|/\\|} 
45
	escaped_result=${escaped_result//|/\\|} 
46
    escaped_result=${escaped_result//&/\\&} 
46
	escaped_result=${escaped_result//&/\\&} 
47
    escaped_result=${escaped_result//~/\\~} 
47
	escaped_result=${escaped_result//~/\\~} 
48
    escaped_result=${escaped_result//^/\\^} 
48
	escaped_result=${escaped_result//^/\\^} 
49
    escaped_result=${escaped_result//$/\\$} 
49
	escaped_result=${escaped_result//$/\\$} 
50
    echo $escaped_result
50
	echo $escaped_result
51
}
51
}
52
52
53
# bool pppd_update_secrets_file(char* filepath, char* username, \
53
# bool pppd_update_secrets_file(char* filepath, char* username, \
Lines 55-98 Link Here
55
#
55
#
56
# Add/update PAP/CHAP authentication information 
56
# Add/update PAP/CHAP authentication information 
57
pppd_update_secrets_file() {
57
pppd_update_secrets_file() {
58
    local filepath="$1" username="$2" remotename="$3" password="$4"
58
	local filepath="$1" username="$2" remotename="$3" password="$4"
59
    if [[ ! -f ${filepath} ]]; then
59
	if [[ ! -f ${filepath} ]]; then
60
        touch ${filepath} && \
60
		touch ${filepath} && \
61
            chmod 0600 ${filepath} || \
61
		chmod 0600 ${filepath} || \
62
            return 1
62
		return 1
63
    fi
63
	fi
64
    
65
    #escape username and remotename, used in following sed calls
66
    local regex_username=$(pppd_regex_escape ${username})
67
    local regex_remotename=$(pppd_regex_escape ${remotename})
68
    local regex_password
69
    local regex_filter="[ \t]*\"?${regex_username}\"?[ \t]*\"?${regex_remotename}\"?[ \t]*"
70
    
71
    #read old password, including " chars 
72
    #for being able to distinct when we need to add or update auth info
73
    local old_password=$(
74
        sed -r -e "/^${regex_filter}\".*\"[ \t]*\$/\
75
            {s/^${regex_filter}(\".*\")[ \t]*\$/\1/;q;};\
76
            d;" \
77
                ${filepath}
78
        )
79
64
80
    if [[ -z "${old_password}" ]]; then
65
	#escape username and remotename, used in following sed calls
81
        regex_username=${username//\\/\\\\}
66
	local regex_username=$(pppd_regex_escape ${username})
82
        regex_remotename=${remotename//\\/\\\\}
67
	local regex_remotename=$(pppd_regex_escape ${remotename})
83
        regex_password=${password//\\/\\\\}
68
	local regex_password
84
        regex_password=${password//"/\\"}
69
	local regex_filter="[ \t]*\"?${regex_username}\"?[ \t]*\"?${regex_remotename}\"?[ \t]*"
85
        sed -r -i -e "\$a\"${regex_username}\" ${regex_remotename} \"${regex_password}\"" ${filepath}
70
86
        vewarn "Authentication info has been added to ${filepath}"
71
	#read old password, including " chars 
87
    elif [[ "\"${password//\"/\\\"}\"" != "${old_password}" ]]; then
72
	#for being able to distinct when we need to add or update auth info
88
        regex_password=${password//\\/\\\\}
73
	local old_password=$(
89
        regex_password=${regex_password//\//\\/}
74
	sed -r -e "/^${regex_filter}\".*\"[ \t]*\$/\
90
        regex_password=${regex_password//&/\\&}
75
		{s/^${regex_filter}(\".*\")[ \t]*\$/\1/;q;};\
91
        regex_password=${regex_password//\"/\\\\\"}
76
		d;" \
92
        sed -r -i -e "s/^(${regex_filter}\").*(\"[ \t]*)\$/\1${regex_password}\2/" ${filepath}
77
		${filepath}
93
        vewarn "Authentication info has been updated in ${filepath}"
78
	)
94
    fi
79
95
    return 0
80
	if [[ -z "${old_password}" ]]; then
81
		regex_username=${username//\\/\\\\}
82
		regex_remotename=${remotename//\\/\\\\}
83
		regex_password=${password//\\/\\\\}
84
		regex_password=${password//"/\\"}
85
		sed -r -i -e "\$a\"${regex_username}\" ${regex_remotename} \"${regex_password}\"" ${filepath}
86
		vewarn "Authentication info has been added to ${filepath}"
87
	elif [[ "\"${password//\"/\\\"}\"" != "${old_password}" ]]; then
88
		regex_password=${password//\\/\\\\}
89
		regex_password=${regex_password//\//\\/}
90
		regex_password=${regex_password//&/\\&}
91
		regex_password=${regex_password//\"/\\\\\"}
92
		sed -r -i -e "s/^(${regex_filter}\").*(\"[ \t]*)\$/\1${regex_password}\2/" ${filepath}
93
		vewarn "Authentication info has been updated in ${filepath}"
94
	fi
95
	return 0
96
}
96
}
97
97
98
# bool pppd_start(char *iface)
98
# bool pppd_start(char *iface)
Lines 101-240 Link Here
101
#
101
#
102
# Returns 0 (true) when successful, otherwise 1
102
# Returns 0 (true) when successful, otherwise 1
103
pppd_start() {
103
pppd_start() {
104
    local iface="$1" ifvar=$( bash_variable "$1" ) opts="" link
104
	${IN_BACKGROUND} && return 0
105
    if [[ ${iface%%[0-9]*} != "ppp" ]]; then
106
        eerror "PPP can only be invoked from net.ppp[0-9]"
107
        return 1
108
    fi
109
105
110
    local unit="${iface#ppp}"
106
	local iface="$1" ifvar=$( bash_variable "$1" ) opts="" link
111
    if [[ -z ${unit} ]] ; then
107
	if [[ ${iface%%[0-9]*} != "ppp" ]]; then
112
        eerror "PPP requires a unit - use net.ppp[0-9] instead of net.ppp"
108
		eerror "PPP can only be invoked from net.ppp[0-9]"
113
        return 1
109
		return 1
114
    fi
110
	fi
115
111
116
    # PPP requires a link to communicate over - normally a serial port
112
	local unit="${iface#ppp}" t
117
    # PPPoE communicates over ethernet
113
	if [[ -z ${unit} ]] ; then
118
    # PPPoA communictes over ATM
114
		eerror "PPP requires a unit - use net.ppp[0-9] instead of net.ppp"
119
    # In all cases, the link needs to be available before we start PPP
115
		return 1
120
    eval link=\"\$\{link_${ifvar}\}\"
116
	fi
121
    if [[ -z ${link} ]]; then
122
        eerror "link_${ifvar} has not been set in /etc/conf.d/net"
123
        return 1
124
    fi
125
117
126
    # Might or might not be set in conf.d/net
118
	# PPP requires a link to communicate over - normally a serial port
127
    local user password i
119
	# PPPoE communicates over Ethernet
128
    eval username=\"\$\{username_${ifvar}\}\"
120
	# PPPoA communicates over ATM
129
    eval password=\"\$\{password_${ifvar}\}\"
121
	# In all cases, the link needs to be available before we start PPP
122
	t="link_${ifvar}"
123
	link="${!t}"
124
	if [[ -z ${link} ]]; then
125
		eerror "link_${ifvar} has not been set in /etc/conf.d/net"
126
		return 1
127
	fi
130
128
131
    #Add/update info in PAP/CHAP secrets files
129
	# Might or might not be set in conf.d/net
132
    if [[ -n ${username} && -n ${password} ]]; then
130
	local user password i opts
133
        for i in chap pap ; do
131
	t="username_${ifvar}"
134
            if ! pppd_update_secrets_file "/etc/ppp/${i}-secrets" \
132
	username="${!t}"
135
                    "${username}" "${iface}" "${password}" ; then
133
	t="password_${ifvar}"
136
                eerror "Failed to update /etc/ppp/${i}-secrets"
134
	password="${!t}"
137
                return 1
138
            fi
139
        done
140
    fi
141
135
142
    # Load any commandline options
136
	#Add/update info in PAP/CHAP secrets files
143
    eval opts=\"\$\{pppd_${ifvar}\[@\]}\"
137
	if [[ -n ${username} && -n ${password} ]]; then
138
		for i in chap pap ; do
139
			if ! pppd_update_secrets_file "/etc/ppp/${i}-secrets" \
140
				"${username}" "${iface}" "${password}" ; then
141
				eerror "Failed to update /etc/ppp/${i}-secrets"
142
				return 1
143
			fi
144
		done
145
	fi
144
146
145
    # We don't work if unit, no detach or linkname is set.
147
	# Load any commandline options
146
    for i in unit nodetach linkname ; do
148
	t="pppd_${ifvar}[@]}"
147
        if [[ " ${opts} " == *" ${i} "* ]]; then
149
	opts=( "${!t}" )
148
            eerror "The option \"${i}\" is not allowed"
149
            return 1
150
        fi
151
    done
152
150
153
    # Check for mtu/mru
151
	# We don't work with these options set by the user
154
    local mtu
152
	for i in unit nodetach linkname maxfail persist ; do
155
    eval mtu=\"\$\{mtu_${ifvar}\}\"
153
		if [[ " ${opts[@]} " == *" ${i} "* ]]; then
156
    if [[ -n ${mtu} ]]; then
154
			eerror "The option \"${i}\" is not allowed"
157
        [[ " ${opts} " != *" mtu "* ]] && opts="${opts} mtu ${mtu}"
155
			return 1
158
        [[ " ${opts} " != *" mru "* ]] && opts="${opts} mru ${mtu}"
156
		fi
159
    fi
157
	done
160
158
161
    # Set linkname because we need /var/run/ppp-${linkname}.pid
159
	# Check for mtu/mru
162
    # This pidfile has the advantage of being there, even if ${iface} interface was never started
160
	local mtu
163
    opts="linkname ${iface} ${opts}"
161
	mtu="mtu_${ifvar}"
162
	if [[ -n ${!mtu} ]]; then
163
		[[ " ${opts[@]} " != *" mtu "* ]] && opts=("${opts[@]}" mtu "${!mtu}")
164
		[[ " ${opts[@]} " != *" mru "* ]] && opts=("${opts[@]}" mru "${!mtu}")
165
	fi
164
166
165
    # Setup auth info
167
	# Set linkname because we need /var/run/ppp-${linkname}.pid
166
    [[ -n ${username} ]] && opts="user \"${username}\" ${opts}"
168
	# This pidfile has the advantage of being there, even if ${iface} interface was never started
167
    opts="remotename ${iface} ${opts}"
169
	opts=( linkname "${iface}" "${opts[@]}" )
168
170
169
    # Load a custom interface configuration file if it exists
171
	# Setup auth info
170
    [[ -f "/etc/ppp/options.${iface}" ]] \
172
	[[ -n ${username} ]] && opts=( user "${username}" "${opts[@]}" )
171
        && opts="${opts} file /etc/ppp/options.${iface}"
173
	opts=( remotename "${iface}" "${opts[@]}" )
172
174
173
    # Set forced options
175
	# Load a custom interface configuration file if it exists
174
    opts="unit ${unit} persist maxfail 0 ${opts}"
176
	[[ -f "/etc/ppp/options.${iface}" ]] \
177
		&& opts=( "${opts[@]}" file "/etc/ppp/options.${iface}" )
175
178
176
    # Setup connect script
179
	# Set forced options
177
    local -a chat
180
	opts=( unit "${unit}" persist maxfail 0 "${opts[@]}" )
178
    eval chat=( \"\$\{chat_${ifvar}\[@\]\}\" )
179
    if [[ -n "${chat[@]}" ]]; then
180
        opts="${opts} connect \"/usr/sbin/chat -e -E -v"
181
181
182
        local -a phone_number
182
	# Setup connect script
183
        eval phone_number=( \"\$\{phone_number_${ifvar}\}\" )
183
	local -a chat
184
        if [[ ${#phone_number[@]} -ge 1 ]]; then
184
	eval chat=( \"\$\{chat_${ifvar}\[@\]\}\" )
185
            opts="${opts} -T '${phone_number[0]}'"
185
	if [[ -n "${chat[@]}" ]]; then
186
            if [[ ${#phone_number[@]} -ge 2 ]]; then
186
		local c="/usr/sbin/chat -e -E -v"
187
                opts="${opts} -U '${phone_number[1]}'"
188
            fi
189
        fi
190
187
191
        for (( i=0; i<${#chat[@]}; i++ )); do
188
		local -a phone_number
192
            opts="${opts} '${chat[i]}'"
189
		eval phone_number=( \"\$\{phone_number_${ifvar}\}\" )
193
        done
190
		if [[ ${#phone_number[@]} -ge 1 ]]; then
191
			c="${c} -T '${phone_number[0]}'"
192
			if [[ ${#phone_number[@]} -ge 2 ]]; then
193
				c="${c} -U '${phone_number[1]}'"
194
			fi
195
		fi
194
196
195
        opts="${opts}\""
197
		for (( i=0; i<${#chat[@]}; i++ )); do
196
    fi
198
			c="${c} '${chat[i]}'"
199
		done
197
200
198
    # Add plugins
201
		opts=( "${opts[@]}" "${c}" )
199
    local -a plugins
202
	fi
200
    eval plugins=( \"\$\{plugins_${ifvar}\[@\]\}\" )
201
    if [[ -n "${plugins[@]}" ]]; then
202
        for (( i=0; i<${#plugins[@]}; i++ )); do
203
            local -a plugin=( ${plugins[i]} )
204
            # Bound to be some users who do this
205
            [[ ${plugin[0]} == "pppoe" ]] && plugin[0]="rp-pppoe"
206
            [[ ${plugin[0]} == "pppoa" ]] && plugin[0]="pppoatm"
207
            [[ ${plugin[0]} == "capi" ]] && plugin[0]="capiplugin"
208
203
209
            [[ ${plugin[0]} == "rp-pppoe" ]] && opts="${opts} connect true"
204
	# Add plugins
210
            opts="${opts} plugin ${plugin[0]}.so ${plugin[@]:1}"
205
	local -a plugins
211
            [[ ${plugin[0]} == "rp-pppoe" ]] && opts="${opts} ${link}"
206
	t="plugins_${ifvar}[@]"
212
        done
207
	plugins=( "${!t}" )
213
    fi
208
	if [[ -n "${plugins[@]}" ]]; then
209
		for (( i=0; i<${#plugins[@]}; i++ )); do
210
			local -a plugin=( ${plugins[i]} )
211
			# Bound to be some users who do this
212
			[[ ${plugin[0]} == "pppoe" ]] && plugin[0]="rp-pppoe"
213
			[[ ${plugin[0]} == "pppoa" ]] && plugin[0]="pppoatm"
214
			[[ ${plugin[0]} == "capi" ]] && plugin[0]="capiplugin"
214
215
215
    #Specialized stuff. Insert here actions particular to connection type (pppoe,pppoa,capi)
216
			[[ ${plugin[0]} == "rp-pppoe" ]] \
216
    local insert_link_in_opts=1
217
				&& opts=( "${opts[@]}" connect true )
217
    if [[ " ${opts} " == *" plugin rp-pppoe.so "* ]]; then
218
			opts=( "${opts[@]}" plugin "${plugin[0]}.so" "${plugin[@]:1}" )
218
        # Ensure that the link exists and is up
219
			[[ ${plugin[0]} == "rp-pppoe" ]] && opts=( "${opts[@]}" "${link}" )
219
        interface_exists "${link}" true || return 1
220
		done
220
        interface_up "${link}"
221
	fi
221
222
222
        # Load the pppoe kernel module - if this fails, we have to hope
223
	#Specialized stuff. Insert here actions particular to connection type (pppoe,pppoa,capi)
223
        # that pppoe support is compiled into the kernel
224
	local insert_link_in_opts=1
224
        modprobe pppoe 2>/dev/null
225
	if [[ " ${opts[@]} " == *" plugin rp-pppoe.so "* ]]; then
226
		if [[ ! -e /proc/net/pppoe ]]; then
227
			# Load the PPPoE kernel module
228
			if ! modprobe pppoe ; then
229
				eerror "kernel does not support PPPoE"
230
				return 1
231
			fi
232
		fi
225
233
226
        insert_link_in_opts=0
234
		# Ensure that the link exists and is up
227
    fi
235
		interface_exists "${link}" true || return 1
228
    [[ ${insert_link_in_opts} -eq 0 ]] || opts="${link} ${opts}"
236
		interface_up "${link}"
229
    
230
    ebegin "Running pppd"
231
    i=$( eval /usr/sbin/pppd ${opts} 2>&1 )
232
    eend $? "${i}" || return 1
233
237
234
    if [[ " ${opts} " == *" updetach "* ]]; then
238
		insert_link_in_opts=0
235
        local addr=$( interface_get_address "${iface}" )
239
	fi
236
        einfo "${iface} received address ${addr}"
240
237
    fi
241
	if [[ " ${opts[@]} " == *" plugin pppoatm.so "* ]]; then
242
		if [[ ! -d /proc/net/atm ]]; then
243
			# Load the PPPoA kernel module
244
			if ! modprobe pppoatm ; then
245
				eerror "kernel does not support PPPoATM"
246
				return 1
247
			fi
248
		fi
249
	fi
250
	[[ ${insert_link_in_opts} -eq 0 ]] || opts="${link} ${opts}"
251
252
	ebegin "Running pppd"
253
	[[ " ${opts[@]} " != *" updetach "* ]] \
254
		&& mark_service_inactive "net.${iface}"
255
	start-stop-daemon --start --exec /usr/sbin/pppd \
256
		--pidfile "/var/run/ppp-${iface}.pid" -- "${opts[@]}" >/dev/null
257
	if [[ $? == 0 ]]; then
258
		eend 0
259
	else
260
		eend $?
261
		mark_service_starting "net.${iface}"
262
		return 1
263
	fi
264
265
	if [[ " ${opts[@]} " == *" updetach "* ]]; then
266
		local addr=$( interface_get_address "${iface}" )
267
		einfo "${iface} received address ${addr}"
268
	else
269
		einfo "Backgrounding ..."
270
		exit 0
271
	fi
238
}
272
}
239
273
240
# bool pppd_stop(char *iface)
274
# bool pppd_stop(char *iface)
Lines 244-258 Link Here
244
# Returns 0 (true) if no process to kill or it terminates successfully,
278
# Returns 0 (true) if no process to kill or it terminates successfully,
245
# otherwise non-zero (false)
279
# otherwise non-zero (false)
246
pppd_stop() {
280
pppd_stop() {
247
    local iface="$1" pidfile="/var/run/ppp-$1.pid"
281
	${IN_BACKGROUND} && return 0
282
	local iface="$1" pidfile="/var/run/ppp-$1.pid"
248
283
249
    [[ ! -s ${pidfile} ]] && return 0 
284
	[[ ! -s ${pidfile} ]] && return 0
250
285
251
    local pid
286
	einfo "Stopping pppd on ${iface}"
252
    read pid <"${pidfile}" #PID is the first line of the pidfile
287
	start-stop-daemon --stop --exec /usr/sbin/pppd --pidfile "${pidfile}"
253
    einfo "Stopping pppd on ${iface}"
288
	eend $?
254
    kill -s TERM "${pid}"
255
    process_finished "${pid}" /usr/sbin/pppd
256
    
257
    eend $?
258
}
289
}
290
291
# vim: ts=4
(-)lib/rcscripts/net.modules.d/iproute2 (-3 / +16 lines)
Lines 309-317 Link Here
309
309
310
		# Support net-tools routing too
310
		# Support net-tools routing too
311
		x="${x//gw/via}"
311
		x="${x//gw/via}"
312
		x="${x//-A inet6}"
312
		x="${x//-A inet6/}"
313
		x="${x//-net}"
313
		x="${x//-net/}"
314
		[[ " ${x} " == *" -host "* ]] && x="${x//-host} scope host"
314
		[[ " ${x} " == *" -host "* ]] && x="${x//-host/} scope host"
315
315
316
		# Attempt to support net-tools route netmask option
316
		# Attempt to support net-tools route netmask option
317
		netmask="${x##* netmask }"
317
		netmask="${x##* netmask }"
Lines 334-339 Link Here
334
	return 0
334
	return 0
335
}
335
}
336
336
337
# void iproute2_route_metric(char* interface, int metric)
338
#
339
# Change all routes for an interface to a given metric
340
iproute2_route_metric() {
341
	local route
342
	ip route | grep " dev $1" | {
343
		while read route ; do
344
			ip route del ${route}
345
			ip route add ${route} metric "$2"
346
		done
347
	}
348
}
349
337
# void iproute2_default_route(char* interface, char* gateway_ip, int metric)
350
# void iproute2_default_route(char* interface, char* gateway_ip, int metric)
338
#
351
#
339
# Force default route to the specified gateway, optionally on
352
# Force default route to the specified gateway, optionally on
(-)init.d/net.lo (-1 / +2 lines)
Lines 772-778 Link Here
772
		&& eval "config_${IFVAR}=( "\"\$\{config\[@\]:1\}\"" )"
772
		&& eval "config_${IFVAR}=( "\"\$\{config\[@\]:1\}\"" )"
773
773
774
		# There may be existing ip address info - so we strip it
774
		# There may be existing ip address info - so we strip it
775
		interface_del_addresses "${iface}"
775
		[[ ${RC_INTERFACE_KEEP_CONFIG} != "yes" ]] \
776
			&& interface_del_addresses "${iface}"
776
777
777
		# Start the interface
778
		# Start the interface
778
		if ! iface_start "${iface}" ; then
779
		if ! iface_start "${iface}" ; then

Return to bug 112049