yellowman / nsh

OpenBSD networking configuration shell
http://www.nmedia.net/nsh/
Other
174 stars 27 forks source link

implement tab-completion for the rtable command #118

Closed stspdotname closed 1 year ago

stspdotname commented 1 year ago

Completion for the rtable command now lists routing table numbers as stored in the nsh database, i.e. as preserved in nsh configuration. Aside from default routing table 0 users will have to visit a given routing table with nsh at least once before the table will show up in the completion list of the rtable command. This behaviour seems like a fair trade-off given that there is no way to query the kernel for existing routing tables without looping over all possible routing table numbers and doing a syscall for each of them.

While here, fix an error in the rtable command help completion table, and fix problems with no-command completion exposed by "no rtable".

smytht commented 1 year ago

Hi Stefan ... below is my test script nsh(config-p)/rtable 0 rtable

rtable
[name] nsh(config-p)/rtable 0 rtable
rtable
[name] nsh(config-p)/rtable 0 rtable
rtable
[name] nsh(config-p)/rtable 1 nsh(config-p-rtable 1)/rtable 0 nsh(config-p)/rtable 0 1 nsh(config-p)/rtable

double tab rtable witin an rdomain suggests the current rdomain... and not 0. I would suggest rdomain 0 (and every other active rdomain ) be presented as an option when in another rdomain...

when in rdomain 0 every other rdomain should be presented...

perhaps a comment / description for rdomain feature is needed and this is displayed also with 0 having main by default (unless rtable0 description is reconfigured by the user ... ? ) it is a new feature to have a description / name for the rdomain (similar to the interface description command) ill add it to the todolist

yellowman commented 1 year ago

smytht @.*** wrote:

Hi Stefan ... below is my test script nsh(config-p)/rtable 0 rtable

rtable
[name] nsh(config-p)/rtable 0 rtable
rtable
[name] nsh(config-p)/rtable 0 rtable
rtable
[name] nsh(config-p)/rtable 1 nsh(config-p-rtable 1)/rtable 0 nsh(config-p)/rtable 0 1 nsh(config-p)/rtable

double tab rtable witin an rdomain suggests the current rdomain... and not 0. I would suggest rdomain 0 (and every other active rdomain ) be presented as an option when in another rdomain...

when in rdomain 0 every other rdomain should be presented...

perhaps a comment / description for rdomain feature is needed and this is displayed also with 0 having main by default (unless rtable0 description is reconfigured by the user ... ? ) it is a new feature to have a description / name for the rdomain (similar to the interface description command) ill add it to the todolist

rtable/rdomain 0 means no rdomain

stspdotname commented 1 year ago

Above force-push makes this change honor the assumption that rtable 0 is never present in the DB.

stspdotname commented 1 year ago

Since this change depends on the one proposed in PR 117 I have merged that change in here to make testing easier.

smytht commented 1 year ago

This seems to work ok from my perspective ... nsh(config-p)/rtable 0 tested trying to create an rdomain greater than what is allowed ... iit worked ok completion worked as expected ... works with adding new rtables and removing ones

rtable

rtable
[name] nsh(config-p)/rtable 0 rtable
rtable
[name] nsh(config-p)/rtable 0 nsh(config-p)/exit nsh(p)/rtable 1 nsh(p-rtable 1)/enable nsh(p-rtable 1)/show run ! hostname nsh ! interface lo0 group lo inet ::1/128 inet 127.0.0.1/8 ! interface em0 group egress autoconf4 ! interface em1 description test show active inet 10.10.10.1/30 ! interface enc0 group enc shutdown ! interface pflog0 group pflog no shutdown !
interface vlan100 group vlan shutdown ! interface vlan200 group vlan shutdown ! ! no ip forwarding ! route 224.0.0.0/4 127.0.0.1 iface nompath reject route 127.0.0.0/8 127.0.0.1 nompath reject route ::/96 ::1 nompath reject route ::ffff:0.0.0.0/96 ::1 nompath reject route 2002::/24 ::1 nompath reject route 2002:7f00::/24 ::1 nompath reject route 2002:e000::/20 ::1 nompath reject route 2002:ff00::/24 ::1 nompath reject route fe80::/10 ::1 nompath reject route fec0::/10 ::1 nompath reject route ff01::/16 ::1 nompath reject route ff02::/16 ::1 nompath reject ! ! resolv enable ! rtable 1 ! ! nsh(p-rtable 1)/ ! exit ipsec pf show ? flush ldap ping smtp arp ftp-proxy ldp ping6 snmp bgp group manual pipex ssh bridge halt motd quit sshd configure help mpls rad telnet ddb hostname nameserver reboot tftp dhcp ifstate ndp relay tftp-proxy disable ike no resolv traceroute dvmrp inet nppp rip traceroute6 editing interface ntp route verbose eigrp ip ospf rtable who enable ip6 ospf6 sasync write-config nsh(p-rtable 1)/ ! exit ipsec pf show ? flush ldap ping smtp arp ftp-proxy ldp ping6 snmp bgp group manual pipex ssh bridge halt motd quit sshd configure help mpls rad telnet ddb hostname nameserver reboot tftp dhcp ifstate ndp relay tftp-proxy disable ike no resolv traceroute dvmrp inet nppp rip traceroute6 editing interface ntp route verbose eigrp ip ospf rtable who enable ip6 ospf6 sasync write-config nsh(p-rtable 1)/rtable 0 1 nsh(p-rtable 1)/rtable 0 1 nsh(p-rtable 1)/rtable 0 nsh(p)/rtable 0 1 nsh(p)/rtable 0 1 nsh(p)/rtable 1 nsh(p-rtable 1)/rtable 10240 % invalid table id: too large nsh(p-rtable 1)/rtable 256 % invalid table id: too large nsh(p-rtable 1)/rtable 255 nsh(config-p-rtable 255)/rtable 0 1 255 nsh(config-p-rtable 255)/rtable 0 1 255 nsh(config-p-rtable 255)/rtable

nsh(config-p)/no rtable 2 0 255 nsh(config-p)/no rtable 2 0 255 nsh(config-p)/no rtable 25 0 255 nsh(config-p)/no rtable 255 0 255 nsh(config-p)/no rtable 255 nsh(config-p)/rtable 0 1 nsh(config-p)/rtable 0 1 nsh(config-p)/rtable

stspdotname commented 1 year ago

Is there anything left to be done here?

smytht commented 1 year ago

I have no objection... I have tested / tortured this particular release and it worked as expected...

stspdotname commented 1 year ago

OK I think this is good to go. Let me know if any issues arise, of course.