Skip to content

Commit 7247887

Browse files
Arnaldo Carvalho de Melodavem330
authored andcommitted
[DCCP] ipv6: Add missing ipv6 control socket
I guess I forgot to add it, nah, now it just works: 18:04:33.274066 IP6 ::1.1476 > ::1.5001: request (service=0) 18:04:33.334482 IP6 ::1.5001 > ::1.1476: reset (code=bad_service_code) Ditched IP_DCCP_UNLOAD_HACK, as now we would have to do it for both IPv6 and IPv4, so I'll come up with another way for freeing the control sockets in upcoming changesets. Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent c25a18b commit 7247887

6 files changed

Lines changed: 72 additions & 65 deletions

File tree

‎net/dccp/Kconfig‎

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,6 @@ config IP_DCCP_DEBUG
4040

4141
Just say N.
4242

43-
config IP_DCCP_UNLOAD_HACK
44-
depends on IP_DCCP=m && IP_DCCP_CCID3=m
45-
bool "DCCP control sock unload hack"
46-
---help---
47-
Enable this to be able to unload the dccp module when the it
48-
has only one refcount held, the control sock one. Just execute
49-
"rmmod dccp_ccid3 dccp"
50-
51-
Just say N.
5243
endmenu
5344

5445
endmenu

‎net/dccp/ccids/ccid3.c‎

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,15 +1211,6 @@ module_init(ccid3_module_init);
12111211

12121212
static __exit void ccid3_module_exit(void)
12131213
{
1214-
#ifdef CONFIG_IP_DCCP_UNLOAD_HACK
1215-
/*
1216-
* Hack to use while developing, so that we get rid of the control
1217-
* sock, that is what keeps a refcount on dccp.ko -acme
1218-
*/
1219-
extern void dccp_ctl_sock_exit(void);
1220-
1221-
dccp_ctl_sock_exit();
1222-
#endif
12231214
ccid_unregister(&ccid3);
12241215

12251216
if (ccid3_tx_hist != NULL) {

‎net/dccp/dccp.h‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ extern int dccp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
177177
extern int dccp_rcv_established(struct sock *sk, struct sk_buff *skb,
178178
const struct dccp_hdr *dh, const unsigned len);
179179

180-
extern int dccp_init_sock(struct sock *sk);
180+
extern int dccp_init_sock(struct sock *sk, const __u8 ctl_sock_initialized);
181181
extern int dccp_destroy_sock(struct sock *sk);
182182

183183
extern void dccp_close(struct sock *sk, long timeout);
@@ -337,8 +337,6 @@ extern void dccp_insert_option(struct sock *sk, struct sk_buff *skb,
337337
unsigned char option,
338338
const void *value, unsigned char len);
339339

340-
extern struct socket *dccp_ctl_socket;
341-
342340
extern void dccp_timestamp(const struct sock *sk, struct timeval *tv);
343341

344342
static inline suseconds_t timeval_usecs(const struct timeval *tv)

‎net/dccp/ipv4.c‎

Lines changed: 29 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@
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+
3542
static 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

9981005
static 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-
11321125
static 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;
11481141
out:

‎net/dccp/ipv6.c‎

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
#include "dccp.h"
3434
#include "ipv6.h"
3535

36+
/* Socket used for sending RSTs and ACKs */
37+
static struct socket *dccp_v6_ctl_socket;
38+
3639
static void dccp_v6_ctl_send_reset(struct sk_buff *skb);
3740
static void dccp_v6_reqsk_send_ack(struct sk_buff *skb,
3841
struct request_sock *req);
@@ -568,7 +571,7 @@ static void dccp_v6_ctl_send_reset(struct sk_buff *rxskb)
568571
/* sk = NULL, but it is safe for now. RST socket required. */
569572
if (!ip6_dst_lookup(NULL, &skb->dst, &fl)) {
570573
if (xfrm_lookup(&skb->dst, &fl, NULL, 0) >= 0) {
571-
ip6_xmit(NULL, skb, &fl, NULL, 0);
574+
ip6_xmit(dccp_v6_ctl_socket->sk, skb, &fl, NULL, 0);
572575
DCCP_INC_STATS_BH(DCCP_MIB_OUTSEGS);
573576
DCCP_INC_STATS_BH(DCCP_MIB_OUTRSTS);
574577
return;
@@ -623,7 +626,7 @@ static void dccp_v6_ctl_send_ack(struct sk_buff *rxskb)
623626

624627
if (!ip6_dst_lookup(NULL, &skb->dst, &fl)) {
625628
if (xfrm_lookup(&skb->dst, &fl, NULL, 0) >= 0) {
626-
ip6_xmit(NULL, skb, &fl, NULL, 0);
629+
ip6_xmit(dccp_v6_ctl_socket->sk, skb, &fl, NULL, 0);
627630
DCCP_INC_STATS_BH(DCCP_MIB_OUTSEGS);
628631
return;
629632
}
@@ -1146,10 +1149,14 @@ static struct inet_connection_sock_af_ops dccp_ipv6_mapped = {
11461149
*/
11471150
static int dccp_v6_init_sock(struct sock *sk)
11481151
{
1149-
int err = dccp_init_sock(sk);
1152+
static __u8 dccp_v6_ctl_sock_initialized;
1153+
int err = dccp_init_sock(sk, dccp_v6_ctl_sock_initialized);
11501154

1151-
if (err == 0)
1155+
if (err == 0) {
1156+
if (unlikely(!dccp_v6_ctl_sock_initialized))
1157+
dccp_v6_ctl_sock_initialized = 1;
11521158
inet_csk(sk)->icsk_af_ops = &dccp_ipv6_af_ops;
1159+
}
11531160

11541161
return err;
11551162
}
@@ -1222,6 +1229,29 @@ static struct inet_protosw dccp_v6_protosw = {
12221229
.flags = INET_PROTOSW_ICSK,
12231230
};
12241231

1232+
static char dccp_v6_ctl_socket_err_msg[] __initdata =
1233+
KERN_ERR "DCCP: Failed to create the control socket.\n";
1234+
1235+
static int __init dccp_v6_ctl_sock_init(void)
1236+
{
1237+
int rc = sock_create_kern(PF_INET6, SOCK_DCCP, IPPROTO_DCCP,
1238+
&dccp_v6_ctl_socket);
1239+
if (rc < 0)
1240+
printk(dccp_v6_ctl_socket_err_msg);
1241+
else {
1242+
dccp_v6_ctl_socket->sk->sk_allocation = GFP_ATOMIC;
1243+
inet_sk(dccp_v6_ctl_socket->sk)->uc_ttl = -1;
1244+
1245+
/* Unhash it so that IP input processing does not even
1246+
* see it, we do not wish this socket to see incoming
1247+
* packets.
1248+
*/
1249+
dccp_v6_ctl_socket->sk->sk_prot->unhash(dccp_v6_ctl_socket->sk);
1250+
}
1251+
1252+
return rc;
1253+
}
1254+
12251255
static int __init dccp_v6_init(void)
12261256
{
12271257
int err = proto_register(&dccp_v6_prot, 1);
@@ -1234,8 +1264,14 @@ static int __init dccp_v6_init(void)
12341264
goto out_unregister_proto;
12351265

12361266
inet6_register_protosw(&dccp_v6_protosw);
1267+
1268+
if (dccp_v6_ctl_sock_init() != 0)
1269+
goto out_unregister_protosw;
12371270
out:
12381271
return err;
1272+
out_unregister_protosw:
1273+
inet6_del_protocol(&dccp_v6_protocol, IPPROTO_DCCP);
1274+
inet6_unregister_protosw(&dccp_v6_protosw);
12391275
out_unregister_proto:
12401276
proto_unregister(&dccp_v6_prot);
12411277
goto out;

‎net/dccp/proto.c‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,10 @@ void dccp_unhash(struct sock *sk)
163163

164164
EXPORT_SYMBOL_GPL(dccp_unhash);
165165

166-
int dccp_init_sock(struct sock *sk)
166+
int dccp_init_sock(struct sock *sk, const __u8 ctl_sock_initialized)
167167
{
168168
struct dccp_sock *dp = dccp_sk(sk);
169169
struct inet_connection_sock *icsk = inet_csk(sk);
170-
static int dccp_ctl_socket_init = 1;
171170

172171
dccp_options_init(&dp->dccps_options);
173172
do_gettimeofday(&dp->dccps_epoch);
@@ -179,7 +178,7 @@ int dccp_init_sock(struct sock *sk)
179178
* lets leave it here, later the real solution is to do this in a
180179
* setsockopt(CCIDs-I-want/accept). -acme
181180
*/
182-
if (likely(!dccp_ctl_socket_init)) {
181+
if (likely(ctl_sock_initialized)) {
183182
int rc = dccp_feat_init(sk);
184183

185184
if (rc)
@@ -211,7 +210,6 @@ int dccp_init_sock(struct sock *sk)
211210
/* control socket doesn't need feat nego */
212211
INIT_LIST_HEAD(&dp->dccps_options.dccpo_pending);
213212
INIT_LIST_HEAD(&dp->dccps_options.dccpo_conf);
214-
dccp_ctl_socket_init = 0;
215213
}
216214

217215
dccp_init_xmit_timers(sk);

0 commit comments

Comments
 (0)