日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

linux htb 源代码,LINUX TC:HTB相关源码

發布時間:2024/8/23 linux 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 linux htb 源代码,LINUX TC:HTB相关源码 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

LINUX TC:HTB相關源碼 收藏

HTB(hierarchy token buffer)是linux tc(traffic control)模塊中的排隊隊列的一種。它的配置比CBQ要簡單.同時實現功能也很強大。下面,就來看看,HTB在linux中的源碼。

1、???????????? Qdisc_ops的注冊

先從module_init函數看起(遵從fudan_abc的建議)

static int __init htb_module_init(void)

{

return register_qdisc(&htb_qdisc_ops);

}

上面的code會調用register_qdisc函數,將htb_qdisc_ops注冊到系統中,那么htb_qdisc_ops包含了那些內容:

static struct Qdisc_ops htb_qdisc_ops __read_mostly = {

.cl_ops??????? =???? &htb_class_ops,

.id????????? =???? "htb",

.priv_size?? =???? sizeof(struct htb_sched),

.enqueue???? =???? htb_enqueue,

.dequeue???? =???? htb_dequeue,

.peek??????????? =???? qdisc_peek_dequeued,

.drop??????????? =???? htb_drop,

.init????????????? =???? htb_init,

.reset?????????? =???? htb_reset,

.destroy????? =???? htb_destroy,

.dump????????? =???? htb_dump,

.owner???????? =???? THIS_MODULE,

};

可以看出,htb_qdisc_ops其實就是注冊了htb管理queue的函數,最重要的莫過于:enqueue 和dequeue函數,它們作用如同它們的名字一樣。那么到底將htb_qdisc_ops注冊到那了呢?

這就要看看register函數了

static struct Qdisc_ops *qdisc_base;

/*

*qdisc_base 就是系統維護所以qdisc所使用的變量,系統中的所有的qdisc都要

*注冊到這變量變量中

*在struct Qdisc_ops中,包含了成員(struct Qdisc_ops *)next

*也就是,所以的qdisc是以鏈表的形式存在的

*/

int register_qdisc(struct Qdisc_ops *qops)

{

struct Qdisc_ops *q, **qp;

int rc = -EEXIST;

write_lock(&qdisc_mod_lock);

/*

*首先,檢測這個qdisc是否已經注冊過了,這是通過比較id實現的,

*id的類型是char 數組:char???????????????? id[IFNAMSIZ];IFNAMESIZ=16

*htb的id=”htb”

*/

for (qp = &qdisc_base; (q = *qp) != NULL; qp = &q->next)

if (!strcmp(qops->id, q->id))

goto out;

/*

*然后檢測ops中的enqueue、dequeue、peek函數,

*如果這些函數都沒有被初始化,將使用noop_qdisc_ops函數來初始化

*noop_qdisc_ops也是Qdisc_ops結構,

*它的作用就像是定義了Qdisc_ops的默認值

*/

if (qops->enqueue == NULL)

qops->enqueue = noop_qdisc_ops.enqueue;

if (qops->peek == NULL) {

if (qops->dequeue == NULL)

qops->peek = noop_qdisc_ops.peek;

else

goto out_einval;

}

if (qops->dequeue == NULL)

qops->dequeue = noop_qdisc_ops.dequeue;

/*

*然后檢測cl_ops成員。

*cl_ops是結構Qdisc_class_ops,

*它定義了用于管理掛載到這個qdisc下的所有class(或者qdisc)

*/

if (qops->cl_ops) {

const struct Qdisc_class_ops *cops = qops->cl_ops;

if (!(cops->get && cops->put && cops->walk && cops->leaf))

goto out_einval;

if (cops->tcf_chain && !(cops->bind_tcf && cops->unbind_tcf))

goto out_einval;

}

/*

*最后將新的qops插入到鏈表的尾部:*qp = qops;

*這樣就注冊完成了

*/

qops->next = NULL;

*qp = qops;

rc = 0;

out:

write_unlock(&qdisc_mod_lock);

return rc;

out_einval:

rc = -EINVAL;

goto out;

}

EXPORT_SYMBOL(register_qdisc);

Qdisc_class_ops是管理這個tree的,那么看看htb的cl_ops有哪些函數:

static const struct Qdisc_class_ops htb_class_ops = {

.graft?????????? =???? htb_graft,

.leaf???????????? =???? htb_leaf,

.qlen_notify????? =???? htb_qlen_notify,

.get????????????? =???? htb_get,

.put????????????? =???? htb_put,

.change????????????? =???? htb_change_class,

.delete???????? =???? htb_delete,

.walk?????????? =???? htb_walk,

.tcf_chain?? =???? htb_find_tcf,

.bind_tcf???? =???? htb_bind_filter,

.unbind_tcf =???? htb_unbind_filter,

.dump????????? =???? htb_dump_class,

.dump_stats????? =???? htb_dump_class_stats,

};

我們知道,tc qdisc命令添加qdisc到某個設備后,為了對數據包進行分類,需要使用tc filter 來添加fitler到某個qdisc, 當數據包來時,通過fitler來區分數據包,并轉發到不同的subqdisc 或者subclass。而綁定fitler都是通過函數:bind_tcf來實現的。

創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

以上是生活随笔為你收集整理的linux htb 源代码,LINUX TC:HTB相关源码的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。