ila.h 3.0 KB

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