内核非法MAC检查

来源:互联网 发布:把mac照片导入iphone8 编辑:程序博客网 时间:2024/05/22 06:20
/** * is_zero_ether_addr - Determine if give Ethernet address is all zeros. * @addr: Pointer to a six-byte array containing the Ethernet address * * Return true if the address is all zeroes. */static inline int is_zero_ether_addr(const u8 *addr){return !(addr[0] | addr[1] | addr[2] | addr[3] | addr[4] | addr[5]);}/** * 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];}/** * is_local_ether_addr - Determine if the Ethernet address is locally-assigned one (IEEE 802). * @addr: Pointer to a six-byte array containing the Ethernet address * * Return true if the address is a local address. */static inline int is_local_ether_addr(const u8 *addr){return 0x02 & addr[0];}/** * is_broadcast_ether_addr - Determine if the Ethernet address is broadcast * @addr: Pointer to a six-byte array containing the Ethernet address * * Return true if the address is the broadcast address. */static inline int is_broadcast_ether_addr(const u8 *addr){return (addr[0] & addr[1] & addr[2] & addr[3] & addr[4] & addr[5]) == 0xff;}/** * is_unicast_ether_addr - Determine if the Ethernet address is unicast * @addr: Pointer to a six-byte array containing the Ethernet address * * Return true if the address is a unicast address. */static inline int is_unicast_ether_addr(const u8 *addr){return !is_multicast_ether_addr(addr);}/** * is_valid_ether_addr - Determine if the given Ethernet 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);}

原创粉丝点击