qeth_l3.h 3.4 KB

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