Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 /*
0003  *  SR-IPv6 implementation
0004  *
0005  *  Author:
0006  *  David Lebrun <david.lebrun@uclouvain.be>
0007  */
0008 
0009 #ifndef _NET_SEG6_H
0010 #define _NET_SEG6_H
0011 
0012 #include <linux/net.h>
0013 #include <linux/ipv6.h>
0014 #include <linux/seg6.h>
0015 #include <linux/rhashtable-types.h>
0016 
0017 static inline void update_csum_diff4(struct sk_buff *skb, __be32 from,
0018                      __be32 to)
0019 {
0020     __be32 diff[] = { ~from, to };
0021 
0022     skb->csum = ~csum_partial((char *)diff, sizeof(diff), ~skb->csum);
0023 }
0024 
0025 static inline void update_csum_diff16(struct sk_buff *skb, __be32 *from,
0026                       __be32 *to)
0027 {
0028     __be32 diff[] = {
0029         ~from[0], ~from[1], ~from[2], ~from[3],
0030         to[0], to[1], to[2], to[3],
0031     };
0032 
0033     skb->csum = ~csum_partial((char *)diff, sizeof(diff), ~skb->csum);
0034 }
0035 
0036 struct seg6_pernet_data {
0037     struct mutex lock;
0038     struct in6_addr __rcu *tun_src;
0039 #ifdef CONFIG_IPV6_SEG6_HMAC
0040     struct rhashtable hmac_infos;
0041 #endif
0042 };
0043 
0044 static inline struct seg6_pernet_data *seg6_pernet(struct net *net)
0045 {
0046 #if IS_ENABLED(CONFIG_IPV6)
0047     return net->ipv6.seg6_data;
0048 #else
0049     return NULL;
0050 #endif
0051 }
0052 
0053 extern int seg6_init(void);
0054 extern void seg6_exit(void);
0055 extern int seg6_iptunnel_init(void);
0056 extern void seg6_iptunnel_exit(void);
0057 extern int seg6_local_init(void);
0058 extern void seg6_local_exit(void);
0059 
0060 extern bool seg6_validate_srh(struct ipv6_sr_hdr *srh, int len, bool reduced);
0061 extern struct ipv6_sr_hdr *seg6_get_srh(struct sk_buff *skb, int flags);
0062 extern void seg6_icmp_srh(struct sk_buff *skb, struct inet6_skb_parm *opt);
0063 extern int seg6_do_srh_encap(struct sk_buff *skb, struct ipv6_sr_hdr *osrh,
0064                  int proto);
0065 extern int seg6_do_srh_inline(struct sk_buff *skb, struct ipv6_sr_hdr *osrh);
0066 extern int seg6_lookup_nexthop(struct sk_buff *skb, struct in6_addr *nhaddr,
0067                    u32 tbl_id);
0068 
0069 /* If the packet which invoked an ICMP error contains an SRH return
0070  * the true destination address from within the SRH, otherwise use the
0071  * destination address in the IP header.
0072  */
0073 static inline const struct in6_addr *seg6_get_daddr(struct sk_buff *skb,
0074                             struct inet6_skb_parm *opt)
0075 {
0076     struct ipv6_sr_hdr *srh;
0077 
0078     if (opt->flags & IP6SKB_SEG6) {
0079         srh = (struct ipv6_sr_hdr *)(skb->data + opt->srhoff);
0080         return  &srh->segments[0];
0081     }
0082 
0083     return NULL;
0084 }
0085 
0086 
0087 #endif