Skip to content

Commit

Permalink
Make, cmd_gen: fix make lib build, update cmd_gen
Browse files Browse the repository at this point in the history
  • Loading branch information
Ali-aqrabawi committed Feb 23, 2024
1 parent 8af0490 commit 703fd26
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 91 deletions.
66 changes: 34 additions & 32 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,44 +25,46 @@ IPR2_SR_OBJ = $(IPR2_SR_SRC:.c=.o)


all: $(IPR2_SR_OBJ) $(IPR2_SR_LIB_OBJ) iproute2/config.mk
@set -e; \
for i in $(SUBDIRS); do \
$(MAKE) -C $$i || exit 1; done && \
echo "Building $(BIN)/$(EXEC)" && \
rm iproute2/ip/rtmon.o
rm iproute2/ip/ip.o
rm iproute2/bridge/bridge.o
rm iproute2/tc/tc.o
@echo ""
@echo "Patching conflicting symbols"
objcopy --redefine-sym print_linkinfo=br_print_linkinfo iproute2/bridge/link.o
objcopy --redefine-sym print_linkinfo=br_print_linkinfo iproute2/bridge/monitor.o
@echo ""
$(CC) -o $(BIN)/$(EXEC) $(IPR2_SR_OBJ) $(IPR2_SR_LIB_OBJ) `find iproute2/ip -name '*.[o]'` `find iproute2/bridge -name '*.[o]'` `find iproute2/tc -name '*.[o]'` `find iproute2/lib -name '*.[o]'` $(LDFLAGS)
@echo ""
@echo "Make complete"
@set -e; \
for i in $(SUBDIRS); do \
$(MAKE) -C $$i || exit 1; done && \
echo "Building $(BIN)/$(EXEC)" && \
rm iproute2/ip/rtmon.o
rm iproute2/ip/ip.o
rm iproute2/bridge/bridge.o
rm iproute2/tc/tc.o
@echo ""
@echo "Patching conflicting symbols"
objcopy --redefine-sym print_linkinfo=br_print_linkinfo iproute2/bridge/link.o
objcopy --redefine-sym print_linkinfo=br_print_linkinfo iproute2/bridge/monitor.o
@echo ""
$(CC) -o $(BIN)/$(EXEC) $(IPR2_SR_OBJ) $(IPR2_SR_LIB_OBJ) `find iproute2/ip -name '*.[o]'` `find iproute2/bridge -name '*.[o]'` `find iproute2/tc -name '*.[o]'` `find iproute2/lib -name '*.[o]'` $(LDFLAGS)
@echo ""
@echo "Make complete"

clean:
@set -e; \
for i in $(SUBDIRS); do \
$(MAKE) -C $$i clean || exit 1; done && \
rm -f iproute2/config.mk && \
rm -f $(IPR2_SR_OBJ) && \
rm -f $(IPR2_SR_LIB_OBJ) && \
rm -f $(BIN)/$(EXEC)
@set -e; \
for i in $(SUBDIRS); do \
$(MAKE) -C $$i clean || exit 1; done && \
rm -f iproute2/config.mk && \
rm -f $(IPR2_SR_OBJ) && \
rm -f $(IPR2_SR_LIB_OBJ) && \
rm -f $(BIN)/$(EXEC)

iproute2/config.mk:
@set -e; \
cd iproute2 && \
./configure && \
cd ..
@set -e; \
cd iproute2 && \
./configure && \
cd ..

check:
yanglint yang/*.yang
yanglint yang/*.yang

$(IPR2_SR_LIB_OBJ): $(IPR2_SR_LIB_SRC)
$(CC) -c $< -o $@ -Iiproute2/ip -Iiproute2/bridge -Iiproute2/tc -Iiproute2/include
src/lib/%.o: src/lib/%.c
$(CC) -c $< -o $@ -Iiproute2/ip -Iiproute2/bridge -Iiproute2/tc -Iiproute2/include


src/%.o: $(IPR2_SR_SRC) $(IPR2_SR_LIB_OBJ)
$(CC) -c $< -o $@ -Iiproute2/ip -Iiproute2/bridge -Iiproute2/tc -Iiproute2/include

$(IPR2_SR_OBJ): $(IPR2_SR_SRC)
$(CC) -c $< -o $@ -Iiproute2/ip -Iiproute2/bridge -Iiproute2/tc -Iiproute2/include

4 changes: 2 additions & 2 deletions src/iproute2_sysrepo.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
#include "br_common.h"

/* sysrepo */
#include "lib/cmdgen.h"
#include <sysrepo.h>
#include "lib/iproute2_cmdgen.h"

#ifndef LIBDIR
#define LIBDIR "/usr/lib"
Expand Down Expand Up @@ -352,7 +352,7 @@ int ip_sr_config_change_cb_apply(const struct lyd_node *change_dnode)
return SR_ERR_INVAL_ARG;
}

ipr2_cmds = lyd2cmd_argv(change_dnode);
ipr2_cmds = lyd2cmds_argv(change_dnode);
if (ipr2_cmds == NULL){
fprintf(stderr,
"%s: failed to generate commands for the change \n",
Expand Down
24 changes: 13 additions & 11 deletions src/lib/iproute2_cmdgen.c → src/lib/change_cmdgen.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include <ctype.h>
#include <bsd/string.h>

#include "iproute2_cmdgen.h"
#include "cmdgen.h"

#define CMD_LINE_SIZE 1024

Expand Down Expand Up @@ -139,7 +139,7 @@ oper_t get_operation(struct lyd_node *dnode)
}

/*
* return true if the node has ir2cgen:cmd-start extension.
* return true if the node has ipr2cgen:cmd-start extension.
*/
int is_startcmd_node(struct lyd_node *dnode)
{
Expand Down Expand Up @@ -215,7 +215,8 @@ void parse_command(const char *command, int *argc, char ***argv)
free(cmd_copy);
}

void add_command(char *cmd_line, struct cmd_args **cmds, int *cmd_idx, char **oper2cmd_prefix)
void add_command(char *cmd_line, struct cmd_args **cmds, int *cmd_idx,
char **oper2cmd_prefix, const struct lyd_node *start_dnode)
{
int argc;
char **argv;
Expand All @@ -233,12 +234,13 @@ void add_command(char *cmd_line, struct cmd_args **cmds, int *cmd_idx, char **op
}
dup_argv(&((cmds)[*cmd_idx]->argv), argv, argc);
(cmds)[*cmd_idx]->argc = argc;
(cmds)[*cmd_idx]->cmd_start_dnode = start_dnode;
(*cmd_idx)++;
memset(cmd_line, 0, CMD_LINE_SIZE);
free_argv(argv, argc);
}

struct cmd_args **lyd2cmd_argv(const struct lyd_node *change_node)
struct cmd_args **lyd2cmds_argv(const struct lyd_node *change_node)
{
char *result;
int cmd_idx = 0;
Expand All @@ -263,19 +265,19 @@ struct cmd_args **lyd2cmd_argv(const struct lyd_node *change_node)
// first get the add, update, delete cmds prefixis from schema extensions
if (get_extension(CMD_ADD_EXT, change_node, &oper2cmd_prefix[ADD_OPR]) != EXIT_SUCCESS) {
fprintf(stderr, "%s: cmd-add extension is missing from root container "
"make sure root container has ir2cgen:cmd-add\n",
"make sure root container has ipr2cgen:cmd-add\n",
__func__);
return NULL;
}
if (get_extension(CMD_DELETE_EXT, change_node, &oper2cmd_prefix[DELETE_OPR]) != EXIT_SUCCESS) {
fprintf(stderr, "%s: cmd-delete extension is missing from root container "
"make sure root container has ir2cgen:cmd-delete\n",
"make sure root container has ipr2cgen:cmd-delete\n",
__func__);
return NULL;
}
if (get_extension(CMD_UPDATE_EXT, change_node, &oper2cmd_prefix[UPDATE_OPR]) != EXIT_SUCCESS) {
fprintf(stderr, "%s: ir2cgen:cmd-update extension is missing from root container "
"make sure root container has ir2cgen:cmd-update\n",
fprintf(stderr, "%s: ipr2cgen:cmd-update extension is missing from root container "
"make sure root container has ipr2cgen:cmd-update\n",
__func__);
return NULL;
}
Expand All @@ -285,11 +287,11 @@ struct cmd_args **lyd2cmd_argv(const struct lyd_node *change_node)
struct lyd_node *next;
LYD_TREE_DFS_BEGIN(change_node, next)
{
// if this is startcmd node (schema has ir2cgen:cmd-start), then start building a new command
// if this is startcmd node (schema has ipr2cgen:cmd-start), then start building a new command
if (is_startcmd_node(next)) {
// check if the cmd is not empty (first cmd)
if (cmd_line[0] != 0)
add_command(cmd_line, cmds, &cmd_idx, oper2cmd_prefix);
add_command(cmd_line, cmds, &cmd_idx, oper2cmd_prefix, next);

// prepare for new command
op_val = get_operation(next);
Expand Down Expand Up @@ -340,7 +342,7 @@ struct cmd_args **lyd2cmd_argv(const struct lyd_node *change_node)
LYD_TREE_DFS_END(change_node, next);
}
if (cmd_line[0] != 0)
add_command(cmd_line, cmds, &cmd_idx, oper2cmd_prefix);
add_command(cmd_line, cmds, &cmd_idx, oper2cmd_prefix,next);

return cmds;
}
39 changes: 39 additions & 0 deletions src/lib/cmdgen.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/* SPDX-License-Identifier: AGPL-3.0-or-later */
#ifndef IPROUTE2_SYSREPO_CMDGEN_H
#define IPROUTE2_SYSREPO_CMDGEN_H

#include <libyang/libyang.h>

#define CMDS_ARRAY_SIZE 1024

/**
* @brief data struct to store the int argc,char **argv pair.
*
* this struct can be easily used by
* iproute2::do_cmd(argc,argv)
*/
struct cmd_args{
int argc;
char **argv;
const struct lyd_node *cmd_start_dnode;
};

/**
* @brief generate argc,argv commands out of the lyd_node (diff).
*
*
* @param[in] node Data node diff to generate the argc, argv.
* @return Array of cmd_args struct.
*/
struct cmd_args** lyd2cmds_argv(const struct lyd_node *change_node);

/**
* @brief generate argc,argv rollback command out of the lyd_node (diff).
*
*
* @param[in] node Data node diff to generate the argc, argv.
* @return Array of cmd_args struct.
*/
struct cmd_args* lyd2rollbackcmd_argv(const struct lyd_node *change_node);

#endif// IPROUTE2_SYSREPO_CMDGEN_H
29 changes: 0 additions & 29 deletions src/lib/iproute2_cmdgen.h

This file was deleted.

2 changes: 1 addition & 1 deletion tests/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ done
sysrepo_pid=$!
sleep 0.5

# Iterate over all .sh files in the current directory
# Iterate over all case/*.sh files
for test_script in tests/cases/*.sh; do
# Check if the file is executable and has the .sh extension
if [ -x "$test_script" ] && [[ "$test_script" == *.sh ]]; then
Expand Down
2 changes: 1 addition & 1 deletion yang/iproute2-cmdgen-extensions.yang
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module iproute2-cmdgen-extensions {
yang-version 1.1;
namespace "urn:okda:iproute2:cmdgen:extensions";
prefix "ir2cgen";
prefix "ipr2cgen";

organization
"Okda networks";
Expand Down
12 changes: 6 additions & 6 deletions yang/iproute2-ip-link.yang
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module iproute2-ip-link {
namespace "urn:okda:iproute2:ip:link";
prefix "iplink";

import iproute2-cmdgen-extensions { prefix ir2cgen; }
import iproute2-cmdgen-extensions { prefix ipr2cgen; }
//import ietf-inet-types { prefix inet; }
//import ietf-yang-types { prefix yang; }
organization
Expand Down Expand Up @@ -130,16 +130,16 @@ module iproute2-ip-link {


container links {
ir2cgen:cmd-add "ip link add";
ir2cgen:cmd-update "ip link set";
ir2cgen:cmd-delete "ip link delete";
ipr2cgen:cmd-add "ip link add";
ipr2cgen:cmd-update "ip link set";
ipr2cgen:cmd-delete "ip link delete";
description "ip-link - network device configuration";
list link {
ir2cgen:cmd-start;
ipr2cgen:cmd-start;
key "name";
description "ip-link - network device";
leaf name {
ir2cgen:value-only-on-update;
ipr2cgen:value-only-on-update;
type string;
description "link name";
}
Expand Down
18 changes: 9 additions & 9 deletions yang/iproute2-ip-nexthop.yang
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module iproute2-ip-nexthop {

import ietf-inet-types { prefix inet; }
import iproute2-ip-link { prefix iplink; }
import iproute2-cmdgen-extensions { prefix ir2cgen; }
import iproute2-cmdgen-extensions { prefix ipr2cgen; }

organization
"Okda Networks";
Expand All @@ -27,18 +27,18 @@ module iproute2-ip-nexthop {
}

container nexthops{
ir2cgen:cmd-add "ip nexthop add";
ir2cgen:cmd-update "ip nexthop replace";
ir2cgen:cmd-delete "ip nexthop del";
ipr2cgen:cmd-add "ip nexthop add";
ipr2cgen:cmd-update "ip nexthop replace";
ipr2cgen:cmd-delete "ip nexthop del";
description
"iproute2 nexthops configurations";
list nexthop{
ir2cgen:cmd-start;
ipr2cgen:cmd-start;
key "id";
description
"nexthop configuraton";
leaf id{
ir2cgen:value-only-on-update;
ipr2cgen:value-only-on-update;
description "nexthop id";
type uint32;
}
Expand Down Expand Up @@ -68,13 +68,13 @@ module iproute2-ip-nexthop {

}
leaf blackhole {
ir2cgen:flag;
ipr2cgen:flag;
description "specify if this is blackhole nexthop, which discards all traffic sent to it.";
type boolean;
when "not(../dev) and not(../ipv6) and not(../ipv4)";
}
leaf onlink {
ir2cgen:flag;
ipr2cgen:flag;
type boolean;
description "Indicates that the nexthop is directly reachable on the link.";
}
Expand Down Expand Up @@ -141,7 +141,7 @@ module iproute2-ip-nexthop {
}
}
leaf fdb {
ir2cgen:flag;
ipr2cgen:flag;
type boolean;
description "nexthop and nexthop groups for use with layer-2 fdb entries.
A fdb nexthop group can only have fdb nexthops. Example: Used to represent a vxlan remote
Expand Down

0 comments on commit 703fd26

Please sign in to comment.