关于Busybox对interfaces文件的解析过程

写了那么多,最后保存时却只剩这一点。。。 这博客真难用。。。

网络的启动是通过执行脚本:
/etc/init.d/networking start
脚本中调用了命令 ifup -a;

ls -l /sbin/ifup
lrwxrwxrwx 1 admin sysadmin 14 Jan 1 1970 /sbin/ifup -> ../bin/busybox

可见,该命令被集成到busbox中去了,如果要看详细的过程那只能看源码了.
找到busbox中的 ifupdown_main 函数,该函数用来执行ifup ifdown命令。

int ifupdown_main(int argc, char **argv)
{
    int (*cmds)(struct interface_defn_t *);
    struct interfaces_file_t *defn;
    llist_t *target_list = NULL;
    const char *interfaces = "/etc/network/interfaces";
    bool any_failures = 0;

    cmds = iface_down;
    if (applet_name[2] == 'u') {
        /* ifup command */
        cmds = iface_up;
    }
...
    defn = read_interfaces(interfaces);
    debug_noise("\ndone reading %s\n\n", interfaces);

    startup_PATH = getenv("PATH");
    if (!startup_PATH) startup_PATH = "";

    /* Create a list of interfaces to work on */
    if (DO_ALL) {
        target_list = defn->autointerfaces;
    } else {
        llist_add_to_end(&target_list, argv[optind]);
    }

    /* Update the interfaces */
    while (target_list) {
        llist_t *iface_list;
        struct interface_defn_t *currif;
        char *iface;
        char *liface;
        char *pch;
        bool okay = 0;
        int cmds_ret;

        iface = xstrdup(target_list->data);
        target_list = target_list->link;

        pch = strchr(iface, '=');
        if (pch) {
            *pch = '\0';
            liface = xstrdup(pch + 1);
        } else {
            liface = xstrdup(iface);
        }

        if (!FORCE) {
            llist_t *state_list = read_iface_state();
            const llist_t *iface_state = find_iface_state(state_list, iface);

            if (cmds == iface_up) {
                /* ifup */
                if (iface_state) {
                    bb_error_msg("interface %s already configured", iface);
                    goto next;
                }
            } else {
                /* ifdown */
                if (!iface_state) {
                    bb_error_msg("interface %s not configured", iface);
                    goto 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值