Revision d7827421
Added by Renato Botelho almost 10 years ago
src/etc/inc/services.inc | ||
---|---|---|
1628 | 1628 |
} |
1629 | 1629 |
} |
1630 | 1630 |
|
1631 |
/* |
|
1632 |
* In order for the relay to work, it needs to be active |
|
1633 |
* on the interface in which the destination server sits. |
|
1634 |
*/ |
|
1631 | 1635 |
$srvips = explode(",", $dhcrelaycfg['server']); |
1632 | 1636 |
if (!is_array($srvips)) { |
1633 |
log_error("No destination IP has been configured!");
|
|
1637 |
log_error("No destination ip has been configured!");
|
|
1634 | 1638 |
return; |
1635 | 1639 |
} |
1636 | 1640 |
|
1641 |
foreach ($srvips as $srcidx => $srvip) { |
|
1642 |
unset($destif); |
|
1643 |
foreach ($iflist as $ifname) { |
|
1644 |
$subnet = get_interface_ip($ifname); |
|
1645 |
if (!is_ipaddr($subnet)) { |
|
1646 |
continue; |
|
1647 |
} |
|
1648 |
$subnet .= "/" . get_interface_subnet($ifname); |
|
1649 |
if (ip_in_subnet($srvip, $subnet)) { |
|
1650 |
$destif = get_real_interface($ifname); |
|
1651 |
break; |
|
1652 |
} |
|
1653 |
} |
|
1654 |
if (!isset($destif)) { |
|
1655 |
foreach (get_staticroutes() as $rtent) { |
|
1656 |
if (ip_in_subnet($srvip, $rtent['network'])) { |
|
1657 |
$a_gateways = return_gateways_array(true); |
|
1658 |
$destif = $a_gateways[$rtent['gateway']]['interface']; |
|
1659 |
break; |
|
1660 |
} |
|
1661 |
} |
|
1662 |
} |
|
1663 |
|
|
1664 |
if (!isset($destif)) { |
|
1665 |
/* Create a array from the existing route table */ |
|
1666 |
exec("/usr/bin/netstat -rnWf inet", $route_str); |
|
1667 |
array_shift($route_str); |
|
1668 |
array_shift($route_str); |
|
1669 |
array_shift($route_str); |
|
1670 |
array_shift($route_str); |
|
1671 |
$route_arr = array(); |
|
1672 |
foreach ($route_str as $routeline) { |
|
1673 |
$items = preg_split("/[ ]+/i", $routeline); |
|
1674 |
if (is_subnetv4($items[0])) { |
|
1675 |
$subnet = $items[0]; |
|
1676 |
} elseif (is_ipaddrv4($items[0])) { |
|
1677 |
$subnet = "{$items[0]}/32"; |
|
1678 |
} else { |
|
1679 |
// Not a subnet or IP address, skip to the next line. |
|
1680 |
continue; |
|
1681 |
} |
|
1682 |
if (ip_in_subnet($srvip, $subnet)) { |
|
1683 |
$destif = trim($items[6]); |
|
1684 |
break; |
|
1685 |
} |
|
1686 |
} |
|
1687 |
} |
|
1688 |
|
|
1689 |
if (!isset($destif)) { |
|
1690 |
if (is_array($config['gateways']['gateway_item'])) { |
|
1691 |
foreach ($config['gateways']['gateway_item'] as $gateway) { |
|
1692 |
if (isset($gateway['defaultgw'])) { |
|
1693 |
$destif = get_real_interface($gateway['interface']); |
|
1694 |
break; |
|
1695 |
} |
|
1696 |
} |
|
1697 |
} else { |
|
1698 |
$destif = get_real_interface("wan"); |
|
1699 |
} |
|
1700 |
} |
|
1701 |
|
|
1702 |
if (!empty($destif)) { |
|
1703 |
$dhcrelayifs[] = $destif; |
|
1704 |
} |
|
1705 |
} |
|
1637 | 1706 |
$dhcrelayifs = array_unique($dhcrelayifs); |
1638 | 1707 |
|
1639 | 1708 |
/* fire up dhcrelay */ |
... | ... | |
1694 | 1763 |
} |
1695 | 1764 |
$dhcrelayifs = array_unique($dhcrelayifs); |
1696 | 1765 |
|
1766 |
/* |
|
1767 |
* In order for the relay to work, it needs to be active |
|
1768 |
* on the interface in which the destination server sits. |
|
1769 |
*/ |
|
1697 | 1770 |
$srvips = explode(",", $dhcrelaycfg['server']); |
1698 |
if (!is_array($srvips)) { |
|
1699 |
log_error("No destination IP has been configured!"); |
|
1700 |
return; |
|
1771 |
$srvifaces = array(); |
|
1772 |
foreach ($srvips as $srcidx => $srvip) { |
|
1773 |
unset($destif); |
|
1774 |
foreach ($iflist as $ifname) { |
|
1775 |
$subnet = get_interface_ipv6($ifname); |
|
1776 |
if (!is_ipaddrv6($subnet)) { |
|
1777 |
continue; |
|
1778 |
} |
|
1779 |
$subnet .= "/" . get_interface_subnetv6($ifname); |
|
1780 |
if (ip_in_subnet($srvip, $subnet)) { |
|
1781 |
$destif = get_real_interface($ifname); |
|
1782 |
break; |
|
1783 |
} |
|
1784 |
} |
|
1785 |
if (!isset($destif)) { |
|
1786 |
if (is_array($config['staticroutes']['route'])) { |
|
1787 |
foreach ($config['staticroutes']['route'] as $rtent) { |
|
1788 |
if (ip_in_subnet($srvip, $rtent['network'])) { |
|
1789 |
$a_gateways = return_gateways_array(true); |
|
1790 |
$destif = $a_gateways[$rtent['gateway']]['interface']; |
|
1791 |
break; |
|
1792 |
} |
|
1793 |
} |
|
1794 |
} |
|
1795 |
} |
|
1796 |
|
|
1797 |
if (!isset($destif)) { |
|
1798 |
/* Create a array from the existing route table */ |
|
1799 |
exec("/usr/bin/netstat -rnWf inet6", $route_str); |
|
1800 |
array_shift($route_str); |
|
1801 |
array_shift($route_str); |
|
1802 |
array_shift($route_str); |
|
1803 |
array_shift($route_str); |
|
1804 |
$route_arr = array(); |
|
1805 |
foreach ($route_str as $routeline) { |
|
1806 |
$items = preg_split("/[ ]+/i", $routeline); |
|
1807 |
if (ip_in_subnet($srvip, $items[0])) { |
|
1808 |
$destif = trim($items[6]); |
|
1809 |
break; |
|
1810 |
} |
|
1811 |
} |
|
1812 |
} |
|
1813 |
|
|
1814 |
if (!isset($destif)) { |
|
1815 |
if (is_array($config['gateways']['gateway_item'])) { |
|
1816 |
foreach ($config['gateways']['gateway_item'] as $gateway) { |
|
1817 |
if (isset($gateway['defaultgw'])) { |
|
1818 |
$destif = get_real_interface($gateway['interface']); |
|
1819 |
break; |
|
1820 |
} |
|
1821 |
} |
|
1822 |
} else { |
|
1823 |
$destif = get_real_interface("wan"); |
|
1824 |
} |
|
1825 |
} |
|
1826 |
|
|
1827 |
if (!empty($destif)) { |
|
1828 |
$srvifaces[] = "{$srvip}%{$destif}"; |
|
1829 |
} |
|
1701 | 1830 |
} |
1702 | 1831 |
|
1703 | 1832 |
/* fire up dhcrelay */ |
Also available in: Unified diff
Revert "remove the destination server's interface(s) from dhcrelay. Ticket #4908"
This reverts commit f791f28d6794c3b0601259f0de7acdebf6a367a8