/* Returns 0 on success or an error code  */
static int smack_netlabel(struct sock *sk, int labeled)
/* Returns 0 on success or an error code  */
static int smack_netlabel(struct sock *sk, int labeled)
{
	struct socket_smack *ssp = sk->sk_security;
	struct netlbl_lsm_secattr secattr;
	int rc = 0;
	local_bh_disable();
	bh_lock_sock_nested(sk);
	if (ssp->smk_out == smack_net_ambient ||
	    labeled == SMACK_UNLABELED_SOCKET)
		netlbl_sock_delattr(sk);
	else {
		netlbl_secattr_init(&secattr);
		smack_to_secattr(ssp->smk_out, &secattr);
		rc = netlbl_sock_setattr(sk, sk->sk_family, &secattr);
		netlbl_secattr_destroy(&secattr);
	}
	bh_unlock_sock(sk);
	local_bh_enable();
	return rc;
}