usnic_common_util.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. #ifndef USNIC_CMN_UTIL_H
  19. #define USNIC_CMN_UTIL_H
  20. static inline void
  21. usnic_mac_to_gid(const char *const mac, char *raw_gid)
  22. {
  23. raw_gid[0] = 0xfe;
  24. raw_gid[1] = 0x80;
  25. memset(&raw_gid[2], 0, 6);
  26. raw_gid[8] = mac[0]^2;
  27. raw_gid[9] = mac[1];
  28. raw_gid[10] = mac[2];
  29. raw_gid[11] = 0xff;
  30. raw_gid[12] = 0xfe;
  31. raw_gid[13] = mac[3];
  32. raw_gid[14] = mac[4];
  33. raw_gid[15] = mac[5];
  34. }
  35. static inline void
  36. usnic_mac_ip_to_gid(const char *const mac, const __be32 inaddr, char *raw_gid)
  37. {
  38. raw_gid[0] = 0xfe;
  39. raw_gid[1] = 0x80;
  40. memset(&raw_gid[2], 0, 2);
  41. memcpy(&raw_gid[4], &inaddr, 4);
  42. raw_gid[8] = mac[0]^2;
  43. raw_gid[9] = mac[1];
  44. raw_gid[10] = mac[2];
  45. raw_gid[11] = 0xff;
  46. raw_gid[12] = 0xfe;
  47. raw_gid[13] = mac[3];
  48. raw_gid[14] = mac[4];
  49. raw_gid[15] = mac[5];
  50. }
  51. static inline void
  52. usnic_write_gid_if_id_from_mac(char *mac, char *raw_gid)
  53. {
  54. raw_gid[8] = mac[0]^2;
  55. raw_gid[9] = mac[1];
  56. raw_gid[10] = mac[2];
  57. raw_gid[11] = 0xff;
  58. raw_gid[12] = 0xfe;
  59. raw_gid[13] = mac[3];
  60. raw_gid[14] = mac[4];
  61. raw_gid[15] = mac[5];
  62. }
  63. #endif /* USNIC_COMMON_UTIL_H */