@@ -310,6 +310,52 @@ static void xfrmi_scrub_packet(struct sk_buff *skb, bool xnet)
310310 skb -> mark = 0 ;
311311}
312312
313+ static int xfrmi_input (struct sk_buff * skb , int nexthdr , __be32 spi ,
314+ int encap_type , unsigned short family )
315+ {
316+ struct sec_path * sp ;
317+
318+ sp = skb_sec_path (skb );
319+ if (sp && (sp -> len || sp -> olen ) &&
320+ !xfrm_policy_check (NULL , XFRM_POLICY_IN , skb , family ))
321+ goto discard ;
322+
323+ XFRM_SPI_SKB_CB (skb )-> family = family ;
324+ if (family == AF_INET ) {
325+ XFRM_SPI_SKB_CB (skb )-> daddroff = offsetof(struct iphdr , daddr );
326+ XFRM_TUNNEL_SKB_CB (skb )-> tunnel .ip4 = NULL ;
327+ } else {
328+ XFRM_SPI_SKB_CB (skb )-> daddroff = offsetof(struct ipv6hdr , daddr );
329+ XFRM_TUNNEL_SKB_CB (skb )-> tunnel .ip6 = NULL ;
330+ }
331+
332+ return xfrm_input (skb , nexthdr , spi , encap_type );
333+ discard :
334+ kfree_skb (skb );
335+ return 0 ;
336+ }
337+
338+ static int xfrmi4_rcv (struct sk_buff * skb )
339+ {
340+ return xfrmi_input (skb , ip_hdr (skb )-> protocol , 0 , 0 , AF_INET );
341+ }
342+
343+ static int xfrmi6_rcv (struct sk_buff * skb )
344+ {
345+ return xfrmi_input (skb , skb_network_header (skb )[IP6CB (skb )-> nhoff ],
346+ 0 , 0 , AF_INET6 );
347+ }
348+
349+ static int xfrmi4_input (struct sk_buff * skb , int nexthdr , __be32 spi , int encap_type )
350+ {
351+ return xfrmi_input (skb , nexthdr , spi , encap_type , AF_INET );
352+ }
353+
354+ static int xfrmi6_input (struct sk_buff * skb , int nexthdr , __be32 spi , int encap_type )
355+ {
356+ return xfrmi_input (skb , nexthdr , spi , encap_type , AF_INET6 );
357+ }
358+
313359static int xfrmi_rcv_cb (struct sk_buff * skb , int err )
314360{
315361 const struct xfrm_mode * inner_mode ;
@@ -945,8 +991,8 @@ static struct pernet_operations xfrmi_net_ops = {
945991};
946992
947993static struct xfrm6_protocol xfrmi_esp6_protocol __read_mostly = {
948- .handler = xfrm6_rcv ,
949- .input_handler = xfrm_input ,
994+ .handler = xfrmi6_rcv ,
995+ .input_handler = xfrmi6_input ,
950996 .cb_handler = xfrmi_rcv_cb ,
951997 .err_handler = xfrmi6_err ,
952998 .priority = 10 ,
@@ -996,8 +1042,8 @@ static struct xfrm6_tunnel xfrmi_ip6ip_handler __read_mostly = {
9961042#endif
9971043
9981044static struct xfrm4_protocol xfrmi_esp4_protocol __read_mostly = {
999- .handler = xfrm4_rcv ,
1000- .input_handler = xfrm_input ,
1045+ .handler = xfrmi4_rcv ,
1046+ .input_handler = xfrmi4_input ,
10011047 .cb_handler = xfrmi_rcv_cb ,
10021048 .err_handler = xfrmi4_err ,
10031049 .priority = 10 ,
0 commit comments