Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
| ipp_up_and_iff_running [2018/08/25 16:09] – [Flags] rpjday | ipp_up_and_iff_running [2018/08/27 11:03] (current) – [net/core/dev_ioctl.c] rpjday | ||
|---|---|---|---|
| Line 8: | Line 8: | ||
| ===== Flags ===== | ===== Flags ===== | ||
| + | |||
| + | Issues: | ||
| + | |||
| + | * Is '' | ||
| + | * Can we use '' | ||
| + | * Understand actual meaning of " | ||
| From '' | From '' | ||
| < | < | ||
| + | /** | ||
| + | * enum net_device_flags - &struct net_device flags | ||
| + | * | ||
| + | * These are the &struct net_device flags, they can be set by drivers, the | ||
| + | * kernel and some can be triggered by userspace. Userspace can query and | ||
| + | * set these flags using userspace utilities but there is also a sysfs | ||
| + | * entry available for all dev flags which can be queried and set. These flags | ||
| + | * are shared for all types of net_devices. The sysfs entries are available | ||
| + | * via / | ||
| + | * are annotated below, note that only a few flags can be toggled and some | ||
| + | * other flags are always preserved from the original net_device flags | ||
| + | * even if you try to set them via sysfs. Flags which are always preserved | ||
| + | * are kept under the flag grouping @IFF_VOLATILE. Flags which are volatile | ||
| + | * are annotated below as such. | ||
| + | * | ||
| + | * You should have a pretty good reason to be extending these flags. | ||
| + | * | ||
| + | * @IFF_UP: interface is up. Can be toggled through sysfs. | ||
| + | * @IFF_BROADCAST: | ||
| + | * @IFF_DEBUG: turn on debugging. Can be toggled through sysfs. | ||
| + | * @IFF_LOOPBACK: | ||
| + | * @IFF_POINTOPOINT: | ||
| + | * @IFF_NOTRAILERS: | ||
| + | | ||
| + | * @IFF_RUNNING: | ||
| + | * @IFF_NOARP: no ARP protocol. Can be toggled through sysfs. Volatile. | ||
| + | * @IFF_PROMISC: | ||
| + | * @IFF_ALLMULTI: | ||
| + | | ||
| + | * @IFF_MASTER: | ||
| + | * @IFF_SLAVE: slave of a load balancer. Volatile. | ||
| + | * @IFF_MULTICAST: | ||
| + | * @IFF_PORTSEL: | ||
| + | * @IFF_AUTOMEDIA: | ||
| + | * @IFF_DYNAMIC: | ||
| + | | ||
| + | * @IFF_LOWER_UP: | ||
| + | * @IFF_DORMANT: | ||
| + | * @IFF_ECHO: echo sent packets. Volatile. | ||
| + | */ | ||
| + | |||
| enum net_device_flags { | enum net_device_flags { | ||
| /* for compatibility with glibc net/if.h */ | /* for compatibility with glibc net/if.h */ | ||
| Line 41: | Line 88: | ||
| ===== operstates.txt ===== | ===== operstates.txt ===== | ||
| + | |||
| + | Administrative versus operational state: | ||
| < | < | ||
| Line 60: | Line 109: | ||
| a RFC2863 compatible state that is derived from these flags, a policy, | a RFC2863 compatible state that is derived from these flags, a policy, | ||
| and changeable from userspace under certain rules. | and changeable from userspace under certain rules. | ||
| + | </ | ||
| + | |||
| + | ===== Flags ===== | ||
| + | |||
| + | ==== Source ==== | ||
| + | |||
| + | '' | ||
| + | |||
| + | ==== Up and running ==== | ||
| + | |||
| + | 4163: | ||
| + | |||
| + | < | ||
| + | enp3s0: flags=4163< | ||
| + | inet 192.168.0.15 | ||
| + | inet6 fd00: | ||
| + | inet6 fe80:: | ||
| + | ether 2c: | ||
| + | RX packets 81232 bytes 92092778 (87.8 MiB) | ||
| + | RX errors 0 dropped 0 overruns 0 frame 0 | ||
| + | TX packets 36768 bytes 9024553 (8.6 MiB) | ||
| + | TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 | ||
| + | </ | ||
| + | |||
| + | ==== Down ==== | ||
| + | |||
| + | 4098: | ||
| + | |||
| + | < | ||
| + | enp3s0: flags=4098< | ||
| + | inet 192.168.0.15 | ||
| + | ether 2c: | ||
| + | RX packets 81290 bytes 92110209 (87.8 MiB) | ||
| + | RX errors 0 dropped 0 overruns 0 frame 0 | ||
| + | TX packets 36836 bytes 9042100 (8.6 MiB) | ||
| + | TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 | ||
| + | </ | ||
| + | |||
| + | ==== Up again ==== | ||
| + | |||
| + | UP, shortly followed by RUNNING: | ||
| + | |||
| + | < | ||
| + | enp3s0: flags=4163< | ||
| + | inet 192.168.0.15 | ||
| + | inet6 fd00: | ||
| + | inet6 fe80:: | ||
| + | ether 2c: | ||
| + | RX packets 1268514 | ||
| + | RX errors 0 dropped 0 overruns 0 frame 0 | ||
| + | TX packets 396222 | ||
| + | TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 | ||
| + | </ | ||
| + | |||
| + | ==== Up, then disconnected ==== | ||
| + | |||
| + | 4099: | ||
| + | |||
| + | < | ||
| + | enp3s0: flags=4099< | ||
| + | inet 192.168.0.15 | ||
| + | inet6 fd00: | ||
| + | inet6 fe80:: | ||
| + | ether 2c: | ||
| + | RX packets 81318 bytes 92115343 (87.8 MiB) | ||
| + | RX errors 0 dropped 0 overruns 0 frame 0 | ||
| + | TX packets 36917 bytes 9052750 (8.6 MiB) | ||
| + | TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 | ||
| + | </ | ||
| + | |||
| + | ===== dev_get_flags() ===== | ||
| + | |||
| + | ==== net/ | ||
| + | |||
| + | This is how '' | ||
| + | |||
| + | < | ||
| + | /* | ||
| + | | ||
| + | */ | ||
| + | static int dev_ifsioc_locked(struct net *net, struct ifreq *ifr, unsigned int cmd) | ||
| + | { | ||
| + | int err; | ||
| + | struct net_device *dev = dev_get_by_name_rcu(net, | ||
| + | |||
| + | if (!dev) | ||
| + | return -ENODEV; | ||
| + | |||
| + | switch (cmd) { | ||
| + | case SIOCGIFFLAGS: | ||
| + | ifr-> | ||
| + | return 0; | ||
| + | </ | ||
| + | |||
| + | ==== net/ | ||
| + | |||
| + | Volatile flags are supported via RFC2863 operstates. | ||
| + | |||
| + | < | ||
| + | /** | ||
| + | | ||
| + | | ||
| + | * | ||
| + | * Get the combination of flag bits exported through APIs to userspace. | ||
| + | */ | ||
| + | unsigned int dev_get_flags(const struct net_device *dev) | ||
| + | { | ||
| + | unsigned int flags; | ||
| + | |||
| + | flags = (dev-> | ||
| + | IFF_ALLMULTI | | ||
| + | IFF_RUNNING | | ||
| + | IFF_LOWER_UP | | ||
| + | IFF_DORMANT)) | | ||
| + | (dev-> | ||
| + | IFF_ALLMULTI)); | ||
| + | |||
| + | if (netif_running(dev)) { | ||
| + | if (netif_oper_up(dev)) | ||
| + | flags |= IFF_RUNNING; | ||
| + | if (netif_carrier_ok(dev)) | ||
| + | flags |= IFF_LOWER_UP; | ||
| + | if (netif_dormant(dev)) | ||
| + | flags |= IFF_DORMANT; | ||
| + | } | ||
| + | |||
| + | return flags; | ||
| + | } | ||
| + | EXPORT_SYMBOL(dev_get_flags); | ||
| </ | </ | ||