linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/1] IPv6: Fixed support for blackhole and prohibit routes
@ 2013-11-19 16:49 Kamala R
  2013-11-20  4:57 ` Hannes Frederic Sowa
  0 siblings, 1 reply; 2+ messages in thread
From: Kamala R @ 2013-11-19 16:49 UTC (permalink / raw)
  To: Hannes Frederic Sowa, netdev, David Miller; +Cc: linux-kernel, Kamala R

From: Kamala R <kamala@aristanetworks.com>

The behaviour of blackhole and prohibit routes has been corrected by setting the input and output
function pointers of the dst variable appropriately. For blackhole routes, they are set to
dst_discard and for prohibit routes they are set to ip6_pkt_prohibit and ip6_pkt_prohbit_out
respectively.

Signed-off-by: Kamala R <kamala@aristanetworks.com>
---
 net/ipv6/route.c |   18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index f54e3a1..f2289fd 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -1564,21 +1564,25 @@ int ip6_route_add(struct fib6_config *cfg)
 				goto out;
 			}
 		}
-		rt->dst.output = ip6_pkt_discard_out;
-		rt->dst.input = ip6_pkt_discard;
+
 		rt->rt6i_flags = RTF_REJECT|RTF_NONEXTHOP;
+		rt->dst.error = (cfg->fc_type == RTN_BLACKHOLE) ? -EINVAL
+				: ((cfg->fc_type == RTN_PROHIBIT ? -EACCES
+				: ((cfg->fc_type == RTN_THROW ? -EAGAIN
+				: -ENETUNREACH))));
 		switch (cfg->fc_type) {
 		case RTN_BLACKHOLE:
-			rt->dst.error = -EINVAL;
+			rt->dst.output = dst_discard;
+			rt->dst.input = dst_discard;
 			break;
 		case RTN_PROHIBIT:
-			rt->dst.error = -EACCES;
+			rt->dst.output = ip6_pkt_prohibit_out;
+			rt->dst.input = ip6_pkt_prohibit;
 			break;
 		case RTN_THROW:
-			rt->dst.error = -EAGAIN;
-			break;
 		default:
-			rt->dst.error = -ENETUNREACH;
+			rt->dst.output = ip6_pkt_discard_out;
+			rt->dst.input = ip6_pkt_discard;
 			break;
 		}
 		goto install_route;
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH 1/1] IPv6: Fixed support for blackhole and prohibit routes
  2013-11-19 16:49 [PATCH 1/1] IPv6: Fixed support for blackhole and prohibit routes Kamala R
@ 2013-11-20  4:57 ` Hannes Frederic Sowa
  0 siblings, 0 replies; 2+ messages in thread
From: Hannes Frederic Sowa @ 2013-11-20  4:57 UTC (permalink / raw)
  To: Kamala R; +Cc: netdev, David Miller, linux-kernel

On Tue, Nov 19, 2013 at 10:19:33PM +0530, Kamala R wrote:
> From: Kamala R <kamala@aristanetworks.com>
> 
> The behaviour of blackhole and prohibit routes has been corrected by setting the input and output
> function pointers of the dst variable appropriately. For blackhole routes, they are set to
> dst_discard and for prohibit routes they are set to ip6_pkt_prohibit and ip6_pkt_prohbit_out
> respectively.
> 
> Signed-off-by: Kamala R <kamala@aristanetworks.com>
> ---
>  net/ipv6/route.c |   18 +++++++++++-------
>  1 file changed, 11 insertions(+), 7 deletions(-)
> 
> diff --git a/net/ipv6/route.c b/net/ipv6/route.c
> index f54e3a1..f2289fd 100644
> --- a/net/ipv6/route.c
> +++ b/net/ipv6/route.c
> @@ -1564,21 +1564,25 @@ int ip6_route_add(struct fib6_config *cfg)
>  				goto out;
>  			}
>  		}
> -		rt->dst.output = ip6_pkt_discard_out;
> -		rt->dst.input = ip6_pkt_discard;
> +
>  		rt->rt6i_flags = RTF_REJECT|RTF_NONEXTHOP;
> +		rt->dst.error = (cfg->fc_type == RTN_BLACKHOLE) ? -EINVAL
> +				: ((cfg->fc_type == RTN_PROHIBIT ? -EACCES
> +				: ((cfg->fc_type == RTN_THROW ? -EAGAIN
> +				: -ENETUNREACH))));

Uh, sorry, I was a bit too unclear. This is rather ugly. I meant merging
the RTN_THROW and default case and just use one dst.error assignment
with a ternary operator where it makes sense.

>  		switch (cfg->fc_type) {
>  		case RTN_BLACKHOLE:
> -			rt->dst.error = -EINVAL;
> +			rt->dst.output = dst_discard;
> +			rt->dst.input = dst_discard;
>  			break;
>  		case RTN_PROHIBIT:
> -			rt->dst.error = -EACCES;
> +			rt->dst.output = ip6_pkt_prohibit_out;
> +			rt->dst.input = ip6_pkt_prohibit;
>  			break;
>  		case RTN_THROW:
> -			rt->dst.error = -EAGAIN;
> -			break;
>  		default:
> -			rt->dst.error = -ENETUNREACH;
> +			rt->dst.output = ip6_pkt_discard_out;
> +			rt->dst.input = ip6_pkt_discard;
>  			break;

case RTN_THROW:
default:
	rt->dst.error = (cfg->fc_type == ...) ? ... : ...;
	rt->dst.output = ....
	rt->dst.input = ....

I also don't mind if you are more verbose and specify each case
independent. Just have a look how it looks more pleasing. ;)

Greetings,

  Hannes


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-11-20  4:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-19 16:49 [PATCH 1/1] IPv6: Fixed support for blackhole and prohibit routes Kamala R
2013-11-20  4:57 ` Hannes Frederic Sowa

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).