Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
David Lebrun | 1ababeb | 2016-11-08 14:57:39 +0100 | [diff] [blame] | 2 | /* |
| 3 | * SR-IPv6 implementation |
| 4 | * |
| 5 | * Author: |
| 6 | * David Lebrun <david.lebrun@uclouvain.be> |
David Lebrun | 1ababeb | 2016-11-08 14:57:39 +0100 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #ifndef _NET_SEG6_H |
| 10 | #define _NET_SEG6_H |
| 11 | |
David Lebrun | 915d7e5 | 2016-11-08 14:57:40 +0100 | [diff] [blame] | 12 | #include <linux/net.h> |
| 13 | #include <linux/ipv6.h> |
David Lebrun | 6c8702c | 2016-11-08 14:57:41 +0100 | [diff] [blame] | 14 | #include <linux/seg6.h> |
NeilBrown | 0eb71a9 | 2018-06-18 12:52:50 +1000 | [diff] [blame] | 15 | #include <linux/rhashtable-types.h> |
David Lebrun | 915d7e5 | 2016-11-08 14:57:40 +0100 | [diff] [blame] | 16 | |
David Lebrun | 1ababeb | 2016-11-08 14:57:39 +0100 | [diff] [blame] | 17 | static inline void update_csum_diff4(struct sk_buff *skb, __be32 from, |
| 18 | __be32 to) |
| 19 | { |
| 20 | __be32 diff[] = { ~from, to }; |
| 21 | |
| 22 | skb->csum = ~csum_partial((char *)diff, sizeof(diff), ~skb->csum); |
| 23 | } |
| 24 | |
| 25 | static inline void update_csum_diff16(struct sk_buff *skb, __be32 *from, |
| 26 | __be32 *to) |
| 27 | { |
| 28 | __be32 diff[] = { |
| 29 | ~from[0], ~from[1], ~from[2], ~from[3], |
| 30 | to[0], to[1], to[2], to[3], |
| 31 | }; |
| 32 | |
| 33 | skb->csum = ~csum_partial((char *)diff, sizeof(diff), ~skb->csum); |
| 34 | } |
| 35 | |
David Lebrun | 915d7e5 | 2016-11-08 14:57:40 +0100 | [diff] [blame] | 36 | struct seg6_pernet_data { |
| 37 | struct mutex lock; |
| 38 | struct in6_addr __rcu *tun_src; |
David Lebrun | bf355b8 | 2016-11-08 14:57:42 +0100 | [diff] [blame] | 39 | #ifdef CONFIG_IPV6_SEG6_HMAC |
| 40 | struct rhashtable hmac_infos; |
| 41 | #endif |
David Lebrun | 915d7e5 | 2016-11-08 14:57:40 +0100 | [diff] [blame] | 42 | }; |
| 43 | |
| 44 | static inline struct seg6_pernet_data *seg6_pernet(struct net *net) |
| 45 | { |
Mathieu Xhonneux | 63526e1 | 2018-05-20 14:58:12 +0100 | [diff] [blame] | 46 | #if IS_ENABLED(CONFIG_IPV6) |
David Lebrun | 915d7e5 | 2016-11-08 14:57:40 +0100 | [diff] [blame] | 47 | return net->ipv6.seg6_data; |
Mathieu Xhonneux | 63526e1 | 2018-05-20 14:58:12 +0100 | [diff] [blame] | 48 | #else |
| 49 | return NULL; |
| 50 | #endif |
David Lebrun | 915d7e5 | 2016-11-08 14:57:40 +0100 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | extern int seg6_init(void); |
| 54 | extern void seg6_exit(void); |
David Lebrun | 6c8702c | 2016-11-08 14:57:41 +0100 | [diff] [blame] | 55 | extern int seg6_iptunnel_init(void); |
| 56 | extern void seg6_iptunnel_exit(void); |
David Lebrun | d1df6fd | 2017-08-05 12:38:26 +0200 | [diff] [blame] | 57 | extern int seg6_local_init(void); |
| 58 | extern void seg6_local_exit(void); |
David Lebrun | 6c8702c | 2016-11-08 14:57:41 +0100 | [diff] [blame] | 59 | |
Ahmed Abdelsalam | bb986a5 | 2020-06-03 06:54:42 +0000 | [diff] [blame] | 60 | extern bool seg6_validate_srh(struct ipv6_sr_hdr *srh, int len, bool reduced); |
Andrew Lunn | fa55a7d | 2022-01-03 18:11:30 +0100 | [diff] [blame] | 61 | extern struct ipv6_sr_hdr *seg6_get_srh(struct sk_buff *skb, int flags); |
Andrew Lunn | e412944 | 2022-01-03 18:11:31 +0100 | [diff] [blame] | 62 | extern void seg6_icmp_srh(struct sk_buff *skb, struct inet6_skb_parm *opt); |
David Lebrun | 32d99d0 | 2017-08-25 09:56:44 +0200 | [diff] [blame] | 63 | extern int seg6_do_srh_encap(struct sk_buff *skb, struct ipv6_sr_hdr *osrh, |
| 64 | int proto); |
David Lebrun | b04c80d | 2017-08-05 12:38:25 +0200 | [diff] [blame] | 65 | extern int seg6_do_srh_inline(struct sk_buff *skb, struct ipv6_sr_hdr *osrh); |
Mathieu Xhonneux | 1c1e761 | 2018-05-20 14:58:13 +0100 | [diff] [blame] | 66 | extern int seg6_lookup_nexthop(struct sk_buff *skb, struct in6_addr *nhaddr, |
| 67 | u32 tbl_id); |
Andrew Lunn | 222a011 | 2022-01-03 18:11:32 +0100 | [diff] [blame] | 68 | |
| 69 | /* If the packet which invoked an ICMP error contains an SRH return |
| 70 | * the true destination address from within the SRH, otherwise use the |
| 71 | * destination address in the IP header. |
| 72 | */ |
| 73 | static inline const struct in6_addr *seg6_get_daddr(struct sk_buff *skb, |
| 74 | struct inet6_skb_parm *opt) |
| 75 | { |
| 76 | struct ipv6_sr_hdr *srh; |
| 77 | |
| 78 | if (opt->flags & IP6SKB_SEG6) { |
| 79 | srh = (struct ipv6_sr_hdr *)(skb->data + opt->srhoff); |
| 80 | return &srh->segments[0]; |
| 81 | } |
| 82 | |
| 83 | return NULL; |
| 84 | } |
| 85 | |
| 86 | |
David Lebrun | 1ababeb | 2016-11-08 14:57:39 +0100 | [diff] [blame] | 87 | #endif |