seg6.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * SR-IPv6 implementation
  4. *
  5. * Author:
  6. * David Lebrun <david.lebrun@uclouvain.be>
  7. */
  8. #ifndef _NET_SEG6_H
  9. #define _NET_SEG6_H
  10. #include <linux/net.h>
  11. #include <linux/ipv6.h>
  12. #include <linux/seg6.h>
  13. #include <linux/rhashtable-types.h>
  14. static inline void update_csum_diff4(struct sk_buff *skb, __be32 from,
  15. __be32 to)
  16. {
  17. __be32 diff[] = { ~from, to };
  18. skb->csum = ~csum_partial((char *)diff, sizeof(diff), ~skb->csum);
  19. }
  20. static inline void update_csum_diff16(struct sk_buff *skb, __be32 *from,
  21. __be32 *to)
  22. {
  23. __be32 diff[] = {
  24. ~from[0], ~from[1], ~from[2], ~from[3],
  25. to[0], to[1], to[2], to[3],
  26. };
  27. skb->csum = ~csum_partial((char *)diff, sizeof(diff), ~skb->csum);
  28. }
  29. struct seg6_pernet_data {
  30. struct mutex lock;
  31. struct in6_addr __rcu *tun_src;
  32. #ifdef CONFIG_IPV6_SEG6_HMAC
  33. struct rhashtable hmac_infos;
  34. #endif
  35. };
  36. static inline struct seg6_pernet_data *seg6_pernet(struct net *net)
  37. {
  38. #if IS_ENABLED(CONFIG_IPV6)
  39. return net->ipv6.seg6_data;
  40. #else
  41. return NULL;
  42. #endif
  43. }
  44. extern int seg6_init(void);
  45. extern void seg6_exit(void);
  46. #ifdef CONFIG_IPV6_SEG6_LWTUNNEL
  47. extern int seg6_iptunnel_init(void);
  48. extern void seg6_iptunnel_exit(void);
  49. extern int seg6_local_init(void);
  50. extern void seg6_local_exit(void);
  51. #else
  52. static inline int seg6_iptunnel_init(void) { return 0; }
  53. static inline void seg6_iptunnel_exit(void) {}
  54. static inline int seg6_local_init(void) { return 0; }
  55. static inline void seg6_local_exit(void) {}
  56. #endif
  57. extern bool seg6_validate_srh(struct ipv6_sr_hdr *srh, int len, bool reduced);
  58. extern struct ipv6_sr_hdr *seg6_get_srh(struct sk_buff *skb, int flags);
  59. extern void seg6_icmp_srh(struct sk_buff *skb, struct inet6_skb_parm *opt);
  60. extern int seg6_do_srh_encap(struct sk_buff *skb, struct ipv6_sr_hdr *osrh,
  61. int proto);
  62. extern int seg6_do_srh_inline(struct sk_buff *skb, struct ipv6_sr_hdr *osrh);
  63. extern int seg6_lookup_nexthop(struct sk_buff *skb, struct in6_addr *nhaddr,
  64. u32 tbl_id);
  65. /* If the packet which invoked an ICMP error contains an SRH return
  66. * the true destination address from within the SRH, otherwise use the
  67. * destination address in the IP header.
  68. */
  69. static inline const struct in6_addr *seg6_get_daddr(struct sk_buff *skb,
  70. struct inet6_skb_parm *opt)
  71. {
  72. struct ipv6_sr_hdr *srh;
  73. if (opt->flags & IP6SKB_SEG6) {
  74. srh = (struct ipv6_sr_hdr *)(skb->data + opt->srhoff);
  75. return &srh->segments[0];
  76. }
  77. return NULL;
  78. }
  79. #endif