-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mikrotik RouterOS Parser #244
Merged
itdependsnetworks
merged 7 commits into
networktocode:develop
from
h4ndzdatm0ld:feature/parsers/mikrotik-ros
May 11, 2023
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e6db422
Starting adding routeros
h4ndzdatm0ld ef6e109
Basic RouterOS Parser capabilities
h4ndzdatm0ld 319ff2b
Mappers
h4ndzdatm0ld 14ccd4d
feedback: Parsing tests for system note
h4ndzdatm0ld 2db3e58
Merge branch 'networktocode:develop' into feature/parsers/mikrotik-ros
h4ndzdatm0ld f28525a
if it looks like a duck, banners like a banner, then..
h4ndzdatm0ld 4f0ac6f
banner_end satisfied, but rely on is_banner_end
h4ndzdatm0ld File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
59 changes: 59 additions & 0 deletions
59
tests/unit/mock/config/compliance/compliance/mikrotik_routeros/routeros_backup.txt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# by RouterOS 6.49.6 | ||
# software id = WZ00-84LP | ||
# | ||
# model = CCR1036-8G-2S+ | ||
# serial number = C6CD0BF7A020 | ||
/interface bridge add name=google-vpc-peering-iface | ||
/interface bridge add name=loopback | ||
/interface bonding add mode=802.3ad name=Po1 slaves=sfp-sfpplus1,sfp-sfpplus2 | ||
/interface vlan add interface=Po1 name=vlan11-mgmt vlan-id=11 | ||
/interface vlan add interface=vlan2933-Transit-to-CC-NNI name=vlan3049-Transit-to-XXX vlan-id=3049 | ||
/interface vlan add disabled=yes interface=Po1 name=vlan3051-Transit-to-CSW-through-QoE-Disabled vlan-id=3051 | ||
/interface vlan add interface=Po1 mtu=1300 name=vlan3225-Transit-CORE-Agg1-to-COREXXX vlan-id=3225 | ||
/interface wireless security-profiles set [ find default=yes ] supplicant-identity=MikroTik | ||
/ip ipsec peer add address=50.157.100.38/32 exchange-mode=ike2 local-address=55.106.77.11 name=google-vpc-peer | ||
/ip pool add name=BNEdgeLiteTest ranges=192.168.69.254 | ||
/ip pool add name=BNEdgeLiteTest2 ranges=192.168.70.254 | ||
/ip dhcp-server add address-pool=BNEdgeLiteTest disabled=no interface=ether1 name=dhcp1 | ||
/ip dhcp-server add address-pool=BNEdgeLiteTest2 disabled=no interface=ether2 name=dhcp2 | ||
/routing bgp instance set default as=1234 router-id=10.127.1.3 | ||
/routing ospf instance set [ find default=yes ] router-id=10.127.1.3 | ||
/snmp community add addresses=::/0 name=somestringa | ||
/system logging action set 3 bsd-syslog=yes remote=172.16.11.1 remote-port=5140 | ||
/user group set full policy=local,telnet,ssh,ftp,reboot,read,write,policy,test,winbox,password,web,sniff,sensitive,api,romon,dude,tikapp | ||
/user group add name=prom policy=ssh,read,winbox,api,!local,!telnet,!ftp,!reboot,!write,!policy,!test,!password,!web,!sniff,!sensitive,!romon,!dude,!tikapp | ||
/ip neighbor discovery-settings set discover-interface-list=!dynamic | ||
/ip address add address=10.0.11.13/24 interface=vlan11-mgmt network=10.0.11.0 | ||
/ip address add address=192.168.69.1/24 interface=ether1 network=192.168.69.0 | ||
/ip dhcp-server network add address=192.168.69.0/24 gateway=192.168.69.1 | ||
/ip dhcp-server network add address=192.168.70.0/24 gateway=192.168.70.1 | ||
/ip dns set servers=8.8.8.8 | ||
/ip firewall address-list add address=34.157.17.38 list=whitelist | ||
/ip firewall address-list add address=72.202.79.109 list=google-vpc-acl | ||
/ip firewall address-list add address=34.157.17.38 list=google-vpc-acl | ||
/ip firewall filter add action=drop chain=input dst-address=50.106.77.11 src-address-list=!google-vpc-acl | ||
/ip firewall nat add action=dst-nat chain=dstnat dst-address=50.106.77.11 dst-port=443 protocol=tcp to-addresses=10.1.15.10 | ||
/ip firewall nat add action=masquerade chain=srcnat out-interface=vlan12-Servers | ||
/ip firewall nat add action=src-nat chain=srcnat src-address=50.64.0.75 to-addresses=55.106.77.11 | ||
/ip ipsec identity add peer=google-vpc-peer secret=***** | ||
/ip ipsec policy set 0 disabled=yes | ||
/ip ipsec policy add disabled=yes dst-address=169.254.1.1/32 peer=google-vpc-peer src-address=169.254.1.2/32 tunnel=yes | ||
/ip ipsec policy add disabled=yes dst-address=10.150.0.0/20 peer=google-vpc-peer src-address=0.0.0.0/0 tunnel=yes | ||
/ip service set telnet disabled=yes | ||
/ip service set ftp disabled=yes | ||
/ip service set www disabled=yes | ||
/ip service set api address=10.1.15.5/32,10.120.16.0/20,172.16.11.0/24 | ||
/ip service set api-ssl disabled=yes | ||
/routing bgp network add network=55.106.77.11/32 synchronize=no | ||
/routing bgp network add network=55.106.77.12/32 synchronize=no | ||
/routing bgp peer add in-filter=ibgp-allow-default-in name=CSW out-filter=ibgp-no-default-out remote-address=10.127.1.10 remote-as=12345 update-source=loopback | ||
/routing filter add action=discard chain=ibgp-no-default-out prefix=10.127.1.0/24 | ||
/routing filter add action=accept chain=ibgp-no-default-out prefix=10.64.0.0/10 prefix-length=22-32 | ||
/routing ospf interface add dead-interval=8s hello-interval=2s interface=vlan3049-Transit-to-85Presidential network-type=point-to-point | ||
/routing ospf interface add cost=11 dead-interval=8s hello-interval=2s interface=vlan3166-Transit-HalseyCore-Agg1-to-Indigo-5 network-type=point-to-point | ||
/routing ospf network add area=backbone network=10.126.0.16/29 | ||
/snmp set enabled=yes trap-community=somestring | ||
/system clock set time-zone-name=America/New_York | ||
/system identity set name=ag1.123site.nwk.nj | ||
/system logging add action=remote topics=error | ||
/system logging add action=remote topics=info |
5 changes: 5 additions & 0 deletions
5
tests/unit/mock/config/compliance/compliance/mikrotik_routeros/routeros_feature.py
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
features = [ | ||
{"name": "bgp", "ordered": True, "section": ["/routing bgp instance"]}, | ||
{"name": "snmp", "ordered": True, "section": ["/snmp"]}, | ||
{"name": "ospf-networks", "ordered": True, "section": ["/routing ospf network"]}, | ||
] |
60 changes: 60 additions & 0 deletions
60
tests/unit/mock/config/compliance/compliance/mikrotik_routeros/routeros_intended.txt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# by RouterOS 6.49.6 | ||
# software id = WZ00-84LP | ||
# | ||
# model = CCR1036-8G-2S+ | ||
# serial number = C6CD0BF7A020 | ||
/interface bridge add name=google-vpc-peering-iface | ||
/interface bridge add name=loopback | ||
/interface bonding add mode=802.3ad name=Po1 slaves=sfp-sfpplus1,sfp-sfpplus2 | ||
/interface vlan add interface=Po1 name=vlan11-mgmt vlan-id=11 | ||
/interface vlan add interface=vlan2933-Transit-to-CC-NNI name=vlan3049-Transit-to-XXX vlan-id=3049 | ||
/interface vlan add disabled=yes interface=Po1 name=vlan3051-Transit-to-CSW-through-QoE-Disabled vlan-id=3051 | ||
/interface vlan add interface=Po1 mtu=1300 name=vlan3225-Transit-CORE-Agg1-to-COREXXX vlan-id=3225 | ||
/interface wireless security-profiles set [ find default=yes ] supplicant-identity=MikroTik | ||
/ip ipsec peer add address=50.157.100.38/32 exchange-mode=ike2 local-address=55.106.77.11 name=google-vpc-peer | ||
/ip pool add name=BNEdgeLiteTest ranges=192.168.69.254 | ||
/ip pool add name=BNEdgeLiteTest2 ranges=192.168.70.254 | ||
/ip dhcp-server add address-pool=BNEdgeLiteTest disabled=no interface=ether1 name=dhcp1 | ||
/ip dhcp-server add address-pool=BNEdgeLiteTest2 disabled=no interface=ether2 name=dhcp2 | ||
/routing bgp instance set default as=1234 router-id=10.127.1.3 | ||
/routing ospf instance set [ find default=yes ] router-id=10.127.1.3 | ||
/snmp community add addresses=::/0 name=somestringa | ||
/system logging action set 3 bsd-syslog=yes remote=172.16.11.1 remote-port=5140 | ||
/user group set full policy=local,telnet,ssh,ftp,reboot,read,write,policy,test,winbox,password,web,sniff,sensitive,api,romon,dude,tikapp | ||
/user group add name=prom policy=ssh,read,winbox,api,!local,!telnet,!ftp,!reboot,!write,!policy,!test,!password,!web,!sniff,!sensitive,!romon,!dude,!tikapp | ||
/ip neighbor discovery-settings set discover-interface-list=!dynamic | ||
/ip address add address=10.0.11.13/24 interface=vlan11-mgmt network=10.0.11.0 | ||
/ip address add address=192.168.69.1/24 interface=ether1 network=192.168.69.0 | ||
/ip dhcp-server network add address=192.168.69.0/24 gateway=192.168.69.1 | ||
/ip dhcp-server network add address=192.168.70.0/24 gateway=192.168.70.1 | ||
/ip dns set servers=8.8.8.8 | ||
/ip firewall address-list add address=34.157.17.38 list=whitelist | ||
/ip firewall address-list add address=72.202.79.109 list=google-vpc-acl | ||
/ip firewall address-list add address=34.157.17.38 list=google-vpc-acl | ||
/ip firewall filter add action=drop chain=input dst-address=50.106.77.11 src-address-list=!google-vpc-acl | ||
/ip firewall nat add action=dst-nat chain=dstnat dst-address=50.106.77.11 dst-port=443 protocol=tcp to-addresses=10.1.15.10 | ||
/ip firewall nat add action=masquerade chain=srcnat out-interface=vlan12-Servers | ||
/ip firewall nat add action=src-nat chain=srcnat src-address=50.64.0.75 to-addresses=55.106.77.11 | ||
/ip ipsec identity add peer=google-vpc-peer secret=***** | ||
/ip ipsec policy set 0 disabled=yes | ||
/ip ipsec policy add disabled=yes dst-address=169.254.1.1/32 peer=google-vpc-peer src-address=169.254.1.2/32 tunnel=yes | ||
/ip ipsec policy add disabled=yes dst-address=10.150.0.0/20 peer=google-vpc-peer src-address=0.0.0.0/0 tunnel=yes | ||
/ip service set telnet disabled=yes | ||
/ip service set ftp disabled=yes | ||
/ip service set www disabled=yes | ||
/ip service set api address=10.1.15.5/32,10.120.16.0/20,172.16.11.0/24 | ||
/ip service set api-ssl disabled=yes | ||
/routing bgp network add network=55.106.77.11/32 synchronize=no | ||
/routing bgp network add network=55.106.77.12/32 synchronize=no | ||
/routing bgp peer add in-filter=ibgp-allow-default-in name=CSW out-filter=ibgp-no-default-out remote-address=10.127.1.10 remote-as=12345 update-source=loopback | ||
/routing filter add action=discard chain=ibgp-no-default-out prefix=10.127.1.0/24 | ||
/routing filter add action=accept chain=ibgp-no-default-out prefix=10.64.0.0/10 prefix-length=22-32 | ||
/routing ospf interface add dead-interval=8s hello-interval=2s interface=vlan3049-Transit-to-85Presidential network-type=point-to-point | ||
/routing ospf interface add cost=11 dead-interval=8s hello-interval=2s interface=vlan3166-Transit-Core-Agg1-to-SiteXYZ network-type=point-to-point | ||
/routing ospf network add area=backbone network=10.126.0.16/29 | ||
/routing ospf network add area=backbone network=10.127.1.3/32 | ||
/snmp set enabled=yes trap-community=somestring | ||
/system clock set time-zone-name=America/New_York | ||
/system identity set name=ag1.123site.nwk.nj | ||
/system logging add action=remote topics=error | ||
/system logging add action=remote topics=info |
32 changes: 32 additions & 0 deletions
32
tests/unit/mock/config/compliance/compliance/mikrotik_routeros/routeros_received.json
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"bgp": { | ||
"actual": "/routing bgp instance set default as=1234 router-id=10.127.1.3", | ||
"cannot_parse": true, | ||
"compliant": true, | ||
"extra": "", | ||
"intended": "/routing bgp instance set default as=1234 router-id=10.127.1.3", | ||
"missing": "", | ||
"ordered_compliant": true, | ||
"unordered_compliant": true | ||
}, | ||
"snmp": { | ||
"actual": "/snmp community add addresses=::/0 name=somestringa\n/snmp set enabled=yes trap-community=somestring", | ||
"cannot_parse": true, | ||
"compliant": true, | ||
"extra": "", | ||
"intended": "/snmp community add addresses=::/0 name=somestringa\n/snmp set enabled=yes trap-community=somestring", | ||
"missing": "", | ||
"ordered_compliant": true, | ||
"unordered_compliant": true | ||
}, | ||
"ospf-networks": { | ||
"actual": "/routing ospf network add area=backbone network=10.126.0.16/29", | ||
"cannot_parse": true, | ||
"compliant": false, | ||
"extra": "", | ||
"intended": "/routing ospf network add area=backbone network=10.126.0.16/29\n/routing ospf network add area=backbone network=10.127.1.3/32", | ||
"missing": "/routing ospf network add area=backbone network=10.127.1.3/32", | ||
"ordered_compliant": false, | ||
"unordered_compliant": false | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
...it/mock/config/compliance/config_section_not_parsed/mikrotik_routeros/routeros_feature.py
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
features = [ | ||
{"name": "routing-filter", "ordered": True, "section": ["/routing filter"]}, | ||
{"name": "ospf", "ordered": True, "section": ["/routing ospf"]}, | ||
{"name": "snmp", "ordered": True, "section": ["/snmp"]}, | ||
{"name": "ip-firewall", "ordered": True, "section": ["/ip firewall"]}, | ||
] |
5 changes: 5 additions & 0 deletions
5
...mock/config/compliance/config_section_not_parsed/mikrotik_routeros/routeros_received.json
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"remaining_cfg": "/system clock set time-zone-name=America/New_York\n/system identity set name=ag1.123site.nwk.nj\n/system logging add action=remote topics=error\n/system logging add action=remote topics=info", | ||
|
||
"section_not_found": ["ip-firewall"] | ||
} |
10 changes: 10 additions & 0 deletions
10
...unit/mock/config/compliance/config_section_not_parsed/mikrotik_routeros/routeros_sent.txt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/routing filter add action=discard chain=ibgp-no-default-out prefix=10.127.1.0/24 | ||
/routing filter add action=accept chain=ibgp-no-default-out prefix=10.64.0.0/10 prefix-length=22-32 | ||
/routing ospf interface add dead-interval=8s hello-interval=2s interface=vlan3049-Transit-to-85Presidential network-type=point-to-point | ||
/routing ospf interface add cost=11 dead-interval=8s hello-interval=2s interface=vlan3166-Transit-HalseyCore-Agg1-to-Indigo-5 network-type=point-to-point | ||
/routing ospf network add area=backbone network=10.126.0.16/29 | ||
/snmp set enabled=yes trap-community=somestring | ||
/system clock set time-zone-name=America/New_York | ||
/system identity set name=ag1.123site.nwk.nj | ||
/system logging add action=remote topics=error | ||
/system logging add action=remote topics=info |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Always like to have an example of a banner being parsed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey Ken! The comments at the top of the config files, is that considered a banner here, not just comments? There is a
system note
command, but it just outputs like a normal str config line.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, perhaps simpleton of me to presume there is a banner :)
I do think it would be great to have a few options for "note", like how does it handle multi-line (is that supported), special characters, can you have a double quote in there, etc.. Think of ways to break it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@itdependsnetworks I added to the
parsing
tests to capture the lines that are children of the/system note set note=..
line. This is the exact input that went into the device is below. If a user inputs a string without adding\n
the config export will handle it and add it for you, same with special chars. Device will just escape them when exporting config.and when doing a
terse
config export, the following output appears ->hope this helps and captures what you asked for, LMK.