Chinaunix首页 | 论坛 | 博客
  • 博客访问: 419753
  • 博文数量: 124
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 872
  • 用 户 组: 普通用户
  • 注册时间: 2018-03-29 14:38
个人简介

默默的一块石头

文章分类

全部博文(124)

文章存档

2022年(26)

2021年(10)

2020年(28)

2019年(60)

我的朋友

分类: LINUX

2019-08-23 17:18:42

//链接过程中struct rtable于struct dst_entry创建关联的过程
int tcp_v4_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len)
{
struct sockaddr_in *usin = (struct sockaddr_in *)uaddr;
struct inet_sock *inet = inet_sk(sk);
struct tcp_sock *tp = tcp_sk(sk);
struct flowi4 *fl4;
struct rtable *rt;

rt = ip_route_connect(fl4, nexthop, inet->inet_saddr,
      RT_CONN_FLAGS(sk), sk->sk_bound_dev_if,
      IPPROTO_TCP,
      orig_sport, orig_dport, sk, true);
......
}

static inline struct rtable *ip_route_connect(struct flowi4 *fl4,
      __be32 dst, __be32 src, u32 tos,
      int oif, u8 protocol,
      __be16 sport, __be16 dport,
      struct sock *sk, bool can_sleep)
{
struct net *net = sock_net(sk);
struct rtable *rt;

ip_route_connect_init(fl4, dst, src, tos, oif, protocol,sport, dport, sk, can_sleep);

return ip_route_output_flow(net, fl4, sk);
}

struct rtable *ip_route_output_flow(struct net *net, struct flowi4 *flp4,struct sock *sk)
{
struct rtable *rt = __ip_route_output_key(net, flp4);

if (IS_ERR(rt))
return rt;

if (flp4->flowi4_proto)
rt = (struct rtable *) xfrm_lookup(net, &rt->dst,flowi4_to_flowi(flp4),sk, 0);

return rt;
}

/*
 * Major route resolver routine.
 */
struct rtable *__ip_route_output_key(struct net *net, struct flowi4 *fl4)
{
struct net_device *dev_out = NULL;
struct fib_result res;
struct rtable *rth;
......
make_route:
rth = __mkroute_output(&res, fl4, orig_oif, dev_out, flags);

out:
rcu_read_unlock();
return rth;
}

/* called with rcu_read_lock() and with __ip_route_output_key()*/
static struct rtable *__mkroute_output(const struct fib_result *res,
       const struct flowi4 *fl4, int orig_oif,
       struct net_device *dev_out,
       unsigned int flags)
{
struct fib_info *fi = res->fi;
struct in_device *in_dev;
struct rtable *rth;
......
add:
rth = rt_dst_alloc(dev_out,
   IN_DEV_CONF_GET(in_dev, NOPOLICY),
   IN_DEV_CONF_GET(in_dev, NOXFRM),
   do_cache);
......
}

static struct rtable *rt_dst_alloc(struct net_device *dev,
   bool nopolicy, bool noxfrm, bool will_cache)
{
return dst_alloc(&ipv4_dst_ops, dev, 1, DST_OBSOLETE_FORCE_CHK,
(will_cache ? 0 : (DST_HOST | DST_NOCACHE)) |
(nopolicy ? DST_NOPOLICY : 0) |
(noxfrm ? DST_NOXFRM : 0));
}

void *dst_alloc(struct dst_ops *ops, struct net_device *dev,
int initial_ref, int initial_obsolete, unsigned short flags)
{
struct dst_entry *dst;
.....
return dst;//struct dst_entry *dst;
}

struct rtable {
struct dst_entry dst;
......
}

//红色标记的可真会玩
阅读(4110) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~