Project

General

Profile

« Previous | Next » 

Revision b7a15cf8

Added by Seth Mos almost 14 years ago

Added blind coded DHCPv6 relay backend code. Needs to be tested, basic adaption to IPv6 implemented, only works on IPv6 interfaces. Checks inet6 route tables. Adds distinct PID file for dhcrelay -6. Adds to Ticket #1663

View differences:

etc/inc/services.inc
1037 1037
	return 0;
1038 1038
}
1039 1039

  
1040
function services_dhcrelay6_configure() {
1041
	global $config, $g;
1042
	if ($g['platform'] == 'jail')
1043
		return;
1044
	if(isset($config['system']['developerspew'])) {
1045
		$mt = microtime();
1046
		echo "services_dhcrelay_configure() being called $mt\n";
1047
	}
1048

  
1049
	/* kill any running dhcrelay */
1050
	killbypid("{$g['varrun_path']}/dhcrelay6.pid");
1051

  
1052
	$dhcrelaycfg =& $config['dhcrelay6'];
1053

  
1054
	/* DHCPv6 Relay enabled on any interfaces? */
1055
	if (!isset($dhcrelaycfg['enable']))
1056
		return 0;
1057

  
1058
	if ($g['booting'])
1059
		echo gettext("Starting DHCPv6 relay service...");
1060
	else
1061
		sleep(1);
1062

  
1063
	$iflist = get_configured_interface_list();
1064

  
1065
	$dhcifaces = explode(",", $dhcrelaycfg['interface']);
1066
	foreach ($dhcifaces as $dhcrelayif) {
1067
		if (!isset($iflist[$dhcrelayif]) ||
1068
			link_interface_to_bridge($dhcrelayif))
1069
			continue;
1070

  
1071
		if (is_ipaddrv6(get_interface_ipv6($dhcrelayif)))
1072
			$dhcrelayifs[] = get_real_interface($dhcrelayif);
1073
	}
1074

  
1075
	/* 
1076
	 * In order for the relay to work, it needs to be active
1077
	 * on the interface in which the destination server sits.
1078
	 */
1079
	$srvips = explode(",", $dhcrelaycfg['server']);
1080
	foreach ($srvips as $srcidx => $srvip) {
1081
		unset($destif);
1082
		foreach ($iflist as $ifname) {
1083
			$subnet = get_interface_ipv6($ifname);
1084
			if (!is_ipaddrv6($subnet))
1085
				continue;
1086
			$subnet .=  "/" . get_interface_subnetv6($ifname);
1087
			if (ip_in_subnet($srvip, $subnet)) {
1088
				$destif = get_real_interface($ifname);
1089
				break;
1090
			}
1091
		}
1092
		if (!isset($destif)) {
1093
			if (is_array($config['staticroutes']['route'])) {
1094
				foreach ($config['staticroutes']['route'] as $rtent) {
1095
					if (ip_in_subnet($srvip, $rtent['network'])) {
1096
						$a_gateways = return_gateways_array(true);
1097
						$destif = $a_gateways[$rtent['gateway']]['interface'];
1098
						break;
1099
					}
1100
				}
1101
			}
1102
		}
1103

  
1104
		if (!isset($destif)) {
1105
			/* Create a array from the existing route table */
1106
        		exec("/usr/bin/netstat -rnWf inet6", $route_str);
1107
        		array_shift($route_str);
1108
        		array_shift($route_str);
1109
        		array_shift($route_str);
1110
        		array_shift($route_str);
1111
        		$route_arr = array();
1112
        		foreach($route_str as $routeline) {
1113
                		$items = preg_split("/[ ]+/i", $routeline);
1114
				if (ip_in_subnet($srvip, $items[0])) {
1115
					$destif = trim($items[6]);
1116
					break;
1117
				}
1118
        		}
1119
		}
1120
	
1121
		if (!isset($destif)) {
1122
			if (is_array($config['gateways']['gateway_item'])) {
1123
				foreach ($config['gateways']['gateway_item'] as $gateway) {
1124
					if (isset($gateway['defaultgw'])) {
1125
						$a_gateways = return_gateways_array(true);
1126
                                        	$destif = $a_gateways[$rtent['gateway']]['interface'];
1127
						break;
1128
					}		
1129
				}
1130
			} else
1131
				$destif = get_real_interface("wan");
1132
		}
1133

  
1134
		if (!empty($destif))
1135
			$dhcrelayifs[] = $destif;
1136
	}
1137
	$dhcrelayifs = array_unique($dhcrelayifs);
1138

  
1139
	/* fire up dhcrelay */
1140
	if (empty($dhcrelayifs)) {
1141
		log_error("No suitable interface found for running dhcrelay -6!");
1142
		return; /* XXX */
1143
	}
1144

  
1145
	$cmd = "/usr/local/sbin/dhcrelay -6 -pf "{$g['varetc_path]}/dhcrelay6.pid" -i " .  implode(" -i ", $dhcrelayifs);
1146

  
1147
	if (isset($dhcrelaycfg['agentoption']))
1148
		$cmd .=  " -a -m replace";
1149

  
1150
	$cmd .= " " . implode(" ", $srvips);
1151
	mwexec($cmd);
1152

  
1153
	return 0;
1154
}
1155

  
1040 1156
function services_dyndns_configure_client($conf) {
1041 1157

  
1042 1158
	if (!isset($conf['enable']))

Also available in: Unified diff