Show pageOld revisionsBacklinksBack to top This page is read only. You can view the source, but not change it. Ask your administrator if you think this is wrong. ===== Overview ===== Setting/detecting carrier, and the subsequent implications of setting ''net_device_ops'' ''ndo_change_carrier'' field (if any implications actually exist): ===== Normal behaviour ===== ==== Net device state ==== From ''include/linux/netdevice.h'': Net device state: <code> struct net_device { ... snip ... unsigned long state; ... snip ... </code> State flag bits for later testing: <code> enum netdev_state_t { __LINK_STATE_START, __LINK_STATE_PRESENT, __LINK_STATE_NOCARRIER, __LINK_STATE_LINKWATCH_PENDING, __LINK_STATE_DORMANT, }; </code> ==== Checking for state of carrier ==== Again from ''netdevice.h'': <code> /** * netif_carrier_ok - test if carrier present * @dev: network device * * Check if carrier is present on device */ static inline bool netif_carrier_ok(const struct net_device *dev) { return !test_bit(__LINK_STATE_NOCARRIER, &dev->state); } void netif_carrier_on(struct net_device *dev); void netif_carrier_off(struct net_device *dev); </code> ==== Test for interface running ==== Still in ''netdevice.h'': <code> /** * netif_running - test if up * @dev: network device * * Test if the device has been brought up. */ static inline bool netif_running(const struct net_device *dev) { return test_bit(__LINK_STATE_START, &dev->state); } </code> ==== Test if carrier on or off ==== From ''net/sched/sch_generic.c'': <code> /** * netif_carrier_on - set carrier * @dev: network device * * Device has detected that carrier. */ void netif_carrier_on(struct net_device *dev) { if (test_and_clear_bit(__LINK_STATE_NOCARRIER, &dev->state)) { if (dev->reg_state == NETREG_UNINITIALIZED) return; atomic_inc(&dev->carrier_up_count); linkwatch_fire_event(dev); if (netif_running(dev)) __netdev_watchdog_up(dev); } } EXPORT_SYMBOL(netif_carrier_on); /** * netif_carrier_off - clear carrier * @dev: network device * * Device has detected loss of carrier. */ void netif_carrier_off(struct net_device *dev) { if (!test_and_set_bit(__LINK_STATE_NOCARRIER, &dev->state)) { if (dev->reg_state == NETREG_UNINITIALIZED) return; atomic_inc(&dev->carrier_down_count); linkwatch_fire_event(dev); } } EXPORT_SYMBOL(netif_carrier_off); </code> ndo_change_carrier.txt Last modified: 2018/08/04 17:31by rpjday