aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipv6/udp.c
diff options
context:
space:
mode:
authorBenjamin LaHaise <bcrl@kvack.org>2012-04-27 04:24:08 -0400
committerDavid S. Miller <davem@davemloft.net>2012-04-28 22:21:51 -0400
commitd7f3f62167bc2299d9669888b493b6e6ba561c35 (patch)
tree54bf3e1e796aba2aa1eb6b5e3fd0381c91327385 /net/ipv6/udp.c
parentcb80ef463d1881757ade3197cdf875a2ff856651 (diff)
net/ipv6/udp: UDP encapsulation: introduce encap_rcv hook into IPv6
Now that the sematics of udpv6_queue_rcv_skb() match IPv4's udp_queue_rcv_skb(), introduce the UDP encap_rcv() hook for IPv6. Signed-off-by: Benjamin LaHaise <bcrl@kvack.org> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv6/udp.c')
-rw-r--r--net/ipv6/udp.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
index bc533ea8fc68..c1d91a713e8e 100644
--- a/net/ipv6/udp.c
+++ b/net/ipv6/udp.c
@@ -525,6 +525,14 @@ static __inline__ void udpv6_err(struct sk_buff *skb,
525 __udp6_lib_err(skb, opt, type, code, offset, info, &udp_table); 525 __udp6_lib_err(skb, opt, type, code, offset, info, &udp_table);
526} 526}
527 527
528static struct static_key udpv6_encap_needed __read_mostly;
529void udpv6_encap_enable(void)
530{
531 if (!static_key_enabled(&udpv6_encap_needed))
532 static_key_slow_inc(&udpv6_encap_needed);
533}
534EXPORT_SYMBOL(udpv6_encap_enable);
535
528int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb) 536int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
529{ 537{
530 struct udp_sock *up = udp_sk(sk); 538 struct udp_sock *up = udp_sk(sk);
@@ -534,6 +542,37 @@ int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
534 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) 542 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb))
535 goto drop; 543 goto drop;
536 544
545 if (static_key_false(&udpv6_encap_needed) && up->encap_type) {
546 int (*encap_rcv)(struct sock *sk, struct sk_buff *skb);
547
548 /*
549 * This is an encapsulation socket so pass the skb to
550 * the socket's udp_encap_rcv() hook. Otherwise, just
551 * fall through and pass this up the UDP socket.
552 * up->encap_rcv() returns the following value:
553 * =0 if skb was successfully passed to the encap
554 * handler or was discarded by it.
555 * >0 if skb should be passed on to UDP.
556 * <0 if skb should be resubmitted as proto -N
557 */
558
559 /* if we're overly short, let UDP handle it */
560 encap_rcv = ACCESS_ONCE(up->encap_rcv);
561 if (skb->len > sizeof(struct udphdr) && encap_rcv != NULL) {
562 int ret;
563
564 ret = encap_rcv(sk, skb);
565 if (ret <= 0) {
566 UDP_INC_STATS_BH(sock_net(sk),
567 UDP_MIB_INDATAGRAMS,
568 is_udplite);
569 return -ret;
570 }
571 }
572
573 /* FALLTHROUGH -- it's a UDP Packet */
574 }
575
537 /* 576 /*
538 * UDP-Lite specific tests, ignored on UDP sockets (see net/ipv4/udp.c). 577 * UDP-Lite specific tests, ignored on UDP sockets (see net/ipv4/udp.c).
539 */ 578 */