Skip to content

Commit

Permalink
ksmbd: browse interfaces list on FSCTL_QUERY_INTERFACE_INFO IOCTL
Browse files Browse the repository at this point in the history
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: Namjae Jeon <[email protected]>
  • Loading branch information
namjaejeon committed Jan 30, 2025
1 parent b9161a7 commit bb1eb11
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 42 deletions.
3 changes: 2 additions & 1 deletion ksmbd_netlink.h
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
};
Expand Down
1 change: 1 addition & 0 deletions server.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions smb2pdu.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,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)
{
Expand Down Expand Up @@ -8364,6 +8365,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;
Expand Down
1 change: 1 addition & 0 deletions transport_ipc.c
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,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) {
Expand Down
73 changes: 32 additions & 41 deletions transport_tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -544,32 +544,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 (netdev->priv_flags & IFF_BRIDGE_PORT)
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;
ksmbd_debug(CONN, "netdev-up event: netdev(%s) is going up\n",
iface->name);
ret = create_socket(iface);
if (ret)
return NOTIFY_OK;
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;
}
if (!found && bind_additional_ifaces) {
if (!iface && bind_additional_ifaces) {
iface = alloc_iface(kstrdup(netdev->name, KSMBD_DEFAULT_GFP));
if (!iface)
return NOTIFY_OK;
Expand All @@ -581,21 +586,19 @@ 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) {
ksmbd_debug(CONN, "netdev-down event: netdev(%s) is going down\n",
iface->name);
tcp_stop_kthread(iface->ksmbd_kthread);
iface->ksmbd_kthread = NULL;
mutex_lock(&iface->sock_release_lock);
tcp_destroy_socket(iface->ksmbd_socket);
iface->ksmbd_socket = NULL;
mutex_unlock(&iface->sock_release_lock);

iface->state = IFACE_STATE_DOWN;
break;
}
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);
iface->ksmbd_kthread = NULL;
mutex_lock(&iface->sock_release_lock);
tcp_destroy_socket(iface->ksmbd_socket);
iface->ksmbd_socket = NULL;
mutex_unlock(&iface->sock_release_lock);

iface->state = IFACE_STATE_DOWN;
break;
}
break;
}
Expand Down Expand Up @@ -664,18 +667,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 (netdev->priv_flags & IFF_BRIDGE_PORT)
continue;
if (!alloc_iface(kstrdup(netdev->name, KSMBD_DEFAULT_GFP))) {
rtnl_unlock();
return -ENOMEM;
}
}
rtnl_unlock();
bind_additional_ifaces = 1;
return 0;
}
Expand Down
1 change: 1 addition & 0 deletions transport_tcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#define __KSMBD_TRANSPORT_TCP_H__

int ksmbd_tcp_set_interfaces(char *ifc_list, int ifc_list_sz);
struct interface *ksmbd_find_netdev_name_iface_list(char *netdev_name);
int ksmbd_tcp_init(void);
void ksmbd_tcp_destroy(void);

Expand Down

0 comments on commit bb1eb11

Please sign in to comment.