^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * INET An implementation of the TCP/IP protocol suite for the LINUX
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * operating system. INET is implemented using the BSD Socket
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * interface as the means of communication with the user level.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * RAW - implementation of IP "raw" sockets.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * Authors: Ross Biro
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * Fixes:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * Alan Cox : verify_area() fixed up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * Alan Cox : ICMP error handling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * Alan Cox : EMSGSIZE if you send too big a packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * Alan Cox : Now uses generic datagrams and shared
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * skbuff library. No more peek crashes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * no more backlogs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * Alan Cox : Checks sk->broadcast.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * Alan Cox : Uses skb_free_datagram/skb_copy_datagram
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * Alan Cox : Raw passes ip options too
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * Alan Cox : Setsocketopt added
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * Alan Cox : Fixed error return for broadcasts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * Alan Cox : Removed wake_up calls
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * Alan Cox : Use ttl/tos
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * Alan Cox : Cleaned up old debugging
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * Alan Cox : Use new kernel side addresses
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * Arnt Gulbrandsen : Fixed MSG_DONTROUTE in raw sockets.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) * Alan Cox : BSD style RAW socket demultiplexing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * Alan Cox : Beginnings of mrouted support.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) * Alan Cox : Added IP_HDRINCL option.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) * Alan Cox : Skip broadcast check if BSDism set.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) * David S. Miller : New socket lookup architecture.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #include <linux/atomic.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #include <asm/byteorder.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #include <asm/current.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #include <asm/ioctls.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #include <linux/stddef.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) #include <linux/sockios.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) #include <linux/socket.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) #include <linux/in.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) #include <linux/mroute.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) #include <linux/in_route.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) #include <linux/route.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) #include <linux/skbuff.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) #include <linux/igmp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) #include <net/net_namespace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) #include <net/dst.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) #include <net/sock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) #include <linux/ip.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) #include <linux/net.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) #include <net/ip.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) #include <net/icmp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) #include <net/udp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) #include <net/raw.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) #include <net/snmp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) #include <net/tcp_states.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) #include <net/inet_common.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) #include <net/checksum.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) #include <net/xfrm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) #include <linux/rtnetlink.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) #include <linux/proc_fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) #include <linux/seq_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) #include <linux/netfilter.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) #include <linux/netfilter_ipv4.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) #include <linux/compat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) #include <linux/uio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) struct raw_frag_vec {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) struct msghdr *msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) union {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) struct icmphdr icmph;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) char c[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) } hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) int hlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) struct raw_hashinfo raw_v4_hashinfo = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) .lock = __RW_LOCK_UNLOCKED(raw_v4_hashinfo.lock),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) EXPORT_SYMBOL_GPL(raw_v4_hashinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) int raw_hash_sk(struct sock *sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) struct raw_hashinfo *h = sk->sk_prot->h.raw_hash;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) struct hlist_head *head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) head = &h->ht[inet_sk(sk)->inet_num & (RAW_HTABLE_SIZE - 1)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) write_lock_bh(&h->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) sk_add_node(sk, head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) write_unlock_bh(&h->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) EXPORT_SYMBOL_GPL(raw_hash_sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) void raw_unhash_sk(struct sock *sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) struct raw_hashinfo *h = sk->sk_prot->h.raw_hash;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) write_lock_bh(&h->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) if (sk_del_node_init(sk))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) sock_prot_inuse_add(sock_net(sk), sk->sk_prot, -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) write_unlock_bh(&h->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) EXPORT_SYMBOL_GPL(raw_unhash_sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) struct sock *__raw_v4_lookup(struct net *net, struct sock *sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) unsigned short num, __be32 raddr, __be32 laddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) int dif, int sdif)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) sk_for_each_from(sk) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) struct inet_sock *inet = inet_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) if (net_eq(sock_net(sk), net) && inet->inet_num == num &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) !(inet->inet_daddr && inet->inet_daddr != raddr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) !(inet->inet_rcv_saddr && inet->inet_rcv_saddr != laddr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) raw_sk_bound_dev_eq(net, sk->sk_bound_dev_if, dif, sdif))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) goto found; /* gotcha */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) sk = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) found:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) return sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) EXPORT_SYMBOL_GPL(__raw_v4_lookup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) * 0 - deliver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) * 1 - block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) static int icmp_filter(const struct sock *sk, const struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) struct icmphdr _hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) const struct icmphdr *hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) hdr = skb_header_pointer(skb, skb_transport_offset(skb),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) sizeof(_hdr), &_hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) if (!hdr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) if (hdr->type < 32) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) __u32 data = raw_sk(sk)->filter.data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) return ((1U << hdr->type) & data) != 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) /* Do not block unknown ICMP types */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) /* IP input processing comes here for RAW socket delivery.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) * Caller owns SKB, so we must make clones.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) * RFC 1122: SHOULD pass TOS value up to the transport layer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) * -> It does. And not only TOS, but all IP header.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) static int raw_v4_input(struct sk_buff *skb, const struct iphdr *iph, int hash)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) int sdif = inet_sdif(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) int dif = inet_iif(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) struct sock *sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) struct hlist_head *head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) int delivered = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) struct net *net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) read_lock(&raw_v4_hashinfo.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) head = &raw_v4_hashinfo.ht[hash];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) if (hlist_empty(head))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) net = dev_net(skb->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) sk = __raw_v4_lookup(net, __sk_head(head), iph->protocol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) iph->saddr, iph->daddr, dif, sdif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) while (sk) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) delivered = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) if ((iph->protocol != IPPROTO_ICMP || !icmp_filter(sk, skb)) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) ip_mc_sf_allow(sk, iph->daddr, iph->saddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) skb->dev->ifindex, sdif)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) struct sk_buff *clone = skb_clone(skb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) /* Not releasing hash table! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) if (clone)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) raw_rcv(sk, clone);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) sk = __raw_v4_lookup(net, sk_next(sk), iph->protocol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) iph->saddr, iph->daddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) dif, sdif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) read_unlock(&raw_v4_hashinfo.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) return delivered;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) int raw_local_deliver(struct sk_buff *skb, int protocol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) int hash;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) struct sock *raw_sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) hash = protocol & (RAW_HTABLE_SIZE - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) raw_sk = sk_head(&raw_v4_hashinfo.ht[hash]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) /* If there maybe a raw socket we must check - if not we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) * don't care less
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) if (raw_sk && !raw_v4_input(skb, ip_hdr(skb), hash))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) raw_sk = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) return raw_sk != NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) static void raw_err(struct sock *sk, struct sk_buff *skb, u32 info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) struct inet_sock *inet = inet_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) const int type = icmp_hdr(skb)->type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) const int code = icmp_hdr(skb)->code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) int harderr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) if (type == ICMP_DEST_UNREACH && code == ICMP_FRAG_NEEDED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) ipv4_sk_update_pmtu(skb, sk, info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) else if (type == ICMP_REDIRECT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) ipv4_sk_redirect(skb, sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) /* Report error on raw socket, if:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 1. User requested ip_recverr.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 2. Socket is connected (otherwise the error indication
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) is useless without ip_recverr and error is hard.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) if (!inet->recverr && sk->sk_state != TCP_ESTABLISHED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) switch (type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) case ICMP_TIME_EXCEEDED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) err = EHOSTUNREACH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) case ICMP_SOURCE_QUENCH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) case ICMP_PARAMETERPROB:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) err = EPROTO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) harderr = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) case ICMP_DEST_UNREACH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) err = EHOSTUNREACH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) if (code > NR_ICMP_UNREACH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) if (code == ICMP_FRAG_NEEDED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) harderr = inet->pmtudisc != IP_PMTUDISC_DONT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) err = EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) err = icmp_err_convert[code].errno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) harderr = icmp_err_convert[code].fatal;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) if (inet->recverr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) const struct iphdr *iph = (const struct iphdr *)skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) u8 *payload = skb->data + (iph->ihl << 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) if (inet->hdrincl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) payload = skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) ip_icmp_error(sk, skb, err, 0, info, payload);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) if (inet->recverr || harderr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) sk->sk_err = err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) sk->sk_error_report(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) void raw_icmp_error(struct sk_buff *skb, int protocol, u32 info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) int hash;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) struct sock *raw_sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) const struct iphdr *iph;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) struct net *net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) hash = protocol & (RAW_HTABLE_SIZE - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) read_lock(&raw_v4_hashinfo.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) raw_sk = sk_head(&raw_v4_hashinfo.ht[hash]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) if (raw_sk) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) int dif = skb->dev->ifindex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) int sdif = inet_sdif(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) iph = (const struct iphdr *)skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) net = dev_net(skb->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) while ((raw_sk = __raw_v4_lookup(net, raw_sk, protocol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) iph->daddr, iph->saddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) dif, sdif)) != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) raw_err(raw_sk, skb, info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) raw_sk = sk_next(raw_sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) iph = (const struct iphdr *)skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) read_unlock(&raw_v4_hashinfo.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) /* Charge it to the socket. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) ipv4_pktinfo_prepare(sk, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) if (sock_queue_rcv_skb(sk, skb) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) return NET_RX_DROP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) return NET_RX_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) int raw_rcv(struct sock *sk, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) atomic_inc(&sk->sk_drops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) return NET_RX_DROP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) nf_reset_ct(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) skb_push(skb, skb->data - skb_network_header(skb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) raw_rcv_skb(sk, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) static int raw_send_hdrinc(struct sock *sk, struct flowi4 *fl4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) struct msghdr *msg, size_t length,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) struct rtable **rtp, unsigned int flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) const struct sockcm_cookie *sockc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) struct inet_sock *inet = inet_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) struct net *net = sock_net(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) struct iphdr *iph;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) unsigned int iphlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) struct rtable *rt = *rtp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) int hlen, tlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) if (length > rt->dst.dev->mtu) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) ip_local_error(sk, EMSGSIZE, fl4->daddr, inet->inet_dport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) rt->dst.dev->mtu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) return -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) if (length < sizeof(struct iphdr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) if (flags&MSG_PROBE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) hlen = LL_RESERVED_SPACE(rt->dst.dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) tlen = rt->dst.dev->needed_tailroom;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) skb = sock_alloc_send_skb(sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) length + hlen + tlen + 15,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) flags & MSG_DONTWAIT, &err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) skb_reserve(skb, hlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) skb->priority = sk->sk_priority;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) skb->mark = sockc->mark;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) skb->tstamp = sockc->transmit_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) skb_dst_set(skb, &rt->dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) *rtp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) skb_reset_network_header(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) iph = ip_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) skb_put(skb, length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) skb->ip_summed = CHECKSUM_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) skb_setup_tx_timestamp(skb, sockc->tsflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) if (flags & MSG_CONFIRM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) skb_set_dst_pending_confirm(skb, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) skb->transport_header = skb->network_header;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) err = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) if (memcpy_from_msg(iph, msg, length))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) goto error_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) iphlen = iph->ihl * 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) * We don't want to modify the ip header, but we do need to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) * be sure that it won't cause problems later along the network
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) * stack. Specifically we want to make sure that iph->ihl is a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) * sane value. If ihl points beyond the length of the buffer passed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) * in, reject the frame as invalid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) if (iphlen > length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) goto error_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) if (iphlen >= sizeof(*iph)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) if (!iph->saddr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) iph->saddr = fl4->saddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) iph->check = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) iph->tot_len = htons(length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) if (!iph->id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) ip_select_ident(net, skb, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) iph->check = ip_fast_csum((unsigned char *)iph, iph->ihl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) skb->transport_header += iphlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) if (iph->protocol == IPPROTO_ICMP &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) length >= iphlen + sizeof(struct icmphdr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) icmp_out_count(net, ((struct icmphdr *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) skb_transport_header(skb))->type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) err = NF_HOOK(NFPROTO_IPV4, NF_INET_LOCAL_OUT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) net, sk, skb, NULL, rt->dst.dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) dst_output);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) if (err > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) err = net_xmit_errno(err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) error_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) IP_INC_STATS(net, IPSTATS_MIB_OUTDISCARDS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) if (err == -ENOBUFS && !inet->recverr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) static int raw_probe_proto_opt(struct raw_frag_vec *rfv, struct flowi4 *fl4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) if (fl4->flowi4_proto != IPPROTO_ICMP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) /* We only need the first two bytes. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) rfv->hlen = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) err = memcpy_from_msg(rfv->hdr.c, rfv->msg, rfv->hlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) fl4->fl4_icmp_type = rfv->hdr.icmph.type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) fl4->fl4_icmp_code = rfv->hdr.icmph.code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) static int raw_getfrag(void *from, char *to, int offset, int len, int odd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) struct raw_frag_vec *rfv = from;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) if (offset < rfv->hlen) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) int copy = min(rfv->hlen - offset, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) if (skb->ip_summed == CHECKSUM_PARTIAL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) memcpy(to, rfv->hdr.c + offset, copy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) skb->csum = csum_block_add(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) skb->csum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) csum_partial_copy_nocheck(rfv->hdr.c + offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) to, copy),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) odd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) odd = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) offset += copy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) to += copy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) len -= copy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) if (!len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) offset -= rfv->hlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) return ip_generic_getfrag(rfv->msg, to, offset, len, odd, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) static int raw_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) struct inet_sock *inet = inet_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) struct net *net = sock_net(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) struct ipcm_cookie ipc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) struct rtable *rt = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) struct flowi4 fl4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) int free = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) __be32 daddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) __be32 saddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) u8 tos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) struct ip_options_data opt_copy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) struct raw_frag_vec rfv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) int hdrincl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) err = -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) if (len > 0xFFFF)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) /* hdrincl should be READ_ONCE(inet->hdrincl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) * but READ_ONCE() doesn't work with bit fields.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) * Doing this indirectly yields the same result.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) hdrincl = inet->hdrincl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) hdrincl = READ_ONCE(hdrincl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) * Check the flags.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) err = -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) if (msg->msg_flags & MSG_OOB) /* Mirror BSD error message */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) goto out; /* compatibility */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) * Get and verify the address.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) if (msg->msg_namelen) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) DECLARE_SOCKADDR(struct sockaddr_in *, usin, msg->msg_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) if (msg->msg_namelen < sizeof(*usin))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) if (usin->sin_family != AF_INET) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) pr_info_once("%s: %s forgot to set AF_INET. Fix it!\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) __func__, current->comm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) err = -EAFNOSUPPORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) if (usin->sin_family)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) daddr = usin->sin_addr.s_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) /* ANK: I did not forget to get protocol from port field.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) * I just do not know, who uses this weirdness.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) * IP_HDRINCL is much more convenient.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) err = -EDESTADDRREQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) if (sk->sk_state != TCP_ESTABLISHED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) daddr = inet->inet_daddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) ipcm_init_sk(&ipc, inet);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) if (msg->msg_controllen) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) err = ip_cmsg_send(sk, msg, &ipc, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) if (unlikely(err)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) kfree(ipc.opt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) if (ipc.opt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) free = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) saddr = ipc.addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) ipc.addr = daddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) if (!ipc.opt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) struct ip_options_rcu *inet_opt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) inet_opt = rcu_dereference(inet->inet_opt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) if (inet_opt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) memcpy(&opt_copy, inet_opt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) sizeof(*inet_opt) + inet_opt->opt.optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) ipc.opt = &opt_copy.opt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) if (ipc.opt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) /* Linux does not mangle headers on raw sockets,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) * so that IP options + IP_HDRINCL is non-sense.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) if (hdrincl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) if (ipc.opt->opt.srr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) if (!daddr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) daddr = ipc.opt->opt.faddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) tos = get_rtconn_flags(&ipc, sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) if (msg->msg_flags & MSG_DONTROUTE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) tos |= RTO_ONLINK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) if (ipv4_is_multicast(daddr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) if (!ipc.oif || netif_index_is_l3_master(sock_net(sk), ipc.oif))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) ipc.oif = inet->mc_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) if (!saddr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) saddr = inet->mc_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) } else if (!ipc.oif) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) ipc.oif = inet->uc_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) } else if (ipv4_is_lbcast(daddr) && inet->uc_index) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) /* oif is set, packet is to local broadcast
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) * and uc_index is set. oif is most likely set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) * by sk_bound_dev_if. If uc_index != oif check if the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) * oif is an L3 master and uc_index is an L3 slave.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) * If so, we want to allow the send using the uc_index.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) if (ipc.oif != inet->uc_index &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) ipc.oif == l3mdev_master_ifindex_by_index(sock_net(sk),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) inet->uc_index)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) ipc.oif = inet->uc_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) flowi4_init_output(&fl4, ipc.oif, ipc.sockc.mark, tos,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) RT_SCOPE_UNIVERSE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) hdrincl ? IPPROTO_RAW : sk->sk_protocol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) inet_sk_flowi_flags(sk) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) (hdrincl ? FLOWI_FLAG_KNOWN_NH : 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) daddr, saddr, 0, 0, sk->sk_uid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) if (!hdrincl) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) rfv.msg = msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) rfv.hlen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) err = raw_probe_proto_opt(&rfv, &fl4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) security_sk_classify_flow(sk, flowi4_to_flowi(&fl4));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) rt = ip_route_output_flow(net, &fl4, sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) if (IS_ERR(rt)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) err = PTR_ERR(rt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) rt = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) err = -EACCES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) if (rt->rt_flags & RTCF_BROADCAST && !sock_flag(sk, SOCK_BROADCAST))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) if (msg->msg_flags & MSG_CONFIRM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) goto do_confirm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) back_from_confirm:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) if (hdrincl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) err = raw_send_hdrinc(sk, &fl4, msg, len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) &rt, msg->msg_flags, &ipc.sockc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) if (!ipc.addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) ipc.addr = fl4.daddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) lock_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) err = ip_append_data(sk, &fl4, raw_getfrag,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) &rfv, len, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) &ipc, &rt, msg->msg_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) ip_flush_pending_frames(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) else if (!(msg->msg_flags & MSG_MORE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) err = ip_push_pending_frames(sk, &fl4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) if (err == -ENOBUFS && !inet->recverr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) release_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) if (free)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) kfree(ipc.opt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) ip_rt_put(rt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) do_confirm:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) if (msg->msg_flags & MSG_PROBE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) dst_confirm_neigh(&rt->dst, &fl4.daddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) if (!(msg->msg_flags & MSG_PROBE) || len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) goto back_from_confirm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) static void raw_close(struct sock *sk, long timeout)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) * Raw sockets may have direct kernel references. Kill them.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) ip_ra_control(sk, 0, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) sk_common_release(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) static void raw_destroy(struct sock *sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) lock_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) ip_flush_pending_frames(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) release_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) /* This gets rid of all the nasties in af_inet. -DaveM */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) static int raw_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) struct inet_sock *inet = inet_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) struct sockaddr_in *addr = (struct sockaddr_in *) uaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) u32 tb_id = RT_TABLE_LOCAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) int ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) int chk_addr_ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) lock_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_in))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) if (sk->sk_bound_dev_if)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) tb_id = l3mdev_fib_table_by_index(sock_net(sk),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) sk->sk_bound_dev_if) ? : tb_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) chk_addr_ret = inet_addr_type_table(sock_net(sk), addr->sin_addr.s_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) tb_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) ret = -EADDRNOTAVAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) if (addr->sin_addr.s_addr && chk_addr_ret != RTN_LOCAL &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) inet->inet_saddr = 0; /* Use device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) sk_dst_reset(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) release_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) * This should be easy, if there is something there
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) * we return it, otherwise we block.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) static int raw_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) int noblock, int flags, int *addr_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) struct inet_sock *inet = inet_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) size_t copied = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) int err = -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) DECLARE_SOCKADDR(struct sockaddr_in *, sin, msg->msg_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) if (flags & MSG_OOB)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) if (flags & MSG_ERRQUEUE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) err = ip_recv_error(sk, msg, len, addr_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) skb = skb_recv_datagram(sk, flags, noblock, &err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) copied = skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) if (len < copied) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) msg->msg_flags |= MSG_TRUNC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) copied = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) err = skb_copy_datagram_msg(skb, 0, msg, copied);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) sock_recv_ts_and_drops(msg, sk, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) /* Copy the address. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) if (sin) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) sin->sin_family = AF_INET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) sin->sin_port = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) *addr_len = sizeof(*sin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) if (inet->cmsg_flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) ip_cmsg_recv(msg, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) if (flags & MSG_TRUNC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) copied = skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) skb_free_datagram(sk, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) return copied;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) static int raw_sk_init(struct sock *sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) struct raw_sock *rp = raw_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) if (inet_sk(sk)->inet_num == IPPROTO_ICMP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) memset(&rp->filter, 0, sizeof(rp->filter));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) static int raw_seticmpfilter(struct sock *sk, sockptr_t optval, int optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) if (optlen > sizeof(struct icmp_filter))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) optlen = sizeof(struct icmp_filter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) if (copy_from_sockptr(&raw_sk(sk)->filter, optval, optlen))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) int len, ret = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) if (get_user(len, optlen))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) if (len < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) if (len > sizeof(struct icmp_filter))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) len = sizeof(struct icmp_filter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) ret = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) if (put_user(len, optlen) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) copy_to_user(optval, &raw_sk(sk)->filter, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) out: return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) static int do_raw_setsockopt(struct sock *sk, int level, int optname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) sockptr_t optval, unsigned int optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) if (optname == ICMP_FILTER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) if (inet_sk(sk)->inet_num != IPPROTO_ICMP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) return raw_seticmpfilter(sk, optval, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) return -ENOPROTOOPT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) static int raw_setsockopt(struct sock *sk, int level, int optname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) sockptr_t optval, unsigned int optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) if (level != SOL_RAW)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) return ip_setsockopt(sk, level, optname, optval, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) return do_raw_setsockopt(sk, level, optname, optval, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) static int do_raw_getsockopt(struct sock *sk, int level, int optname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) char __user *optval, int __user *optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) if (optname == ICMP_FILTER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) if (inet_sk(sk)->inet_num != IPPROTO_ICMP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) return raw_geticmpfilter(sk, optval, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) return -ENOPROTOOPT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) static int raw_getsockopt(struct sock *sk, int level, int optname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) char __user *optval, int __user *optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) if (level != SOL_RAW)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) return ip_getsockopt(sk, level, optname, optval, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) return do_raw_getsockopt(sk, level, optname, optval, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) static int raw_ioctl(struct sock *sk, int cmd, unsigned long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) case SIOCOUTQ: {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) int amount = sk_wmem_alloc_get(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) return put_user(amount, (int __user *)arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) case SIOCINQ: {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) int amount = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) spin_lock_bh(&sk->sk_receive_queue.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) skb = skb_peek(&sk->sk_receive_queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) if (skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) amount = skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) spin_unlock_bh(&sk->sk_receive_queue.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) return put_user(amount, (int __user *)arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) #ifdef CONFIG_IP_MROUTE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) return ipmr_ioctl(sk, cmd, (void __user *)arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) return -ENOIOCTLCMD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) #ifdef CONFIG_COMPAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) static int compat_raw_ioctl(struct sock *sk, unsigned int cmd, unsigned long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) case SIOCOUTQ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) case SIOCINQ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) return -ENOIOCTLCMD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) #ifdef CONFIG_IP_MROUTE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) return ipmr_compat_ioctl(sk, cmd, compat_ptr(arg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) return -ENOIOCTLCMD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) int raw_abort(struct sock *sk, int err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) lock_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) sk->sk_err = err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) sk->sk_error_report(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) __udp_disconnect(sk, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) release_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) EXPORT_SYMBOL_GPL(raw_abort);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) struct proto raw_prot = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) .name = "RAW",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) .close = raw_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) .destroy = raw_destroy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) .connect = ip4_datagram_connect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) .disconnect = __udp_disconnect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) .ioctl = raw_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) .init = raw_sk_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) .setsockopt = raw_setsockopt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) .getsockopt = raw_getsockopt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) .sendmsg = raw_sendmsg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) .recvmsg = raw_recvmsg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) .bind = raw_bind,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) .backlog_rcv = raw_rcv_skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) .release_cb = ip4_datagram_release_cb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) .hash = raw_hash_sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) .unhash = raw_unhash_sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) .obj_size = sizeof(struct raw_sock),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) .useroffset = offsetof(struct raw_sock, filter),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) .usersize = sizeof_field(struct raw_sock, filter),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) .h.raw_hash = &raw_v4_hashinfo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) #ifdef CONFIG_COMPAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) .compat_ioctl = compat_raw_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) .diag_destroy = raw_abort,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) #ifdef CONFIG_PROC_FS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) static struct sock *raw_get_first(struct seq_file *seq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) struct sock *sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) struct raw_hashinfo *h = PDE_DATA(file_inode(seq->file));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) struct raw_iter_state *state = raw_seq_private(seq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) for (state->bucket = 0; state->bucket < RAW_HTABLE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) ++state->bucket) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) sk_for_each(sk, &h->ht[state->bucket])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) if (sock_net(sk) == seq_file_net(seq))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) goto found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) sk = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) found:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) return sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) static struct sock *raw_get_next(struct seq_file *seq, struct sock *sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) struct raw_hashinfo *h = PDE_DATA(file_inode(seq->file));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) struct raw_iter_state *state = raw_seq_private(seq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) sk = sk_next(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) try_again:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999) } while (sk && sock_net(sk) != seq_file_net(seq));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) if (!sk && ++state->bucket < RAW_HTABLE_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) sk = sk_head(&h->ht[state->bucket]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) goto try_again;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) return sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) static struct sock *raw_get_idx(struct seq_file *seq, loff_t pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) struct sock *sk = raw_get_first(seq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) if (sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) while (pos && (sk = raw_get_next(seq, sk)) != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) --pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) return pos ? NULL : sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) void *raw_seq_start(struct seq_file *seq, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) __acquires(&h->lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) struct raw_hashinfo *h = PDE_DATA(file_inode(seq->file));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) read_lock(&h->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) return *pos ? raw_get_idx(seq, *pos - 1) : SEQ_START_TOKEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) EXPORT_SYMBOL_GPL(raw_seq_start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) void *raw_seq_next(struct seq_file *seq, void *v, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) struct sock *sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) if (v == SEQ_START_TOKEN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) sk = raw_get_first(seq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) sk = raw_get_next(seq, v);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) ++*pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) return sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) EXPORT_SYMBOL_GPL(raw_seq_next);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) void raw_seq_stop(struct seq_file *seq, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) __releases(&h->lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) struct raw_hashinfo *h = PDE_DATA(file_inode(seq->file));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) read_unlock(&h->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) EXPORT_SYMBOL_GPL(raw_seq_stop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) struct inet_sock *inet = inet_sk(sp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) __be32 dest = inet->inet_daddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) src = inet->inet_rcv_saddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) __u16 destp = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) srcp = inet->inet_num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) seq_printf(seq, "%4d: %08X:%04X %08X:%04X"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) " %02X %08X:%08X %02X:%08lX %08X %5u %8d %lu %d %pK %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) i, src, srcp, dest, destp, sp->sk_state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) sk_wmem_alloc_get(sp),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) sk_rmem_alloc_get(sp),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) 0, 0L, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) 0, sock_i_ino(sp),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) refcount_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) static int raw_seq_show(struct seq_file *seq, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) if (v == SEQ_START_TOKEN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) seq_printf(seq, " sl local_address rem_address st tx_queue "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) "rx_queue tr tm->when retrnsmt uid timeout "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) "inode ref pointer drops\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) raw_sock_seq_show(seq, v, raw_seq_private(seq)->bucket);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) static const struct seq_operations raw_seq_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) .start = raw_seq_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) .next = raw_seq_next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) .stop = raw_seq_stop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) .show = raw_seq_show,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) static __net_init int raw_init_net(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) if (!proc_create_net_data("raw", 0444, net->proc_net, &raw_seq_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) sizeof(struct raw_iter_state), &raw_v4_hashinfo))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) static __net_exit void raw_exit_net(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) remove_proc_entry("raw", net->proc_net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) static __net_initdata struct pernet_operations raw_net_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) .init = raw_init_net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) .exit = raw_exit_net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) int __init raw_proc_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) return register_pernet_subsys(&raw_net_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) void __init raw_proc_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) unregister_pernet_subsys(&raw_net_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) #endif /* CONFIG_PROC_FS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) static void raw_sysctl_init_net(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) #ifdef CONFIG_NET_L3_MASTER_DEV
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) net->ipv4.sysctl_raw_l3mdev_accept = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) static int __net_init raw_sysctl_init(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) raw_sysctl_init_net(net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) static struct pernet_operations __net_initdata raw_sysctl_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) .init = raw_sysctl_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) void __init raw_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) raw_sysctl_init_net(&init_net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) if (register_pernet_subsys(&raw_sysctl_ops))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) panic("RAW: failed to init sysctl parameters.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) }