Fix Mikrotik / Mikrotik 7 src-address separator - #220
Open
HomesONE wants to merge 1 commit into
Open
Conversation
When source-interface-id is configured as an IP address (rather
than an interface name), `build_ping()` and `build_traceroute()`
in `mikrotik.php` and `mikrotik7.php` emit:
$cmd->add('src-address=');
$cmd->add($this->get_source_interface_id('ipv4'));
`CommandBuilder` joins added elements with its separator (default
single space), so the resulting RouterOS command is:
/tool/ping ... src-address= 1.2.3.4 ...
with a space between `=` and the address — RouterOS rejects this
with a syntax error. The interface variant
(`'interface='.$this->get_source_interface_id()`) on the else
branch already does the concatenation correctly; this PR makes
the IP-address branch behave the same way.
Affects: any Mikrotik or Mikrotik 7 router whose
`source-interface-id` is configured as an IPv4 or IPv6 literal.
Configurations using an interface name (the more common case)
are unaffected.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When
source-interface-idis configured as an IP address (rather than an interface name),build_ping()andbuild_traceroute()inmikrotik.phpand the parallel methods inmikrotik7.phpemit:```php
$cmd->add('src-address=');
$cmd->add($this->get_source_interface_id('ipv4'));
```
CommandBuilder::__toString()joins added elements with its separator (default single space), so the resulting RouterOS command is:```
/tool/ping ... src-address= 1.2.3.4 ...
```
with a space between
=and the address — RouterOS rejects this with a syntax error. The interface variant on theelsebranch already concatenates correctly:```php
$cmd->add('interface='.$this->get_source_interface_id());
```
Fix
Move the
src-address=prefix into the sameadd()call as the value, matching the pattern already used foraddress=andinterface=:```php
if (match_ipv6($parameter)) {
$cmd->add('src-address='.$this->get_source_interface_id('ipv6'));
} else {
$cmd->add('src-address='.$this->get_source_interface_id('ipv4'));
}
```
Affected configs
Any Mikrotik (RouterOS 6) or Mikrotik 7 router with
source-interface-idset to an IPv4 or IPv6 literal. Configs using an interface name (the more common case) are unaffected.Smoke test
Before:
```
/tool/ping count=1 address=8.8.8.8 src-address= 10.0.0.1
syntax error (line 1 column 56)
```
After:
```
/tool/ping count=1 address=8.8.8.8 src-address=10.0.0.1
SEQ HOST SIZE TTL TIME STATUS
0 8.8.8.8 56 56 5ms
```