diff --git a/CHANGES b/CHANGES index 8273757a2a..cbbcb21af9 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,20 @@ +6.0.0-dev.64 | 2023-02-17 17:36:40 +0100 + + * TableVal: Propagate &on_change attribute through copy() (Arne Welzel, Corelight) + + Mostly for consistency with &default, &expire_func and other attributes + being propagated through a copy(). Seems this was just missed during + the implementation and/or was never tested for. + + * GH-2793: TableVal: Propagate &ordered through copy() (Arne Welzel, Corelight) + + Copying an &ordered table or set would result in a copy that is not ordered. + This seems rather surprising behavior, so propagate the &ordered attribute. + + * GH-2690: Type/is_supported_index_type: Deal with recursive record types (Arne Welzel, Corelight) + + This plugs the issue reported in #2690, there might be more though. + 6.0.0-dev.57 | 2023-02-16 15:10:33 -0700 * Move get_relative_seq and get_segment_len to public static methods (Tim Wojtulewicz, Corelight) diff --git a/NEWS b/NEWS index 6f5acde047..0104e6a89f 100644 --- a/NEWS +++ b/NEWS @@ -20,6 +20,9 @@ Changed Functionality an appropriate callback function, log a warning and return a generic handle value based on the analyzer and connection information. +- The ``&on_change`` attribute of set and tables is propagated through ``copy()``. + + Zeek 5.2.0 ========== diff --git a/VERSION b/VERSION index d0d3b41279..fb0d313131 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -6.0.0-dev.57 +6.0.0-dev.64 diff --git a/src/Val.cc b/src/Val.cc index 97afd9c333..cef6ca7050 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -2661,6 +2661,9 @@ ValPtr TableVal::DoClone(CloneState* state) detail::timer_mgr->Add(tv->timer); } + if ( change_func ) + tv->change_func = change_func; + if ( expire_func ) tv->expire_func = expire_func; diff --git a/testing/btest/Baseline/language.expire_func-copy/output b/testing/btest/Baseline/language.expire_func-copy/output new file mode 100644 index 0000000000..f971c3d005 --- /dev/null +++ b/testing/btest/Baseline/language.expire_func-copy/output @@ -0,0 +1,54 @@ +### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63. +@XXXXXXXXXX.XXXXXX expired a +@XXXXXXXXXX.XXXXXX expired copy [orig_h=172.16.238.1, orig_p=5353/udp, resp_h=224.0.0.251, resp_p=5353/udp] +@XXXXXXXXXX.XXXXXX expired copy [orig_h=fe80::20c:29ff:febd:6f01, orig_p=5353/udp, resp_h=ff02::fb, resp_p=5353/udp] +@XXXXXXXXXX.XXXXXX expired copy [orig_h=172.16.238.1, orig_p=49658/tcp, resp_h=172.16.238.131, resp_p=80/tcp] +@XXXXXXXXXX.XXXXXX expired b +@XXXXXXXXXX.XXXXXX expired copy [orig_h=172.16.238.1, orig_p=17500/udp, resp_h=172.16.238.255, resp_p=17500/udp] +@XXXXXXXXXX.XXXXXX expired copy [orig_h=172.16.238.1, orig_p=49656/tcp, resp_h=172.16.238.131, resp_p=22/tcp] +@XXXXXXXXXX.XXXXXX expired copy [orig_h=172.16.238.131, orig_p=5353/udp, resp_h=224.0.0.251, resp_p=5353/udp] +@XXXXXXXXXX.XXXXXX expired copy [orig_h=172.16.238.131, orig_p=37975/udp, resp_h=172.16.238.2, resp_p=53/udp] +@XXXXXXXXXX.XXXXXX expired copy [orig_h=172.16.238.1, orig_p=49657/tcp, resp_h=172.16.238.131, resp_p=80/tcp] +@XXXXXXXXXX.XXXXXX expired a +@XXXXXXXXXX.XXXXXX expired [orig_h=172.16.238.131, orig_p=5353/udp, resp_h=224.0.0.251, resp_p=5353/udp] +@XXXXXXXXXX.XXXXXX expired [orig_h=172.16.238.1, orig_p=49658/tcp, resp_h=172.16.238.131, resp_p=80/tcp] +@XXXXXXXXXX.XXXXXX expired [orig_h=172.16.238.1, orig_p=5353/udp, resp_h=224.0.0.251, resp_p=5353/udp] +@XXXXXXXXXX.XXXXXX expired [orig_h=172.16.238.131, orig_p=37975/udp, resp_h=172.16.238.2, resp_p=53/udp] +@XXXXXXXXXX.XXXXXX expired [orig_h=172.16.238.1, orig_p=17500/udp, resp_h=172.16.238.255, resp_p=17500/udp] +@XXXXXXXXXX.XXXXXX expired [orig_h=fe80::20c:29ff:febd:6f01, orig_p=5353/udp, resp_h=ff02::fb, resp_p=5353/udp] +@XXXXXXXXXX.XXXXXX expired [orig_h=172.16.238.1, orig_p=49657/tcp, resp_h=172.16.238.131, resp_p=80/tcp] +@XXXXXXXXXX.XXXXXX expired [orig_h=172.16.238.1, orig_p=49656/tcp, resp_h=172.16.238.131, resp_p=22/tcp] +@XXXXXXXXXX.XXXXXX expired [orig_h=172.16.238.131, orig_p=45126/udp, resp_h=172.16.238.2, resp_p=53/udp] +@XXXXXXXXXX.XXXXXX expired [orig_h=172.16.238.1, orig_p=49659/tcp, resp_h=172.16.238.131, resp_p=21/tcp] +@XXXXXXXXXX.XXXXXX expired copy [orig_h=172.16.238.131, orig_p=45126/udp, resp_h=172.16.238.2, resp_p=53/udp] +@XXXXXXXXXX.XXXXXX expired copy [orig_h=172.16.238.1, orig_p=49659/tcp, resp_h=172.16.238.131, resp_p=21/tcp] +@XXXXXXXXXX.XXXXXX expired [orig_h=172.16.238.131, orig_p=53102/udp, resp_h=172.16.238.2, resp_p=53/udp] +@XXXXXXXXXX.XXXXXX expired [orig_h=172.16.238.131, orig_p=48621/udp, resp_h=172.16.238.2, resp_p=53/udp] +@XXXXXXXXXX.XXXXXX expired [orig_h=172.16.238.131, orig_p=33109/udp, resp_h=172.16.238.2, resp_p=53/udp] +@XXXXXXXXXX.XXXXXX expired [orig_h=172.16.238.131, orig_p=57272/udp, resp_h=172.16.238.2, resp_p=53/udp] +@XXXXXXXXXX.XXXXXX expired [orig_h=172.16.238.131, orig_p=50205/udp, resp_h=172.16.238.2, resp_p=53/udp] +@XXXXXXXXXX.XXXXXX expired [orig_h=172.16.238.131, orig_p=54304/udp, resp_h=172.16.238.2, resp_p=53/udp] +@XXXXXXXXXX.XXXXXX expired [orig_h=172.16.238.131, orig_p=44555/udp, resp_h=172.16.238.2, resp_p=53/udp] +@XXXXXXXXXX.XXXXXX expired [orig_h=172.16.238.131, orig_p=51970/udp, resp_h=172.16.238.2, resp_p=53/udp] +@XXXXXXXXXX.XXXXXX expired [orig_h=172.16.238.131, orig_p=59573/udp, resp_h=172.16.238.2, resp_p=53/udp] +@XXXXXXXXXX.XXXXXX expired [orig_h=172.16.238.131, orig_p=55515/tcp, resp_h=74.125.225.81, resp_p=80/tcp] +@XXXXXXXXXX.XXXXXX expired [orig_h=172.16.238.131, orig_p=33818/udp, resp_h=172.16.238.2, resp_p=53/udp] +@XXXXXXXXXX.XXXXXX expired [orig_h=172.16.238.131, orig_p=55368/udp, resp_h=172.16.238.2, resp_p=53/udp] +@XXXXXXXXXX.XXXXXX expired [orig_h=172.16.238.131, orig_p=37846/udp, resp_h=172.16.238.2, resp_p=53/udp] +@XXXXXXXXXX.XXXXXX expired [orig_h=172.16.238.131, orig_p=45140/udp, resp_h=172.16.238.2, resp_p=53/udp] +@XXXXXXXXXX.XXXXXX expired [orig_h=172.16.238.131, orig_p=52952/udp, resp_h=172.16.238.2, resp_p=53/udp] +@XXXXXXXXXX.XXXXXX expired copy [orig_h=172.16.238.131, orig_p=53102/udp, resp_h=172.16.238.2, resp_p=53/udp] +@XXXXXXXXXX.XXXXXX expired copy [orig_h=172.16.238.131, orig_p=48621/udp, resp_h=172.16.238.2, resp_p=53/udp] +@XXXXXXXXXX.XXXXXX expired copy [orig_h=172.16.238.131, orig_p=51970/udp, resp_h=172.16.238.2, resp_p=53/udp] +@XXXXXXXXXX.XXXXXX expired copy [orig_h=172.16.238.131, orig_p=52952/udp, resp_h=172.16.238.2, resp_p=53/udp] +@XXXXXXXXXX.XXXXXX expired copy [orig_h=172.16.238.131, orig_p=33818/udp, resp_h=172.16.238.2, resp_p=53/udp] +@XXXXXXXXXX.XXXXXX expired copy [orig_h=172.16.238.131, orig_p=37846/udp, resp_h=172.16.238.2, resp_p=53/udp] +@XXXXXXXXXX.XXXXXX expired copy [orig_h=172.16.238.131, orig_p=50205/udp, resp_h=172.16.238.2, resp_p=53/udp] +@XXXXXXXXXX.XXXXXX expired copy [orig_h=172.16.238.131, orig_p=59573/udp, resp_h=172.16.238.2, resp_p=53/udp] +@XXXXXXXXXX.XXXXXX expired copy [orig_h=172.16.238.131, orig_p=55368/udp, resp_h=172.16.238.2, resp_p=53/udp] +@XXXXXXXXXX.XXXXXX expired copy [orig_h=172.16.238.131, orig_p=55515/tcp, resp_h=74.125.225.81, resp_p=80/tcp] +@XXXXXXXXXX.XXXXXX expired copy [orig_h=172.16.238.131, orig_p=57272/udp, resp_h=172.16.238.2, resp_p=53/udp] +@XXXXXXXXXX.XXXXXX expired copy [orig_h=172.16.238.131, orig_p=44555/udp, resp_h=172.16.238.2, resp_p=53/udp] +@XXXXXXXXXX.XXXXXX expired copy [orig_h=172.16.238.131, orig_p=33109/udp, resp_h=172.16.238.2, resp_p=53/udp] +@XXXXXXXXXX.XXXXXX expired copy [orig_h=172.16.238.131, orig_p=45140/udp, resp_h=172.16.238.2, resp_p=53/udp] +@XXXXXXXXXX.XXXXXX expired copy [orig_h=172.16.238.131, orig_p=54304/udp, resp_h=172.16.238.2, resp_p=53/udp] diff --git a/testing/btest/Baseline/language.on_change-copy/output b/testing/btest/Baseline/language.on_change-copy/output new file mode 100644 index 0000000000..ec1bc1a6f9 --- /dev/null +++ b/testing/btest/Baseline/language.on_change-copy/output @@ -0,0 +1,9 @@ +### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63. +inserting +tbl_change, a, 1, 5, TABLE_ELEMENT_NEW +set_change, hi, TABLE_ELEMENT_NEW +changing +tbl_change, a, 1, 5, TABLE_ELEMENT_CHANGED +deleting +tbl_change, a, 1, 2, TABLE_ELEMENT_REMOVED +set_change, hi, TABLE_ELEMENT_REMOVED diff --git a/testing/btest/language/expire_func-copy.zeek b/testing/btest/language/expire_func-copy.zeek new file mode 100644 index 0000000000..e6e1ee31c7 --- /dev/null +++ b/testing/btest/language/expire_func-copy.zeek @@ -0,0 +1,27 @@ +# @TEST-DOC: Test that expire_func is copied (the expiration behavior of existing elements +# +# @TEST-EXEC: zeek -b -C -r $TRACES/var-services-std-ports.trace %INPUT >output +# @TEST-EXEC: btest-diff output + +function inform_me(s: table[string] of count, idx: string): interval + { + print fmt("@%.2f expired %s", time_to_double(network_time()), idx); + return 0secs; + } + +global s: table[string] of count &create_expire=1secs &expire_func=inform_me; +global scopy: table[string] of count; + +event new_connection(c: connection) + { + s[fmt("%s", c$id)] = 1; + scopy[fmt("copy %s", c$id)] = 1; + } + +event zeek_init() + { + # This copies &expire_func and &create_expire from the value s; + s["a"] = 5; + scopy = copy(s); + scopy["b"] = 5; + } diff --git a/testing/btest/language/on_change-copy.test b/testing/btest/language/on_change-copy.test new file mode 100644 index 0000000000..5eecfd6c6a --- /dev/null +++ b/testing/btest/language/on_change-copy.test @@ -0,0 +1,31 @@ +# @TEST-EXEC: zeek -b %INPUT >output +# @TEST-EXEC: btest-diff output + +module TestModule; + +function tbl_change(t: table[string, int] of count, tpe: TableChange, idxa: string, idxb: int, val: count) + { + print "tbl_change", idxa, idxb, val, tpe; + } + +function set_change(t: set[string], tpe: TableChange, idx: string) + { + print "set_change", idx, tpe; + } + +global t: table[string, int] of count &on_change=tbl_change; +global s: set[string] &on_change=set_change; + +event zeek_init() + { + local tc = copy(t); + local sc = copy(s); + print "inserting"; + tc["a", 1] = 5; + add sc["hi"]; + print "changing"; + tc["a", 1] = 2; + print "deleting"; + delete tc["a", 1]; + delete sc["hi"]; + }