vusb-daemon handles USB device passthrough.
It listens to dbus and udev for user, toolstack and device events.
Then, according to the database-stored policy, it uses the vusb dom0 kernel module to trigger USB passthrough action.
vusb-daemon runs a udev monitor to get notified of device activity.
It also uses udev to get more information about new devices.
vusb-daemon talks to:
vusb-daemon exposes device information and methods on dbus, to interact with the UI and the toolstack.
It is possible to test it using xec -s com.citrix.xenclient.usbdaemon
. NOTE: This call is blocked by SELinux policy, to call this run setenforce 0
to enter SELinux permissive mode.
The policy is stored in the main database, under /usb-rules
.
It can be dumped using db-ls /usb-rules
.
vusb-daemon uses db.c to access it. db.c has been written in such a way that it should be re-usable by other projects, like a command line policy manager.
Each rule is written under /usb-rules/. Low number == high priority.
Rules are made of:
A device is a list of sub-nodes, chosen from:
Shortcuts
sysfs Nodes
Example: To deny all USB 3.0 devices:
"usb-rules": {
"1001": {
"description": "Deny USB 3.0 to all VMs",
"command": "deny",
"device": {
"sysattr": {
"version" = "3.00"
}
}
}
...
}
udev Properties
Example: To allow all Toshiba devicesby manufacturer name (as opposed to vendor ID):
"usb-rules": {
"1001": {
"description": "Allow Toshiba to all VMs",
"command": "deny",
"device": {
"property": {
"ID_VENDOR" = "Toshiba"
}
}
}
...
}
In json, taken from /config/db
:
"usb-rules": {
"9900": {
"description": "Deny keyboard passthrough to all VMs",
"command": "deny",
"device": {
"keyboard": "1"
}
},
"9999": {
"description": "Allow everything else",
"command": "allow"
}
}
Rule 9900 blocks keyboard passthrough and rule 9999 allows everything, effectively switching the default behavior from "deny" to "allow".
Some legacy flags are still supported by the vusb-daemon, even it they should probably be moved to the policy in the database.
The previous vusb-daemon used to check if VMs had tools installed before allowing plugging devices to them. That requirement doesn't make much sense so it got removed. Now one can install only the USB drivers in a VM and still get USB passthrough.
If this ends up begin a requirement, something like a "tools-installed" VM property could be added to the policy.
When a device is set to be "Always assigned" to a VM, vusb-daemon creates an "always" rule, and puts it at the beginning of the policy, using the highest available priority number below 1001. This means that those rules will have a high priority, which is assumed is what the user wants...
For that reason, manually added rules should have a priority higher than 1000.
Rules can be manually added using db-write
(recommended) or by editing /config/db
(in that case, don't forget to run killall -HUP dbd
after).
As mentioned above, using priority numbers above 1000 is highly recommended.