Skip to content

Fix Mikrotik / Mikrotik 7 src-address separator - #220

Open
HomesONE wants to merge 1 commit into
gmazoyer:mainfrom
HomesONE:fix/mikrotik-src-address-separator
Open

Fix Mikrotik / Mikrotik 7 src-address separator#220
HomesONE wants to merge 1 commit into
gmazoyer:mainfrom
HomesONE:fix/mikrotik-src-address-separator

Conversation

@HomesONE

Copy link
Copy Markdown

Problem

When source-interface-id is configured as an IP address (rather than an interface name), build_ping() and build_traceroute() in mikrotik.php and the parallel methods in mikrotik7.php emit:

```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 the else branch already concatenates correctly:

```php
$cmd->add('interface='.$this->get_source_interface_id());
```

Fix

Move the src-address= prefix into the same add() call as the value, matching the pattern already used for address= and interface=:

```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-id set 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
```

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant