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

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

Version: ~ [ linux-6.3-rc3 ] ~ [ linux-6.2.7 ] ~ [ linux-6.1.20 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.103 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.175 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.237 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.278 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.310 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.302 ] ~ [ 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.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

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

~ [ 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