On 25/08/2022 18:46, Eyal Birger wrote: > This commit adds support for 'collect_md' mode on xfrm interfaces. > > Each net can have one collect_md device, created by providing the > IFLA_XFRM_COLLECT_METADATA flag at creation. This device cannot be > altered and has no if_id or link device attributes. > > On transmit to this device, the if_id is fetched from the attached dst > metadata on the skb. If exists, the link property is also fetched from > the metadata. The dst metadata type used is METADATA_XFRM which holds > these properties. > > On the receive side, xfrmi_rcv_cb() populates a dst metadata for each > packet received and attaches it to the skb. The if_id used in this case is > fetched from the xfrm state, and the link is fetched from the incoming > device. This information can later be used by upper layers such as tc, > ebpf, and ip rules. > > Because the skb is scrubed in xfrmi_rcv_cb(), the attachment of the dst > metadata is postponed until after scrubing. Similarly, xfrm_input() is > adapted to avoid dropping metadata dsts by only dropping 'valid' > (skb_valid_dst(skb) == true) dsts. > > Policy matching on packets arriving from collect_md xfrmi devices is > done by using the xfrm state existing in the skb's sec_path. > The xfrm_if_cb.decode_cb() interface implemented by xfrmi_decode_session() > is changed to keep the details of the if_id extraction tucked away > in xfrm_interface.c. > > Signed-off-by: Eyal Birger <eyal.birger@xxxxxxxxx> > > ---- > > v3: > - coding improvements suggested by Nikolay Aleksandrov > - use RCU_INIT_POINTER() instead of rcu_assign_pointer() in > xfrmi_dev_uninit() and rtnl_dereference() in xfrmi_exit_batch_net() > as suggested by Nikolay Aleksandrov > - omit redundant check on link assignment from metadata as suggested > by Nicolas Dichtel > - add missing extack message as suggested by Nicolas Dichtel > > v2: > - add "link" property as suggested by Nicolas Dichtel > - rename xfrm_if_decode_session_params to xfrm_if_decode_session_result > --- > include/net/xfrm.h | 11 +++- > include/uapi/linux/if_link.h | 1 + > net/xfrm/xfrm_input.c | 7 +- > net/xfrm/xfrm_interface.c | 121 +++++++++++++++++++++++++++++------ > net/xfrm/xfrm_policy.c | 10 +-- > 5 files changed, 121 insertions(+), 29 deletions(-) > Reviewed-by: Nikolay Aleksandrov <razor@xxxxxxxxxxxxx>