Skip to content

resolvconf(8) compat interface - #8296

Merged
keszybz merged 2 commits into
systemd:masterfrom
poettering:resolvconf
Mar 12, 2018
Merged

keszybz merged 2 commits into
systemd:masterfrom
poettering:resolvconf

Conversation

@poettering

Copy link
Copy Markdown
Member

No description provided.

@keszybz keszybz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great in general. I had some grumbles about the docs and the structure of the code though.

Please add the resolvconf symlink like we do with systemd-umount, and how #8300 now does with systemctl.

Comment thread src/resolve/resolved-resolv-conf.c Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to include a line number here.

Comment thread src/resolve/resolve-tool.c Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be a separate file... Let's try not to grow another systemctl.c. Even even this doesn't happen now, the interface should be accessible so that we can write unittests for parsing.

Comment thread man/systemd-resolve.xml Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Frankly, I think there's no choice but to provide a brief summary what these options do. Referring to a "competing" program, especially one that has many semi-compatible implementations, is just too vague for the users. Note that this is only for "supported" options, "ignored" and "unsupported" options below do not have to be explained.

Comment thread man/systemd-resolve.xml Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this also needs an entry in the synopsis.

@keszybz keszybz added the reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks label Feb 27, 2018
Comment thread src/shared/uid-range.c Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to include alloc-util.h

@yuwata yuwata added the ci-fails/needs-rework 🔥 Please rework this, the CI noticed an issue with the PR label Feb 28, 2018
@poettering poettering changed the title resolvconf(8) compat interface, reallocarray() cocinellication and other minor stuff resolvconf(8) compat interface, reallocarray() coccinellication and other minor stuff Feb 28, 2018
@poettering

Copy link
Copy Markdown
Member Author

OK, force pushed a new version. PTAL. All issues adressed, and one trivial (though unrelated) commit added on top.

@poettering poettering removed ci-fails/needs-rework 🔥 Please rework this, the CI noticed an issue with the PR reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks labels Feb 28, 2018
@yuwata

yuwata commented Feb 28, 2018

Copy link
Copy Markdown
Member

Thank you for adding the comment about telinit.
lgtm now.

Comment thread man/systemd-resolve.xml Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you consider supporting -l [interface]? The information and logic to support it is easily available, and so it wouldn't be cumbersome to support. This is used by wg-quick(8) to (optionally) save the active runtime configuration when deleting the interface.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think providing the API for 3rd party tools to hook into is priority, and I figure that's mostly -a and -d. OTOH -l is mostly user-facing, and we do have "systemd-resolve --status" covering that already (and without the skewedness because resolved's and resolvconf's concept don't match 100%).

That said, I think we can totally add support for that later on, if people want that (and apparently they do, as you have just shown). But I think it's just the cherry on top, and not not necessary to make the basic functionality work.

Or to say this differently: a PR adding support for that on top of this once it's merged would be very welcome!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed the other program supports many things too, but the point of having resolvconf in the first place is to maintain compatibility with scripts, just like shutdown and the rest. wg-quick(8) won't be growing support for a cornucopia of different DNS management invocations, preferring instead to use a single API (resolvconf). It's just a shell script after all.

You can see its usage of -l here: https://git.zx2c4.com/WireGuard/tree/src/tools/wg-quick.bash#n194

But I think it's just the cherry on top, and not necessary to make the basic functionality work.

It's certainly required to make wg-quick(8) work, rather than being a mere cherry.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note that "-l" is only supported by openresolv, btw, it's not available in the original Debian implementation.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, that script uses -m 0 -x btw, which isn't in the debian implementation. It appears the script only works with openresolv.

What confuses me a bit is this line in that script:

resolvconf -a "tun.$INTERFACE" -m 0 -x

The interface argument is reversed: According to the manpages you are supposed to specified the interface first, and the protocol second. i.e. it should be $INTERFACE.tun and not tun.$INTERFACE. (Oh, and I think it would be more expressive if you'd use "wguard or so instead of "tun" as protocol ID).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FreeBSD uses openresolv, by the way.

I think it's based on it, yes, but it deviates, has new options and the file locations are all different.

@zx2c4 zx2c4 Feb 28, 2018 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's based on it, yes,

That man page you linked explicitly mentions openresolv, anyhow.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are they? i just checked out the resolvconf upstream git repo, and if i run the command there

I'm reading this source: https://anonscm.debian.org/cgit/resolvconf/resolvconf.git/tree/bin/resolvconf

The key is to make -x the second argument, not the first. Then you avoid the error message and have future compatibility with openresolv.

@zx2c4 zx2c4 Feb 28, 2018 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The compat implementation of this PR also expects that the interface name is valid. It will generate an error if it isn't.

Ahh, okay, that could be problematic, then, unless what you're saying about IF_EXCLUSIVE is actually true in current versions, in which case, I wouldn't need the tun. prefix hack. I can't find that, though:

zx2c4@thinkpad /tmp $ git clone https://anonscm.debian.org/cgit/resolvconf/resolvconf.git
Cloning into 'resolvconf'...
remote: Counting objects: 3635, done.
remote: Compressing objects: 100% (1474/1474), done.
remote: Total 3635 (delta 2510), reused 3044 (delta 2125)
Receiving objects: 100% (3635/3635), 598.85 KiB | 3.09 MiB/s, done.
Resolving deltas: 100% (2510/2510), done.
zx2c4@thinkpad /tmp/resolvconf $ grep -ri IF_EXCLUSIVE
zx2c4@thinkpad /tmp/resolvconf $ 

That seems to be, rather, an openresolv option, not a Debian one.


Anyway, I've just committed this: https://git.zx2c4.com/WireGuard/commit/?id=92320b60b6d85dc13a1932079366465569683b1e So hopefully the strict naming requirements of systemd should now be satisfied.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note that "-l" is only supported by openresolv, btw, it's not available in the original Debian implementation.

https://git.zx2c4.com/WireGuard/commit/?id=6ed55dec679b2aaa36b4170632cdc510475fc310

So, it might be a good idea for systemd to support the modern interface for this instead of the old Debian cruft.

Comment thread src/udev/udev-rules.c Outdated

@zx2c4 zx2c4 Feb 28, 2018 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really important, but I'm interested why you went with malloc_multiply as the name instead of the better known mallocarray (from OpenBSD etc)?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reallocarray() was added recently to glibc, mallocarray() still isn't available there. C namespacing is a mess, but so far we tried to stay away from names that libcs currently don't provide but might very likely support later, though possibly in a slightly different way than the other platforms which inspired it. We do that mostly as a safety measure so that things don't start breaking when these things are added, and our implementation clashes with the libc one.

As soon as something gets added to glibc we however then rework our stuff to make use of it, which just happened in the case of reallocarray(), see #8279.

Or to say this differently: as soon as glibc made its mind up, and added the call we'll rework our stuff and use the exact same prototype as compat kludge for older distributions.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, that's a really good idea.

@keszybz keszybz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's OK to start with an implementation that is incomplete matches some version of the software. It's funny how this was supposed to be a unifying interface. It should be fairly easy to add support for other options once the basic thing is in place.

Comment thread meson.build Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That doesn't make much sense to cross from rootsbindir to bindir. resolvconf is in /sbin on Ubuntu/Debian, sp the second argument has to use rootsbindir. We can either say "who cares" and live with the fact that we'll have a dangling symlink until /usr is mounted, or move systemd-resolve to /bin. I don't care either way, maybe people who use split-usr can chime in?

@mbiebl, @martinpitt, does /sbin/resolvconf need to be usable before /usr is mounted?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@keszybz on the systems that boot with systemd, our initramfs insures that /usr is mounted. So no. But there are things that use resolvconf state in the initramfs and hope that it will be transfered into the root filesystem, post initramfs. I have not yet checked, but it would be extra nice if there is e.g. path&service unit combos that process /run/resolvconf/interface/$IFACE files on boot. I didn't read all of the pull request, to check if this is done or not.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, we only provide command line compat with openresolv and debian's resolvconf, nothing else.

that said, if you run resolved in the initrd (which should be safe now) it should pass on its data 1:1 without isses to the main system

Comment thread src/resolve/resolvconf-compat.c Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be nice to keep this line in the same order as the cases below… That makes it easier to verify that they match.

Comment thread man/systemd-resolve.xml Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll probably need to make this optional, since people install systemd into their root file system and might not want to overwrite their installed resolvconf. But this can be done later.

Comment thread src/systemctl/systemctl.c Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I'm dumb, but I don't think I'd understand what is going on based on this comment.
What you wrote in #8305 is much clearer:

On SysV "telinit" was the official command to communicate with PID 1, but "init" would redirect itself to "telinit" if called with PID != 1. We follow the same logic here still, though we add one level of indirection, as we implement "telinit" in "systemctl". Hence, for us if you invoke "init" you get "systemd", but it will execve() "systemctl" immediately with argv[] unmodified if PID is != 1. If you invoke "telinit" you directly get "systemctl". In both cases we shall do the same thing, which is why we do strstr(p_i_s_n, "init") here, as a quick way to match both.

Also see redirect_telinit() in src/core/main.c.

This turns resolve-tool into a multi-call binary. When invoked as
"resolvconf" it provides minimal compatibility with the resolvconf(8)
tool of various distributions (and FreeBSD as it appears).

This new interface understands to varying degrees features of the two
major implementations of resolvconf(8): Debian's original one and
"openresolv". Specifically:

Fully supported:

        -a -d (supported by all implementations)
        -f    (introduced by openresolv)

Somewhat supported:

        -x    (introduced by openresolv, mapped to a '~.' domain entry)

Unsupported and ignored:

        -m -p (introduced by openresolv, not really necessary for us)

Unsupported and resulting in failure:
        -u    (supported by all other implementations)
        -I -i -l -R -r -v -V
              (all introduced by openresolv)
        --enable-updates --disable-updates --updates-are-enabled
              (specific to Debian's implementation)

Of course, resolvconf(8) is a tool with multiple backends, in our
implementation systemd-resolved is the only backend.

Fixes: systemd#7202
@poettering

Copy link
Copy Markdown
Member Author

I force pushed a new version now. It drops all patches that were already merged in the meantime, thus only leaving resolvconf(8)-related patches in place.

I already reordered the getopt() string, as requested. No other changes, in particular none regarding the location of systemd-resolve and its symlink, as the situation is not clear yet.

So, my thinking regarding the precise location of the symlink was purely focussed on using the same path that upstream openresolv/debian's resolvconf use, nothing else. We are explicitly not supporting boots with /usr split off and not mounted in the initrd anyway, hence I don't think linking from /sbin to /usr/bin is a problem. People who still care about that are not using systemd anyway

@yuwata yuwata changed the title resolvconf(8) compat interface, reallocarray() coccinellication and other minor stuff resolvconf(8) compat interface Mar 3, 2018
@yuwata yuwata removed the coccinelle label Mar 3, 2018
@keszybz
keszybz merged commit 99eae07 into systemd:master Mar 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

5 participants