Skip to content

add "resolvectl show-cache" call and IPC backend for that - #28012

Merged
poettering merged 5 commits into
systemd:mainfrom
poettering:resolvectl-dump-cache
Jun 14, 2023
Merged

poettering merged 5 commits into
systemd:mainfrom
poettering:resolvectl-dump-cache

Conversation

@poettering

Copy link
Copy Markdown
Member

This builds on the DNS query monitoring logic, and adds a simply way to dump all of resolved's caches.

Replaces: #20053 #19104

Fixes: #14796

This is identical to json_dispatch_variant() but doesn't increase the
ref counter of the variant. This is useful for taking JSON objects apart
locally without the intention to keep any component pinned for longer
than the local stack frame.
@Winterhuman

Winterhuman commented Jun 12, 2023 •

Copy link
Copy Markdown
Contributor

Would this also solve #23923?

EDIT: Looks like it does, didn't realise until now that it was a duplicate of #14796.

… all of resolved's RR caches

This adds a simple varlink call io.systemd.Resolve.Monitor.DumpCache to
the existing io.systemd.Resolve.Monitor service. It compiles a JSON
object containing the per-scope cache entries and returns it.

Replaces: systemd#20053 systemd#19104

Fixes: systemd#14796
It reverse what dns_resource_key_to_json(), i.e. turns JSON data into a
parsed DnsResourceKey object.

Ultimately this just moves a client-side local wrapper into generic
code. Nothing truly new here.
This does the usual compound init trick to get formatted strings of
stuff.

We should probably port various pieces of code over to using this.
A wrapper around the new varlink call, showing the data either in its
native JSON or in a more human readable textual form.
@poettering
poettering force-pushed the resolvectl-dump-cache branch from 992cd8c to 6050e8b Compare June 12, 2023 20:21
@poettering

Copy link
Copy Markdown
Member Author

@Winterhuman well, this really just dumps caches, it does not do statistics or so. But if this works for you then this sounds good to me.

@Winterhuman

Copy link
Copy Markdown
Contributor

It'd still give the same information, even if not presented nicely, right? If so, yeah, that works for me, a --pretty output would be appreciated if possible, but the data itself is more important

@bluca

bluca commented Jun 13, 2023

Copy link
Copy Markdown
Member

Can you add some tests to TEST-75-RESOLVED?

@bluca bluca added good-to-merge/with-minor-suggestions and removed please-review PR is ready for (re-)review by a maintainer labels Jun 13, 2023
@poettering

Copy link
Copy Markdown
Member Author

Can you add some tests to TEST-75-RESOLVED?

Is that really necessary? it's a debug tool...

@poettering

Copy link
Copy Markdown
Member Author

tbh, i am just too lazy for a debug tool. let's merge.

@bluca

bluca commented Jun 14, 2023

Copy link
Copy Markdown
Member

Can you add some tests to TEST-75-RESOLVED?

Is that really necessary? it's a debug tool...

It's a tool that has functionality, that can break accidentally. If someone else works on resolved and they don't run this manually, there's nothing checking that it won't break

@evverx

evverx commented Jun 14, 2023

Copy link
Copy Markdown
Contributor
=================================================================
==8737==ERROR: AddressSanitizer: heap-use-after-free on address 0x60c0000002eb at pc 0x7f3905aadac1 bp 0x7fff473fe250 sp 0x7fff473fe248
READ of size 1 at 0x60c0000002eb thread T0
    #0 0x7f3905aadac0 in json_variant_unref ../src/shared/json.c:864
    #1 0x40a3ef in json_variant_unrefp ../src/shared/json.h:96
    #2 0x430193 in verb_show_cache ../src/resolve/resolvectl.c:2897
    #3 0x7f3905c77d27 in dispatch_verb ../src/shared/verbs.c:103
    #4 0x4332bc in native_main ../src/resolve/resolvectl.c:3690
    #5 0x4341f6 in run ../src/resolve/resolvectl.c:3830
    #6 0x43431c in main ../src/resolve/resolvectl.c:3833
    #7 0x7f390424a50f in __libc_start_call_main (/lib64/libc.so.6+0x2750f)
    #8 0x7f390424a5c8 in __libc_start_main@GLIBC_2.2.5 (/lib64/libc.so.6+0x275c8)
    #9 0x407314 in _start (/home/vagrant/systemd/build/resolvectl+0x407314)

0x60c0000002eb is located 107 bytes inside of 120-byte region [0x60c000000280,0x60c0000002f8)
freed by thread T0 here:
    #0 0x7f39070b9388 in __interceptor_free.part.0 (/lib64/libasan.so.8+0xb9388)
    #1 0x7f3905aadca0 in json_variant_unref ../src/shared/json.c:872
    #2 0x7f3905c4e5e9 in varlink_clear_current ../src/shared/varlink.c:441
    #3 0x7f3905c4ea78 in varlink_clear ../src/shared/varlink.c:455
    #4 0x7f3905c4fc25 in varlink_destroy ../src/shared/varlink.c:489
    #5 0x7f3905c50079 in varlink_unref ../src/shared/varlink.c:495
    #6 0x40b485 in varlink_unrefp ../src/shared/varlink.h:173
    #7 0x430187 in verb_show_cache ../src/resolve/resolvectl.c:2898
    #8 0x7f3905c77d27 in dispatch_verb ../src/shared/verbs.c:103
    #9 0x4332bc in native_main ../src/resolve/resolvectl.c:3690
    #10 0x4341f6 in run ../src/resolve/resolvectl.c:3830
    #11 0x43431c in main ../src/resolve/resolvectl.c:3833
    #12 0x7f390424a50f in __libc_start_call_main (/lib64/libc.so.6+0x2750f)

previously allocated by thread T0 here:
    #0 0x7f39070ba6af in __interceptor_malloc (/lib64/libasan.so.8+0xba6af)
    #1 0x7f3905aa4aa0 in malloc_multiply ../src/basic/alloc-util.h:120
    #2 0x7f3905aac078 in json_variant_new_object ../src/shared/json.c:714
    #3 0x7f3905ac1d57 in json_parse_internal ../src/shared/json.c:3014
    #4 0x7f3905ac4dab in json_parse_with_source ../src/shared/json.c:3258
    #5 0x7f3905c4b73b in json_parse ../src/shared/json.h:233
    #6 0x7f3905c55b46 in varlink_parse_message ../src/shared/varlink.c:795
    #7 0x7f3905c590a8 in varlink_process ../src/shared/varlink.c:1155
    #8 0x7f3905c62f11 in varlink_call ../src/shared/varlink.c:1765
    #9 0x42fc9a in verb_show_cache ../src/resolve/resolvectl.c:2905
    #10 0x7f3905c77d27 in dispatch_verb ../src/shared/verbs.c:103
    #11 0x4332bc in native_main ../src/resolve/resolvectl.c:3690
    #12 0x4341f6 in run ../src/resolve/resolvectl.c:3830
    #13 0x43431c in main ../src/resolve/resolvectl.c:3833
    #14 0x7f390424a50f in __libc_start_call_main (/lib64/libc.so.6+0x2750f)

SUMMARY: AddressSanitizer: heap-use-after-free ../src/shared/json.c:864 in json_variant_unref

poettering added a commit to poettering/systemd that referenced this pull request Jun 14, 2023
@poettering

Copy link
Copy Markdown
Member Author

Fix for those memory issues → #28034

@evverx

evverx commented Jun 14, 2023

Copy link
Copy Markdown
Contributor

Thanks! Though the idea was to make a compelling argument in favor of a simple test that could just call resolvectl show-cache somewhere :-) It wouldn't make sure it works correctly but It should be enough to exercise the resolvectl/resolved codepaths under ASan on CentOS CI.

poettering added a commit that referenced this pull request Jun 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

resolvectl: Add a way to show resolved's cache entries

4 participants