]> bbs.cooldavid.org Git - net-next-2.6.git/blob - net/ipv4/inet_connection_sock.c
[INET]: Rename inet_csk_ctl_sock_create to inet_ctl_sock_create.
[net-next-2.6.git] / net / ipv4 / inet_connection_sock.c
1 /*
2  * INET         An implementation of the TCP/IP protocol suite for the LINUX
3  *              operating system.  INET is implemented using the  BSD Socket
4  *              interface as the means of communication with the user level.
5  *
6  *              Support for INET connection oriented protocols.
7  *
8  * Authors:     See the TCP sources
9  *
10  *              This program is free software; you can redistribute it and/or
11  *              modify it under the terms of the GNU General Public License
12  *              as published by the Free Software Foundation; either version
13  *              2 of the License, or(at your option) any later version.
14  */
15
16 #include <linux/module.h>
17 #include <linux/jhash.h>
18
19 #include <net/inet_connection_sock.h>
20 #include <net/inet_hashtables.h>
21 #include <net/inet_timewait_sock.h>
22 #include <net/ip.h>
23 #include <net/route.h>
24 #include <net/tcp_states.h>
25 #include <net/xfrm.h>
26
27 #ifdef INET_CSK_DEBUG
28 const char inet_csk_timer_bug_msg[] = "inet_csk BUG: unknown timer value\n";
29 EXPORT_SYMBOL(inet_csk_timer_bug_msg);
30 #endif
31
32 /*
33  * This array holds the first and last local port number.
34  */
35 int sysctl_local_port_range[2] = { 32768, 61000 };
36 DEFINE_SEQLOCK(sysctl_port_range_lock);
37
38 void inet_get_local_port_range(int *low, int *high)
39 {
40         unsigned seq;
41         do {
42                 seq = read_seqbegin(&sysctl_port_range_lock);
43
44                 *low = sysctl_local_port_range[0];
45                 *high = sysctl_local_port_range[1];
46         } while (read_seqretry(&sysctl_port_range_lock, seq));
47 }
48 EXPORT_SYMBOL(inet_get_local_port_range);
49
50 int inet_csk_bind_conflict(const struct sock *sk,
51                            const struct inet_bind_bucket *tb)
52 {
53         const __be32 sk_rcv_saddr = inet_rcv_saddr(sk);
54         struct sock *sk2;
55         struct hlist_node *node;
56         int reuse = sk->sk_reuse;
57
58         sk_for_each_bound(sk2, node, &tb->owners) {
59                 if (sk != sk2 &&
60                     !inet_v6_ipv6only(sk2) &&
61                     (!sk->sk_bound_dev_if ||
62                      !sk2->sk_bound_dev_if ||
63                      sk->sk_bound_dev_if == sk2->sk_bound_dev_if)) {
64                         if (!reuse || !sk2->sk_reuse ||
65                             sk2->sk_state == TCP_LISTEN) {
66                                 const __be32 sk2_rcv_saddr = inet_rcv_saddr(sk2);
67                                 if (!sk2_rcv_saddr || !sk_rcv_saddr ||
68                                     sk2_rcv_saddr == sk_rcv_saddr)
69                                         break;
70                         }
71                 }
72         }
73         return node != NULL;
74 }
75
76 EXPORT_SYMBOL_GPL(inet_csk_bind_conflict);
77
78 /* Obtain a reference to a local port for the given sock,
79  * if snum is zero it means select any available local port.
80  */
81 int inet_csk_get_port(struct sock *sk, unsigned short snum)
82 {
83         struct inet_hashinfo *hashinfo = sk->sk_prot->h.hashinfo;
84         struct inet_bind_hashbucket *head;
85         struct hlist_node *node;
86         struct inet_bind_bucket *tb;
87         int ret;
88         struct net *net = sock_net(sk);
89
90         local_bh_disable();
91         if (!snum) {
92                 int remaining, rover, low, high;
93
94                 inet_get_local_port_range(&low, &high);
95                 remaining = (high - low) + 1;
96                 rover = net_random() % remaining + low;
97
98                 do {
99                         head = &hashinfo->bhash[inet_bhashfn(rover, hashinfo->bhash_size)];
100                         spin_lock(&head->lock);
101                         inet_bind_bucket_for_each(tb, node, &head->chain)
102                                 if (tb->ib_net == net && tb->port == rover)
103                                         goto next;
104                         break;
105                 next:
106                         spin_unlock(&head->lock);
107                         if (++rover > high)
108                                 rover = low;
109                 } while (--remaining > 0);
110
111                 /* Exhausted local port range during search?  It is not
112                  * possible for us to be holding one of the bind hash
113                  * locks if this test triggers, because if 'remaining'
114                  * drops to zero, we broke out of the do/while loop at
115                  * the top level, not from the 'break;' statement.
116                  */
117                 ret = 1;
118                 if (remaining <= 0)
119                         goto fail;
120
121                 /* OK, here is the one we will use.  HEAD is
122                  * non-NULL and we hold it's mutex.
123                  */
124                 snum = rover;
125         } else {
126                 head = &hashinfo->bhash[inet_bhashfn(snum, hashinfo->bhash_size)];
127                 spin_lock(&head->lock);
128                 inet_bind_bucket_for_each(tb, node, &head->chain)
129                         if (tb->ib_net == net && tb->port == snum)
130                                 goto tb_found;
131         }
132         tb = NULL;
133         goto tb_not_found;
134 tb_found:
135         if (!hlist_empty(&tb->owners)) {
136                 if (sk->sk_reuse > 1)
137                         goto success;
138                 if (tb->fastreuse > 0 &&
139                     sk->sk_reuse && sk->sk_state != TCP_LISTEN) {
140                         goto success;
141                 } else {
142                         ret = 1;
143                         if (inet_csk(sk)->icsk_af_ops->bind_conflict(sk, tb))
144                                 goto fail_unlock;
145                 }
146         }
147 tb_not_found:
148         ret = 1;
149         if (!tb && (tb = inet_bind_bucket_create(hashinfo->bind_bucket_cachep,
150                                         net, head, snum)) == NULL)
151                 goto fail_unlock;
152         if (hlist_empty(&tb->owners)) {
153                 if (sk->sk_reuse && sk->sk_state != TCP_LISTEN)
154                         tb->fastreuse = 1;
155                 else
156                         tb->fastreuse = 0;
157         } else if (tb->fastreuse &&
158                    (!sk->sk_reuse || sk->sk_state == TCP_LISTEN))
159                 tb->fastreuse = 0;
160 success:
161         if (!inet_csk(sk)->icsk_bind_hash)
162                 inet_bind_hash(sk, tb, snum);
163         BUG_TRAP(inet_csk(sk)->icsk_bind_hash == tb);
164         ret = 0;
165
166 fail_unlock:
167         spin_unlock(&head->lock);
168 fail:
169         local_bh_enable();
170         return ret;
171 }
172
173 EXPORT_SYMBOL_GPL(inet_csk_get_port);
174
175 /*
176  * Wait for an incoming connection, avoid race conditions. This must be called
177  * with the socket locked.
178  */
179 static int inet_csk_wait_for_connect(struct sock *sk, long timeo)
180 {
181         struct inet_connection_sock *icsk = inet_csk(sk);
182         DEFINE_WAIT(wait);
183         int err;
184
185         /*
186          * True wake-one mechanism for incoming connections: only
187          * one process gets woken up, not the 'whole herd'.
188          * Since we do not 'race & poll' for established sockets
189          * anymore, the common case will execute the loop only once.
190          *
191          * Subtle issue: "add_wait_queue_exclusive()" will be added
192          * after any current non-exclusive waiters, and we know that
193          * it will always _stay_ after any new non-exclusive waiters
194          * because all non-exclusive waiters are added at the
195          * beginning of the wait-queue. As such, it's ok to "drop"
196          * our exclusiveness temporarily when we get woken up without
197          * having to remove and re-insert us on the wait queue.
198          */
199         for (;;) {
200                 prepare_to_wait_exclusive(sk->sk_sleep, &wait,
201                                           TASK_INTERRUPTIBLE);
202                 release_sock(sk);
203                 if (reqsk_queue_empty(&icsk->icsk_accept_queue))
204                         timeo = schedule_timeout(timeo);
205                 lock_sock(sk);
206                 err = 0;
207                 if (!reqsk_queue_empty(&icsk->icsk_accept_queue))
208                         break;
209                 err = -EINVAL;
210                 if (sk->sk_state != TCP_LISTEN)
211                         break;
212                 err = sock_intr_errno(timeo);
213                 if (signal_pending(current))
214                         break;
215                 err = -EAGAIN;
216                 if (!timeo)
217                         break;
218         }
219         finish_wait(sk->sk_sleep, &wait);
220         return err;
221 }
222
223 /*
224  * This will accept the next outstanding connection.
225  */
226 struct sock *inet_csk_accept(struct sock *sk, int flags, int *err)
227 {
228         struct inet_connection_sock *icsk = inet_csk(sk);
229         struct sock *newsk;
230         int error;
231
232         lock_sock(sk);
233
234         /* We need to make sure that this socket is listening,
235          * and that it has something pending.
236          */
237         error = -EINVAL;
238         if (sk->sk_state != TCP_LISTEN)
239                 goto out_err;
240
241         /* Find already established connection */
242         if (reqsk_queue_empty(&icsk->icsk_accept_queue)) {
243                 long timeo = sock_rcvtimeo(sk, flags & O_NONBLOCK);
244
245                 /* If this is a non blocking socket don't sleep */
246                 error = -EAGAIN;
247                 if (!timeo)
248                         goto out_err;
249
250                 error = inet_csk_wait_for_connect(sk, timeo);
251                 if (error)
252                         goto out_err;
253         }
254
255         newsk = reqsk_queue_get_child(&icsk->icsk_accept_queue, sk);
256         BUG_TRAP(newsk->sk_state != TCP_SYN_RECV);
257 out:
258         release_sock(sk);
259         return newsk;
260 out_err:
261         newsk = NULL;
262         *err = error;
263         goto out;
264 }
265
266 EXPORT_SYMBOL(inet_csk_accept);
267
268 /*
269  * Using different timers for retransmit, delayed acks and probes
270  * We may wish use just one timer maintaining a list of expire jiffies
271  * to optimize.
272  */
273 void inet_csk_init_xmit_timers(struct sock *sk,
274                                void (*retransmit_handler)(unsigned long),
275                                void (*delack_handler)(unsigned long),
276                                void (*keepalive_handler)(unsigned long))
277 {
278         struct inet_connection_sock *icsk = inet_csk(sk);
279
280         setup_timer(&icsk->icsk_retransmit_timer, retransmit_handler,
281                         (unsigned long)sk);
282         setup_timer(&icsk->icsk_delack_timer, delack_handler,
283                         (unsigned long)sk);
284         setup_timer(&sk->sk_timer, keepalive_handler, (unsigned long)sk);
285         icsk->icsk_pending = icsk->icsk_ack.pending = 0;
286 }
287
288 EXPORT_SYMBOL(inet_csk_init_xmit_timers);
289
290 void inet_csk_clear_xmit_timers(struct sock *sk)
291 {
292         struct inet_connection_sock *icsk = inet_csk(sk);
293
294         icsk->icsk_pending = icsk->icsk_ack.pending = icsk->icsk_ack.blocked = 0;
295
296         sk_stop_timer(sk, &icsk->icsk_retransmit_timer);
297         sk_stop_timer(sk, &icsk->icsk_delack_timer);
298         sk_stop_timer(sk, &sk->sk_timer);
299 }
300
301 EXPORT_SYMBOL(inet_csk_clear_xmit_timers);
302
303 void inet_csk_delete_keepalive_timer(struct sock *sk)
304 {
305         sk_stop_timer(sk, &sk->sk_timer);
306 }
307
308 EXPORT_SYMBOL(inet_csk_delete_keepalive_timer);
309
310 void inet_csk_reset_keepalive_timer(struct sock *sk, unsigned long len)
311 {
312         sk_reset_timer(sk, &sk->sk_timer, jiffies + len);
313 }
314
315 EXPORT_SYMBOL(inet_csk_reset_keepalive_timer);
316
317 struct dst_entry* inet_csk_route_req(struct sock *sk,
318                                      const struct request_sock *req)
319 {
320         struct rtable *rt;
321         const struct inet_request_sock *ireq = inet_rsk(req);
322         struct ip_options *opt = inet_rsk(req)->opt;
323         struct flowi fl = { .oif = sk->sk_bound_dev_if,
324                             .nl_u = { .ip4_u =
325                                       { .daddr = ((opt && opt->srr) ?
326                                                   opt->faddr :
327                                                   ireq->rmt_addr),
328                                         .saddr = ireq->loc_addr,
329                                         .tos = RT_CONN_FLAGS(sk) } },
330                             .proto = sk->sk_protocol,
331                             .uli_u = { .ports =
332                                        { .sport = inet_sk(sk)->sport,
333                                          .dport = ireq->rmt_port } } };
334
335         security_req_classify_flow(req, &fl);
336         if (ip_route_output_flow(sock_net(sk), &rt, &fl, sk, 0)) {
337                 IP_INC_STATS_BH(IPSTATS_MIB_OUTNOROUTES);
338                 return NULL;
339         }
340         if (opt && opt->is_strictroute && rt->rt_dst != rt->rt_gateway) {
341                 ip_rt_put(rt);
342                 IP_INC_STATS_BH(IPSTATS_MIB_OUTNOROUTES);
343                 return NULL;
344         }
345         return &rt->u.dst;
346 }
347
348 EXPORT_SYMBOL_GPL(inet_csk_route_req);
349
350 static inline u32 inet_synq_hash(const __be32 raddr, const __be16 rport,
351                                  const u32 rnd, const u32 synq_hsize)
352 {
353         return jhash_2words((__force u32)raddr, (__force u32)rport, rnd) & (synq_hsize - 1);
354 }
355
356 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
357 #define AF_INET_FAMILY(fam) ((fam) == AF_INET)
358 #else
359 #define AF_INET_FAMILY(fam) 1
360 #endif
361
362 struct request_sock *inet_csk_search_req(const struct sock *sk,
363                                          struct request_sock ***prevp,
364                                          const __be16 rport, const __be32 raddr,
365                                          const __be32 laddr)
366 {
367         const struct inet_connection_sock *icsk = inet_csk(sk);
368         struct listen_sock *lopt = icsk->icsk_accept_queue.listen_opt;
369         struct request_sock *req, **prev;
370
371         for (prev = &lopt->syn_table[inet_synq_hash(raddr, rport, lopt->hash_rnd,
372                                                     lopt->nr_table_entries)];
373              (req = *prev) != NULL;
374              prev = &req->dl_next) {
375                 const struct inet_request_sock *ireq = inet_rsk(req);
376
377                 if (ireq->rmt_port == rport &&
378                     ireq->rmt_addr == raddr &&
379                     ireq->loc_addr == laddr &&
380                     AF_INET_FAMILY(req->rsk_ops->family)) {
381                         BUG_TRAP(!req->sk);
382                         *prevp = prev;
383                         break;
384                 }
385         }
386
387         return req;
388 }
389
390 EXPORT_SYMBOL_GPL(inet_csk_search_req);
391
392 void inet_csk_reqsk_queue_hash_add(struct sock *sk, struct request_sock *req,
393                                    unsigned long timeout)
394 {
395         struct inet_connection_sock *icsk = inet_csk(sk);
396         struct listen_sock *lopt = icsk->icsk_accept_queue.listen_opt;
397         const u32 h = inet_synq_hash(inet_rsk(req)->rmt_addr, inet_rsk(req)->rmt_port,
398                                      lopt->hash_rnd, lopt->nr_table_entries);
399
400         reqsk_queue_hash_req(&icsk->icsk_accept_queue, h, req, timeout);
401         inet_csk_reqsk_queue_added(sk, timeout);
402 }
403
404 /* Only thing we need from tcp.h */
405 extern int sysctl_tcp_synack_retries;
406
407 EXPORT_SYMBOL_GPL(inet_csk_reqsk_queue_hash_add);
408
409 void inet_csk_reqsk_queue_prune(struct sock *parent,
410                                 const unsigned long interval,
411                                 const unsigned long timeout,
412                                 const unsigned long max_rto)
413 {
414         struct inet_connection_sock *icsk = inet_csk(parent);
415         struct request_sock_queue *queue = &icsk->icsk_accept_queue;
416         struct listen_sock *lopt = queue->listen_opt;
417         int thresh = icsk->icsk_syn_retries ? : sysctl_tcp_synack_retries;
418         unsigned long now = jiffies;
419         struct request_sock **reqp, *req;
420         int i, budget;
421
422         if (lopt == NULL || lopt->qlen == 0)
423                 return;
424
425         /* Normally all the openreqs are young and become mature
426          * (i.e. converted to established socket) for first timeout.
427          * If synack was not acknowledged for 3 seconds, it means
428          * one of the following things: synack was lost, ack was lost,
429          * rtt is high or nobody planned to ack (i.e. synflood).
430          * When server is a bit loaded, queue is populated with old
431          * open requests, reducing effective size of queue.
432          * When server is well loaded, queue size reduces to zero
433          * after several minutes of work. It is not synflood,
434          * it is normal operation. The solution is pruning
435          * too old entries overriding normal timeout, when
436          * situation becomes dangerous.
437          *
438          * Essentially, we reserve half of room for young
439          * embrions; and abort old ones without pity, if old
440          * ones are about to clog our table.
441          */
442         if (lopt->qlen>>(lopt->max_qlen_log-1)) {
443                 int young = (lopt->qlen_young<<1);
444
445                 while (thresh > 2) {
446                         if (lopt->qlen < young)
447                                 break;
448                         thresh--;
449                         young <<= 1;
450                 }
451         }
452
453         budget = 2 * (lopt->nr_table_entries / (timeout / interval));
454         i = lopt->clock_hand;
455
456         do {
457                 reqp=&lopt->syn_table[i];
458                 while ((req = *reqp) != NULL) {
459                         if (time_after_eq(now, req->expires)) {
460                                 if (req->retrans < thresh &&
461                                     !req->rsk_ops->rtx_syn_ack(parent, req)) {
462                                         unsigned long timeo;
463
464                                         if (req->retrans++ == 0)
465                                                 lopt->qlen_young--;
466                                         timeo = min((timeout << req->retrans), max_rto);
467                                         req->expires = now + timeo;
468                                         reqp = &req->dl_next;
469                                         continue;
470                                 }
471
472                                 /* Drop this request */
473                                 inet_csk_reqsk_queue_unlink(parent, req, reqp);
474                                 reqsk_queue_removed(queue, req);
475                                 reqsk_free(req);
476                                 continue;
477                         }
478                         reqp = &req->dl_next;
479                 }
480
481                 i = (i + 1) & (lopt->nr_table_entries - 1);
482
483         } while (--budget > 0);
484
485         lopt->clock_hand = i;
486
487         if (lopt->qlen)
488                 inet_csk_reset_keepalive_timer(parent, interval);
489 }
490
491 EXPORT_SYMBOL_GPL(inet_csk_reqsk_queue_prune);
492
493 struct sock *inet_csk_clone(struct sock *sk, const struct request_sock *req,
494                             const gfp_t priority)
495 {
496         struct sock *newsk = sk_clone(sk, priority);
497
498         if (newsk != NULL) {
499                 struct inet_connection_sock *newicsk = inet_csk(newsk);
500
501                 newsk->sk_state = TCP_SYN_RECV;
502                 newicsk->icsk_bind_hash = NULL;
503
504                 inet_sk(newsk)->dport = inet_rsk(req)->rmt_port;
505                 newsk->sk_write_space = sk_stream_write_space;
506
507                 newicsk->icsk_retransmits = 0;
508                 newicsk->icsk_backoff     = 0;
509                 newicsk->icsk_probes_out  = 0;
510
511                 /* Deinitialize accept_queue to trap illegal accesses. */
512                 memset(&newicsk->icsk_accept_queue, 0, sizeof(newicsk->icsk_accept_queue));
513
514                 security_inet_csk_clone(newsk, req);
515         }
516         return newsk;
517 }
518
519 EXPORT_SYMBOL_GPL(inet_csk_clone);
520
521 /*
522  * At this point, there should be no process reference to this
523  * socket, and thus no user references at all.  Therefore we
524  * can assume the socket waitqueue is inactive and nobody will
525  * try to jump onto it.
526  */
527 void inet_csk_destroy_sock(struct sock *sk)
528 {
529         BUG_TRAP(sk->sk_state == TCP_CLOSE);
530         BUG_TRAP(sock_flag(sk, SOCK_DEAD));
531
532         /* It cannot be in hash table! */
533         BUG_TRAP(sk_unhashed(sk));
534
535         /* If it has not 0 inet_sk(sk)->num, it must be bound */
536         BUG_TRAP(!inet_sk(sk)->num || inet_csk(sk)->icsk_bind_hash);
537
538         sk->sk_prot->destroy(sk);
539
540         sk_stream_kill_queues(sk);
541
542         xfrm_sk_free_policy(sk);
543
544         sk_refcnt_debug_release(sk);
545
546         atomic_dec(sk->sk_prot->orphan_count);
547         sock_put(sk);
548 }
549
550 EXPORT_SYMBOL(inet_csk_destroy_sock);
551
552 int inet_csk_listen_start(struct sock *sk, const int nr_table_entries)
553 {
554         struct inet_sock *inet = inet_sk(sk);
555         struct inet_connection_sock *icsk = inet_csk(sk);
556         int rc = reqsk_queue_alloc(&icsk->icsk_accept_queue, nr_table_entries);
557
558         if (rc != 0)
559                 return rc;
560
561         sk->sk_max_ack_backlog = 0;
562         sk->sk_ack_backlog = 0;
563         inet_csk_delack_init(sk);
564
565         /* There is race window here: we announce ourselves listening,
566          * but this transition is still not validated by get_port().
567          * It is OK, because this socket enters to hash table only
568          * after validation is complete.
569          */
570         sk->sk_state = TCP_LISTEN;
571         if (!sk->sk_prot->get_port(sk, inet->num)) {
572                 inet->sport = htons(inet->num);
573
574                 sk_dst_reset(sk);
575                 sk->sk_prot->hash(sk);
576
577                 return 0;
578         }
579
580         sk->sk_state = TCP_CLOSE;
581         __reqsk_queue_destroy(&icsk->icsk_accept_queue);
582         return -EADDRINUSE;
583 }
584
585 EXPORT_SYMBOL_GPL(inet_csk_listen_start);
586
587 /*
588  *      This routine closes sockets which have been at least partially
589  *      opened, but not yet accepted.
590  */
591 void inet_csk_listen_stop(struct sock *sk)
592 {
593         struct inet_connection_sock *icsk = inet_csk(sk);
594         struct request_sock *acc_req;
595         struct request_sock *req;
596
597         inet_csk_delete_keepalive_timer(sk);
598
599         /* make all the listen_opt local to us */
600         acc_req = reqsk_queue_yank_acceptq(&icsk->icsk_accept_queue);
601
602         /* Following specs, it would be better either to send FIN
603          * (and enter FIN-WAIT-1, it is normal close)
604          * or to send active reset (abort).
605          * Certainly, it is pretty dangerous while synflood, but it is
606          * bad justification for our negligence 8)
607          * To be honest, we are not able to make either
608          * of the variants now.                 --ANK
609          */
610         reqsk_queue_destroy(&icsk->icsk_accept_queue);
611
612         while ((req = acc_req) != NULL) {
613                 struct sock *child = req->sk;
614
615                 acc_req = req->dl_next;
616
617                 local_bh_disable();
618                 bh_lock_sock(child);
619                 BUG_TRAP(!sock_owned_by_user(child));
620                 sock_hold(child);
621
622                 sk->sk_prot->disconnect(child, O_NONBLOCK);
623
624                 sock_orphan(child);
625
626                 atomic_inc(sk->sk_prot->orphan_count);
627
628                 inet_csk_destroy_sock(child);
629
630                 bh_unlock_sock(child);
631                 local_bh_enable();
632                 sock_put(child);
633
634                 sk_acceptq_removed(sk);
635                 __reqsk_free(req);
636         }
637         BUG_TRAP(!sk->sk_ack_backlog);
638 }
639
640 EXPORT_SYMBOL_GPL(inet_csk_listen_stop);
641
642 void inet_csk_addr2sockaddr(struct sock *sk, struct sockaddr *uaddr)
643 {
644         struct sockaddr_in *sin = (struct sockaddr_in *)uaddr;
645         const struct inet_sock *inet = inet_sk(sk);
646
647         sin->sin_family         = AF_INET;
648         sin->sin_addr.s_addr    = inet->daddr;
649         sin->sin_port           = inet->dport;
650 }
651
652 EXPORT_SYMBOL_GPL(inet_csk_addr2sockaddr);
653
654 #ifdef CONFIG_COMPAT
655 int inet_csk_compat_getsockopt(struct sock *sk, int level, int optname,
656                                char __user *optval, int __user *optlen)
657 {
658         const struct inet_connection_sock *icsk = inet_csk(sk);
659
660         if (icsk->icsk_af_ops->compat_getsockopt != NULL)
661                 return icsk->icsk_af_ops->compat_getsockopt(sk, level, optname,
662                                                             optval, optlen);
663         return icsk->icsk_af_ops->getsockopt(sk, level, optname,
664                                              optval, optlen);
665 }
666
667 EXPORT_SYMBOL_GPL(inet_csk_compat_getsockopt);
668
669 int inet_csk_compat_setsockopt(struct sock *sk, int level, int optname,
670                                char __user *optval, int optlen)
671 {
672         const struct inet_connection_sock *icsk = inet_csk(sk);
673
674         if (icsk->icsk_af_ops->compat_setsockopt != NULL)
675                 return icsk->icsk_af_ops->compat_setsockopt(sk, level, optname,
676                                                             optval, optlen);
677         return icsk->icsk_af_ops->setsockopt(sk, level, optname,
678                                              optval, optlen);
679 }
680
681 EXPORT_SYMBOL_GPL(inet_csk_compat_setsockopt);
682 #endif