[linux-yocto] [PATCH] net/bluetooth: make bluetooth socket can be created in net namespace

Bruce Ashfield bruce.ashfield at windriver.com
Mon Dec 18 14:01:39 PST 2017


On 2017-12-17 8:24 PM, Fupan Li wrote:
> From: fupan li <fupan.li at windriver.com>
> 
> By now kernel only supported creating bluetooth socket in init_net
> net namespace, which made bluetooth device cannot be accessed in
> containers, this patch made bluetooth socket can be created in
> net namespaces to fix this problem.

Staged.

I'm doing build testing and expect to push this later tonight.

Bruce

> 
> Signed-off-by: fupan li <fupan.li at windriver.com>
> Signed-off-by: Bruce Ashfield <bruce.ashfield at windriver.com>
> ---
>   net/bluetooth/af_bluetooth.c | 2 +-
>   net/bluetooth/bnep/sock.c    | 4 ++--
>   net/bluetooth/cmtp/sock.c    | 4 ++--
>   net/bluetooth/hci_sock.c     | 4 ++--
>   net/bluetooth/hidp/sock.c    | 4 ++--
>   net/bluetooth/l2cap_sock.c   | 4 ++--
>   net/bluetooth/rfcomm/sock.c  | 4 ++--
>   net/bluetooth/sco.c          | 4 ++--
>   8 files changed, 15 insertions(+), 15 deletions(-)
> 
> diff --git a/net/bluetooth/af_bluetooth.c b/net/bluetooth/af_bluetooth.c
> index 42d0997..72f7e32 100644
> --- a/net/bluetooth/af_bluetooth.c
> +++ b/net/bluetooth/af_bluetooth.c
> @@ -113,7 +113,7 @@ static int bt_sock_create(struct net *net, struct socket *sock, int proto,
>   {
>   	int err;
>   
> -	if (net != &init_net)
> +	if (!net_eq(net, current->nsproxy->net_ns))
>   		return -EAFNOSUPPORT;
>   
>   	if (proto < 0 || proto >= BT_MAX_PROTO)
> diff --git a/net/bluetooth/bnep/sock.c b/net/bluetooth/bnep/sock.c
> index b5116fa..742b862 100644
> --- a/net/bluetooth/bnep/sock.c
> +++ b/net/bluetooth/bnep/sock.c
> @@ -241,7 +241,7 @@ int __init bnep_sock_init(void)
>   		goto error;
>   	}
>   
> -	err = bt_procfs_init(&init_net, "bnep", &bnep_sk_list, NULL);
> +	err = bt_procfs_init(current->nsproxy->net_ns, "bnep", &bnep_sk_list, NULL);
>   	if (err < 0) {
>   		BT_ERR("Failed to create BNEP proc file");
>   		bt_sock_unregister(BTPROTO_BNEP);
> @@ -259,7 +259,7 @@ int __init bnep_sock_init(void)
>   
>   void __exit bnep_sock_cleanup(void)
>   {
> -	bt_procfs_cleanup(&init_net, "bnep");
> +	bt_procfs_cleanup(current->nsproxy->net_ns, "bnep");
>   	bt_sock_unregister(BTPROTO_BNEP);
>   	proto_unregister(&bnep_proto);
>   }
> diff --git a/net/bluetooth/cmtp/sock.c b/net/bluetooth/cmtp/sock.c
> index ce86a7b..d3d6084 100644
> --- a/net/bluetooth/cmtp/sock.c
> +++ b/net/bluetooth/cmtp/sock.c
> @@ -245,7 +245,7 @@ int cmtp_init_sockets(void)
>   		goto error;
>   	}
>   
> -	err = bt_procfs_init(&init_net, "cmtp", &cmtp_sk_list, NULL);
> +	err = bt_procfs_init(current->nsproxy->net_ns, "cmtp", &cmtp_sk_list, NULL);
>   	if (err < 0) {
>   		BT_ERR("Failed to create CMTP proc file");
>   		bt_sock_unregister(BTPROTO_HIDP);
> @@ -263,7 +263,7 @@ int cmtp_init_sockets(void)
>   
>   void cmtp_cleanup_sockets(void)
>   {
> -	bt_procfs_cleanup(&init_net, "cmtp");
> +	bt_procfs_cleanup(current->nsproxy->net_ns, "cmtp");
>   	bt_sock_unregister(BTPROTO_CMTP);
>   	proto_unregister(&cmtp_proto);
>   }
> diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
> index 638bf0e..a8b07c6 100644
> --- a/net/bluetooth/hci_sock.c
> +++ b/net/bluetooth/hci_sock.c
> @@ -2038,7 +2038,7 @@ int __init hci_sock_init(void)
>   		goto error;
>   	}
>   
> -	err = bt_procfs_init(&init_net, "hci", &hci_sk_list, NULL);
> +	err = bt_procfs_init(current->nsproxy->net_ns, "hci", &hci_sk_list, NULL);
>   	if (err < 0) {
>   		BT_ERR("Failed to create HCI proc file");
>   		bt_sock_unregister(BTPROTO_HCI);
> @@ -2056,7 +2056,7 @@ int __init hci_sock_init(void)
>   
>   void hci_sock_cleanup(void)
>   {
> -	bt_procfs_cleanup(&init_net, "hci");
> +	bt_procfs_cleanup(current->nsproxy->net_ns, "hci");
>   	bt_sock_unregister(BTPROTO_HCI);
>   	proto_unregister(&hci_sk_proto);
>   }
> diff --git a/net/bluetooth/hidp/sock.c b/net/bluetooth/hidp/sock.c
> index 008ba43..19d4e9a 100644
> --- a/net/bluetooth/hidp/sock.c
> +++ b/net/bluetooth/hidp/sock.c
> @@ -275,7 +275,7 @@ int __init hidp_init_sockets(void)
>   		goto error;
>   	}
>   
> -	err = bt_procfs_init(&init_net, "hidp", &hidp_sk_list, NULL);
> +	err = bt_procfs_init(current->nsproxy->net_ns, "hidp", &hidp_sk_list, NULL);
>   	if (err < 0) {
>   		BT_ERR("Failed to create HIDP proc file");
>   		bt_sock_unregister(BTPROTO_HIDP);
> @@ -293,7 +293,7 @@ int __init hidp_init_sockets(void)
>   
>   void __exit hidp_cleanup_sockets(void)
>   {
> -	bt_procfs_cleanup(&init_net, "hidp");
> +	bt_procfs_cleanup(current->nsproxy->net_ns, "hidp");
>   	bt_sock_unregister(BTPROTO_HIDP);
>   	proto_unregister(&hidp_proto);
>   }
> diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
> index 507b80d..4509fc4 100644
> --- a/net/bluetooth/l2cap_sock.c
> +++ b/net/bluetooth/l2cap_sock.c
> @@ -1684,7 +1684,7 @@ int __init l2cap_init_sockets(void)
>   		goto error;
>   	}
>   
> -	err = bt_procfs_init(&init_net, "l2cap", &l2cap_sk_list,
> +	err = bt_procfs_init(current->nsproxy->net_ns, "l2cap", &l2cap_sk_list,
>   			     NULL);
>   	if (err < 0) {
>   		BT_ERR("Failed to create L2CAP proc file");
> @@ -1703,7 +1703,7 @@ int __init l2cap_init_sockets(void)
>   
>   void l2cap_cleanup_sockets(void)
>   {
> -	bt_procfs_cleanup(&init_net, "l2cap");
> +	bt_procfs_cleanup(current->nsproxy->net_ns, "l2cap");
>   	bt_sock_unregister(BTPROTO_L2CAP);
>   	proto_unregister(&l2cap_proto);
>   }
> diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
> index ac3c650..e1e275c 100644
> --- a/net/bluetooth/rfcomm/sock.c
> +++ b/net/bluetooth/rfcomm/sock.c
> @@ -1075,7 +1075,7 @@ int __init rfcomm_init_sockets(void)
>   		goto error;
>   	}
>   
> -	err = bt_procfs_init(&init_net, "rfcomm", &rfcomm_sk_list, NULL);
> +	err = bt_procfs_init(current->nsproxy->net_ns, "rfcomm", &rfcomm_sk_list, NULL);
>   	if (err < 0) {
>   		BT_ERR("Failed to create RFCOMM proc file");
>   		bt_sock_unregister(BTPROTO_RFCOMM);
> @@ -1100,7 +1100,7 @@ int __init rfcomm_init_sockets(void)
>   
>   void __exit rfcomm_cleanup_sockets(void)
>   {
> -	bt_procfs_cleanup(&init_net, "rfcomm");
> +	bt_procfs_cleanup(current->nsproxy->net_ns, "rfcomm");
>   
>   	debugfs_remove(rfcomm_sock_debugfs);
>   
> diff --git a/net/bluetooth/sco.c b/net/bluetooth/sco.c
> index 728e0c8..57de0be 100644
> --- a/net/bluetooth/sco.c
> +++ b/net/bluetooth/sco.c
> @@ -1231,7 +1231,7 @@ int __init sco_init(void)
>   		goto error;
>   	}
>   
> -	err = bt_procfs_init(&init_net, "sco", &sco_sk_list, NULL);
> +	err = bt_procfs_init(current->nsproxy->net_ns, "sco", &sco_sk_list, NULL);
>   	if (err < 0) {
>   		BT_ERR("Failed to create SCO proc file");
>   		bt_sock_unregister(BTPROTO_SCO);
> @@ -1257,7 +1257,7 @@ int __init sco_init(void)
>   
>   void sco_exit(void)
>   {
> -	bt_procfs_cleanup(&init_net, "sco");
> +	bt_procfs_cleanup(current->nsproxy->net_ns, "sco");
>   
>   	debugfs_remove(sco_debugfs);
>   
> 



More information about the linux-yocto mailing list