3232#include "dccp.h"
3333#include "feat.h"
3434
35+ /*
36+ * This is the global socket data structure used for responding to
37+ * the Out-of-the-blue (OOTB) packets. A control sock will be created
38+ * for this socket at the initialization time.
39+ */
40+ static struct socket * dccp_v4_ctl_socket ;
41+
3542static int dccp_v4_get_port (struct sock * sk , const unsigned short snum )
3643{
3744 return inet_csk_get_port (& dccp_hashinfo , sk , snum ,
@@ -226,11 +233,11 @@ static void dccp_v4_ctl_send_ack(struct sk_buff *rxskb)
226233 dccp_hdr_set_ack (dccp_hdr_ack_bits (skb ),
227234 DCCP_SKB_CB (rxskb )-> dccpd_seq );
228235
229- bh_lock_sock (dccp_ctl_socket -> sk );
230- err = ip_build_and_send_pkt (skb , dccp_ctl_socket -> sk ,
236+ bh_lock_sock (dccp_v4_ctl_socket -> sk );
237+ err = ip_build_and_send_pkt (skb , dccp_v4_ctl_socket -> sk ,
231238 rxskb -> nh .iph -> daddr ,
232239 rxskb -> nh .iph -> saddr , NULL );
233- bh_unlock_sock (dccp_ctl_socket -> sk );
240+ bh_unlock_sock (dccp_v4_ctl_socket -> sk );
234241
235242 if (err == NET_XMIT_CN || err == 0 ) {
236243 DCCP_INC_STATS_BH (DCCP_MIB_OUTSEGS );
@@ -704,7 +711,7 @@ static void dccp_v4_ctl_send_reset(struct sk_buff *rxskb)
704711 if (((struct rtable * )rxskb -> dst )-> rt_type != RTN_LOCAL )
705712 return ;
706713
707- dst = dccp_v4_route_skb (dccp_ctl_socket -> sk , rxskb );
714+ dst = dccp_v4_route_skb (dccp_v4_ctl_socket -> sk , rxskb );
708715 if (dst == NULL )
709716 return ;
710717
@@ -741,11 +748,11 @@ static void dccp_v4_ctl_send_reset(struct sk_buff *rxskb)
741748 dh -> dccph_checksum = dccp_v4_checksum (skb , rxskb -> nh .iph -> saddr ,
742749 rxskb -> nh .iph -> daddr );
743750
744- bh_lock_sock (dccp_ctl_socket -> sk );
745- err = ip_build_and_send_pkt (skb , dccp_ctl_socket -> sk ,
751+ bh_lock_sock (dccp_v4_ctl_socket -> sk );
752+ err = ip_build_and_send_pkt (skb , dccp_v4_ctl_socket -> sk ,
746753 rxskb -> nh .iph -> daddr ,
747754 rxskb -> nh .iph -> saddr , NULL );
748- bh_unlock_sock (dccp_ctl_socket -> sk );
755+ bh_unlock_sock (dccp_v4_ctl_socket -> sk );
749756
750757 if (err == NET_XMIT_CN || err == 0 ) {
751758 DCCP_INC_STATS_BH (DCCP_MIB_OUTSEGS );
@@ -997,10 +1004,15 @@ static struct inet_connection_sock_af_ops dccp_ipv4_af_ops = {
9971004
9981005static int dccp_v4_init_sock (struct sock * sk )
9991006{
1000- const int err = dccp_init_sock (sk );
1007+ static __u8 dccp_v4_ctl_sock_initialized ;
1008+ int err = dccp_init_sock (sk , dccp_v4_ctl_sock_initialized );
10011009
1002- if (err == 0 )
1010+ if (err == 0 ) {
1011+ if (unlikely (!dccp_v4_ctl_sock_initialized ))
1012+ dccp_v4_ctl_sock_initialized = 1 ;
10031013 inet_csk (sk )-> icsk_af_ops = & dccp_ipv4_af_ops ;
1014+ }
1015+
10041016 return err ;
10051017}
10061018
@@ -1087,48 +1099,29 @@ static struct inet_protosw dccp_v4_protosw = {
10871099 .flags = INET_PROTOSW_ICSK ,
10881100};
10891101
1090- /*
1091- * This is the global socket data structure used for responding to
1092- * the Out-of-the-blue (OOTB) packets. A control sock will be created
1093- * for this socket at the initialization time.
1094- */
1095- struct socket * dccp_ctl_socket ;
1096-
1097- static char dccp_ctl_socket_err_msg [] __initdata =
1102+ static char dccp_v4_ctl_socket_err_msg [] __initdata =
10981103 KERN_ERR "DCCP: Failed to create the control socket.\n" ;
10991104
1100- static int __init dccp_ctl_sock_init (void )
1105+ static int __init dccp_v4_ctl_sock_init (void )
11011106{
11021107 int rc = sock_create_kern (PF_INET , SOCK_DCCP , IPPROTO_DCCP ,
1103- & dccp_ctl_socket );
1108+ & dccp_v4_ctl_socket );
11041109 if (rc < 0 )
1105- printk (dccp_ctl_socket_err_msg );
1110+ printk (dccp_v4_ctl_socket_err_msg );
11061111 else {
1107- dccp_ctl_socket -> sk -> sk_allocation = GFP_ATOMIC ;
1108- inet_sk (dccp_ctl_socket -> sk )-> uc_ttl = -1 ;
1112+ dccp_v4_ctl_socket -> sk -> sk_allocation = GFP_ATOMIC ;
1113+ inet_sk (dccp_v4_ctl_socket -> sk )-> uc_ttl = -1 ;
11091114
11101115 /* Unhash it so that IP input processing does not even
11111116 * see it, we do not wish this socket to see incoming
11121117 * packets.
11131118 */
1114- dccp_ctl_socket -> sk -> sk_prot -> unhash (dccp_ctl_socket -> sk );
1119+ dccp_v4_ctl_socket -> sk -> sk_prot -> unhash (dccp_v4_ctl_socket -> sk );
11151120 }
11161121
11171122 return rc ;
11181123}
11191124
1120- #ifdef CONFIG_IP_DCCP_UNLOAD_HACK
1121- void dccp_ctl_sock_exit (void )
1122- {
1123- if (dccp_ctl_socket != NULL ) {
1124- sock_release (dccp_ctl_socket );
1125- dccp_ctl_socket = NULL ;
1126- }
1127- }
1128-
1129- EXPORT_SYMBOL_GPL (dccp_ctl_sock_exit );
1130- #endif
1131-
11321125static int __init dccp_v4_init (void )
11331126{
11341127 int err = proto_register (& dccp_v4_prot , 1 );
@@ -1142,7 +1135,7 @@ static int __init dccp_v4_init(void)
11421135
11431136 inet_register_protosw (& dccp_v4_protosw );
11441137
1145- err = dccp_ctl_sock_init ();
1138+ err = dccp_v4_ctl_sock_init ();
11461139 if (err )
11471140 goto out_unregister_protosw ;
11481141out :
0 commit comments