[PATCH]ipv6: Add an ICMP error handler icmpv6_err

Subsystems: networking [general], networking [ipv4/ipv6], the rest

STALE5104d

2 messages, 2 authors, 2012-10-24 · open the first message on its own page

[PATCH]ipv6: Add an ICMP error handler icmpv6_err

From: Duan Jiong <hidden>
Date: 2012-10-23 15:24:34

Add an ICMP error handler icmpv6_err to deal with ICMPV6 Error
Messages and Redirect Message, when we do not have a socket
context.

Signed-off-by: Duan Jiong <redacted>
---
 net/ipv6/icmp.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
index 24d69db..d3cb61d 100644
--- a/net/ipv6/icmp.c
+++ b/net/ipv6/icmp.c
@@ -82,9 +82,12 @@ static inline struct sock *icmpv6_sk(struct net *net)
 }
 
 static int icmpv6_rcv(struct sk_buff *skb);
+static void icmpv6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
+			u8 type, u8 code, int offset, __be32 info);
 
 static const struct inet6_protocol icmpv6_protocol = {
 	.handler	=	icmpv6_rcv,
+	.err_handler	=	icmpv6_err,
 	.flags		=	INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
 };
 
@@ -782,6 +785,26 @@ drop_no_count:
 	return 0;
 }
 
+static void icmpv6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
+			u8 type, u8 code, int offset, __be32 info)
+{
+	struct net *net = dev_net(skb->dev);
+	struct icmp6hdr *hdr = icmp6_hdr(skb);
+
+	switch (hdr->icmp6_type) {
+	case ICMPV6_PKT_TOOBIG:
+		ip6_update_pmtu(skb, net, info, 0, 0);
+		break;
+
+	case NDISC_REDIRECT:
+		ip6_redirect(skb, net, 0, 0);
+		break;
+
+	default:
+		break;
+	}
+}
+
 void icmpv6_flow_init(struct sock *sk, struct flowi6 *fl6,
 		      u8 type,
 		      const struct in6_addr *saddr,
-- 
1.7.11.4

Re: [PATCH]ipv6: Add an ICMP error handler icmpv6_err

From: Steffen Klassert <steffen.klassert@secunet.com>
Date: 2012-10-24 05:01:59

On Tue, Oct 23, 2012 at 11:24:29PM +0800, Duan Jiong wrote:
quoted hunk
Add an ICMP error handler icmpv6_err to deal with ICMPV6 Error
Messages and Redirect Message, when we do not have a socket
context.

Signed-off-by: Duan Jiong <redacted>
---
 net/ipv6/icmp.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
index 24d69db..d3cb61d 100644
--- a/net/ipv6/icmp.c
+++ b/net/ipv6/icmp.c
@@ -82,9 +82,12 @@ static inline struct sock *icmpv6_sk(struct net *net)
 }
 
 static int icmpv6_rcv(struct sk_buff *skb);
+static void icmpv6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
+			u8 type, u8 code, int offset, __be32 info);
 
 static const struct inet6_protocol icmpv6_protocol = {
 	.handler	=	icmpv6_rcv,
+	.err_handler	=	icmpv6_err,
 	.flags		=	INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
 };
 
@@ -782,6 +785,26 @@ drop_no_count:
 	return 0;
 }
 
+static void icmpv6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
+			u8 type, u8 code, int offset, __be32 info)
+{
+	struct net *net = dev_net(skb->dev);
+	struct icmp6hdr *hdr = icmp6_hdr(skb);
+
+	switch (hdr->icmp6_type) {
+	case ICMPV6_PKT_TOOBIG:
+		ip6_update_pmtu(skb, net, info, 0, 0);
+		break;
+
+	case NDISC_REDIRECT:
+		ip6_redirect(skb, net, 0, 0);
+		break;
+
+	default:
+		break;
+	}
+}
+
Not sure if it really matters, but the ip6_update_pmtu/ip6_redirect
function would be called twice if we have (raw) socket context. Maybe
it's better to do this in raw6_icmp_error() if we have no socket context.
 
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help