ila.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. * Copyright (c) 2015 Tom Herbert <tom@herbertland.com>
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation; either version 2 of
  7. * the License, or (at your option) any later version.
  8. *
  9. */
  10. #ifndef __ILA_H
  11. #define __ILA_H
  12. #include <linux/errno.h>
  13. #include <linux/ip.h>
  14. #include <linux/kernel.h>
  15. #include <linux/module.h>
  16. #include <linux/socket.h>
  17. #include <linux/skbuff.h>
  18. #include <linux/types.h>
  19. #include <net/checksum.h>
  20. #include <net/ip.h>
  21. #include <net/protocol.h>
  22. #include <uapi/linux/ila.h>
  23. struct ila_locator {
  24. union {
  25. __u8 v8[8];
  26. __be16 v16[4];
  27. __be32 v32[2];
  28. __be64 v64;
  29. };
  30. };
  31. struct ila_identifier {
  32. union {
  33. struct {
  34. #if defined(__LITTLE_ENDIAN_BITFIELD)
  35. u8 __space:4;
  36. u8 csum_neutral:1;
  37. u8 type:3;
  38. #elif defined(__BIG_ENDIAN_BITFIELD)
  39. u8 type:3;
  40. u8 csum_neutral:1;
  41. u8 __space:4;
  42. #else
  43. #error "Adjust your <asm/byteorder.h> defines"
  44. #endif
  45. u8 __space2[7];
  46. };
  47. __u8 v8[8];
  48. __be16 v16[4];
  49. __be32 v32[2];
  50. __be64 v64;
  51. };
  52. };
  53. enum {
  54. ILA_ATYPE_IID = 0,
  55. ILA_ATYPE_LUID,
  56. ILA_ATYPE_VIRT_V4,
  57. ILA_ATYPE_VIRT_UNI_V6,
  58. ILA_ATYPE_VIRT_MULTI_V6,
  59. ILA_ATYPE_RSVD_1,
  60. ILA_ATYPE_RSVD_2,
  61. ILA_ATYPE_RSVD_3,
  62. };
  63. #define CSUM_NEUTRAL_FLAG htonl(0x10000000)
  64. struct ila_addr {
  65. union {
  66. struct in6_addr addr;
  67. struct {
  68. struct ila_locator loc;
  69. struct ila_identifier ident;
  70. };
  71. };
  72. };
  73. static inline struct ila_addr *ila_a2i(struct in6_addr *addr)
  74. {
  75. return (struct ila_addr *)addr;
  76. }
  77. static inline bool ila_addr_is_ila(struct ila_addr *iaddr)
  78. {
  79. return (iaddr->ident.type != ILA_ATYPE_IID);
  80. }
  81. struct ila_params {
  82. struct ila_locator locator;
  83. struct ila_locator locator_match;
  84. __wsum csum_diff;
  85. u8 csum_mode;
  86. };
  87. static inline __wsum compute_csum_diff8(const __be32 *from, const __be32 *to)
  88. {
  89. __be32 diff[] = {
  90. ~from[0], ~from[1], to[0], to[1],
  91. };
  92. return csum_partial(diff, sizeof(diff), 0);
  93. }
  94. static inline bool ila_csum_neutral_set(struct ila_identifier ident)
  95. {
  96. return !!(ident.csum_neutral);
  97. }
  98. void ila_update_ipv6_locator(struct sk_buff *skb, struct ila_params *p,
  99. bool set_csum_neutral);
  100. void ila_init_saved_csum(struct ila_params *p);
  101. int ila_lwt_init(void);
  102. void ila_lwt_fini(void);
  103. int ila_xlat_init(void);
  104. void ila_xlat_fini(void);
  105. #endif /* __ILA_H */