X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=datapath%2Fvport-internal_dev.c;h=26b432b7cee0a54b11bf3f1c49515fe630f33ae8;hb=77912ae717298cb06544f1bebd9701d0b3c2f2f0;hp=04f51eb330186ba8c90b5e41be2e1248d7a3a558;hpb=9197df76b46ff6fbe1f7a522961730ffc55a860d;p=openvswitch diff --git a/datapath/vport-internal_dev.c b/datapath/vport-internal_dev.c index 04f51eb3..26b432b7 100644 --- a/datapath/vport-internal_dev.c +++ b/datapath/vport-internal_dev.c @@ -22,41 +22,51 @@ #include "vport-internal_dev.h" #include "vport-netdev.h" +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,1,0) +#define HAVE_NET_DEVICE_OPS +#endif + struct internal_dev { struct vport *vport; +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,22) struct net_device_stats stats; +#endif }; -static inline struct internal_dev *internal_dev_priv(struct net_device *netdev) +static struct internal_dev *internal_dev_priv(struct net_device *netdev) { return netdev_priv(netdev); } -/* This function is only called by the kernel network layer. It is not a vport - * get_stats() function. If a vport get_stats() function is defined that - * results in this being called it will cause infinite recursion. */ +/* This function is only called by the kernel network layer.*/ +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,36) +static struct rtnl_link_stats64 *internal_dev_get_stats(struct net_device *netdev, + struct rtnl_link_stats64 *stats) +{ +#else static struct net_device_stats *internal_dev_sys_stats(struct net_device *netdev) { - struct vport *vport = internal_dev_get_vport(netdev); +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,22) struct net_device_stats *stats = &internal_dev_priv(netdev)->stats; +#else + struct net_device_stats *stats = &netdev->stats; +#endif +#endif + struct vport *vport = internal_dev_get_vport(netdev); + struct ovs_vport_stats vport_stats; - if (vport) { - struct rtnl_link_stats64 vport_stats; - - vport_get_stats(vport, &vport_stats); - - /* The tx and rx stats need to be swapped because the switch - * and host OS have opposite perspectives. */ - stats->rx_packets = vport_stats.tx_packets; - stats->tx_packets = vport_stats.rx_packets; - stats->rx_bytes = vport_stats.tx_bytes; - stats->tx_bytes = vport_stats.rx_bytes; - stats->rx_errors = vport_stats.tx_errors; - stats->tx_errors = vport_stats.rx_errors; - stats->rx_dropped = vport_stats.tx_dropped; - stats->tx_dropped = vport_stats.rx_dropped; - stats->collisions = vport_stats.collisions; - } + vport_get_stats(vport, &vport_stats); + + /* The tx and rx stats need to be swapped because the + * switch and host OS have opposite perspectives. */ + stats->rx_packets = vport_stats.tx_packets; + stats->tx_packets = vport_stats.rx_packets; + stats->rx_bytes = vport_stats.tx_bytes; + stats->tx_bytes = vport_stats.rx_bytes; + stats->rx_errors = vport_stats.tx_errors; + stats->tx_errors = vport_stats.rx_errors; + stats->rx_dropped = vport_stats.tx_dropped; + stats->tx_dropped = vport_stats.rx_dropped; return stats; } @@ -71,7 +81,7 @@ static int internal_dev_mac_addr(struct net_device *dev, void *p) return 0; } -/* Called with rcu_read_lock and bottom-halves disabled. */ +/* Called with rcu_read_lock_bh. */ static int internal_dev_xmit(struct sk_buff *skb, struct net_device *netdev) { if (unlikely(compute_ip_summed(skb, true))) { @@ -82,7 +92,9 @@ static int internal_dev_xmit(struct sk_buff *skb, struct net_device *netdev) vlan_copy_skb_tci(skb); OVS_CB(skb)->flow = NULL; + rcu_read_lock(); vport_receive(internal_dev_priv(netdev)->vport, skb); + rcu_read_unlock(); return 0; } @@ -107,12 +119,14 @@ static void internal_dev_getinfo(struct net_device *netdev, static const struct ethtool_ops internal_dev_ethtool_ops = { .get_drvinfo = internal_dev_getinfo, .get_link = ethtool_op_get_link, +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,39) .get_sg = ethtool_op_get_sg, .set_sg = ethtool_op_set_sg, .get_tx_csum = ethtool_op_get_tx_csum, .set_tx_csum = ethtool_op_set_tx_hw_csum, .get_tso = ethtool_op_get_tso, .set_tso = ethtool_op_set_tso, +#endif }; static int internal_dev_change_mtu(struct net_device *netdev, int new_mtu) @@ -124,7 +138,8 @@ static int internal_dev_change_mtu(struct net_device *netdev, int new_mtu) return 0; } -static int internal_dev_do_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) +static int internal_dev_do_ioctl(struct net_device *dev, + struct ifreq *ifr, int cmd) { if (dp_ioctl_hook) return dp_ioctl_hook(dev, ifr, cmd); @@ -148,7 +163,11 @@ static const struct net_device_ops internal_dev_netdev_ops = { .ndo_set_mac_address = internal_dev_mac_addr, .ndo_do_ioctl = internal_dev_do_ioctl, .ndo_change_mtu = internal_dev_change_mtu, +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,36) + .ndo_get_stats64 = internal_dev_get_stats, +#else .ndo_get_stats = internal_dev_sys_stats, +#endif }; #endif @@ -168,11 +187,11 @@ static void do_setup(struct net_device *netdev) netdev->change_mtu = internal_dev_change_mtu; #endif + netdev->priv_flags &= ~IFF_TX_SKB_SHARING; netdev->destructor = internal_dev_destructor; SET_ETHTOOL_OPS(netdev, &internal_dev_ethtool_ops); netdev->tx_queue_len = 0; - netdev->flags = IFF_BROADCAST | IFF_MULTICAST; netdev->features = NETIF_F_LLTX | NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_HIGHDMA | NETIF_F_HW_CSUM | NETIF_F_TSO; @@ -181,6 +200,9 @@ static void do_setup(struct net_device *netdev) netdev->features |= NETIF_F_HW_VLAN_TX; #endif +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,39) + netdev->hw_features = netdev->features & ~NETIF_F_LLTX; +#endif vport_gen_rand_ether_addr(netdev->dev_addr); } @@ -191,7 +213,8 @@ static struct vport *internal_dev_create(const struct vport_parms *parms) struct internal_dev *internal_dev; int err; - vport = vport_alloc(sizeof(struct netdev_vport), &internal_vport_ops, parms); + vport = vport_alloc(sizeof(struct netdev_vport), + &internal_vport_ops, parms); if (IS_ERR(vport)) { err = PTR_ERR(vport); goto error; @@ -199,7 +222,8 @@ static struct vport *internal_dev_create(const struct vport_parms *parms) netdev_vport = netdev_vport_priv(vport); - netdev_vport->dev = alloc_netdev(sizeof(struct internal_dev), parms->name, do_setup); + netdev_vport->dev = alloc_netdev(sizeof(struct internal_dev), + parms->name, do_setup); if (!netdev_vport->dev) { err = -ENOMEM; goto error_free_vport; @@ -252,10 +276,7 @@ static int internal_dev_recv(struct vport *vport, struct sk_buff *skb) skb->protocol = eth_type_trans(skb, netdev); forward_ip_summed(skb, false); - if (in_interrupt()) - netif_rx(skb); - else - netif_rx_ni(skb); + netif_rx(skb); #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,29) netdev->last_rx = jiffies; @@ -266,7 +287,7 @@ static int internal_dev_recv(struct vport *vport, struct sk_buff *skb) const struct vport_ops internal_vport_ops = { .type = OVS_VPORT_TYPE_INTERNAL, - .flags = VPORT_F_REQUIRED | VPORT_F_GEN_STATS | VPORT_F_FLOW, + .flags = VPORT_F_REQUIRED | VPORT_F_FLOW, .create = internal_dev_create, .destroy = internal_dev_destroy, .set_addr = netdev_set_addr,