写了那么多,最后保存时却只剩这一点。。。 这博客真难用。。。
网络的启动是通过执行脚本:
/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