Commit b2d99376 authored by Namjae Jeon's avatar Namjae Jeon Committed by Steve French
Browse files

ksmbd: browse interfaces list on FSCTL_QUERY_INTERFACE_INFO IOCTL



ksmbd.mount will give each interfaces list and bind_interfaces_only flags
to ksmbd server. Previously, the interfaces list was sent only
when bind_interfaces_only was enabled.
ksmbd server browse only interfaces list given from ksmbd.conf on
FSCTL_QUERY_INTERFACE_INFO IOCTL.

Signed-off-by: default avatarNamjae Jeon <linkinjeon@kernel.org>
Signed-off-by: default avatarSteve French <stfrench@microsoft.com>
parent fe4b4188
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -111,7 +111,8 @@ struct ksmbd_startup_request {
	__u32	smb2_max_credits;	/* MAX credits */
	__u32	smbd_max_io_size;	/* smbd read write size */
	__u32	max_connections;	/* Number of maximum simultaneous connections */
	__u32	reserved[126];		/* Reserved room */
	__s8	bind_interfaces_only;
	__s8	reserved[503];		/* Reserved room */
	__u32	ifc_list_sz;		/* interfaces list size */
	__s8	____payload[];
};
+1 −0
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ struct ksmbd_server_config {

	char			*conf[SERVER_CONF_WORK_GROUP + 1];
	struct task_struct	*dh_task;
	bool			bind_interfaces_only;
};

extern struct ksmbd_server_config server_conf;
+4 −0
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@
#include "mgmt/user_session.h"
#include "mgmt/ksmbd_ida.h"
#include "ndr.h"
#include "transport_tcp.h"

static void __wbuf(struct ksmbd_work *work, void **req, void **rsp)
{
@@ -7759,6 +7760,9 @@ static int fsctl_query_iface_info_ioctl(struct ksmbd_conn *conn,
		if (netdev->type == ARPHRD_LOOPBACK)
			continue;

		if (!ksmbd_find_netdev_name_iface_list(netdev->name))
			continue;

		flags = dev_get_flags(netdev);
		if (!(flags & IFF_RUNNING))
			continue;
+1 −0
Original line number Diff line number Diff line
@@ -333,6 +333,7 @@ static int ipc_server_config_on_startup(struct ksmbd_startup_request *req)
	ret = ksmbd_set_netbios_name(req->netbios_name);
	ret |= ksmbd_set_server_string(req->server_string);
	ret |= ksmbd_set_work_group(req->work_group);
	server_conf.bind_interfaces_only = req->bind_interfaces_only;
	ret |= ksmbd_tcp_set_interfaces(KSMBD_STARTUP_CONFIG_INTERFACES(req),
					req->ifc_list_sz);
	if (ret) {
+32 −41
Original line number Diff line number Diff line
@@ -504,32 +504,37 @@ static int create_socket(struct interface *iface)
	return ret;
}

struct interface *ksmbd_find_netdev_name_iface_list(char *netdev_name)
{
	struct interface *iface;

	list_for_each_entry(iface, &iface_list, entry)
		if (!strcmp(iface->name, netdev_name))
			return iface;
	return NULL;
}

static int ksmbd_netdev_event(struct notifier_block *nb, unsigned long event,
			      void *ptr)
{
	struct net_device *netdev = netdev_notifier_info_to_dev(ptr);
	struct interface *iface;
	int ret, found = 0;
	int ret;

	switch (event) {
	case NETDEV_UP:
		if (netif_is_bridge_port(netdev))
			return NOTIFY_OK;

		list_for_each_entry(iface, &iface_list, entry) {
			if (!strcmp(iface->name, netdev->name)) {
				found = 1;
				if (iface->state != IFACE_STATE_DOWN)
					break;
		iface = ksmbd_find_netdev_name_iface_list(netdev->name);
		if (iface && iface->state == IFACE_STATE_DOWN) {
			ksmbd_debug(CONN, "netdev-up event: netdev(%s) is going up\n",
					iface->name);
			ret = create_socket(iface);
			if (ret)
				return NOTIFY_OK;
				break;
			}
		}
		if (!found && bind_additional_ifaces) {
		if (!iface && bind_additional_ifaces) {
			iface = alloc_iface(kstrdup(netdev->name, KSMBD_DEFAULT_GFP));
			if (!iface)
				return NOTIFY_OK;
@@ -541,9 +546,8 @@ static int ksmbd_netdev_event(struct notifier_block *nb, unsigned long event,
		}
		break;
	case NETDEV_DOWN:
		list_for_each_entry(iface, &iface_list, entry) {
			if (!strcmp(iface->name, netdev->name) &&
			    iface->state == IFACE_STATE_CONFIGURED) {
		iface = ksmbd_find_netdev_name_iface_list(netdev->name);
		if (iface && iface->state == IFACE_STATE_CONFIGURED) {
			ksmbd_debug(CONN, "netdev-down event: netdev(%s) is going down\n",
					iface->name);
			tcp_stop_kthread(iface->ksmbd_kthread);
@@ -556,7 +560,6 @@ static int ksmbd_netdev_event(struct notifier_block *nb, unsigned long event,
			iface->state = IFACE_STATE_DOWN;
			break;
		}
		}
		break;
	}

@@ -624,18 +627,6 @@ int ksmbd_tcp_set_interfaces(char *ifc_list, int ifc_list_sz)
	int sz = 0;

	if (!ifc_list_sz) {
		struct net_device *netdev;

		rtnl_lock();
		for_each_netdev(&init_net, netdev) {
			if (netif_is_bridge_port(netdev))
				continue;
			if (!alloc_iface(kstrdup(netdev->name, KSMBD_DEFAULT_GFP))) {
				rtnl_unlock();
				return -ENOMEM;
			}
		}
		rtnl_unlock();
		bind_additional_ifaces = 1;
		return 0;
	}
Loading