^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0-or-later */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * SR-IPv6 implementation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Author:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * David Lebrun <david.lebrun@uclouvain.be>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #ifndef _NET_SEG6_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #define _NET_SEG6_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/net.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/ipv6.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/seg6.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/rhashtable-types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) static inline void update_csum_diff4(struct sk_buff *skb, __be32 from,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) __be32 to)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) __be32 diff[] = { ~from, to };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) skb->csum = ~csum_partial((char *)diff, sizeof(diff), ~skb->csum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) static inline void update_csum_diff16(struct sk_buff *skb, __be32 *from,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) __be32 *to)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) __be32 diff[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) ~from[0], ~from[1], ~from[2], ~from[3],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) to[0], to[1], to[2], to[3],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) skb->csum = ~csum_partial((char *)diff, sizeof(diff), ~skb->csum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) struct seg6_pernet_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) struct mutex lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) struct in6_addr __rcu *tun_src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #ifdef CONFIG_IPV6_SEG6_HMAC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) struct rhashtable hmac_infos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) static inline struct seg6_pernet_data *seg6_pernet(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #if IS_ENABLED(CONFIG_IPV6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) return net->ipv6.seg6_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) extern int seg6_init(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) extern void seg6_exit(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) extern int seg6_iptunnel_init(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) extern void seg6_iptunnel_exit(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) extern int seg6_local_init(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) extern void seg6_local_exit(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) extern bool seg6_validate_srh(struct ipv6_sr_hdr *srh, int len, bool reduced);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) extern int seg6_do_srh_encap(struct sk_buff *skb, struct ipv6_sr_hdr *osrh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) int proto);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) extern int seg6_do_srh_inline(struct sk_buff *skb, struct ipv6_sr_hdr *osrh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) extern int seg6_lookup_nexthop(struct sk_buff *skb, struct in6_addr *nhaddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) u32 tbl_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) #endif