]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - include/net/ip_tunnels.h
Merge tag 'sound-fix-4.3-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/tiwai...
[karo-tx-linux.git] / include / net / ip_tunnels.h
index 984dbfa15e13f199682825fa10e0f295be9102ad..9a6a3ba888e8d48e9cd706f48f045113e79d19f4 100644 (file)
@@ -4,6 +4,7 @@
 #include <linux/if_tunnel.h>
 #include <linux/netdevice.h>
 #include <linux/skbuff.h>
+#include <linux/socket.h>
 #include <linux/types.h>
 #include <linux/u64_stats_sync.h>
 #include <net/dsfield.h>
 #define IPTUNNEL_ERR_TIMEO     (30*HZ)
 
 /* Used to memset ip_tunnel padding. */
-#define IP_TUNNEL_KEY_SIZE                                     \
-       (offsetof(struct ip_tunnel_key, tp_dst) +               \
-        FIELD_SIZEOF(struct ip_tunnel_key, tp_dst))
+#define IP_TUNNEL_KEY_SIZE     offsetofend(struct ip_tunnel_key, tp_dst)
+
+/* Used to memset ipv4 address padding. */
+#define IP_TUNNEL_KEY_IPV4_PAD offsetofend(struct ip_tunnel_key, u.ipv4.dst)
+#define IP_TUNNEL_KEY_IPV4_PAD_LEN                             \
+       (FIELD_SIZEOF(struct ip_tunnel_key, u) -                \
+        FIELD_SIZEOF(struct ip_tunnel_key, u.ipv4))
 
 struct ip_tunnel_key {
        __be64                  tun_id;
-       __be32                  ipv4_src;
-       __be32                  ipv4_dst;
+       union {
+               struct {
+                       __be32  src;
+                       __be32  dst;
+               } ipv4;
+               struct {
+                       struct in6_addr src;
+                       struct in6_addr dst;
+               } ipv6;
+       } u;
        __be16                  tun_flags;
-       __u8                    ipv4_tos;
-       __u8                    ipv4_ttl;
+       u8                      tos;            /* TOS for IPv4, TC for IPv6 */
+       u8                      ttl;            /* TTL for IPv4, HL for IPv6 */
        __be16                  tp_src;
        __be16                  tp_dst;
-} __packed __aligned(4); /* Minimize padding. */
-
-/* Indicates whether the tunnel info structure represents receive
- * or transmit tunnel parameters.
- */
-enum {
-       IP_TUNNEL_INFO_RX,
-       IP_TUNNEL_INFO_TX,
 };
 
+/* Flags for ip_tunnel_info mode. */
+#define IP_TUNNEL_INFO_TX      0x01    /* represents tx tunnel parameters */
+#define IP_TUNNEL_INFO_IPV6    0x02    /* key contains IPv6 addresses */
+
 struct ip_tunnel_info {
        struct ip_tunnel_key    key;
-       const void              *options;
        u8                      options_len;
        u8                      mode;
 };
@@ -64,8 +72,8 @@ struct ip_tunnel_6rd_parm {
 #endif
 
 struct ip_tunnel_encap {
-       __u16                   type;
-       __u16                   flags;
+       u16                     type;
+       u16                     flags;
        __be16                  sport;
        __be16                  dport;
 };
@@ -95,8 +103,8 @@ struct ip_tunnel {
                                         * arrived */
 
        /* These four fields used only by GRE */
-       __u32           i_seqno;        /* The last seen seqno  */
-       __u32           o_seqno;        /* The last output seqno */
+       u32             i_seqno;        /* The last seen seqno  */
+       u32             o_seqno;        /* The last output seqno */
        int             tun_hlen;       /* Precalculated header length */
        int             mlink;
 
@@ -171,45 +179,38 @@ int ip_tunnel_encap_add_ops(const struct ip_tunnel_encap_ops *op,
 int ip_tunnel_encap_del_ops(const struct ip_tunnel_encap_ops *op,
                            unsigned int num);
 
-static inline void __ip_tunnel_info_init(struct ip_tunnel_info *tun_info,
-                                        __be32 saddr, __be32 daddr,
-                                        u8 tos, u8 ttl,
-                                        __be16 tp_src, __be16 tp_dst,
-                                        __be64 tun_id, __be16 tun_flags,
-                                        const void *opts, u8 opts_len)
+static inline void ip_tunnel_key_init(struct ip_tunnel_key *key,
+                                     __be32 saddr, __be32 daddr,
+                                     u8 tos, u8 ttl,
+                                     __be16 tp_src, __be16 tp_dst,
+                                     __be64 tun_id, __be16 tun_flags)
 {
-       tun_info->key.tun_id = tun_id;
-       tun_info->key.ipv4_src = saddr;
-       tun_info->key.ipv4_dst = daddr;
-       tun_info->key.ipv4_tos = tos;
-       tun_info->key.ipv4_ttl = ttl;
-       tun_info->key.tun_flags = tun_flags;
+       key->tun_id = tun_id;
+       key->u.ipv4.src = saddr;
+       key->u.ipv4.dst = daddr;
+       memset((unsigned char *)key + IP_TUNNEL_KEY_IPV4_PAD,
+              0, IP_TUNNEL_KEY_IPV4_PAD_LEN);
+       key->tos = tos;
+       key->ttl = ttl;
+       key->tun_flags = tun_flags;
 
        /* For the tunnel types on the top of IPsec, the tp_src and tp_dst of
         * the upper tunnel are used.
         * E.g: GRE over IPSEC, the tp_src and tp_port are zero.
         */
-       tun_info->key.tp_src = tp_src;
-       tun_info->key.tp_dst = tp_dst;
+       key->tp_src = tp_src;
+       key->tp_dst = tp_dst;
 
        /* Clear struct padding. */
-       if (sizeof(tun_info->key) != IP_TUNNEL_KEY_SIZE)
-               memset((unsigned char *)&tun_info->key + IP_TUNNEL_KEY_SIZE,
-                      0, sizeof(tun_info->key) - IP_TUNNEL_KEY_SIZE);
-
-       tun_info->options = opts;
-       tun_info->options_len = opts_len;
+       if (sizeof(*key) != IP_TUNNEL_KEY_SIZE)
+               memset((unsigned char *)key + IP_TUNNEL_KEY_SIZE,
+                      0, sizeof(*key) - IP_TUNNEL_KEY_SIZE);
 }
 
-static inline void ip_tunnel_info_init(struct ip_tunnel_info *tun_info,
-                                      const struct iphdr *iph,
-                                      __be16 tp_src, __be16 tp_dst,
-                                      __be64 tun_id, __be16 tun_flags,
-                                      const void *opts, u8 opts_len)
+static inline unsigned short ip_tunnel_info_af(const struct ip_tunnel_info
+                                              *tun_info)
 {
-       __ip_tunnel_info_init(tun_info, iph->saddr, iph->daddr,
-                             iph->tos, iph->ttl, tp_src, tp_dst,
-                             tun_id, tun_flags, opts, opts_len);
+       return tun_info->mode & IP_TUNNEL_INFO_IPV6 ? AF_INET6 : AF_INET;
 }
 
 #ifdef CONFIG_INET
@@ -273,8 +274,8 @@ static inline u8 ip_tunnel_ecn_encap(u8 tos, const struct iphdr *iph,
 
 int iptunnel_pull_header(struct sk_buff *skb, int hdr_len, __be16 inner_proto);
 int iptunnel_xmit(struct sock *sk, struct rtable *rt, struct sk_buff *skb,
-                 __be32 src, __be32 dst, __u8 proto,
-                 __u8 tos, __u8 ttl, __be16 df, bool xnet);
+                 __be32 src, __be32 dst, u8 proto,
+                 u8 tos, u8 ttl, __be16 df, bool xnet);
 
 struct sk_buff *iptunnel_handle_offloads(struct sk_buff *skb, bool gre_csum,
                                         int gso_type_mask);
@@ -298,11 +299,24 @@ static inline void iptunnel_xmit_stats(int err,
        }
 }
 
-static inline void *ip_tunnel_info_opts(struct ip_tunnel_info *info, size_t n)
+static inline void *ip_tunnel_info_opts(struct ip_tunnel_info *info)
 {
        return info + 1;
 }
 
+static inline void ip_tunnel_info_opts_get(void *to,
+                                          const struct ip_tunnel_info *info)
+{
+       memcpy(to, info + 1, info->options_len);
+}
+
+static inline void ip_tunnel_info_opts_set(struct ip_tunnel_info *info,
+                                          const void *from, int len)
+{
+       memcpy(ip_tunnel_info_opts(info), from, len);
+       info->options_len = len;
+}
+
 static inline struct ip_tunnel_info *lwt_tun_info(struct lwtunnel_state *lwtstate)
 {
        return (struct ip_tunnel_info *)lwtstate->data;