Project

General

Profile

« Previous | Next » 

Revision 9111e5fd

Added by Renato Botelho over 12 years ago

When a interface type is changed, old configuration remains. When moving from static ip to ppp, it kepts the static ip configured on interface, when moving from ppp to static ip, it doesn't kill mpd. Implement interface_clean() to make sure only current configuration is in place

View differences:

etc/inc/interfaces.inc
1061 1061
	}
1062 1062
}
1063 1063

  
1064
function interface_cleanup($interface = "wan") {
1065
	global $config, $g;
1066

  
1067
	if (!isset($config['interfaces'][$interface]))
1068
		return;
1069

  
1070
	$ifcfg = $config['interfaces'][$interface];
1071

  
1072
	$ppp_types = array("ppp", "pppoe", "pptp", "l2tp");
1073

  
1074
	$realifs = array(get_real_interface($interface));
1075

  
1076
	if (in_array($ifcfg['ipaddr'], $ppp_types)) {
1077
		if (is_array($config['ppps']['ppp']) && count($config['ppps']['ppp'])) {
1078
			foreach ($config['ppps']['ppp'] as $pppid => $ppp) {
1079
				if (get_real_interface($interface) == $ppp['if']) {
1080
					$realifs = array();
1081
					$ports = explode(',',$ppp['ports']);
1082
					foreach($ports as $port) {
1083
						$realifs[] = get_real_interface($port);
1084
					}
1085
				}
1086
			}
1087
		}
1088
	}
1089

  
1090
	foreach ($ppp_types as $type) {
1091
		if (($ifcfg['ipaddr'] != $type) && file_exists("{$g['varrun_path']}/{$type}_{$interface}.pid")) {
1092
			killbypid("{$g['varrun_path']}/{$type}_{$interface}.pid");
1093
			sleep(2);
1094
		}
1095
	}
1096

  
1097
	if (!in_array($ifcfg['ipaddr'], $ppp_types))
1098
		unlink_if_exists("{$g['varetc_path']}/mpd_{$interface}.conf");
1099

  
1100
	if ($ifcfg['ipaddr'] != "dhcp") {
1101
		foreach($realifs as $realif) {
1102
			$pid = find_dhclient_process($realif);
1103
			if($pid)
1104
				mwexec("/bin/kill {$pid}");
1105
			sleep(1);
1106
		}
1107
		unlink_if_exists("{$g['varetc_path']}/dhclient_{$interface}.conf");
1108
	}
1109

  
1110
	if (!is_ipaddrv4($ifcfg['ipaddr'])) {
1111
		foreach($realifs as $realif) {
1112
			mwexec("/sbin/ifconfig " . escapeshellarg($realif) . " delete", true);
1113
			mwexec("/usr/sbin/arp -d -i {$realif} -a");
1114
		}
1115
	}
1116
}
1117

  
1064 1118
function interface_bring_down($interface = "wan", $destroy = false) {
1065 1119
	global $config, $g;
1066 1120

  
......
1072 1126

  
1073 1127
	$realif = get_real_interface($interface);
1074 1128

  
1129
	interface_cleanup($interface);
1130

  
1075 1131
	switch ($ifcfg['ipaddr']) {
1076 1132
	case "ppp":
1077 1133
	case "pppoe":

Also available in: Unified diff