You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello! You can dispatch it only with very hard validation callback on snooping command. I think, you have very hard command hierarchy. You can define vlan config mode, where you can store context within all required data about vlan, and declare commands, that would be enable on vlan config mode.
#defineMODE_CONFIG_VLAN 0x02
structvlan_context {
// Add all fields that you need for vlan
};
intconfig_vlan(structcli_def*cli, constchar*command, char*argv[], intargc);
voidinitialize_commands(structcli_def*cli) {
structcli_def*c;
c=cli_register_command(cli, NULL, "vlan", config_vlan, PRIVILEGE_PRIVILEGED, MODE_CONFIG,
"Configure VLAN");
c=cli_register_command(cli, c, "ip", NULL, PRIVILEGE_PRIVILEGED, MODE_CONFIG, "ip help");
c=cli_register_command(cli, c, "igmp", NULL, PRIVILEGE_PRIVILEGED, MODE_CONFIG,
"igmp help");
c=cli_register_command(cli, c, "snooping", NULL, PRIVILEGE_PRIVILEGED, MODE_CONFIG,
"snooping help");
c=cli_register_command(cli, c, "mrouter", NULL, PRIVILEGE_PRIVILEGED, MODE_CONFIG_VLAN,
"mrouter help");
c=cli_register_command(cli, c, "interfaces", NULL, PRIVILEGE_PRIVILEGED, MODE_CONFIG_VLAN,
"interfaces help");
}
intconfig_vlan(structcli_def*cli, constchar*command, char*argv[], intargc) {
staticstructvlan_contextctx;
// Your validation routine, if no argument should be use -- set default vlan id
...
// If all is okcli_set_context(cli, (void*)&ctx);
cli_set_configmode(cli, MODE_CONFIG_VLAN, "vlan");
}
Thanks for your reply, @filka55533. it is a good opinion. Unfortunately, we don't want to modify the CLI command hierarchy. So, regarding question 2, is there any way to solve it?
Just look on example with perimeter command on clitest.c . On optarg shape you can see function shape_transient_eval, where according to the shape (rectangle or triangle) should be setting new MODE_CONFIG_* mode. You can use same technique, where you should be enable your new mode (f.e. MODE_CONFIG_VLAN) and register other commands (mrouter and interfaces) only for this new mode like on the clitest.c file with side_1-4 arguments. But this solution would be harder to scale for new command if compare it with my previous solution, keep in mind it.
Activity
[-]how to append the command after arugments?[/-][+]how to append the command after arugment?[/+]filka55533 commentedon Jun 30, 2024
Hello! You can dispatch it only with very hard validation callback on
snoopingcommand. I think, you have very hard command hierarchy. You can define vlan config mode, where you can store context within all required data about vlan, and declare commands, that would be enable on vlan config mode.And than you can config it as
For my opinion this would be much easier, than when you would write
snoopingcommand callback.PFtyrant commentedon Jul 1, 2024
Thanks for your reply, @filka55533. it is a good opinion. Unfortunately, we don't want to modify the CLI command hierarchy. So, regarding question 2, is there any way to solve it?
filka55533 commentedon Jul 1, 2024
Just look on example with
perimetercommand onclitest.c. On optargshapeyou can see functionshape_transient_eval, where according to the shape (rectangle or triangle) should be setting newMODE_CONFIG_*mode. You can use same technique, where you should be enable your new mode (f.e.MODE_CONFIG_VLAN) and register other commands (mrouterandinterfaces) only for this new mode like on theclitest.cfile withside_1-4arguments. But this solution would be harder to scale for new command if compare it with my previous solution, keep in mind it.