qeth_l3.h 3.0 KB

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