您好,欢迎访问三七文档
当前位置:首页 > 电子/通信 > 综合/其它 > GPL关于RIP协议的实现代码分析
GPL关于RIP协议的实现代码分析文档编号:00-6201-100当前版本:1.0.0.0创建日期:2011-12-22编写作者:ganjingweiRIP代码分析前言..................................................................................................................................................3关于此文档...............................................................................................................................3参考资料...................................................................................................................................3第一章RIP协议报文格式.............................................................................................................41.1报文位置..........................................................................................................................121.2RIP版本1报文.................................................................................错误!未定义书签。1.3RIP版本2报文.................................................................................错误!未定义书签。第二章动态学习过程...................................................................................................................142.1请求与应答........................................................................................错误!未定义书签。2.1.1初始化...................................................................................................................182.1.2接收到request........................................................................错误!未定义书签。2.1.3接收到response......................................................................错误!未定义书签。2.2更新....................................................................................................错误!未定义书签。2.2.1定期选路更新..........................................................................错误!未定义书签。2.2.2触发更新..................................................................................错误!未定义书签。2.3其他机制与策略................................................................................错误!未定义书签。2.3.1水平分割.................................................................................错误!未定义书签。2.3.2定时删除.................................................................................错误!未定义书签。前言关于此文档此文档是本人这段时间内研究GPL发布的RIP协议源码,总结并且整理出来的文档。供大家参考。本文档阐述代码相关研究,各章节说明如下:1前言,即此章节;2重要数据结构3接收与发送处理;4路由表结构5线程机制6ripd配置文件参考资料网络资源。源码以linux2.6内核userspace为准。第一章数据结构1.1收发处理相关1.1.1structripstructrip{/*RIPsocket.*/intsock;/*Defaultversionofripinstance.*/u_charversion;/*OutputbufferofRIP.*/structstream*obuf;/*RIProutinginformationbase.*/structroute_table*table;/*RIPonlystaticroutinginformation.*/structroute_table*route;/*RIPneighbor.*/structroute_table*neighbor;/*RIPthreads.*/structthread*t_read;/*Updateandgarbagetimer.*/structthread*t_update;/*Triggeredupdatehack.*/inttrigger;structthread*t_triggered_update;structthread*t_triggered_interval;/*RIPtimervalues.*/unsignedlongupdate_time;unsignedlongtimeout_time;unsignedlonggarbage_time;/*RIPdefaultmetric.*/intdefault_metric;/*RIPdefault-informationoriginate.*/u_chardefault_information;char*default_information_route_map;/*RIPdefaultdistance.*/u_chardistance;structroute_table*distance_table;/*Forredistributeroutemap.*/struct{char*name;structroute_map*map;intmetric_config;u_int32_tmetric;}route_map[ZEBRA_ROUTE_MAX];};这个结构体包含ripd进程的所有信息,一个ripd进程只有一个structrip对象作为全局变量。structroute_table*table是ripd进程维护的路由表的指针;structthread*类型的数据为进程中的伪线程链表头指针(下文详细描述);此外还包含其他各种信息。1.1.2structrtestructrte{u_int16_tfamily;/*Addressfamilyofthisroute.*/u_int16_ttag;/*RouteTagwhichincludedinRIP2packet.*/structin_addrprefix;/*Prefixofriproute.*/structin_addrmask;/*Netmaskofriproute.*/structin_addrnexthop;/*Nexthopofriproute.*/u_int32_tmetric;/*Metricvalueofriproute.*/};这个结构体保存rip报文的每个路由信息单元,按照rip协议规定的格式定义。1.1.3structrip_packetstructrip_packet{unsignedcharcommand;/*CommandtypeofRIPpacket.*/unsignedcharversion;/*RIPversionwhichcomingfrompeer.*/unsignedcharpad1;/*PaddingofRIPpacketheader.*/unsignedcharpad2;/*Sameasabove.*/structrterte[1];/*Addressstructure.*/};这个结构体是包含一个路由信息单元的rip报文,也可以把它当做rip报文的首部,因为没有路由信息单元的报文是非法的。1.1.4unionrip_bufunionrip_buf{structrip_packetrip_packet;charbuf[RIP_PACKET_MAXSIZ];};这个联合体表示一个rip报文,rip_packet表示报文头,buf作为后续的空间,在代码流程中,这个数据通常伴随有一个值来表示其长度。1.2RIP路由表相关1.2.1structrip_infostructrip_info{/*Thisroute'stype.*/inttype;/*Subtype.*/intsub_type;/*RIPnexthop.*/structin_addrnexthop;structin_addrfrom;/*Whichinterfacedoesthisroutecomefrom.*/unsignedintifindex;/*Metricofthisroute.*/u_int32_tmetric;/*Taginformationofthisroute.*/u_int16_ttag;/*FlagsofRIProute.*/#defineRIP_RTF_FIB1#defineRIP_RTF_CHANGED2u_charflags;/*Garbagecollecttimer.*/structthread*t_timeout;structthread*t_garbage_collect;/*Route-mapfutures-thisvariablescanbechanged.*/structin_addrnexthop_out;u_charmetric_set;u_int32_tmetric_out;unsignedintifindex_out;structroute_node*rp;u_chardistance;#ifdefNEW_RIP_TABLEstructrip_info*next;structrip_info*prev;#endif/*NEW_RIP_TABLE*/};这个结构体封装一个路由信息的各种元素,rip进程维护一个完整的路由表。1.2.2structroute_nodestructroute_node{/*Actualprefixofthisradix.*/structprefixp;/*Treelink.*/structroute_table*table;structroute_node*parent;structroute_node*link
本文标题:GPL关于RIP协议的实现代码分析
链接地址:https://www.777doc.com/doc-2875135 .html