Skip to content

Commit

Permalink
[link,vlan]: add support for vlans config pull, fix link vlan update.
Browse files Browse the repository at this point in the history
- added iproute2 patch for /bridge/vlan.c
- add oper_cmd_inner extension for inner list show command.
- for onupdate_replace: duplicate the start_cmd after adding the operations to the original startcmd

Signed-off-by: ali-aqrabawi <[email protected]>
  • Loading branch information
Ali-aqrabawi committed Jul 13, 2024
1 parent 479d41d commit c562ec9
Show file tree
Hide file tree
Showing 8 changed files with 185 additions and 65 deletions.
14 changes: 6 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ BINDIR = $(PREFIX)/bin

all: $(IPR2_SR_OBJ) $(IPR2_SR_LIB_OBJ) iproute2/config.mk
@echo "Checking if json_print patch is already applied..."
@if ! patch --dry-run --reverse --force -d iproute2 -p1 < ipr2_patches/json_print.patch; then \
@if ! patch --dry-run --reverse --force -d iproute2 -p1 < ipr2_patches/ipr2_src.patch; then \
echo "Applying json_print patch..."; \
patch -d iproute2 -p1 < ipr2_patches/json_print.patch || { echo "Patch failed"; true; }; \
patch -d iproute2 -p1 < ipr2_patches/ipr2_src.patch || { echo "Patch failed"; true; }; \
else \
echo "json_print patch is already applied, skipping..."; \
fi
Expand Down Expand Up @@ -65,11 +65,11 @@ uninstall:

clean:
@echo "Checking if json_print patch is already applied..."
@if ! patch --dry-run --reverse --force -d iproute2 -p1 < ipr2_patches/json_print.patch; then \
@if ! patch --dry-run --reverse --force -d iproute2 -p1 < ipr2_patches/ipr2_src.patch; then \
echo "Patch wasn't applying, nothing to reverse..."; \
else \
echo "Reversing json_print patch..."; \
patch -R -d iproute2 -p1 < ipr2_patches/json_print.patch || { echo "Patch failed"; true; }; \
patch -R -d iproute2 -p1 < ipr2_patches/ipr2_src.patch || { echo "Patch failed"; true; }; \
fi
@set -e; \
for i in $(SUBDIRS); do \
Expand Down Expand Up @@ -97,7 +97,5 @@ check:
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

src/%.o: src/%.c
$(CC) -c $< -o $@ -Iiproute2/ip -Iiproute2/bridge -Iiproute2/tc -Iiproute2/include
10 changes: 10 additions & 0 deletions ipr2_patches/json_print.patch → ipr2_patches/ipr2_src.patch
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,13 @@
+ fclose(j_stream);
}
}

--- /bridge/vlan.c 2024-03-01 19:01:32.645610624 -0500
+++ ipr2_patches/bridge_vlan_modified.c 2024-03-01 18:41:21.869658736 -0500
@@ -1119,7 +1119,8 @@
static int vlan_show(int argc, char **argv, int subject)
{
char *filter_dev = NULL;
- int ret = 0;
+ int ret = 0;
+ vlan_rtm_cur_ifidx = -1;
4 changes: 1 addition & 3 deletions src/iproute2_sysrepo.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ int force;
int max_flush_loops = 10;
int batch_mode;
bool do_all;

int vlan_rtm_cur_ifidx = -1;
/* bridge definitions */
int compress_vlans;

Expand Down Expand Up @@ -650,7 +650,6 @@ int apply_ipr2_cmd(char *ipr2_show_cmd)
int ret;
char **argv;
int argc;

parse_command(ipr2_show_cmd, &argc, &argv);
jump_set = 1;
if (setjmp(jbuf)) {
Expand Down Expand Up @@ -921,7 +920,6 @@ int sysrepo_start(int do_monitor)
++json; /* set iproute2 to format its print outputs in json */
++show_details; /* set iproute2 to include details in its print outputs */
++show_stats; /* set iproute2 to include stats in its print outputs */

ret = sr_connect(SR_CONN_DEFAULT, &sr_connection);

if (ret != SR_ERR_OK) {
Expand Down
85 changes: 43 additions & 42 deletions src/lib/cmdgen.c
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,6 @@ int create_cmd_arg_value(struct lyd_node *dnode, oper_t startcmd_op_val, char **
if (xpath_arg != NULL) {
struct ly_set *match_set = NULL;
int ret = lyd_find_xpath(dnode, xpath_arg, &match_set);
// lyd_find_xpath(dnode, "../../name", &match_set);
if (match_set != NULL) {
free(xpath_arg);
xpath_arg = strdup(lyd_get_value(match_set->dnodes[0]));
Expand Down Expand Up @@ -968,13 +967,13 @@ char *lyd2cmdline_args(const struct lyd_node *startcmd_node, oper_t op_val)

/**
* @brief this will fetch the startcmd_node from sysrepo, and merge it with the change node
* this will result on a replace on update change node.
* this is used by include_all_by_update extension.
* @param dnode the change lyd_node.
* @return EXIST_SUCCESS
* @return EXIST_FAILURE
*/

int ext_onupdate_replace_hdlr(struct lyd_node **dnode)
int ext_onupdate_include_all_hdlr(struct lyd_node **dnode)
{
int ret;
// get the original node from sysrepo
Expand Down Expand Up @@ -1029,7 +1028,7 @@ char *lyd2cmd_line(struct lyd_node *startcmd_node, char *oper2cmd_prefix[3])

if (op_val == UPDATE_OPR &&
(get_extension(INCLUDE_ALL_ON_UPDATE_EXT, startcmd_node, NULL) == EXIT_SUCCESS)) {
ext_onupdate_replace_hdlr(&startcmd_node);
ext_onupdate_include_all_hdlr(&startcmd_node);
}
// add cmd prefix to the cmd_line
strlcpy(cmd_line, oper2cmd_prefix[op_val], sizeof(cmd_line));
Expand Down Expand Up @@ -1233,44 +1232,6 @@ int add_cmd_info_core(struct cmd_info **cmds, int *cmd_idx, struct lyd_node *sta
goto cleanup;
}

// if this node is replace-on-update (where we need to delete and recreate the node in iproute2)
// first create a del_node with del operation then generate and add the command to the cmds before
// the original update cmd.
if (get_extension(REPLACE_ON_UPDATE_EXT, startcmd_node, NULL) == EXIT_SUCCESS &&
get_operation(startcmd_node) == UPDATE_OPR) {
//
ret = lyd_dup_single(startcmd_node, NULL, LYD_DUP_RECURSIVE, &del_startcmd_node);
if (ret != LY_SUCCESS) {
fprintf(
stderr,
"%s: ipr2cgen:failed to create del_startcmd_node: failed to duplicate node %s: %s\n",
__func__, startcmd_node->schema->name, ly_strerrcode(ret));
ret = EXIT_FAILURE;
goto cleanup;
}
// set the operation of the del_startcmd to delete.
struct lyd_meta *del_meta = lyd_find_meta(del_startcmd_node->meta, NULL, "yang:operation");
ret = lyd_change_meta(del_meta, "delete");
if (ret != LY_SUCCESS) {
fprintf(
stderr,
"%s: ipr2cgen:failed to add delete operation to del_startcmd_node for node %s: %s \n",
__func__, startcmd_node->schema->name, ly_strerrcode(ret));
ret = EXIT_FAILURE;
goto cleanup;
}
char *del_cmd_line = NULL;
initialize_startcmdinfo(del_startcmd_node);
del_cmd_line = lyd2cmd_line(del_startcmd_node, oper2cmd_prefix);
if (del_cmd_line == NULL) {
fprintf(stderr, "%s: failed to generate cmd for del_startcmd node \"%s\" \n", __func__,
startcmd_node->schema->name);
ret = EXIT_FAILURE;
goto cleanup;
}
add_command(cmds, cmd_idx, del_cmd_line, del_cmd_line);
}

// special case: for inner start_cmd, where the operation need to be taken from parent node.
oper_t op_val = get_operation(startcmd_node);
if (op_val == UNKNOWN_OPR) {
Expand Down Expand Up @@ -1308,6 +1269,46 @@ int add_cmd_info_core(struct cmd_info **cmds, int *cmd_idx, struct lyd_node *sta
}
}

// if this node is replace-on-update (where we need to delete and recreate the node in iproute2)
// first create a del_node with del operation then generate and add the command to the cmds before
// the original update cmd.
if (get_extension(REPLACE_ON_UPDATE_EXT, startcmd_node, NULL) == EXIT_SUCCESS &&
get_operation(startcmd_node) == UPDATE_OPR) {
//
ret = lyd_dup_single(startcmd_node, NULL, LYD_DUP_RECURSIVE | LYD_DUP_WITH_PARENTS,
&del_startcmd_node);
if (ret != LY_SUCCESS) {
fprintf(
stderr,
"%s: ipr2cgen:failed to create del_startcmd_node: failed to duplicate node %s: %s\n",
__func__, startcmd_node->schema->name, ly_strerrcode(ret));
ret = EXIT_FAILURE;
goto cleanup;
}
// set the operation of the del_startcmd to delete.
struct lyd_meta *del_meta = lyd_find_meta(del_startcmd_node->meta, NULL, "yang:operation");
ret = lyd_change_meta(del_meta, "delete");
if (ret != LY_SUCCESS) {
fprintf(
stderr,
"%s: ipr2cgen:failed to add delete operation to del_startcmd_node for node %s: %s \n",
__func__, startcmd_node->schema->name, ly_strerrcode(ret));
ret = EXIT_FAILURE;
goto cleanup;
}
char *del_cmd_line = NULL;
initialize_startcmdinfo(del_startcmd_node);

del_cmd_line = lyd2cmd_line(del_startcmd_node, oper2cmd_prefix);
if (del_cmd_line == NULL) {
fprintf(stderr, "%s: failed to generate cmd for del_startcmd node \"%s\" \n", __func__,
startcmd_node->schema->name);
ret = EXIT_FAILURE;
goto cleanup;
}
add_command(cmds, cmd_idx, del_cmd_line, del_cmd_line);
}

// before calling diff_reserve we need to do dup_single, otherwise all sibling startcmds,
// will be reversed
struct lyd_node *tmp_startcmd;
Expand Down
4 changes: 2 additions & 2 deletions src/lib/cmdgen.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ struct cmd_info {
void free_cmds_info(struct cmd_info **cmds_info);

/**
* parse the command line and convert it to argc, argv
* FOR_OPER: parse the command line and convert it to argc, argv
* @param [in] command command line string "ip link add ..."
* @param [out] argc parsed argv count
* @param [out] argv parsed argv
*/
void parse_command(const char *command, int *argc, char ***argv);

/**
* this func insert the netns name in the cmd, for example if cmd = ip link, and netns = "red"
* FOR_OPER: this func insert the netns name in the cmd, for example if cmd = ip link, and netns = "red"
* the cmd will become "ip -n red link",
* @param cmd
* @param netns
Expand Down
Loading

0 comments on commit c562ec9

Please sign in to comment.