hotplug脚本调用

hotplug脚本调用

hotplug调用流程

最终调用hotplug脚本在netifd interface-event.c:

    char *eventnames[] = {
  "ifdown", "ifup", "ifupdate"};
    setenv("ACTION", eventnames[event], 1);
    setenv("INTERFACE", ifname, 1);
    if (device)
        setenv("DEVICE", device, 1);
    argv[0] = hotplug_cmd_path;
    argv[1] = "iface";
    argv[2] = NULL;
    execvp(argv[0], argv);
    exit(127);

netifd’s cycle appears to be:

  1. Start some proto-specific mechanism for acquiring interface configuration. For DHCP this is driven by proto-shell.c, which spawns /lib/netifd/proto/dhcp.sh, which is a thin wrapper around udhcpc. udhcpc is long-lived and set up to call back into /lib/netifd/dhcp.script for dhcp events:
      833 root      1488 S    udhcpc -p /var/run/udhcpc-eth1.pid -s /lib/netifd/dhcp.script -f -t 0 -i eth1 -C
     
  2. dhcp.script packages variables from udhcpc into json and end up doing ‘ubus call network.interface notify_proto ’. This in turn is handled by netifd in proto-shell.c, in proto_shell_notify. Action is 0, which leads into proto_shell_update_link.

  3. proto_shell_update_link delivers an event to the interface through state->proto.proto_event (interface_proto_cb), which calls interface_event, which leads to the snippet above, calling into /sbin/hotplug-call with ACTION=ifupdate.

代码实现

内核

代码路径:linux/drivers/net/raeth/raether.c
内核,网口down/up 在raether.c中监测寄存器来判断网口的插拔,当出现WAN口插拔事件之后,向udhcpc发送信号release/renew

#if defined(CONFIG_RALINK_MT7621) || defined(CONFIG_ARCH_MT7623)
    fp = filp_open("/var/run/udhcpc-eth1.pid", O_RDONLY, 0);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值