hc
2024-05-10 cde9070d9970eef1f7ec2360586c802a16230ad8
kernel/drivers/net/ipvlan/ipvlan_core.c
....@@ -1,10 +1,5 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /* Copyright (c) 2014 Mahesh Bandewar <maheshb@google.com>
2
- *
3
- * This program is free software; you can redistribute it and/or
4
- * modify it under the terms of the GNU General Public License as
5
- * published by the Free Software Foundation; either version 2 of
6
- * the License, or (at your option) any later version.
7
- *
83 */
94
105 #include "ipvlan.h"
....@@ -138,7 +133,7 @@
138133 return ret;
139134 }
140135
141
-static void *ipvlan_get_L3_hdr(struct ipvl_port *port, struct sk_buff *skb, int *type)
136
+void *ipvlan_get_L3_hdr(struct ipvl_port *port, struct sk_buff *skb, int *type)
142137 {
143138 void *lyr3h = NULL;
144139
....@@ -356,9 +351,8 @@
356351 return ret;
357352 }
358353
359
-static struct ipvl_addr *ipvlan_addr_lookup(struct ipvl_port *port,
360
- void *lyr3h, int addr_type,
361
- bool use_dest)
354
+struct ipvl_addr *ipvlan_addr_lookup(struct ipvl_port *port, void *lyr3h,
355
+ int addr_type, bool use_dest)
362356 {
363357 struct ipvl_addr *addr = NULL;
364358
....@@ -443,6 +437,9 @@
443437 goto err;
444438 }
445439 skb_dst_set(skb, &rt->dst);
440
+
441
+ memset(IPCB(skb), 0, sizeof(*IPCB(skb)));
442
+
446443 err = ip_local_out(net, skb->sk, skb);
447444 if (unlikely(net_xmit_eval(err)))
448445 dev->stats.tx_errors++;
....@@ -481,6 +478,9 @@
481478 goto err;
482479 }
483480 skb_dst_set(skb, dst);
481
+
482
+ memset(IP6CB(skb), 0, sizeof(*IP6CB(skb)));
483
+
484484 err = ip6_local_out(net, skb->sk, skb);
485485 if (unlikely(net_xmit_eval(err)))
486486 dev->stats.tx_errors++;
....@@ -502,7 +502,6 @@
502502
503503 static int ipvlan_process_outbound(struct sk_buff *skb)
504504 {
505
- struct ethhdr *ethh = eth_hdr(skb);
506505 int ret = NET_XMIT_DROP;
507506
508507 /* The ipvlan is a pseudo-L2 device, so the packets that we receive
....@@ -512,6 +511,8 @@
512511 if (skb_mac_header_was_set(skb)) {
513512 /* In this mode we dont care about
514513 * multicast and broadcast traffic */
514
+ struct ethhdr *ethh = eth_hdr(skb);
515
+
515516 if (is_multicast_ether_addr(ethh->h_dest)) {
516517 pr_debug_ratelimited(
517518 "Dropped {multi|broad}cast of type=[%x]\n",
....@@ -585,7 +586,8 @@
585586 consume_skb(skb);
586587 return NET_XMIT_DROP;
587588 }
588
- return ipvlan_rcv_frame(addr, &skb, true);
589
+ ipvlan_rcv_frame(addr, &skb, true);
590
+ return NET_XMIT_SUCCESS;
589591 }
590592 }
591593 out:
....@@ -596,7 +598,7 @@
596598 static int ipvlan_xmit_mode_l2(struct sk_buff *skb, struct net_device *dev)
597599 {
598600 const struct ipvl_dev *ipvlan = netdev_priv(dev);
599
- struct ethhdr *eth = eth_hdr(skb);
601
+ struct ethhdr *eth = skb_eth_hdr(skb);
600602 struct ipvl_addr *addr;
601603 void *lyr3h;
602604 int addr_type;
....@@ -611,7 +613,8 @@
611613 consume_skb(skb);
612614 return NET_XMIT_DROP;
613615 }
614
- return ipvlan_rcv_frame(addr, &skb, true);
616
+ ipvlan_rcv_frame(addr, &skb, true);
617
+ return NET_XMIT_SUCCESS;
615618 }
616619 }
617620 skb = skb_share_check(skb, GFP_ATOMIC);
....@@ -623,9 +626,11 @@
623626 * the skb for the main-dev. At the RX side we just return
624627 * RX_PASS for it to be processed further on the stack.
625628 */
626
- return dev_forward_skb(ipvlan->phy_dev, skb);
629
+ dev_forward_skb(ipvlan->phy_dev, skb);
630
+ return NET_XMIT_SUCCESS;
627631
628632 } else if (is_multicast_ether_addr(eth->h_dest)) {
633
+ skb_reset_mac_header(skb);
629634 ipvlan_skb_crossing_ns(skb, NULL);
630635 ipvlan_multicast_enqueue(ipvlan->port, skb, true);
631636 return NET_XMIT_SUCCESS;
....@@ -650,7 +655,9 @@
650655 case IPVLAN_MODE_L2:
651656 return ipvlan_xmit_mode_l2(skb, dev);
652657 case IPVLAN_MODE_L3:
658
+#ifdef CONFIG_IPVLAN_L3S
653659 case IPVLAN_MODE_L3S:
660
+#endif
654661 return ipvlan_xmit_mode_l3(skb, dev);
655662 }
656663
....@@ -746,8 +753,10 @@
746753 return ipvlan_handle_mode_l2(pskb, port);
747754 case IPVLAN_MODE_L3:
748755 return ipvlan_handle_mode_l3(pskb, port);
756
+#ifdef CONFIG_IPVLAN_L3S
749757 case IPVLAN_MODE_L3S:
750758 return RX_HANDLER_PASS;
759
+#endif
751760 }
752761
753762 /* Should not reach here */
....@@ -755,98 +764,4 @@
755764 port->mode);
756765 kfree_skb(skb);
757766 return RX_HANDLER_CONSUMED;
758
-}
759
-
760
-static struct ipvl_addr *ipvlan_skb_to_addr(struct sk_buff *skb,
761
- struct net_device *dev)
762
-{
763
- struct ipvl_addr *addr = NULL;
764
- struct ipvl_port *port;
765
- void *lyr3h;
766
- int addr_type;
767
-
768
- if (!dev || !netif_is_ipvlan_port(dev))
769
- goto out;
770
-
771
- port = ipvlan_port_get_rcu(dev);
772
- if (!port || port->mode != IPVLAN_MODE_L3S)
773
- goto out;
774
-
775
- lyr3h = ipvlan_get_L3_hdr(port, skb, &addr_type);
776
- if (!lyr3h)
777
- goto out;
778
-
779
- addr = ipvlan_addr_lookup(port, lyr3h, addr_type, true);
780
-out:
781
- return addr;
782
-}
783
-
784
-struct sk_buff *ipvlan_l3_rcv(struct net_device *dev, struct sk_buff *skb,
785
- u16 proto)
786
-{
787
- struct ipvl_addr *addr;
788
- struct net_device *sdev;
789
-
790
- addr = ipvlan_skb_to_addr(skb, dev);
791
- if (!addr)
792
- goto out;
793
-
794
- sdev = addr->master->dev;
795
- switch (proto) {
796
- case AF_INET:
797
- {
798
- int err;
799
- struct iphdr *ip4h = ip_hdr(skb);
800
-
801
- err = ip_route_input_noref(skb, ip4h->daddr, ip4h->saddr,
802
- ip4h->tos, sdev);
803
- if (unlikely(err))
804
- goto out;
805
- break;
806
- }
807
-#if IS_ENABLED(CONFIG_IPV6)
808
- case AF_INET6:
809
- {
810
- struct dst_entry *dst;
811
- struct ipv6hdr *ip6h = ipv6_hdr(skb);
812
- int flags = RT6_LOOKUP_F_HAS_SADDR;
813
- struct flowi6 fl6 = {
814
- .flowi6_iif = sdev->ifindex,
815
- .daddr = ip6h->daddr,
816
- .saddr = ip6h->saddr,
817
- .flowlabel = ip6_flowinfo(ip6h),
818
- .flowi6_mark = skb->mark,
819
- .flowi6_proto = ip6h->nexthdr,
820
- };
821
-
822
- skb_dst_drop(skb);
823
- dst = ip6_route_input_lookup(dev_net(sdev), sdev, &fl6,
824
- skb, flags);
825
- skb_dst_set(skb, dst);
826
- break;
827
- }
828
-#endif
829
- default:
830
- break;
831
- }
832
-
833
-out:
834
- return skb;
835
-}
836
-
837
-unsigned int ipvlan_nf_input(void *priv, struct sk_buff *skb,
838
- const struct nf_hook_state *state)
839
-{
840
- struct ipvl_addr *addr;
841
- unsigned int len;
842
-
843
- addr = ipvlan_skb_to_addr(skb, skb->dev);
844
- if (!addr)
845
- goto out;
846
-
847
- skb->dev = addr->master->dev;
848
- len = skb->len + ETH_HLEN;
849
- ipvlan_count_rx(addr->master, len, true, false);
850
-out:
851
- return NF_ACCEPT;
852767 }