Skip to content

Commit 618ef4a

Browse files
authored
Add better support for Mikrotik RouterOS 7
1 parent acff7cc commit 618ef4a

File tree

4 files changed

+197
-5
lines changed

4 files changed

+197
-5
lines changed

.dockerignore

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
.*
22
!/.htaccess
3-
4-
/docs/
5-
/scripts/
6-
/vendor/
7-
3+
docs/
4+
scripts/
5+
vendor/
86
LICENSE
7+
config.php.example
98
config.php
109
config.php.example
1110
mkdocs.yaml
@@ -15,3 +14,6 @@ peering_policy.*
1514
*.db
1615
*.log
1716
*.html
17+
*.md
18+
mkdocs.yaml
19+
.readthedocs.yaml

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ WORKDIR /var/www/html/
1919
RUN mkdir -p /var/log/ \
2020
&& touch /var/log/looking-glass.log \
2121
&& chown www-data /var/log/looking-glass.log
22+

routers/mikrotik7.php

Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
<?php
2+
3+
/*
4+
* Looking Glass - An easy to deploy Looking Glass
5+
* Copyright (C) 2014-2023 Guillaume Mazoyer <guillaume@mazoyer.eu>
6+
*
7+
* This program is free software; you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation; either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20+
*/
21+
22+
require_once('router.php');
23+
require_once('includes/command_builder.php');
24+
require_once('includes/utils.php');
25+
26+
final class Mikrotik7 extends Router {
27+
protected function build_bgp($parameter, $routing_instance = false) {
28+
if (!is_valid_ip_address($parameter)) {
29+
throw new Exception('The parameter is not an IP address.');
30+
}
31+
32+
$cmd = new CommandBuilder();
33+
$cmd->add('routing route print');
34+
35+
if ($this->config['bgp_detail']) {
36+
$cmd->add('detail');
37+
}
38+
39+
$cmd->add('where', quote($parameter).' in dst-address');
40+
41+
if ($routing_instance !== false) {
42+
$cmd->add('and routing-table='.$routing_instance);
43+
}
44+
45+
// Remove blackhole routes
46+
if (!$this->config['blackhole']) {
47+
$cmd->add('and !blackhole');
48+
}
49+
if (!$this->config['filtered']) {
50+
$cmd->add('and !filtered');
51+
}
52+
if (!$this->config['disabled']) {
53+
$cmd->add('and !disabled');
54+
}
55+
56+
return array($cmd);
57+
}
58+
59+
protected function build_aspath_regexp($parameter, $routing_instance = false) {
60+
$cmd = new CommandBuilder();
61+
$cmd->add('routing route print');
62+
63+
if ($this->config['bgp_detail']) {
64+
$cmd->add('detail');
65+
}
66+
67+
$cmd->add('where', 'bgp.as-path~'.quote($parameter));
68+
69+
if ($routing_instance !== false) {
70+
$cmd->add('and routing-table='.$routing_instance);
71+
}
72+
73+
// Remove blackhole routes
74+
if (!$this->config['blackhole']) {
75+
$cmd->add('and !blackhole');
76+
}
77+
if (!$this->config['filtered']) {
78+
$cmd->add('and !filtered');
79+
}
80+
if (!$this->config['disabled']) {
81+
$cmd->add('and !disabled');
82+
}
83+
84+
return array($cmd);
85+
}
86+
87+
protected function build_as($parameter, $routing_instance = false) {
88+
$cmd = new CommandBuilder();
89+
$cmd->add('routing route print');
90+
91+
if ($this->config['bgp_detail']) {
92+
$cmd->add('detail');
93+
}
94+
95+
$cmd->add('where', 'bgp.as-path~'.quote($parameter.'\$'));
96+
97+
if ($routing_instance !== false) {
98+
$cmd->add('and routing-table='.$routing_instance);
99+
}
100+
101+
// Remove blackhole routes
102+
if (!$this->config['blackhole']) {
103+
$cmd->add('and !blackhole');
104+
}
105+
if (!$this->config['filtered']) {
106+
$cmd->add('and !filtered');
107+
}
108+
if (!$this->config['disabled']) {
109+
$cmd->add('and !disabled');
110+
}
111+
112+
return array($cmd);
113+
//return $commands;
114+
}
115+
116+
protected function build_ping($parameter, $routing_instance = false) {
117+
if (!is_valid_destination($parameter)) {
118+
throw new Exception('The parameter is not an IP address or a hostname.');
119+
}
120+
121+
$cmd = new CommandBuilder();
122+
$cmd->add('ping count=10');
123+
124+
if (match_hostname($parameter)) {
125+
$cmd->add('address=[:resolv '.quote($parameter).']');
126+
} else {
127+
$cmd->add('address='.quote($parameter));
128+
}
129+
130+
if ($this->has_source_interface_id()) {
131+
if (is_valid_ip_address($this->get_source_interface_id())) {
132+
$cmd->add('src-address=');
133+
if (match_ipv6($parameter)) {
134+
$cmd->add($this->get_source_interface_id('ipv6'));
135+
} else {
136+
$cmd->add($this->get_source_interface_id('ipv4'));
137+
}
138+
} else {
139+
$cmd->add('interface='.$this->get_source_interface_id());
140+
}
141+
}
142+
143+
if ($routing_instance !== false) {
144+
$cmd->add('vrf='.$routing_instance);
145+
}
146+
147+
return array($cmd);
148+
}
149+
protected function build_traceroute($parameter, $routing_instance = false) {
150+
if (!is_valid_destination($parameter)) {
151+
throw new Exception('The parameter is not an IP address or a hostname.');
152+
}
153+
154+
$cmd = new CommandBuilder();
155+
$cmd->add('tool traceroute count=10 use-dns=yes');
156+
157+
if (match_hostname($parameter)) {
158+
$cmd->add('address=[:resolv '.quote($parameter).']');
159+
} else {
160+
$cmd->add('address='.quote($parameter));
161+
}
162+
163+
if ($this->has_source_interface_id()) {
164+
if (is_valid_ip_address($this->get_source_interface_id())) {
165+
$cmd->add('src-address=');
166+
if (match_ipv6($parameter)) {
167+
$cmd->add($this->get_source_interface_id('ipv6'));
168+
} else {
169+
$cmd->add($this->get_source_interface_id('ipv4'));
170+
}
171+
} else {
172+
$cmd->add('interface='.$this->get_source_interface_id());
173+
}
174+
}
175+
176+
if ($routing_instance !== false) {
177+
$cmd->add('vrf='.$routing_instance);
178+
}
179+
180+
return array($cmd);
181+
}
182+
}
183+
184+
// End of mikrotik7.php

routers/router.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
require_once('extreme_netiron.php');
3030
require_once('juniper.php');
3131
require_once('mikrotik.php');
32+
require_once('mikrotik7.php');
3233
require_once('nokia.php');
3334
require_once('openbgpd.php');
3435
require_once('quagga.php');
@@ -244,6 +245,10 @@ public static final function instance($id, $requester) {
244245
case 'routeros':
245246
return new Mikrotik($config, $router_config, $id, $requester);
246247

248+
case 'mikrotik7':
249+
case 'routeros7':
250+
return new Mikrotik7($config, $router_config, $id, $requester);
251+
247252
case 'nokia':
248253
return new Nokia($config, $router_config, $id, $requester);
249254

0 commit comments

Comments
 (0)