Exec configure command in my C program?

Beside using http api, how could a C program running in vyos exec config command, such as:

set interfaces ethernet eth0 address dhcp

get interfaces ethernet eth0 address


For op-mode you can use op mode wrapper “/opt/vyatta/bin/vyatta-op-cmd-wrapper show version”


/opt/vyatta/bin/vyatta-op-cmd-wrapper show interfaces
Codes: S - State, L - Link, u - Up, D - Down, A - Admin Down
Interface        IP Address                        S/L  Description
---------        ----------                        ---  -----------
eth0                    u/u  
eth1                     u/u  
lo                            u/u  

Do we have something like /opt/vyatta/bin/vyatta-config-cmd-wrapper ?
I want to set/get configure in my C program.

Not sure if it will work in C
But you should use “source”

source /opt/vyatta/etc/functions/script-template

set protocols bgp system-as 65536
set protocols bgp neighbor remote-as 65002

I’m not C guy
but something like this

#include <stdlib.h>

int main() {
    system("source /opt/vyatta/etc/functions/script-template");
    system("set protocols bgp system-as 65536");
    system("set protocols bgp neighbor remote-as 65002");

    return 0;

Another example:


$cfg begin
$cfg set interfaces ethernet eth1 description TEST
$cfg commit
$cfg save
$cfg end

I.e. C

#include <stdlib.h>

int main() {
    system("/opt/vyatta/sbin/vyatta-cfg-cmd-wrapper begin");
    system("/opt/vyatta/sbin/vyatta-cfg-cmd-wrapper set interfaces ethernet eth1 description TEST");
    system("/opt/vyatta/sbin/vyatta-cfg-cmd-wrapper commit");
    system("/opt/vyatta/sbin/vyatta-cfg-cmd-wrapper end");

    return 0;

That’s not going to work. Each time you call system() it forks a child process that executes a POSIX shell (/bin/sh) with the -c string parameter that you specify. This means that every such call starts a new shell process. Your call to source, for example, is useless as once that system() call is returning, all your environment set by the template is gone.

Thanks, guys, and it works:

#include <stdlib.h>

int main() {
    system("/opt/vyatta/sbin/vyatta-cfg-cmd-wrapper begin;/opt/vyatta/sbin/vyatta-cfg-cmd-wrapper set interfaces ethernet eth1 description TEST;/opt/vyatta/sbin/vyatta-cfg-cmd-wrapper commit;/opt/vyatta/sbin/vyatta-cfg-cmd-wrapper end;");
    return 0;

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.