494 |
494 |
}
|
495 |
495 |
|
496 |
496 |
/* Generate a 'nat on' or 'no nat on' rule for given interface */
|
497 |
|
function filter_nat_rules_generate_if($if, $src = "any", $srcport = "", $dst = "any", $dstport = "", $natip = "", $natport = "", $nonat = false, $staticnatport = false) {
|
|
497 |
function filter_nat_rules_generate_if($if, $src = "any", $proto = "any", $srcport = "", $dst = "any", $dstport = "", $natip = "", $natport = "", $nonat = false, $staticnatport = false) {
|
498 |
498 |
global $config;
|
499 |
499 |
|
500 |
500 |
/* XXX: billm - any idea if this code is needed? */
|
... | ... | |
507 |
507 |
else
|
508 |
508 |
$tgt = "($if)";
|
509 |
509 |
|
|
510 |
/* Add the protocol, if defined */
|
|
511 |
if (($proto != "") && ($proto != "any"))
|
|
512 |
$protocol = " proto {$proto}";
|
|
513 |
else
|
|
514 |
$protocol = "";
|
|
515 |
|
510 |
516 |
/* Add the hard set source port (useful for ISAKMP) */
|
511 |
517 |
if ($natport != "")
|
512 |
518 |
$tgt .= " port {$natport}";
|
... | ... | |
546 |
552 |
|
547 |
553 |
/* Put all the pieces together */
|
548 |
554 |
if($if_friendly)
|
549 |
|
$natrule = "{$nat} on \${$if_friendly} from {$src} to {$dst} {$target}{$staticnatport_txt}\n";
|
|
555 |
$natrule = "{$nat} on \${$if_friendly} {$protocol} from {$src} to {$dst} {$target}{$staticnatport_txt}\n";
|
550 |
556 |
|
551 |
557 |
return $natrule;
|
552 |
558 |
}
|
... | ... | |
654 |
660 |
|
655 |
661 |
$natrules .= filter_nat_rules_generate_if($natif,
|
656 |
662 |
$src,
|
|
663 |
$obent['protocol'],
|
657 |
664 |
$obent['sourceport'],
|
658 |
665 |
$dst,
|
659 |
666 |
$obent['dstport'],
|
... | ... | |
669 |
676 |
update_filter_reload_status("Creating outbound NAT rules");
|
670 |
677 |
|
671 |
678 |
$natrules .= filter_nat_rules_generate_if($wanif,
|
672 |
|
"{$lansa}/{$lancfg['subnet']}", 500, "", 500, null, 500, false);
|
|
679 |
"{$lansa}/{$lancfg['subnet']}", "any", 500, "", 500, null, 500, false);
|
673 |
680 |
$natrules .= filter_nat_rules_generate_if($wanif,
|
674 |
|
"{$lansa}/{$lancfg['subnet']}", 5060, "", 5060, null, 5060, false);
|
|
681 |
"{$lansa}/{$lancfg['subnet']}", "any", 5060, "", 5060, null, 5060, false);
|
675 |
682 |
$natrules .= filter_nat_rules_generate_if($wanif,
|
676 |
683 |
"{$lansa}/{$lancfg['subnet']}");
|
677 |
684 |
|
... | ... | |
683 |
690 |
$opt_interface = $oc['if'];
|
684 |
691 |
if (interface_has_gateway("$opt_interface")) {
|
685 |
692 |
$natrules .= filter_nat_rules_generate_if($opt_interface,
|
686 |
|
"{$lansa}/{$lancfg['subnet']}", 500, "", 500, null, 500, false);
|
|
693 |
"{$lansa}/{$lancfg['subnet']}", "any", 500, "", 500, null, 500, false);
|
687 |
694 |
$natrules .= filter_nat_rules_generate_if($opt_interface,
|
688 |
|
"{$lansa}/{$lancfg['subnet']}", 5060, "", 5060, null, 5060, false);
|
|
695 |
"{$lansa}/{$lancfg['subnet']}", "any", 5060, "", 5060, null, 5060, false);
|
689 |
696 |
$natrules .= filter_nat_rules_generate_if($opt_interface,
|
690 |
697 |
"{$lansa}/{$lancfg['subnet']}");
|
691 |
698 |
}
|
... | ... | |
701 |
708 |
|
702 |
709 |
/* create outbound nat entries for primary wan */
|
703 |
710 |
$natrules .= filter_nat_rules_generate_if($wanif,
|
704 |
|
"{$optsa}/{$optcfg['subnet']}", 500, "", 500, null, 500, false);
|
|
711 |
"{$optsa}/{$optcfg['subnet']}", "any", 500, "", 500, null, 500, false);
|
705 |
712 |
$natrules .= filter_nat_rules_generate_if($wanif,
|
706 |
|
"{$optsa}/{$optcfg['subnet']}", 5060, "", 5060, null, 5060, false);
|
|
713 |
"{$optsa}/{$optcfg['subnet']}", "any", 5060, "", 5060, null, 5060, false);
|
707 |
714 |
$natrules .= filter_nat_rules_generate_if($wanif,
|
708 |
|
"{$optsa}/{$optcfg['subnet']}", null, "", null, null, null, isset($optcfg['nonat']));
|
|
715 |
"{$optsa}/{$optcfg['subnet']}", "any", null, "", null, null, null, isset($optcfg['nonat']));
|
709 |
716 |
|
710 |
717 |
/* create outbound nat entries for all opt wans */
|
711 |
718 |
foreach($optints as $oc) {
|
712 |
719 |
$opt_interface = $oc['if'];
|
713 |
720 |
if (interface_has_gateway("$opt_interface")) {
|
714 |
721 |
$natrules .= filter_nat_rules_generate_if($opt_interface,
|
715 |
|
"{$optsa}/{$optcfg['subnet']}", 500, "", 500, null, 500, false);
|
|
722 |
"{$optsa}/{$optcfg['subnet']}", "any", 500, "", 500, null, 500, false);
|
716 |
723 |
$natrules .= filter_nat_rules_generate_if($opt_interface,
|
717 |
|
"{$optsa}/{$optcfg['subnet']}", 5060, "", 5060, null, 5060, false);
|
|
724 |
"{$optsa}/{$optcfg['subnet']}", "any", 5060, "", 5060, null, 5060, false);
|
718 |
725 |
$natrules .= filter_nat_rules_generate_if($opt_interface,
|
719 |
|
"{$optsa}/{$optcfg['subnet']}", null, "", null, null, null, isset($optcfg['nonat']));
|
|
726 |
"{$optsa}/{$optcfg['subnet']}", "any", null, "", null, null, null, isset($optcfg['nonat']));
|
720 |
727 |
}
|
721 |
728 |
}
|
722 |
729 |
}
|
... | ... | |
728 |
735 |
if($config['pptp']['pptp_subnet'] <> "")
|
729 |
736 |
$pptp_subnet = $config['pptp']['pptp_subnet'];
|
730 |
737 |
$natrules .= filter_nat_rules_generate_if($wanif,
|
731 |
|
"{$pptpdcfg['remoteip']}/{$pptp_subnet}", 500, "", 500, null, 500, false);
|
|
738 |
"{$pptpdcfg['remoteip']}/{$pptp_subnet}", "any", 500, "", 500, null, 500, false);
|
732 |
739 |
$natrules .= filter_nat_rules_generate_if($wanif,
|
733 |
|
"{$pptpdcfg['remoteip']}/{$pptp_subnet}", 5060, "", 5060, null, 5060, false);
|
|
740 |
"{$pptpdcfg['remoteip']}/{$pptp_subnet}", "any", 5060, "", 5060, null, 5060, false);
|
734 |
741 |
$natrules .= filter_nat_rules_generate_if($wanif,
|
735 |
742 |
"{$pptpdcfg['remoteip']}/{$pptp_subnet}");
|
736 |
743 |
|
... | ... | |
739 |
746 |
$opt_interface = $oc['if'];
|
740 |
747 |
if ((is_private_ip($pptpdcfg['remoteip'])) && (interface_has_gateway($opt_interface))) {
|
741 |
748 |
$natrules .= filter_nat_rules_generate_if($opt_interface,
|
742 |
|
"{$pptpdcfg['remoteip']}/{$pptp_subnet}", 500, "", 500, null, 500, false);
|
|
749 |
"{$pptpdcfg['remoteip']}/{$pptp_subnet}", "any", 500, "", 500, null, 500, false);
|
743 |
750 |
$natrules .= filter_nat_rules_generate_if($opt_interface,
|
744 |
|
"{$pptpdcfg['remoteip']}/{$pptp_subnet}", 5060, "", 5060, null, 5060, false);
|
|
751 |
"{$pptpdcfg['remoteip']}/{$pptp_subnet}", "any", 5060, "", 5060, null, 5060, false);
|
745 |
752 |
$natrules .= filter_nat_rules_generate_if($opt_interface,
|
746 |
753 |
"{$pptpdcfg['remoteip']}/{$pptp_subnet}");
|
747 |
754 |
}
|
... | ... | |
754 |
761 |
if($config['pppoe']['pppoe_subnet'] <> "")
|
755 |
762 |
$pppoe_subnet = $config['pppoe']['pppoe_subnet'];
|
756 |
763 |
$natrules .= filter_nat_rules_generate_if($wanif,
|
757 |
|
"{$pppoecfg['remoteip']}/{$pppoe_subnet}", 500, "", 500, null, 500, false);
|
|
764 |
"{$pppoecfg['remoteip']}/{$pppoe_subnet}", "any", 500, "", 500, null, 500, false);
|
758 |
765 |
$natrules .= filter_nat_rules_generate_if($wanif,
|
759 |
|
"{$pppoecfg['remoteip']}/{$pppoe_subnet}", 5060, "", 5060, null, 5060, false);
|
|
766 |
"{$pppoecfg['remoteip']}/{$pppoe_subnet}", "any", 5060, "", 5060, null, 5060, false);
|
760 |
767 |
$natrules .= filter_nat_rules_generate_if($wanif,
|
761 |
|
"{$pppoecfg['remoteip']}/{$pppoe_subnet}");
|
|
768 |
"{$pppoecfg['remoteip']}/{$pppoe_subnet}", "any");
|
762 |
769 |
|
763 |
770 |
/* generate nat mappings for opts with a gateway opts */
|
764 |
771 |
foreach($optints as $oc) {
|
765 |
772 |
$opt_interface = $oc['if'];
|
766 |
773 |
if ((is_private_ip($pppoecfg['remoteip'])) && (interface_has_gateway($opt_interface))) {
|
767 |
774 |
$natrules .= filter_nat_rules_generate_if($opt_interface,
|
768 |
|
"{$pppoecfg['remoteip']}/{$pppoe_subnet}", 500, "", 500, null, 500, false);
|
|
775 |
"{$pppoecfg['remoteip']}/{$pppoe_subnet}", "any", 500, "", 500, null, 500, false);
|
769 |
776 |
$natrules .= filter_nat_rules_generate_if($opt_interface,
|
770 |
|
"{$pppoecfg['remoteip']}/{$pppoe_subnet}", 5060, "", 5060, null, 5060, false);
|
|
777 |
"{$pppoecfg['remoteip']}/{$pppoe_subnet}", "any", 5060, "", 5060, null, 5060, false);
|
771 |
778 |
$natrules .= filter_nat_rules_generate_if($opt_interface,
|
772 |
779 |
"{$pppoecfg['remoteip']}/{$pppoe_subnet}");
|
773 |
780 |
}
|
... | ... | |
780 |
787 |
$netip = explode("/", $route['network']);
|
781 |
788 |
if ((! interface_has_gateway($route['interface'])) && (is_private_ip($netip[0]))) {
|
782 |
789 |
$natrules .= filter_nat_rules_generate_if($wanif,
|
783 |
|
"{$route['network']}", 500, "", 500, null, 500, false);
|
|
790 |
"{$route['network']}", "any", 500, "", 500, null, 500, false);
|
784 |
791 |
$natrules .= filter_nat_rules_generate_if($wanif,
|
785 |
|
"{$route['network']}", 5060, "", 5060, null, 5060, false);
|
|
792 |
"{$route['network']}", "any", 5060, "", 5060, null, 5060, false);
|
786 |
793 |
$natrules .= filter_nat_rules_generate_if($wanif,
|
787 |
|
"{$route['network']}", "", null);
|
|
794 |
"{$route['network']}", "any", "", null);
|
788 |
795 |
}
|
789 |
796 |
/* generate nat mapping for static routes on opts */
|
790 |
797 |
foreach($optints as $oc) {
|
791 |
798 |
$opt_interface = $oc['if'];
|
792 |
799 |
if ((! interface_has_gateway($route['interface'])) && (is_private_ip($netip[0])) && (interface_has_gateway($opt_interface))) {
|
793 |
800 |
$natrules .= filter_nat_rules_generate_if($opt_interface,
|
794 |
|
"{$route['network']}", 500, "", 500, null, 500, false);
|
|
801 |
"{$route['network']}", "any", 500, "", 500, null, 500, false);
|
795 |
802 |
$natrules .= filter_nat_rules_generate_if($opt_interface,
|
796 |
|
"{$route['network']}", 5060, "", 5060, null, 5060, false);
|
|
803 |
"{$route['network']}", "any", 5060, "", 5060, null, 5060, false);
|
797 |
804 |
$natrules .= filter_nat_rules_generate_if($opt_interface,
|
798 |
|
"{$route['network']}", "", null);
|
|
805 |
"{$route['network']}", "any", "", null);
|
799 |
806 |
}
|
800 |
807 |
}
|
801 |
808 |
|
Add protocol options for Manual Outbound NAT rules. See ticket #1887