quagga源码分析--路由信息处理zebra-rib
對(duì)于各個(gè)協(xié)議生成的路由信息的處理屬于quagga中非常重要的一個(gè)功能,如何在內(nèi)核進(jìn)行路由增加,更新,刪除是一個(gè)復(fù)雜的過(guò)程。
quagga在thread任務(wù)調(diào)度中加入了一種工作隊(duì)列,work_queue,與內(nèi)核的工作隊(duì)列類(lèi)似,是一種相對(duì)而言,低優(yōu)先級(jí)的任務(wù),這里的任務(wù)看成類(lèi)似的系統(tǒng)進(jìn)程。
1、隊(duì)列初始化:
1 /* initialise zebra rib work queue */ 2 static void 3 rib_queue_init(struct zebra_t *zebra) 4 { 5 assert(zebra); 6 7 if (!(zebra->ribq = work_queue_new(zebra->master, 8 "route_node processing"))) 9 { 10 zlog_err("%s: could not initialise work queue!", __func__); 11 return; 12 } 13 14 /* fill in the work queue spec */ 15 zebra->ribq->spec.workfunc = &meta_queue_process; 16 zebra->ribq->spec.errorfunc = NULL; 17 /* XXX: TODO: These should be runtime configurable via vty */ 18 zebra->ribq->spec.max_retries = 3; 19 zebra->ribq->spec.hold = rib_process_hold_time; 20 21 if (!(zebra->mq = meta_queue_new())) 22 { 23 zlog_err("%s: could not initialise meta queue!", __func__); 24 return; 25 } 26 return; 27 }第19行,zebra->ribq->spec.hold = rib_process_hold_time; 指定了rib工作隊(duì)列在thread_fetch的時(shí)候會(huì)等待10毫秒
?
1 /* Hold time for RIB process, should be very minimal. 2 * it is useful to able to set it otherwise for testing, hence exported 3 * as global here for test-rig code. 4 */ 5 int rib_process_hold_time = 10;?
在添加thread任務(wù)的時(shí)候進(jìn)行了時(shí)間單位換算:
1 /* Add a background thread, with an optional millisec delay */ 2 struct thread* 3 funcname_thread_add_background(struct thread_master *m, 4 int (*func)(struct thread *), 5 void *arg, long delay, 6 debugargdef) { 7 struct timeval trel; 8 9 assert(m != NULL); 10 11 if (delay) { 12 trel.tv_sec = delay / 1000; 13 trel.tv_usec = 1000 * (delay % 1000); 14 } else { 15 trel.tv_sec = 0; 16 trel.tv_usec = 0; 17 } 18 19 return funcname_thread_add_timer_timeval(m, func, THREAD_BACKGROUND, 20 arg, &trel, debugargpass); 21 }OK,meta_queue_process,就指定了工作隊(duì)列在調(diào)度執(zhí)行的處理函數(shù),由此guagga就會(huì)一直同步更新路由了。
2、每個(gè)子網(wǎng)的下一跳路由表項(xiàng)的描述:
quagga使用了雙向鏈表來(lái)管理表項(xiàng),定義了路由表現(xiàn)的詳細(xì)信息,但比如 status 這個(gè)字段是用來(lái)在更新路由時(shí)來(lái)做比較的關(guān)鍵字段。如下宏定義了3種狀態(tài):
#define RIB_ENTRY_REMOVED?? ?(1 << 0)
#define RIB_ENTRY_CHANGED?? ?(1 << 1)
#define RIB_ENTRY_SELECTED_FIB?? ?(1 << 2)
?3、整個(gè)路由表的描述:
/* Routing table top structure. */ struct route_table {struct route_node *top;/** Delegate that performs certain functions for this table.*/route_table_delegate_t *delegate;unsigned long count;void *info; /* User data. */ };route_table包含了一個(gè)二叉樹(shù)結(jié)構(gòu)來(lái)保存所有的路由前綴和下一跳路由表項(xiàng),prefix結(jié)構(gòu)保持了路由前綴的長(zhǎng)度和值,用來(lái)做最長(zhǎng)前綴匹配:
1 /* Each routing entry. */ 2 struct route_node { 3 struct prefix p; /* Actual prefix of this radix. */ 4 struct route_table *table; /* Tree link. */ 5 struct route_node *parent; 6 struct route_node *link[2]; 7 unsigned int lock; /* Lock of this radix */ 8 void *info; /* Each node of route. */ 9 void *aggregate; /* Aggregation. */ 10 11 #define l_left link[0] 12 #define l_right link[1] 13 };呃,說(shuō)好的mtire樹(shù)呢? 好吧,我們不太可能把成千上萬(wàn)的路由表項(xiàng)塞給linux內(nèi)核,夠用就行。
?
?
轉(zhuǎn)載于:https://www.cnblogs.com/danxi/p/6285545.html
總結(jié)
以上是生活随笔為你收集整理的quagga源码分析--路由信息处理zebra-rib的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: DFS:C 小Y的难题(1)
- 下一篇: CentOS 7安装redis及php扩