3

I've recently bought an Ethernet to USB adapter.

When I plug this into my computer running Linux (Ubuntu in my case) , this just works automatically, and I can see an internet connection over this interface without doing anything.

What I want to know is, how is this working without installing any specific drivers?

I guess when this device is plugged in, udev sets it up, but how does it know that this USB device is actually used as an interface that connects to Ethernet and hence routes traffic over it?

Where is the code that detects and manages this? Thanks in advance

3

You already have installed the driver. It is most likely just an adapter that uses the USB-net driver. The system knows the device from the IDs in lsusb.

3

how is this working without installing any specific drivers?

The Linux kernel offered by most distros as default already contains a large number of drivers. Most Ethernet-to-USB adapters are marked in the USB descriptor as a CDC device, so one of the standard drivers (there are several variants) will do for most devices.

I guess when this device is plugged in, udev sets it up, but how does it know that this USB device is actually used as an interface that connects to Ethernet and hence routes traffic over it?

All kernel modules can contain patterns that describe for which devices they can be used. These patterns are called alias. If you do for example modinfo cdc_ether, you'll see quite a number of aliases starting with usb. The rest of the aliases matches on values in the USB descriptor.

All aliases are collected into a modules_alias file (in /lib/modules/<kernel_version>/), and then the kernel uses this file to decide which driver to activate when a new device (USB or other) is found.

The driver itself will take care of telling the kernel that it represents a device that has a representation in other kernel layers, e.g. a network interface. These upper layers then will take care of other steps, sometimes using interactions with user space, to initialize the network interface, set routes etc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.