Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New D-Bus API #175

Merged
merged 12 commits into from May 7, 2019
Merged

New D-Bus API #175

merged 12 commits into from May 7, 2019

Conversation

ghost
Copy link

@ghost ghost commented Apr 5, 2018

This pull request implements the API change mentioned in #173

@ghost ghost mentioned this pull request Apr 5, 2018
@ghost
Copy link
Author

ghost commented Apr 9, 2018

Ping @lathiat
Do you think this pull request is ready to be merged?

@r-mike
Copy link

r-mike commented Apr 9, 2018

nice work @Simoninator ! Looking forward to see this getting merged.

@ghost
Copy link
Author

ghost commented Apr 11, 2018

Hey @lathiat,
when do you think you'll have the time to merge this pull request?

@ghost
Copy link
Author

ghost commented Apr 16, 2018

Hey @lathiat,
any news on merging this pull request?

@lathiat
Copy link
Contributor

lathiat commented Apr 16, 2018

Planning to get on top of it this week

@ghost
Copy link
Author

ghost commented Apr 25, 2018

Probably this week?

1 similar comment
@ghost
Copy link
Author

ghost commented May 7, 2018

Probably this week?

@r-mike
Copy link

r-mike commented May 9, 2018

Any news about this?

@ghost
Copy link
Author

ghost commented May 17, 2018

Well, I think that this pull request is never going to be merged!

@ghost
Copy link
Author

ghost commented Jul 11, 2018

@lathiat, any news on merging this PR?

@ghost
Copy link
Author

ghost commented Aug 28, 2018

@lathiat could you find some time to have a look at this PR and maybe merge it?

@lathiat
Copy link
Contributor

lathiat commented Sep 14, 2018

I'd much prefer if we avoid tacking a "2" on the end of the function names (e.g. ServiceBrowserNew2). I've got a couple of ideas on how we can do that

The first thing that makes sense would be to use a versioned API. The following documents cover this topic:
http://0pointer.de/blog/projects/versioning-dbus.html
https://dbus.freedesktop.org/doc/dbus-api-design.html

Initially I got stuck on this point "Note, however, that supporting multiple interface versions simultaneously requires that object paths are versioned as well, so objects must not be put on the bus at the root path (‘/’). This is for technical reasons: signals sent from a D-Bus service have the originating service name overwritten by its unique name (e.g. com.example.MyService2 is overwritten by :1:15)."

I think? we can get away with this for our limited use case, because the interface name is always sent when calling ServiceBrowserNew and we don't need to persist what interface was used later. So at least for this specific change we can get away with it.

(for the below I specifically reference ServiceBrowserNew since that's the most common however obviously this also applies to a number of other Browsers and Resolvers so assume when I mention ServiceBrowser below that I am talking about all of them - I just found it helpful to give an explicit example)

If it's too difficult or otherwise problematic to user the interface version; I think instead we can simply change the name instead. Instead of "ServiceBrowserNew2" we can use "ServiceBrowserPrepare" which then requires an explicit call to "Start" where as "ServiceBrowserNew" would retain it's existing behavior and automatically Start as part of the creation. Besides looking less silly having "2" in the new name used permanently, it also more clearly distinguishes the difference in behavior between the two. The only slightly problem is that clients supporting the new and old server APIs would need to handle calling Prepare and then falling back if it gets back a NoMethodError.

Lastly I considered how we can fix existing clients alongside providing a new v2 API for this. We should be able to defer the start of the resolvers on the server-side for a short time to give the client time to setup it's signal receiver. This should make clients that are currently likely to fail, less likely to fail. I did a few quick tests and the best case delay for the signal handlers to be registered seems to be around 0.6 milliseconds so I don't think we'd need to delay it by much - only a few ms to handle most cases. I'd probably want to re-test this on a loaded and slower system to make sure it's not orders of magnitudes out. I think we should do this regardless of whatever other API change we end up making.

If we're worried about issues caused by the reply delays (though if we only need a few ms I am not too worried about it - if we ended up needing 100s of ms it might be more of a concern) - we could probably only do the delay for the Browsers and skip it for the Resolvers since we have directly-reply dbus methods for ServiceResolve/HostNameResolve/AddressResolve and don't need registering to a new object path. We could also obviously just skip the delay when the new version API is used and/or when Start is called - just cancel the delay and start anyway.

Which brings me full circle to what I think might be the most ideal and backwards compatible solution

(1) Create a new Avahi server interface API version, org.freedesktop.Avahi2
(2) Keep the name ServiceBrowserNew on both interfaces.

  • If they use org.freedesktop.Avahi then we maintain the existing behavior to automatically start the ServiceBrowser but we delay the start by perhaps 10ms (we can determine the most ideal value) to magically fix most existing clients in most situations - it's not an ideal fix but they were already broken so it's not any worse. To make life easy we can potentially support a specific call to Start to start it early.
  • If they use org.freedesktop.Avahi2 then we don't auto-start at all,

Lastly we have a number of avahi-core users outside of avahi-daemon and the current change will silently break those apps in that the API isn't backwards compatible. That's probably not necessary -- similar to the first suggestion above we could add a new _prepare method to go with _start and keep _new with the existing behavior to just call _prepare and then _start. Even if we don't add _prepare to the client/dbus API.

Would love feedback/discussion on each of the ideas.

@ghost
Copy link
Author

ghost commented Sep 18, 2018

Thank you @lathiat for your response.

I also think a second interface is the best option we have, as it doesn't break existing behaviour.

In my opinion, I think we should change the method names from xBrowserNew to xBrowserPrepare in the new interface. The API change would then be recognized directly in the new dbus interface and there might be no confusion.

I haven't found the time to look for a suitable timer solution to delay the replies in the old interface. Is there an implementation of a timer available, that can be used to delay the callbacks in the event/poll loop?
Edit: Well, there is obviously a timer and an example: watch-test.c 🥇

@ghost
Copy link
Author

ghost commented Sep 27, 2018

@lathiat ping

2 similar comments
@ghost
Copy link
Author

ghost commented Oct 8, 2018

@lathiat ping

@ghost
Copy link
Author

ghost commented Oct 15, 2018

@lathiat ping

@ghost
Copy link
Author

ghost commented Nov 26, 2018

@lathiat Could you please have a look at the latest commits of this pull request?

@ghost
Copy link
Author

ghost commented Dec 21, 2018

@lathiat Could you please have a look at the latest commits of this pull request?

@lathiat
Copy link
Contributor

lathiat commented Feb 22, 2019

As I read the current pull request, the general approach is

  • To add new "Prepare" and "Start" methods for most services on both the avahi-core and avahi-client APIs when using the org.freedesktop.Avahi2 interface
  • Re-implement the existing "New" methods on the old org.freedesktop.Avahi interface to call Prepare and then Start immediately
  • Implement a 10ms delay on the Start for DBUS API users to attempt to silently fix old clients

This all looks good to me, I will check a couple extra details and do some testing next week but should more or less be OK.

@lathiat
Copy link
Contributor

lathiat commented Feb 22, 2019

Will need to bump the minor version numbers for the libraries in configure.ac but I can take care of that. In theory since we keep the old New function we shouldn't have to bump the major number.

@ghost
Copy link
Author

ghost commented Mar 6, 2019

@lathiat did you find some time to check the PR?

@lathiat lathiat added this to the v0.8 milestone May 7, 2019
@lathiat lathiat merged commit 8f75a04 into avahi:master May 7, 2019
@lathiat lathiat mentioned this pull request Feb 18, 2020
rantala added a commit to nokia/avahi that referenced this pull request Feb 8, 2021
avahi-daemon is crashing when running "ping .local".
The crash is due to failing assertion from NULL pointer.
Add missing NULL pointer checks to fix it.

Introduced in avahi#175 - merge commit 8f75a04
lathiat added a commit that referenced this pull request Jun 4, 2021
Fix NULL pointer crashes such as when doing "ping .local.", originially introduced in #175 (CVE-2021-3502)

Closes: #338
anodos325 pushed a commit to truenas/avahi that referenced this pull request Mar 30, 2022
avahi-daemon is crashing when running "ping .local".
The crash is due to failing assertion from NULL pointer.
Add missing NULL pointer checks to fix it.

Introduced in avahi#175 - merge commit 8f75a04
anodos325 pushed a commit to truenas/avahi that referenced this pull request Mar 30, 2022
avahi-daemon is crashing when running "ping .local".
The crash is due to failing assertion from NULL pointer.
Add missing NULL pointer checks to fix it.

Introduced in avahi#175 - merge commit 8f75a04
evverx added a commit to evverx/avahi that referenced this pull request Dec 9, 2022
Looks like the policy wasn't updated when the Server2 interface was
introduced.

It's a follow-up to avahi#175
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants