^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (c) 2007-2012 Nicira, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #include <linux/if_vlan.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/etherdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/ethtool.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/skbuff.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <net/dst.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <net/xfrm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <net/rtnetlink.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include "datapath.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include "vport-internal_dev.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include "vport-netdev.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) struct internal_dev {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) struct vport *vport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) static struct vport_ops ovs_internal_vport_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) static struct internal_dev *internal_dev_priv(struct net_device *netdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) return netdev_priv(netdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) /* Called with rcu_read_lock_bh. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) static netdev_tx_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) internal_dev_xmit(struct sk_buff *skb, struct net_device *netdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) int len, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) len = skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) err = ovs_vport_receive(internal_dev_priv(netdev)->vport, skb, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) if (likely(!err)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) struct pcpu_sw_netstats *tstats = this_cpu_ptr(netdev->tstats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) u64_stats_update_begin(&tstats->syncp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) tstats->tx_bytes += len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) tstats->tx_packets++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) u64_stats_update_end(&tstats->syncp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) netdev->stats.tx_errors++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) return NETDEV_TX_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) static int internal_dev_open(struct net_device *netdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) netif_start_queue(netdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) static int internal_dev_stop(struct net_device *netdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) netif_stop_queue(netdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) static void internal_dev_getinfo(struct net_device *netdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) struct ethtool_drvinfo *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) strlcpy(info->driver, "openvswitch", sizeof(info->driver));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) static const struct ethtool_ops internal_dev_ethtool_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) .get_drvinfo = internal_dev_getinfo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) .get_link = ethtool_op_get_link,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) static void internal_dev_destructor(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) struct vport *vport = ovs_internal_dev_get_vport(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) ovs_vport_free(vport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) internal_get_stats(struct net_device *dev, struct rtnl_link_stats64 *stats)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) memset(stats, 0, sizeof(*stats));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) stats->rx_errors = dev->stats.rx_errors;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) stats->tx_errors = dev->stats.tx_errors;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) stats->tx_dropped = dev->stats.tx_dropped;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) stats->rx_dropped = dev->stats.rx_dropped;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) dev_fetch_sw_netstats(stats, dev->tstats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) static const struct net_device_ops internal_dev_netdev_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) .ndo_open = internal_dev_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) .ndo_stop = internal_dev_stop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) .ndo_start_xmit = internal_dev_xmit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) .ndo_set_mac_address = eth_mac_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) .ndo_get_stats64 = internal_get_stats,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) static struct rtnl_link_ops internal_dev_link_ops __read_mostly = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) .kind = "openvswitch",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) static void do_setup(struct net_device *netdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) ether_setup(netdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) netdev->max_mtu = ETH_MAX_MTU;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) netdev->netdev_ops = &internal_dev_netdev_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) netdev->priv_flags &= ~IFF_TX_SKB_SHARING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) netdev->priv_flags |= IFF_LIVE_ADDR_CHANGE | IFF_OPENVSWITCH |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) IFF_NO_QUEUE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) netdev->needs_free_netdev = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) netdev->priv_destructor = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) netdev->ethtool_ops = &internal_dev_ethtool_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) netdev->rtnl_link_ops = &internal_dev_link_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) netdev->features = NETIF_F_LLTX | NETIF_F_SG | NETIF_F_FRAGLIST |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) NETIF_F_HIGHDMA | NETIF_F_HW_CSUM |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) NETIF_F_GSO_SOFTWARE | NETIF_F_GSO_ENCAP_ALL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) netdev->vlan_features = netdev->features;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) netdev->hw_enc_features = netdev->features;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) netdev->features |= NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_STAG_TX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) netdev->hw_features = netdev->features & ~NETIF_F_LLTX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) eth_hw_addr_random(netdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) static struct vport *internal_dev_create(const struct vport_parms *parms)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) struct vport *vport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) struct internal_dev *internal_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) struct net_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) vport = ovs_vport_alloc(0, &ovs_internal_vport_ops, parms);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) if (IS_ERR(vport)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) err = PTR_ERR(vport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) dev = alloc_netdev(sizeof(struct internal_dev),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) parms->name, NET_NAME_USER, do_setup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) vport->dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) if (!vport->dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) goto error_free_vport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) vport->dev->tstats = netdev_alloc_pcpu_stats(struct pcpu_sw_netstats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) if (!vport->dev->tstats) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) goto error_free_netdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) dev_net_set(vport->dev, ovs_dp_get_net(vport->dp));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) internal_dev = internal_dev_priv(vport->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) internal_dev->vport = vport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) /* Restrict bridge port to current netns. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) if (vport->port_no == OVSP_LOCAL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) vport->dev->features |= NETIF_F_NETNS_LOCAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) rtnl_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) err = register_netdevice(vport->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) goto error_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) vport->dev->priv_destructor = internal_dev_destructor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) dev_set_promiscuity(vport->dev, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) rtnl_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) netif_start_queue(vport->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) return vport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) error_unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) rtnl_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) free_percpu(dev->tstats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) error_free_netdev:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) free_netdev(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) error_free_vport:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) ovs_vport_free(vport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) return ERR_PTR(err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) static void internal_dev_destroy(struct vport *vport)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) netif_stop_queue(vport->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) rtnl_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) dev_set_promiscuity(vport->dev, -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) /* unregister_netdevice() waits for an RCU grace period. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) unregister_netdevice(vport->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) free_percpu(vport->dev->tstats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) rtnl_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) static netdev_tx_t internal_dev_recv(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) struct net_device *netdev = skb->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) if (unlikely(!(netdev->flags & IFF_UP))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) netdev->stats.rx_dropped++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) return NETDEV_TX_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) skb_dst_drop(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) nf_reset_ct(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) secpath_reset(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) skb->pkt_type = PACKET_HOST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) skb->protocol = eth_type_trans(skb, netdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) skb_postpull_rcsum(skb, eth_hdr(skb), ETH_HLEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) dev_sw_netstats_rx_add(netdev, skb->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) netif_rx(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) return NETDEV_TX_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) static struct vport_ops ovs_internal_vport_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) .type = OVS_VPORT_TYPE_INTERNAL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) .create = internal_dev_create,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) .destroy = internal_dev_destroy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) .send = internal_dev_recv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) int ovs_is_internal_dev(const struct net_device *netdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) return netdev->netdev_ops == &internal_dev_netdev_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) struct vport *ovs_internal_dev_get_vport(struct net_device *netdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) if (!ovs_is_internal_dev(netdev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) return internal_dev_priv(netdev)->vport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) int ovs_internal_dev_rtnl_link_register(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) err = rtnl_link_register(&internal_dev_link_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) err = ovs_vport_ops_register(&ovs_internal_vport_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) rtnl_link_unregister(&internal_dev_link_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) void ovs_internal_dev_rtnl_link_unregister(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) ovs_vport_ops_unregister(&ovs_internal_vport_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) rtnl_link_unregister(&internal_dev_link_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) }