Can application in LXC listen to the netlink message from the host kernel?

I have one requirement to have the application running in the LXC to get the event for host kernel to get the notification for some events, such as key pressed.
Currently the host kernel driver is publishing the event via the netlink interface, I’m wondering if the application in the LXC also can use the netlink to receive such notification?
Please someone help on this for I’m pretty new to LXC.


Normally, no, netlink events are namespaced by the network namespace.
@brauner has done some work that would allow you to directly send events to the container’s namespace, but that’d require a kernel change (which hasn’t been merged yet) as well as extra userspac code to send such an event.

A probably easier alternative for you would be to bind-mount /proc/1/ns/net from the host into the container, you could then have your software in the container use setns against that file descriptor to attach to the host’s network namespace, allowing it to see all hosts uevents.

The obvious downside to this is that the container would then be able to do anything it wants against the host’s network namespace too, so depending on your security concerns, that may be a problem.

Thanks @stgraber.
BTW, as for the work you mentioned by @brauner, will it be partial of official linux kernel in the future?

Yes, if all goes well, it should be merged in the next dev cycle, so probably in 4.17 or so.

Great, thank you @stgraber for the help.