Openflow 与 Linux 路由共存问题 - lethelog

Openflow 与 Linux 路由共存问题

wliao posted @ Wed, 04 May 2011 14:16:15 +0800 in 未分类 , 4050 readers

1.内核路由

主要参考了《Understanding Linux Network Internals》

understandlni_1302

从此图可以看出:

  • PF_PACKET处于网络层,与IP协议在同一层
  • PF_PACKET通过socket与内核建立通信
  • ptype_base包含了各种协议的回调函数(func函数)
  • 当链路层(也就是设备驱动,位于drivers/net下)完成接受frame的工作后,将其数据封装到skbuff中,然后轮询ptype_base中的各种协议,然后调用deliver_skb函数,将skb传给上层协议。
  • 分析linux转发与openflow使用的PF_PACKET类型的socket主要需要研究两个协议之间的差别
  • PF_PACKET类型socket文件位于net/packet/Af_packet.c中
  • IP协议位于net/ipv4

此处只讨论旧网络API,NAPI主要解决传输速率较高时,采用轮询+中断方式,与我们要分析的问题关系不大。

驱动程序注册完中断之后,当有包到达时,收到中断,初始化skb然后触发内核softirq(软中断),软中断由

open_softirq(NET_TX_SOFTIRQ, net_tx_action, NULL);

open_softirq(NET_RX_SOFTIRQ, net_rx_action, NULL);

注册。

在软中断中,调用process_backlog(初始化为名为poll的回调函数)。

process_backlog会取出其中的skbuff然后调用netif_receive_skb来处理此skbuff。

在netif_receive_skb中,

list_for_each_entry_rcu(ptype, &ptype_all, list) {
    if (ptype->dev == null_or_orig || ptype->dev == skb->dev ||
        ptype->dev == orig_dev) {
        if (pt_prev)
            ret = deliver_skb(skb, pt_prev, orig_dev);
        pt_prev = ptype;
    }
}

对于ptype_all中的所有协议都调用此协议的func函数,来处理skbuff。
问题:为何此处使用pt_prev?而不是 ptype?

type = skb->protocol;
list_for_each_entry_rcu(ptype,
        &ptype_base[ntohs(type) & PTYPE_HASH_MASK], list) {
    if (ptype->type == type && (ptype->dev == null_or_orig ||
         ptype->dev == skb->dev || ptype->dev == orig_dev ||
         ptype->dev == orig_or_bond)) {
        if (pt_prev)
            ret = deliver_skb(skb, pt_prev, orig_dev);
        pt_prev = ptype;
    }
}

对于ptype_base同样处理。

由下图可以看到,对于每个协议都拷贝了一份skbuff,然后再调用func回调函数。

static inline int deliver_skb(struct sk_buff *skb,
                  struct packet_type *pt_prev,
                  struct net_device *orig_dev)
{
    atomic_inc(&skb->users);
    return pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
}

这里其实只是通过skb->users加一来计算引用。拷贝则由相应的协议回调函数完成。

understandlni_0902

协议由packet_type表示,通过void dev_add_pack(struct packet_type *pt)注册。

dev_add_pack区分type(ETH_P_ALL | 其他),分别添加到ptype_all与ptype_base中。

对于IP协议,调用的是ip_rev,然后进行路由或者传递给上层等工作。

下面主要涉及Openflow使用的socket(AF_PACKET)。

2.Openflow处理包

先看看openflow中对socket的使用,在连接switch与host(即除掉连接nox的连接)方面,使用netdev来封装。

int netdev_fd;              /* Network device. */
int tap_fd;                 /* TAP character device, if any, otherwise the
                             * network device. */

其中netdev_fd就是保存了AF_PACKET类型的socket的文件描述符(file descriptor),tap字符设备主要是用来实现点对点的虚拟字符设备(TUN/TAP虚拟网络设备为用户空间程序提供了网络数据包的发送和接收能力)。

然后在do_open_netdev中创建socket。

netdev_fd = socket(PF_PACKET, SOCK_RAW,
                   htons(ethertype == NETDEV_ETH_TYPE_NONE ? 0
                         : ethertype == NETDEV_ETH_TYPE_ANY ? ETH_P_ALL
                         : ethertype == NETDEV_ETH_TYPE_802_2 ? ETH_P_802_2
                         : ethertype));

在轮询中调用了接收包的函数netdev_recv(netdev_recv_wait为阻塞)

if (!strncmp(netdev->name, "tap", 3)) {
    do {
        n_bytes = read(netdev->tap_fd, ofpbuf_tail(buffer),
                       (ssize_t)ofpbuf_tailroom(buffer));
    } while (n_bytes < 0 && errno == EINTR);
}
else {
    do {
        n_bytes = recvfrom(netdev->tap_fd, ofpbuf_tail(buffer),
                           (ssize_t)ofpbuf_tailroom(buffer), 0,
                           (struct sockaddr *)&sll, &sll_len);
    } while (n_bytes < 0 && errno == EINTR);
}

接收的数据保存到buffer中,再进行后续的提取包头,查flow表,转发等

netdev->queue_fd[0] = netdev->tap_fd; (在do_open_netdev函数中)

n_bytes = write(netdev->queue_fd[class_id], buffer->data, buffer->size); (在netdev_send函数中)

 

3.二者之间的联系

4.references

  • No match
how to clear clipboa said:
Sat, 09 May 2020 13:12:04 +0800

if you want to access it quickly, then here at
mostly who working on their laptops or computer system so I can say you, now just read more about basic information

AAA said:
Sat, 09 Apr 2022 18:41:03 +0800

This particular papers fabulous, and My spouse and i enjoy each of the perform that you have placed into this. I’m sure that you will be making a really useful place. I has been additionally pleased. Good perform! 온라인카지노

meidir said:
Tue, 05 Jul 2022 03:59:03 +0800

Very interesting points you have observed , regards for putting up. iphone trade in

meidir said:
Sun, 18 Sep 2022 19:37:15 +0800

Youre so cool! I dont suppose Ive read anything like this before. So nice to find somebody with some original thoughts on this subject. realy thank you for starting this up. this website is something that is needed on the web, someone with a little originality. useful job for bringing something new to the internet! 腳架

 

====================

 

But wanna admit that this is very helpful , Thanks for taking your time to write this. 鬼滅之刃

 

====================

 

Wow! This could be one particular of the most useful blogs We have ever arrive across on this subject. Actually Magnificent. I am also a specialist in this topic so I can understand your effort. 攝影器材

 

====================

 

I really got into this article. I found it to be interesting and loaded with unique points of interest. I like to read material that makes me think. Thank you for writing this great content. Macbook Pro

meidir said:
Fri, 07 Oct 2022 21:34:40 +0800

Information given by you is really very useful and valuable for me. I have to write an article in my class about this theme and thanks a lot for it. I even didn’t know about Laboratory and Unarmed stick insects. Thanks a lot 오피베스트

meidir said:
Mon, 10 Oct 2022 21:18:17 +0800

joker mobile ใหม่ ที่สุดแห่งความสนุกที่ทุกท่านกำลังจะได้สัมผัสในเว็บไซต์ จะเป็นหนึ่งในสิ่งที่สามารถทำทุกท่านรวยได้พร้อมความสะใจ. joker mobile

=============

joker ฝาก19รับ100 หนึ่งในโปรโมชั่นสุดคุ้มที่มีเงื่อนไขในการรับโปรโมชั่นง่าย ๆ เพียงทำการสมัครและทำการฝากรับโบนัสฟรีทันที. joker slotxo ฝาก 19 รับ 100

=============

joker สล็อต ฝาก10รับ100 ผู้ให้บริการสล็อตออนไลน์ที่มีเกมสล็อตให้เลือกเล่นมากมายหลากหลายเกมปัจจุบันมีการพัฒนาระบบให้มาพร้อมกับความทันสมัย. joker สล็อต ฝาก10รับ100

=============

pg joker ใหม่ เว็บของเราเล่นได้และถอนได้เลยทันทีและมี สูตรสล็อต โบนัสแตกง่าย ให้คุณได้เพลิดเพลิน กับเกมหลากหลายที่มีคุณภาพสูง. pg joker

=============

pg joker wallet ค่ายเกมสล็อตที่ได้รับกระแสที่นิยมอย่างไม่ขาดสาย มากับแบบอย่างธีมเกมที่หลากหลาย ให้ท่านได้เลือกเล่นแบบไม่น่าเบื่อ. pg joker wallet

=============

ทดลองเล่นสล็อต joker เกมใหม่ๆมาแล้วกับเว็บอันดับหนึ่ง เพลิดเพลินไปกับรูปแบบที่หลากหลาย วางเดิมพันได้มากมาย สมัครวันนี้รับเครดิตฟรี. ทดลองเล่นสล็อต joker

=============

ทางเข้าslotxo joker คลิ๊กที่นี่เพื่อเข้าสู่ความมันส์ในปี 2022 เว็บสล็อตรูปแบบใหม่ เกมไม่ซ้ำใคร วางเดิมพันสุดเร้าใจ แตกไว แจกจริง จ่ายจริง. ทางเข้าslotxo joker

=============

ทางเข้าslotxo joker คลิ๊กที่นี่เพื่อเข้าสู่ความมันส์ในปี 2022 เว็บสล็อตรูปแบบใหม่ เกมไม่ซ้ำใคร วางเดิมพันสุดเร้าใจ แตกไว แจกจริง จ่ายจริง. ทางเข้าเล่น slotxo joker

=============

สล็อตเติม true wallet ขั้นต่ำ1บาท เกมสล็อตเป็นเกมที่ได้รับความนิยม ที่ได้รับกระแสการตอบกลับจากผู้เล่นอย่างดีเยี่ยม. สล็อต เติม true wallet ขั้นต่ำ 1 บาท

=============

slot1234 joker พบกับโปรโมชั่นสุดพิเศษของเกมส์สล็อตได้เงินจริง พบกับระบบถอนเงินเกมสล็อตออนไลน์ ที่รวดเร็วที่สุด มีเครดิตฟรีแจกทุกUser. สล็อต1234 joker

meidir said:
Tue, 11 Oct 2022 19:52:19 +0800

member slot - บทความสล็อตออนไลน์ SLOTXO - สล็อตออนไลน์ XOSLOTZ. member slot


============


sagame 1688 - คาสิโน SA Game SLOTXO - สล็อตออนไลน์ XOSLOTZ. sagame 1688


============


slot auto wallet ระบบการเล่นเกมสล็อต สมัครอัตโนมัติฟรี - บทความสล็อตออนไลน์ SLOTXO - สล็อตออนไลน์ XOSLOTZ. slot auto wallet


============


slotxo สล็อต ฝาก10รับ100 โปรโมชั่นใหม่ล่าสุด โปรโมชั่นดีๆพร้อมที่จะให้บริการสมาชิกทุกคนที่ทำตามเงื่อนไข ฝาก 10 บาทรับเพิ่มรวมเป็น 100 บาท. slotxo สล็อต ฝาก10รับ100


============


slotxo สล็อต ฝาก20รับ100 หนึ่งในผู้ให้บริการเกมสล็อตออนไลน์ที่มาแรงที่สุดเป็นอันดับ 1 สมัครสมาชิกวันนี้รับฟรีโปรโมชั่นโบนัสสุดคุ้ม. slotxo สล็อต ฝาก20รับ100


============


เครดิตฟรี 100 สมัครสมาชิกใหม่วันนี้รับทันที ฟรีเครดิต 100 วางแผนทดสอบการเล่นสล็อตออนไลน์ เล่นได้ไม่จำกัดเวลา ไม่มีเงื่อนไขใดๆทั้งสิ้น. เครดิตฟรี 100


============


เครดิตฟรี 50ยืนยันเบอร์ เล่นสล็อตออนไลน์ ผ่านเว็บตรง อุปกรณ์สื่อสาร ทุกระบบ ได้อย่างปลอดภัย ไม่มีประวัติการโกง เว็บมาแรงที่สุดแห่งปี. เครดิตฟรี 50 ยืนยันเบอร์


============


เครดิตฟรีไม่ต้องแชร์ เล่นเกมสล็อตออนไลน์ โดยไม่ต้องพึ่งดวง กับกลยุทธสำหรับในการเอาชนะเกมได้เงินจริง รับรองผล สามารถเอาชนะเกมได้ไม่ยาก. เครดิตฟรีไม่ต้องแชร์


============


เครดิตฟรีไม่ต้องฝากไม่ต้องแชร์แค่สมัคร - บทความสล็อตออนไลน์ SLOTXO - สล็อตออนไลน์ XOSLOTZ. เครดิตฟรีไม่ต้องฝาก


============


ฝากถอนslotxo ด้วยระบบง่าย ๆ ในไม่กี่ขั้นตอน จัดการได้เร็วทันใจ ถอนเงินไว โดยสามารถใช้งานผ่านหน้าเว็บไซต์ของเรา เล่นที่นี่ รองรับระบบออโต้ จัดการสะดวก. ฝาก-ถอน slotxo

meidir said:
Sat, 22 Oct 2022 00:53:31 +0800

Loving the info on this internet site , you have done outstanding job on the posts . specialty coffee

meidir said:
Fri, 25 Nov 2022 00:29:42 +0800

You could certainly see your skills within the work you write. The sector hopes for more passionate writers such as you who aren’t afraid to mention how they believe. All the time go after your heart. 白居二

meidir said:
Fri, 17 Mar 2023 23:44:56 +0800

You seem to be very professional in the way you write.*”~*~ 노래방알바


Login *


loading captcha image...
(type the code from the image)
or Ctrl+Enter
Host by is-Programmer.com | Power by Chito 1.3.3 beta | © 2007 LinuxGem | Design by Matthew "Agent Spork" McGee