Skip to content

Commit f21e68c

Browse files
Arnaldo Carvalho de MeloDavid S. Miller
authored andcommitted
[DCCP]: Prepare the AF agnostic core for the introduction of DCCPv6
Basically exports a similar set of functions as the one exported by the non-AF specific TCP code. In the process moved some non-AF specific code from dccp_v4_connect to dccp_connect_init and moved the checksum verification from dccp_invalid_packet to dccp_v4_rcv, so as to use it in dccp_v6_rcv too. Signed-off-by: Arnaldo Carvalho de Melo <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 34ca686 commit f21e68c

File tree

6 files changed

+114
-52
lines changed

6 files changed

+114
-52
lines changed

net/dccp/dccp.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,9 @@ extern int dccp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
228228
extern int dccp_rcv_established(struct sock *sk, struct sk_buff *skb,
229229
const struct dccp_hdr *dh, const unsigned len);
230230

231+
extern int dccp_v4_init_sock(struct sock *sk);
232+
extern int dccp_v4_destroy_sock(struct sock *sk);
233+
231234
extern void dccp_close(struct sock *sk, long timeout);
232235
extern struct sk_buff *dccp_make_response(struct sock *sk,
233236
struct dst_entry *dst,
@@ -238,6 +241,7 @@ extern struct sk_buff *dccp_make_reset(struct sock *sk,
238241

239242
extern int dccp_connect(struct sock *sk);
240243
extern int dccp_disconnect(struct sock *sk, int flags);
244+
extern void dccp_unhash(struct sock *sk);
241245
extern int dccp_getsockopt(struct sock *sk, int level, int optname,
242246
char __user *optval, int __user *optlen);
243247
extern int dccp_setsockopt(struct sock *sk, int level, int optname,
@@ -249,13 +253,31 @@ extern int dccp_recvmsg(struct kiocb *iocb, struct sock *sk,
249253
struct msghdr *msg, size_t len, int nonblock,
250254
int flags, int *addr_len);
251255
extern void dccp_shutdown(struct sock *sk, int how);
256+
extern int inet_dccp_listen(struct socket *sock, int backlog);
257+
extern unsigned int dccp_poll(struct file *file, struct socket *sock,
258+
poll_table *wait);
259+
extern void dccp_v4_send_check(struct sock *sk, int len,
260+
struct sk_buff *skb);
261+
extern int dccp_v4_connect(struct sock *sk, struct sockaddr *uaddr,
262+
int addr_len);
252263

253264
extern int dccp_v4_checksum(const struct sk_buff *skb,
254265
const u32 saddr, const u32 daddr);
255266

256267
extern int dccp_v4_send_reset(struct sock *sk,
257268
enum dccp_reset_codes code);
258269
extern void dccp_send_close(struct sock *sk, const int active);
270+
extern int dccp_invalid_packet(struct sk_buff *skb);
271+
272+
static inline int dccp_bad_service_code(const struct sock *sk,
273+
const __u32 service)
274+
{
275+
const struct dccp_sock *dp = dccp_sk(sk);
276+
277+
if (dp->dccps_service == service)
278+
return 0;
279+
return !dccp_list_has_service(dp->dccps_service_list, service);
280+
}
259281

260282
struct dccp_skb_cb {
261283
__u8 dccpd_type:4;

net/dccp/input.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,8 @@ int dccp_rcv_established(struct sock *sk, struct sk_buff *skb,
250250
return 0;
251251
}
252252

253+
EXPORT_SYMBOL_GPL(dccp_rcv_established);
254+
253255
static int dccp_rcv_request_sent_state_process(struct sock *sk,
254256
struct sk_buff *skb,
255257
const struct dccp_hdr *dh,
@@ -567,3 +569,5 @@ int dccp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
567569
}
568570
return 0;
569571
}
572+
573+
EXPORT_SYMBOL_GPL(dccp_rcv_state_process);

net/dccp/ipv4.c

Lines changed: 34 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,13 @@ static void dccp_v4_hash(struct sock *sk)
4646
inet_hash(&dccp_hashinfo, sk);
4747
}
4848

49-
static void dccp_v4_unhash(struct sock *sk)
49+
void dccp_unhash(struct sock *sk)
5050
{
5151
inet_unhash(&dccp_hashinfo, sk);
5252
}
5353

54+
EXPORT_SYMBOL_GPL(dccp_unhash);
55+
5456
/* called with local bh disabled */
5557
static int __dccp_v4_check_established(struct sock *sk, const __u16 lport,
5658
struct inet_timewait_sock **twp)
@@ -209,8 +211,7 @@ static int dccp_v4_hash_connect(struct sock *sk)
209211
}
210212
}
211213

212-
static int dccp_v4_connect(struct sock *sk, struct sockaddr *uaddr,
213-
int addr_len)
214+
int dccp_v4_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len)
214215
{
215216
struct inet_sock *inet = inet_sk(sk);
216217
struct dccp_sock *dp = dccp_sk(sk);
@@ -288,16 +289,6 @@ static int dccp_v4_connect(struct sock *sk, struct sockaddr *uaddr,
288289
usin->sin_port);
289290
dccp_update_gss(sk, dp->dccps_iss);
290291

291-
/*
292-
* SWL and AWL are initially adjusted so that they are not less than
293-
* the initial Sequence Numbers received and sent, respectively:
294-
* SWL := max(GSR + 1 - floor(W/4), ISR),
295-
* AWL := max(GSS - W' + 1, ISS).
296-
* These adjustments MUST be applied only at the beginning of the
297-
* connection.
298-
*/
299-
dccp_set_seqno(&dp->dccps_awl, max48(dp->dccps_awl, dp->dccps_iss));
300-
301292
inet->id = dp->dccps_iss ^ jiffies;
302293

303294
err = dccp_connect(sk);
@@ -317,6 +308,8 @@ static int dccp_v4_connect(struct sock *sk, struct sockaddr *uaddr,
317308
goto out;
318309
}
319310

311+
EXPORT_SYMBOL_GPL(dccp_v4_connect);
312+
320313
/*
321314
* This routine does path mtu discovery as defined in RFC1191.
322315
*/
@@ -608,14 +601,16 @@ void dccp_v4_err(struct sk_buff *skb, u32 info)
608601
}
609602

610603
/* This routine computes an IPv4 DCCP checksum. */
611-
static void dccp_v4_send_check(struct sock *sk, int len, struct sk_buff *skb)
604+
void dccp_v4_send_check(struct sock *sk, int len, struct sk_buff *skb)
612605
{
613606
const struct inet_sock *inet = inet_sk(sk);
614607
struct dccp_hdr *dh = dccp_hdr(skb);
615608

616609
dh->dccph_checksum = dccp_v4_checksum(skb, inet->saddr, inet->daddr);
617610
}
618611

612+
EXPORT_SYMBOL_GPL(dccp_v4_send_check);
613+
619614
int dccp_v4_send_reset(struct sock *sk, enum dccp_reset_codes code)
620615
{
621616
struct sk_buff *skb;
@@ -651,16 +646,6 @@ static inline u64 dccp_v4_init_sequence(const struct sock *sk,
651646
dccp_hdr(skb)->dccph_sport);
652647
}
653648

654-
static inline int dccp_bad_service_code(const struct sock *sk,
655-
const __u32 service)
656-
{
657-
const struct dccp_sock *dp = dccp_sk(sk);
658-
659-
if (dp->dccps_service == service)
660-
return 0;
661-
return !dccp_list_has_service(dp->dccps_service_list, service);
662-
}
663-
664649
int dccp_v4_conn_request(struct sock *sk, struct sk_buff *skb)
665650
{
666651
struct inet_request_sock *ireq;
@@ -672,7 +657,6 @@ int dccp_v4_conn_request(struct sock *sk, struct sk_buff *skb)
672657
const __u32 service = dccp_hdr_request(skb)->dccph_req_service;
673658
struct dccp_skb_cb *dcb = DCCP_SKB_CB(skb);
674659
__u8 reset_code = DCCP_RESET_CODE_TOO_BUSY;
675-
struct dst_entry *dst = NULL;
676660

677661
/* Never answer to DCCP_PKT_REQUESTs send to broadcast or multicast */
678662
if (((struct rtable *)skb->dst)->rt_flags &
@@ -713,7 +697,6 @@ int dccp_v4_conn_request(struct sock *sk, struct sk_buff *skb)
713697
ireq = inet_rsk(req);
714698
ireq->loc_addr = daddr;
715699
ireq->rmt_addr = saddr;
716-
/* FIXME: Merge Aristeu's option parsing code when ready */
717700
req->rcv_wnd = 100; /* Fake, option parsing will get the
718701
right value */
719702
ireq->opt = NULL;
@@ -731,7 +714,7 @@ int dccp_v4_conn_request(struct sock *sk, struct sk_buff *skb)
731714
dreq->dreq_iss = dccp_v4_init_sequence(sk, skb);
732715
dreq->dreq_service = service;
733716

734-
if (dccp_v4_send_response(sk, req, dst))
717+
if (dccp_v4_send_response(sk, req, NULL))
735718
goto drop_and_free;
736719

737720
inet_csk_reqsk_queue_hash_add(sk, req, DCCP_TIMEOUT_INIT);
@@ -748,6 +731,8 @@ int dccp_v4_conn_request(struct sock *sk, struct sk_buff *skb)
748731
return -1;
749732
}
750733

734+
EXPORT_SYMBOL_GPL(dccp_v4_conn_request);
735+
751736
/*
752737
* The three way handshake has completed - we got a valid ACK or DATAACK -
753738
* now create the new socket.
@@ -802,6 +787,8 @@ struct sock *dccp_v4_request_recv_sock(struct sock *sk, struct sk_buff *skb,
802787
return NULL;
803788
}
804789

790+
EXPORT_SYMBOL_GPL(dccp_v4_request_recv_sock);
791+
805792
static struct sock *dccp_v4_hnd_req(struct sock *sk, struct sk_buff *skb)
806793
{
807794
const struct dccp_hdr *dh = dccp_hdr(skb);
@@ -1021,7 +1008,9 @@ int dccp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
10211008
return 0;
10221009
}
10231010

1024-
static inline int dccp_invalid_packet(struct sk_buff *skb)
1011+
EXPORT_SYMBOL_GPL(dccp_v4_do_rcv);
1012+
1013+
int dccp_invalid_packet(struct sk_buff *skb)
10251014
{
10261015
const struct dccp_hdr *dh;
10271016

@@ -1075,17 +1064,11 @@ static inline int dccp_invalid_packet(struct sk_buff *skb)
10751064
return 1;
10761065
}
10771066

1078-
/* If the header checksum is incorrect, drop packet and return */
1079-
if (dccp_v4_verify_checksum(skb, skb->nh.iph->saddr,
1080-
skb->nh.iph->daddr) < 0) {
1081-
LIMIT_NETDEBUG(KERN_WARNING "DCCP: header checksum is "
1082-
"incorrect\n");
1083-
return 1;
1084-
}
1085-
10861067
return 0;
10871068
}
10881069

1070+
EXPORT_SYMBOL_GPL(dccp_invalid_packet);
1071+
10891072
/* this is called when real data arrives */
10901073
int dccp_v4_rcv(struct sk_buff *skb)
10911074
{
@@ -1098,6 +1081,14 @@ int dccp_v4_rcv(struct sk_buff *skb)
10981081
if (dccp_invalid_packet(skb))
10991082
goto discard_it;
11001083

1084+
/* If the header checksum is incorrect, drop packet and return */
1085+
if (dccp_v4_verify_checksum(skb, skb->nh.iph->saddr,
1086+
skb->nh.iph->daddr) < 0) {
1087+
LIMIT_NETDEBUG(KERN_WARNING "%s: incorrect header checksum\n",
1088+
__FUNCTION__);
1089+
goto discard_it;
1090+
}
1091+
11011092
dh = dccp_hdr(skb);
11021093

11031094
DCCP_SKB_CB(skb)->dccpd_seq = dccp_hdr_seq(skb);
@@ -1217,7 +1208,7 @@ struct inet_connection_sock_af_ops dccp_ipv4_af_ops = {
12171208
.sockaddr_len = sizeof(struct sockaddr_in),
12181209
};
12191210

1220-
static int dccp_v4_init_sock(struct sock *sk)
1211+
int dccp_v4_init_sock(struct sock *sk)
12211212
{
12221213
struct dccp_sock *dp = dccp_sk(sk);
12231214
static int dccp_ctl_socket_init = 1;
@@ -1270,7 +1261,9 @@ static int dccp_v4_init_sock(struct sock *sk)
12701261
return 0;
12711262
}
12721263

1273-
static int dccp_v4_destroy_sock(struct sock *sk)
1264+
EXPORT_SYMBOL_GPL(dccp_v4_init_sock);
1265+
1266+
int dccp_v4_destroy_sock(struct sock *sk)
12741267
{
12751268
struct dccp_sock *dp = dccp_sk(sk);
12761269

@@ -1303,6 +1296,8 @@ static int dccp_v4_destroy_sock(struct sock *sk)
13031296
return 0;
13041297
}
13051298

1299+
EXPORT_SYMBOL_GPL(dccp_v4_destroy_sock);
1300+
13061301
static void dccp_v4_reqsk_destructor(struct request_sock *req)
13071302
{
13081303
kfree(inet_rsk(req)->opt);
@@ -1331,7 +1326,7 @@ struct proto dccp_prot = {
13311326
.recvmsg = dccp_recvmsg,
13321327
.backlog_rcv = dccp_v4_do_rcv,
13331328
.hash = dccp_v4_hash,
1334-
.unhash = dccp_v4_unhash,
1329+
.unhash = dccp_unhash,
13351330
.accept = inet_csk_accept,
13361331
.get_port = dccp_v4_get_port,
13371332
.shutdown = dccp_shutdown,

net/dccp/minisocks.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ struct inet_timewait_death_row dccp_death_row = {
4040
(unsigned long)&dccp_death_row),
4141
};
4242

43+
EXPORT_SYMBOL_GPL(dccp_death_row);
44+
4345
void dccp_time_wait(struct sock *sk, int state, int timeo)
4446
{
4547
struct inet_timewait_sock *tw = NULL;
@@ -170,6 +172,8 @@ struct sock *dccp_create_openreq_child(struct sock *sk,
170172
return newsk;
171173
}
172174

175+
EXPORT_SYMBOL_GPL(dccp_create_openreq_child);
176+
173177
/*
174178
* Process an incoming packet for RESPOND sockets represented
175179
* as an request_sock.
@@ -236,6 +240,8 @@ struct sock *dccp_check_req(struct sock *sk, struct sk_buff *skb,
236240
goto out;
237241
}
238242

243+
EXPORT_SYMBOL_GPL(dccp_check_req);
244+
239245
/*
240246
* Queue segment on the new socket if the new socket is active,
241247
* otherwise we just shortcircuit this and continue with
@@ -266,3 +272,5 @@ int dccp_child_process(struct sock *parent, struct sock *child,
266272
sock_put(child);
267273
return ret;
268274
}
275+
276+
EXPORT_SYMBOL_GPL(dccp_child_process);

net/dccp/output.c

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,6 @@ static int dccp_transmit_skb(struct sock *sk, struct sk_buff *skb)
135135
unsigned int dccp_sync_mss(struct sock *sk, u32 pmtu)
136136
{
137137
struct dccp_sock *dp = dccp_sk(sk);
138-
/*
139-
* FIXME: we really should be using the af_specific thing to support
140-
* IPv6.
141-
* mss_now = pmtu - tp->af_specific->net_header_len -
142-
* sizeof(struct dccp_hdr) - sizeof(struct dccp_hdr_ext);
143-
*/
144138
int mss_now = (pmtu - inet_csk(sk)->icsk_af_ops->net_header_len -
145139
sizeof(struct dccp_hdr) - sizeof(struct dccp_hdr_ext));
146140

@@ -164,6 +158,8 @@ unsigned int dccp_sync_mss(struct sock *sk, u32 pmtu)
164158
return mss_now;
165159
}
166160

161+
EXPORT_SYMBOL_GPL(dccp_sync_mss);
162+
167163
void dccp_write_space(struct sock *sk)
168164
{
169165
read_lock(&sk->sk_callback_lock);
@@ -319,6 +315,8 @@ struct sk_buff *dccp_make_response(struct sock *sk, struct dst_entry *dst,
319315
return skb;
320316
}
321317

318+
EXPORT_SYMBOL_GPL(dccp_make_response);
319+
322320
struct sk_buff *dccp_make_reset(struct sock *sk, struct dst_entry *dst,
323321
const enum dccp_reset_codes code)
324322

@@ -375,6 +373,7 @@ struct sk_buff *dccp_make_reset(struct sock *sk, struct dst_entry *dst,
375373
*/
376374
static inline void dccp_connect_init(struct sock *sk)
377375
{
376+
struct dccp_sock *dp = dccp_sk(sk);
378377
struct dst_entry *dst = __sk_dst_get(sk);
379378
struct inet_connection_sock *icsk = inet_csk(sk);
380379

@@ -383,10 +382,16 @@ static inline void dccp_connect_init(struct sock *sk)
383382

384383
dccp_sync_mss(sk, dst_mtu(dst));
385384

386-
/*
387-
* FIXME: set dp->{dccps_swh,dccps_swl}, with
388-
* something like dccp_inc_seq
389-
*/
385+
dccp_update_gss(sk, dp->dccps_iss);
386+
/*
387+
* SWL and AWL are initially adjusted so that they are not less than
388+
* the initial Sequence Numbers received and sent, respectively:
389+
* SWL := max(GSR + 1 - floor(W/4), ISR),
390+
* AWL := max(GSS - W' + 1, ISS).
391+
* These adjustments MUST be applied only at the beginning of the
392+
* connection.
393+
*/
394+
dccp_set_seqno(&dp->dccps_awl, max48(dp->dccps_awl, dp->dccps_iss));
390395

391396
icsk->icsk_retransmits = 0;
392397
}
@@ -418,6 +423,8 @@ int dccp_connect(struct sock *sk)
418423
return 0;
419424
}
420425

426+
EXPORT_SYMBOL_GPL(dccp_connect);
427+
421428
void dccp_send_ack(struct sock *sk)
422429
{
423430
/* If we have been reset, we may not send again. */

0 commit comments

Comments
 (0)