Ethernet to USB adapter on Linux

7,300

Solution 1

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.

Solution 2

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.

Share:
7,300

Related videos on Youtube

Engineer999
Author by

Engineer999

Updated on September 18, 2022

Comments

  • Engineer999
    Engineer999 over 1 year

    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