LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
12
返回列表 发新帖
楼主: haohao_h

请教怎样的IP可设为网关?

[复制链接]
发表于 2005-8-22 15:28:49 | 显示全部楼层
Post by haohao_h
这个我知道。我只是想知道,route命令根据什么得出"Network is unreachable"错误!我猜测是去检查一下所添加的IP是不是本网段内的IP,如果不是,则返回错误!判断一个IP是不是本网段的地址,arp协议能否解析应该是一个标准吧?不知道想得对不对?



  1. if (nh->nh_gw) {
  2.                 struct fib_result res;

  3. #ifdef CONFIG_IP_ROUTE_PERVASIVE
  4.                 if (nh->nh_flags&RTNH_F_PERVASIVE)
  5.                         return 0;
  6. #endif
  7.                 if (nh->nh_flags&RTNH_F_ONLINK) {
  8.                         struct net_device *dev;

  9.                         if (r->rtm_scope >= RT_SCOPE_LINK)
  10.                                 return -EINVAL;
  11.                         if (inet_addr_type(nh->nh_gw) != RTN_UNICAST)
  12.                                 return -EINVAL;
  13.                         if ((dev = __dev_get_by_index(nh->nh_oif)) == NULL)
  14.                                 return -ENODEV;
  15.                         if (!(dev->flags&IFF_UP))
  16.                                 return -ENETDOWN;
  17.                         nh->nh_dev = dev;
  18.                         dev_hold(dev);
  19.                         nh->nh_scope = RT_SCOPE_LINK;
  20.                         return 0;
  21.                 }
  22.                 {
  23.                         struct flowi fl = { .nl_u = { .ip4_u =
  24.                                                       { .daddr = nh->nh_gw,
  25.                                                         .scope = r->rtm_scope + 1 } },
  26.                                             .oif = nh->nh_oif };

  27.                         /* It is not necessary, but requires a bit of thinking */
  28.                         if (fl.fl4_scope < RT_SCOPE_LINK)
  29.                                 [color=Red]fl.fl4_scope = RT_SCOPE_LINK;[/color]
  30.                         if ((err = fib_lookup(&fl, &res)) != 0)
  31.                                 return err;
  32.                 }
  33.                 err = -EINVAL;
  34.                 if (res.type != RTN_UNICAST && res.type != RTN_LOCAL)
  35.                         goto out;
  36.                 nh->nh_scope = res.scope;
  37.                 nh->nh_oif = FIB_RES_OIF(res);
  38.                 if ((nh->nh_dev = FIB_RES_DEV(res)) == NULL)
  39.                         goto out;
  40.                 dev_hold(nh->nh_dev);
  41.                 err = -ENETDOWN;
  42.                 if (!(nh->nh_dev->flags & IFF_UP))
  43.                         goto out;
  44.                 err = 0;
  45. out:
  46.                 fib_res_put(&res);
  47.                 return err;
  48.         }
复制代码
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表