~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/net/ipv6/raw.c

Version: ~ [ linux-5.13-rc5 ] ~ [ linux-5.12.9 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.42 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.124 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.193 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.235 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.271 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.271 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.18.140 ] ~ [ linux-3.16.85 ] ~ [ linux-3.14.79 ] ~ [ linux-3.12.74 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  *      RAW sockets for IPv6
  3  *      Linux INET6 implementation
  4  *
  5  *      Authors:
  6  *      Pedro Roque             <roque@di.fc.ul.pt>
  7  *
  8  *      Adapted from linux/net/ipv4/raw.c
  9  *
 10  *      Fixes:
 11  *      Hideaki YOSHIFUJI       :       sin6_scope_id support
 12  *      YOSHIFUJI,H.@USAGI      :       raw checksum (RFC2292(bis) compliance)
 13  *      Kazunori MIYAZAWA @USAGI:       change process style to use ip6_append_data
 14  *
 15  *      This program is free software; you can redistribute it and/or
 16  *      modify it under the terms of the GNU General Public License
 17  *      as published by the Free Software Foundation; either version
 18  *      2 of the License, or (at your option) any later version.
 19  */
 20 
 21 #include <linux/errno.h>
 22 #include <linux/types.h>
 23 #include <linux/socket.h>
 24 #include <linux/sockios.h>
 25 #include <linux/net.h>
 26 #include <linux/in6.h>
 27 #include <linux/netdevice.h>
 28 #include <linux/if_arp.h>
 29 #include <linux/icmpv6.h>
 30 #include <linux/netfilter.h>
 31 #include <linux/netfilter_ipv6.h>
 32 #include <linux/skbuff.h>
 33 #include <asm/uaccess.h>
 34 #include <asm/ioctls.h>
 35 
 36 #include <net/net_namespace.h>
 37 #include <net/ip.h>
 38 #include <net/sock.h>
 39 #include <net/snmp.h>
 40 
 41 #include <net/ipv6.h>
 42 #include <net/ndisc.h>
 43 #include <net/protocol.h>
 44 #include <net/ip6_route.h>
 45 #include <net/ip6_checksum.h>
 46 #include <net/addrconf.h>
 47 #include <net/transp_v6.h>
 48 #include <net/udp.h>
 49 #include <net/inet_common.h>
 50 #include <net/tcp_states.h>
 51 #if defined(CONFIG_IPV6_MIP6) || defined(CONFIG_IPV6_MIP6_MODULE)
 52 #include <net/mip6.h>
 53 #endif
 54 #include <linux/mroute6.h>
 55 
 56 #include <net/raw.h>
 57 #include <net/rawv6.h>
 58 #include <net/xfrm.h>
 59 
 60 #include <linux/proc_fs.h>
 61 #include <linux/seq_file.h>
 62 #include <linux/ccsecurity.h>
 63 
 64 static struct raw_hashinfo raw_v6_hashinfo = {
 65         .lock = __RW_LOCK_UNLOCKED(raw_v6_hashinfo.lock),
 66 };
 67 
 68 static struct sock *__raw_v6_lookup(struct net *net, struct sock *sk,
 69                 unsigned short num, struct in6_addr *loc_addr,
 70                 struct in6_addr *rmt_addr, int dif)
 71 {
 72         struct hlist_node *node;
 73         int is_multicast = ipv6_addr_is_multicast(loc_addr);
 74 
 75         sk_for_each_from(sk, node)
 76                 if (inet_sk(sk)->num == num) {
 77                         struct ipv6_pinfo *np = inet6_sk(sk);
 78 
 79                         if (!net_eq(sock_net(sk), net))
 80                                 continue;
 81 
 82                         if (!ipv6_addr_any(&np->daddr) &&
 83                             !ipv6_addr_equal(&np->daddr, rmt_addr))
 84                                 continue;
 85 
 86                         if (sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif)
 87                                 continue;
 88 
 89                         if (!ipv6_addr_any(&np->rcv_saddr)) {
 90                                 if (ipv6_addr_equal(&np->rcv_saddr, loc_addr))
 91                                         goto found;
 92                                 if (is_multicast &&
 93                                     inet6_mc_check(sk, loc_addr, rmt_addr))
 94                                         goto found;
 95                                 continue;
 96                         }
 97                         goto found;
 98                 }
 99         sk = NULL;
100 found:
101         return sk;
102 }
103 
104 /*
105  *      0 - deliver
106  *      1 - block
107  */
108 static __inline__ int icmpv6_filter(struct sock *sk, struct sk_buff *skb)
109 {
110         struct icmp6hdr *icmph;
111         struct raw6_sock *rp = raw6_sk(sk);
112 
113         if (pskb_may_pull(skb, sizeof(struct icmp6hdr))) {
114                 __u32 *data = &rp->filter.data[0];
115                 int bit_nr;
116 
117                 icmph = (struct icmp6hdr *) skb->data;
118                 bit_nr = icmph->icmp6_type;
119 
120                 return (data[bit_nr >> 5] & (1 << (bit_nr & 31))) != 0;
121         }
122         return 0;
123 }
124 
125 #if defined(CONFIG_IPV6_MIP6) || defined(CONFIG_IPV6_MIP6_MODULE)
126 static int (*mh_filter)(struct sock *sock, struct sk_buff *skb);
127 
128 int rawv6_mh_filter_register(int (*filter)(struct sock *sock,
129                                            struct sk_buff *skb))
130 {
131         rcu_assign_pointer(mh_filter, filter);
132         return 0;
133 }
134 EXPORT_SYMBOL(rawv6_mh_filter_register);
135 
136 int rawv6_mh_filter_unregister(int (*filter)(struct sock *sock,
137                                              struct sk_buff *skb))
138 {
139         rcu_assign_pointer(mh_filter, NULL);
140         synchronize_rcu();
141         return 0;
142 }
143 EXPORT_SYMBOL(rawv6_mh_filter_unregister);
144 
145 #endif
146 
147 /*
148  *      demultiplex raw sockets.
149  *      (should consider queueing the skb in the sock receive_queue
150  *      without calling rawv6.c)
151  *
152  *      Caller owns SKB so we must make clones.
153  */
154 static int ipv6_raw_deliver(struct sk_buff *skb, int nexthdr)
155 {
156         struct in6_addr *saddr;
157         struct in6_addr *daddr;
158         struct sock *sk;
159         int delivered = 0;
160         __u8 hash;
161         struct net *net;
162 
163         saddr = &ipv6_hdr(skb)->saddr;
164         daddr = saddr + 1;
165 
166         hash = nexthdr & (MAX_INET_PROTOS - 1);
167 
168         read_lock(&raw_v6_hashinfo.lock);
169         sk = sk_head(&raw_v6_hashinfo.ht[hash]);
170 
171         if (sk == NULL)
172                 goto out;
173 
174         net = dev_net(skb->dev);
175         sk = __raw_v6_lookup(net, sk, nexthdr, daddr, saddr, IP6CB(skb)->iif);
176 
177         while (sk) {
178                 int filtered;
179 
180                 delivered = 1;
181                 switch (nexthdr) {
182                 case IPPROTO_ICMPV6:
183                         filtered = icmpv6_filter(sk, skb);
184                         break;
185 
186 #if defined(CONFIG_IPV6_MIP6) || defined(CONFIG_IPV6_MIP6_MODULE)
187                 case IPPROTO_MH:
188                 {
189                         /* XXX: To validate MH only once for each packet,
190                          * this is placed here. It should be after checking
191                          * xfrm policy, however it doesn't. The checking xfrm
192                          * policy is placed in rawv6_rcv() because it is
193                          * required for each socket.
194                          */
195                         int (*filter)(struct sock *sock, struct sk_buff *skb);
196 
197                         filter = rcu_dereference(mh_filter);
198                         filtered = filter ? filter(sk, skb) : 0;
199                         break;
200                 }
201 #endif
202                 default:
203                         filtered = 0;
204                         break;
205                 }
206 
207                 if (filtered < 0)
208                         break;
209                 if (filtered == 0) {
210                         struct sk_buff *clone = skb_clone(skb, GFP_ATOMIC);
211 
212                         /* Not releasing hash table! */
213                         if (clone) {
214                                 nf_reset(clone);
215                                 rawv6_rcv(sk, clone);
216                         }
217                 }
218                 sk = __raw_v6_lookup(net, sk_next(sk), nexthdr, daddr, saddr,
219                                      IP6CB(skb)->iif);
220         }
221 out:
222         read_unlock(&raw_v6_hashinfo.lock);
223         return delivered;
224 }
225 
226 int raw6_local_deliver(struct sk_buff *skb, int nexthdr)
227 {
228         struct sock *raw_sk;
229 
230         raw_sk = sk_head(&raw_v6_hashinfo.ht[nexthdr & (MAX_INET_PROTOS - 1)]);
231         if (raw_sk && !ipv6_raw_deliver(skb, nexthdr))
232                 raw_sk = NULL;
233 
234         return raw_sk != NULL;
235 }
236 
237 /* This cleans up af_inet6 a bit. -DaveM */
238 static int rawv6_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len)
239 {
240         struct inet_sock *inet = inet_sk(sk);
241         struct ipv6_pinfo *np = inet6_sk(sk);
242         struct sockaddr_in6 *addr = (struct sockaddr_in6 *) uaddr;
243         __be32 v4addr = 0;
244         int addr_type;
245         int err;
246 
247         if (addr_len < SIN6_LEN_RFC2133)
248                 return -EINVAL;
249         addr_type = ipv6_addr_type(&addr->sin6_addr);
250 
251         /* Raw sockets are IPv6 only */
252         if (addr_type == IPV6_ADDR_MAPPED)
253                 return(-EADDRNOTAVAIL);
254 
255         lock_sock(sk);
256 
257         err = -EINVAL;
258         if (sk->sk_state != TCP_CLOSE)
259                 goto out;
260 
261         /* Check if the address belongs to the host. */
262         if (addr_type != IPV6_ADDR_ANY) {
263                 struct net_device *dev = NULL;
264 
265                 if (addr_type & IPV6_ADDR_LINKLOCAL) {
266                         if (addr_len >= sizeof(struct sockaddr_in6) &&
267                             addr->sin6_scope_id) {
268                                 /* Override any existing binding, if another
269                                  * one is supplied by user.
270                                  */
271                                 sk->sk_bound_dev_if = addr->sin6_scope_id;
272                         }
273 
274                         /* Binding to link-local address requires an interface */
275                         if (!sk->sk_bound_dev_if)
276                                 goto out;
277 
278                         dev = dev_get_by_index(sock_net(sk), sk->sk_bound_dev_if);
279                         if (!dev) {
280                                 err = -ENODEV;
281                                 goto out;
282                         }
283                 }
284 
285                 /* ipv4 addr of the socket is invalid.  Only the
286                  * unspecified and mapped address have a v4 equivalent.
287                  */
288                 v4addr = LOOPBACK4_IPV6;
289                 if (!(addr_type & IPV6_ADDR_MULTICAST)) {
290                         err = -EADDRNOTAVAIL;
291                         if (!ipv6_chk_addr(sock_net(sk), &addr->sin6_addr,
292                                            dev, 0)) {
293                                 if (dev)
294                                         dev_put(dev);
295                                 goto out;
296                         }
297                 }
298                 if (dev)
299                         dev_put(dev);
300         }
301 
302         inet->rcv_saddr = inet->saddr = v4addr;
303         ipv6_addr_copy(&np->rcv_saddr, &addr->sin6_addr);
304         if (!(addr_type & IPV6_ADDR_MULTICAST))
305                 ipv6_addr_copy(&np->saddr, &addr->sin6_addr);
306         err = 0;
307 out:
308         release_sock(sk);
309         return err;
310 }
311 
312 static void rawv6_err(struct sock *sk, struct sk_buff *skb,
313                struct inet6_skb_parm *opt,
314                u8 type, u8 code, int offset, __be32 info)
315 {
316         struct inet_sock *inet = inet_sk(sk);
317         struct ipv6_pinfo *np = inet6_sk(sk);
318         int err;
319         int harderr;
320 
321         /* Report error on raw socket, if:
322            1. User requested recverr.
323            2. Socket is connected (otherwise the error indication
324               is useless without recverr and error is hard.
325          */
326         if (!np->recverr && sk->sk_state != TCP_ESTABLISHED)
327                 return;
328 
329         harderr = icmpv6_err_convert(type, code, &err);
330         if (type == ICMPV6_PKT_TOOBIG)
331                 harderr = (np->pmtudisc == IPV6_PMTUDISC_DO);
332 
333         if (np->recverr) {
334                 u8 *payload = skb->data;
335                 if (!inet->hdrincl)
336                         payload += offset;
337                 ipv6_icmp_error(sk, skb, err, 0, ntohl(info), payload);
338         }
339 
340         if (np->recverr || harderr) {
341                 sk->sk_err = err;
342                 sk->sk_error_report(sk);
343         }
344 }
345 
346 void raw6_icmp_error(struct sk_buff *skb, int nexthdr,
347                 u8 type, u8 code, int inner_offset, __be32 info)
348 {
349         struct sock *sk;
350         int hash;
351         struct in6_addr *saddr, *daddr;
352         struct net *net;
353 
354         hash = nexthdr & (RAW_HTABLE_SIZE - 1);
355 
356         read_lock(&raw_v6_hashinfo.lock);
357         sk = sk_head(&raw_v6_hashinfo.ht[hash]);
358         if (sk != NULL) {
359                 /* Note: ipv6_hdr(skb) != skb->data */
360                 struct ipv6hdr *ip6h = (struct ipv6hdr *)skb->data;
361                 saddr = &ip6h->saddr;
362                 daddr = &ip6h->daddr;
363                 net = dev_net(skb->dev);
364 
365                 while ((sk = __raw_v6_lookup(net, sk, nexthdr, saddr, daddr,
366                                                 IP6CB(skb)->iif))) {
367                         rawv6_err(sk, skb, NULL, type, code,
368                                         inner_offset, info);
369                         sk = sk_next(sk);
370                 }
371         }
372         read_unlock(&raw_v6_hashinfo.lock);
373 }
374 
375 static inline int rawv6_rcv_skb(struct sock * sk, struct sk_buff * skb)
376 {
377         if ((raw6_sk(sk)->checksum || sk->sk_filter) &&
378             skb_checksum_complete(skb)) {
379                 atomic_inc(&sk->sk_drops);
380                 kfree_skb(skb);
381                 return NET_RX_DROP;
382         }
383 
384         /* Charge it to the socket. */
385         if (sock_queue_rcv_skb(sk,skb)<0) {
386                 atomic_inc(&sk->sk_drops);
387                 kfree_skb(skb);
388                 return NET_RX_DROP;
389         }
390 
391         return 0;
392 }
393 
394 /*
395  *      This is next to useless...
396  *      if we demultiplex in network layer we don't need the extra call
397  *      just to queue the skb...
398  *      maybe we could have the network decide upon a hint if it
399  *      should call raw_rcv for demultiplexing
400  */
401 int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
402 {
403         struct inet_sock *inet = inet_sk(sk);
404         struct raw6_sock *rp = raw6_sk(sk);
405 
406         if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
407                 atomic_inc(&sk->sk_drops);
408                 kfree_skb(skb);
409                 return NET_RX_DROP;
410         }
411 
412         if (!rp->checksum)
413                 skb->ip_summed = CHECKSUM_UNNECESSARY;
414 
415         if (skb->ip_summed == CHECKSUM_COMPLETE) {
416                 skb_postpull_rcsum(skb, skb_network_header(skb),
417                                    skb_network_header_len(skb));
418                 if (!csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
419                                      &ipv6_hdr(skb)->daddr,
420                                      skb->len, inet->num, skb->csum))
421                         skb->ip_summed = CHECKSUM_UNNECESSARY;
422         }
423         if (!skb_csum_unnecessary(skb))
424                 skb->csum = ~csum_unfold(csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
425                                                          &ipv6_hdr(skb)->daddr,
426                                                          skb->len,
427                                                          inet->num, 0));
428 
429         if (inet->hdrincl) {
430                 if (skb_checksum_complete(skb)) {
431                         atomic_inc(&sk->sk_drops);
432                         kfree_skb(skb);
433                         return NET_RX_DROP;
434                 }
435         }
436 
437         rawv6_rcv_skb(sk, skb);
438         return 0;
439 }
440 
441 
442 /*
443  *      This should be easy, if there is something there
444  *      we return it, otherwise we block.
445  */
446 
447 static int rawv6_recvmsg(struct kiocb *iocb, struct sock *sk,
448                   struct msghdr *msg, size_t len,
449                   int noblock, int flags, int *addr_len)
450 {
451         struct ipv6_pinfo *np = inet6_sk(sk);
452         struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)msg->msg_name;
453         struct sk_buff *skb;
454         size_t copied;
455         int err;
456 
457         if (flags & MSG_OOB)
458                 return -EOPNOTSUPP;
459 
460         if (flags & MSG_ERRQUEUE)
461                 return ipv6_recv_error(sk, msg, len, addr_len);
462 
463         skb = skb_recv_datagram(sk, flags, noblock, &err);
464         if (!skb)
465                 goto out;
466         if (ccs_socket_post_recvmsg_permission(sk, skb, flags)) {
467                 err = -EAGAIN; /* Hope less harmful than -EPERM. */
468                 goto out;
469         }
470 
471         copied = skb->len;
472         if (copied > len) {
473                 copied = len;
474                 msg->msg_flags |= MSG_TRUNC;
475         }
476 
477         if (skb_csum_unnecessary(skb)) {
478                 err = skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied);
479         } else if (msg->msg_flags&MSG_TRUNC) {
480                 if (__skb_checksum_complete(skb))
481                         goto csum_copy_err;
482                 err = skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied);
483         } else {
484                 err = skb_copy_and_csum_datagram_iovec(skb, 0, msg->msg_iov);
485                 if (err == -EINVAL)
486                         goto csum_copy_err;
487         }
488         if (err)
489                 goto out_free;
490 
491         /* Copy the address. */
492         if (sin6) {
493                 sin6->sin6_family = AF_INET6;
494                 sin6->sin6_port = 0;
495                 ipv6_addr_copy(&sin6->sin6_addr, &ipv6_hdr(skb)->saddr);
496                 sin6->sin6_flowinfo = 0;
497                 sin6->sin6_scope_id = 0;
498                 if (ipv6_addr_type(&sin6->sin6_addr) & IPV6_ADDR_LINKLOCAL)
499                         sin6->sin6_scope_id = IP6CB(skb)->iif;
500                 *addr_len = sizeof(*sin6);
501         }
502 
503         sock_recv_timestamp(msg, sk, skb);
504 
505         if (np->rxopt.all)
506                 datagram_recv_ctl(sk, msg, skb);
507 
508         err = copied;
509         if (flags & MSG_TRUNC)
510                 err = skb->len;
511 
512 out_free:
513         skb_free_datagram(sk, skb);
514 out:
515         return err;
516 
517 csum_copy_err:
518         skb_kill_datagram(sk, skb, flags);
519 
520         /* Error for blocking case is chosen to masquerade
521            as some normal condition.
522          */
523         err = (flags&MSG_DONTWAIT) ? -EAGAIN : -EHOSTUNREACH;
524         atomic_inc(&sk->sk_drops);
525         goto out;
526 }
527 
528 static int rawv6_push_pending_frames(struct sock *sk, struct flowi *fl,
529                                      struct raw6_sock *rp)
530 {
531         struct sk_buff *skb;
532         int err = 0;
533         int offset;
534         int len;
535         int total_len;
536         __wsum tmp_csum;
537         __sum16 csum;
538 
539         if (!rp->checksum)
540                 goto send;
541 
542         if ((skb = skb_peek(&sk->sk_write_queue)) == NULL)
543                 goto out;
544 
545         offset = rp->offset;
546         total_len = inet_sk(sk)->cork.length - (skb_network_header(skb) -
547                                                 skb->data);
548         if (offset >= total_len - 1) {
549                 err = -EINVAL;
550                 ip6_flush_pending_frames(sk);
551                 goto out;
552         }
553 
554         /* should be check HW csum miyazawa */
555         if (skb_queue_len(&sk->sk_write_queue) == 1) {
556                 /*
557                  * Only one fragment on the socket.
558                  */
559                 tmp_csum = skb->csum;
560         } else {
561                 struct sk_buff *csum_skb = NULL;
562                 tmp_csum = 0;
563 
564                 skb_queue_walk(&sk->sk_write_queue, skb) {
565                         tmp_csum = csum_add(tmp_csum, skb->csum);
566 
567                         if (csum_skb)
568                                 continue;
569 
570                         len = skb->len - skb_transport_offset(skb);
571                         if (offset >= len) {
572                                 offset -= len;
573                                 continue;
574                         }
575 
576                         csum_skb = skb;
577                 }
578 
579                 skb = csum_skb;
580         }
581 
582         offset += skb_transport_offset(skb);
583         if (skb_copy_bits(skb, offset, &csum, 2))
584                 BUG();
585 
586         /* in case cksum was not initialized */
587         if (unlikely(csum))
588                 tmp_csum = csum_sub(tmp_csum, csum_unfold(csum));
589 
590         csum = csum_ipv6_magic(&fl->fl6_src,
591                                    &fl->fl6_dst,
592                                    total_len, fl->proto, tmp_csum);
593 
594         if (csum == 0 && fl->proto == IPPROTO_UDP)
595                 csum = CSUM_MANGLED_0;
596 
597         if (skb_store_bits(skb, offset, &csum, 2))
598                 BUG();
599 
600 send:
601         err = ip6_push_pending_frames(sk);
602 out:
603         return err;
604 }
605 
606 static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
607                         struct flowi *fl, struct rt6_info *rt,
608                         unsigned int flags)
609 {
610         struct ipv6_pinfo *np = inet6_sk(sk);
611         struct ipv6hdr *iph;
612         struct sk_buff *skb;
613         int err;
614 
615         if (length > rt->u.dst.dev->mtu) {
616                 ipv6_local_error(sk, EMSGSIZE, fl, rt->u.dst.dev->mtu);
617                 return -EMSGSIZE;
618         }
619         if (flags&MSG_PROBE)
620                 goto out;
621 
622         skb = sock_alloc_send_skb(sk,
623                                   length + LL_ALLOCATED_SPACE(rt->u.dst.dev) + 15,
624                                   flags & MSG_DONTWAIT, &err);
625         if (skb == NULL)
626                 goto error;
627         skb_reserve(skb, LL_RESERVED_SPACE(rt->u.dst.dev));
628 
629         skb->priority = sk->sk_priority;
630         skb->mark = sk->sk_mark;
631         skb_dst_set(skb, dst_clone(&rt->u.dst));
632 
633         skb_put(skb, length);
634         skb_reset_network_header(skb);
635         iph = ipv6_hdr(skb);
636 
637         skb->ip_summed = CHECKSUM_NONE;
638 
639         skb->transport_header = skb->network_header;
640         err = memcpy_fromiovecend((void *)iph, from, 0, length);
641         if (err)
642                 goto error_fault;
643 
644         IP6_UPD_PO_STATS(sock_net(sk), rt->rt6i_idev, IPSTATS_MIB_OUT, skb->len);
645         err = NF_HOOK(PF_INET6, NF_INET_LOCAL_OUT, skb, NULL, rt->u.dst.dev,
646                       dst_output);
647         if (err > 0)
648                 err = net_xmit_errno(err);
649         if (err)
650                 goto error;
651 out:
652         return 0;
653 
654 error_fault:
655         err = -EFAULT;
656         kfree_skb(skb);
657 error:
658         IP6_INC_STATS(sock_net(sk), rt->rt6i_idev, IPSTATS_MIB_OUTDISCARDS);
659         if (err == -ENOBUFS && !np->recverr)
660                 err = 0;
661         return err;
662 }
663 
664 static int rawv6_probe_proto_opt(struct flowi *fl, struct msghdr *msg)
665 {
666         struct iovec *iov;
667         u8 __user *type = NULL;
668         u8 __user *code = NULL;
669         u8 len = 0;
670         int probed = 0;
671         int i;
672 
673         if (!msg->msg_iov)
674                 return 0;
675 
676         for (i = 0; i < msg->msg_iovlen; i++) {
677                 iov = &msg->msg_iov[i];
678                 if (!iov)
679                         continue;
680 
681                 switch (fl->proto) {
682                 case IPPROTO_ICMPV6:
683                         /* check if one-byte field is readable or not. */
684                         if (iov->iov_base && iov->iov_len < 1)
685                                 break;
686 
687                         if (!type) {
688                                 type = iov->iov_base;
689                                 /* check if code field is readable or not. */
690                                 if (iov->iov_len > 1)
691                                         code = type + 1;
692                         } else if (!code)
693                                 code = iov->iov_base;
694 
695                         if (type && code) {
696                                 if (get_user(fl->fl_icmp_type, type) ||
697                                     get_user(fl->fl_icmp_code, code))
698                                         return -EFAULT;
699                                 probed = 1;
700                         }
701                         break;
702                 case IPPROTO_MH:
703                         if (iov->iov_base && iov->iov_len < 1)
704                                 break;
705                         /* check if type field is readable or not. */
706                         if (iov->iov_len > 2 - len) {
707                                 u8 __user *p = iov->iov_base;
708                                 if (get_user(fl->fl_mh_type, &p[2 - len]))
709                                         return -EFAULT;
710                                 probed = 1;
711                         } else
712                                 len += iov->iov_len;
713 
714                         break;
715                 default:
716                         probed = 1;
717                         break;
718                 }
719                 if (probed)
720                         break;
721         }
722         return 0;
723 }
724 
725 static int rawv6_sendmsg(struct kiocb *iocb, struct sock *sk,
726                    struct msghdr *msg, size_t len)
727 {
728         struct ipv6_txoptions opt_space;
729         struct sockaddr_in6 * sin6 = (struct sockaddr_in6 *) msg->msg_name;
730         struct in6_addr *daddr, *final_p = NULL, final;
731         struct inet_sock *inet = inet_sk(sk);
732         struct ipv6_pinfo *np = inet6_sk(sk);
733         struct raw6_sock *rp = raw6_sk(sk);
734         struct ipv6_txoptions *opt = NULL;
735         struct ip6_flowlabel *flowlabel = NULL;
736         struct dst_entry *dst = NULL;
737         struct flowi fl;
738         int addr_len = msg->msg_namelen;
739         int hlimit = -1;
740         int tclass = -1;
741         u16 proto;
742         int err;
743 
744         /* Rough check on arithmetic overflow,
745            better check is made in ip6_append_data().
746          */
747         if (len > INT_MAX)
748                 return -EMSGSIZE;
749 
750         /* Mirror BSD error message compatibility */
751         if (msg->msg_flags & MSG_OOB)
752                 return -EOPNOTSUPP;
753 
754         /*
755          *      Get and verify the address.
756          */
757         memset(&fl, 0, sizeof(fl));
758 
759         fl.mark = sk->sk_mark;
760 
761         if (sin6) {
762                 if (addr_len < SIN6_LEN_RFC2133)
763                         return -EINVAL;
764 
765                 if (sin6->sin6_family && sin6->sin6_family != AF_INET6)
766                         return(-EAFNOSUPPORT);
767 
768                 /* port is the proto value [0..255] carried in nexthdr */
769                 proto = ntohs(sin6->sin6_port);
770 
771                 if (!proto)
772                         proto = inet->num;
773                 else if (proto != inet->num)
774                         return(-EINVAL);
775 
776                 if (proto > 255)
777                         return(-EINVAL);
778 
779                 daddr = &sin6->sin6_addr;
780                 if (np->sndflow) {
781                         fl.fl6_flowlabel = sin6->sin6_flowinfo&IPV6_FLOWINFO_MASK;
782                         if (fl.fl6_flowlabel&IPV6_FLOWLABEL_MASK) {
783                                 flowlabel = fl6_sock_lookup(sk, fl.fl6_flowlabel);
784                                 if (flowlabel == NULL)
785                                         return -EINVAL;
786                                 daddr = &flowlabel->dst;
787                         }
788                 }
789 
790                 /*
791                  * Otherwise it will be difficult to maintain
792                  * sk->sk_dst_cache.
793                  */
794                 if (sk->sk_state == TCP_ESTABLISHED &&
795                     ipv6_addr_equal(daddr, &np->daddr))
796                         daddr = &np->daddr;
797 
798                 if (addr_len >= sizeof(struct sockaddr_in6) &&
799                     sin6->sin6_scope_id &&
800                     ipv6_addr_type(daddr)&IPV6_ADDR_LINKLOCAL)
801                         fl.oif = sin6->sin6_scope_id;
802         } else {
803                 if (sk->sk_state != TCP_ESTABLISHED)
804                         return -EDESTADDRREQ;
805 
806                 proto = inet->num;
807                 daddr = &np->daddr;
808                 fl.fl6_flowlabel = np->flow_label;
809         }
810 
811         if (fl.oif == 0)
812                 fl.oif = sk->sk_bound_dev_if;
813 
814         if (msg->msg_controllen) {
815                 opt = &opt_space;
816                 memset(opt, 0, sizeof(struct ipv6_txoptions));
817                 opt->tot_len = sizeof(struct ipv6_txoptions);
818 
819                 err = datagram_send_ctl(sock_net(sk), msg, &fl, opt, &hlimit, &tclass);
820                 if (err < 0) {
821                         fl6_sock_release(flowlabel);
822                         return err;
823                 }
824                 if ((fl.fl6_flowlabel&IPV6_FLOWLABEL_MASK) && !flowlabel) {
825                         flowlabel = fl6_sock_lookup(sk, fl.fl6_flowlabel);
826                         if (flowlabel == NULL)
827                                 return -EINVAL;
828                 }
829                 if (!(opt->opt_nflen|opt->opt_flen))
830                         opt = NULL;
831         }
832         if (opt == NULL)
833                 opt = np->opt;
834         if (flowlabel)
835                 opt = fl6_merge_options(&opt_space, flowlabel, opt);
836         opt = ipv6_fixup_options(&opt_space, opt);
837 
838         fl.proto = proto;
839         err = rawv6_probe_proto_opt(&fl, msg);
840         if (err)
841                 goto out;
842 
843         if (!ipv6_addr_any(daddr))
844                 ipv6_addr_copy(&fl.fl6_dst, daddr);
845         else
846                 fl.fl6_dst.s6_addr[15] = 0x1; /* :: means loopback (BSD'ism) */
847         if (ipv6_addr_any(&fl.fl6_src) && !ipv6_addr_any(&np->saddr))
848                 ipv6_addr_copy(&fl.fl6_src, &np->saddr);
849 
850         /* merge ip6_build_xmit from ip6_output */
851         if (opt && opt->srcrt) {
852                 struct rt0_hdr *rt0 = (struct rt0_hdr *) opt->srcrt;
853                 ipv6_addr_copy(&final, &fl.fl6_dst);
854                 ipv6_addr_copy(&fl.fl6_dst, rt0->addr);
855                 final_p = &final;
856         }
857 
858         if (!fl.oif && ipv6_addr_is_multicast(&fl.fl6_dst))
859                 fl.oif = np->mcast_oif;
860         security_sk_classify_flow(sk, &fl);
861 
862         err = ip6_dst_lookup(sk, &dst, &fl);
863         if (err)
864                 goto out;
865         if (final_p)
866                 ipv6_addr_copy(&fl.fl6_dst, final_p);
867 
868         err = __xfrm_lookup(sock_net(sk), &dst, &fl, sk, XFRM_LOOKUP_WAIT);
869         if (err < 0) {
870                 if (err == -EREMOTE)
871                         err = ip6_dst_blackhole(sk, &dst, &fl);
872                 if (err < 0)
873                         goto out;
874         }
875 
876         if (hlimit < 0) {
877                 if (ipv6_addr_is_multicast(&fl.fl6_dst))
878                         hlimit = np->mcast_hops;
879                 else
880                         hlimit = np->hop_limit;
881                 if (hlimit < 0)
882                         hlimit = ip6_dst_hoplimit(dst);
883         }
884 
885         if (tclass < 0)
886                 tclass = np->tclass;
887 
888         if (msg->msg_flags&MSG_CONFIRM)
889                 goto do_confirm;
890 
891 back_from_confirm:
892         if (inet->hdrincl) {
893                 err = rawv6_send_hdrinc(sk, msg->msg_iov, len, &fl, (struct rt6_info*)dst, msg->msg_flags);
894         } else {
895                 lock_sock(sk);
896                 err = ip6_append_data(sk, ip_generic_getfrag, msg->msg_iov,
897                         len, 0, hlimit, tclass, opt, &fl, (struct rt6_info*)dst,
898                         msg->msg_flags);
899 
900                 if (err)
901                         ip6_flush_pending_frames(sk);
902                 else if (!(msg->msg_flags & MSG_MORE))
903                         err = rawv6_push_pending_frames(sk, &fl, rp);
904                 release_sock(sk);
905         }
906 done:
907         dst_release(dst);
908 out:
909         fl6_sock_release(flowlabel);
910         return err<0?err:len;
911 do_confirm:
912         dst_confirm(dst);
913         if (!(msg->msg_flags & MSG_PROBE) || len)
914                 goto back_from_confirm;
915         err = 0;
916         goto done;
917 }
918 
919 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
920                                char __user *optval, int optlen)
921 {
922         switch (optname) {
923         case ICMPV6_FILTER:
924                 if (optlen > sizeof(struct icmp6_filter))
925                         optlen = sizeof(struct icmp6_filter);
926                 if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
927                         return -EFAULT;
928                 return 0;
929         default:
930                 return -ENOPROTOOPT;
931         }
932 
933         return 0;
934 }
935 
936 static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
937                                char __user *optval, int __user *optlen)
938 {
939         int len;
940 
941         switch (optname) {
942         case ICMPV6_FILTER:
943                 if (get_user(len, optlen))
944                         return -EFAULT;
945                 if (len < 0)
946                         return -EINVAL;
947                 if (len > sizeof(struct icmp6_filter))
948                         len = sizeof(struct icmp6_filter);
949                 if (put_user(len, optlen))
950                         return -EFAULT;
951                 if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
952                         return -EFAULT;
953                 return 0;
954         default:
955                 return -ENOPROTOOPT;
956         }
957 
958         return 0;
959 }
960 
961 
962 static int do_rawv6_setsockopt(struct sock *sk, int level, int optname,
963                             char __user *optval, unsigned int optlen)
964 {
965         struct raw6_sock *rp = raw6_sk(sk);
966         int val;
967 
968         if (get_user(val, (int __user *)optval))
969                 return -EFAULT;
970 
971         switch (optname) {
972                 case IPV6_CHECKSUM:
973                         if (inet_sk(sk)->num == IPPROTO_ICMPV6 &&
974                             level == IPPROTO_IPV6) {
975                                 /*
976                                  * RFC3542 tells that IPV6_CHECKSUM socket
977                                  * option in the IPPROTO_IPV6 level is not
978                                  * allowed on ICMPv6 sockets.
979                                  * If you want to set it, use IPPROTO_RAW
980                                  * level IPV6_CHECKSUM socket option
981                                  * (Linux extension).
982                                  */
983                                 return -EINVAL;
984                         }
985 
986                         /* You may get strange result with a positive odd offset;
987                            RFC2292bis agrees with me. */
988                         if (val > 0 && (val&1))
989                                 return(-EINVAL);
990                         if (val < 0) {
991                                 rp->checksum = 0;
992                         } else {
993                                 rp->checksum = 1;
994                                 rp->offset = val;
995                         }
996 
997                         return 0;
998                         break;
999 
1000                 default:
1001                         return(-ENOPROTOOPT);
1002         }
1003 }
1004 
1005 static int rawv6_setsockopt(struct sock *sk, int level, int optname,
1006                           char __user *optval, unsigned int optlen)
1007 {
1008         switch(level) {
1009                 case SOL_RAW:
1010                         break;
1011 
1012                 case SOL_ICMPV6:
1013                         if (inet_sk(sk)->num != IPPROTO_ICMPV6)
1014                                 return -EOPNOTSUPP;
1015                         return rawv6_seticmpfilter(sk, level, optname, optval,
1016                                                    optlen);
1017                 case SOL_IPV6:
1018                         if (optname == IPV6_CHECKSUM)
1019                                 break;
1020                 default:
1021                         return ipv6_setsockopt(sk, level, optname, optval,
1022                                                optlen);
1023         }
1024 
1025         return do_rawv6_setsockopt(sk, level, optname, optval, optlen);
1026 }
1027 
1028 #ifdef CONFIG_COMPAT
1029 static int compat_rawv6_setsockopt(struct sock *sk, int level, int optname,
1030                                    char __user *optval, unsigned int optlen)
1031 {
1032         switch (level) {
1033         case SOL_RAW:
1034                 break;
1035         case SOL_ICMPV6:
1036                 if (inet_sk(sk)->num != IPPROTO_ICMPV6)
1037                         return -EOPNOTSUPP;
1038                 return rawv6_seticmpfilter(sk, level, optname, optval, optlen);
1039         case SOL_IPV6:
1040                 if (optname == IPV6_CHECKSUM)
1041                         break;
1042         default:
1043                 return compat_ipv6_setsockopt(sk, level, optname,
1044                                               optval, optlen);
1045         }
1046         return do_rawv6_setsockopt(sk, level, optname, optval, optlen);
1047 }
1048 #endif
1049 
1050 static int do_rawv6_getsockopt(struct sock *sk, int level, int optname,
1051                             char __user *optval, int __user *optlen)
1052 {
1053         struct raw6_sock *rp = raw6_sk(sk);
1054         int val, len;
1055 
1056         if (get_user(len,optlen))
1057                 return -EFAULT;
1058 
1059         switch (optname) {
1060         case IPV6_CHECKSUM:
1061                 /*
1062                  * We allow getsockopt() for IPPROTO_IPV6-level
1063                  * IPV6_CHECKSUM socket option on ICMPv6 sockets
1064                  * since RFC3542 is silent about it.
1065                  */
1066                 if (rp->checksum == 0)
1067                         val = -1;
1068                 else
1069                         val = rp->offset;
1070                 break;
1071 
1072         default:
1073                 return -ENOPROTOOPT;
1074         }
1075 
1076         len = min_t(unsigned int, sizeof(int), len);
1077 
1078         if (put_user(len, optlen))
1079                 return -EFAULT;
1080         if (copy_to_user(optval,&val,len))
1081                 return -EFAULT;
1082         return 0;
1083 }
1084 
1085 static int rawv6_getsockopt(struct sock *sk, int level, int optname,
1086                           char __user *optval, int __user *optlen)
1087 {
1088         switch(level) {
1089                 case SOL_RAW:
1090                         break;
1091 
1092                 case SOL_ICMPV6:
1093                         if (inet_sk(sk)->num != IPPROTO_ICMPV6)
1094                                 return -EOPNOTSUPP;
1095                         return rawv6_geticmpfilter(sk, level, optname, optval,
1096                                                    optlen);
1097                 case SOL_IPV6:
1098                         if (optname == IPV6_CHECKSUM)
1099                                 break;
1100                 default:
1101                         return ipv6_getsockopt(sk, level, optname, optval,
1102                                                optlen);
1103         }
1104 
1105         return do_rawv6_getsockopt(sk, level, optname, optval, optlen);
1106 }
1107 
1108 #ifdef CONFIG_COMPAT
1109 static int compat_rawv6_getsockopt(struct sock *sk, int level, int optname,
1110                                    char __user *optval, int __user *optlen)
1111 {
1112         switch (level) {
1113         case SOL_RAW:
1114                 break;
1115         case SOL_ICMPV6:
1116                 if (inet_sk(sk)->num != IPPROTO_ICMPV6)
1117                         return -EOPNOTSUPP;
1118                 return rawv6_geticmpfilter(sk, level, optname, optval, optlen);
1119         case SOL_IPV6:
1120                 if (optname == IPV6_CHECKSUM)
1121                         break;
1122         default:
1123                 return compat_ipv6_getsockopt(sk, level, optname,
1124                                               optval, optlen);
1125         }
1126         return do_rawv6_getsockopt(sk, level, optname, optval, optlen);
1127 }
1128 #endif
1129 
1130 static int rawv6_ioctl(struct sock *sk, int cmd, unsigned long arg)
1131 {
1132         switch(cmd) {
1133                 case SIOCOUTQ:
1134                 {
1135                         int amount = sk_wmem_alloc_get(sk);
1136 
1137                         return put_user(amount, (int __user *)arg);
1138                 }
1139                 case SIOCINQ:
1140                 {
1141                         struct sk_buff *skb;
1142                         int amount = 0;
1143 
1144                         spin_lock_bh(&sk->sk_receive_queue.lock);
1145                         skb = skb_peek(&sk->sk_receive_queue);
1146                         if (skb != NULL)
1147                                 amount = skb->tail - skb->transport_header;
1148                         spin_unlock_bh(&sk->sk_receive_queue.lock);
1149                         return put_user(amount, (int __user *)arg);
1150                 }
1151 
1152                 default:
1153 #ifdef CONFIG_IPV6_MROUTE
1154                         return ip6mr_ioctl(sk, cmd, (void __user *)arg);
1155 #else
1156                         return -ENOIOCTLCMD;
1157 #endif
1158         }
1159 }
1160 
1161 static void rawv6_close(struct sock *sk, long timeout)
1162 {
1163         if (inet_sk(sk)->num == IPPROTO_RAW)
1164                 ip6_ra_control(sk, -1);
1165         ip6mr_sk_done(sk);
1166         sk_common_release(sk);
1167 }
1168 
1169 static void raw6_destroy(struct sock *sk)
1170 {
1171         lock_sock(sk);
1172         ip6_flush_pending_frames(sk);
1173         release_sock(sk);
1174 
1175         inet6_destroy_sock(sk);
1176 }
1177 
1178 static int rawv6_init_sk(struct sock *sk)
1179 {
1180         struct raw6_sock *rp = raw6_sk(sk);
1181 
1182         switch (inet_sk(sk)->num) {
1183         case IPPROTO_ICMPV6:
1184                 rp->checksum = 1;
1185                 rp->offset   = 2;
1186                 break;
1187         case IPPROTO_MH:
1188                 rp->checksum = 1;
1189                 rp->offset   = 4;
1190                 break;
1191         default:
1192                 break;
1193         }
1194         return(0);
1195 }
1196 
1197 struct proto rawv6_prot = {
1198         .name              = "RAWv6",
1199         .owner             = THIS_MODULE,
1200         .close             = rawv6_close,
1201         .destroy           = raw6_destroy,
1202         .connect           = ip6_datagram_connect,
1203         .disconnect        = udp_disconnect,
1204         .ioctl             = rawv6_ioctl,
1205         .init              = rawv6_init_sk,
1206         .setsockopt        = rawv6_setsockopt,
1207         .getsockopt        = rawv6_getsockopt,
1208         .sendmsg           = rawv6_sendmsg,
1209         .recvmsg           = rawv6_recvmsg,
1210         .bind              = rawv6_bind,
1211         .backlog_rcv       = rawv6_rcv_skb,
1212         .hash              = raw_hash_sk,
1213         .unhash            = raw_unhash_sk,
1214         .obj_size          = sizeof(struct raw6_sock),
1215         .h.raw_hash        = &raw_v6_hashinfo,
1216 #ifdef CONFIG_COMPAT
1217         .compat_setsockopt = compat_rawv6_setsockopt,
1218         .compat_getsockopt = compat_rawv6_getsockopt,
1219 #endif
1220 };
1221 
1222 #ifdef CONFIG_PROC_FS
1223 static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
1224 {
1225         struct ipv6_pinfo *np = inet6_sk(sp);
1226         struct in6_addr *dest, *src;
1227         __u16 destp, srcp;
1228 
1229         dest  = &np->daddr;
1230         src   = &np->rcv_saddr;
1231         destp = 0;
1232         srcp  = inet_sk(sp)->num;
1233         seq_printf(seq,
1234                    "%4d: %08X%08X%08X%08X:%04X %08X%08X%08X%08X:%04X "
1235                    "%02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p %d\n",
1236                    i,
1237                    src->s6_addr32[0], src->s6_addr32[1],
1238                    src->s6_addr32[2], src->s6_addr32[3], srcp,
1239                    dest->s6_addr32[0], dest->s6_addr32[1],
1240                    dest->s6_addr32[2], dest->s6_addr32[3], destp,
1241                    sp->sk_state,
1242                    sk_wmem_alloc_get(sp),
1243                    sk_rmem_alloc_get(sp),
1244                    0, 0L, 0,
1245                    sock_i_uid(sp), 0,
1246                    sock_i_ino(sp),
1247                    atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
1248 }
1249 
1250 static int raw6_seq_show(struct seq_file *seq, void *v)
1251 {
1252         if (v == SEQ_START_TOKEN)
1253                 seq_printf(seq,
1254                            "  sl  "
1255                            "local_address                         "
1256                            "remote_address                        "
1257                            "st tx_queue rx_queue tr tm->when retrnsmt"
1258                            "   uid  timeout inode ref pointer drops\n");
1259         else
1260                 raw6_sock_seq_show(seq, v, raw_seq_private(seq)->bucket);
1261         return 0;
1262 }
1263 
1264 static const struct seq_operations raw6_seq_ops = {
1265         .start =        raw_seq_start,
1266         .next =         raw_seq_next,
1267         .stop =         raw_seq_stop,
1268         .show =         raw6_seq_show,
1269 };
1270 
1271 static int raw6_seq_open(struct inode *inode, struct file *file)
1272 {
1273         return raw_seq_open(inode, file, &raw_v6_hashinfo, &raw6_seq_ops);
1274 }
1275 
1276 static const struct file_operations raw6_seq_fops = {
1277         .owner =        THIS_MODULE,
1278         .open =         raw6_seq_open,
1279         .read =         seq_read,
1280         .llseek =       seq_lseek,
1281         .release =      seq_release_net,
1282 };
1283 
1284 static int raw6_init_net(struct net *net)
1285 {
1286         if (!proc_net_fops_create(net, "raw6", S_IRUGO, &raw6_seq_fops))
1287                 return -ENOMEM;
1288 
1289         return 0;
1290 }
1291 
1292 static void raw6_exit_net(struct net *net)
1293 {
1294         proc_net_remove(net, "raw6");
1295 }
1296 
1297 static struct pernet_operations raw6_net_ops = {
1298         .init = raw6_init_net,
1299         .exit = raw6_exit_net,
1300 };
1301 
1302 int __init raw6_proc_init(void)
1303 {
1304         return register_pernet_subsys(&raw6_net_ops);
1305 }
1306 
1307 void raw6_proc_exit(void)
1308 {
1309         unregister_pernet_subsys(&raw6_net_ops);
1310 }
1311 #endif  /* CONFIG_PROC_FS */
1312 
1313 /* Same as inet6_dgram_ops, sans udp_poll.  */
1314 static const struct proto_ops inet6_sockraw_ops = {
1315         .family            = PF_INET6,
1316         .owner             = THIS_MODULE,
1317         .release           = inet6_release,
1318         .bind              = inet6_bind,
1319         .connect           = inet_dgram_connect,        /* ok           */
1320         .socketpair        = sock_no_socketpair,        /* a do nothing */
1321         .accept            = sock_no_accept,            /* a do nothing */
1322         .getname           = inet6_getname,
1323         .poll              = datagram_poll,             /* ok           */
1324         .ioctl             = inet6_ioctl,               /* must change  */
1325         .listen            = sock_no_listen,            /* ok           */
1326         .shutdown          = inet_shutdown,             /* ok           */
1327         .setsockopt        = sock_common_setsockopt,    /* ok           */
1328         .getsockopt        = sock_common_getsockopt,    /* ok           */
1329         .sendmsg           = inet_sendmsg,              /* ok           */
1330         .recvmsg           = sock_common_recvmsg,       /* ok           */
1331         .mmap              = sock_no_mmap,
1332         .sendpage          = sock_no_sendpage,
1333 #ifdef CONFIG_COMPAT
1334         .compat_setsockopt = compat_sock_common_setsockopt,
1335         .compat_getsockopt = compat_sock_common_getsockopt,
1336 #endif
1337 };
1338 
1339 static struct inet_protosw rawv6_protosw = {
1340         .type           = SOCK_RAW,
1341         .protocol       = IPPROTO_IP,   /* wild card */
1342         .prot           = &rawv6_prot,
1343         .ops            = &inet6_sockraw_ops,
1344         .capability     = CAP_NET_RAW,
1345         .no_check       = UDP_CSUM_DEFAULT,
1346         .flags          = INET_PROTOSW_REUSE,
1347 };
1348 
1349 int __init rawv6_init(void)
1350 {
1351         int ret;
1352 
1353         ret = inet6_register_protosw(&rawv6_protosw);
1354         if (ret)
1355                 goto out;
1356 out:
1357         return ret;
1358 }
1359 
1360 void rawv6_exit(void)
1361 {
1362         inet6_unregister_protosw(&rawv6_protosw);
1363 }
1364 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp