Project

General

Profile

« Previous | Next » 

Revision f791f28d

Added by Chris Buechler almost 10 years ago

remove the destination server's interface(s) from dhcrelay. Ticket #4908

View differences:

etc/inc/services.inc
1604 1604
			$dhcrelayifs[] = get_real_interface($dhcrelayif);
1605 1605
		}
1606 1606
	}
1607

  
1608
	/*
1609
	 * In order for the relay to work, it needs to be active
1610
	 * on the interface in which the destination server sits.
1611
	 */
1612
	$srvips = explode(",", $dhcrelaycfg['server']);
1607
	
1608
	$srvips = explode(",", $dhcrelaycfg['server']);	
1613 1609
	if (!is_array($srvips)) {
1614
		log_error("No destination ip has been configured!");
1610
		log_error("No destination IP has been configured!");
1615 1611
		return;
1616 1612
	}
1617 1613

  
1618
	foreach ($srvips as $srcidx => $srvip) {
1619
		unset($destif);
1620
		foreach ($iflist as $ifname) {
1621
			$subnet = get_interface_ip($ifname);
1622
			if (!is_ipaddr($subnet)) {
1623
				continue;
1624
			}
1625
			$subnet .= "/" . get_interface_subnet($ifname);
1626
			if (ip_in_subnet($srvip, $subnet)) {
1627
				$destif = get_real_interface($ifname);
1628
				break;
1629
			}
1630
		}
1631
		if (!isset($destif)) {
1632
			foreach (get_staticroutes() as $rtent) {
1633
				if (ip_in_subnet($srvip, $rtent['network'])) {
1634
					$a_gateways = return_gateways_array(true);
1635
					$destif = $a_gateways[$rtent['gateway']]['interface'];
1636
					break;
1637
				}
1638
			}
1639
		}
1640

  
1641
		if (!isset($destif)) {
1642
			/* Create a array from the existing route table */
1643
			exec("/usr/bin/netstat -rnWf inet", $route_str);
1644
			array_shift($route_str);
1645
			array_shift($route_str);
1646
			array_shift($route_str);
1647
			array_shift($route_str);
1648
			$route_arr = array();
1649
			foreach ($route_str as $routeline) {
1650
				$items = preg_split("/[ ]+/i", $routeline);
1651
				if (is_subnetv4($items[0])) {
1652
					$subnet = $items[0];
1653
				} elseif (is_ipaddrv4($items[0])) {
1654
					$subnet = "{$items[0]}/32";
1655
				} else {
1656
					// Not a subnet or IP address, skip to the next line.
1657
					continue;
1658
				}
1659
				if (ip_in_subnet($srvip, $subnet)) {
1660
					$destif = trim($items[6]);
1661
					break;
1662
				}
1663
			}
1664
		}
1665

  
1666
		if (!isset($destif)) {
1667
			if (is_array($config['gateways']['gateway_item'])) {
1668
				foreach ($config['gateways']['gateway_item'] as $gateway) {
1669
					if (isset($gateway['defaultgw'])) {
1670
						$destif = get_real_interface($gateway['interface']);
1671
						break;
1672
					}
1673
				}
1674
			} else {
1675
				$destif = get_real_interface("wan");
1676
			}
1677
		}
1678

  
1679
		if (!empty($destif)) {
1680
			$dhcrelayifs[] = $destif;
1681
		}
1682
	}
1683 1614
	$dhcrelayifs = array_unique($dhcrelayifs);
1684 1615

  
1685 1616
	/* fire up dhcrelay */
......
1742 1673
	}
1743 1674
	$dhcrelayifs = array_unique($dhcrelayifs);
1744 1675

  
1745
	/*
1746
	 * In order for the relay to work, it needs to be active
1747
	 * on the interface in which the destination server sits.
1748
	 */
1749 1676
	$srvips = explode(",", $dhcrelaycfg['server']);
1750
	$srvifaces = array();
1751
	foreach ($srvips as $srcidx => $srvip) {
1752
		unset($destif);
1753
		foreach ($iflist as $ifname) {
1754
			$subnet = get_interface_ipv6($ifname);
1755
			if (!is_ipaddrv6($subnet)) {
1756
				continue;
1757
			}
1758
			$subnet .= "/" . get_interface_subnetv6($ifname);
1759
			if (ip_in_subnet($srvip, $subnet)) {
1760
				$destif = get_real_interface($ifname);
1761
				break;
1762
			}
1763
		}
1764
		if (!isset($destif)) {
1765
			if (is_array($config['staticroutes']['route'])) {
1766
				foreach ($config['staticroutes']['route'] as $rtent) {
1767
					if (ip_in_subnet($srvip, $rtent['network'])) {
1768
						$a_gateways = return_gateways_array(true);
1769
						$destif = $a_gateways[$rtent['gateway']]['interface'];
1770
						break;
1771
					}
1772
				}
1773
			}
1774
		}
1775

  
1776
		if (!isset($destif)) {
1777
			/* Create a array from the existing route table */
1778
			exec("/usr/bin/netstat -rnWf inet6", $route_str);
1779
			array_shift($route_str);
1780
			array_shift($route_str);
1781
			array_shift($route_str);
1782
			array_shift($route_str);
1783
			$route_arr = array();
1784
			foreach ($route_str as $routeline) {
1785
				$items = preg_split("/[ ]+/i", $routeline);
1786
				if (ip_in_subnet($srvip, $items[0])) {
1787
					$destif = trim($items[6]);
1788
					break;
1789
				}
1790
			}
1791
		}
1792

  
1793
		if (!isset($destif)) {
1794
			if (is_array($config['gateways']['gateway_item'])) {
1795
				foreach ($config['gateways']['gateway_item'] as $gateway) {
1796
					if (isset($gateway['defaultgw'])) {
1797
						$destif = get_real_interface($gateway['interface']);
1798
						break;
1799
					}
1800
				}
1801
			} else {
1802
				$destif = get_real_interface("wan");
1803
			}
1804
		}
1805

  
1806
		if (!empty($destif)) {
1807
			$srvifaces[] = "{$srvip}%{$destif}";
1808
		}
1677
	if (!is_array($srvips)) {
1678
		log_error("No destination IP has been configured!");
1679
		return;
1809 1680
	}
1810 1681

  
1811 1682
	/* fire up dhcrelay */

Also available in: Unified diff