Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 548c84fd authored by qctecmdr Service's avatar qctecmdr Service Committed by Gerrit - the friendly Code Review server
Browse files

Merge "net: socket: Added notifier chains for socket administrative functions"

parents 7b7bcf16 e6388951
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -2521,6 +2521,16 @@ static inline void sk_pacing_shift_update(struct sock *sk, int val)
		return;
	sk->sk_pacing_shift = val;
}
/* SOCKEV Notifier Events */
#define SOCKEV_SOCKET   0x00
#define SOCKEV_BIND     0x01
#define SOCKEV_LISTEN   0x02
#define SOCKEV_ACCEPT   0x03
#define SOCKEV_CONNECT  0x04
#define SOCKEV_SHUTDOWN 0x05

int sockev_register_notify(struct notifier_block *nb);
int sockev_unregister_notify(struct notifier_block *nb);

/* if a socket is bound to a device, check that the given device
 * index is either the same or that the socket is bound to an L3
+33 −1
Original line number Diff line number Diff line
@@ -115,6 +115,8 @@ unsigned int sysctl_net_busy_poll __read_mostly;

static ssize_t sock_read_iter(struct kiocb *iocb, struct iov_iter *to);
static ssize_t sock_write_iter(struct kiocb *iocb, struct iov_iter *from);
static BLOCKING_NOTIFIER_HEAD(sockev_notifier_list);

static int sock_mmap(struct file *file, struct vm_area_struct *vma);

static int sock_close(struct inode *inode, struct file *file);
@@ -163,6 +165,14 @@ static DEFINE_SPINLOCK(net_family_lock);
static const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;

/*
 * Socket Event framework helpers
 */
static void sockev_notify(unsigned long event, struct socket *sk)
{
	blocking_notifier_call_chain(&sockev_notifier_list, event, sk);
}

/**
 * Support routines.
 * Move socket addresses back and forth across the kernel/user
 * divide and look after the messy bits.
@@ -1348,6 +1358,9 @@ int __sys_socket(int family, int type, int protocol)
	if (retval < 0)
		return retval;

	if (retval == 0)
		sockev_notify(SOCKEV_SOCKET, sock);

	return sock_map_fd(sock, flags & (O_CLOEXEC | O_NONBLOCK));
}

@@ -1485,6 +1498,8 @@ int __sys_bind(int fd, struct sockaddr __user *umyaddr, int addrlen)
						      &address, addrlen);
		}
		fput_light(sock->file, fput_needed);
		if (!err)
			sockev_notify(SOCKEV_BIND, sock);
	}
	return err;
}
@@ -1517,6 +1532,8 @@ int __sys_listen(int fd, int backlog)
			err = sock->ops->listen(sock, backlog);

		fput_light(sock->file, fput_needed);
		if (!err)
			sockev_notify(SOCKEV_LISTEN, sock);
	}
	return err;
}
@@ -1608,7 +1625,8 @@ int __sys_accept4(int fd, struct sockaddr __user *upeer_sockaddr,

	fd_install(newfd, newfile);
	err = newfd;

	if (!err)
		sockev_notify(SOCKEV_ACCEPT, sock);
out_put:
	fput_light(sock->file, fput_needed);
out:
@@ -1663,6 +1681,8 @@ int __sys_connect(int fd, struct sockaddr __user *uservaddr, int addrlen)

	err = sock->ops->connect(sock, (struct sockaddr *)&address, addrlen,
				 sock->file->f_flags);
	if (!err)
		sockev_notify(SOCKEV_CONNECT, sock);
out_put:
	fput_light(sock->file, fput_needed);
out:
@@ -1961,6 +1981,7 @@ int __sys_shutdown(int fd, int how)

	sock = sockfd_lookup_light(fd, &err, &fput_needed);
	if (sock != NULL) {
		sockev_notify(SOCKEV_SHUTDOWN, sock);
		err = security_socket_shutdown(sock, how);
		if (!err)
			err = sock->ops->shutdown(sock, how);
@@ -3397,3 +3418,14 @@ u32 kernel_sock_ip_overhead(struct sock *sk)
	}
}
EXPORT_SYMBOL(kernel_sock_ip_overhead);
int sockev_register_notify(struct notifier_block *nb)
{
	return blocking_notifier_chain_register(&sockev_notifier_list, nb);
}
EXPORT_SYMBOL(sockev_register_notify);

int sockev_unregister_notify(struct notifier_block *nb)
{
	return blocking_notifier_chain_unregister(&sockev_notifier_list, nb);
}
EXPORT_SYMBOL(sockev_unregister_notify);