Page 1 of 1

Script Help for Newbie Enumerating Ethernet Interfaces

Posted: Tue Dec 04, 2012 2:58 am
by sonoracomm
Hi,

I'm trying to add "the rest of the Ethernet ports" to the bridge in a script where ether1 will be the WAN interface and ether2 will be the master bridge port.

This works, but I'd like to enumerate the ports rather than statically add lines:
#
# Set up the bridge and add the interfaces if required.
#
:if ($internalinterface = $bridgeinterface) do={
  /interface bridge add comment="LAN Bridge" disabled=no name=$bridgeinterface;
#
  /interface bridge port add bridge=$bridgeinterface comment="Master Bridge Port" disabled=no\
    edge=auto external-fdb=auto horizon=none interface=$etherlaninterface path-cost=10\
    point-to-point=auto priority=0x80;
#
  :if ($bridgetherest = "yes") do={
     /interface bridge port add bridge=$bridgeinterface comment="Bridged Port" disabled=no\
        interface=ether3;
     /interface bridge port add bridge=$bridgeinterface comment="Bridged Port" disabled=no\
        interface=ether4;
     /interface bridge port add bridge=$bridgeinterface comment="Bridged Port" disabled=no\
        interface=ether5;
     }
#
  /interface bridge port add bridge=$bridgeinterface comment="Wireless Bridge Port" disabled=no\
     interface=$wlaninterface;
  }
#
This is my latest failed attempt at enumeration:
#
# Set up the bridge and add the interfaces if required.
#
:if ( $internalinterface = $bridgeinterface ) do={
  /interface bridge add comment="LAN Bridge" disabled=no name=$bridgeinterface;
#
  /interface bridge port add bridge=$bridgeinterface comment="Master Bridge Port" disabled=no\
    edge=auto external-fdb=auto horizon=none interface=$etherlaninterface path-cost=10\
    point-to-point=auto priority=0x80;
#
  :if ( $bridgetherest = "yes" ) do={
     :foreach i in [/interface find type=ether] do={
       :local ethername [/interface get $i name];
       :if (( $ethername != ether1 ) and ( $ethername != ether2 )) do={
         /interface bridge port add bridge=$bridgeinterface comment="Bridged Port" disabled=no\
            interface=$ethername;
         }
      }
    }
# Add the wireless LAN to the bridge
  /interface bridge port add bridge=$bridgeinterface comment="Wireless Bridge Port" disabled=no\
     interface=$wlaninterface;
  }
#
I would appreciate any comments including tips on how to troubleshoot scripts.

Thanks in advance,

G

Re: Script Help for Newbie Enumerating Ethernet Interfaces

Posted: Tue Dec 11, 2012 9:10 pm
by sonoracomm
Well, I worked it out for myself.

I'm no programmer and there is probably a better way, but here is what I used to enumerate the Ethernet ports and add them to the bridge:
#
# Set up the bridge and add the interfaces if required.
#
:if ( $internalinterface = $bridgeinterface ) do={
  /interface bridge add comment="LAN Bridge" disabled=no name=$bridgeinterface;
#
  /interface bridge port add bridge=$bridgeinterface comment="Master Bridge Port" disabled=no\
    edge=auto external-fdb=auto horizon=none interface=$etherlaninterface path-cost=10\
    point-to-point=auto priority=0x80;
#
  :if ( $bridgetherest = "yes" ) do={
     :local etherports [ /interface ethernet find ];
     :local ethername "";
     :foreach etherport in=$etherports do={
       :set ethername [/interface get $etherport name];
       :if (( $ethername != "$waninterface" ) and ( $ethername != "$etherlaninterface" )) do={
         /interface bridge port add bridge=$bridgeinterface comment="Bridged Port" disabled=no\
            interface=$ethername;
         :log info "Added $ethername to $bridgeinterface";
         }
       }
     }
# Add the wireless LAN to the bridge
  /interface bridge port add bridge=$bridgeinterface comment="Wireless Bridge Port" disabled=no\
     interface=$wlaninterface;
  }
#
I hope it helps someone.

G