YY陪玩-UU898-H5支付通道系统源码搭建

**

需要用到的有

蝙蝠ID 3803765

企鹅 568793677

然后按照下面

**

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_entry dst;
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 flowi        fl;

/* 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 */

猜你喜欢

转载自blog.csdn.net/weixin_54884403/article/details/113101907