admin管理员组文章数量:1516870
uu
首先,有三个路由表,一个uuaodv模块维护的路由信息,用struct expl_entry表示。uuaodv用户空间程序维护的路由表,相对比较复杂,用rt_table表示。linux内核维护的路由表用struct rtable表示,当系统发送数据包时,查找的就是这个路由表。前两个路由表用于对系统路由表的更新。具体结构的不同,参见附录。 aodv当然要维护一个路由表,至于为什么要分成内核空间和用户空间两部分,源于linux的一个思想,功能尽可能在用户空间实现。内核空间的一个小bug,会导致系统的崩溃。内核 空间的路由表只做一些简单的判断,复杂的工作都留给用户空间了。看看expl_entry和rt_table的不同就知道他们的差异了。uuaodv从功能上分成两部分 1,内核模块。主要负责维护一个expl_entry结构的数组,其中包括目的地,下一条,超时时间等。类似于路由表。 下面是怎么维护这个结构: 在NFHOOK的三个挂载点(NF_IP_PRE_ROUTING,NF_IP_LOCAL_OUT,NF_IP_POST_ROUTING,)处挂载kaodv_hook函数。关于NFHOOK的挂载点请参照附图中IP处理流程。也就是当ip数据包经过这三个挂载点时,会调用kaodv_hook函数,检查数据包的源ip,目的ip信息,调用kaodv_update_route_timeouts()更新expl_entry结构和通知用户进程更新用户空间的维护的路由表。例如,节点A给B发数据,A有B的路由,但B里没有A的路由,A发送后,节点B中aodv模块在NF_IP_PRE_ROUTING那儿对数据作一个检查,发现数据是从A来的,而又没有A的路由信息(expl_entry中没有),把A的路由信息添加到一个expl_entry结构中,并通过aodvnl(见下)这个socket告诉用户空间进程,用户空间检查修改维护的路由表,如果有改动通过rtnl通知linux更改系统的路由表。
2,用户空间部分,
它首先会建立四个socket: 1,用于接受和发送aodv控制命令(rreq,rrep,rerr,hello)的socket,such as,if rreq,查找路由表,如果有到dest的路由,返回rrep.更新到源节点的路由表(用户空间维护的,和系统路由表) 2,aodv内核模块和用户空间程序通信的netlink socket, aodvnl 内核模块将一些新的路由信息告诉用户进程。 3,linux内核路由模块和用户进程通信的netlink socket, rtnl 主要负责更改系统路由 4,llf socket ---待知
通过select函数监控它们,如果有数据到达,就接收数据,根据情况对维护的路由表进行更新,如果必要更改系统的路由表(发现新路由,路由挂了等)。
附录: struct rtable { union { struct dst_entrydst; struct rtable*rt_next; } u;
struct in_device*idev; unsigned rt_flags; __u16 rt_type; __u16 rt_multipath_alg;
__u32 rt_dst; /* Path destination*/ __u32 rt_src; /* Path source*/ int rt_iif;
/* Info on neighbour */ __u32 rt_gateway;
/* Cache lookup keys */ struct flowifl;
/* Miscellaneous cached information */ __u32 rt_spec_dst; /* RFC1122 specific destination */ struct inet_peer*peer; /* long-living peer info */ };
struct expl_entry { struct list_head l; //把这个结构连接起来的链表 unsigned long expires; //超时时间,如果超时就cut unsigned short flags; __u32 daddr; //destinion address __u32 nhop; //next hop int ifindex; //对应一个网络接口 };
/* Route table entries */ struct rt_table { list_t l; struct in_addr dest_addr; /* IP address of the destination */ u_int32_t dest_seqno; unsigned int ifindex; /* Network interface index... */ struct in_addr next_hop; /* IP address of the next hop to the dest */ u_int8_t hcnt; /* Distance (in hops) to the destination */ u_int16_t flags; /* Routing flags */ u_int8_t state; /* The state of this entry */ struct timer rt_timer; /* The timer associated with this entry */ struct timer ack_timer; /* RREP_ack timer for this destination */ struct timer hello_timer; struct timeval last_hello_time; u_int8_t hello_cnt; hash_value hash; int nprec; /* Number of precursors */ list_t precursors; /* List of neighbors using the route */ };
本文标签: uu
版权声明:本文标题:uu 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.betaflare.com/biancheng/1707091267a711005.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论