lists.osmocom.org
Sign In Sign Up
Manage this list Sign In Sign Up

Keyboard Shortcuts

Thread View

  • j: Next unread message
  • k: Previous unread message
  • j a: Jump to all threads
  • j l: Jump to MailingList overview

gerrit-log

Thread Start a new thread
Download
Threads by month
  • ----- 2026 -----
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2025 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2024 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2023 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2022 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
gerrit-log@lists.osmocom.org

August 2022

  • 3 participants
  • 2402 discussions
Change in osmo-upf[master]: improve manual: PFCP and GTP interfaces
by neels 24 Aug '22

24 Aug '22
neels has submitted this change. ( https://gerrit.osmocom.org/c/osmo-upf/+/29143 ) Change subject: improve manual: PFCP and GTP interfaces ...................................................................... improve manual: PFCP and GTP interfaces Related: SYS#5599 Change-Id: Iccb3f0f52bd5006bc94d0ca06ac5d3271ea89eb9 --- M doc/manuals/chapters/overview.adoc A doc/manuals/chapters/running.adoc 2 files changed, 208 insertions(+), 0 deletions(-) Approvals: fixeria: Looks good to me, but someone else must approve laforge: Looks good to me, approved Jenkins Builder: Verified diff --git a/doc/manuals/chapters/overview.adoc b/doc/manuals/chapters/overview.adoc index 2b9b547..9cd7751 100644 --- a/doc/manuals/chapters/overview.adoc +++ b/doc/manuals/chapters/overview.adoc @@ -22,3 +22,160 @@ - 1000 modifications of tunnel state per second (add/remove/modify), - 4-8 Gbps throughput, - 100-125k concurrent GTP tunnels. + +A typical network scenario using OsmoUPF is illustrated in the following +diagram: + +.Typical network architecture used with OsmoUPF +[graphviz] +---- +digraph G { + rankdir = LR; + + UE [label="UE\n(3G phone)"] + + subgraph cluster_hnbgw_mgw_upf { + style=dotted + HNBGW -> UPF [label="PFCP",constraint=false] + UPF [label=OsmoUPF,style=bold] + } + + subgraph cluster_hnbgw_mgw_upf2 { + style=dotted + SGSN -> UPF2 [label="PFCP",constraint=false] + UPF2 [label=OsmoUPF,style=bold] + } + + subgraph cluster_hnbgw_mgw_upf3 { + style=dotted + GGSN -> UPF3 [label="PFCP",constraint=false] + UPF3 [label=OsmoUPF,style=bold] + } + + hNodeB [shape="box",label="hNodeB\n(3G femto cell)"] + + UE -> hNodeB [label="Uu"] + hNodeB -> HNBGW [label="Iuh",style=dashed] + STP [label="STP\n(SCCP/M3UA)"] + HNBGW -> STP -> SGSN [label="IuPS",style=dashed] + SGSN -> GGSN [label="GTP-C",style="dashed"] + hNodeB -> UPF -> UPF2 -> UPF3 [label="GTP-U"] + UPF3 -> internet [label="apn"] +} +---- + +NOTE: at the time of writing this section, the only Osmocom component providing +a PFCP CPF interface is OsmoHNBGW. PFCP support has not yet made its way into +OsmoSGSN nor OsmoGGSN. + +=== the PFCP interface + +PFCP is specified by 3GPP TS 29.244. + +OsmoUPF implements a PFCP User Plane Function interface, listening for PFCP +requests from PFCP Control Plane Function clients, to carry out proxy-relaying +and encapsulation/decapsulation of GTP tunnels. + +OsmoUPF does not support the complete PFCP feature set. It detects exactly two +use cases that will provide service of actual GTP tunnels: + +* GTP tunnel encapsulation/decapsulation: + - One Packet Detection Rule (PDR) accepts a GTP tunnel from the Access side + with an Outer Header Removal. + - This PDR uses a Forwarding Action Rule (FAR) for plain IP towards Core. + - Another PDR accepts plain IP on a specific IP address from Core. + - The second PDR uses a FAR towards Access with Outer Header Creation for GTP. + +* GTP tunnel forwarding: + - One Packet Detection Rule (PDR) accepts a GTP tunnel from the Access side + with an Outer Header Removal. + - This PDR uses a Forwarding Action Rule (FAR) towards Core with an Outer + Header Creation for GTP. + - A second PDR+FAR pair like above, with Access and Core swapped. + +Any set of rules only partially or not at all matching the above PDR and FAR +rules will not result in any actions on the GTP user plane, but will still +return a successful outcome in the PFCP messages. + +For example, a rule set using an interface other than "Access" or "Core" results +in a PFCP no-op, returning PFCP responses with successful outcome, but not +providing any GTP-U service. + +This is a direct result of: + +- allowing PFCP rule sets to be setup incrementally by several subsequent PFCP + messages, and of +- OsmoUPF using Linux kernel features for the GTP user plane, where there is + either a full bidirectional GTP tunnel in place or none at all. + +For example, a typical CPF will first establish a PFCP session with the UPF +before passing on a data service request from Access to Core, because the UPF +must first choose the GTP TEID that needs to be forwarded towards Core. When the +Core side has responded with its GTP details, the UPF is updated, to form a +complete PFCP rule set. + +.Typical sequence of establishing a GTP-U tunnel relay +["mscgen"] +---- +msc { + hscale="1"; + sgsn[label="SGSN"],sgwc[label="SGW-C"],sgwu[label="SGW-U"],pgwc[label="PGW-C"]; + + sgsn << pgwc [label="Access"]; + sgsn >> pgwc [label="Core"]; + + sgsn => sgwc [label="GTP Create Session Request\n\n\n"]; + + |||; + + sgwc => sgwu [label="PFCP Session Establishment Request\n\n2x Create PDR\nF-TEID = CHOOSE"]; + + |||; + + sgwc <= sgwu [label="PFCP Session Establishment Response\n\n2x Created PDR\nwith chosen F-TEID"]; + + |||; + + sgwc => pgwc [label="GTP Create Session Request"]; + sgwc <= pgwc [label="GTP Create Session Response"]; + + |||; + + sgwc => sgwu [label="PFCP Session Modification Request\n\nUpdate FAR\nwith F-TEID from Core"]; + + |||; + + sgwc <= sgwu [label="PFCP Session Modification Response\n\n\n"]; + + |||; + + sgsn <= sgwc [label="GTP Create Session Response\n\n\n"]; +} +---- + +The OsmoUPF logging as well as the VTY interface yield information on whether a +ruleset results in an actual bidirectional GTP tunnel being set up. + + +=== the GTP interface + +OsmoUPF requires the following Linux kernel features to provide the GTP user +plane functionality: + +- the Linux kernel GTP module for encapsulation/decapsulation between GTP and + plain IP. +- the Linux netfilter nftables feature for relaying GTP, i.e. forwarding between + two GTP tunnels. + +Tunnel relaying with netfilter requires at least Linux kernel 5.17. + +To be able to interact with these Linux kernel features, the osmo-upf binary +needs cap_net_admin privileges, as in: + +---- +sudo setcap cap_net_admin+pe /usr/bin/osmo-upf +---- + +Without above Linux kernel features, or when no cap_net_admin is available, +OsmoUPF is only useful for testing PFCP clients: the GTP features may be run in +mockup mode, so that OsmoUPF serves as a "dry run" PFCP server. diff --git a/doc/manuals/chapters/running.adoc b/doc/manuals/chapters/running.adoc new file mode 100644 index 0000000..6a6afd4 --- /dev/null +++ b/doc/manuals/chapters/running.adoc @@ -0,0 +1,51 @@ +== Running OsmoUPF + +The OsmoUPF executable (`osmo-upf`) offers the following command-line +arguments: + +=== SYNOPSIS + +*osmo-upf* [-h|-V] [-D] [-c 'CONFIGFILE'] + +=== OPTIONS + +*-h, --help*:: + Print a short help message about the supported options +*-V, --version*:: + Print the compile-time version number of the OsmoHNBGW program +*-D, --daemonize*:: + Fork the process as a daemon into background. +*-c, --config-file 'CONFIGFILE'*:: + Specify the file and path name of the configuration file to be + used. If none is specified, use `osmo-upf.cfg` in the current + working directory. + +=== Multiple instances + +Running multiple instances of `osmo-upf` on the same computer is possible if +all interfaces (VTY, CTRL, PFCP) are separated using the appropriate +configuration options. The IP based interfaces are binding to local host by +default. In order to separate the processes, the user has to bind those +services to different ports, or different specific IP addresses. + +The VTY and the Control interface can be bound to IP addresses from the loopback +address range, for example: + +---- +line vty + bind 127.0.0.2 +ctrl + bind 127.0.0.2 +---- + +The PFCP port is specified to be fixed as port 8805. Hence, each osmo-upf +process needs to run on a distinct local interface: + +---- +pfcp + local-addr 10.9.0.2 +---- + +For GTP encapsulation/decapsulation and GTP tunnel relaying, osmo-upf depends on +the IP addresses configured at the Linux kernel GTP module, and the IP addresses +negotiated within PFCP by the control plane function. -- To view, visit https://gerrit.osmocom.org/c/osmo-upf/+/29143 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: osmo-upf Gerrit-Branch: master Gerrit-Change-Id: Iccb3f0f52bd5006bc94d0ca06ac5d3271ea89eb9 Gerrit-Change-Number: 29143 Gerrit-PatchSet: 5 Gerrit-Owner: neels <nhofmeyr(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: neels <nhofmeyr(a)sysmocom.de> Gerrit-MessageType: merged
1 0
0 0
Change in libosmo-pfcp[master]: gtlv: fix repeated IEIs to several struct members
by neels 24 Aug '22

24 Aug '22
neels has submitted this change. ( https://gerrit.osmocom.org/c/libosmo-pfcp/+/29042 ) Change subject: gtlv: fix repeated IEIs to several struct members ...................................................................... gtlv: fix repeated IEIs to several struct members Coverity Scan has brought my attention to a problem with decoding repeated IEIs, where there are multiple struct members in the decoded struct that these are decoded to. Before this patch, gtlv aborts with an error as soon as the first struct member for a given tag is full, not parsing following IEIs into subsequent struct members. After this patch, gtlv continues to look whether subsequent entries in the message coding also decode the same tag, but to a different struct member. First commit without changing the gtlv regression test, to show that all current tests still succeed. The test for this particular issue follow in I994d0fb1f1435d2c27a8630a43fe106652ac6e41 Related: CID#275415 Related: SYS#5599 Change-Id: Ie37585178ff27306d425b75d8e407b71f92f1cdc --- M src/libosmo-gtlv/gtlv_dec_enc.c 1 file changed, 70 insertions(+), 20 deletions(-) diff --git a/src/libosmo-gtlv/gtlv_dec_enc.c b/src/libosmo-gtlv/gtlv_dec_enc.c index 58c0405..385ebfa 100644 --- a/src/libosmo-gtlv/gtlv_dec_enc.c +++ b/src/libosmo-gtlv/gtlv_dec_enc.c @@ -127,16 +127,19 @@ * that can store them are filled up. */ ie_max_allowed_count = 0; + /* Unordered: for every tag, look for matching IE definitions from the start. */ + iec = ie_coding; + /* There may be multiple subsequent occurences of the same tag, to be decoded into multiple members of + * the decoded struct. Iterate until encountering a still "free slot" for decoding. */ do { /* Find the IE coding for this tag */ - for (iec = ie_coding; - !osmo_gtlv_coding_end(iec) && osmo_gtlv_tag_inst_cmp(&iec->ti, &gtlv->ti); + for (; !osmo_gtlv_coding_end(iec) && osmo_gtlv_tag_inst_cmp(&iec->ti, &gtlv->ti); iec++); /* No such IE coding found. */ if (osmo_gtlv_coding_end(iec)) break; - /* Keep track how often this tag can occur */ + /* Keep track how often this tag can occur in total */ ie_max_allowed_count += iec->has_count ? iec->count_max : 1; /* Was this iec instance already decoded? Then skip to the next one, if any. */ @@ -145,23 +148,35 @@ multi_count_p = iec->has_count ? membof(obj, obj_maxlen, iec->count_ofs) : NULL; if ((presence_flag_p && *presence_flag_p) - || (multi_count_p && *multi_count_p >= iec->count_max)) + || (multi_count_p && *multi_count_p >= iec->count_max)) { + iec++; continue; + } + /* For IEs with a presence flag or a multi count, the decoded struct provides the information * whether the IE has already been decoded. Do the same for mandatory IEs, using local state in * seen_ie_coding_entries[]. */ - CHECK_SEEN(iec); - if (*seen_p) - continue; - } while (0); + if (!presence_flag_p && !multi_count_p) { + CHECK_SEEN(iec); + if (*seen_p) { + iec++; + continue; + } + } + + /* Found an IE coding that has not yet been decoded / still has unused struct members to decode + * to. */ + break; + } while (1); + if (osmo_gtlv_coding_end(iec)) { if (ie_max_allowed_count) { - /* There have been IE definitions for this IEI, but all slots to decode it are already - * filled. */ + /* This tag exists in the protocol definitions, but we've run out of struct members to + * decode the tag to. */ RETURN_ERROR(-ENOTSUP, gtlv->ti, "Only %u instances of this IE are supported per message", ie_max_allowed_count); } - /* No such IE defined in ie_coding, just skip the TLV. */ + /* This is an unknown tag, no such IEI defined in ie_coding, just skip the TLV. */ continue; } @@ -264,14 +279,22 @@ osmo_gtlv_load_start(gtlv); + /* Ordered: traverse the ie_coding exactly once, expecting tags to be decoded to appear in the same order. */ for (; !osmo_gtlv_coding_end(ie_coding); ie_coding++) { int rc; - bool *presence_flag = ie_coding->has_presence_flag ? - membof(obj, obj_maxlen, ie_coding->presence_flag_ofs) : NULL; - unsigned int *multi_count = ie_coding->has_count ? - membof(obj, obj_maxlen, ie_coding->count_ofs) : NULL; + bool *presence_flag; + unsigned int *multi_count; struct osmo_gtlv_tag_inst peek_ti; +#define UPDATE_STATE_FROM_IE_CODING() do { \ + presence_flag = ie_coding->has_presence_flag ? \ + membof(obj, obj_maxlen, ie_coding->presence_flag_ofs) : NULL; \ + multi_count = ie_coding->has_count ? \ + membof(obj, obj_maxlen, ie_coding->count_ofs) : NULL; \ + } while (0) + + UPDATE_STATE_FROM_IE_CODING(); + rc = osmo_gtlv_load_next_by_tag_inst(gtlv, &ie_coding->ti); switch (rc) { case 0: @@ -289,12 +312,39 @@ for (;;) { /* If this is a repeated IE, decode into the correct array index memb[idx], * next idx == (*multi_count) */ - unsigned int memb_next_array_idx = multi_count ? *multi_count : 0; - unsigned int memb_ofs = ie_coding->memb_ofs + memb_next_array_idx * ie_coding->memb_array_pitch; + unsigned int memb_next_array_idx; + unsigned int memb_ofs; - if (multi_count && memb_next_array_idx >= ie_coding->count_max) - RETURN_ERROR(-ENOTSUP, ie_coding->ti, "Only %u instances of this IE are supported per message", - ie_coding->count_max); +#define UPDATE_MEMB_IDX() do { \ + memb_next_array_idx = multi_count ? *multi_count : 0; \ + memb_ofs = ie_coding->memb_ofs + memb_next_array_idx * ie_coding->memb_array_pitch; \ + } while (0) + + UPDATE_MEMB_IDX(); + + if (multi_count && memb_next_array_idx >= ie_coding->count_max) { + /* This repeated IE is full. But the protocol may define this same IEI to follow again, + * with a different target struct member. See if this IEI appears again. */ + const struct osmo_gtlv_coding *iec = ie_coding; + bool iei_appears_again = false; + for (iec = ie_coding + 1; !osmo_gtlv_coding_end(iec); iec++) { + if (osmo_gtlv_tag_inst_cmp(&gtlv->ti, &iec->ti) == 0) { + iei_appears_again = true; + break; + } + } + + if (!iei_appears_again) + RETURN_ERROR(-ENOTSUP, ie_coding->ti, "Only %u instances of this IE are supported per message", + ie_coding->count_max); + + /* IEI does appear again. Skip forward to this ie_coding, and use that to decode the + * current TLV (do not call osmo_gtlv_load_next_by_tag_inst() again, or we'd skip the + * TLV in the message being decoded). */ + ie_coding = iec; + UPDATE_STATE_FROM_IE_CODING(); + UPDATE_MEMB_IDX(); + } /* Decode IE value part */ if (ie_coding->nested_ies) { null-- To view, visit https://gerrit.osmocom.org/c/libosmo-pfcp/+/29042 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmo-pfcp Gerrit-Branch: master Gerrit-Change-Id: Ie37585178ff27306d425b75d8e407b71f92f1cdc Gerrit-Change-Number: 29042 Gerrit-PatchSet: 5 Gerrit-Owner: neels <nhofmeyr(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-CC: pespin <pespin(a)sysmocom.de> Gerrit-MessageType: merged
1 0
0 0
Change in libosmo-pfcp[master]: gtlv: test repeated IEIs to several struct members
by neels 24 Aug '22

24 Aug '22
neels has submitted this change. ( https://gerrit.osmocom.org/c/libosmo-pfcp/+/29043 ) Change subject: gtlv: test repeated IEIs to several struct members ...................................................................... gtlv: test repeated IEIs to several struct members Test the behavior fixed by Ie37585178ff27306d425b75d8e407b71f92f1cdc Related: CID#275415 Related: SYS#5599 Change-Id: I994d0fb1f1435d2c27a8630a43fe106652ac6e41 --- M tests/libosmo-gtlv/gtlv_dec_enc_test.c M tests/libosmo-gtlv/gtlv_dec_enc_test.ok 2 files changed, 380 insertions(+), 47 deletions(-) Approvals: pespin: Looks good to me, but someone else must approve laforge: Looks good to me, approved diff --git a/tests/libosmo-gtlv/gtlv_dec_enc_test.c b/tests/libosmo-gtlv/gtlv_dec_enc_test.c index f0de7b0..848c0ef 100644 --- a/tests/libosmo-gtlv/gtlv_dec_enc_test.c +++ b/tests/libosmo-gtlv/gtlv_dec_enc_test.c @@ -94,7 +94,13 @@ struct baz baz; unsigned int repeat_int_count; - int repeat_int[32]; + int repeat_int[3]; + + unsigned int repeat_int2_count; + int repeat_int2[2]; + + bool repeat_int3_present; + unsigned int repeat_int3; unsigned int repeat_struct_count; struct repeat repeat_struct[32]; @@ -264,6 +270,26 @@ .count_max = ARRAY_SIZE(((struct decoded_msg *)0)->repeat_int), }, { + .ti = { TAG_REPEAT_INT }, + .dec_func = dec_u16, + .enc_func = enc_u16, + .enc_to_str_func = enc_to_str_u16, + .memb_ofs = offsetof(struct decoded_msg, repeat_int2), + .memb_array_pitch = OSMO_MEMB_ARRAY_PITCH(struct decoded_msg, repeat_int2), + .has_count = true, + .count_ofs = offsetof(struct decoded_msg, repeat_int2_count), + .count_max = ARRAY_SIZE(((struct decoded_msg *)0)->repeat_int2), + }, + { + .ti = { TAG_REPEAT_INT }, + .dec_func = dec_u16, + .enc_func = enc_u16, + .enc_to_str_func = enc_to_str_u16, + .memb_ofs = offsetof(struct decoded_msg, repeat_int3), + .has_presence_flag = true, + .presence_flag_ofs = offsetof(struct decoded_msg, repeat_int3_present), + }, + { .ti = { TAG_REPEAT_STRUCT }, .dec_func = dec_repeat_struct, .enc_func = enc_repeat_struct, @@ -284,11 +310,88 @@ {} }; -char *decoded_msg_to_str(const struct decoded_msg *m) -{ - return osmo_gtlvs_encode_to_str_c(ctx, m, sizeof(*m), 0, msg_ie_coding, tag_names); -} +/* Same as msg_ie_coding, but with different ordering of the REPEAT_INT IEIs: in msg_ie_coding, the three separate + * REPEAT_INT tags follow directly after each other, while in msg_ie_coding2, other tags appear in-between. */ +struct osmo_gtlv_coding msg_ie_coding2[] = { + { + .ti = { TAG_FOO }, + .dec_func = dec_u16, + .enc_func = enc_u16, + .enc_to_str_func = enc_to_str_u16, + .memb_ofs = offsetof(struct decoded_msg, foo), + }, + { + .ti = { TAG_BAR }, + .dec_func = dec_bar, + .enc_func = enc_bar, + .enc_to_str_func = enc_to_str_bar, + .memb_ofs = offsetof(struct decoded_msg, bar), + }, + { + .ti = { TAG_BAZ }, + .dec_func = dec_baz, + .enc_func = enc_baz, + .enc_to_str_func = enc_to_str_baz, + .memb_ofs = offsetof(struct decoded_msg, baz), + .has_presence_flag = true, + .presence_flag_ofs = offsetof(struct decoded_msg, baz_present), + }, + { + .ti = { TAG_REPEAT_INT }, + .dec_func = dec_u16, + .enc_func = enc_u16, + .enc_to_str_func = enc_to_str_u16, + .memb_ofs = offsetof(struct decoded_msg, repeat_int), + .memb_array_pitch = OSMO_MEMB_ARRAY_PITCH(struct decoded_msg, repeat_int), + .has_count = true, + .count_ofs = offsetof(struct decoded_msg, repeat_int_count), + .count_max = ARRAY_SIZE(((struct decoded_msg *)0)->repeat_int), + }, + { + .ti = { TAG_REPEAT_STRUCT }, + .dec_func = dec_repeat_struct, + .enc_func = enc_repeat_struct, + .enc_to_str_func = enc_to_str_repeat_struct, + .memb_ofs = offsetof(struct decoded_msg, repeat_struct), + .memb_array_pitch = OSMO_MEMB_ARRAY_PITCH(struct decoded_msg, repeat_struct), + .has_count = true, + .count_ofs = offsetof(struct decoded_msg, repeat_struct_count), + .count_max = ARRAY_SIZE(((struct decoded_msg *)0)->repeat_struct), + }, + { + .ti = { TAG_REPEAT_INT }, + .dec_func = dec_u16, + .enc_func = enc_u16, + .enc_to_str_func = enc_to_str_u16, + .memb_ofs = offsetof(struct decoded_msg, repeat_int2), + .memb_array_pitch = OSMO_MEMB_ARRAY_PITCH(struct decoded_msg, repeat_int2), + .has_count = true, + .count_ofs = offsetof(struct decoded_msg, repeat_int2_count), + .count_max = ARRAY_SIZE(((struct decoded_msg *)0)->repeat_int2), + }, + { + .ti = { TAG_NEST }, + .memb_ofs = offsetof(struct decoded_msg, nest), + .nested_ies = nested_inner_msg_ies, + .has_presence_flag = true, + .presence_flag_ofs = offsetof(struct decoded_msg, nest_present), + }, + { + .ti = { TAG_REPEAT_INT }, + .dec_func = dec_u16, + .enc_func = enc_u16, + .enc_to_str_func = enc_to_str_u16, + .memb_ofs = offsetof(struct decoded_msg, repeat_int3), + .has_presence_flag = true, + .presence_flag_ofs = offsetof(struct decoded_msg, repeat_int3_present), + }, + {} +}; +char *decoded_msg_to_str(const struct decoded_msg *m, const struct osmo_gtlv_coding *iec) +{ + return osmo_gtlvs_encode_to_str_c(ctx, m, sizeof(*m), 0, iec, tag_names); +} const struct decoded_msg enc_dec_tests[] = { { @@ -322,6 +425,38 @@ .foo = 23, .bar = { "twentythree" }, + .repeat_int_count = 3, + .repeat_int = { 1, 2, 0x7fff }, + + .repeat_struct_count = 1, + .repeat_struct = { + { + .v_int = 1001, + .v_bool = true, + .v_enum = R_A, + }, + }, + + .repeat_int2_count = 2, + .repeat_int2 = { 23, 42 }, + + .nest_present = true, + .nest = { + .foo = 42, + .bar = { "fortytwo" }, + .baz = { + .v_int = 4242, + .v_bool = false, + }, + }, + + .repeat_int3_present = true, + .repeat_int3 = 423, + }, + { + .foo = 23, + .bar = { "twentythree" }, + .baz_present = true, .baz = { .v_int = 2323, @@ -370,7 +505,7 @@ va_end(args); } -void test_enc_dec(const char *label, const struct osmo_gtlv_cfg *cfg, bool ordered) +void test_enc_dec(const char *label, const struct osmo_gtlv_cfg *cfg, const struct osmo_gtlv_coding *iec, bool ordered) { int i; for (i = 0; i < ARRAY_SIZE(enc_dec_tests); i++) { @@ -381,13 +516,13 @@ struct osmo_gtlv_put put; printf("\n=== start %s %s[%d]\n", label, __func__, i); - printf("encoded: %s\n", decoded_msg_to_str(orig)); + printf("encoded: %s\n", decoded_msg_to_str(orig, iec)); put = (struct osmo_gtlv_put){ .cfg = cfg, .dst = msgb_alloc(1024, __func__), }; - rc = osmo_gtlvs_encode(&put, (void *)orig, sizeof(*orig), 0, msg_ie_coding, + rc = osmo_gtlvs_encode(&put, (void *)orig, sizeof(*orig), 0, iec, err_cb, &verify_err_cb_data, tag_names); printf("osmo_gtlvs_encode() rc = %d\n", rc); printf("%s.\n", osmo_hexdump(put.dst->data, put.dst->len)); @@ -396,11 +531,11 @@ .cfg = cfg, .src = { put.dst->data, put.dst->len }, }; - rc = osmo_gtlvs_decode(&parsed, sizeof(parsed), 0, &load, ordered, msg_ie_coding, + rc = osmo_gtlvs_decode(&parsed, sizeof(parsed), 0, &load, ordered, iec, err_cb, &verify_err_cb_data, tag_names); printf("osmo_gtlvs_decode() rc = %d\n", rc); - printf("decoded: %s\n", decoded_msg_to_str(&parsed)); - if (strcmp(decoded_msg_to_str(orig), decoded_msg_to_str(&parsed))) { + printf("decoded: %s\n", decoded_msg_to_str(&parsed, iec)); + if (strcmp(decoded_msg_to_str(orig, iec), decoded_msg_to_str(&parsed, iec))) { printf(" ERROR: parsed != orig\n"); exit(1); } @@ -413,11 +548,17 @@ ctx = talloc_named_const(NULL, 0, "gtlv_test"); msgb_talloc_ctx_init(ctx, 0); - test_enc_dec("t8l8v ordered", &osmo_t8l8v_cfg, true); - test_enc_dec("t8l8v unordered", &osmo_t8l8v_cfg, false); + test_enc_dec("1: t8l8v ordered", &osmo_t8l8v_cfg, msg_ie_coding, true); + test_enc_dec("1: t8l8v unordered", &osmo_t8l8v_cfg, msg_ie_coding, false); - test_enc_dec("t16l16v ordered", &osmo_t16l16v_cfg, true); - test_enc_dec("t16l16v unordered", &osmo_t16l16v_cfg, false); + test_enc_dec("1: t16l16v ordered", &osmo_t16l16v_cfg, msg_ie_coding, true); + test_enc_dec("1: t16l16v unordered", &osmo_t16l16v_cfg, msg_ie_coding, false); + + test_enc_dec("2: t8l8v ordered", &osmo_t8l8v_cfg, msg_ie_coding2, true); + test_enc_dec("2: t8l8v unordered", &osmo_t8l8v_cfg, msg_ie_coding2, false); + + test_enc_dec("2: t16l16v ordered", &osmo_t16l16v_cfg, msg_ie_coding2, true); + test_enc_dec("2: t16l16v unordered", &osmo_t16l16v_cfg, msg_ie_coding2, false); talloc_free(ctx); return 0; diff --git a/tests/libosmo-gtlv/gtlv_dec_enc_test.ok b/tests/libosmo-gtlv/gtlv_dec_enc_test.ok index bd6df52..b6a2d7f 100644 --- a/tests/libosmo-gtlv/gtlv_dec_enc_test.ok +++ b/tests/libosmo-gtlv/gtlv_dec_enc_test.ok @@ -1,128 +1,320 @@ -=== start t8l8v ordered test_enc_dec[0] +=== start 1: t8l8v ordered test_enc_dec[0] encoded: 'FOO'=23 'BAR'="twentythree" osmo_gtlvs_encode() rc = 0 01 02 00 17 02 0b 74 77 65 6e 74 79 74 68 72 65 65 . osmo_gtlvs_decode() rc = 0 decoded: 'FOO'=23 'BAR'="twentythree" -=== end t8l8v ordered test_enc_dec[0] +=== end 1: t8l8v ordered test_enc_dec[0] -=== start t8l8v ordered test_enc_dec[1] +=== start 1: t8l8v ordered test_enc_dec[1] encoded: 'FOO'=23 'BAR'="twentythree" 'BAZ'={2323,true} osmo_gtlvs_encode() rc = 0 01 02 00 17 02 0b 74 77 65 6e 74 79 74 68 72 65 65 03 02 89 13 . osmo_gtlvs_decode() rc = 0 decoded: 'FOO'=23 'BAR'="twentythree" 'BAZ'={2323,true} -=== end t8l8v ordered test_enc_dec[1] +=== end 1: t8l8v ordered test_enc_dec[1] -=== start t8l8v ordered test_enc_dec[2] +=== start 1: t8l8v ordered test_enc_dec[2] encoded: 'FOO'=23 'BAR'="twentythree" 'BAZ'={2323,true} 'REPEAT_INT'={ 1, 2, 32767 } osmo_gtlvs_encode() rc = 0 01 02 00 17 02 0b 74 77 65 6e 74 79 74 68 72 65 65 03 02 89 13 04 02 00 01 04 02 00 02 04 02 7f ff . osmo_gtlvs_decode() rc = 0 decoded: 'FOO'=23 'BAR'="twentythree" 'BAZ'={2323,true} 'REPEAT_INT'={ 1, 2, 32767 } -=== end t8l8v ordered test_enc_dec[2] +=== end 1: t8l8v ordered test_enc_dec[2] -=== start t8l8v ordered test_enc_dec[3] +=== start 1: t8l8v ordered test_enc_dec[3] +encoded: 'FOO'=23 'BAR'="twentythree" 'REPEAT_INT'={ 1, 2, 32767 } 'REPEAT_INT'={ 23, 42 } 'REPEAT_INT'=423 'REPEAT_STRUCT'={ {1001,true,R_A} } 'NEST'={ 'FOO'=42 'BAR'="fortytwo" 'BAZ'={4242,false} } +osmo_gtlvs_encode() rc = 0 +01 02 00 17 02 0b 74 77 65 6e 74 79 74 68 72 65 65 04 02 00 01 04 02 00 02 04 02 7f ff 04 02 00 17 04 02 00 2a 04 02 01 a7 05 03 03 e9 80 06 12 01 02 00 2a 02 08 66 6f 72 74 79 74 77 6f 03 02 10 92 . +osmo_gtlvs_decode() rc = 0 +decoded: 'FOO'=23 'BAR'="twentythree" 'REPEAT_INT'={ 1, 2, 32767 } 'REPEAT_INT'={ 23, 42 } 'REPEAT_INT'=423 'REPEAT_STRUCT'={ {1001,true,R_A} } 'NEST'={ 'FOO'=42 'BAR'="fortytwo" 'BAZ'={4242,false} } +=== end 1: t8l8v ordered test_enc_dec[3] + +=== start 1: t8l8v ordered test_enc_dec[4] encoded: 'FOO'=23 'BAR'="twentythree" 'BAZ'={2323,true} 'REPEAT_INT'={ 1, 2, 32767 } 'REPEAT_STRUCT'={ {1001,true,R_A}, {1002,false,R_B} } 'NEST'={ 'FOO'=42 'BAR'="fortytwo" 'BAZ'={4242,false} } osmo_gtlvs_encode() rc = 0 01 02 00 17 02 0b 74 77 65 6e 74 79 74 68 72 65 65 03 02 89 13 04 02 00 01 04 02 00 02 04 02 7f ff 05 03 03 e9 80 05 03 03 ea 01 06 12 01 02 00 2a 02 08 66 6f 72 74 79 74 77 6f 03 02 10 92 . osmo_gtlvs_decode() rc = 0 decoded: 'FOO'=23 'BAR'="twentythree" 'BAZ'={2323,true} 'REPEAT_INT'={ 1, 2, 32767 } 'REPEAT_STRUCT'={ {1001,true,R_A}, {1002,false,R_B} } 'NEST'={ 'FOO'=42 'BAR'="fortytwo" 'BAZ'={4242,false} } -=== end t8l8v ordered test_enc_dec[3] +=== end 1: t8l8v ordered test_enc_dec[4] -=== start t8l8v unordered test_enc_dec[0] +=== start 1: t8l8v unordered test_enc_dec[0] encoded: 'FOO'=23 'BAR'="twentythree" osmo_gtlvs_encode() rc = 0 01 02 00 17 02 0b 74 77 65 6e 74 79 74 68 72 65 65 . osmo_gtlvs_decode() rc = 0 decoded: 'FOO'=23 'BAR'="twentythree" -=== end t8l8v unordered test_enc_dec[0] +=== end 1: t8l8v unordered test_enc_dec[0] -=== start t8l8v unordered test_enc_dec[1] +=== start 1: t8l8v unordered test_enc_dec[1] encoded: 'FOO'=23 'BAR'="twentythree" 'BAZ'={2323,true} osmo_gtlvs_encode() rc = 0 01 02 00 17 02 0b 74 77 65 6e 74 79 74 68 72 65 65 03 02 89 13 . osmo_gtlvs_decode() rc = 0 decoded: 'FOO'=23 'BAR'="twentythree" 'BAZ'={2323,true} -=== end t8l8v unordered test_enc_dec[1] +=== end 1: t8l8v unordered test_enc_dec[1] -=== start t8l8v unordered test_enc_dec[2] +=== start 1: t8l8v unordered test_enc_dec[2] encoded: 'FOO'=23 'BAR'="twentythree" 'BAZ'={2323,true} 'REPEAT_INT'={ 1, 2, 32767 } osmo_gtlvs_encode() rc = 0 01 02 00 17 02 0b 74 77 65 6e 74 79 74 68 72 65 65 03 02 89 13 04 02 00 01 04 02 00 02 04 02 7f ff . osmo_gtlvs_decode() rc = 0 decoded: 'FOO'=23 'BAR'="twentythree" 'BAZ'={2323,true} 'REPEAT_INT'={ 1, 2, 32767 } -=== end t8l8v unordered test_enc_dec[2] +=== end 1: t8l8v unordered test_enc_dec[2] -=== start t8l8v unordered test_enc_dec[3] +=== start 1: t8l8v unordered test_enc_dec[3] +encoded: 'FOO'=23 'BAR'="twentythree" 'REPEAT_INT'={ 1, 2, 32767 } 'REPEAT_INT'={ 23, 42 } 'REPEAT_INT'=423 'REPEAT_STRUCT'={ {1001,true,R_A} } 'NEST'={ 'FOO'=42 'BAR'="fortytwo" 'BAZ'={4242,false} } +osmo_gtlvs_encode() rc = 0 +01 02 00 17 02 0b 74 77 65 6e 74 79 74 68 72 65 65 04 02 00 01 04 02 00 02 04 02 7f ff 04 02 00 17 04 02 00 2a 04 02 01 a7 05 03 03 e9 80 06 12 01 02 00 2a 02 08 66 6f 72 74 79 74 77 6f 03 02 10 92 . +osmo_gtlvs_decode() rc = 0 +decoded: 'FOO'=23 'BAR'="twentythree" 'REPEAT_INT'={ 1, 2, 32767 } 'REPEAT_INT'={ 23, 42 } 'REPEAT_INT'=423 'REPEAT_STRUCT'={ {1001,true,R_A} } 'NEST'={ 'FOO'=42 'BAR'="fortytwo" 'BAZ'={4242,false} } +=== end 1: t8l8v unordered test_enc_dec[3] + +=== start 1: t8l8v unordered test_enc_dec[4] encoded: 'FOO'=23 'BAR'="twentythree" 'BAZ'={2323,true} 'REPEAT_INT'={ 1, 2, 32767 } 'REPEAT_STRUCT'={ {1001,true,R_A}, {1002,false,R_B} } 'NEST'={ 'FOO'=42 'BAR'="fortytwo" 'BAZ'={4242,false} } osmo_gtlvs_encode() rc = 0 01 02 00 17 02 0b 74 77 65 6e 74 79 74 68 72 65 65 03 02 89 13 04 02 00 01 04 02 00 02 04 02 7f ff 05 03 03 e9 80 05 03 03 ea 01 06 12 01 02 00 2a 02 08 66 6f 72 74 79 74 77 6f 03 02 10 92 . osmo_gtlvs_decode() rc = 0 decoded: 'FOO'=23 'BAR'="twentythree" 'BAZ'={2323,true} 'REPEAT_INT'={ 1, 2, 32767 } 'REPEAT_STRUCT'={ {1001,true,R_A}, {1002,false,R_B} } 'NEST'={ 'FOO'=42 'BAR'="fortytwo" 'BAZ'={4242,false} } -=== end t8l8v unordered test_enc_dec[3] +=== end 1: t8l8v unordered test_enc_dec[4] -=== start t16l16v ordered test_enc_dec[0] +=== start 1: t16l16v ordered test_enc_dec[0] encoded: 'FOO'=23 'BAR'="twentythree" osmo_gtlvs_encode() rc = 0 00 01 00 02 00 17 00 02 00 0b 74 77 65 6e 74 79 74 68 72 65 65 . osmo_gtlvs_decode() rc = 0 decoded: 'FOO'=23 'BAR'="twentythree" -=== end t16l16v ordered test_enc_dec[0] +=== end 1: t16l16v ordered test_enc_dec[0] -=== start t16l16v ordered test_enc_dec[1] +=== start 1: t16l16v ordered test_enc_dec[1] encoded: 'FOO'=23 'BAR'="twentythree" 'BAZ'={2323,true} osmo_gtlvs_encode() rc = 0 00 01 00 02 00 17 00 02 00 0b 74 77 65 6e 74 79 74 68 72 65 65 00 03 00 02 89 13 . osmo_gtlvs_decode() rc = 0 decoded: 'FOO'=23 'BAR'="twentythree" 'BAZ'={2323,true} -=== end t16l16v ordered test_enc_dec[1] +=== end 1: t16l16v ordered test_enc_dec[1] -=== start t16l16v ordered test_enc_dec[2] +=== start 1: t16l16v ordered test_enc_dec[2] encoded: 'FOO'=23 'BAR'="twentythree" 'BAZ'={2323,true} 'REPEAT_INT'={ 1, 2, 32767 } osmo_gtlvs_encode() rc = 0 00 01 00 02 00 17 00 02 00 0b 74 77 65 6e 74 79 74 68 72 65 65 00 03 00 02 89 13 00 04 00 02 00 01 00 04 00 02 00 02 00 04 00 02 7f ff . osmo_gtlvs_decode() rc = 0 decoded: 'FOO'=23 'BAR'="twentythree" 'BAZ'={2323,true} 'REPEAT_INT'={ 1, 2, 32767 } -=== end t16l16v ordered test_enc_dec[2] +=== end 1: t16l16v ordered test_enc_dec[2] -=== start t16l16v ordered test_enc_dec[3] +=== start 1: t16l16v ordered test_enc_dec[3] +encoded: 'FOO'=23 'BAR'="twentythree" 'REPEAT_INT'={ 1, 2, 32767 } 'REPEAT_INT'={ 23, 42 } 'REPEAT_INT'=423 'REPEAT_STRUCT'={ {1001,true,R_A} } 'NEST'={ 'FOO'=42 'BAR'="fortytwo" 'BAZ'={4242,false} } +osmo_gtlvs_encode() rc = 0 +00 01 00 02 00 17 00 02 00 0b 74 77 65 6e 74 79 74 68 72 65 65 00 04 00 02 00 01 00 04 00 02 00 02 00 04 00 02 7f ff 00 04 00 02 00 17 00 04 00 02 00 2a 00 04 00 02 01 a7 00 05 00 03 03 e9 80 00 06 00 18 00 01 00 02 00 2a 00 02 00 08 66 6f 72 74 79 74 77 6f 00 03 00 02 10 92 . +osmo_gtlvs_decode() rc = 0 +decoded: 'FOO'=23 'BAR'="twentythree" 'REPEAT_INT'={ 1, 2, 32767 } 'REPEAT_INT'={ 23, 42 } 'REPEAT_INT'=423 'REPEAT_STRUCT'={ {1001,true,R_A} } 'NEST'={ 'FOO'=42 'BAR'="fortytwo" 'BAZ'={4242,false} } +=== end 1: t16l16v ordered test_enc_dec[3] + +=== start 1: t16l16v ordered test_enc_dec[4] encoded: 'FOO'=23 'BAR'="twentythree" 'BAZ'={2323,true} 'REPEAT_INT'={ 1, 2, 32767 } 'REPEAT_STRUCT'={ {1001,true,R_A}, {1002,false,R_B} } 'NEST'={ 'FOO'=42 'BAR'="fortytwo" 'BAZ'={4242,false} } osmo_gtlvs_encode() rc = 0 00 01 00 02 00 17 00 02 00 0b 74 77 65 6e 74 79 74 68 72 65 65 00 03 00 02 89 13 00 04 00 02 00 01 00 04 00 02 00 02 00 04 00 02 7f ff 00 05 00 03 03 e9 80 00 05 00 03 03 ea 01 00 06 00 18 00 01 00 02 00 2a 00 02 00 08 66 6f 72 74 79 74 77 6f 00 03 00 02 10 92 . osmo_gtlvs_decode() rc = 0 decoded: 'FOO'=23 'BAR'="twentythree" 'BAZ'={2323,true} 'REPEAT_INT'={ 1, 2, 32767 } 'REPEAT_STRUCT'={ {1001,true,R_A}, {1002,false,R_B} } 'NEST'={ 'FOO'=42 'BAR'="fortytwo" 'BAZ'={4242,false} } -=== end t16l16v ordered test_enc_dec[3] +=== end 1: t16l16v ordered test_enc_dec[4] -=== start t16l16v unordered test_enc_dec[0] +=== start 1: t16l16v unordered test_enc_dec[0] encoded: 'FOO'=23 'BAR'="twentythree" osmo_gtlvs_encode() rc = 0 00 01 00 02 00 17 00 02 00 0b 74 77 65 6e 74 79 74 68 72 65 65 . osmo_gtlvs_decode() rc = 0 decoded: 'FOO'=23 'BAR'="twentythree" -=== end t16l16v unordered test_enc_dec[0] +=== end 1: t16l16v unordered test_enc_dec[0] -=== start t16l16v unordered test_enc_dec[1] +=== start 1: t16l16v unordered test_enc_dec[1] encoded: 'FOO'=23 'BAR'="twentythree" 'BAZ'={2323,true} osmo_gtlvs_encode() rc = 0 00 01 00 02 00 17 00 02 00 0b 74 77 65 6e 74 79 74 68 72 65 65 00 03 00 02 89 13 . osmo_gtlvs_decode() rc = 0 decoded: 'FOO'=23 'BAR'="twentythree" 'BAZ'={2323,true} -=== end t16l16v unordered test_enc_dec[1] +=== end 1: t16l16v unordered test_enc_dec[1] -=== start t16l16v unordered test_enc_dec[2] +=== start 1: t16l16v unordered test_enc_dec[2] encoded: 'FOO'=23 'BAR'="twentythree" 'BAZ'={2323,true} 'REPEAT_INT'={ 1, 2, 32767 } osmo_gtlvs_encode() rc = 0 00 01 00 02 00 17 00 02 00 0b 74 77 65 6e 74 79 74 68 72 65 65 00 03 00 02 89 13 00 04 00 02 00 01 00 04 00 02 00 02 00 04 00 02 7f ff . osmo_gtlvs_decode() rc = 0 decoded: 'FOO'=23 'BAR'="twentythree" 'BAZ'={2323,true} 'REPEAT_INT'={ 1, 2, 32767 } -=== end t16l16v unordered test_enc_dec[2] +=== end 1: t16l16v unordered test_enc_dec[2] -=== start t16l16v unordered test_enc_dec[3] +=== start 1: t16l16v unordered test_enc_dec[3] +encoded: 'FOO'=23 'BAR'="twentythree" 'REPEAT_INT'={ 1, 2, 32767 } 'REPEAT_INT'={ 23, 42 } 'REPEAT_INT'=423 'REPEAT_STRUCT'={ {1001,true,R_A} } 'NEST'={ 'FOO'=42 'BAR'="fortytwo" 'BAZ'={4242,false} } +osmo_gtlvs_encode() rc = 0 +00 01 00 02 00 17 00 02 00 0b 74 77 65 6e 74 79 74 68 72 65 65 00 04 00 02 00 01 00 04 00 02 00 02 00 04 00 02 7f ff 00 04 00 02 00 17 00 04 00 02 00 2a 00 04 00 02 01 a7 00 05 00 03 03 e9 80 00 06 00 18 00 01 00 02 00 2a 00 02 00 08 66 6f 72 74 79 74 77 6f 00 03 00 02 10 92 . +osmo_gtlvs_decode() rc = 0 +decoded: 'FOO'=23 'BAR'="twentythree" 'REPEAT_INT'={ 1, 2, 32767 } 'REPEAT_INT'={ 23, 42 } 'REPEAT_INT'=423 'REPEAT_STRUCT'={ {1001,true,R_A} } 'NEST'={ 'FOO'=42 'BAR'="fortytwo" 'BAZ'={4242,false} } +=== end 1: t16l16v unordered test_enc_dec[3] + +=== start 1: t16l16v unordered test_enc_dec[4] encoded: 'FOO'=23 'BAR'="twentythree" 'BAZ'={2323,true} 'REPEAT_INT'={ 1, 2, 32767 } 'REPEAT_STRUCT'={ {1001,true,R_A}, {1002,false,R_B} } 'NEST'={ 'FOO'=42 'BAR'="fortytwo" 'BAZ'={4242,false} } osmo_gtlvs_encode() rc = 0 00 01 00 02 00 17 00 02 00 0b 74 77 65 6e 74 79 74 68 72 65 65 00 03 00 02 89 13 00 04 00 02 00 01 00 04 00 02 00 02 00 04 00 02 7f ff 00 05 00 03 03 e9 80 00 05 00 03 03 ea 01 00 06 00 18 00 01 00 02 00 2a 00 02 00 08 66 6f 72 74 79 74 77 6f 00 03 00 02 10 92 . osmo_gtlvs_decode() rc = 0 decoded: 'FOO'=23 'BAR'="twentythree" 'BAZ'={2323,true} 'REPEAT_INT'={ 1, 2, 32767 } 'REPEAT_STRUCT'={ {1001,true,R_A}, {1002,false,R_B} } 'NEST'={ 'FOO'=42 'BAR'="fortytwo" 'BAZ'={4242,false} } -=== end t16l16v unordered test_enc_dec[3] +=== end 1: t16l16v unordered test_enc_dec[4] + +=== start 2: t8l8v ordered test_enc_dec[0] +encoded: 'FOO'=23 'BAR'="twentythree" +osmo_gtlvs_encode() rc = 0 +01 02 00 17 02 0b 74 77 65 6e 74 79 74 68 72 65 65 . +osmo_gtlvs_decode() rc = 0 +decoded: 'FOO'=23 'BAR'="twentythree" +=== end 2: t8l8v ordered test_enc_dec[0] + +=== start 2: t8l8v ordered test_enc_dec[1] +encoded: 'FOO'=23 'BAR'="twentythree" 'BAZ'={2323,true} +osmo_gtlvs_encode() rc = 0 +01 02 00 17 02 0b 74 77 65 6e 74 79 74 68 72 65 65 03 02 89 13 . +osmo_gtlvs_decode() rc = 0 +decoded: 'FOO'=23 'BAR'="twentythree" 'BAZ'={2323,true} +=== end 2: t8l8v ordered test_enc_dec[1] + +=== start 2: t8l8v ordered test_enc_dec[2] +encoded: 'FOO'=23 'BAR'="twentythree" 'BAZ'={2323,true} 'REPEAT_INT'={ 1, 2, 32767 } +osmo_gtlvs_encode() rc = 0 +01 02 00 17 02 0b 74 77 65 6e 74 79 74 68 72 65 65 03 02 89 13 04 02 00 01 04 02 00 02 04 02 7f ff . +osmo_gtlvs_decode() rc = 0 +decoded: 'FOO'=23 'BAR'="twentythree" 'BAZ'={2323,true} 'REPEAT_INT'={ 1, 2, 32767 } +=== end 2: t8l8v ordered test_enc_dec[2] + +=== start 2: t8l8v ordered test_enc_dec[3] +encoded: 'FOO'=23 'BAR'="twentythree" 'REPEAT_INT'={ 1, 2, 32767 } 'REPEAT_STRUCT'={ {1001,true,R_A} } 'REPEAT_INT'={ 23, 42 } 'NEST'={ 'FOO'=42 'BAR'="fortytwo" 'BAZ'={4242,false} } 'REPEAT_INT'=423 +osmo_gtlvs_encode() rc = 0 +01 02 00 17 02 0b 74 77 65 6e 74 79 74 68 72 65 65 04 02 00 01 04 02 00 02 04 02 7f ff 05 03 03 e9 80 04 02 00 17 04 02 00 2a 06 12 01 02 00 2a 02 08 66 6f 72 74 79 74 77 6f 03 02 10 92 04 02 01 a7 . +osmo_gtlvs_decode() rc = 0 +decoded: 'FOO'=23 'BAR'="twentythree" 'REPEAT_INT'={ 1, 2, 32767 } 'REPEAT_STRUCT'={ {1001,true,R_A} } 'REPEAT_INT'={ 23, 42 } 'NEST'={ 'FOO'=42 'BAR'="fortytwo" 'BAZ'={4242,false} } 'REPEAT_INT'=423 +=== end 2: t8l8v ordered test_enc_dec[3] + +=== start 2: t8l8v ordered test_enc_dec[4] +encoded: 'FOO'=23 'BAR'="twentythree" 'BAZ'={2323,true} 'REPEAT_INT'={ 1, 2, 32767 } 'REPEAT_STRUCT'={ {1001,true,R_A}, {1002,false,R_B} } 'NEST'={ 'FOO'=42 'BAR'="fortytwo" 'BAZ'={4242,false} } +osmo_gtlvs_encode() rc = 0 +01 02 00 17 02 0b 74 77 65 6e 74 79 74 68 72 65 65 03 02 89 13 04 02 00 01 04 02 00 02 04 02 7f ff 05 03 03 e9 80 05 03 03 ea 01 06 12 01 02 00 2a 02 08 66 6f 72 74 79 74 77 6f 03 02 10 92 . +osmo_gtlvs_decode() rc = 0 +decoded: 'FOO'=23 'BAR'="twentythree" 'BAZ'={2323,true} 'REPEAT_INT'={ 1, 2, 32767 } 'REPEAT_STRUCT'={ {1001,true,R_A}, {1002,false,R_B} } 'NEST'={ 'FOO'=42 'BAR'="fortytwo" 'BAZ'={4242,false} } +=== end 2: t8l8v ordered test_enc_dec[4] + +=== start 2: t8l8v unordered test_enc_dec[0] +encoded: 'FOO'=23 'BAR'="twentythree" +osmo_gtlvs_encode() rc = 0 +01 02 00 17 02 0b 74 77 65 6e 74 79 74 68 72 65 65 . +osmo_gtlvs_decode() rc = 0 +decoded: 'FOO'=23 'BAR'="twentythree" +=== end 2: t8l8v unordered test_enc_dec[0] + +=== start 2: t8l8v unordered test_enc_dec[1] +encoded: 'FOO'=23 'BAR'="twentythree" 'BAZ'={2323,true} +osmo_gtlvs_encode() rc = 0 +01 02 00 17 02 0b 74 77 65 6e 74 79 74 68 72 65 65 03 02 89 13 . +osmo_gtlvs_decode() rc = 0 +decoded: 'FOO'=23 'BAR'="twentythree" 'BAZ'={2323,true} +=== end 2: t8l8v unordered test_enc_dec[1] + +=== start 2: t8l8v unordered test_enc_dec[2] +encoded: 'FOO'=23 'BAR'="twentythree" 'BAZ'={2323,true} 'REPEAT_INT'={ 1, 2, 32767 } +osmo_gtlvs_encode() rc = 0 +01 02 00 17 02 0b 74 77 65 6e 74 79 74 68 72 65 65 03 02 89 13 04 02 00 01 04 02 00 02 04 02 7f ff . +osmo_gtlvs_decode() rc = 0 +decoded: 'FOO'=23 'BAR'="twentythree" 'BAZ'={2323,true} 'REPEAT_INT'={ 1, 2, 32767 } +=== end 2: t8l8v unordered test_enc_dec[2] + +=== start 2: t8l8v unordered test_enc_dec[3] +encoded: 'FOO'=23 'BAR'="twentythree" 'REPEAT_INT'={ 1, 2, 32767 } 'REPEAT_STRUCT'={ {1001,true,R_A} } 'REPEAT_INT'={ 23, 42 } 'NEST'={ 'FOO'=42 'BAR'="fortytwo" 'BAZ'={4242,false} } 'REPEAT_INT'=423 +osmo_gtlvs_encode() rc = 0 +01 02 00 17 02 0b 74 77 65 6e 74 79 74 68 72 65 65 04 02 00 01 04 02 00 02 04 02 7f ff 05 03 03 e9 80 04 02 00 17 04 02 00 2a 06 12 01 02 00 2a 02 08 66 6f 72 74 79 74 77 6f 03 02 10 92 04 02 01 a7 . +osmo_gtlvs_decode() rc = 0 +decoded: 'FOO'=23 'BAR'="twentythree" 'REPEAT_INT'={ 1, 2, 32767 } 'REPEAT_STRUCT'={ {1001,true,R_A} } 'REPEAT_INT'={ 23, 42 } 'NEST'={ 'FOO'=42 'BAR'="fortytwo" 'BAZ'={4242,false} } 'REPEAT_INT'=423 +=== end 2: t8l8v unordered test_enc_dec[3] + +=== start 2: t8l8v unordered test_enc_dec[4] +encoded: 'FOO'=23 'BAR'="twentythree" 'BAZ'={2323,true} 'REPEAT_INT'={ 1, 2, 32767 } 'REPEAT_STRUCT'={ {1001,true,R_A}, {1002,false,R_B} } 'NEST'={ 'FOO'=42 'BAR'="fortytwo" 'BAZ'={4242,false} } +osmo_gtlvs_encode() rc = 0 +01 02 00 17 02 0b 74 77 65 6e 74 79 74 68 72 65 65 03 02 89 13 04 02 00 01 04 02 00 02 04 02 7f ff 05 03 03 e9 80 05 03 03 ea 01 06 12 01 02 00 2a 02 08 66 6f 72 74 79 74 77 6f 03 02 10 92 . +osmo_gtlvs_decode() rc = 0 +decoded: 'FOO'=23 'BAR'="twentythree" 'BAZ'={2323,true} 'REPEAT_INT'={ 1, 2, 32767 } 'REPEAT_STRUCT'={ {1001,true,R_A}, {1002,false,R_B} } 'NEST'={ 'FOO'=42 'BAR'="fortytwo" 'BAZ'={4242,false} } +=== end 2: t8l8v unordered test_enc_dec[4] + +=== start 2: t16l16v ordered test_enc_dec[0] +encoded: 'FOO'=23 'BAR'="twentythree" +osmo_gtlvs_encode() rc = 0 +00 01 00 02 00 17 00 02 00 0b 74 77 65 6e 74 79 74 68 72 65 65 . +osmo_gtlvs_decode() rc = 0 +decoded: 'FOO'=23 'BAR'="twentythree" +=== end 2: t16l16v ordered test_enc_dec[0] + +=== start 2: t16l16v ordered test_enc_dec[1] +encoded: 'FOO'=23 'BAR'="twentythree" 'BAZ'={2323,true} +osmo_gtlvs_encode() rc = 0 +00 01 00 02 00 17 00 02 00 0b 74 77 65 6e 74 79 74 68 72 65 65 00 03 00 02 89 13 . +osmo_gtlvs_decode() rc = 0 +decoded: 'FOO'=23 'BAR'="twentythree" 'BAZ'={2323,true} +=== end 2: t16l16v ordered test_enc_dec[1] + +=== start 2: t16l16v ordered test_enc_dec[2] +encoded: 'FOO'=23 'BAR'="twentythree" 'BAZ'={2323,true} 'REPEAT_INT'={ 1, 2, 32767 } +osmo_gtlvs_encode() rc = 0 +00 01 00 02 00 17 00 02 00 0b 74 77 65 6e 74 79 74 68 72 65 65 00 03 00 02 89 13 00 04 00 02 00 01 00 04 00 02 00 02 00 04 00 02 7f ff . +osmo_gtlvs_decode() rc = 0 +decoded: 'FOO'=23 'BAR'="twentythree" 'BAZ'={2323,true} 'REPEAT_INT'={ 1, 2, 32767 } +=== end 2: t16l16v ordered test_enc_dec[2] + +=== start 2: t16l16v ordered test_enc_dec[3] +encoded: 'FOO'=23 'BAR'="twentythree" 'REPEAT_INT'={ 1, 2, 32767 } 'REPEAT_STRUCT'={ {1001,true,R_A} } 'REPEAT_INT'={ 23, 42 } 'NEST'={ 'FOO'=42 'BAR'="fortytwo" 'BAZ'={4242,false} } 'REPEAT_INT'=423 +osmo_gtlvs_encode() rc = 0 +00 01 00 02 00 17 00 02 00 0b 74 77 65 6e 74 79 74 68 72 65 65 00 04 00 02 00 01 00 04 00 02 00 02 00 04 00 02 7f ff 00 05 00 03 03 e9 80 00 04 00 02 00 17 00 04 00 02 00 2a 00 06 00 18 00 01 00 02 00 2a 00 02 00 08 66 6f 72 74 79 74 77 6f 00 03 00 02 10 92 00 04 00 02 01 a7 . +osmo_gtlvs_decode() rc = 0 +decoded: 'FOO'=23 'BAR'="twentythree" 'REPEAT_INT'={ 1, 2, 32767 } 'REPEAT_STRUCT'={ {1001,true,R_A} } 'REPEAT_INT'={ 23, 42 } 'NEST'={ 'FOO'=42 'BAR'="fortytwo" 'BAZ'={4242,false} } 'REPEAT_INT'=423 +=== end 2: t16l16v ordered test_enc_dec[3] + +=== start 2: t16l16v ordered test_enc_dec[4] +encoded: 'FOO'=23 'BAR'="twentythree" 'BAZ'={2323,true} 'REPEAT_INT'={ 1, 2, 32767 } 'REPEAT_STRUCT'={ {1001,true,R_A}, {1002,false,R_B} } 'NEST'={ 'FOO'=42 'BAR'="fortytwo" 'BAZ'={4242,false} } +osmo_gtlvs_encode() rc = 0 +00 01 00 02 00 17 00 02 00 0b 74 77 65 6e 74 79 74 68 72 65 65 00 03 00 02 89 13 00 04 00 02 00 01 00 04 00 02 00 02 00 04 00 02 7f ff 00 05 00 03 03 e9 80 00 05 00 03 03 ea 01 00 06 00 18 00 01 00 02 00 2a 00 02 00 08 66 6f 72 74 79 74 77 6f 00 03 00 02 10 92 . +osmo_gtlvs_decode() rc = 0 +decoded: 'FOO'=23 'BAR'="twentythree" 'BAZ'={2323,true} 'REPEAT_INT'={ 1, 2, 32767 } 'REPEAT_STRUCT'={ {1001,true,R_A}, {1002,false,R_B} } 'NEST'={ 'FOO'=42 'BAR'="fortytwo" 'BAZ'={4242,false} } +=== end 2: t16l16v ordered test_enc_dec[4] + +=== start 2: t16l16v unordered test_enc_dec[0] +encoded: 'FOO'=23 'BAR'="twentythree" +osmo_gtlvs_encode() rc = 0 +00 01 00 02 00 17 00 02 00 0b 74 77 65 6e 74 79 74 68 72 65 65 . +osmo_gtlvs_decode() rc = 0 +decoded: 'FOO'=23 'BAR'="twentythree" +=== end 2: t16l16v unordered test_enc_dec[0] + +=== start 2: t16l16v unordered test_enc_dec[1] +encoded: 'FOO'=23 'BAR'="twentythree" 'BAZ'={2323,true} +osmo_gtlvs_encode() rc = 0 +00 01 00 02 00 17 00 02 00 0b 74 77 65 6e 74 79 74 68 72 65 65 00 03 00 02 89 13 . +osmo_gtlvs_decode() rc = 0 +decoded: 'FOO'=23 'BAR'="twentythree" 'BAZ'={2323,true} +=== end 2: t16l16v unordered test_enc_dec[1] + +=== start 2: t16l16v unordered test_enc_dec[2] +encoded: 'FOO'=23 'BAR'="twentythree" 'BAZ'={2323,true} 'REPEAT_INT'={ 1, 2, 32767 } +osmo_gtlvs_encode() rc = 0 +00 01 00 02 00 17 00 02 00 0b 74 77 65 6e 74 79 74 68 72 65 65 00 03 00 02 89 13 00 04 00 02 00 01 00 04 00 02 00 02 00 04 00 02 7f ff . +osmo_gtlvs_decode() rc = 0 +decoded: 'FOO'=23 'BAR'="twentythree" 'BAZ'={2323,true} 'REPEAT_INT'={ 1, 2, 32767 } +=== end 2: t16l16v unordered test_enc_dec[2] + +=== start 2: t16l16v unordered test_enc_dec[3] +encoded: 'FOO'=23 'BAR'="twentythree" 'REPEAT_INT'={ 1, 2, 32767 } 'REPEAT_STRUCT'={ {1001,true,R_A} } 'REPEAT_INT'={ 23, 42 } 'NEST'={ 'FOO'=42 'BAR'="fortytwo" 'BAZ'={4242,false} } 'REPEAT_INT'=423 +osmo_gtlvs_encode() rc = 0 +00 01 00 02 00 17 00 02 00 0b 74 77 65 6e 74 79 74 68 72 65 65 00 04 00 02 00 01 00 04 00 02 00 02 00 04 00 02 7f ff 00 05 00 03 03 e9 80 00 04 00 02 00 17 00 04 00 02 00 2a 00 06 00 18 00 01 00 02 00 2a 00 02 00 08 66 6f 72 74 79 74 77 6f 00 03 00 02 10 92 00 04 00 02 01 a7 . +osmo_gtlvs_decode() rc = 0 +decoded: 'FOO'=23 'BAR'="twentythree" 'REPEAT_INT'={ 1, 2, 32767 } 'REPEAT_STRUCT'={ {1001,true,R_A} } 'REPEAT_INT'={ 23, 42 } 'NEST'={ 'FOO'=42 'BAR'="fortytwo" 'BAZ'={4242,false} } 'REPEAT_INT'=423 +=== end 2: t16l16v unordered test_enc_dec[3] + +=== start 2: t16l16v unordered test_enc_dec[4] +encoded: 'FOO'=23 'BAR'="twentythree" 'BAZ'={2323,true} 'REPEAT_INT'={ 1, 2, 32767 } 'REPEAT_STRUCT'={ {1001,true,R_A}, {1002,false,R_B} } 'NEST'={ 'FOO'=42 'BAR'="fortytwo" 'BAZ'={4242,false} } +osmo_gtlvs_encode() rc = 0 +00 01 00 02 00 17 00 02 00 0b 74 77 65 6e 74 79 74 68 72 65 65 00 03 00 02 89 13 00 04 00 02 00 01 00 04 00 02 00 02 00 04 00 02 7f ff 00 05 00 03 03 e9 80 00 05 00 03 03 ea 01 00 06 00 18 00 01 00 02 00 2a 00 02 00 08 66 6f 72 74 79 74 77 6f 00 03 00 02 10 92 . +osmo_gtlvs_decode() rc = 0 +decoded: 'FOO'=23 'BAR'="twentythree" 'BAZ'={2323,true} 'REPEAT_INT'={ 1, 2, 32767 } 'REPEAT_STRUCT'={ {1001,true,R_A}, {1002,false,R_B} } 'NEST'={ 'FOO'=42 'BAR'="fortytwo" 'BAZ'={4242,false} } +=== end 2: t16l16v unordered test_enc_dec[4] null-- To view, visit https://gerrit.osmocom.org/c/libosmo-pfcp/+/29043 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmo-pfcp Gerrit-Branch: master Gerrit-Change-Id: I994d0fb1f1435d2c27a8630a43fe106652ac6e41 Gerrit-Change-Number: 29043 Gerrit-PatchSet: 5 Gerrit-Owner: neels <nhofmeyr(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: pespin <pespin(a)sysmocom.de> Gerrit-MessageType: merged
1 0
0 0
Change in libosmo-pfcp[master]: gtlv: check memory bounds 3/3: encoding to str
by neels 24 Aug '22

24 Aug '22
neels has submitted this change. ( https://gerrit.osmocom.org/c/libosmo-pfcp/+/29041 ) Change subject: gtlv: check memory bounds 3/3: encoding to str ...................................................................... gtlv: check memory bounds 3/3: encoding to str See Id8d997c9d5e655ff1842ec69eab6c073875c6330 Related: CID#275417 Related: SYS#5599 Change-Id: I63d52a4f5dba32d3a3887dd9c5e42e1695fb2aa3 --- M include/osmocom/gtlv/gtlv_dec_enc.h M src/libosmo-gtlv/gtlv_dec_enc.c M src/libosmo-gtlv/gtlv_gen.c M tests/libosmo-gtlv/gtlv_dec_enc_test.c M tests/libosmo-gtlv/test_gtlv_gen/gtlv_gen_test.c M tests/libosmo-gtlv/test_tliv/tliv_test.c 6 files changed, 30 insertions(+), 23 deletions(-) Approvals: neels: Looks good to me, approved diff --git a/include/osmocom/gtlv/gtlv_dec_enc.h b/include/osmocom/gtlv/gtlv_dec_enc.h index 2126beb..e671022 100644 --- a/include/osmocom/gtlv/gtlv_dec_enc.h +++ b/include/osmocom/gtlv/gtlv_dec_enc.h @@ -191,10 +191,12 @@ unsigned int obj_ofs, const struct osmo_gtlv_coding *ie_coding, osmo_gtlv_err_cb err_cb, void *err_cb_data, const struct value_string *iei_strs); -int osmo_gtlvs_encode_to_str_buf(char *buf, size_t buflen, const void *decoded_struct, unsigned int obj_ofs, - const struct osmo_gtlv_coding *ie_coding, const struct value_string *iei_strs); -char *osmo_gtlvs_encode_to_str_c(void *ctx, const void *decoded_struct, unsigned int obj_ofs, - const struct osmo_gtlv_coding *ie_coding, const struct value_string *iei_strs); +int osmo_gtlvs_encode_to_str_buf(char *buf, size_t buflen, + const void *decoded_struct, size_t decoded_struct_size, unsigned int obj_ofs, + const struct osmo_gtlv_coding *ie_coding, const struct value_string *iei_strs); +char *osmo_gtlvs_encode_to_str_c(void *ctx, + const void *decoded_struct, size_t decoded_struct_size, unsigned int obj_ofs, + const struct osmo_gtlv_coding *ie_coding, const struct value_string *iei_strs); static inline bool osmo_gtlv_coding_end(const struct osmo_gtlv_coding *iec) { diff --git a/src/libosmo-gtlv/gtlv_dec_enc.c b/src/libosmo-gtlv/gtlv_dec_enc.c index e1e6d45..58c0405 100644 --- a/src/libosmo-gtlv/gtlv_dec_enc.c +++ b/src/libosmo-gtlv/gtlv_dec_enc.c @@ -28,9 +28,6 @@ #include <osmocom/gtlv/gtlv_dec_enc.h> -/* Reverse offsetof(): return the address of the struct member for a given osmo_gtlv_msg and member ofs_foo value. */ -#define MEMB(M, MEMB_OFS) ((void *)((char *)(M) + (MEMB_OFS))) - #define RETURN_ERROR(RC, TAG_INST, FMT, ARGS...) \ do {\ if (err_cb) { \ @@ -486,19 +483,23 @@ * \param[in] iei_strs value_string array to give IEI names in tag headers, or NULL. * \return number of characters that would be written if the buffer is large enough, like snprintf(). */ -int osmo_gtlvs_encode_to_str_buf(char *buf, size_t buflen, const void *decoded_struct, unsigned int obj_ofs, - const struct osmo_gtlv_coding *ie_coding, const struct value_string *iei_strs) +int osmo_gtlvs_encode_to_str_buf(char *buf, size_t buflen, + const void *decoded_struct, size_t decoded_struct_size, unsigned int obj_ofs, + const struct osmo_gtlv_coding *ie_coding, const struct value_string *iei_strs) { struct osmo_strbuf sb = { .buf = buf, .len = buflen }; - void *obj = MEMB(decoded_struct, obj_ofs); + const void *obj = membof_const(decoded_struct, decoded_struct_size, obj_ofs); + size_t obj_maxlen = decoded_struct_size - obj_ofs; if (!ie_coding) return -ENOTSUP; for (; !osmo_gtlv_coding_end(ie_coding); ie_coding++) { - bool *presence_flag_p = ie_coding->has_presence_flag ? MEMB(obj, ie_coding->presence_flag_ofs) : NULL; - unsigned int *multi_count_p = ie_coding->has_count ? MEMB(obj, ie_coding->count_ofs) : NULL; + const bool *presence_flag_p = ie_coding->has_presence_flag ? + membof_const(obj, obj_maxlen, ie_coding->presence_flag_ofs) : NULL; + const unsigned int *multi_count_p = ie_coding->has_count ? + membof_const(obj, obj_maxlen, ie_coding->count_ofs) : NULL; unsigned int n; unsigned int i; @@ -531,12 +532,14 @@ if (ie_coding->nested_ies) { OSMO_STRBUF_PRINTF(sb, "{"); - OSMO_STRBUF_APPEND(sb, osmo_gtlvs_encode_to_str_buf, decoded_struct, obj_ofs + memb_ofs, + OSMO_STRBUF_APPEND(sb, osmo_gtlvs_encode_to_str_buf, + decoded_struct, decoded_struct_size, obj_ofs + memb_ofs, ie_coding->nested_ies, iei_strs); OSMO_STRBUF_PRINTF(sb, " }"); } else { if (ie_coding->enc_to_str_func) - OSMO_STRBUF_APPEND(sb, ie_coding->enc_to_str_func, MEMB(obj, memb_ofs)); + OSMO_STRBUF_APPEND(sb, ie_coding->enc_to_str_func, + membof_const(obj, obj_maxlen, memb_ofs)); else OSMO_STRBUF_PRINTF(sb, "(enc_to_str_func==NULL)"); } @@ -557,8 +560,10 @@ * \param[in] iei_strs value_string array to give IEI names in tag headers, or NULL. * \return human readable string. */ -char *osmo_gtlvs_encode_to_str_c(void *ctx, const void *decoded_struct, unsigned int obj_ofs, - const struct osmo_gtlv_coding *ie_coding, const struct value_string *iei_strs) +char *osmo_gtlvs_encode_to_str_c(void *ctx, + const void *decoded_struct, size_t decoded_struct_size, unsigned int obj_ofs, + const struct osmo_gtlv_coding *ie_coding, const struct value_string *iei_strs) { - OSMO_NAME_C_IMPL(ctx, 256, "ERROR", osmo_gtlvs_encode_to_str_buf, decoded_struct, obj_ofs, ie_coding, iei_strs) + OSMO_NAME_C_IMPL(ctx, 256, "ERROR", osmo_gtlvs_encode_to_str_buf, decoded_struct, decoded_struct_size, + obj_ofs, ie_coding, iei_strs) } diff --git a/src/libosmo-gtlv/gtlv_gen.c b/src/libosmo-gtlv/gtlv_gen.c index 3b2b1f0..e374ea9 100644 --- a/src/libosmo-gtlv/gtlv_gen.c +++ b/src/libosmo-gtlv/gtlv_gen.c @@ -397,7 +397,7 @@ "int %s_ies_encode_to_str(char *buf, size_t buflen, const union %s_ies *src,\n" " %s message_type, const struct value_string *iei_strs)\n" "{\n" - " return osmo_gtlvs_encode_to_str_buf(buf, buflen, src, 0, %s_get_msg_coding(message_type), iei_strs);\n" + " return osmo_gtlvs_encode_to_str_buf(buf, buflen, src, sizeof(*src), 0, %s_get_msg_coding(message_type), iei_strs);\n" "}\n", g_cfg->proto_name, g_cfg->proto_name, g_cfg->message_type_enum ? : "int", g_cfg->proto_name); } diff --git a/tests/libosmo-gtlv/gtlv_dec_enc_test.c b/tests/libosmo-gtlv/gtlv_dec_enc_test.c index a542cfa..f0de7b0 100644 --- a/tests/libosmo-gtlv/gtlv_dec_enc_test.c +++ b/tests/libosmo-gtlv/gtlv_dec_enc_test.c @@ -286,7 +286,7 @@ char *decoded_msg_to_str(const struct decoded_msg *m) { - return osmo_gtlvs_encode_to_str_c(ctx, m, 0, msg_ie_coding, tag_names); + return osmo_gtlvs_encode_to_str_c(ctx, m, sizeof(*m), 0, msg_ie_coding, tag_names); } diff --git a/tests/libosmo-gtlv/test_gtlv_gen/gtlv_gen_test.c b/tests/libosmo-gtlv/test_gtlv_gen/gtlv_gen_test.c index ef5372c..1997fdc 100644 --- a/tests/libosmo-gtlv/test_gtlv_gen/gtlv_gen_test.c +++ b/tests/libosmo-gtlv/test_gtlv_gen/gtlv_gen_test.c @@ -203,8 +203,8 @@ { struct osmo_strbuf sb = { .buf = buf, .len = buflen }; OSMO_STRBUF_PRINTF(sb, "%s={", get_value_string(myproto_msg_type_names, m->type)); - OSMO_STRBUF_APPEND(sb, osmo_gtlvs_encode_to_str_buf, &m->ies, 0, myproto_get_msg_coding(m->type), - myproto_iei_names); + OSMO_STRBUF_APPEND(sb, osmo_gtlvs_encode_to_str_buf, &m->ies, sizeof(m->ies), 0, + myproto_get_msg_coding(m->type), myproto_iei_names); OSMO_STRBUF_PRINTF(sb, " }"); return sb.chars_needed; diff --git a/tests/libosmo-gtlv/test_tliv/tliv_test.c b/tests/libosmo-gtlv/test_tliv/tliv_test.c index fd4e310..49ae25c 100644 --- a/tests/libosmo-gtlv/test_tliv/tliv_test.c +++ b/tests/libosmo-gtlv/test_tliv/tliv_test.c @@ -101,8 +101,8 @@ { struct osmo_strbuf sb = { .buf = buf, .len = buflen }; OSMO_STRBUF_PRINTF(sb, "%s={", get_value_string(myproto_msg_type_names, m->type)); - OSMO_STRBUF_APPEND(sb, osmo_gtlvs_encode_to_str_buf, &m->ies, 0, myproto_get_msg_coding(m->type), - myproto_iei_names); + OSMO_STRBUF_APPEND(sb, osmo_gtlvs_encode_to_str_buf, &m->ies, sizeof(m->ies), 0, + myproto_get_msg_coding(m->type), myproto_iei_names); OSMO_STRBUF_PRINTF(sb, " }"); return sb.chars_needed; null-- To view, visit https://gerrit.osmocom.org/c/libosmo-pfcp/+/29041 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmo-pfcp Gerrit-Branch: master Gerrit-Change-Id: I63d52a4f5dba32d3a3887dd9c5e42e1695fb2aa3 Gerrit-Change-Number: 29041 Gerrit-PatchSet: 5 Gerrit-Owner: neels <nhofmeyr(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: neels <nhofmeyr(a)sysmocom.de> Gerrit-Reviewer: pespin <pespin(a)sysmocom.de> Gerrit-MessageType: merged
1 0
0 0
Change in libosmo-pfcp[master]: gtlv: check memory bounds 2/3: decoding TLV
by neels 24 Aug '22

24 Aug '22
neels has submitted this change. ( https://gerrit.osmocom.org/c/libosmo-pfcp/+/29040 ) Change subject: gtlv: check memory bounds 2/3: decoding TLV ...................................................................... gtlv: check memory bounds 2/3: decoding TLV See Id8d997c9d5e655ff1842ec69eab6c073875c6330 Related: CID#275417 Related: SYS#5599 Change-Id: I841da89112ccf70fcd0f60eb902445fb1712eb48 --- M include/osmocom/gtlv/gtlv_dec_enc.h M src/libosmo-gtlv/gtlv_dec_enc.c M src/libosmo-gtlv/gtlv_gen.c M tests/libosmo-gtlv/gtlv_dec_enc_test.c 4 files changed, 50 insertions(+), 30 deletions(-) diff --git a/include/osmocom/gtlv/gtlv_dec_enc.h b/include/osmocom/gtlv/gtlv_dec_enc.h index cb62fe3..2126beb 100644 --- a/include/osmocom/gtlv/gtlv_dec_enc.h +++ b/include/osmocom/gtlv/gtlv_dec_enc.h @@ -182,9 +182,10 @@ */ typedef void (*osmo_gtlv_err_cb)(void *data, void *decoded_struct, const char *file, int line, const char *fmt, ...); -int osmo_gtlvs_decode(void *decoded_struct, unsigned int obj_ofs, struct osmo_gtlv_load *gtlv, bool tlv_ordered, - const struct osmo_gtlv_coding *ie_coding, - osmo_gtlv_err_cb err_cb, void *err_cb_data, const struct value_string *iei_strs); +int osmo_gtlvs_decode(void *decoded_struct, size_t decoded_struct_size, + unsigned int obj_ofs, struct osmo_gtlv_load *gtlv, bool tlv_ordered, + const struct osmo_gtlv_coding *ie_coding, + osmo_gtlv_err_cb err_cb, void *err_cb_data, const struct value_string *iei_strs); int osmo_gtlvs_encode(struct osmo_gtlv_put *gtlv, const void *decoded_struct, size_t decoded_struct_size, unsigned int obj_ofs, const struct osmo_gtlv_coding *ie_coding, osmo_gtlv_err_cb err_cb, diff --git a/src/libosmo-gtlv/gtlv_dec_enc.c b/src/libosmo-gtlv/gtlv_dec_enc.c index be3002f..e1e6d45 100644 --- a/src/libosmo-gtlv/gtlv_dec_enc.c +++ b/src/libosmo-gtlv/gtlv_dec_enc.c @@ -63,6 +63,11 @@ return memb; } +static void *membof(void *parent, size_t parent_size, unsigned int memb_ofs) +{ + return (void *)membof_const((const void *)parent, parent_size, memb_ofs); +} + /*! Decode a TLV structure from raw data to a decoded struct, for unordered TLV IEs. * How to decode IE values and where to place them in the decoded struct, is defined by ie_coding, an array terminated * by a '{}' entry. @@ -78,11 +83,13 @@ * \param[in] iei_strs value_string array to give IEI names in error messages passed to err_cb(), or NULL. * \return 0 on success, negative on error. */ -static int osmo_gtlvs_decode_unordered(void *decoded_struct, unsigned int obj_ofs, struct osmo_gtlv_load *gtlv, - const struct osmo_gtlv_coding *ie_coding, - osmo_gtlv_err_cb err_cb, void *err_cb_data, const struct value_string *iei_strs) +static int osmo_gtlvs_decode_unordered(void *decoded_struct, size_t decoded_struct_size, + unsigned int obj_ofs, struct osmo_gtlv_load *gtlv, + const struct osmo_gtlv_coding *ie_coding, + osmo_gtlv_err_cb err_cb, void *err_cb_data, const struct value_string *iei_strs) { - void *obj = MEMB(decoded_struct, obj_ofs); + void *obj = membof(decoded_struct, decoded_struct_size, obj_ofs); + size_t obj_maxlen = decoded_struct_size - obj_ofs; const struct osmo_gtlv_coding *iec; unsigned int *multi_count_p = NULL; @@ -136,8 +143,10 @@ ie_max_allowed_count += iec->has_count ? iec->count_max : 1; /* Was this iec instance already decoded? Then skip to the next one, if any. */ - presence_flag_p = iec->has_presence_flag ? MEMB(obj, iec->presence_flag_ofs) : NULL; - multi_count_p = iec->has_count ? MEMB(obj, iec->count_ofs) : NULL; + presence_flag_p = iec->has_presence_flag ? + membof(obj, obj_maxlen, iec->presence_flag_ofs) : NULL; + multi_count_p = iec->has_count ? + membof(obj, obj_maxlen, iec->count_ofs) : NULL; if ((presence_flag_p && *presence_flag_p) || (multi_count_p && *multi_count_p >= iec->count_max)) continue; @@ -187,15 +196,16 @@ default: OSMO_ASSERT(0); } - rc = osmo_gtlvs_decode(decoded_struct, obj_ofs + memb_ofs, &inner_tlv, ordered, iec->nested_ies, - err_cb, err_cb_data, iei_strs); + rc = osmo_gtlvs_decode(decoded_struct, decoded_struct_size, + obj_ofs + memb_ofs, &inner_tlv, ordered, iec->nested_ies, + err_cb, err_cb_data, iei_strs); if (rc) RETURN_ERROR(rc, gtlv->ti, "Error while decoding TLV structure nested inside this IE"); } else { /* Normal IE, decode the specific IE data. */ if (!iec->dec_func) RETURN_ERROR(-EIO, gtlv->ti, "IE definition lacks a dec_func()"); - rc = iec->dec_func(decoded_struct, MEMB(obj, memb_ofs), gtlv); + rc = iec->dec_func(decoded_struct, membof(obj, obj_maxlen, memb_ofs), gtlv); if (rc) RETURN_ERROR(rc, gtlv->ti, "Error while decoding this IE"); } @@ -218,7 +228,7 @@ for (iec = ie_coding; !osmo_gtlv_coding_end(iec); iec++) { if (iec->has_presence_flag) continue; - multi_count_p = iec->has_count ? MEMB(obj, iec->count_ofs) : NULL; + multi_count_p = iec->has_count ? membof(obj, obj_maxlen, iec->count_ofs) : NULL; if (multi_count_p) { if (*multi_count_p < iec->count_mandatory) RETURN_ERROR(-EINVAL, iec->ti, "%u instances of this IE are mandatory, got %u", @@ -247,18 +257,22 @@ * \param[in] iei_strs value_string array to give IEI names in error messages passed to err_cb(), or NULL. * \return 0 on success, negative on error. */ -static int osmo_gtlvs_decode_ordered(void *decoded_struct, unsigned int obj_ofs, struct osmo_gtlv_load *gtlv, - const struct osmo_gtlv_coding *ie_coding, - osmo_gtlv_err_cb err_cb, void *err_cb_data, const struct value_string *iei_strs) +static int osmo_gtlvs_decode_ordered(void *decoded_struct, size_t decoded_struct_size, + unsigned int obj_ofs, struct osmo_gtlv_load *gtlv, + const struct osmo_gtlv_coding *ie_coding, + osmo_gtlv_err_cb err_cb, void *err_cb_data, const struct value_string *iei_strs) { - void *obj = MEMB(decoded_struct, obj_ofs); + void *obj = membof(decoded_struct, decoded_struct_size, obj_ofs); + size_t obj_maxlen = decoded_struct_size - obj_ofs; osmo_gtlv_load_start(gtlv); for (; !osmo_gtlv_coding_end(ie_coding); ie_coding++) { int rc; - bool *presence_flag = ie_coding->has_presence_flag ? MEMB(obj, ie_coding->presence_flag_ofs) : NULL; - unsigned int *multi_count = ie_coding->has_count ? MEMB(obj, ie_coding->count_ofs) : NULL; + bool *presence_flag = ie_coding->has_presence_flag ? + membof(obj, obj_maxlen, ie_coding->presence_flag_ofs) : NULL; + unsigned int *multi_count = ie_coding->has_count ? + membof(obj, obj_maxlen, ie_coding->count_ofs) : NULL; struct osmo_gtlv_tag_inst peek_ti; rc = osmo_gtlv_load_next_by_tag_inst(gtlv, &ie_coding->ti); @@ -308,8 +322,9 @@ default: OSMO_ASSERT(0); } - rc = osmo_gtlvs_decode(decoded_struct, obj_ofs + memb_ofs, &inner_tlv, ordered, - ie_coding->nested_ies, err_cb, err_cb_data, iei_strs); + rc = osmo_gtlvs_decode(decoded_struct, decoded_struct_size, + obj_ofs + memb_ofs, &inner_tlv, ordered, ie_coding->nested_ies, + err_cb, err_cb_data, iei_strs); if (rc) RETURN_ERROR(rc, ie_coding->ti, "Error while decoding TLV structure nested inside this IE"); @@ -317,7 +332,7 @@ /* Normal IE, decode the specific IE data. */ if (!ie_coding->dec_func) RETURN_ERROR(-EIO, ie_coding->ti, "IE definition lacks a dec_func()"); - rc = ie_coding->dec_func(decoded_struct, MEMB(obj, memb_ofs), gtlv); + rc = ie_coding->dec_func(decoded_struct, membof(obj, obj_maxlen, memb_ofs), gtlv); if (rc) RETURN_ERROR(rc, ie_coding->ti, "Error while decoding this IE"); } @@ -365,17 +380,19 @@ * \param[in] iei_strs value_string array to give IEI names in error messages passed to err_cb(), or NULL. * \return 0 on success, negative on error. */ -int osmo_gtlvs_decode(void *decoded_struct, unsigned int obj_ofs, struct osmo_gtlv_load *gtlv, bool tlv_ordered, - const struct osmo_gtlv_coding *ie_coding, - osmo_gtlv_err_cb err_cb, void *err_cb_data, const struct value_string *iei_strs) +int osmo_gtlvs_decode(void *decoded_struct, size_t decoded_struct_size, + unsigned int obj_ofs, struct osmo_gtlv_load *gtlv, bool tlv_ordered, + const struct osmo_gtlv_coding *ie_coding, + osmo_gtlv_err_cb err_cb, void *err_cb_data, const struct value_string *iei_strs) { if (!ie_coding) return -ENOTSUP; if (tlv_ordered) - return osmo_gtlvs_decode_ordered(decoded_struct, obj_ofs, gtlv, ie_coding, err_cb, err_cb_data, iei_strs); + return osmo_gtlvs_decode_ordered(decoded_struct, decoded_struct_size, obj_ofs, gtlv, ie_coding, + err_cb, err_cb_data, iei_strs); else - return osmo_gtlvs_decode_unordered(decoded_struct, obj_ofs, gtlv, ie_coding, err_cb, err_cb_data, - iei_strs); + return osmo_gtlvs_decode_unordered(decoded_struct, decoded_struct_size, obj_ofs, gtlv, ie_coding, + err_cb, err_cb_data, iei_strs); } /*! Encode a TLV structure from decoded struct to raw data. diff --git a/src/libosmo-gtlv/gtlv_gen.c b/src/libosmo-gtlv/gtlv_gen.c index 9fe4b0c..3b2b1f0 100644 --- a/src/libosmo-gtlv/gtlv_gen.c +++ b/src/libosmo-gtlv/gtlv_gen.c @@ -381,7 +381,8 @@ " %s message_type,\n" " osmo_gtlv_err_cb err_cb, void *err_cb_data, const struct value_string *iei_strs)\n" "{\n" - " return osmo_gtlvs_decode(dst, 0, gtlv, tlv_ordered, %s_get_msg_coding(message_type), err_cb, err_cb_data, iei_strs);\n" + " return osmo_gtlvs_decode(dst, sizeof(*dst), 0, gtlv, tlv_ordered, %s_get_msg_coding(message_type),\n" + " err_cb, err_cb_data, iei_strs);\n" "}\n", g_cfg->proto_name, g_cfg->proto_name, g_cfg->message_type_enum ? : "int", g_cfg->proto_name); printf("\n" diff --git a/tests/libosmo-gtlv/gtlv_dec_enc_test.c b/tests/libosmo-gtlv/gtlv_dec_enc_test.c index 63de266..a542cfa 100644 --- a/tests/libosmo-gtlv/gtlv_dec_enc_test.c +++ b/tests/libosmo-gtlv/gtlv_dec_enc_test.c @@ -396,7 +396,8 @@ .cfg = cfg, .src = { put.dst->data, put.dst->len }, }; - rc = osmo_gtlvs_decode(&parsed, 0, &load, ordered, msg_ie_coding, err_cb, &verify_err_cb_data, tag_names); + rc = osmo_gtlvs_decode(&parsed, sizeof(parsed), 0, &load, ordered, msg_ie_coding, + err_cb, &verify_err_cb_data, tag_names); printf("osmo_gtlvs_decode() rc = %d\n", rc); printf("decoded: %s\n", decoded_msg_to_str(&parsed)); if (strcmp(decoded_msg_to_str(orig), decoded_msg_to_str(&parsed))) { null-- To view, visit https://gerrit.osmocom.org/c/libosmo-pfcp/+/29040 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmo-pfcp Gerrit-Branch: master Gerrit-Change-Id: I841da89112ccf70fcd0f60eb902445fb1712eb48 Gerrit-Change-Number: 29040 Gerrit-PatchSet: 5 Gerrit-Owner: neels <nhofmeyr(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-MessageType: merged
1 0
0 0
Change in libosmo-pfcp[master]: pfcp_msg: check use count correctness
by neels 24 Aug '22

24 Aug '22
neels has submitted this change. ( https://gerrit.osmocom.org/c/libosmo-pfcp/+/29095 ) Change subject: pfcp_msg: check use count correctness ...................................................................... pfcp_msg: check use count correctness Related: CID#275414 Related: SYS#5599 Change-Id: I685855da8b6f373fdc62a3c75f7f2e0af2839617 --- M src/libosmo-pfcp/pfcp_msg.c 1 file changed, 2 insertions(+), 2 deletions(-) Approvals: fixeria: Looks good to me, approved diff --git a/src/libosmo-pfcp/pfcp_msg.c b/src/libosmo-pfcp/pfcp_msg.c index 098ffa2..ff8860a 100644 --- a/src/libosmo-pfcp/pfcp_msg.c +++ b/src/libosmo-pfcp/pfcp_msg.c @@ -455,13 +455,13 @@ { OSMO_LOG_PFCP_MSG(m, LOGL_DEBUG, "discarding\n"); if (m->ctx.session_use_count) - osmo_use_count_get_put(m->ctx.session_use_count, m->ctx.session_use_token, -1); + OSMO_ASSERT(osmo_use_count_get_put(m->ctx.session_use_count, m->ctx.session_use_token, -1) == 0); m->ctx.session_fi = NULL; m->ctx.session_use_count = NULL; m->ctx.session_use_token = NULL; if (m->ctx.peer_use_count) - osmo_use_count_get_put(m->ctx.peer_use_count, m->ctx.peer_use_token, -1); + OSMO_ASSERT(osmo_use_count_get_put(m->ctx.peer_use_count, m->ctx.peer_use_token, -1) == 0); m->ctx.peer_fi = NULL; m->ctx.peer_use_count = NULL; m->ctx.peer_use_token = NULL; null-- To view, visit https://gerrit.osmocom.org/c/libosmo-pfcp/+/29095 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmo-pfcp Gerrit-Branch: master Gerrit-Change-Id: I685855da8b6f373fdc62a3c75f7f2e0af2839617 Gerrit-Change-Number: 29095 Gerrit-PatchSet: 2 Gerrit-Owner: neels <nhofmeyr(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-MessageType: merged
1 0
0 0
Change in libosmo-pfcp[master]: gtlv: check memory bounds 1/3: encoding TLV
by neels 24 Aug '22

24 Aug '22
neels has submitted this change. ( https://gerrit.osmocom.org/c/libosmo-pfcp/+/29039 ) Change subject: gtlv: check memory bounds 1/3: encoding TLV ...................................................................... gtlv: check memory bounds 1/3: encoding TLV Introduce a maximum bound of memory access to the osmo_gtlv API. Properly pass const-ness within the gtlv implementation. This patch adds membof_const(). The following patch will add the non-const membof() equivalent, which is not needed in this patch, yet. Coverity CID#275417 drew my attention to the fact that the gtlv decoding and encoding does not actually guard against access past the end of the decoded struct. We have not yet officially released libosmo-gtlv; also, osmo-upf and osmo-hnbgw so far only use the libosmo-pfcp API, which "hides" the gtlv API. Hence just change the API without a backwards compat shim. Related: CID#275417 Related: SYS#5599 Change-Id: Id8d997c9d5e655ff1842ec69eab6c073875c6330 --- M include/osmocom/gtlv/gtlv_dec_enc.h M src/libosmo-gtlv/gtlv_dec_enc.c M src/libosmo-gtlv/gtlv_gen.c M tests/libosmo-gtlv/gtlv_dec_enc_test.c 4 files changed, 33 insertions(+), 14 deletions(-) Approvals: neels: Looks good to me, approved diff --git a/include/osmocom/gtlv/gtlv_dec_enc.h b/include/osmocom/gtlv/gtlv_dec_enc.h index 132239f..cb62fe3 100644 --- a/include/osmocom/gtlv/gtlv_dec_enc.h +++ b/include/osmocom/gtlv/gtlv_dec_enc.h @@ -186,9 +186,9 @@ const struct osmo_gtlv_coding *ie_coding, osmo_gtlv_err_cb err_cb, void *err_cb_data, const struct value_string *iei_strs); -int osmo_gtlvs_encode(struct osmo_gtlv_put *gtlv, const void *decoded_struct, unsigned int obj_ofs, - const struct osmo_gtlv_coding *ie_coding, - osmo_gtlv_err_cb err_cb, void *err_cb_data, const struct value_string *iei_strs); +int osmo_gtlvs_encode(struct osmo_gtlv_put *gtlv, const void *decoded_struct, size_t decoded_struct_size, + unsigned int obj_ofs, const struct osmo_gtlv_coding *ie_coding, osmo_gtlv_err_cb err_cb, + void *err_cb_data, const struct value_string *iei_strs); int osmo_gtlvs_encode_to_str_buf(char *buf, size_t buflen, const void *decoded_struct, unsigned int obj_ofs, const struct osmo_gtlv_coding *ie_coding, const struct value_string *iei_strs); diff --git a/src/libosmo-gtlv/gtlv_dec_enc.c b/src/libosmo-gtlv/gtlv_dec_enc.c index c3e45ea..be3002f 100644 --- a/src/libosmo-gtlv/gtlv_dec_enc.c +++ b/src/libosmo-gtlv/gtlv_dec_enc.c @@ -49,6 +49,19 @@ return RC; \ } while (0) +/* Reverse offsetof(): return the address of the struct member for a given parent struct and member offset value. + * \param parent Pointer to the parent struct, e.g. decoded_struct as passed to osmo_gtlvs_decode(). + * \param parent_size sizeof(*parent), for memory bounds checking, e.g. decoded_struct_size. + * \param memb_ofs byte offset to reach a member (e.g. osmo_gtlv_coding.memb_ofs, .presence_flag_ofs, ...). */ +static const void *membof_const(const void *parent, size_t parent_size, unsigned int memb_ofs) +{ + const uint8_t *p = parent; + const uint8_t *end = p + parent_size; + const uint8_t *memb = p + memb_ofs; + OSMO_ASSERT(memb < end); + OSMO_ASSERT(memb >= p); + return memb; +} /*! Decode a TLV structure from raw data to a decoded struct, for unordered TLV IEs. * How to decode IE values and where to place them in the decoded struct, is defined by ie_coding, an array terminated @@ -378,19 +391,22 @@ * \param[in] iei_strs value_string array to give IEI names in error messages passed to err_cb(), or NULL. * \return 0 on success, negative on error. */ -int osmo_gtlvs_encode(struct osmo_gtlv_put *gtlv, const void *decoded_struct, unsigned int obj_ofs, - const struct osmo_gtlv_coding *ie_coding, - osmo_gtlv_err_cb err_cb, void *err_cb_data, const struct value_string *iei_strs) +int osmo_gtlvs_encode(struct osmo_gtlv_put *gtlv, const void *decoded_struct, size_t decoded_struct_size, + unsigned int obj_ofs, const struct osmo_gtlv_coding *ie_coding, osmo_gtlv_err_cb err_cb, + void *err_cb_data, const struct value_string *iei_strs) { - void *obj = MEMB(decoded_struct, obj_ofs); + const void *obj = membof_const(decoded_struct, decoded_struct_size, obj_ofs); + size_t obj_maxlen = decoded_struct_size - obj_ofs; if (!ie_coding) return -ENOTSUP; for (; !osmo_gtlv_coding_end(ie_coding); ie_coding++) { int rc; - bool *presence_flag_p = ie_coding->has_presence_flag ? MEMB(obj, ie_coding->presence_flag_ofs) : NULL; - unsigned int *multi_count_p = ie_coding->has_count ? MEMB(obj, ie_coding->count_ofs) : NULL; + const bool *presence_flag_p = ie_coding->has_presence_flag ? + membof_const(obj, obj_maxlen, ie_coding->presence_flag_ofs) : NULL; + const unsigned int *multi_count_p = ie_coding->has_count ? + membof_const(obj, obj_maxlen, ie_coding->count_ofs) : NULL; unsigned int n; unsigned int i; @@ -423,13 +439,14 @@ .cfg = ie_coding->nested_ies_cfg ? : gtlv->cfg, .dst = gtlv->dst, }; - rc = osmo_gtlvs_encode(&nested_tlv, decoded_struct, obj_ofs + memb_ofs, - ie_coding->nested_ies, err_cb, err_cb_data, iei_strs); + rc = osmo_gtlvs_encode(&nested_tlv, decoded_struct, decoded_struct_size, + obj_ofs + memb_ofs, ie_coding->nested_ies, + err_cb, err_cb_data, iei_strs); if (rc) RETURN_ERROR(rc, ie_coding->ti, "Error while encoding TLV structure nested inside this IE"); } else { - rc = ie_coding->enc_func(gtlv, decoded_struct, MEMB(obj, memb_ofs)); + rc = ie_coding->enc_func(gtlv, decoded_struct, membof_const(obj, obj_maxlen, memb_ofs)); if (rc) RETURN_ERROR(rc, ie_coding->ti, "Error while encoding this IE"); } diff --git a/src/libosmo-gtlv/gtlv_gen.c b/src/libosmo-gtlv/gtlv_gen.c index fd3fbd9..9fe4b0c 100644 --- a/src/libosmo-gtlv/gtlv_gen.c +++ b/src/libosmo-gtlv/gtlv_gen.c @@ -388,7 +388,8 @@ "int %s_ies_encode(struct osmo_gtlv_put *gtlv, const union %s_ies *src,\n" " %s message_type, osmo_gtlv_err_cb err_cb, void *err_cb_data, const struct value_string *iei_strs)\n" "{\n" - " return osmo_gtlvs_encode(gtlv, src, 0, %s_get_msg_coding(message_type), err_cb, err_cb_data, iei_strs);\n" + " return osmo_gtlvs_encode(gtlv, src, sizeof(*src), 0, %s_get_msg_coding(message_type),\n" + " err_cb, err_cb_data, iei_strs);\n" "}\n", g_cfg->proto_name, g_cfg->proto_name, g_cfg->message_type_enum ? : "int", g_cfg->proto_name); printf("\n" diff --git a/tests/libosmo-gtlv/gtlv_dec_enc_test.c b/tests/libosmo-gtlv/gtlv_dec_enc_test.c index e02a2e5..63de266 100644 --- a/tests/libosmo-gtlv/gtlv_dec_enc_test.c +++ b/tests/libosmo-gtlv/gtlv_dec_enc_test.c @@ -387,7 +387,8 @@ .cfg = cfg, .dst = msgb_alloc(1024, __func__), }; - rc = osmo_gtlvs_encode(&put, (void *)orig, 0, msg_ie_coding, err_cb, &verify_err_cb_data, tag_names); + rc = osmo_gtlvs_encode(&put, (void *)orig, sizeof(*orig), 0, msg_ie_coding, + err_cb, &verify_err_cb_data, tag_names); printf("osmo_gtlvs_encode() rc = %d\n", rc); printf("%s.\n", osmo_hexdump(put.dst->data, put.dst->len)); null-- To view, visit https://gerrit.osmocom.org/c/libosmo-pfcp/+/29039 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmo-pfcp Gerrit-Branch: master Gerrit-Change-Id: Id8d997c9d5e655ff1842ec69eab6c073875c6330 Gerrit-Change-Number: 29039 Gerrit-PatchSet: 5 Gerrit-Owner: neels <nhofmeyr(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: neels <nhofmeyr(a)sysmocom.de> Gerrit-Reviewer: pespin <pespin(a)sysmocom.de> Gerrit-MessageType: merged
1 0
0 0
Change in libosmo-gprs[master]: libosmo-{csn1,gprs-rlcmac}.pc.in: add missing Requires
by fixeria 24 Aug '22

24 Aug '22
fixeria has submitted this change. ( https://gerrit.osmocom.org/c/libosmo-gprs/+/29203 ) Change subject: libosmo-{csn1,gprs-rlcmac}.pc.in: add missing Requires ...................................................................... libosmo-{csn1,gprs-rlcmac}.pc.in: add missing Requires Change-Id: I673a51fbf8ee339b20baca4998ef79e96170f21e --- M libosmo-csn1.pc.in M libosmo-gprs-rlcmac.pc.in 2 files changed, 2 insertions(+), 0 deletions(-) Approvals: Jenkins Builder: Verified laforge: Looks good to me, approved diff --git a/libosmo-csn1.pc.in b/libosmo-csn1.pc.in index c2e1ff8..b338bbe 100644 --- a/libosmo-csn1.pc.in +++ b/libosmo-csn1.pc.in @@ -6,5 +6,6 @@ Name: Osmocom CSN.1 Codec Library Description: C Utility Library Version: @VERSION@ +Requires: libosmocore Libs: -L${libdir} -losmo-csn1 Cflags: -I${includedir}/ diff --git a/libosmo-gprs-rlcmac.pc.in b/libosmo-gprs-rlcmac.pc.in index 4108c36..5424485 100644 --- a/libosmo-gprs-rlcmac.pc.in +++ b/libosmo-gprs-rlcmac.pc.in @@ -6,5 +6,6 @@ Name: Osmocom [E]GPRS RLC/MAC Library Description: C Utility Library Version: @VERSION@ +Requires: libosmocore, libosmo-csn1 Libs: -L${libdir} -losmo-gprs-rlcmac Cflags: -I${includedir}/ -- To view, visit https://gerrit.osmocom.org/c/libosmo-gprs/+/29203 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmo-gprs Gerrit-Branch: master Gerrit-Change-Id: I673a51fbf8ee339b20baca4998ef79e96170f21e Gerrit-Change-Number: 29203 Gerrit-PatchSet: 2 Gerrit-Owner: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: neels <nhofmeyr(a)sysmocom.de> Gerrit-MessageType: merged
1 0
0 0
Change in libosmo-gprs[master]: rlcmac: make logging category configurable
by fixeria 24 Aug '22

24 Aug '22
Attention is currently required from: laforge. fixeria has posted comments on this change. ( https://gerrit.osmocom.org/c/libosmo-gprs/+/29207 ) Change subject: rlcmac: make logging category configurable ...................................................................... Patch Set 1: (1 comment) File src/rlcmac/gprs_rlcmac.c: https://gerrit.osmocom.org/c/libosmo-gprs/+/29207/comment/a64ec15c_ffcd0e9e PS1, Line 38: e > are we sure that this is not globally exported by the library? If you introduce symbols with such ge […] Yes, this is not a problem. Only symbols prefixed with 'osmo_' are exposed. See 'src/rlcmac/Makefile.am', where we have: -export-symbols-regex '^osmo_'. -- To view, visit https://gerrit.osmocom.org/c/libosmo-gprs/+/29207 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmo-gprs Gerrit-Branch: master Gerrit-Change-Id: Icfef6de126304da81120f1d7b212992ead3409aa Gerrit-Change-Number: 29207 Gerrit-PatchSet: 1 Gerrit-Owner: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-CC: laforge <laforge(a)osmocom.org> Gerrit-Attention: laforge <laforge(a)osmocom.org> Gerrit-Comment-Date: Wed, 24 Aug 2022 15:44:47 +0000 Gerrit-HasComments: Yes Gerrit-Has-Labels: No Comment-In-Reply-To: laforge <laforge(a)osmocom.org> Gerrit-MessageType: comment
1 0
0 0
Change in docker-playground[master]: ttcn3-bsc: Enable OSMUX feature in osmo-bts-omldummy
by laforge 24 Aug '22

24 Aug '22
Attention is currently required from: pespin. laforge has posted comments on this change. ( https://gerrit.osmocom.org/c/docker-playground/+/29011 ) Change subject: ttcn3-bsc: Enable OSMUX feature in osmo-bts-omldummy ...................................................................... Patch Set 1: Code-Review+2 -- To view, visit https://gerrit.osmocom.org/c/docker-playground/+/29011 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: docker-playground Gerrit-Branch: master Gerrit-Change-Id: Ia402b7514b636750442d0859d5ebc3fcad67dd9f Gerrit-Change-Number: 29011 Gerrit-PatchSet: 1 Gerrit-Owner: pespin <pespin(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: osmith <osmith(a)sysmocom.de> Gerrit-Attention: pespin <pespin(a)sysmocom.de> Gerrit-Comment-Date: Wed, 24 Aug 2022 15:44:01 +0000 Gerrit-HasComments: No Gerrit-Has-Labels: Yes Gerrit-MessageType: comment
1 0
0 0
  • ← Newer
  • 1
  • ...
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • ...
  • 241
  • Older →

HyperKitty Powered by HyperKitty version 1.3.12.