seg6.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * SR-IPv6 implementation
  4. *
  5. * Author:
  6. * David Lebrun <[email protected]>
  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. extern int seg6_iptunnel_init(void);
  47. extern void seg6_iptunnel_exit(void);
  48. extern int seg6_local_init(void);
  49. extern void seg6_local_exit(void);
  50. extern bool seg6_validate_srh(struct ipv6_sr_hdr *srh, int len, bool reduced);
  51. extern struct ipv6_sr_hdr *seg6_get_srh(struct sk_buff *skb, int flags);
  52. extern void seg6_icmp_srh(struct sk_buff *skb, struct inet6_skb_parm *opt);
  53. extern int seg6_do_srh_encap(struct sk_buff *skb, struct ipv6_sr_hdr *osrh,
  54. int proto);
  55. extern int seg6_do_srh_inline(struct sk_buff *skb, struct ipv6_sr_hdr *osrh);
  56. extern int seg6_lookup_nexthop(struct sk_buff *skb, struct in6_addr *nhaddr,
  57. u32 tbl_id);
  58. /* If the packet which invoked an ICMP error contains an SRH return
  59. * the true destination address from within the SRH, otherwise use the
  60. * destination address in the IP header.
  61. */
  62. static inline const struct in6_addr *seg6_get_daddr(struct sk_buff *skb,
  63. struct inet6_skb_parm *opt)
  64. {
  65. struct ipv6_sr_hdr *srh;
  66. if (opt->flags & IP6SKB_SEG6) {
  67. srh = (struct ipv6_sr_hdr *)(skb->data + opt->srhoff);
  68. return &srh->segments[0];
  69. }
  70. return NULL;
  71. }
  72. #endif