ipv6: allow rejecting with "source address failed policy"
Subsystems (3)
RFC 1/1 ipv6: allow rejecting with "source address failed policy"
RFC6204 L-14 requires rejecting traffic from invalid addresses with ICMPv6 Destination Unreachable, Code 5 (Source address failed ingress/ egress policy) on the LAN side, so add an appropriate rule for that.
---
Since I'm a total noob in regard to the net subsystem, this is a RFC patch for now. The things that bug me:
Is -EPERM a sensible error message?
Do I need one at all?
Is adding its handling to IPv4 necessary? It seems to me the fib_* need to cover all RTN_* values.
Because I don't expect this patch to survive the review I did not send any userspace patches yet.
Regards,
Jonas
include/net/netns/ipv6.h | 1 + include/uapi/linux/fib_rules.h | 4 +++ include/uapi/linux/icmpv6.h | 1 + include/uapi/linux/rtnetlink.h | 1 + net/ipv4/fib_rules.c | 4 +++ net/ipv4/fib_semantics.c | 4 +++ net/ipv4/fib_trie.c | 1 + net/ipv4/ipmr.c | 1 + net/ipv6/fib6_rules.c | 3 +++ net/ipv6/ip6mr.c | 2 ++ net/ipv6/route.c | 57 +++++++++++++++++++++++++++++++++++++++- 11 files changed, 78 insertions(+), 1 deletion(-)
include/net/netns/ipv6.h +1 -0
@@ -55,6 +55,7 @@ struct netns_ipv6 {unsigned long ip6_rt_last_gc;#ifdef CONFIG_IPV6_MULTIPLE_TABLES struct rt6_info *ip6_prohibit_entry; +struct rt6_info *ip6_failed_policy_entry;struct rt6_info *ip6_blk_hole_entry;struct fib6_table *fib6_local_tbl;struct fib_rules_ops *fib6_rules_ops;
include/uapi/linux/fib_rules.h +4 -0
@@ -64,6 +64,10 @@ enum {FR_ACT_BLACKHOLE ,/* Drop without notification */ FR_ACT_UNREACHABLE ,/* Drop with ENETUNREACH */ FR_ACT_PROHIBIT ,/* Drop with EACCES */ +FR_ACT_RES9 , +FR_ACT_RES10 , +FR_ACT_RES11 , +FR_ACT_FAILED_POLICY ,/* Drop with EPERM */ __FR_ACT_MAX, };
include/uapi/linux/icmpv6.h +1 -0
@@ -115,6 +115,7 @@ struct icmp6hdr {#define ICMPV6_NOT_NEIGHBOUR 2#define ICMPV6_ADDR_UNREACH 3#define ICMPV6_PORT_UNREACH 4 +#define ICMPV6_FAILED_POLICY 5/* * Codes for Time Exceeded
include/uapi/linux/rtnetlink.h +1 -0
@@ -203,6 +203,7 @@ enum {RTN_THROW ,/* Not in this table */ RTN_NAT ,/* Translate this address */ RTN_XRESOLVE ,/* Use external resolver */ +RTN_FAILED_POLICY ,/* Failed ingress/egress policy */ __RTN_MAX };
net/ipv4/fib_rules.c +4 -0
@@ -84,6 +84,10 @@ static int fib4_rule_action(struct fib_rule *rule, struct flowi *flp, err = -EACCES ; goto errout; +case FR_ACT_FAILED_POLICY : + err = -EPERM ; + goto errout; +case FR_ACT_BLACKHOLE :default : err = -EINVAL ;
net/ipv4/fib_semantics.c +4 -0
@@ -138,6 +138,10 @@ const struct fib_prop fib_props[RTN_MAX + 1] = { .error = -EINVAL, .scope = RT_SCOPE_NOWHERE, }, + [RTN_FAILED_POLICY] = { + .error = -EPERM, + .scope = RT_SCOPE_UNIVERSE, + }, };static void rt_fibinfo_free (struct rtable __rcu **rtp)
net/ipv4/fib_trie.c +1 -0
@@ -2334,6 +2334,7 @@ static const char *const rtn_type_names[__RTN_MAX] = { [RTN_THROW] = "THROW", [RTN_NAT] = "NAT", [RTN_XRESOLVE] = "XRESOLVE", + [RTN_FAILED_POLICY] = "FAILED_POLICY", };static inline const char *rtn_type (char *buf,size_t len,unsigned int t)
net/ipv4/ipmr.c +1 -0
@@ -181,6 +181,7 @@ static int ipmr_rule_action(struct fib_rule *rule, struct flowi *flp,case FR_ACT_UNREACHABLE :return -ENETUNREACH ;case FR_ACT_PROHIBIT : +case FR_ACT_FAILED_POLICY :return -EACCES ;case FR_ACT_BLACKHOLE :default :
net/ipv6/fib6_rules.c +3 -0
@@ -69,6 +69,9 @@ static int fib6_rule_action(struct fib_rule *rule, struct flowi *flp,case FR_ACT_PROHIBIT : rt = net->ipv6.ip6_prohibit_entry; goto discard_pkt; +case FR_ACT_FAILED_POLICY : + rt = net->ipv6.ip6_failed_policy_entry; + goto discard_pkt; } table =fib6_get_table (net, rule->table);
net/ipv6/ip6mr.c +2 -0
@@ -166,6 +166,8 @@ static int ip6mr_rule_action(struct fib_rule *rule, struct flowi *flp,return -ENETUNREACH ;case FR_ACT_PROHIBIT :return -EACCES ; +case FR_ACT_FAILED_POLICY : +return -EPERM ;case FR_ACT_BLACKHOLE :default :return -EINVAL ;
net/ipv6/route.c +56 -1
117 lines not on this page · raw message
Signature · 1 line
1.7.10.4
David Miller
maintainerFrom: Jonas Gorski <[email protected]>
Date: Mon, 3 Jun 2013 16:45:08 +0200
Quoted 5 lines
RFC6204 L-14 requires rejecting traffic from invalid addresses with ICMPv6 Destination Unreachable, Code 5 (Source address failed ingress/ egress policy) on the LAN side, so add an appropriate rule for that.
Signed-off-by Jonas Gorski <[email protected]>
I don't see the point of this, there is no difference from the existing PROHIBIT other than the error code. Everything that needs to be expressed can be done using PROHIBIT.
Quoted 8 lines · On Fri, 07 Jun 2013 15:27:30 -0700 (PDT) David Miller <[email protected]>…
From: Jonas Gorski <[email protected]>
Date: Mon, 3 Jun 2013 16:45:08 +0200Quoted 5 lines
RFC6204 L-14 requires rejecting traffic from invalid addresses with ICMPv6 Destination Unreachable, Code 5 (Source address failed ingress/ egress policy) on the LAN side, so add an appropriate rule for that.
Quoted 6 lines
Quoted 1 line
Signed-off-by Jonas Gorski <[email protected]>I don't see the point of this, there is no difference from the existing PROHIBIT other than the error code. Everything that needs to be expressed can be done using PROHIBIT.
There is a semantic difference. PROHIBIT says the *destination* address is not allowed, so trying again is pointless.
This one says the while the destination is allowed, the *source* address is not allowed, and a different source address should be used. So probably -EAGAIN would be the right error code in that case. "POLICY_FAILED" is maybe a wrong abbreviation, but the full name is quite long (I'm open for suggestions).
Of course maybe handling of this kind of message should be added, too; which should trigger the source address selection to chose a different one.
Unless you say I can change the ICMPv6 Destination Unreached Code used through appropriate rules, then this might be redundant.
Regards
Jonas