hc
2024-01-03 2f7c68cb55ecb7331f2381deb497c27155f32faf
kernel/drivers/net/vxlan.c
similarity index 98%rename from kernel/drivers/net/vxlan.crename to kernel/drivers/net/vxlan/vxlan_core.c
....@@ -729,6 +729,32 @@
729729 return 1;
730730 }
731731
732
+static bool vxlan_parse_gpe_proto(struct vxlanhdr *hdr, __be16 *protocol)
733
+{
734
+ struct vxlanhdr_gpe *gpe = (struct vxlanhdr_gpe *)hdr;
735
+
736
+ /* Need to have Next Protocol set for interfaces in GPE mode. */
737
+ if (!gpe->np_applied)
738
+ return false;
739
+ /* "The initial version is 0. If a receiver does not support the
740
+ * version indicated it MUST drop the packet.
741
+ */
742
+ if (gpe->version != 0)
743
+ return false;
744
+ /* "When the O bit is set to 1, the packet is an OAM packet and OAM
745
+ * processing MUST occur." However, we don't implement OAM
746
+ * processing, thus drop the packet.
747
+ */
748
+ if (gpe->oam_flag)
749
+ return false;
750
+
751
+ *protocol = tun_p_to_eth_p(gpe->next_protocol);
752
+ if (!*protocol)
753
+ return false;
754
+
755
+ return true;
756
+}
757
+
732758 static struct vxlanhdr *vxlan_gro_remcsum(struct sk_buff *skb,
733759 unsigned int off,
734760 struct vxlanhdr *vh, size_t hdrlen,
....@@ -1737,35 +1763,6 @@
17371763 unparsed->vx_flags &= ~VXLAN_GBP_USED_BITS;
17381764 }
17391765
1740
-static bool vxlan_parse_gpe_hdr(struct vxlanhdr *unparsed,
1741
- __be16 *protocol,
1742
- struct sk_buff *skb, u32 vxflags)
1743
-{
1744
- struct vxlanhdr_gpe *gpe = (struct vxlanhdr_gpe *)unparsed;
1745
-
1746
- /* Need to have Next Protocol set for interfaces in GPE mode. */
1747
- if (!gpe->np_applied)
1748
- return false;
1749
- /* "The initial version is 0. If a receiver does not support the
1750
- * version indicated it MUST drop the packet.
1751
- */
1752
- if (gpe->version != 0)
1753
- return false;
1754
- /* "When the O bit is set to 1, the packet is an OAM packet and OAM
1755
- * processing MUST occur." However, we don't implement OAM
1756
- * processing, thus drop the packet.
1757
- */
1758
- if (gpe->oam_flag)
1759
- return false;
1760
-
1761
- *protocol = tun_p_to_eth_p(gpe->next_protocol);
1762
- if (!*protocol)
1763
- return false;
1764
-
1765
- unparsed->vx_flags &= ~VXLAN_GPE_USED_BITS;
1766
- return true;
1767
-}
1768
-
17691766 static bool vxlan_set_mac(struct vxlan_dev *vxlan,
17701767 struct vxlan_sock *vs,
17711768 struct sk_buff *skb, __be32 vni)
....@@ -1866,8 +1863,9 @@
18661863 * used by VXLAN extensions if explicitly requested.
18671864 */
18681865 if (vs->flags & VXLAN_F_GPE) {
1869
- if (!vxlan_parse_gpe_hdr(&unparsed, &protocol, skb, vs->flags))
1866
+ if (!vxlan_parse_gpe_proto(&unparsed, &protocol))
18701867 goto drop;
1868
+ unparsed.vx_flags &= ~VXLAN_GPE_USED_BITS;
18711869 raw_proto = true;
18721870 }
18731871
....@@ -2720,7 +2718,7 @@
27202718 }
27212719
27222720 ndst = &rt->dst;
2723
- err = skb_tunnel_check_pmtu(skb, ndst, VXLAN_HEADROOM,
2721
+ err = skb_tunnel_check_pmtu(skb, ndst, vxlan_headroom(flags & VXLAN_F_GPE),
27242722 netif_is_any_bridge_port(dev));
27252723 if (err < 0) {
27262724 goto tx_error;
....@@ -2781,7 +2779,8 @@
27812779 goto out_unlock;
27822780 }
27832781
2784
- err = skb_tunnel_check_pmtu(skb, ndst, VXLAN6_HEADROOM,
2782
+ err = skb_tunnel_check_pmtu(skb, ndst,
2783
+ vxlan_headroom((flags & VXLAN_F_GPE) | VXLAN_F_IPV6),
27852784 netif_is_any_bridge_port(dev));
27862785 if (err < 0) {
27872786 goto tx_error;
....@@ -3158,14 +3157,12 @@
31583157 struct vxlan_rdst *dst = &vxlan->default_dst;
31593158 struct net_device *lowerdev = __dev_get_by_index(vxlan->net,
31603159 dst->remote_ifindex);
3161
- bool use_ipv6 = !!(vxlan->cfg.flags & VXLAN_F_IPV6);
31623160
31633161 /* This check is different than dev->max_mtu, because it looks at
31643162 * the lowerdev->mtu, rather than the static dev->max_mtu
31653163 */
31663164 if (lowerdev) {
3167
- int max_mtu = lowerdev->mtu -
3168
- (use_ipv6 ? VXLAN6_HEADROOM : VXLAN_HEADROOM);
3165
+ int max_mtu = lowerdev->mtu - vxlan_headroom(vxlan->cfg.flags);
31693166 if (new_mtu > max_mtu)
31703167 return -EINVAL;
31713168 }
....@@ -3784,11 +3781,11 @@
37843781 struct vxlan_dev *vxlan = netdev_priv(dev);
37853782 struct vxlan_rdst *dst = &vxlan->default_dst;
37863783 unsigned short needed_headroom = ETH_HLEN;
3787
- bool use_ipv6 = !!(conf->flags & VXLAN_F_IPV6);
37883784 int max_mtu = ETH_MAX_MTU;
3785
+ u32 flags = conf->flags;
37893786
37903787 if (!changelink) {
3791
- if (conf->flags & VXLAN_F_GPE)
3788
+ if (flags & VXLAN_F_GPE)
37923789 vxlan_raw_setup(dev);
37933790 else
37943791 vxlan_ether_setup(dev);
....@@ -3814,8 +3811,7 @@
38143811
38153812 dev->needed_tailroom = lowerdev->needed_tailroom;
38163813
3817
- max_mtu = lowerdev->mtu - (use_ipv6 ? VXLAN6_HEADROOM :
3818
- VXLAN_HEADROOM);
3814
+ max_mtu = lowerdev->mtu - vxlan_headroom(flags);
38193815 if (max_mtu < ETH_MIN_MTU)
38203816 max_mtu = ETH_MIN_MTU;
38213817
....@@ -3826,10 +3822,9 @@
38263822 if (dev->mtu > max_mtu)
38273823 dev->mtu = max_mtu;
38283824
3829
- if (use_ipv6 || conf->flags & VXLAN_F_COLLECT_METADATA)
3830
- needed_headroom += VXLAN6_HEADROOM;
3831
- else
3832
- needed_headroom += VXLAN_HEADROOM;
3825
+ if (flags & VXLAN_F_COLLECT_METADATA)
3826
+ flags |= VXLAN_F_IPV6;
3827
+ needed_headroom += vxlan_headroom(flags);
38333828 dev->needed_headroom = needed_headroom;
38343829
38353830 memcpy(&vxlan->cfg, conf, sizeof(*conf));