Chinaunix首页 | 论坛 | 博客
  • 博客访问: 50132
  • 博文数量: 15
  • 博客积分: 1410
  • 博客等级: 上尉
  • 技术积分: 180
  • 用 户 组: 普通用户
  • 注册时间: 2009-12-31 11:18
文章分类
文章存档

2010年(14)

2009年(1)

我的朋友

分类: LINUX

2010-09-01 09:13:38

今天无意中看到一篇关于内核中multicast物理地址的定义,在这里写一下。

x1:xx(比如11:16:36:55:ad:77)开头或者FF:FF:FF:FF:FF:FF的物理地址为multicast物理地址,具体可以参照以下的代码。

在内核的处理中,multicast物理地址的包有时候会当作error来处理,所以在手动指定物理地址的时候需要注意(虚拟机等场合)。
/srv/sources/sources/k/kernel/2.6.18-194.el5/pre-build
/kernel-2.6.18/linux-2.6.18.x86_64/net/bridge/br_input.c
    int br_handle_frame(struct net_bridge_port *p,
 struct sk_buff **pskb)
    {
        struct sk_buff *skb = *pskb;
        const unsigned char *dest = eth_hdr(skb)->h_dest;

        if (!is_valid_ether_addr(eth_hdr(skb)->h_source))

            goto err;


/srv/sources/sources/k/kernel/2.6.18-194.el5/pre-build/
kernel-2.6.18/linux-2.6.18.x86_64/include/linux/etherdevice.h
    /**
     * is_valid_ether_addr - Determine if the given
thernet address is valid
     * @addr: Pointer to a six-byte array containing
the Ethernet address
     *
     * Check that the Ethernet address (MAC) is not
00:00:00:00:00:00, is not
     * a multicast address, and is not FF:FF:FF:FF:FF:FF.
     *
     * Return true if the address is valid.
     */
    static inline int is_valid_ether_addr(const u8 *addr)
    {
        /* FF:FF:FF:FF:FF:FF is a multicast address
so we don't need to
         * explicitly check for it here. */
        return !is_multicast_ether_addr(addr) &&
!is_zero_ether_addr(addr);
    }



    /**
     * is_multicast_ether_addr - Determine if the Ethernet
address is a multicast.
     * @addr: Pointer to a six-byte array containing the
Ethernet address
     *
     * Return true if the address is a multicast address.
     * By definition the broadcast address is also a
multicast address.
     */
    static inline int is_multicast_ether_addr(const u8 *addr)
    {
        return (0x01 & addr[0]);
    }
阅读(1219) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~