{"id":818029,"url":"http://patchwork.ozlabs.org/api/patches/818029/?format=json","web_url":"http://patchwork.ozlabs.org/project/netdev/patch/20170925032941.14586-2-tom@quantonium.net/","project":{"id":7,"url":"http://patchwork.ozlabs.org/api/projects/7/?format=json","name":"Linux network development","link_name":"netdev","list_id":"netdev.vger.kernel.org","list_email":"netdev@vger.kernel.org","web_url":null,"scm_url":null,"webscm_url":null,"list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20170925032941.14586-2-tom@quantonium.net>","list_archive_url":null,"date":"2017-09-25T03:29:30","name":"[v3,net-next,01/12] iptunnel: Add common functions to get a tunnel route","commit_ref":null,"pull_url":null,"state":"changes-requested","archived":true,"hash":"16333d25097051f577338ee5e7e9b5c7e1ea56b0","submitter":{"id":72064,"url":"http://patchwork.ozlabs.org/api/people/72064/?format=json","name":"Tom Herbert","email":"tom@quantonium.net"},"delegate":{"id":34,"url":"http://patchwork.ozlabs.org/api/users/34/?format=json","username":"davem","first_name":"David","last_name":"Miller","email":"davem@davemloft.net"},"mbox":"http://patchwork.ozlabs.org/project/netdev/patch/20170925032941.14586-2-tom@quantonium.net/mbox/","series":[{"id":4865,"url":"http://patchwork.ozlabs.org/api/series/4865/?format=json","web_url":"http://patchwork.ozlabs.org/project/netdev/list/?series=4865","date":"2017-09-25T03:29:29","name":"gtp: Additional feature support - Part I","version":3,"mbox":"http://patchwork.ozlabs.org/series/4865/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/818029/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/818029/checks/","tags":{},"related":[],"headers":{"Return-Path":"<netdev-owner@vger.kernel.org>","X-Original-To":"patchwork-incoming@ozlabs.org","Delivered-To":"patchwork-incoming@ozlabs.org","Authentication-Results":["ozlabs.org;\n\tspf=none (mailfrom) smtp.mailfrom=vger.kernel.org\n\t(client-ip=209.132.180.67; helo=vger.kernel.org;\n\tenvelope-from=netdev-owner@vger.kernel.org;\n\treceiver=<UNKNOWN>)","ozlabs.org; dkim=pass (2048-bit key;\n\tunprotected) header.d=quantonium-net.20150623.gappssmtp.com\n\theader.i=@quantonium-net.20150623.gappssmtp.com\n\theader.b=\"kJbg5X93\"; dkim-atps=neutral"],"Received":["from vger.kernel.org (vger.kernel.org [209.132.180.67])\n\tby ozlabs.org (Postfix) with ESMTP id 3y0qN16K28z9t4B\n\tfor <patchwork-incoming@ozlabs.org>;\n\tMon, 25 Sep 2017 13:30:09 +1000 (AEST)","(majordomo@vger.kernel.org) by vger.kernel.org via listexpand\n\tid S932835AbdIYDaE (ORCPT <rfc822;patchwork-incoming@ozlabs.org>);\n\tSun, 24 Sep 2017 23:30:04 -0400","from mail-pg0-f41.google.com ([74.125.83.41]:53823 \"EHLO\n\tmail-pg0-f41.google.com\" rhost-flags-OK-OK-OK-OK) by vger.kernel.org\n\twith ESMTP id S932698AbdIYDaC (ORCPT\n\t<rfc822;netdev@vger.kernel.org>); Sun, 24 Sep 2017 23:30:02 -0400","by mail-pg0-f41.google.com with SMTP id j70so3268638pgc.10\n\tfor <netdev@vger.kernel.org>; Sun, 24 Sep 2017 20:30:02 -0700 (PDT)","from localhost.localdomain (c-73-162-13-107.hsd1.ca.comcast.net.\n\t[73.162.13.107]) by smtp.gmail.com with ESMTPSA id\n\tj2sm9112907pgn.26.2017.09.24.20.29.59\n\t(version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\n\tSun, 24 Sep 2017 20:30:00 -0700 (PDT)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=quantonium-net.20150623.gappssmtp.com; s=20150623;\n\th=from:to:cc:subject:date:message-id:in-reply-to:references;\n\tbh=H7R4a1v989F/1hXp0bbod6Na0WTSG5WBok1oEpXD/0s=;\n\tb=kJbg5X93JPpmEXFe0AaMs+EYzMuNus5Z16BjjnSkSN1F688FUlHSUpCx6o3MbQuJQk\n\tN7bdvaCNoEsVdhGIgwgSwuvim0rmiaO1ieN1n5MZFqB22ZY/L2sMGMacO4/L8RvVKAf4\n\tIV5gcMmf7kzrDA3mqLm20SreZi/BiznZv+aomBhM1BrHxw3ZerCnJGDhDHnbydHVHbIh\n\tffEuCqWM5d/dXI2d/x/lr12T+UquuSkweRKTmgoZcC16khNN5bftBZCcXJj+54AhjBmM\n\txQyKzBw+m1h6f8KW+DsPDEwCIvAzQLos2ynb+pG62XeRCI+udtDZ2YTadfFLjHO/QLoT\n\tgDYQ==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\n\t:references;\n\tbh=H7R4a1v989F/1hXp0bbod6Na0WTSG5WBok1oEpXD/0s=;\n\tb=jay4B234ycsSRu86n+Ln2O1cx2jaDW8cyNb+w+TKrtkBdSGcA00C5bV6VuIdpcNGme\n\t28dPNPcVp+Kgk46XV+bRcXlQZHZZ8+rhG+AaR0wCoafprQayhqWX+cdyujbJSTGs0ETI\n\tPmEPsgiO6ydOVub4BKALinvAn+VgCkuDtt1Gd7f76CVecKap0YsCyaYPjl0d8cpH/Zb0\n\tIBBBfGgpaXhmVerKQmvtjRY042k0f6aLapYMgEtRReQlw2NF9jZG4BJCf4WftphJGsGD\n\tahYfJw4CfngKFBVfhgbSwtq4V2JEfT1ddiztoe4N8vf65O/tAah0oqmqesEVBV9q6OOf\n\tewag==","X-Gm-Message-State":"AHPjjUgsGdv1JEUSFPF21c707Jzt/aOTH1fj84zlm5dXr7BkXgOt/UdC\n\tUH7sZFLgAjB2HqNEl5MUjyDYBg==","X-Google-Smtp-Source":"AOwi7QB9ltpRTG/kA341p3zpQzckOBjpM02FOvcfAYGzXgzOXhn1g4jpKYMKIkVwrUKV7BoHU3il9A==","X-Received":"by 10.84.177.131 with SMTP id x3mr6350177plb.123.1506310201697; \n\tSun, 24 Sep 2017 20:30:01 -0700 (PDT)","From":"Tom Herbert <tom@quantonium.net>","To":"davem@davemloft.net","Cc":"pablo@netfilter.org, laforge@gnumonks.org, aschultz@tpip.net,\n\tnetdev@vger.kernel.org, rohit@quantonium.net,\n\tTom Herbert <tom@quantonium.net>","Subject":"[PATCH v3 net-next 01/12] iptunnel: Add common functions to get a\n\ttunnel route","Date":"Sun, 24 Sep 2017 20:29:30 -0700","Message-Id":"<20170925032941.14586-2-tom@quantonium.net>","X-Mailer":"git-send-email 2.11.0","In-Reply-To":"<20170925032941.14586-1-tom@quantonium.net>","References":"<20170925032941.14586-1-tom@quantonium.net>","Sender":"netdev-owner@vger.kernel.org","Precedence":"bulk","List-ID":"<netdev.vger.kernel.org>","X-Mailing-List":"netdev@vger.kernel.org"},"content":"ip_tunnel_get_route and ip6_tnl_get_route are created to return\nroutes for a tunnel. These functions are derived from the VXLAN\nfunctions.\n\nSigned-off-by: Tom Herbert <tom@quantonium.net>\n---\n include/net/ip6_tunnel.h | 35 +++++++++++++++++++++++++++++++++++\n include/net/ip_tunnels.h | 33 +++++++++++++++++++++++++++++++++\n net/ipv4/ip_tunnel.c     | 41 +++++++++++++++++++++++++++++++++++++++++\n net/ipv6/ip6_tunnel.c    | 43 +++++++++++++++++++++++++++++++++++++++++++\n 4 files changed, 152 insertions(+)","diff":"diff --git a/include/net/ip6_tunnel.h b/include/net/ip6_tunnel.h\nindex 08fbc7f7d8d7..5a67301b0416 100644\n--- a/include/net/ip6_tunnel.h\n+++ b/include/net/ip6_tunnel.h\n@@ -142,6 +142,41 @@ __u32 ip6_tnl_get_cap(struct ip6_tnl *t, const struct in6_addr *laddr,\n struct net *ip6_tnl_get_link_net(const struct net_device *dev);\n int ip6_tnl_get_iflink(const struct net_device *dev);\n int ip6_tnl_change_mtu(struct net_device *dev, int new_mtu);\n+struct dst_entry *__ip6_tnl_get_route(struct net_device *dev,\n+\t\t\t\t      struct sk_buff *skb, struct sock *sk,\n+\t\t\t\t      u8 proto, int oif, u8 tos, __be32 label,\n+\t\t\t\t      const struct in6_addr *daddr,\n+\t\t\t\t      struct in6_addr *saddr,\n+\t\t\t\t      __be16 dport, __be16 sport,\n+\t\t\t\t      struct dst_cache *dst_cache,\n+\t\t\t\t      const struct ip_tunnel_info *info,\n+\t\t\t\t      bool use_cache);\n+\n+static inline struct dst_entry *ip6_tnl_get_route(struct net_device *dev,\n+\t\t\tstruct sk_buff *skb, struct sock *sk, u8 proto,\n+\t\t\tint oif, u8 tos, __be32 label,\n+\t\t\tconst struct in6_addr *daddr,\n+\t\t\tstruct in6_addr *saddr,\n+\t\t\t__be16 dport, __be16 sport,\n+\t\t\tstruct dst_cache *dst_cache,\n+\t\t\tconst struct ip_tunnel_info *info)\n+{\n+\t bool use_cache = (ip_tunnel_dst_cache_usable(skb, info) &&\n+\t\t(!tos || info));\n+\n+#if IS_ENABLED(CONFIG_IPV6)\n+\tif (use_cache) {\n+\t\tstruct dst_entry *ndst = dst_cache_get_ip6(dst_cache, saddr);\n+\n+\t\tif (ndst)\n+\t\t\treturn ndst;\n+\t}\n+#endif\n+\n+\treturn __ip6_tnl_get_route(dev, skb, sk, proto, oif, tos, label,\n+\t\t\t\t   daddr, saddr, dport, sport, dst_cache,\n+\t\t\t\t   info, use_cache);\n+}\n \n static inline void ip6tunnel_xmit(struct sock *sk, struct sk_buff *skb,\n \t\t\t\t  struct net_device *dev)\ndiff --git a/include/net/ip_tunnels.h b/include/net/ip_tunnels.h\nindex b41a1e057fce..9650efff33d7 100644\n--- a/include/net/ip_tunnels.h\n+++ b/include/net/ip_tunnels.h\n@@ -285,6 +285,39 @@ int ip_tunnel_newlink(struct net_device *dev, struct nlattr *tb[],\n \t\t      struct ip_tunnel_parm *p, __u32 fwmark);\n void ip_tunnel_setup(struct net_device *dev, unsigned int net_id);\n \n+struct rtable *__ip_tunnel_get_route(struct net_device *dev,\n+\t\t\t\t     struct sk_buff *skb, u8 proto,\n+\t\t\t\t     int oif, u8 tos,\n+\t\t\t\t     __be32 daddr, __be32 *saddr,\n+\t\t\t\t     __be16 dport, __be16 sport,\n+\t\t\t\t     struct dst_cache *dst_cache,\n+\t\t\t\t     const struct ip_tunnel_info *info,\n+\t\t\t\t     bool use_cache);\n+\n+static inline struct rtable *ip_tunnel_get_route(struct net_device *dev,\n+\t\t\t\t     struct sk_buff *skb, u8 proto,\n+\t\t\t\t     int oif, u8 tos,\n+\t\t\t\t     __be32 daddr, __be32 *saddr,\n+\t\t\t\t     __be16 dport, __be16 sport,\n+\t\t\t\t     struct dst_cache *dst_cache,\n+\t\t\t\t     const struct ip_tunnel_info *info)\n+{\n+\tbool use_cache = (ip_tunnel_dst_cache_usable(skb, info) &&\n+\t\t(!tos || info));\n+\n+\tif (use_cache) {\n+\t\tstruct rtable *rt;\n+\n+\t\trt = dst_cache_get_ip4(dst_cache, saddr);\n+\t\tif (rt)\n+\t\t\treturn rt;\n+\t}\n+\n+\treturn __ip_tunnel_get_route(dev, skb, proto, oif, tos,\n+\t\t\t\t     daddr, saddr, dport, sport,\n+\t\t\t\t     dst_cache, info, use_cache);\n+}\n+\n struct ip_tunnel_encap_ops {\n \tsize_t (*encap_hlen)(struct ip_tunnel_encap *e);\n \tint (*build_header)(struct sk_buff *skb, struct ip_tunnel_encap *e,\ndiff --git a/net/ipv4/ip_tunnel.c b/net/ipv4/ip_tunnel.c\nindex fe6fee728ce4..ea8f8bc0aaf9 100644\n--- a/net/ipv4/ip_tunnel.c\n+++ b/net/ipv4/ip_tunnel.c\n@@ -935,6 +935,47 @@ int ip_tunnel_ioctl(struct net_device *dev, struct ip_tunnel_parm *p, int cmd)\n }\n EXPORT_SYMBOL_GPL(ip_tunnel_ioctl);\n \n+struct rtable *__ip_tunnel_get_route(struct net_device *dev,\n+\t\t\t\t     struct sk_buff *skb, u8 proto,\n+\t\t\t\t    int oif, u8 tos,\n+\t\t\t\t     __be32 daddr, __be32 *saddr,\n+\t\t\t\t     __be16 dport, __be16 sport,\n+\t\t\t\t     struct dst_cache *dst_cache,\n+\t\t\t\t     const struct ip_tunnel_info *info,\n+\t\t\t\t     bool use_cache)\n+{\n+\tstruct rtable *rt = NULL;\n+\tstruct flowi4 fl4;\n+\n+\tmemset(&fl4, 0, sizeof(fl4));\n+\tfl4.flowi4_oif = oif;\n+\tfl4.flowi4_tos = RT_TOS(tos);\n+\tfl4.flowi4_mark = skb->mark;\n+\tfl4.flowi4_proto = proto;\n+\tfl4.daddr = daddr;\n+\tfl4.saddr = *saddr;\n+\tfl4.fl4_dport = dport;\n+\tfl4.fl4_sport = sport;\n+\n+\trt = ip_route_output_key(dev_net(dev), &fl4);\n+\tif (likely(!IS_ERR(rt))) {\n+\t\tif (rt->dst.dev == dev) {\n+\t\t\tnetdev_dbg(dev, \"circular route to %pI4\\n\", &daddr);\n+\t\t\tip_rt_put(rt);\n+\t\t\treturn ERR_PTR(-ELOOP);\n+\t\t}\n+\n+\t\t*saddr = fl4.saddr;\n+\t\tif (use_cache)\n+\t\t\tdst_cache_set_ip4(dst_cache, &rt->dst, fl4.saddr);\n+\t} else {\n+\t\tnetdev_dbg(dev, \"no route to %pI4\\n\", &daddr);\n+\t\treturn ERR_PTR(-ENETUNREACH);\n+\t}\n+\treturn rt;\n+}\n+EXPORT_SYMBOL_GPL(__ip_tunnel_get_route);\n+\n int __ip_tunnel_change_mtu(struct net_device *dev, int new_mtu, bool strict)\n {\n \tstruct ip_tunnel *tunnel = netdev_priv(dev);\ndiff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c\nindex 3d6df489b39f..a541daea1379 100644\n--- a/net/ipv6/ip6_tunnel.c\n+++ b/net/ipv6/ip6_tunnel.c\n@@ -1663,6 +1663,49 @@ ip6_tnl_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)\n \treturn err;\n }\n \n+struct dst_entry *__ip6_tnl_get_route(struct net_device *dev,\n+\t\t\t\t      struct sk_buff *skb, struct sock *sk,\n+\t\t\t\t      u8 proto, int oif, u8 tos, __be32 label,\n+\t\t\t\t      const struct in6_addr *daddr,\n+\t\t\t\t      struct in6_addr *saddr,\n+\t\t\t\t      __be16 dport, __be16 sport,\n+\t\t\t\t      struct dst_cache *dst_cache,\n+\t\t\t\t      const struct ip_tunnel_info *info,\n+\t\t\t\t      bool use_cache)\n+{\n+\tstruct dst_entry *ndst;\n+\tstruct flowi6 fl6;\n+\tint err;\n+\n+\tmemset(&fl6, 0, sizeof(fl6));\n+\tfl6.flowi6_oif = oif;\n+\tfl6.daddr = *daddr;\n+\tfl6.saddr = *saddr;\n+\tfl6.flowlabel = ip6_make_flowinfo(RT_TOS(tos), label);\n+\tfl6.flowi6_mark = skb->mark;\n+\tfl6.flowi6_proto = proto;\n+\tfl6.fl6_dport = dport;\n+\tfl6.fl6_sport = sport;\n+\n+\terr = ipv6_stub->ipv6_dst_lookup(dev_net(dev), sk, &ndst, &fl6);\n+\tif (unlikely(err < 0)) {\n+\t\tnetdev_dbg(dev, \"no route to %pI6\\n\", daddr);\n+\t\treturn ERR_PTR(-ENETUNREACH);\n+\t}\n+\n+\tif (unlikely(ndst->dev == dev)) {\n+\t\tnetdev_dbg(dev, \"circular route to %pI6\\n\", daddr);\n+\t\tdst_release(ndst);\n+\t\treturn ERR_PTR(-ELOOP);\n+\t}\n+\n+\t*saddr = fl6.saddr;\n+\tif (use_cache)\n+\t\tdst_cache_set_ip6(dst_cache, ndst, saddr);\n+\treturn ndst;\n+}\n+EXPORT_SYMBOL_GPL(__ip6_tnl_get_route);\n+\n /**\n  * ip6_tnl_change_mtu - change mtu manually for tunnel device\n  *   @dev: virtual device associated with tunnel\n","prefixes":["v3","net-next","01/12"]}