* [RFC PATCH] ipv6: fix handling of blackhole and prohibit routes
@ 2012-08-30 14:29 Nicolas Dichtel
2012-09-04 19:58 ` David Miller
0 siblings, 1 reply; 6+ messages in thread
From: Nicolas Dichtel @ 2012-08-30 14:29 UTC (permalink / raw)
To: netdev
[-- Attachment #1: Type: text/plain, Size: 116 bytes --]
Hi,
enclosed is a patch to fix addition of blackhole and prohibit routes.
Comments are welcome.
Regards,
Nicolas
[-- Attachment #2: 0001-ipv6-fix-handling-of-blackhole-and-prohibit-routes.patch --]
[-- Type: text/x-patch, Size: 3867 bytes --]
>From 0131261ac3947631b96036ffafb30ee2e95604f2 Mon Sep 17 00:00:00 2001
From: Nicolas Dichtel <nicolas.dichtel@6wind.com>
Date: Thu, 30 Aug 2012 07:07:30 -0400
Subject: [PATCH] ipv6: fix handling of blackhole and prohibit routes
When adding a blackhole or a prohibit route, they were handling like classic
routes. Moreover, it was only possible to add this kind of routes by specifying
an interface.
Bug already reported here:
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=498498
Before the patch:
$ ip route add blackhole 2001::1/128
RTNETLINK answers: No such device
$ ip route add blackhole 2001::1/128 dev eth0
$ ip -6 route | grep 2001
2001::1 dev eth0 metric 1024
After:
$ ip route add blackhole 2001::1/128
$ ip -6 route | grep 2001
blackhole 2001::1 dev lo metric 1024 error -22
Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
---
include/linux/route.h | 2 ++
net/ipv6/route.c | 27 ++++++++++++++++++++++-----
2 files changed, 24 insertions(+), 5 deletions(-)
diff --git a/include/linux/route.h b/include/linux/route.h
index 6600708..166fb68 100644
--- a/include/linux/route.h
+++ b/include/linux/route.h
@@ -58,6 +58,8 @@ struct rtentry {
#define RTF_WINDOW 0x0080 /* per route window clamping */
#define RTF_IRTT 0x0100 /* Initial round trip time */
#define RTF_REJECT 0x0200 /* Reject route */
+#define RTF_BLACKHOLE 0x0400 /* Blackhole route */
+#define RTF_PROHIBIT 0x0800 /* Prohibit route */
/*
* <linux/ipv6_route.h> uses RTF values >= 64k
diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index 8e80fd2..69369b0 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -251,7 +251,7 @@ static struct rt6_info ip6_prohibit_entry_template = {
.input = ip6_pkt_prohibit,
.output = ip6_pkt_prohibit_out,
},
- .rt6i_flags = (RTF_REJECT | RTF_NONEXTHOP),
+ .rt6i_flags = (RTF_REJECT | RTF_NONEXTHOP | RTF_PROHIBIT),
.rt6i_protocol = RTPROT_KERNEL,
.rt6i_metric = ~(u32) 0,
.rt6i_ref = ATOMIC_INIT(1),
@@ -266,7 +266,7 @@ static struct rt6_info ip6_blk_hole_entry_template = {
.input = dst_discard,
.output = dst_discard,
},
- .rt6i_flags = (RTF_REJECT | RTF_NONEXTHOP),
+ .rt6i_flags = (RTF_REJECT | RTF_NONEXTHOP | RTF_BLACKHOLE),
.rt6i_protocol = RTPROT_KERNEL,
.rt6i_metric = ~(u32) 0,
.rt6i_ref = ATOMIC_INIT(1),
@@ -1463,8 +1463,15 @@ int ip6_route_add(struct fib6_config *cfg)
}
rt->dst.output = ip6_pkt_discard_out;
rt->dst.input = ip6_pkt_discard;
- rt->dst.error = -ENETUNREACH;
rt->rt6i_flags = RTF_REJECT|RTF_NONEXTHOP;
+ if (cfg->fc_flags & RTF_BLACKHOLE) {
+ rt->dst.error = -EINVAL;
+ rt->rt6i_flags |= RTF_BLACKHOLE;
+ } else if (cfg->fc_flags & RTF_PROHIBIT) {
+ rt->dst.error = -EACCES;
+ rt->rt6i_flags |= RTF_PROHIBIT;
+ } else
+ rt->dst.error = -ENETUNREACH;
goto install_route;
}
@@ -2264,6 +2271,10 @@ static int rtm_to_fib6_config(struct sk_buff *skb, struct nlmsghdr *nlh,
if (rtm->rtm_type == RTN_UNREACHABLE)
cfg->fc_flags |= RTF_REJECT;
+ if (rtm->rtm_type == RTN_BLACKHOLE)
+ cfg->fc_flags |= RTF_REJECT | RTF_BLACKHOLE;
+ if (rtm->rtm_type == RTN_PROHIBIT)
+ cfg->fc_flags |= RTF_REJECT | RTF_PROHIBIT;
if (rtm->rtm_type == RTN_LOCAL)
cfg->fc_flags |= RTF_LOCAL;
@@ -2391,8 +2402,14 @@ static int rt6_fill_node(struct net *net,
rtm->rtm_table = table;
if (nla_put_u32(skb, RTA_TABLE, table))
goto nla_put_failure;
- if (rt->rt6i_flags & RTF_REJECT)
- rtm->rtm_type = RTN_UNREACHABLE;
+ if (rt->rt6i_flags & RTF_REJECT) {
+ if (rt->rt6i_flags & RTF_BLACKHOLE)
+ rtm->rtm_type = RTN_BLACKHOLE;
+ else if (rt->rt6i_flags & RTF_PROHIBIT)
+ rtm->rtm_type = RTN_PROHIBIT;
+ else
+ rtm->rtm_type = RTN_UNREACHABLE;
+ }
else if (rt->rt6i_flags & RTF_LOCAL)
rtm->rtm_type = RTN_LOCAL;
else if (rt->dst.dev && (rt->dst.dev->flags & IFF_LOOPBACK))
--
1.7.10.4
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [RFC PATCH] ipv6: fix handling of blackhole and prohibit routes
2012-08-30 14:29 [RFC PATCH] ipv6: fix handling of blackhole and prohibit routes Nicolas Dichtel
@ 2012-09-04 19:58 ` David Miller
2012-09-05 11:34 ` [RFC PATCH v2] " Nicolas Dichtel
0 siblings, 1 reply; 6+ messages in thread
From: David Miller @ 2012-09-04 19:58 UTC (permalink / raw)
To: nicolas.dichtel; +Cc: netdev
From: Nicolas Dichtel <nicolas.dichtel@6wind.com>
Date: Thu, 30 Aug 2012 16:29:28 +0200
> Comments are welcome.
I don't see why we have to create new flags for this.
Handle it like ipv4, where the RTN_* type dictates whether the
route is blackhole, prohibit, or other type of route.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [RFC PATCH v2] ipv6: fix handling of blackhole and prohibit routes
2012-09-05 11:34 ` [RFC PATCH v2] " Nicolas Dichtel
@ 2012-09-05 10:03 ` Nicolas Dichtel
2012-09-05 12:12 ` [RFC PATCH v3] " Nicolas Dichtel
0 siblings, 1 reply; 6+ messages in thread
From: Nicolas Dichtel @ 2012-09-05 10:03 UTC (permalink / raw)
To: davem; +Cc: netdev
Please, forget this patch, it's a wrong version.
Sorry for that.
Regards,
Nicolas
Le 05/09/2012 13:34, Nicolas Dichtel a écrit :
> When adding a blackhole or a prohibit route, they were handling like classic
> routes. Moreover, it was only possible to add this kind of routes by specifying
> an interface.
>
> Bug already reported here:
> http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=498498
>
> Before the patch:
> $ ip route add blackhole 2001::1/128
> RTNETLINK answers: No such device
> $ ip route add blackhole 2001::1/128 dev eth0
> $ ip -6 route | grep 2001
> 2001::1 dev eth0 metric 1024
>
> After:
> $ ip route add blackhole 2001::1/128
> $ ip -6 route | grep 2001
> blackhole 2001::1 dev lo metric 1024 error -22
>
> Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
> ---
> include/net/ip6_fib.h | 1 +
> net/ipv6/route.c | 32 ++++++++++++++++++++++++++++----
> 2 files changed, 29 insertions(+), 4 deletions(-)
>
> diff --git a/include/net/ip6_fib.h b/include/net/ip6_fib.h
> index 0fedbd8..cd64cf3 100644
> --- a/include/net/ip6_fib.h
> +++ b/include/net/ip6_fib.h
> @@ -37,6 +37,7 @@ struct fib6_config {
> int fc_ifindex;
> u32 fc_flags;
> u32 fc_protocol;
> + u32 fc_type; /* only 8 bits are used */
>
> struct in6_addr fc_dst;
> struct in6_addr fc_src;
> diff --git a/net/ipv6/route.c b/net/ipv6/route.c
> index 8e80fd2..5642fb5 100644
> --- a/net/ipv6/route.c
> +++ b/net/ipv6/route.c
> @@ -1463,8 +1463,18 @@ int ip6_route_add(struct fib6_config *cfg)
> }
> rt->dst.output = ip6_pkt_discard_out;
> rt->dst.input = ip6_pkt_discard;
> - rt->dst.error = -ENETUNREACH;
> rt->rt6i_flags = RTF_REJECT|RTF_NONEXTHOP;
> + switch (cfg->fc_type) {
> + case RTM_BLACKHOLE:
> + rt->dst.error = -EINVAL;
> + break;
> + case RTM_PROHIBIT:
> + rt->dst.error = -EACCES;
> + break;
> + default:
> + rt->dst.error = -ENETUNREACH;
> + break;
> + }
> goto install_route;
> }
>
> @@ -2261,8 +2271,11 @@ static int rtm_to_fib6_config(struct sk_buff *skb, struct nlmsghdr *nlh,
> cfg->fc_src_len = rtm->rtm_src_len;
> cfg->fc_flags = RTF_UP;
> cfg->fc_protocol = rtm->rtm_protocol;
> + cfg->type = rtm->rtm_type;
>
> - if (rtm->rtm_type == RTN_UNREACHABLE)
> + if (rtm->rtm_type == RTN_UNREACHABLE ||
> + rtm->rtm_type == RTN_BLACKHOLE ||
> + rtm->rtm_type == RTN_PROHIBIT)
> cfg->fc_flags |= RTF_REJECT;
>
> if (rtm->rtm_type == RTN_LOCAL)
> @@ -2391,8 +2404,19 @@ static int rt6_fill_node(struct net *net,
> rtm->rtm_table = table;
> if (nla_put_u32(skb, RTA_TABLE, table))
> goto nla_put_failure;
> - if (rt->rt6i_flags & RTF_REJECT)
> - rtm->rtm_type = RTN_UNREACHABLE;
> + if (rt->rt6i_flags & RTF_REJECT) {
> + switch (rt->dst.error) {
> + case -EINVAL:
> + rtm->rtm_type = RTN_BLACKHOLE;
> + break;
> + case -EACCES:
> + rtm->rtm_type = RTN_PROHIBIT;
> + break;
> + default:
> + rtm->rtm_type = RTN_UNREACHABLE;
> + break;
> + }
> + }
> else if (rt->rt6i_flags & RTF_LOCAL)
> rtm->rtm_type = RTN_LOCAL;
> else if (rt->dst.dev && (rt->dst.dev->flags & IFF_LOOPBACK))
>
--
Nicolas DICHTEL
6WIND
R&D Engineer
Tel: +33 1 39 30 92 10
Fax: +33 1 39 30 92 11
nicolas.dichtel@6wind.com
www.6wind.com
Twitter: http://twitter.com/6windsoftware
Join the Multicore Packet Processing Forum: www.multicorepacketprocessing.com
Ce courriel ainsi que toutes les pièces jointes, est uniquement destiné à son ou
ses destinataires. Il contient des informations confidentielles qui sont la
propriété de 6WIND. Toute révélation, distribution ou copie des informations
qu'il contient est strictement interdite. Si vous avez reçu ce message par
erreur, veuillez immédiatement le signaler à l'émetteur et détruire toutes les
données reçues.
This e-mail message, including any attachments, is for the sole use of the
intended recipient(s) and contains information that is confidential and
proprietary to 6WIND. All unauthorized review, use, disclosure or distribution
is prohibited. If you are not the intended recipient, please contact the sender
by reply e-mail and destroy all copies of the original message.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [RFC PATCH v2] ipv6: fix handling of blackhole and prohibit routes
2012-09-04 19:58 ` David Miller
@ 2012-09-05 11:34 ` Nicolas Dichtel
2012-09-05 10:03 ` Nicolas Dichtel
0 siblings, 1 reply; 6+ messages in thread
From: Nicolas Dichtel @ 2012-09-05 11:34 UTC (permalink / raw)
To: davem; +Cc: netdev, Nicolas Dichtel
When adding a blackhole or a prohibit route, they were handling like classic
routes. Moreover, it was only possible to add this kind of routes by specifying
an interface.
Bug already reported here:
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=498498
Before the patch:
$ ip route add blackhole 2001::1/128
RTNETLINK answers: No such device
$ ip route add blackhole 2001::1/128 dev eth0
$ ip -6 route | grep 2001
2001::1 dev eth0 metric 1024
After:
$ ip route add blackhole 2001::1/128
$ ip -6 route | grep 2001
blackhole 2001::1 dev lo metric 1024 error -22
Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
---
include/net/ip6_fib.h | 1 +
net/ipv6/route.c | 32 ++++++++++++++++++++++++++++----
2 files changed, 29 insertions(+), 4 deletions(-)
diff --git a/include/net/ip6_fib.h b/include/net/ip6_fib.h
index 0fedbd8..cd64cf3 100644
--- a/include/net/ip6_fib.h
+++ b/include/net/ip6_fib.h
@@ -37,6 +37,7 @@ struct fib6_config {
int fc_ifindex;
u32 fc_flags;
u32 fc_protocol;
+ u32 fc_type; /* only 8 bits are used */
struct in6_addr fc_dst;
struct in6_addr fc_src;
diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index 8e80fd2..5642fb5 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -1463,8 +1463,18 @@ int ip6_route_add(struct fib6_config *cfg)
}
rt->dst.output = ip6_pkt_discard_out;
rt->dst.input = ip6_pkt_discard;
- rt->dst.error = -ENETUNREACH;
rt->rt6i_flags = RTF_REJECT|RTF_NONEXTHOP;
+ switch (cfg->fc_type) {
+ case RTM_BLACKHOLE:
+ rt->dst.error = -EINVAL;
+ break;
+ case RTM_PROHIBIT:
+ rt->dst.error = -EACCES;
+ break;
+ default:
+ rt->dst.error = -ENETUNREACH;
+ break;
+ }
goto install_route;
}
@@ -2261,8 +2271,11 @@ static int rtm_to_fib6_config(struct sk_buff *skb, struct nlmsghdr *nlh,
cfg->fc_src_len = rtm->rtm_src_len;
cfg->fc_flags = RTF_UP;
cfg->fc_protocol = rtm->rtm_protocol;
+ cfg->type = rtm->rtm_type;
- if (rtm->rtm_type == RTN_UNREACHABLE)
+ if (rtm->rtm_type == RTN_UNREACHABLE ||
+ rtm->rtm_type == RTN_BLACKHOLE ||
+ rtm->rtm_type == RTN_PROHIBIT)
cfg->fc_flags |= RTF_REJECT;
if (rtm->rtm_type == RTN_LOCAL)
@@ -2391,8 +2404,19 @@ static int rt6_fill_node(struct net *net,
rtm->rtm_table = table;
if (nla_put_u32(skb, RTA_TABLE, table))
goto nla_put_failure;
- if (rt->rt6i_flags & RTF_REJECT)
- rtm->rtm_type = RTN_UNREACHABLE;
+ if (rt->rt6i_flags & RTF_REJECT) {
+ switch (rt->dst.error) {
+ case -EINVAL:
+ rtm->rtm_type = RTN_BLACKHOLE;
+ break;
+ case -EACCES:
+ rtm->rtm_type = RTN_PROHIBIT;
+ break;
+ default:
+ rtm->rtm_type = RTN_UNREACHABLE;
+ break;
+ }
+ }
else if (rt->rt6i_flags & RTF_LOCAL)
rtm->rtm_type = RTN_LOCAL;
else if (rt->dst.dev && (rt->dst.dev->flags & IFF_LOOPBACK))
--
1.7.12
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [RFC PATCH v3] ipv6: fix handling of blackhole and prohibit routes
2012-09-05 10:03 ` Nicolas Dichtel
@ 2012-09-05 12:12 ` Nicolas Dichtel
2012-09-05 21:50 ` David Miller
0 siblings, 1 reply; 6+ messages in thread
From: Nicolas Dichtel @ 2012-09-05 12:12 UTC (permalink / raw)
To: davem; +Cc: netdev, Nicolas Dichtel
When adding a blackhole or a prohibit route, they were handling like classic
routes. Moreover, it was only possible to add this kind of routes by specifying
an interface.
Bug already reported here:
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=498498
Before the patch:
$ ip route add blackhole 2001::1/128
RTNETLINK answers: No such device
$ ip route add blackhole 2001::1/128 dev eth0
$ ip -6 route | grep 2001
2001::1 dev eth0 metric 1024
After:
$ ip route add blackhole 2001::1/128
$ ip -6 route | grep 2001
blackhole 2001::1 dev lo metric 1024 error -22
v2: wrong patch
v3: add a field fc_type in struct fib6_config to store RTN_* type
Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
---
include/net/ip6_fib.h | 1 +
net/ipv6/route.c | 32 ++++++++++++++++++++++++++++----
2 files changed, 29 insertions(+), 4 deletions(-)
diff --git a/include/net/ip6_fib.h b/include/net/ip6_fib.h
index 0fedbd8..cd64cf3 100644
--- a/include/net/ip6_fib.h
+++ b/include/net/ip6_fib.h
@@ -37,6 +37,7 @@ struct fib6_config {
int fc_ifindex;
u32 fc_flags;
u32 fc_protocol;
+ u32 fc_type; /* only 8 bits are used */
struct in6_addr fc_dst;
struct in6_addr fc_src;
diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index 8e80fd2..63de1c1 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -1463,8 +1463,18 @@ int ip6_route_add(struct fib6_config *cfg)
}
rt->dst.output = ip6_pkt_discard_out;
rt->dst.input = ip6_pkt_discard;
- rt->dst.error = -ENETUNREACH;
rt->rt6i_flags = RTF_REJECT|RTF_NONEXTHOP;
+ switch (cfg->fc_type) {
+ case RTN_BLACKHOLE:
+ rt->dst.error = -EINVAL;
+ break;
+ case RTN_PROHIBIT:
+ rt->dst.error = -EACCES;
+ break;
+ default:
+ rt->dst.error = -ENETUNREACH;
+ break;
+ }
goto install_route;
}
@@ -2261,8 +2271,11 @@ static int rtm_to_fib6_config(struct sk_buff *skb, struct nlmsghdr *nlh,
cfg->fc_src_len = rtm->rtm_src_len;
cfg->fc_flags = RTF_UP;
cfg->fc_protocol = rtm->rtm_protocol;
+ cfg->fc_type = rtm->rtm_type;
- if (rtm->rtm_type == RTN_UNREACHABLE)
+ if (rtm->rtm_type == RTN_UNREACHABLE ||
+ rtm->rtm_type == RTN_BLACKHOLE ||
+ rtm->rtm_type == RTN_PROHIBIT)
cfg->fc_flags |= RTF_REJECT;
if (rtm->rtm_type == RTN_LOCAL)
@@ -2391,8 +2404,19 @@ static int rt6_fill_node(struct net *net,
rtm->rtm_table = table;
if (nla_put_u32(skb, RTA_TABLE, table))
goto nla_put_failure;
- if (rt->rt6i_flags & RTF_REJECT)
- rtm->rtm_type = RTN_UNREACHABLE;
+ if (rt->rt6i_flags & RTF_REJECT) {
+ switch (rt->dst.error) {
+ case -EINVAL:
+ rtm->rtm_type = RTN_BLACKHOLE;
+ break;
+ case -EACCES:
+ rtm->rtm_type = RTN_PROHIBIT;
+ break;
+ default:
+ rtm->rtm_type = RTN_UNREACHABLE;
+ break;
+ }
+ }
else if (rt->rt6i_flags & RTF_LOCAL)
rtm->rtm_type = RTN_LOCAL;
else if (rt->dst.dev && (rt->dst.dev->flags & IFF_LOOPBACK))
--
1.7.12
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [RFC PATCH v3] ipv6: fix handling of blackhole and prohibit routes
2012-09-05 12:12 ` [RFC PATCH v3] " Nicolas Dichtel
@ 2012-09-05 21:50 ` David Miller
0 siblings, 0 replies; 6+ messages in thread
From: David Miller @ 2012-09-05 21:50 UTC (permalink / raw)
To: nicolas.dichtel; +Cc: netdev
From: Nicolas Dichtel <nicolas.dichtel@6wind.com>
Date: Wed, 5 Sep 2012 08:12:42 -0400
> When adding a blackhole or a prohibit route, they were handling like classic
> routes. Moreover, it was only possible to add this kind of routes by specifying
> an interface.
>
> Bug already reported here:
> http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=498498
>
> Before the patch:
> $ ip route add blackhole 2001::1/128
> RTNETLINK answers: No such device
> $ ip route add blackhole 2001::1/128 dev eth0
> $ ip -6 route | grep 2001
> 2001::1 dev eth0 metric 1024
>
> After:
> $ ip route add blackhole 2001::1/128
> $ ip -6 route | grep 2001
> blackhole 2001::1 dev lo metric 1024 error -22
>
> v2: wrong patch
> v3: add a field fc_type in struct fib6_config to store RTN_* type
>
> Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
I like this a lot more than your original patch, applied to net-next,
thanks.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2012-09-05 21:50 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-08-30 14:29 [RFC PATCH] ipv6: fix handling of blackhole and prohibit routes Nicolas Dichtel
2012-09-04 19:58 ` David Miller
2012-09-05 11:34 ` [RFC PATCH v2] " Nicolas Dichtel
2012-09-05 10:03 ` Nicolas Dichtel
2012-09-05 12:12 ` [RFC PATCH v3] " Nicolas Dichtel
2012-09-05 21:50 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).