seg6_hmac.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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_HMAC_H
  9. #define _NET_SEG6_HMAC_H
  10. #include <crypto/sha1.h>
  11. #include <crypto/sha2.h>
  12. #include <net/flow.h>
  13. #include <net/ip6_fib.h>
  14. #include <net/sock.h>
  15. #include <linux/ip.h>
  16. #include <linux/ipv6.h>
  17. #include <linux/route.h>
  18. #include <net/seg6.h>
  19. #include <linux/seg6_hmac.h>
  20. #include <linux/rhashtable-types.h>
  21. #define SEG6_HMAC_RING_SIZE 256
  22. struct seg6_hmac_info {
  23. struct rhash_head node;
  24. struct rcu_head rcu;
  25. u32 hmackeyid;
  26. /* The raw key, kept only so it can be returned back to userspace */
  27. char secret[SEG6_HMAC_SECRET_LEN];
  28. u8 slen;
  29. u8 alg_id;
  30. /* The prepared key, which the calculations actually use */
  31. union {
  32. struct hmac_sha1_key sha1;
  33. struct hmac_sha256_key sha256;
  34. } key;
  35. };
  36. extern int seg6_hmac_compute(struct seg6_hmac_info *hinfo,
  37. struct ipv6_sr_hdr *hdr, struct in6_addr *saddr,
  38. u8 *output);
  39. extern struct seg6_hmac_info *seg6_hmac_info_lookup(struct net *net, u32 key);
  40. extern int seg6_hmac_info_add(struct net *net, u32 key,
  41. struct seg6_hmac_info *hinfo);
  42. extern int seg6_hmac_info_del(struct net *net, u32 key);
  43. extern int seg6_push_hmac(struct net *net, struct in6_addr *saddr,
  44. struct ipv6_sr_hdr *srh);
  45. extern bool seg6_hmac_validate_skb(struct sk_buff *skb);
  46. #ifdef CONFIG_IPV6_SEG6_HMAC
  47. extern int seg6_hmac_net_init(struct net *net);
  48. extern void seg6_hmac_net_exit(struct net *net);
  49. #else
  50. static inline int seg6_hmac_net_init(struct net *net) { return 0; }
  51. static inline void seg6_hmac_net_exit(struct net *net) {}
  52. #endif
  53. #endif