@@ -623,6 +623,32 @@ static int vxlan_fdb_append(struct vxlan_fdb *f,
623
623
return 1 ;
624
624
}
625
625
626
+ static bool vxlan_parse_gpe_proto (struct vxlanhdr * hdr , __be16 * protocol )
627
+ {
628
+ struct vxlanhdr_gpe * gpe = (struct vxlanhdr_gpe * )hdr ;
629
+
630
+ /* Need to have Next Protocol set for interfaces in GPE mode. */
631
+ if (!gpe -> np_applied )
632
+ return false;
633
+ /* "The initial version is 0. If a receiver does not support the
634
+ * version indicated it MUST drop the packet.
635
+ */
636
+ if (gpe -> version != 0 )
637
+ return false;
638
+ /* "When the O bit is set to 1, the packet is an OAM packet and OAM
639
+ * processing MUST occur." However, we don't implement OAM
640
+ * processing, thus drop the packet.
641
+ */
642
+ if (gpe -> oam_flag )
643
+ return false;
644
+
645
+ * protocol = tun_p_to_eth_p (gpe -> next_protocol );
646
+ if (!* protocol )
647
+ return false;
648
+
649
+ return true;
650
+ }
651
+
626
652
static struct vxlanhdr * vxlan_gro_remcsum (struct sk_buff * skb ,
627
653
unsigned int off ,
628
654
struct vxlanhdr * vh , size_t hdrlen ,
@@ -649,39 +675,37 @@ static struct vxlanhdr *vxlan_gro_remcsum(struct sk_buff *skb,
649
675
return vh ;
650
676
}
651
677
652
- static struct sk_buff * vxlan_gro_receive (struct sock * sk ,
653
- struct list_head * head ,
654
- struct sk_buff * skb )
678
+ static struct vxlanhdr * vxlan_gro_prepare_receive (struct sock * sk ,
679
+ struct list_head * head ,
680
+ struct sk_buff * skb ,
681
+ struct gro_remcsum * grc )
655
682
{
656
- struct sk_buff * pp = NULL ;
657
683
struct sk_buff * p ;
658
684
struct vxlanhdr * vh , * vh2 ;
659
685
unsigned int hlen , off_vx ;
660
- int flush = 1 ;
661
686
struct vxlan_sock * vs = rcu_dereference_sk_user_data (sk );
662
687
__be32 flags ;
663
- struct gro_remcsum grc ;
664
688
665
- skb_gro_remcsum_init (& grc );
689
+ skb_gro_remcsum_init (grc );
666
690
667
691
off_vx = skb_gro_offset (skb );
668
692
hlen = off_vx + sizeof (* vh );
669
693
vh = skb_gro_header (skb , hlen , off_vx );
670
694
if (unlikely (!vh ))
671
- goto out ;
695
+ return NULL ;
672
696
673
697
skb_gro_postpull_rcsum (skb , vh , sizeof (struct vxlanhdr ));
674
698
675
699
flags = vh -> vx_flags ;
676
700
677
701
if ((flags & VXLAN_HF_RCO ) && (vs -> flags & VXLAN_F_REMCSUM_RX )) {
678
702
vh = vxlan_gro_remcsum (skb , off_vx , vh , sizeof (struct vxlanhdr ),
679
- vh -> vx_vni , & grc ,
703
+ vh -> vx_vni , grc ,
680
704
!!(vs -> flags &
681
705
VXLAN_F_REMCSUM_NOPARTIAL ));
682
706
683
707
if (!vh )
684
- goto out ;
708
+ return NULL ;
685
709
}
686
710
687
711
skb_gro_pull (skb , sizeof (struct vxlanhdr )); /* pull vxlan header */
@@ -698,12 +722,48 @@ static struct sk_buff *vxlan_gro_receive(struct sock *sk,
698
722
}
699
723
}
700
724
701
- pp = call_gro_receive ( eth_gro_receive , head , skb ) ;
702
- flush = 0 ;
725
+ return vh ;
726
+ }
703
727
704
- out :
728
+ static struct sk_buff * vxlan_gro_receive (struct sock * sk ,
729
+ struct list_head * head ,
730
+ struct sk_buff * skb )
731
+ {
732
+ struct sk_buff * pp = NULL ;
733
+ struct gro_remcsum grc ;
734
+ int flush = 1 ;
735
+
736
+ if (vxlan_gro_prepare_receive (sk , head , skb , & grc )) {
737
+ pp = call_gro_receive (eth_gro_receive , head , skb );
738
+ flush = 0 ;
739
+ }
705
740
skb_gro_flush_final_remcsum (skb , pp , flush , & grc );
741
+ return pp ;
742
+ }
743
+
744
+ static struct sk_buff * vxlan_gpe_gro_receive (struct sock * sk ,
745
+ struct list_head * head ,
746
+ struct sk_buff * skb )
747
+ {
748
+ const struct packet_offload * ptype ;
749
+ struct sk_buff * pp = NULL ;
750
+ struct gro_remcsum grc ;
751
+ struct vxlanhdr * vh ;
752
+ __be16 protocol ;
753
+ int flush = 1 ;
706
754
755
+ vh = vxlan_gro_prepare_receive (sk , head , skb , & grc );
756
+ if (vh ) {
757
+ if (!vxlan_parse_gpe_proto (vh , & protocol ))
758
+ goto out ;
759
+ ptype = gro_find_receive_by_type (protocol );
760
+ if (!ptype )
761
+ goto out ;
762
+ pp = call_gro_receive (ptype -> callbacks .gro_receive , head , skb );
763
+ flush = 0 ;
764
+ }
765
+ out :
766
+ skb_gro_flush_final_remcsum (skb , pp , flush , & grc );
707
767
return pp ;
708
768
}
709
769
@@ -715,6 +775,21 @@ static int vxlan_gro_complete(struct sock *sk, struct sk_buff *skb, int nhoff)
715
775
return eth_gro_complete (skb , nhoff + sizeof (struct vxlanhdr ));
716
776
}
717
777
778
+ static int vxlan_gpe_gro_complete (struct sock * sk , struct sk_buff * skb , int nhoff )
779
+ {
780
+ struct vxlanhdr * vh = (struct vxlanhdr * )(skb -> data + nhoff );
781
+ const struct packet_offload * ptype ;
782
+ int err = - ENOSYS ;
783
+ __be16 protocol ;
784
+
785
+ if (!vxlan_parse_gpe_proto (vh , & protocol ))
786
+ return err ;
787
+ ptype = gro_find_complete_by_type (protocol );
788
+ if (ptype )
789
+ err = ptype -> callbacks .gro_complete (skb , nhoff + sizeof (struct vxlanhdr ));
790
+ return err ;
791
+ }
792
+
718
793
static struct vxlan_fdb * vxlan_fdb_alloc (struct vxlan_dev * vxlan , const u8 * mac ,
719
794
__u16 state , __be32 src_vni ,
720
795
__u16 ndm_flags )
@@ -1525,35 +1600,6 @@ static void vxlan_parse_gbp_hdr(struct vxlanhdr *unparsed,
1525
1600
unparsed -> vx_flags &= ~VXLAN_GBP_USED_BITS ;
1526
1601
}
1527
1602
1528
- static bool vxlan_parse_gpe_hdr (struct vxlanhdr * unparsed ,
1529
- __be16 * protocol ,
1530
- struct sk_buff * skb , u32 vxflags )
1531
- {
1532
- struct vxlanhdr_gpe * gpe = (struct vxlanhdr_gpe * )unparsed ;
1533
-
1534
- /* Need to have Next Protocol set for interfaces in GPE mode. */
1535
- if (!gpe -> np_applied )
1536
- return false;
1537
- /* "The initial version is 0. If a receiver does not support the
1538
- * version indicated it MUST drop the packet.
1539
- */
1540
- if (gpe -> version != 0 )
1541
- return false;
1542
- /* "When the O bit is set to 1, the packet is an OAM packet and OAM
1543
- * processing MUST occur." However, we don't implement OAM
1544
- * processing, thus drop the packet.
1545
- */
1546
- if (gpe -> oam_flag )
1547
- return false;
1548
-
1549
- * protocol = tun_p_to_eth_p (gpe -> next_protocol );
1550
- if (!* protocol )
1551
- return false;
1552
-
1553
- unparsed -> vx_flags &= ~VXLAN_GPE_USED_BITS ;
1554
- return true;
1555
- }
1556
-
1557
1603
static bool vxlan_set_mac (struct vxlan_dev * vxlan ,
1558
1604
struct vxlan_sock * vs ,
1559
1605
struct sk_buff * skb , __be32 vni )
@@ -1655,8 +1701,9 @@ static int vxlan_rcv(struct sock *sk, struct sk_buff *skb)
1655
1701
* used by VXLAN extensions if explicitly requested.
1656
1702
*/
1657
1703
if (vs -> flags & VXLAN_F_GPE ) {
1658
- if (!vxlan_parse_gpe_hdr (& unparsed , & protocol , skb , vs -> flags ))
1704
+ if (!vxlan_parse_gpe_proto (& unparsed , & protocol ))
1659
1705
goto drop ;
1706
+ unparsed .vx_flags &= ~VXLAN_GPE_USED_BITS ;
1660
1707
raw_proto = true;
1661
1708
}
1662
1709
@@ -3378,8 +3425,13 @@ static struct vxlan_sock *vxlan_socket_create(struct net *net, bool ipv6,
3378
3425
tunnel_cfg .encap_rcv = vxlan_rcv ;
3379
3426
tunnel_cfg .encap_err_lookup = vxlan_err_lookup ;
3380
3427
tunnel_cfg .encap_destroy = NULL ;
3381
- tunnel_cfg .gro_receive = vxlan_gro_receive ;
3382
- tunnel_cfg .gro_complete = vxlan_gro_complete ;
3428
+ if (vs -> flags & VXLAN_F_GPE ) {
3429
+ tunnel_cfg .gro_receive = vxlan_gpe_gro_receive ;
3430
+ tunnel_cfg .gro_complete = vxlan_gpe_gro_complete ;
3431
+ } else {
3432
+ tunnel_cfg .gro_receive = vxlan_gro_receive ;
3433
+ tunnel_cfg .gro_complete = vxlan_gro_complete ;
3434
+ }
3383
3435
3384
3436
setup_udp_tunnel_sock (net , sock , & tunnel_cfg );
3385
3437
0 commit comments