1 #ifndef __NET_UDP_TUNNEL_WRAPPER_H
2 #define __NET_UDP_TUNNEL_WRAPPER_H
4 #include <linux/version.h>
5 #include <linux/kconfig.h>
7 #include <net/addrconf.h>
8 #include <net/dst_metadata.h>
9 #include <linux/netdev_features.h>
11 #ifdef USE_UPSTREAM_TUNNEL
12 #include_next <net/udp_tunnel.h>
16 #include <net/addrconf.h>
17 #include <net/ip_tunnels.h>
23 /* Used only for kernel-created sockets */
25 struct in_addr local_ip;
26 #if IS_ENABLED(CONFIG_IPV6)
27 struct in6_addr local_ip6;
32 struct in_addr peer_ip;
33 #if IS_ENABLED(CONFIG_IPV6)
34 struct in6_addr peer_ip6;
38 __be16 local_udp_port;
40 unsigned int use_udp_checksums:1,
41 use_udp6_tx_checksums:1,
42 use_udp6_rx_checksums:1,
46 #define udp_sock_create4 rpl_udp_sock_create4
47 int rpl_udp_sock_create4(struct net *net, struct udp_port_cfg *cfg,
48 struct socket **sockp);
50 #define udp_sock_create6 rpl_udp_sock_create6
51 #if IS_ENABLED(CONFIG_IPV6)
52 int rpl_udp_sock_create6(struct net *net, struct udp_port_cfg *cfg,
53 struct socket **sockp);
55 static inline int udp_sock_create6(struct net *net, struct udp_port_cfg *cfg,
56 struct socket **sockp)
62 #define udp_sock_create rpl_udp_sock_create
63 static inline int udp_sock_create(struct net *net,
64 struct udp_port_cfg *cfg,
65 struct socket **sockp)
67 if (cfg->family == AF_INET)
68 return udp_sock_create4(net, cfg, sockp);
70 if (cfg->family == AF_INET6)
71 return udp_sock_create6(net, cfg, sockp);
76 typedef int (*udp_tunnel_encap_rcv_t)(struct sock *sk, struct sk_buff *skb);
77 typedef void (*udp_tunnel_encap_destroy_t)(struct sock *sk);
78 typedef struct sk_buff **(*udp_tunnel_gro_receive_t)(struct sock *sk,
79 struct sk_buff **head,
81 typedef int (*udp_tunnel_gro_complete_t)(struct sock *sk, struct sk_buff *skb,
84 struct udp_tunnel_sock_cfg {
85 void *sk_user_data; /* user data used by encap_rcv call back */
86 /* Used for setting up udp_sock fields, see udp.h for details */
88 udp_tunnel_encap_rcv_t encap_rcv;
89 udp_tunnel_encap_destroy_t encap_destroy;
90 #ifdef HAVE_UDP_TUNNEL_SOCK_CFG_GRO_RECEIVE
91 udp_tunnel_gro_receive_t gro_receive;
92 udp_tunnel_gro_complete_t gro_complete;
96 /* Setup the given (UDP) sock to receive UDP encapsulated packets */
97 #define setup_udp_tunnel_sock rpl_setup_udp_tunnel_sock
98 void rpl_setup_udp_tunnel_sock(struct net *net, struct socket *sock,
99 struct udp_tunnel_sock_cfg *sock_cfg);
101 /* Transmit the skb using UDP encapsulation. */
102 #define udp_tunnel_xmit_skb rpl_udp_tunnel_xmit_skb
103 void rpl_udp_tunnel_xmit_skb(struct rtable *rt,
104 struct sock *sk, struct sk_buff *skb,
105 __be32 src, __be32 dst, __u8 tos, __u8 ttl,
106 __be16 df, __be16 src_port, __be16 dst_port,
107 bool xnet, bool nocheck);
110 #define udp_tunnel_sock_release rpl_udp_tunnel_sock_release
111 void rpl_udp_tunnel_sock_release(struct socket *sock);
113 #define udp_tunnel_encap_enable rpl_udp_tunnel_encap_enable
114 static inline void udp_tunnel_encap_enable(struct socket *sock)
116 #if IS_ENABLED(CONFIG_IPV6)
117 if (sock->sk->sk_family == PF_INET6)
118 #ifdef HAVE_IPV6_STUB
119 ipv6_stub->udpv6_encap_enable();
121 udpv6_encap_enable();
128 #if IS_ENABLED(CONFIG_IPV6)
129 #define udp_tunnel6_xmit_skb rpl_udp_tunnel6_xmit_skb
130 int rpl_udp_tunnel6_xmit_skb(struct dst_entry *dst, struct sock *sk,
132 struct net_device *dev, struct in6_addr *saddr,
133 struct in6_addr *daddr,
134 __u8 prio, __u8 ttl, __be32 label, __be16 src_port,
135 __be16 dst_port, bool nocheck);
138 static inline void udp_tunnel_gro_complete(struct sk_buff *skb, int nhoff)
142 uh = (struct udphdr *)(skb->data + nhoff - sizeof(struct udphdr));
143 skb_shinfo(skb)->gso_type |= uh->check ?
144 SKB_GSO_UDP_TUNNEL_CSUM : SKB_GSO_UDP_TUNNEL;
147 void ovs_udp_gso(struct sk_buff *skb);
148 void ovs_udp_csum_gso(struct sk_buff *skb);
150 static inline int rpl_udp_tunnel_handle_offloads(struct sk_buff *skb,
155 void (*fix_segment)(struct sk_buff *);
157 if (skb_is_gso(skb) && skb_is_encapsulated(skb)) {
161 type |= udp_csum ? SKB_GSO_UDP_TUNNEL_CSUM : SKB_GSO_UDP_TUNNEL;
163 fix_segment = ovs_udp_gso;
165 fix_segment = ovs_udp_csum_gso;
166 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,18,0)
167 /* This functuin is not used by vxlan lan tunnel. On older
168 * udp offload only supports vxlan, therefore fallback to software
174 return ovs_iptunnel_handle_offloads(skb, udp_csum, type, fix_segment);
177 #define udp_tunnel_handle_offloads rpl_udp_tunnel_handle_offloads
178 static inline void ovs_udp_tun_rx_dst(struct metadata_dst *md_dst,
180 unsigned short family,
181 __be16 flags, __be64 tunnel_id, int md_size)
183 struct ip_tunnel_info *info = &md_dst->u.tun_info;
185 if (family == AF_INET)
186 ovs_ip_tun_rx_dst(md_dst, skb, flags, tunnel_id, md_size);
188 ovs_ipv6_tun_rx_dst(md_dst, skb, flags, tunnel_id, md_size);
190 info->key.tp_src = udp_hdr(skb)->source;
191 info->key.tp_dst = udp_hdr(skb)->dest;
192 if (udp_hdr(skb)->check)
193 info->key.tun_flags |= TUNNEL_CSUM;
195 #endif /* USE_UPSTREAM_TUNNEL */