raw.c (db6da59cf27b5661ced03754ae0550f8914eda9e) | raw.c (e1d001fa5b477c4da46a29be1fcece91db7c7c6f) |
---|---|
1// SPDX-License-Identifier: GPL-2.0-or-later 2/* 3 * INET An implementation of the TCP/IP protocol suite for the LINUX 4 * operating system. INET is implemented using the BSD Socket 5 * interface as the means of communication with the user level. 6 * 7 * RAW - implementation of IP "raw" sockets. 8 * --- 462 unchanged lines hidden (view full) --- 471 472static int raw_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) 473{ 474 struct inet_sock *inet = inet_sk(sk); 475 struct net *net = sock_net(sk); 476 struct ipcm_cookie ipc; 477 struct rtable *rt = NULL; 478 struct flowi4 fl4; | 1// SPDX-License-Identifier: GPL-2.0-or-later 2/* 3 * INET An implementation of the TCP/IP protocol suite for the LINUX 4 * operating system. INET is implemented using the BSD Socket 5 * interface as the means of communication with the user level. 6 * 7 * RAW - implementation of IP "raw" sockets. 8 * --- 462 unchanged lines hidden (view full) --- 471 472static int raw_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) 473{ 474 struct inet_sock *inet = inet_sk(sk); 475 struct net *net = sock_net(sk); 476 struct ipcm_cookie ipc; 477 struct rtable *rt = NULL; 478 struct flowi4 fl4; |
479 u8 tos, scope; |
|
479 int free = 0; 480 __be32 daddr; 481 __be32 saddr; | 480 int free = 0; 481 __be32 daddr; 482 __be32 saddr; |
482 u8 tos; | |
483 int err; 484 struct ip_options_data opt_copy; 485 struct raw_frag_vec rfv; 486 int hdrincl; 487 488 err = -EMSGSIZE; 489 if (len > 0xFFFF) 490 goto out; --- 36 unchanged lines hidden (view full) --- 527 } else { 528 err = -EDESTADDRREQ; 529 if (sk->sk_state != TCP_ESTABLISHED) 530 goto out; 531 daddr = inet->inet_daddr; 532 } 533 534 ipcm_init_sk(&ipc, inet); | 483 int err; 484 struct ip_options_data opt_copy; 485 struct raw_frag_vec rfv; 486 int hdrincl; 487 488 err = -EMSGSIZE; 489 if (len > 0xFFFF) 490 goto out; --- 36 unchanged lines hidden (view full) --- 527 } else { 528 err = -EDESTADDRREQ; 529 if (sk->sk_state != TCP_ESTABLISHED) 530 goto out; 531 daddr = inet->inet_daddr; 532 } 533 534 ipcm_init_sk(&ipc, inet); |
535 /* Keep backward compat */ 536 if (hdrincl) 537 ipc.protocol = IPPROTO_RAW; |
|
535 536 if (msg->msg_controllen) { 537 err = ip_cmsg_send(sk, msg, &ipc, false); 538 if (unlikely(err)) { 539 kfree(ipc.opt); 540 goto out; 541 } 542 if (ipc.opt) --- 24 unchanged lines hidden (view full) --- 567 if (hdrincl) 568 goto done; 569 if (ipc.opt->opt.srr) { 570 if (!daddr) 571 goto done; 572 daddr = ipc.opt->opt.faddr; 573 } 574 } | 538 539 if (msg->msg_controllen) { 540 err = ip_cmsg_send(sk, msg, &ipc, false); 541 if (unlikely(err)) { 542 kfree(ipc.opt); 543 goto out; 544 } 545 if (ipc.opt) --- 24 unchanged lines hidden (view full) --- 570 if (hdrincl) 571 goto done; 572 if (ipc.opt->opt.srr) { 573 if (!daddr) 574 goto done; 575 daddr = ipc.opt->opt.faddr; 576 } 577 } |
575 tos = get_rtconn_flags(&ipc, sk); 576 if (msg->msg_flags & MSG_DONTROUTE) 577 tos |= RTO_ONLINK; | 578 tos = get_rttos(&ipc, inet); 579 scope = ip_sendmsg_scope(inet, &ipc, msg); |
578 579 if (ipv4_is_multicast(daddr)) { 580 if (!ipc.oif || netif_index_is_l3_master(sock_net(sk), ipc.oif)) 581 ipc.oif = inet->mc_index; 582 if (!saddr) 583 saddr = inet->mc_addr; 584 } else if (!ipc.oif) { 585 ipc.oif = inet->uc_index; --- 6 unchanged lines hidden (view full) --- 592 */ 593 if (ipc.oif != inet->uc_index && 594 ipc.oif == l3mdev_master_ifindex_by_index(sock_net(sk), 595 inet->uc_index)) { 596 ipc.oif = inet->uc_index; 597 } 598 } 599 | 580 581 if (ipv4_is_multicast(daddr)) { 582 if (!ipc.oif || netif_index_is_l3_master(sock_net(sk), ipc.oif)) 583 ipc.oif = inet->mc_index; 584 if (!saddr) 585 saddr = inet->mc_addr; 586 } else if (!ipc.oif) { 587 ipc.oif = inet->uc_index; --- 6 unchanged lines hidden (view full) --- 594 */ 595 if (ipc.oif != inet->uc_index && 596 ipc.oif == l3mdev_master_ifindex_by_index(sock_net(sk), 597 inet->uc_index)) { 598 ipc.oif = inet->uc_index; 599 } 600 } 601 |
600 flowi4_init_output(&fl4, ipc.oif, ipc.sockc.mark, tos, 601 RT_SCOPE_UNIVERSE, 602 hdrincl ? IPPROTO_RAW : sk->sk_protocol, | 602 flowi4_init_output(&fl4, ipc.oif, ipc.sockc.mark, tos, scope, 603 hdrincl ? ipc.protocol : sk->sk_protocol, |
603 inet_sk_flowi_flags(sk) | 604 (hdrincl ? FLOWI_FLAG_KNOWN_NH : 0), 605 daddr, saddr, 0, 0, sk->sk_uid); 606 607 if (!hdrincl) { 608 rfv.msg = msg; 609 rfv.hlen = 0; 610 --- 239 unchanged lines hidden (view full) --- 850static int raw_getsockopt(struct sock *sk, int level, int optname, 851 char __user *optval, int __user *optlen) 852{ 853 if (level != SOL_RAW) 854 return ip_getsockopt(sk, level, optname, optval, optlen); 855 return do_raw_getsockopt(sk, level, optname, optval, optlen); 856} 857 | 604 inet_sk_flowi_flags(sk) | 605 (hdrincl ? FLOWI_FLAG_KNOWN_NH : 0), 606 daddr, saddr, 0, 0, sk->sk_uid); 607 608 if (!hdrincl) { 609 rfv.msg = msg; 610 rfv.hlen = 0; 611 --- 239 unchanged lines hidden (view full) --- 851static int raw_getsockopt(struct sock *sk, int level, int optname, 852 char __user *optval, int __user *optlen) 853{ 854 if (level != SOL_RAW) 855 return ip_getsockopt(sk, level, optname, optval, optlen); 856 return do_raw_getsockopt(sk, level, optname, optval, optlen); 857} 858 |
858static int raw_ioctl(struct sock *sk, int cmd, unsigned long arg) | 859static int raw_ioctl(struct sock *sk, int cmd, int *karg) |
859{ 860 switch (cmd) { 861 case SIOCOUTQ: { | 860{ 861 switch (cmd) { 862 case SIOCOUTQ: { |
862 int amount = sk_wmem_alloc_get(sk); 863 864 return put_user(amount, (int __user *)arg); | 863 *karg = sk_wmem_alloc_get(sk); 864 return 0; |
865 } 866 case SIOCINQ: { 867 struct sk_buff *skb; | 865 } 866 case SIOCINQ: { 867 struct sk_buff *skb; |
868 int amount = 0; | |
869 870 spin_lock_bh(&sk->sk_receive_queue.lock); 871 skb = skb_peek(&sk->sk_receive_queue); 872 if (skb) | 868 869 spin_lock_bh(&sk->sk_receive_queue.lock); 870 skb = skb_peek(&sk->sk_receive_queue); 871 if (skb) |
873 amount = skb->len; | 872 *karg = skb->len; 873 else 874 *karg = 0; |
874 spin_unlock_bh(&sk->sk_receive_queue.lock); | 875 spin_unlock_bh(&sk->sk_receive_queue.lock); |
875 return put_user(amount, (int __user *)arg); | 876 return 0; |
876 } 877 878 default: 879#ifdef CONFIG_IP_MROUTE | 877 } 878 879 default: 880#ifdef CONFIG_IP_MROUTE |
880 return ipmr_ioctl(sk, cmd, (void __user *)arg); | 881 return ipmr_ioctl(sk, cmd, karg); |
881#else 882 return -ENOIOCTLCMD; 883#endif 884 } 885} 886 887#ifdef CONFIG_COMPAT 888static int compat_raw_ioctl(struct sock *sk, unsigned int cmd, unsigned long arg) --- 223 unchanged lines hidden --- | 882#else 883 return -ENOIOCTLCMD; 884#endif 885 } 886} 887 888#ifdef CONFIG_COMPAT 889static int compat_raw_ioctl(struct sock *sk, unsigned int cmd, unsigned long arg) --- 223 unchanged lines hidden --- |