pespin submitted this change.

View Change

Approvals: pespin: Looks good to me, approved osmith: Looks good to me, but someone else must approve Jenkins Builder: Verified
osmo-config-merge: Fix comments with different indentation creating merge problems

VTY comments are not part of the tree structure, since they can be
placed anywhere and are just ignored.
Hence, ignore them when generating the tree structure during file read.

This has the backside that of course when merging files, comments on the
0-level show up in the end in testB.ok since the content below it in
testB.confmerge is now merged (properly) into previous nodes.
This can be slightly improved by placing the comments in the proper
indentation level, since if a new node is appended from the .confmerge,
they will be added in order and hence will show up properly.

Change-Id: I7de78d3ed3ca27e3470ea66a78ff9c5acfe65741
---
M tests/osmo-config-merge/testA.ok
M tests/osmo-config-merge/testB.ok
M tests/osmo-config-merge/testB2.ok
M utils/osmo-config-merge.c
4 files changed, 156 insertions(+), 128 deletions(-)

diff --git a/tests/osmo-config-merge/testA.ok b/tests/osmo-config-merge/testA.ok
index b0768ad..c244bd0 100644
--- a/tests/osmo-config-merge/testA.ok
+++ b/tests/osmo-config-merge/testA.ok
@@ -15,7 +15,6 @@
logging print level 1
logging timestamp 1
logging color 1
-!
logging level set-all notice
logging level rsl info
logging level meas info
@@ -28,6 +27,7 @@
logging level lmib info
logging level lmux info
!
+!
line vty
no login
bind 127.0.0.1
diff --git a/tests/osmo-config-merge/testB.ok b/tests/osmo-config-merge/testB.ok
index 64860f8..0edb5a9 100644
--- a/tests/osmo-config-merge/testB.ok
+++ b/tests/osmo-config-merge/testB.ok
@@ -54,6 +54,74 @@
local-ip 127.0.0.1
local-ip ::1
accept-asp-connections dynamic-permitted
+ asp asp-sender 9999 2905 m3ua
+ local-ip 127.0.0.1
+ local-ip ::1
+ remote-ip 127.0.0.1
+ remote-ip ::1
+ role sg
+ sctp-role server
+ asp asp-receiver0 10000 2905 m3ua
+ local-ip 127.0.0.1
+ local-ip ::1
+ remote-ip 127.0.0.1
+ remote-ip ::1
+ role sg
+ sctp-role server
+ asp asp-receiver1 10001 2905 m3ua
+ local-ip 127.0.0.1
+ local-ip ::1
+ remote-ip 127.0.0.1
+ remote-ip ::1
+ role sg
+ sctp-role server
+ asp asp-client0 10002 2906 m3ua
+ local-ip 127.0.0.1
+ local-ip ::1
+ remote-ip 127.0.0.1
+ remote-ip ::1
+ role asp
+ sctp-role client
+ asp asp-client60-norctx0 11060 2907 m3ua
+ local-ip 127.0.0.1
+ local-ip ::1
+ remote-ip 127.0.0.1
+ remote-ip ::1
+ role asp
+ sctp-role client
+ asp asp-client61-norctx0 11061 2907 m3ua
+ local-ip 127.0.0.1
+ local-ip ::1
+ remote-ip 127.0.0.1
+ remote-ip ::1
+ role asp
+ sctp-role client
+ as as-sender m3ua
+ asp asp-sender
+ routing-key 1023 23
+ as as-receiver m3ua
+ asp asp-receiver0
+ asp asp-receiver1
+ routing-key 1042 42
+ as as-client m3ua
+ routing-key 1055 55
+ asp asp-client0
+ as as-client60-norctx m3ua
+ routing-key 0 60
+ asp asp-client60-norctx0
+ as as-client61-norctx m3ua
+ routing-key 0 61
+ asp asp-client61-norctx0
+ route-table system
+ update route 23 16777215 linkset as-sender
+ update route 42 16777215 linkset as-receiver
+ update route 55 16777215 linkset as-client
+ update route 60 16777215 linkset as-client60-norctx
+ update route 61 16777215 linkset as-client61-norctx
+ listen m3ua 2905
+ local-ip 127.0.0.1
+ local-ip ::1
+ accept-asp-connections dynamic-permitted
!
! IPA AS/ASP:
!
@@ -124,77 +192,9 @@
!
!M3UA AS/ASP:
!
- asp asp-sender 9999 2905 m3ua
- local-ip 127.0.0.1
- local-ip ::1
- remote-ip 127.0.0.1
- remote-ip ::1
- role sg
- sctp-role server
- asp asp-receiver0 10000 2905 m3ua
- local-ip 127.0.0.1
- local-ip ::1
- remote-ip 127.0.0.1
- remote-ip ::1
- role sg
- sctp-role server
- asp asp-receiver1 10001 2905 m3ua
- local-ip 127.0.0.1
- local-ip ::1
- remote-ip 127.0.0.1
- remote-ip ::1
- role sg
- sctp-role server
- asp asp-client0 10002 2906 m3ua
- local-ip 127.0.0.1
- local-ip ::1
- remote-ip 127.0.0.1
- remote-ip ::1
- role asp
- sctp-role client
- asp asp-client60-norctx0 11060 2907 m3ua
- local-ip 127.0.0.1
- local-ip ::1
- remote-ip 127.0.0.1
- remote-ip ::1
- role asp
- sctp-role client
- asp asp-client61-norctx0 11061 2907 m3ua
- local-ip 127.0.0.1
- local-ip ::1
- remote-ip 127.0.0.1
- remote-ip ::1
- role asp
- sctp-role client
- as as-sender m3ua
- asp asp-sender
- routing-key 1023 23
- as as-receiver m3ua
- asp asp-receiver0
- asp asp-receiver1
- routing-key 1042 42
- as as-client m3ua
- routing-key 1055 55
- asp asp-client0
- as as-client60-norctx m3ua
- routing-key 0 60
- asp asp-client60-norctx0
- as as-client61-norctx m3ua
- routing-key 0 61
- asp asp-client61-norctx0
!
! ROUTING TABLE:
!
- route-table system
- update route 23 16777215 linkset as-sender
- update route 42 16777215 linkset as-receiver
- update route 55 16777215 linkset as-client
- update route 60 16777215 linkset as-client60-norctx
- update route 61 16777215 linkset as-client61-norctx
!
!SERVERS:
!
- listen m3ua 2905
- local-ip 127.0.0.1
- local-ip ::1
- accept-asp-connections dynamic-permitted
diff --git a/tests/osmo-config-merge/testB2.ok b/tests/osmo-config-merge/testB2.ok
index 6a44388..e206e74 100644
--- a/tests/osmo-config-merge/testB2.ok
+++ b/tests/osmo-config-merge/testB2.ok
@@ -1,37 +1,4 @@
!
- asp ipa-asp-loadshare-sender0 20000 5000 ipa
- local-ip 127.0.0.1
- remote-ip 127.0.0.1
- asp ipa-asp-loadshare-sender1 20001 5000 ipa
- local-ip 127.0.0.1
- remote-ip 127.0.0.1
- as ipa-as-loadshare-sender ipa
- routing-key 0 6
- point-code override dpc 31
- asp ipa-asp-loadshare-sender0
- asp ipa-asp-loadshare-sender1
- asp ipa-asp-loadshare-receiver0 20002 5000 ipa
- local-ip 127.0.0.1
- remote-ip 127.0.0.1
- role sg
- sctp-role server
- asp ipa-asp-loadshare-receiver1 20003 5000 ipa
- local-ip 127.0.0.1
- remote-ip 127.0.0.1
- role sg
- sctp-role server
- as ipa-as-loadshare-receiver ipa
- traffic-mode loadshare
- routing-key 0 7
- point-code override dpc 32
- asp ipa-asp-loadshare-receiver0
- asp ipa-asp-loadshare-receiver1
- route-table system
- update route 31 16777215 linkset ipa-as-loadshare-receiver
- update route 33 16777215 linkset ipa-as-override-receiver
- update route 5 16777215 linkset ipa-as-dynamic-asp
- listen ipa 5000
- accept-asp-connections dynamic-permitted
! OsmoSTP (1.1.0.2-3884) configuration saved from vty
!!
!
@@ -80,13 +47,13 @@
route-table system
update route 123 16777215 linkset as-sender-tcp
update route 155 16777215 linkset as-client-tcp
+ update route 31 16777215 linkset ipa-as-loadshare-receiver
+ update route 33 16777215 linkset ipa-as-override-receiver
+ update route 5 16777215 linkset ipa-as-dynamic-asp
listen m3ua 2905 tcp
local-ip 127.0.0.1
local-ip ::1
accept-asp-connections dynamic-permitted
-!
-!M3UA AS/ASP:
-!
asp asp-sender 9999 2905 m3ua
local-ip 127.0.0.1
local-ip ::1
@@ -145,27 +112,43 @@
as as-client61-norctx m3ua
routing-key 0 61
asp asp-client61-norctx0
-!
-! ROUTING TABLE:
-!
route-table system
update route 23 16777215 linkset as-sender
update route 42 16777215 linkset as-receiver
update route 55 16777215 linkset as-client
update route 60 16777215 linkset as-client60-norctx
update route 61 16777215 linkset as-client61-norctx
-!
-!SERVERS:
-!
listen m3ua 2905
local-ip 127.0.0.1
local-ip ::1
accept-asp-connections dynamic-permitted
-cs7 instance 0
-!
-! IPA AS/ASP:
-! Port 2004 is reserved for use with ipa-as-dynamic-asp in TTCN-3.
-! OVERRIDE:
+ asp ipa-asp-loadshare-sender0 20000 5000 ipa
+ local-ip 127.0.0.1
+ remote-ip 127.0.0.1
+ asp ipa-asp-loadshare-sender1 20001 5000 ipa
+ local-ip 127.0.0.1
+ remote-ip 127.0.0.1
+ as ipa-as-loadshare-sender ipa
+ routing-key 0 6
+ point-code override dpc 31
+ asp ipa-asp-loadshare-sender0
+ asp ipa-asp-loadshare-sender1
+ asp ipa-asp-loadshare-receiver0 20002 5000 ipa
+ local-ip 127.0.0.1
+ remote-ip 127.0.0.1
+ role sg
+ sctp-role server
+ asp ipa-asp-loadshare-receiver1 20003 5000 ipa
+ local-ip 127.0.0.1
+ remote-ip 127.0.0.1
+ role sg
+ sctp-role server
+ as ipa-as-loadshare-receiver ipa
+ traffic-mode loadshare
+ routing-key 0 7
+ point-code override dpc 32
+ asp ipa-asp-loadshare-receiver0
+ asp ipa-asp-loadshare-receiver1
asp ipa-asp-override-sender 20005 5000 ipa
local-ip 127.0.0.1
remote-ip 127.0.0.1
@@ -189,11 +172,29 @@
point-code override dpc 34
asp ipa-asp-override-receiver0
asp ipa-asp-override-receiver1
-! DYNAMIC AS:
as ipa-as-dynamic-asp ipa
routing-key 0 5
point-code override dpc 23
+ listen ipa 5000
+ accept-asp-connections dynamic-permitted
+!
+!M3UA AS/ASP:
+!
!
! ROUTING TABLE:
!
+!
!SERVERS:
+!
+!
+! IPA AS/ASP:
+!
+! Port 2004 is reserved for use with ipa-as-dynamic-asp in TTCN-3.
+! OVERRIDE:
+! DYNAMIC AS:
+!
+! ROUTING TABLE:
+!
+!
+!SERVERS:
+!
diff --git a/utils/osmo-config-merge.c b/utils/osmo-config-merge.c
index ed2039a..f7db945 100644
--- a/utils/osmo-config-merge.c
+++ b/utils/osmo-config-merge.c
@@ -39,6 +39,7 @@
*/

#include <stdio.h>
+#include <stdbool.h>
#include <string.h>
#include <errno.h>

@@ -89,16 +90,35 @@
return NULL;
}

+/* Return pointer to line content, or empty string if only whitspace is found */
+static const char *line_lstrip(const char *line)
+{
+ OSMO_ASSERT(line);
+ unsigned int len = strlen(line);
+ for (unsigned int i = 0; i < len; i++) {
+ if (line[i] == ' ')
+ continue;
+ return &line[i];
+ }
+ /* points to empty string '\0' */
+ return &line[len];
+}
+
/* count the number of spaces / indent level */
static int count_indent(const char *line)
{
- int i;
+ const char *content = line_lstrip(line);
+ return content - line;
+}

- for (i = 0; i < strlen(line); i++) {
- if (line[i] != ' ')
- return i;
- }
- return i;
+static bool line_is_comment(const char *line)
+{
+ const char *content = line_lstrip(line);
+ if (content[0] == '\0')
+ return true;
+ if (content[0] == '!' || line[0] == '#')
+ return true;
+ return false;
}

/* strip any triling CR / LF */
@@ -141,7 +161,9 @@
line_num++;
chomp(line);
int indent = count_indent(line);
+ bool coment = line_is_comment(&line[indent]);
struct node *n;
+
if (indent > cur_indent) {
if (indent > cur_indent+1) {
fprintf(stderr, "File '%s' isn't well-formed in line %u, aborting!\n",
@@ -153,20 +175,25 @@
n = node_alloc_child(last);
} else if (indent < cur_indent) {
int i;
+ struct node *par = last;
for (i = 0; i < cur_indent - indent; i++) {
/* go to parent, add another sibling */
- if (last->parent)
- last = last->parent;
+ if (par->parent)
+ par = par->parent;
}
- n = node_alloc_child(last->parent);
+ n = node_alloc_child(par->parent);
} else {
/* add a new sibling (child of parent) */
n = node_alloc_child(last->parent);
}
n->line = talloc_strdup(n, line);

- last = n;
- cur_indent = indent;
+ /* comments are not part of the indentation structure of the
+ * file, hence commands after it are not to be affected by them: */
+ if (!coment) {
+ last = n;
+ cur_indent = indent;
+ }
}

fclose(infile);

To view, visit change 40296. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-MessageType: merged
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I7de78d3ed3ca27e3470ea66a78ff9c5acfe65741
Gerrit-Change-Number: 40296
Gerrit-PatchSet: 5
Gerrit-Owner: pespin <pespin@sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge@osmocom.org>
Gerrit-Reviewer: osmith <osmith@sysmocom.de>
Gerrit-Reviewer: pespin <pespin@sysmocom.de>