ila.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * Copyright (c) 2015 Tom Herbert <[email protected]>
  4. */
  5. #ifndef __ILA_H
  6. #define __ILA_H
  7. #include <linux/errno.h>
  8. #include <linux/ip.h>
  9. #include <linux/kernel.h>
  10. #include <linux/module.h>
  11. #include <linux/socket.h>
  12. #include <linux/skbuff.h>
  13. #include <linux/types.h>
  14. #include <net/checksum.h>
  15. #include <net/genetlink.h>
  16. #include <net/ip.h>
  17. #include <net/protocol.h>
  18. #include <uapi/linux/ila.h>
  19. struct ila_locator {
  20. union {
  21. __u8 v8[8];
  22. __be16 v16[4];
  23. __be32 v32[2];
  24. __be64 v64;
  25. };
  26. };
  27. struct ila_identifier {
  28. union {
  29. struct {
  30. #if defined(__LITTLE_ENDIAN_BITFIELD)
  31. u8 __space:4;
  32. u8 csum_neutral:1;
  33. u8 type:3;
  34. #elif defined(__BIG_ENDIAN_BITFIELD)
  35. u8 type:3;
  36. u8 csum_neutral:1;
  37. u8 __space:4;
  38. #else
  39. #error "Adjust your <asm/byteorder.h> defines"
  40. #endif
  41. u8 __space2[7];
  42. };
  43. __u8 v8[8];
  44. __be16 v16[4];
  45. __be32 v32[2];
  46. __be64 v64;
  47. };
  48. };
  49. #define CSUM_NEUTRAL_FLAG htonl(0x10000000)
  50. struct ila_addr {
  51. union {
  52. struct in6_addr addr;
  53. struct {
  54. struct ila_locator loc;
  55. struct ila_identifier ident;
  56. };
  57. };
  58. };
  59. static inline struct ila_addr *ila_a2i(struct in6_addr *addr)
  60. {
  61. return (struct ila_addr *)addr;
  62. }
  63. struct ila_params {
  64. struct ila_locator locator;
  65. struct ila_locator locator_match;
  66. __wsum csum_diff;
  67. u8 csum_mode;
  68. u8 ident_type;
  69. };
  70. static inline __wsum compute_csum_diff8(const __be32 *from, const __be32 *to)
  71. {
  72. __be32 diff[] = {
  73. ~from[0], ~from[1], to[0], to[1],
  74. };
  75. return csum_partial(diff, sizeof(diff), 0);
  76. }
  77. static inline bool ila_csum_neutral_set(struct ila_identifier ident)
  78. {
  79. return !!(ident.csum_neutral);
  80. }
  81. void ila_update_ipv6_locator(struct sk_buff *skb, struct ila_params *p,
  82. bool set_csum_neutral);
  83. void ila_init_saved_csum(struct ila_params *p);
  84. struct ila_net {
  85. struct {
  86. struct rhashtable rhash_table;
  87. spinlock_t *locks; /* Bucket locks for entry manipulation */
  88. unsigned int locks_mask;
  89. bool hooks_registered;
  90. } xlat;
  91. };
  92. int ila_lwt_init(void);
  93. void ila_lwt_fini(void);
  94. int ila_xlat_init_net(struct net *net);
  95. void ila_xlat_exit_net(struct net *net);
  96. int ila_xlat_nl_cmd_add_mapping(struct sk_buff *skb, struct genl_info *info);
  97. int ila_xlat_nl_cmd_del_mapping(struct sk_buff *skb, struct genl_info *info);
  98. int ila_xlat_nl_cmd_get_mapping(struct sk_buff *skb, struct genl_info *info);
  99. int ila_xlat_nl_cmd_flush(struct sk_buff *skb, struct genl_info *info);
  100. int ila_xlat_nl_dump_start(struct netlink_callback *cb);
  101. int ila_xlat_nl_dump_done(struct netlink_callback *cb);
  102. int ila_xlat_nl_dump(struct sk_buff *skb, struct netlink_callback *cb);
  103. extern unsigned int ila_net_id;
  104. extern struct genl_family ila_nl_family;
  105. #endif /* __ILA_H */