Skip to content

Conversation

@p-luke
Copy link
Contributor

@p-luke p-luke commented May 16, 2024

Netlink fds are not passed to the user callback for external loop adoption, because vhost and its protocols are not yet in place when rops_pt_init_destroy_netlink() gets called during context creation. As a consequence, netlink fds are not polled, leading to outdated/missing routing table entries in the library, expecially when application starts at the same time of network itnerfaces. A complex rework would be required to support this, so for now disable netlink when external poll is needed.

This is the function calls sequence:

  • lws_create_context() calls LWS_ROPS_pt_init_destroy() for every available role (so netlink too, on Linux)
  • rops_pt_init_destroy_netlink() creates the netlink fd, and passes it to lws_wsi_inject_to_loop() , which then passes it to __insert_wsi_socket_into_fds()
  • here, if LWS_WITH_EXTERNAL_POLL is defined, normally the fd is passed to LWS_CALLBACK_ADD_POLL_FD callback - but wsi->a.vhost is not yet inited at this point - so fd is not passed to the application, which gets no chance of adding it to its own poll loop

So, netlink socket ends up being not polled, thus all the library logic on routing table entries is disrupted.
For this reason, if application needs LWS_WITH_EXTERNAL_POLL support, unfortunately it is better to disable netlink on Linux, too.

…bled.

Netlink fds are not passed to the user callback for external loop adoption, because vhost and its protocols are not yet in place when rops_pt_init_destroy_netlink() gets called during context creation. As a consequence, netlink fds are not polled, leading to outdated/wrong routing table entries in the library.
A complex rework would be required to support this, so for now disable netlink when external poll is needed.
@lws-team
Copy link
Member

Thanks for the explanation... isn't it better to solve this by finally removing EXTERNAL_POLL?

There's support for custom eventlib stuff now that should be better in every way.

Or can't netlink be initialized later when EXTERNAL_POLL can handle it?

@p-luke
Copy link
Contributor Author

p-luke commented May 20, 2024

Or can't netlink be initialized later when EXTERNAL_POLL can handle it?

I was trying to analyze lws_create_context() execution flow to see how to achieve this, but I am not yet there...
Netlink stuff, being a role, is inited along all other roles way before wsi->a.vhost is in place, and I do not know if moving all roles init after that can break something else (maybe there is code in between which requires roles to be inited...?), I have not yet analyzed all the context creation related code.

@lws-team
Copy link
Member

Maybe it's enough if the Netlink role sees that you're using EXTERNAL_POLL and defers initializing it until you do it manually after the start of EXTERNAL_POLL

@p-luke
Copy link
Contributor Author

p-luke commented May 29, 2024

I am not sure on how to achieve this deferred initialization. Netlink role gets called via lws_rops_t callbacks, and the socket creation is performed in pt_init_destroy. The role has not other callbacks set (apart from handle_POLLIN), so how could I manually call netlink to create the socket?

@lws-team lws-team force-pushed the main branch 4 times, most recently from fd918f2 to 207d634 Compare January 22, 2025 08:44
@lws-team lws-team force-pushed the main branch 20 times, most recently from dd2700b to f96cb33 Compare April 25, 2025 06:18
@lws-team lws-team force-pushed the main branch 3 times, most recently from a0c73c1 to 7c9d4bc Compare September 9, 2025 14:28
@lws-team lws-team force-pushed the main branch 12 times, most recently from a800d4a to 7f2f518 Compare September 18, 2025 08:03
@lws-team lws-team force-pushed the main branch 3 times, most recently from baf4897 to 0c7fa23 Compare October 1, 2025 14:55
@lws-team lws-team force-pushed the main branch 3 times, most recently from 2b74af4 to 5f77374 Compare October 12, 2025 10:02
@lws-team lws-team force-pushed the main branch 5 times, most recently from a677221 to 0c67054 Compare October 24, 2025 16:36
@lws-team lws-team force-pushed the main branch 2 times, most recently from f5fa440 to 278c671 Compare November 6, 2025 08:28
@lws-team lws-team force-pushed the main branch 2 times, most recently from 580b993 to c837e3f Compare December 29, 2025 15:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants