xfrm: Store ipsec interface index
Subsystems (3)
PATCH 1/1 xfrm: Store ipsec interface index
From: wangfe <[email protected]>
When there are multiple ipsec sessions, packet offload driver can use the index to distinguish the packets from the different sessions even though xfrm_selector are same. Thus each packet is handled corresponding to its session parameter.
--- net/xfrm/xfrm_interface_core.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
net/xfrm/xfrm_interface_core.c +3 -1
@@ -506,7 +506,9 @@ xfrmi_xmit2(struct sk_buff *skb, struct net_device *dev, struct flowi *fl)xfrmi_scrub_packet (skb, !net_eq (xi->net,dev_net (dev)));skb_dst_set (skb, dst); skb->dev = tdev; - +#ifdef CONFIG_XFRM_OFFLOAD + skb->skb_iif = if_id; +#endif err =dst_output (xi->net, skb->sk, skb);if (net_xmit_eval (err) ==0 ) {dev_sw_netstats_tx_add (dev,1 , length);
Signature · 1 line
2.44.0.291.gc1ea87d7ee-goog
Quoted 5 lines · Feng Wang
From: wangfe <[email protected]>
When there are multiple ipsec sessions, packet offload driver can use the index to distinguish the packets from the different sessions even though
xfrm_selectorare same.
Do we have such "packet offload driver" in the kernel tree?
Thanks
Quoted 26 lines
Thus each packet is handled corresponding to its session parameter.
Signed-off-by wangfe <[email protected]>--- net/xfrm/xfrm_interface_core.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)net/xfrm/xfrm_interface_core.c +3
-1@@ -506,7 +506,9 @@ xfrmi_xmit2(struct sk_buff *skb, struct net_device *dev, struct flowi *fl)xfrmi_scrub_packet (skb, !net_eq (xi->net,dev_net (dev)));skb_dst_set (skb, dst); skb->dev = tdev; - +#ifdef CONFIG_XFRM_OFFLOAD + skb->skb_iif = if_id; +#endif err =dst_output (xi->net, skb->sk, skb);if (net_xmit_eval (err) ==0 ) {dev_sw_netstats_tx_add (dev,1 , length);Signature · 1 line
2.44.0.291.gc1ea87d7ee-goog
A message that is not in the archive (sent off-list or not yet received): CADsK2K_65Wytnr5y+5Biw=ebtb-+hO=K7hxhSNJd6X+q9nAieg@mail.gmail.com
Steffen Klassert
maintainerQuoted 5 lines · Feng Wang
Hi Leon,
There is no "packet offload driver" in the current kernel tree. The packet offload driver mostly is vendor specific, it implements hardware packet offload.
There are 'packet offload drivers' in the kernel, that's why we support this kind of offload. We don't add code for proprietary drivers.
Quoted 27 lines · Leon Romanovsky
Quoted 26 lines · Feng Wang
Quoted 5 lines
From: wangfe <[email protected]>
When there are multiple ipsec sessions, packet offload driver can use the index to distinguish the packets from the different sessions even though
xfrm_selectorare same.Do we have such "packet offload driver" in the kernel tree?
Thanks
Review
Quoted 8 lines
Thus each packet is handled corresponding to its session parameter.
Signed-off-by wangfe <[email protected]>--- net/xfrm/xfrm_interface_core.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)(quoted diff) +0
-0
b/net/xfrm/xfrm_interface_core.cnet/xfrm/xfrm_interface_core.c xfrmi_xmit2(struct sk_buff *skb, struct net_device
Quoted 4 lines
index
21d50d75c260..996571af53e5100644net/xfrm/xfrm_interface_core.c +0
-0@@ -506,7 +506,9 @@ xfrmi_xmit2(struct sk_buff *skb, struct net_device*dev, struct flowi *fl)
Quoted 7 lines
Quoted 7 lines
net/xfrm/xfrm_interface_core.c xfrmi_xmit2(struct sk_buff *skb, struct net_device *dev, struct flowi *fl) · line 511
Quoted 7 lines
net/xfrm/xfrm_interface_core.c +3
-1xfrmi_scrub_packet (skb, !net_eq (xi->net,dev_net (dev)));skb_dst_set (skb, dst); skb->dev = tdev; - +#ifdef CONFIG_XFRM_OFFLOAD + skb->skb_iif = if_id; +#endif
This looks wrong. The network interface ID is not the same as the xfrm interface ID.
A message that is not in the archive (sent off-list or not yet received): CADsK2K-WFG2+2NQ08xBq89ty-G-xcoV517Eq5D7kNePcT4z0MQ@mail.gmail.com
Quoted 5 lines · Feng Wang
Hi Steffen,
Thanks for your comment. Firstly, the patch is using the xfrm interface ID instead of network interface ID. Secondly, would you please point me to the 'packet offload drivers' in the kernel tree?
First, please don't reply to emails in top-post format. Second, did you try to search for "packet offload drivers" in the kernel?
https://elixir.bootlin.com/linux/v6.8.1/source/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec.c#L1152
Thanks
Quoted 65 lines
I want to understand how the offload driver can distinguish 2 ipsec sessions if two sessions accidentally have the same address/mask and proto
values(same xfrm_selector)? The offload driver needs to find the corresponding encryption parameters to do the work.Thank you for your help,
Feng
Quoted 51 lines · Steffen Klassert
Quoted 3 lines · Feng Wang
Hi Leon,
There is no "packet offload driver" in the current kernel tree. The
packet
Quoted 2 lines
offload driver mostly is vendor specific, it implements hardware packet offload.
There are 'packet offload drivers' in the kernel, that's why we support this kind of offload. We don't add code for proprietary drivers.
Quoted 20 lines · Leon Romanovsky
Quoted 19 lines · Feng Wang
Quoted 5 lines
From: wangfe <[email protected]>
When there are multiple ipsec sessions, packet offload driver can use the index to distinguish the packets from the different sessions even though
xfrm_selectorare same.Do we have such "packet offload driver" in the kernel tree?
Thanks
Quoted 7 lines
Thus each packet is handled corresponding to its session parameter.
Signed-off-by wangfe <[email protected]>--- net/xfrm/xfrm_interface_core.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)Quoted 6 lines
Quoted 6 lines
Review
Quoted 1 line
(quoted diff) +0
-0
b/net/xfrm/xfrm_interface_core.cnet/xfrm/xfrm_interface_core.c xfrmi_xmit2(struct sk_buff *skb, struct
Quoted 4 lines
index
21d50d75c260..996571af53e5100644net/xfrm/xfrm_interface_core.c +0
-0@@ -506,7 +506,9 @@ xfrmi_xmit2(struct sk_buff *skb, struct
net_deviceQuoted 8 lines
Quoted 8 lines
*dev, struct flowi *fl)
net/xfrm/xfrm_interface_core.c xfrmi_xmit2(struct sk_buff *skb, struct net_device *dev, struct flowi *fl) · line 511
Quoted 7 lines
net/xfrm/xfrm_interface_core.c +3
-1xfrmi_scrub_packet (skb, !net_eq (xi->net,dev_net (dev)));skb_dst_set (skb, dst); skb->dev = tdev; - +#ifdef CONFIG_XFRM_OFFLOAD + skb->skb_iif = if_id; +#endif This looks wrong. The network interface ID is not the same as the xfrm interface ID.
A message that is not in the archive (sent off-list or not yet received): CADsK2K8=B=Yv4i6rzNdbuc-C6yc-pw6RSuRvKbsL2qYjsO9seg@mail.gmail.com
Quoted 7 lines · Feng Wang
Hi Leon and Steffen,
Thanks for providing me with the information. I went through the offload driver code but I didn't find any solution for my case. Is there any existing solution available? For example, there are 2 IPSec sessions with the same
xfrm_selectorresults, when trying to encrypt the packet, how to find out which session this packet belongs to?
HW catches packets based on match criteria of source and destination. If source, destination and other match criteria are the same for different sessions, then from HW perspective, it is the same session.
Thanks
A message that is not in the archive (sent off-list or not yet received): CADsK2K-VLdiuxeP82bmuGvmU6z848mLpk+JBYdhXppOq0B76VA@mail.gmail.com
Quoted 3 lines · Feng Wang
Thanks Leon for answering my question. In the above example, if we can pass the xfrm interface id to the HW, then HW can distinguish them based on it. That's what my patch is trying to do.
From partial grep, it looks like "xfrm interface id" is actually netdevice index. If this is the case, HW doesn't need to know about it, because packet offload is performed by specific device and skb_iif will be equal to that index anyway.
Quoted 2 lines
Would you please take this into consideration? If needed, I can improve my patch.
As a standalone patch, it is not correct. If you have a real use case, please send together with code which uses it.
Thanks
Quoted 26 lines
Thanks,
Feng
Quoted 16 lines · Leon Romanovsky
Quoted 5 lines · Feng Wang
Hi Leon and Steffen,
Thanks for providing me with the information. I went through the offload driver code but I didn't find any solution for my case. Is there any existing solution available? For example, there are 2 IPSec sessions
with
Quoted 2 lines
the same
xfrm_selectorresults, when trying to encrypt the packet, how to find out which session this packet belongs to?HW catches packets based on match criteria of source and destination. If source, destination and other match criteria are the same for different sessions, then from HW perspective, it is the same session.
Thanks
A message that is not in the archive (sent off-list or not yet received): CADsK2K8WvGmUdno5X=_ebNF1mzP9=kd1=ve31Tb5hSk+q4VTkg@mail.gmail.com
Quoted 11 lines · Feng Wang
The xfrm interface ID is the index of the ipsec device, for example, ipsec11, ipsec12. One ipsec application(VPN) might create an ipsec11 interface and send the data through this interface.
Another application(Wifi calling) might create an ipsec12 interface and send its data through ipsec12. Both packets are routed through the kernel to the one device driver(wifi). When the device driver receives the packet, it needs to find the correct application parameters to encrypt the packet. So if theskb_iifis marked by the kernel with ipsec11 or ipsec12, device driver can use this information to find the corresponding parameter. I hope I explain my user case clearly. If there is any misunderstanding, please let me know. I try my best to make it clear.
Like I said before, please send the code which uses this feature. Right now, packet offload doesn't need this feature.
Thanks
Quoted 57 lines
Thanks Leon.
FengQuoted 50 lines · Leon Romanovsky
Quoted 2 lines · Feng Wang
Thanks Leon for answering my question. In the above example, if we can pass the xfrm interface id to the HW, then HW can distinguish them based
on
Quoted 1 line
it. That's what my patch is trying to do.
From partial grep, it looks like "xfrm interface id" is actually netdevice index. If this is the case, HW doesn't need to know about it, because packet offload is performed by specific device and
skb_iifwill be equal to that index anyway.Quoted 1 line
Would you please take this into consideration? If needed, I can improve
my
Quoted 1 line
patch.
As a standalone patch, it is not correct. If you have a real use case, please send together with code which uses it.
Thanks
Quoted 14 lines
Thanks,
Feng
Quoted 4 lines · Leon Romanovsky
Quoted 3 lines · Feng Wang
Hi Leon and Steffen,
Thanks for providing me with the information. I went through the
offload
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
driver code but I didn't find any solution for my case. Is there any existing solution available? For example, there are 2 IPSec sessions
with
Quoted 1 line
the same
xfrm_selectorresults, when trying to encrypt the packet,how to
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
find out which session this packet belongs to?
HW catches packets based on match criteria of source and destination.
If
Quoted 5 lines
Quoted 5 lines
source, destination and other match criteria are the same for different sessions, then from HW perspective, it is the same session.
Thanks
Hi Feng,
Quoted 4 lines · Leon Romanovsky
Quoted 3 lines · Feng Wang
The xfrm interface ID is the index of the ipsec device, for example, ipsec11, ipsec12. One ipsec application(VPN) might create an ipsec11 interface and send the data through this interface.
Where to find xfrm interface if_id depends on the direction the packet is traversing, direction "out": (clear text in ESP out), or "in": (ESP in clear text out) use if_id diffrently.
Which case are you looking at? It sounds like out.
Quoted 4 lines
Quoted 4 lines
Another application(Wifi calling) might create an ipsec12 interface and send its data through ipsec12. Both packets are routed through the kernel to the one device driver(wifi). When the device driver receives the packet, it needs to find the correct application parameters to encrypt the
this looks like an out case. After a successful dst lookup, xfrm_lookup(),
look at skb_dst(skb)->xfrm->if_id ?
Quoted 4 lines
Quoted 4 lines
packet. So if the
skb_iifis marked by the kernel with ipsec11 or ipsec12, device driver can use this information to find the corresponding parameter. I hope I explain my user case clearly. If there is any misunderstanding, please let me know. I try my best to make it clear.
skb_dst(skb)->xfrm->if_id should match what is in the xfrm policy I think, p->if_id.
Note I assumed the packet is locally generated. If it is a forwarded packet there could be another policy lookup before.
Quoted 2 lines
Like I said before, please send the code which uses this feature. Right now, packet offload doesn't need this feature.
+1
-antony