国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Linux > 正文

Linux IP in IP隧道簡述

2024-08-28 00:23:09
字體:
來源:轉載
供稿:網友

前言:IPIP隧道是一種三層隧道,通過把原來的IP包封裝在新的IP包里面,來創建隧道傳輸。本篇簡單分析Linux(2.6.32版本)中的IPIP隧道的實現過程,期望有所借鑒,造出輪子:-)

一. IPIP的初始化

Linux中的IPIP隧道文件主要分布在tunnel4.cipip.c文件中。因為是三層隧道,在IP報文中填充的三層協議自然就不能是常見的TCP和UDP,所以,Linux抽象了一個隧道層,位置就相當于傳輸層,主要的實現就是在tunnel4.c中。來看看他們的初始化:

抽象的隧道層和IPIP模塊都是以注冊模塊的方式進行初始化

module_init(tunnel4_init);module_init(ipip_init);

首先看隧道層的初始化,主要的工作就是注冊隧道協議和對應的處理函數:

static int __init tunnel4_init(void){    if (inet_add_protocol(&tunnel4_protocol, IPPROTO_IPIP)) {        printk(KERN_ERR "tunnel4 init: can't add protocol/n");        return -EAGAIN;    }#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)    if (inet_add_protocol(&tunnel64_protocol, IPPROTO_IPV6)) {        printk(KERN_ERR "tunnel64 init: can't add protocol/n");        inet_del_protocol(&tunnel4_protocol, IPPROTO_IPIP);        return -EAGAIN;    }#endif    return 0;}

inet_add_protocol(&tunnel4_protocol, IPPROTO_IPIP)把IPIP隧道協議注冊進inet_protos全局數組中,而inet_protos中的其他協議注冊是在inet_init()中:

    if (inet_add_protocol(&icmp_protocol, IPPROTO_ICMP) < 0)        printk(KERN_CRIT "inet_init: Cannot add ICMP protocol/n");    if (inet_add_protocol(&udp_protocol, IPPROTO_UDP) < 0)        printk(KERN_CRIT "inet_init: Cannot add UDP protocol/n");    if (inet_add_protocol(&tcp_protocol, IPPROTO_TCP) < 0)        printk(KERN_CRIT "inet_init: Cannot add TCP protocol/n");#ifdef CONFIG_IP_MULTICAST    if (inet_add_protocol(&igmp_protocol, IPPROTO_IGMP) < 0)        printk(KERN_CRIT "inet_init: Cannot add IGMP protocol/n");#endif

看一下隧道層的處理函數:

static const struct net_protocol tunnel4_protocol = {    .handler    =   tunnel4_rcv,    .err_handler    =   tunnel4_err,    .no_policy  =   1,    .netns_ok   =   1,};

這樣注冊完后,當接收到三層類型是IPPROTO_IPIP時,就會調用tunnel4_rcv進行下一步的處理。可以說在隧道層對隧道協議進行的注冊,保證能夠識別接收到隧道包。而對隧道包的處理則是在IPIP中完成的。

for (handler = tunnel4_handlers; handler; handler = handler->next)        if (!handler->handler(skb))            return 0;icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);

在隧道層的處理函數中進一步調用注冊的不同隧道協議的處理函數,分別處理。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 宽城| 柳州市| 措勤县| 缙云县| 克什克腾旗| 滨州市| 邮箱| 平远县| 遂宁市| 澎湖县| 滨海县| 黄骅市| 垦利县| 南投县| 揭阳市| 红桥区| 吴堡县| 同江市| 利辛县| 庄河市| 德清县| 子长县| 车险| 房产| 克东县| 福建省| 韩城市| 黄骅市| 商城县| 海淀区| 达州市| 浙江省| 长汀县| 伊金霍洛旗| 营山县| 长武县| 涟水县| 贵州省| 雷州市| 永仁县| 全椒县|