qeth_l3.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright IBM Corp. 2007
  4. * Author(s): Utz Bacher <utz.bacher@de.ibm.com>,
  5. * Frank Pavlic <fpavlic@de.ibm.com>,
  6. * Thomas Spatzier <tspat@de.ibm.com>,
  7. * Frank Blaschka <frank.blaschka@de.ibm.com>
  8. */
  9. #ifndef __QETH_L3_H__
  10. #define __QETH_L3_H__
  11. #include "qeth_core.h"
  12. #include <linux/hashtable.h>
  13. #define QETH_SNIFF_AVAIL 0x0008
  14. enum qeth_ip_types {
  15. QETH_IP_TYPE_NORMAL,
  16. QETH_IP_TYPE_VIPA,
  17. QETH_IP_TYPE_RXIP,
  18. };
  19. struct qeth_ipaddr {
  20. struct hlist_node hnode;
  21. enum qeth_ip_types type;
  22. unsigned char mac[ETH_ALEN];
  23. u8 is_multicast:1;
  24. u8 in_progress:1;
  25. u8 disp_flag:2;
  26. u8 ipato:1; /* ucast only */
  27. /* is changed only for normal ip addresses
  28. * for non-normal addresses it always is 1
  29. */
  30. int ref_counter;
  31. enum qeth_prot_versions proto;
  32. union {
  33. struct {
  34. unsigned int addr;
  35. unsigned int mask;
  36. } a4;
  37. struct {
  38. struct in6_addr addr;
  39. unsigned int pfxlen;
  40. } a6;
  41. } u;
  42. };
  43. static inline void qeth_l3_init_ipaddr(struct qeth_ipaddr *addr,
  44. enum qeth_ip_types type,
  45. enum qeth_prot_versions proto)
  46. {
  47. memset(addr, 0, sizeof(*addr));
  48. addr->type = type;
  49. addr->proto = proto;
  50. addr->disp_flag = QETH_DISP_ADDR_DO_NOTHING;
  51. }
  52. static inline bool qeth_l3_addr_match_ip(struct qeth_ipaddr *a1,
  53. struct qeth_ipaddr *a2)
  54. {
  55. if (a1->proto != a2->proto)
  56. return false;
  57. if (a1->proto == QETH_PROT_IPV6)
  58. return ipv6_addr_equal(&a1->u.a6.addr, &a2->u.a6.addr);
  59. return a1->u.a4.addr == a2->u.a4.addr;
  60. }
  61. static inline bool qeth_l3_addr_match_all(struct qeth_ipaddr *a1,
  62. struct qeth_ipaddr *a2)
  63. {
  64. /* Assumes that the pair was obtained via qeth_l3_addr_find_by_ip(),
  65. * so 'proto' and 'addr' match for sure.
  66. *
  67. * For ucast:
  68. * - 'mac' is always 0.
  69. * - 'mask'/'pfxlen' for RXIP/VIPA is always 0. For NORMAL, matching
  70. * values are required to avoid mixups in takeover eligibility.
  71. *
  72. * For mcast,
  73. * - 'mac' is mapped from the IP, and thus always matches.
  74. * - 'mask'/'pfxlen' is always 0.
  75. */
  76. if (a1->type != a2->type)
  77. return false;
  78. if (a1->proto == QETH_PROT_IPV6)
  79. return a1->u.a6.pfxlen == a2->u.a6.pfxlen;
  80. return a1->u.a4.mask == a2->u.a4.mask;
  81. }
  82. static inline u64 qeth_l3_ipaddr_hash(struct qeth_ipaddr *addr)
  83. {
  84. u64 ret = 0;
  85. u8 *point;
  86. if (addr->proto == QETH_PROT_IPV6) {
  87. point = (u8 *) &addr->u.a6.addr;
  88. ret = get_unaligned((u64 *)point) ^
  89. get_unaligned((u64 *) (point + 8));
  90. }
  91. if (addr->proto == QETH_PROT_IPV4) {
  92. point = (u8 *) &addr->u.a4.addr;
  93. ret = get_unaligned((u32 *) point);
  94. }
  95. return ret;
  96. }
  97. struct qeth_ipato_entry {
  98. struct list_head entry;
  99. enum qeth_prot_versions proto;
  100. char addr[16];
  101. int mask_bits;
  102. };
  103. extern const struct attribute_group *qeth_l3_attr_groups[];
  104. void qeth_l3_ipaddr_to_string(enum qeth_prot_versions, const __u8 *, char *);
  105. int qeth_l3_create_device_attributes(struct device *);
  106. void qeth_l3_remove_device_attributes(struct device *);
  107. int qeth_l3_setrouting_v4(struct qeth_card *);
  108. int qeth_l3_setrouting_v6(struct qeth_card *);
  109. int qeth_l3_add_ipato_entry(struct qeth_card *, struct qeth_ipato_entry *);
  110. int qeth_l3_del_ipato_entry(struct qeth_card *card,
  111. enum qeth_prot_versions proto, u8 *addr,
  112. int mask_bits);
  113. void qeth_l3_update_ipato(struct qeth_card *card);
  114. int qeth_l3_modify_hsuid(struct qeth_card *card, bool add);
  115. int qeth_l3_modify_rxip_vipa(struct qeth_card *card, bool add, const u8 *ip,
  116. enum qeth_ip_types type,
  117. enum qeth_prot_versions proto);
  118. #endif /* __QETH_L3_H__ */