Linux内核如何接收不同类型以太帧
1. 前言
以太头中除了6字节目的MAC地址、6字节源MAC地址外,还有两字节的以太帧类型值,如IPv4为0x0800,ARP为0x0806等,网卡驱动收到以太帧后通过接口函数netif_receive_skb()(netif_rx实际最后也是调用netif_receive_skb)交到上层,而这个接口函数就完成对以太帧类型的区分,交到不同的协议处理程序。如果想自己编写某一以太类型帧的处理程序,需要自己添加相应的
以下Linux内核代码为2.6.17.11。
2. 数据结构
每种协议都要定义一个packet_type结构,引导进入相关的协议数据处理函数,所有节点组成一个链表(HASH链表)。
/* include/linux/netdevice.h */
struct packet_type {
__be16 type; /* This is really htons(ether_type). */
struct net_device *dev; /* NULL is wildcarded here */
int (*func) (struct sk_buff *,
struct net_device *,
struct packet_type *,
struct net_device *);
void *af_packet_priv;
struct list_head list;
};
参数说明:
type:以太帧类型,16位
dev:所附着的网卡设备,如果为NULL则匹配全部网卡
func:协议入口接收处理函数
af_packet_priv:协议私有数据
list:链表扣
一般各协议的packet_type结构都是静态存在,初始化时只提供type和func两个参数就可以了,每个协议在初始化时都要将此结构加入到系统类型链表中。
3. 处理函数
3.1 添加节点
/* net/core/dev.c */
/**
* dev_add_pack - add packet handler
* @pt: packet type declaration
*
* Add a protocol handler to the networking stack. The passed &packet_type
* is linked into kernel lists and may not be freed until it has been
* removed from the kernel lists.
*
* This call does not sleep therefore it can not
* guarantee all CPU's that are in middle of receiving packets
* will see the new packet type (until the next received packet).
*/
void dev_add_pack(struct packet_type *pt)
{
int hash;
 
相关文档:
Service Discovery Protocol(SDP)提供一种能力,让应用程序有方法发现哪种服务可用以及这种服务的特性。
服务发现协议(SDP或Bluetooth SDP)在蓝牙协议栈中对蓝牙环境中的应用程序有特殊的含意,发现哪个服务是可用的和确定这些可用服务的特征。SDP定义了bluetooth client发现可用bluetooth server服务和它们的特征的方法。 ......
1、MYSQL的安装
1)首先当然是下载源码包咯,如:mysql-5.0.27的安装,http://www.mysql.com
2)解压缩,>tar -zxvf mysql-5.0.27.tar.gz
3)解压完成,进入mysql-5.0.27文件夹,>cd mysql-5.0.27
4)安装配置,>./configure --prefix=/opt/mysql --with-extra-charsets=all --with-unix-socket-path=/opt/m ......
Linux下mbstring安装
1、用cd命令进入php的源代码目录下的etc/mbstring目录下,如“/src/php5.2.5”,即“cd /src/php5.2.5”;
2、>/usr/local/php/bin/phpize (假设php安装在/usr/local/php目录下)
3、编译配置,>./configure --with-php-config=/usr/local/php/bin/php-config
4、执行 ......
1、下载phpMyAdmin至web服务器目录并重命名为:phpmyadmin。假设服务器目录为www,则存放位置为www/phpmyadmin,访问路径为http://localhost/phpmyadmin
2、复制"/phpmyadmin/libraries/"目录下的"config.default.php"文件至"/phpmyadmin/"目录下,并重命名为"config.inc.php"
3 ......