Duplicate Interface Configuration Entries in konfd When Using Two Input Formats

47 views
Skip to first unread message

Mohammad RafatPanah

unread,
Feb 23, 2025, 9:19:28 AMFeb 23
to klish

We have encountered an issue with our KLISH configuration where entering the interface command in two different formats—such as:

  • Normalized Format:
    interface Ethernet2
  • Full-Name Format:
    interface Ethernet 2

—results in duplicate interface entries in the running configuration stored by konfd.

In our XML configuration, we defined the commands as follows:
<VIEW name="configure-view">

<COMMAND name="interface"
help="Select an interface to configure"
view="configure-if-view"
viewid="iface=${iface_name}">
<PARAM name="iface_name"
help="Interface name"
ptype="IFACE_NAME"/>
<CONFIG priority="0x2001" pattern="^interface ${iface_name}$"/>
</COMMAND>

<COMMAND name="interface Ethernet"
help="Ethernet IEEE 802.3"
view="configure-if-view"
viewid="iface=Ethernet${iface_num}">
<PARAM name="iface_num"
help="Ethernet interface number"
ptype="IFACE_NUM"/>
<CONFIG priority="0x2001" pattern="^interface Ethernet${iface_num}$"/>
</COMMAND>

<COMMAND name="interface Vlan"
help="Vlan interface"
view="configure-if-view"
viewid="iface=Vlan${iface_num}">
<PARAM name="iface_num"
help="vlan interface number"
ptype="IFACE_NUM"/>
<CONFIG priority="0x2001" pattern="^interface vlan${iface_num}$"/>
</COMMAND>

</VIEW>

<VIEW name="configure-if-view"
prompt="${SYSTEM_NAME}(config-if-${iface})# "
depth="1">
<NAMESPACE ref="configure-view"
help="false"
completion="true"/>
</VIEW>

Observed Behavior:
When navigating into an interface configuration, even if the interface has already been configured (with subordinate commands such as shutdown or ip address), entering the command again creates a new configuration header. For example, after configuring interface Ethernet 2 and adding subcommands, subsequent entries cause duplicates like:

interface Ethernet 2
 ip address 192.168.20.10/24
!
interface Ethernet 2
 shutdown
!
interface Ethernet2
 shutdown

How can I resolve this? Is there any way to force konfd to save them as a unique config?

Serj Kalichev

unread,
Feb 24, 2025, 3:48:46 AMFeb 24
to kl...@googlegroups.com
The problem is a "path". When user enters the section (nested VIEW) the engine saves the command as a component of the "path". For example you write "interface Ethernet2", enters the VIEW and "path" contains "interface Ethernet2" as a first component. The internal (VIEW's) commands will search for that "path" while writing to the config (konfd). So nested VIEW has no it's own unique identifier but navigation command (that has "view="...") actually identifies the nesting. You have two different commands so "path" contains two different path component when you type normalized and non-normalized commands.

The config contains two "interface Ethernet 2" because your regexp for CONFIG tag targets normalized command and doesn't target non-normalized.
--
You received this message because you are subscribed to the Google Groups "klish" group.
To unsubscribe from this group and stop receiving emails from it, send an email to klish+un...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/klish/2d03cc92-b9cf-4f85-8a4a-51e8764930a5n%40googlegroups.com.


Message has been deleted
Message has been deleted

Mohammad RafatPanah

unread,
Feb 24, 2025, 7:00:21 AMFeb 24
to klish

Hi Serj,
Thank you very much for your detailed explanation.

Given this, I'm wondering if there's a way to resolve the issue so that both the normalized and non-normalized inputs are consolidated into a single, normalized configuration entry (preferably in the format "interface Ethernet2"). Any further guidance or suggestions on how to achieve this would be greatly appreciated.

Thanks again for your help!

Serj Kalichev

unread,
Feb 24, 2025, 7:44:37 AMFeb 24
to kl...@googlegroups.com
Suggestion #1:
The konfd is a stand alone daemon. There is konf utility to communicate to it. Utility connects to the konfd (by UNIX-socket) and uses special protocol to set or del entries. The "CONFIG" tag is just a wrapper for this protocol. You can don't use <CONFIG> tag but use konf utility by hands.

<ACTION>
..your_code
konf ..options.. "Ethernet$num" # set entry
</ACTION>

See konf -h for possible options

But it's rather ugly method because you need to use konf utility within all nested commands. To fix "path".

Suggestion #2:

Don't use non-normalized format. It's not good to use two formats for one object. It will be really simpler without such aliases.

Mohammad RafatPanah

unread,
Feb 24, 2025, 8:58:46 AMFeb 24
to klish

Thank you very much for your detailed suggestions.

I did try using konf -h, but it only shows the following minimal output:

konf -h
Usage: konf [options] -- <command for konfd daemon>
Utility for communication to the konfd configuration daemon.
Options:
        -v, --version   Print utility version.
        -h, --help      Print this help.
        -s <path>, --socket=<path>      Specify listen socket of the konfd daemon.

Is there any additional documentation available for the konf command that describes its options or the underlying protocol in more detail? Any pointers to further resources would be much appreciated.  

Serj Kalichev

unread,
Feb 24, 2025, 10:12:53 AMFeb 24
to kl...@googlegroups.com
Unfortunately there is no documentation for konfd.

You can configure klish with "--enable-debug" then execute konfd "konfd -d" in debug mode and without daemonize. So it will print all requests and parsed request to the console. You can execute klish with your XML-configs and see what requests it generates.
So you can see many real-world examples.

$ konf -- --set --line="mycmd" --pattern="mycmd"
will add command "mycmd" to config

$ konf -- --dump
will dump all config

It's simple commands but you can get the complex ones by debug mode.

Possible options (from C-code):

<------><------>{"set",><------>0, NULL, 's'},
<------><------>{"unset",<----->0, NULL, 'u'},
<------><------>{"ok",<><------>0, NULL, 'o'},
<------><------>{"error",<----->0, NULL, 'e'},
<------><------>{"dump",<------>0, NULL, 'd'},
<------><------>{"stream",<---->0, NULL, 't'},
<------><------>{"priority",<-->1, NULL, 'p'},
<------><------>{"seq",><------>1, NULL, 'q'},
<------><------>{"pattern",<--->1, NULL, 'r'},
<------><------>{"line",<------>1, NULL, 'l'},
<------><------>{"file",<------>1, NULL, 'f'},
<------><------>{"splitter",<-->0, NULL, 'i'},
<------><------>{"non-unique",<>0, NULL, 'n'},
<------><------>{"depth",<----->1, NULL, 'h'},
<

Mohammad RafatPanah

unread,
Feb 25, 2025, 1:38:05 AMFeb 25
to klish
Thank you in advance, Serj.
This will help me a lot.
Reply all
Reply to author
Forward
Message has been deleted
Message has been deleted
0 new messages