[strongSwan] activate only a small part of a right subnet

Tobias Brunner tobias at strongswan.org
Mon Jun 7 19:04:25 CEST 2021


> If I change the 
> rightsubnet to only use this one host, the tunnel will not properly come 
> up, as it does not match the partner settings anymore.

This is called traffic selector (TS) narrowing, and it's one of the
major improvements of IKEv2 over IKEv1.  Unfortunately, some IKEv2
implementations are just minimally patched IKEv1 implementations, so
they don't support narrowing (or multiple TS per CHILD_SA).  I think
this violates RFC 7296, section 2.9 (see [1]), so you may want to report
that to the remote admins.

> Is there a way to 
> build the SA with the large subnet, but internally only add routes for a 
> smaller subnet?

Theoretically, yes.  But there are no configuration options for it.  You
could disable policy installation (installpolicy=no) and do that
manually in an updown script (a route might also be necessary), or you
could write a custom plugin that narrows the local TS before policies
for the IPsec SAs are installed (NARROW_INITIATOR_POST_*).

However, both approaches get complicated by your using traps
(auto=route).   If you disable policy installation, you'd need to
install those trap policies manually too (and the updown script is not
called at that point, so you'd need to do that outside e.g. from a start
And if you don't disable the policy installation and go the plugin
route, you'd need the outbound trap policy (i.e. your configuration) to
be narrow already (it would otherwise capture all traffic to the larger
remote subnet even if the eventually installed policy is narrowed,
because the whole point is to send matching traffic through the IPsec SA
once it exists), then a larger TS has to be negotiated and then a
narrowed TS should again be used when installing policies for the
negotiated IPsec SAs.  That could be done from a plugin as you can, as
mentioned above, change the TS before they are installed and also before
they are sent (NARROW_INITIATOR_PRE_*).  So that's possible but maybe
not that easy if you're not familiar with the codebase.

A simpler alternative could be to install bypass policies for the parts
of the remote TS you don't want to tunnel.  These policies have a higher
priority than regular or trap policies, so traffic matching those
destinations won't trigger traps or get tunneled later.  For instance,
if you have as remote subnet and only want to tunnel
traffic to (I don't know the actual IP, so...) you need
to add a passthrough connection (see [2]) with the following:



[1] https://datatracker.ietf.org/doc/html/rfc7296#section-2.9

More information about the Users mailing list