1/* 2 * Copyright (c) 2013, Cisco Systems, Inc. All rights reserved. 3 * 4 * This program is free software; you may redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; version 2 of the License. 7 * 8 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 9 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 10 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 11 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 12 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 13 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 14 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 15 * SOFTWARE. 16 * 17 */ 18 19#ifndef USNIC_CMN_UTIL_H 20#define USNIC_CMN_UTIL_H 21 22static inline void 23usnic_mac_to_gid(const char *const mac, char *raw_gid) 24{ 25 raw_gid[0] = 0xfe; 26 raw_gid[1] = 0x80; 27 memset(&raw_gid[2], 0, 6); 28 raw_gid[8] = mac[0]^2; 29 raw_gid[9] = mac[1]; 30 raw_gid[10] = mac[2]; 31 raw_gid[11] = 0xff; 32 raw_gid[12] = 0xfe; 33 raw_gid[13] = mac[3]; 34 raw_gid[14] = mac[4]; 35 raw_gid[15] = mac[5]; 36} 37 38static inline void 39usnic_mac_ip_to_gid(const char *const mac, const __be32 inaddr, char *raw_gid) 40{ 41 raw_gid[0] = 0xfe; 42 raw_gid[1] = 0x80; 43 memset(&raw_gid[2], 0, 2); 44 memcpy(&raw_gid[4], &inaddr, 4); 45 raw_gid[8] = mac[0]^2; 46 raw_gid[9] = mac[1]; 47 raw_gid[10] = mac[2]; 48 raw_gid[11] = 0xff; 49 raw_gid[12] = 0xfe; 50 raw_gid[13] = mac[3]; 51 raw_gid[14] = mac[4]; 52 raw_gid[15] = mac[5]; 53} 54 55static inline void 56usnic_write_gid_if_id_from_mac(char *mac, char *raw_gid) 57{ 58 raw_gid[8] = mac[0]^2; 59 raw_gid[9] = mac[1]; 60 raw_gid[10] = mac[2]; 61 raw_gid[11] = 0xff; 62 raw_gid[12] = 0xfe; 63 raw_gid[13] = mac[3]; 64 raw_gid[14] = mac[4]; 65 raw_gid[15] = mac[5]; 66} 67 68#endif /* USNIC_COMMON_UTIL_H */ 69