|
|
发表于 2005-8-22 15:28:49
|
显示全部楼层
Post by haohao_h
这个我知道。我只是想知道,route命令根据什么得出"Network is unreachable"错误!我猜测是去检查一下所添加的IP是不是本网段内的IP,如果不是,则返回错误!判断一个IP是不是本网段的地址,arp协议能否解析应该是一个标准吧?不知道想得对不对?
- if (nh->nh_gw) {
- struct fib_result res;
- #ifdef CONFIG_IP_ROUTE_PERVASIVE
- if (nh->nh_flags&RTNH_F_PERVASIVE)
- return 0;
- #endif
- if (nh->nh_flags&RTNH_F_ONLINK) {
- struct net_device *dev;
- if (r->rtm_scope >= RT_SCOPE_LINK)
- return -EINVAL;
- if (inet_addr_type(nh->nh_gw) != RTN_UNICAST)
- return -EINVAL;
- if ((dev = __dev_get_by_index(nh->nh_oif)) == NULL)
- return -ENODEV;
- if (!(dev->flags&IFF_UP))
- return -ENETDOWN;
- nh->nh_dev = dev;
- dev_hold(dev);
- nh->nh_scope = RT_SCOPE_LINK;
- return 0;
- }
- {
- struct flowi fl = { .nl_u = { .ip4_u =
- { .daddr = nh->nh_gw,
- .scope = r->rtm_scope + 1 } },
- .oif = nh->nh_oif };
- /* It is not necessary, but requires a bit of thinking */
- if (fl.fl4_scope < RT_SCOPE_LINK)
- [color=Red]fl.fl4_scope = RT_SCOPE_LINK;[/color]
- if ((err = fib_lookup(&fl, &res)) != 0)
- return err;
- }
- err = -EINVAL;
- if (res.type != RTN_UNICAST && res.type != RTN_LOCAL)
- goto out;
- nh->nh_scope = res.scope;
- nh->nh_oif = FIB_RES_OIF(res);
- if ((nh->nh_dev = FIB_RES_DEV(res)) == NULL)
- goto out;
- dev_hold(nh->nh_dev);
- err = -ENETDOWN;
- if (!(nh->nh_dev->flags & IFF_UP))
- goto out;
- err = 0;
- out:
- fib_res_put(&res);
- return err;
- }
复制代码 |
|