  Searches for primordial gravitational waves have resulted in constraints in a
large frequency range from a variety of sources. The standard Cosmic Microwave
Background (CMB) technique is to parameterise the tensor power spectrum in
terms of the tensor-to-scalar ratio, $r$, and spectral index, $n_{\rm t}$, and
constrain these using measurements of the temperature and polarization power
spectra. Another method, applicable to modes well inside the cosmological
horizon at recombination, uses the shortwave approximation, under which
gravitational waves behave as an effective neutrino species. In this paper we
give model-independent CMB constraints on the energy density of gravitational
waves, $\Omega_\textrm{gw} h^2$, for the entire range of observable
frequencies. On large scales, $f \lesssim 10^{-16}\, \text{Hz}$, we reconstruct
the initial tensor power spectrum in logarithmic frequency bins, finding
maximal sensitivity for scales close to the horizon size at recombination. On
small scales, $f \gtrsim10^{-15}\,\mbox{Hz}$, we use the shortwave
approximation, finding $\Omega_\textrm{gw} h^2 < 1.7 \times10^{-6}$ for
adiabatic initial conditions and $\Omega_\textrm{gw} h^2 < 2.9 \times10^{-7}$
for homogeneous initial conditions (both $2\sigma$ upper limits). For scales
close to the horizon size at recombination, we use second-order perturbation
theory to calculate the back-reaction from gravitational waves, finding
$\Omega_\textrm{gw} h^2 < 8.4 \times10^{-7}$, in the absence of neutrino
anisotropic stress and $\Omega_\textrm{gw} h^2 < 8.6 \times10^{-7}$ when
including neutrino anisotropic stress. These constraints are valid for $
10^{-15}\, \text{Hz} \gtrsim f \gtrsim 3 \times 10^{-16}\, \text{Hz}$.
