From: Eric Dumazet <eric.dumazet@gmail.com>
To: Anders Franzen <Anders.Franzen@ericsson.com>
Cc: "netdev@vger.kernel.org" <netdev@vger.kernel.org>
Subject: Re: [RFC]: not possible to do policy routing for next hop on tunnels.
Date: Wed, 01 Sep 2010 14:49:10 +0200 [thread overview]
Message-ID: <1283345350.2556.265.camel@edumazet-laptop> (raw)
In-Reply-To: <1283343685.14066.24.camel@seasc7941.dyn.rnd.as.sw.ericsson.se>
Le mercredi 01 septembre 2010 à 14:21 +0200, Anders Franzen a écrit :
> If I have multiple routing choices to reach a tunnel end point,
> I would like to mark different flows with iptables, after the
> postrouting of the primary route look up, this would put an fwmark on
> the skb. The route would in my case resolve to an ip6_tunnel.
>
> In the tunnel a secondary route lookup is done to select next hop for
> the tunnel end point.
>
> I would like to apply policy routing to the secondary lookup.
>
> This will not work, for two reasons:
>
> 1. None of the tunnels (ipip, gre, ip6_tunnel) I looked at regards the
> fwmark at the skb, when performing the route lookup.
>
> 2. ip6_tunnel is keeping a local dst cache, so it will never reroute as
> long as the current cache is valid.
>
>
> I wonder if there is a reason for not giving the fwmark at the tunnel
> route for tunnels in general?
>
> And the local dst cache for ip6_tunnel, is it needed, is not the routing
> subsystem keeping some form of internal cache (ip route ls cache).
ip6_tunnel (or others) could be extended with a
IP6_TNL_F_USE_ORIG_FWMARK, and in this case not use/cache the route.
untested patch to get the idea :
diff --git a/include/linux/ip6_tunnel.h b/include/linux/ip6_tunnel.h
index acb9ad6..bf22b03 100644
--- a/include/linux/ip6_tunnel.h
+++ b/include/linux/ip6_tunnel.h
@@ -16,6 +16,8 @@
#define IP6_TNL_F_MIP6_DEV 0x8
/* copy DSCP from the outer packet */
#define IP6_TNL_F_RCV_DSCP_COPY 0x10
+/* copy fwmark from inner packet */
+#define IP6_TNL_F_USE_ORIG_FWMARK 0x20
struct ip6_tnl_parm {
char name[IFNAMSIZ]; /* name of tunnel device */
diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
index 0fd027f..e31a91f 100644
--- a/net/ipv6/ip6_tunnel.c
+++ b/net/ipv6/ip6_tunnel.c
@@ -858,7 +858,7 @@ static int ip6_tnl_xmit2(struct sk_buff *skb,
int err = -1;
int pkt_len;
- if ((dst = ip6_tnl_dst_check(t)) != NULL)
+ if (!fl->mark && (dst = ip6_tnl_dst_check(t)) != NULL)
dst_hold(dst);
else {
dst = ip6_route_output(net, NULL, fl);
@@ -910,7 +910,7 @@ static int ip6_tnl_xmit2(struct sk_buff *skb,
skb = new_skb;
}
skb_dst_drop(skb);
- skb_dst_set(skb, dst_clone(dst));
+ skb_dst_set(skb, fl->mark ? dst : dst_clone(dst));
skb->transport_header = skb->network_header;
@@ -940,7 +940,9 @@ static int ip6_tnl_xmit2(struct sk_buff *skb,
stats->tx_errors++;
stats->tx_aborted_errors++;
}
- ip6_tnl_dst_store(t, dst);
+ if (!fl->mark)
+ ip6_tnl_dst_store(t, dst);
+
return 0;
tx_err_link_failure:
stats->tx_carrier_errors++;
@@ -976,6 +978,8 @@ ip4ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev)
if ((t->parms.flags & IP6_TNL_F_USE_ORIG_TCLASS))
fl.fl6_flowlabel |= htonl((__u32)iph->tos << IPV6_TCLASS_SHIFT)
& IPV6_TCLASS_MASK;
+ if ((t->parms.flags & IP6_TNL_F_USE_ORIG_FWMARK))
+ fl.mark = skb->mark;
err = ip6_tnl_xmit2(skb, dev, dsfield, &fl, encap_limit, &mtu);
if (err != 0) {
@@ -1026,7 +1030,8 @@ ip6ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev)
fl.fl6_flowlabel |= (*(__be32 *) ipv6h & IPV6_TCLASS_MASK);
if ((t->parms.flags & IP6_TNL_F_USE_ORIG_FLOWLABEL))
fl.fl6_flowlabel |= (*(__be32 *) ipv6h & IPV6_FLOWLABEL_MASK);
-
+ if ((t->parms.flags & IP6_TNL_F_USE_ORIG_FWMARK))
+ fl.mark = skb->mark;
err = ip6_tnl_xmit2(skb, dev, dsfield, &fl, encap_limit, &mtu);
if (err != 0) {
if (err == -EMSGSIZE)
next prev parent reply other threads:[~2010-09-01 12:51 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-09-01 12:21 [RFC]: not possible to do policy routing for next hop on tunnels Anders Franzen
2010-09-01 12:49 ` Eric Dumazet [this message]
2010-09-01 13:27 ` Anders Franzen
2010-09-01 13:37 ` Eric Dumazet
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1283345350.2556.265.camel@edumazet-laptop \
--to=eric.dumazet@gmail.com \
--cc=Anders.Franzen@ericsson.com \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox