David Lebrun | 1ababeb | 2016-11-08 14:57:39 +0100 | [diff] [blame] | 1 | /* |
| 2 | * SR-IPv6 implementation |
| 3 | * |
| 4 | * Author: |
| 5 | * David Lebrun <david.lebrun@uclouvain.be> |
| 6 | * |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License |
| 10 | * as published by the Free Software Foundation; either version |
| 11 | * 2 of the License, or (at your option) any later version. |
| 12 | */ |
| 13 | |
| 14 | #ifndef _NET_SEG6_H |
| 15 | #define _NET_SEG6_H |
| 16 | |
David Lebrun | 915d7e5 | 2016-11-08 14:57:40 +0100 | [diff] [blame] | 17 | #include <linux/net.h> |
| 18 | #include <linux/ipv6.h> |
David Lebrun | 6c8702c | 2016-11-08 14:57:41 +0100 | [diff] [blame] | 19 | #include <net/lwtunnel.h> |
| 20 | #include <linux/seg6.h> |
NeilBrown | 0eb71a9 | 2018-06-18 12:52:50 +1000 | [diff] [blame] | 21 | #include <linux/rhashtable-types.h> |
David Lebrun | 915d7e5 | 2016-11-08 14:57:40 +0100 | [diff] [blame] | 22 | |
David Lebrun | 1ababeb | 2016-11-08 14:57:39 +0100 | [diff] [blame] | 23 | static inline void update_csum_diff4(struct sk_buff *skb, __be32 from, |
| 24 | __be32 to) |
| 25 | { |
| 26 | __be32 diff[] = { ~from, to }; |
| 27 | |
| 28 | skb->csum = ~csum_partial((char *)diff, sizeof(diff), ~skb->csum); |
| 29 | } |
| 30 | |
| 31 | static inline void update_csum_diff16(struct sk_buff *skb, __be32 *from, |
| 32 | __be32 *to) |
| 33 | { |
| 34 | __be32 diff[] = { |
| 35 | ~from[0], ~from[1], ~from[2], ~from[3], |
| 36 | to[0], to[1], to[2], to[3], |
| 37 | }; |
| 38 | |
| 39 | skb->csum = ~csum_partial((char *)diff, sizeof(diff), ~skb->csum); |
| 40 | } |
| 41 | |
David Lebrun | 915d7e5 | 2016-11-08 14:57:40 +0100 | [diff] [blame] | 42 | struct seg6_pernet_data { |
| 43 | struct mutex lock; |
| 44 | struct in6_addr __rcu *tun_src; |
David Lebrun | bf355b8 | 2016-11-08 14:57:42 +0100 | [diff] [blame] | 45 | #ifdef CONFIG_IPV6_SEG6_HMAC |
| 46 | struct rhashtable hmac_infos; |
| 47 | #endif |
David Lebrun | 915d7e5 | 2016-11-08 14:57:40 +0100 | [diff] [blame] | 48 | }; |
| 49 | |
| 50 | static inline struct seg6_pernet_data *seg6_pernet(struct net *net) |
| 51 | { |
Mathieu Xhonneux | 63526e1 | 2018-05-20 14:58:12 +0100 | [diff] [blame] | 52 | #if IS_ENABLED(CONFIG_IPV6) |
David Lebrun | 915d7e5 | 2016-11-08 14:57:40 +0100 | [diff] [blame] | 53 | return net->ipv6.seg6_data; |
Mathieu Xhonneux | 63526e1 | 2018-05-20 14:58:12 +0100 | [diff] [blame] | 54 | #else |
| 55 | return NULL; |
| 56 | #endif |
David Lebrun | 915d7e5 | 2016-11-08 14:57:40 +0100 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | extern int seg6_init(void); |
| 60 | extern void seg6_exit(void); |
David Lebrun | 6c8702c | 2016-11-08 14:57:41 +0100 | [diff] [blame] | 61 | extern int seg6_iptunnel_init(void); |
| 62 | extern void seg6_iptunnel_exit(void); |
David Lebrun | d1df6fd | 2017-08-05 12:38:26 +0200 | [diff] [blame] | 63 | extern int seg6_local_init(void); |
| 64 | extern void seg6_local_exit(void); |
David Lebrun | 6c8702c | 2016-11-08 14:57:41 +0100 | [diff] [blame] | 65 | |
| 66 | extern bool seg6_validate_srh(struct ipv6_sr_hdr *srh, int len); |
David Lebrun | 32d99d0 | 2017-08-25 09:56:44 +0200 | [diff] [blame] | 67 | extern int seg6_do_srh_encap(struct sk_buff *skb, struct ipv6_sr_hdr *osrh, |
| 68 | int proto); |
David Lebrun | b04c80d | 2017-08-05 12:38:25 +0200 | [diff] [blame] | 69 | 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] | 70 | extern int seg6_lookup_nexthop(struct sk_buff *skb, struct in6_addr *nhaddr, |
| 71 | u32 tbl_id); |
David Lebrun | 1ababeb | 2016-11-08 14:57:39 +0100 | [diff] [blame] | 72 | #endif |