Home > Operation and Maintenance > Linux Operation and Maintenance > What process is linux linkwatch?

What process is linux linkwatch?

藏色散人
Release: 2023-03-14 10:30:05
Original
1248 people have browsed it

linux linkwatch is the "link status change" process; in the Linux network protocol stack, the linkwatch module is used to notify the network card whether it can currently transmit data; the "netif_carrier_on/netif_carrier_off" function is called in the driver to notify the network status Variety.

What process is linux linkwatch?

#The operating environment of this tutorial: linux5.9.8 system, Dell G3 computer.

What is the process of linux linkwatch?

Link status change (linkwatch)

In the Linux network protocol stack, the linkwatch module is used to notify the network card whether data transmission is currently possible.

The netif_carrier_on/netif_carrier_off function is called in the driver to notify network status changes.

Main functions:

  • Enable/disable flow control of the TX queue Function

  • Initiate netlink message NETDEV_CHANGE to user space

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;
                   linkwatch_fire_event(dev);
                   if (netif_running(dev))
                            __netdev_watchdog_up(dev);
         }
}
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 ;
                   linkwatch_fire_event(dev);
         }
}
linwatch模块,只需要知道状态改变了,不需要知道具体是on还是off
void linkwatch_fire_event(struct net_device *dev)
{
   /*判断是否为紧急事件, 内核规定两次事件的间隔至少为1个HZ*/
         bool urgent = linkwatch_urgent_event(dev);
         if (!test_and_set_bit(__LINK_STATE_LINKWATCH_PENDING, &dev->state)) {
                   linkwatch_add_event(dev);//把dev添加到lweventlist链表
         } else if (!urgent)
                   return;
   /*调用工作队列linkwatch_event */
         linkwatch_schedule_work(urgent);
}
 
static void __linkwatch_run_queue(int urgent_only)
{
         struct net_device *dev;
         LIST_HEAD(wrk);
         while (!list_empty(&wrk)) {
                   dev = list_first_entry(&wrk, struct net_device, link_watch_list);
                   list_del_init(&dev->link_watch_list);
      /*判断是否只执行紧急事件 */
                   if (urgent_only && !linkwatch_urgent_event(dev)) {
                            list_add_tail(&dev->link_watch_list, &lweventlist);
                            continue;
                   }       
                   spin_unlock_irq(&lweventlist_lock);
                   linkwatch_do_dev(dev);
                   spin_lock_irq(&lweventlist_lock);
         }
         if (!list_empty(&lweventlist)){
                   linkwatch_schedule_work(0);
         }
         spin_unlock_irq(&lweventlist_lock);
}
 
static void linkwatch_do_dev(struct net_device *dev)
{
         rfc2863_policy(dev);
         if (dev->flags & IFF_UP) {
                   if (netif_carrier_ok(dev))
                            dev_activate(dev);//启动tx队列流量控制功能
                   else
                            dev_deactivate(dev);//禁止tx队列流量控制功能
                   netdev_state_change(dev);//发起Netlink事件:NETDEV_CHANGE
         }
         dev_put(dev);
}
Copy after login

Related recommendations: "Linux Video Tutorial

The above is the detailed content of What process is linux linkwatch?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template